use of org.abs_models.frontend.ast.CompilationUnit in project abstools by abstools.
the class TraitTest method addAddModifierAtRuntimeBackComp.
@Test
public void addAddModifierAtRuntimeBackComp() {
Model model = assertParse("module M;" + "class C { Unit m(){skip;} }");
ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
MethodSig sig = AbsASTBuilderUtil.createMethodSig("n", AbsASTBuilderUtil.getUnit());
MethodImpl impl = new MethodImpl(sig, new Block(new List<>(), new List<>(new SkipStmt())));
AddMethodModifier opr = new AddMethodModifier(impl);
assertNotNull(opr.getMethodImpl());
ModifyClassModifier mcn = new ModifyClassModifier();
mcn.setName("M.C");
DeltaAccess acc = new DeltaAccess(cls.getModuleDecl().getName());
DeltaDecl dd = new DeltaDecl();
dd.setName("MyDelta");
dd.setImportedModule(acc);
dd.addModuleModifier(mcn);
mcn.addModifier(opr);
mcn.setParent(dd);
acc.setParent(dd);
opr.setParent(mcn);
sig.setParent(opr);
CompilationUnit cu = model.getCompilationUnitList().getChild(0);
cu.addDeltaDecl(dd);
dd.setParent(cu);
model.applyDelta(dd);
assertEquals(2, cls.getMethods().getNumChild());
}
use of org.abs_models.frontend.ast.CompilationUnit in project abstools by abstools.
the class Main method parseUnit.
/**
* Parse the content of `reader` into a CompilationUnit.
*
* @param file The filename of the input stream, or null
* @param reader The stream to parse
* @param raiseExceptions Raise parse errors as exceptions if true
* @return The parsed content of `reader`, or an empty CompilationUnit with parse error information
* @throws IOException
*/
private static CompilationUnit parseUnit(File file, Reader reader) throws IOException {
try {
SyntaxErrorCollector errorlistener = new SyntaxErrorCollector(file);
ANTLRInputStream input = new ANTLRInputStream(reader);
ABSLexer lexer = new ABSLexer(input);
lexer.removeErrorListeners();
lexer.addErrorListener(errorlistener);
CommonTokenStream tokens = new CommonTokenStream(lexer);
ABSParser aparser = new ABSParser(tokens);
aparser.removeErrorListeners();
aparser.addErrorListener(errorlistener);
ParseTree tree = aparser.goal();
if (errorlistener.parserErrors.isEmpty()) {
ParseTreeWalker walker = new ParseTreeWalker();
CreateJastAddASTListener l = new CreateJastAddASTListener(file);
walker.walk(l, tree);
CompilationUnit u = new ASTPreProcessor().preprocess(l.getCompilationUnit());
return u;
} else {
String path = "<unknown path>";
if (file != null)
path = file.getPath();
CompilationUnit u = new CompilationUnit();
u.setName(path);
u.setParserErrors(errorlistener.parserErrors);
return u;
}
} finally {
reader.close();
}
}
use of org.abs_models.frontend.ast.CompilationUnit in project abstools by abstools.
the class ASTBasedABSTestRunnerGenerator method generateTestRunner.
@Override
public void generateTestRunner(PrintStream stream) {
// In order to safely call module.doPrettyPrint() we need a complete AST
Model model = new Model();
CompilationUnit compilationunit = new CompilationUnit();
ModuleDecl module = new ModuleDecl();
model.addCompilationUnitNoTransform(compilationunit);
compilationunit.addModuleDeclNoTransform(module);
module.setName(RUNNER_MAIN);
module.setImportList(generateImportsAST());
module.setBlock(generateMainBlockAST(module.getImportList()));
PrintWriter writer = new PrintWriter(stream, true);
ABSFormatter formatter = new DefaultABSFormatter(writer);
module.doPrettyPrint(writer, formatter);
}
use of org.abs_models.frontend.ast.CompilationUnit in project abstools by abstools.
the class DeadlockPreanalysis method analyzeModel.
/**
* Applies the deadlock preanalysis
*/
public void analyzeModel() {
try {
// CompilationUnit cu = model.getCompilationUnits().getChild(0);
for (CompilationUnit cu : model.getCompilationUnits()) {
computeInstructions(cu, 0);
if (cu.hasMainBlock()) {
System.out.println("Processing main block" + cu.getName());
computeInstructions(cu.getMainBlock(), 0);
}
}
System.out.println(getExpressions);
System.out.println(this);
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.abs_models.frontend.ast.CompilationUnit in project abstools by abstools.
the class Main method parseFiles.
private static Model parseFiles(boolean verbose, final java.util.List<File> fileNames) throws IOException, InternalBackendException {
if (fileNames.isEmpty()) {
throw new IllegalArgumentException("Please provide at least one input file");
}
java.util.List<CompilationUnit> units = new ArrayList<>();
for (File f : fileNames) {
if (!f.canRead()) {
throw new IllegalArgumentException("File " + f + " cannot be read");
}
if (!f.isDirectory() && !isABSSourceFile(f) && !isABSPackageFile(f)) {
throw new IllegalArgumentException("File " + f + " is not a legal ABS file");
}
}
for (File f : fileNames) {
parseFileOrDirectory(units, f, verbose);
}
units.add(getStdLib());
List<CompilationUnit> unitList = new List<>();
for (CompilationUnit u : units) {
unitList.add(u);
}
Model m = new Model(unitList);
return m;
}
Aggregations