use of com.rockwellcollins.atc.agree.agree.EnumStatement in project AGREE by loonwerks.
the class AgreeValidator method getEnumValueDefLocation.
private String getEnumValueDefLocation(NamedID id) {
EObject container = id.eContainer();
EnumStatement enumStatement = (EnumStatement) container;
String enumName = enumStatement.getName();
while (!(container instanceof AadlPackage) && !(container instanceof ComponentClassifier)) {
container = container.eContainer();
}
return ((NamedElement) container).getQualifiedName() + "::" + enumName;
}
use of com.rockwellcollins.atc.agree.agree.EnumStatement 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 com.rockwellcollins.atc.agree.agree.EnumStatement in project AGREE by loonwerks.
the class AgreeTypeSystem method typeDefFromNE.
public static TypeDef typeDefFromNE(NamedElement ne) {
if (ne instanceof Classifier) {
return typeDefFromClassifier((Classifier) ne);
} else if (ne instanceof RecordDef) {
EList<Arg> args = ((RecordDef) ne).getArgs();
Map<String, TypeDef> fields = new HashMap<>();
for (Arg arg : args) {
String key = arg.getName();
TypeDef typeDef = typeDefFromType(arg.getType());
fields.put(key, typeDef);
}
return new RecordTypeDef(ne.getQualifiedName(), fields, ne);
} else if (ne instanceof EnumStatement) {
String name = ne.getQualifiedName();
List<String> enumValues = new ArrayList<String>();
for (NamedID nid : ((EnumStatement) ne).getEnums()) {
String enumValue = name + "_" + nid.getName();
enumValues.add(enumValue);
}
return new EnumTypeDef(name, enumValues, ne);
} else if (ne instanceof Arg) {
return typeDefFromType(((Arg) ne).getType());
} else {
return Prim.ErrorTypeDef;
}
}
use of com.rockwellcollins.atc.agree.agree.EnumStatement in project AGREE by loonwerks.
the class AgreeLinkingService method getElm.
private Element getElm(EObject context, EReference reference, String name) {
String[] segments = name.split("::");
if (segments.length >= 2) {
String pkgName = String.join("::", Arrays.copyOf(segments, segments.length - 1));
String statementName = segments[segments.length - 1];
Namespace namespace = AadlUtil.getContainingTopLevelNamespace(context);
PropertySet propSet = AadlUtil.findImportedPropertySet(pkgName, namespace);
if (propSet != null) {
Element elm = propSet.findNamedElement(statementName);
return elm;
}
AadlPackage aadlPackage = AadlUtil.findImportedPackage(pkgName, namespace);
if (aadlPackage == null) {
for (PackageRename rename : EcoreUtil2.getAllContentsOfType(namespace.getElementRoot(), PackageRename.class)) {
if (rename.getName() != null && pkgName.equals(rename.getName())) {
aadlPackage = rename.getRenamedPackage();
}
}
}
if (aadlPackage != null) {
for (AnnexLibrary annex : AnnexUtil.getAllActualAnnexLibraries(aadlPackage, AgreePackage.eINSTANCE.getAgreeContractLibrary())) {
AgreeContract contract = (AgreeContract) ((AgreeContractLibrary) annex).getContract();
for (SpecStatement spec : contract.getSpecs()) {
if (spec instanceof RecordDef) {
if (((RecordDef) spec).getName().equals(statementName)) {
return (spec);
}
} else if (spec instanceof FnDef) {
if (((FnDef) spec).getName().equals(statementName)) {
return (spec);
}
} else if (spec instanceof LibraryFnDef) {
if (((LibraryFnDef) spec).getName().equals(statementName)) {
return (spec);
}
} else if (spec instanceof UninterpretedFnDef) {
if (((UninterpretedFnDef) spec).getName().equals(statementName)) {
return (spec);
}
} else if (spec instanceof NodeDef) {
if (((NodeDef) spec).getName().equals(statementName)) {
return (spec);
}
} else if (spec instanceof LinearizationDef) {
if (((LinearizationDef) spec).getName().equals(statementName)) {
return (spec);
}
} else if (spec instanceof ConstStatement) {
if (((ConstStatement) spec).getName().equals(statementName)) {
return (spec);
}
} else if (spec instanceof EnumStatement) {
if (((EnumStatement) spec).getName().equals(statementName)) {
return (spec);
}
EList<NamedID> enums = ((EnumStatement) spec).getEnums();
for (NamedID nid : enums) {
if (nid.getName().contentEquals(statementName)) {
return nid;
}
}
}
}
}
}
}
return null;
}
use of com.rockwellcollins.atc.agree.agree.EnumStatement in project AGREE by loonwerks.
the class AgreeScopeProvider method getNamedElementsFromSpecs.
private Map<String, NamedElement> getNamedElementsFromSpecs(EList<SpecStatement> specs) {
Map<String, NamedElement> nelms = new HashMap<>();
for (SpecStatement spec : specs) {
if (spec instanceof NamedElement) {
nelms.put(((NamedElement) spec).getName(), (NamedElement) spec);
}
if (spec instanceof EqStatement) {
EqStatement eq = (EqStatement) spec;
ArrayList<NamedElement> nes = new ArrayList<>();
nes.addAll(eq.getLhs());
nelms.putAll(toNamedElementMap(nes));
} else if (spec instanceof ConstStatement) {
ConstStatement c = (ConstStatement) spec;
nelms.put(c.getName(), c);
} else if (spec instanceof InputStatement) {
ArrayList<NamedElement> nes = new ArrayList<>();
nes.addAll(((InputStatement) spec).getLhs());
nelms.putAll(toNamedElementMap(nes));
} else if (spec instanceof EnumStatement) {
ArrayList<NamedElement> nes = new ArrayList<>();
nes.addAll(((EnumStatement) spec).getEnums());
nelms.putAll(toNamedElementMap(nes));
}
}
return nelms;
}
Aggregations