summaryrefslogtreecommitdiff
path: root/gcc/melt/xtramelt-ana-tree.melt
blob: bdd84893c8e0985a0708679781c55f63a8392e36 (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
;; -*- Lisp -*-
;; file xtramelt-ana-tree.melt
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(comment "***
    Copyright 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
    Contributed by Basile Starynkevitch <basile@starynkevitch.net>
                and Jeremie Salvucci  <jeremie.salvucci@free.fr>
                and Pierre Vittet  <piervit@pvittet.com>
                and Romain Geissler  <romain.geissler@gmail.com>

    This file xtramelt-ana-tree.{melt,c} is part of GCC.

    GCC is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 3, or (at your option)
    any later version.

    GCC is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with GCC; see the file COPYING3.  If not see
    <http://www.gnu.org/licenses/>.
***")

;; the copyright notice above apply both to xtramelt-ana-tree.melt and 
;; to the generated file  xtramelt-ana-tree*.c

;; Most code here was in xtramelt-ana-base.melt before svn rev 186705
;; ie MELT version 0.9.5 and earlier (before april 24th, 2012).


(defprimitive walk_use_def_chain_depth_first (:value clos val :tree trvar) :void
  :doc #{Walk in a depth first order the use-def chaine of SSA
variable $TRVAR; apply the $CLOS closure to the $VAL value and to the
current :tree and :gimple. Stop walking if the closure gives null.}#
  #{ /* walk_use_def_chain_depth_first */  meltgc_walk_use_def_chain (((melt_ptr_t)($CLOS)),
     ((melt_ptr_t)($VAL)), $TRVAR, /*depth first*/TRUE); }#
)

(defprimitive walk_use_def_chain_breadth_first (:value clos val :tree trvar) :void
  :doc #{Walk in a breadth first order the use-def chaine of SSA
variable $TRVAR; apply the $CLOS closure to the $VAL value and to the
current :tree and :gimple. Stop walking if the closure gives null.}#
  #{ /* walk_use_def_chain_breadth_first */ meltgc_walk_use_def_chain (((melt_ptr_t)($CLOS)), 
    ((melt_ptr_t)($VAL)), $TRVAR, /*depth first*/FALSE); }#
)



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defprimitive is_tree (v) :long
  :doc #{$IS_TREE test if value $V is a boxed tree}#
  #{(melt_magic_discr((melt_ptr_t)($v)) == MELTOBMAG_TREE)}# )

(defprimitive isnull_tree (:tree tr) :long
  :doc #{$ISNULL_TREE test if raw tree $TR is null}#
  #{$tr == NULL_TREE}#
)

(defprimitive make_tree (discr :tree tr) :value
  :doc #{$MAKE_TREE build a boxed tree of given $DISCR and tree $TR}#
  #{(meltgc_new_tree((meltobject_ptr_t)($DISCR),($TR)))}# )

(defprimitive tree_content (v) :tree
  :doc #{$TREE_CONTENT safely retrieve the tree inside boxed value $V}#
  #{(melt_tree_content((melt_ptr_t)($V)))}# )

(defprimitive ==t (:tree t1 t2) :long
  :doc #{==T safely compare tree $T1 and $T2 for identity}#
  #{(($t1) == ($t2))}# )

(defprimitive null_tree () :tree 
  :doc #{$NULL_TREE gives the null tree}#
#{(NULL_TREE)}#)

(defprimitive inform_at_tree (:tree tr :cstring msg) :void
  ;; if DECL_P(tr) use DECL_SOURCE_LOCATION(tr)
  ;; if EXPR_P(tr) use EXPR_LOCATION(tr)
  ;; otherwise no location
  :doc #{$INFORM_AT_TREE give a notice at location of tree $TR with message $MSG}#
  #{ inform((($tr && DECL_P($tr))? DECL_SOURCE_LOCATION($tr)
	    : ($tr && EXPR_P($tr)) ? EXPR_LOCATION($tr) : UNKNOWN_LOCATION), 
  $msg );
  }# )

(defprimitive warning_at_tree (:tree tr :cstring msg) :void
  ;; if DECL_P(tr) use DECL_SOURCE_LOCATION(tr)
  ;; if EXPR_P(tr) use EXPR_LOCATION(tr)
  ;; otherwise no location
  :doc #{$WARNING_AT_TREE give a warning at location of tree $TR with message $MSG}#
  #{ warning_at( (($tr && DECL_P($tr))? DECL_SOURCE_LOCATION($tr)
		 : ($tr && EXPR_P($tr)) ? EXPR_LOCATION($tr) : UNKNOWN_LOCATION), 
		 0,
		 $msg);
  }# )

(defprimitive warning_at_tree_decl_with_number
  (:tree trdecl :cstring msg :long num) :void
  :doc #{$WARNING_AT_TREE_DECL_WITH_NUMBER give a warning with declaration of tree $TRDECL message $MSG number $NUM}#
  #{ warning (0, "MELT warning %s at %q+D - #%ld", $MSG, ($TRDECL), ($NUM));
  }# )

(defprimitive tree_type (:tree tr) :tree
  :doc #{$TREE_TYPE gives the type of tree $TR}#
  #{(($TR) ? TREE_TYPE($TR) : (tree) NULL)}#)

(defprimitive tree_uid (:tree tr) :long
  :doc #{$TREE_UID gives the uid of tree $TR}#
  #{(($TR) ? (long) DECL_UID($TR) : 0L)}#)

(defprimitive tree_chain_prepend (:tree purpose value chain) :tree
	:doc #{Create a new TREE_LIST node with $PURPOSE and $VALUE trees
	and chain it at the begining of $CHAIN. Returns the newly created
	chain.}#
	#{ /* tree_chain_prepend */
		tree_cons ($PURPOSE, $VALUE, $CHAIN)
	}#)

(defprimitive tree_chain_append (:tree purpose value chain) :tree
	:doc #{Create a new TREE_LIST node with $PURPOSE and $VALUE trees
	and chain it at the end of $CHAIN. Returns the newly created
	chain (different from $CHAIN if $CHAIN is NULL_TREE).}#
	#{ /* tree_chain_append */
		chainon ($CHAIN, tree_cons ($PURPOSE, $VALUE, NULL_TREE))
	}#)

(defprimitive tree_chain_join (:tree chain1 chain2) :tree
	:doc #{Append $CHAIN2 to $CHAIN1 and returns the newly created
	chain (different from $CHAIN1 if $CHAIN1 is NULL_TREE).}#
	#{ /* tree_chain_join */
		chainon ($CHAIN1, $CHAIN2)
	}#)

(defprimitive build_identifier_tree (name) :tree
	:doc #{Create and returns a new IDENTIFIER_NODE tree whose
	name is $NAME.}#
	#{ /* build_identifier_tree */
		get_identifier (melt_string_str ((melt_ptr_t) $NAME))
	}#)

(defprimitive build_string_tree (string_value) :tree
	:doc #{Create and returns a new STRING_CST tree whose
	value is $STRING_VALUE.}#
	#{ /* build_string_tree */
		build_string (strlen (melt_string_str ((melt_ptr_t) $STRING_VALUE)),
				     melt_string_str ((melt_ptr_t) $STRING_VALUE))
	}#)


(defprimitive build_int_tree (int_value) :tree
	:doc #{Create and returns a new INTEGER_CST tree whose
	value is $INT_VALUE and type is the default language
	integer type.}#
	#{
		build_int_cst (integer_type_node, (int)melt_get_int ($INT_VALUE))
	}#
)


;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;
;; pattern (tree_function_decl_named <funame> <initialtree>) match a tree for a function
;; declaration
(defcmatcher tree_function_decl_named 
  (:tree tr) 				;matched
  ;; output 
  (:cstring funame
   :tree trresult
   )
  treefunam				;state symbol
  :doc #{$TREE_FUNCTION_DECL_NAMED match a function declaration extracting its name $FUNAME and result tree decl $TRRESULT}#
  ;; test expansion
  #{ /*  tree_function_decl_named $TREEFUNAM ? */ (($TR) && TREE_CODE($TR) == FUNCTION_DECL) }#
  ;; fill expansion
  #{/*  tree_function_decl_named $TREEFUNAM ! */ 
   $FUNAME = NULL; 
   $TRRESULT = NULL; 
   if (DECL_NAME($tr))
     $FUNAME = IDENTIFIER_POINTER(DECL_NAME($TR)); 
   $TRRESULT = DECL_RESULT($TR); 
  }#
)

;; match a function decl of a given name
(defcmatcher tree_function_decl_of_name 
  (:tree tr :cstring fname) 				;matched
  ;; output 
  (:tree tfunname
   :tree ttrresult
   )
  treefunofnam				;state symbol
  :doc #{$TREE_FUNCTION_DECL_OF_NAME match a function declaration tree $TR for function named $FNAME extracting the tree name $TFUNAME and result tree $TTRRESULT}#
  ;; test expansion
  #{ /* tree_function_decl_of_name $TREEFUNOFNAM ?*/ (($TR) && TREE_CODE($TR) == FUNCTION_DECL && DECL_NAME($TR) 
     && !strcmp($fname, IDENTIFIER_POINTER(DECL_NAME($TR)))) }#
  ;; fill expansion
  #{ /* tree_function_decl_of_name  $TREEFUNOFNAM ! */
   $TFUNNAME = DECL_NAME($TR);
   $TTRRESULT = DECL_RESULT($TR); 
  }#
)


(defcmatcher tree_function_decl 
  (:tree tr) 				;matched
  ;; output 
  (:tree tfuname
   :tree tresult
   )
  treefun				;state symbol
  :doc #{$TREE_FUNCTION_DECL match a function declaration tree, extracting the tree name $TFUNAME and the tree result $TRESULT.}#
  ;; test expansion
  #{ /* tree_function_decl $TREEFUN ?*/ (($TR) && TREE_CODE($TR) == FUNCTION_DECL) }#
  ;; fill expansion
  #{ /* tree_function_decl  $TREEFUN ! */
   $TFUNAME = DECL_NAME($TR);
   $TRESULT = DECL_RESULT($TR); 
  }#
)

;; pattern (tree_function_type <return type>) match a tree function type.
(defcmatcher tree_function_type
  (:tree tr)
  (:tree trtyp)
  tfunt
  :doc #{$TREE_FUNCTION_TYPE match a function type tree $TR extracting the result type tree $TRTYP}#
  ;; test expansion
  #{ /* tree_function_type $tfunt ? */ (($TR) && TREE_CODE($TR) == FUNCTION_TYPE) }#
  ;; fill expansion
  #{ /* tree_function_type $tfunt ! */
      $TRTYP = TREE_TYPE($TR);
  }#)

;; pattern (tree_method_type <return type>) match a tree method type.
(defcmatcher tree_method_type
  (:tree tr)
  (:tree trtyp)
  tmethoty
  :doc #{$TREE_FUNCTION_TYPE match a method type tree $TR extracting the result type tree $TRTYP}#
  ;; test expansion
  #{ /*  tree_method_type $TMETHOTY ? */ (($tr) && TREE_CODE($tr) == METHOD_TYPE) }#
  ;; fill expansion
  #{ /*  tree_method_type $TMETHOTY ! */
      $TRTYP = TREE_TYPE($tr);
  }#)

;;;;;;;;;;;;;;;;
(defcmatcher tree_of_type 
  (:tree tr)
  (:tree trtyp)
  treeoftype
  :doc #{$TREE_FUNCTION_TYPE match any non-null tree $TR extracting the type tree $TRTYP}#
  ;; test expansion
  #{ /* tree_of_type $treeoftype ?*/ ($TR) != NULL }#
  ;; fill expansion
  #{ /* tree_of_type $treeoftype !*/ $TRTYP = TREE_TYPE($tr); }#
)


;;;;;;;;;;;;;;;;
;; pattern for variables (tree_var_decl <type> <name> <uid>)
(defcmatcher tree_var_decl_named 
  (:tree tr)
  (:tree type :cstring varname :long uid)
  treevardnam				;statesym
  :doc #{$TREE_VAR_DECL_NAMED match a variable declartion tree $TR extracting its type tree $TYPE, its $VARNAME and its $UID}#
  ;; test expansion
  #{/* tree_var_decl_named $TREEVARDNAM ?*/ (($TR) && TREE_CODE($TR) == VAR_DECL) }#
  ;; fill expansion
  #{/* tree_var_decl_named $TREEVARDNAM !*/
   $VARNAME =NULL;
   $TYPE = TREE_TYPE($TR);
   $UID = DECL_UID($TR);
   if (DECL_NAME($TR))
     $VARNAME = IDENTIFIER_POINTER(DECL_NAME($TR));
   }# )

;; pattern for variables (tree_var_decl <type> <name> <uid>)
(defcmatcher tree_var_decl 
  (:tree tr)
  (:tree ttype tname :long uid)
  treevard				;statesym
  :doc #{$TREE_VAR_DECL match a variable declaration tree $TR extracting its type tree $TTYPE, its name tree $TNAME and its $UID}#
  ;; test expansion
  #{/* tree_var_decl $TREEVARD ?*/ (($TR) && TREE_CODE($TR) == VAR_DECL) }#
  ;; fill expansion
  #{/* tree_var_decl $TREEVARD !*/
   $TTYPE = TREE_TYPE($TR);
   $UID = DECL_UID($TR);
   $TNAME = DECL_NAME($TR);
   }# )

;;;;;;;;
;; pattern for a var_decl of given name
	   
(defcmatcher tree_var_decl_of_name 
  (:tree tr :cstring varname)
  (:tree ttype)
  treevarn				;statesym
  :doc #{$TREE_VAR_DECL match a variable declaration tree $TR of name $VARNAME extracting its type tree $TTYPE}#
  ;; test expansion
  #{ /* tree_var_decl_of_name $TREEVARN ?*/ (($TR) && TREE_CODE($TR) == VAR_DECL && DECL_NAME($TR) 
      && !strcmp($varname, IDENTIFIER_POINTER(DECL_NAME($TR)))) }#
  ;; fill expansion
  #{ /* tree_var_decl_of_name $TREEVARN !*/ 
   $TTYPE = TREE_TYPE($TR);
  }# )

;;;;;;;;;;;;;;;;
;; pattern for constants (tree_const_decl <type> <name> <uid>)
(defcmatcher tree_const_decl 
  (:tree tr)
  (:tree ttype :cstring constname :long uid)
  treeconstd				;statesym
  :doc #{$TREE_CONST_DECL match a const declaration tree $TR extracting its type tree $TTYPE, its name $CONSTNAME, its $UID}#
  ;; test expansion
  #{/* tree_const_decl $TREECONSTD ?*/ (($TR) && TREE_CODE($TR) == CONST_DECL) }#
  ;; fill expansion
  #{/* tree_const_decl $TREECONSTD !*/
   $CONSTNAME =NULL;
   $TTYPE = TREE_TYPE($TR);
   $UID = DECL_UID($TR);
   if (DECL_NAME($TR))
     $CONSTNAME = IDENTIFIER_POINTER(DECL_NAME($TR));
   }# )

;;;;;;;;
;; pattern for a const_decl of given name
	   
(defcmatcher tree_const_decl_of_name 
  (:tree tr :cstring constname)
  (:tree ttype)
  treeconstn				;statesym
  :doc #{$TREE_CONST_DECL_OF_NAME match a const declaration tree $TR of name $CONSTNAME extracting its type tree $TTYPE}#
  ;; test expansion
  #{ /* tree_const_decl_of_name $TREECONSTN ?*/ (($TR) && TREE_CODE($TR) == CONST_DECL && DECL_NAME($TR) 
      && !strcmp($constname, IDENTIFIER_POINTER(DECL_NAME($TR)))) }#
  ;; fill expansion
  #{ /* tree_const_decl_of_name $TREECONSTN !*/
   $TTYPE = TREE_TYPE($TR); }# )

;; pattern for constant declaration  (tree_const_decl_named <type> <name> <uid>)
(defcmatcher tree_const_decl_named 
  (:tree tr)
  (:tree ttype :cstring constname :long uid)
  treeconstnam				;statesym
  :doc #{$TREE_CONST_DECL_NAMED match a const declaration tree $TR extracting its type $TTYPE, its name $CONSTNAME its $UID}#
  ;; test expansion
  #{/* tree_const_decl_named $TREECONSTNAM ?*/ (($TR) && TREE_CODE($TR) == CONST_DECL) }#
  ;; fill expansion
  #{/* tree_const_decl_named $TREECONSTNAM !*/
   $CONSTNAME = NULL;
   $TTYPE = TREE_TYPE($TR);
   $UID = DECL_UID($TR);
   if (DECL_NAME($TR))
     $CONSTNAME = IDENTIFIER_POINTER(DECL_NAME($TR));
   }# )


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; pattern for parameters (tree_parm_decl <type> <name> <uid>)
(defcmatcher tree_parm_decl_named 
  (:tree tr)
  (:tree type :cstring parmname :long uid)
  treeparmdcnam				;statesym
  :doc #{$TREE_PARM_DECL_NAMED match a parm declaration tree $TR extracting its type $TTYPE, its name $PARMNAME its $UID}#
  ;; test expansion
  #{/* tree_parm_decl_named $TREEPARMDCNAM ?*/ (($TR) && TREE_CODE($TR) == PARM_DECL) }#
  ;; fill expansion
  #{/* tree_parm_decl_named $TREEPARMDCNAM !*/
   $PARMNAME =NULL;
   $TYPE = DECL_ARG_TYPE($TR);
   $UID = DECL_UID($TR);
   if (DECL_NAME($TR))
     $PARMNAME = IDENTIFIER_POINTER(DECL_NAME($TR));
   }# )

;; pattern for a parm_decl of given name
(defcmatcher tree_parm_decl_of_name 
  (:tree tr :cstring parmname)
  (:tree type)
  treeparmofnam				;statesym
  :doc #{$TREE_PARM_DECL_OF_NAME match a parm declaration tree $TR named $PARMNAME extracting its $TYPE}#
  ;; test expansion
  #{ /* tree_parm_decl_of_name $TREEPARMOFNAM ?*/ (($TR) && TREE_CODE($TR) == PARM_DECL && DECL_NAME($TR) 
      && !strcmp($PARMNAME, IDENTIFIER_POINTER(DECL_NAME($TR)))) }#
  ;; fill expansion
  #{ /* tree_parm_decl_of_name $TREEPARMOFNAM !*/ 
   $TYPE = DECL_ARG_TYPE($TR); }# )


;; pattern for a parm_decl
(defcmatcher tree_parm_decl
  (:tree tr)
  (:tree trargtype trdeclnam)
  treeparmde				;statesym
  :doc #{$TREE_PARM_DECL_OF_NAME match a parm declaration tree $TR extracting its $TRARGTYPE and decl name tree $TRDECLNAME}#
  ;; test expansion
  #{ /* tree_parm_decl $TREEPARMDE ?*/ (($TR) && TREE_CODE($TR) == PARM_DECL) }#
  ;; fill expansion
  #{ /* tree_parm_decl $TREEPARMDE !*/ 
   $TRARGTYPE = DECL_ARG_TYPE($TR);
   $TRDECLNAM = DECL_NAME($TR); }# )


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; pattern for results (tree_result_decl <type> <name> <uid>)
(defcmatcher tree_result_decl_named
  (:tree tr)
  (:tree type :cstring name :long uid)
  treeparmd				;statesym
  :doc #{$TREE_RESULT_DECL_NAMED match a result declaration tree $TR extracting its $TYPE, $NAME, $UID}#
  ;; test expansion
  #{/* tree_result_decl_named $TREEPARMD ?*/ (($TR) && TREE_CODE($TR) == RESULT_DECL) }#
  ;; fill expansion
  #{/* tree_result_decl_named $TREEPARMD !*/
   $NAME =NULL;
   $TYPE = TREE_TYPE($TR);
   $UID = DECL_UID($TR);
   if (DECL_NAME($TR))
     $NAME = IDENTIFIER_POINTER(DECL_NAME($TR));
   }# )


(defcmatcher tree_result_decl
  (:tree tr)
  (:tree tnam ttyp)
  treeresd				;statesym
  :doc #{$TREE_RESULT_DECL match a result declaration $TR extracting its tree $TNAM and $TTYP}#
  ;; test expansion
  #{ /* tree_result_decl $TREERESD ?*/ (($TR) && TREE_CODE($TR) == RESULT_DECL) }#
  ;; fill expansion
  #{ /* tree_result_decl $TREERESD !*/ 
   $TNAM = DECL_NAME($TR);
   $TTYP = TREE_TYPE($TR); 
  }# )

;; pattern for a parm_decl of given name
(defcmatcher tree_result_decl_of_name 
  (:tree tr :cstring name)
  (:tree ttyp)
  treeparmn				;statesym
  :doc #{$TREE_RESULT_DECL_OF_NAME match a result declaration $TR named $NAME extracting its $TTYP}#
  ;; test expansion
  #{ /* tree_result_decl_of_name $TREEPARMN ?*/ (($TR) && TREE_CODE($TR) == RESULT_DECL && DECL_NAME($TR) 
      && !strcmp($NAME, IDENTIFIER_POINTER(DECL_NAME($TR)))) }#
  ;; fill expansion
  #{ /* tree_result_decl_of_name $TREEPARMN !*/ 
   $TTYP = TREE_TYPE($TR); }# )



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; pattern for defined types (tree_type_decl <type> <name> <uid>)
(defcmatcher tree_type_decl 
  (:tree tr)
  (:tree type :cstring name :long uid)
  treeparmd				;statesym
  :doc #{$TREE_TYPE_DECL match a tree type decl $TR extracting its $TYPE, $NAME, $UID}#
  ;; test expansion
  #{/* tree_type_decl $TREEPARMD ?*/ (($TR) && TREE_CODE($TR) == TYPE_DECL) }#
  ;; fill expansion
  #{/* tree_type_decl $TREEPARMD !*/
   $NAME =NULL;
   $TYPE = TREE_TYPE($TR);
   $UID = DECL_UID($TR);
   if (DECL_NAME($TR))
     $NAME = IDENTIFIER_POINTER(DECL_NAME($TR));
   }# )

;; pattern for a typr_decl of given name
(defcmatcher tree_type_decl_named 
  (:tree tr :cstring name)
  (:tree type)
  treetypn				;statesym
  :doc #{$TREE_TYPE_DECL match a tree type decl $TR for a type named $NAME extracting its $TYPE}#
  ;; test expansion
  #{ /* tree_type_decl_named $TREETYPN ?*/ (($TR) && TREE_CODE($TR) == TYPE_DECL && DECL_NAME($TR) 
      && !strcmp($NAME, IDENTIFIER_POINTER(DECL_NAME($TR)))) }#
  ;; fill expansion
  #{ /* tree_type_decl_named $TREETYPN !*/ 
   $TYPE = TREE_TYPE($TR);
  }# )



;;;;;;;;;;;;;;;;
;; pattern tree_array_ref matches an array reference with array and index
(defcmatcher tree_array_ref
  (:tree tr)				;input
  (:tree trarr trindex)
  treearrayref			 ;statesym
  :doc #{$TREE_ARRAY_REF match a tree array reference extracting array $TRARR and index $TRINDEX}#
  ;; test
  #{ /* tree_array_ref $TREEARRAYREF ?*/ (($TR) && TREE_CODE($TR) == ARRAY_REF) }#
  ;; fill
  #{ /* tree_array_ref $TREEARRAYREF !*/ 
    $TRARR = TREE_OPERAND ($TR, 0);
    $TRINDEX = TREE_OPERAND ($TR, 1);
  }#)

;; pattern tree_array_ref_full
(defcmatcher  tree_array_ref_full
  (:tree tr)				;input
  (:tree trarr trindex trmin trsize)
  treearrayreffull			 ;statesym
  :doc #{$TREE_ARRAY_REF_FULL match a tree array reference extracting array $TRARR and index $TRINDEX minimum $TRMIN and size $TRSIZE}#
  ;; test
  #{ /* tree_array_ref_full $TREEARRAYREFFULL ?*/ (($TR) && TREE_CODE($TR) == ARRAY_REF) }#
  ;; fill
  #{ /* tree_array_ref_full $TREEARRAYREFFULL !*/ 
    int $TREEARRAYREFFULL#_len = TREE_OPERAND_LENGTH($TR);
    $TRARR = TREE_OPERAND ($TR, 0);
    $TRINDEX = TREE_OPERAND ($TR, 1);
    $TRMIN = ($TREEARRAYREFFULL#_len >= 3) ? TREE_OPERAND ($TR, 2) : (NULL_TREE);
    $TRSIZE = ($TREEARRAYREFFULL#_len >= 4) ? TREE_OPERAND ($TR, 3) : (NULL_TREE);
  }#)

;;;;;;;;;;;;;;;;
;; pattern tree_component_ref matches an component reference with component and index
(defcmatcher tree_component_ref
  (:tree tr)				;input
  ;; traggr is the aggregate (ie a struct or union)
  (:tree traggr trfield)		;output
  treecomponentref			 ;statesym
  :doc #{$TREE_COMPONENT_REF match a component reference tree $TR extracting aggregate $TRAGGR and field $TRFIELD}#
  ;; test
  #{ /* tree_component_ref $TREECOMPONENTREF ?*/ (($TR) && TREE_CODE($TR) == COMPONENT_REF) }#
  ;; fill
  #{ /* tree_component_ref $TREECOMPONENTREF !*/ 
    $TRAGGR = TREE_OPERAND ($TR, 0);
    $TRFIELD = TREE_OPERAND ($TR, 1);
  }#)

(defcmatcher tree_component_ref_full
  (:tree tr)				;input
  ;; traggr is the aggregate (ie a struct or union)
  (:tree traggr trfield troff)
  treecomponentreffull			 ;statesym
  :doc #{$TREE_COMPONENT_REF_FULL match a component reference tree $TR extracting aggregate $TRAGGR and field $TRFIELD and offset $TROFF}#
  ;; test
  #{ /* tree_component_ref_full $TREECOMPONENTREFFULL ?*/ (($TR) && TREE_CODE($TR) == COMPONENT_REF) }#
  ;; fill
  #{ /* tree_component_ref_full $TREECOMPONENTREFFULL !*/ 
    int $TREECOMPONENTREFFULL#_len = TREE_OPERAND_LENGTH($TR);
    $TRAGGR = TREE_OPERAND ($TR, 0);
    $TRFIELD = TREE_OPERAND ($TR, 1);
    $TROFF = ($TREECOMPONENTREFFULL#_len > 2) ? TREE_OPERAND ($TR, 2) : NULL_TREE;
  }#)

(defcmatcher tree_component_ref_typed
  (:tree tr)
  (:tree type
   :tree traggr
   :tree trfield)
  treecr
  :doc #{$TREE_COMPONENT_REF_TYPED match a component reference tree $TR extracting the $TYPE, aggregate $TRAGGR, field $TRFIELD }#

  #{ /*  tree_component_ref_typed $TREECR ? */
       (($tr) && TREE_CODE ($tr) == COMPONENT_REF)
  }#

  #{/*  tree_component_ref_typed $TREECR ! */
       $TYPE = TREE_TYPE ($tr);
       $TRAGGR = TREE_OPERAND ($tr, 0);
       $TRFIELD = TREE_OPERAND ($tr, 1);
  }#)

;; pattern tree_mem_ref matches a memory reference with pointer and offset
(defcmatcher tree_mem_ref
  (:tree tr)				;input
  (:tree trptr troff)
  treememref			 ;statesym
  :doc #{$TREE_MEM_REF match a memory reference tree extracing pointer $TRPTR and offset $TROFF}#
  ;; test
  #{ /* tree_mem_ref $TREEMEMREF ?*/ (($TR) && TREE_CODE($TR) == MEM_REF) }#
  ;; fill
  #{ /* tree_mem_ref $TREEMEMREF !*/ 
    $TRPTR = TREE_OPERAND ($TR, 0);
    $TROFF = TREE_OPERAND ($TR, 1);
  }#)

;;;;;;;;;;;;;;;;
;; pattern tree_block matches a block
(defcmatcher tree_block 
  (:tree tr)
  (					;output
   :tree trvars  trsubblocks 	 
   )
  treeblock				;statesym
  :doc #{$TREE_BLOCK match a tree block extracting tree variables $TRVARS and subblocks $TRSUBBLOCKS}#
  ;; test expander
   #{/*tree_block $TREEBLOCK ?*/ (($TR) && TREE_CODE($TR) == BLOCK)}#
  ;; fill expander
   #{ /*tree_block $TREEBLOCK !*/
   $TRVARS = BLOCK_VARS($TR);
   $TRSUBBLOCKS = BLOCK_SUBBLOCKS($TR);
   }# )

;;;;;;;;;;;;;;;;
;; pattern tree_offset_type is for pointers relative to object
(defcmatcher tree_offset_type
 (:tree tr)
 (:tree trtype trbasetype)
 treeoffsettype				;statesym
  :doc #{$TREE_OFFSET_TYPE match offset type tree $TR extracting type $TRTYPE and basetype $TRBASETYPE}#
 ;; expander
 #{/*tree_offset_type $TREEOFFSETTYPE ?*/ (($TR) && TREE_CODE($TR) == OFFSET_TYPE) }#
 ;; filler
 #{/*tree_offset_type $TREEOFFSETTYPE !*/ $TRTYPE = TREE_TYPE($TR);
   $TRBASETYPE = TYPE_OFFSET_BASETYPE ($TR);
 }#)


;;;;;;;;
;;; pattern tree_identifier matches any identifier node
(defcmatcher tree_identifier
  (:tree tr)
  (:cstring name)
  treeident			;statesym
  :doc #{$TREE_IDENTIFIER match an identifier tree $TR extracting its $NAME}#
  #{ /*tree_identifier  $TREEIDENT ?*/ $TR 
         && TREE_CODE ($TR) == IDENTIFIER_NODE }#
  #{ /*tree_identifier $TREEIDENT !*/ $NAME = (const char*) IDENTIFIER_POINTER ($TR); 
}#
)

;;; pattern tree_list matches any tree list node
(defcmatcher tree_list
  (:tree tr)
  (:tree trvalue trpurpose trchain)
  treelist
  :doc #{$TREE_LIST match a tree list node extracting $TRVALUE $TRPURPOSE $TRCHAIN}#
  #{ /* tree_list $TREELIST ?*/ $TR && TREE_CODE ($TR) == TREE_LIST }#
  #{ /* tree_list $TREELIST !*/ 
    $TRVALUE = TREE_VALUE ($TR);
    $TRPURPOSE = TREE_PURPOSE ($TR);
    $TRCHAIN = TREE_CHAIN ($TR);
  }#
)

;;; pattern tree_vec matches any tree vector node
(defcmatcher tree_vec
  (:tree tr)
  (:long len :tree trchain)
  treevec
  :doc #{$TREE_VEC match a tree vector node extracting $LEN and $TRCHAIN}#
  #{ /* tree_vec $TREEVEC ?*/ $TR && TREE_CODE ($TR) == TREE_VEC }#
  #{ /* tree_vec $TREEVEC !*/ 
  $LEN = TREE_VEC_LENGTH ($TR);
  $TRCHAIN = TREE_CHAIN ($TR);
  }#
)

;;;;;;;;;;;;;;;;
;;; pattern tree_decl matches any declaration
(defcmatcher tree_decl 
  (:tree tr)
  (					;output
   :tree trname
   :cstring name
   :long uid
   )
  treedecl				;statesym
  :doc #{$TREE_DECL match any declaration extracting $TRANME $NAME $UID}#
  ;; test expander
  #{/* tree_decl $TREEDECL ? */ (($tr) && DECL_P($tr))}#
  ;; fill expander
  #{/* tree_decl $TREEDECL ! */ 
   tree  $treedecl#_name = DECL_NAME($tr);
   $TRNAME = $treedecl#_name;
   $NAME = ($treedecl#_name) ? IDENTIFIER_POINTER($treedecl#_name) : NULL;
   $UID = DECL_UID($tr);
   }# )

;; pattern tree_decl_at_source_location matches a declaration tree with a
;; known location
(defcmatcher tree_decl_at_source_location 
  (:tree tr)
  (:value filepathv
   :long line
   :long col)
  treedeclatloc				;statesym
  :doc #{$TREE_DECL_AT_SOURCE_LOCATION match any declaration with some
  known source location, extracting the cached $FILEPATHV string value and the
  $LINE and $COL info.}#
   ;; test expander
  #{/* tree_decl_at_source_location $TREEDECLATLOC ? */ (($TR)
      && DECL_P($TR) && DECL_SOURCE_LOCATION($TR) != UNKNOWN_LOCATION)}#
   ;; test filler
  #{/* tree_decl_at_source_location $TREEDECLATLOC ! */ {
     source_location $TREEDECLATLOC#_sloc = DECL_SOURCE_LOCATION($tr);
     $FILEPATHV =
         meltgc_cached_string_path_of_source_location ($TREEDECLATLOC#_sloc);
     $LINE = LOCATION_LINE ($TREEDECLATLOC#_sloc);
     $COL = LOCATION_COLUMN ($TREEDECLATLOC#_sloc);
   } /* end tree_decl_at_source_location $TREEDECLATLOC */ }#)


;; pattern tree_decl_at_source_location matches a declaration tree with a
;; known location
(defcmatcher tree_expr_at_source_location 
  (:tree tr)
  (:value filepathv
   :long line
   :long col)
  treeexpratloc				;statesym
  :doc #{$TREE_EXPR_AT_SOURCE_LOCATION match any expression with some
  known source location, extracting the cached $FILEPATHV string value and the
  $LINE and $COL info.}#
   ;; test expander
  #{/* tree_expr_at_source_location $TREEEXPRATLOC ? */ (($TR)
      && EXPR_P($TR) && EXPR_LOCATION($TR) != UNKNOWN_LOCATION)}#
   ;; test filler
  #{/* tree_expr_at_source_location $TREEEXPRATLOC ! */ {
     source_location $TREEEXPRATLOC#_sloc = EXPR_LOCATION($tr);
     $FILEPATHV =
         meltgc_cached_string_path_of_source_location ($TREEEXPRATLOC#_sloc);
     $LINE = LOCATION_LINE ($TREEEXPRATLOC#_sloc);
     $COL = LOCATION_COLUMN ($TREEEXPRATLOC#_sloc);
   } /* end tree_expr_at_source_location $TREEEXPRATLOC */ }#)



;; pattern tree_void_type
(defcmatcher tree_void_type
  (:tree tr)
  (:tree type)
  treevt
  :doc #{$TREE_VOID_TYPE match a void type $TR extracting its type $TYPE}#

  #{ /* tree_void_type $TREEVT ? */
       (($tr) && TREE_CODE ($tr) == VOID_TYPE)
  }#

  #{/* tree_void_type $TREEVT ! */
       $type = TYPE_NAME ($tr);
  }#)

;;;;;;;;;;;;;;;;
;;; pattern tree_integer_type
(defcmatcher tree_integer_type 
  (:tree tr)
  (					;output
   :tree type
   :value minbig maxbig 
   :tree size
   )
  treeinty				;statesym
  :doc #{$TREE_INTEGER_TYPE match an integer type tree $TR extracting its $TYPE and big minimal $MINBIG and maximal $MAXBIG values and tree size $SIZE}#
  ;; test expander
   #{ /* tree_integer_type $treeinty ?*/ (($tr) && TREE_CODE($tr) == INTEGER_TYPE) }#
  ;; fill expander
   #{ /* tree_integer_type $treeinty !*/
      mpz_t $treeinty#_minz;
      mpz_t $treeinty#_maxz;

      $type = TYPE_NAME($tr);
      $size = TYPE_SIZE($tr);

      mpz_init ($treeinty#_minz);
      mpz_init ($treeinty#_maxz);
      get_type_static_bounds($tr, $treeinty#_minz, $treeinty#_maxz);
      $minbig = meltgc_new_mixbigint_mpz((meltobject_ptr_t) MELT_PREDEF (DISCR_MIXED_BIGINT), 
					 NULL, 
					 $treeinty#_minz);
      $maxbig =  meltgc_new_mixbigint_mpz((meltobject_ptr_t) MELT_PREDEF (DISCR_MIXED_BIGINT), 
					 NULL, 
					 $treeinty#_maxz);
      mpz_clear ($treeinty#_minz);
      mpz_clear ($treeinty#_maxz);
    }#)

;;;;;;;;;;;;;;;;
(defcmatcher tree_enumeral_type
  (:tree tr)
  (:tree ttype
   :tree tmin tmax
   :tree tsize
   :tree tvalues)
  treeenumtype
  :doc #{$TREE_ENUMERAL_TYPE match a tree $TR enumeral extracting $TTYPE $TMIN $TMAX $TSIZE $TVALUES}#
  ;; test
  #{/* tree_enumeral_type $TREEENUMTYPE ?*/ (($TR) && TREE_CODE($TR) == ENUMERAL_TYPE) }#
  ;; fill
  #{/* tree_enumeral_type $TREEENUMTYPE !*/
      $TTYPE = TYPE_NAME($TR);
      $TSIZE = TYPE_SIZE($TR);
      $TMIN = TYPE_MIN_VALUE ($TR);
      $TMAX = TYPE_MAX_VALUE ($TR);
      $TVALUES = TYPE_VALUES ($TR); }#
)

;;;;;;;;;;;;;;;;;
(defcmatcher tree_boolean_type
  (:tree tr)
  (:tree ttype
   :tree tmin tmax
   :tree tsize
  )
  treebooltype
  :doc #{$TREE_BOOLEAN_TYPE match a boolean type tree $TR extracting $TTYPE $TMIN $TMAX $TSIZE}#
  ;; test
  #{/* tree_boolean_type $TREEBOOLTYPE ?*/ (($TR) && TREE_CODE($TR) == BOOLEAN_TYPE) }#
  ;; fill
  #{/* tree_boolean_type $TREEBOOLTYPE !*/
      $TTYPE = TYPE_NAME($TR);
      $TSIZE = TYPE_SIZE($TR);
      $TMIN = TYPE_MIN_VALUE ($TR);
      $TMAX = TYPE_MAX_VALUE ($TR);}#
)


;;;;;;;;;;;;;;;;
;;; pattern tree_integer_type_bounded, the bounds are trees
(defcmatcher tree_integer_type_bounded
  (:tree tr)
  (					;output
   :tree ttype
   :tree tmin tmax
   :tree tsize
   )
  treeintybnd				;statesym
  :doc #{$TREE_INTEGER_TYPE_BOUNDED match an integer type tree $TR  extracting $TTYPE $TMIN $TMAX $TSIZE}#
  ;; test expander
   #{ /* tree_integer_type_bounded $TREEINTYBND ?*/ (($TR) && TREE_CODE($TR) == INTEGER_TYPE) }#
  ;; fill expander
   #{ /* tree_integer_type_bounded $TREEINTYBND !*/
      $TTYPE = TYPE_NAME($TR);
      $TSIZE = TYPE_SIZE($TR);
      $TMIN = TYPE_MIN_VALUE ($TR);
      $TMAX = TYPE_MAX_VALUE ($TR);
    }#)


;;;; pattern for fixed point type

(defcmatcher tree_fixed_point_type
  (:tree tr)
  (					;output
   :tree ttype
   :tree tmin tmax
   :tree tsize
   )
  treefixpt				;statesym
  :doc #{$TREE_FIXED_POINT_TYPE match an fixed point type tree $TR  extracting $TTYPE $TMIN $TMAX $TSIZE}#
  ;; test expander
   #{ /* tree_fixed_point_type $TREEFIXPT ?*/ (($TR) && TREE_CODE($TR) == FIXED_POINT_TYPE) }#
  ;; fill expander
   #{ /* tree_fixed_point_type $TREEFIXPT !*/
      $TTYPE = TYPE_NAME($TR);
      $TSIZE = TYPE_SIZE($TR);
      $TMIN = TYPE_MIN_VALUE ($TR);
      $TMAX = TYPE_MAX_VALUE ($TR);
    }#)

;;;; pattern for the type of nullptr
(defcmatcher tree_nullptr_type 
  (:tree tr)
  ()
  treenullptr
  :doc #{$TREE_NULLPTR_TYPE match an nullptr type tree $TR }#
  #{ /* tree_nullptr_type $TREENULLPTR ?*/ (($TR) && TREE_CODE($TR) == NULLPTR_TYPE) }#
  #{ /* tree_nullptr_type $TREENULLPTR !*/ }#
)


;; Pattern tree_type_declaration. 
(defcmatcher tree_type_declaration
  (:tree tr)
  (:tree name)
  titd
  :doc #{$TREE_TYPE_DECLARATION match a type decl tree $TR extracting the declared name tree $NAME}#
  #{ /* tree_type_declaration $TITD ? */
      (($TR) && TREE_CODE($TR) == TYPE_DECL)
  }#

  #{ /* tree_type_declaration $TITD ! */
      $NAME = DECL_NAME($TR);
  }#)

;;; pattern tree_real_type. It matches any real type.
;;; asked by Marie Krumpe.
(defcmatcher tree_real_type 
  (:tree tr)
  (					;output
   :tree name
   :tree size
  )
  tranyfloaty
  :doc #{$TREE_REAL_TYPE match any real type tree $TR extracting its $NAME & $SIZE trees }#

  #{ /*  tree_real_type $tranyfloaty ? */ 
      (($tr) && TREE_CODE($tr) == REAL_TYPE)
  }#

  #{ /*  tree_real_type $tranyfloaty ! */
      $NAME = TYPE_NAME($tr);
      $SIZE = TYPE_SIZE($tr);
  }#
)

;;; pattern tree_complex_type. It matches any complex type.
(defcmatcher tree_complex_type 
  (:tree tr)
  (					;output
   :tree name
   :tree size
  )
  tranycplxy
  :doc #{$TREE_COMPLEX_TYPE match any complex type tree $TR extracting its $NAME & $SIZE trees }#

  #{ /* tree_complex_type $TRANYCPLXY ? */ 
      (($tr) && TREE_CODE($tr) == COMPLEX_TYPE)
  }#

  #{ /* tree_complex_type $TRANYCPLXY ! */
      $NAME = TYPE_NAME($tr);
      $SIZE = TYPE_SIZE($tr);
  }#
)

;;; pattern tree_integer_cst
(defcmatcher tree_integer_cst
  (:tree tr)
  (					;output
   :long n )
  treeintk
  :doc #{ $TREE_INTEGER_CST match a constant integer tree $TR extracting the constant $N. Might behave strangely if the constant don't fit in a long.}#
  ;; test expander
  #{ /*tree_integer_cst $TREEINTK ?*/ (($TR) && TREE_CODE($TR) == INTEGER_CST 
		      && host_integerp($TR, 0)) }#
  ;; fill expander
  #{ /*tree_integer_cst $TREEINTK !*/ $N  = tree_low_cst(($TR), 0);
  }#  )


;;; pattern tree_real_cst
(defcmatcher tree_real_cst
  (:tree tr)
  (:value v)
  treerealc
  :doc #{ $TREE_REAL_CST match a constant real tree $TR extracting the constant into a value $V}#
  ;; test expander 
  #{ /* tree_real_cst $treerealc ?*/ (($tr) && TREE_CODE($tr) == REAL_CST) }#
  ;; fill expander
  #{ /* tree_real_cst treerealc! */
  $v = meltgc_new_real ((meltobject_ptr_t) MELT_PREDEF (DISCR_REAL), 
                       TREE_REAL_CST(($tr))); }#
)

(defcmatcher tree_string_cst
  (:tree tr)
  (:value v)
  treestringc
  :doc #{ $TREE_STRING_CST match a constant string tree $TR extracting its string into value $V}#
  ;; test expander
  #{   /* tree_string_cst $treestringc ? */
       (($tr) && TREE_CODE ($tr) == STRING_CST)
  }#
  ;; fill expander
  #{   /* tree_string_cst $treestringc ! */
       $v = meltgc_new_string_raw_len ((meltobject_ptr_t) MELT_PREDEF (DISCR_STRING),
				       TREE_STRING_POINTER ($tr),
				       TREE_STRING_LENGTH ($tr));
  }#)
       
;;; pattern for pointer types (or reference type)
(defcmatcher tree_pointer_type_p
  (:tree tr)
  (:tree typetr)
  treeisptrt
  :doc #{$TREE_POINTER_TYPE_P match a pointer type tree $TR and extract the pointed type $TYPETR}#
  ;; test
  #{ /*tree_pointer_type_p $treeisptrt ?*/ (($tr) && POINTER_TYPE_P(($tr))) }#
  ;; fill
  #{ /*tree_pointer_type_p $treeisptrt !*/ $typetr = TREE_TYPE($tr); }#
)

(defcmatcher tree_pointer_type
  (:tree tr)
  (:tree typetr)
  treeptrty
  :doc #{$TREE_POINTER_TYPE_P match or build a POINTER_TYPE tree $TR and extract the pointed type $TYPETR}#
  ;; test
  #{ /*  tree_pointer_type $TREEPTRTY ?*/ (($TR) && TREE_CODE($TR) == POINTER_TYPE) }#
  ;; fill
  #{ /* tree_pointer_type $TREEPTRTY !*/ $TYPETR = TREE_TYPE($TR); }#
  ;; operator
  #{ /* tree_pointer_type: */ build_pointer_type(($TYPETR)) }#
)

(defcmatcher tree_reference_type
  (:tree tr)
  (:tree typetr)
  treerefty
  :doc #{$TREE_REFERENCE_TYPE match a REFERENCE_TYPE tree $TR extracting the $TYPETR}#
  ;; test
  #{ /* tree_reference_type $TREEREFTY ?*/ (($TR) && TREE_CODE($TR) == REFERENCE_TYPE) }#
  ;; fill
  #{ /* tree_reference_type $TREEREFTY !*/ $TYPETR = TREE_TYPE($TR); }#
)


;;; pattern for indirect references
(defcmatcher tree_indirect_reference
  (:tree tr)
  (:tree type
   :tree reference)
  treeir
  :doc #{$TREE_INDIRECT_REFERENCE match an indirect ref tree $TR extracting the $TYPE and $REFERENCE subtrees}#
  #{ /* tree_indirect_reference $TREEIR ? */
       (($tr) && INDIRECT_REF_P ($tr))
  }#

  #{ /* tree_indirect_reference $TREEIR ! */
       $type = TREE_TYPE ($tr);
       $reference = TREE_OPERAND ($tr, 0);
  }#)

(defcmatcher tree_addr_expr
  (:tree tr)
  (:tree type
   :tree expr)
  treeae
  :doc #{$TREE_ADDR_EXPR match an ADDR_EXPR tree $TR extracting the $TYPE and $EXPR subtrees}#

  #{ /*  tree_addr_expr $TREEAE ?*/
       (($tr) && TREE_CODE ($tr) == ADDR_EXPR)
  }#

  #{ /*  tree_addr_expr $TREEAE !*/
       $TYPE = TREE_TYPE ($tr);
       $EXPR = TREE_OPERAND ($tr, 0);
  }#)


;;;;;;;;
(defcmatcher tree_record_type
  (:tree tr)
  (:tree name)
  treerectyp

  :doc #{$TREE_RECORD_TYPE match a record type tree $TR extracting its $NAME }#
  #{ /*  tree_record_type $TREERECTYP ? */
       (($TR) && TREE_CODE ($TR) == RECORD_TYPE)
  }#
  #{ /*  tree_record_type $TREERECTYP ! */
       $NAME = TYPE_NAME ($TR);
  }#)

(defcmatcher tree_record_type_with_fields
  (:tree tr)
  (:tree tname tfields)
  trectyfld
  :doc #{$TREE_RECORD_TYPE_WITH_FIELDS match a record type tree $TR extracting its $TNAME & $TFIELDS}#
  #{  /*  tree_record_type_with_fields $TRECTYFLD ? */
       (($TR) && TREE_CODE ($TR) == RECORD_TYPE)
  }#
  #{ /*  tree_record_type_with_fields $TRECTYFLD ! */
       $TNAME = TYPE_NAME ($TR);
       $TFIELDS = TYPE_FIELDS ($TR);
  }#)


;; qualified union
(defcmatcher tree_qual_union_type
  (:tree tr)
  (:tree type)
  treequunityp
  :doc #{$TREE_QUAL_UNION_TYPE match a qualified union type tree $TR extracting its $TYPE}#

  #{ /* tree_qual_union_type $TREEQUUNITYP ? */
       (($TR) && TREE_CODE ($TR) == QUAL_UNION_TYPE)
  }#
  #{ /* tree_qual_union_type  $TREEQUUNITYP ! */
       $TYPE = TYPE_NAME ($TR);
  }#)

(defcmatcher tree_qual_union_type_with_fields
  (:tree tr)
  (:tree type tfields)
  tquunityfld
  :doc #{$TREE_QUAL_UNION_TYPE_WITH_FIELDS match a qualified union type tree $TR extracting its $TYPE & $TFIELDS}#

  #{  /* tree_qual_union_type_with_fields $TQUUNITYFLD ? */
       (($TR) && TREE_CODE ($TR) == QUAL_UNION_TYPE)
  }#
  #{ /* tree_qual_union_type_with_fields $TQUUNITYFLD ! */
       $TYPE = TYPE_NAME ($TR);
       $TFIELDS = TYPE_FIELDS ($TR);
  }#)


(defcmatcher tree_array_type
  (:tree tr)
  (:tree telemtype tdomaintype)
  treearrtyp
  :doc #{$TREE_ARRAY_TYPE match an array type tree $TR extracting the elements tpe $TELEMTYPE and the domain type $TDOMAINTYPE}#
  #{ /* tree_array_type $TREEARRTYP ? */
  (($TR) && TREE_CODE ($TR) == ARRAY_TYPE)
  }#
  #{ /* tree_array_type $TREEARRTYP ! */
  $TELEMTYPE = TREE_TYPE ($TR);
  $TDOMAINTYPE = TYPE_DOMAIN ($TR);
  }#)


(defcmatcher tree_field_decl
  (:tree tr)
  (:tree name type)
  treefield
  :doc #{$TREE_FIELD_DECL match a field declaration tree $TR extracting $NAME & $TYPE}#
  #{ /*  tree_field_decl $TREEFIELD ? */
       (($TR) && TREE_CODE ($TR) == FIELD_DECL)
  }#
  #{ /*  tree_field_decl $TREEFIELD ! */
       $NAME = DECL_NAME ($TR);
       $TYPE = TREE_TYPE ($TR);
  }#)

;;;; matcher for pattern ssa_name
(defcmatcher tree_ssa_name 
  (:tree tr)
  (:tree tvar tvalu :long vers :gimple defstmt)
  treessa
  :doc #{$TREE_SSA_NAME match an SSA name tree $TR extracting the $TVAR $TVALUE $VERS and $DEFSTMT}#
  ;; test expander
  #{ /*  tree_ssa_name $TREESSA ? */ (($tr) && TREE_CODE($tr) == SSA_NAME) }#
  ;; fill expander
  #{ /*  tree_ssa_name $TREESSA ! */
   $tvar = SSA_NAME_VAR($tr);
   $tvalu = SSA_NAME_VALUE($tr);
   $vers = SSA_NAME_VERSION($tr);
   $defstmt = SSA_NAME_DEF_STMT($tr);
  }# )

;;;; simpler matcher for pattern ssa_name
(defcmatcher tree_simple_ssa_name 
  (:tree tr)
  (:tree tvar :long vers)
  treesssa
  :doc #{$TREE_SIMPLE_SSA_NAME match an SSA name tree $TR extracting the $TVAR and $VERS}#
  ;; test expander
  #{ /* tree_simple_ssa_name  $TREESSSA ? */ (($TR) && TREE_CODE($TR) == SSA_NAME) }#
  ;; fill expander
  #{ /* tree_simple_ssa_name  $TREESSSA ! */
   $tvar = SSA_NAME_VAR($tr);
   $vers = SSA_NAME_VERSION($tr);
  }# )



;; Iterator on function argument 
(defciterator foreach_argument_in_function_tree
  (:tree tr_fun)
  eachtrfun
  (:tree trarg)
  #{
      /* foreach_argument_in_function_tree $EACHTRFUN start */
      tree $EACHTRFUN#_tr = NULL;

      $TRARG = (tree) NULL;
      if ($TR_FUN && TREE_CODE($TR_FUN) == FUNCTION_TYPE)
      {
          function_args_iterator $EACHTRFUN#_args_iter;
          FOREACH_FUNCTION_ARGS($TR_FUN, $EACHTRFUN#_tr, $EACHTRFUN#_args_iter)
          {
              $TRARG = $EACHTRFUN#_tr;
   }#
              
   #{ /* ending  foreach_argument_in_function_tree $EACHTRFUN */
              $TRARG = (tree) NULL;
          } 
      }
      /* end foreach_argument_in_function_tree $EACHTRFUN */
   }#)



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; constant c-matchers for predefined tree nodes

;;; "char"
(defcmatcher tree_char_type_node (:tree tr) ()
 nodetr
 :doc #{$TREE_CHAR_TYPE_NODE matches or gives the constant char integer 
type node.}#
 #{ /* tree_char_type_node $NODETR ? */ $TR == char_type_node }#
 ()
 #{ /* tree_char_type_node : */ char_type_node }#)

;;; "signed char"
(defcmatcher tree_signed_char_type_node (:tree tr) ()
 nodetr
 :doc #{$TREE_SIGNED_CHAR_TYPE_NODE matches or gives the constant signed 
char integer type node.}#
 #{ /* tree_signed_char_type_node $NODETR ? */ $TR == signed_char_type_node }#
 ()
 #{ /* tree_signed_char_type_node : */ signed_char_type_node }#)

;;; "unsigned char"
(defcmatcher tree_unsigned_char_type_node (:tree tr) ()
 nodetr
 :doc #{$TREE_UNSIGNED_CHAR_TYPE_NODE matches or gives the constant unsigned 
char integer type node.}#
 #{ /* tree_unsigned_char_type_node $NODETR ? */ $TR == unsigned_char_type_node }#
 ()
 #{ /* tree_unsigned_char_type_node : */ unsigned_char_type_node }#)

;;; "short"
(defcmatcher tree_short_integer_type_node (:tree tr) ()
 nodetr
 :doc #{$TREE_SHORT_INTEGER_TYPE_NODE matches or gives the constant short integer 
type node.}#
 #{ /* tree_short_integer_type_node $NODETR ? */ $TR == short_integer_type_node }#
 ()
 #{ /* tree_short_integer_type_node : */ short_integer_type_node }#)

;;; "unsigned short"
(defcmatcher tree_short_unsigned_type_node (:tree tr) ()
 nodetr
 :doc #{$TREE_SHORT_UNSIGNED_TYPE_NODE matches or gives the constant short integer 
type node.}#
 #{ /* tree_short_unsigned_type_node $NODETR ? */ $TR == short_unsigned_type_node }#
 ()
 #{ /* tree_short_unsigned_type_node : */ short_unsigned_type_node }#)

;;; "int"
(defcmatcher tree_integer_type_node (:tree tr) ()
 nodetr
 :doc #{$TREE_INTEGER_TYPE_NODE matches or gives the constant  integer 
type node.}#
 #{ /* tree_integer_type_node $NODETR ? */ $TR == integer_type_node }#
 ()
 #{ /* tree_integer_type_node : */ integer_type_node }#)

;;; "unsigned"
(defcmatcher tree_unsigned_type_node (:tree tr) ()
 nodetr
 :doc #{$TREE_UNSIGNED_TYPE_NODE matches or gives the constant unsigned integer 
type node.}#
 #{ /* tree_unsigned_type_node $NODETR ? */ $TR == unsigned_type_node }#
 ()
 #{ /* tree_unsigned_type_node : */ unsigned_type_node }#)

;;; "long"
(defcmatcher tree_long_integer_type_node (:tree tr) ()
 nodetr
 :doc #{$TREE_LONG_INTEGER_TYPE_NODE matches or gives the constant long integer 
type node.}#
 #{ /* tree_long_integer_type_node $NODETR ? */ $TR == long_integer_type_node }#
 ()
 #{ /* tree_long_integer_type_node : */ long_integer_type_node }#)

;;; "size_t"
(defcmatcher tree_size_type_node (:tree tr) ()
 nodetr
 :doc #{$TREE_SIZE_TYPE_NODE matches or gives the constant size_t integer 
type node.}#
 #{ /* tree_size_type_node $NODETR ? */ $TR == size_type_node }#
 ()
 #{ /* tree_size_type_node : */ size_type_node }#)

;;; "unsigned long"
(defcmatcher tree_long_unsigned_type_node (:tree tr) ()
 nodetr
 :doc #{$TREE_LONG_UNSIGNED_TYPE_NODE matches or gives the constant unsigned long integer 
type node.}#
 #{ /* tree_long_unsigned_type_node $NODETR ? */ $TR == long_unsigned_type_node }#
 ()
 #{ /* tree_long_unsigned_type_node : */ long_unsigned_type_node }#)

;;; "long long"
(defcmatcher tree_long_long_integer_type_node (:tree tr) ()
 nodetr
 :doc #{$TREE_LONG_LONG_INTEGER_TYPE_NODE matches or gives the constant long long integer 
type node.}#
 #{ /* tree_long_long_integer_type_node $NODETR ? */ $TR == long_long_integer_type_node }#
 ()
 #{ /* tree_long_long_integer_type_node : */ long_long_integer_type_node }#)

;;; "unsigned long long"
(defcmatcher tree_long_long_unsigned_type_node (:tree tr) ()
 nodetr
 :doc #{$TREE_LONG_LONG_UNSIGNED_TYPE_NODE matches or gives the constant unsigned long long integer 
type node.}#
 #{ /* tree_long_long_unsigned_type_node $NODETR ? */ $TR == long_long_unsigned_type_node }#
 ()
 #{ /* tree_long_long_unsigned_type_node : */ long_long_unsigned_type_node }#)

;;; "int128"
(defcmatcher tree_int128_integer_type_node (:tree tr) ()
 nodetr
 :doc #{$TREE_INT128_INTEGER_TYPE_NODE matches or gives the constant 128 bits integer 
type node.}#
 #{ /* tree_int128_integer_type_node $NODETR ? */ $TR == int128_integer_type_node }#
 ()
 #{ /* tree_int128_integer_type_node : */ int128_integer_type_node }#)

;;; "unsigned int128"
(defcmatcher tree_int128_unsigned_type_node (:tree tr) ()
 nodetr
 :doc #{$TREE_INT128_UNSIGNED_TYPE_NODE matches or gives the constant 128 bits unsigned integer 
type node.}#
 #{ /* tree_int128_unsigned_type_node $NODETR ? */ $TR == int128_unsigned_type_node }#
 ()
 #{ /* tree_int128_unsigned_type_node : */ int128_unsigned_type_node }#)

;;; "float"
(defcmatcher tree_float_type_node (:tree tr) ()
 nodetr
 :doc #{$TREE_FLOAT_TYPE_NODE matches or gives the constant float
type node.}#
 #{ /* tree_float_type_node $NODETR ? */ $TR == float_type_node }#
 ()
 #{ /* tree_float_type_node : */ float_type_node }#)

;;; "double"
(defcmatcher tree_double_type_node (:tree tr) ()
 nodetr
 :doc #{$TREE_DOUBLE_TYPE_NODE matches or gives the constant double
type node.}#
 #{ /* tree_double_type_node $NODETR ? */ $TR == double_type_node }#
 ()
 #{ /* tree_double_type_node : */ double_type_node }#)

;;; "long double"
(defcmatcher tree_long_double_type_node (:tree tr) ()
 nodetr
 :doc #{$TREE_LONG_DOUBLE_TYPE_NODE matches or gives the constant long double
type node.}#
 #{ /* tree_long_double_type_node $NODETR ? */ $TR == long_double_type_node }#
 ()
 #{ /* tree_long_double_type_node : */ long_double_type_node }#)

;;; "void"
(defcmatcher tree_void_type_node (:tree tr) ()
 nodetr
 :doc #{$TREE_VOID_TYPE_NODE matches or gives the constant void
type node.}#
 #{ /* tree_void_type_node $NODETR ? */ $TR == void_type_node }#
 ()
 #{ /* tree_void_type_node : */ void_type_node }#)

;;; "void*"
(defcmatcher tree_ptr_type_node (:tree tr) ()
 nodetr
 :doc #{$TREE_PTR_TYPE_NODE matches or gives the constant void*
pointer type node.}#
 #{ /* tree_ptr_type_node $NODETR ? */ $TR == ptr_type_node }#
 ()
 #{ /* tree_ptr_type_node : */ ptr_type_node }#)

;;; "const void*"
(defcmatcher tree_const_ptr_type_node (:tree tr) ()
 nodetr
 :doc #{$TREE_CONST_PTR_TYPE_NODE matches or gives the constant const void*
pointer type node.}#
 #{ /* tree_const_ptr_type_node $NODETR ? */ $TR == const_ptr_type_node }#
 ()
 #{ /* tree_const_ptr_type_node : */ const_ptr_type_node }#)

;;; "bool"
(defcmatcher tree_boolean_type_node (:tree tr) ()
 nodetr
 :doc #{$TREE_BOOLEAN_TYPE_NODE matches or gives the constant bool
 type node.}#
 #{ /* tree_boolean_type_node $NODETR ? */ $TR == boolean_type_node }#
 ()
 #{ /* tree_boolean_type_node : */ boolean_type_node }#)

;;; "true"
(defcmatcher tree_boolean_true_node (:tree tr) ()
 nodetr
 :doc #{$TREE_BOOLEAN_TRUE_NODE matches or gives the constant true node.}#
 #{ /* tree_boolean_true_node $NODETR ? */ $TR == boolean_true_node }#
 ()
 #{ /* tree_boolean_true_node : */ boolean_true_node }#)

;;; "false"
(defcmatcher tree_boolean_false_node (:tree tr) ()
 nodetr
 :doc #{$TREE_BOOLEAN_FALSE_NODE matches or gives the constant false node.}#
 #{ /* tree_boolean_false_node $NODETR ? */ $TR == boolean_false_node }#
 ()
 #{ /* tree_boolean_false_node : */ boolean_false_node }#)


;;; "0"
(defcmatcher tree_integer_zero_node (:tree tr) ()
 nodetr
 :doc #{$TREE_INTEGER_ZERO_NODE matches or gives the constant integer 0 node.}#
 #{ /* tree_integer_zero_node $NODETR ? */ $TR == integer_zero_node }#
 ()
 #{ /* tree_integer_zero_node : */ integer_zero_node }#)

;;; "NULL"
(defcmatcher tree_null_pointer_node (:tree tr) ()
 nodetr
 :doc #{$TREE_NULL_POINTER_NODE matches or gives the constant NULL pointer node.}#
 #{ /* tree_null_pointer_node $NODETR ? */ $TR == null_pointer_node }#
 ()
 #{ /* tree_null_pointer_node : */ null_pointer_node }#)


;;; "1"
(defcmatcher tree_integer_one_node (:tree tr) ()
 nodetr
 :doc #{$TREE_INTEGER_ONE_NODE matches or gives the constant integer 1 node.}#
 #{ /* tree_integer_one_node $NODETR ? */ $TR == integer_one_node }#
 ()
 #{ /* tree_integer_one_node : */ integer_one_node }#)

;;; "-1"
(defcmatcher tree_integer_minus_one_node (:tree tr) ()
 nodetr
 :doc #{$TREE_INTEGER_MINUS_ONE_NODE matches or gives the constant integer -1 node.}#
 #{ /* tree_integer_minus_one_node $NODETR ? */ $TR == integer_minus_one_node }#
 ()
 #{ /* tree_integer_minus_one_node : */ integer_minus_one_node }#)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;; map keyed by raw trees
(defprimitive is_maptree (map) :long
  :doc #{Test if $MAP is a map of trees.}#
  #{ (melt_magic_discr((melt_ptr_t)($map)) == MELTOBMAG_MAPTREES) }#)
(defprimitive maptree_size (map) :long
  :doc #{Safely retrieve allocated size of map of trees $MAP.}#
 #{ (melt_size_maptrees((struct meltmaptrees_st*)($map))) }#)
;; primitive to get the attribute count of a maptree
(defprimitive maptree_count (map) :long
  :doc #{Safely retrieve used count of map of trees $MAP.}#
  #{ (melt_count_maptrees((struct meltmaptrees_st*)($map))) }# )
;; get an entry in a maptree from a C tree
(defprimitive maptree_get (map :tree tr) :value
  :doc #{Safely get in map of trees $MAP value associated to tree $TR.}#
  #{(melt_get_maptrees((melt_ptr_t) ($MAP), ($TR)))}#)
;; primitive for making a new map of trees
(defprimitive make_maptree (discr :long len) :value
  :doc #{Make a map of trees with discriminant $DISCR and initial size $LEN.}#
 #{(meltgc_new_maptrees((meltobject_ptr_t) ($DISCR), ($LEN)))}#)
;; primitive for putting into a map of trees
(defprimitive maptree_put (map :tree trkey :value val) :void
  :doc #{Safely put in map of trees $MAP associated to tree $TRKEY the non-nil value $VAL.}#
  #{melt_put_maptrees((melt_ptr_t) ($MAP),  ($TRKEY), 
		      (melt_ptr_t) ($VAL))}#)
;; primitive for removing from a map of trees
(defprimitive maptree_remove (map :tree trkey) :void
  :doc #{Safely remove in map of trees $MAP entry for tree $TRKEY.}#
  #{melt_remove_maptrees((melt_ptr_t) ($MAP), ($TRKEY))}#)
;; primitive to retrieve the auxiliary data of a map of trees
(defprimitive maptree_aux (map) :value
  :doc #{Safely retrieve in map of trees $MAP the auxiliary data.}#
  #{melt_auxdata_maptrees ((melt_ptr_t)$MAP)}#)
;; primitive to put the auxiliary data of a map of trees
(defprimitive maptree_auxput (map aux) :void
  :doc #{Safely put in map of trees $MAP the auxiliary data to $AUX.}#
  #{melt_auxput_maptrees ((melt_ptr_t)$MAP, (melt_ptr_t)$AUX)}#)

;; primitive to get the nth tree of a maptree
(defprimitive maptree_nth_attr (map :long n) :tree
  #{(melt_nthattr_maptrees((struct meltmaptrees_st*)($map), (int)($n)))}#)
;; primitive to get the nth value of a mapobject
(defprimitive maptree_nth_val (map :long n) :value
  #{(melt_nthval_maptrees((struct meltmaptrees_st*)($map), (int)($n)))}# )
;; iterator inside maptree
(defciterator foreach_maptree 
  (trmap)				; startformals
  eachmaptr 				;state symbol
  (:tree tratt :value trval)	;local formals
  ;; before expansion
  #{
   /*$EACHMAPTR*/ int $EACHMAPTR#_rk=0;
   for ($EACHMAPTR#_rk=0;
        $EACHMAPTR#_rk<melt_size_maptrees((struct meltmaptrees_st*)($TRMAP));
	$EACHMAPTR#_rk++) {
   tree $EACHMAPTR#_tr = ((struct meltmaptrees_st*)($TRMAP))->entab[$EACHMAPTR#_rk].e_at;
   $TRATT = (tree) NULL;
   $TRVAL = (melt_ptr_t) NULL;
   if (!$EACHMAPTR#_tr 
       || (void*) $EACHMAPTR#_tr == (void*) HTAB_DELETED_ENTRY) 
     continue;
   $TRATT = $EACHMAPTR#_tr;
   $TRVAL = ((struct meltmaptrees_st*)($TRMAP))->entab[$EACHMAPTR#_rk].e_va;
   }#
  ;;after expansion
   #{
   } /*end $EACHMAPTR*/
   $TRATT = (tree) NULL;
   $TRVAL = (melt_ptr_t) NULL;
   }#
  )


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; TREE DEBUG OUTPUT 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; boxed tree debug
(defun dbgout_boxtree_method (self dbgi :long depth)
  (assert_msg "check dbgi" (is_a dbgi class_debug_information))
  (let ( (dis (discrim self)) 
	 (out  (unsafe_get_field :dbgi_out dbgi)) ) 
    (add2out_strconst out " ?/")
    (if (is_a dis class_named) (add2out_string out (unsafe_get_field :named_name dis)))
    (add2out_strconst out "/{")
    (output_tree_briefly out (tree_content self))
    (add2out_strconst out "}/")
    (add2out_indentnl out depth)
    )
  )
(install_method discr_tree dbg_output dbgout_boxtree_method)


;;;; treemap debug
(defun dbgout_maptree_method (self dbgi :long depth)
  (assert_msg "check dbgi" (is_a dbgi class_debug_information))
  (assert_msg "check self" (is_maptree self))
  (let ( (dis (discrim self)) 
	 (:long mapcount (maptree_count self))
	 (aux (maptree_aux self))
	 (out  (unsafe_get_field :dbgi_out dbgi)) ) 
    (add2out_strconst out " !treemap.")
    (if (is_a dis class_named) (add2out_string out (unsafe_get_field :named_name dis)))
    (add2out_strconst out "/")
    (add2out_longdec out mapcount)
    (add2out_strconst out "!{ ")
    (if (and (<=i depth 1)
	     aux)
	(progn
	  (add2out out " aux:")
	  (dbg_out aux dbgi (+i depth 3))
	  ))
    (foreach_maptree
     (self)
     (:tree tratt :value trval)
     (add2out_indentnl out (+i depth 1))
     (add2out_strconst out "*")
     (output_tree_briefly out tratt)
     (add2out_strconst out " == ")
     (dbg_out trval dbgi (+i depth 2))
     )
    (add2out_strconst out " }!")
    (add2out_indentnl out depth)
    ))
(install_method discr_map_trees dbg_output dbgout_maptree_method)

;;;;;;;;;;;;;;;;
;;; primitive to push the cfun asociated with a function declaration
;;; this is required otherwise dump of gimple crashes
(defprimitive push_cfun_decl (:tree fundecl) :void
#{ push_cfun(DECL_STRUCT_FUNCTION($fundecl)) }#) 
(defprimitive pop_cfun () :void
"pop_cfun()")


(export_values
 ;;in alphanumerical order
 ==t
 build_identifier_tree
 build_int_tree
 build_string_tree
 foreach_argument_in_function_tree
 foreach_maptree
 inform_at_tree
 is_maptree
 is_tree
 isnull_tree
 make_maptree
 make_tree  
 maptree_aux
 maptree_auxput
 maptree_count
 maptree_get
 maptree_nth_attr
 maptree_nth_val
 maptree_put
 maptree_remove
 maptree_size
 null_tree
 pop_cfun
 push_cfun_decl
 tree_addr_expr
 tree_array_ref
 tree_array_ref_full
 tree_array_type
 tree_block
 tree_boolean_false_node 
 tree_boolean_true_node 
 tree_boolean_type
 tree_boolean_type_node 
 tree_chain_append
 tree_chain_join
 tree_chain_prepend
 tree_char_type_node 
 tree_complex_type
 tree_component_ref
 tree_component_ref_full
 tree_component_ref_typed
 tree_const_decl
 tree_const_decl_named
 tree_const_decl_of_name
 tree_const_ptr_type_node 
 tree_content 
 tree_decl
 tree_decl_at_source_location
 tree_double_type_node 
 tree_enumeral_type
 tree_expr_at_source_location
 tree_field_decl
 tree_fixed_point_type
 tree_float_type_node 
 tree_function_decl 
 tree_function_decl_named
 tree_function_decl_of_name
 tree_function_type
 tree_identifier
 tree_indirect_reference
 tree_int128_integer_type_node 
 tree_int128_unsigned_type_node 
 tree_integer_cst
 tree_integer_minus_one_node 
 tree_integer_one_node 
 tree_integer_type
 tree_integer_type_bounded
 tree_integer_type_node 
 tree_integer_zero_node 
 tree_list
 tree_long_double_type_node 
 tree_long_integer_type_node 
 tree_long_long_integer_type_node 
 tree_long_long_unsigned_type_node 
 tree_long_unsigned_type_node 
 tree_mem_ref
 tree_null_pointer_node 
 tree_nullptr_type
 tree_of_type
 tree_offset_type
 tree_parm_decl
 tree_parm_decl_named
 tree_parm_decl_of_name
 tree_pointer_type
 tree_pointer_type_p
 tree_ptr_type_node 
 tree_real_cst
 tree_real_type
 tree_record_type
 tree_record_type_with_fields
 tree_reference_type
 tree_result_decl
 tree_result_decl_named
 tree_result_decl_of_name
 tree_short_integer_type_node 
 tree_short_unsigned_type_node 
 tree_signed_char_type_node 
 tree_simple_ssa_name 
 tree_size_type_node 
 tree_ssa_name 
 tree_string_cst
 tree_type
 tree_type_decl
 tree_type_decl_named
 tree_type_declaration
 tree_uid
 tree_unsigned_char_type_node 
 tree_unsigned_type_node 
 tree_var_decl
 tree_var_decl_named
 tree_var_decl_of_name
 tree_vec
 tree_void_type
 tree_void_type_node 
 walk_use_def_chain_breadth_first 
 walk_use_def_chain_depth_first 
 warning_at_tree
 warning_at_tree_decl_with_number
)


;; eof xtramelt-ana-tree.melt