OSDN Git Service

* c-common.c (c_alignof, c_alignof_expr): Move here...
[pf3gnuchains/gcc-fork.git] / gcc / cp / dump.c
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>
4
5 This file is part of GNU CC.
6
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.
11
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.
16
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.  */
21
22 #include "config.h"
23 #include "system.h"
24 #include "tree.h"
25 #include "cp-tree.h"
26 #include "c-dump.h"
27
28 static void dump_access
29   PARAMS ((dump_info_p, tree));
30
31 /* Dump a representation of the accessibility information associated
32    with T.  */
33
34 static void
35 dump_access (di, t)
36      dump_info_p di;
37      tree t;
38 {
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");
45 }
46
47 int
48 cp_dump_tree (di, t)
49      dump_info_p di;
50      tree t;
51 {
52   enum tree_code code;
53
54   /* Figure out what kind of node this is.  */
55   code = TREE_CODE (t);
56
57   if (DECL_P (t))
58     {
59       if (DECL_LANG_SPECIFIC (t) && DECL_LANGUAGE (t) != lang_cplusplus)
60         dump_string (di, language_to_string (DECL_LANGUAGE (t), 0));
61     }
62
63   switch (code)
64     {
65     case IDENTIFIER_NODE:
66       if (IDENTIFIER_OPNAME_P (t))
67         {
68           dump_string (di, "operator");
69           return 1;
70         }
71       else if (IDENTIFIER_TYPENAME_P (t))
72         {
73           dump_child ("tynm", TREE_TYPE (t));
74           return 1;
75         }
76       else if (t == anonymous_namespace_name)
77         {
78           dump_string (di, "unnamed");
79           return 1;
80         }
81       break;
82
83     case POINTER_TYPE:
84       if (TYPE_PTRMEM_P (t))
85         {
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;
90         }
91       break;
92
93     case RECORD_TYPE:
94     case UNION_TYPE:
95       if (TYPE_PTRMEMFUNC_P (t))
96         {
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;
101         }
102
103       dump_child ("vfld", TYPE_VFIELD (t));
104
105       if (!dump_flag (di, TDF_SLIM, t))
106         {
107           int i;
108           
109           for (i = 0; i < CLASSTYPE_N_BASECLASSES (t); ++i)
110             {
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);
116             }
117         }
118       break;
119
120     case FIELD_DECL:
121       dump_access (di, t);
122       break;
123
124     case FUNCTION_DECL:
125       if (!DECL_THUNK_P (t))
126         {
127           if (DECL_FUNCTION_MEMBER_P (t)) 
128             {
129               dump_string (di, "member");
130               dump_access (di, t);
131             }
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))
141             {
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));
147             }
148           if (DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (t))
149             dump_string (di, "pseudo tmpl");
150         }
151       else
152         {
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));
157         }
158       break;
159
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;
166
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;
173
174     case OVERLOAD:
175       dump_child ("crnt", OVL_CURRENT (t));
176       dump_child ("chan", OVL_CHAIN (t));
177       break;
178
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;
187
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;
194
195     case PTRMEM_CST:
196       dump_child ("clas", PTRMEM_CST_CLASS (t));
197       dump_child ("mbr", PTRMEM_CST_MEMBER (t));
198       break;
199
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;
204
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;
211       
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;
218
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;
227
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;
234
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;
240
241     case SUBOBJECT:
242       dump_stmt (di, t);
243       dump_child ("clnp", TREE_OPERAND (t, 0));
244       dump_next_stmt (di, t);
245       break;
246
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;
252       
253     default:
254       break;
255     }
256
257   return 0;
258 }
259