OSDN Git Service

* dump.c (dump_access): New function.
[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       {
106         int i;
107
108         for (i = 0; i < CLASSTYPE_N_BASECLASSES (t); ++i)
109           {
110             tree base_binfo = BINFO_BASETYPE (TYPE_BINFO (t), i);
111             dump_child ("base", BINFO_TYPE (base_binfo));
112             if (TREE_VIA_VIRTUAL (base_binfo)) 
113               dump_string (di, "virtual");
114             dump_access (di, base_binfo);
115           }
116       }
117       break;
118
119     case FIELD_DECL:
120       dump_access (di, t);
121       break;
122
123     case FUNCTION_DECL:
124       if (!DECL_THUNK_P (t))
125         {
126           if (DECL_FUNCTION_MEMBER_P (t)) 
127             {
128               dump_string (di, "member");
129               dump_access (di, t);
130             }
131           if (DECL_CONSTRUCTOR_P (t))
132             dump_string (di, "constructor");
133           if (DECL_DESTRUCTOR_P (t))
134             dump_string (di, "destructor");
135           if (DECL_OVERLOADED_OPERATOR_P (t))
136             dump_string (di, "operator");
137           if (DECL_CONV_FN_P (t))
138             dump_string (di, "conversion");
139           if (DECL_GLOBAL_CTOR_P (t) || DECL_GLOBAL_DTOR_P (t))
140             {
141               if (DECL_GLOBAL_CTOR_P (t))
142                 dump_string (di, "global init");
143               if (DECL_GLOBAL_DTOR_P (t))
144                 dump_string (di, "global fini");
145               dump_int (di, "prio", GLOBAL_INIT_PRIORITY (t));
146             }
147           if (DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (t))
148             dump_string (di, "pseudo tmpl");
149         }
150       else
151         {
152           dump_string (di, "thunk");
153           dump_int (di, "dlta", THUNK_DELTA (t));
154           dump_child ("vcll", THUNK_VCALL_OFFSET (t));
155           dump_child ("fn", DECL_INITIAL (t));
156         }
157       break;
158
159     case NAMESPACE_DECL:
160       /* The fake `::std' namespace does not have DECL_LANG_SPECIFIC,
161          and therefore many other macros do not work on it.  */
162       if (t == fake_std_node)
163         break;
164       if (DECL_NAMESPACE_ALIAS (t))
165         dump_child ("alis", DECL_NAMESPACE_ALIAS (t));
166       else
167         dump_child ("dcls", cp_namespace_decls (t));
168       break;
169
170     case TEMPLATE_DECL:
171       dump_child ("rslt", DECL_TEMPLATE_RESULT (t));
172       dump_child ("inst", DECL_TEMPLATE_INSTANTIATIONS (t));
173       dump_child ("spcs", DECL_TEMPLATE_SPECIALIZATIONS (t));
174       dump_child ("prms", DECL_TEMPLATE_PARMS (t));
175       break;
176
177     case OVERLOAD:
178       dump_child ("crnt", OVL_CURRENT (t));
179       dump_child ("chan", OVL_CHAIN (t));
180       break;
181
182     case TRY_BLOCK:
183       dump_stmt (di, t);
184       if (CLEANUP_P (t))
185         dump_string (di, "cleanup");
186       dump_child ("body", TRY_STMTS (t));
187       dump_child ("hdlr", TRY_HANDLERS (t));
188       dump_next_stmt (di, t);
189       break;
190
191     case PTRMEM_CST:
192       dump_child ("clas", PTRMEM_CST_CLASS (t));
193       dump_child ("mbr", PTRMEM_CST_MEMBER (t));
194       break;
195
196     case THROW_EXPR:
197       /* These nodes are unary, but do not have code class `1'.  */
198       dump_child ("op 0", TREE_OPERAND (t, 0));
199       break;
200
201     case AGGR_INIT_EXPR:
202       dump_int (di, "ctor", AGGR_INIT_VIA_CTOR_P (t));
203       dump_child ("fn", TREE_OPERAND (t, 0));
204       dump_child ("args", TREE_OPERAND (t, 1));
205       dump_child ("decl", TREE_OPERAND (t, 2));
206       break;
207       
208     case CLEANUP_STMT:
209       dump_stmt (di, t);
210       dump_child ("decl", CLEANUP_DECL (t));
211       dump_child ("expr", CLEANUP_EXPR (t));
212       dump_next_stmt (di, t);
213       break;
214
215     case CTOR_STMT:
216       dump_stmt (di, t);
217       if (CTOR_BEGIN_P (t))
218         dump_string (di, "begn");
219       else
220         dump_string (di, "end");
221       dump_next_stmt (di, t);
222       break;
223
224     case HANDLER:
225       dump_stmt (di, t);
226       dump_child ("body", HANDLER_BODY (t));
227       dump_next_stmt (di, t);
228       break;
229
230     case SUBOBJECT:
231       dump_stmt (di, t);
232       dump_child ("clnp", TREE_OPERAND (t, 0));
233       dump_next_stmt (di, t);
234       break;
235
236     case START_CATCH_STMT:
237       dump_stmt (di, t);
238       queue_and_dump_type (di, t);
239       dump_next_stmt (di, t);
240       break;
241
242     default:
243       break;
244     }
245
246   return 0;
247 }
248