use of org.abs_models.frontend.ast.MethodSig 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.MethodSig in project abstools by abstools.
the class JavaGeneratorHelper method generateAwaitAsyncCall.
public static void generateAwaitAsyncCall(PrintStream stream, AwaitAsyncCall call) {
final PureExp callee = call.getCallee();
final List<PureExp> params = call.getParams();
final MethodSig sig = call.getMethodSig();
final List<Annotation> annotations = call.getAnnotations();
// FIXME: implement await, assignment afterwards
// OutputStream exprOStream = new ByteArrayOutputStream();
// PrintStream exprStream = new PrintStream(exprOStream);
// ClaimGuard guard = new ClaimGuard();
// // Necessary temporary variables are written to "stream" and the
// // await-expression is written to exprStream
//
// // FIXME: implement await, assignment afterwards
// guard.generateJavaGuard(stream, exprStream);
// stream.print(JavaBackendConstants.ABSRUNTIME + ".await(");
// stream.print(exprOStream.toString());
// stream.println(");");
generateAsyncCall(stream, null, callee, callee.getType(), params, null, sig, annotations);
}
use of org.abs_models.frontend.ast.MethodSig in project abstools by abstools.
the class JavaGeneratorHelper method generateAsyncMethod.
public static void generateAsyncMethod(PrintStream stream, MethodImpl method) {
final MethodSig sig = method.getMethodSig();
generateMethodSig(stream, sig, true, "final", "");
stream.println(" {");
stream.print("return (" + ABSFut.class.getName() + ")");
generateAsyncCall(stream, "this", null, method.getContextDecl().getType(), null, sig.getParams(), sig, new List<>());
stream.println(";");
stream.println("}");
}
use of org.abs_models.frontend.ast.MethodSig in project abstools by abstools.
the class TraitTest method addAddModifierAtRuntimeBackComp.
@Test
public void addAddModifierAtRuntimeBackComp() {
Model model = assertParse("module M;" + "class C { Unit m(){skip;} }");
ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
MethodSig sig = AbsASTBuilderUtil.createMethodSig("n", AbsASTBuilderUtil.getUnit());
MethodImpl impl = new MethodImpl(sig, new Block(new List<>(), new List<>(new SkipStmt())));
AddMethodModifier opr = new AddMethodModifier(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(2, cls.getMethods().getNumChild());
}
use of org.abs_models.frontend.ast.MethodSig in project abstools by abstools.
the class ASTBasedABSTestRunnerGenerator method generateDataPointsAST.
private TypeUse generateDataPointsAST(InterfaceDecl key, ClassDecl clazz, Set<TypeUse> use, MainBlock block) {
MethodSig dataPoint = findDataPoints(key);
if (dataPoint == null) {
return null;
}
TypeIdUse rt = dataPoint.getReturnType();
if (!(rt instanceof ParametricDataTypeUse)) {
return null;
}
ParametricDataTypeUse prt = (ParametricDataTypeUse) rt;
if (!prt.getName().equals("Set")) {
return null;
}
// Set has only one type parameter
TypeUse u = (TypeUse) prt.getParam(0).copy();
use.add(u);
String objName = uncap(clazz.getName()) + "dataPoint";
String dataSet = dataPointSetName(clazz);
block.addStmtNoTransform(newObj(key, clazz, objName, true));
block.addStmtNoTransform(getVarDecl(dataSet, prt.copy(), new SyncCall(new VarUse(objName), dataPoint.getName(), new List<>())));
return u;
}
Aggregations