use of org.abs_models.frontend.analyser.TypeError in project abstools by abstools.
the class TypeCheckerHelper method typeCheckProductDecl.
public static void typeCheckProductDecl(ProductDecl prod, Map<String, Feature> featureNames, Set<String> prodNames, Map<String, DeltaDecl> deltaNames, SemanticConditionList e) {
if (featureNames != null) {
// Do the features exist in the PL declaration (and also check feature attributes)?
Model m = prod.getModel();
for (Feature f : prod.getProduct().getFeatures()) {
if (!featureNames.containsKey(f.getName()))
e.add(new TypeError(prod, ErrorMessage.NAME_NOT_RESOLVABLE, f.getName()));
else {
Collection<DeltaClause> dcs = findDeltasForFeature(m, f);
for (int i = 0; i < f.getNumAttrAssignment(); i++) {
AttrAssignment aa = f.getAttrAssignment(i);
for (DeltaClause dc : dcs) {
DeltaDecl dd = m.findDelta(dc.getDeltaspec().getDeltaID());
DeltaParamDecl dp = dd.getParam(i);
// not used by this delta).
if (dp != null && !dp.accepts(aa.getValue())) {
e.add(new TypeError(aa, ErrorMessage.CANNOT_ASSIGN, aa.getValue().getName(), dp.getType().getSimpleName()));
}
}
}
}
}
}
// Check the right side of product expression that contains in prodNames
Set<String> productNames = new HashSet<>();
prod.getProductExpr().setRightSideProductNames(productNames);
for (String productName : productNames) {
if (!prodNames.contains(productName)) {
e.add(new TypeError(prod, ErrorMessage.UNDECLARED_PRODUCT, productName));
}
}
// Check solution from getProduct()
if (prod.getProduct() != null) {
java.util.List<String> errors = prod.getModel().instantiateCSModel().checkSolutionWithErrors(prod.getProduct().getSolution(), prod.getModel());
if (!errors.isEmpty()) {
String failedConstraints = "";
for (String s : errors) failedConstraints += "\n- " + s;
e.add(new TypeError(prod, ErrorMessage.INVALID_PRODUCT, prod.getName(), failedConstraints));
}
}
}
use of org.abs_models.frontend.analyser.TypeError in project abstools by abstools.
the class TypeCheckerHelper method checkForDuplicateModulesAndDeltas.
/**
* check a list of compilation units for duplicate module names, product names, delta names
*/
public static void checkForDuplicateModulesAndDeltas(SemanticConditionList errors, Iterable<CompilationUnit> compilationUnits) {
Map<String, ModuleDecl> seenModules = new HashMap<>();
Map<String, DeltaDecl> seenDeltas = new HashMap<>();
for (CompilationUnit u : compilationUnits) {
for (ModuleDecl module : u.getModuleDecls()) {
if (seenModules.containsKey(module.getName())) {
ModuleDecl prev = seenModules.get(module.getName());
String location = "";
if (!prev.getFileName().equals(Main.UNKNOWN_FILENAME)) {
location = " at " + prev.getFileName() + ":" + prev.getStartLine() + ":" + prev.getStartColumn();
}
errors.add(new TypeError(module, ErrorMessage.DUPLICATE_MODULE_NAME, module.getName(), location));
} else {
seenModules.put(module.getName(), module);
}
}
for (DeltaDecl d : u.getDeltaDecls()) {
if (seenModules.containsKey(d.getName())) {
ModuleDecl prev = seenModules.get(d.getName());
String location = "";
if (!prev.getFileName().equals(Main.UNKNOWN_FILENAME)) {
location = " at " + prev.getFileName() + ":" + prev.getStartLine() + ":" + prev.getStartColumn();
}
errors.add(new TypeError(d, ErrorMessage.DELTA_USES_NAME_OF_MODULE, d.getName(), location));
}
if (seenDeltas.containsKey(d.getName())) {
DeltaDecl prev = seenDeltas.get(d.getName());
String location = "";
if (!prev.getFileName().equals(Main.UNKNOWN_FILENAME)) {
location = " at " + prev.getFileName() + ":" + prev.getStartLine() + ":" + prev.getStartColumn();
}
errors.add(new TypeError(d, ErrorMessage.DUPLICATE_DELTA, d.getName(), location));
} else {
seenDeltas.put(d.getName(), d);
}
}
}
}
use of org.abs_models.frontend.analyser.TypeError in project abstools by abstools.
the class TypeCheckerHelper method checkForDuplicatesOfVarDecl.
/**
* checks whether the local variable v was already defined in the current function
*/
public static void checkForDuplicatesOfVarDecl(SemanticConditionList e, VarDeclStmt v) {
String varName = v.getVarDecl().getName();
VarOrFieldDecl otherVar = v.lookupVarOrFieldName(varName, false);
if (otherVar != null && v.inSameMethodOrBlock(otherVar)) {
String location = "";
if (!otherVar.getFileName().equals(Main.UNKNOWN_FILENAME)) {
location = " at " + otherVar.getFileName() + ":" + otherVar.getStartLine() + ":" + otherVar.getStartColumn();
}
e.add(new TypeError(v, ErrorMessage.VARIABLE_ALREADY_DECLARED, varName, location));
}
}
use of org.abs_models.frontend.analyser.TypeError in project abstools by abstools.
the class TypeCheckerHelper method typeCheckEqual.
public static void typeCheckEqual(SemanticConditionList l, ASTNode<?> n, java.util.List<Type> params) {
org.abs_models.frontend.ast.List<PureExp> args = ((HasActualParams) n).getParams();
if (params.size() != args.getNumChild()) {
l.add(new TypeError(n, ErrorMessage.WRONG_NUMBER_OF_ARGS, params.size(), args.getNumChild()));
} else {
for (int i = 0; i < params.size(); i++) {
Type argType = params.get(i);
PureExp exp = args.getChild(i);
int nerrors = l.getErrorCount();
exp.typeCheck(l);
if (nerrors == l.getErrorCount()) {
Type expType = exp.getType();
if (!expType.isAssignableTo(argType)) {
l.add(new TypeError(exp, ErrorMessage.TYPE_MISMATCH, exp.getType(), argType));
}
}
}
}
}
use of org.abs_models.frontend.analyser.TypeError in project abstools by abstools.
the class TypeCheckerHelper method typeCheckEqualPattern.
private static void typeCheckEqualPattern(SemanticConditionList l, ConstructorPattern n, java.util.List<Type> params) {
org.abs_models.frontend.ast.List<Pattern> args = n.getParams();
if (params.size() != args.getNumChild()) {
l.add(new TypeError(n, ErrorMessage.WRONG_NUMBER_OF_ARGS, params.size(), args.getNumChild()));
} else {
for (int i = 0; i < params.size(); i++) {
Type argType = params.get(i);
Pattern exp = args.getChild(i);
exp.typeCheck(l, argType);
}
}
}
Aggregations