use of org.osate.aadl2.DataImplementation in project AGREE by loonwerks.
the class AgreeValidator method getArgNames.
private List<NamedElement> getArgNames(DoubleDotRef recType) {
NamedElement rec = recType.getElm();
// =======
// private List<NamedElement> getArgNames(DoubleDotRef recId) {
//
// NamedElement rec = recId.getElm();
// >>>>>>> origin/develop
List<NamedElement> names = new ArrayList<>();
if (rec instanceof RecordDef) {
RecordDef recDef = (RecordDef) rec;
for (Arg arg : recDef.getArgs()) {
names.add(arg);
}
} else if (rec instanceof DataImplementation) {
DataImplementation dataImpl = (DataImplementation) rec;
for (Subcomponent sub : dataImpl.getAllSubcomponents()) {
names.add(sub);
}
} else {
error(recType, "Record type '" + rec.getName() + "' must be a feature group or a record type definition");
}
return names;
}
use of org.osate.aadl2.DataImplementation 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.DataImplementation in project AGREE by loonwerks.
the class AgreeValidator method getFieldTypes.
private Map<String, TypeDef> getFieldTypes(DoubleDotRef recType) {
NamedElement rec = recType.getElm();
Map<String, TypeDef> typeMap = new HashMap<>();
if (rec instanceof RecordDef) {
RecordDef recDef = (RecordDef) rec;
for (Arg arg : recDef.getArgs()) {
typeMap.put(arg.getName(), AgreeTypeSystem.typeDefFromType(arg.getType()));
}
} else if (rec instanceof DataImplementation) {
DataImplementation dataImpl = (DataImplementation) rec;
for (Subcomponent sub : dataImpl.getAllSubcomponents()) {
typeMap.put(sub.getName(), AgreeTypeSystem.typeDefFromClassifier((sub.getClassifier())));
}
} else {
error(recType, "Record type '" + rec.getName() + "' must be a feature group or a record type definition");
}
return typeMap;
}
use of org.osate.aadl2.DataImplementation in project AGREE by loonwerks.
the class AgreeValidator method checkRecordDefExpr.
// =======
// // private List<AgreeType> getArgTypes(NestedDotID recId){
// //
// // NamedElement rec = getFinalNestId(recId);
// // List<AgreeType> types = new ArrayList<AgreeType>();
// //
// // if(rec instanceof RecordDefExpr){
// // RecordDefExpr recDef = (RecordDefExpr)rec;
// // for(Arg arg : recDef.getArgs()){
// // types.add(getAgreeType(arg.getType()));
// // }
// // }else if(rec instanceof FeatureGroupType){
// // FeatureGroupType featGroup = (FeatureGroupType)rec;
// // for(Feature feat : featGroup.getAllFeatures()){
// // types.add(getAgreeType(feat));
// // }
// // }
// //
// // return types;
// // }
//
// private void dataImplCycleCheck(NestedDotID dataID) {
// NamedElement finalId = dataID.getBase();
// DataImplementation dataImpl = (DataImplementation) finalId;
// dataImplCycleCheck(dataImpl, dataID);
// }
//
// private void dataImplCycleCheck(DoubleDotRef dataID) {
// NamedElement finalId = dataID.getElm();
// DataImplementation dataImpl = (DataImplementation) finalId;
// dataImplCycleCheck(dataImpl, dataID);
// }
//
//
// private void dataImplCycleCheck(DataImplementation dataImpl, EObject errorSource) {
// Set<DataImplementation> dataClosure = new HashSet<>();
// Set<DataImplementation> prevClosure = null;
//
// for (Subcomponent sub : dataImpl.getAllSubcomponents()) {
// ComponentImplementation subImpl = sub.getComponentImplementation();
// if (subImpl != null) {
// dataClosure.add((DataImplementation) subImpl);
// }
// }
//
// do {
// prevClosure = new HashSet<>(dataClosure);
// for (DataImplementation subImpl : prevClosure) {
// if (subImpl == dataImpl) {
// error(errorSource, "The component implementation '" + dataImpl.getName()
// + "' has a cyclic definition. This cannot be reasoned about by AGREE.");
// break;
// }
// for (Subcomponent subSub : subImpl.getAllSubcomponents()) {
// ComponentImplementation subSubImpl = subSub.getComponentImplementation();
// if (subSubImpl != null) {
// dataClosure.add((DataImplementation) subSubImpl);
// }
// }
//
// }
//
// } while (!prevClosure.equals(dataClosure));
//
// }
// >>>>>>> origin/develop
@Check(CheckType.FAST)
public void checkRecordDefExpr(RecordDef recordDef) {
Set<RecordDef> recordClosure = new HashSet<>();
Set<RecordDef> prevClosure = null;
for (Arg arg : recordDef.getArgs()) {
Type type = arg.getType();
if (type instanceof DoubleDotRef) {
NamedElement finalId = ((DoubleDotRef) type).getElm();
if (finalId instanceof RecordDef) {
recordClosure.add((RecordDef) finalId);
}
}
}
do {
prevClosure = new HashSet<>(recordClosure);
for (RecordDef subRecDef : prevClosure) {
if (subRecDef == recordDef) {
error(recordDef, "The definition of type '" + recordDef.getName() + "' is involved in a cyclic definition");
break;
}
for (Arg arg : subRecDef.getArgs()) {
Type type = arg.getType();
if (type instanceof DoubleDotRef) {
NamedElement subFinalEl = ((DoubleDotRef) type).getElm();
if (subFinalEl instanceof RecordDef) {
recordClosure.add((RecordDef) subFinalEl);
// =======
// if (type instanceof RecordType) {
// DoubleDotRef subRecId = ((RecordType) type).getRecord();
// NamedElement subFinalEl = subRecId.getElm();
// if (subFinalEl instanceof RecordDefExpr) {
// recordClosure.add((RecordDefExpr) subFinalEl);
// >>>>>>> origin/develop
}
}
}
}
} while (!prevClosure.equals(recordClosure));
}
use of org.osate.aadl2.DataImplementation in project AGREE by loonwerks.
the class AgreeScopeProvider method getNamedElements.
private Map<String, NamedElement> getNamedElements(EObject ctx) {
Map<String, NamedElement> components = new HashMap<>();
if (ctx instanceof AadlPackage) {
components.put(((AadlPackage) ctx).getName(), (AadlPackage) ctx);
PublicPackageSection pubSec = ((AadlPackage) ctx).getPublicSection();
for (Element el : pubSec.getOwnedElements()) {
if (el instanceof DataImplementation || el instanceof DataType) {
components.put(((NamedElement) el).getName(), (NamedElement) el);
}
}
for (AnnexLibrary annex : AnnexUtil.getAllActualAnnexLibraries(((AadlPackage) ctx), AgreePackage.eINSTANCE.getAgreeContractLibrary())) {
AgreeContract contract = (AgreeContract) ((AgreeContractLibrary) annex).getContract();
components.putAll(getNamedElementsFromSpecs(contract.getSpecs()));
}
} else {
components.putAll(getNamedElementsFromClassifier((Classifier) ctx, false));
}
return components;
}
Aggregations