Search in sources :

Example 6 with Annotation

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

the class JavaGeneratorHelper method generateAwaitAsyncCall.

public static void generateAwaitAsyncCall(PrintStream stream, AwaitAsyncCall call) {
    final PureExp callee = call.getCallee();
    final List<PureExp> params = call.getParams();
    final MethodSig sig = call.getMethodSig();
    final List<Annotation> annotations = call.getAnnotations();
    // FIXME: implement await, assignment afterwards
    // OutputStream exprOStream = new ByteArrayOutputStream();
    // PrintStream exprStream = new PrintStream(exprOStream);
    // ClaimGuard guard = new ClaimGuard();
    // // Necessary temporary variables are written to "stream" and the
    // // await-expression is written to exprStream
    // 
    // // FIXME: implement await, assignment afterwards
    // guard.generateJavaGuard(stream, exprStream);
    // stream.print(JavaBackendConstants.ABSRUNTIME + ".await(");
    // stream.print(exprOStream.toString());
    // stream.println(");");
    generateAsyncCall(stream, null, callee, callee.getType(), params, null, sig, annotations);
}
Also used : MethodSig(abs.frontend.ast.MethodSig) PureExp(abs.frontend.ast.PureExp) Annotation(abs.frontend.ast.Annotation)

Example 7 with Annotation

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

Example 8 with Annotation

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

the class AnnotationUtil method addToAnnotations.

private static void addToAnnotations(List<Annotation> annotations, Access annotationType, int expansionId) {
    IntLiteral indexLiteral = new IntLiteral(Integer.toString(expansionId));
    Annotation toAdd = getAnnotation(annotations, annotationType);
    if (toAdd == null) {
        toAdd = new TypedAnnotation(new ListLiteral(new List<>()), annotationType);
        annotations.add(toAdd);
    }
    PureExp value = toAdd.getValue();
    if (value instanceof ListLiteral) {
        ListLiteral list = (ListLiteral) value;
        for (PureExp exp : list.getPureExps()) {
            if (exp instanceof IntLiteral) {
                IntLiteral intLiteral = (IntLiteral) exp;
                if (intLiteral.getContent().equals(indexLiteral.getContent())) {
                    return;
                }
            }
        }
        list.addPureExp(indexLiteral);
    } else {
        throw new IllegalArgumentException("Annotation list contains invalid expansion annotation");
    }
}
Also used : ListLiteral(abs.frontend.ast.ListLiteral) IntLiteral(abs.frontend.ast.IntLiteral) TypedAnnotation(abs.frontend.ast.TypedAnnotation) PureExp(abs.frontend.ast.PureExp) Annotation(abs.frontend.ast.Annotation) TypedAnnotation(abs.frontend.ast.TypedAnnotation)

Example 9 with Annotation

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

the class AnnotationUtil method annotateExpansion.

public static void annotateExpansion(FunctionDecl expansion, int expansionId) {
    IntLiteral indexLiteral = new IntLiteral(Integer.toString(expansionId));
    Annotation annotation = new TypedAnnotation(indexLiteral, expansionType());
    expansion.addAnnotation(annotation);
}
Also used : IntLiteral(abs.frontend.ast.IntLiteral) TypedAnnotation(abs.frontend.ast.TypedAnnotation) Annotation(abs.frontend.ast.Annotation) TypedAnnotation(abs.frontend.ast.TypedAnnotation)

Example 10 with Annotation

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

the class AnnotationUtil method getExpansionId.

/**
 * Gets the expansion ID of a function declaration. If the function declaration is not an expansion, -1 is
 * returned.
 *
 * @param decl a function declaration
 * @return an expansion ID, or -1
 * @throws NullPointerException if decl is null
 */
public static int getExpansionId(FunctionDecl decl) {
    Objects.requireNonNull(decl);
    Annotation annotation = getAnnotation(decl.getAnnotationsNoTransform(), expansionType());
    if (annotation == null) {
        return -1;
    }
    PureExp value = annotation.getValue();
    if (value instanceof IntLiteral) {
        IntLiteral intValue = (IntLiteral) value;
        try {
            int result = Integer.parseInt(intValue.getContent());
            return result < 0 ? -1 : result;
        } catch (NumberFormatException e) {
            return -1;
        }
    } else {
        return -1;
    }
}
Also used : IntLiteral(abs.frontend.ast.IntLiteral) PureExp(abs.frontend.ast.PureExp) Annotation(abs.frontend.ast.Annotation) TypedAnnotation(abs.frontend.ast.TypedAnnotation)

Aggregations

Annotation (abs.frontend.ast.Annotation)11 MethodSig (abs.frontend.ast.MethodSig)6 PureExp (abs.frontend.ast.PureExp)4 AbsASTBuilderUtil.createMethodSig (abs.backend.tests.AbsASTBuilderUtil.createMethodSig)3 ClassDecl (abs.frontend.ast.ClassDecl)3 IntLiteral (abs.frontend.ast.IntLiteral)3 MethodImpl (abs.frontend.ast.MethodImpl)3 ParamDecl (abs.frontend.ast.ParamDecl)3 TypedAnnotation (abs.frontend.ast.TypedAnnotation)3 AddMethodModifier (abs.frontend.ast.AddMethodModifier)2 Block (abs.frontend.ast.Block)2 FieldUse (abs.frontend.ast.FieldUse)2 AbsASTBuilderUtil.createMethodImpl (abs.backend.tests.AbsASTBuilderUtil.createMethodImpl)1 TypeError (abs.frontend.analyser.TypeError)1 CaseBranchStmt (abs.frontend.ast.CaseBranchStmt)1 CompilationUnit (abs.frontend.ast.CompilationUnit)1 DataConstructorExp (abs.frontend.ast.DataConstructorExp)1 Decl (abs.frontend.ast.Decl)1 FieldDecl (abs.frontend.ast.FieldDecl)1 InitBlock (abs.frontend.ast.InitBlock)1