Search in sources :

Example 1 with MainBlock

use of abs.frontend.ast.MainBlock in project abstools by abstools.

the class ModulePathTest method setUp.

/**
 * @throws java.lang.Exception
 */
@Before
public void setUp() throws Exception {
    // Set up ABS nature
    natureMock = mock(AbsNature.class, Mockito.RETURNS_DEEP_STUBS);
    MainBlock main = mock(MainBlock.class, Mockito.RETURNS_DEEP_STUBS);
    natureMock.modelLock = new Object();
    // Set up mocks with @Mock annotation
    MockitoAnnotations.initMocks(this);
    declArray = new ModuleDecl[] { modDeclA, modDeclAAA, modDeclAAB, modDeclAAC, modDeclAAD, modDeclAAE };
    // Set up module paths
    modPathEmpty = new ModulePath(natureMock, "");
    modPathA = new ModulePath(natureMock, "A");
    modPathAA = new ModulePath(natureMock, "A.A");
    modPathAAA = new ModulePath(natureMock, "A.A.A");
    modPathAAB = new ModulePath(natureMock, "A.A.B");
    modPathAAC = new ModulePath(natureMock, "A.A.C");
    modPathAAD = new ModulePath(natureMock, "A.A.D");
    modPathAAE = new ModulePath(natureMock, "A.A.E");
    // Return "fake" module names.
    when(modDeclA.getName()).thenReturn("A");
    when(modDeclAAA.getName()).thenReturn("A.A.A");
    when(modDeclAAB.getName()).thenReturn("A.A.B");
    when(modDeclAAC.getName()).thenReturn("A.A.C");
    when(modDeclAAD.getName()).thenReturn("A.A.D");
    when(modDeclAAE.getName()).thenReturn("A.A.E");
    // Setting up child nodes of ModuleDecls
    // moduleDeclA and moduleDeclAAA are empty
    // moduleDeclAAB has a main block
    when(declArray[2].hasBlock()).thenReturn(true);
    when(declArray[2].getBlock()).thenReturn(main);
    // moduleDeclAAC has a decl (class declaration)
    when(declArray[3].getNumDecl()).thenReturn(1);
    abs.frontend.ast.List<Decl> declList = new abs.frontend.ast.List<Decl>();
    declList.add((Decl) mock(ClassDecl.class));
    when(declArray[3].getDeclList()).thenReturn(declList);
    // moduleDeclAAD has an Export
    when(declArray[4].getNumExport()).thenReturn(1);
    // moduleDeclAAD has an Import
    when(declArray[5].getNumImport()).thenReturn(2);
    decls = Arrays.asList(declArray);
    when(model.getModuleDecls()).thenReturn(decls);
    when(natureMock.getCompleteModel()).thenReturn(model);
}
Also used : ModulePath(org.absmodels.abs.plugin.navigator.ModulePath) ModuleDecl(abs.frontend.ast.ModuleDecl) Decl(abs.frontend.ast.Decl) ClassDecl(abs.frontend.ast.ClassDecl) ArrayList(java.util.ArrayList) List(java.util.List) MainBlock(abs.frontend.ast.MainBlock) AbsNature(org.absmodels.abs.plugin.builder.AbsNature) Before(org.junit.Before)

Example 2 with MainBlock

use of abs.frontend.ast.MainBlock in project abstools by abstools.

the class WizardUtil method getInsertionPosition.

/**
 * Determines the insertion position for a new interface/class declaration.
 * If the given ModuleDecl has a MainBlock the insertion point is right
 * before the main block. Otherwise, the insertion point is at the end of
 * the ModuleDecl.
 *
 * @param d
 *            The target document
 * @param astNode
 *            The target ModuleDecl
 * @return the insertion position of the new class or interface.
 * @throws BadLocationException
 *             if the location of the module declaration or the respective
 *             main block could not be found
 */
public static int getInsertionPosition(IDocument d, InternalASTNode<ModuleDecl> astNode) throws BadLocationException {
    Assert.isNotNull(d);
    Assert.isNotNull(astNode);
    final ModuleDecl m = astNode.getASTNode();
    Assert.isNotNull(m, "ModuleDecl argument is null!");
    final EditorPosition position;
    /* Classes and interfaces go before product lines / products in the grammar.
		 * We don't want to generate invalid input for the user.
		 */
    if (m.hasBlock()) {
        MainBlock block = m.getBlock();
        position = UtilityFunctions.getPosition(block);
        return d.getLineOffset(position.getLinestart()) + position.getColstart();
    } else {
        position = UtilityFunctions.getPosition(m);
        return d.getLineOffset(position.getLineend()) + position.getColend();
    }
}
Also used : EditorPosition(org.absmodels.abs.plugin.util.UtilityFunctions.EditorPosition) ModuleDecl(abs.frontend.ast.ModuleDecl) MainBlock(abs.frontend.ast.MainBlock)

Example 3 with MainBlock

use of abs.frontend.ast.MainBlock in project abstools by abstools.

the class LocationTypeInferrerExtension method getFarTypes.

private List<LocationType> getFarTypes(ASTNode<?> originatingNode) {
    HasCogs node = null;
    String prefix = "";
    if (precision == LocationTypingPrecision.GLOBAL_FAR) {
        node = originatingNode.getCompilationUnit().getModel();
        prefix = "G";
    }
    if (precision == LocationTypingPrecision.COMPILATION_UNIT_LOCAL_FAR) {
        node = originatingNode.getCompilationUnit();
        prefix = "U";
    }
    if (precision == LocationTypingPrecision.MODULE_LOCAL_FAR) {
        node = originatingNode.getModuleDecl();
        prefix = "M";
    }
    if (precision == LocationTypingPrecision.CLASS_LOCAL_FAR) {
        Decl d = originatingNode.getContextDecl();
        if (d instanceof ClassDecl) {
            node = d;
            prefix = "C";
        }
        Block b = originatingNode.getContextBlock();
        if (b instanceof MainBlock) {
            node = b;
            prefix = "C";
        }
    }
    if (precision == LocationTypingPrecision.METHOD_LOCAL_FAR) {
        Block b = originatingNode.getContextBlock();
        if (b != null) {
            node = b;
            prefix = "M";
        }
    }
    if (node == null) {
        return Collections.emptyList();
    }
    final List<LocationType> e = farTypes.get(node);
    if (e != null) {
        return e;
    } else {
        List<LocationType> result = new ArrayList<>();
        int numberOfNewCogs = node.getNumberOfNewCogExpr();
        if (numberOfNewCogs > THRESHOLD) {
            numberOfNewCogs = THRESHOLD;
        }
        for (int i = 0; i < numberOfNewCogs; i++) {
            result.add(LocationType.createParametricFar(prefix + i));
        }
        farTypes.put(node, result);
        return result;
    }
}
Also used : ClassDecl(abs.frontend.ast.ClassDecl) HasCogs(abs.frontend.analyser.HasCogs) Block(abs.frontend.ast.Block) MainBlock(abs.frontend.ast.MainBlock) ClassDecl(abs.frontend.ast.ClassDecl) Decl(abs.frontend.ast.Decl) MainBlock(abs.frontend.ast.MainBlock) LocationType(abs.frontend.typechecker.locationtypes.LocationType)

Example 4 with MainBlock

use of abs.frontend.ast.MainBlock in project abstools by abstools.

the class ASTBasedABSTestRunnerGenerator method generateMainBlockAST.

private MainBlock generateMainBlockAST(List<Import> list) {
    final MainBlock block = new MainBlock();
    DataConstructorExp empty = new DataConstructorExp("EmptySet", new List<>());
    VarDeclStmt futsStatement = getVarDecl(futs, getType("Set", getFutUnitType()), empty);
    block.addStmtNoTransform(futsStatement);
    VarDeclStmt futStatement = getVarDecl(fut, getFutUnitType(), null);
    block.addStmtNoTransform(futStatement);
    Set<TypeUse> use = new HashSet<>();
    for (InterfaceDecl key : tests.keySet()) {
        for (ClassDecl clazz : tests.get(key)) {
            use.addAll(generateTestClassImplAST(key, clazz, block));
        }
    }
    block.addStmtNoTransform(generateWaitSyncAST());
    return block;
}
Also used : DataConstructorExp(abs.frontend.ast.DataConstructorExp) TypeUse(abs.frontend.ast.TypeUse) ParametricDataTypeUse(abs.frontend.ast.ParametricDataTypeUse) DataTypeUse(abs.frontend.ast.DataTypeUse) ClassDecl(abs.frontend.ast.ClassDecl) VarDeclStmt(abs.frontend.ast.VarDeclStmt) InterfaceDecl(abs.frontend.ast.InterfaceDecl) MainBlock(abs.frontend.ast.MainBlock) HashSet(java.util.HashSet)

Example 5 with MainBlock

use of abs.frontend.ast.MainBlock in project abstools by abstools.

the class ASTBasedABSTestRunnerGenerator method generateTestClassImplAST.

private Set<TypeUse> generateTestClassImplAST(InterfaceDecl inf, ClassDecl clazz, MainBlock block) {
    Set<TypeUse> accesses = new HashSet<>();
    TypeUse dataType = generateDataPointsAST(inf, clazz, accesses, block);
    String namePrefix = clazz.getName();
    int instance = 0;
    for (MethodSig method : getTestMethods(inf)) {
        Block thisBlock = block;
        WhileStmt ws = null;
        if (method.getNumParam() > 0) {
            if (dataType == null) {
                throw new IllegalStateException("Test method requires arguments but test class defines no data point");
            }
            /*
                 * a while loop over all data points
                 */
            String dataPointSet = dataPointSetName(clazz);
            ws = new WhileStmt();
            ws.setCondition(getFnApp("hasNext", new VarUse(dataPointSet)));
            Block body = new Block();
            thisBlock = body;
            DataTypeUse u = getType("Pair", getType("Set", (TypeUse) dataType.copy()), (TypeUse) dataType.copy());
            thisBlock.addStmtNoTransform(getVarDecl("nt", u, getFnApp("next", new VarUse(dataPointSet))));
            thisBlock.addStmtNoTransform(getVarDecl(dataValue, (TypeUse) dataType.copy(), getFnApp("snd", new VarUse("nt"))));
            thisBlock.addStmtNoTransform(getVAssign(dataPointSet, getFnApp("fst", new VarUse("nt"))));
            ws.setBody(body);
        }
        /*
             * Add those methods that are not ignored
             */
        if (!isIgnored(clazz, method)) {
            String objectRef = uncap(namePrefix) + instance;
            thisBlock.addStmtNoTransform(newObj(inf, clazz, objectRef, false));
            generateAsyncTestCallAST(thisBlock, objectRef, method);
        }
        if (ws != null) {
            block.addStmtNoTransform(ws);
        }
        instance++;
    }
    return accesses;
}
Also used : MethodSig(abs.frontend.ast.MethodSig) TypeUse(abs.frontend.ast.TypeUse) ParametricDataTypeUse(abs.frontend.ast.ParametricDataTypeUse) DataTypeUse(abs.frontend.ast.DataTypeUse) WhileStmt(abs.frontend.ast.WhileStmt) ParametricDataTypeUse(abs.frontend.ast.ParametricDataTypeUse) DataTypeUse(abs.frontend.ast.DataTypeUse) Block(abs.frontend.ast.Block) MainBlock(abs.frontend.ast.MainBlock) VarUse(abs.frontend.ast.VarUse) HashSet(java.util.HashSet)

Aggregations

MainBlock (abs.frontend.ast.MainBlock)5 ClassDecl (abs.frontend.ast.ClassDecl)3 Block (abs.frontend.ast.Block)2 DataTypeUse (abs.frontend.ast.DataTypeUse)2 Decl (abs.frontend.ast.Decl)2 ModuleDecl (abs.frontend.ast.ModuleDecl)2 ParametricDataTypeUse (abs.frontend.ast.ParametricDataTypeUse)2 TypeUse (abs.frontend.ast.TypeUse)2 HashSet (java.util.HashSet)2 HasCogs (abs.frontend.analyser.HasCogs)1 DataConstructorExp (abs.frontend.ast.DataConstructorExp)1 InterfaceDecl (abs.frontend.ast.InterfaceDecl)1 MethodSig (abs.frontend.ast.MethodSig)1 VarDeclStmt (abs.frontend.ast.VarDeclStmt)1 VarUse (abs.frontend.ast.VarUse)1 WhileStmt (abs.frontend.ast.WhileStmt)1 LocationType (abs.frontend.typechecker.locationtypes.LocationType)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 AbsNature (org.absmodels.abs.plugin.builder.AbsNature)1