Linux GNU 11.4.0 Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 79.3% 23 / 0 / 29
Functions: -% 0 / 1 / 1
Branches: 87.5% 7 / 0 / 8

OMCompiler/Compiler/FrontEnd/Builtin.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 Builtin
37 " file: Builtin.mo
38 package: Builtin
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 import Absyn;
47 import DAE;
48 import SCode;
49 import FCore;
50 import FGraph;
51
52 protected
53
54 import Config;
55 import FBuiltin;
56 import Flags;
57 import FGraphBuildEnv;
58 import Global;
59 import Util;
60
61 public function variableIsBuiltin
62 "Returns true if cref is a builtin variable.
63 Currently only 'time' is a builtin variable."
64 input DAE.ComponentRef cref;
65 output Boolean b;
66 algorithm
67 b := match cref
68 local
69 String id;
70 183926 case DAE.CREF_IDENT(ident=id) then variableNameIsBuiltin(id);
71 else false;
72 end match;
73 end variableIsBuiltin;
74
75 public function variableNameIsBuiltin
76 "Returns true if cref is a builtin variable.
77 Currently only 'time' is a builtin variable."
78 input String name;
79 output Boolean b;
80 algorithm
81 b := match name
82 case "time" then true;
83 //If accepting Optimica then these variabels are also builtin
84 ✗ case "startTime" then Config.acceptOptimicaGrammar();
85 ✗ case "finalTime" then Config.acceptOptimicaGrammar();
86 ✗ case "objective" then Config.acceptOptimicaGrammar();
87 ✗ case "objectiveIntegrand" then Config.acceptOptimicaGrammar();
88 else false;
89 end match;
90 end variableNameIsBuiltin;
91
92 public function isDer
93 input Absyn.Path inPath;
94 algorithm
95 ():=
96 match inPath
97 local Absyn.Path path;
98 case Absyn.IDENT(name = "der") then ();
99 ✗ case Absyn.FULLYQUALIFIED(path) algorithm isDer(path); then ();
100 end match;
101 end isDer;
102
103 public function initialGraph
104 "The initial environment where instantiation takes place is built
105 up using this function. It creates an empty environment and adds
106 all the built-in definitions to it.
107 NOTE:
108 The following built in operators can not be described in
109 the type system, since they e.g. have arbitrary arguments, etc.
110 - fill
111 - cat
112 These operators are catched in the elabBuiltinHandler, along with all
113 others."
114 input FCore.Cache inCache;
115 output FCore.Cache outCache;
116 output FGraph.Graph graph;
117 protected
118 FCore.Cache cache;
119
120 algorithm
121 (outCache, graph) := matchcontinue inCache
122 local
123 SCode.Program initialProgram;
124
125 // First look for cached version
126 case cache algorithm
127 29048 graph := FCore.getCachedInitialGraph(cache);
128 // we have references in the graph so we need to clone it before giving it away
129 ✗ graph := FGraph.clone(graph);
130 then (cache,graph);
131
132 // then look in the global roots[builtinEnvIndex]
133 case cache
134 algorithm
135 29048 graph := getSetInitialGraph(NONE());
136 then
137 (cache, graph);
138
139 // if no cached version found create initial graph.
140 case cache
141 algorithm
142 2196 graph := FGraph.new("graph", FCore.dummyTopModel);
143 2196 graph := FGraphBuildEnv.mkProgramGraph(FBuiltin.getBasicTypes(), FCore.BASIC_TYPE(), graph);
144
145 2196 graph := FBuiltin.initialGraphModelica(graph, FGraphBuildEnv.mkTypeNode, FGraphBuildEnv.mkCompNode);
146
147 2196 (_, initialProgram) := FBuiltin.getInitialFunctions();
148 // add the ModelicaBuiltin/MetaModelicaBuiltin classes in the initial graph
149 2196 graph := FGraphBuildEnv.mkProgramGraph(initialProgram, FCore.BUILTIN(), graph);
150
151 2196 graph := FBuiltin.initialGraphOptimica(graph, FGraphBuildEnv.mkCompNode);
152 2196 graph := FBuiltin.initialGraphMetaModelica(graph, FGraphBuildEnv.mkTypeNode);
153
154 2196 cache := FCore.setCachedInitialGraph(cache,graph);
155 2196 getSetInitialGraph(SOME(graph));
156
157 2196 graph := FGraph.clone(graph); // we have references in the graph so we need to clone it before returning it
158 then
159 (cache,graph);
160
161 end matchcontinue;
162 end initialGraph;
163
164 protected function getSetInitialGraph
165 "gets/sets the initial environment depending on grammar flags"
166 input Option<FGraph.Graph> inEnvOpt;
167 output FGraph.Graph initialEnv;
168 algorithm
169 initialEnv := matchcontinue inEnvOpt
170 local
171 list<tuple<Integer,FGraph.Graph>> assocLst;
172 FGraph.Graph graph;
173 Integer f;
174
175 // nothing there
176 case _
177 algorithm
178
2/2
✓ Branch 0 taken 31244 times.
✓ Branch 1 taken 1926 times.
33170 failure(getGlobalRoot(Global.builtinGraphIndex));
179 1926 setGlobalRoot(Global.builtinGraphIndex, {});
180 1926 then
181 fail();
182
183 // return the correct graph depending on flags
184 case NONE()
185 algorithm
186 29048 assocLst := getGlobalRoot(Global.builtinGraphIndex);
187 // we have references in the graph so we need to clone it before giving it away
188 29048 graph := FGraph.clone(Util.assoc(Flags.getConfigEnum(Flags.GRAMMAR), assocLst));
189 then
190 graph;
191
192 case SOME(graph)
193 algorithm
194 2196 assocLst := getGlobalRoot(Global.builtinGraphIndex);
195 2196 f := Flags.getConfigEnum(Flags.GRAMMAR);
196
5/6
✓ Branch 0 taken 76 times.
✓ Branch 1 taken 2120 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2120 times.
✓ Branch 6 taken 1883 times.
✓ Branch 7 taken 237 times.
2196 assocLst := if f == Flags.METAMODELICA
197 then (Flags.METAMODELICA,graph)::assocLst
198 else if f == Flags.PARMODELICA
199 then (Flags.PARMODELICA,graph)::assocLst
200 else if f == Flags.MODELICA
201 then (Flags.MODELICA,graph)::assocLst
202 else assocLst;
203 2196 setGlobalRoot(Global.builtinGraphIndex, assocLst);
204 then
205 graph;
206
207 end matchcontinue;
208 end getSetInitialGraph;
209
210 public function clearInitialGraph
211 algorithm
212 11 setGlobalRoot(Global.builtinGraphIndex, {});
213 end clearInitialGraph;
214
215 annotation(__OpenModelica_Interface="frontend");
216 end Builtin;
217