use of org.abs_models.frontend.analyser.SemanticError in project abstools by abstools.
the class TypeCheckerHelper method typeCheck.
public static void typeCheck(ConstructorPattern p, SemanticConditionList e, Type t) {
DataConstructor c = p.getDataConstructor();
if (c == null) {
e.add(new SemanticError(p, ErrorMessage.CONSTRUCTOR_NOT_RESOLVABLE, p.getConstructor()));
return;
}
String cname = c.getQualifiedName();
if (deprecatedConstructors.contains(cname) && !(cname.startsWith(p.getModuleDecl().getName()))) {
e.add(new SemanticWarning(p, ErrorMessage.DEPRECATED_CONSTRUCTOR, cname));
}
if (c.getNumConstructorArg() != p.getNumParam()) {
e.add(new TypeError(p, ErrorMessage.WRONG_NUMBER_OF_ARGS, c.getNumConstructorArg(), p.getNumParam()));
return;
}
// isExceptionType only for clarity, since exceptions are datatypes
assert t.isDataType() || t.isExceptionType() : t;
if (!t.isExceptionType()) {
if (!t.getDecl().equals(c.getDataTypeDecl())) {
e.add(new TypeError(p, ErrorMessage.WRONG_CONSTRUCTOR, t.toString(), p.getConstructor()));
}
}
Type myType = p.getType();
if (!(myType instanceof DataTypeType))
return;
if (!(t instanceof DataTypeType)) {
e.add(new TypeError(p, ErrorMessage.TYPE_MISMATCH, myType, t));
return;
}
DataTypeType myDType = (DataTypeType) myType;
DataTypeType otherType = (DataTypeType) t;
if (!myDType.getDecl().equals(otherType.getDecl())) {
e.add(new TypeError(p, ErrorMessage.TYPE_MISMATCH, myDType, t));
return;
}
typeCheckMatchingParamsPattern(e, p, c);
}
use of org.abs_models.frontend.analyser.SemanticError in project abstools by abstools.
the class ProductLineAnalysisHelper method wellFormedProductLine.
/*
* Check that the 'productline' declaration is well formed. This means...
* - after clauses do not reference any deltaIDs that do not have their own delta clause
* - deltas named in the productline correspond to actual DeltaDecls
*/
protected static boolean wellFormedProductLine(ProductLine pl, SemanticConditionList e) {
boolean wellformed = true;
// preliminaries
final Set<String> declaredDeltas = pl.getModel().getDeltaDeclsMap().keySet();
final Set<String> referencedDeltas = new HashSet<>(pl.getDeltaClauses().getNumChild());
for (DeltaClause clause : pl.getDeltaClauses()) referencedDeltas.add(clause.getDeltaspec().getDeltaID());
// check
for (DeltaClause clause : pl.getDeltaClauses()) {
// ensure deltas in the productline correspond to actual DeltaDecls
if (!declaredDeltas.contains(clause.getDeltaspec().getDeltaID())) {
e.add(new SemanticError(clause, ErrorMessage.NO_DELTA_DECL, clause.getDeltaspec().getDeltaID()));
wellformed = false;
}
// ensure 'after' clauses do not reference any deltaIDs that do not have their own delta clause
for (DeltaID id : clause.getAfterDeltaIDs()) {
String afterID = id.getName();
if (!referencedDeltas.contains(afterID)) {
e.add(new SemanticError(clause, ErrorMessage.MISSING_DELTA_CLAUSE_ERROR, afterID, pl.getName()));
wellformed = false;
}
}
}
return wellformed;
}
Aggregations