Search in sources :

Example 1 with FieldDecl

use of org.abs_models.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(org.abs_models.frontend.ast.FieldDecl) GetExp(org.abs_models.frontend.ast.GetExp)

Example 2 with FieldDecl

use of org.abs_models.frontend.ast.FieldDecl 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(org.abs_models.frontend.ast.FieldDecl) ParamDecl(org.abs_models.frontend.ast.ParamDecl)

Example 3 with FieldDecl

use of org.abs_models.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(org.abs_models.frontend.ast.FieldDecl) ParamDecl(org.abs_models.frontend.ast.ParamDecl)

Example 4 with FieldDecl

use of org.abs_models.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(org.abs_models.frontend.ast.FieldDecl) MethodImpl(org.abs_models.frontend.ast.MethodImpl) ParamDecl(org.abs_models.frontend.ast.ParamDecl) ABSField(org.abs_models.backend.java.lib.runtime.ABSField) ABSDynamicClass(org.abs_models.backend.java.lib.runtime.ABSDynamicClass)

Example 5 with FieldDecl

use of org.abs_models.frontend.ast.FieldDecl in project abstools by abstools.

the class TypingTest method testFieldUse.

@Test
public void testFieldUse() {
    Model m = assertParse(" class C { Bool f; Bool m() { return this.f; } }");
    ClassDecl d = (ClassDecl) m.lookup(new KindedName(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(org.abs_models.frontend.ast.FieldDecl) ClassDecl(org.abs_models.frontend.ast.ClassDecl) Model(org.abs_models.frontend.ast.Model) KindedName(org.abs_models.frontend.typechecker.KindedName) ReturnStmt(org.abs_models.frontend.ast.ReturnStmt) FrontendTest(org.abs_models.frontend.FrontendTest) Test(org.junit.Test)

Aggregations

FieldDecl (org.abs_models.frontend.ast.FieldDecl)11 ParamDecl (org.abs_models.frontend.ast.ParamDecl)6 FrontendTest (org.abs_models.frontend.FrontendTest)2 TypeError (org.abs_models.frontend.analyser.TypeError)2 ClassDecl (org.abs_models.frontend.ast.ClassDecl)2 Model (org.abs_models.frontend.ast.Model)2 ReturnStmt (org.abs_models.frontend.ast.ReturnStmt)2 TypedVarOrFieldDecl (org.abs_models.frontend.ast.TypedVarOrFieldDecl)2 VarOrFieldDecl (org.abs_models.frontend.ast.VarOrFieldDecl)2 KindedName (org.abs_models.frontend.typechecker.KindedName)2 Test (org.junit.Test)2 ABSDynamicClass (org.abs_models.backend.java.lib.runtime.ABSDynamicClass)1 ABSField (org.abs_models.backend.java.lib.runtime.ABSField)1 ABSValue (org.abs_models.backend.java.lib.types.ABSValue)1 FnApp (org.abs_models.frontend.ast.FnApp)1 FunctionDecl (org.abs_models.frontend.ast.FunctionDecl)1 GetExp (org.abs_models.frontend.ast.GetExp)1 MethodImpl (org.abs_models.frontend.ast.MethodImpl)1 PureExp (org.abs_models.frontend.ast.PureExp)1 VarOrFieldUse (org.abs_models.frontend.ast.VarOrFieldUse)1