use of com.rockwellcollins.atc.agree.AgreeTypeSystem.TypeDef 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 com.rockwellcollins.atc.agree.AgreeTypeSystem.TypeDef in project AGREE by loonwerks.
the class AgreeValidator method checkLemma.
@Check(CheckType.FAST)
public void checkLemma(LemmaStatement lemma) {
Classifier comp = lemma.getContainingClassifier();
if (!(comp instanceof ComponentImplementation)) {
error(lemma, "Lemma statements are allowed only in component implementations and nodes");
}
Expr expr = lemma.getExpr();
if (expr != null) {
TypeDef exprType = AgreeTypeSystem.infer(expr);
if (!AgreeTypeSystem.typesEqual(AgreeTypeSystem.Prim.BoolTypeDef, exprType)) {
error(lemma, "Expression for lemma statement is of type '" + nameOfTypeDef(exprType) + "' but must be of type 'bool'");
}
}
if (lemma.getName() == null) {
info(lemma, "It is recommended that lemma statements be named." + " (Hint: an identifier may be placed between the \"lemma\" keyword and the quoted description.)");
}
}
use of com.rockwellcollins.atc.agree.AgreeTypeSystem.TypeDef in project AGREE by loonwerks.
the class AgreeValidator method checkWhenOccursStatment.
@Check(CheckType.FAST)
public void checkWhenOccursStatment(WhenOccursStatment when) {
Expr condition = when.getCondition();
Expr event = when.getEvent();
Expr times = when.getTimes();
checkExprIsIdentifier(condition);
checkExprIsIdentifier(event);
TypeDef type = AgreeTypeSystem.infer(condition);
if (!AgreeTypeSystem.typesEqual(AgreeTypeSystem.Prim.BoolTypeDef, type)) {
error(condition, "The condition of the 'when' statement is of type '" + type + "'" + " but must be of type 'bool'");
}
type = AgreeTypeSystem.infer(event);
if (!AgreeTypeSystem.typesEqual(AgreeTypeSystem.Prim.BoolTypeDef, type)) {
error(event, "The effect of the 'when' statement is of type '" + type + "'" + " but must be of type 'bool'");
}
type = AgreeTypeSystem.infer(times);
if (!AgreeTypeSystem.typesEqual(AgreeTypeSystem.Prim.IntTypeDef, type)) {
error(event, "The 'times' of the 'when' statement is of type '" + type + "'" + " but must be of type 'int'");
}
}
use of com.rockwellcollins.atc.agree.AgreeTypeSystem.TypeDef in project AGREE by loonwerks.
the class AgreeValidator method checkRealCast.
@Check(CheckType.FAST)
public void checkRealCast(RealCast real) {
if (isInLinearizationBody(real)) {
error(real, "'event' expressions not allowed in linearization body expressions");
return;
}
checkTypeExists(real.getExpr());
TypeDef exprType = AgreeTypeSystem.infer(real.getExpr());
if (!AgreeTypeSystem.typesEqual(AgreeTypeSystem.Prim.IntTypeDef, exprType)) {
error(real, "Argument of real cast is of type '" + nameOfTypeDef(exprType) + "' but must be of type 'int'");
}
}
use of com.rockwellcollins.atc.agree.AgreeTypeSystem.TypeDef in project AGREE by loonwerks.
the class AgreeValidator method checkWheneverOccursStatement.
@Check(CheckType.FAST)
public void checkWheneverOccursStatement(WheneverOccursStatement whenever) {
Expr cause = whenever.getCause();
Expr effect = whenever.getEffect();
checkExprIsIdentifier(cause);
checkExprIsIdentifier(effect);
TypeDef type = AgreeTypeSystem.infer(cause);
if (!AgreeTypeSystem.typesEqual(AgreeTypeSystem.Prim.BoolTypeDef, type)) {
error(cause, "The cause of the 'whenever' statement is of type '" + type + "' " + "but must be of type 'bool'");
}
type = AgreeTypeSystem.infer(effect);
if (!AgreeTypeSystem.typesEqual(AgreeTypeSystem.Prim.BoolTypeDef, type)) {
error(effect, "The effect of the 'whenever' statement is of type '" + type + "' " + "but must be of type 'bool'");
}
}
Aggregations