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);
}
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();
}
}
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;
}
}
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;
}
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;
}
Aggregations