2002-02-19 Philip Blundell <philb@gnu.org>
[official-gcc.git] / gcc / cp / dump.c
blob98c1fc49d87b0ad5ee0d88e45cef9d257feb75e0
1 /* Tree-dumping functionality for intermediate representation.
2 Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
3 Written by Mark Mitchell <mark@codesourcery.com>
5 This file is part of GNU CC.
7 GNU CC 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 2, or (at your option)
10 any later version.
12 GNU CC 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.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 #include "config.h"
23 #include "system.h"
24 #include "tree.h"
25 #include "cp-tree.h"
26 #include "tree-dump.h"
28 static void dump_access
29 PARAMS ((dump_info_p, tree));
31 static void dump_op
32 PARAMS ((dump_info_p, tree));
34 /* Dump a representation of the accessibility information associated
35 with T. */
37 static void
38 dump_access (di, t)
39 dump_info_p di;
40 tree t;
42 if (TREE_PROTECTED(t))
43 dump_string (di, "protected");
44 else if (TREE_PRIVATE(t))
45 dump_string (di, "private");
46 else
47 dump_string (di, "public");
50 /* Dump a representation of the specific operator for an overloaded
51 operator associated with node t.
54 static void
55 dump_op (di, t)
56 dump_info_p di;
57 tree t;
59 switch (DECL_OVERLOADED_OPERATOR_P (t)) {
60 case NEW_EXPR:
61 dump_string (di, "new");
62 break;
63 case VEC_NEW_EXPR:
64 dump_string (di, "vecnew");
65 break;
66 case DELETE_EXPR:
67 dump_string (di, "delete");
68 break;
69 case VEC_DELETE_EXPR:
70 dump_string (di, "vecdelete");
71 break;
72 case CONVERT_EXPR:
73 dump_string (di, "pos");
74 break;
75 case NEGATE_EXPR:
76 dump_string (di, "neg");
77 break;
78 case ADDR_EXPR:
79 dump_string (di, "addr");
80 break;
81 case INDIRECT_REF:
82 dump_string(di, "deref");
83 break;
84 case BIT_NOT_EXPR:
85 dump_string(di, "not");
86 break;
87 case TRUTH_NOT_EXPR:
88 dump_string(di, "lnot");
89 break;
90 case PREINCREMENT_EXPR:
91 dump_string(di, "preinc");
92 break;
93 case PREDECREMENT_EXPR:
94 dump_string(di, "predec");
95 break;
96 case PLUS_EXPR:
97 if (DECL_ASSIGNMENT_OPERATOR_P (t))
98 dump_string (di, "plusassign");
99 else
100 dump_string(di, "plus");
101 break;
102 case MINUS_EXPR:
103 if (DECL_ASSIGNMENT_OPERATOR_P (t))
104 dump_string (di, "minusassign");
105 else
106 dump_string(di, "minus");
107 break;
108 case MULT_EXPR:
109 if (DECL_ASSIGNMENT_OPERATOR_P (t))
110 dump_string (di, "multassign");
111 else
112 dump_string (di, "mult");
113 break;
114 case TRUNC_DIV_EXPR:
115 if (DECL_ASSIGNMENT_OPERATOR_P (t))
116 dump_string (di, "divassign");
117 else
118 dump_string (di, "div");
119 break;
120 case TRUNC_MOD_EXPR:
121 if (DECL_ASSIGNMENT_OPERATOR_P (t))
122 dump_string (di, "modassign");
123 else
124 dump_string (di, "mod");
125 break;
126 case BIT_AND_EXPR:
127 if (DECL_ASSIGNMENT_OPERATOR_P (t))
128 dump_string (di, "andassign");
129 else
130 dump_string (di, "and");
131 break;
132 case BIT_IOR_EXPR:
133 if (DECL_ASSIGNMENT_OPERATOR_P (t))
134 dump_string (di, "orassign");
135 else
136 dump_string (di, "or");
137 break;
138 case BIT_XOR_EXPR:
139 if (DECL_ASSIGNMENT_OPERATOR_P (t))
140 dump_string (di, "xorassign");
141 else
142 dump_string (di, "xor");
143 break;
144 case LSHIFT_EXPR:
145 if (DECL_ASSIGNMENT_OPERATOR_P (t))
146 dump_string (di, "lshiftassign");
147 else
148 dump_string (di, "lshift");
149 break;
150 case RSHIFT_EXPR:
151 if (DECL_ASSIGNMENT_OPERATOR_P (t))
152 dump_string (di, "rshiftassign");
153 else
154 dump_string (di, "rshift");
155 break;
156 case EQ_EXPR:
157 dump_string (di, "eq");
158 break;
159 case NE_EXPR:
160 dump_string (di, "ne");
161 break;
162 case LT_EXPR:
163 dump_string (di, "lt");
164 break;
165 case GT_EXPR:
166 dump_string (di, "gt");
167 break;
168 case LE_EXPR:
169 dump_string (di, "le");
170 break;
171 case GE_EXPR:
172 dump_string (di, "ge");
173 break;
174 case TRUTH_ANDIF_EXPR:
175 dump_string (di, "land");
176 break;
177 case TRUTH_ORIF_EXPR:
178 dump_string (di, "lor");
179 break;
180 case COMPOUND_EXPR:
181 dump_string (di, "compound");
182 break;
183 case MEMBER_REF:
184 dump_string (di, "memref");
185 break;
186 case COMPONENT_REF:
187 dump_string (di, "ref");
188 break;
189 case ARRAY_REF:
190 dump_string (di, "subs");
191 break;
192 case POSTINCREMENT_EXPR:
193 dump_string (di, "postinc");
194 break;
195 case POSTDECREMENT_EXPR:
196 dump_string (di, "postdec");
197 break;
198 case CALL_EXPR:
199 dump_string (di, "call");
200 break;
201 case NOP_EXPR:
202 if (DECL_ASSIGNMENT_OPERATOR_P (t))
203 dump_string (di, "assign");
204 break;
205 default:
206 break;
211 cp_dump_tree (dump_info, t)
212 void *dump_info;
213 tree t;
215 enum tree_code code;
216 dump_info_p di = (dump_info_p) dump_info;
218 /* Figure out what kind of node this is. */
219 code = TREE_CODE (t);
221 if (DECL_P (t))
223 if (DECL_LANG_SPECIFIC (t) && DECL_LANGUAGE (t) != lang_cplusplus)
224 dump_string (di, language_to_string (DECL_LANGUAGE (t), 0));
227 switch (code)
229 case IDENTIFIER_NODE:
230 if (IDENTIFIER_OPNAME_P (t))
232 dump_string (di, "operator");
233 return 1;
235 else if (IDENTIFIER_TYPENAME_P (t))
237 dump_child ("tynm", TREE_TYPE (t));
238 return 1;
240 else if (t == anonymous_namespace_name)
242 dump_string (di, "unnamed");
243 return 1;
245 break;
247 case POINTER_TYPE:
248 if (TYPE_PTRMEM_P (t))
250 dump_string (di, "ptrmem");
251 dump_child ("ptd", TYPE_PTRMEM_POINTED_TO_TYPE (t));
252 dump_child ("cls", TYPE_PTRMEM_CLASS_TYPE (t));
253 return 1;
255 break;
257 case RECORD_TYPE:
258 case UNION_TYPE:
259 if (TYPE_PTRMEMFUNC_P (t))
261 dump_string (di, "ptrmem");
262 dump_child ("ptd", TYPE_PTRMEM_POINTED_TO_TYPE (t));
263 dump_child ("cls", TYPE_PTRMEM_CLASS_TYPE (t));
264 return 1;
267 dump_child ("vfld", TYPE_VFIELD (t));
268 if (CLASSTYPE_TEMPLATE_SPECIALIZATION(t))
269 dump_string(di, "spec");
271 if (!dump_flag (di, TDF_SLIM, t))
273 int i;
275 for (i = 0; i < CLASSTYPE_N_BASECLASSES (t); ++i)
277 tree base_binfo = BINFO_BASETYPE (TYPE_BINFO (t), i);
278 dump_child ("base", BINFO_TYPE (base_binfo));
279 if (TREE_VIA_VIRTUAL (base_binfo))
280 dump_string (di, "virtual");
281 dump_access (di, base_binfo);
284 break;
286 case FIELD_DECL:
287 dump_access (di, t);
288 if (DECL_MUTABLE_P (t))
289 dump_string(di, "mutable");
290 break;
292 case VAR_DECL:
293 if (TREE_CODE (CP_DECL_CONTEXT (t)) == RECORD_TYPE)
294 dump_access (di, t);
295 if (TREE_STATIC (t) && !TREE_PUBLIC (t))
296 dump_string (di, "static");
297 break;
299 case FUNCTION_DECL:
300 if (!DECL_THUNK_P (t))
302 if (DECL_OVERLOADED_OPERATOR_P (t)) {
303 dump_string (di, "operator");
304 dump_op (di, t);
306 if (DECL_FUNCTION_MEMBER_P (t))
308 dump_string (di, "member");
309 dump_access (di, t);
311 if (DECL_PURE_VIRTUAL_P (t))
312 dump_string (di, "pure");
313 if (DECL_VIRTUAL_P (t))
314 dump_string (di, "virtual");
315 if (DECL_CONSTRUCTOR_P (t))
316 dump_string (di, "constructor");
317 if (DECL_DESTRUCTOR_P (t))
318 dump_string (di, "destructor");
319 if (DECL_CONV_FN_P (t))
320 dump_string (di, "conversion");
321 if (DECL_GLOBAL_CTOR_P (t) || DECL_GLOBAL_DTOR_P (t))
323 if (DECL_GLOBAL_CTOR_P (t))
324 dump_string (di, "global init");
325 if (DECL_GLOBAL_DTOR_P (t))
326 dump_string (di, "global fini");
327 dump_int (di, "prio", GLOBAL_INIT_PRIORITY (t));
329 if (DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (t))
330 dump_string (di, "pseudo tmpl");
332 else
334 dump_string (di, "thunk");
335 dump_int (di, "dlta", THUNK_DELTA (t));
336 dump_child ("vcll", THUNK_VCALL_OFFSET (t));
337 dump_child ("fn", DECL_INITIAL (t));
339 break;
341 case NAMESPACE_DECL:
342 if (DECL_NAMESPACE_ALIAS (t))
343 dump_child ("alis", DECL_NAMESPACE_ALIAS (t));
344 else if (!dump_flag (di, TDF_SLIM, t))
345 dump_child ("dcls", cp_namespace_decls (t));
346 break;
348 case TEMPLATE_DECL:
349 dump_child ("rslt", DECL_TEMPLATE_RESULT (t));
350 dump_child ("inst", DECL_TEMPLATE_INSTANTIATIONS (t));
351 dump_child ("spcs", DECL_TEMPLATE_SPECIALIZATIONS (t));
352 dump_child ("prms", DECL_TEMPLATE_PARMS (t));
353 break;
355 case OVERLOAD:
356 dump_child ("crnt", OVL_CURRENT (t));
357 dump_child ("chan", OVL_CHAIN (t));
358 break;
360 case TRY_BLOCK:
361 dump_stmt (di, t);
362 if (CLEANUP_P (t))
363 dump_string (di, "cleanup");
364 dump_child ("body", TRY_STMTS (t));
365 dump_child ("hdlr", TRY_HANDLERS (t));
366 dump_next_stmt (di, t);
367 break;
369 case EH_SPEC_BLOCK:
370 dump_stmt (di, t);
371 dump_child ("body", EH_SPEC_STMTS (t));
372 dump_child ("raises", EH_SPEC_RAISES (t));
373 dump_next_stmt (di, t);
374 break;
376 case PTRMEM_CST:
377 dump_child ("clas", PTRMEM_CST_CLASS (t));
378 dump_child ("mbr", PTRMEM_CST_MEMBER (t));
379 break;
381 case THROW_EXPR:
382 /* These nodes are unary, but do not have code class `1'. */
383 dump_child ("op 0", TREE_OPERAND (t, 0));
384 break;
386 case AGGR_INIT_EXPR:
387 dump_int (di, "ctor", AGGR_INIT_VIA_CTOR_P (t));
388 dump_child ("fn", TREE_OPERAND (t, 0));
389 dump_child ("args", TREE_OPERAND (t, 1));
390 dump_child ("decl", TREE_OPERAND (t, 2));
391 break;
393 case CLEANUP_STMT:
394 dump_stmt (di, t);
395 dump_child ("decl", CLEANUP_DECL (t));
396 dump_child ("expr", CLEANUP_EXPR (t));
397 dump_next_stmt (di, t);
398 break;
400 case CTOR_STMT:
401 dump_stmt (di, t);
402 if (CTOR_BEGIN_P (t))
403 dump_string (di, "begn");
404 else
405 dump_string (di, "end");
406 dump_next_stmt (di, t);
407 break;
409 case HANDLER:
410 dump_stmt (di, t);
411 dump_child ("parm", HANDLER_PARMS (t));
412 dump_child ("body", HANDLER_BODY (t));
413 dump_next_stmt (di, t);
414 break;
416 case MUST_NOT_THROW_EXPR:
417 dump_stmt (di, t);
418 dump_child ("body", TREE_OPERAND (t, 0));
419 dump_next_stmt (di, t);
420 break;
422 case SUBOBJECT:
423 dump_stmt (di, t);
424 dump_child ("clnp", TREE_OPERAND (t, 0));
425 dump_next_stmt (di, t);
426 break;
428 case USING_STMT:
429 dump_stmt (di, t);
430 dump_child ("nmsp", USING_STMT_NAMESPACE (t));
431 dump_next_stmt (di, t);
432 break;
434 default:
435 break;
438 return 0;