Changeset 13948


Ignore:
Timestamp:
Nov 4, 2019 4:33:01 PM (2 weeks ago)
Author:
molsson
Message:

#5843 Recommitted r13927 and r13932.

Location:
trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk

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

    r13940 r13948  
    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

    r13940 r13948  
    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/src/jastadd/flattening/Flattening.jrag

    r13940 r13948  
    17341734        }
    17351735        if (isConnectorVariable()) {
    1736             if (isInput()) {
    1737                 return CausalityConnectorPrefix.INPUT;
    1738             } else if (isOutput()) {
    1739                 return CausalityConnectorPrefix.OUTPUT;
    1740             } else if (isFlow()) {
    1741                 return CausalityConnectorPrefix.FLOW;
    1742             } else if (isStream()) {
    1743                 return CausalityConnectorPrefix.STREAM;
    1744             } else if (!variability().parameterOrLess()) {
    1745                 return CausalityConnectorPrefix.POTENTIAL;
    1746             } else {
    1747                 return CausalityConnectorPrefix.NONE;
    1748             }
     1736            return connectorVariablePrefix();
    17491737        } else {
    17501738            if (isInput()) {
     
    17551743                return CausalityConnectorPrefix.NONE;
    17561744            }
     1745        }
     1746    }
     1747   
     1748    /**
     1749     * Computes the {@link CausalityConnectorPrefix} this variable would have if it
     1750     * was a connector variable in a top-level connector.
     1751     */
     1752    public CausalityConnectorPrefix InstAssignable.connectorVariablePrefix() {
     1753        if (isInput()) {
     1754            return CausalityConnectorPrefix.INPUT;
     1755        } else if (isOutput()) {
     1756            return CausalityConnectorPrefix.OUTPUT;
     1757        } else if (isFlow()) {
     1758            return CausalityConnectorPrefix.FLOW;
     1759        } else if (isStream()) {
     1760            return CausalityConnectorPrefix.STREAM;
     1761        } else if (!variability().parameterOrLess()) {
     1762            return CausalityConnectorPrefix.POTENTIAL;
     1763        } else {
     1764            return CausalityConnectorPrefix.NONE;
    17571765        }
    17581766    }
  • trunk/Compiler/ModelicaFrontEnd/src/jastadd/instance/InnerOuter.jrag

    r13940 r13948  
    113113    eq BaseNode.getChild().isGeneratedInner()                       = false;
    114114
     115    inh boolean InstComponentDecl.isInGeneratedInner();
     116    eq InstGeneratedInner.getInstComponentDecl().isInGeneratedInner() = true;
     117    eq InstClassDecl.getChild().isInGeneratedInner()                  = false;
     118
    115119}
    116120
  • trunk/Compiler/ModelicaFrontEnd/src/jastadd/util/Util.jrag

    r13940 r13948  
    13131313   
    13141314
    1315     /**
    1316      * Check if this component is declared parameter.
    1317      */
    1318     syn boolean SrcComponentDecl.isParameter() = hasSrcTypePrefixVariability() && getSrcTypePrefixVariability().parameterVariability();
    1319    
    1320     /**
    1321      * Check if this component is declared constant.
    1322      */
    1323     syn boolean SrcComponentDecl.isConstant() = hasSrcTypePrefixVariability() && getSrcTypePrefixVariability().constantVariability();
    1324    
    1325     /**
    1326      * Check if this component clause is declared constant.
    1327      */
    1328     syn boolean SrcComponentClause.isConstant() = hasSrcTypePrefixVariability() && getSrcTypePrefixVariability().constantVariability();
    1329    
    1330     /**
    1331      * Check if this component is declared discrete.
    1332      */
    1333     syn boolean SrcComponentDecl.isDiscrete() = hasSrcTypePrefixVariability() && getSrcTypePrefixVariability().discreteVariability();
     1315    syn boolean SrcComponentDecl.isParameter() = myComponentClause().isParameter();
     1316    syn boolean SrcComponentDecl.isConstant()  = myComponentClause().isConstant();
     1317    syn boolean SrcComponentDecl.isDiscrete()  = myComponentClause().isDiscrete();
     1318   
     1319    syn boolean SrcComponentClause.isParameter() = hasSrcTypePrefixVariability() && getSrcTypePrefixVariability().parameterVariability();
     1320    syn boolean SrcComponentClause.isConstant()  = hasSrcTypePrefixVariability() && getSrcTypePrefixVariability().constantVariability();
     1321    syn boolean SrcComponentClause.isDiscrete()  = hasSrcTypePrefixVariability() && getSrcTypePrefixVariability().discreteVariability();
    13341322
    13351323    /**
  • trunk/Compiler/ModelicaFrontEnd/test/modelica/CheckTests.mo

    r13940 r13948  
    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

    r13940 r13948  
    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

    r13940 r13948  
    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

    r13940 r13948  
    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")})));
  • trunk/Compiler/ModelicaMiddleEnd/src/jastadd/scalarization/Scalarization.jrag

    r13940 r13948  
    619619    public class ScalarizingVariableInstance {
    620620       
    621         private TypePrefixVariability variability;
    622        
    623         private VisibilityType visibility;
     621        private final TypePrefixVariability variability;
     622       
     623        private final VisibilityType visibility;
    624624       
    625625        // Binding expression
    626         private FExp bExp;
     626        private final FExp bExp;
    627627       
    628628        // (Mapped) attributes of this variable
    629         private Map<String, FAttribute> mattrs;
     629        private final Map<String, FAttribute> mattrs;
    630630       
    631631        // Full name of this variable
    632         private String name;
     632        private final String name;
    633633       
    634634        // input/output prefix of top-level variable
    635         private CausalityConnectorPrefix inputOutput;
    636        
    637         private Index index;
     635        private final CausalityConnectorPrefix inputOutput;
     636       
     637        private final Index index;
    638638       
    639639        private ScalarizingVariableInstance(String name, Map<String, FAttribute> mattrs, FExp be,
     
    645645            this.variability = variability;
    646646            this.visibility = visibility;
    647             this.inputOutput = inputOutput;
     647            /* If we have a record with input/output prefix that contains a parameter,
     648             * that parameter should not inherit the input/output prefix */
     649            this.inputOutput = variability.parameterOrLess() ? CausalityConnectorPrefix.NONE : inputOutput;
    648650        }
    649651       
Note: See TracChangeset for help on using the changeset viewer.