Search in sources :

Example 6 with List

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

the class AbsASTBuilderUtil method createMethodSig.

public static final MethodSig createMethodSig(String methodName, TypeUse returnType, ParamDecl... decls) {
    List<ParamDecl> dl = new List<>();
    for (ParamDecl d : decls) {
        dl.add(d);
    }
    MethodSig method = new MethodSig(methodName, returnType, dl);
    return method;
}
Also used : MethodSig(org.abs_models.frontend.ast.MethodSig) ParamDecl(org.abs_models.frontend.ast.ParamDecl) List(org.abs_models.frontend.ast.List)

Example 7 with List

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

the class ASTBasedABSTestRunnerGenerator method generateAsyncTestCallAST.

private void generateAsyncTestCallAST(Block block, String objectRef, MethodSig method) {
    List<PureExp> args = new List<>();
    if (method.getNumParam() > 0) {
        args.add(new VarUse(dataValue));
    }
    block.addStmtNoTransform(getVAssign(fut, new AsyncCall(new VarUse(objectRef), method.getName(), args)));
    block.addStmtNoTransform(getVAssign(futs, getFnApp("Insert", new VarUse(fut), new VarUse(futs))));
}
Also used : List(org.abs_models.frontend.ast.List) PureExp(org.abs_models.frontend.ast.PureExp) AsyncCall(org.abs_models.frontend.ast.AsyncCall) VarUse(org.abs_models.frontend.ast.VarUse)

Example 8 with List

use of org.abs_models.frontend.ast.List 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;
}
Also used : CompilationUnit(org.abs_models.frontend.ast.CompilationUnit) ArrayList(java.util.ArrayList) Model(org.abs_models.frontend.ast.Model) SemanticConditionList(org.abs_models.frontend.analyser.SemanticConditionList) ArrayList(java.util.ArrayList) List(org.abs_models.frontend.ast.List) File(java.io.File)

Example 9 with List

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

use of org.abs_models.frontend.ast.List 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

List (org.abs_models.frontend.ast.List)10 ClassDecl (org.abs_models.frontend.ast.ClassDecl)4 CompilationUnit (org.abs_models.frontend.ast.CompilationUnit)4 MethodSig (org.abs_models.frontend.ast.MethodSig)4 Model (org.abs_models.frontend.ast.Model)4 ArrayList (java.util.ArrayList)3 DeltaAccess (org.abs_models.frontend.ast.DeltaAccess)3 DeltaDecl (org.abs_models.frontend.ast.DeltaDecl)3 ModifyClassModifier (org.abs_models.frontend.ast.ModifyClassModifier)3 SemanticConditionList (org.abs_models.frontend.analyser.SemanticConditionList)2 Block (org.abs_models.frontend.ast.Block)2 FnApp (org.abs_models.frontend.ast.FnApp)2 MethodImpl (org.abs_models.frontend.ast.MethodImpl)2 PureExp (org.abs_models.frontend.ast.PureExp)2 StringLiteral (org.abs_models.frontend.ast.StringLiteral)2 Test (org.junit.Test)2 File (java.io.File)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 WrongProgramArgumentException (org.abs_models.common.WrongProgramArgumentException)1