use of org.osate.aadl2.NamedElement in project AGREE by loonwerks.
the class AgreeValidator method checkNamedElement.
@Check(CheckType.FAST)
public void checkNamedElement(NamedElement namedEl) {
// check for namespace collision in component types of component
// implementations
// and for collisions between subcomponent and feature names
EObject container = namedEl.eContainer();
if (container == null) {
return;
}
if (container instanceof RecordDef || container instanceof NodeDef) {
// TODO: perhaps we can ignore all arguments?
return;
}
while (!(container instanceof AadlPackage || container instanceof ComponentImplementation || container instanceof ComponentType)) {
container = container.eContainer();
}
ComponentImplementation compImpl = null;
ComponentType type = null;
if (container instanceof ComponentImplementation) {
compImpl = (ComponentImplementation) container;
type = compImpl.getType();
checkDupNames(namedEl, type, compImpl);
} else if (container instanceof ComponentType) {
type = (ComponentType) container;
}
if (type != null && (namedEl.getName() != null)) {
for (Feature feat : type.getAllFeatures()) {
if (namedEl.getName().equals(feat.getName())) {
error(feat, "Element of the same name ('" + namedEl.getName() + "') in AGREE Annex in '" + (compImpl == null ? type.getName() : compImpl.getName()) + "'");
error(namedEl, "Feature of the same name ('" + namedEl.getName() + "') in component type");
}
}
}
// check name space collision with enumerated types
}
use of org.osate.aadl2.NamedElement in project AGREE by loonwerks.
the class AgreeValidator method checkOrderStatement.
@Check(CheckType.FAST)
public void checkOrderStatement(OrderStatement order) {
Classifier container = order.getContainingClassifier();
if (container instanceof ComponentImplementation) {
ComponentImplementation compImpl = (ComponentImplementation) container;
for (int index = 0; index < order.getComps().size(); ++index) {
NamedElement comp = order.getComps().get(index);
if (!(comp instanceof Subcomponent) || !((Subcomponent) comp).getContainingComponentImpl().equals(container)) {
error("Element '" + comp.getName() + "' is not a subcomponent of '" + container.getName() + "'", order, AgreePackage.Literals.ORDER_STATEMENT__COMPS, index);
}
}
List<NamedElement> notPresent = new ArrayList<>();
for (Subcomponent subcomp : compImpl.getAllSubcomponents()) {
boolean found = false;
for (NamedElement el : order.getComps()) {
if (el.equals(subcomp)) {
found = true;
break;
}
}
if (!found) {
notPresent.add(subcomp);
}
}
if (notPresent.size() != 0) {
String delim = "";
StringBuilder errorStr = new StringBuilder("The following subcomponents are not present in the ordering: ");
for (NamedElement subcomp : notPresent) {
errorStr.append(delim);
errorStr.append(subcomp.getName());
delim = ", ";
}
error(order, errorStr.toString());
}
} else {
error(order, "Ordering statements can appear only in component implementations");
}
}
use of org.osate.aadl2.NamedElement in project AGREE by loonwerks.
the class AgreeValidator method checkArg.
@Check(CheckType.FAST)
public void checkArg(Arg arg) {
Type type = arg.getType();
if (type instanceof PrimType) {
PrimType primType = (PrimType) type;
String strType = primType.getName();
String rangeLow = primType.getRangeLow();
String rangeHigh = primType.getRangeHigh();
if (rangeLow != null && rangeHigh != null) {
// this is a ranged argument. It can show up only in an equation statement
EObject container = arg.eContainer();
if (!(container instanceof EqStatement || container instanceof InputStatement)) {
error(arg, "Ranged arguments can appear only in equation statements or agree_input statements");
}
boolean rangeLowDot = rangeLow.contains(".");
boolean rangeHighDot = rangeHigh.contains(".");
if (rangeLowDot != rangeHighDot) {
error(arg, "The range intervals are of differing types");
}
if (strType.equals("int") && (rangeLowDot || rangeHighDot)) {
error(arg, "Ranged variable of type 'int' contains a 'real' value in its interval");
}
if (strType.equals("real") && (!rangeLowDot || !rangeHighDot)) {
error(arg, "Ranged variable of type 'real' contains an 'int' value in its interval");
}
float low = Float.valueOf(rangeLow);
float high = Float.valueOf(rangeHigh);
low *= primType.getLowNeg() == null ? 1.0 : -1.0;
high *= primType.getHighNeg() == null ? 1.0 : -1.0;
if (low >= high) {
error(arg, "The low value of the interval is greater than or equal to the high end");
}
}
} else if (type instanceof DoubleDotRef) {
DoubleDotRef recType = (DoubleDotRef) type;
NamedElement finalId = recType.getElm();
if (!(finalId instanceof DataImplementation) && !(finalId instanceof RecordDef) && !(finalId instanceof DataType) && !(finalId instanceof EnumStatement)) {
error(recType, "types must be record definition, array definition, data implementation, enumeration, or datatype");
}
if (finalId instanceof DataImplementation) {
if (AgreeTypeSystem.typesEqual(AgreeTypeSystem.typeDefFromType(recType), AgreeTypeSystem.Prim.ErrorTypeDef)) {
error(recType, "Data Implementations with no subcomponents must extend" + " a Base_Type that AGREE can reason about.");
return;
}
if (((DataImplementation) finalId).getAllSubcomponents().size() != 0) {
if (AgreeTypeSystem.typesEqual(AgreeTypeSystem.typeDefFromType(recType), AgreeTypeSystem.Prim.BoolTypeDef) || AgreeTypeSystem.typesEqual(AgreeTypeSystem.typeDefFromType(recType), AgreeTypeSystem.Prim.IntTypeDef) || AgreeTypeSystem.typesEqual(AgreeTypeSystem.typeDefFromType(recType), AgreeTypeSystem.Prim.RealTypeDef)) {
error(finalId, "Data implementations with subcomponents cannot be" + " interpreted by AGREE if they extend Base_Types");
}
}
// dataImplCycleCheck(recId);
return;
}
if (finalId instanceof DataType) {
if (AgreeTypeSystem.typesEqual(AgreeTypeSystem.typeDefFromType(recType), AgreeTypeSystem.Prim.ErrorTypeDef)) {
error(recType, "AADL Datatypes must extend" + " a Base_Type that AGREE can reason about.");
return;
}
}
}
}
use of org.osate.aadl2.NamedElement in project AGREE by loonwerks.
the class AgreeValidator method checkMultiAssignEq.
private void checkMultiAssignEq(EObject src, List<Arg> lhsArgs, Expr rhsExpr) {
if (rhsExpr == null) {
return;
}
if (lhsArgs.size() == 1) {
// we should only need to check for cycles for single equations
String name = lhsArgs.get(0).getName();
ExprCycleVisitor cycleVisitor = new ExprCycleVisitor(name);
Set<EObject> cycleObjects = cycleVisitor.doSwitch(rhsExpr);
if (cycleObjects == null) {
throw new IllegalArgumentException("something went wrong with the cycle checker");
}
for (EObject obj : cycleObjects) {
error(obj, "Cyclic reference to variable '" + name + "'");
}
}
if (argsContainRangeValue(lhsArgs)) {
error(src, "Equation statements cannot contain a ranged value and a right hand side expression");
}
List<TypeDef> agreeLhsTypes = new ArrayList<>();
for (Arg arg : lhsArgs) {
agreeLhsTypes.add(AgreeTypeSystem.typeDefFromType(arg.getType()));
}
List<TypeDef> agreeRhsTypes = new ArrayList<>();
if (rhsExpr instanceof CallExpr) {
NamedElement namedEl = ((CallExpr) rhsExpr).getRef().getElm();
if (namedEl instanceof NodeDef) {
NodeDef nodeDef = (NodeDef) namedEl;
for (Arg var : nodeDef.getRets()) {
agreeRhsTypes.add(AgreeTypeSystem.typeDefFromType(var.getType()));
}
} else if (namedEl instanceof FnDef) {
FnDef fnDef = (FnDef) namedEl;
agreeRhsTypes.add(AgreeTypeSystem.typeDefFromType(fnDef.getType()));
} else if (namedEl instanceof UninterpretedFnDef) {
UninterpretedFnDef uninterpretedFnDef = (UninterpretedFnDef) namedEl;
agreeRhsTypes.add(AgreeTypeSystem.typeDefFromType(uninterpretedFnDef.getType()));
} else {
// parse error
return;
}
} else {
checkTypeExists(rhsExpr);
TypeDef rhsType = AgreeTypeSystem.infer(rhsExpr);
agreeRhsTypes.add(rhsType);
}
if (agreeLhsTypes.size() != agreeRhsTypes.size()) {
error(src, "Equation assigns " + agreeLhsTypes.size() + " variables, but right side returns " + agreeRhsTypes.size() + " values");
return;
}
for (int i = 0; i < agreeLhsTypes.size(); i++) {
TypeDef lhsType = agreeLhsTypes.get(i);
TypeDef rhsType = agreeRhsTypes.get(i);
if (!AgreeTypeSystem.typesEqual(rhsType, lhsType)) {
error(src, "The variable '" + lhsArgs.get(i).getName() + "' on the left side of equation is of type '" + nameOfTypeDef(lhsType) + "' but must be of type '" + nameOfTypeDef(rhsType) + "'");
}
}
}
use of org.osate.aadl2.NamedElement in project AGREE by loonwerks.
the class AgreeValidator method checkNoDuplicateIdInSpec.
@Check(CheckType.NORMAL)
public void checkNoDuplicateIdInSpec(AadlPackage toppkg) {
// namedSpecs associates an agree spec ID with all the agree specs that have that ID
HashMultimap<String, NamedSpecStatement> namedSpecs = HashMultimap.create();
// Get the set of packages referenced in model
Set<AadlPackage> pkgs = new HashSet<>();
getPackageDependencies(toppkg, pkgs);
for (AadlPackage pkg : pkgs) {
// Get the list of agree specs in each package
List<NamedSpecStatement> specs = getNamedSpecStatements(pkg);
for (NamedSpecStatement spec : specs) {
String id = spec.getName();
if (id != null) {
namedSpecs.put(id, spec);
}
}
}
// Get the agree specs in the current package
List<NamedSpecStatement> specs = getNamedSpecStatements(toppkg);
Iterator<NamedSpecStatement> i = specs.iterator();
while (i.hasNext()) {
NamedSpecStatement spec = i.next();
String id = spec.getName();
// If the current spec name is associated with multiple agree specs, we've found a duplicate
if (namedSpecs.get(id).size() > 1) {
Iterator<NamedSpecStatement> ii = namedSpecs.get(id).iterator();
while (ii.hasNext()) {
String pkgName = AadlUtil.getContainingPackage(ii.next()).getName();
// // If the specs are from the same package, the error will be generated from the
// // NamedElement check.
// if (!pkgName.contentEquals(AadlUtil.getContainingPackage(spec).getName())) {
error("Duplicate AGREE property ID in package " + pkgName, spec, Aadl2Package.eINSTANCE.getNamedElement_Name());
// }
}
namedSpecs.removeAll(id);
}
}
}
Aggregations