Skip to content

Commit

Permalink
Merge branch 'master' into enclaves2
Browse files Browse the repository at this point in the history
  • Loading branch information
erlingrj authored Sep 26, 2023
2 parents c0ee111 + 93aef01 commit 28e4fe7
Show file tree
Hide file tree
Showing 24 changed files with 166 additions and 46 deletions.
15 changes: 15 additions & 0 deletions .github/actions/prepare-build-env/action.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
name: Set up build environment
description: Set up Java and Gradle (including caching).

inputs:
lingua-franca-dir:
description: 'Path to the lingua-franca directory'
required: false

runs:
using: "composite"
steps:
Expand All @@ -11,3 +17,12 @@ runs:
uses: gradle/[email protected]
with:
cache-read-only: false
- name: Download Gradle and print version
working-directory: ${{ inputs.lingua-franca-dir }}
run: |
# Retry 3 times before the steps actually fails
(echo "==== Gradle Download Attempt: 1 ====" && ./gradlew --version) || \
(sleep 30 && echo "==== Gradle Download Attempt: 2 ====" && ./gradlew --version) || \
(sleep 30 && echo "==== Gradle Download Attempt: 3 ====" && ./gradlew --version) || \
(echo "==== Gradle Download Failed ====" && exit 1)
shell: bash
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ jobs:
uses: lf-lang/epoch/.github/workflows/build.yml@main
with:
lingua-franca-ref: ${{ github.head_ref || github.ref_name }}
lingua-franca-repo: ${{ github.event.pull_request.head.repo.full_name }}
upload-artifacts: false
2 changes: 1 addition & 1 deletion buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
implementation "com.diffplug.spotless:spotless-plugin-gradle:$spotlessVersion"

implementation "gradle.plugin.com.github.johnrengelman:shadow:$shadowJarVersion"
implementation "com.github.johnrengelman:shadow:$shadowJarVersion"
}
8 changes: 4 additions & 4 deletions buildSrc/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[versions]
spotlessVersion=6.11.0
spotlessVersion=6.21.0
spotlessLibVersion=2.30.0
kotlinVersion=1.6.21
shadowJarVersion=7.1.2
spotbugsPluginVersion=5.1.3
kotlinVersion=1.9.0
shadowJarVersion=8.1.1
spotbugsPluginVersion=5.1.3
3 changes: 0 additions & 3 deletions core/src/main/java/org/lflang/AttributeUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,6 @@ public static Attribute findAttributeByName(EObject node, String name) {
*/
public static List<Attribute> findAttributesByName(EObject node, String name) {
List<Attribute> attrs = getAttributes(node);
if (!attrs.isEmpty()) {
System.out.println("Fun");
}
return attrs.stream()
.filter(
it ->
Expand Down
8 changes: 8 additions & 0 deletions core/src/main/java/org/lflang/LinguaFranca.xtext
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ Expression:
| ParameterReference
| {CodeExpr} code=Code
| BracedListExpression
| BracketListExpression
;

// A list of expressions within braces.
Expand All @@ -328,6 +329,13 @@ BracedListExpression:
'{' {BracedListExpression} (items+=Expression (',' items+=Expression)*)? ','? '}'
;

// A list of expressions within square brackets.
// In Python and TS, this is a list literal. In Rust this could be an array but Rust
// array expressions are relatively rare so probably not worth supporting.
BracketListExpression:
'[' {BracketListExpression} (items+=Expression (',' items+=Expression)*)? ','? ']'
;

ParameterReference:
parameter=[Parameter]
;
Expand Down
5 changes: 5 additions & 0 deletions core/src/main/java/org/lflang/Target.java
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,11 @@ public boolean allowsBracedListExpressions() {
return this == C || this == CCPP || this == CPP;
}

/** Allow expressions of the form {@code [a, b, c]}. */
public boolean allowsBracketListExpressions() {
return this == Python || this == TS || this == Rust;
}

/** Return a string that demarcates the beginning of a single-line comment. */
public String getSingleLineCommentPrefix() {
return this.equals(Target.Python) ? "#" : "//";
Expand Down
8 changes: 8 additions & 0 deletions core/src/main/java/org/lflang/ast/IsEqual.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.lflang.lf.AttrParm;
import org.lflang.lf.Attribute;
import org.lflang.lf.BracedListExpression;
import org.lflang.lf.BracketListExpression;
import org.lflang.lf.BuiltinTriggerRef;
import org.lflang.lf.Code;
import org.lflang.lf.CodeExpr;
Expand Down Expand Up @@ -465,6 +466,13 @@ public Boolean caseBracedListExpression(BracedListExpression object) {
.conclusion;
}

@Override
public Boolean caseBracketListExpression(BracketListExpression object) {
return new ComparisonMachine<>(object, BracketListExpression.class)
.listsEquivalent(BracketListExpression::getItems)
.conclusion;
}

@Override
public Boolean caseParameterReference(ParameterReference object) {
return new ComparisonMachine<>(object, ParameterReference.class)
Expand Down
9 changes: 9 additions & 0 deletions core/src/main/java/org/lflang/ast/ToLf.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.lflang.lf.AttrParm;
import org.lflang.lf.Attribute;
import org.lflang.lf.BracedListExpression;
import org.lflang.lf.BracketListExpression;
import org.lflang.lf.BuiltinTriggerRef;
import org.lflang.lf.Code;
import org.lflang.lf.CodeExpr;
Expand Down Expand Up @@ -873,6 +874,14 @@ public MalleableString caseBracedListExpression(BracedListExpression object) {
return bracedListExpression(object.getItems());
}

@Override
public MalleableString caseBracketListExpression(BracketListExpression object) {
if (object.getItems().isEmpty()) {
return MalleableString.anyOf("[]");
}
return list(", ", "[", "]", false, false, true, object.getItems());
}

/**
* Represent a braced list expression. Do not invoke on expressions that may have comments
* attached.
Expand Down
6 changes: 6 additions & 0 deletions core/src/main/java/org/lflang/ast/ToText.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
import org.lflang.lf.ArraySpec;
import org.lflang.lf.BracedListExpression;
import org.lflang.lf.BracketListExpression;
import org.lflang.lf.Code;
import org.lflang.lf.CodeExpr;
import org.lflang.lf.Host;
Expand Down Expand Up @@ -80,6 +81,11 @@ public String caseBracedListExpression(BracedListExpression object) {
return new ToLf().caseBracedListExpression(object).toString();
}

@Override
public String caseBracketListExpression(BracketListExpression object) {
return new ToLf().caseBracketListExpression(object).toString();
}

@Override
public String caseHost(Host host) {
return new ToLf().caseHost(host).toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,6 @@ public class LinguaFrancaSynthesis extends AbstractDiagramSynthesis<Model> {
SynthesisOption.createCheckOption("Multiport Widths", false).setCategory(APPEARANCE);
public static final SynthesisOption SHOW_REACTION_CODE =
SynthesisOption.createCheckOption("Reaction Code", false).setCategory(APPEARANCE);
public static final SynthesisOption SHOW_REACTION_LEVEL =
SynthesisOption.createCheckOption("Reaction Level", false).setCategory(APPEARANCE);
public static final SynthesisOption SHOW_REACTION_ORDER_EDGES =
SynthesisOption.createCheckOption("Reaction Order Edges", false).setCategory(APPEARANCE);
public static final SynthesisOption SHOW_REACTOR_HOST =
Expand All @@ -257,6 +255,9 @@ public class LinguaFrancaSynthesis extends AbstractDiagramSynthesis<Model> {
SynthesisOption.<Integer>createRangeOption("Reactor Parameter/Variable Columns", 1, 10, 1)
.setCategory(APPEARANCE);

public static final SynthesisOption DEFAULT_EXPAND_ALL =
SynthesisOption.createCheckOption("Expand reactors by default", false);

public static final SynthesisOption FIXED_PORT_SIDE =
SynthesisOption.createCheckOption("Fixed Port Sides", true).setCategory(LAYOUT);
public static final SynthesisOption SPACING =
Expand All @@ -273,6 +274,7 @@ public class LinguaFrancaSynthesis extends AbstractDiagramSynthesis<Model> {
public List<SynthesisOption> getDisplayedSynthesisOptions() {
return List.of(
SHOW_ALL_REACTORS,
DEFAULT_EXPAND_ALL,
MemorizingExpandCollapseAction.MEMORIZE_EXPANSION_STATES,
CYCLE_DETECTION,
APPEARANCE,
Expand All @@ -287,7 +289,6 @@ public List<SynthesisOption> getDisplayedSynthesisOptions() {
SHOW_PORT_NAMES,
SHOW_MULTIPORT_WIDTH,
SHOW_REACTION_CODE,
SHOW_REACTION_LEVEL,
SHOW_REACTION_ORDER_EDGES,
SHOW_REACTOR_HOST,
SHOW_INSTANCE_NAMES,
Expand Down Expand Up @@ -1019,18 +1020,16 @@ private Collection<KNode> transformReactorNetwork(
TriggerInstance<?> reset = null;

// Transform instances
int index = 0;
for (ReactorInstance child : reactorInstance.children) {
Boolean expansionState = MemorizingExpandCollapseAction.getExpansionState(child);
Collection<KNode> rNodes =
createReactorNode(
child,
expansionState != null ? expansionState : false,
expansionState != null ? expansionState : getBooleanValue(DEFAULT_EXPAND_ALL),
inputPorts,
outputPorts,
allReactorNodes);
nodes.addAll(rNodes);
index++;
}

// Create timers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
import org.eclipse.elk.graph.properties.Property;
import org.eclipse.xtext.xbase.lib.Extension;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.Pair;
import org.eclipse.xtext.xbase.lib.StringExtensions;
import org.lflang.ast.ASTUtils;
Expand Down Expand Up @@ -424,26 +423,10 @@ public KPolygon addReactionFigure(KNode node, ReactionInstance reaction) {
DiagramSyntheses.suppressSelectability(textToAdd);
}

// optional reaction level
if (getBooleanValue(LinguaFrancaSynthesis.SHOW_REACTION_LEVEL)) {
// Force calculation of levels for reactions. This calculation
// will only be done once. Note that if this fails due to a causality loop,
// then some reactions will have level -1.
try {
String levels = IterableExtensions.join(reaction.getLevels(), ", ");
KText levelsText =
_kContainerRenderingExtensions.addText(contentContainer, ("level: " + levels));
_kRenderingExtensions.setFontBold(levelsText, false);
_linguaFrancaStyleExtensions.noSelectionStyle(levelsText);
DiagramSyntheses.suppressSelectability(levelsText);
} catch (Exception ex) {
// If the graph has cycles, the above fails. Continue without showing levels.
}
}

// optional code content
boolean hasCode =
getBooleanValue(LinguaFrancaSynthesis.SHOW_REACTION_CODE)
&& reaction.getDefinition().getCode() != null
&& !StringExtensions.isNullOrEmpty(reaction.getDefinition().getCode().getBody());
if (hasCode) {
KText hasCodeText =
Expand Down
19 changes: 19 additions & 0 deletions core/src/main/java/org/lflang/generator/LfExpressionVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package org.lflang.generator;

import org.lflang.lf.BracedListExpression;
import org.lflang.lf.BracketListExpression;
import org.lflang.lf.Code;
import org.lflang.lf.CodeExpr;
import org.lflang.lf.Expression;
Expand All @@ -44,6 +45,8 @@ public interface LfExpressionVisitor<P, R> {

R visitBracedListExpr(BracedListExpression expr, P param);

R visitBracketListExpr(BracketListExpression expr, P param);

R visitTimeLiteral(Time expr, P param);

R visitCodeExpr(CodeExpr expr, P param);
Expand All @@ -66,6 +69,8 @@ static <P, R> R dispatch(
return visitor.visitLiteral((Literal) e, arg);
} else if (e instanceof BracedListExpression) {
return visitor.visitBracedListExpr((BracedListExpression) e, arg);
} else if (e instanceof BracketListExpression) {
return visitor.visitBracketListExpr((BracketListExpression) e, arg);
} else if (e instanceof Time) {
return visitor.visitTimeLiteral((Time) e, arg);
} else if (e instanceof CodeExpr) {
Expand Down Expand Up @@ -106,6 +111,11 @@ public R visitCodeExpr(CodeExpr expr, P param) {
public R visitParameterRef(ParameterReference expr, P param) {
return visitExpression(expr, param);
}

@Override
public R visitBracketListExpr(BracketListExpression expr, P param) {
return visitExpression(expr, param);
}
}

/**
Expand Down Expand Up @@ -147,6 +157,15 @@ public Expression visitParameterRef(ParameterReference expr, P param) {
return clone;
}

@Override
public Expression visitBracketListExpr(BracketListExpression expr, P param) {
BracketListExpression clone = LfFactory.eINSTANCE.createBracketListExpression();
for (Expression item : expr.getItems()) {
clone.getItems().add(dispatch(item, param, this));
}
return clone;
}

@Override
public Expression visitCodeExpr(CodeExpr expr, P param) {
CodeExpr codeExpr = LfFactory.eINSTANCE.createCodeExpr();
Expand Down
11 changes: 11 additions & 0 deletions core/src/main/java/org/lflang/generator/TargetTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.lflang.ast.ASTUtils;
import org.lflang.lf.Action;
import org.lflang.lf.BracedListExpression;
import org.lflang.lf.BracketListExpression;
import org.lflang.lf.CodeExpr;
import org.lflang.lf.Expression;
import org.lflang.lf.Initializer;
Expand Down Expand Up @@ -60,6 +61,14 @@ default String getTargetBracedListExpr(BracedListExpression expr, InferredType t
.collect(Collectors.joining(",", "{", "}"));
}

/** Translate the bracket list expression into target language syntax. */
default String getTargetBracketListExpr(BracketListExpression expr, InferredType typeOrNull) {
InferredType t = typeOrNull == null ? InferredType.undefined() : typeOrNull;
return expr.getItems().stream()
.map(e -> getTargetExpr(e, t))
.collect(Collectors.joining(", ", "[", "]"));
}

/** Return an "unknown" type which is used as a default when a type cannot be inferred. */
String getTargetUndefinedType();

Expand Down Expand Up @@ -224,6 +233,8 @@ default String getTargetExpr(Expression expr, InferredType type) {
return ASTUtils.toText(((CodeExpr) expr).getCode());
} else if (expr instanceof BracedListExpression) {
return getTargetBracedListExpr((BracedListExpression) expr, type);
} else if (expr instanceof BracketListExpression) {
return getTargetBracketListExpr((BracketListExpression) expr, type);
} else {
throw new IllegalStateException("Invalid value " + expr);
}
Expand Down
10 changes: 10 additions & 0 deletions core/src/main/java/org/lflang/validation/LFValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
import org.lflang.lf.Assignment;
import org.lflang.lf.Attribute;
import org.lflang.lf.BracedListExpression;
import org.lflang.lf.BracketListExpression;
import org.lflang.lf.BuiltinTrigger;
import org.lflang.lf.BuiltinTriggerRef;
import org.lflang.lf.Connection;
Expand Down Expand Up @@ -194,6 +195,15 @@ public void checkBracedExpression(BracedListExpression expr) {
}
}

@Check(CheckType.FAST)
public void checkBracketExpression(BracketListExpression expr) {
if (!target.allowsBracketListExpressions()) {
var message =
"Bracketed expression lists are not a valid expression for the " + target + " target.";
error(message, Literals.BRACKET_LIST_EXPRESSION.eContainmentFeature());
}
}

@Check(CheckType.FAST)
public void checkAssignment(Assignment assignment) {

Expand Down
14 changes: 10 additions & 4 deletions core/src/testFixtures/java/org/lflang/tests/LFTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ public class LFTest implements Comparable<LFTest> {
/** String builder for collecting issues encountered during test execution. */
private final StringBuilder issues = new StringBuilder();

/** Reference to System.out for restoring the default output. */
private static final PrintStream out = System.out;

/** Reference to System.err for restoring the default output. */
private static final PrintStream err = System.err;

private long executionTimeNanoseconds;

/**
Expand Down Expand Up @@ -71,11 +77,11 @@ public void redirectOutputs() {
}

/** End output redirection. */
public void restoreOutputs() {
public static void restoreOutputs() {
System.out.flush();
System.err.flush();
System.setOut(System.out);
System.setErr(System.err);
System.setOut(out);
System.setErr(err);
}

/**
Expand Down Expand Up @@ -130,7 +136,7 @@ public boolean hasPassed() {
return result == Result.TEST_PASS;
}

/** Compile a string that contains all collected errors and return it. */
/** Print a report of all the collected errors. */
public void reportErrors() {
if (this.hasFailed()) {
System.out.println(
Expand Down
Loading

0 comments on commit 28e4fe7

Please sign in to comment.