use of com.rockwellcollins.atc.agree.agree.SpecStatement in project AGREE by loonwerks.
the class AgreeASTBuilder method getAssertionStatements.
private List<AgreeStatement> getAssertionStatements(EList<SpecStatement> specs) {
List<AgreeStatement> asserts = new ArrayList<>();
for (SpecStatement spec : specs) {
if (spec instanceof AssertStatement) {
AssertStatement assertState = (AssertStatement) spec;
String str = assertState.getStr();
if (assertState.getExpr() != null) {
asserts.add(new AgreeStatement(str, doSwitch(assertState.getExpr()), assertState));
} else {
PatternStatement pattern = assertState.getPattern();
asserts.add(new AgreePatternBuilder(str, assertState, this).doSwitch(pattern));
}
}
}
return asserts;
}
use of com.rockwellcollins.atc.agree.agree.SpecStatement in project AGREE by loonwerks.
the class AgreeValidator method checkLatchedExpr.
@Check(CheckType.FAST)
public void checkLatchedExpr(LatchedExpr latched) {
// get container
EObject container = latched.eContainer();
AgreeContract contract = null;
while (!(container instanceof ComponentClassifier)) {
if (container instanceof AgreeContract) {
contract = (AgreeContract) container;
}
container = container.eContainer();
}
if (container instanceof ComponentImplementation) {
boolean foundLatchedStatement = false;
for (SpecStatement spec : contract.getSpecs()) {
if (spec instanceof LatchedStatement) {
foundLatchedStatement = true;
break;
}
}
if (!foundLatchedStatement) {
error(latched, "Latched expressions can appear only in component implementations " + "that contain a latched synchrony statement");
}
} else {
error(latched, "Latched expressions can appear only in component implementations");
}
Expr expr = latched.getExpr();
Expr nestId = null;
if (expr instanceof NamedElmExpr) {
nestId = expr;
} else if (expr instanceof EventExpr) {
EventExpr eventExpr = (EventExpr) expr;
nestId = eventExpr.getPort();
}
if (nestId != null) {
NamedElement namedEl = null;
if (nestId instanceof NamedElmExpr) {
namedEl = ((NamedElmExpr) nestId).getElm();
} else if (nestId instanceof SelectionExpr) {
namedEl = ((SelectionExpr) nestId).getField();
}
if ((namedEl instanceof DataPort) && ((DataPort) namedEl).isIn()) {
return;
} else if ((namedEl instanceof EventDataPort) && ((EventDataPort) namedEl).isIn()) {
return;
} else {
// check to see if it is an "agree_input"
EObject namedElContainer = namedEl.eContainer();
if (namedElContainer instanceof InputStatement) {
return;
}
}
}
error(latched, "Latched expressions are valid only for input data ports or event expressions over input event data ports");
}
use of com.rockwellcollins.atc.agree.agree.SpecStatement in project AGREE by loonwerks.
the class AgreeValidator method checkNameOverlap.
@Check(CheckType.FAST)
public void checkNameOverlap(AgreeContract contract) {
Set<SynchStatement> syncs = new HashSet<>();
Set<InitialStatement> inits = new HashSet<>();
List<ConnectionStatement> conns = new ArrayList<>();
// check that there are zero or more synchrony statements
for (SpecStatement spec : contract.getSpecs()) {
if (spec instanceof SynchStatement) {
syncs.add((SynchStatement) spec);
} else if (spec instanceof CalenStatement) {
syncs.add((CalenStatement) spec);
} else if (spec instanceof InitialStatement) {
inits.add((InitialStatement) spec);
} else if (spec instanceof ConnectionStatement) {
conns.add((ConnectionStatement) spec);
}
}
if (syncs.size() > 1) {
for (SynchStatement sync : syncs) {
error(sync, "Multiple synchrony or calender statements in a single contract");
}
}
if (inits.size() > 1) {
for (InitialStatement init : inits) {
error(init, "Multiple initially statements in a single contract");
}
}
for (int i = 0; i < conns.size(); i++) {
ConnectionStatement connStat0 = conns.get(i);
NamedElement conn0 = connStat0.getConn();
for (int j = i + 1; j < conns.size(); j++) {
ConnectionStatement connStat1 = conns.get(j);
NamedElement conn1 = connStat1.getConn();
if (conn0 == null || conn1 == null) {
break;
}
if (conn0.equals(conn1)) {
error(connStat0, "Multiple connection overrides for connection: '" + conn0.getName() + "'");
error(connStat1, "Multiple connection overrides for connection: '" + conn1.getName() + "'");
}
}
}
ComponentImplementation ci = EcoreUtil2.getContainerOfType(contract, ComponentImplementation.class);
if (ci == null) {
return;
}
Set<String> parentNames = getParentNames(ci);
for (AgreeSubclause subclause : EcoreUtil2.getAllContentsOfType(ci, AgreeSubclause.class)) {
List<NamedElement> es = EcoreUtil2.getAllContentsOfType(subclause, NamedElement.class);
for (NamedElement e : es) {
if (!(e.eContainer() instanceof NodeDef || e instanceof NamedSpecStatement)) {
// ignore elements in node defs
if (parentNames.contains(e.getName())) {
// =======
// if (!(e.eContainer() instanceof NodeDefExpr)) { // ignore elements in node defs
// if (e.getName() != null && parentNames.contains(e.getName())) {
// >>>>>>> origin/develop
error(e, e.getName() + " already defined in component type contract");
}
}
}
}
}
use of com.rockwellcollins.atc.agree.agree.SpecStatement 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.SpecStatement 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