Search in sources :

Example 6 with CompilationUnit

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));
                }
            }
        }
    }
}
Also used : CompilationUnit(org.abs_models.frontend.ast.CompilationUnit) Block(org.abs_models.frontend.ast.Block) ModuleDecl(org.abs_models.frontend.ast.ModuleDecl) SemanticWarning(org.abs_models.frontend.analyser.SemanticWarning)

Example 7 with CompilationUnit

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());
}
Also used : CompilationUnit(org.abs_models.frontend.ast.CompilationUnit) MethodSig(org.abs_models.frontend.ast.MethodSig) ClassDecl(org.abs_models.frontend.ast.ClassDecl) MethodImpl(org.abs_models.frontend.ast.MethodImpl) ModifyMethodModifier(org.abs_models.frontend.ast.ModifyMethodModifier) DeltaAccess(org.abs_models.frontend.ast.DeltaAccess) Model(org.abs_models.frontend.ast.Model) Block(org.abs_models.frontend.ast.Block) List(org.abs_models.frontend.ast.List) DeltaDecl(org.abs_models.frontend.ast.DeltaDecl) SkipStmt(org.abs_models.frontend.ast.SkipStmt) ModifyClassModifier(org.abs_models.frontend.ast.ModifyClassModifier) Test(org.junit.Test)

Example 8 with CompilationUnit

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);
}
Also used : CompilationUnit(org.abs_models.frontend.ast.CompilationUnit) DeltaDecl(org.abs_models.frontend.ast.DeltaDecl) FrontendTest(org.abs_models.frontend.FrontendTest) Test(org.junit.Test)

Example 9 with CompilationUnit

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());
}
Also used : CompilationUnit(org.abs_models.frontend.ast.CompilationUnit) MethodSig(org.abs_models.frontend.ast.MethodSig) RemoveMethodModifier(org.abs_models.frontend.ast.RemoveMethodModifier) ClassDecl(org.abs_models.frontend.ast.ClassDecl) DeltaAccess(org.abs_models.frontend.ast.DeltaAccess) Model(org.abs_models.frontend.ast.Model) List(org.abs_models.frontend.ast.List) DeltaDecl(org.abs_models.frontend.ast.DeltaDecl) ModifyClassModifier(org.abs_models.frontend.ast.ModifyClassModifier) Test(org.junit.Test)

Aggregations

CompilationUnit (org.abs_models.frontend.ast.CompilationUnit)9 Model (org.abs_models.frontend.ast.Model)5 DeltaDecl (org.abs_models.frontend.ast.DeltaDecl)4 List (org.abs_models.frontend.ast.List)4 Test (org.junit.Test)4 Block (org.abs_models.frontend.ast.Block)3 ClassDecl (org.abs_models.frontend.ast.ClassDecl)3 DeltaAccess (org.abs_models.frontend.ast.DeltaAccess)3 MethodSig (org.abs_models.frontend.ast.MethodSig)3 ModifyClassModifier (org.abs_models.frontend.ast.ModifyClassModifier)3 MethodImpl (org.abs_models.frontend.ast.MethodImpl)2 ModuleDecl (org.abs_models.frontend.ast.ModuleDecl)2 SkipStmt (org.abs_models.frontend.ast.SkipStmt)2 File (java.io.File)1 PrintWriter (java.io.PrintWriter)1 ArrayList (java.util.ArrayList)1 ABSFormatter (org.abs_models.backend.prettyprint.ABSFormatter)1 DefaultABSFormatter (org.abs_models.backend.prettyprint.DefaultABSFormatter)1 FrontendTest (org.abs_models.frontend.FrontendTest)1 SemanticConditionList (org.abs_models.frontend.analyser.SemanticConditionList)1