Search in sources :

Example 11 with ParamDecl

use of abs.frontend.ast.ParamDecl in project abstools by abstools.

the class JavaGeneratorHelper method generateParams.

public static void generateParams(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("final ");
        d.generateJava(stream);
        first = false;
    }
    stream.print(")");
}
Also used : ParamDecl(abs.frontend.ast.ParamDecl)

Example 12 with ParamDecl

use of abs.frontend.ast.ParamDecl in project abstools by abstools.

the class ClassDeclGenerator method generateGetFieldValueMethod.

private void generateGetFieldValueMethod() {
    stream.println("protected final " + ABSValue.class.getName() + " getFieldValue(java.lang.String __ABS_fieldName) throws java.lang.NoSuchFieldException {");
    for (ParamDecl p : decl.getParams()) {
        stream.println("if (\"" + p.getName() + "\".equals(__ABS_fieldName)) return " + JavaBackend.getVariableName(p.getName()) + ";");
    }
    for (FieldDecl f : decl.getFields()) {
        stream.println("if (\"" + f.getName() + "\".equals(__ABS_fieldName)) return " + JavaBackend.getVariableName(f.getName()) + ";");
    }
    stream.println("return super.getFieldValue(__ABS_fieldName);");
    stream.println("}");
}
Also used : FieldDecl(abs.frontend.ast.FieldDecl) ParamDecl(abs.frontend.ast.ParamDecl) ABSValue(abs.backend.java.lib.types.ABSValue)

Example 13 with ParamDecl

use of abs.frontend.ast.ParamDecl in project abstools by abstools.

the class ClassDeclGenerator method generateConstructor.

private void generateConstructor() {
    // constructor
    stream.print("public " + className);
    JavaGeneratorHelper.generateParams(stream, decl.getParams());
    stream.println(" {");
    for (ParamDecl p : decl.getParams()) {
        stream.println("this." + JavaBackend.getVariableName(p.getName()) + " = " + JavaBackend.getVariableName(p.getName()) + ";");
    }
    stream.println("getCOG().objectCreated(this);");
    stream.println("}");
    stream.println("protected final void __ABS_init() {");
    for (FieldDecl f : decl.getFields()) {
        if (f.hasInitExp()) {
            stream.print("this.");
            stream.print(JavaBackend.getVariableName(f.getName()));
            stream.print(" = ");
            f.getInitExp().generateJava(stream);
            stream.print(";");
        }
    }
    if (decl.hasInitBlock()) {
        decl.getInitBlock().generateJava(stream);
    }
    stream.println("getCOG().objectInitialized(this);");
    stream.println("}");
}
Also used : FieldDecl(abs.frontend.ast.FieldDecl) ParamDecl(abs.frontend.ast.ParamDecl)

Example 14 with ParamDecl

use of abs.frontend.ast.ParamDecl in project abstools by abstools.

the class ClassDeclGenerator method generateFields.

private void generateFields() {
    for (ParamDecl p : decl.getParams()) {
        stream.print("private ");
        p.generateJava(stream);
        stream.println(";");
    }
    for (FieldDecl f : decl.getFields()) {
        f.generateJava(stream);
    }
}
Also used : FieldDecl(abs.frontend.ast.FieldDecl) ParamDecl(abs.frontend.ast.ParamDecl)

Example 15 with ParamDecl

use of abs.frontend.ast.ParamDecl in project abstools by abstools.

the class DeltaForGetSetFieldsBuilder method addGetter.

AddMethodModifier addGetter(Exp returnValue, String fieldName, Access returnType) {
    MethodSig sig = new MethodSig(testCaseNameBuilder.getterMethodName(fieldName), new abs.frontend.ast.List<Annotation>(), returnType, new abs.frontend.ast.List<ParamDecl>());
    Block block = new Block();
    ReturnStmt rs = new ReturnStmt();
    rs.setRetExp(new FieldUse(fieldName));
    block.addStmtNoTransform(rs);
    MethodImpl method = new MethodImpl(sig, block, false);
    AddMethodModifier modifier = new AddMethodModifier(method);
    return modifier;
}
Also used : AbsASTBuilderUtil.createMethodSig(abs.backend.tests.AbsASTBuilderUtil.createMethodSig) MethodSig(abs.frontend.ast.MethodSig) MethodImpl(abs.frontend.ast.MethodImpl) ParamDecl(abs.frontend.ast.ParamDecl) FieldUse(abs.frontend.ast.FieldUse) AddMethodModifier(abs.frontend.ast.AddMethodModifier) Block(abs.frontend.ast.Block) ReturnStmt(abs.frontend.ast.ReturnStmt) Annotation(abs.frontend.ast.Annotation)

Aggregations

ParamDecl (abs.frontend.ast.ParamDecl)16 FieldDecl (abs.frontend.ast.FieldDecl)6 MethodImpl (abs.frontend.ast.MethodImpl)4 MethodSig (abs.frontend.ast.MethodSig)4 VarUse (abs.frontend.ast.VarUse)4 AbsASTBuilderUtil.createMethodSig (abs.backend.tests.AbsASTBuilderUtil.createMethodSig)3 Annotation (abs.frontend.ast.Annotation)3 AddMethodModifier (abs.frontend.ast.AddMethodModifier)2 Block (abs.frontend.ast.Block)2 ClassDecl (abs.frontend.ast.ClassDecl)2 FieldUse (abs.frontend.ast.FieldUse)2 PureExp (abs.frontend.ast.PureExp)2 ReturnStmt (abs.frontend.ast.ReturnStmt)2 ArrayList (java.util.ArrayList)2 ABSDynamicClass (abs.backend.java.lib.runtime.ABSDynamicClass)1 ABSField (abs.backend.java.lib.runtime.ABSField)1 ABSValue (abs.backend.java.lib.types.ABSValue)1 DeclNamePredicate (abs.backend.tests.AbsASTBuilderUtil.DeclNamePredicate)1 AbsASTBuilderUtil.createMethodImpl (abs.backend.tests.AbsASTBuilderUtil.createMethodImpl)1 AbsASTBuilderUtil.getCall (abs.backend.tests.AbsASTBuilderUtil.getCall)1