/
Static.rml
6001 lines (4962 loc) · 209 KB
/
Static.rml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(*
This file is part of OpenModelica.
Copyright (c) 1998-2005, Linköpings universitet, Department of
Computer and Information Science, PELAB
All rights reserved.
(The new BSD license, see also
http://www.opensource.org/licenses/bsd-license.php)
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
* Neither the name of Linköpings universitet nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
\"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*)
(**
** file: static.rml
** module: Static
** description: Static analysis of expressions
**
** RCS: $Id$
**
** This module does static analysis on expressions.
** The analyzed expressions are built using the
** constructors in the `Exp' module from expressions defined in 'Absyn'.
** Also, a set of properties of the expressions is calculated during analysis.
** Properties of expressions include type information and a boolean indicating if the
** expression is constant or not.
** If the expression is constant, the 'Ceval' module is used to evaluate the expression
** value. A value of an expression is described using the 'Values' module.
** The main relation in this module is 'eval_exp' which takes an Absyn.Exp and transform it
** into an Exp.Exp, while performing type checking and automatic type conversions, etc.
** To determine types of builtin functions and operators, the module also contain an elaboration
** handler for functions and operators. This relation is called 'elab_builtin_handler'.
** NOTE: These relations should only determine the type and properties of the builtin functions and
** operators and not evaluate them. Constant evaluation is performed by the 'Ceval' module.
** The module also contain a relation for deoverloading of operators, in the 'deoverload' relation.
** It transforms operators like '+' to its specific form, ADD, ADD_ARR, etc.
**
** Interactive function calls are also given their types by 'elab_exp', which calls
** 'elab_call_interactive'.
**
** Elaboration for functions involve checking the types of the arguments by filling slots of the
** argument list with first positional and then named arguments to find a matching function. The
** details of this mechanism can be found in the Modelica specification.
** The elaboration also contain function deoverloading which will be added to Modelica in the future.
**)
module Static :
with "Absyn.rml"
with "Exp.rml"
with "SCode.rml"
with "Types.rml"
with "Env.rml"
with "Values.rml"
with "Interactive.rml"
type Ident = string
datatype Slot = SLOT of Types.FuncArg * (* An argument to a function *)
bool * (* True if the slot has been filled, *)
(* i.e. argument has been given a value*)
Exp.Exp option * (* Contain the elaborated expression *)
(* for the actual argument *)
Types.ArrayDim list (* dim_size - if argument is a
* 'foreach' argument this list is
* non-empty with the dimension
* sizes of the argument.
* See vectorized calls.
*)
(* Expression analysis *)
relation elab_exp : (Env.Env, Absyn.Exp,bool,Interactive.InteractiveSymbolTable option)
=> (Exp.Exp, Types.Properties, Interactive.InteractiveSymbolTable option)
relation elab_graphics_exp : (Env.Env, Absyn.Exp, bool (*impl*) ) => (Exp.Exp,
Types.Properties)
(* Special relation for graphics annotations, because of inhomogenous *)
(* array of graphics primitives *)
relation elab_exp_list : (Env.Env, Absyn.Exp list,bool (* Implicit inst *)
, Interactive.InteractiveSymbolTable option)
=> (Exp.Exp list, Types.Properties list, Interactive.InteractiveSymbolTable option)
relation elab_exp_list_list : (Env.Env, Absyn.Exp list list, bool (* Implicit inst *)
, Interactive.InteractiveSymbolTable option)
=> (Exp.Exp list list, Types.Properties list list, Interactive.InteractiveSymbolTable option)
relation elab_cref : (Env.Env, Absyn.ComponentRef, bool (*impl*) )
=> (Exp.Exp, Types.Properties, SCode.Accessibility)
relation elab_subscripts : (Env.Env, Absyn.Subscript list, bool (*impl*) )
=> (Exp.Subscript list, Types.Const)
relation canon_cref : (Env.Env, Exp.ComponentRef, bool (*impl*) ) => Exp.ComponentRef
relation elab_builtin_handler : Ident => ((Env.Env, Absyn.Exp list, bool (*impl*) )
=> (Exp.Exp, Types.Properties))
relation elab_builtin_handler_generic : Ident => ((Env.Env, Absyn.Exp list, bool (*impl*) )
=> (Exp.Exp, Types.Properties))
(* Property matching (type conversions etc.) *)
relation deoverload : ((Exp.Operator * Types.Type list * Types.Type) list,
(Exp.Exp * Types.Type) list,
Absyn.Exp)
=> (Exp.Operator, Exp.Exp list, Types.Type)
relation operators : (Absyn.Operator, Env.Env, Types.Type, Types.Type)
=> (Exp.Operator * Types.Type list * Types.Type) list
(* Utility relations *)
relation eq_cref : (Exp.ComponentRef, Exp.ComponentRef) => ()
relation value_exp : Values.Value => Exp.Exp
relation component_ref_to_path: Exp.ComponentRef => Absyn.Path
relation is_function_in_cflist : ((Absyn.Path * Types.Type) list, Absyn.Path)
=> bool
end
with "ClassInf.rml"
with "Dump.rml"
with "Print.rml"
with "System.rml"
with "Lookup.rml"
with "Debug.rml"
with "Inst.rml"
with "Codegen.rml"
with "ModUtil.rml"
with "DAE.rml"
with "Util.rml"
with "RTOpts.rml"
with "Parser.rml"
with "ClassLoader.rml"
with "Mod.rml"
with "Prefix.rml"
with "Ceval.rml"
with "Connect.rml"
(** relation: elab_exp_list
**
** Expression elaboration of Absyn.Exp list, i.e. lists of expressions.
**)
relation elab_exp_list : (Env.Env, Absyn.Exp list, bool, Interactive.InteractiveSymbolTable option)
=> (Exp.Exp list, Types.Properties list, Interactive.InteractiveSymbolTable option ) =
axiom elab_exp_list (_,[],impl,st) => ([],[],st)
rule elab_exp (env, e,impl,st) => (exp,p,st') &
elab_exp_list (env, rest,impl,st') => (exps, props,st'')
-----------------------------------------
elab_exp_list (env, e::rest,impl,st) => (exp::exps, p::props,st'')
end
(** relation: elab_exp_list_list
**
** Expression elaboration of lists of lists of expressions. Used in for
** instance matrices, etc.
**)
relation elab_exp_list_list : (Env.Env, Absyn.Exp list list, bool
, Interactive.InteractiveSymbolTable option)
=> (Exp.Exp list list, Types.Properties list list, Interactive.InteractiveSymbolTable option ) =
axiom elab_exp_list_list (_,[],impl,st) => ([],[],st)
rule elab_exp_list (env, e,impl,st) => (exp,p,st') &
elab_exp_list_list (env, rest,impl,st') => (exps, props,st'')
-----------------------------------------
elab_exp_list_list (env, e::rest,impl,st) => (exp::exps, p::props,st'')
end
(** relation: ceval_if_constant
**
** This relation calls Ceval.ceval if the Constant parameter indicates
** C_CONST.
**)
relation ceval_if_constant: (Exp.Exp, Types.Properties, Types.Const, bool (* impl *), Env.Env)
=> (Exp.Exp, Types.Properties) =
axiom ceval_if_constant(e,prop,Types.C_VAR,_,_) => (e, prop)
axiom ceval_if_constant(e,prop,Types.C_PARAM,_,_) => (e, prop)
axiom ceval_if_constant(e,prop,Types.C_CONST ,impl as true,_) => (e, prop)
rule Ceval.ceval(env,e,impl,NONE,NONE,Ceval.MSG) => (v,_) &
value_exp(v) => e' &
value_type(v) => vt
---------------------------------
ceval_if_constant(e,prop as Types.PROP(_,c),Types.C_CONST,impl (*as false*),env) => (e',Types.PROP(vt,c))
rule Ceval.ceval(env,e,impl,NONE,NONE,Ceval.MSG) => (v,_) &
value_exp(v) => e' &
value_type(v) => vt
---------------------------------
ceval_if_constant(e,prop as Types.PROP_TUPLE(_,c),Types.C_CONST,impl (*as false*),env) => (e',Types.PROP_TUPLE(vt,c))
axiom ceval_if_constant(e,prop,const,impl,env) => (e,prop)
end
(** relation: elab_exp
**
** Static analysis of expressions means finding out the properties of
** the expression. These properties are described by the
** `Types.Properties' type, and include the type and the variability of the
** expression. This relation performs analysis, and returns an
** `Exp.Exp' and the properties.
**)
relation elab_exp : (Env.Env, Absyn.Exp, bool, Interactive.InteractiveSymbolTable option)
=> (Exp.Exp, Types.Properties,Interactive.InteractiveSymbolTable option) =
(* The types below should contain the default values of the attributes of the builtin
* types. But since they are default, we can leave them out for now, unit="" is not
* that interesting to find out.
*)
axiom elab_exp(_, Absyn.INTEGER(x),impl,st)
=> (Exp.ICONST(x), Types.PROP((Types.T_INTEGER([]),NONE),Types.C_CONST),st)
axiom elab_exp(_, Absyn.REAL(x),impl,st)
=> (Exp.RCONST(x), Types.PROP((Types.T_REAL([]),NONE), Types.C_CONST),st)
axiom elab_exp(_, Absyn.STRING(x),impl,st)
=> (Exp.SCONST(x), Types.PROP((Types.T_STRING([]),NONE), Types.C_CONST),st)
axiom elab_exp(_, Absyn.BOOL(x),impl,st)
=> (Exp.BCONST(x), Types.PROP((Types.T_BOOL([]),NONE), Types.C_CONST),st)
axiom elab_exp(_,Absyn.END,impl,st)
=> (Exp.END, Types.PROP((Types.T_INTEGER([]),NONE), Types.C_CONST),st)
rule elab_cref(env, cr,impl) => (exp,prop,_)
---------------------------------------
elab_exp(env, Absyn.CREF(cr),impl,st) => (exp,prop,st)
(** Binary and unary operations *)
rule elab_exp (env,e1,impl,st) => (e1', Types.PROP(t1, c1),st') &
elab_exp (env,e2,impl,st') => (e2', Types.PROP(t2, c2),st'') &
Types.const_and (c1,c2) => c &
operators(op, env, t1, t2) => ops &
deoverload (ops, [(e1',t1),(e2',t2)], exp) => (op',[e1'',e2''],rtype) &
replace_operator_with_fcall(Exp.BINARY(e1'',op',e2''),c) => exp' &
let prop = Types.PROP(rtype,c) &
ceval_if_constant(exp',prop,c,impl,env) => (exp'',prop')
---------------------------------------------
elab_exp (env,exp as Absyn.BINARY(e1,op,e2),impl,st)
=> (exp'',prop',st'')
rule elab_exp (env,e,impl,st) => (e',Types.PROP(t,c),st') &
operators(op, env, t, (Types.T_NOTYPE,NONE)) => ops &
deoverload (ops, [(e',t)], exp) => (op', [e''], rtype) &
replace_operator_with_fcall(Exp.UNARY(op',e''),c) => exp' &
let prop = Types.PROP(rtype,c) &
ceval_if_constant(exp',prop,c,impl,env) => (exp'',prop')
---------------------------------------------------------
elab_exp (env,exp as Absyn.UNARY(op,e),impl, st)
=> (exp'',prop',st')
rule (* Logical binary expressions *)
elab_exp (env,e1,impl,st) => (e1', Types.PROP(t1, c1),st') &
elab_exp (env,e2,impl,st') => (e2', Types.PROP(t2, c2),st'') &
Types.const_and (c1,c2) => c &
operators(op, env, t1, t2) => ops &
deoverload (ops, [(e1',t1),(e2',t2)], exp) => (op',[e1'',e2''],rtype) &
replace_operator_with_fcall(Exp.LBINARY(e1'',op',e2''),c) => exp' &
let prop = Types.PROP(rtype,c) &
ceval_if_constant(exp',prop,c,impl,env) => (exp'',prop')
-----------------------------------------------------------------
elab_exp (env,exp as Absyn.LBINARY(e1,op,e2),impl,st)
=> (exp'',prop',st'')
rule (* Logical unary expressions *)
elab_exp (env,e,impl,st) => (e',Types.PROP(t,c),st') &
operators(op, env, t, (Types.T_NOTYPE,NONE)) => ops &
deoverload (ops, [(e',t)], exp) => (op', [e''], rtype) &
replace_operator_with_fcall(Exp.LUNARY(op',e''),c) => exp' &
let prop = Types.PROP(rtype,c) &
ceval_if_constant(exp',prop,c,impl,env) => (exp'',prop')
----------------------------------------------------------
elab_exp (env,exp as Absyn.LUNARY(op,e),impl,st)
=> (exp'',prop',st')
rule (* Relations, e.g. a < b *)
elab_exp (env,e1,impl,st) => (e1', Types.PROP(t1, c1),st') &
elab_exp (env,e2,impl,st') => (e2', Types.PROP(t2, c2),st'') &
Types.const_and (c1,c2) => c &
operators(op, env, t1, t2) => ops &
deoverload (ops, [(e1',t1),(e2',t2)], exp) => (op',[e1'',e2''],rtype) &
replace_operator_with_fcall(Exp.RELATION(e1'',op',e2''),c) => exp' &
let prop = Types.PROP(rtype,c) &
ceval_if_constant(exp',prop,c,impl,env) => (exp'',prop')
-----------------------------------------------------------------
elab_exp (env,exp as Absyn.RELATION(e1,op,e2),impl,st)
=> (exp'',prop',st'')
(** Conditional expressions *)
rule (* if expressions *)
elab_exp (env,e1,impl,st) => (e1', prop1,st') &
elab_exp (env,e2,impl,st') => (e2', prop2,st'') &
elab_exp (env,e3,impl,st'') => (e3', prop3,st''') &
elab_ifexp(env,e1',prop1,e2',prop2,e3',prop3,impl,st) => (e,prop)
(*TODO elseif part *)
------------------------------------------------------
elab_exp (env,Absyn.IFEXP(e1,e2,e3,_),impl,st) => (e,prop,st''')
rule (** Function calls *)
(** PA. Only positional arguments are elaborated for now.*)
(** TODO: Implement elaboration of named arguments. *)
Debug.fprintln("sei", "elab_exp CALL...") &
elab_call(env,fn,args,nargs,impl,st) => (e,prop,st') &
Types.prop_all_const prop => c &
ceval_if_constant(e,prop,c,impl,env) => (e',prop') &
Debug.fprintln("sei", "elab_exp CALL done")
--------------------------------------
elab_exp (env,Absyn.CALL(fn,Absyn.FUNCTIONARGS(args,nargs)),impl,st)
=> (e',prop',st')
(*PR. Get the properties for each expression in the tuple.
* Each expression has its own constflag.
* !!The output from functions does just have one const flag.
* Fix this!!
*)
rule (* Tuple function calls *)
elab_tuple(env,e,impl) => (e', props) &
split_props(props) => (types, consts)
-------------------------------------
elab_exp (env,Absyn.TUPLE(e as e1::rest),impl,st)
=> (Exp.TUPLE(e'),Types.PROP_TUPLE((Types.T_TUPLE(types),NONE), Types.TUPLE_CONST(consts)),st)
(** Array-related expressions *)
(** Elab reduction expressions, including array() constructor **)
rule elab_call_reduction(env,fn,exp,id,iterexp,impl,st) => (e,prop,st')
-------------------------------------------------------------------
elab_exp (env,Absyn.CALL(fn,Absyn.FOR_ITER_FARG(exp,id,iterexp)),impl,st)
=> (e,prop,st')
rule (* Range expressions without step value, e.g. 1:5 *)
elab_exp (env, start,impl,st) => (start', Types.PROP(start_t, c_start),st') &
elab_exp (env, stop,impl,st') => (stop', Types.PROP(stop_t, c_stop),st'') &
deoverload_range((start',start_t),
NONE,
(stop',stop_t)) => (start'',NONE,stop'',rt) &
Types.const_and (c_start, c_stop) => const &
elab_range_type (env,start'',NONE,stop'',const,rt,impl) => t
--------------------------------------------------
elab_exp (env, Absyn.RANGE(start, NONE, stop),impl,st)
=> (Exp.RANGE(rt,start',NONE,stop'), Types.PROP(t, const),st'')
rule (* Range expressions with step value, e.g. 1:0.5:4 *)
elab_exp (env,start,impl,st) => (start', Types.PROP(start_t, c_start),st') &
elab_exp (env,step,impl,st') => (step', Types.PROP(step_t, c_step),st'') &
elab_exp (env,stop,impl,st'') => (stop', Types.PROP(stop_t, c_stop),st''') &
deoverload_range((start',start_t),
SOME((step',step_t)),
(stop',stop_t)) => (start'',SOME(step''),stop'',rt) &
Types.const_and (c_start, c_step) => c1 &
Types.const_and (c1, c_stop) => const &
elab_range_type (env,start'',SOME(step''),stop'',const,rt,impl) => t
---------------------
elab_exp (env, Absyn.RANGE(start, SOME(step), stop),impl,st)
=> (Exp.RANGE(rt,start'',SOME(step''),stop''), Types.PROP(t, const),st''')
rule (* array expressions, e.g. {1,2,3} *)
elab_array (env, es,impl,st) => (es', Types.PROP(t, const)) & list_length es' => l&
Types.elab_type t => at &
Types.is_array t => a
--------------------------------------------------------------
elab_exp (env, Absyn.ARRAY(es),impl,st)
=> (Exp.ARRAY(at,a,es'),
Types.PROP((Types.T_ARRAY(Types.DIM(SOME(l)), t),NONE),
const),st)
rule (* matrix expressions, e.g. [1,0;0,1] with elements of simple type.*)
elab_exp_list_list(env,es,impl,st) => (_, tps, _) &
Util.list_list_map(tps,Types.get_prop_type) => tps' &
Util.list_flatten(tps') => tps'' &
Types.contain_real(tps'') => havereal &
elab_matrix_semi (env,es,impl,st,havereal) => (es', Types.PROP(t,c), dim1,dim2,nmax) &
Types.simple_type(t) &
Types.elab_type t => at
------------------------------------------------------------
elab_exp (env, Absyn.MATRIX(es),impl,st)
=> (Exp.MATRIX(at,nmax,es'),
Types.PROP((Types.T_ARRAY(Types.DIM(SOME(dim1)),
(Types.T_ARRAY(Types.DIM(SOME(dim2)), t),NONE)),NONE),
c),st)
rule (* matrix expressions, e.g. [1,0;0,1] with array elements. *)
elab_exp_list_list(env,es,impl,st) => (_, tps, _) &
Util.list_list_map(tps,Types.get_prop_type) => tps' &
Util.list_flatten(tps') => tps'' &
Types.contain_real(tps'') => havereal &
elab_matrix_semi (env,es,impl,st,havereal) => (es', Types.PROP(t,c), dim1,dim2,nmax) &
not Types.simple_type(t) &
add_onesized_dimensions(es', tps,nmax) => es'' &
Types.elab_type t => at
------------------------------------------------------------
elab_exp (env, Absyn.MATRIX(es),impl,st)
=> (Exp.MATRIX(at,nmax,es''),
Types.PROP((Types.T_ARRAY(Types.DIM(SOME(dim1)),
(Types.T_ARRAY(Types.DIM(SOME(dim2)), t),NONE)),NONE),
c),st)
rule (* Code expressions *)
elab_code_type(env,c) => tp &
Types.elab_type tp => tp'
-------------------
elab_exp (env, Absyn.CODE(c),impl,st) => (Exp.CODE(c,tp'),Types.PROP(tp,Types.C_CONST),st)
rule Debug.fprint("failtrace", "- elab_exp failed: ") &
Debug.fcallret("failtrace", Dump.print_exp_str, e, "") => expstr &
Debug.fprintln("failtrace", expstr)
-----------------------------------------------------------
elab_exp(_,e,_,_) => fail
end
(** relation: add_for_loop_scope_const
**
** Creates a new scope on the environment used for loops and adds a loop
** variable which is named by the second argument. The variable is given
** the value 1 (one) such that elaboration of expressions of containing the
** loop variable become constant.
**)
relation add_for_loop_scope_const : (Env.Env, Ident, Types.Type) => Env.Env =
rule Env.open_scope (env,false (*encapsulated?*),SOME("$for loop scope$")) => env' &
Env.extend_frame_v(env',
Types.VAR(i,
Types.ATTR(false,
SCode.RW,
SCode.PARAM,
Absyn.BIDIR),
false,
typ,
Types.VALBOUND(Values.INTEGER(1))),NONE,
false,
[]) => env''
--------------------------------------------------------------------------
add_for_loop_scope_const(env,i,typ) => env''
end
(** relation: elab_call_reduction
**
** This relation elaborates reduction expressions, that look like function
** calls. For example an array constructor.
**)
relation elab_call_reduction : (Env.Env, Absyn.ComponentRef, Absyn.Exp,
Ident, Absyn.Exp, bool,
Interactive.InteractiveSymbolTable option)
=> (Exp.Exp, Types.Properties,Interactive.InteractiveSymbolTable option) =
rule elab_exp (env,iterexp,impl,st)
=> (iterexp',
Types.PROP((Types.T_ARRAY(arraydim as Types.DIM(_), iterty),_),
iterconst),
_) &
add_for_loop_scope_const(env,iter,iterty) => env' &
(** const so that expr is elaborated to const **)
elab_exp (env', exp, impl, st) => (exp', Types.PROP(expty, expconst), st) &
Types.const_and (expconst, iterconst) => const &
let prop = Types.PROP((Types.T_ARRAY(arraydim, expty),NONE), const) &
Absyn.cref_to_path fn => fn'
---------------------------------------------------
elab_call_reduction (env,fn,exp,iter,iterexp,impl,st)
=> (Exp.REDUCTION (fn',exp',iter,iterexp'), prop, st)
end
(** relation: replace_operator_with_fcall
**
** Replaces a userdefined operator expression with a corresponding function
** call expression. Other expressions just passes through.
**)
relation replace_operator_with_fcall: (Exp.Exp,Types.Const ) => Exp.Exp =
axiom replace_operator_with_fcall(Exp.BINARY(e1,Exp.USERDEFINED(funcname),e2),c)
=> (Exp.CALL(funcname,[e1,e2],false,false))
axiom replace_operator_with_fcall(Exp.UNARY(Exp.USERDEFINED(funcname),e1),c)
=> (Exp.CALL(funcname,[e1],false,false))
axiom replace_operator_with_fcall(Exp.LBINARY(e1,Exp.USERDEFINED(funcname),e2),c)
=> (Exp.CALL(funcname,[e1,e2],false,false))
axiom replace_operator_with_fcall(Exp.LUNARY(Exp.USERDEFINED(funcname),e1),c)
=> (Exp.CALL(funcname,[e1],false,false))
axiom replace_operator_with_fcall(Exp.RELATION(e1,Exp.USERDEFINED(funcname),e2),c)
=> (Exp.CALL(funcname,[e1,e2],false,false))
axiom replace_operator_with_fcall(e,_) => e
end
(** relation: elab_code_type
**
** This relation will construct the correct type for the given Code
** expression. The types are built-in classes of different types. E.g.
** the class TypeName is the type
** of Code expressions corresponding to a type name Code expression.
**)
relation elab_code_type: (Env.Env, Absyn.Code) => Types.Type =
axiom elab_code_type(env, Absyn.C_TYPENAME(_))
=> ((Types.T_COMPLEX(ClassInf.UNKNOWN("TypeName"),[]),NONE))
axiom elab_code_type(env, Absyn.C_VARIABLENAME(_))
=> ((Types.T_COMPLEX(ClassInf.UNKNOWN("VariableName"),[]),NONE))
axiom elab_code_type(env, Absyn.C_EQUATIONSECTION(_,_))
=> ((Types.T_COMPLEX(ClassInf.UNKNOWN("EquationSection"),[]),NONE))
axiom elab_code_type(env, Absyn.C_ALGORITHMSECTION(_,_))
=> ((Types.T_COMPLEX(ClassInf.UNKNOWN("AlgorithmSection"),[]),NONE))
axiom elab_code_type(env, Absyn.C_ELEMENT(_))
=> ((Types.T_COMPLEX(ClassInf.UNKNOWN("Element"),[]),NONE))
axiom elab_code_type(env, Absyn.C_EXPRESSION(_))
=> ((Types.T_COMPLEX(ClassInf.UNKNOWN("Expression"),[]),NONE))
axiom elab_code_type(env, Absyn.C_MODIFICATION(_))
=> ((Types.T_COMPLEX(ClassInf.UNKNOWN("Modification"),[]),NONE))
end
(** relation elab_graphics_exp
**
** This relation is specially designed for elaboration of expressions when
** investigating Modelica 2.0 graphical annotations.
** These have an array of records representing graphical objects. These
** elements can have different types, therefore elab_graphic_exp will allow
** arrays with elements of varying types.
**)
relation elab_graphics_exp : (Env.Env, Absyn.Exp, bool (*impl*) )
=> (Exp.Exp, Types.Properties) =
axiom elab_graphics_exp(_, Absyn.INTEGER(x),impl)
=> (Exp.ICONST(x), Types.PROP((Types.T_INTEGER([]),NONE),Types.C_CONST))
axiom elab_graphics_exp(_, Absyn.REAL(x),impl)
=> (Exp.RCONST(x), Types.PROP((Types.T_REAL([]),NONE), Types.C_CONST))
axiom elab_graphics_exp(_, Absyn.STRING(x),impl)
=> (Exp.SCONST(x), Types.PROP((Types.T_STRING([]),NONE), Types.C_CONST))
axiom elab_graphics_exp(_, Absyn.BOOL(x),impl)
=> (Exp.BCONST(x), Types.PROP((Types.T_BOOL([]),NONE), Types.C_CONST))
rule elab_cref(env, cr, impl) => (exp,prop,_)
---------------------------------------
elab_graphics_exp(env, Absyn.CREF(cr), impl) => (exp,prop)
(** Binary and unary operations *)
rule elab_graphics_exp (env,e1,impl) => (e1', Types.PROP(t1, c1)) &
elab_graphics_exp (env,e2,impl) => (e2', Types.PROP(t2, c2)) &
Types.const_and (c1,c2) => c &
operators(op, env, t1, t2) => ops &
deoverload (ops, [(e1',t1),(e2',t2)], exp) => (op',[e1'',e2''],rtype)
---------------------------------------------------------------------
elab_graphics_exp (env,exp as Absyn.BINARY(e1,op,e2),impl)
=> (Exp.BINARY(e1'',op',e2''),Types.PROP(rtype,c))
rule elab_graphics_exp (env,e,impl) => (e',Types.PROP(t,c)) &
operators(op, env, t, (Types.T_NOTYPE,NONE)) => ops &
deoverload (ops, [(e',t)], exp) => (op', [e''], rtype)
------------------------------------------------------
elab_graphics_exp (env,exp as Absyn.UNARY(op,e),impl)
=> (Exp.UNARY(op',e''),Types.PROP(rtype,c))
rule (* Logical binary expressions *)
elab_graphics_exp (env,e1,impl) => (e1', Types.PROP(t1, c1)) &
elab_graphics_exp (env,e2,impl) => (e2', Types.PROP(t2, c2)) &
Types.const_and (c1,c2) => c &
operators(op, env, t1, t2) => ops &
deoverload (ops, [(e1',t1),(e2',t2)], exp) => (op',[e1'',e2''],rtype)
---------------------------------------------------------------------
elab_graphics_exp (env,exp as Absyn.LBINARY(e1,op,e2),impl)
=> (Exp.LBINARY(e1'',op',e2''),Types.PROP(rtype,c))
rule (* Logical unary expressions *)
elab_graphics_exp (env,e,impl) => (e',Types.PROP(t,c)) &
operators(op, env, t, (Types.T_NOTYPE,NONE)) => ops &
deoverload (ops, [(e',t)], exp) => (op', [e''], rtype)
------------------------------------------------------
elab_graphics_exp (env,exp as Absyn.LUNARY(op,e),impl)
=> (Exp.LUNARY(op',e''),Types.PROP(rtype,c))
rule (* Relation expressions *)
elab_graphics_exp (env,e1,impl) => (e1', Types.PROP(t1, c1)) &
elab_graphics_exp (env,e2,impl) => (e2', Types.PROP(t2, c2)) &
Types.const_and (c1,c2) => c &
operators(op, env, t1, t2) => ops &
deoverload (ops, [(e1',t1),(e2',t2)], exp) => (op',[e1'',e2''],rtype)
----------------------------------------------
elab_graphics_exp (env,exp as Absyn.RELATION(e1,op,e2),impl)
=> (Exp.RELATION(e1'',op',e2''),Types.PROP(rtype,c))
(** Conditional expressions *)
rule elab_graphics_exp (env,e1,impl) => (e1', prop1) &
elab_graphics_exp (env,e2,impl) => (e2', prop2) &
elab_graphics_exp (env,e3,impl) => (e3', prop3) &
elab_ifexp(env,e1',prop1,e2',prop2,e3',prop3,impl,NONE) => (e,prop)
(* TODO elseif part*)
------------------------------------------------------
elab_graphics_exp (env,Absyn.IFEXP(e1,e2,e3,_),impl) => (e,prop)
(** Function calls *)
rule Dump.print_component_ref_str fn => fnstr &
elab_call(env,fn,args,nargs,true,NONE) => (e,prop,_)
--------------------------------------
elab_graphics_exp (env,Absyn.CALL(fn,Absyn.FUNCTIONARGS(args,nargs)),impl)
=> (e,prop)
(*PR. Get the properties for each expression in the tuple.
* Each expression has its own constflag.
* !!The output from functions does just have one const flag.
* Fix this!!
*)
rule
elab_tuple(env,e,impl) => (e', props) &
split_props(props) => (types, consts)
-------------------------------------
elab_graphics_exp (env,Absyn.TUPLE(e as e1::rest),impl)
=> (Exp.TUPLE(e'),Types.PROP_TUPLE((Types.T_TUPLE(types),NONE), Types.TUPLE_CONST(consts)))
(** Array-related expressions *)
rule elab_graphics_exp (env, start,impl) => (start', Types.PROP(start_t, c_start)) &
elab_graphics_exp (env, stop,impl) => (stop', Types.PROP(stop_t, c_stop)) &
deoverload_range((start',start_t),
NONE,
(stop',stop_t)) => (start'',NONE,stop'',rt) &
Types.const_and (c_start, c_stop) => const &
elab_range_type (env,start'',NONE,stop'',const,rt,impl) => t
--------------------------------------------------
elab_graphics_exp (env, Absyn.RANGE(start, NONE, stop),impl)
=> (Exp.RANGE(rt,start',NONE,stop'), Types.PROP(t, const))
rule (*Debug.fprintln("setr", "elab_graphics_exp_range2") &*)
elab_graphics_exp (env, start,impl) => (start', Types.PROP(start_t, c_start)) &
elab_graphics_exp (env, step,impl) => (step', Types.PROP(step_t, c_step)) &
elab_graphics_exp (env, stop,impl) => (stop', Types.PROP(stop_t, c_stop)) &
deoverload_range((start',start_t),
SOME((step',step_t)),
(stop',stop_t)) => (start'',SOME(step''),stop'',rt) &
Types.const_and (c_start, c_step) => c1 &
Types.const_and (c1, c_stop) => const &
elab_range_type (env,start'',SOME(step''),stop'',const,rt,impl) => t
---------------------
elab_graphics_exp (env, Absyn.RANGE(start, SOME(step), stop),impl)
=> (Exp.RANGE(rt,start'',SOME(step''),stop''), Types.PROP(t, const))
rule elab_graphics_array (env, es,impl)
=> (es', Types.PROP(t, const)) & list_length es' => l&
Types.elab_type t => at &
Types.is_array t => a
--------------------------------------------------------------
elab_graphics_exp (env, Absyn.ARRAY(es),impl)
=> (Exp.ARRAY(at,a,es'),
Types.PROP((Types.T_ARRAY(Types.DIM(SOME(l)), t),NONE),
const))
rule elab_exp_list_list(env,es,impl,NONE) => (_, tps, _) &
Util.list_list_map(tps,Types.get_prop_type) => tps' &
Util.list_flatten(tps') => tps'' &
Types.contain_real(tps'') => havereal &
elab_matrix_semi (env,es,impl,NONE,havereal) => (es', Types.PROP(t,c), dim1,dim2,nmax) &
Types.elab_type t => at
------------------------------------------------------------
elab_graphics_exp (env, Absyn.MATRIX(es),impl)
=> (Exp.MATRIX(at,nmax,es'),
Types.PROP((Types.T_ARRAY(Types.DIM(SOME(dim1)),
(Types.T_ARRAY(Types.DIM(SOME(dim2)), t),NONE)),NONE),
c))
rule Print.print_error_buf "- elab_graphics_exp failed: " &
Dump.print_exp_str e => es &
Print.print_error_buf es &
Print.print_error_buf "\n"
-----------------------------------------------------------
elab_graphics_exp(_,e,impl) => fail
end
(** relation: deoverload_range
**
** Does deoverloading of range expressions. They can be both Integer ranges
** and Real ranges. This relation determines which one to use.
**)
relation deoverload_range : ((Exp.Exp*Types.Type),
(Exp.Exp*Types.Type) option,
(Exp.Exp*Types.Type))
=> (Exp.Exp, Exp.Exp option, Exp.Exp, Exp.Type) =
axiom deoverload_range((e1,(Types.T_INTEGER(_),_)),
NONE,
(e3,(Types.T_INTEGER(_),_))) => (e1,NONE,e3,Exp.INT)
axiom deoverload_range((e1,(Types.T_INTEGER(_),_)),
SOME((e2,(Types.T_INTEGER(_),_))),
(e3,(Types.T_INTEGER(_),_))) => (e1,SOME(e2),e3,Exp.INT)
rule elab_arglist([(Types.T_REAL([]),NONE),(Types.T_REAL([]),NONE)],
[(e1,t1),(e3,t3)]) => ([e1',e3'],_)
---------------------------------------------------
deoverload_range((e1,t1),NONE,(e3,t3)) => (e1',NONE,e3',Exp.REAL)
rule elab_arglist([(Types.T_REAL([]),NONE),(Types.T_REAL([]),NONE),(Types.T_REAL([]),NONE)],
[(e1,t1),(e2,t2),(e3,t3)]) => ([e1',e2',e3'],_)
---------------------------------------------------
deoverload_range((e1,t1),SOME((e2,t2)),(e3,t3))
=> (e1',SOME(e2'),e3',Exp.REAL)
end
(** relation: elab_range_type
**
** Helper relation to elab_range. Calculates the dimension of the
** range expression.
**)
relation elab_range_type : (Env.Env, Exp.Exp, Exp.Exp option,
Exp.Exp, Types.Const,
Exp.Type, bool (*impl*) )
=> Types.Type =
rule Ceval.ceval (env,start,impl,NONE,NONE,Ceval.MSG) => (Values.INTEGER(startv),_) &
Ceval.ceval (env,stop,impl,NONE,NONE,Ceval.MSG) => (Values.INTEGER(stopv),_) &
int_sub (stopv,startv) => n & int_add (n,1) => n'
-------------------------------------------------
elab_range_type (env,start,NONE,stop,const ,_,impl (*as false*))
=> ((Types.T_ARRAY(Types.DIM(SOME(n')), (Types.T_INTEGER([]),NONE)),NONE))
rule Ceval.ceval (env,start,impl,NONE,NONE,Ceval.MSG)
=> (Values.INTEGER(startv),_) &
Ceval.ceval (env,step,impl,NONE,NONE,Ceval.MSG)
=> (Values.INTEGER(stepv),_) &
Ceval.ceval (env,stop,impl,NONE,NONE,Ceval.MSG)
=> (Values.INTEGER(stopv),_) &
int_sub (stopv,startv) => n &
int_div (n,stepv) => n' &
int_add (n',1) => n''
-------------------------------------------------
elab_range_type (env,start,SOME(step),stop,const,_,impl (*as false*))
=> ((Types.T_ARRAY(Types.DIM(SOME(n'')), (Types.T_INTEGER([]),NONE)),NONE))
rule Ceval.ceval (env,start,impl,NONE,NONE,Ceval.MSG)
=> (Values.REAL(startv),_) &
Ceval.ceval (env,stop,impl,NONE,NONE,Ceval.MSG)
=> (Values.REAL(stopv),_) &
real_sub (stopv,startv) => n &
real_floor n => n'' &
real_int n'' => n''' &
int_add (n''',1) => n'
-------------------------------------------------
elab_range_type (env,start,NONE,stop,const,_,impl (*as false*))
=> ((Types.T_ARRAY(Types.DIM(SOME(n')), (Types.T_REAL([]),NONE)),NONE))
rule Ceval.ceval (env,start,impl,NONE,NONE,Ceval.MSG)
=> (Values.REAL(startv),_) &
Ceval.ceval (env,step,impl,NONE,NONE,Ceval.MSG)
=> (Values.REAL(stepv),_) &
Ceval.ceval (env,stop,impl,NONE,NONE,Ceval.MSG)
=> (Values.REAL(stopv),_) &
real_sub (stopv,startv) => n &
real_div (n,stepv) => n' &
real_floor n' => n''' &
real_int n''' => n'''' &
int_add (n'''',1) => n''
-------------------------------------------------
elab_range_type (env,start,SOME(step),stop,const,_,impl (*as false*))
=> ((Types.T_ARRAY(Types.DIM(SOME(n'')), (Types.T_REAL([]),NONE)),NONE))
axiom elab_range_type (_,_,_,_,const,Exp.INT,impl as true)
=> ((Types.T_ARRAY(Types.DIM(NONE), (Types.T_INTEGER([]),NONE)),NONE))
axiom elab_range_type (_,_,_,_,const,Exp.REAL,impl as true)
=> ((Types.T_ARRAY(Types.DIM(NONE), (Types.T_REAL([]),NONE)),NONE))
rule Debug.fprint("failtrace", "- elab_range_type failed: ") &
Exp.print_exp_str start => s1 &
Util.apply_option(step, Exp.print_exp_str) => s2opt &
Util.flatten_option (s2opt,"none") => s2 &
Exp.print_exp_str stop => s3 &
Types.unparse_const const => s4 &
Util.if(impl, "impl", "expl") => s5 &
Exp.type_string expty => s6 &
Util.string_append_list(["(",s1,":",s2,":",s3,") ",s4," ",s5," ",s6]) => str &
Debug.fprintln("failtrace", str)
-------------------------------------------------------
elab_range_type (env,start,step,stop,const,expty,impl) => fail
end
(** relation: elab_tuple
**
** This relation does elaboration of tuples, i.e. function calls returning
** several values.
**)
relation elab_tuple : (Env.Env, Absyn.Exp list, bool (*impl*) )
=> (Exp.Exp list, Types.Properties list) =
rule (*Debug.print "\nEntered elab_tuple." &*)
elab_exp (env,e,impl,NONE) => (e',p,_) &
(* Debug.print "\nElaborated expression." &*)
elab_tuple(env,exps,impl) => (exps',props)
(* Debug.print "\nThe last element was just elaborated."*)
-----------------------------
elab_tuple(env,e::exps,impl) => (e'::exps', p::props)
rule (*Debug.print "elaborating last element."*)
----------------
elab_tuple(env,[],impl) => ([], [])
end
(** relation: elab_array
**
** This relation elaborates on array expressions.
**
** All types of an array should be equivalent. However, mixed Integer and Real
** elements are allowed in an array and in that case the Integer elements
** are converted to Real elements.
**)
relation elab_array : (Env.Env, Absyn.Exp list,
bool (*impl*),
Interactive.InteractiveSymbolTable option)
=> (Exp.Exp list, Types.Properties) =
(* array contains mixed Integer and Real types *)
rule elab_array_has_mixed_int_reals(env,expl,impl,st) &
elab_array_real(env,expl,impl,st) => (expl',prop)
-------------
elab_array(env,expl,impl,st) => (expl',prop)
rule elab_array2(env,expl,impl,st) => (expl',prop)
----------------------
elab_array(env,expl,impl,st) => (expl',prop)
end
(** relation: elab_array_has_mixed_int_reals
**
** Helper relation to elab_array, checks if expression list contains both
** Integer and Real types.
**)
relation elab_array_has_mixed_int_reals: (Env.Env, Absyn.Exp list,
bool (*impl*),
Interactive.InteractiveSymbolTable option) => () =
rule elab_array_has_int(env,expl,impl,st) &
elab_array_has_real(env,expl,impl,st)
---------------------------------------------------
elab_array_has_mixed_int_reals(env,expl,impl,st)
end
(** relation: elab_array_has_int
** author :PA
**
** Helper relation to elab_array.
**)
relation elab_array_has_int: (Env.Env, Absyn.Exp list,
bool (* impl *),
Interactive.InteractiveSymbolTable option)
=> () =
rule elab_exp(env,e,impl,st) => (e',Types.PROP((Types.T_INTEGER([]),_),_),_)
-----------------------------
elab_array_has_int(env,e::expl,impl,st)
rule elab_array_has_int(env,expl,impl,st)
-----------------------------
elab_array_has_int(env,e::expl,impl,st)
end
(** relation: elab_array_has_real
** author :PA
**
** Helper relation to elab_array.
**)
relation elab_array_has_real: (Env.Env, Absyn.Exp list,
bool (* impl *),
Interactive.InteractiveSymbolTable option)
=> () =
rule elab_exp(env,e,impl,st) => (e',Types.PROP((Types.T_REAL([]),_),_),_)
-----------------------------
elab_array_has_real(env,e::expl,impl,st)
rule elab_array_has_real(env,expl,impl,st)
-----------------------------
elab_array_has_real(env,e::expl,impl,st)
end
(** relation: elab_array_real
**
** Helper relation to elab_array, converts all elements to Real
**)
relation elab_array_real : (Env.Env, Absyn.Exp list,
bool (*impl*),
Interactive.InteractiveSymbolTable option)
=> (Exp.Exp list, Types.Properties) =
(* elaborate each expression, pick first realtype
** and type_convert all expressions to that type *)
rule elab_exp_list(env,expl,impl,st) => (expl',props,_) &
elab_array_first_props_real(props) => real_tp &
elab_array_const(props) => const &
Util.list_map(props,Types.get_prop_type) => types &
elab_array_real2(expl',types,real_tp) => (expl'',real_tp')
-----------------------
elab_array_real(env,expl,impl,st)
=> (expl'',Types.PROP(real_tp',const))
end
(** relation: elab_array_first_props_real
** author: PA
**
** Pick the first type among the list of properties which has elementype
** Real.
**)
relation elab_array_first_props_real: Types.Properties list => Types.Type =
rule Types.array_element_type(tp) => (tp' as (Types.T_REAL(_),_))
-----------------------------------
elab_array_first_props_real(Types.PROP(tp,_)::_) => tp'
rule elab_array_first_props_real(rest) => tp
-----------------------------------
elab_array_first_props_real(_::rest) => tp
end
(** relation: elab_array_const
**
** Constructs a const value from a list of properties, using const_and.
**)
relation elab_array_const: (Types.Properties list) => Types.Const =
axiom elab_array_const([Types.PROP(tp,c)]) => c
rule elab_array_const(rest) => c2 &
Types.const_and(c2,c1) => c
--------------------------
elab_array_const(Types.PROP(_,c1)::rest) => c
end