Skip to content

Commit

Permalink
Merge branch 'master' into static-schedule
Browse files Browse the repository at this point in the history
  • Loading branch information
lsk567 committed Oct 21, 2024
2 parents 28a995e + dcd3e70 commit 58a6e93
Show file tree
Hide file tree
Showing 46 changed files with 865 additions and 123 deletions.
8 changes: 0 additions & 8 deletions .github/workflows/all-misc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,6 @@ jobs:
with:
all-platforms: ${{ github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }}

# Run language server tests.
lsp:
if: ${{ needs.check-diff.outputs.run_misc == 'true' }}
needs: check-diff
uses: ./.github/workflows/lsp-tests.yml
with:
all-platforms: ${{ github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }}

check-labels:
uses: ./.github/workflows/check-labels.yml
if: ${{ github.event_name == 'pull_request' }}
4 changes: 4 additions & 0 deletions .github/workflows/lsp-tests.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: Language server tests

on:
schedule:
# * is a special character in YAML so you have to quote this string
- cron: '0 8 * * 6'
workflow_dispatch:
workflow_call:
inputs:
all-platforms:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ts-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ jobs:
- name: Prepare build environment
uses: ./.github/actions/prepare-build-env
- name: Setup Node.js environment
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 18
node-version: 22
- name: Install pnpm
run: npm i -g pnpm
- name: Install coreutils (macOS)
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,6 @@ gradle-app.setting
*.jar
core/model/

# Exclude all build directories except test/Python/build for testing purposes
!test/Python/build/

13 changes: 12 additions & 1 deletion core/src/main/java/org/lflang/LFResourceDescriptionStrategy.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.eclipse.xtext.scoping.impl.ImportUriResolver;
import org.eclipse.xtext.util.IAcceptor;
import org.lflang.lf.Model;
import org.lflang.util.ImportUtil;

/**
* Resource description strategy designed to limit global scope to only those files that were
Expand Down Expand Up @@ -77,7 +78,17 @@ public boolean createEObjectDescriptions(
*/
private void createEObjectDescriptionForModel(
Model model, IAcceptor<IEObjectDescription> acceptor) {
var uris = model.getImports().stream().map(uriResolver).collect(Collectors.joining(DELIMITER));
var uris =
model.getImports().stream()
.map(
importObj -> {
return (importObj.getImportURI() != null)
? importObj.getImportURI()
: ImportUtil.buildPackageURI(
importObj.getImportPackage(),
model.eResource()); // Use the resolved import string
})
.collect(Collectors.joining(DELIMITER));
var userData = Map.of(INCLUDES, uris);
QualifiedName qname = QualifiedName.create(model.eResource().getURI().toString());
acceptor.accept(EObjectDescription.create(qname, model, userData));
Expand Down
16 changes: 12 additions & 4 deletions core/src/main/java/org/lflang/LinguaFranca.xtext
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Model:
/**
* Import declaration.
*/
Import: 'import' reactorClasses+=ImportedReactor (',' reactorClasses+=ImportedReactor)* 'from' importURI=STRING ';'?;
Import: 'import' reactorClasses+=ImportedReactor (',' reactorClasses+=ImportedReactor)* 'from' (importURI=STRING | '<' importPackage=Path '>') ';'?;

ReactorDecl: Reactor | ImportedReactor;

Expand Down Expand Up @@ -392,8 +392,16 @@ SignedInt:
INT | NEGINT
;

Forever:
'forever'
;

Never:
'never'
;

Literal:
STRING | CHAR_LIT | SignedFloat | SignedInt | Boolean
STRING | CHAR_LIT | SignedFloat | SignedInt | Boolean | Forever | Never
;

Boolean:
Expand Down Expand Up @@ -478,7 +486,7 @@ Code:
;

FSName:
(ID | '.' | '_')+
(ID | '.' | '_' | '-')+
;
// Absolute or relative directory path in Windows, Linux, or MacOS.
Path:
Expand Down Expand Up @@ -521,7 +529,7 @@ Token:
'startup' | 'shutdown' | 'after' | 'deadline' | 'mutation' | 'preamble' |
'new' | 'federated' | 'at' | 'as' | 'from' | 'widthof' | 'const' | 'method' |
'interleaved' | 'mode' | 'initial' | 'reset' | 'history' | 'watchdog' |
'extends' |
'extends' | 'forever' | 'never' |

// Other terminals
NEGINT | TRUE | FALSE |
Expand Down
3 changes: 3 additions & 0 deletions core/src/main/java/org/lflang/TimeValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public final class TimeValue implements Comparable<TimeValue> {
/** The maximum value of this type. This is approximately equal to 292 years. */
public static final TimeValue MAX_VALUE = new TimeValue(Long.MAX_VALUE, TimeUnit.NANO);

/** The minimum value of this type. */
public static final TimeValue MIN_VALUE = new TimeValue(Long.MIN_VALUE, TimeUnit.NANO);

/** A time value equal to zero. */
public static final TimeValue ZERO = new TimeValue(0, null);

Expand Down
52 changes: 51 additions & 1 deletion core/src/main/java/org/lflang/ast/ASTUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ public static ReactorInstance createMainReactorInstance(
messageReporter
.nowhere()
.error("Main reactor has causality cycles. Skipping code generation.");
return null;
return main; // Avoid NPE.
}
// Inform the run-time of the breadth/parallelism of the reaction graph
var breadth = reactionInstanceGraph.getBreadth();
Expand Down Expand Up @@ -949,6 +949,26 @@ public static boolean isZero(String literal) {
return false;
}

/**
* Report whether the given literal is forever or not.
*
* @param literal AST node to inspect.
* @return True if the given literal denotes the constant {@code forever}, false otherwise.
*/
public static boolean isForever(String literal) {
return literal != null && literal.equals("forever");
}

/**
* Report whether the given literal is never or not.
*
* @param literal AST node to inspect.
* @return True if the given literal denotes the constant {@code never}, false otherwise.
*/
public static boolean isNever(String literal) {
return literal != null && literal.equals("never");
}

/**
* Report whether the given expression is zero or not.
*
Expand All @@ -962,6 +982,32 @@ public static boolean isZero(Expression expr) {
return false;
}

/**
* Report whether the given expression is forever or not.
*
* @param expr AST node to inspect.
* @return True if the given value denotes the constant {@code forever}, false otherwise.
*/
public static boolean isForever(Expression expr) {
if (expr instanceof Literal) {
return isForever(((Literal) expr).getLiteral());
}
return false;
}

/**
* Report whether the given expression is never or not.
*
* @param expr AST node to inspect.
* @return True if the given value denotes the constant {@code never}, false otherwise.
*/
public static boolean isNever(Expression expr) {
if (expr instanceof Literal) {
return isNever(((Literal) expr).getLiteral());
}
return false;
}

/**
* Report whether the given string literal is an integer number or not.
*
Expand Down Expand Up @@ -1142,6 +1188,10 @@ public static TimeValue getLiteralTimeValue(Expression expr) {
return toTimeValue((Time) expr);
} else if (expr instanceof Literal && isZero(((Literal) expr).getLiteral())) {
return TimeValue.ZERO;
} else if (expr instanceof Literal && isForever(((Literal) expr).getLiteral())) {
return TimeValue.MAX_VALUE;
} else if (expr instanceof Literal && isNever(((Literal) expr).getLiteral())) {
return TimeValue.MIN_VALUE;
} else {
return null;
}
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/org/lflang/ast/IsEqual.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public Boolean caseModel(Model object) {
public Boolean caseImport(Import object) {
return new ComparisonMachine<>(object, Import.class)
.equalAsObjects(Import::getImportURI)
.equalAsObjects(Import::getImportPackage)
.listsEquivalent(Import::getReactorClasses)
.conclusion;
}
Expand Down
8 changes: 5 additions & 3 deletions core/src/main/java/org/lflang/ast/ToLf.java
Original file line number Diff line number Diff line change
Expand Up @@ -400,9 +400,11 @@ public MalleableString caseImport(Import object) {
.append("import ")
// TODO: This is a place where we can use conditional parentheses.
.append(list(", ", "", "", false, true, true, object.getReactorClasses()))
.append(" from \"")
.append(object.getImportURI())
.append("\"")
.append(" from ")
.append(
object.getImportURI() != null
? "\"" + object.getImportURI() + "\""
: "<" + object.getImportPackage() + ">")
.get();
}

Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/org/lflang/ast/ToSExpr.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ public SExpr caseImport(Import object) {
// reactorClasses+=ImportedReactor)* 'from' importURI=STRING ';'?;
return sList(
"import",
new SAtom<>(object.getImportURI()),
new SAtom<>(
object.getImportURI() != null ? object.getImportURI() : object.getImportPackage()),
sList("reactors", object.getReactorClasses()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ protected void serializeAndSend(
result.pr(
"size_t _lf_message_length = "
+ sendRef
+ "->token->length * "
+ "->length * "
+ sendRef
+ "->token->type->element_size;");
result.pr(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.lflang.federated.generator;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;
Expand All @@ -9,6 +10,7 @@
import org.lflang.generator.CodeBuilder;
import org.lflang.lf.Import;
import org.lflang.lf.Model;
import org.lflang.util.ImportUtil;

/**
* Helper class to generate import statements for a federate.
Expand All @@ -31,7 +33,15 @@ String generateImports(FederateInstance federate, FederationFileConfig fileConfi
.forEach(
i -> {
visitedImports.add(i);
Path importPath = fileConfig.srcPath.resolve(i.getImportURI()).toAbsolutePath();
Path importPath =
fileConfig
.srcPath
.resolve(
i.getImportURI() != null
? Paths.get(i.getImportURI())
: ImportUtil.buildPackageURIfromSrc(
i.getImportPackage(), fileConfig.srcPath.toString()))
.toAbsolutePath();
i.setImportURI(
fileConfig.getSrcPath().relativize(importPath).toString().replace('\\', '/'));
});
Expand Down
11 changes: 3 additions & 8 deletions core/src/main/java/org/lflang/generator/GeneratorBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import org.lflang.lf.Mode;
import org.lflang.lf.Reaction;
import org.lflang.lf.Reactor;
import org.lflang.lf.VarRef;
import org.lflang.target.Target;
import org.lflang.target.TargetConfig;
import org.lflang.target.property.FilesProperty;
Expand Down Expand Up @@ -441,13 +442,7 @@ private void transformConflictingConnectionsInModalReactors(Set<Resource> resour
reaction.getEffects().add(destRef);

var code = factory.createCode();
var source =
(sourceRef.getContainer() != null ? sourceRef.getContainer().getName() + "." : "")
+ sourceRef.getVariable().getName();
var dest =
(destRef.getContainer() != null ? destRef.getContainer().getName() + "." : "")
+ destRef.getVariable().getName();
code.setBody(getConflictingConnectionsInModalReactorsBody(source, dest));
code.setBody(getConflictingConnectionsInModalReactorsBody(sourceRef, destRef));
reaction.setCode(code);

EcoreUtil.remove(connection);
Expand All @@ -464,7 +459,7 @@ private void transformConflictingConnectionsInModalReactors(Set<Resource> resour
* <p>This method needs to be overridden in target specific code generators that support modal
* reactors.
*/
protected String getConflictingConnectionsInModalReactorsBody(String source, String dest) {
protected String getConflictingConnectionsInModalReactorsBody(VarRef source, VarRef dest) {
messageReporter
.nowhere()
.error(
Expand Down
4 changes: 4 additions & 0 deletions core/src/main/java/org/lflang/generator/TargetTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ default String getTargetInitializer(Initializer init, Type type) {
default String getTargetExpr(Expression expr, InferredType type) {
if (ASTUtils.isZero(expr) && type != null && type.isTime) {
return getTargetTimeExpr(TimeValue.ZERO);
} else if (ASTUtils.isForever(expr) && type != null) {
return getTargetTimeExpr(TimeValue.MAX_VALUE);
} else if (ASTUtils.isNever(expr) && type != null) {
return getTargetTimeExpr(TimeValue.MIN_VALUE);
} else if (expr instanceof ParameterReference) {
return getTargetParamRef((ParameterReference) expr, type);
} else if (expr instanceof Time) {
Expand Down
Loading

0 comments on commit 58a6e93

Please sign in to comment.