Search in sources :

Example 26 with DoubleDotRef

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

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