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