1 /* Prints out trees in human readable form.
2    Copyright (C) 1992-2016 Free Software Foundation, Inc.
3    Hacked by Michael Tiemann (tiemann@cygnus.com)
4 
5 This file is part of GCC.
6 
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
11 
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3.  If not see
19 <http://www.gnu.org/licenses/>.  */
20 
21 
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "cp-tree.h"
26 #include "print-tree.h"
27 
28 void
cxx_print_decl(FILE * file,tree node,int indent)29 cxx_print_decl (FILE *file, tree node, int indent)
30 {
31   if (TREE_CODE (node) == FIELD_DECL)
32     {
33       if (DECL_MUTABLE_P (node))
34 	{
35 	  indent_to (file, indent + 3);
36 	  fprintf (file, " mutable ");
37 	}
38       return;
39     }
40 
41   if (!CODE_CONTAINS_STRUCT (TREE_CODE (node), TS_DECL_COMMON)
42       || !DECL_LANG_SPECIFIC (node))
43     return;
44   if (TREE_CODE (node) == FUNCTION_DECL)
45     {
46       int flags = TFF_DECL_SPECIFIERS|TFF_RETURN_TYPE
47 	|TFF_FUNCTION_DEFAULT_ARGUMENTS|TFF_EXCEPTION_SPECIFICATION ;
48       indent_to (file, indent + 3);
49       fprintf (file, " full-name \"%s\"", decl_as_string (node, flags));
50     }
51   else if (TREE_CODE (node) == TEMPLATE_DECL)
52     {
53       indent_to (file, indent + 3);
54       fprintf (file, " full-name \"%s\"",
55 	       decl_as_string (node, TFF_TEMPLATE_HEADER));
56     }
57 
58   indent_to (file, indent + 3);
59   if (DECL_EXTERNAL (node) && DECL_NOT_REALLY_EXTERN (node))
60     fprintf (file, " not-really-extern");
61   if (TREE_CODE (node) == FUNCTION_DECL
62       && DECL_PENDING_INLINE_INFO (node))
63     fprintf (file, " pending-inline-info %p",
64 	     (void *) DECL_PENDING_INLINE_INFO (node));
65   if (VAR_OR_FUNCTION_DECL_P (node)
66       && DECL_TEMPLATE_INFO (node))
67     fprintf (file, " template-info %p",
68 	     (void *) DECL_TEMPLATE_INFO (node));
69 }
70 
71 void
cxx_print_type(FILE * file,tree node,int indent)72 cxx_print_type (FILE *file, tree node, int indent)
73 {
74   switch (TREE_CODE (node))
75     {
76     case TEMPLATE_TYPE_PARM:
77     case TEMPLATE_TEMPLATE_PARM:
78     case BOUND_TEMPLATE_TEMPLATE_PARM:
79       indent_to (file, indent + 3);
80       fprintf (file, "index %d level %d orig_level %d",
81 	       TEMPLATE_TYPE_IDX (node), TEMPLATE_TYPE_LEVEL (node),
82 	       TEMPLATE_TYPE_ORIG_LEVEL (node));
83       return;
84 
85     case FUNCTION_TYPE:
86     case METHOD_TYPE:
87       if (TYPE_RAISES_EXCEPTIONS (node))
88 	print_node (file, "throws", TYPE_RAISES_EXCEPTIONS (node), indent + 4);
89       return;
90 
91     case RECORD_TYPE:
92     case UNION_TYPE:
93       break;
94 
95     case DECLTYPE_TYPE:
96       print_node (file, "expr", DECLTYPE_TYPE_EXPR (node), indent + 4);
97       return;
98 
99     case TYPENAME_TYPE:
100       print_node (file, "fullname", TYPENAME_TYPE_FULLNAME (node),
101 		  indent + 4);
102       return;
103 
104     case TYPE_PACK_EXPANSION:
105       print_node (file, "args", PACK_EXPANSION_EXTRA_ARGS (node), indent + 4);
106       return;
107 
108     default:
109       return;
110     }
111 
112   if (TYPE_PTRMEMFUNC_P (node))
113     print_node (file, "ptrmemfunc fn type", TYPE_PTRMEMFUNC_FN_TYPE (node),
114 		indent + 4);
115 
116   if (! CLASS_TYPE_P (node))
117     return;
118 
119   indent_to (file, indent + 4);
120   fprintf (file, "full-name \"%s\"",
121 	   type_as_string (node, TFF_CLASS_KEY_OR_ENUM));
122 
123   indent_to (file, indent + 3);
124 
125   if (TYPE_NEEDS_CONSTRUCTING (node))
126     fputs ( " needs-constructor", file);
127   if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (node))
128     fputs (" needs-destructor", file);
129   if (TYPE_HAS_DEFAULT_CONSTRUCTOR (node))
130     fputs (" X()", file);
131   if (TYPE_HAS_CONVERSION (node))
132     fputs (" has-type-conversion", file);
133   if (TYPE_HAS_COPY_CTOR (node))
134     {
135       if (TYPE_HAS_CONST_COPY_CTOR (node))
136 	fputs (" X(constX&)", file);
137       else
138 	fputs (" X(X&)", file);
139     }
140   if (TYPE_HAS_NEW_OPERATOR (node))
141     fputs (" new", file);
142   if (TYPE_HAS_ARRAY_NEW_OPERATOR (node))
143     fputs (" new[]", file);
144   if (TYPE_GETS_DELETE (node) & 1)
145     fputs (" delete", file);
146   if (TYPE_GETS_DELETE (node) & 2)
147     fputs (" delete[]", file);
148   if (TYPE_HAS_COPY_ASSIGN (node))
149     fputs (" this=(X&)", file);
150   if (CLASSTYPE_SORTED_FIELDS (node))
151     fprintf (file, " sorted-fields %p",
152 	     (void *) CLASSTYPE_SORTED_FIELDS (node));
153 
154   if (TREE_CODE (node) == RECORD_TYPE)
155     {
156       if (TYPE_BINFO (node))
157 	fprintf (file, " n_parents=%d",
158 		 BINFO_N_BASE_BINFOS (TYPE_BINFO (node)));
159       else
160 	fprintf (file, " no-binfo");
161 
162       fprintf (file, " use_template=%d", CLASSTYPE_USE_TEMPLATE (node));
163       if (CLASSTYPE_INTERFACE_ONLY (node))
164 	fprintf (file, " interface-only");
165       if (CLASSTYPE_INTERFACE_UNKNOWN (node))
166 	fprintf (file, " interface-unknown");
167     }
168 }
169 
170 
171 static void
cxx_print_binding(FILE * stream,cxx_binding * binding,const char * prefix)172 cxx_print_binding (FILE *stream, cxx_binding *binding, const char *prefix)
173 {
174   fprintf (stream, "%s <%p>",
175 	   prefix, (void *) binding);
176 }
177 
178 void
cxx_print_identifier(FILE * file,tree node,int indent)179 cxx_print_identifier (FILE *file, tree node, int indent)
180 {
181   if (indent == 0)
182     fprintf (file, " ");
183   else
184     indent_to (file, indent + 4);
185   cxx_print_binding (file, IDENTIFIER_NAMESPACE_BINDINGS (node), "bindings");
186   if (indent == 0)
187     fprintf (file, " ");
188   else
189     indent_to (file, indent + 4);
190   cxx_print_binding (file, IDENTIFIER_BINDING (node), "local bindings");
191   print_node (file, "label", IDENTIFIER_LABEL_VALUE (node), indent + 4);
192   print_node (file, "template", IDENTIFIER_TEMPLATE (node), indent + 4);
193 }
194 
195 void
cxx_print_lambda_node(FILE * file,tree node,int indent)196 cxx_print_lambda_node (FILE *file, tree node, int indent)
197 {
198   if (LAMBDA_EXPR_MUTABLE_P (node))
199     fprintf (file, " /mutable");
200   fprintf (file, " default_capture_mode=[");
201   switch (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (node))
202     {
203     case CPLD_NONE:
204       fprintf (file, "NONE");
205       break;
206     case CPLD_COPY:
207       fprintf (file, "COPY");
208       break;
209     case CPLD_REFERENCE:
210       fprintf (file, "CPLD_REFERENCE");
211       break;
212     default:
213       fprintf (file, "??");
214       break;
215     }
216   fprintf (file, "] ");
217   print_node (file, "capture_list", LAMBDA_EXPR_CAPTURE_LIST (node), indent + 4);
218   print_node (file, "this_capture", LAMBDA_EXPR_THIS_CAPTURE (node), indent + 4);
219   print_node (file, "return_type", LAMBDA_EXPR_RETURN_TYPE (node), indent + 4);
220   print_node (file, "closure", LAMBDA_EXPR_CLOSURE (node), indent + 4);
221 }
222 
223 void
cxx_print_xnode(FILE * file,tree node,int indent)224 cxx_print_xnode (FILE *file, tree node, int indent)
225 {
226   switch (TREE_CODE (node))
227     {
228     case BASELINK:
229       print_node (file, "functions", BASELINK_FUNCTIONS (node), indent + 4);
230       print_node (file, "binfo", BASELINK_BINFO (node), indent + 4);
231       print_node (file, "access_binfo", BASELINK_ACCESS_BINFO (node),
232 		  indent + 4);
233       break;
234     case OVERLOAD:
235       print_node (file, "function", OVL_FUNCTION (node), indent+4);
236       print_node (file, "chain", TREE_CHAIN (node), indent+4);
237       break;
238     case TEMPLATE_PARM_INDEX:
239       indent_to (file, indent + 3);
240       fprintf (file, "index %d level %d orig_level %d",
241 	       TEMPLATE_PARM_IDX (node), TEMPLATE_PARM_LEVEL (node),
242 	       TEMPLATE_PARM_ORIG_LEVEL (node));
243       break;
244     case TEMPLATE_INFO:
245       print_node (file, "template", TI_TEMPLATE (node), indent+4);
246       print_node (file, "args", TI_ARGS (node), indent+4);
247       if (TI_PENDING_TEMPLATE_FLAG (node))
248 	{
249 	  indent_to (file, indent + 3);
250 	  fprintf (file, "pending_template");
251 	}
252       break;
253     case CONSTRAINT_INFO:
254       {
255         tree_constraint_info *cinfo = (tree_constraint_info *)node;
256         if (cinfo->template_reqs)
257           print_node (file, "template_reqs", cinfo->template_reqs, indent+4);
258         if (cinfo->declarator_reqs)
259           print_node (file, "declarator_reqs", cinfo->declarator_reqs,
260 		      indent+4);
261         print_node (file, "associated_constr",
262                           cinfo->associated_constr, indent+4);
263         break;
264       }
265     case ARGUMENT_PACK_SELECT:
266       print_node (file, "pack", ARGUMENT_PACK_SELECT_FROM_PACK (node),
267 		  indent+4);
268       indent_to (file, indent + 3);
269       fprintf (file, "index %d", ARGUMENT_PACK_SELECT_INDEX (node));
270       break;
271     case DEFERRED_NOEXCEPT:
272       print_node (file, "pattern", DEFERRED_NOEXCEPT_PATTERN (node), indent+4);
273       print_node (file, "args", DEFERRED_NOEXCEPT_ARGS (node), indent+4);
274       break;
275     case TRAIT_EXPR:
276       indent_to (file, indent+4);
277       fprintf (file, "kind %d", TRAIT_EXPR_KIND (node));
278       print_node (file, "type 1", TRAIT_EXPR_TYPE1 (node), indent+4);
279       if (TRAIT_EXPR_TYPE2 (node))
280 	print_node (file, "type 2", TRAIT_EXPR_TYPE2 (node), indent+4);
281       break;
282     case LAMBDA_EXPR:
283       cxx_print_lambda_node (file, node, indent);
284       break;
285     default:
286       break;
287     }
288 }
289 
290 /* Print the node NODE on standard error, for debugging.  */
291 
292 DEBUG_FUNCTION void
debug_tree(cp_expr node)293 debug_tree (cp_expr node)
294 {
295   debug_tree (node.get_value());
296 }
297