use of org.abs_models.frontend.ast.CompilationUnit in project abstools by abstools.
the class MainBlockChecker method checkModel.
@Override
public void checkModel(Model model) {
int nMainBlocks = 0;
for (CompilationUnit u : model.getCompilationUnits()) {
for (ModuleDecl m : u.getModuleDecls()) {
if (m.hasBlock()) {
nMainBlocks = nMainBlocks + 1;
}
}
}
if (nMainBlocks == 0) {
CompilationUnit c = model.getCompilationUnit(0);
errors.add(new SemanticWarning(c, ErrorMessage.MAIN_BLOCK_NOT_FOUND, "dummy string to keep constructor happy"));
} else if (nMainBlocks > 1) {
Block b = model.getMainBlock();
String moduleName = ((ModuleDecl) (b.getParent().getParent())).getName();
for (CompilationUnit u : model.getCompilationUnits()) {
for (ModuleDecl m : u.getModuleDecls()) {
if (m.hasBlock() && m.getBlock() != b) {
errors.add(new SemanticWarning(m.getBlock(), ErrorMessage.MAIN_BLOCK_AMBIGUOUS, moduleName));
}
}
}
}
}
use of org.abs_models.frontend.ast.CompilationUnit in project abstools by abstools.
the class TraitTest method addModifyModifierAtRuntimeBackComp.
@Test
public void addModifyModifierAtRuntimeBackComp() {
Model model = assertParse("module M;" + "class C { Unit m(){skip;} }");
ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
MethodSig sig = AbsASTBuilderUtil.createMethodSig("m", AbsASTBuilderUtil.getUnit());
MethodImpl impl = new MethodImpl(sig, new Block(new List<>(), new List<>(new SkipStmt(), new SkipStmt())));
ModifyMethodModifier opr = new ModifyMethodModifier(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(1, cls.getMethods().getNumChild());
assertEquals(2, cls.getMethod(0).getBlock().getNumChild());
}
use of org.abs_models.frontend.ast.CompilationUnit in project abstools by abstools.
the class ParserTest method entry_deltadecl.
@Test
public void entry_deltadecl() throws Exception {
CompilationUnit u = parseString("delta Mon;").getCompilationUnit(1);
DeltaDecl d = (DeltaDecl) u.getDeltaDecl(0);
Assert.assertNotNull(d);
}
use of org.abs_models.frontend.ast.CompilationUnit in project abstools by abstools.
the class TraitTest method addRemoveModifierAtRuntime.
@Test
public void addRemoveModifierAtRuntime() {
Model model = assertParse("module M;" + "class C { Unit m(){skip;} }");
ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
MethodSig sig = AbsASTBuilderUtil.createMethodSig("m", AbsASTBuilderUtil.getUnit());
List<MethodSig> l = new List<>(sig);
RemoveMethodModifier opr = new RemoveMethodModifier(l);
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(0, cls.getMethods().getNumChild());
}
Aggregations