Skip to content

Commit

Permalink
Factored out code generation for each federate
Browse files Browse the repository at this point in the history
  • Loading branch information
Soroosh129 authored and petervdonovan committed Jun 13, 2022
1 parent 2fbd047 commit 90d719e
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions org.lflang/src/org/lflang/federated/FedGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,28 @@ public FedGenerator(FedFileConfig fileConfig, ErrorReporter errorReporter) {
public boolean doGenerate(Resource resource, LFGeneratorContext context) throws IOException {
Reactor fedReactor = FedASTUtils.findFederatedReactor(resource);
for (Instantiation fedInstantiation : fedReactor.getInstantiations()) {
System.out.println("Generating code for federate " + fedInstantiation.getName() + " in directory "
+ fileConfig.getFedSrcPath());
Files.createDirectories(fileConfig.getFedSrcPath());

Path lfFilePath = fileConfig.getFedSrcPath().resolve(fedInstantiation.getName() + ".lf");
try (var srcWriter = Files.newBufferedWriter(lfFilePath)) {
srcWriter.write(NodeModelUtils.getNode(fedReactor.eContainer()).getText());
}

generateFederate(fedInstantiation);
}
return false;
}

// private void generateFederate();
/**
* Generate a .lf file for federate {@code fed}.
* @param fed
* @throws IOException
*/
private void generateFederate(Instantiation fed) throws IOException {
System.out.println("##### Generating code for federate " + fed.getName() + " in directory "
+ fileConfig.getFedSrcPath());
Files.createDirectories(fileConfig.getFedSrcPath());

Path lfFilePath = fileConfig.getFedSrcPath().resolve(fed.getName() + ".lf");

// FIXME: Do magic...

try (var srcWriter = Files.newBufferedWriter(lfFilePath)) {
srcWriter.write(NodeModelUtils.getNode(fed.eContainer()).getText());
}

}
}

0 comments on commit 90d719e

Please sign in to comment.