Search in sources :

Example 6 with FieldDecl

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

the class DeadlockPreanalysis method toString.

public String toString() {
    StringBuffer buffer = new StringBuffer();
    buffer.append("***** Deadlock Preanalysis Results: *****\n");
    buffer.append("----- GET Expressions evaluation --------\n");
    for (GetExp get : getExpressions.keySet()) {
        buffer.append(get.toString());
        buffer.append("[");
        int line = get.getStartLine();
        buffer.append(get.getCompilationUnit().getName() + ":" + (line != 0 ? +line : "_"));
        buffer.append("]");
        buffer.append(":" + (getExpressions.get(get) != null ? true : false) + "\n");
    }
    buffer.append("----- Field Types -----------------------\n");
    for (FieldDecl field : dataFieldDecls.keySet()) {
        buffer.append(field.getContextDecl().getName() + "." + field.getName() + " [" + field.getCompilationUnit().getName() + ":" + field.getStartLine() + "]");
        buffer.append(" might contain a future value?: " + dataFieldDecls.get(field) + "\n");
    }
    buffer.append("*****************************************");
    return buffer.toString();
}
Also used : FieldDecl(abs.frontend.ast.FieldDecl) GetExp(abs.frontend.ast.GetExp)

Example 7 with FieldDecl

use of abs.frontend.ast.FieldDecl 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("}");
}
Also used : FieldDecl(abs.frontend.ast.FieldDecl) MethodImpl(abs.frontend.ast.MethodImpl) ParamDecl(abs.frontend.ast.ParamDecl) ABSField(abs.backend.java.lib.runtime.ABSField) ABSDynamicClass(abs.backend.java.lib.runtime.ABSDynamicClass)

Example 8 with FieldDecl

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

the class TypingTest method testFieldUse.

@Test
public void testFieldUse() {
    Model m = assertParseOkStdLib(" class C { Bool f; Bool m() { return this.f; } }");
    ClassDecl d = (ClassDecl) m.lookup(new KindedName(Kind.CLASS, "UnitTest.C"));
    FieldDecl f = d.getField(0);
    ReturnStmt s = (ReturnStmt) d.getMethod(0).getBlock().getStmt(0);
    assertEquals(f.getType(), s.getRetExp().getType());
}
Also used : FieldDecl(abs.frontend.ast.FieldDecl) ClassDecl(abs.frontend.ast.ClassDecl) Model(abs.frontend.ast.Model) KindedName(abs.frontend.typechecker.KindedName) ReturnStmt(abs.frontend.ast.ReturnStmt) Test(org.junit.Test) FrontendTest(abs.frontend.FrontendTest)

Example 9 with FieldDecl

use of abs.frontend.ast.FieldDecl 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 10 with FieldDecl

use of abs.frontend.ast.FieldDecl 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)

Aggregations

FieldDecl (abs.frontend.ast.FieldDecl)14 ParamDecl (abs.frontend.ast.ParamDecl)6 ClassDecl (abs.frontend.ast.ClassDecl)4 InterfaceTypeUse (abs.frontend.ast.InterfaceTypeUse)4 MethodImpl (abs.frontend.ast.MethodImpl)3 TypeError (abs.frontend.analyser.TypeError)2 DeltaDecl (abs.frontend.ast.DeltaDecl)2 InterfaceDecl (abs.frontend.ast.InterfaceDecl)2 ModifyClassModifier (abs.frontend.ast.ModifyClassModifier)2 VarUse (abs.frontend.ast.VarUse)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 AbsASTBuilderUtil.createMethodImpl (abs.backend.tests.AbsASTBuilderUtil.createMethodImpl)1 AbsASTBuilderUtil.createMethodSig (abs.backend.tests.AbsASTBuilderUtil.createMethodSig)1 AbsASTBuilderUtil.getExpStmt (abs.backend.tests.AbsASTBuilderUtil.getExpStmt)1 FrontendTest (abs.frontend.FrontendTest)1 AddFieldModifier (abs.frontend.ast.AddFieldModifier)1 AddInterfaceModifier (abs.frontend.ast.AddInterfaceModifier)1 AddMethodModifier (abs.frontend.ast.AddMethodModifier)1