Search in sources :

Example 6 with DoubleDotRef

use of com.rockwellcollins.atc.agree.agree.DoubleDotRef in project AGREE by loonwerks.

the class AgreeAnnexContentAssist method getNestedDotIDCandidates.

private List<String> getNestedDotIDCandidates(SelectionExpr id) {
    NamedElement base = ((NamedElmExpr) id).getElm();
    NamedElement namedEl = null;
    if (base instanceof Arg) {
        Type type = ((Arg) base).getType();
        DoubleDotRef elID = ((DoubleDotRef) type);
        namedEl = elID.getElm();
    // =======
    // DoubleDotRef elID = ((RecordType) type).getRecord();
    // namedEl = elID.getElm();
    // >>>>>>> origin/develop
    } else if (base instanceof DataPort) {
        namedEl = ((DataPort) base).getDataFeatureClassifier();
    } else if (base instanceof EventDataPort) {
        namedEl = ((EventDataPort) base).getDataFeatureClassifier();
    } else if (base instanceof AadlPackage) {
        return getNestedDotIDCandidates((AadlPackage) base);
    } else {
        return new ArrayList<>();
    }
    return getNestedDotIDCandidates(namedEl);
}
Also used : DataPort(org.osate.aadl2.DataPort) EventDataPort(org.osate.aadl2.EventDataPort) Type(com.rockwellcollins.atc.agree.agree.Type) AadlPackage(org.osate.aadl2.AadlPackage) Arg(com.rockwellcollins.atc.agree.agree.Arg) DoubleDotRef(com.rockwellcollins.atc.agree.agree.DoubleDotRef) EventDataPort(org.osate.aadl2.EventDataPort) NamedElement(org.osate.aadl2.NamedElement) NamedElmExpr(com.rockwellcollins.atc.agree.agree.NamedElmExpr)

Example 7 with DoubleDotRef

use of com.rockwellcollins.atc.agree.agree.DoubleDotRef 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;
            }
        }
    }
}
Also used : DataImplementation(org.osate.aadl2.DataImplementation) 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) EObject(org.eclipse.emf.ecore.EObject) DoubleDotRef(com.rockwellcollins.atc.agree.agree.DoubleDotRef) EnumStatement(com.rockwellcollins.atc.agree.agree.EnumStatement) PrimType(com.rockwellcollins.atc.agree.agree.PrimType) DataType(org.osate.aadl2.DataType) EqStatement(com.rockwellcollins.atc.agree.agree.EqStatement) InputStatement(com.rockwellcollins.atc.agree.agree.InputStatement) NamedElement(org.osate.aadl2.NamedElement) RecordDef(com.rockwellcollins.atc.agree.agree.RecordDef) Check(org.eclipse.xtext.validation.Check)

Example 8 with DoubleDotRef

use of com.rockwellcollins.atc.agree.agree.DoubleDotRef in project AGREE by loonwerks.

the class CallRecursionHelper method caseCallExpr.

@Override
public Expr caseCallExpr(CallExpr object) {
    DoubleDotRef id = object.getRef();
    Abstraction callDef = null;
    try {
        callDef = (Abstraction) id.getElm();
    // =======
    // public Expr caseFnCallExpr(FnCallExpr object) {
    // 
    // CallDef callDef = null;
    // 
    // try {
    // callDef = (CallDef) object.getFn().getBase();
    // >>>>>>> origin/develop:fm-workbench/agree/com.rockwellcollins.atc.agree/src/com/rockwellcollins/atc/agree/validation/FnCallRecursionHelper.java
    // 
    } catch (ClassCastException e) {
        return null;
    }
    doSwitch(callDef);
    return null;
}
Also used : DoubleDotRef(com.rockwellcollins.atc.agree.agree.DoubleDotRef) Abstraction(com.rockwellcollins.atc.agree.agree.Abstraction)

Example 9 with DoubleDotRef

use of com.rockwellcollins.atc.agree.agree.DoubleDotRef 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 10 with DoubleDotRef

use of com.rockwellcollins.atc.agree.agree.DoubleDotRef in project AMASE by loonwerks.

the class SafetyUtil method getFaultNode.

/**
 * Gets a fault node from a fault statement.
 * @param faultStatement fault definition statement created by user.
 * @return NodeDef object referenced in fault statement
 */
public static NodeDef getFaultNode(FaultStatement faultStatement) {
    // defName: faults.fail_to
    DoubleDotRef defName = faultStatement.getFaultDefName();
    // defNameSub: fail_to
    NamedElement defNameField = null;
    if (defName != null) {
        defNameField = defName.getElm();
    } else {
        new Exception("Fault definition name in " + faultStatement.getName() + " is not allowed.");
    }
    if (!(defNameField instanceof NodeDef)) {
        new Exception("Fault node definition is not working correctly. " + "A possible reason is that the project needs to be cleaned.");
    } else {
        return (NodeDef) defNameField;
    }
    return null;
}
Also used : NodeDef(com.rockwellcollins.atc.agree.agree.NodeDef) DoubleDotRef(com.rockwellcollins.atc.agree.agree.DoubleDotRef) NamedElement(org.osate.aadl2.NamedElement) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException)

Aggregations

DoubleDotRef (com.rockwellcollins.atc.agree.agree.DoubleDotRef)26 NamedElement (org.osate.aadl2.NamedElement)17 NamedElmExpr (com.rockwellcollins.atc.agree.agree.NamedElmExpr)11 BoolLitExpr (com.rockwellcollins.atc.agree.agree.BoolLitExpr)8 IntLitExpr (com.rockwellcollins.atc.agree.agree.IntLitExpr)8 RealLitExpr (com.rockwellcollins.atc.agree.agree.RealLitExpr)8 SelectionExpr (com.rockwellcollins.atc.agree.agree.SelectionExpr)8 Arg (com.rockwellcollins.atc.agree.agree.Arg)7 CallExpr (com.rockwellcollins.atc.agree.agree.CallExpr)7 EnumLitExpr (com.rockwellcollins.atc.agree.agree.EnumLitExpr)7 EventExpr (com.rockwellcollins.atc.agree.agree.EventExpr)7 NodeBodyExpr (com.rockwellcollins.atc.agree.agree.NodeBodyExpr)7 PreExpr (com.rockwellcollins.atc.agree.agree.PreExpr)7 PrevExpr (com.rockwellcollins.atc.agree.agree.PrevExpr)7 RecordLitExpr (com.rockwellcollins.atc.agree.agree.RecordLitExpr)7 DataImplementation (org.osate.aadl2.DataImplementation)7 ArrayLiteralExpr (com.rockwellcollins.atc.agree.agree.ArrayLiteralExpr)6 ArraySubExpr (com.rockwellcollins.atc.agree.agree.ArraySubExpr)6 ArrayUpdateExpr (com.rockwellcollins.atc.agree.agree.ArrayUpdateExpr)6 ExistsExpr (com.rockwellcollins.atc.agree.agree.ExistsExpr)6