aboutsummaryrefslogtreecommitdiff
path: root/gcc/objc/objc-dmp-tree.c
blob: 14d9dabfca15836f50fa57269bcba772115cb53a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
/* APPLE LOCAL file new tree dump */
/* Common condensed tree display routines specific for objc and objc++.
   Copyright (C) 2001  Free Software Foundation, Inc.
   Contributed by Ira L. Ruben (ira@apple.com)

This file is part of GNU CC.

GNU CC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.

GNU CC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with GNU CC; see the file COPYING.  If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.  */

/* The Objective-C++ and Objective-C tree dump handling is piggybacked
   on either C++ or C tree dump handling.  */
   
#ifdef OBJCPLUS
#include "cp-dmp-tree.c"
#else
#include "c-dmp-tree.c"
#endif

#include "objc-act.h"

int objc_dump_tree_p (FILE *, const char *, tree, int);
lang_dump_tree_p_t objc_prev_lang_dump_tree_p = NULL;

#define DEFTREECODE(SYM, NAME, TYPE, LENGTH) \
static void print_ ## SYM (FILE *file, const char *annotation, tree node, int indent);
#include "objc-tree.def"
#undef DEFTREECODE

/*-------------------------------------------------------------------*/

static void
print_CLASS_INTERFACE_TYPE (file, annotation, node, indent)
     FILE *file ATTRIBUTE_UNUSED;
     const char *annotation ATTRIBUTE_UNUSED;
     tree node ATTRIBUTE_UNUSED;
     int indent ATTRIBUTE_UNUSED;
{
  tree n;
  
  if (CLASS_SUPER_NAME (node))		
    fprintf (file, " super-name=%s",
  		  IDENTIFIER_POINTER (CLASS_SUPER_NAME (node)));
  /* The ivars for the class are accessible either via
     CLASS_IVARS(node), or as fields of the
     underlying C struct (itself accessible via
     CLASS_STATIC_TEMPLATE(node).  */
  fprintf (file, " ivars=");
  fprintf (file, HOST_PTR_PRINTF,
  		HOST_PTR_PRINTF_VALUE (CLASS_IVARS (node)));
  /* zlaski 2001-Jul-26:  not sure what the raw ivars are for...  */		
  fprintf (file, " raw_ivars=");
  fprintf (file, HOST_PTR_PRINTF,
  		HOST_PTR_PRINTF_VALUE (CLASS_RAW_IVARS (node)));
  /* The "own ivars" list contains just the ivars defined by this
     class (i.e., not inherited).  */		
  fprintf (file, " own_ivars=");
  fprintf (file, HOST_PTR_PRINTF,
  		HOST_PTR_PRINTF_VALUE (CLASS_OWN_IVARS (node)));

  print_type (file, annotation, node, indent);
  (void)node_seen (node, TRUE);

  /* print out names of protocols, categories.  */
  for (n = CLASS_PROTOCOL_LIST (node); n; n = TREE_CHAIN (n))
    print_type (file, NULL, TREE_VALUE (n), indent + INDENT);
  for (n = CLASS_CATEGORY_LIST (node); n; n = TREE_CHAIN (n))
    print_type (file, NULL, TREE_VALUE (n), indent + INDENT);
    
  /* Print the underlying RECORD_TYPE node, with fields.  */
  dump_tree (file, annotation, CLASS_STATIC_TEMPLATE (node),
	     indent + INDENT);
  /* Print out names of class and instance methods.  */	     
  for (n = CLASS_CLS_METHODS (node); n; n = TREE_CHAIN (n))
    dump_tree (file, NULL, n, indent + INDENT);
  for (n = CLASS_NST_METHODS (node); n; n = TREE_CHAIN (n))
    dump_tree (file, NULL, n, indent + INDENT);
}

static void
print_CLASS_IMPLEMENTATION_TYPE (file, annotation, node, indent)
     FILE *file ATTRIBUTE_UNUSED;
     const char *annotation ATTRIBUTE_UNUSED;
     tree node ATTRIBUTE_UNUSED;
     int indent ATTRIBUTE_UNUSED;
{
  print_CLASS_INTERFACE_TYPE (file, annotation, node, indent);
}

static void
print_CATEGORY_INTERFACE_TYPE (file, annotation, node, indent)
     FILE *file ATTRIBUTE_UNUSED;
     const char *annotation ATTRIBUTE_UNUSED;
     tree node ATTRIBUTE_UNUSED;
     int indent ATTRIBUTE_UNUSED;
{
  tree n;
  
  fprintf (file, " cat-name=%s",
  		  IDENTIFIER_POINTER (CLASS_SUPER_NAME (node)));
  print_type (file, annotation, node, indent);
  (void)node_seen (node, TRUE);
  
  for (n = CLASS_PROTOCOL_LIST (node); n; n = TREE_CHAIN (n))
    dump_tree (file, NULL, TREE_VALUE (n), indent + INDENT);
  /* Print out names of class and instance methods.  */	     
  for (n = CLASS_CLS_METHODS (node); n; n = TREE_CHAIN (n))
    dump_tree (file, NULL, n, indent + INDENT);
  for (n = CLASS_NST_METHODS (node); n; n = TREE_CHAIN (n))
    dump_tree (file, NULL, n, indent + INDENT);
}

static void
print_CATEGORY_IMPLEMENTATION_TYPE (file, annotation, node, indent)
     FILE *file ATTRIBUTE_UNUSED;
     const char *annotation ATTRIBUTE_UNUSED;
     tree node ATTRIBUTE_UNUSED;
     int indent ATTRIBUTE_UNUSED;
{
  print_CATEGORY_INTERFACE_TYPE (file, annotation, node, indent);
}

static void
print_PROTOCOL_INTERFACE_TYPE (file, annotation, node, indent)
     FILE *file ATTRIBUTE_UNUSED;
     const char *annotation ATTRIBUTE_UNUSED;
     tree node ATTRIBUTE_UNUSED;
     int indent ATTRIBUTE_UNUSED;
{
  tree n;
  
  fprintf (file, " fwd-decl=");
  fprintf (file, HOST_PTR_PRINTF,
  		HOST_PTR_PRINTF_VALUE (PROTOCOL_FORWARD_DECL (node)));
  fprintf (file, " defined=%d", PROTOCOL_DEFINED (node));

  print_type (file, annotation, node, indent);
  (void)node_seen (node, TRUE);
  
  /* print superprotocols, if any.  */
  for (n = PROTOCOL_LIST (node); n; n = TREE_CHAIN (n))
    dump_tree (file, NULL, TREE_VALUE (n), indent + INDENT);
    
  /* Print out names of class and instance methods.  */	     
  for (n = PROTOCOL_CLS_METHODS (node); n; n = TREE_CHAIN (n))
    dump_tree (file, NULL, n, indent + INDENT);
  for (n = PROTOCOL_NST_METHODS (node); n; n = TREE_CHAIN (n))
    dump_tree (file, NULL, n, indent + INDENT);
}

static void
print_KEYWORD_DECL (file, annotation, node, indent)
     FILE *file ATTRIBUTE_UNUSED;
     const char *annotation ATTRIBUTE_UNUSED;
     tree node ATTRIBUTE_UNUSED;
     int indent ATTRIBUTE_UNUSED;
{
  fprintf (file, " key=%s",
  		IDENTIFIER_POINTER (KEYWORD_KEY_NAME (node)));
  fprintf (file, " arg=%s",
  		IDENTIFIER_POINTER (KEYWORD_ARG_NAME (node)));
		
  print_type (file, annotation, node, indent);
  (void)node_seen (node, TRUE);
}

static void
print_INSTANCE_METHOD_DECL (file, annotation, node, indent)
     FILE *file ATTRIBUTE_UNUSED;
     const char *annotation ATTRIBUTE_UNUSED;
     tree node ATTRIBUTE_UNUSED;
     int indent ATTRIBUTE_UNUSED;
{
  fprintf (file, " args=");
  fprintf (file, HOST_PTR_PRINTF,
  		HOST_PTR_PRINTF_VALUE (METHOD_SEL_ARGS (node)));
  fprintf (file, " addl=");
  fprintf (file, HOST_PTR_PRINTF,
  		HOST_PTR_PRINTF_VALUE (METHOD_ADD_ARGS (node)));
  if (METHOD_ENCODING (node))		
    fprintf (file, " encode=%s",
  		  IDENTIFIER_POINTER (METHOD_ENCODING (node)));

  print_decl (file, annotation, node, indent);
  
  /* Print the underlying FUNCTION_DECL node.  */
  if (METHOD_DEFINITION (node))
    dump_tree (file, annotation, METHOD_DEFINITION (node),
  	       indent + INDENT);
  
  (void)node_seen (node, TRUE);
}

static void
print_CLASS_METHOD_DECL (file, annotation, node, indent)
     FILE *file ATTRIBUTE_UNUSED;
     const char *annotation ATTRIBUTE_UNUSED;
     tree node ATTRIBUTE_UNUSED;
     int indent ATTRIBUTE_UNUSED;
{
  print_INSTANCE_METHOD_DECL (file, annotation, node, indent);
}

static void
print_CLASS_REFERENCE_EXPR (file, annotation, node, indent)
     FILE *file ATTRIBUTE_UNUSED;
     const char *annotation ATTRIBUTE_UNUSED;
     tree node ATTRIBUTE_UNUSED;
     int indent ATTRIBUTE_UNUSED;
{
  fprintf (file, " ident=");
  fprintf (file, HOST_PTR_PRINTF,
  		HOST_PTR_PRINTF_VALUE (TREE_OPERAND (node, 0)));
  (void)node_seen (node, TRUE);
}

static void
print_MESSAGE_SEND_EXPR (file, annotation, node, indent)
     FILE *file ATTRIBUTE_UNUSED;
     const char *annotation ATTRIBUTE_UNUSED;
     tree node ATTRIBUTE_UNUSED;
     int indent ATTRIBUTE_UNUSED;
{
  fprintf (file, " receiver=");
  fprintf (file, HOST_PTR_PRINTF,
  		HOST_PTR_PRINTF_VALUE (TREE_OPERAND (node, 0)));
  fprintf (file, " sel_name=%s",
  		IDENTIFIER_POINTER (TREE_OPERAND (node, 1)));
  fprintf (file, " args=");
  fprintf (file, HOST_PTR_PRINTF,
  		HOST_PTR_PRINTF_VALUE (TREE_OPERAND (node, 2)));
  (void)node_seen (node, TRUE);
}

/*-------------------------------------------------------------------*/

int
objc_dump_tree_p (file, annotation, node, indent)
     FILE *file;
     const char *annotation ATTRIBUTE_UNUSED;
     tree node;
     int indent;
{
   switch (TREE_CODE (node)) 
   {
#define DEFTREECODE(SYM, NAME, TYPE, LENGTH) \
     	   case SYM: print_ ## SYM (file, annotation, node, indent); break;
#include "objc-tree.def"
#undef DEFTREECODE
   default:
     return objc_prev_lang_dump_tree_p (file, annotation, node, indent);
   }
   
   return 1;
}


/*-------------------------------------------------------------------*/

#if 0

cd $gcc3/gcc; \
cc -no-cpp-precomp -c  -DIN_GCC  -g \
  -W -Wall -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -Wtraditional -pedantic -Wno-long-long \
  -DHAVE_CONFIG_H \
  -I$gcc3obj \
  -I. \
  -Iobjc \
  -Iconfig \
  -I../include \
  objc/objc-dmp-tree.c -o ~/tmp.o -w 

#endif