Debian Codegraph @

gcc/m2/gm2-gcc/m2tree.cc

raw
1 /* m2tree.cc provides a simple interface to GCC tree queries and skips.
2
3 Copyright (C) 2012-2025 Free Software Foundation, Inc.
4 Contributed by Gaius Mulley <[email protected]>.
5
6 This file is part of GNU Modula-2.
7
8 GNU Modula-2 is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
11 any later version.
12
13 GNU Modula-2 is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GNU Modula-2; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
21
22 #include "gcc-consolidation.h"
23
24 #include "../m2-tree.h"
25
26 #define m2tree_c
27 #include "m2tree.h"
28
29 bool
30 m2tree_is_var (tree var)
31 {
32 return VAR_P (var);
33 }
34
35 bool
36 m2tree_is_array (tree array)
37 {
38 return TREE_CODE (array) == ARRAY_TYPE;
39 }
40
41 bool
42 m2tree_is_type (tree type)
43 {
44 switch (TREE_CODE (type))
45 {
46
47 case TYPE_DECL:
48 case ARRAY_TYPE:
49 case RECORD_TYPE:
50 case SET_TYPE:
51 case ENUMERAL_TYPE:
52 case POINTER_TYPE:
53 case INTEGER_TYPE:
54 case REAL_TYPE:
55 case UNION_TYPE:
56 case BOOLEAN_TYPE:
57 case COMPLEX_TYPE:
58 return TRUE;
59 default:
60 return FALSE;
61 }
62 }
63
64 tree
65 m2tree_skip_type_decl (tree type)
66 {
67 if (type == error_mark_node)
68 return error_mark_node;
69
70 if (type == NULL_TREE)
71 return NULL_TREE;
72
73 if (TREE_CODE (type) == TYPE_DECL)
74 return m2tree_skip_type_decl (TREE_TYPE (type));
75 return type;
76 }
77
78 tree
79 m2tree_skip_const_decl (tree exp)
80 {
81 if (exp == error_mark_node)
82 return error_mark_node;
83
84 if (exp == NULL_TREE)
85 return NULL_TREE;
86
87 if (TREE_CODE (exp) == CONST_DECL)
88 return DECL_INITIAL (exp);
89 return exp;
90 }
91
92 /* m2tree_skip_reference_type - skips all POINTER_TYPE and
93 REFERENCE_TYPEs. Otherwise return exp. */
94
95 tree
96 m2tree_skip_reference_type (tree exp)
97 {
98 if (TREE_CODE (exp) == REFERENCE_TYPE)
99 return m2tree_skip_reference_type (TREE_TYPE (exp));
100 if (TREE_CODE (exp) == POINTER_TYPE)
101 return m2tree_skip_reference_type (TREE_TYPE (exp));
102 return exp;
103 }
104
105 /* m2tree_IsOrdinal - return TRUE if code is an INTEGER, BOOLEAN or
106 ENUMERAL type. */
107
108 bool
109 m2tree_IsOrdinal (tree type)
110 {
111 enum tree_code code = TREE_CODE (type);
112
113 return (code == INTEGER_TYPE || (code) == BOOLEAN_TYPE
114 || (code) == ENUMERAL_TYPE);
115 }
116
117 /* is_a_constant - returns TRUE if tree, t, is a constant. */
118
119 bool
120 m2tree_IsAConstant (tree t)
121 {
122 return (TREE_CODE (t) == INTEGER_CST) || (TREE_CODE (t) == REAL_CST)
123 || (TREE_CODE (t) == REAL_CST) || (TREE_CODE (t) == COMPLEX_CST)
124 || (TREE_CODE (t) == STRING_CST) || (TREE_CODE (t) == CONSTRUCTOR);
125 }
126
127
128 void
129 m2tree_debug_tree (tree t)
130 {
131 debug_tree (t);
132 }