OMCompiler/Compiler/NFFrontEnd/NFBuiltin.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 NFBuiltin | ||
| 37 | " file: NFBuiltin.mo | ||
| 38 | package: NFBuiltin | ||
| 39 | description: Builtin definitions. | ||
| 40 | |||
| 41 | |||
| 42 | Definitions for various builtin Modelica types and variables that can't be | ||
| 43 | defined by ModelicaBuiltin.mo. | ||
| 44 | " | ||
| 45 | |||
| 46 | public | ||
| 47 | import Absyn; | ||
| 48 | import Attributes = NFAttributes; | ||
| 49 | import SCode; | ||
| 50 | import NFBinding; | ||
| 51 | import Class = NFClass; | ||
| 52 | import NFClassTree.ClassTree; | ||
| 53 | import Component = NFComponent; | ||
| 54 | import NFComponent.ComponentState; | ||
| 55 | import Expression = NFExpression; | ||
| 56 | import NFInstNode.InstNode; | ||
| 57 | import NFInstNode; | ||
| 58 | import NFInstNode.InstNodeType; | ||
| 59 | import NFModifier.Modifier; | ||
| 60 | import Type = NFType; | ||
| 61 | import BuiltinFuncs = NFBuiltinFuncs; | ||
| 62 | import Pointer; | ||
| 63 | import NFPrefixes.Variability; | ||
| 64 | import NFPrefixes.Visibility; | ||
| 65 | import ComponentRef = NFComponentRef; | ||
| 66 | import NFComponentRef.Origin; | ||
| 67 | import Restriction = NFRestriction; | ||
| 68 | import LookupTree = NFLookupTree; | ||
| 69 | import NFDuplicateTree; | ||
| 70 | |||
| 71 | protected | ||
| 72 | import MetaModelica.Dangerous.*; | ||
| 73 | |||
| 74 | public | ||
| 75 | encapsulated package Elements | ||
| 76 | import SCode; | ||
| 77 | import Absyn; | ||
| 78 | |||
| 79 | // Default parts of the declarations for builtin elements and types: | ||
| 80 | public constant Absyn.TypeSpec ENUMTYPE_SPEC = | ||
| 81 | Absyn.TPATH(Absyn.IDENT("$EnumType"), NONE()); | ||
| 82 | |||
| 83 | // StateSelect-specific elements: | ||
| 84 | constant SCode.Element REAL = SCode.CLASS("Real", | ||
| 85 | SCode.defaultPrefixes, SCode.NOT_ENCAPSULATED(), SCode.NOT_PARTIAL(), SCode.R_TYPE(), | ||
| 86 | SCode.PARTS({}, {}, {}, {}, {}, {}, {}, NONE()), | ||
| 87 | SCode.noComment, Absyn.dummyInfo); | ||
| 88 | |||
| 89 | constant SCode.Element INTEGER = SCode.CLASS("Integer", | ||
| 90 | SCode.defaultPrefixes, SCode.NOT_ENCAPSULATED(), SCode.NOT_PARTIAL(), SCode.R_TYPE(), | ||
| 91 | SCode.PARTS({}, {}, {}, {}, {}, {}, {}, NONE()), | ||
| 92 | SCode.noComment, Absyn.dummyInfo); | ||
| 93 | |||
| 94 | constant SCode.Element BOOLEAN = SCode.CLASS("Boolean", | ||
| 95 | SCode.defaultPrefixes, SCode.NOT_ENCAPSULATED(), SCode.NOT_PARTIAL(), SCode.R_TYPE(), | ||
| 96 | SCode.PARTS({}, {}, {}, {}, {}, {}, {}, NONE()), | ||
| 97 | SCode.noComment, Absyn.dummyInfo); | ||
| 98 | |||
| 99 | constant SCode.Element STRING = SCode.CLASS("String", | ||
| 100 | SCode.defaultPrefixes, SCode.NOT_ENCAPSULATED(), SCode.NOT_PARTIAL(), SCode.R_TYPE(), | ||
| 101 | SCode.PARTS({}, {}, {}, {}, {}, {}, {}, NONE()), | ||
| 102 | SCode.noComment, Absyn.dummyInfo); | ||
| 103 | |||
| 104 | constant SCode.Element ENUMERATION = SCode.CLASS("enumeration", | ||
| 105 | SCode.defaultPrefixes, SCode.NOT_ENCAPSULATED(), SCode.NOT_PARTIAL(), SCode.R_TYPE(), | ||
| 106 | SCode.PARTS({}, {}, {}, {}, {}, {}, {}, NONE()), | ||
| 107 | SCode.noComment, Absyn.dummyInfo); | ||
| 108 | |||
| 109 | constant SCode.Element ANY = SCode.CLASS("polymorphic", | ||
| 110 | SCode.defaultPrefixes, SCode.NOT_ENCAPSULATED(), SCode.NOT_PARTIAL(), SCode.R_TYPE(), | ||
| 111 | SCode.PARTS({}, {}, {}, {}, {}, {}, {}, NONE()), | ||
| 112 | SCode.noComment, Absyn.dummyInfo); | ||
| 113 | |||
| 114 | constant SCode.Element CLOCK = SCode.CLASS("Clock", | ||
| 115 | SCode.defaultPrefixes, SCode.NOT_ENCAPSULATED(), SCode.NOT_PARTIAL(), SCode.R_PREDEFINED_CLOCK(), | ||
| 116 | SCode.PARTS({}, {}, {}, {}, {}, {}, {}, NONE()), | ||
| 117 | SCode.noComment, Absyn.dummyInfo) "the Clock type"; | ||
| 118 | |||
| 119 | end Elements; | ||
| 120 | |||
| 121 | // An empty InstNode cache for the builtin types. This should really be an empty | ||
| 122 | // array to make sure all attempts at using the cache fails, since trying to | ||
| 123 | // update the cache of a constant literal would cause a segfault. Creating a | ||
| 124 | // completely empty array here doesn't work due to compiler bugs though | ||
| 125 | // (generates invalid C code), but this is probably close enough. | ||
| 126 | constant array<NFInstNode.CachedData> EMPTY_NODE_CACHE = listArrayLiteral({ | ||
| 127 | NFInstNode.CachedData.FUNCTION({}, true, true) | ||
| 128 | }); | ||
| 129 | |||
| 130 | // InstNodes for the builtin types. These have empty class trees to prevent | ||
| 131 | // access to the attributes via dot notation (which is not needed for | ||
| 132 | // modifiers and illegal in other cases). | ||
| 133 | constant InstNode POLYMORPHIC_NODE = InstNode.CLASS_NODE("polymorphic", | ||
| 134 | Elements.ANY, Visibility.PUBLIC, | ||
| 135 | Pointer.createImmutable(Class.PARTIAL_BUILTIN(Type.POLYMORPHIC(""), ClassTree.EMPTY_TREE(), | ||
| 136 | Modifier.NOMOD(), NFClass.DEFAULT_PREFIXES, Restriction.TYPE())), | ||
| 137 | EMPTY_NODE_CACHE, NFInstNode.NO_SCOPE, InstNodeType.BUILTIN_CLASS()); | ||
| 138 | |||
| 139 | // Lookup tree for Real. Generated by makeBuiltinLookupTree. | ||
| 140 | constant LookupTree.Tree REAL_LOOKUP_TREE = LookupTree.Tree.NODE( | ||
| 141 | key = "quantity", value = LookupTree.Entry.COMPONENT(index = 1), height = 4, | ||
| 142 | left = LookupTree.Tree.NODE( | ||
| 143 | key = "max", value = LookupTree.Entry.COMPONENT(index = 5), height = 3, | ||
| 144 | left = LookupTree.Tree.NODE( | ||
| 145 | key = "displayUnit", value = LookupTree.Entry.COMPONENT(index = 3), height = 2, | ||
| 146 | left = LookupTree.Tree.EMPTY(), | ||
| 147 | right = LookupTree.Tree.LEAF( | ||
| 148 | key = "fixed", value = LookupTree.Entry.COMPONENT(index = 7))), | ||
| 149 | right = LookupTree.Tree.NODE( | ||
| 150 | key = "min", value = LookupTree.Entry.COMPONENT(index = 4), height = 2, | ||
| 151 | left = LookupTree.Tree.EMPTY(), | ||
| 152 | right = LookupTree.Tree.LEAF( | ||
| 153 | key = "nominal", value = LookupTree.Entry.COMPONENT(index = 8)))), | ||
| 154 | right = LookupTree.Tree.NODE( | ||
| 155 | key = "unbounded", value = LookupTree.Entry.COMPONENT(index = 9), height = 3, | ||
| 156 | left = LookupTree.Tree.NODE( | ||
| 157 | key = "start", value = LookupTree.Entry.COMPONENT(index = 6), height = 2, | ||
| 158 | left = LookupTree.Tree.EMPTY(), | ||
| 159 | right = LookupTree.Tree.LEAF( | ||
| 160 | key = "stateSelect", value = LookupTree.Entry.COMPONENT(index = 10))), | ||
| 161 | right = LookupTree.Tree.NODE( | ||
| 162 | key = "unit", value = LookupTree.Entry.COMPONENT(index = 2), height = 2, | ||
| 163 | left = LookupTree.Tree.LEAF( | ||
| 164 | key = "uncertain", value = LookupTree.Entry.COMPONENT(index = 11)), | ||
| 165 | right = LookupTree.Tree.EMPTY()))); | ||
| 166 | |||
| 167 | constant ClassTree REAL_CLASS_TREE = ClassTree.FLAT_TREE( | ||
| 168 | REAL_LOOKUP_TREE, | ||
| 169 | listArray({}), | ||
| 170 | listArrayLiteral({ | ||
| 171 | InstNode.COMPONENT_NODE("quantity", NONE(), Visibility.PUBLIC, | ||
| 172 | Pointer.createImmutable(Component.TYPE_ATTRIBUTE(Type.STRING(), | ||
| 173 | Modifier.NOMOD())), NFInstNode.NO_SCOPE, InstNodeType.NORMAL_COMP()), | ||
| 174 | InstNode.COMPONENT_NODE("unit", NONE(), Visibility.PUBLIC, | ||
| 175 | Pointer.createImmutable(Component.TYPE_ATTRIBUTE(Type.STRING(), | ||
| 176 | Modifier.NOMOD())), NFInstNode.NO_SCOPE, InstNodeType.NORMAL_COMP()), | ||
| 177 | InstNode.COMPONENT_NODE("displayUnit", NONE(), Visibility.PUBLIC, | ||
| 178 | Pointer.createImmutable(Component.TYPE_ATTRIBUTE(Type.STRING(), | ||
| 179 | Modifier.NOMOD())), NFInstNode.NO_SCOPE, InstNodeType.NORMAL_COMP()), | ||
| 180 | InstNode.COMPONENT_NODE("min", NONE(), Visibility.PUBLIC, | ||
| 181 | Pointer.createImmutable(Component.TYPE_ATTRIBUTE(Type.REAL(), | ||
| 182 | Modifier.NOMOD())), NFInstNode.NO_SCOPE, InstNodeType.NORMAL_COMP()), | ||
| 183 | InstNode.COMPONENT_NODE("max", NONE(), Visibility.PUBLIC, | ||
| 184 | Pointer.createImmutable(Component.TYPE_ATTRIBUTE(Type.REAL(), | ||
| 185 | Modifier.NOMOD())), NFInstNode.NO_SCOPE, InstNodeType.NORMAL_COMP()), | ||
| 186 | InstNode.COMPONENT_NODE("start", NONE(), Visibility.PUBLIC, | ||
| 187 | Pointer.createImmutable(Component.TYPE_ATTRIBUTE(Type.REAL(), | ||
| 188 | Modifier.NOMOD())), NFInstNode.NO_SCOPE, InstNodeType.NORMAL_COMP()), | ||
| 189 | InstNode.COMPONENT_NODE("fixed", NONE(), Visibility.PUBLIC, | ||
| 190 | Pointer.createImmutable(Component.TYPE_ATTRIBUTE(Type.BOOLEAN(), | ||
| 191 | Modifier.NOMOD())), NFInstNode.NO_SCOPE, InstNodeType.NORMAL_COMP()), | ||
| 192 | InstNode.COMPONENT_NODE("nominal", NONE(), Visibility.PUBLIC, | ||
| 193 | Pointer.createImmutable(Component.TYPE_ATTRIBUTE(Type.REAL(), | ||
| 194 | Modifier.NOMOD())), NFInstNode.NO_SCOPE, InstNodeType.NORMAL_COMP()), | ||
| 195 | InstNode.COMPONENT_NODE("unbounded", NONE(), Visibility.PUBLIC, | ||
| 196 | Pointer.createImmutable(Component.TYPE_ATTRIBUTE(Type.BOOLEAN(), | ||
| 197 | Modifier.NOMOD())), NFInstNode.NO_SCOPE, InstNodeType.NORMAL_COMP()), | ||
| 198 | InstNode.COMPONENT_NODE("stateSelect", NONE(), Visibility.PUBLIC, | ||
| 199 | Pointer.createImmutable(Component.TYPE_ATTRIBUTE(STATESELECT_TYPE, | ||
| 200 | Modifier.NOMOD())), NFInstNode.NO_SCOPE, InstNodeType.NORMAL_COMP()), | ||
| 201 | InstNode.COMPONENT_NODE("uncertain", NONE(), Visibility.PUBLIC, | ||
| 202 | Pointer.createImmutable(Component.TYPE_ATTRIBUTE(UNCERTAINTY_TYPE, | ||
| 203 | Modifier.NOMOD())), NFInstNode.NO_SCOPE, InstNodeType.NORMAL_COMP()) | ||
| 204 | }), | ||
| 205 | listArray({}), // TODO: #4895: This should be listArrayLiteral too, but causes compilation issues. | ||
| 206 | NFDuplicateTree.EMPTY()); | ||
| 207 | |||
| 208 | constant InstNode REAL_NODE = InstNode.CLASS_NODE("Real", | ||
| 209 | Elements.REAL, Visibility.PUBLIC, | ||
| 210 | Pointer.createImmutable( | ||
| 211 | Class.PARTIAL_BUILTIN(Type.REAL(), REAL_CLASS_TREE, Modifier.NOMOD(), | ||
| 212 | NFClass.DEFAULT_PREFIXES, Restriction.TYPE())), | ||
| 213 | EMPTY_NODE_CACHE, NFInstNode.NO_SCOPE, InstNodeType.BUILTIN_CLASS()); | ||
| 214 | |||
| 215 | // Lookup tree for Integer. Generated by makeBuiltinLookupTree. | ||
| 216 | constant LookupTree.Tree INTEGER_LOOKUP_TREE = LookupTree.Tree.NODE( | ||
| 217 | key = "min", value = LookupTree.Entry.COMPONENT(index = 2), height = 3, | ||
| 218 | left = LookupTree.Tree.NODE( | ||
| 219 | key = "max", value = LookupTree.Entry.COMPONENT(index = 3), height = 2, | ||
| 220 | left = LookupTree.Tree.LEAF( | ||
| 221 | key = "fixed", value = LookupTree.Entry.COMPONENT(index = 5)), | ||
| 222 | right = LookupTree.Tree.EMPTY()), | ||
| 223 | right = LookupTree.Tree.NODE( | ||
| 224 | key = "quantity", value = LookupTree.Entry.COMPONENT(index = 1), height = 2, | ||
| 225 | left = LookupTree.Tree.EMPTY(), | ||
| 226 | right = LookupTree.Tree.LEAF( | ||
| 227 | key = "start", value = LookupTree.Entry.COMPONENT(index = 4)))); | ||
| 228 | |||
| 229 | constant ClassTree INTEGER_CLASS_TREE = ClassTree.FLAT_TREE( | ||
| 230 | INTEGER_LOOKUP_TREE, | ||
| 231 | listArray({}), | ||
| 232 | listArrayLiteral({ | ||
| 233 | InstNode.COMPONENT_NODE("quantity", NONE(), Visibility.PUBLIC, | ||
| 234 | Pointer.createImmutable(Component.TYPE_ATTRIBUTE(Type.STRING(), | ||
| 235 | Modifier.NOMOD())), NFInstNode.NO_SCOPE, InstNodeType.NORMAL_COMP()), | ||
| 236 | InstNode.COMPONENT_NODE("min", NONE(), Visibility.PUBLIC, | ||
| 237 | Pointer.createImmutable(Component.TYPE_ATTRIBUTE(Type.INTEGER(), | ||
| 238 | Modifier.NOMOD())), NFInstNode.NO_SCOPE, InstNodeType.NORMAL_COMP()), | ||
| 239 | InstNode.COMPONENT_NODE("max", NONE(), Visibility.PUBLIC, | ||
| 240 | Pointer.createImmutable(Component.TYPE_ATTRIBUTE(Type.INTEGER(), | ||
| 241 | Modifier.NOMOD())), NFInstNode.NO_SCOPE, InstNodeType.NORMAL_COMP()), | ||
| 242 | InstNode.COMPONENT_NODE("start", NONE(), Visibility.PUBLIC, | ||
| 243 | Pointer.createImmutable(Component.TYPE_ATTRIBUTE(Type.INTEGER(), | ||
| 244 | Modifier.NOMOD())), NFInstNode.NO_SCOPE, InstNodeType.NORMAL_COMP()), | ||
| 245 | InstNode.COMPONENT_NODE("fixed", NONE(), Visibility.PUBLIC, | ||
| 246 | Pointer.createImmutable(Component.TYPE_ATTRIBUTE(Type.BOOLEAN(), | ||
| 247 | Modifier.NOMOD())), NFInstNode.NO_SCOPE, InstNodeType.NORMAL_COMP()) | ||
| 248 | }), | ||
| 249 | listArray({}), // TODO: #4895: This should be listArrayLiteral too, but causes compilation issues. | ||
| 250 | NFDuplicateTree.EMPTY()); | ||
| 251 | |||
| 252 | constant InstNode INTEGER_NODE = InstNode.CLASS_NODE("Integer", | ||
| 253 | Elements.INTEGER, Visibility.PUBLIC, | ||
| 254 | Pointer.createImmutable( | ||
| 255 | Class.PARTIAL_BUILTIN(Type.INTEGER(), INTEGER_CLASS_TREE, Modifier.NOMOD(), | ||
| 256 | NFClass.DEFAULT_PREFIXES, Restriction.TYPE())), | ||
| 257 | EMPTY_NODE_CACHE, NFInstNode.NO_SCOPE, InstNodeType.BUILTIN_CLASS()); | ||
| 258 | |||
| 259 | // Lookup tree for Boolean. Generated by makeBuiltinLookupTree. | ||
| 260 | constant LookupTree.Tree BOOLEAN_LOOKUP_TREE = LookupTree.Tree.NODE( | ||
| 261 | key = "quantity", value = LookupTree.Entry.COMPONENT(index = 1), height = 2, | ||
| 262 | left = LookupTree.Tree.LEAF( | ||
| 263 | key = "fixed", value = LookupTree.Entry.COMPONENT(index = 3)), | ||
| 264 | right = LookupTree.Tree.LEAF( | ||
| 265 | key = "start", value = LookupTree.Entry.COMPONENT(index = 2))); | ||
| 266 | |||
| 267 | constant ClassTree BOOLEAN_CLASS_TREE = ClassTree.FLAT_TREE( | ||
| 268 | BOOLEAN_LOOKUP_TREE, | ||
| 269 | listArray({}), | ||
| 270 | listArrayLiteral({ | ||
| 271 | InstNode.COMPONENT_NODE("quantity", NONE(), Visibility.PUBLIC, | ||
| 272 | Pointer.createImmutable(Component.TYPE_ATTRIBUTE(Type.STRING(), | ||
| 273 | Modifier.NOMOD())), NFInstNode.NO_SCOPE, InstNodeType.NORMAL_COMP()), | ||
| 274 | InstNode.COMPONENT_NODE("start", NONE(), Visibility.PUBLIC, | ||
| 275 | Pointer.createImmutable(Component.TYPE_ATTRIBUTE(Type.BOOLEAN(), | ||
| 276 | Modifier.NOMOD())), NFInstNode.NO_SCOPE, InstNodeType.NORMAL_COMP()), | ||
| 277 | InstNode.COMPONENT_NODE("fixed", NONE(), Visibility.PUBLIC, | ||
| 278 | Pointer.createImmutable(Component.TYPE_ATTRIBUTE(Type.BOOLEAN(), | ||
| 279 | Modifier.NOMOD())), NFInstNode.NO_SCOPE, InstNodeType.NORMAL_COMP()) | ||
| 280 | }), | ||
| 281 | listArray({}), // TODO: #4895: This should be listArrayLiteral too, but causes compilation issues. | ||
| 282 | NFDuplicateTree.EMPTY()); | ||
| 283 | |||
| 284 | constant InstNode BOOLEAN_NODE = InstNode.CLASS_NODE("Boolean", | ||
| 285 | Elements.BOOLEAN, Visibility.PUBLIC, | ||
| 286 | Pointer.createImmutable( | ||
| 287 | Class.PARTIAL_BUILTIN(Type.BOOLEAN(), BOOLEAN_CLASS_TREE, Modifier.NOMOD(), | ||
| 288 | NFClass.DEFAULT_PREFIXES, Restriction.TYPE())), | ||
| 289 | EMPTY_NODE_CACHE, NFInstNode.NO_SCOPE, InstNodeType.BUILTIN_CLASS()); | ||
| 290 | |||
| 291 | constant ComponentRef BOOLEAN_CREF = | ||
| 292 | ComponentRef.CREF(BOOLEAN_NODE, {}, Type.INTEGER(), Origin.CREF, ComponentRef.EMPTY()); | ||
| 293 | |||
| 294 | // Lookup tree for String. Generated by makeBuiltinLookupTree. | ||
| 295 | constant LookupTree.Tree STRING_LOOKUP_TREE = LookupTree.Tree.NODE( | ||
| 296 | key = "quantity", value = LookupTree.Entry.COMPONENT(index = 1), height = 2, | ||
| 297 | left = LookupTree.Tree.LEAF( | ||
| 298 | key = "fixed", value = LookupTree.Entry.COMPONENT(index = 3)), | ||
| 299 | right = LookupTree.Tree.LEAF( | ||
| 300 | key = "start", value = LookupTree.Entry.COMPONENT(index = 2))); | ||
| 301 | |||
| 302 | constant ClassTree STRING_CLASS_TREE = ClassTree.FLAT_TREE( | ||
| 303 | STRING_LOOKUP_TREE, | ||
| 304 | listArray({}), | ||
| 305 | listArrayLiteral({ | ||
| 306 | InstNode.COMPONENT_NODE("quantity", NONE(), Visibility.PUBLIC, | ||
| 307 | Pointer.createImmutable(Component.TYPE_ATTRIBUTE(Type.STRING(), | ||
| 308 | Modifier.NOMOD())), NFInstNode.NO_SCOPE, InstNodeType.NORMAL_COMP()), | ||
| 309 | InstNode.COMPONENT_NODE("start", NONE(), Visibility.PUBLIC, | ||
| 310 | Pointer.createImmutable(Component.TYPE_ATTRIBUTE(Type.STRING(), | ||
| 311 | Modifier.NOMOD())), NFInstNode.NO_SCOPE, InstNodeType.NORMAL_COMP()), | ||
| 312 | InstNode.COMPONENT_NODE("fixed", NONE(), Visibility.PUBLIC, | ||
| 313 | Pointer.createImmutable(Component.TYPE_ATTRIBUTE(Type.BOOLEAN(), | ||
| 314 | Modifier.NOMOD())), NFInstNode.NO_SCOPE, InstNodeType.NORMAL_COMP()) | ||
| 315 | }), | ||
| 316 | listArray({}), // TODO: #4895: This should be listArrayLiteral too, but causes compilation issues. | ||
| 317 | NFDuplicateTree.EMPTY()); | ||
| 318 | |||
| 319 | constant InstNode STRING_NODE = InstNode.CLASS_NODE("String", | ||
| 320 | Elements.STRING, Visibility.PUBLIC, | ||
| 321 | Pointer.createImmutable( | ||
| 322 | Class.PARTIAL_BUILTIN(Type.STRING(), STRING_CLASS_TREE, Modifier.NOMOD(), | ||
| 323 | NFClass.DEFAULT_PREFIXES, Restriction.TYPE())), | ||
| 324 | EMPTY_NODE_CACHE, NFInstNode.NO_SCOPE, InstNodeType.BUILTIN_CLASS()); | ||
| 325 | |||
| 326 | // Lookup tree for enumerations. Generated by makeBuiltinLookupTree. | ||
| 327 | // NOTE: The enumeration attributes themselves are created by ClassTree.fromEnumeration, | ||
| 328 | // so any changes to this lookup tree requires fromEnumeration to be updated too. | ||
| 329 | constant LookupTree.Tree ENUM_LOOKUP_TREE = LookupTree.Tree.NODE( | ||
| 330 | key = "min", value = LookupTree.Entry.COMPONENT(index = 2), height = 3, | ||
| 331 | left = LookupTree.Tree.NODE( | ||
| 332 | key = "max", value = LookupTree.Entry.COMPONENT(index = 3), height = 2, | ||
| 333 | left = LookupTree.Tree.LEAF( | ||
| 334 | key = "fixed", value = LookupTree.Entry.COMPONENT(index = 5)), | ||
| 335 | right = LookupTree.Tree.EMPTY()), | ||
| 336 | right = LookupTree.Tree.NODE( | ||
| 337 | key = "quantity", value = LookupTree.Entry.COMPONENT(index = 1), height = 2, | ||
| 338 | left = LookupTree.Tree.EMPTY(), | ||
| 339 | right = LookupTree.Tree.LEAF( | ||
| 340 | key = "start", value = LookupTree.Entry.COMPONENT(index = 4)))); | ||
| 341 | |||
| 342 | constant InstNode ENUM_NODE = InstNode.CLASS_NODE("enumeration", | ||
| 343 | Elements.ENUMERATION, Visibility.PUBLIC, | ||
| 344 | Pointer.createImmutable(Class.PARTIAL_BUILTIN(Type.ENUMERATION(Absyn.Path.IDENT(":"), {}), NFClassTree.EMPTY_TREE(), | ||
| 345 | Modifier.NOMOD(), NFClass.DEFAULT_PREFIXES, Restriction.ENUMERATION())), | ||
| 346 | EMPTY_NODE_CACHE, NFInstNode.NO_SCOPE, InstNodeType.BUILTIN_CLASS()); | ||
| 347 | |||
| 348 | constant Type STATESELECT_TYPE = Type.ENUMERATION( | ||
| 349 | Absyn.IDENT("StateSelect"), {"never", "avoid", "default", "prefer", "always"}); | ||
| 350 | |||
| 351 | constant Type ASSERTIONLEVEL_TYPE = Type.ENUMERATION( | ||
| 352 | Absyn.IDENT("AssertionLevel"), {"warning", "error"}); | ||
| 353 | |||
| 354 | constant Expression ASSERTIONLEVEL_WARNING = Expression.ENUM_LITERAL( | ||
| 355 | ASSERTIONLEVEL_TYPE, "error", 1); | ||
| 356 | |||
| 357 | constant Expression ASSERTIONLEVEL_ERROR = Expression.ENUM_LITERAL( | ||
| 358 | ASSERTIONLEVEL_TYPE, "error", 2); | ||
| 359 | |||
| 360 | constant Type UNCERTAINTY_TYPE = Type.ENUMERATION( | ||
| 361 | Absyn.IDENT("Uncertainty"), {"given", "sought", "refine", "propagate"}); | ||
| 362 | |||
| 363 | // Lookup tree for Clock. Generated by makeBuiltinLookupTree. | ||
| 364 | constant LookupTree.Tree CLOCK_LOOKUP_TREE = LookupTree.Tree.NODE( | ||
| 365 | key = "quantity", value = LookupTree.Entry.COMPONENT(index = 1), height = 2, | ||
| 366 | left = LookupTree.Tree.LEAF( | ||
| 367 | key = "fixed", value = LookupTree.Entry.COMPONENT(index = 3)), | ||
| 368 | right = LookupTree.Tree.LEAF( | ||
| 369 | key = "start", value = LookupTree.Entry.COMPONENT(index = 2))); | ||
| 370 | |||
| 371 | constant ClassTree CLOCK_CLASS_TREE = ClassTree.FLAT_TREE( | ||
| 372 | CLOCK_LOOKUP_TREE, | ||
| 373 | listArray({}), | ||
| 374 | listArrayLiteral({ | ||
| 375 | InstNode.COMPONENT_NODE("quantity", NONE(), Visibility.PUBLIC, | ||
| 376 | Pointer.createImmutable(Component.TYPE_ATTRIBUTE(Type.STRING(), | ||
| 377 | Modifier.NOMOD())), NFInstNode.NO_SCOPE, InstNodeType.NORMAL_COMP()), | ||
| 378 | InstNode.COMPONENT_NODE("start", NONE(), Visibility.PUBLIC, | ||
| 379 | Pointer.createImmutable(Component.TYPE_ATTRIBUTE(Type.CLOCK(), | ||
| 380 | Modifier.NOMOD())), NFInstNode.NO_SCOPE, InstNodeType.NORMAL_COMP()), | ||
| 381 | InstNode.COMPONENT_NODE("fixed", NONE(), Visibility.PUBLIC, | ||
| 382 | Pointer.createImmutable(Component.TYPE_ATTRIBUTE(Type.CLOCK(), | ||
| 383 | Modifier.NOMOD())), NFInstNode.NO_SCOPE, InstNodeType.NORMAL_COMP()) | ||
| 384 | }), | ||
| 385 | listArray({}), // TODO: #4895: This should be listArrayLiteral too, but causes compilation issues. | ||
| 386 | NFDuplicateTree.EMPTY()); | ||
| 387 | |||
| 388 | constant InstNode CLOCK_NODE = InstNode.CLASS_NODE("Clock", | ||
| 389 | Elements.CLOCK, Visibility.PUBLIC, | ||
| 390 | Pointer.createImmutable( | ||
| 391 | Class.PARTIAL_BUILTIN(Type.CLOCK(), CLOCK_CLASS_TREE, Modifier.NOMOD(), | ||
| 392 | NFClass.DEFAULT_PREFIXES, Restriction.CLOCK())), | ||
| 393 | listArrayLiteral({ | ||
| 394 | NFInstNode.CachedData.FUNCTION({ | ||
| 395 | NFBuiltinFuncs.CLOCK_INFERRED, | ||
| 396 | NFBuiltinFuncs.CLOCK_INT, | ||
| 397 | NFBuiltinFuncs.CLOCK_REAL, | ||
| 398 | NFBuiltinFuncs.CLOCK_BOOL, | ||
| 399 | NFBuiltinFuncs.CLOCK_SOLVER | ||
| 400 | }, | ||
| 401 | true, true), | ||
| 402 | NFInstNode.CachedData.NO_CACHE(), | ||
| 403 | NFInstNode.CachedData.NO_CACHE()} | ||
| 404 | ), | ||
| 405 | NFInstNode.NO_SCOPE, InstNodeType.BUILTIN_CLASS()); | ||
| 406 | |||
| 407 | constant ComponentRef CLOCK_CREF = | ||
| 408 | ComponentRef.CREF(CLOCK_NODE, {}, Type.CLOCK(), Origin.CREF, ComponentRef.EMPTY()); | ||
| 409 | |||
| 410 | constant InstNode TIME = | ||
| 411 | InstNode.COMPONENT_NODE("time", | ||
| 412 | NONE(), | ||
| 413 | Visibility.PUBLIC, | ||
| 414 | Pointer.createImmutable(Component.COMPONENT( | ||
| 415 | REAL_NODE, | ||
| 416 | Type.REAL(), | ||
| 417 | NFBinding.EMPTY_BINDING, | ||
| 418 | NFBinding.EMPTY_BINDING, | ||
| 419 | NFAttributes.INPUT_ATTR, | ||
| 420 | SCode.noComment, | ||
| 421 | ComponentState.TypeChecked, | ||
| 422 | Absyn.dummyInfo)), | ||
| 423 | NFInstNode.NO_SCOPE, | ||
| 424 | InstNodeType.NORMAL_COMP()); | ||
| 425 | |||
| 426 | constant InstNode SUBST_NODE = | ||
| 427 | InstNode.COMPONENT_NODE("$SUBST_CREF", | ||
| 428 | NONE(), | ||
| 429 | Visibility.PUBLIC, | ||
| 430 | Pointer.createImmutable(Component.COMPONENT( | ||
| 431 | REAL_NODE, // TODO: make this generic integer / real | ||
| 432 | Type.ANY(), | ||
| 433 | NFBinding.EMPTY_BINDING, | ||
| 434 | NFBinding.EMPTY_BINDING, | ||
| 435 | NFAttributes.DEFAULT_ATTR, | ||
| 436 | SCode.noComment, | ||
| 437 | ComponentState.TypeChecked, | ||
| 438 | Absyn.dummyInfo)), | ||
| 439 | NFInstNode.NO_SCOPE, | ||
| 440 | InstNodeType.NORMAL_COMP()); | ||
| 441 | |||
| 442 | constant ComponentRef TIME_CREF = ComponentRef.CREF(TIME, {}, Type.REAL(), Origin.CREF, ComponentRef.EMPTY()); | ||
| 443 | constant ComponentRef SUBST_CREF = ComponentRef.CREF(SUBST_NODE, {}, Type.ANY(), Origin.CREF, ComponentRef.EMPTY()); | ||
| 444 | |||
| 445 | |||
| 446 | function makeBuiltinLookupTree | ||
| 447 | "This function takes lists of component and class names and prints out a lookup tree. | ||
| 448 | Useful in case any attributes needs to be added to any of the builtin type." | ||
| 449 | input String name "Not used in the tree, only to identify the printout."; | ||
| 450 | input list<String> components; | ||
| 451 | input list<String> classes = {}; | ||
| 452 | protected | ||
| 453 | LookupTree.Tree ltree = LookupTree.new(); | ||
| 454 | Integer i; | ||
| 455 | algorithm | ||
| 456 | i := 1; | ||
| 457 | ✗ | for comp in components loop | |
| 458 | ✗ | ltree := LookupTree.add(ltree, comp, LookupTree.Entry.COMPONENT(i)); | |
| 459 | ✗ | i := i + 1; | |
| 460 | end for; | ||
| 461 | |||
| 462 | ✗ | for cls in classes loop | |
| 463 | ✗ | ltree := LookupTree.add(ltree, cls, LookupTree.Entry.COMPONENT(i)); | |
| 464 | ✗ | i := i + 1; | |
| 465 | end for; | ||
| 466 | |||
| 467 | ✗ | print("Lookup tree for " + name + ":\n"); | |
| 468 | ✗ | print(anyString(ltree)); | |
| 469 | ✗ | print("\n"); | |
| 470 | end makeBuiltinLookupTree; | ||
| 471 | |||
| 472 | annotation(__OpenModelica_Interface="nf_frontend"); | ||
| 473 | end NFBuiltin; | ||
| 474 |