OMCompiler/Compiler/FFrontEnd/FBuiltin.mo
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * This file is part of OpenModelica. | ||
| 3 | * | ||
| 4 | * Copyright (c) 1998-2026, Open Source Modelica Consortium (OSMC), | ||
| 5 | * c/o Linköpings universitet, Department of Computer and Information Science, | ||
| 6 | * SE-58183 Linköping, Sweden. | ||
| 7 | * | ||
| 8 | * All rights reserved. | ||
| 9 | * | ||
| 10 | * THIS PROGRAM IS PROVIDED UNDER THE TERMS OF AGPL VERSION 3 LICENSE OR | ||
| 11 | * THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.8. | ||
| 12 | * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES | ||
| 13 | * RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GNU AGPL | ||
| 14 | * VERSION 3, ACCORDING TO RECIPIENTS CHOICE. | ||
| 15 | * | ||
| 16 | * The OpenModelica software and the OSMC (Open Source Modelica Consortium) | ||
| 17 | * Public License (OSMC-PL) are obtained from OSMC, either from the above | ||
| 18 | * address, from the URLs: | ||
| 19 | * http://www.openmodelica.org or | ||
| 20 | * https://github.com/OpenModelica/ or | ||
| 21 | * http://www.ida.liu.se/projects/OpenModelica, | ||
| 22 | * and in the OpenModelica distribution. | ||
| 23 | * | ||
| 24 | * GNU AGPL version 3 is obtained from: | ||
| 25 | * https://www.gnu.org/licenses/licenses.html#GPL | ||
| 26 | * | ||
| 27 | * This program is distributed WITHOUT ANY WARRANTY; without | ||
| 28 | * even the implied warranty of MERCHANTABILITY or FITNESS | ||
| 29 | * FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH | ||
| 30 | * IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL. | ||
| 31 | * | ||
| 32 | * See the full OSMC Public License conditions for more details. | ||
| 33 | * | ||
| 34 | */ | ||
| 35 | |||
| 36 | encapsulated package FBuiltin | ||
| 37 | " file: FBuiltin.mo | ||
| 38 | package: FBuiltin | ||
| 39 | description: Builting tyepes and variables | ||
| 40 | |||
| 41 | |||
| 42 | This module defines the builtin types, variables and functions in Modelica. | ||
| 43 | |||
| 44 | There are several builtin attributes defined in the builtin types, such as unit, start, etc." | ||
| 45 | |||
| 46 | public import Absyn; | ||
| 47 | public import DAE; | ||
| 48 | public import Error; | ||
| 49 | public import SCode; | ||
| 50 | public import FCore; | ||
| 51 | public import FGraph; | ||
| 52 | |||
| 53 | // protected imports | ||
| 54 | protected import ClassInf; | ||
| 55 | protected import Config; | ||
| 56 | protected import Flags; | ||
| 57 | protected import FGraphBuild; | ||
| 58 | protected import Global; | ||
| 59 | protected import MetaUtil; | ||
| 60 | protected import Parser; | ||
| 61 | protected import AbsynToSCode; | ||
| 62 | import SCodeUtil; | ||
| 63 | protected import Settings; | ||
| 64 | protected import System; | ||
| 65 | protected import Util; | ||
| 66 | |||
| 67 | /* These imports were used in e.g. MSL 1.6. They should not be here anymore... | ||
| 68 | If you need them, add them to the initial environment and recompile; they are not standard Modelica. | ||
| 69 | import arcsin = asin; | ||
| 70 | import arccos = acos; | ||
| 71 | import arctan = atan; | ||
| 72 | import ln = log; | ||
| 73 | */ | ||
| 74 | |||
| 75 | // Predefined DAE.Types | ||
| 76 | // Real arrays | ||
| 77 | protected constant DAE.Type T_REAL_ARRAY_DEFAULT = DAE.T_ARRAY(DAE.T_REAL_DEFAULT, {DAE.DIM_UNKNOWN()}); | ||
| 78 | protected constant DAE.Type T_REAL_ARRAY_1_DEFAULT = DAE.T_ARRAY(DAE.T_REAL_DEFAULT, {DAE.DIM_INTEGER(1)}); | ||
| 79 | |||
| 80 | // Integer arrays | ||
| 81 | protected constant DAE.Type T_INT_ARRAY_1_DEFAULT = DAE.T_ARRAY(DAE.T_INTEGER_DEFAULT, {DAE.DIM_INTEGER(1)}); | ||
| 82 | |||
| 83 | protected constant SCode.Prefixes commonPrefixes = | ||
| 84 | SCode.PREFIXES( | ||
| 85 | SCode.PUBLIC(), | ||
| 86 | SCode.NOT_REDECLARE(), | ||
| 87 | SCode.FINAL(), // make everything here final! | ||
| 88 | Absyn.NOT_INNER_OUTER(), | ||
| 89 | SCode.NOT_REPLACEABLE()); | ||
| 90 | |||
| 91 | protected constant SCode.Prefixes commonPrefixesNotFinal = | ||
| 92 | SCode.PREFIXES( | ||
| 93 | SCode.PUBLIC(), | ||
| 94 | SCode.NOT_REDECLARE(), | ||
| 95 | SCode.NOT_FINAL(), // make everything here final! | ||
| 96 | Absyn.NOT_INNER_OUTER(), | ||
| 97 | SCode.NOT_REPLACEABLE()); | ||
| 98 | |||
| 99 | protected | ||
| 100 | constant SCode.Attributes attrConst = SCode.ATTR({},SCode.POTENTIAL(),SCode.NON_PARALLEL(),SCode.CONST(),Absyn.BIDIR(),Absyn.NONFIELD()); | ||
| 101 | constant SCode.Attributes attrParam = SCode.ATTR({},SCode.POTENTIAL(),SCode.NON_PARALLEL(),SCode.PARAM(),Absyn.BIDIR(),Absyn.NONFIELD()); | ||
| 102 | constant SCode.Attributes attrParamVectorNoDim = SCode.ATTR({Absyn.NOSUB()},SCode.POTENTIAL(),SCode.NON_PARALLEL(),SCode.PARAM(),Absyn.BIDIR(),Absyn.NONFIELD()); | ||
| 103 | |||
| 104 | // | ||
| 105 | // The primitive types | ||
| 106 | // These are the primitive types that are used to build the types | ||
| 107 | // Real, Integer etc. | ||
| 108 | protected constant SCode.Element rlType = SCode.CLASS("RealType",commonPrefixes,SCode.NOT_ENCAPSULATED(),SCode.NOT_PARTIAL(),SCode.R_PREDEFINED_REAL(), | ||
| 109 | SCode.PARTS({},{},{},{},{},{},{},NONE()),SCode.noComment,Absyn.dummyInfo) " real type "; | ||
| 110 | |||
| 111 | protected constant SCode.Element intType = SCode.CLASS("IntegerType",commonPrefixes,SCode.NOT_ENCAPSULATED(),SCode.NOT_PARTIAL(),SCode.R_PREDEFINED_INTEGER(), | ||
| 112 | SCode.PARTS({},{},{},{},{},{},{},NONE()),SCode.noComment,Absyn.dummyInfo); | ||
| 113 | |||
| 114 | protected constant SCode.Element strType = SCode.CLASS("StringType",commonPrefixes,SCode.NOT_ENCAPSULATED(),SCode.NOT_PARTIAL(),SCode.R_PREDEFINED_STRING(), | ||
| 115 | SCode.PARTS({},{},{},{},{},{},{},NONE()),SCode.noComment,Absyn.dummyInfo); | ||
| 116 | |||
| 117 | protected constant SCode.Element boolType = SCode.CLASS("BooleanType",commonPrefixes,SCode.NOT_ENCAPSULATED(),SCode.NOT_PARTIAL(),SCode.R_PREDEFINED_BOOLEAN(), | ||
| 118 | SCode.PARTS({},{},{},{},{},{},{},NONE()),SCode.noComment,Absyn.dummyInfo); | ||
| 119 | |||
| 120 | protected constant SCode.Element enumType = SCode.CLASS("EnumType",commonPrefixes,SCode.NOT_ENCAPSULATED(),SCode.NOT_PARTIAL(),SCode.R_PREDEFINED_ENUMERATION(), | ||
| 121 | SCode.PARTS({},{},{},{},{},{},{},NONE()),SCode.noComment,Absyn.dummyInfo); | ||
| 122 | |||
| 123 | protected constant SCode.Element unit = SCode.COMPONENT("unit",commonPrefixes, | ||
| 124 | attrParam,Absyn.TPATH(Absyn.IDENT("StringType"),NONE()), | ||
| 125 | SCode.MOD(SCode.NOT_FINAL(),SCode.NOT_EACH(),{},SOME(Absyn.STRING("")), NONE(), Absyn.dummyInfo),SCode.noComment,NONE(),Absyn.dummyInfo) "This `unit\' component is used in several places below, and it is | ||
| 126 | declared once here to make the definitions below easier to read." ; | ||
| 127 | |||
| 128 | protected constant SCode.Element quantity = SCode.COMPONENT("quantity",commonPrefixes, | ||
| 129 | attrParam,Absyn.TPATH(Absyn.IDENT("StringType"),NONE()), | ||
| 130 | SCode.MOD(SCode.NOT_FINAL(),SCode.NOT_EACH(),{},SOME(Absyn.STRING("")), NONE(), Absyn.dummyInfo),SCode.noComment,NONE(),Absyn.dummyInfo); | ||
| 131 | |||
| 132 | protected constant SCode.Element displayUnit = SCode.COMPONENT("displayUnit",commonPrefixes, | ||
| 133 | attrParam,Absyn.TPATH(Absyn.IDENT("StringType"),NONE()), | ||
| 134 | SCode.MOD(SCode.NOT_FINAL(),SCode.NOT_EACH(),{},SOME(Absyn.STRING("")), NONE(), Absyn.dummyInfo),SCode.noComment,NONE(),Absyn.dummyInfo); | ||
| 135 | |||
| 136 | protected constant SCode.Element min = SCode.COMPONENT("min",commonPrefixes, | ||
| 137 | attrParam,Absyn.TPATH(Absyn.IDENT("RealType"),NONE()), | ||
| 138 | SCode.MOD(SCode.NOT_FINAL(),SCode.NOT_EACH(),{},SOME(Absyn.REAL("-1e+099")), NONE(), Absyn.dummyInfo),SCode.noComment,NONE(),Absyn.dummyInfo); | ||
| 139 | |||
| 140 | protected constant SCode.Element max = SCode.COMPONENT("max",commonPrefixes, | ||
| 141 | attrParam,Absyn.TPATH(Absyn.IDENT("RealType"),NONE()), | ||
| 142 | SCode.MOD(SCode.NOT_FINAL(),SCode.NOT_EACH(),{},SOME(Absyn.REAL("1e+099")), NONE(), Absyn.dummyInfo),SCode.noComment,NONE(),Absyn.dummyInfo); | ||
| 143 | |||
| 144 | protected constant SCode.Element startOrigin = SCode.COMPONENT("startOrigin",commonPrefixes, | ||
| 145 | attrParam,Absyn.TPATH(Absyn.IDENT("StringType"),NONE()), | ||
| 146 | SCode.MOD(SCode.NOT_FINAL(),SCode.NOT_EACH(),{},SOME(Absyn.STRING("undefined")), NONE(), Absyn.dummyInfo),SCode.noComment,NONE(),Absyn.dummyInfo); | ||
| 147 | |||
| 148 | protected constant SCode.Element realStart = SCode.COMPONENT("start",commonPrefixes, | ||
| 149 | attrParam,Absyn.TPATH(Absyn.IDENT("RealType"),NONE()), | ||
| 150 | SCode.MOD(SCode.NOT_FINAL(),SCode.NOT_EACH(),{},SOME(Absyn.REAL("0.0")), NONE(), Absyn.dummyInfo),SCode.noComment,NONE(),Absyn.dummyInfo); | ||
| 151 | |||
| 152 | protected constant SCode.Element integerStart = SCode.COMPONENT("start",commonPrefixes, | ||
| 153 | attrParam,Absyn.TPATH(Absyn.IDENT("IntegerType"),NONE()), | ||
| 154 | SCode.MOD(SCode.NOT_FINAL(),SCode.NOT_EACH(),{},SOME(Absyn.INTEGER(0)), NONE(), Absyn.dummyInfo),SCode.noComment,NONE(),Absyn.dummyInfo); | ||
| 155 | |||
| 156 | protected constant SCode.Element stringStart = SCode.COMPONENT("start",commonPrefixes, | ||
| 157 | attrParam,Absyn.TPATH(Absyn.IDENT("StringType"),NONE()), | ||
| 158 | SCode.MOD(SCode.NOT_FINAL(),SCode.NOT_EACH(),{},SOME(Absyn.STRING("")), NONE(), Absyn.dummyInfo),SCode.noComment,NONE(),Absyn.dummyInfo); | ||
| 159 | |||
| 160 | protected constant SCode.Element booleanStart = SCode.COMPONENT("start",commonPrefixes, | ||
| 161 | attrParam,Absyn.TPATH(Absyn.IDENT("BooleanType"),NONE()), | ||
| 162 | SCode.MOD(SCode.NOT_FINAL(),SCode.NOT_EACH(),{},SOME(Absyn.BOOL(false)), NONE(), Absyn.dummyInfo),SCode.noComment,NONE(),Absyn.dummyInfo); | ||
| 163 | |||
| 164 | protected constant SCode.Element fixed = SCode.COMPONENT("fixed",commonPrefixes, | ||
| 165 | attrParam,Absyn.TPATH(Absyn.IDENT("BooleanType"),NONE()), | ||
| 166 | SCode.MOD(SCode.NOT_FINAL(),SCode.NOT_EACH(),{},SOME(Absyn.BOOL(false)), NONE(), Absyn.dummyInfo),SCode.noComment,NONE(),Absyn.dummyInfo) "Should be true for variables" ; | ||
| 167 | |||
| 168 | protected constant SCode.Element nominal = SCode.COMPONENT("nominal",commonPrefixes, | ||
| 169 | attrParam,Absyn.TPATH(Absyn.IDENT("RealType"),NONE()), | ||
| 170 | SCode.MOD(SCode.NOT_FINAL(),SCode.NOT_EACH(),{},NONE(), NONE(), Absyn.dummyInfo),SCode.noComment,NONE(),Absyn.dummyInfo); | ||
| 171 | |||
| 172 | protected constant SCode.Element stateSelect = SCode.COMPONENT("stateSelect",commonPrefixes, | ||
| 173 | attrParam,Absyn.TPATH(Absyn.IDENT("StateSelect"),NONE()), | ||
| 174 | SCode.MOD(SCode.NOT_FINAL(),SCode.NOT_EACH(),{}, | ||
| 175 | SOME( | ||
| 176 | Absyn.CREF( | ||
| 177 | Absyn.CREF_QUAL("StateSelect",{},Absyn.CREF_IDENT("default",{})))), NONE(), Absyn.dummyInfo),SCode.noComment,NONE(),Absyn.dummyInfo); | ||
| 178 | |||
| 179 | // Extensions for uncertainties | ||
| 180 | protected constant SCode.Element uncertainty=SCode.COMPONENT("uncertain",commonPrefixes, | ||
| 181 | attrParam,Absyn.TPATH(Absyn.IDENT("Uncertainty"),NONE()), | ||
| 182 | SCode.MOD(SCode.NOT_FINAL(),SCode.NOT_EACH(),{}, | ||
| 183 | SOME(Absyn.CREF(Absyn.CREF_QUAL("Uncertainty",{},Absyn.CREF_IDENT("given",{})))),NONE(),Absyn.dummyInfo),SCode.noComment,NONE(),Absyn.dummyInfo); | ||
| 184 | |||
| 185 | protected constant SCode.Element distribution = SCode.COMPONENT("distribution",commonPrefixes,attrParam,Absyn.TPATH(Absyn.IDENT("Distribution"),NONE()), | ||
| 186 | SCode.NOMOD(),SCode.noComment,NONE(),Absyn.dummyInfo); // Distribution is declared in ModelicaBuiltin.mo | ||
| 187 | // END Extensions for uncertainties | ||
| 188 | |||
| 189 | protected constant list<SCode.Element> stateSelectComps = { | ||
| 190 | SCode.COMPONENT("never",commonPrefixes, | ||
| 191 | attrConst,Absyn.TPATH(Absyn.IDENT("EnumType"),NONE()),SCode.NOMOD(),SCode.noComment,NONE(),Absyn.dummyInfo), | ||
| 192 | SCode.COMPONENT("avoid",commonPrefixes, | ||
| 193 | attrConst,Absyn.TPATH(Absyn.IDENT("EnumType"),NONE()),SCode.NOMOD(),SCode.noComment,NONE(),Absyn.dummyInfo), | ||
| 194 | SCode.COMPONENT("default",commonPrefixes, | ||
| 195 | attrConst,Absyn.TPATH(Absyn.IDENT("EnumType"),NONE()),SCode.NOMOD(),SCode.noComment,NONE(),Absyn.dummyInfo), | ||
| 196 | SCode.COMPONENT("prefer",commonPrefixes, | ||
| 197 | attrConst,Absyn.TPATH(Absyn.IDENT("EnumType"),NONE()),SCode.NOMOD(),SCode.noComment,NONE(),Absyn.dummyInfo), | ||
| 198 | SCode.COMPONENT("always",commonPrefixes, | ||
| 199 | attrConst,Absyn.TPATH(Absyn.IDENT("EnumType"),NONE()),SCode.NOMOD(),SCode.noComment,NONE(),Absyn.dummyInfo)} "The StateSelect enumeration" ; | ||
| 200 | |||
| 201 | protected constant list<SCode.Element> uncertaintyComps = { | ||
| 202 | SCode.COMPONENT("given",commonPrefixes, | ||
| 203 | attrConst,Absyn.TPATH(Absyn.IDENT("EnumType"),NONE()),SCode.NOMOD(),SCode.noComment,NONE(),Absyn.dummyInfo), | ||
| 204 | SCode.COMPONENT("sought",commonPrefixes, | ||
| 205 | attrConst,Absyn.TPATH(Absyn.IDENT("EnumType"),NONE()),SCode.NOMOD(),SCode.noComment,NONE(),Absyn.dummyInfo), | ||
| 206 | SCode.COMPONENT("refine",commonPrefixes, | ||
| 207 | attrConst,Absyn.TPATH(Absyn.IDENT("EnumType"),NONE()),SCode.NOMOD(),SCode.noComment,NONE(),Absyn.dummyInfo), | ||
| 208 | SCode.COMPONENT("propagate",commonPrefixes, | ||
| 209 | attrConst,Absyn.TPATH(Absyn.IDENT("EnumType"),NONE()),SCode.NOMOD(),SCode.noComment,NONE(),Absyn.dummyInfo)} "The Uncertainty enumeration" ; | ||
| 210 | |||
| 211 | protected constant SCode.Element stateSelectType = SCode.CLASS("StateSelect",commonPrefixes,SCode.NOT_ENCAPSULATED(),SCode.NOT_PARTIAL(),SCode.R_ENUMERATION(), | ||
| 212 | SCode.PARTS(stateSelectComps,{},{},{},{},{},{},NONE()),SCode.noComment,Absyn.dummyInfo) "The State Select Type"; | ||
| 213 | |||
| 214 | protected constant SCode.Element uncertaintyType = SCode.CLASS("Uncertainty",commonPrefixes,SCode.NOT_ENCAPSULATED(),SCode.NOT_PARTIAL(),SCode.R_ENUMERATION(), | ||
| 215 | SCode.PARTS(uncertaintyComps,{},{},{},{},{},{},NONE()),SCode.noComment,Absyn.dummyInfo) "The Uncertainty Type"; | ||
| 216 | |||
| 217 | protected constant SCode.Element ExternalObjectType = SCode.CLASS("ExternalObject",commonPrefixes,SCode.NOT_ENCAPSULATED(),SCode.NOT_PARTIAL(),SCode.R_CLASS(), | ||
| 218 | SCode.PARTS({},{},{},{},{},{},{},NONE()),SCode.noComment,Absyn.dummyInfo) "ExternalObject type" ; | ||
| 219 | |||
| 220 | // The Real type | ||
| 221 | protected constant SCode.Element realType = SCode.CLASS("Real",commonPrefixes,SCode.NOT_ENCAPSULATED(),SCode.NOT_PARTIAL(),SCode.R_PREDEFINED_REAL(), | ||
| 222 | SCode.PARTS({unit,quantity,displayUnit,min,max,realStart,fixed,nominal, | ||
| 223 | stateSelect,uncertainty,distribution,startOrigin},{},{},{},{},{},{},NONE()),SCode.noComment,Absyn.dummyInfo) "- The `Real\' type" ; | ||
| 224 | |||
| 225 | // The Integer type | ||
| 226 | protected constant SCode.Element integerType = SCode.CLASS("Integer",commonPrefixes,SCode.NOT_ENCAPSULATED(),SCode.NOT_PARTIAL(),SCode.R_PREDEFINED_INTEGER(), | ||
| 227 | SCode.PARTS({quantity,min,max,integerStart,fixed,uncertainty,distribution,startOrigin},{},{},{},{},{},{},NONE()),SCode.noComment,Absyn.dummyInfo) "- The `Integer\' type" ; | ||
| 228 | |||
| 229 | // The String type | ||
| 230 | protected constant SCode.Element stringType = SCode.CLASS("String",commonPrefixes,SCode.NOT_ENCAPSULATED(),SCode.NOT_PARTIAL(),SCode.R_PREDEFINED_STRING(), | ||
| 231 | SCode.PARTS({quantity,stringStart,startOrigin},{},{},{},{},{},{},NONE()),SCode.noComment,Absyn.dummyInfo) "- The `String\' type" ; | ||
| 232 | |||
| 233 | // The Boolean type | ||
| 234 | protected constant SCode.Element booleanType = SCode.CLASS("Boolean",commonPrefixes,SCode.NOT_ENCAPSULATED(),SCode.NOT_PARTIAL(),SCode.R_PREDEFINED_BOOLEAN(), | ||
| 235 | SCode.PARTS({quantity,booleanStart,fixed,startOrigin},{},{},{},{},{},{},NONE()),SCode.noComment,Absyn.dummyInfo) "- The `Boolean\' type" ; | ||
| 236 | |||
| 237 | // BTH The Clock type | ||
| 238 | protected constant SCode.Element clockType = SCode.CLASS("Clock",commonPrefixes,SCode.NOT_ENCAPSULATED(),SCode.NOT_PARTIAL(),SCode.R_PREDEFINED_CLOCK(), | ||
| 239 | SCode.PARTS({},{},{},{},{},{},{},NONE()),SCode.noComment,Absyn.dummyInfo) "- The `Clock\' type" ; | ||
| 240 | |||
| 241 | // The builtin variable time. See also variableIsBuiltin | ||
| 242 | protected constant DAE.Var timeVar = DAE.TYPES_VAR("time", | ||
| 243 | DAE.dummyAttrInput, | ||
| 244 | DAE.T_REAL_DEFAULT,DAE.UNBOUND(),false,NONE()); | ||
| 245 | |||
| 246 | /* Optimica Extensions. Theses variables are considered builtin for Optimica: startTime, finalTime, objectiveIntegrand and objective */ | ||
| 247 | /* Optimica Extensions. The builtin variable startTime. */ | ||
| 248 | protected constant DAE.Var startTimeVar = DAE.TYPES_VAR("startTime", | ||
| 249 | DAE.dummyAttrInput, | ||
| 250 | DAE.T_REAL_DEFAULT,DAE.UNBOUND(),false,NONE()) "- The `startTime\' variable" ; | ||
| 251 | |||
| 252 | /* Optimica Extensions. The builtin variable finalTime. */ | ||
| 253 | protected constant DAE.Var finalTimeVar = DAE.TYPES_VAR("finalTime", | ||
| 254 | DAE.dummyAttrInput, | ||
| 255 | DAE.T_REAL_DEFAULT,DAE.UNBOUND(),false,NONE()) "- The `finalTime\' variable" ; | ||
| 256 | |||
| 257 | /* Optimica Extensions. The builtin variable objectiveIntegrand. */ | ||
| 258 | protected constant DAE.Var objectiveIntegrandVar = DAE.TYPES_VAR("objectiveIntegrand", | ||
| 259 | DAE.dummyAttrInput, | ||
| 260 | DAE.T_REAL_DEFAULT,DAE.UNBOUND(),false,NONE()) "- The `objectiveIntegrand\' variable" ; | ||
| 261 | |||
| 262 | /* Optimica Extensions. The builtin variable objective. */ | ||
| 263 | protected constant DAE.Var objectiveVar = DAE.TYPES_VAR("objective", | ||
| 264 | DAE.dummyAttrInput, | ||
| 265 | DAE.T_REAL_DEFAULT,DAE.UNBOUND(),false,NONE()) "- The `objective\' variable" ; | ||
| 266 | |||
| 267 | protected constant DAE.FuncArg argRealX = DAE.FUNCARG("x",DAE.T_REAL_DEFAULT,DAE.C_VAR(),DAE.NON_PARALLEL(),NONE()); | ||
| 268 | protected constant DAE.FuncArg argRealY = DAE.FUNCARG("y",DAE.T_REAL_DEFAULT,DAE.C_VAR(),DAE.NON_PARALLEL(),NONE()); | ||
| 269 | protected constant DAE.FuncArg argRealZ = DAE.FUNCARG("z",DAE.T_REAL_DEFAULT,DAE.C_VAR(),DAE.NON_PARALLEL(),NONE()); | ||
| 270 | |||
| 271 | protected constant list<DAE.FuncArg> argsRealX = {argRealX}; | ||
| 272 | protected constant list<DAE.FuncArg> argsRealXY = {argRealX, argRealY}; | ||
| 273 | protected constant list<DAE.FuncArg> argsRealXYZ = {argRealX, argRealY, argRealZ}; | ||
| 274 | |||
| 275 | protected constant SCode.Element timeComp = | ||
| 276 | SCode.COMPONENT( | ||
| 277 | "time", | ||
| 278 | SCode.defaultPrefixes, | ||
| 279 | SCode.ATTR({}, SCode.POTENTIAL(), SCode.NON_PARALLEL(), SCode.VAR(), Absyn.INPUT(),Absyn.NONFIELD()), | ||
| 280 | Absyn.TPATH(Absyn.IDENT("Real"), NONE()), SCode.NOMOD(), | ||
| 281 | SCode.noComment, NONE(), Absyn.dummyInfo); | ||
| 282 | |||
| 283 | protected constant SCode.Element startTimeComp = | ||
| 284 | SCode.COMPONENT( | ||
| 285 | "startTime", | ||
| 286 | SCode.defaultPrefixes, | ||
| 287 | SCode.ATTR({}, SCode.POTENTIAL(), SCode.NON_PARALLEL(), SCode.VAR(), Absyn.INPUT(),Absyn.NONFIELD()), | ||
| 288 | Absyn.TPATH(Absyn.IDENT("Real"), NONE()), SCode.NOMOD(), | ||
| 289 | SCode.noComment, NONE(), Absyn.dummyInfo); | ||
| 290 | |||
| 291 | protected constant SCode.Element finalTimeComp = | ||
| 292 | SCode.COMPONENT( | ||
| 293 | "finalTime", | ||
| 294 | SCode.defaultPrefixes, | ||
| 295 | SCode.ATTR({}, SCode.POTENTIAL(), SCode.NON_PARALLEL(), SCode.VAR(), Absyn.INPUT(),Absyn.NONFIELD()), | ||
| 296 | Absyn.TPATH(Absyn.IDENT("Real"), NONE()), SCode.NOMOD(), | ||
| 297 | SCode.noComment, NONE(), Absyn.dummyInfo); | ||
| 298 | |||
| 299 | protected constant SCode.Element objectiveIntegrandComp = | ||
| 300 | SCode.COMPONENT( | ||
| 301 | "objectiveIntegrand", | ||
| 302 | SCode.defaultPrefixes, | ||
| 303 | SCode.ATTR({}, SCode.POTENTIAL(), SCode.NON_PARALLEL(), SCode.VAR(), Absyn.INPUT(),Absyn.NONFIELD()), | ||
| 304 | Absyn.TPATH(Absyn.IDENT("Real"), NONE()), SCode.NOMOD(), | ||
| 305 | SCode.noComment, NONE(), Absyn.dummyInfo); | ||
| 306 | |||
| 307 | protected constant SCode.Element objectiveVarComp = | ||
| 308 | SCode.COMPONENT( | ||
| 309 | "objectiveVar", | ||
| 310 | SCode.defaultPrefixes, | ||
| 311 | SCode.ATTR({}, SCode.POTENTIAL(), SCode.NON_PARALLEL(), SCode.VAR(), Absyn.INPUT(),Absyn.NONFIELD()), | ||
| 312 | Absyn.TPATH(Absyn.IDENT("Real"), NONE()), SCode.NOMOD(), | ||
| 313 | SCode.noComment, NONE(), Absyn.dummyInfo); | ||
| 314 | |||
| 315 | protected constant list<SCode.Element> basicTypes = {clockType, rlType, intType, strType, boolType, enumType, ExternalObjectType, realType, integerType, stringType, booleanType, uncertaintyType}; | ||
| 316 | protected constant list<SCode.Element> basicTypesNF = {rlType, intType, strType, boolType, enumType, realType, integerType, stringType, booleanType}; | ||
| 317 | |||
| 318 | public function getBasicTypes | ||
| 319 | output list<SCode.Element> tys; | ||
| 320 | algorithm | ||
| 321 |
2/2✓ Branch 1 taken 1324 times.
✓ Branch 2 taken 872 times.
|
2196 | tys := if Flags.isSet(Flags.SCODE_INST) then basicTypesNF else basicTypes; |
| 322 | end getBasicTypes; | ||
| 323 | |||
| 324 | public function variableIsBuiltin | ||
| 325 | "Returns true if cref is a builtin variable. | ||
| 326 | Currently only 'time' is a builtin variable." | ||
| 327 | input DAE.ComponentRef cref; | ||
| 328 | input Boolean useOptimica; | ||
| 329 | output Boolean b; | ||
| 330 | algorithm | ||
| 331 | b := match (cref, useOptimica) | ||
| 332 | case(DAE.CREF_IDENT(ident="time"),_) then true; | ||
| 333 | case(_,false) then false; | ||
| 334 | |||
| 335 | //If accepting Optimica then these variabels are also builtin | ||
| 336 | case(DAE.CREF_IDENT(ident="startTime"),true) then true; | ||
| 337 | case(DAE.CREF_IDENT(ident="finalTime"),true) then true; | ||
| 338 | case(DAE.CREF_IDENT(ident="objective"),true) then true; | ||
| 339 | case(DAE.CREF_IDENT(ident="objectiveIntegrand"),true) then true; | ||
| 340 | |||
| 341 | else false; | ||
| 342 | end match; | ||
| 343 | end variableIsBuiltin; | ||
| 344 | |||
| 345 | public function isDer | ||
| 346 | input Absyn.Path inPath; | ||
| 347 | algorithm | ||
| 348 | ():= | ||
| 349 | match inPath | ||
| 350 | local Absyn.Path path; | ||
| 351 | case Absyn.IDENT(name = "der") then (); | ||
| 352 | ✗ | case Absyn.FULLYQUALIFIED(path) algorithm isDer(path); then (); | |
| 353 | end match; | ||
| 354 | end isDer; | ||
| 355 | |||
| 356 | protected function mergePrograms | ||
| 357 | input Absyn.Program program1; | ||
| 358 | input Absyn.Program program2; | ||
| 359 | output Absyn.Program outProgram = program1; | ||
| 360 | algorithm | ||
| 361 | 154 | outProgram.classes := listAppend(program1.classes, program2.classes); | |
| 362 | end mergePrograms; | ||
| 363 | |||
| 364 | public function getInitialFunctions | ||
| 365 | "Fetches the Absyn.Program representation of the functions (and other classes) in the initial environment" | ||
| 366 | output Absyn.Program initialProgram; | ||
| 367 | output SCode.Program initialSCodeProgram; | ||
| 368 | protected | ||
| 369 | // legend: NF = new frontend; CF = current frontend | ||
| 370 | String fileModelicaNF,fileModelicaCF,fileMetaModelica,fileParModelica,filePDEModelica; | ||
| 371 | list<tuple<tuple<Integer,Boolean>,tuple<Absyn.Program,SCode.Program>>> assocLst; | ||
| 372 | Absyn.Program p, pNF, pCF, pMM; | ||
| 373 | SCode.Program sp, spNF, spCF; | ||
| 374 | algorithm | ||
| 375 | 10179 | fileModelicaNF := Settings.getInstallationDirectoryPath() + "/lib/omc/NFModelicaBuiltin.mo"; | |
| 376 | 10179 | fileModelicaCF := Settings.getInstallationDirectoryPath() + "/lib/omc/ModelicaBuiltin.mo"; | |
| 377 | 10179 | fileMetaModelica := Settings.getInstallationDirectoryPath() + "/lib/omc/MetaModelicaBuiltin.mo"; | |
| 378 | 10179 | fileParModelica := Settings.getInstallationDirectoryPath() + "/lib/omc/ParModelicaBuiltin.mo"; | |
| 379 | 10179 | filePDEModelica := Settings.getInstallationDirectoryPath() + "/lib/omc/PDEModelicaBuiltin.mo"; | |
| 380 | |||
| 381 | (initialProgram,initialSCodeProgram) := matchcontinue () | ||
| 382 | case () | ||
| 383 | algorithm | ||
| 384 |
2/2✓ Branch 0 taken 10179 times.
✓ Branch 1 taken 2658 times.
|
12837 | failure(getGlobalRoot(Global.builtinIndex)); |
| 385 | 2658 | setGlobalRoot(Global.builtinIndex,{}); | |
| 386 | 2658 | then fail(); | |
| 387 | case () | ||
| 388 | algorithm | ||
| 389 | 10179 | assocLst := getGlobalRoot(Global.builtinIndex); | |
| 390 |
2/2✓ Branch 1 taken 4077 times.
✓ Branch 2 taken 6102 times.
|
14256 | (p,sp) := Util.assoc(Util.makeTuple(Flags.getConfigEnum(Flags.GRAMMAR), Flags.isSet(Flags.SCODE_INST)) , assocLst); |
| 391 | then (p,sp); | ||
| 392 | case () | ||
| 393 | algorithm | ||
| 394 |
2/2✓ Branch 1 taken 2902 times.
✓ Branch 2 taken 76 times.
|
2978 | true := intEq(Flags.getConfigEnum(Flags.GRAMMAR), Flags.METAMODELICA); |
| 395 | 76 | Error.assertionOrAddSourceMessage(System.regularFileExists(fileModelicaNF),Error.FILE_NOT_FOUND_ERROR,{fileModelicaNF},Absyn.dummyInfo); | |
| 396 | 76 | Error.assertionOrAddSourceMessage(System.regularFileExists(fileModelicaCF),Error.FILE_NOT_FOUND_ERROR,{fileModelicaCF},Absyn.dummyInfo); | |
| 397 | 76 | Error.assertionOrAddSourceMessage(System.regularFileExists(fileMetaModelica),Error.FILE_NOT_FOUND_ERROR,{fileMetaModelica},Absyn.dummyInfo); | |
| 398 | 76 | pNF := Parser.parse(fileModelicaNF, "UTF-8", "", NONE(), acceptedGram = Flags.METAMODELICA); | |
| 399 | 76 | pCF := Parser.parse(fileModelicaCF, "UTF-8", "", NONE(), acceptedGram = Flags.METAMODELICA); | |
| 400 | 76 | pMM := Parser.parse(fileMetaModelica, "UTF-8", "", NONE(), acceptedGram = Flags.METAMODELICA); | |
| 401 | 76 | pNF := mergePrograms(pNF, pMM); | |
| 402 | 76 | pCF := mergePrograms(pCF, pMM); | |
| 403 | 76 | pNF := MetaUtil.createMetaClassesInProgram(pNF); | |
| 404 | 76 | pCF := MetaUtil.createMetaClassesInProgram(pCF); | |
| 405 |
4/4✓ Branch 0 taken 16340 times.
✓ Branch 1 taken 76 times.
✓ Branch 2 taken 16340 times.
✓ Branch 3 taken 76 times.
|
16416 | spNF := list(AbsynToSCode.translateClass(c) for c in pNF.classes); |
| 406 |
4/4✓ Branch 0 taken 15352 times.
✓ Branch 1 taken 76 times.
✓ Branch 2 taken 15352 times.
✓ Branch 3 taken 76 times.
|
15428 | spCF := list(AbsynToSCode.translateClass(c) for c in pCF.classes); |
| 407 | 76 | assocLst := getGlobalRoot(Global.builtinIndex); | |
| 408 | 152 | setGlobalRoot(Global.builtinIndex, ((Flags.METAMODELICA, true), (pNF,spNF))::((Flags.METAMODELICA, false), (pCF,spCF))::assocLst); | |
| 409 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 2 taken 73 times.
|
76 | (p, sp) := if Flags.isSet(Flags.SCODE_INST) then (pNF, spNF) else (pCF, spCF); |
| 410 | then (p,sp); | ||
| 411 | case () | ||
| 412 | algorithm | ||
| 413 |
1/2✓ Branch 1 taken 2902 times.
✗ Branch 2 not taken.
|
2902 | true := intEq(Flags.getConfigEnum(Flags.GRAMMAR), Flags.PARMODELICA); |
| 414 | ✗ | Error.assertionOrAddSourceMessage(System.regularFileExists(fileModelicaNF),Error.FILE_NOT_FOUND_ERROR,{fileModelicaNF},Absyn.dummyInfo); | |
| 415 | ✗ | Error.assertionOrAddSourceMessage(System.regularFileExists(fileModelicaCF),Error.FILE_NOT_FOUND_ERROR,{fileModelicaCF},Absyn.dummyInfo); | |
| 416 | ✗ | Error.assertionOrAddSourceMessage(System.regularFileExists(fileMetaModelica),Error.FILE_NOT_FOUND_ERROR,{fileMetaModelica},Absyn.dummyInfo); | |
| 417 | ✗ | pNF := Parser.parse(fileModelicaNF, "UTF-8", "", NONE(), acceptedGram = Flags.METAMODELICA); | |
| 418 | ✗ | pCF := Parser.parse(fileModelicaCF, "UTF-8", "", NONE(), acceptedGram = Flags.METAMODELICA); | |
| 419 | ✗ | pMM := Parser.parse(fileParModelica, "UTF-8", "", NONE(), acceptedGram = Flags.METAMODELICA); | |
| 420 | ✗ | pNF := mergePrograms(pNF, pMM); | |
| 421 | ✗ | pCF := mergePrograms(pCF, pMM); | |
| 422 | ✗ | spNF := list(AbsynToSCode.translateClass(c) for c in pNF.classes); | |
| 423 | ✗ | spCF := list(AbsynToSCode.translateClass(c) for c in pCF.classes); | |
| 424 | ✗ | assocLst := getGlobalRoot(Global.builtinIndex); | |
| 425 | ✗ | setGlobalRoot(Global.builtinIndex, ((Flags.PARMODELICA, true), (pNF,spNF))::((Flags.PARMODELICA, false), (pCF,spCF))::assocLst); | |
| 426 | ✗ | (p, sp) := if Flags.isSet(Flags.SCODE_INST) then (pNF, spNF) else (pCF, spCF); | |
| 427 | then (p,sp); | ||
| 428 | case () | ||
| 429 | algorithm | ||
| 430 |
4/4✓ Branch 1 taken 298 times.
✓ Branch 2 taken 2604 times.
✓ Branch 4 taken 297 times.
✓ Branch 5 taken 1 time.
|
2902 | true := intEq(Flags.getConfigEnum(Flags.GRAMMAR), Flags.MODELICA) or intEq(Flags.getConfigEnum(Flags.GRAMMAR), Flags.OPTIMICA); |
| 431 | 2901 | Error.assertionOrAddSourceMessage(System.regularFileExists(fileModelicaNF),Error.FILE_NOT_FOUND_ERROR,{fileModelicaNF},Absyn.dummyInfo); | |
| 432 | 2901 | Error.assertionOrAddSourceMessage(System.regularFileExists(fileModelicaCF),Error.FILE_NOT_FOUND_ERROR,{fileModelicaCF},Absyn.dummyInfo); | |
| 433 | 2901 | pNF := Parser.parse(fileModelicaNF, "UTF-8", "", NONE(), acceptedGram = Flags.METAMODELICA); | |
| 434 | 2901 | pCF := Parser.parse(fileModelicaCF, "UTF-8", "", NONE(), acceptedGram = Flags.METAMODELICA); | |
| 435 |
4/4✓ Branch 0 taken 284298 times.
✓ Branch 1 taken 2901 times.
✓ Branch 2 taken 284298 times.
✓ Branch 3 taken 2901 times.
|
287199 | spNF := list(AbsynToSCode.translateClass(c) for c in pNF.classes); |
| 436 |
4/4✓ Branch 0 taken 246585 times.
✓ Branch 1 taken 2901 times.
✓ Branch 2 taken 246585 times.
✓ Branch 3 taken 2901 times.
|
249486 | spCF := list(AbsynToSCode.translateClass(c) for c in pCF.classes); |
| 437 | 2901 | assocLst := getGlobalRoot(Global.builtinIndex); | |
| 438 | 5802 | setGlobalRoot(Global.builtinIndex, ((Flags.MODELICA, true), (pNF,spNF))::((Flags.MODELICA, false), (pCF,spCF))::assocLst); | |
| 439 |
2/2✓ Branch 1 taken 2101 times.
✓ Branch 2 taken 800 times.
|
2901 | (p, sp) := if Flags.isSet(Flags.SCODE_INST) then (pNF, spNF) else (pCF, spCF); |
| 440 | then (p,sp); | ||
| 441 | case () | ||
| 442 | algorithm | ||
| 443 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 time.
|
1 | true := intEq(Flags.getConfigEnum(Flags.GRAMMAR), Flags.PDEMODELICA); |
| 444 | 1 | Error.assertionOrAddSourceMessage(System.regularFileExists(fileModelicaNF),Error.FILE_NOT_FOUND_ERROR,{fileModelicaNF},Absyn.dummyInfo); | |
| 445 | 1 | Error.assertionOrAddSourceMessage(System.regularFileExists(fileModelicaCF),Error.FILE_NOT_FOUND_ERROR,{fileModelicaCF},Absyn.dummyInfo); | |
| 446 | 1 | Error.assertionOrAddSourceMessage(System.regularFileExists(filePDEModelica),Error.FILE_NOT_FOUND_ERROR,{filePDEModelica},Absyn.dummyInfo); | |
| 447 | 1 | pNF := Parser.parse(fileModelicaNF, "UTF-8", "", NONE(), acceptedGram = Flags.METAMODELICA); | |
| 448 | 1 | pCF := Parser.parse(fileModelicaCF, "UTF-8", "", NONE(), acceptedGram = Flags.METAMODELICA); | |
| 449 | 1 | pMM := Parser.parse(filePDEModelica, "UTF-8", "", NONE(), acceptedGram = Flags.METAMODELICA); | |
| 450 | 1 | pNF := mergePrograms(pNF, pMM); | |
| 451 | 1 | pCF := mergePrograms(pCF, pMM); | |
| 452 |
4/4✓ Branch 0 taken 101 times.
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 101 times.
✓ Branch 3 taken 1 time.
|
102 | spNF := list(AbsynToSCode.translateClass(c) for c in pNF.classes); |
| 453 |
4/4✓ Branch 0 taken 88 times.
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 88 times.
✓ Branch 3 taken 1 time.
|
89 | spCF := list(AbsynToSCode.translateClass(c) for c in pCF.classes); |
| 454 | 1 | assocLst := getGlobalRoot(Global.builtinIndex); | |
| 455 | 2 | setGlobalRoot(Global.builtinIndex, ((Flags.PDEMODELICA, true), (pNF,spNF))::((Flags.PDEMODELICA, false), (pCF,spCF))::assocLst); | |
| 456 |
1/2✓ Branch 1 taken 1 time.
✗ Branch 2 not taken.
|
1 | (p, sp) := if Flags.isSet(Flags.SCODE_INST) then (pNF, spNF) else (pCF, spCF); |
| 457 | then (p,sp); | ||
| 458 | |||
| 459 | else | ||
| 460 | algorithm | ||
| 461 | ✗ | Error.addInternalError("FBuiltin.getInitialFunctions failed.", sourceInfo()); | |
| 462 | ✗ | then fail(); | |
| 463 | end matchcontinue; | ||
| 464 | end getInitialFunctions; | ||
| 465 | |||
| 466 | public function initialGraph | ||
| 467 | "The initial environment where instantiation takes place is built | ||
| 468 | up using this function. It creates an empty environment and adds | ||
| 469 | all the built-in definitions to it. | ||
| 470 | NOTE: | ||
| 471 | The following built in operators can not be described in | ||
| 472 | the type system, since they e.g. have arbitrary arguments, etc. | ||
| 473 | - fill | ||
| 474 | - cat | ||
| 475 | These operators are catched in the elabBuiltinHandler, along with all | ||
| 476 | others." | ||
| 477 | input FCore.Cache inCache; | ||
| 478 | output FCore.Cache outCache; | ||
| 479 | output FGraph.Graph graph; | ||
| 480 | protected | ||
| 481 | FCore.Cache cache; | ||
| 482 | algorithm | ||
| 483 | (outCache, graph) := matchcontinue inCache | ||
| 484 | local | ||
| 485 | SCode.Program initialProgram; | ||
| 486 | |||
| 487 | // First look for cached version | ||
| 488 | case cache algorithm | ||
| 489 | ✗ | graph := FCore.getCachedInitialGraph(cache); | |
| 490 | then (cache,graph); | ||
| 491 | |||
| 492 | // then look in the global roots[builtinEnvIndex] | ||
| 493 | case cache | ||
| 494 | algorithm | ||
| 495 | ✗ | graph := getSetInitialGraph(NONE()); | |
| 496 | then | ||
| 497 | (cache, graph); | ||
| 498 | |||
| 499 | // if no cached version found create initial graph. | ||
| 500 | case cache | ||
| 501 | algorithm | ||
| 502 | ✗ | graph := FGraph.new("graph", FCore.dummyTopModel); | |
| 503 | ✗ | graph := FGraphBuild.mkProgramGraph(basicTypes, FCore.BASIC_TYPE(), graph); | |
| 504 | |||
| 505 | ✗ | graph := initialGraphOptimica(graph, FGraphBuild.mkCompNode); | |
| 506 | ✗ | graph := initialGraphMetaModelica(graph, FGraphBuild.mkTypeNode); | |
| 507 | ✗ | graph := initialGraphModelica(graph, FGraphBuild.mkTypeNode, FGraphBuild.mkCompNode); | |
| 508 | |||
| 509 | ✗ | (_, initialProgram) := getInitialFunctions(); | |
| 510 | // add the ModelicaBuiltin/MetaModelicaBuiltin classes in the initial graph | ||
| 511 | ✗ | graph := FGraphBuild.mkProgramGraph(initialProgram, FCore.BUILTIN(), graph); | |
| 512 | |||
| 513 | ✗ | cache := FCore.setCachedInitialGraph(cache,graph); | |
| 514 | ✗ | getSetInitialGraph(SOME(graph)); | |
| 515 | then | ||
| 516 | (cache,graph); | ||
| 517 | |||
| 518 | end matchcontinue; | ||
| 519 | end initialGraph; | ||
| 520 | |||
| 521 | protected function getSetInitialGraph | ||
| 522 | "gets/sets the initial environment depending on grammar flags" | ||
| 523 | input Option<FGraph.Graph> inEnvOpt; | ||
| 524 | output FGraph.Graph initialEnv; | ||
| 525 | algorithm | ||
| 526 | initialEnv := matchcontinue inEnvOpt | ||
| 527 | local | ||
| 528 | list<tuple<Integer,FGraph.Graph>> assocLst; | ||
| 529 | FGraph.Graph graph; | ||
| 530 | |||
| 531 | // nothing there | ||
| 532 | case _ | ||
| 533 | algorithm | ||
| 534 | ✗ | failure(getGlobalRoot(Global.builtinGraphIndex)); | |
| 535 | ✗ | setGlobalRoot(Global.builtinGraphIndex, {}); | |
| 536 | ✗ | then | |
| 537 | fail(); | ||
| 538 | |||
| 539 | // return the correct graph depending on flags | ||
| 540 | case NONE() | ||
| 541 | algorithm | ||
| 542 | ✗ | assocLst := getGlobalRoot(Global.builtinGraphIndex); | |
| 543 | ✗ | then | |
| 544 | Util.assoc(Flags.getConfigEnum(Flags.GRAMMAR), assocLst); | ||
| 545 | |||
| 546 | case SOME(graph) | ||
| 547 | algorithm | ||
| 548 | ✗ | true := intEq(Flags.getConfigEnum(Flags.GRAMMAR), Flags.METAMODELICA); | |
| 549 | ✗ | assocLst := getGlobalRoot(Global.builtinGraphIndex); | |
| 550 | ✗ | setGlobalRoot(Global.builtinGraphIndex, (Flags.METAMODELICA,graph)::assocLst); | |
| 551 | then | ||
| 552 | graph; | ||
| 553 | |||
| 554 | case SOME(graph) | ||
| 555 | algorithm | ||
| 556 | ✗ | true := intEq(Flags.getConfigEnum(Flags.GRAMMAR), Flags.PARMODELICA); | |
| 557 | ✗ | assocLst := getGlobalRoot(Global.builtinGraphIndex); | |
| 558 | ✗ | setGlobalRoot(Global.builtinGraphIndex, (Flags.PARMODELICA,graph)::assocLst); | |
| 559 | then | ||
| 560 | graph; | ||
| 561 | |||
| 562 | case SOME(graph) | ||
| 563 | algorithm | ||
| 564 | ✗ | true := intEq(Flags.getConfigEnum(Flags.GRAMMAR), Flags.MODELICA) or intEq(Flags.getConfigEnum(Flags.GRAMMAR), Flags.OPTIMICA); | |
| 565 | ✗ | assocLst := getGlobalRoot(Global.builtinGraphIndex); | |
| 566 | ✗ | setGlobalRoot(Global.builtinGraphIndex, (Flags.MODELICA,graph)::assocLst); | |
| 567 | then | ||
| 568 | graph; | ||
| 569 | end matchcontinue; | ||
| 570 | end getSetInitialGraph; | ||
| 571 | |||
| 572 | public | ||
| 573 | |||
| 574 | partial function MakeTypeNode | ||
| 575 | input list<DAE.Type> inTypes "the types to add"; | ||
| 576 | input FCore.Ref inParentRef; | ||
| 577 | input FCore.Name inName "name to search for"; | ||
| 578 | input FCore.Graph inGraph; | ||
| 579 | output FCore.Graph outGraph; | ||
| 580 | end MakeTypeNode; | ||
| 581 | |||
| 582 | partial function MakeCompNode | ||
| 583 | input SCode.Element inComp; | ||
| 584 | input FCore.Ref inParentRef; | ||
| 585 | input FCore.Kind inKind; | ||
| 586 | input FCore.Graph inGraph; | ||
| 587 | output FCore.Graph outGraph; | ||
| 588 | end MakeCompNode; | ||
| 589 | |||
| 590 | function initialGraphModelica | ||
| 591 | input output FGraph.Graph graph; | ||
| 592 | input MakeTypeNode mkTypeNode; | ||
| 593 | input MakeCompNode mkCompNode; | ||
| 594 | protected | ||
| 595 | constant DAE.Type enumeration2int = | ||
| 596 | DAE.T_FUNCTION( | ||
| 597 | {DAE.FUNCARG("x",DAE.T_ENUMERATION(NONE(), Absyn.IDENT(""), {}, {}, {}),DAE.C_VAR(),DAE.NON_PARALLEL(),NONE())}, | ||
| 598 | DAE.T_INTEGER_DEFAULT, | ||
| 599 | DAE.FUNCTION_ATTRIBUTES_BUILTIN, | ||
| 600 | Absyn.IDENT("Integer")); | ||
| 601 | algorithm | ||
| 602 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2196 times.
|
2196 | graph := mkCompNode(timeComp, FGraph.top(graph), FCore.BUILTIN(), graph); |
| 603 | 2196 | graph := FGraph.updateComp(graph, timeVar, FCore.VAR_UNTYPED(), FGraph.empty()); | |
| 604 | |||
| 605 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2196 times.
|
2196 | graph := mkTypeNode({ |
| 606 | DAE.T_FUNCTION( | ||
| 607 | {DAE.FUNCARG("x", DAE.T_ANYTYPE(SOME(ClassInf.CONNECTOR(Absyn.IDENT("$dummy$"),false))),DAE.C_VAR(),DAE.NON_PARALLEL(),NONE())}, | ||
| 608 | DAE.T_INTEGER_DEFAULT, | ||
| 609 | DAE.FUNCTION_ATTRIBUTES_BUILTIN, | ||
| 610 | Absyn.IDENT("cardinality")), | ||
| 611 | DAE.T_FUNCTION( | ||
| 612 | {DAE.FUNCARG("x",DAE.T_ANYTYPE(SOME(ClassInf.CONNECTOR(Absyn.IDENT("$dummy$"),true))),DAE.C_VAR(),DAE.NON_PARALLEL(),NONE())}, | ||
| 613 | DAE.T_INTEGER_DEFAULT, | ||
| 614 | DAE.FUNCTION_ATTRIBUTES_BUILTIN, | ||
| 615 | Absyn.IDENT("cardinality"))}, | ||
| 616 | FGraph.top(graph), | ||
| 617 | "cardinality", graph); | ||
| 618 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2196 times.
|
2196 | graph := mkTypeNode({enumeration2int}, FGraph.top(graph), "Integer", graph); |
| 619 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2196 times.
|
2196 | graph := mkTypeNode({enumeration2int}, FGraph.top(graph), "EnumToInteger", graph); |
| 620 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2196 times.
|
2196 | graph := mkTypeNode({DAE.T_FUNCTION(argsRealX,DAE.T_REAL_DEFAULT,DAE.FUNCTION_ATTRIBUTES_BUILTIN,Absyn.IDENT("noEvent"))}, |
| 621 | FGraph.top(graph), "noEvent", graph); | ||
| 622 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2196 times.
|
2196 | graph := mkTypeNode({DAE.T_FUNCTION(argsRealX,DAE.T_REAL_DEFAULT,DAE.FUNCTION_ATTRIBUTES_BUILTIN,Absyn.IDENT("actualStream"))}, |
| 623 | FGraph.top(graph), "actualStream", graph); | ||
| 624 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2196 times.
|
2196 | graph := mkTypeNode({DAE.T_FUNCTION(argsRealX,DAE.T_REAL_DEFAULT,DAE.FUNCTION_ATTRIBUTES_BUILTIN,Absyn.IDENT("inStream"))}, |
| 625 | FGraph.top(graph), "inStream", graph); | ||
| 626 | end initialGraphModelica; | ||
| 627 | |||
| 628 | function initialGraphMetaModelica | ||
| 629 | input output FGraph.Graph graph; | ||
| 630 | input MakeTypeNode mkTypeNode; | ||
| 631 | algorithm | ||
| 632 |
2/2✓ Branch 1 taken 2120 times.
✓ Branch 2 taken 76 times.
|
2196 | if not Config.acceptMetaModelicaGrammar() then |
| 633 | 2120 | return; | |
| 634 | end if; | ||
| 635 | |||
| 636 | // getGlobalRoot can not be represented by a regular function... | ||
| 637 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 76 times.
|
76 | graph := mkTypeNode({DAE.T_FUNCTION( |
| 638 | {DAE.FUNCARG("index",DAE.T_INTEGER_DEFAULT,DAE.C_VAR(),DAE.NON_PARALLEL(),NONE())}, | ||
| 639 | DAE.T_METABOXED_DEFAULT, | ||
| 640 | DAE.FUNCTION_ATTRIBUTES_BUILTIN, | ||
| 641 | Absyn.IDENT("getGlobalRoot"))}, FGraph.top(graph), "getGlobalRoot", graph); | ||
| 642 | end initialGraphMetaModelica; | ||
| 643 | |||
| 644 | function initialGraphOptimica | ||
| 645 | input output FGraph.Graph graph; | ||
| 646 | input MakeCompNode mkCompNode; | ||
| 647 | algorithm | ||
| 648 |
2/2✓ Branch 1 taken 1965 times.
✓ Branch 2 taken 231 times.
|
2196 | if not Config.acceptOptimicaGrammar() then |
| 649 | 1965 | return; | |
| 650 | end if; | ||
| 651 | |||
| 652 | //If Optimica add the startTime,finalTime,objectiveIntegrand and objective "builtin" variables. | ||
| 653 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 231 times.
|
231 | graph := mkCompNode(objectiveVarComp, FGraph.top(graph), FCore.BUILTIN(), graph); |
| 654 | 231 | graph := FGraph.updateComp(graph, objectiveVar, FCore.VAR_UNTYPED(), FGraph.empty()); | |
| 655 | |||
| 656 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 231 times.
|
231 | graph := mkCompNode(objectiveIntegrandComp, FGraph.top(graph), FCore.BUILTIN(), graph); |
| 657 | 231 | graph := FGraph.updateComp(graph, objectiveIntegrandVar, FCore.VAR_UNTYPED(), FGraph.empty()); | |
| 658 | |||
| 659 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 231 times.
|
231 | graph := mkCompNode(startTimeComp, FGraph.top(graph), FCore.BUILTIN(), graph); |
| 660 | 231 | graph := FGraph.updateComp(graph, startTimeVar, FCore.VAR_UNTYPED(), FGraph.empty()); | |
| 661 | |||
| 662 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 231 times.
|
231 | graph := mkCompNode(finalTimeComp, FGraph.top(graph), FCore.BUILTIN(), graph); |
| 663 | 231 | graph := FGraph.updateComp(graph, finalTimeVar, FCore.VAR_UNTYPED(), FGraph.empty()); | |
| 664 | |||
| 665 | end initialGraphOptimica; | ||
| 666 | |||
| 667 | function getElementWithPathCheckBuiltin | ||
| 668 | "returns the element from the program having the name as the id. | ||
| 669 | if the element does not exist it fails" | ||
| 670 | input SCode.Program inProgram; | ||
| 671 | input Absyn.Path inPath; | ||
| 672 | output SCode.Element outElement; | ||
| 673 | algorithm | ||
| 674 | outElement := matchcontinue inPath | ||
| 675 | local | ||
| 676 | SCode.Program sp; | ||
| 677 | |||
| 678 | case _ | ||
| 679 | 78 | then SCodeUtil.getElementWithPath(inProgram, inPath); | |
| 680 | |||
| 681 | else | ||
| 682 | algorithm | ||
| 683 | ✗ | (_,sp) := FBuiltin.getInitialFunctions(); | |
| 684 | ✗ | then SCodeUtil.getElementWithPath(sp, inPath); | |
| 685 | end matchcontinue; | ||
| 686 | end getElementWithPathCheckBuiltin; | ||
| 687 | |||
| 688 | annotation(__OpenModelica_Interface="frontend"); | ||
| 689 | end FBuiltin; | ||
| 690 |