use of org.abs_models.frontend.ast.Decl in project abstools by abstools.
the class AbstractPartialFunctionTest method assertHasFunction.
protected FunctionDecl assertHasFunction(Model model, String regex) {
FunctionDecl result = getFunction(model, Pattern.compile(regex));
String errorMessage = "No expanded function with name " + regex + " created" + " (functions: " + getFunctions(model) + ")";
assertNotNull(errorMessage, result);
Decl decl = model.lookup(new KindedName(KindedName.Kind.FUN, result.getName()));
assertFalse("Could not lookup function " + result.getName(), decl.isUnknown());
return result;
}
use of org.abs_models.frontend.ast.Decl in project abstools by abstools.
the class DeltaAddFunctionalTest method addTypeSyn.
@Test
public void addTypeSyn() throws DeltaModellingException {
Model model = assertParse("module M;" + "type X = Int;" + "delta I; uses M;" + "adds type Y = X;");
Decl typeX = findDecl(model, "M", "X");
assertNotNull(typeX);
assertThat(typeX, instanceOf(TypeSynDecl.class));
DeltaDecl delta = findDelta(model, "I");
assertNotNull(delta);
assertThat(delta, instanceOf(DeltaDecl.class));
Decl typeY = findDecl(model, "M", "Y");
assertNull(typeY);
model.applyDelta(delta);
typeY = findDecl(model, "M", "Y");
assertNotNull(typeY);
assertThat(typeY, instanceOf(TypeSynDecl.class));
}
use of org.abs_models.frontend.ast.Decl in project abstools by abstools.
the class DeltaAddFunctionalTest method addDataType.
@Test
public void addDataType() throws DeltaModellingException {
Model model = assertParse("module M;" + "data O = O;" + "delta I; uses M;" + "adds data X<A> = X(A a) | N;" + "adds data Y = K | Y(Int i);");
Decl dataO = findDecl(model, "M", "O");
assertNotNull(dataO);
assertThat(dataO, instanceOf(DataTypeDecl.class));
DeltaDecl delta = findDelta(model, "I");
assertNotNull(delta);
assertThat(delta, instanceOf(DeltaDecl.class));
Decl dataX = findDecl(model, "M", "X");
assertNull(dataX);
Decl dataY = findDecl(model, "M", "Y");
assertNull(dataY);
model.applyDelta(delta);
dataX = findDecl(model, "M", "X");
assertNotNull(dataX);
assertThat(dataX, instanceOf(ParametricDataTypeDecl.class));
dataY = findDecl(model, "M", "Y");
assertNotNull(dataY);
assertThat(dataY, instanceOf(DataTypeDecl.class));
}
use of org.abs_models.frontend.ast.Decl 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.Decl in project abstools by abstools.
the class DeltaAddFunctionalTest method addFun.
@Test
public void addFun() throws DeltaModellingException {
Model model = assertParse("module M;" + "def Int i() = 1;" + "delta I; uses M;" + "adds def Int j<A>(A a) = 2;" + "adds def Int h() = 2;");
Decl funI = findDecl(model, "M", "i");
assertNotNull(funI);
assertThat(funI, instanceOf(FunctionDecl.class));
DeltaDecl delta = findDelta(model, "I");
assertNotNull(delta);
assertThat(delta, instanceOf(DeltaDecl.class));
Decl funj = findDecl(model, "M", "j");
assertNull(funj);
Decl funh = findDecl(model, "M", "h");
assertNull(funh);
model.applyDelta(delta);
funj = findDecl(model, "M", "j");
assertNotNull(funj);
assertThat(funj, instanceOf(FunctionDecl.class));
funh = findDecl(model, "M", "h");
assertNotNull(funh);
assertThat(funh, instanceOf(FunctionDecl.class));
}
Aggregations