use of com.rockwellcollins.atc.agree.agree.Arg 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.agree.Arg 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 com.rockwellcollins.atc.agree.agree.Arg 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 com.rockwellcollins.atc.agree.agree.Arg in project AMASE by loonwerks.
the class SafetyValidator method checkIntervalEqStatement.
/**
* Interval eq stmts:
* Checks:
* - Only primitive types supported for intervals.
* - The interval type matches high and low parameters of interval.
* - High and low parameters of interval are same type.
* @param intervalEq
*/
@Check(CheckType.FAST)
public void checkIntervalEqStatement(IntervalEq intervalEq) {
Arg arg = intervalEq.getLhs_int();
String typeName = "";
SafetyInterval interval = intervalEq.getInterv();
Expr low = interval.getLow();
Expr high = interval.getHigh();
if (arg.getType() instanceof PrimType) {
typeName = ((PrimType) arg.getType()).getName();
if (typeName.equalsIgnoreCase("bool")) {
error(arg, "Boolean intervals are not allowed. Only real or int intervals are supported.");
}
} else {
error(arg, "The only types that are supported for intervals are real and int.");
}
// Negative values are allowed: hence the check for UnaryExpr
if (low instanceof UnaryExpr) {
UnaryExpr unex_low = (UnaryExpr) low;
if (!(unex_low.getExpr() instanceof IntLitExpr) & !(unex_low.getExpr() instanceof RealLitExpr)) {
error(low, "Only real and integer types are supported for intervals.");
}
if (high instanceof UnaryExpr) {
UnaryExpr unex_high = (UnaryExpr) high;
if (!(unex_high.getExpr() instanceof IntLitExpr) & !(unex_high.getExpr() instanceof RealLitExpr)) {
error(high, "Only real and integer types are supported for intervals.");
}
testLowAndHighTypes(intervalEq, typeName, unex_low.getExpr(), unex_high.getExpr());
} else {
testLowAndHighTypes(intervalEq, typeName, unex_low.getExpr(), high);
}
} else {
testLowAndHighTypes(intervalEq, typeName, low, high);
}
}
use of com.rockwellcollins.atc.agree.agree.Arg in project AMASE by loonwerks.
the class SafetyValidator method getNodeReturnArgs.
/**
* Method finds return values of fault node given a fault statement.
* @param fStmt
* @return List<Arg> of return arguments.
*/
private List<Arg> getNodeReturnArgs(FaultStatement fStmt) {
List<Arg> returnArgs = new ArrayList<Arg>();
NodeDef nodeDef = null;
try {
nodeDef = SafetyUtil.getFaultNode(fStmt);
} catch (IllegalArgumentException e) {
return null;
}
// Get the return values
if (nodeDef != null) {
returnArgs = nodeDef.getRets();
} else {
return null;
}
return returnArgs;
}
Aggregations