use of org.osate.aadl2.NamedElement in project AGREE by loonwerks.
the class AgreeValidator method checkEventExpr.
@Check(CheckType.FAST)
public void checkEventExpr(EventExpr event) {
if (isInLinearizationBody(event)) {
error(event, "'event' expressions not allowed in linearization body expressions");
return;
}
Expr expr = event.getPort();
NamedElement namedEl = null;
if (expr instanceof NamedElmExpr) {
namedEl = ((NamedElmExpr) expr).getElm();
} else if (expr instanceof SelectionExpr) {
namedEl = ((SelectionExpr) expr).getField();
}
if (namedEl == null || !(namedEl instanceof EventPort || namedEl instanceof EventDataPort)) {
error(event, "Argument of event expression must be an event port or event data port");
}
}
use of org.osate.aadl2.NamedElement 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.NamedElement 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 org.osate.aadl2.NamedElement 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;
}
use of org.osate.aadl2.NamedElement 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