Search in sources :

Example 26 with DataImplementation

use of org.osate.aadl2.DataImplementation in project AGREE by loonwerks.

the class AgreeValidator method checkRecordLitExpr.

@Check(CheckType.FAST)
public void checkRecordLitExpr(RecordLitExpr recExpr) {
    DoubleDotRef recType = recExpr.getRecordType();
    // =======
    // DoubleDotRef recType = recExpr.getRecord();
    // >>>>>>> origin/develop
    List<NamedElement> defArgs = getArgNames(recType);
    EList<NamedElement> exprArgs = recExpr.getArgs();
    EList<Expr> argExprs = recExpr.getArgExpr();
    NamedElement finalId = recExpr.getRecordType().getElm();
    if (!(finalId instanceof DataImplementation) && !(finalId instanceof RecordDef)) {
        error(recType, "types must be record definition or data implementation");
    // =======
    // DoubleDotRef recId = recExpr.getRecord();
    // NamedElement finalId = recId.getElm();
    // 
    // if (!(finalId instanceof DataImplementation) && !(finalId instanceof RecordDefExpr)) {
    // error(recId, "types must be record definition or data implementation");
    // }
    // 
    // if (finalId instanceof DataImplementation) {
    // dataImplCycleCheck(recId);
    // >>>>>>> origin/develop
    }
    if (exprArgs.size() != defArgs.size()) {
        error(recExpr, "Incorrect number of arguments");
        return;
    }
    for (NamedElement argDefName : defArgs) {
        boolean foundArg = false;
        for (NamedElement argExprEl : exprArgs) {
            if (argExprEl.getName().equals(argDefName.getName())) {
                foundArg = true;
                break;
            }
        }
        if (!foundArg) {
            error(recExpr, "No assignment to defined variable '" + argDefName + "' in record expression.");
        }
    }
    // check typing
    Map<String, TypeDef> argNameMap = getFieldTypes(recType);
    for (int i = 0; i < recExpr.getArgs().size(); i++) {
        NamedElement actArg = recExpr.getArgs().get(i);
        String actArgName = actArg.getName();
        TypeDef defType = argNameMap.get(actArgName);
        checkTypeExists(argExprs.get(i));
        TypeDef exprType = AgreeTypeSystem.infer(argExprs.get(i));
        if (!AgreeTypeSystem.typesEqual(defType, exprType)) {
            error(recExpr, "The expression assigned to '" + actArgName + "' does not match its definition type of '" + defType + "'");
        }
    }
}
Also used : DataImplementation(org.osate.aadl2.DataImplementation) EnumLitExpr(com.rockwellcollins.atc.agree.agree.EnumLitExpr) IndicesExpr(com.rockwellcollins.atc.agree.agree.IndicesExpr) TimeRiseExpr(com.rockwellcollins.atc.agree.agree.TimeRiseExpr) FlatmapExpr(com.rockwellcollins.atc.agree.agree.FlatmapExpr) TimeFallExpr(com.rockwellcollins.atc.agree.agree.TimeFallExpr) RealLitExpr(com.rockwellcollins.atc.agree.agree.RealLitExpr) GetPropertyExpr(com.rockwellcollins.atc.agree.agree.GetPropertyExpr) TimeOfExpr(com.rockwellcollins.atc.agree.agree.TimeOfExpr) PrevExpr(com.rockwellcollins.atc.agree.agree.PrevExpr) FoldRightExpr(com.rockwellcollins.atc.agree.agree.FoldRightExpr) TagExpr(com.rockwellcollins.atc.agree.agree.TagExpr) EventExpr(com.rockwellcollins.atc.agree.agree.EventExpr) LatchedExpr(com.rockwellcollins.atc.agree.agree.LatchedExpr) NamedElmExpr(com.rockwellcollins.atc.agree.agree.NamedElmExpr) SelectionExpr(com.rockwellcollins.atc.agree.agree.SelectionExpr) IfThenElseExpr(com.rockwellcollins.atc.agree.agree.IfThenElseExpr) ArraySubExpr(com.rockwellcollins.atc.agree.agree.ArraySubExpr) PreExpr(com.rockwellcollins.atc.agree.agree.PreExpr) RecordLitExpr(com.rockwellcollins.atc.agree.agree.RecordLitExpr) BinaryExpr(com.rockwellcollins.atc.agree.agree.BinaryExpr) UnaryExpr(com.rockwellcollins.atc.agree.agree.UnaryExpr) ExistsExpr(com.rockwellcollins.atc.agree.agree.ExistsExpr) FoldLeftExpr(com.rockwellcollins.atc.agree.agree.FoldLeftExpr) RecordUpdateExpr(com.rockwellcollins.atc.agree.agree.RecordUpdateExpr) ForallExpr(com.rockwellcollins.atc.agree.agree.ForallExpr) Expr(com.rockwellcollins.atc.agree.agree.Expr) ArrayUpdateExpr(com.rockwellcollins.atc.agree.agree.ArrayUpdateExpr) BoolLitExpr(com.rockwellcollins.atc.agree.agree.BoolLitExpr) NodeBodyExpr(com.rockwellcollins.atc.agree.agree.NodeBodyExpr) IntLitExpr(com.rockwellcollins.atc.agree.agree.IntLitExpr) CallExpr(com.rockwellcollins.atc.agree.agree.CallExpr) ArrayLiteralExpr(com.rockwellcollins.atc.agree.agree.ArrayLiteralExpr) 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) DoubleDotRef(com.rockwellcollins.atc.agree.agree.DoubleDotRef) NamedElement(org.osate.aadl2.NamedElement) RecordDef(com.rockwellcollins.atc.agree.agree.RecordDef) Check(org.eclipse.xtext.validation.Check)

Aggregations

DataImplementation (org.osate.aadl2.DataImplementation)24 DataSubcomponent (org.osate.aadl2.DataSubcomponent)11 NamedElement (org.osate.aadl2.NamedElement)11 DataType (org.osate.aadl2.DataType)10 RecordDef (com.rockwellcollins.atc.agree.agree.RecordDef)8 DoubleDotRef (com.rockwellcollins.atc.agree.agree.DoubleDotRef)7 Arg (com.rockwellcollins.atc.agree.agree.Arg)6 ComponentClassifier (org.osate.aadl2.ComponentClassifier)6 Subcomponent (org.osate.aadl2.Subcomponent)6 Classifier (org.osate.aadl2.Classifier)5 DataSubcomponentType (org.osate.aadl2.DataSubcomponentType)5 PrimType (com.rockwellcollins.atc.agree.agree.PrimType)4 HashSet (java.util.HashSet)4 Check (org.eclipse.xtext.validation.Check)4 DataPort (org.osate.aadl2.DataPort)4 Element (org.osate.aadl2.Element)4 EventDataPort (org.osate.aadl2.EventDataPort)4 EventPort (org.osate.aadl2.EventPort)4 FeatureGroupType (org.osate.aadl2.FeatureGroupType)4 LPort (com.ge.research.osate.verdict.dsl.verdict.LPort)3