use of org.abs_models.frontend.ast.ClassModifier in project abstools by abstools.
the class ProductLineAnalysisHelper method isStronglyUnambiguous.
/*
* A product line is strongly unambiguous if each set in the partition of
* the delta modules specified in the product-line declaration is
* consistent, that is, if one delta module in a set adds or removes a
* class, no other delta module in the same set may add, remove or modify
* the same class, and the modifications of the same class in different
* delta modules in the same set have to be disjoint.
*/
public static boolean isStronglyUnambiguous(ProductLine pl, SemanticConditionList errors) {
boolean result = true;
Model model = pl.getModel();
/*
System.out.print("Delta partition: ");
for (Set<String> set : pl.getDeltaPartition()) {
System.out.print("{");
for (String el : set)
System.out.print(" " + el + " ");
System.out.print("} ");
}
System.out.println();
*/
assert pl.getDeltaPartition() != null;
for (Set<String> set : pl.getDeltaPartition()) {
// Remember the names of classes and methods modified by deltas in
// current set
// { Module.Class -> { Method -> Delta } }
// { Module.Class -> { "CLASS" -> Delta } }
Map<String, Map<String, String>> cache = new HashMap<>();
for (String deltaID : set) {
// assumes the DeltaDecl corresponding to deltaID exists (wellFormedProductLine)
DeltaDecl delta = model.getDeltaDeclsMap().get(deltaID);
assert delta.getModuleModifiers() != null;
for (ModuleModifier moduleModifier : delta.getModuleModifiers()) {
if (moduleModifier instanceof ModifyClassModifier) {
// String methodID;
String prefix = ((ClassModifier) moduleModifier).getQualifiedName();
for (Modifier mod : ((ModifyClassModifier) moduleModifier).getModifiers()) {
if (mod instanceof DeltaTraitModifier) {
HashSet<String> methodIDSet = new HashSet<>();
((DeltaTraitModifier) mod).collectMethodIDs(methodIDSet, model);
for (String methodID : methodIDSet) {
if (cache.containsKey(prefix)) {
if (cache.get(prefix).containsKey(methodID)) {
result = false;
String otherDeltaID = cache.get(prefix).get(methodID);
if (!deltaID.equals(otherDeltaID))
errors.add(new TypeError(pl, ErrorMessage.AMBIGUOUS_PRODUCTLINE, pl.getName(), deltaID, otherDeltaID, prefix + ", method " + methodID));
else
// FIXME also a kind of ambiguity but needs a different error message
;
} else if (cache.get(prefix).containsKey("CLASS")) {
result = false;
String otherDeltaID = cache.get(prefix).get("CLASS");
if (!deltaID.equals(otherDeltaID))
errors.add(new TypeError(pl, ErrorMessage.AMBIGUOUS_PRODUCTLINE, pl.getName(), deltaID, otherDeltaID, prefix));
else
// FIXME also a kind of ambiguity but needs a different error message
;
} else {
cache.get(prefix).put(methodID, deltaID);
}
} else {
cache.put(prefix, new HashMap<>());
cache.get(prefix).put(methodID, deltaID);
}
}
}
}
} else if (moduleModifier instanceof AddClassModifier || moduleModifier instanceof RemoveClassModifier) {
String prefix = ((ClassModifier) moduleModifier).getQualifiedName();
if (cache.containsKey(prefix)) {
result = false;
assert !cache.get(prefix).isEmpty();
String otherDeltaID = cache.get(prefix).values().iterator().next();
errors.add(new TypeError(pl, ErrorMessage.AMBIGUOUS_PRODUCTLINE, pl.getName(), deltaID, otherDeltaID, prefix));
System.out.println("3 ambiguity due to " + deltaID + "<>" + otherDeltaID);
} else {
cache.put(prefix, new HashMap<>());
cache.get(prefix).put("CLASS", deltaID);
}
}
}
// TODO apply same reasoning to other elements: fields,
// functions, ADTs, etc
}
}
// TODO remove boolean result unless needed
return result;
}
Aggregations