Merge from mainline
[official-gcc.git] / gcc / cp / dump.c
blob17a6b30b7058cd472a599f2914b409b6d5eaeec2
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 "c-dump.h"
28 static void dump_access
29 PARAMS ((dump_info_p, tree));
31 /* Dump a representation of the accessibility information associated
32 with T. */
34 static void
35 dump_access (di, t)
36 dump_info_p di;
37 tree t;
39 if (TREE_PROTECTED(t))
40 dump_string (di, "protected");
41 else if (TREE_PRIVATE(t))
42 dump_string (di, "private");
43 else
44 dump_string (di, "public");
47 int
48 cp_dump_tree (di, t)
49 dump_info_p di;
50 tree t;
52 enum tree_code code;
54 /* Figure out what kind of node this is. */
55 code = TREE_CODE (t);
57 if (DECL_P (t))
59 if (DECL_LANG_SPECIFIC (t) && DECL_LANGUAGE (t) != lang_cplusplus)
60 dump_string (di, language_to_string (DECL_LANGUAGE (t), 0));
63 switch (code)
65 case IDENTIFIER_NODE:
66 if (IDENTIFIER_OPNAME_P (t))
68 dump_string (di, "operator");
69 return 1;
71 else if (IDENTIFIER_TYPENAME_P (t))
73 dump_child ("tynm", TREE_TYPE (t));
74 return 1;
76 else if (t == anonymous_namespace_name)
78 dump_string (di, "unnamed");
79 return 1;
81 break;
83 case POINTER_TYPE:
84 if (TYPE_PTRMEM_P (t))
86 dump_string (di, "ptrmem");
87 dump_child ("ptd", TYPE_PTRMEM_POINTED_TO_TYPE (t));
88 dump_child ("cls", TYPE_PTRMEM_CLASS_TYPE (t));
89 return 1;
91 break;
93 case RECORD_TYPE:
94 case UNION_TYPE:
95 if (TYPE_PTRMEMFUNC_P (t))
97 dump_string (di, "ptrmem");
98 dump_child ("ptd", TYPE_PTRMEM_POINTED_TO_TYPE (t));
99 dump_child ("cls", TYPE_PTRMEM_CLASS_TYPE (t));
100 return 1;
103 dump_child ("vfld", TYPE_VFIELD (t));
105 if (!dump_flag (di, TDF_SLIM, t))
107 int i;
109 for (i = 0; i < CLASSTYPE_N_BASECLASSES (t); ++i)
111 tree base_binfo = BINFO_BASETYPE (TYPE_BINFO (t), i);
112 dump_child ("base", BINFO_TYPE (base_binfo));
113 if (TREE_VIA_VIRTUAL (base_binfo))
114 dump_string (di, "virtual");
115 dump_access (di, base_binfo);
118 break;
120 case FIELD_DECL:
121 dump_access (di, t);
122 break;
124 case FUNCTION_DECL:
125 if (!DECL_THUNK_P (t))
127 if (DECL_FUNCTION_MEMBER_P (t))
129 dump_string (di, "member");
130 dump_access (di, t);
132 if (DECL_CONSTRUCTOR_P (t))
133 dump_string (di, "constructor");
134 if (DECL_DESTRUCTOR_P (t))
135 dump_string (di, "destructor");
136 if (DECL_OVERLOADED_OPERATOR_P (t))
137 dump_string (di, "operator");
138 if (DECL_CONV_FN_P (t))
139 dump_string (di, "conversion");
140 if (DECL_GLOBAL_CTOR_P (t) || DECL_GLOBAL_DTOR_P (t))
142 if (DECL_GLOBAL_CTOR_P (t))
143 dump_string (di, "global init");
144 if (DECL_GLOBAL_DTOR_P (t))
145 dump_string (di, "global fini");
146 dump_int (di, "prio", GLOBAL_INIT_PRIORITY (t));
148 if (DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (t))
149 dump_string (di, "pseudo tmpl");
151 else
153 dump_string (di, "thunk");
154 dump_int (di, "dlta", THUNK_DELTA (t));
155 dump_child ("vcll", THUNK_VCALL_OFFSET (t));
156 dump_child ("fn", DECL_INITIAL (t));
158 break;
160 case NAMESPACE_DECL:
161 if (DECL_NAMESPACE_ALIAS (t))
162 dump_child ("alis", DECL_NAMESPACE_ALIAS (t));
163 else if (!dump_flag (di, TDF_SLIM, t))
164 dump_child ("dcls", cp_namespace_decls (t));
165 break;
167 case TEMPLATE_DECL:
168 dump_child ("rslt", DECL_TEMPLATE_RESULT (t));
169 dump_child ("inst", DECL_TEMPLATE_INSTANTIATIONS (t));
170 dump_child ("spcs", DECL_TEMPLATE_SPECIALIZATIONS (t));
171 dump_child ("prms", DECL_TEMPLATE_PARMS (t));
172 break;
174 case OVERLOAD:
175 dump_child ("crnt", OVL_CURRENT (t));
176 dump_child ("chan", OVL_CHAIN (t));
177 break;
179 case TRY_BLOCK:
180 dump_stmt (di, t);
181 if (CLEANUP_P (t))
182 dump_string (di, "cleanup");
183 dump_child ("body", TRY_STMTS (t));
184 dump_child ("hdlr", TRY_HANDLERS (t));
185 dump_next_stmt (di, t);
186 break;
188 case EH_SPEC_BLOCK:
189 dump_stmt (di, t);
190 dump_child ("body", EH_SPEC_STMTS (t));
191 dump_child ("raises", EH_SPEC_RAISES (t));
192 dump_next_stmt (di, t);
193 break;
195 case PTRMEM_CST:
196 dump_child ("clas", PTRMEM_CST_CLASS (t));
197 dump_child ("mbr", PTRMEM_CST_MEMBER (t));
198 break;
200 case THROW_EXPR:
201 /* These nodes are unary, but do not have code class `1'. */
202 dump_child ("op 0", TREE_OPERAND (t, 0));
203 break;
205 case AGGR_INIT_EXPR:
206 dump_int (di, "ctor", AGGR_INIT_VIA_CTOR_P (t));
207 dump_child ("fn", TREE_OPERAND (t, 0));
208 dump_child ("args", TREE_OPERAND (t, 1));
209 dump_child ("decl", TREE_OPERAND (t, 2));
210 break;
212 case CLEANUP_STMT:
213 dump_stmt (di, t);
214 dump_child ("decl", CLEANUP_DECL (t));
215 dump_child ("expr", CLEANUP_EXPR (t));
216 dump_next_stmt (di, t);
217 break;
219 case CTOR_STMT:
220 dump_stmt (di, t);
221 if (CTOR_BEGIN_P (t))
222 dump_string (di, "begn");
223 else
224 dump_string (di, "end");
225 dump_next_stmt (di, t);
226 break;
228 case HANDLER:
229 dump_stmt (di, t);
230 dump_child ("parm", HANDLER_PARMS (t));
231 dump_child ("body", HANDLER_BODY (t));
232 dump_next_stmt (di, t);
233 break;
235 case MUST_NOT_THROW_EXPR:
236 dump_stmt (di, t);
237 dump_child ("body", TREE_OPERAND (t, 0));
238 dump_next_stmt (di, t);
239 break;
241 case SUBOBJECT:
242 dump_stmt (di, t);
243 dump_child ("clnp", TREE_OPERAND (t, 0));
244 dump_next_stmt (di, t);
245 break;
247 case USING_STMT:
248 dump_stmt (di, t);
249 dump_child ("nmsp", USING_STMT_NAMESPACE (t));
250 dump_next_stmt (di, t);
251 break;
253 default:
254 break;
257 return 0;