|
| 1 | +/* |
| 2 | + * This file is part of OpenModelica. |
| 3 | + * |
| 4 | + * Copyright (c) 1998-2014, 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 GPL VERSION 3 LICENSE OR |
| 11 | + * THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2. |
| 12 | + * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES |
| 13 | + * RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3, |
| 14 | + * ACCORDING TO RECIPIENTS CHOICE. |
| 15 | + * |
| 16 | + * The OpenModelica software and the Open Source Modelica |
| 17 | + * Consortium (OSMC) Public License (OSMC-PL) are obtained |
| 18 | + * from OSMC, either from the above address, |
| 19 | + * from the URLs: http://www.ida.liu.se/projects/OpenModelica or |
| 20 | + * http://www.openmodelica.org, and in the OpenModelica distribution. |
| 21 | + * GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html. |
| 22 | + * |
| 23 | + * This program is distributed WITHOUT ANY WARRANTY; without |
| 24 | + * even the implied warranty of MERCHANTABILITY or FITNESS |
| 25 | + * FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH |
| 26 | + * IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL. |
| 27 | + * |
| 28 | + * See the full OSMC Public License conditions for more details. |
| 29 | + * |
| 30 | + */ |
| 31 | + |
| 32 | +encapsulated package NFBuiltinFuncs |
| 33 | + |
| 34 | +import NFFunction.Function; |
| 35 | +import NFFunction.Slot; |
| 36 | +import NFFunction.SlotType; |
| 37 | +import NFFunction.FuncType; |
| 38 | +import NFInstNode.InstNode; |
| 39 | +import NFInstNode.InstNodeType; |
| 40 | +import NFComponent.Component; |
| 41 | +import Type = NFType; |
| 42 | +import Expression = NFExpression; |
| 43 | +import Absyn; |
| 44 | +import Absyn.{Path, TypeSpec}; |
| 45 | +import SCode; |
| 46 | +import SCode.{Mod, Comment}; |
| 47 | +import DAE; |
| 48 | +import Builtin = NFBuiltin; |
| 49 | +import Binding = NFBinding; |
| 50 | + |
| 51 | +// Dummy SCode component, since we usually don't need the definition for anything. |
| 52 | +constant SCode.Element DUMMY_ELEMENT = SCode.COMPONENT("dummy", |
| 53 | + SCode.defaultPrefixes, SCode.defaultVarAttr, |
| 54 | + TypeSpec.TPATH(Path.IDENT("$dummy"), NONE()), SCode.Mod.NOMOD(), |
| 55 | + SCode.Comment.COMMENT(NONE(), NONE()), NONE(), Absyn.dummyInfo); |
| 56 | + |
| 57 | +// Default Integer parameter. |
| 58 | +constant Component INT_COMPONENT = Component.TYPED_COMPONENT(NFInstNode.EMPTY_NODE(), |
| 59 | + Type.INTEGER(), Binding.UNBOUND(), NFComponent.DEFAULT_ATTR); |
| 60 | + |
| 61 | +constant InstNode INT_PARAM = InstNode.COMPONENT_NODE("i", |
| 62 | + DUMMY_ELEMENT, listArray({INT_COMPONENT}), InstNode.EMPTY_NODE()); |
| 63 | + |
| 64 | +// Default Real parameter. |
| 65 | +constant Component REAL_COMPONENT = Component.TYPED_COMPONENT(NFInstNode.EMPTY_NODE(), |
| 66 | + Type.REAL(), Binding.UNBOUND(), NFComponent.DEFAULT_ATTR); |
| 67 | + |
| 68 | +constant InstNode REAL_PARAM = InstNode.COMPONENT_NODE("r", |
| 69 | + DUMMY_ELEMENT, listArray({REAL_COMPONENT}), InstNode.EMPTY_NODE()); |
| 70 | + |
| 71 | +// Default Boolean parameter. |
| 72 | +constant Component BOOL_COMPONENT = Component.TYPED_COMPONENT(NFInstNode.EMPTY_NODE(), |
| 73 | + Type.BOOLEAN(), Binding.UNBOUND(), NFComponent.DEFAULT_ATTR); |
| 74 | + |
| 75 | +constant InstNode BOOL_PARAM = InstNode.COMPONENT_NODE("b", |
| 76 | + DUMMY_ELEMENT, listArray({BOOL_COMPONENT}), InstNode.EMPTY_NODE()); |
| 77 | + |
| 78 | +// Default String parameter. |
| 79 | +constant Component STRING_COMPONENT = Component.TYPED_COMPONENT(NFInstNode.EMPTY_NODE(), |
| 80 | + Type.STRING(), Binding.UNBOUND(), NFComponent.DEFAULT_ATTR); |
| 81 | + |
| 82 | +constant InstNode STRING_PARAM = InstNode.COMPONENT_NODE("s", |
| 83 | + DUMMY_ELEMENT, listArray({STRING_COMPONENT}), InstNode.EMPTY_NODE()); |
| 84 | + |
| 85 | +// Default enumeration(:) parameter. |
| 86 | +constant Component ENUM_COMPONENT = Component.TYPED_COMPONENT(NFInstNode.EMPTY_NODE(), |
| 87 | + Type.ENUMERATION_ANY(), Binding.UNBOUND(), NFComponent.DEFAULT_ATTR); |
| 88 | + |
| 89 | +constant InstNode ENUM_PARAM = InstNode.COMPONENT_NODE("e", |
| 90 | + DUMMY_ELEMENT, listArray({ENUM_COMPONENT}), InstNode.EMPTY_NODE()); |
| 91 | + |
| 92 | +// Integer(e) |
| 93 | +constant Function INTEGER = Function.FUNCTION(Path.IDENT("Integer"), |
| 94 | + InstNode.EMPTY_NODE(), {ENUM_PARAM}, {}, {}, { |
| 95 | + Slot.SLOT("e", SlotType.POSITIONAL, NONE(), NONE()) |
| 96 | + }, Type.INTEGER(), DAE.FUNCTION_ATTRIBUTES_BUILTIN, listArray({true})); |
| 97 | + |
| 98 | +// String(r, significantDigits=d, minimumLength=0, leftJustified=true) |
| 99 | +constant InstNode STRING_NODE = NFInstNode.CLASS_NODE("String", DUMMY_ELEMENT, |
| 100 | + listArray({}), listArray({}), InstNode.EMPTY_NODE(), InstNodeType.NORMAL_CLASS()); |
| 101 | + |
| 102 | +constant Function STRING_REAL = Function.FUNCTION(Path.IDENT("String"), |
| 103 | + STRING_NODE, {REAL_PARAM, INT_PARAM, INT_PARAM, BOOL_PARAM}, {STRING_PARAM}, {}, { |
| 104 | + Slot.SLOT("r", SlotType.POSITIONAL, NONE(), NONE()), |
| 105 | + Slot.SLOT("significantDigits", SlotType.NAMED, SOME(Expression.INTEGER(6)), NONE()), |
| 106 | + Slot.SLOT("minimumLength", SlotType.NAMED, SOME(Expression.INTEGER(0)), NONE()), |
| 107 | + Slot.SLOT("leftJustified", SlotType.NAMED, SOME(Expression.BOOLEAN(true)), NONE()) |
| 108 | + }, Type.STRING(), DAE.FUNCTION_ATTRIBUTES_BUILTIN, listArray({true})); |
| 109 | + |
| 110 | +// String(r, format="-0.6g") |
| 111 | +constant Function STRING_REAL_FORMAT = Function.FUNCTION(Path.IDENT("String"), |
| 112 | + STRING_NODE, {REAL_PARAM, STRING_PARAM}, {STRING_PARAM}, {}, { |
| 113 | + Slot.SLOT("r", SlotType.POSITIONAL, NONE(), NONE()), |
| 114 | + Slot.SLOT("format", SlotType.NAMED, SOME(Expression.STRING("-0.6g")), NONE()) |
| 115 | + }, Type.STRING(), DAE.FUNCTION_ATTRIBUTES_BUILTIN, listArray({true})); |
| 116 | + |
| 117 | +// String(i, minimumLength=0, leftJustified=true) |
| 118 | +constant Function STRING_INT = Function.FUNCTION(Path.IDENT("String"), |
| 119 | + STRING_NODE, {INT_PARAM, INT_PARAM, BOOL_PARAM}, {STRING_PARAM}, {}, { |
| 120 | + Slot.SLOT("i", SlotType.POSITIONAL, NONE(), NONE()), |
| 121 | + Slot.SLOT("minimumLength", SlotType.NAMED, SOME(Expression.INTEGER(0)), NONE()), |
| 122 | + Slot.SLOT("leftJustified", SlotType.NAMED, SOME(Expression.BOOLEAN(true)), NONE()) |
| 123 | + }, Type.STRING(), DAE.FUNCTION_ATTRIBUTES_BUILTIN, listArray({true})); |
| 124 | + |
| 125 | +// String(b, minimumLength=0, leftJustified=true) |
| 126 | +constant Function STRING_BOOL = Function.FUNCTION(Path.IDENT("String"), |
| 127 | + STRING_NODE, {BOOL_PARAM, INT_PARAM, BOOL_PARAM}, {STRING_PARAM}, {}, { |
| 128 | + Slot.SLOT("b", SlotType.POSITIONAL, NONE(), NONE()), |
| 129 | + Slot.SLOT("minimumLength", SlotType.NAMED, SOME(Expression.INTEGER(0)), NONE()), |
| 130 | + Slot.SLOT("leftJustified", SlotType.NAMED, SOME(Expression.BOOLEAN(true)), NONE()) |
| 131 | + }, Type.STRING(), DAE.FUNCTION_ATTRIBUTES_BUILTIN, listArray({true})); |
| 132 | + |
| 133 | +// String(e, minimumLength=0, leftJustified=true) |
| 134 | +constant Function STRING_ENUM = Function.FUNCTION(Path.IDENT("String"), |
| 135 | + STRING_NODE, {ENUM_PARAM, INT_PARAM, BOOL_PARAM}, {STRING_PARAM}, {}, { |
| 136 | + Slot.SLOT("e", SlotType.POSITIONAL, NONE(), NONE()), |
| 137 | + Slot.SLOT("minimumLength", SlotType.NAMED, SOME(Expression.INTEGER(0)), NONE()), |
| 138 | + Slot.SLOT("leftJustified", SlotType.NAMED, SOME(Expression.BOOLEAN(true)), NONE()) |
| 139 | + }, Type.STRING(), DAE.FUNCTION_ATTRIBUTES_BUILTIN, listArray({true})); |
| 140 | + |
| 141 | +annotation(__OpenModelica_Interface="frontend"); |
| 142 | +end NFBuiltinFuncs; |
0 commit comments