use of org.abs_models.frontend.ast.ListLiteral 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);
}
}
Aggregations