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