Search in sources :

Example 1 with TypedAnnotation

use of org.abs_models.frontend.ast.TypedAnnotation 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(org.abs_models.frontend.ast.IntLiteral) TypedAnnotation(org.abs_models.frontend.ast.TypedAnnotation) Annotation(org.abs_models.frontend.ast.Annotation) TypedAnnotation(org.abs_models.frontend.ast.TypedAnnotation)

Example 2 with TypedAnnotation

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

the class AnnotationUtil method addToAnnotations.

/**
 * Add an ExpansionCall annotation, or an argument to an existing
 * annotation.  Creates or adds to [ExpansionCall : list[expansionId]]
 * annotation.
 *
 * @param annotations The list to mutate
 * @param annotationType Currently always EXPANSION_CALL
 * @param expansionId An integer to add to the list.
 */
private static void addToAnnotations(List<Annotation> annotations, TypeIdUse annotationType, int expansionId) {
    IntLiteral indexLiteral = new IntLiteral(Integer.toString(expansionId));
    Annotation toAdd = getAnnotation(annotations, annotationType);
    if (toAdd == null) {
        List<PureExp> llist = new List<>(new ListLiteral(new List<PureExp>(indexLiteral)));
        toAdd = new TypedAnnotation(new FnApp("list", llist), annotationType);
        annotations.add(toAdd);
    } else {
        PureExp value = toAdd.getValue();
        if (!(value instanceof FnApp)) {
            throw new IllegalArgumentException("Annotation list contains invalid expansion annotation");
        }
        FnApp fvalue = (FnApp) value;
        if (!fvalue.getName().equals("list")) {
            throw new IllegalArgumentException("Annotation list contains invalid expansion annotation");
        }
        ListLiteral list = (ListLiteral) fvalue.getParam(0);
        for (PureExp exp : list.getPureExps()) {
            if (exp instanceof IntLiteral) {
                IntLiteral intLiteral = (IntLiteral) exp;
                if (intLiteral.getContent().equals(indexLiteral.getContent())) {
                    return;
                }
            }
        }
        list.addPureExp(indexLiteral);
    }
}
Also used : ListLiteral(org.abs_models.frontend.ast.ListLiteral) FnApp(org.abs_models.frontend.ast.FnApp) IntLiteral(org.abs_models.frontend.ast.IntLiteral) List(org.abs_models.frontend.ast.List) TypedAnnotation(org.abs_models.frontend.ast.TypedAnnotation) PureExp(org.abs_models.frontend.ast.PureExp) Annotation(org.abs_models.frontend.ast.Annotation) TypedAnnotation(org.abs_models.frontend.ast.TypedAnnotation)

Aggregations

Annotation (org.abs_models.frontend.ast.Annotation)2 IntLiteral (org.abs_models.frontend.ast.IntLiteral)2 TypedAnnotation (org.abs_models.frontend.ast.TypedAnnotation)2 FnApp (org.abs_models.frontend.ast.FnApp)1 List (org.abs_models.frontend.ast.List)1 ListLiteral (org.abs_models.frontend.ast.ListLiteral)1 PureExp (org.abs_models.frontend.ast.PureExp)1