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();
}
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);
}
}
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("}");
}
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("}");
}
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());
}
Aggregations