Search in sources :

Example 36 with TypeDef

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

RecordTypeDef (com.rockwellcollins.atc.agree.AgreeTypeSystem.RecordTypeDef)36 TypeDef (com.rockwellcollins.atc.agree.AgreeTypeSystem.TypeDef)36 ArrayTypeDef (com.rockwellcollins.atc.agree.AgreeTypeSystem.ArrayTypeDef)34 AgreeTypeSystem.nameOfTypeDef (com.rockwellcollins.atc.agree.AgreeTypeSystem.nameOfTypeDef)34 Check (org.eclipse.xtext.validation.Check)31 CallExpr (com.rockwellcollins.atc.agree.agree.CallExpr)23 ArrayLiteralExpr (com.rockwellcollins.atc.agree.agree.ArrayLiteralExpr)22 ArraySubExpr (com.rockwellcollins.atc.agree.agree.ArraySubExpr)22 ArrayUpdateExpr (com.rockwellcollins.atc.agree.agree.ArrayUpdateExpr)22 BinaryExpr (com.rockwellcollins.atc.agree.agree.BinaryExpr)22 BoolLitExpr (com.rockwellcollins.atc.agree.agree.BoolLitExpr)22 EnumLitExpr (com.rockwellcollins.atc.agree.agree.EnumLitExpr)22 EventExpr (com.rockwellcollins.atc.agree.agree.EventExpr)22 ExistsExpr (com.rockwellcollins.atc.agree.agree.ExistsExpr)22 Expr (com.rockwellcollins.atc.agree.agree.Expr)22 FlatmapExpr (com.rockwellcollins.atc.agree.agree.FlatmapExpr)22 FoldLeftExpr (com.rockwellcollins.atc.agree.agree.FoldLeftExpr)22 FoldRightExpr (com.rockwellcollins.atc.agree.agree.FoldRightExpr)22 ForallExpr (com.rockwellcollins.atc.agree.agree.ForallExpr)22 GetPropertyExpr (com.rockwellcollins.atc.agree.agree.GetPropertyExpr)22