use of org.abs_models.frontend.ast.InterfaceDecl in project abstools by abstools.
the class ClassGenerator method generateExports.
private void generateExports() {
ecs.println("-export([get_val_internal/2,set_val_internal/3,init_internal/0,get_state_for_modelapi/1,implemented_interfaces/0,exported/0]).");
ecs.println("-compile(export_all).");
ecs.println();
HashSet<MethodSig> callable_sigs = new HashSet<>();
HashSet<InterfaceDecl> visited = new HashSet<>();
for (InterfaceTypeUse i : classDecl.getImplementedInterfaceUseList()) {
visited.add((InterfaceDecl) i.getDecl());
}
while (!visited.isEmpty()) {
InterfaceDecl id = visited.iterator().next();
visited.remove(id);
for (MethodSig ms : id.getBodyList()) {
if (ms.isHTTPCallable()) {
callable_sigs.add(ms);
}
}
for (InterfaceTypeUse i : id.getExtendedInterfaceUseList()) {
visited.add((InterfaceDecl) i.getDecl());
}
}
ecs.print("implemented_interfaces() -> [ ");
String separator = "";
for (InterfaceDecl i : classDecl.getSuperTypes()) {
ecs.format("%s<<\"%s\">>", separator, i.getName());
separator = ", ";
}
ecs.println(" ].");
ecs.println();
ecs.print("exported() -> #{ ");
boolean first = true;
for (MethodSig ms : callable_sigs) {
if (ms.isHTTPCallable()) {
if (!first)
ecs.print(", ");
first = false;
ecs.print("<<\"" + ms.getName() + "\">> => { ");
ecs.print("'m_" + ms.getName() + "'");
ecs.print(", ");
ecs.print("<<\"" + ms.getReturnType().getType().toString() + "\">>");
ecs.print(", ");
ecs.print("[ ");
boolean innerfirst = true;
for (ParamDecl p : ms.getParamList()) {
// ABS type, and ABS type arguments (if present)
if (!innerfirst)
ecs.print(", ");
innerfirst = false;
ecs.print("{ ");
ecs.print("<<\"" + p.getName() + "\">>, ");
ecs.print("<<\"" + p.getType().toString() + "\">>, ");
generateParameterDescription(p.getType());
ecs.print(" }");
}
ecs.print("] ");
ecs.print("}");
}
}
ecs.println(" }.");
ecs.println();
}
use of org.abs_models.frontend.ast.InterfaceDecl 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;
}
use of org.abs_models.frontend.ast.InterfaceDecl 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;
}
use of org.abs_models.frontend.ast.InterfaceDecl 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 org.abs_models.frontend.ast.InterfaceDecl 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());
}
Aggregations