use of com.rockwellcollins.atc.agree.agree.InputStatement in project AGREE by loonwerks.
the class AgreeASTBuilder method getAgreeInputVars.
private GatheredVariablesAndConstraints getAgreeInputVars(List<SpecStatement> specs, ComponentInstance compInst) {
GatheredVariablesAndConstraints result = new GatheredVariablesAndConstraints();
for (SpecStatement spec : specs) {
if (spec instanceof InputStatement) {
EList<Arg> args = ((InputStatement) spec).getLhs();
List<VarDecl> vars = agreeVarsFromArgs(args, compInst);
for (VarDecl var : vars) {
result.variables.add((AgreeVar) var);
}
result.assertions.addAll(getConstraintsFromArgs(args, spec));
}
}
return result;
}
use of com.rockwellcollins.atc.agree.agree.InputStatement in project AGREE by loonwerks.
the class LustreAstBuilder method addNodeCall.
protected static void addNodeCall(AgreeNode agreeNode, List<AgreeStatement> assertions, String prefix, Expr clockExpr, Node lustreNode) {
List<Expr> inputIds = new ArrayList<>();
for (VarDecl var : lustreNode.inputs) {
String suffix = "";
// if this component implementation is using the latched semantics
if (agreeNode.timing == TimingModel.LATCHED) {
EObject ref = ((AgreeVar) var).reference;
if (ref instanceof DataPortImpl && ((DataPortImpl) ref).isIn() || (ref instanceof EventDataPortImpl && ((EventDataPortImpl) ref).isIn() || (ref instanceof Arg && ref.eContainer() instanceof InputStatement))) {
suffix = AgreeInlineLatchedConnections.LATCHED_SUFFIX;
}
}
inputIds.add(new IdExpr(prefix + var.id + suffix));
}
if (agreeNode.timing == TimingModel.ASYNC || agreeNode.timing == TimingModel.LATCHED) {
// the clock expr should be the last input to the node
inputIds.set(inputIds.size() - 1, clockExpr);
}
Expr condactExpr = new NodeCallExpr(lustreNode.id, inputIds);
AgreeStatement condactCall = new AgreeStatement("", condactExpr, null);
assertions.add(condactCall);
}
use of com.rockwellcollins.atc.agree.agree.InputStatement 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.InputStatement 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.InputStatement 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