Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit a6e4095

Browse files
perostOpenModelica-Hudson
authored andcommitted
New instantiation update.
- Initial support for dimensions and equations/algorithms. - Improved lookup. - Prefixing WIP. - Probably a lot more.
1 parent ea2bf10 commit a6e4095

18 files changed

Lines changed: 3647 additions & 3494 deletions

Compiler/NFFrontEnd/NFBinding.mo

Lines changed: 62 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,9 @@ uniontype Binding
5858
end RAW_BINDING;
5959

6060
record UNTYPED_BINDING
61-
DAE.Exp bindingExp;
61+
Absyn.Exp bindingExp;
6262
Boolean isProcessing;
63+
Integer scope;
6364
Integer propagatedDims;
6465
SourceInfo info;
6566
end UNTYPED_BINDING;
@@ -73,54 +74,93 @@ uniontype Binding
7374

7475
public
7576
function fromAbsyn
76-
input Option<Absyn.Exp> inBinding;
77-
input SCode.Final inFinal;
78-
input SCode.Each inEach;
77+
input Option<Absyn.Exp> bindingExp;
78+
input SCode.Final finalPrefix;
79+
input SCode.Each eachPrefix;
7980
input Integer scope;
80-
input SourceInfo inInfo;
81-
output Binding outBinding;
81+
input Integer dimensions;
82+
input SourceInfo info;
83+
output Binding binding;
8284
algorithm
83-
outBinding := match inBinding
85+
binding := match bindingExp
8486
local
8587
Absyn.Exp exp;
88+
Integer pd;
8689

8790
case SOME(exp)
88-
then RAW_BINDING(exp, inFinal, inEach, 0, scope, inInfo);
91+
algorithm
92+
pd := if SCode.eachBool(eachPrefix) then -1 else dimensions;
93+
then
94+
RAW_BINDING(exp, finalPrefix, eachPrefix, scope, pd, info);
8995

9096
else UNBOUND();
9197
end match;
9298
end fromAbsyn;
9399

94100
function isBound
95-
input Binding inBinding;
96-
output Boolean outIsBound;
101+
input Binding binding;
102+
output Boolean isBound;
97103
algorithm
98-
outIsBound := match inBinding
104+
isBound := match binding
99105
case UNBOUND() then false;
100106
else true;
101107
end match;
102108
end isBound;
103109

104110
function untypedExp
105-
input Binding inBinding;
106-
output Option<DAE.Exp> outExp;
111+
input Binding binding;
112+
output Option<Absyn.Exp> exp;
107113
algorithm
108-
outExp := match inBinding
109-
case UNTYPED_BINDING() then SOME(inBinding.bindingExp);
114+
exp := match binding
115+
case UNTYPED_BINDING() then SOME(binding.bindingExp);
110116
else NONE();
111117
end match;
112118
end untypedExp;
113119

120+
function typedExp
121+
input Binding binding;
122+
output Option<DAE.Exp> exp;
123+
algorithm
124+
exp := match binding
125+
case TYPED_BINDING() then SOME(binding.bindingExp);
126+
else NONE();
127+
end match;
128+
end typedExp;
129+
130+
function getInfo
131+
input Binding binding;
132+
output SourceInfo info;
133+
algorithm
134+
info := match binding
135+
case UNBOUND() then Absyn.dummyInfo;
136+
case RAW_BINDING() then binding.info;
137+
case UNTYPED_BINDING() then binding.info;
138+
case TYPED_BINDING() then binding.info;
139+
end match;
140+
end getInfo;
141+
142+
function isEach
143+
input Binding binding;
144+
output Boolean isEach;
145+
algorithm
146+
isEach := match binding
147+
case RAW_BINDING() then binding.propagatedDims == -1;
148+
case UNTYPED_BINDING() then binding.propagatedDims == -1;
149+
case TYPED_BINDING() then binding.propagatedDims == -1;
150+
else false;
151+
end match;
152+
end isEach;
153+
114154
function toString
115-
input Binding inBinding;
116-
input String inPrefix = "";
117-
output String outString;
155+
input Binding binding;
156+
input String prefix = "";
157+
output String string;
118158
algorithm
119-
outString := match inBinding
159+
string := match binding
120160
case UNBOUND() then "";
121-
case RAW_BINDING() then inPrefix + Dump.printExpStr(inBinding.bindingExp);
122-
case UNTYPED_BINDING() then inPrefix + ExpressionDump.printExpStr(inBinding.bindingExp);
123-
case TYPED_BINDING() then inPrefix + ExpressionDump.printExpStr(inBinding.bindingExp);
161+
case RAW_BINDING() then prefix + Dump.printExpStr(binding.bindingExp);
162+
case UNTYPED_BINDING() then prefix + Dump.printExpStr(binding.bindingExp);
163+
case TYPED_BINDING() then prefix + ExpressionDump.printExpStr(binding.bindingExp);
124164
end match;
125165
end toString;
126166

Compiler/NFFrontEnd/NFComponent.mo

Lines changed: 100 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@
3131

3232
encapsulated package NFComponent
3333

34-
import SCode.Element;
3534
import DAE.Type;
36-
import NFInstNode.InstNode;
3735
import NFBinding.Binding;
36+
import NFDimension.Dimension;
37+
import NFInstNode.InstNode;
3838
import NFMod.Modifier;
39+
import SCode.Element;
3940

4041
uniontype Component
4142
uniontype Attributes
@@ -53,24 +54,65 @@ uniontype Component
5354
Integer scope;
5455
end COMPONENT_DEF;
5556

56-
record COMPONENT
57+
record UNTYPED_COMPONENT
58+
String name;
59+
InstNode classInst;
60+
array<Dimension> dimensions;
61+
Binding binding;
62+
Component.Attributes attributes;
63+
SourceInfo info;
64+
end UNTYPED_COMPONENT;
65+
66+
record TYPED_COMPONENT
5767
String name;
5868
InstNode classInst;
5969
Type ty;
6070
Binding binding;
6171
Component.Attributes attributes;
62-
end COMPONENT;
72+
end TYPED_COMPONENT;
73+
74+
record EXTENDS_NODE
75+
InstNode node;
76+
end EXTENDS_NODE;
77+
78+
record COMPONENT_REF
79+
String name;
80+
Integer node;
81+
Integer index;
82+
end COMPONENT_REF;
6383

6484
function name
6585
input Component component;
6686
output String name;
6787
algorithm
6888
name := match component
6989
case COMPONENT_DEF(definition = SCode.COMPONENT(name = name)) then name;
70-
case COMPONENT() then component.name;
90+
case UNTYPED_COMPONENT() then component.name;
91+
case TYPED_COMPONENT() then component.name;
92+
case COMPONENT_REF() then component.name;
7193
end match;
7294
end name;
7395

96+
function isNamedComponent
97+
input Component component;
98+
output Boolean isNamed;
99+
algorithm
100+
isNamed := match component
101+
case EXTENDS_NODE() then false;
102+
else true;
103+
end match;
104+
end isNamedComponent;
105+
106+
function classInstance
107+
input Component component;
108+
output InstNode classInst;
109+
algorithm
110+
classInst := match component
111+
case UNTYPED_COMPONENT() then component.classInst;
112+
case TYPED_COMPONENT() then component.classInst;
113+
end match;
114+
end classInstance;
115+
74116
function setModifier
75117
input Modifier modifier;
76118
input output Component component;
@@ -83,6 +125,59 @@ uniontype Component
83125
();
84126
end match;
85127
end setModifier;
128+
129+
function getType
130+
input Component component;
131+
output DAE.Type ty;
132+
algorithm
133+
ty := match component
134+
case TYPED_COMPONENT() then component.ty;
135+
end match;
136+
end getType;
137+
138+
function setType
139+
input DAE.Type ty;
140+
input output Component component;
141+
algorithm
142+
component := match component
143+
case UNTYPED_COMPONENT()
144+
then TYPED_COMPONENT(component.name, component.classInst, ty,
145+
component.binding, component.attributes);
146+
147+
case TYPED_COMPONENT()
148+
algorithm
149+
component.ty := ty;
150+
then
151+
component;
152+
end match;
153+
end setType;
154+
155+
function unliftType
156+
input output Component component;
157+
algorithm
158+
_ := match component
159+
local
160+
DAE.Type ty;
161+
162+
case TYPED_COMPONENT(ty = DAE.T_ARRAY(ty = ty))
163+
algorithm
164+
component.ty := ty;
165+
then
166+
();
167+
168+
else ();
169+
end match;
170+
end unliftType;
171+
172+
function makeTopComponent
173+
input InstNode inst;
174+
output Component comp;
175+
algorithm
176+
comp := TYPED_COMPONENT(InstNode.name(inst), inst, DAE.T_UNKNOWN_DEFAULT,
177+
Binding.UNBOUND(), Attributes.ATTRIBUTES(
178+
DAE.VarKind.VARIABLE(), DAE.VarDirection.BIDIR(),
179+
DAE.VarVisibility.PUBLIC(), DAE.ConnectorType.NON_CONNECTOR()));
180+
end makeTopComponent;
86181
end Component;
87182

88183
annotation(__OpenModelica_Interface="frontend");

Compiler/NFFrontEnd/NFDimension.mo

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
33+
encapsulated package NFDimension
34+
" file: NFMod.mo
35+
package: NFMod
36+
description: A type for dimensions in NFInst.
37+
"
38+
39+
public
40+
import Absyn;
41+
import DAE;
42+
43+
protected
44+
import List;
45+
46+
public
47+
uniontype Dimension
48+
record UNTYPED_DIM
49+
Absyn.Exp dimension;
50+
Boolean isProcessing;
51+
end UNTYPED_DIM;
52+
53+
record TYPED_DIM
54+
DAE.Dimension dimension;
55+
end TYPED_DIM;
56+
57+
public
58+
function dimension
59+
input Dimension inDim;
60+
output DAE.Dimension outDim;
61+
algorithm
62+
TYPED_DIM(dimension = outDim) := inDim;
63+
end dimension;
64+
end Dimension;
65+
66+
annotation(__OpenModelica_Interface="frontend");
67+
end NFDimension;

0 commit comments

Comments
 (0)