Skip to content

Commit d56b33a

Browse files
author
x97davka
committed
Bug and doc fixes
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@446 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent f0df895 commit d56b33a

File tree

10 files changed

+327
-215
lines changed

10 files changed

+327
-215
lines changed

modeq/absyn.rml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,11 @@ module Absyn:
157157
datatype Subscript = NOSUB
158158
| SUBSCRIPT of Exp
159159
(** The `Subscript' datatype is used both in array declarations and *)
160-
(** component references. *)
160+
(** component references. This might seem strange, but it is *)
161+
(** inherited from the grammar. The `NOSUB' constructor means that *)
162+
(** the dimension size is undefined when used in a declaration, and *)
163+
(** when it is used in a component reference it means a slice of the *)
164+
(** whole dimension. *)
161165

162166
(** - Component references and paths *)
163167
datatype ComponentRef = CREF_QUAL of Ident * (Subscript list) * ComponentRef

modeq/builtin.rml

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,20 @@ val bool_type = SCode.CLASS("BooleanType",false,Absyn.R_PREDEFINED_BOOL,
4343

4444
(** - The `Real' type *)
4545

46-
val real_type =
47-
SCode.CLASS("Real",false,Absyn.R_PREDEFINED_REAL,
48-
SCode.PARTS
49-
([(* quantity *)
50-
SCode.COMPONENT("unit",true,false,
46+
val unit = SCode.COMPONENT("unit",true,false,
5147
SCode.ATTR([],
5248
false,
5349
SCode.RW,
5450
Absyn.VAR,
5551
Absyn.BIDIR),
5652
Absyn.IDENT("StringType"),
57-
SCode.NOMOD)],
53+
SCode.MOD(false,[],SOME(Absyn.STRING(""))))
54+
55+
val real_type =
56+
SCode.CLASS("Real",false,Absyn.R_PREDEFINED_REAL,
57+
SCode.PARTS
58+
([(* quantity *)
59+
unit],
5860
(* displayUnit *)
5961
[],
6062
[]))
@@ -65,14 +67,7 @@ val integer_type =
6567
SCode.CLASS("Integer",false,Absyn.R_PREDEFINED_INT,
6668
SCode.PARTS
6769
([(* quantity *)
68-
SCode.COMPONENT("unit",true,false,
69-
SCode.ATTR([],
70-
false,
71-
SCode.RW,
72-
Absyn.VAR,
73-
Absyn.BIDIR),
74-
Absyn.IDENT("StringType"),
75-
SCode.NOMOD)],
70+
unit],
7671
(* displayUnit *)
7772
[],
7873
[]))
@@ -98,7 +93,7 @@ SCode.CLASS("Boolean",false,Absyn.R_PREDEFINED_BOOL,
9893
(** - The `time' variable *)
9994

10095
val time_var =
101-
Types.VAR("time", SCode.ATTR([] , false, SCode.RO, Absyn.VAR, Absyn.BIDIR),
96+
Types.VAR("time", Types.ATTR(false, SCode.RO, Absyn.VAR, Absyn.BIDIR),
10297
false, Types.T_REAL, Types.UNBOUND)
10398

10499
(** - Some assorted function types *)

modeq/classinf.rml

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,6 @@
1414
** `trans' signals transitions in the machine. Finally, the state
1515
** can be checked agains a restriction with the `valid' relation.
1616
**
17-
** The restricted forms are ordered in a hierarchal fashion as
18-
** described by the following diagram:
19-
**
20-
**| CLASS -+- TYPE --- RECORD --- CONNECTOR
21-
**| |
22-
**| +- BLOCK --- FUNCTION
23-
**| |
24-
**| +- PACKAGE
25-
**| |
26-
**| +- MODEL
27-
**
2817
**)
2918

3019
module ClassInf :
@@ -72,7 +61,10 @@ end
7261
(** - Printing *)
7362
(**)
7463
(** Some relations for printing error and debug information about the *)
75-
(** state machine. *)
64+
(** state machine.
65+
**
66+
** The code is excluded from the report.
67+
**)
7668

7769
(*!ignorecode*)
7870

@@ -238,6 +230,13 @@ relation trans : (State, Event) => State =
238230
end
239231

240232
(** relation: valid
233+
**
234+
** This is the validity relation which determines if a state is valid
235+
** according to one of the restrictions. This means, that if a class
236+
** definition is to be used as, say, a connector, the state of the
237+
** state machine is checked against the `Absyn.R_CONNECTOR'
238+
** restriction using this relation to find out if it is an error to
239+
** use this class definition as a connector.
241240
**)
242241

243242
relation valid : (State, Absyn.Restriction) => () =
@@ -279,6 +278,9 @@ relation valid : (State, Absyn.Restriction) => () =
279278
end
280279

281280
(** relation: assert_valid
281+
**
282+
** This relation has the same semantical meaning as the relation
283+
** `valid'. However, it prints an error message when it faild.
282284
**)
283285

284286
relation assert_valid : (State, Absyn.Restriction) => () =

modeq/exp.rml

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ module Exp:
7979
datatype ComponentRef = CREF_QUAL of Ident * (Subscript list) * ComponentRef
8080
| CREF_IDENT of Ident * (Subscript list)
8181

82-
datatype Subscript = NOSUB
82+
datatype Subscript = WHOLEDIM
8383
| SLICE of Exp
8484
| INDEX of Exp
8585
(** the `Subscript' and `ComponentRef' datatypes are simple *)
@@ -91,6 +91,7 @@ module Exp:
9191
relation simplify : Exp => Exp
9292
relation print_exp : Exp => ()
9393
relation print_component_ref : ComponentRef => ()
94+
relation print_subscript: Subscript => ()
9495
relation print_list : ('a list, 'a => (), string) => ()
9596

9697
end
@@ -166,7 +167,7 @@ relation simplify : Exp => Exp =
166167
simplify ASUB(e, i) => IFEXP(c,t',f')
167168

168169
rule simplify e => CREF(CREF_IDENT(n,s)) &
169-
list_append(s,[INDEX(ICONST(i))]) => s'
170+
subscripts_append(s,i) => s'
170171
------------------------
171172
simplify ASUB(e, i) => CREF(CREF_IDENT(n,s'))
172173

@@ -179,6 +180,31 @@ relation simplify : Exp => Exp =
179180

180181
end
181182

183+
(** relation: subscripts_append
184+
**
185+
** This relation takes a subscript list and adds a new subscript.
186+
** But there are a few special cases. When the last existing
187+
** subscript is a slice, it is replaced by the slice indexed by the
188+
** new subscript.
189+
**)
190+
191+
relation subscripts_append : (Subscript list, int) => Subscript list =
192+
193+
axiom subscripts_append([], i) => [INDEX(ICONST(i))]
194+
195+
axiom subscripts_append([WHOLEDIM], i) => [INDEX(ICONST(i))]
196+
197+
rule simplify ASUB(e, i) => e'
198+
-------------------------
199+
subscripts_append([SLICE(e)], i) => [INDEX(e')]
200+
201+
axiom subscripts_append([s as INDEX(_)], i) => [s, INDEX(ICONST(i))]
202+
203+
rule subscripts_append(ss, i) => ss'
204+
-------------------------------
205+
subscripts_append(s::ss, i) => s::ss'
206+
207+
end
182208

183209
(**
184210
** - Printing expressions
@@ -256,7 +282,7 @@ relation print_subscript: Subscript => () =
256282

257283
rule print ":"
258284
---------
259-
print_subscript(NOSUB)
285+
print_subscript(WHOLEDIM)
260286

261287
rule print_exp(e1)
262288
-------------

modeq/inst.rml

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,8 @@ relation inst_element : (Env, Mod, Prefix, Connect.Sets, ClassInf.State,
406406
(** binding. *)
407407

408408
make_binding (env,attr,eq,cl) => binding &
409-
Env.extend_frame_v(env,Types.VAR(n,attr,prot,ty,binding)) => env' &
409+
Env.extend_frame_v(env,Types.VAR(n,Types.ATTR(flow,acc,param,dir),
410+
prot,ty,binding)) => env' &
410411

411412
(** If the type is one of the simple, predifined types a *)
412413
(** simple variable declaration is added to the DAE. *)
@@ -421,8 +422,7 @@ relation inst_element : (Env, Mod, Prefix, Connect.Sets, ClassInf.State,
421422
attr as SCode.ATTR(ad,flow,acc,param,dir),
422423
t,m))
423424
=> (dae, env',csets',ci_state,
424-
[Types.VAR(n,SCode.ATTR([],flow,acc,param,dir),
425-
prot, ty, binding)])
425+
[Types.VAR(n,Types.ATTR(flow,acc,param,dir), prot, ty, binding)])
426426

427427

428428
(** If the class lookup in the previous rule fails, this
@@ -478,7 +478,8 @@ relation inst_var : (Env.Env,Mod.Mod,Prefix.Prefix,Connect.Sets,Ident,
478478
eq,[],idxs)
479479
=> (dae,csets',ty)
480480

481-
rule inst_array(env,mod,pre,csets,n,(cl,attr),1,dim,dims,idxs)
481+
rule print "= inst_array mod: " & print n & Mod.print_mod mod & print "\n" &
482+
inst_array(env,mod,pre,csets,n,(cl,attr),1,dim,dims,idxs)
482483
=> (dae, csets', ty) &
483484
Types.lift_array(ty,SOME(dim)) => ty'
484485
-------------------------------
@@ -754,8 +755,7 @@ relation add_package : (Env.Env, Absyn.Ident, Types.Type, ClassInf.State,
754755

755756
rule ClassInf.valid(st, Absyn.R_PACKAGE) &
756757
Env.extend_frame_v(env,
757-
Types.VAR(n, SCode.ATTR([],
758-
false,SCode.RO,Absyn.CONST,
758+
Types.VAR(n, Types.ATTR(false,SCode.RO,Absyn.CONST,
759759
Absyn.BIDIR),
760760
false,
761761
ty,Types.UNBOUND)) => env'
@@ -909,9 +909,13 @@ relation inst_equation : (Env,Mod, Prefix, Connect.Sets, ClassInf.State,
909909
**
910910
** The loop expression is evaluated to a constant array of
911911
** integers, and then the loop is unrolled.
912+
**
912913
**)
913914

914-
rule Static.elab_exp (env,e)
915+
rule Lookup.lookup_var(env, Exp.CREF_IDENT(i,[]))
916+
=> (Types.ATTR(false, SCode.RW, Absyn.VAR, _),
917+
Types.T_INTEGER, Types.UNBOUND) &
918+
Static.elab_exp (env,e)
915919
=> (e',Static.PROP(Types.T_ARRAY(Types.DIM(_),
916920
Types.T_INTEGER),
917921
true)) &
@@ -923,6 +927,14 @@ relation inst_equation : (Env,Mod, Prefix, Connect.Sets, ClassInf.State,
923927
inst_equation(env,mod,pre,csets,ci_state,SCode.EQ_FOR(i,e,el))
924928
=> (dae, env,csets', ci_state')
925929

930+
rule not Lookup.lookup_var(env, Exp.CREF_IDENT(i,[]))
931+
=> (Types.ATTR(false, SCode.RW, Absyn.VAR, _),
932+
Types.T_INTEGER, Types.UNBOUND) &
933+
print "# Invalid loop variable: " & print i & print "\n"
934+
-----------------------------------------------------------
935+
inst_equation(env,mod,pre,csets,ci_state,SCode.EQ_FOR(i,e,el))
936+
=> fail
937+
926938
rule print "- inst_equation failed\n"
927939
----------------------------------
928940
inst_equation(_,_,_,_,_,_) => fail
@@ -987,6 +999,9 @@ relation inst_eq_equation_2 : (Exp.Exp, Exp.Exp, Types.Type)
987999
=> [DAE.EQUATION(e1,e2)]
9881000

9891001
rule RTOpts.split_arrays => true &
1002+
print " Array equation: " &
1003+
Exp.print_exp e1 & print " = " &
1004+
Exp.print_exp e2 & print "\n" &
9901005
inst_array_equation(e1,e2,ad,t) => dae
9911006
-----------------------------------------
9921007
inst_eq_equation_2(e1,e2,Types.T_ARRAY(ad,t)) => dae
@@ -1142,8 +1157,7 @@ relation unroll : (Env, Mod, Prefix, Connect.Sets, ClassInf.State,
11421157

11431158
rule Env.open_scope env => env' &
11441159
Env.extend_frame_v (env',
1145-
Types.VAR(i, SCode.ATTR([],
1146-
false,
1160+
Types.VAR(i, Types.ATTR(false,
11471161
SCode.RO,
11481162
Absyn.CONST,
11491163
Absyn.BIDIR),
@@ -1270,7 +1284,7 @@ relation inst_connect: (Connect.Sets, Env, Prefix,
12701284
Static.canon_cref(env, c1') => c1'' &
12711285
Static.canon_cref(env, c2') => c2'' &
12721286
Lookup.lookup_var_local(env,c1'')
1273-
=> (attr1 as SCode.ATTR(_,flow1,_,_,_),ty1,_) &
1287+
=> (attr1 as Types.ATTR(flow1,_,_,_),ty1,_) &
12741288
Lookup.lookup_var_local(env,c2'') => (attr2,ty2,_) &
12751289

12761290
(** Check that the types of the connectors are good. *)
@@ -1320,45 +1334,45 @@ end
13201334
**)
13211335

13221336
relation check_connect_types : (Exp.ComponentRef, Types.Type,
1323-
SCode.Attributes,
1337+
Types.Attributes,
13241338
Exp.ComponentRef, Types.Type,
1325-
SCode.Attributes) => () =
1339+
Types.Attributes) => () =
13261340

13271341
rule print "# Can't connect two input variables\n" &
13281342
print " while connecting " & Exp.print_component_ref c1 &
13291343
print " to " & Exp.print_component_ref c2 & print "\n"
13301344
------------------------------------------------------
1331-
check_connect_types(c1,_,SCode.ATTR(_,_,_,_,Absyn.INPUT),
1332-
c2,_,SCode.ATTR(_,_,_,_,Absyn.INPUT)) => fail
1345+
check_connect_types(c1,_,Types.ATTR(_,_,_,Absyn.INPUT),
1346+
c2,_,Types.ATTR(_,_,_,Absyn.INPUT)) => fail
13331347

13341348
rule print "# Can't connect two output variables\n" &
13351349
print " while connecting " & Exp.print_component_ref c1 &
13361350
print " to " & Exp.print_component_ref c2 & print "\n"
13371351
------------------------------------------------------
1338-
check_connect_types(c1,_,SCode.ATTR(_,_,_,_,Absyn.OUTPUT),
1339-
c2,_,SCode.ATTR(_,_,_,_,Absyn.OUTPUT)) => fail
1352+
check_connect_types(c1,_,Types.ATTR(_,_,_,Absyn.OUTPUT),
1353+
c2,_,Types.ATTR(_,_,_,Absyn.OUTPUT)) => fail
13401354

13411355
rule flow1 = flow2 &
13421356
Types.equivtypes(t1, t2) => true
13431357
-------------------------------
1344-
check_connect_types(_,t1,SCode.ATTR(_,flow1,_,_,_),
1345-
_,t2,SCode.ATTR(_,flow2,_,_,_))
1358+
check_connect_types(_,t1,Types.ATTR(flow1,_,_,_),
1359+
_,t2,Types.ATTR(flow2,_,_,_))
13461360

13471361
rule print "# Can't connect flow component " &
13481362
Exp.print_component_ref c1 &
13491363
print " to non-flow component " &
13501364
Exp.print_component_ref c2 & print "\n"
13511365
------------------------------------------------------
1352-
check_connect_types(c1,_,SCode.ATTR(_,true,_,_,_),
1353-
c2,_,SCode.ATTR(_,false,_,_,_)) => fail
1366+
check_connect_types(c1,_,Types.ATTR(true,_,_,_),
1367+
c2,_,Types.ATTR(false,_,_,_)) => fail
13541368

13551369
rule print "# Can't connect non-flow component " &
13561370
Exp.print_component_ref c1 &
13571371
print " to flow component " &
13581372
Exp.print_component_ref c2 & print "\n"
13591373
------------------------------------------------------
1360-
check_connect_types(c1,_,SCode.ATTR(_,false,_,_,_),
1361-
c2,_,SCode.ATTR(_,true,_,_,_)) => fail
1374+
check_connect_types(c1,_,Types.ATTR(false,_,_,_),
1375+
c2,_,Types.ATTR(true,_,_,_)) => fail
13621376

13631377
rule print "- check_connect_types(" & Exp.print_component_ref c1 &
13641378
print " <-> " & Exp.print_component_ref c2 & print ") failed\n"
@@ -1446,9 +1460,9 @@ relation connect_vars : (Connect.Sets,
14461460
connect_vars(sets',c1,f1,xs1,c2,f2,xs2) => sets''
14471461
--------------------------------------
14481462
connect_vars(sets,
1449-
c1,f1, Types.VAR(n,attr1 as SCode.ATTR(_,flow1,_,vt1,_),
1463+
c1,f1, Types.VAR(n,attr1 as Types.ATTR(flow1,_,vt1,_),
14501464
_,ty1,_)::xs1,
1451-
c2,f2, Types.VAR(_,attr2 as SCode.ATTR(_,flow2,_,vt2,_),
1465+
c2,f2, Types.VAR(_,attr2 as Types.ATTR(flow2,_,vt2,_),
14521466
_,ty2,_)::xs2)
14531467
=> sets''
14541468

0 commit comments

Comments
 (0)