annotate gcc/c/c-aux-info.c @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* Generate information regarding function declarations and definitions based
kono
parents:
diff changeset
2 on information stored in GCC's tree structure. This code implements the
kono
parents:
diff changeset
3 -aux-info option.
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
4 Copyright (C) 1989-2018 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
5 Contributed by Ron Guilmette (rfg@segfault.us.com).
kono
parents:
diff changeset
6
kono
parents:
diff changeset
7 This file is part of GCC.
kono
parents:
diff changeset
8
kono
parents:
diff changeset
9 GCC is free software; you can redistribute it and/or modify it under
kono
parents:
diff changeset
10 the terms of the GNU General Public License as published by the Free
kono
parents:
diff changeset
11 Software Foundation; either version 3, or (at your option) any later
kono
parents:
diff changeset
12 version.
kono
parents:
diff changeset
13
kono
parents:
diff changeset
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
kono
parents:
diff changeset
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
kono
parents:
diff changeset
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
kono
parents:
diff changeset
17 for more details.
kono
parents:
diff changeset
18
kono
parents:
diff changeset
19 You should have received a copy of the GNU General Public License
kono
parents:
diff changeset
20 along with GCC; see the file COPYING3. If not see
kono
parents:
diff changeset
21 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
22
kono
parents:
diff changeset
23 #include "config.h"
kono
parents:
diff changeset
24 #include "system.h"
kono
parents:
diff changeset
25 #include "coretypes.h"
kono
parents:
diff changeset
26 #include "tm.h"
kono
parents:
diff changeset
27 #include "c-tree.h"
kono
parents:
diff changeset
28
kono
parents:
diff changeset
29 enum formals_style {
kono
parents:
diff changeset
30 ansi,
kono
parents:
diff changeset
31 k_and_r_names,
kono
parents:
diff changeset
32 k_and_r_decls
kono
parents:
diff changeset
33 };
kono
parents:
diff changeset
34
kono
parents:
diff changeset
35
kono
parents:
diff changeset
36 static const char *data_type;
kono
parents:
diff changeset
37
kono
parents:
diff changeset
38 static char *affix_data_type (const char *) ATTRIBUTE_MALLOC;
kono
parents:
diff changeset
39 static const char *gen_formal_list_for_type (tree, formals_style);
kono
parents:
diff changeset
40 static const char *gen_formal_list_for_func_def (tree, formals_style);
kono
parents:
diff changeset
41 static const char *gen_type (const char *, tree, formals_style);
kono
parents:
diff changeset
42 static const char *gen_decl (tree, int, formals_style);
kono
parents:
diff changeset
43
kono
parents:
diff changeset
44 /* Given a string representing an entire type or an entire declaration
kono
parents:
diff changeset
45 which only lacks the actual "data-type" specifier (at its left end),
kono
parents:
diff changeset
46 affix the data-type specifier to the left end of the given type
kono
parents:
diff changeset
47 specification or object declaration.
kono
parents:
diff changeset
48
kono
parents:
diff changeset
49 Because of C language weirdness, the data-type specifier (which normally
kono
parents:
diff changeset
50 goes in at the very left end) may have to be slipped in just to the
kono
parents:
diff changeset
51 right of any leading "const" or "volatile" qualifiers (there may be more
kono
parents:
diff changeset
52 than one). Actually this may not be strictly necessary because it seems
kono
parents:
diff changeset
53 that GCC (at least) accepts `<data-type> const foo;' and treats it the
kono
parents:
diff changeset
54 same as `const <data-type> foo;' but people are accustomed to seeing
kono
parents:
diff changeset
55 `const char *foo;' and *not* `char const *foo;' so we try to create types
kono
parents:
diff changeset
56 that look as expected. */
kono
parents:
diff changeset
57
kono
parents:
diff changeset
58 static char *
kono
parents:
diff changeset
59 affix_data_type (const char *param)
kono
parents:
diff changeset
60 {
kono
parents:
diff changeset
61 char *const type_or_decl = ASTRDUP (param);
kono
parents:
diff changeset
62 char *p = type_or_decl;
kono
parents:
diff changeset
63 char *qualifiers_then_data_type;
kono
parents:
diff changeset
64 char saved;
kono
parents:
diff changeset
65
kono
parents:
diff changeset
66 /* Skip as many leading const's or volatile's as there are. */
kono
parents:
diff changeset
67
kono
parents:
diff changeset
68 for (;;)
kono
parents:
diff changeset
69 {
kono
parents:
diff changeset
70 if (!strncmp (p, "volatile ", 9))
kono
parents:
diff changeset
71 {
kono
parents:
diff changeset
72 p += 9;
kono
parents:
diff changeset
73 continue;
kono
parents:
diff changeset
74 }
kono
parents:
diff changeset
75 if (!strncmp (p, "const ", 6))
kono
parents:
diff changeset
76 {
kono
parents:
diff changeset
77 p += 6;
kono
parents:
diff changeset
78 continue;
kono
parents:
diff changeset
79 }
kono
parents:
diff changeset
80 break;
kono
parents:
diff changeset
81 }
kono
parents:
diff changeset
82
kono
parents:
diff changeset
83 /* p now points to the place where we can insert the data type. We have to
kono
parents:
diff changeset
84 add a blank after the data-type of course. */
kono
parents:
diff changeset
85
kono
parents:
diff changeset
86 if (p == type_or_decl)
kono
parents:
diff changeset
87 return concat (data_type, " ", type_or_decl, NULL);
kono
parents:
diff changeset
88
kono
parents:
diff changeset
89 saved = *p;
kono
parents:
diff changeset
90 *p = '\0';
kono
parents:
diff changeset
91 qualifiers_then_data_type = concat (type_or_decl, data_type, NULL);
kono
parents:
diff changeset
92 *p = saved;
kono
parents:
diff changeset
93 return reconcat (qualifiers_then_data_type,
kono
parents:
diff changeset
94 qualifiers_then_data_type, " ", p, NULL);
kono
parents:
diff changeset
95 }
kono
parents:
diff changeset
96
kono
parents:
diff changeset
97 /* Given a tree node which represents some "function type", generate the
kono
parents:
diff changeset
98 source code version of a formal parameter list (of some given style) for
kono
parents:
diff changeset
99 this function type. Return the whole formal parameter list (including
kono
parents:
diff changeset
100 a pair of surrounding parens) as a string. Note that if the style
kono
parents:
diff changeset
101 we are currently aiming for is non-ansi, then we just return a pair
kono
parents:
diff changeset
102 of empty parens here. */
kono
parents:
diff changeset
103
kono
parents:
diff changeset
104 static const char *
kono
parents:
diff changeset
105 gen_formal_list_for_type (tree fntype, formals_style style)
kono
parents:
diff changeset
106 {
kono
parents:
diff changeset
107 const char *formal_list = "";
kono
parents:
diff changeset
108 tree formal_type;
kono
parents:
diff changeset
109
kono
parents:
diff changeset
110 if (style != ansi)
kono
parents:
diff changeset
111 return "()";
kono
parents:
diff changeset
112
kono
parents:
diff changeset
113 formal_type = TYPE_ARG_TYPES (fntype);
kono
parents:
diff changeset
114 while (formal_type && TREE_VALUE (formal_type) != void_type_node)
kono
parents:
diff changeset
115 {
kono
parents:
diff changeset
116 const char *this_type;
kono
parents:
diff changeset
117
kono
parents:
diff changeset
118 if (*formal_list)
kono
parents:
diff changeset
119 formal_list = concat (formal_list, ", ", NULL);
kono
parents:
diff changeset
120
kono
parents:
diff changeset
121 this_type = gen_type ("", TREE_VALUE (formal_type), ansi);
kono
parents:
diff changeset
122 formal_list
kono
parents:
diff changeset
123 = ((strlen (this_type))
kono
parents:
diff changeset
124 ? concat (formal_list, affix_data_type (this_type), NULL)
kono
parents:
diff changeset
125 : concat (formal_list, data_type, NULL));
kono
parents:
diff changeset
126
kono
parents:
diff changeset
127 formal_type = TREE_CHAIN (formal_type);
kono
parents:
diff changeset
128 }
kono
parents:
diff changeset
129
kono
parents:
diff changeset
130 /* If we got to here, then we are trying to generate an ANSI style formal
kono
parents:
diff changeset
131 parameters list.
kono
parents:
diff changeset
132
kono
parents:
diff changeset
133 New style prototyped ANSI formal parameter lists should in theory always
kono
parents:
diff changeset
134 contain some stuff between the opening and closing parens, even if it is
kono
parents:
diff changeset
135 only "void".
kono
parents:
diff changeset
136
kono
parents:
diff changeset
137 The brutal truth though is that there is lots of old K&R code out there
kono
parents:
diff changeset
138 which contains declarations of "pointer-to-function" parameters and
kono
parents:
diff changeset
139 these almost never have fully specified formal parameter lists associated
kono
parents:
diff changeset
140 with them. That is, the pointer-to-function parameters are declared
kono
parents:
diff changeset
141 with just empty parameter lists.
kono
parents:
diff changeset
142
kono
parents:
diff changeset
143 In cases such as these, protoize should really insert *something* into
kono
parents:
diff changeset
144 the vacant parameter lists, but what? It has no basis on which to insert
kono
parents:
diff changeset
145 anything in particular.
kono
parents:
diff changeset
146
kono
parents:
diff changeset
147 Here, we make life easy for protoize by trying to distinguish between
kono
parents:
diff changeset
148 K&R empty parameter lists and new-style prototyped parameter lists
kono
parents:
diff changeset
149 that actually contain "void". In the latter case we (obviously) want
kono
parents:
diff changeset
150 to output the "void" verbatim, and that what we do. In the former case,
kono
parents:
diff changeset
151 we do our best to give protoize something nice to insert.
kono
parents:
diff changeset
152
kono
parents:
diff changeset
153 This "something nice" should be something that is still valid (when
kono
parents:
diff changeset
154 re-compiled) but something that can clearly indicate to the user that
kono
parents:
diff changeset
155 more typing information (for the parameter list) should be added (by
kono
parents:
diff changeset
156 hand) at some convenient moment.
kono
parents:
diff changeset
157
kono
parents:
diff changeset
158 The string chosen here is a comment with question marks in it. */
kono
parents:
diff changeset
159
kono
parents:
diff changeset
160 if (!*formal_list)
kono
parents:
diff changeset
161 {
kono
parents:
diff changeset
162 if (prototype_p (fntype))
kono
parents:
diff changeset
163 /* assert (TREE_VALUE (TYPE_ARG_TYPES (fntype)) == void_type_node); */
kono
parents:
diff changeset
164 formal_list = "void";
kono
parents:
diff changeset
165 else
kono
parents:
diff changeset
166 formal_list = "/* ??? */";
kono
parents:
diff changeset
167 }
kono
parents:
diff changeset
168 else
kono
parents:
diff changeset
169 {
kono
parents:
diff changeset
170 /* If there were at least some parameters, and if the formals-types-list
kono
parents:
diff changeset
171 petered out to a NULL (i.e. without being terminated by a
kono
parents:
diff changeset
172 void_type_node) then we need to tack on an ellipsis. */
kono
parents:
diff changeset
173 if (!formal_type)
kono
parents:
diff changeset
174 formal_list = concat (formal_list, ", ...", NULL);
kono
parents:
diff changeset
175 }
kono
parents:
diff changeset
176
kono
parents:
diff changeset
177 return concat (" (", formal_list, ")", NULL);
kono
parents:
diff changeset
178 }
kono
parents:
diff changeset
179
kono
parents:
diff changeset
180 /* Generate a parameter list for a function definition (in some given style).
kono
parents:
diff changeset
181
kono
parents:
diff changeset
182 Note that this routine has to be separate (and different) from the code that
kono
parents:
diff changeset
183 generates the prototype parameter lists for function declarations, because
kono
parents:
diff changeset
184 in the case of a function declaration, all we have to go on is a tree node
kono
parents:
diff changeset
185 representing the function's own "function type". This can tell us the types
kono
parents:
diff changeset
186 of all of the formal parameters for the function, but it cannot tell us the
kono
parents:
diff changeset
187 actual *names* of each of the formal parameters. We need to output those
kono
parents:
diff changeset
188 parameter names for each function definition.
kono
parents:
diff changeset
189
kono
parents:
diff changeset
190 This routine gets a pointer to a tree node which represents the actual
kono
parents:
diff changeset
191 declaration of the given function, and this DECL node has a list of formal
kono
parents:
diff changeset
192 parameter (variable) declarations attached to it. These formal parameter
kono
parents:
diff changeset
193 (variable) declaration nodes give us the actual names of the formal
kono
parents:
diff changeset
194 parameters for the given function definition.
kono
parents:
diff changeset
195
kono
parents:
diff changeset
196 This routine returns a string which is the source form for the entire
kono
parents:
diff changeset
197 function formal parameter list. */
kono
parents:
diff changeset
198
kono
parents:
diff changeset
199 static const char *
kono
parents:
diff changeset
200 gen_formal_list_for_func_def (tree fndecl, formals_style style)
kono
parents:
diff changeset
201 {
kono
parents:
diff changeset
202 const char *formal_list = "";
kono
parents:
diff changeset
203 tree formal_decl;
kono
parents:
diff changeset
204
kono
parents:
diff changeset
205 formal_decl = DECL_ARGUMENTS (fndecl);
kono
parents:
diff changeset
206 while (formal_decl)
kono
parents:
diff changeset
207 {
kono
parents:
diff changeset
208 const char *this_formal;
kono
parents:
diff changeset
209
kono
parents:
diff changeset
210 if (*formal_list && ((style == ansi) || (style == k_and_r_names)))
kono
parents:
diff changeset
211 formal_list = concat (formal_list, ", ", NULL);
kono
parents:
diff changeset
212 this_formal = gen_decl (formal_decl, 0, style);
kono
parents:
diff changeset
213 if (style == k_and_r_decls)
kono
parents:
diff changeset
214 formal_list = concat (formal_list, this_formal, "; ", NULL);
kono
parents:
diff changeset
215 else
kono
parents:
diff changeset
216 formal_list = concat (formal_list, this_formal, NULL);
kono
parents:
diff changeset
217 formal_decl = TREE_CHAIN (formal_decl);
kono
parents:
diff changeset
218 }
kono
parents:
diff changeset
219 if (style == ansi)
kono
parents:
diff changeset
220 {
kono
parents:
diff changeset
221 if (!DECL_ARGUMENTS (fndecl))
kono
parents:
diff changeset
222 formal_list = concat (formal_list, "void", NULL);
kono
parents:
diff changeset
223 if (stdarg_p (TREE_TYPE (fndecl)))
kono
parents:
diff changeset
224 formal_list = concat (formal_list, ", ...", NULL);
kono
parents:
diff changeset
225 }
kono
parents:
diff changeset
226 if ((style == ansi) || (style == k_and_r_names))
kono
parents:
diff changeset
227 formal_list = concat (" (", formal_list, ")", NULL);
kono
parents:
diff changeset
228 return formal_list;
kono
parents:
diff changeset
229 }
kono
parents:
diff changeset
230
kono
parents:
diff changeset
231 /* Generate a string which is the source code form for a given type (t). This
kono
parents:
diff changeset
232 routine is ugly and complex because the C syntax for declarations is ugly
kono
parents:
diff changeset
233 and complex. This routine is straightforward so long as *no* pointer types,
kono
parents:
diff changeset
234 array types, or function types are involved.
kono
parents:
diff changeset
235
kono
parents:
diff changeset
236 In the simple cases, this routine will return the (string) value which was
kono
parents:
diff changeset
237 passed in as the "ret_val" argument. Usually, this starts out either as an
kono
parents:
diff changeset
238 empty string, or as the name of the declared item (i.e. the formal function
kono
parents:
diff changeset
239 parameter variable).
kono
parents:
diff changeset
240
kono
parents:
diff changeset
241 This routine will also return with the global variable "data_type" set to
kono
parents:
diff changeset
242 some string value which is the "basic" data-type of the given complete type.
kono
parents:
diff changeset
243 This "data_type" string can be concatenated onto the front of the returned
kono
parents:
diff changeset
244 string after this routine returns to its caller.
kono
parents:
diff changeset
245
kono
parents:
diff changeset
246 In complicated cases involving pointer types, array types, or function
kono
parents:
diff changeset
247 types, the C declaration syntax requires an "inside out" approach, i.e. if
kono
parents:
diff changeset
248 you have a type which is a "pointer-to-function" type, you need to handle
kono
parents:
diff changeset
249 the "pointer" part first, but it also has to be "innermost" (relative to
kono
parents:
diff changeset
250 the declaration stuff for the "function" type). Thus, is this case, you
kono
parents:
diff changeset
251 must prepend a "(*" and append a ")" to the name of the item (i.e. formal
kono
parents:
diff changeset
252 variable). Then you must append and prepend the other info for the
kono
parents:
diff changeset
253 "function type" part of the overall type.
kono
parents:
diff changeset
254
kono
parents:
diff changeset
255 To handle the "innermost precedence" rules of complicated C declarators, we
kono
parents:
diff changeset
256 do the following (in this routine). The input parameter called "ret_val"
kono
parents:
diff changeset
257 is treated as a "seed". Each time gen_type is called (perhaps recursively)
kono
parents:
diff changeset
258 some additional strings may be appended or prepended (or both) to the "seed"
kono
parents:
diff changeset
259 string. If yet another (lower) level of the GCC tree exists for the given
kono
parents:
diff changeset
260 type (as in the case of a pointer type, an array type, or a function type)
kono
parents:
diff changeset
261 then the (wrapped) seed is passed to a (recursive) invocation of gen_type()
kono
parents:
diff changeset
262 this recursive invocation may again "wrap" the (new) seed with yet more
kono
parents:
diff changeset
263 declarator stuff, by appending, prepending (or both). By the time the
kono
parents:
diff changeset
264 recursion bottoms out, the "seed value" at that point will have a value
kono
parents:
diff changeset
265 which is (almost) the complete source version of the declarator (except
kono
parents:
diff changeset
266 for the data_type info). Thus, this deepest "seed" value is simply passed
kono
parents:
diff changeset
267 back up through all of the recursive calls until it is given (as the return
kono
parents:
diff changeset
268 value) to the initial caller of the gen_type() routine. All that remains
kono
parents:
diff changeset
269 to do at this point is for the initial caller to prepend the "data_type"
kono
parents:
diff changeset
270 string onto the returned "seed". */
kono
parents:
diff changeset
271
kono
parents:
diff changeset
272 static const char *
kono
parents:
diff changeset
273 gen_type (const char *ret_val, tree t, formals_style style)
kono
parents:
diff changeset
274 {
kono
parents:
diff changeset
275 tree chain_p;
kono
parents:
diff changeset
276
kono
parents:
diff changeset
277 /* If there is a typedef name for this type, use it. */
kono
parents:
diff changeset
278 if (TYPE_NAME (t) && TREE_CODE (TYPE_NAME (t)) == TYPE_DECL)
kono
parents:
diff changeset
279 data_type = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (t)));
kono
parents:
diff changeset
280 else
kono
parents:
diff changeset
281 {
kono
parents:
diff changeset
282 switch (TREE_CODE (t))
kono
parents:
diff changeset
283 {
kono
parents:
diff changeset
284 case POINTER_TYPE:
kono
parents:
diff changeset
285 if (TYPE_ATOMIC (t))
kono
parents:
diff changeset
286 ret_val = concat ("_Atomic ", ret_val, NULL);
kono
parents:
diff changeset
287 if (TYPE_READONLY (t))
kono
parents:
diff changeset
288 ret_val = concat ("const ", ret_val, NULL);
kono
parents:
diff changeset
289 if (TYPE_VOLATILE (t))
kono
parents:
diff changeset
290 ret_val = concat ("volatile ", ret_val, NULL);
kono
parents:
diff changeset
291
kono
parents:
diff changeset
292 ret_val = concat ("*", ret_val, NULL);
kono
parents:
diff changeset
293
kono
parents:
diff changeset
294 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE || TREE_CODE (TREE_TYPE (t)) == FUNCTION_TYPE)
kono
parents:
diff changeset
295 ret_val = concat ("(", ret_val, ")", NULL);
kono
parents:
diff changeset
296
kono
parents:
diff changeset
297 ret_val = gen_type (ret_val, TREE_TYPE (t), style);
kono
parents:
diff changeset
298
kono
parents:
diff changeset
299 return ret_val;
kono
parents:
diff changeset
300
kono
parents:
diff changeset
301 case ARRAY_TYPE:
kono
parents:
diff changeset
302 if (!COMPLETE_TYPE_P (t) || TREE_CODE (TYPE_SIZE (t)) != INTEGER_CST)
kono
parents:
diff changeset
303 ret_val = gen_type (concat (ret_val, "[]", NULL),
kono
parents:
diff changeset
304 TREE_TYPE (t), style);
kono
parents:
diff changeset
305 else if (int_size_in_bytes (t) == 0)
kono
parents:
diff changeset
306 ret_val = gen_type (concat (ret_val, "[0]", NULL),
kono
parents:
diff changeset
307 TREE_TYPE (t), style);
kono
parents:
diff changeset
308 else
kono
parents:
diff changeset
309 {
kono
parents:
diff changeset
310 char buff[23];
kono
parents:
diff changeset
311 sprintf (buff, "[" HOST_WIDE_INT_PRINT_DEC"]",
kono
parents:
diff changeset
312 int_size_in_bytes (t)
kono
parents:
diff changeset
313 / int_size_in_bytes (TREE_TYPE (t)));
kono
parents:
diff changeset
314 ret_val = gen_type (concat (ret_val, buff, NULL),
kono
parents:
diff changeset
315 TREE_TYPE (t), style);
kono
parents:
diff changeset
316 }
kono
parents:
diff changeset
317 break;
kono
parents:
diff changeset
318
kono
parents:
diff changeset
319 case FUNCTION_TYPE:
kono
parents:
diff changeset
320 ret_val = gen_type (concat (ret_val,
kono
parents:
diff changeset
321 gen_formal_list_for_type (t, style),
kono
parents:
diff changeset
322 NULL),
kono
parents:
diff changeset
323 TREE_TYPE (t), style);
kono
parents:
diff changeset
324 break;
kono
parents:
diff changeset
325
kono
parents:
diff changeset
326 case IDENTIFIER_NODE:
kono
parents:
diff changeset
327 data_type = IDENTIFIER_POINTER (t);
kono
parents:
diff changeset
328 break;
kono
parents:
diff changeset
329
kono
parents:
diff changeset
330 /* The following three cases are complicated by the fact that a
kono
parents:
diff changeset
331 user may do something really stupid, like creating a brand new
kono
parents:
diff changeset
332 "anonymous" type specification in a formal argument list (or as
kono
parents:
diff changeset
333 part of a function return type specification). For example:
kono
parents:
diff changeset
334
kono
parents:
diff changeset
335 int f (enum { red, green, blue } color);
kono
parents:
diff changeset
336
kono
parents:
diff changeset
337 In such cases, we have no name that we can put into the prototype
kono
parents:
diff changeset
338 to represent the (anonymous) type. Thus, we have to generate the
kono
parents:
diff changeset
339 whole darn type specification. Yuck! */
kono
parents:
diff changeset
340
kono
parents:
diff changeset
341 case RECORD_TYPE:
kono
parents:
diff changeset
342 if (TYPE_NAME (t))
kono
parents:
diff changeset
343 data_type = IDENTIFIER_POINTER (TYPE_NAME (t));
kono
parents:
diff changeset
344 else
kono
parents:
diff changeset
345 {
kono
parents:
diff changeset
346 data_type = "";
kono
parents:
diff changeset
347 chain_p = TYPE_FIELDS (t);
kono
parents:
diff changeset
348 while (chain_p)
kono
parents:
diff changeset
349 {
kono
parents:
diff changeset
350 data_type = concat (data_type, gen_decl (chain_p, 0, ansi),
kono
parents:
diff changeset
351 NULL);
kono
parents:
diff changeset
352 chain_p = TREE_CHAIN (chain_p);
kono
parents:
diff changeset
353 data_type = concat (data_type, "; ", NULL);
kono
parents:
diff changeset
354 }
kono
parents:
diff changeset
355 data_type = concat ("{ ", data_type, "}", NULL);
kono
parents:
diff changeset
356 }
kono
parents:
diff changeset
357 data_type = concat ("struct ", data_type, NULL);
kono
parents:
diff changeset
358 break;
kono
parents:
diff changeset
359
kono
parents:
diff changeset
360 case UNION_TYPE:
kono
parents:
diff changeset
361 if (TYPE_NAME (t))
kono
parents:
diff changeset
362 data_type = IDENTIFIER_POINTER (TYPE_NAME (t));
kono
parents:
diff changeset
363 else
kono
parents:
diff changeset
364 {
kono
parents:
diff changeset
365 data_type = "";
kono
parents:
diff changeset
366 chain_p = TYPE_FIELDS (t);
kono
parents:
diff changeset
367 while (chain_p)
kono
parents:
diff changeset
368 {
kono
parents:
diff changeset
369 data_type = concat (data_type, gen_decl (chain_p, 0, ansi),
kono
parents:
diff changeset
370 NULL);
kono
parents:
diff changeset
371 chain_p = TREE_CHAIN (chain_p);
kono
parents:
diff changeset
372 data_type = concat (data_type, "; ", NULL);
kono
parents:
diff changeset
373 }
kono
parents:
diff changeset
374 data_type = concat ("{ ", data_type, "}", NULL);
kono
parents:
diff changeset
375 }
kono
parents:
diff changeset
376 data_type = concat ("union ", data_type, NULL);
kono
parents:
diff changeset
377 break;
kono
parents:
diff changeset
378
kono
parents:
diff changeset
379 case ENUMERAL_TYPE:
kono
parents:
diff changeset
380 if (TYPE_NAME (t))
kono
parents:
diff changeset
381 data_type = IDENTIFIER_POINTER (TYPE_NAME (t));
kono
parents:
diff changeset
382 else
kono
parents:
diff changeset
383 {
kono
parents:
diff changeset
384 data_type = "";
kono
parents:
diff changeset
385 chain_p = TYPE_VALUES (t);
kono
parents:
diff changeset
386 while (chain_p)
kono
parents:
diff changeset
387 {
kono
parents:
diff changeset
388 data_type = concat (data_type,
kono
parents:
diff changeset
389 IDENTIFIER_POINTER (TREE_PURPOSE (chain_p)), NULL);
kono
parents:
diff changeset
390 chain_p = TREE_CHAIN (chain_p);
kono
parents:
diff changeset
391 if (chain_p)
kono
parents:
diff changeset
392 data_type = concat (data_type, ", ", NULL);
kono
parents:
diff changeset
393 }
kono
parents:
diff changeset
394 data_type = concat ("{ ", data_type, " }", NULL);
kono
parents:
diff changeset
395 }
kono
parents:
diff changeset
396 data_type = concat ("enum ", data_type, NULL);
kono
parents:
diff changeset
397 break;
kono
parents:
diff changeset
398
kono
parents:
diff changeset
399 case TYPE_DECL:
kono
parents:
diff changeset
400 data_type = IDENTIFIER_POINTER (DECL_NAME (t));
kono
parents:
diff changeset
401 break;
kono
parents:
diff changeset
402
kono
parents:
diff changeset
403 case INTEGER_TYPE:
kono
parents:
diff changeset
404 case FIXED_POINT_TYPE:
kono
parents:
diff changeset
405 data_type = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (t)));
kono
parents:
diff changeset
406 /* Normally, `unsigned' is part of the deal. Not so if it comes
kono
parents:
diff changeset
407 with a type qualifier. */
kono
parents:
diff changeset
408 if (TYPE_UNSIGNED (t) && TYPE_QUALS (t))
kono
parents:
diff changeset
409 data_type = concat ("unsigned ", data_type, NULL);
kono
parents:
diff changeset
410 break;
kono
parents:
diff changeset
411
kono
parents:
diff changeset
412 case REAL_TYPE:
kono
parents:
diff changeset
413 data_type = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (t)));
kono
parents:
diff changeset
414 break;
kono
parents:
diff changeset
415
kono
parents:
diff changeset
416 case VOID_TYPE:
kono
parents:
diff changeset
417 data_type = "void";
kono
parents:
diff changeset
418 break;
kono
parents:
diff changeset
419
kono
parents:
diff changeset
420 case ERROR_MARK:
kono
parents:
diff changeset
421 data_type = "[ERROR]";
kono
parents:
diff changeset
422 break;
kono
parents:
diff changeset
423
kono
parents:
diff changeset
424 default:
kono
parents:
diff changeset
425 gcc_unreachable ();
kono
parents:
diff changeset
426 }
kono
parents:
diff changeset
427 }
kono
parents:
diff changeset
428 if (TYPE_ATOMIC (t))
kono
parents:
diff changeset
429 ret_val = concat ("_Atomic ", ret_val, NULL);
kono
parents:
diff changeset
430 if (TYPE_READONLY (t))
kono
parents:
diff changeset
431 ret_val = concat ("const ", ret_val, NULL);
kono
parents:
diff changeset
432 if (TYPE_VOLATILE (t))
kono
parents:
diff changeset
433 ret_val = concat ("volatile ", ret_val, NULL);
kono
parents:
diff changeset
434 if (TYPE_RESTRICT (t))
kono
parents:
diff changeset
435 ret_val = concat ("restrict ", ret_val, NULL);
kono
parents:
diff changeset
436 return ret_val;
kono
parents:
diff changeset
437 }
kono
parents:
diff changeset
438
kono
parents:
diff changeset
439 /* Generate a string (source) representation of an entire entity declaration
kono
parents:
diff changeset
440 (using some particular style for function types).
kono
parents:
diff changeset
441
kono
parents:
diff changeset
442 The given entity may be either a variable or a function.
kono
parents:
diff changeset
443
kono
parents:
diff changeset
444 If the "is_func_definition" parameter is nonzero, assume that the thing
kono
parents:
diff changeset
445 we are generating a declaration for is a FUNCTION_DECL node which is
kono
parents:
diff changeset
446 associated with a function definition. In this case, we can assume that
kono
parents:
diff changeset
447 an attached list of DECL nodes for function formal arguments is present. */
kono
parents:
diff changeset
448
kono
parents:
diff changeset
449 static const char *
kono
parents:
diff changeset
450 gen_decl (tree decl, int is_func_definition, formals_style style)
kono
parents:
diff changeset
451 {
kono
parents:
diff changeset
452 const char *ret_val;
kono
parents:
diff changeset
453
kono
parents:
diff changeset
454 if (DECL_NAME (decl))
kono
parents:
diff changeset
455 ret_val = IDENTIFIER_POINTER (DECL_NAME (decl));
kono
parents:
diff changeset
456 else
kono
parents:
diff changeset
457 ret_val = "";
kono
parents:
diff changeset
458
kono
parents:
diff changeset
459 /* If we are just generating a list of names of formal parameters, we can
kono
parents:
diff changeset
460 simply return the formal parameter name (with no typing information
kono
parents:
diff changeset
461 attached to it) now. */
kono
parents:
diff changeset
462
kono
parents:
diff changeset
463 if (style == k_and_r_names)
kono
parents:
diff changeset
464 return ret_val;
kono
parents:
diff changeset
465
kono
parents:
diff changeset
466 /* Note that for the declaration of some entity (either a function or a
kono
parents:
diff changeset
467 data object, like for instance a parameter) if the entity itself was
kono
parents:
diff changeset
468 declared as either const or volatile, then const and volatile properties
kono
parents:
diff changeset
469 are associated with just the declaration of the entity, and *not* with
kono
parents:
diff changeset
470 the `type' of the entity. Thus, for such declared entities, we have to
kono
parents:
diff changeset
471 generate the qualifiers here. */
kono
parents:
diff changeset
472
kono
parents:
diff changeset
473 if (TREE_THIS_VOLATILE (decl))
kono
parents:
diff changeset
474 ret_val = concat ("volatile ", ret_val, NULL);
kono
parents:
diff changeset
475 if (TREE_READONLY (decl))
kono
parents:
diff changeset
476 ret_val = concat ("const ", ret_val, NULL);
kono
parents:
diff changeset
477
kono
parents:
diff changeset
478 data_type = "";
kono
parents:
diff changeset
479
kono
parents:
diff changeset
480 /* For FUNCTION_DECL nodes, there are two possible cases here. First, if
kono
parents:
diff changeset
481 this FUNCTION_DECL node was generated from a function "definition", then
kono
parents:
diff changeset
482 we will have a list of DECL_NODE's, one for each of the function's formal
kono
parents:
diff changeset
483 parameters. In this case, we can print out not only the types of each
kono
parents:
diff changeset
484 formal, but also each formal's name. In the second case, this
kono
parents:
diff changeset
485 FUNCTION_DECL node came from an actual function declaration (and *not*
kono
parents:
diff changeset
486 a definition). In this case, we do nothing here because the formal
kono
parents:
diff changeset
487 argument type-list will be output later, when the "type" of the function
kono
parents:
diff changeset
488 is added to the string we are building. Note that the ANSI-style formal
kono
parents:
diff changeset
489 parameter list is considered to be a (suffix) part of the "type" of the
kono
parents:
diff changeset
490 function. */
kono
parents:
diff changeset
491
kono
parents:
diff changeset
492 if (TREE_CODE (decl) == FUNCTION_DECL && is_func_definition)
kono
parents:
diff changeset
493 {
kono
parents:
diff changeset
494 ret_val = concat (ret_val, gen_formal_list_for_func_def (decl, ansi),
kono
parents:
diff changeset
495 NULL);
kono
parents:
diff changeset
496
kono
parents:
diff changeset
497 /* Since we have already added in the formals list stuff, here we don't
kono
parents:
diff changeset
498 add the whole "type" of the function we are considering (which
kono
parents:
diff changeset
499 would include its parameter-list info), rather, we only add in
kono
parents:
diff changeset
500 the "type" of the "type" of the function, which is really just
kono
parents:
diff changeset
501 the return-type of the function (and does not include the parameter
kono
parents:
diff changeset
502 list info). */
kono
parents:
diff changeset
503
kono
parents:
diff changeset
504 ret_val = gen_type (ret_val, TREE_TYPE (TREE_TYPE (decl)), style);
kono
parents:
diff changeset
505 }
kono
parents:
diff changeset
506 else
kono
parents:
diff changeset
507 ret_val = gen_type (ret_val, TREE_TYPE (decl), style);
kono
parents:
diff changeset
508
kono
parents:
diff changeset
509 ret_val = affix_data_type (ret_val);
kono
parents:
diff changeset
510
kono
parents:
diff changeset
511 if (TREE_CODE (decl) != FUNCTION_DECL && C_DECL_REGISTER (decl))
kono
parents:
diff changeset
512 ret_val = concat ("register ", ret_val, NULL);
kono
parents:
diff changeset
513 if (TREE_PUBLIC (decl))
kono
parents:
diff changeset
514 ret_val = concat ("extern ", ret_val, NULL);
kono
parents:
diff changeset
515 if (TREE_CODE (decl) == FUNCTION_DECL && !TREE_PUBLIC (decl))
kono
parents:
diff changeset
516 ret_val = concat ("static ", ret_val, NULL);
kono
parents:
diff changeset
517
kono
parents:
diff changeset
518 return ret_val;
kono
parents:
diff changeset
519 }
kono
parents:
diff changeset
520
kono
parents:
diff changeset
521 extern FILE *aux_info_file;
kono
parents:
diff changeset
522
kono
parents:
diff changeset
523 /* Generate and write a new line of info to the aux-info (.X) file. This
kono
parents:
diff changeset
524 routine is called once for each function declaration, and once for each
kono
parents:
diff changeset
525 function definition (even the implicit ones). */
kono
parents:
diff changeset
526
kono
parents:
diff changeset
527 void
kono
parents:
diff changeset
528 gen_aux_info_record (tree fndecl, int is_definition, int is_implicit,
kono
parents:
diff changeset
529 int is_prototyped)
kono
parents:
diff changeset
530 {
kono
parents:
diff changeset
531 if (flag_gen_aux_info)
kono
parents:
diff changeset
532 {
kono
parents:
diff changeset
533 static int compiled_from_record = 0;
kono
parents:
diff changeset
534 expanded_location xloc = expand_location (DECL_SOURCE_LOCATION (fndecl));
kono
parents:
diff changeset
535
kono
parents:
diff changeset
536 /* Each output .X file must have a header line. Write one now if we
kono
parents:
diff changeset
537 have not yet done so. */
kono
parents:
diff changeset
538
kono
parents:
diff changeset
539 if (!compiled_from_record++)
kono
parents:
diff changeset
540 {
kono
parents:
diff changeset
541 /* The first line tells which directory file names are relative to.
kono
parents:
diff changeset
542 Currently, -aux-info works only for files in the working
kono
parents:
diff changeset
543 directory, so just use a `.' as a placeholder for now. */
kono
parents:
diff changeset
544 fprintf (aux_info_file, "/* compiled from: . */\n");
kono
parents:
diff changeset
545 }
kono
parents:
diff changeset
546
kono
parents:
diff changeset
547 /* Write the actual line of auxiliary info. */
kono
parents:
diff changeset
548
kono
parents:
diff changeset
549 fprintf (aux_info_file, "/* %s:%d:%c%c */ %s;",
kono
parents:
diff changeset
550 xloc.file, xloc.line,
kono
parents:
diff changeset
551 (is_implicit) ? 'I' : (is_prototyped) ? 'N' : 'O',
kono
parents:
diff changeset
552 (is_definition) ? 'F' : 'C',
kono
parents:
diff changeset
553 gen_decl (fndecl, is_definition, ansi));
kono
parents:
diff changeset
554
kono
parents:
diff changeset
555 /* If this is an explicit function declaration, we need to also write
kono
parents:
diff changeset
556 out an old-style (i.e. K&R) function header, just in case the user
kono
parents:
diff changeset
557 wants to run unprotoize. */
kono
parents:
diff changeset
558
kono
parents:
diff changeset
559 if (is_definition)
kono
parents:
diff changeset
560 {
kono
parents:
diff changeset
561 fprintf (aux_info_file, " /*%s %s*/",
kono
parents:
diff changeset
562 gen_formal_list_for_func_def (fndecl, k_and_r_names),
kono
parents:
diff changeset
563 gen_formal_list_for_func_def (fndecl, k_and_r_decls));
kono
parents:
diff changeset
564 }
kono
parents:
diff changeset
565
kono
parents:
diff changeset
566 fprintf (aux_info_file, "\n");
kono
parents:
diff changeset
567 }
kono
parents:
diff changeset
568 }