use of org.abs_models.frontend.ast.DataConstructorExp in project abstools by abstools.
the class AnnotationTests method assertHasLocAnnotation.
private void assertHasLocAnnotation(Type t, String s) {
List<TypeAnnotation> anns = t.getTypeAnnotations();
TypeAnnotation a = anns.get(0);
assertEquals("LocationType", a.getType().getSimpleName());
assertEquals(s, ((DataConstructorExp) a.getValue()).getDecl().getName());
}
use of org.abs_models.frontend.ast.DataConstructorExp in project abstools by abstools.
the class Main method rewriteModel.
/**
* Perform various rewrites that cannot be done in JastAdd.
*
* JastAdd rewrite rules can only rewrite the current node using
* node-local information. ("The code in the body of the rewrite may
* access and rearrange the nodes in the subtree rooted at A, but not any
* other nodes in the AST. Furthermore, the code may not have any other
* side effects." --
* http://jastadd.org/web/documentation/reference-manual.php#Rewrites)
*
* We use this method to generate Exception constructors and the
* information in ABS.Productline.
*
* @param m the model.
* @param productname The name of the product or null.
* @throws WrongProgramArgumentException
*/
private static void rewriteModel(Model m, String productname) throws WrongProgramArgumentException {
// Generate reflective constructors for all features
ProductLine pl = m.getProductLine();
if (pl != null) {
// Let's assume the module and datatype names in abslang.abs did
// not get changed, and just crash otherwise. If you're here
// because of a NPE: Hi! Make the standard library and this code
// agree about what the feature reflection module is called.
ModuleDecl modProductline = null;
DataTypeDecl featureDecl = null;
FunctionDecl currentFeatureFun = null;
FunctionDecl productNameFun = null;
for (ModuleDecl d : m.getModuleDecls()) {
if (d.getName().equals(Constants.PL_NAME)) {
modProductline = d;
break;
}
}
if (modProductline == null) {
throw new WrongProgramArgumentException("Internal error: did not find module " + Constants.PL_NAME + "(should have been defined in the abslang.abs standard library)");
}
for (Decl d : modProductline.getDecls()) {
if (d instanceof DataTypeDecl && d.getName().equals("Feature")) {
featureDecl = (DataTypeDecl) d;
} else if (d instanceof FunctionDecl && d.getName().equals("product_features")) {
currentFeatureFun = (FunctionDecl) d;
} else if (d instanceof FunctionDecl && d.getName().equals("product_name")) {
productNameFun = (FunctionDecl) d;
}
}
// Adjust Feature datatype
featureDecl.setDataConstructorList(new List<>());
for (Feature f : pl.getFeatures()) {
// TODO: when/if we incorporate feature parameters into the
// productline feature declarations (as we should), we need to
// adjust the DataConstructor arguments here.
featureDecl.addDataConstructorNoTransform(new DataConstructor(f.getName(), new List<>()));
}
// Adjust product_name() function
productNameFun.setFunctionDef(new ExpFunctionDef(new StringLiteral(productname)));
// Adjust product_features() function
ProductDecl p = null;
if (productname != null)
p = m.findProduct(productname);
if (p != null) {
DataConstructorExp feature_arglist = new DataConstructorExp("Cons", new List<>());
DataConstructorExp current = feature_arglist;
for (Feature f : p.getProduct().getFeatures()) {
DataConstructorExp next = new DataConstructorExp("Cons", new List<>());
// TODO: when/if we incorporate feature parameters into
// the productline feature declarations (as we should), we
// need to adjust the DataConstructorExp arguments here.
current.addParamNoTransform(new DataConstructorExp(f.getName(), new List<>()));
current.addParamNoTransform(next);
current = next;
}
current.setConstructor("Nil");
currentFeatureFun.setFunctionDef(new ExpFunctionDef(feature_arglist));
}
}
m.flushTreeCache();
}
use of org.abs_models.frontend.ast.DataConstructorExp in project abstools by abstools.
the class AnnotationHelper method getAnnotationsOfType.
public static java.util.List<Annotation> getAnnotationsOfType(List<Annotation> annos, String qualifiedName) {
ArrayList<Annotation> res = new ArrayList<>();
for (Annotation a : annos) {
if (a.getType().getQualifiedName().equals(qualifiedName)) {
DataConstructorExp de = (DataConstructorExp) a.getValue();
res.add(a);
}
}
return res;
}
use of org.abs_models.frontend.ast.DataConstructorExp in project abstools by abstools.
the class ASTBasedABSTestRunnerGenerator method generateMainBlockAST.
private MainBlock generateMainBlockAST(List<Import> list) {
final MainBlock block = new MainBlock();
DataConstructorExp empty = new DataConstructorExp("EmptySet", new List<>());
VarDeclStmt futsStatement = getVarDecl(futs, getType("Set", getFutUnitType()), empty);
block.addStmtNoTransform(futsStatement);
VarDeclStmt futStatement = getVarDecl(fut, getFutUnitType(), null);
block.addStmtNoTransform(futStatement);
Set<TypeUse> use = new HashSet<>();
for (InterfaceDecl key : tests.keySet()) {
for (ClassDecl clazz : tests.get(key)) {
use.addAll(generateTestClassImplAST(key, clazz, block));
}
}
block.addStmtNoTransform(generateWaitSyncAST());
return block;
}
use of org.abs_models.frontend.ast.DataConstructorExp in project abstools by abstools.
the class DeployInformationClass method addAnn.
public void addAnn(PureExp exp) {
// A specification is a list (hence a FnApp with first argument being a list)
DeployInformationClassSpecification info = new DeployInformationClassSpecification(_paramList, _paramType);
PureExp list = ((FnApp) exp).getParam(0);
while (((DataConstructorExp) list).hasParam() && (((DataConstructorExp) list).getParam(0) != null)) {
// means we have a cons
PureExp el = ((DataConstructorExp) list).getParam(0);
list = ((DataConstructorExp) list).getParam(1);
if (((DataConstructorExp) el).getDataConstructor().getName().equals("Cost")) {
String name = ((StringLiteral) ((DataConstructorExp) el).getParam(0)).getContent();
int cost = Integer.parseInt(((IntLiteral) ((DataConstructorExp) el).getParam(1)).getContent());
info.addCost(name, cost);
System.out.println(" Annotation is Cost(\"" + name + "\", " + cost + ")");
} else if (((DataConstructorExp) el).getDataConstructor().getName().equals("MaxUse")) {
int arity = Integer.parseInt(((IntLiteral) ((DataConstructorExp) el).getParam(0)).getContent());
info.setProvide(arity);
System.out.println(" Annotation is MaxUse(" + arity + ")");
} else if (((DataConstructorExp) el).getDataConstructor().getName().equals("Name")) {
String name = ((StringLiteral) ((DataConstructorExp) el).getParam(0)).getContent();
info.addScenarioName(name);
System.out.println(" Annotation is Name(" + name + ")");
} else if (((DataConstructorExp) el).getDataConstructor().getName().equals("Param")) {
String param = ((StringLiteral) ((DataConstructorExp) el).getParam(0)).getContent();
String port = _paramType.get(param);
PureExp spec = ((DataConstructorExp) el).getParam(1);
if (((DataConstructorExp) spec).getDataConstructor().getName().equals("Req")) {
System.out.print("Req");
info.addRequirement(param);
System.out.println(" Annotation is Req(\"" + param + "\")");
} else if (((DataConstructorExp) spec).getDataConstructor().getName().equals("List")) {
int arity = Integer.parseInt(((IntLiteral) ((DataConstructorExp) spec).getParam(0)).getContent());
info.addList(param, arity);
System.out.println(" Annotation is List(\"" + port + "\", " + arity + ")");
} else if (((DataConstructorExp) spec).getDataConstructor().getName().equals("OptList")) {
String value = ((StringLiteral) ((DataConstructorExp) spec).getParam(0)).getContent();
info.addOptList(param, value);
System.out.println(" Annotation is OptList(\"" + port + "\", " + value + ")");
} else if (((DataConstructorExp) spec).getDataConstructor().getName().equals("Default")) {
System.out.print("Default");
String value = ((StringLiteral) ((DataConstructorExp) spec).getParam(0)).getContent();
if (port != null)
System.out.print("(\"" + port + "\", " + value + ")");
info.addDefault(param, value);
System.out.println(" Annotation is Default(\"" + port + "\", " + value + ")");
} else if (((DataConstructorExp) spec).getDataConstructor().getName().equals("User")) {
System.out.print("User");
if (port != null)
System.out.print("(\"" + port + "\")");
info.addUser(param, port);
System.out.println(" Annotation is User(\"" + port + "\", " + param + ")");
}
}
}
_spec.add(info);
}
Aggregations