Search in sources :

Example 11 with Arg

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;
}
Also used : AgreeTypeSystem.nameOfTypeDef(com.rockwellcollins.atc.agree.AgreeTypeSystem.nameOfTypeDef) ArrayTypeDef(com.rockwellcollins.atc.agree.AgreeTypeSystem.ArrayTypeDef) RecordTypeDef(com.rockwellcollins.atc.agree.AgreeTypeSystem.RecordTypeDef) TypeDef(com.rockwellcollins.atc.agree.AgreeTypeSystem.TypeDef) HashMap(java.util.HashMap) Arg(com.rockwellcollins.atc.agree.agree.Arg) Subcomponent(org.osate.aadl2.Subcomponent) DataSubcomponent(org.osate.aadl2.DataSubcomponent) DataImplementation(org.osate.aadl2.DataImplementation) NamedElement(org.osate.aadl2.NamedElement) RecordDef(com.rockwellcollins.atc.agree.agree.RecordDef)

Example 12 with Arg

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));
}
Also used : PrimType(com.rockwellcollins.atc.agree.agree.PrimType) DataType(org.osate.aadl2.DataType) CheckType(org.eclipse.xtext.validation.CheckType) FeatureGroupType(org.osate.aadl2.FeatureGroupType) ComponentType(org.osate.aadl2.ComponentType) Type(com.rockwellcollins.atc.agree.agree.Type) DirectionType(org.osate.aadl2.DirectionType) Arg(com.rockwellcollins.atc.agree.agree.Arg) DoubleDotRef(com.rockwellcollins.atc.agree.agree.DoubleDotRef) NamedElement(org.osate.aadl2.NamedElement) RecordDef(com.rockwellcollins.atc.agree.agree.RecordDef) HashSet(java.util.HashSet) Check(org.eclipse.xtext.validation.Check)

Example 13 with Arg

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;
    }
}
Also used : ArrayList(java.util.ArrayList) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Classifier(org.osate.aadl2.Classifier) AadlString(org.osate.aadl2.AadlString) NamedID(com.rockwellcollins.atc.agree.agree.NamedID) EList(org.eclipse.emf.common.util.EList) Arg(com.rockwellcollins.atc.agree.agree.Arg) EnumStatement(com.rockwellcollins.atc.agree.agree.EnumStatement) Map(java.util.Map) HashMap(java.util.HashMap) RecordDef(com.rockwellcollins.atc.agree.agree.RecordDef)

Example 14 with Arg

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);
    }
}
Also used : RealLitExpr(com.rockwellcollins.atc.agree.agree.RealLitExpr) UnaryExpr(com.rockwellcollins.atc.agree.agree.UnaryExpr) Expr(com.rockwellcollins.atc.agree.agree.Expr) PrevExpr(com.rockwellcollins.atc.agree.agree.PrevExpr) BoolLitExpr(com.rockwellcollins.atc.agree.agree.BoolLitExpr) IntLitExpr(com.rockwellcollins.atc.agree.agree.IntLitExpr) NamedElmExpr(com.rockwellcollins.atc.agree.agree.NamedElmExpr) IntLitExpr(com.rockwellcollins.atc.agree.agree.IntLitExpr) Arg(com.rockwellcollins.atc.agree.agree.Arg) PrimType(com.rockwellcollins.atc.agree.agree.PrimType) RealLitExpr(com.rockwellcollins.atc.agree.agree.RealLitExpr) SafetyInterval(edu.umn.cs.crisys.safety.safety.SafetyInterval) UnaryExpr(com.rockwellcollins.atc.agree.agree.UnaryExpr) Check(org.eclipse.xtext.validation.Check)

Example 15 with Arg

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;
}
Also used : NodeDef(com.rockwellcollins.atc.agree.agree.NodeDef) Arg(com.rockwellcollins.atc.agree.agree.Arg) ArrayList(java.util.ArrayList)

Aggregations

Arg (com.rockwellcollins.atc.agree.agree.Arg)31 ArrayList (java.util.ArrayList)11 NamedElmExpr (com.rockwellcollins.atc.agree.agree.NamedElmExpr)10 BoolLitExpr (com.rockwellcollins.atc.agree.agree.BoolLitExpr)7 DoubleDotRef (com.rockwellcollins.atc.agree.agree.DoubleDotRef)7 NodeBodyExpr (com.rockwellcollins.atc.agree.agree.NodeBodyExpr)7 NodeDef (com.rockwellcollins.atc.agree.agree.NodeDef)7 RealLitExpr (com.rockwellcollins.atc.agree.agree.RealLitExpr)7 NamedElement (org.osate.aadl2.NamedElement)7 IntLitExpr (com.rockwellcollins.atc.agree.agree.IntLitExpr)6 PrimType (com.rockwellcollins.atc.agree.agree.PrimType)6 CallExpr (com.rockwellcollins.atc.agree.agree.CallExpr)5 SelectionExpr (com.rockwellcollins.atc.agree.agree.SelectionExpr)5 Check (org.eclipse.xtext.validation.Check)5 EnumLitExpr (com.rockwellcollins.atc.agree.agree.EnumLitExpr)4 EqStatement (com.rockwellcollins.atc.agree.agree.EqStatement)4 EventExpr (com.rockwellcollins.atc.agree.agree.EventExpr)4 Expr (com.rockwellcollins.atc.agree.agree.Expr)4 InputStatement (com.rockwellcollins.atc.agree.agree.InputStatement)4 PreExpr (com.rockwellcollins.atc.agree.agree.PreExpr)4