-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for the load statement in the compiler (#76)
Porting the load statement from the previous compiler to the new architecture. - Exposing a "partial compilation chain" providing a list of actions out of a file name; - Load statements reified as a `LoadFile` action - When interpreting the action, triggering the partial chain to get actions, and then using the execution engine to enrich the already existing `Unit` - Recording already visited files to avoid loops or double loading.
- Loading branch information
Showing
12 changed files
with
200 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
compiler/src/main/java/ca/mcscert/jpipe/actions/LoadFile.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package ca.mcscert.jpipe.actions; | ||
|
||
import ca.mcscert.jpipe.compiler.CompilerFactory; | ||
import ca.mcscert.jpipe.compiler.model.Source; | ||
import ca.mcscert.jpipe.compiler.model.Transformation; | ||
import ca.mcscert.jpipe.compiler.steps.io.FileReader; | ||
import ca.mcscert.jpipe.error.SemanticError; | ||
import ca.mcscert.jpipe.model.Unit; | ||
import java.io.File; | ||
import java.io.InputStream; | ||
import java.nio.file.Path; | ||
import java.util.List; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
/** | ||
* Load a file referenced in another file. | ||
*/ | ||
public class LoadFile implements Action { | ||
|
||
private static final Logger logger = LogManager.getLogger(); | ||
|
||
private final String fileName; | ||
|
||
public LoadFile(String fileName) { | ||
this.fileName = fileName; | ||
} | ||
|
||
@Override | ||
public void execute(Unit context) throws Exception { | ||
Path p = new File(fileName).toPath().normalize(); | ||
canLoad(p, context); | ||
context.addLoadedFile(p); | ||
Transformation<InputStream, List<Action>> partial = CompilerFactory.actionProvider(); | ||
Source<InputStream> reader = new FileReader(); | ||
try (InputStream in = reader.provideFrom(p.toString())) { | ||
List<Action> actions = partial.fire(in, p.toString()); | ||
ExecutionEngine engine = new ExecutionEngine(); | ||
engine.enrich(context, actions); | ||
} | ||
} | ||
|
||
|
||
private void canLoad(Path p, Unit context) { | ||
|
||
if (context.isInScope(p)) { | ||
throw new SemanticError("Cannot load file " + p + " as it is already loaded"); | ||
} | ||
if (!p.toFile().exists()) { | ||
throw new SemanticError("Cannot load file " + p + " (file not found or not readable)"); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
load "simple.jd" | ||
|
||
justification prove_models2 { | ||
|
||
evidence Su1 is "Atomic Petri Nets are available" | ||
strategy St1 is "Merge atomic models" | ||
Su1 supports St1 | ||
|
||
sub-conclusion SC1 is "Complete model is merged" | ||
St1 supports SC1 | ||
|
||
evidence Su2 is "Prover is available" | ||
evidence Su3 is "Scenario are available as TINA artefacts" | ||
strategy St2 is "Prove model" | ||
Su2 supports St2 | ||
Su3 supports St2 | ||
SC1 supports St2 | ||
|
||
conclusion C is "Model is correct" | ||
St2 supports C | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters