use of org.abs_models.frontend.ast.PureExp in project abstools by abstools.
the class MaudeCompilerHelper method emitParameterValueList.
public static void emitParameterValueList(PrintStream stream, List<PureExp> params, java.util.List<Type> paramTypes) {
if (params.getNumChild() == 0) {
stream.print("emp ");
} else {
boolean inlist = false;
stream.print("(");
for (int i = 0; i < params.getNumChild(); i++) {
PureExp param = params.getChild(i);
Type t = paramTypes.get(i);
boolean needConversion = t.isIntType() && param.getType().isRatType();
if (inlist)
stream.print(":: ");
else
inlist = true;
if (needConversion)
stream.print("\"ABS.StdLib.truncate\"(");
param.generateMaude(stream);
if (needConversion)
stream.print(")");
}
stream.print(") ");
}
}
use of org.abs_models.frontend.ast.PureExp in project abstools by abstools.
the class ASTBasedABSTestRunnerGenerator method generateAsyncTestCallAST.
private void generateAsyncTestCallAST(Block block, String objectRef, MethodSig method) {
List<PureExp> args = new List<>();
if (method.getNumParam() > 0) {
args.add(new VarUse(dataValue));
}
block.addStmtNoTransform(getVAssign(fut, new AsyncCall(new VarUse(objectRef), method.getName(), args)));
block.addStmtNoTransform(getVAssign(futs, getFnApp("Insert", new VarUse(fut), new VarUse(futs))));
}
use of org.abs_models.frontend.ast.PureExp in project abstools by abstools.
the class JavaGeneratorHelper method generateAsyncCall.
private static void generateAsyncCall(PrintStream stream, final String calleeString, final PureExp callee, final Type calleeType, final List<PureExp> args, final List<ParamDecl> params, final MethodSig sig, final List<Annotation> annotations) {
final java.util.List<Type> paramTypes = sig.getTypes();
stream.print(ABSRuntime.class.getName() + ".getCurrentRuntime().asyncCall(");
String targetType = JavaBackend.getQualifiedString(calleeType);
stream.println("new " + AbstractAsyncCallRT.class.getName() + "<" + targetType + ">(");
stream.println("this,");
if (callee instanceof ThisExp) {
if (calleeString != null)
stream.print(calleeString);
else
callee.generateJava(stream);
} else {
stream.print(ABSRuntime.class.getName() + ".checkForNull(");
if (calleeString != null)
stream.print(calleeString);
else
callee.generateJava(stream);
stream.print(")");
}
stream.println(",");
PureExp rtAttr;
rtAttr = AnnotationHelper.getAnnotationValueFromSimpleName(annotations, "Deadline");
if (rtAttr == null)
stream.print("new ABS.StdLib.Duration_InfDuration()");
else
rtAttr.generateJava(stream);
stream.println(",");
rtAttr = AnnotationHelper.getAnnotationValueFromSimpleName(annotations, "Cost");
if (rtAttr == null)
stream.print("new ABS.StdLib.Duration_InfDuration()");
else
rtAttr.generateJava(stream);
stream.println(",");
rtAttr = AnnotationHelper.getAnnotationValueFromSimpleName(annotations, "Critical");
if (rtAttr == null)
stream.print(ABSBool.class.getName() + ".FALSE");
else
rtAttr.generateJava(stream);
stream.println(") {");
int i = 0;
for (Type t : paramTypes) {
stream.println(JavaBackend.getQualifiedString(t) + " arg" + i + ";");
i++;
}
generateTaskGetArgsMethod(stream, paramTypes.size());
generateTaskInitMethod(stream, paramTypes);
stream.println("public java.lang.String methodName() {");
stream.println("return \"" + sig.getName() + "\";");
stream.println("}");
stream.println("public Object execute() {");
stream.print("return target." + JavaBackend.getMethodName(sig.getName()) + "(");
for (i = 0; i < paramTypes.size(); i++) {
if (i > 0)
stream.print(",");
stream.println("arg" + i);
if (paramTypes.get(i).isIntType())
stream.print(".truncate()");
}
stream.println(");");
stream.println("}");
stream.print("}.init");
if (args != null)
JavaGeneratorHelper.generateArgs(stream, args, paramTypes);
else
JavaGeneratorHelper.generateParamArgs(stream, params);
stream.println(")");
}
use of org.abs_models.frontend.ast.PureExp in project abstools by abstools.
the class JavaGeneratorHelper method generateAsyncCall.
public static void generateAsyncCall(PrintStream stream, AsyncCall call) {
final PureExp callee = call.getCallee();
final List<PureExp> params = call.getParams();
final MethodSig sig = call.getMethodSig();
final List<Annotation> annotations = call.getAnnotations();
generateAsyncCall(stream, null, callee, callee.getType(), params, null, sig, annotations);
}
use of org.abs_models.frontend.ast.PureExp in project abstools by abstools.
the class DeployInformationClass method addAnn.
public void addAnn(PureExp exp) {
// A specification is a list (hence a FnApp with first argument being a list)
DeployInformationClassSpecification info = new DeployInformationClassSpecification(_paramList, _paramType);
PureExp list = ((FnApp) exp).getParam(0);
while (((DataConstructorExp) list).hasParam() && (((DataConstructorExp) list).getParam(0) != null)) {
// means we have a cons
PureExp el = ((DataConstructorExp) list).getParam(0);
list = ((DataConstructorExp) list).getParam(1);
if (((DataConstructorExp) el).getDataConstructor().getName().equals("Cost")) {
String name = ((StringLiteral) ((DataConstructorExp) el).getParam(0)).getContent();
int cost = Integer.parseInt(((IntLiteral) ((DataConstructorExp) el).getParam(1)).getContent());
info.addCost(name, cost);
System.out.println(" Annotation is Cost(\"" + name + "\", " + cost + ")");
} else if (((DataConstructorExp) el).getDataConstructor().getName().equals("MaxUse")) {
int arity = Integer.parseInt(((IntLiteral) ((DataConstructorExp) el).getParam(0)).getContent());
info.setProvide(arity);
System.out.println(" Annotation is MaxUse(" + arity + ")");
} else if (((DataConstructorExp) el).getDataConstructor().getName().equals("Name")) {
String name = ((StringLiteral) ((DataConstructorExp) el).getParam(0)).getContent();
info.addScenarioName(name);
System.out.println(" Annotation is Name(" + name + ")");
} else if (((DataConstructorExp) el).getDataConstructor().getName().equals("Param")) {
String param = ((StringLiteral) ((DataConstructorExp) el).getParam(0)).getContent();
String port = _paramType.get(param);
PureExp spec = ((DataConstructorExp) el).getParam(1);
if (((DataConstructorExp) spec).getDataConstructor().getName().equals("Req")) {
System.out.print("Req");
info.addRequirement(param);
System.out.println(" Annotation is Req(\"" + param + "\")");
} else if (((DataConstructorExp) spec).getDataConstructor().getName().equals("List")) {
int arity = Integer.parseInt(((IntLiteral) ((DataConstructorExp) spec).getParam(0)).getContent());
info.addList(param, arity);
System.out.println(" Annotation is List(\"" + port + "\", " + arity + ")");
} else if (((DataConstructorExp) spec).getDataConstructor().getName().equals("OptList")) {
String value = ((StringLiteral) ((DataConstructorExp) spec).getParam(0)).getContent();
info.addOptList(param, value);
System.out.println(" Annotation is OptList(\"" + port + "\", " + value + ")");
} else if (((DataConstructorExp) spec).getDataConstructor().getName().equals("Default")) {
System.out.print("Default");
String value = ((StringLiteral) ((DataConstructorExp) spec).getParam(0)).getContent();
if (port != null)
System.out.print("(\"" + port + "\", " + value + ")");
info.addDefault(param, value);
System.out.println(" Annotation is Default(\"" + port + "\", " + value + ")");
} else if (((DataConstructorExp) spec).getDataConstructor().getName().equals("User")) {
System.out.print("User");
if (port != null)
System.out.print("(\"" + port + "\")");
info.addUser(param, port);
System.out.println(" Annotation is User(\"" + port + "\", " + param + ")");
}
}
}
_spec.add(info);
}
Aggregations