use of org.abs_models.common.WrongProgramArgumentException in project abstools by abstools.
the class ABSTest method assertParseFilesOk.
protected Model assertParseFilesOk(Set<String> fileNames, Config... config) throws IOException, InternalBackendException, DeltaModellingException, WrongProgramArgumentException {
Main main = new Main();
java.util.List<File> files = fileNames.stream().map(f -> new File(resolveFileName(f))).collect(Collectors.toList());
Model m = main.parse(files);
return assertParseModelOk(m, config);
}
use of org.abs_models.common.WrongProgramArgumentException 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.common.WrongProgramArgumentException in project abstools by abstools.
the class CheckSPLCommand method analyzeMTVL.
private void analyzeMTVL(Model m) {
if (m.hasMTVL()) {
if (solve) {
if (parent.verbose)
System.out.println("Searching for solutions for the feature model...");
ChocoSolver s = m.instantiateCSModel();
System.out.print(s.getSolutionsAsString());
}
if (minimise != null) {
if (parent.verbose)
System.out.println("Searching for minimum solutions of " + minimise + " for the feature model...");
ChocoSolver s = m.instantiateCSModel();
System.out.print(s.minimiseToString(minimise));
}
if (maximise != null) {
if (parent.verbose)
System.out.println("Searching for maximum solutions of " + maximise + " for the feature model...");
ChocoSolver s = m.instantiateCSModel();
// System.out.print(s.maximiseToInt(product));
s.addConstraint(ChocoSolver.eqeq(s.vars.get(maximise), s.maximiseToInt(maximise)));
ChocoSolver s1 = m.instantiateCSModel();
int i = 1;
while (s1.solveAgain()) {
System.out.println("------ " + (i++) + "------");
System.out.print(s1.getSolutionsAsString());
}
}
if (solveall) {
if (parent.verbose)
System.out.println("Searching for all solutions for the feature model...");
ChocoSolver solver = m.instantiateCSModel();
System.out.print(solver.getSolutionsAsString());
}
if (solveWithProduct != null) {
ProductDecl solveWithDecl = null;
try {
solveWithDecl = m.findProduct(solveWithProduct);
} catch (WrongProgramArgumentException e) {
// nothing to do
}
if (solveWithDecl != null) {
if (parent.verbose)
System.out.println("Searching for solution that includes " + solveWithProduct + "...");
ChocoSolver s = m.instantiateCSModel();
HashSet<Constraint> newcs = new HashSet<>();
solveWithDecl.getProduct().getProdConstraints(s.vars, newcs);
for (Constraint c : newcs) s.addConstraint(c);
System.out.println("checking solution:\n" + s.getSolutionsAsString());
} else {
System.out.println("Product '" + solveWithProduct + "' not found.");
}
}
if (minWith != null) {
ProductDecl minWithDecl = null;
try {
minWithDecl = m.findProduct(minWith);
} catch (WrongProgramArgumentException e) {
// nothing to do
}
if (minWithDecl != null) {
if (parent.verbose)
System.out.println("Searching for solution that includes " + minWith + "...");
ChocoSolver s = m.instantiateCSModel();
HashSet<Constraint> newcs = new HashSet<>();
s.addIntVar("difference", 0, 50);
m.getDiffConstraints(minWithDecl.getProduct(), s.vars, newcs, "difference");
for (Constraint c : newcs) s.addConstraint(c);
System.out.println("checking solution: " + s.minimiseToString("difference"));
} else {
System.out.println("Product '" + minWith + "' not found.");
}
}
if (maxProduct) {
if (parent.verbose)
System.out.println("Searching for solution with maximum number of features ...");
ChocoSolver s = m.instantiateCSModel();
HashSet<Constraint> newcs = new HashSet<>();
s.addIntVar("noOfFeatures", 0, 50);
if (m.getMaxConstraints(s.vars, newcs, "noOfFeatures")) {
for (Constraint c : newcs) s.addConstraint(c);
System.out.println("checking solution: " + s.maximiseToString("noOfFeatures"));
} else {
System.out.println("---No solution-------------");
}
}
if (checkProduct != null) {
ProductDecl checkProductDecl = null;
try {
checkProductDecl = m.findProduct(checkProduct);
} catch (WrongProgramArgumentException e) {
// nothing to do
}
if (checkProductDecl == null) {
System.out.println("Product '" + checkProduct + "' not found, cannot check.");
} else {
ChocoSolver s = m.instantiateCSModel();
Map<String, Integer> guess = checkProductDecl.getProduct().getSolution();
System.out.println("checking solution: " + s.checkSolution(guess, m));
}
}
if (numbersol) {
ChocoSolver s = m.instantiateCSModel();
// did we call m.dropAttributes() previously?
if (ignoreattr) {
System.out.println("Number of solutions found (without attributes): " + s.countSolutions());
} else {
System.out.println("Number of solutions found: " + s.countSolutions());
}
}
}
}
Aggregations