use of abs.frontend.ast.ParamDecl in project abstools by abstools.
the class JavaGeneratorHelper method generateMethodBody.
public static void generateMethodBody(PrintStream stream, final MethodImpl m, boolean isFliMethod) {
boolean addReturn = false;
if (m.getMethodSig().getReturnType().getType().isUnitType()) {
if (m.getBlock().getNumStmt() == 0 || (!(m.getBlock().getStmt(m.getBlock().getNumStmt() - 1) instanceof ReturnStmt))) {
addReturn = true;
}
}
stream.println(" {");
stream.println("__ABS_checkSameCOG(); ");
if (!isFliMethod && m.isForeign()) {
stream.print("return this.");
stream.print(FLI_METHOD_PREFIX + JavaBackend.getMethodName(m.getMethodSig().getName()));
JavaGeneratorHelper.generateParamArgs(stream, m.getMethodSig().getParams());
stream.println(";");
} else {
stream.println("if (__ABS_getRuntime().debuggingEnabled()) {");
stream.println(Task.class.getName() + "<?> __ABS_currentTask = __ABS_getRuntime().getCurrentTask();");
stream.println("__ABS_currentTask.newStackFrame(this, \"" + m.getMethodSig().getName() + "\");");
for (ParamDecl d : m.getMethodSig().getParams()) {
stream.print("__ABS_currentTask.setLocalVariable(");
stream.println("\"" + d.getName() + "\"," + d.getName() + ");");
}
stream.println("}");
m.getBlock().generateJava(stream, addReturn);
}
stream.println("}");
}
use of abs.frontend.ast.ParamDecl in project abstools by abstools.
the class ClassDeclGenerator method generateClassBody.
private void generateClassBody() {
// singleton() method instantiates strictly one dynamic class object and does initialisation,
// i.e. adds fields, constructor and methods.
stream.println("{");
stream.println("private static " + ABSDynamicClass.class.getName() + " instance;");
stream.println("public static void setInstance(" + ABSDynamicClass.class.getName() + " cls) { instance = cls; }");
stream.println("public static " + ABSDynamicClass.class.getName() + " singleton() {");
stream.println("if (instance == null) {");
stream.println("instance = new " + ABSDynamicClass.class.getName() + "();");
stream.println("instance.setName(\"" + decl.getName() + "\");");
// add class parameters
for (ParamDecl p : decl.getParams()) {
String name = JavaBackend.getVariableName(p.getName());
stream.println("instance.addField(\"" + name + "\", new " + ABSField.class.getName() + "());");
}
// add fields
for (FieldDecl f : decl.getFields()) {
String name = JavaBackend.getVariableName(f.getName());
stream.println("instance.addField(\"" + name + "\", " + className + ".field$" + name + ".singleton());");
}
// add constructor
stream.println("instance.setConstructor(" + className + ".CON$TRUCT.singleton());");
stream.print("instance.setParams(");
for (int i = 0; i < decl.getNumParam(); i++) {
if (i != 0)
stream.print(", ");
stream.print("\"" + JavaBackend.getVariableName(decl.getParam(i).getName()) + "\"");
}
stream.println(");");
// add methods
for (MethodImpl m : decl.getMethods()) {
String methodName = m.getMethodSig().getName();
stream.println("instance.addMethod(\"" + methodName + "\", " + className + "." + methodName + ".singleton());");
}
stream.println("}");
stream.println("return instance;");
stream.println("}");
// generate field inner classes
for (FieldDecl field : decl.getFields()) {
field.generateJavaDynamic(stream);
}
// generate CON$TRUCT inner class
generateConstructor();
// generate method inner classes
for (MethodImpl method : decl.getMethods()) {
method.generateJavaDynamic(stream);
// FIXME not sure how to handle FLI methods
if (method.isForeign()) {
stream.println("/* FLI method: not implemented yet */");
DynamicJavaGeneratorHelper.generateFLIMethod(stream, method);
}
}
generateCreateNewCOGMethod();
generateNewObjectMethods();
stream.println("}");
}
use of abs.frontend.ast.ParamDecl in project abstools by abstools.
the class ErlUtil method functionHeader.
// Not used when garbage collector pause points are added to functions
// Consider removing
public static final void functionHeader(CodeStream ecs, String funName, abs.frontend.ast.List<ParamDecl> args) {
List<String> a = new ArrayList<>(args.getNumChild());
for (ParamDecl p : args) a.add(p.getName());
functionHeader(ecs, funName, a, Mask.all);
}
use of abs.frontend.ast.ParamDecl in project abstools by abstools.
the class ErlUtil method functionHeaderParamsAsList.
public static final void functionHeaderParamsAsList(CodeStream ecs, String funName, String firstParameter, abs.frontend.ast.List<ParamDecl> args, Mask mask) {
StringBuilder b = new StringBuilder("[");
boolean first = true;
for (ParamDecl p : args) {
if (!first)
b.append(',');
else
first = false;
b.append("P_" + p.getName());
}
if (args.hasChildren()) {
b.append(',');
}
b.append("Stack]");
functionHeader(ecs, funName, mask, firstParameter, b.toString());
}
use of abs.frontend.ast.ParamDecl in project abstools by abstools.
the class JavaGeneratorHelper method generateParamArgs.
public static void generateParamArgs(PrintStream stream, String firstArg, List<ParamDecl> params) {
stream.print("(");
boolean first = true;
if (firstArg != null) {
stream.print(firstArg);
first = false;
}
for (ParamDecl d : params) {
if (!first)
stream.print(", ");
stream.print(JavaBackend.getVariableName(d.getName()));
first = false;
}
stream.print(")");
}
Aggregations