OMCompiler/Compiler/Script/StaticScript.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 StaticScript | ||
| 37 | |||
| 38 | public import Absyn; | ||
| 39 | public import DAE; | ||
| 40 | public import FCore; | ||
| 41 | |||
| 42 | protected type Ident = String; | ||
| 43 | |||
| 44 | protected | ||
| 45 | |||
| 46 | import Ceval; | ||
| 47 | import CevalScript; | ||
| 48 | import CevalScriptBackend; | ||
| 49 | import ClassInf; | ||
| 50 | import ComponentReference; | ||
| 51 | import Error; | ||
| 52 | import ErrorExt; | ||
| 53 | import Expression; | ||
| 54 | import ExpressionSimplify; | ||
| 55 | import Flags; | ||
| 56 | import Static; | ||
| 57 | import Values; | ||
| 58 | |||
| 59 | |||
| 60 | protected function calculateSimulationTimes | ||
| 61 | "@author: | ||
| 62 | Calculates the simulation times: startTime, stopTime, numberOfIntervals from the given input arguments" | ||
| 63 | input FCore.Cache inCache; | ||
| 64 | input FCore.Graph inEnv; | ||
| 65 | input list<Absyn.Exp> inAbsynExpLst; | ||
| 66 | input list<Absyn.NamedArg> inAbsynNamedArgLst; | ||
| 67 | input Boolean inImplInst; | ||
| 68 | input DAE.Prefix inPrefix; | ||
| 69 | input SourceInfo inInfo; | ||
| 70 | input InteractiveTypes.SimulationOptions inSimOpt; | ||
| 71 | output FCore.Cache outCache; | ||
| 72 | output DAE.Exp startTime "start time, default 0.0"; | ||
| 73 | output DAE.Exp stopTime "stop time, default 1.0"; | ||
| 74 | output DAE.Exp numberOfIntervals "number of intervals, default 500"; | ||
| 75 | algorithm | ||
| 76 | (outCache, startTime, stopTime, numberOfIntervals) := | ||
| 77 | matchcontinue (inCache, inEnv, inAbsynExpLst, inAbsynNamedArgLst, inImplInst, inPrefix, inInfo) | ||
| 78 | local | ||
| 79 | list<Absyn.NamedArg> args; | ||
| 80 | Boolean impl; | ||
| 81 | DAE.Prefix pre; | ||
| 82 | SourceInfo info; | ||
| 83 | Integer intervals; | ||
| 84 | Real rstepTime, rstopTime, rstartTime; | ||
| 85 | FCore.Cache cache; | ||
| 86 | FCore.Graph env; | ||
| 87 | |||
| 88 | // special case for Parham Vaseles OpenModelica Interactive, where buildModel takes stepSize instead of startTime, stopTime and numberOfIntervals | ||
| 89 | case (cache, env, {Absyn.CREF()}, args, impl, pre, info) | ||
| 90 | algorithm | ||
| 91 | // An ICONST is used as the default value of stepSize so that this case | ||
| 92 | // fails if stepSize isn't given as argument to buildModel. | ||
| 93 |
1/2✓ Branch 1 taken 1295 times.
✗ Branch 2 not taken.
|
1295 | (cache, DAE.RCONST(rstepTime)) := |
| 94 | Static.getOptionalNamedArg(cache, env, impl, "stepSize", DAE.T_REAL_DEFAULT, | ||
| 95 | args, DAE.ICONST(0), // force failure if stepSize is not found via division by zero below! | ||
| 96 | pre, info); | ||
| 97 | |||
| 98 | ✗ | (cache,startTime as DAE.RCONST(rstartTime)) := | |
| 99 | Static.getOptionalNamedArg(cache, env, impl, "startTime", DAE.T_REAL_DEFAULT, | ||
| 100 | args, CevalScriptBackend.getSimulationOption(inSimOpt, "startTime"), | ||
| 101 | pre, info); | ||
| 102 | |||
| 103 | ✗ | (cache,stopTime as DAE.RCONST(rstopTime)) := | |
| 104 | Static.getOptionalNamedArg(cache, env, impl, "stopTime", DAE.T_REAL_DEFAULT, | ||
| 105 | args, CevalScriptBackend.getSimulationOption(inSimOpt, "stopTime"), | ||
| 106 | pre, info); | ||
| 107 | |||
| 108 | ✗ | intervals := realInt((rstopTime - rstartTime) / rstepTime); | |
| 109 | ✗ | numberOfIntervals := DAE.ICONST(intervals); | |
| 110 | ✗ | then | |
| 111 | (cache, startTime, stopTime, numberOfIntervals); | ||
| 112 | |||
| 113 | // normal case, fill in defaults | ||
| 114 | case (cache, env, {Absyn.CREF()}, args, impl, pre, info) | ||
| 115 | algorithm | ||
| 116 | // An ICONST is used as the default value of stepSize so that this case | ||
| 117 | // fails if stepSize isn't given as argument to buildModel. | ||
| 118 | 1295 | (cache,startTime) := | |
| 119 | Static.getOptionalNamedArg(cache, env, impl, "startTime", DAE.T_REAL_DEFAULT, | ||
| 120 | args, CevalScriptBackend.getSimulationOption(inSimOpt, "startTime"), | ||
| 121 | pre, info); | ||
| 122 | |||
| 123 | 1295 | (cache,stopTime) := | |
| 124 | Static.getOptionalNamedArg(cache, env, impl, "stopTime", DAE.T_REAL_DEFAULT, | ||
| 125 | args, CevalScriptBackend.getSimulationOption(inSimOpt, "stopTime"), | ||
| 126 | pre, info); | ||
| 127 | |||
| 128 | 1295 | (cache,numberOfIntervals) := | |
| 129 | Static.getOptionalNamedArg(cache, env, impl, "numberOfIntervals", DAE.T_INTEGER_DEFAULT, | ||
| 130 | args, CevalScriptBackend.getSimulationOption(inSimOpt, "numberOfIntervals"), | ||
| 131 | pre, info); | ||
| 132 | 1295 | then | |
| 133 | (cache, startTime, stopTime, numberOfIntervals); | ||
| 134 | |||
| 135 | end matchcontinue; | ||
| 136 | end calculateSimulationTimes; | ||
| 137 | |||
| 138 | |||
| 139 | |||
| 140 | public function getSimulationArguments | ||
| 141 | "@author: adrpo | ||
| 142 | This functiong gets the simulation options" | ||
| 143 | input FCore.Cache inCache; | ||
| 144 | input FCore.Graph inEnv; | ||
| 145 | input list<Absyn.Exp> inAbsynExpLst; | ||
| 146 | input list<Absyn.NamedArg> inAbsynNamedArgLst; | ||
| 147 | input Boolean inImplInst; | ||
| 148 | input DAE.Prefix inPrefix; | ||
| 149 | input String callName; | ||
| 150 | input SourceInfo inInfo; | ||
| 151 | input Option<InteractiveTypes.SimulationOptions> defaultOption; | ||
| 152 | output FCore.Cache outCache; | ||
| 153 | output list<DAE.Exp> outSimulationArguments; | ||
| 154 | algorithm | ||
| 155 | (outCache, outSimulationArguments) := | ||
| 156 | match (inCache, inEnv, inAbsynExpLst, inAbsynNamedArgLst, inImplInst, inPrefix, inInfo) | ||
| 157 | local | ||
| 158 | Absyn.Exp crexp; | ||
| 159 | list<Absyn.NamedArg> args; | ||
| 160 | Boolean impl; | ||
| 161 | DAE.Prefix pre; | ||
| 162 | SourceInfo info; | ||
| 163 | String cname_str; | ||
| 164 | Absyn.Path className; | ||
| 165 | DAE.Exp exp,startTime,stopTime,numberOfIntervals,tolerance,method,cflags,simflags,resimulateExecutable; | ||
| 166 | DAE.Exp fileNamePrefix,options,outputFormat,variableFilter; | ||
| 167 | InteractiveTypes.SimulationOptions defaulSimOpt; | ||
| 168 | FCore.Cache cache; | ||
| 169 | FCore.Graph env; | ||
| 170 | Values.Value v; | ||
| 171 | |||
| 172 | // fill in defaults | ||
| 173 | case (cache, env, {crexp}, args, impl, pre, info) | ||
| 174 | algorithm | ||
| 175 | 1295 | checkSimulationArguments(args, callName, info); | |
| 176 | 1295 | exp := Static.elabCodeExp(crexp,cache,env,DAE.C_TYPENAME(),info); | |
| 177 | // We need to force eval in order to get the correct prefix | ||
| 178 | 1295 | (cache,v) := Ceval.ceval(cache,env,exp,true,Absyn.MSG(info),0); | |
| 179 |
2/4✗ Branch 1 not taken.
✓ Branch 2 taken 1295 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1295 times.
|
1295 | Values.CODE(Absyn.C_TYPENAME(className)) := CevalScript.evalCodeTypeName(v,env); |
| 180 | |||
| 181 | 1295 | cname_str := AbsynUtil.pathString(AbsynUtil.unqotePathIdents(className)) "easier than checking if the file system supports UTF-8..."; | |
| 182 | 1295 | defaulSimOpt := CevalScriptBackend.buildSimulationOptionsFromModelExperimentAnnotation(className, cname_str, defaultOption); | |
| 183 | |||
| 184 | 1295 | (cache, startTime, stopTime, numberOfIntervals) := | |
| 185 | calculateSimulationTimes(inCache, inEnv, inAbsynExpLst, inAbsynNamedArgLst, impl, inPrefix, inInfo, defaulSimOpt); | ||
| 186 | |||
| 187 | 1295 | (cache,tolerance) := | |
| 188 | Static.getOptionalNamedArg(cache, env, impl, "tolerance", DAE.T_REAL_DEFAULT, | ||
| 189 | args, CevalScriptBackend.getSimulationOption(defaulSimOpt, "tolerance"), | ||
| 190 | pre,info); | ||
| 191 | |||
| 192 | 1295 | (cache,method) := | |
| 193 | Static.getOptionalNamedArg(cache, env, impl, "method", DAE.T_STRING_DEFAULT, | ||
| 194 | args, CevalScriptBackend.getSimulationOption(defaulSimOpt, "method"), | ||
| 195 | pre, info); | ||
| 196 | |||
| 197 | 1295 | (cache,fileNamePrefix) := | |
| 198 | Static.getOptionalNamedArg(cache,env, impl, "fileNamePrefix", DAE.T_STRING_DEFAULT, | ||
| 199 | args, CevalScriptBackend.getSimulationOption(defaulSimOpt, "fileNamePrefix"), | ||
| 200 | pre, info); | ||
| 201 | |||
| 202 | 1295 | (cache,options) := | |
| 203 | Static.getOptionalNamedArg(cache, env, impl, "options", DAE.T_STRING_DEFAULT, | ||
| 204 | args, CevalScriptBackend.getSimulationOption(defaulSimOpt, "options"), | ||
| 205 | pre, info); | ||
| 206 | |||
| 207 | 1295 | (cache,outputFormat) := | |
| 208 | Static.getOptionalNamedArg(cache, env, impl, "outputFormat", DAE.T_STRING_DEFAULT, | ||
| 209 | args, CevalScriptBackend.getSimulationOption(defaulSimOpt, "outputFormat"), | ||
| 210 | pre, info); | ||
| 211 | |||
| 212 | 1295 | (cache,variableFilter) := | |
| 213 | Static.getOptionalNamedArg(cache, env, impl, "variableFilter", DAE.T_STRING_DEFAULT, | ||
| 214 | args, CevalScriptBackend.getSimulationOption(defaulSimOpt, "variableFilter"), | ||
| 215 | pre, info); | ||
| 216 | |||
| 217 | 1295 | (cache,cflags) := | |
| 218 | Static.getOptionalNamedArg(cache, env, impl, "cflags", DAE.T_STRING_DEFAULT, | ||
| 219 | args, CevalScriptBackend.getSimulationOption(defaulSimOpt, "cflags"), | ||
| 220 | pre, info); | ||
| 221 | 1295 | (cache,simflags) := | |
| 222 | Static.getOptionalNamedArg(cache, env, impl, "simflags", DAE.T_STRING_DEFAULT, | ||
| 223 | args, CevalScriptBackend.getSimulationOption(defaulSimOpt, "simflags"), | ||
| 224 | pre, info); | ||
| 225 | 1295 | (cache,resimulateExecutable) := | |
| 226 | Static.getOptionalNamedArg(cache, env, impl, "resimulateExecutable", DAE.T_STRING_DEFAULT, | ||
| 227 | args, DAE.SCONST(""), | ||
| 228 | pre, info); | ||
| 229 | |||
| 230 |
4/4✓ Branch 2 taken 1198 times.
✓ Branch 3 taken 97 times.
✓ Branch 5 taken 1164 times.
✓ Branch 6 taken 34 times.
|
1295 | then |
| 231 | (cache, | ||
| 232 | listAppend( | ||
| 233 | {DAE.CODE(Absyn.C_TYPENAME(className),DAE.T_UNKNOWN_DEFAULT), | ||
| 234 | startTime, | ||
| 235 | stopTime, | ||
| 236 | numberOfIntervals, | ||
| 237 | tolerance, | ||
| 238 | method, | ||
| 239 | fileNamePrefix, | ||
| 240 | options, | ||
| 241 | outputFormat, | ||
| 242 | variableFilter, | ||
| 243 | cflags, | ||
| 244 | simflags}, | ||
| 245 | // resimulateExecutable is a simulate()-only argument | ||
| 246 | if callName == "simulate" then {resimulateExecutable} else {})); | ||
| 247 | |||
| 248 | end match; | ||
| 249 | end getSimulationArguments; | ||
| 250 | |||
| 251 | constant list<String> VALID_SIMULATE_ARGS = { | ||
| 252 | "startTime", | ||
| 253 | "stopTime", | ||
| 254 | "numberOfIntervals", | ||
| 255 | "stepSize", | ||
| 256 | "tolerance", | ||
| 257 | "method", | ||
| 258 | "fileNamePrefix", | ||
| 259 | "options", | ||
| 260 | "outputFormat", | ||
| 261 | "variableFilter", | ||
| 262 | "cflags", | ||
| 263 | "simflags", | ||
| 264 | "resimulateExecutable" | ||
| 265 | }; | ||
| 266 | |||
| 267 | function checkSimulationArguments | ||
| 268 | input list<Absyn.NamedArg> args; | ||
| 269 | input String callName; | ||
| 270 | input SourceInfo info; | ||
| 271 | algorithm | ||
| 272 |
2/2✓ Branch 0 taken 1840 times.
✓ Branch 1 taken 1295 times.
|
3135 | for arg in args loop |
| 273 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1840 times.
|
1840 | if not listMember(arg.argName, VALID_SIMULATE_ARGS) then |
| 274 | ✗ | Error.addSourceMessage(Error.NO_SUCH_PARAMETER, {callName, arg.argName}, info); | |
| 275 | ✗ | fail(); | |
| 276 | end if; | ||
| 277 | end for; | ||
| 278 | end checkSimulationArguments; | ||
| 279 | |||
| 280 | public function elabCallInteractive "This function elaborates the functions defined in the interactive environment. | ||
| 281 | Since some of these functions are meta-functions, they can not be described in the type | ||
| 282 | system, and is thus given the the type T_UNKNOWN" | ||
| 283 | input output FCore.Cache cache; | ||
| 284 | input FCore.Graph env; | ||
| 285 | input Absyn.ComponentRef fn; | ||
| 286 | input list<Absyn.Exp> args; | ||
| 287 | input list<Absyn.NamedArg> nargs; | ||
| 288 | input Boolean impl; | ||
| 289 | input DAE.Prefix pre; | ||
| 290 | input SourceInfo info; | ||
| 291 | output DAE.Exp e; | ||
| 292 | output DAE.Properties prop; | ||
| 293 | protected | ||
| 294 | list<Integer> handles; | ||
| 295 | algorithm | ||
| 296 |
2/2✓ Branch 1 taken 20 times.
✓ Branch 2 taken 2640 times.
|
2660 | if Flags.getConfigBool(Flags.BUILDING_MODEL) then |
| 297 | 20 | ErrorExt.delCheckpoint("elabCall_InteractiveFunction"); | |
| 298 | 20 | fail(); | |
| 299 | end if; | ||
| 300 | 2640 | handles := ErrorExt.popCheckPoint("elabCall_InteractiveFunction"); | |
| 301 | try | ||
| 302 | /* An extra try-block to avoid the assignment to handles being optimized away */ | ||
| 303 | 2640 | ErrorExt.setCheckpoint("elabCall_InteractiveFunction1"); | |
| 304 | 2640 | (cache,e,prop) := elabCallInteractive_work(cache, env, fn, args, nargs, impl, pre, info) "Elaborate interactive function calls, such as simulate(), plot() etc." ; | |
| 305 | 1004 | ErrorExt.delCheckpoint("elabCall_InteractiveFunction1"); | |
| 306 | else | ||
| 307 | 1636 | ErrorExt.rollBack("elabCall_InteractiveFunction1"); | |
| 308 | 1636 | ErrorExt.pushMessages(handles); | |
| 309 | 1636 | fail(); | |
| 310 | end try; | ||
| 311 | 1004 | ErrorExt.freeMessages(handles); | |
| 312 | end elabCallInteractive; | ||
| 313 | |||
| 314 | protected function elabCallInteractive_work "This function elaborates the functions defined in the interactive environment. | ||
| 315 | Since some of these functions are meta-functions, they can not be described in the type | ||
| 316 | system, and is thus given the the type T_UNKNOWN" | ||
| 317 | input FCore.Cache inCache; | ||
| 318 | input FCore.Graph inEnv; | ||
| 319 | input Absyn.ComponentRef inComponentRef; | ||
| 320 | input list<Absyn.Exp> inExps; | ||
| 321 | input list<Absyn.NamedArg> inNamedArgs; | ||
| 322 | input Boolean inImplInst; | ||
| 323 | input DAE.Prefix inPrefix; | ||
| 324 | input SourceInfo info; | ||
| 325 | output FCore.Cache outCache; | ||
| 326 | output DAE.Exp outExp; | ||
| 327 | output DAE.Properties outProperties; | ||
| 328 | algorithm | ||
| 329 | (outCache,outExp,outProperties):= | ||
| 330 | matchcontinue | ||
| 331 | (inCache, inEnv, inComponentRef, inExps, inNamedArgs, inImplInst, inPrefix) | ||
| 332 | local | ||
| 333 | DAE.ComponentRef cr_1; | ||
| 334 | FCore.Graph env; | ||
| 335 | Absyn.ComponentRef cr,cr2; | ||
| 336 | Boolean impl; | ||
| 337 | Ident cname_str,str; | ||
| 338 | DAE.Exp filenameprefix,exp_1,crefExp,outputFile,dumpExtractionSteps; | ||
| 339 | DAE.Type recordtype; | ||
| 340 | list<Absyn.NamedArg> args; | ||
| 341 | list<DAE.Exp> excludeList; | ||
| 342 | DAE.Properties prop; | ||
| 343 | Integer excludeListSize; | ||
| 344 | Absyn.Exp exp; | ||
| 345 | FCore.Cache cache; | ||
| 346 | DAE.Prefix pre; | ||
| 347 | Absyn.Path className; | ||
| 348 | list<DAE.Exp> simulationArgs; | ||
| 349 | String name; | ||
| 350 | case (cache, env, cr2 as Absyn.CREF_IDENT(), _, _, impl, _) | ||
| 351 | algorithm | ||
| 352 | 18493 | ErrorExt.setCheckpoint("Scripting"); | |
| 353 | 18493 | cr := AbsynUtil.joinCrefs(Absyn.CREF_QUAL("OpenModelica",{},Absyn.CREF_IDENT("Scripting",{})),cr2); | |
| 354 | 18493 | (cache,exp_1,prop) := Static.elabExp(cache,env,Absyn.CALL(cr,Absyn.FUNCTIONARGS(inExps,inNamedArgs),{}),impl,false,inPrefix,info); | |
| 355 | 16947 | ErrorExt.delCheckpoint("Scripting"); | |
| 356 | 16947 | then (cache,exp_1,prop); | |
| 357 | |||
| 358 | case (_, _, Absyn.CREF_IDENT(), _, _, _, _) | ||
| 359 | algorithm | ||
| 360 | 1546 | ErrorExt.rollBack("Scripting"); | |
| 361 | 1546 | then fail(); | |
| 362 | |||
| 363 | case (cache, env, Absyn.CREF_IDENT(name = "translateModel"), {Absyn.CREF()}, args, _, _) | ||
| 364 | algorithm | ||
| 365 | 24 | (cache, simulationArgs) := getSimulationArguments(cache, env, inExps, args, inImplInst, inPrefix, "translateModel", info, NONE()); | |
| 366 | 24 | then | |
| 367 | (cache,Expression.makePureBuiltinCall("translateModel",simulationArgs,DAE.T_STRING_DEFAULT),DAE.PROP(DAE.T_STRING_DEFAULT,DAE.C_VAR())); | ||
| 368 | |||
| 369 | case (cache, env, Absyn.CREF_IDENT(name = "modelEquationsUC"), {Absyn.CREF(componentRef = cr)}, args, impl, pre) | ||
| 370 | algorithm | ||
| 371 | 14 | (cache,cr_1) := Static.elabUntypedCref(cache,env,cr,impl,pre,info); | |
| 372 | 14 | className := ComponentReference.crefToPathIgnoreSubs(cr_1) "this extracts the fileNamePrefix which is used when generating code and init-file" ; | |
| 373 | 14 | (cache,outputFile) := Static.getOptionalNamedArg(cache, env, impl, "outputFile", DAE.T_STRING_DEFAULT,args, DAE.SCONST(""),pre,info); | |
| 374 | 14 | (cache,dumpExtractionSteps) := Static.getOptionalNamedArg(cache,env,impl,"dumpSteps",DAE.T_BOOL_DEFAULT,args,DAE.BCONST(false),pre,info); | |
| 375 | 28 | then | |
| 376 | (cache,Expression.makePureBuiltinCall("modelEquationsUC",{DAE.CODE(Absyn.C_TYPENAME(className),DAE.T_UNKNOWN_DEFAULT),outputFile,dumpExtractionSteps},DAE.T_STRING_DEFAULT),DAE.PROP(DAE.T_STRING_DEFAULT,DAE.C_VAR())); | ||
| 377 | |||
| 378 | case (cache, env, Absyn.CREF_IDENT(name = "translateModelCPP"), {Absyn.CREF(componentRef = cr)}, args, impl, pre) | ||
| 379 | algorithm | ||
| 380 | ✗ | className := AbsynUtil.crefToPath(cr); | |
| 381 | ✗ | cname_str := AbsynUtil.pathString(className); | |
| 382 | ✗ | (cache,filenameprefix) := Static.getOptionalNamedArg(cache,env, impl, "fileNamePrefix", | |
| 383 | DAE.T_STRING_DEFAULT, args, DAE.SCONST(cname_str),pre,info); | ||
| 384 | recordtype := | ||
| 385 | DAE.T_COMPLEX(ClassInf.RECORD(Absyn.IDENT("SimulationObject")), | ||
| 386 | {DAE.TYPES_VAR("flatClass",DAE.dummyAttrVar,DAE.T_STRING_DEFAULT,DAE.UNBOUND(),false,NONE()), | ||
| 387 | DAE.TYPES_VAR("exeFile",DAE.dummyAttrVar,DAE.T_STRING_DEFAULT,DAE.UNBOUND(),false,NONE())}, | ||
| 388 | NONE(), false); | ||
| 389 | ✗ | then | |
| 390 | (cache,Expression.makePureBuiltinCall("translateModelCPP", | ||
| 391 | {DAE.CODE(Absyn.C_TYPENAME(className),DAE.T_UNKNOWN_DEFAULT),filenameprefix},DAE.T_STRING_DEFAULT),DAE.PROP(recordtype,DAE.C_VAR())); | ||
| 392 | |||
| 393 | case (cache, env, Absyn.CREF_IDENT(name = "translateModelXML"), {Absyn.CREF(componentRef = cr)}, args, impl, pre) | ||
| 394 | algorithm | ||
| 395 | ✗ | className := AbsynUtil.crefToPath(cr); | |
| 396 | ✗ | cname_str := AbsynUtil.pathString(className); | |
| 397 | ✗ | (cache,filenameprefix) := Static.getOptionalNamedArg(cache,env, impl, "fileNamePrefix", | |
| 398 | DAE.T_STRING_DEFAULT, args, DAE.SCONST(cname_str),pre,info); | ||
| 399 | recordtype := | ||
| 400 | DAE.T_COMPLEX(ClassInf.RECORD(Absyn.IDENT("SimulationObject")), | ||
| 401 | {DAE.TYPES_VAR("flatClass",DAE.dummyAttrVar,DAE.T_STRING_DEFAULT,DAE.UNBOUND(),false,NONE()), | ||
| 402 | DAE.TYPES_VAR("exeFile",DAE.dummyAttrVar,DAE.T_STRING_DEFAULT,DAE.UNBOUND(),false,NONE())}, | ||
| 403 | NONE(), false); | ||
| 404 | ✗ | then | |
| 405 | (cache,Expression.makePureBuiltinCall("translateModelXML", | ||
| 406 | {DAE.CODE(Absyn.C_TYPENAME(className),DAE.T_UNKNOWN_DEFAULT),filenameprefix},DAE.T_STRING_DEFAULT),DAE.PROP(recordtype,DAE.C_VAR())); | ||
| 407 | |||
| 408 | case (cache, env, Absyn.CREF_IDENT(name = "exportDAEtoMatlab"), {Absyn.CREF(componentRef = cr)}, args, impl, pre) | ||
| 409 | algorithm | ||
| 410 | ✗ | className := AbsynUtil.crefToPath(cr); | |
| 411 | ✗ | cname_str := AbsynUtil.pathString(className); | |
| 412 | ✗ | (cache,filenameprefix) := Static.getOptionalNamedArg(cache,env, impl, "fileNamePrefix", | |
| 413 | DAE.T_STRING_DEFAULT, args, DAE.SCONST(cname_str),pre,info); | ||
| 414 | recordtype := | ||
| 415 | DAE.T_COMPLEX(ClassInf.RECORD(Absyn.IDENT("SimulationObject")), | ||
| 416 | {DAE.TYPES_VAR("flatClass",DAE.dummyAttrVar,DAE.T_STRING_DEFAULT,DAE.UNBOUND(),false,NONE()), | ||
| 417 | DAE.TYPES_VAR("exeFile",DAE.dummyAttrVar,DAE.T_STRING_DEFAULT,DAE.UNBOUND(),false,NONE())}, | ||
| 418 | NONE(), false); | ||
| 419 | ✗ | then | |
| 420 | (cache,Expression.makePureBuiltinCall("exportDAEtoMatlab", | ||
| 421 | {DAE.CODE(Absyn.C_TYPENAME(className),DAE.T_UNKNOWN_DEFAULT),filenameprefix},DAE.T_STRING_DEFAULT),DAE.PROP(recordtype,DAE.C_VAR())); | ||
| 422 | |||
| 423 | case (cache, env, Absyn.CREF_IDENT(name = "buildModel"), {Absyn.CREF()}, args, _, _) | ||
| 424 | algorithm | ||
| 425 | 58 | (cache, simulationArgs) := getSimulationArguments(cache, env, inExps, args, inImplInst, inPrefix, "buildModel", info, NONE()); | |
| 426 | 58 | then | |
| 427 | (cache,Expression.makePureBuiltinCall("buildModel",simulationArgs,DAE.T_UNKNOWN_DEFAULT), | ||
| 428 | DAE.PROP(DAE.T_ARRAY(DAE.T_STRING_DEFAULT,{DAE.DIM_INTEGER(2)}),DAE.C_VAR())); | ||
| 429 | |||
| 430 | case (cache, env, Absyn.CREF_IDENT(name = "buildModelBeast"), {Absyn.CREF()}, args, _, _) | ||
| 431 | algorithm | ||
| 432 | ✗ | (cache, simulationArgs) := getSimulationArguments(cache, env, inExps, args, inImplInst, inPrefix, "buildModelBeast", info, NONE()); | |
| 433 | ✗ | then | |
| 434 | (cache,Expression.makePureBuiltinCall("buildModelBeast",simulationArgs,DAE.T_UNKNOWN_DEFAULT), | ||
| 435 | DAE.PROP(DAE.T_ARRAY(DAE.T_STRING_DEFAULT,{DAE.DIM_INTEGER(2)}),DAE.C_VAR())); | ||
| 436 | |||
| 437 | case (cache, env, Absyn.CREF_IDENT(name = "simulate"), {Absyn.CREF()}, args, _, _) /* Fill in rest of defaults here */ | ||
| 438 | algorithm | ||
| 439 | 1164 | (cache, simulationArgs) := getSimulationArguments(cache, env, inExps, args, inImplInst, inPrefix, "simulate", info, NONE()); | |
| 440 | 1164 | recordtype := CevalScriptBackend.getSimulationResultType(); | |
| 441 | 1164 | then | |
| 442 | (cache,Expression.makePureBuiltinCall("simulate",simulationArgs,DAE.T_UNKNOWN_DEFAULT),DAE.PROP(recordtype,DAE.C_VAR())); | ||
| 443 | |||
| 444 | case (cache, env, Absyn.CREF_IDENT(name = "simulation"), {Absyn.CREF()}, args, _, _) /* Fill in rest of defaults here */ | ||
| 445 | algorithm | ||
| 446 | ✗ | (cache, simulationArgs) := getSimulationArguments(cache, env, inExps, args, inImplInst, inPrefix, "simulation", info, NONE()); | |
| 447 | ✗ | recordtype := CevalScriptBackend.getDrModelicaSimulationResultType(); | |
| 448 | ✗ | then | |
| 449 | (cache,Expression.makePureBuiltinCall("simulation",simulationArgs,DAE.T_UNKNOWN_DEFAULT),DAE.PROP(recordtype,DAE.C_VAR())); | ||
| 450 | |||
| 451 | case (cache, env, Absyn.CREF_IDENT(name = "linearize"), {Absyn.CREF()}, args, _, _) /* Fill in rest of defaults here */ | ||
| 452 | algorithm | ||
| 453 | 13 | (cache, simulationArgs) := getSimulationArguments(cache, env, inExps, args, inImplInst, inPrefix, "linearize", info, NONE()); | |
| 454 | 13 | recordtype := CevalScriptBackend.getSimulationResultType(); | |
| 455 | 13 | then | |
| 456 | (cache,Expression.makePureBuiltinCall("linearize",simulationArgs,DAE.T_UNKNOWN_DEFAULT),DAE.PROP(recordtype,DAE.C_VAR())); | ||
| 457 | |||
| 458 | case (cache, env, Absyn.CREF_IDENT(name = "optimize"), {Absyn.CREF()}, args, _, _) /* Fill in rest of defaults here */ | ||
| 459 | algorithm | ||
| 460 | 34 | (cache, simulationArgs) := getSimulationArguments(cache, env, inExps, args, inImplInst, inPrefix, "optimize", info, NONE()); | |
| 461 | 34 | recordtype := CevalScriptBackend.getSimulationResultType(); | |
| 462 | 34 | then | |
| 463 | (cache,Expression.makePureBuiltinCall("optimize",simulationArgs,DAE.T_UNKNOWN_DEFAULT),DAE.PROP(recordtype,DAE.C_VAR())); | ||
| 464 | |||
| 465 | case (cache, env, Absyn.CREF_IDENT(name = "moo"), {Absyn.CREF()}, args, _, _) /* Fill in rest of defaults here */ | ||
| 466 | algorithm | ||
| 467 | ✗ | (cache, simulationArgs) := getSimulationArguments(cache, env, inExps, args, inImplInst, inPrefix, "moo", info, NONE()); | |
| 468 | ✗ | recordtype := CevalScriptBackend.getSimulationResultType(); | |
| 469 | ✗ | then | |
| 470 | (cache,Expression.makePureBuiltinCall("moo",simulationArgs,DAE.T_UNKNOWN_DEFAULT),DAE.PROP(recordtype,DAE.C_VAR())); | ||
| 471 | |||
| 472 | case (cache, env, Absyn.CREF_IDENT(name = "jacobian"), {Absyn.CREF(componentRef = cr)}, _, impl, pre) /* Fill in rest of defaults here */ | ||
| 473 | algorithm | ||
| 474 | ✗ | (cache,cr_1) := Static.elabUntypedCref(cache,env,cr,impl,pre,info); | |
| 475 | ✗ | crefExp := Expression.crefExp(cr_1); | |
| 476 | ✗ | then | |
| 477 | (cache,Expression.makePureBuiltinCall("jacobian",{crefExp},DAE.T_STRING_DEFAULT),DAE.PROP(DAE.T_STRING_DEFAULT,DAE.C_VAR())); | ||
| 478 | |||
| 479 | case (cache, env, Absyn.CREF_IDENT(name = "timing"), {exp}, {}, impl, pre) | ||
| 480 | algorithm | ||
| 481 | ✗ | (cache,exp_1,_) := elabExp(cache,env, exp, impl, true,pre,info); | |
| 482 | ✗ | then | |
| 483 | (cache,Expression.makePureBuiltinCall("timing",{exp_1},DAE.T_REAL_DEFAULT),DAE.PROP(DAE.T_REAL_DEFAULT,DAE.C_VAR())); | ||
| 484 | |||
| 485 | // MathCore-specific. Should be in MathCoreBuiltin.mo :p | ||
| 486 | case (cache, _, Absyn.CREF_IDENT(name = "checkExamplePackages"), {}, args, _, _) | ||
| 487 | algorithm | ||
| 488 | ✗ | excludeList := Static.getOptionalNamedArgExpList("exclude", args); | |
| 489 | ✗ | excludeListSize := listLength(excludeList); | |
| 490 | ✗ | then | |
| 491 | (cache,Expression.makePureBuiltinCall("checkExamplePackages", | ||
| 492 | {DAE.ARRAY(DAE.T_ARRAY(DAE.T_UNKNOWN_DEFAULT,{DAE.DIM_INTEGER(excludeListSize)}),false,excludeList)}, | ||
| 493 | DAE.T_STRING_DEFAULT), | ||
| 494 | DAE.PROP(DAE.T_BOOL_DEFAULT,DAE.C_CONST())); | ||
| 495 | |||
| 496 | case (cache, _, Absyn.CREF_IDENT(name = "checkExamplePackages"), {Absyn.STRING(value = str)}, args, _, _) | ||
| 497 | algorithm | ||
| 498 | ✗ | excludeList := Static.getOptionalNamedArgExpList("exclude", args); | |
| 499 | ✗ | excludeListSize := listLength(excludeList); | |
| 500 | ✗ | then | |
| 501 | (cache,Expression.makePureBuiltinCall("checkExamplePackages", | ||
| 502 | {DAE.ARRAY(DAE.T_ARRAY(DAE.T_UNKNOWN_DEFAULT,{DAE.DIM_INTEGER(excludeListSize)}),false,excludeList),DAE.SCONST(str)}, | ||
| 503 | DAE.T_STRING_DEFAULT), | ||
| 504 | DAE.PROP(DAE.T_BOOL_DEFAULT,DAE.C_CONST())); | ||
| 505 | |||
| 506 | case (cache, _, Absyn.CREF_IDENT(name = "checkExamplePackages"), {Absyn.CREF(componentRef = cr)}, args, _, _) | ||
| 507 | algorithm | ||
| 508 | ✗ | className := AbsynUtil.crefToPath(cr); | |
| 509 | ✗ | excludeList := Static.getOptionalNamedArgExpList("exclude", args); | |
| 510 | ✗ | excludeListSize := listLength(excludeList); | |
| 511 | ✗ | then | |
| 512 | (cache,Expression.makePureBuiltinCall("checkExamplePackages", | ||
| 513 | {DAE.ARRAY(DAE.T_ARRAY(DAE.T_UNKNOWN_DEFAULT,{DAE.DIM_INTEGER(excludeListSize)}),false,excludeList), | ||
| 514 | DAE.CODE(Absyn.C_TYPENAME(className),DAE.T_UNKNOWN_DEFAULT)}, | ||
| 515 | DAE.T_STRING_DEFAULT), | ||
| 516 | DAE.PROP(DAE.T_BOOL_DEFAULT,DAE.C_CONST())); | ||
| 517 | |||
| 518 | case (cache, _, Absyn.CREF_IDENT(name = "checkExamplePackages"), {Absyn.CREF(componentRef = cr), Absyn.STRING(value = str)}, args, _, _) | ||
| 519 | algorithm | ||
| 520 | ✗ | className := AbsynUtil.crefToPath(cr); | |
| 521 | ✗ | excludeList := Static.getOptionalNamedArgExpList("exclude", args); | |
| 522 | ✗ | excludeListSize := listLength(excludeList); | |
| 523 | ✗ | then | |
| 524 | (cache,Expression.makePureBuiltinCall("checkExamplePackages", | ||
| 525 | {DAE.ARRAY(DAE.T_ARRAY(DAE.T_UNKNOWN_DEFAULT,{DAE.DIM_INTEGER(excludeListSize)}),false,excludeList), | ||
| 526 | DAE.CODE(Absyn.C_TYPENAME(className),DAE.T_UNKNOWN_DEFAULT),DAE.SCONST(str)}, | ||
| 527 | DAE.T_STRING_DEFAULT),DAE.PROP(DAE.T_BOOL_DEFAULT,DAE.C_CONST())); | ||
| 528 | |||
| 529 | end matchcontinue; | ||
| 530 | end elabCallInteractive_work; | ||
| 531 | |||
| 532 | public function elabExp " | ||
| 533 | function: elabExp | ||
| 534 | This is an special case tha considers elabCallInteractive. If this function fails elabExp is called." | ||
| 535 | input FCore.Cache inCache; | ||
| 536 | input FCore.Graph inEnv; | ||
| 537 | input Absyn.Exp inExp; | ||
| 538 | input Boolean inImplicit; | ||
| 539 | input Boolean performVectorization; | ||
| 540 | input DAE.Prefix inPrefix; | ||
| 541 | input SourceInfo info; | ||
| 542 | output FCore.Cache outCache; | ||
| 543 | output DAE.Exp outExp; | ||
| 544 | output DAE.Properties outProperties; | ||
| 545 | algorithm | ||
| 546 | 27948 | (outCache,outExp,outProperties) := elabExp2(inCache,inEnv,inExp,inImplicit,performVectorization,inPrefix,info,Error.getNumErrorMessages()); | |
| 547 | end elabExp; | ||
| 548 | |||
| 549 | |||
| 550 | protected function elabExp2 " | ||
| 551 | function: Auxiliary function to elabExp that considers elabCallInteractive. If this function fails elabExp is called." | ||
| 552 | input FCore.Cache inCache; | ||
| 553 | input FCore.Graph inEnv; | ||
| 554 | input Absyn.Exp inExp; | ||
| 555 | input Boolean inImplicit; | ||
| 556 | input Boolean performVectorization; | ||
| 557 | input DAE.Prefix inPrefix; | ||
| 558 | input SourceInfo info; | ||
| 559 | input Integer numErrorMessages; | ||
| 560 | output FCore.Cache outCache; | ||
| 561 | output DAE.Exp outExp; | ||
| 562 | output DAE.Properties outProperties; | ||
| 563 | algorithm | ||
| 564 | (outCache,outExp,outProperties):= | ||
| 565 | matchcontinue (inCache, inEnv, inExp, inImplicit, performVectorization, inPrefix) | ||
| 566 | local | ||
| 567 | Boolean impl,doVect; | ||
| 568 | DAE.Exp e_1; | ||
| 569 | DAE.Properties prop; | ||
| 570 | FCore.Graph env; | ||
| 571 | Absyn.ComponentRef fn; | ||
| 572 | Absyn.Exp exp; | ||
| 573 | list<Absyn.Exp> args; | ||
| 574 | list<Absyn.NamedArg> nargs; | ||
| 575 | FCore.Cache cache; | ||
| 576 | DAE.Prefix pre; | ||
| 577 | case (cache, env, Absyn.CALL(function_ = fn,functionArgs = Absyn.FUNCTIONARGS(args = args,argNames = nargs)), impl, _, pre) | ||
| 578 | algorithm | ||
| 579 | 17945 | (cache,e_1,prop) := elabCall(cache, env, fn, args, nargs, impl, pre, info, Error.getNumErrorMessages()); | |
| 580 | 17250 | (e_1,_) := ExpressionSimplify.simplify1(e_1); | |
| 581 | 17250 | then | |
| 582 | (cache,e_1,prop); | ||
| 583 | case (cache, env, exp, impl, doVect, pre) | ||
| 584 | algorithm | ||
| 585 | 10698 | (cache,e_1,prop) := Static.elabExp(cache,env,exp,impl,doVect,pre,info); | |
| 586 | then | ||
| 587 | (cache,e_1,prop); | ||
| 588 | end matchcontinue; | ||
| 589 | end elabExp2; | ||
| 590 | |||
| 591 | |||
| 592 | protected function elabCall " | ||
| 593 | function: elabCall | ||
| 594 | This is an special case that considers elabCallInteractive." | ||
| 595 | input FCore.Cache inCache; | ||
| 596 | input FCore.Graph inEnv; | ||
| 597 | input Absyn.ComponentRef inComponentRef; | ||
| 598 | input list<Absyn.Exp> inAbsynExpLst; | ||
| 599 | input list<Absyn.NamedArg> inAbsynNamedArgLst; | ||
| 600 | input Boolean inImplInst; | ||
| 601 | input DAE.Prefix inPrefix; | ||
| 602 | input SourceInfo info; | ||
| 603 | input Integer numErrorMessages; | ||
| 604 | output FCore.Cache outCache; | ||
| 605 | output DAE.Exp outExp; | ||
| 606 | output DAE.Properties outProperties; | ||
| 607 | algorithm | ||
| 608 | (outCache,outExp,outProperties):= | ||
| 609 | match (inCache, inEnv, inComponentRef, inAbsynExpLst, inAbsynNamedArgLst, inImplInst, inPrefix) | ||
| 610 | local | ||
| 611 | DAE.Exp e; | ||
| 612 | DAE.Properties prop; | ||
| 613 | FCore.Graph env; | ||
| 614 | Absyn.ComponentRef fn; | ||
| 615 | list<Absyn.Exp> args; | ||
| 616 | list<Absyn.NamedArg> nargs; | ||
| 617 | Boolean impl; | ||
| 618 | FCore.Cache cache; | ||
| 619 | DAE.Prefix pre; | ||
| 620 | case (cache, env, fn, args, nargs, impl, pre) | ||
| 621 | algorithm | ||
| 622 | 17958 | (cache,e,prop) := elabCallInteractive_work(cache, env, fn, args, nargs, impl, pre, info) "Elaborate interactive function calls, such as simulate(), plot() etc." ; | |
| 623 | then | ||
| 624 | (cache,e,prop); | ||
| 625 | end match; | ||
| 626 | end elabCall; | ||
| 627 | |||
| 628 | public function elabGraphicsExp | ||
| 629 | "This is an special case tha considers elabCallInteractive. If this function fails Static.elabGraphicsExp is called" | ||
| 630 | input FCore.Cache inCache; | ||
| 631 | input FCore.Graph inEnv; | ||
| 632 | input Absyn.Exp inExp; | ||
| 633 | input Boolean inImplInst; | ||
| 634 | input DAE.Prefix inPrefix; | ||
| 635 | input SourceInfo info; | ||
| 636 | output FCore.Cache outCache; | ||
| 637 | output DAE.Exp outExp; | ||
| 638 | output DAE.Properties outProperties; | ||
| 639 | algorithm | ||
| 640 | (outCache,outExp,outProperties):= | ||
| 641 | matchcontinue (inCache, inEnv, inExp, inImplInst, inPrefix) | ||
| 642 | local | ||
| 643 | Boolean impl; | ||
| 644 | DAE.Exp e_1; | ||
| 645 | DAE.Properties prop; | ||
| 646 | FCore.Graph env; | ||
| 647 | Absyn.ComponentRef fn; | ||
| 648 | Absyn.Exp e; | ||
| 649 | list<Absyn.Exp> args; | ||
| 650 | list<Absyn.NamedArg> nargs; | ||
| 651 | FCore.Cache cache; | ||
| 652 | DAE.Prefix pre; | ||
| 653 | // Function calls | ||
| 654 | case (cache, env, Absyn.CALL(function_ = fn,functionArgs = Absyn.FUNCTIONARGS(args = args,argNames = nargs)), _, pre) | ||
| 655 | algorithm | ||
| 656 | 13 | (cache,e_1,prop) := elabCall(cache,env, fn, args, nargs, true,pre,info,Error.getNumErrorMessages()); | |
| 657 | then | ||
| 658 | (cache,e_1,prop); | ||
| 659 | case (cache, env, e, impl, pre) | ||
| 660 | algorithm | ||
| 661 | 30 | (cache,e_1,prop) := Static.elabGraphicsExp(cache,env,e,impl,pre,info); | |
| 662 | then | ||
| 663 | (cache,e_1,prop); | ||
| 664 | end matchcontinue; | ||
| 665 | end elabGraphicsExp; | ||
| 666 | |||
| 667 | annotation(__OpenModelica_Interface="backend_main"); | ||
| 668 | end StaticScript; | ||
| 669 |