Changeset 13932


Ignore:
Timestamp:
Nov 1, 2019 12:51:18 PM (3 weeks ago)
Author:
molsson
Message:

#5843 Merging to trunk. (Fixed error checking for conditional components)

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/Compiler/ModelicaFrontEnd/src/jastadd/errorcheck/ErrorCheck.jrag

    r13103 r13932  
    852852                    getFArraySubscripts().collectErrors(checkType);
    853853                }
    854                 if (hasConditionalAttribute())  {
    855                     getConditionalAttribute().collectErrors(checkType);
     854                if (hasConditionalAttribute()) {
     855                    FExp cond = getConditionalAttribute();
     856                    cond.collectErrors(checkType);
     857                    if (!cond.type().isUnknown()) {
     858                        if (!cond.type().isScalar() || !cond.type().isBoolean()) {
     859                            NON_BOOLEAN_CONDITIONAL_GUARD.invoke(this);
     860                        }
     861                        if (!cond.variability().fixedParameterOrLess()) {
     862                            NON_FIXED_CONDITIONAL_GUARD.invoke(this);
     863                        } else {
     864                            cond.markAsStructuralParameter(checkType);
     865                        }
     866                    }
    856867                }
    857868                if (!isDisabled() && hasInstModification()) {
  • trunk/Compiler/ModelicaFrontEnd/src/jastadd/errorcheck/TypeCheck.jrag

    r13396 r13932  
    190190            new ErrorProducerUnlessDisabled("ARRAY_SIZE_MISMATCH_IN_MODIFICATION_DUE_TO_EACH", ProblemKind.SEMANTIC,
    191191                    "Array size mismatch in modification of %s, expected size is (due to 'each') %s and size of binding expression is %s");
    192     public static final SimpleProblemProducer ASTNode.NON_SCALAR_CONDITIONAL_GUARD =
    193             new SimpleErrorProducer("NON_SCALAR_CONDITIONAL_GUARD", ProblemKind.SEMANTIC,
    194                     "The guard expression of a conditional component should be a scalar expression");
    195192    public static final SimpleProblemProducer ASTNode.NON_BOOLEAN_CONDITIONAL_GUARD =
    196193            new SimpleErrorProducer("NON_BOOLEAN_CONDITIONAL_GUARD", ProblemKind.SEMANTIC,
    197                     "The guard expression of a conditional component should be a boolean expression");
     194                    "The guard expression of a conditional component should be a scalar Boolean expression");
    198195    public static final SimpleProblemProducer ASTNode.NON_FIXED_CONDITIONAL_GUARD =
    199196            new SimpleErrorProducer("NON_FIXED_CONDITIONAL_GUARD", ProblemKind.SEMANTIC,
    200                     "The guard expression of a conditional component should have parameter or constant variability");
    201 
     197                    "The guard expression of a conditional component must be a fixed parameter expression");
     198
     199    @Override
    202200    public void InstAssignable.typeCheck(ErrorCheckType checkType) {
    203201        FExp bexp = myBindingInstExp();
     
    262260                        typeCheckCell(expected, actual, bexp, unknownAllowed);
    263261                    }
    264                 }
    265             }
    266         }
    267        
    268         if (hasConditionalAttribute()) {
    269             FExp cond = getConditionalAttribute();
    270             if (!cond.type().isUnknown()) {
    271                 if (!cond.type().isScalar())
    272                     NON_SCALAR_CONDITIONAL_GUARD.invoke(this);
    273                 if (!cond.type().isBoolean())
    274                     NON_BOOLEAN_CONDITIONAL_GUARD.invoke(this);
    275                 if (!cond.variability().parameterOrLess()) {
    276                     NON_FIXED_CONDITIONAL_GUARD.invoke(this);
    277                 } else {
    278                     cond.markAsStructuralParameter(checkType);
    279262                }
    280263            }
  • trunk/Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo

    r12580 r13932  
    174174    parameter Boolean b = false;
    175175
    176     annotation(__JModelica(UnitTesting(tests={
    177         FlatteningTestCase(
    178             name="ConditionalError2",
    179             description="Check that inactive conditional components aren't error checked in compile mode",
    180             flatModel="
     176annotation(__JModelica(UnitTesting(tests={
     177    FlatteningTestCase(
     178        name="ConditionalError2",
     179        description="Check that inactive conditional components aren't error checked in compile mode",
     180        flatModel="
    181181fclass CheckTests.ConditionalError2
    182  parameter Boolean b = false /* false */;
     182 structural parameter Boolean b = false /* false */;
    183183end CheckTests.ConditionalError2;
    184184")})));
     
    203203    parameter Boolean b = false;
    204204
    205     annotation(__JModelica(UnitTesting(tests={
    206         FlatteningTestCase(
    207             name="ConditionalError3",
    208             description="Check that inactive conditional components aren't searched for used functions and enums when flattening in compile mode",
    209             flatModel="
     205annotation(__JModelica(UnitTesting(tests={
     206    FlatteningTestCase(
     207        name="ConditionalError3",
     208        description="Check that inactive conditional components aren't searched for used functions and enums when flattening in compile mode",
     209        flatModel="
    210210fclass CheckTests.ConditionalError3
    211  parameter Boolean b = false /* false */;
     211 structural parameter Boolean b = false /* false */;
    212212end CheckTests.ConditionalError3;
    213213")})));
  • trunk/Compiler/ModelicaFrontEnd/test/modelica/ConnectTests.mo

    r13456 r13932  
    31013101    connect(a.c, c);
    31023102
    3103     annotation(__JModelica(UnitTesting(tests={
    3104         FlatteningTestCase(
    3105             name="ConditionalNoErrTest6",
    3106             description="Ensure that components in conditionaly false components aren't error checked due to connections",
    3107             flatModel="
     3103annotation(__JModelica(UnitTesting(tests={
     3104    FlatteningTestCase(
     3105        name="ConditionalNoErrTest6",
     3106        description="Ensure that components in conditionaly false components aren't error checked due to connections",
     3107        flatModel="
    31083108fclass ConnectTests.ConditionalNoErrTest6
    3109  parameter Boolean on = false /* false */;
     3109 structural parameter Boolean on = false /* false */;
    31103110 Real c;
    31113111end ConnectTests.ConditionalNoErrTest6;
     
    31623162        flatModel="
    31633163fclass ConnectTests.ConditionalCompInConnector1
    3164  parameter Boolean c1.b = false /* false */;
     3164 structural parameter Boolean c1.b = false /* false */;
    31653165 potential Real c1.y;
    3166  parameter Boolean c2.b = false /* false */;
     3166 structural parameter Boolean c2.b = false /* false */;
    31673167 potential Real c2.y;
    31683168equation
  • trunk/Compiler/ModelicaFrontEnd/test/modelica/NameTests.mo

    r13456 r13932  
    30163016  parameter Real x = 1 if 1;
    30173017
    3018     annotation(__JModelica(UnitTesting(tests={
    3019         ErrorTestCase(
    3020             name="ConditionalComponentTest1_Err",
    3021             description="Test of type checking of conditional components.",
    3022             errorMessage="
    3023 1 errors found:
    3024 
    3025 Error at line 2, column 3, in file 'Compiler/ModelicaFrontEnd/test/modelica/NameTests.mo', NON_BOOLEAN_CONDITIONAL_GUARD:
    3026   The guard expression of a conditional component should be a boolean expression
     3018annotation(__JModelica(UnitTesting(tests={
     3019    ErrorTestCase(
     3020        name="ConditionalComponentTest1_Err",
     3021        description="Test of type checking of conditional components.",
     3022        errorMessage="
     3023
     3024
     3025Error at line 2, column 3, in file '...', NON_BOOLEAN_CONDITIONAL_GUARD:
     3026  The guard expression of a conditional component should be a scalar Boolean expression
    30273027")})));
    30283028end ConditionalComponentTest1_Err;
     
    30323032  parameter Real x = 1 if b;
    30333033
    3034     annotation(__JModelica(UnitTesting(tests={
    3035         ErrorTestCase(
    3036             name="ConditionalComponentTest2_Err",
    3037             description="Test of type checking of conditional components.",
    3038             errorMessage="
    3039 1 errors found:
    3040 
    3041 Error at line 3, column 3, in file 'Compiler/ModelicaFrontEnd/test/modelica/NameTests.mo', NON_SCALAR_CONDITIONAL_GUARD:
    3042   The guard expression of a conditional component should be a scalar expression
     3034annotation(__JModelica(UnitTesting(tests={
     3035    ErrorTestCase(
     3036        name="ConditionalComponentTest2_Err",
     3037        description="Test of type checking of conditional components.",
     3038        errorMessage="
     3039
     3040
     3041Error at line 3, column 3, in file '...', NON_BOOLEAN_CONDITIONAL_GUARD:
     3042  The guard expression of a conditional component should be a scalar Boolean expression
    30433043")})));
    30443044end ConditionalComponentTest2_Err;
     
    30483048  parameter Real x = 1 if b;
    30493049
    3050     annotation(__JModelica(UnitTesting(tests={
    3051         ErrorTestCase(
    3052             name="ConditionalComponentTest3_Err",
    3053             description="Test of type checking of conditional components.",
    3054             errorMessage="
    3055 2 errors found:
    3056 
    3057 Error at line 3, column 3, in file 'Compiler/ModelicaFrontEnd/test/modelica/NameTests.mo', NON_BOOLEAN_CONDITIONAL_GUARD:
    3058   The guard expression of a conditional component should be a boolean expression
    3059 
    3060 Error at line 3, column 3, in file 'Compiler/ModelicaFrontEnd/test/modelica/NameTests.mo', NON_SCALAR_CONDITIONAL_GUARD:
    3061   The guard expression of a conditional component should be a scalar expression
     3050annotation(__JModelica(UnitTesting(tests={
     3051    ErrorTestCase(
     3052        name="ConditionalComponentTest3_Err",
     3053        description="Test of type checking of conditional components.",
     3054        errorMessage="
     3055
     3056
     3057Error at line 3, column 3, in file '...', NON_BOOLEAN_CONDITIONAL_GUARD:
     3058  The guard expression of a conditional component should be a scalar Boolean expression
    30623059")})));
    30633060end ConditionalComponentTest3_Err;
     
    31473144            flatModel="
    31483145fclass NameTests.ConditionalComponentTest8
    3149  parameter Boolean b = false /* false */;
     3146 structural parameter Boolean b = false /* false */;
    31503147
    31513148end NameTests.ConditionalComponentTest8;
     
    31783175            flatModel="
    31793176fclass NameTests.ConditionalComponentTest9
    3180  parameter Boolean b = false /* false */;
     3177 structural parameter Boolean b = false /* false */;
    31813178
    31823179end NameTests.ConditionalComponentTest9;
     
    33803377")})));
    33813378end ConditionalComponentTest14;
     3379
     3380
     3381model ConditionalComponentTest15_Err
     3382    connector C
     3383        Real x;
     3384    end C;
     3385   
     3386    parameter Integer b[2] = {1,1};
     3387    C c if b;
     3388annotation(__JModelica(UnitTesting(tests={
     3389    ErrorTestCase(
     3390        name="ConditionalComponentTest15_Err",
     3391        description="Test of type checking of conditional composite component.",
     3392        errorMessage="
     3393
     3394
     3395Error at line 7, column 5, in file '...', NON_BOOLEAN_CONDITIONAL_GUARD:
     3396  The guard expression of a conditional component should be a scalar Boolean expression
     3397")})));
     3398end ConditionalComponentTest15_Err;
     3399
     3400
     3401model ConditionalComponentTest16
     3402    connector C
     3403        Real x;
     3404    end C;
     3405   
     3406    parameter Boolean b = false;
     3407    C c if b;
     3408annotation(__JModelica(UnitTesting(tests={
     3409    FlatteningTestCase(
     3410        description="Flattening conditional composite component",
     3411        flatModel="
     3412fclass NameTests.ConditionalComponentTest16
     3413 structural parameter Boolean b = false /* false */;
     3414end NameTests.ConditionalComponentTest16;
     3415")})));
     3416end ConditionalComponentTest16;
     3417
     3418
     3419model ConditionalComponentTest17
     3420    connector C
     3421        Real x;
     3422    end C;
     3423   
     3424    parameter Boolean b = true;
     3425    C c if b;
     3426annotation(__JModelica(UnitTesting(tests={
     3427    FlatteningTestCase(
     3428        description="Flattening conditional composite component",
     3429        flatModel="
     3430fclass NameTests.ConditionalComponentTest17
     3431 structural parameter Boolean b = true /* true */;
     3432 potential Real c.x;
     3433end NameTests.ConditionalComponentTest17;
     3434")})));
     3435end ConditionalComponentTest17;
     3436
     3437
     3438model ConditionalComponentTest18_Err
     3439    parameter Boolean b(start = false, fixed = false);
     3440    Real x if b;
     3441    Real y if time > 5;
     3442annotation(__JModelica(UnitTesting(tests={
     3443    ErrorTestCase(
     3444        description="Checking that conditional guard is a fixed parameter expression.",
     3445        errorMessage="
     3446Error at line 3, column 5, in file '...', NON_FIXED_CONDITIONAL_GUARD:
     3447  The guard expression of a conditional component must be a fixed parameter expression
     3448Error at line 4, column 5, in file '...', NON_FIXED_CONDITIONAL_GUARD:
     3449  The guard expression of a conditional component must be a fixed parameter expression
     3450
     3451")})));
     3452end ConditionalComponentTest18_Err;
     3453
     3454
    33823455
    33833456model AttributeDot1
  • trunk/Compiler/ModelicaFrontEnd/test/modelica/RedeclareTests.mo

    r13456 r13932  
    66196619    A a(use_b = false, redeclare C b);
    66206620
    6621     annotation(__JModelica(UnitTesting(tests={
    6622         FlatteningTestCase(
    6623             name="RedeclareConditional1",
    6624             description="Redeclaring inactive conditional as modification",
    6625             flatModel="
     6621annotation(__JModelica(UnitTesting(tests={
     6622    FlatteningTestCase(
     6623        name="Misc_RedeclareConditional1",
     6624        description="Redeclaring inactive conditional as modification",
     6625        flatModel="
    66266626fclass RedeclareTests.Misc.RedeclareConditional1
    6627  parameter Boolean a.use_b = false /* false */;
     6627 structural parameter Boolean a.use_b = false /* false */;
    66286628end RedeclareTests.Misc.RedeclareConditional1;
    66296629")})));
     
    66536653    D d;
    66546654
    6655     annotation(__JModelica(UnitTesting(tests={
    6656         FlatteningTestCase(
    6657             name="RedeclareConditional2",
    6658             description="Redeclaring inactive conditional as element",
    6659             flatModel="
     6655annotation(__JModelica(UnitTesting(tests={
     6656    FlatteningTestCase(
     6657        name="Misc_RedeclareConditional2",
     6658        description="Redeclaring inactive conditional as element",
     6659        flatModel="
    66606660fclass RedeclareTests.Misc.RedeclareConditional2
    6661  parameter Boolean d.use_b = false /* false */;
     6661 structural parameter Boolean d.use_b = false /* false */;
    66626662end RedeclareTests.Misc.RedeclareConditional2;
    66636663")})));
Note: See TracChangeset for help on using the changeset viewer.