Search in sources :

Example 36 with ClassDecl

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

the class AddImportsTest method addImport.

@Test
public void addImport() throws DeltaModellingException {
    Model model = assertParse("module Exporter; export *;" + "interface I {}" + "interface J {}" + "module Exporter2; export *;" + "interface K {}" + "module M;" + "class C {}" + "delta D; uses M;" + "adds import Exporter.I;" + "adds import J from Exporter;" + "adds import * from Exporter2;" + "modifies class C { adds Exporter.I field1; } " + "modifies class C { adds          J field2; } " + "modifies class C { adds          K field3; } ");
    ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
    DeltaDecl delta = findDelta(model, "D");
    model.applyDeltas(new ArrayList<>(Arrays.asList(delta)));
    ModuleDecl clsmodule = cls.getModuleDecl();
    Map<KindedName, ResolvedName> clsVisibleSymbols = clsmodule.getVisibleNames();
    KindedName symbol1 = new KindedName(KindedName.Kind.TYPE_DECL, "Exporter.I");
    KindedName symbol2 = new KindedName(KindedName.Kind.TYPE_DECL, "J");
    KindedName symbol3 = new KindedName(KindedName.Kind.TYPE_DECL, "K");
    assertTrue(clsVisibleSymbols.containsKey(symbol1));
    assertTrue(clsVisibleSymbols.containsKey(symbol2));
    assertTrue(clsVisibleSymbols.containsKey(symbol3));
}
Also used : ClassDecl(org.abs_models.frontend.ast.ClassDecl) Model(org.abs_models.frontend.ast.Model) ModuleDecl(org.abs_models.frontend.ast.ModuleDecl) ResolvedName(org.abs_models.frontend.typechecker.ResolvedName) KindedName(org.abs_models.frontend.typechecker.KindedName) DeltaDecl(org.abs_models.frontend.ast.DeltaDecl) Test(org.junit.Test)

Example 37 with ClassDecl

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

the class ClassKindTypeExtension method checkNewExp.

@Override
public void checkNewExp(NewExp e) {
    ClassDecl d = (ClassDecl) e.lookup(new KindedName(Kind.CLASS, e.getClassName()));
    List<Annotation> anns = AnnotationHelper.getAnnotationsOfType(d.getAnnotations(), "ABS.StdLib.ClassKindAnnotation");
    if (!anns.isEmpty()) {
        String name = ((DataConstructorExp) anns.get(0).getValue()).getDecl().getName();
        if (e.hasLocal()) {
            if (name.equals("COG")) {
                errors.add(new TypeError(e, ErrorMessage.CLASSKIND_PLAIN, d.getName()));
            }
        } else {
            if (!name.equals("COG")) {
                errors.add(new TypeError(e, ErrorMessage.CLASSKIND_COG, d.getName()));
            }
        }
    }
}
Also used : ClassDecl(org.abs_models.frontend.ast.ClassDecl) TypeError(org.abs_models.frontend.analyser.TypeError) KindedName(org.abs_models.frontend.typechecker.KindedName) Annotation(org.abs_models.frontend.ast.Annotation)

Example 38 with ClassDecl

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

the class SchedulerChecker method checkNewExp.

@Override
public void checkNewExp(NewExp e) {
    Stmt stmt = CompilerUtils.findStmtForExpression(e);
    PureExp sched = AnnotationHelper.getAnnotationValueFromName(stmt.getAnnotations(), "ABS.Scheduler.Scheduler");
    if (sched != null) {
        ClassDecl decl = (ClassDecl) (e.lookup(new KindedName(KindedName.Kind.CLASS, e.getClassName())));
        checkScheduleExp(sched, decl, stmt);
    }
}
Also used : ClassDecl(org.abs_models.frontend.ast.ClassDecl) PureExp(org.abs_models.frontend.ast.PureExp) KindedName(org.abs_models.frontend.typechecker.KindedName) Stmt(org.abs_models.frontend.ast.Stmt)

Example 39 with ClassDecl

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

the class ASTBasedABSTestRunnerGenerator method generateImportsAST.

private List<Import> generateImportsAST() {
    List<Import> imports = new List<>();
    Set<String> mn = new HashSet<>();
    Set<String> qn = new HashSet<>();
    for (InterfaceDecl key : tests.keySet()) {
        getImportsFrom(mn, qn, key.getModuleDecl());
        for (ClassDecl clazz : tests.get(key)) {
            getImportsFrom(mn, qn, clazz.getModuleDecl());
        }
    }
    for (String m : mn) {
        imports.add(new StarImport(m));
    }
    if (!qn.isEmpty()) {
        List<Name> names = new List<>();
        for (String q : qn) {
            names.add(new Name(q));
        }
        imports.add(new NamedImport(names));
    }
    return imports;
}
Also used : Import(org.abs_models.frontend.ast.Import) NamedImport(org.abs_models.frontend.ast.NamedImport) StarImport(org.abs_models.frontend.ast.StarImport) FromImport(org.abs_models.frontend.ast.FromImport) ClassDecl(org.abs_models.frontend.ast.ClassDecl) StarImport(org.abs_models.frontend.ast.StarImport) List(org.abs_models.frontend.ast.List) InterfaceDecl(org.abs_models.frontend.ast.InterfaceDecl) HashSet(java.util.HashSet) Name(org.abs_models.frontend.ast.Name) NamedImport(org.abs_models.frontend.ast.NamedImport)

Example 40 with ClassDecl

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

the class StringBasedABSTestRunnerGenerator method generateMainBlock.

private TestRunnerScriptBuilder generateMainBlock(TestRunnerScriptBuilder imports) {
    TestRunnerScriptBuilder builder = new TestRunnerScriptBuilder();
    builder.increaseIndent();
    Set<Type> paramNames = new HashSet<>();
    builder.append("Set<Fut<Unit>> ").append(futs).append(" = EmptySet;").newLine();
    builder.append("Fut<Unit> ").append(fut).append(";").newLine();
    for (InterfaceDecl key : tests.keySet()) {
        builder.append("//Test cases for ").append(key.getType().getQualifiedName()).newLine();
        for (ClassDecl clazz : tests.get(key)) {
            builder.append("//Test cases for implementation ").append(clazz.getName()).newLine();
            paramNames.addAll(generateTestClassImpl(key, clazz, builder));
        }
    }
    generateWaitSync(builder);
    generateImports(imports, paramNames);
    return builder;
}
Also used : Type(org.abs_models.frontend.typechecker.Type) ClassDecl(org.abs_models.frontend.ast.ClassDecl) InterfaceDecl(org.abs_models.frontend.ast.InterfaceDecl) HashSet(java.util.HashSet)

Aggregations

ClassDecl (org.abs_models.frontend.ast.ClassDecl)79 Model (org.abs_models.frontend.ast.Model)72 Test (org.junit.Test)72 DeltaDecl (org.abs_models.frontend.ast.DeltaDecl)24 FrontendTest (org.abs_models.frontend.FrontendTest)15 ModifyClassModifier (org.abs_models.frontend.ast.ModifyClassModifier)12 SkipStmt (org.abs_models.frontend.ast.SkipStmt)11 ReturnStmt (org.abs_models.frontend.ast.ReturnStmt)10 KindedName (org.abs_models.frontend.typechecker.KindedName)10 DeltaTraitModifier (org.abs_models.frontend.ast.DeltaTraitModifier)7 ModifyMethodModifier (org.abs_models.frontend.ast.ModifyMethodModifier)7 TraitExpr (org.abs_models.frontend.ast.TraitExpr)7 MethodImpl (org.abs_models.frontend.ast.MethodImpl)6 AddMethodModifier (org.abs_models.frontend.ast.AddMethodModifier)5 MethodSig (org.abs_models.frontend.ast.MethodSig)5 ModuleDecl (org.abs_models.frontend.ast.ModuleDecl)5 TraitSetExpr (org.abs_models.frontend.ast.TraitSetExpr)5 HashSet (java.util.HashSet)4 List (org.abs_models.frontend.ast.List)4 ABSTest (org.abs_models.ABSTest)3