Skip to content

Commit b29081a

Browse files
authored
Run spotless on LFC and add check to CI (#201)
* Apply formatting with spotless * Check formatting of compiler in CI
1 parent dc632df commit b29081a

32 files changed

+965
-990
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@ jobs:
2828
# Uncomment to SSH into the runner.
2929
# - name: Setup upterm session
3030
# uses: lhotari/action-upterm@v1
31-
- name: Format check
31+
- name: Runtime format check
3232
run: |
3333
clang-format --version
3434
make format-check
35+
36+
- name: LFC format check
37+
run: cd lfc && ./gradlew spotlessCheck
3538

3639
- name: Run unit tests
3740
run: make unit-test

lfc/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ code-generate for `reactor-uc`. Since this is a subdirectory within reactor-uc
55
we are not copying reactor-uc into the src-gen directories but rather expecting
66
an environment variable REACTOR_UC_PATH to be defined.
77

8-
The goal is to eventually merge this upstream.
8+
The goal is to eventually merge this upstream.

lfc/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ plugins {
77
spotless {
88
format 'misc', {
99
target rootProject.fileTree(rootProject.rootDir) {
10-
include '**/*.gradle', '**/*.md', '.gitignore', '**/*.yml', '**/*.sh', '**/*.psi'
10+
include '**/*.gradle', '**/*.md', '.gitignore', '**/*.yml', '**/*.sh', '**/*.psi', '**/uc/**'
1111
exclude '**/reactor-cpp/**', '**/reactor-c/**', '**/reactor-rs/**', '**/lf-python-support/**',
1212
'**/src-gen/**', '**/fed-gen/**', '**/test-gen/**', '**/build/**',
1313
'test/*/include', 'test/*/bin/', 'test/*/share', 'test/*/lib'
@@ -41,4 +41,4 @@ assemble.dependsOn('installDist')
4141
// Alias tasks for simpler access
4242
tasks.register('runLfc', JavaExec) {
4343
dependsOn('cli:lfc:run')
44-
}
44+
}

lfc/cli/lfc/src/main/java/org/lflang/cli/Lfc.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,6 @@ public GeneratorArguments getArgs() {
357357
lint,
358358
quiet,
359359
getRtiUri(),
360-
List.of(
361-
new Argument<>(BuildTypeProperty.INSTANCE, getBuildType())));
360+
List.of(new Argument<>(BuildTypeProperty.INSTANCE, getBuildType())));
362361
}
363362
}

lfc/core/src/main/java/org/lflang/AttributeUtils.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
package org.lflang;
2727

2828
import static org.lflang.ast.ASTUtils.factory;
29-
import static org.lflang.ast.ASTUtils.toInteger;
3029

3130
import java.util.HashMap;
3231
import java.util.List;
@@ -116,11 +115,11 @@ public static List<Attribute> findAttributesByName(EObject node, String name) {
116115
public static List<Attribute> findAttributesByNameStartingWith(EObject node, String name) {
117116
List<Attribute> attrs = getAttributes(node);
118117
return attrs.stream()
119-
.filter(
120-
it ->
121-
it.getAttrName().contains(name)) // case-insensitive search (more user-friendly)
122-
.toList();
118+
.filter(
119+
it -> it.getAttrName().contains(name)) // case-insensitive search (more user-friendly)
120+
.toList();
123121
}
122+
124123
/**
125124
* Return the first argument specified for the attribute.
126125
*

lfc/core/src/main/java/org/lflang/ModelInfo.java

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@
3030

3131
import java.util.ArrayList;
3232
import java.util.HashSet;
33-
import java.util.LinkedHashSet;
34-
import java.util.LinkedList;
35-
import java.util.List;
3633
import java.util.Set;
3734
import org.lflang.ast.ASTUtils;
3835
import org.lflang.graph.InstantiationGraph;
@@ -82,7 +79,7 @@ public class ModelInfo {
8279
public Set<Parameter> overflowingParameters;
8380

8481
/** Cycles found during topology analysis. */
85-
// private Set<NamedInstance<?>> topologyCycles = new LinkedHashSet<NamedInstance<?>>();
82+
// private Set<NamedInstance<?>> topologyCycles = new LinkedHashSet<NamedInstance<?>>();
8683

8784
/** Whether or not the model information has been updated at least once. */
8885
public boolean updated;
@@ -97,31 +94,32 @@ public void update(Model model, MessageReporter reporter) {
9794
this.model = model;
9895
this.instantiationGraph = new InstantiationGraph(model, true);
9996

100-
// if (this.instantiationGraph.getCycles().size() == 0) {
101-
// List<ReactorInstance> topLevelReactorInstances = new LinkedList<>();
102-
// var main =
103-
// model.getReactors().stream().filter(it -> it.isMain() || it.isFederated()).findFirst();
104-
// if (main.isPresent()) {
105-
// var inst = new ReactorInstance(main.get(), reporter);
106-
// topLevelReactorInstances.add(inst);
107-
// } else {
108-
// model
109-
// .getReactors()
110-
// .forEach(it -> topLevelReactorInstances.add(new ReactorInstance(it, reporter)));
111-
// }
112-
// // don't store the graph into a field, only the cycles.
113-
// for (ReactorInstance top : topLevelReactorInstances) {
114-
// this.topologyCycles.addAll(top.getCycles());
115-
// }
116-
// }
97+
// if (this.instantiationGraph.getCycles().size() == 0) {
98+
// List<ReactorInstance> topLevelReactorInstances = new LinkedList<>();
99+
// var main =
100+
// model.getReactors().stream().filter(it -> it.isMain() ||
101+
// it.isFederated()).findFirst();
102+
// if (main.isPresent()) {
103+
// var inst = new ReactorInstance(main.get(), reporter);
104+
// topLevelReactorInstances.add(inst);
105+
// } else {
106+
// model
107+
// .getReactors()
108+
// .forEach(it -> topLevelReactorInstances.add(new ReactorInstance(it, reporter)));
109+
// }
110+
// // don't store the graph into a field, only the cycles.
111+
// for (ReactorInstance top : topLevelReactorInstances) {
112+
// this.topologyCycles.addAll(top.getCycles());
113+
// }
114+
// }
117115

118116
// may be null if the target is invalid
119117
var target = Target.forName(model.getTarget().getName()).orElse(null);
120118

121119
// Perform C-specific traversals.
122-
// if (target == Target.C) {
123-
// this.collectOverflowingNodes();
124-
// }
120+
// if (target == Target.C) {
121+
// this.collectOverflowingNodes();
122+
// }
125123

126124
checkCaseInsensitiveNameCollisions(model, reporter);
127125
}
@@ -151,9 +149,9 @@ private String getName(Reactor r) {
151149
: FileUtil.nameWithoutExtension(FileUtil.toPath(model.eResource().getURI()));
152150
}
153151

154-
// public Set<NamedInstance<?>> topologyCycles() {
155-
// return this.topologyCycles;
156-
// }
152+
// public Set<NamedInstance<?>> topologyCycles() {
153+
// return this.topologyCycles;
154+
// }
157155

158156
/**
159157
* Collect all assignments, deadlines, and parameters that can cause the time interval of a

lfc/core/src/main/java/org/lflang/ast/ASTUtils.java

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
import org.eclipse.xtext.xbase.lib.IteratorExtensions;
6060
import org.eclipse.xtext.xbase.lib.StringExtensions;
6161
import org.lflang.InferredType;
62-
import org.lflang.MessageReporter;
6362
import org.lflang.TimeUnit;
6463
import org.lflang.TimeValue;
6564
import org.lflang.generator.CodeMap;
@@ -99,7 +98,6 @@
9998
import org.lflang.lf.WidthSpec;
10099
import org.lflang.lf.WidthTerm;
101100
import org.lflang.target.Target;
102-
import org.lflang.target.TargetConfig;
103101
import org.lflang.util.StringUtil;
104102

105103
/**
@@ -511,14 +509,14 @@ public static List<Mode> allModes(Reactor definition) {
511509
return ASTUtils.collectElements(definition, featurePackage.getReactor_Modes());
512510
}
513511

514-
// public static List<ReactorInstance> recursiveChildren(ReactorInstance r) {
515-
// List<ReactorInstance> ret = new ArrayList<>();
516-
// ret.add(r);
517-
// for (var child : r.children) {
518-
// ret.addAll(recursiveChildren(child));
519-
// }
520-
// return ret;
521-
// }
512+
// public static List<ReactorInstance> recursiveChildren(ReactorInstance r) {
513+
// List<ReactorInstance> ret = new ArrayList<>();
514+
// ret.add(r);
515+
// for (var child : r.children) {
516+
// ret.addAll(recursiveChildren(child));
517+
// }
518+
// return ret;
519+
// }
522520

523521
/**
524522
* Return all the superclasses of the specified reactor in deepest-first order. For example, if A
@@ -606,37 +604,39 @@ public static <T extends EObject> List<T> collectElements(
606604
* This will also assign levels to reactions, then, if the program is federated, perform an AST
607605
* transformation to disconnect connections between federates.
608606
*/
609-
// public static ReactorInstance createMainReactorInstance(
610-
// Instantiation mainDef,
611-
// List<Reactor> reactors,
612-
// MessageReporter messageReporter,
613-
// TargetConfig targetConfig) {
614-
// if (mainDef != null) {
615-
// // Recursively build instances.
616-
// ReactorInstance main =
617-
// new ReactorInstance(toDefinition(mainDef.getReactorClass()), messageReporter, reactors);
618-
// var reactionInstanceGraph = main.assignLevels();
619-
// if (reactionInstanceGraph.nodeCount() > 0) {
620-
// messageReporter
621-
// .nowhere()
622-
// .error("Main reactor has causality cycles. Skipping code generation.");
623-
// return null;
624-
// }
625-
// // Inform the run-time of the breadth/parallelism of the reaction graph
626-
// var breadth = reactionInstanceGraph.getBreadth();
627-
// if (breadth == 0) {
628-
// messageReporter.nowhere().warning("The program has no reactions");
629-
// } else {
630-
// CompileDefinitionsProperty.INSTANCE.update(
631-
// targetConfig,
632-
// Map.of(
633-
// "LF_REACTION_GRAPH_BREADTH", String.valueOf(reactionInstanceGraph.getBreadth())));
634-
// }
635-
// return main;
636-
// }
637-
// return null;
638-
// }
639-
//
607+
// public static ReactorInstance createMainReactorInstance(
608+
// Instantiation mainDef,
609+
// List<Reactor> reactors,
610+
// MessageReporter messageReporter,
611+
// TargetConfig targetConfig) {
612+
// if (mainDef != null) {
613+
// // Recursively build instances.
614+
// ReactorInstance main =
615+
// new ReactorInstance(toDefinition(mainDef.getReactorClass()), messageReporter,
616+
// reactors);
617+
// var reactionInstanceGraph = main.assignLevels();
618+
// if (reactionInstanceGraph.nodeCount() > 0) {
619+
// messageReporter
620+
// .nowhere()
621+
// .error("Main reactor has causality cycles. Skipping code generation.");
622+
// return null;
623+
// }
624+
// // Inform the run-time of the breadth/parallelism of the reaction graph
625+
// var breadth = reactionInstanceGraph.getBreadth();
626+
// if (breadth == 0) {
627+
// messageReporter.nowhere().warning("The program has no reactions");
628+
// } else {
629+
// CompileDefinitionsProperty.INSTANCE.update(
630+
// targetConfig,
631+
// Map.of(
632+
// "LF_REACTION_GRAPH_BREADTH",
633+
// String.valueOf(reactionInstanceGraph.getBreadth())));
634+
// }
635+
// return main;
636+
// }
637+
// return null;
638+
// }
639+
//
640640
/**
641641
* Adds the elements into the given list at a location matching to their textual position.
642642
*
@@ -1657,9 +1657,9 @@ public static boolean isInCode(INode node) {
16571657
*
16581658
* @param instance The instance to check.
16591659
*/
1660-
// public static boolean isTopLevel(NamedInstance instance) {
1661-
// return instance.getParent() == null;
1662-
// }
1660+
// public static boolean isTopLevel(NamedInstance instance) {
1661+
// return instance.getParent() == null;
1662+
// }
16631663

16641664
/** Return true if the given node starts on the same line as the given other node. */
16651665
public static Predicate<INode> sameLine(ICompositeNode compNode) {

lfc/core/src/main/java/org/lflang/generator/GeneratorBase.java

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -26,45 +26,32 @@
2626

2727
import com.google.common.base.Objects;
2828
import com.google.common.collect.Iterables;
29-
import com.google.common.collect.Iterators;
30-
3129
import java.io.IOException;
3230
import java.nio.file.Path;
3331
import java.nio.file.Paths;
3432
import java.util.ArrayList;
3533
import java.util.LinkedHashMap;
3634
import java.util.List;
3735
import java.util.Map;
38-
import java.util.Optional;
3936
import java.util.Set;
40-
import java.util.stream.Collectors;
4137
import org.eclipse.core.resources.IMarker;
4238
import org.eclipse.emf.ecore.EObject;
4339
import org.eclipse.emf.ecore.resource.Resource;
44-
import org.eclipse.emf.ecore.util.EcoreUtil;
4540
import org.eclipse.lsp4j.DiagnosticSeverity;
4641
import org.eclipse.xtext.xbase.lib.IterableExtensions;
4742
import org.eclipse.xtext.xbase.lib.IteratorExtensions;
48-
import org.eclipse.xtext.xbase.lib.StringExtensions;
49-
50-
import org.lflang.AttributeUtils;
51-
import org.lflang.FileConfig;
5243
import org.lflang.MainConflictChecker;
5344
import org.lflang.MessageReporter;
54-
//import org.lflang.ast.ASTUtils;
45+
// import org.lflang.ast.ASTUtils;
5546
import org.lflang.ast.ASTUtils;
5647
import org.lflang.ast.AstTransformation;
5748
import org.lflang.graph.InstantiationGraph;
58-
import org.lflang.lf.Attribute;
59-
import org.lflang.lf.Connection;
6049
import org.lflang.lf.Instantiation;
6150
import org.lflang.lf.LfFactory;
62-
import org.lflang.lf.Mode;
6351
import org.lflang.lf.Reaction;
6452
import org.lflang.lf.Reactor;
6553
import org.lflang.target.Target;
6654
import org.lflang.target.TargetConfig;
67-
import org.lflang.util.FileUtil;
6855
import org.lflang.validation.AbstractLFValidator;
6956

7057
/**
@@ -79,7 +66,7 @@
7966
public abstract class GeneratorBase extends AbstractLFValidator {
8067

8168
/** The main (top-level) reactor instance. */
82-
// public ReactorInstance main;
69+
// public ReactorInstance main;
8370

8471
/** An error reporter for reporting any errors or warnings during the code generation */
8572
public MessageReporter messageReporter;
@@ -226,33 +213,33 @@ public void doGenerate(Resource resource, LFGeneratorContext context) {
226213

227214
Set<Resource> allResources = GeneratorUtils.getResources(reactors);
228215

229-
// GeneratorUtils.accommodatePhysicalActionsIfPresent(
230-
// allResources,
231-
// getTarget().setsKeepAliveOptionAutomatically(),
232-
// targetConfig,
233-
// messageReporter);
216+
// GeneratorUtils.accommodatePhysicalActionsIfPresent(
217+
// allResources,
218+
// getTarget().setsKeepAliveOptionAutomatically(),
219+
// targetConfig,
220+
// messageReporter);
234221

235222
// Load target properties for all resources.
236223
allResources.forEach(r -> loadTargetProperties(r));
237224

238-
// for (AstTransformation transformation : astTransformations) {
239-
// transformation.applyTransformation(reactors);
240-
// }
225+
// for (AstTransformation transformation : astTransformations) {
226+
// transformation.applyTransformation(reactors);
227+
// }
241228

242229
// Transform connections that reside in mutually exclusive modes and are otherwise conflicting
243230
// This should be done before creating the instantiation graph
244-
// transformConflictingConnectionsInModalReactors(allResources);
231+
// transformConflictingConnectionsInModalReactors(allResources);
245232

246233
// Invoke these functions a second time because transformations
247234
// may have introduced new reactors!
248235
setReactorsAndInstantiationGraph(context.getMode());
249236

250237
// Check for existence and support of modes
251-
// hasModalReactors = IterableExtensions.exists(reactors, it -> !it.getModes().isEmpty());
252-
// checkModalReactorSupport(false);
238+
// hasModalReactors = IterableExtensions.exists(reactors, it -> !it.getModes().isEmpty());
239+
// checkModalReactorSupport(false);
253240

254241
// Check for the existence and support of watchdogs
255-
// hasWatchdogs = IterableExtensions.exists(reactors, it -> !it.getWatchdogs().isEmpty());
242+
// hasWatchdogs = IterableExtensions.exists(reactors, it -> !it.getWatchdogs().isEmpty());
256243
}
257244

258245
/**

lfc/core/src/main/java/org/lflang/generator/GeneratorUtils.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,10 @@
1010
import org.eclipse.xtext.xbase.lib.IteratorExtensions;
1111
import org.lflang.MessageReporter;
1212
import org.lflang.generator.LFGeneratorContext.Mode;
13-
import org.lflang.lf.Action;
14-
import org.lflang.lf.ActionOrigin;
1513
import org.lflang.lf.ImportedReactor;
1614
import org.lflang.lf.Instantiation;
1715
import org.lflang.lf.Reactor;
1816
import org.lflang.lf.TargetDecl;
19-
import org.lflang.target.TargetConfig;
2017

2118
/**
2219
* A helper class with functions that may be useful for code generators. This is created to ease our

0 commit comments

Comments
 (0)