Search in sources :

Example 6 with ModuleDecl

use of org.abs_models.frontend.ast.ModuleDecl 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);
}
Also used : CompilationUnit(org.abs_models.frontend.ast.CompilationUnit) DefaultABSFormatter(org.abs_models.backend.prettyprint.DefaultABSFormatter) ABSFormatter(org.abs_models.backend.prettyprint.ABSFormatter) DefaultABSFormatter(org.abs_models.backend.prettyprint.DefaultABSFormatter) Model(org.abs_models.frontend.ast.Model) ModuleDecl(org.abs_models.frontend.ast.ModuleDecl) PrintWriter(java.io.PrintWriter)

Example 7 with ModuleDecl

use of org.abs_models.frontend.ast.ModuleDecl 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 8 with ModuleDecl

use of org.abs_models.frontend.ast.ModuleDecl in project abstools by abstools.

the class TypeCheckerTest method classParamsMethodShadowsField.

@Test
public void classParamsMethodShadowsField() {
    Model m = assertParse("class C(Bool b) { Bool m(Bool b) { return b; } }");
    ModuleDecl u = m.lookupModule("UnitTest");
    ClassDecl c = (ClassDecl) u.lookup(new KindedName(KindedName.Kind.CLASS, "C"));
    MethodImpl me = c.lookupMethod("m");
    ReturnStmt r = (ReturnStmt) me.getBlock().getStmt(0);
    VarOrFieldUse vu = (VarOrFieldUse) r.getRetExp();
    ParamDecl d = (ParamDecl) vu.getDecl();
    assertThat(d.getParent().getParent(), instanceOf(MethodSig.class));
    assertThat(vu.getClass().getName(), vu, instanceOf(VarUse.class));
}
Also used : MethodSig(org.abs_models.frontend.ast.MethodSig) ClassDecl(org.abs_models.frontend.ast.ClassDecl) MethodImpl(org.abs_models.frontend.ast.MethodImpl) ParamDecl(org.abs_models.frontend.ast.ParamDecl) Model(org.abs_models.frontend.ast.Model) ModuleDecl(org.abs_models.frontend.ast.ModuleDecl) KindedName(org.abs_models.frontend.typechecker.KindedName) VarUse(org.abs_models.frontend.ast.VarUse) ReturnStmt(org.abs_models.frontend.ast.ReturnStmt) VarOrFieldUse(org.abs_models.frontend.ast.VarOrFieldUse) ABSTest(org.abs_models.ABSTest) FrontendTest(org.abs_models.frontend.FrontendTest) Test(org.junit.Test)

Example 9 with ModuleDecl

use of org.abs_models.frontend.ast.ModuleDecl in project abstools by abstools.

the class TypeCheckerTest method methodSigs.

@Test
public void methodSigs() {
    Model m = assertParse("interface I { Unit m(); } interface J { Unit n(); } interface K extends I, J { Unit foo(); } { K k; } ");
    ModuleDecl module = m.lookupModule("UnitTest");
    InterfaceDecl d = (InterfaceDecl) module.getDecl(2);
    ArrayList<MethodSig> list = new ArrayList<>(d.getAllMethodSigs());
    assertEquals(list.toString(), 3, list.size());
    VarDeclStmt stmt = (VarDeclStmt) module.getBlock().getStmt(0);
    Collection<MethodSig> sigs = stmt.getVarDecl().getTypeUse().getType().getAllMethodSigs();
    assertArrayEquals(sigs.toArray(), d.getAllMethodSigs().toArray());
}
Also used : MethodSig(org.abs_models.frontend.ast.MethodSig) VarDeclStmt(org.abs_models.frontend.ast.VarDeclStmt) Model(org.abs_models.frontend.ast.Model) ArrayList(java.util.ArrayList) ModuleDecl(org.abs_models.frontend.ast.ModuleDecl) InterfaceDecl(org.abs_models.frontend.ast.InterfaceDecl) ABSTest(org.abs_models.ABSTest) FrontendTest(org.abs_models.frontend.FrontendTest) Test(org.junit.Test)

Example 10 with ModuleDecl

use of org.abs_models.frontend.ast.ModuleDecl in project abstools by abstools.

the class ParFnAppTest method sameAnonTwiceTwoExpansions.

@Test
public void sameAnonTwiceTwoExpansions() {
    Model m = testExpand(parse("apply((Int i) => i)(1);" + "apply((Int i) => i)(1);", applyFunction()));
    ModuleDecl module = m.lookupModule("UnitTest");
    int foundExpansions = 0;
    for (Decl decl : module.getDecls()) {
        if (decl instanceof FunctionDecl) {
            FunctionDecl fun = (FunctionDecl) decl;
            if (fun.getName().startsWith("apply_")) {
                ++foundExpansions;
            }
        }
    }
    assertEquals(2, foundExpansions);
}
Also used : Model(org.abs_models.frontend.ast.Model) ModuleDecl(org.abs_models.frontend.ast.ModuleDecl) ModuleDecl(org.abs_models.frontend.ast.ModuleDecl) FunctionDecl(org.abs_models.frontend.ast.FunctionDecl) Decl(org.abs_models.frontend.ast.Decl) FunctionDecl(org.abs_models.frontend.ast.FunctionDecl) Test(org.junit.Test)

Aggregations

ModuleDecl (org.abs_models.frontend.ast.ModuleDecl)11 Model (org.abs_models.frontend.ast.Model)8 Test (org.junit.Test)7 ClassDecl (org.abs_models.frontend.ast.ClassDecl)5 KindedName (org.abs_models.frontend.typechecker.KindedName)5 ABSTest (org.abs_models.ABSTest)4 FrontendTest (org.abs_models.frontend.FrontendTest)4 MethodImpl (org.abs_models.frontend.ast.MethodImpl)3 MethodSig (org.abs_models.frontend.ast.MethodSig)3 ParamDecl (org.abs_models.frontend.ast.ParamDecl)3 ReturnStmt (org.abs_models.frontend.ast.ReturnStmt)3 VarOrFieldUse (org.abs_models.frontend.ast.VarOrFieldUse)3 ArrayList (java.util.ArrayList)2 CompilationUnit (org.abs_models.frontend.ast.CompilationUnit)2 Decl (org.abs_models.frontend.ast.Decl)2 DeltaDecl (org.abs_models.frontend.ast.DeltaDecl)2 FunctionDecl (org.abs_models.frontend.ast.FunctionDecl)2 VarUse (org.abs_models.frontend.ast.VarUse)2 ResolvedName (org.abs_models.frontend.typechecker.ResolvedName)2 PrintWriter (java.io.PrintWriter)1