diff options
Diffstat (limited to 'contrib/gcc/c-aux-info.c')
-rw-r--r-- | contrib/gcc/c-aux-info.c | 195 |
1 files changed, 67 insertions, 128 deletions
diff --git a/contrib/gcc/c-aux-info.c b/contrib/gcc/c-aux-info.c index 9a66350cf8c8..67ecae6cea17 100644 --- a/contrib/gcc/c-aux-info.c +++ b/contrib/gcc/c-aux-info.c @@ -1,25 +1,26 @@ /* Generate information regarding function declarations and definitions based on information stored in GCC's tree structure. This code implements the -aux-info option. - Copyright (C) 1989, 91, 94, 95, 97-98, 1999 Free Software Foundation, Inc. + Copyright (C) 1989, 1991, 1994, 1995, 1997, 1998, + 1999, 2000 Free Software Foundation, Inc. Contributed by Ron Guilmette (rfg@segfault.us.com). -This file is part of GNU CC. +This file is part of GCC. -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. +GCC 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. +GCC 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. */ +along with GCC; see the file COPYING. If not, write to the Free +Software Foundation, 59 Temple Place - Suite 330, Boston, MA +02111-1307, USA. */ #include "config.h" #include "system.h" @@ -38,74 +39,13 @@ typedef enum formals_style_enum formals_style; static const char *data_type; -static char *affix_data_type PROTO((const char *)); -static const char *gen_formal_list_for_type PROTO((tree, formals_style)); -static int deserves_ellipsis PROTO((tree)); -static const char *gen_formal_list_for_func_def PROTO((tree, formals_style)); -static const char *gen_type PROTO((const char *, tree, formals_style)); -static const char *gen_decl PROTO((tree, int, formals_style)); +static char *affix_data_type PARAMS ((const char *)) ATTRIBUTE_MALLOC; +static const char *gen_formal_list_for_type PARAMS ((tree, formals_style)); +static int deserves_ellipsis PARAMS ((tree)); +static const char *gen_formal_list_for_func_def PARAMS ((tree, formals_style)); +static const char *gen_type PARAMS ((const char *, tree, formals_style)); +static const char *gen_decl PARAMS ((tree, int, formals_style)); -/* Concatenate a sequence of strings, returning the result. - - This function is based on the one in libiberty. */ - -/* This definition will conflict with the one from prefix.c in - libcpp.a when linking cc1 and cc1obj. So only provide it if we are - not using libcpp.a */ -#ifndef USE_CPPLIB -char * -concat VPROTO((const char *first, ...)) -{ - register int length; - register char *newstr; - register char *end; - register const char *arg; - va_list args; -#ifndef ANSI_PROTOTYPES - const char *first; -#endif - - /* First compute the size of the result and get sufficient memory. */ - - VA_START (args, first); -#ifndef ANSI_PROTOTYPES - first = va_arg (args, const char *); -#endif - - arg = first; - length = 0; - - while (arg != 0) - { - length += strlen (arg); - arg = va_arg (args, const char *); - } - - newstr = (char *) malloc (length + 1); - va_end (args); - - /* Now copy the individual pieces to the result string. */ - - VA_START (args, first); -#ifndef ANSI_PROTOTYPES - first = va_arg (args, char *); -#endif - - end = newstr; - arg = first; - while (arg != 0) - { - while (*arg) - *end++ = *arg++; - arg = va_arg (args, const char *); - } - *end = '\000'; - va_end (args); - - return (newstr); -} -#endif /* ! USE_CPPLIB */ - /* Given a string representing an entire type or an entire declaration which only lacks the actual "data-type" specifier (at its left end), affix the data-type specifier to the left end of the given type @@ -124,13 +64,11 @@ static char * affix_data_type (param) const char *param; { - char *type_or_decl = (char *) alloca (strlen (param) + 1); + char *const type_or_decl = ASTRDUP (param); char *p = type_or_decl; char *qualifiers_then_data_type; char saved; - strcpy (type_or_decl, param); - /* Skip as many leading const's or volatile's as there are. */ for (;;) @@ -152,13 +90,14 @@ affix_data_type (param) add a blank after the data-type of course. */ if (p == type_or_decl) - return concat (data_type, " ", type_or_decl, NULL_PTR); + return concat (data_type, " ", type_or_decl, NULL); saved = *p; *p = '\0'; - qualifiers_then_data_type = concat (type_or_decl, data_type, NULL_PTR); + qualifiers_then_data_type = concat (type_or_decl, data_type, NULL); *p = saved; - return concat (qualifiers_then_data_type, " ", p, NULL_PTR); + return reconcat (qualifiers_then_data_type, + qualifiers_then_data_type, " ", p, NULL); } /* Given a tree node which represents some "function type", generate the @@ -185,13 +124,13 @@ gen_formal_list_for_type (fntype, style) const char *this_type; if (*formal_list) - formal_list = concat (formal_list, ", ", NULL_PTR); + formal_list = concat (formal_list, ", ", NULL); this_type = gen_type ("", TREE_VALUE (formal_type), ansi); formal_list = ((strlen (this_type)) - ? concat (formal_list, affix_data_type (this_type), NULL_PTR) - : concat (formal_list, data_type, NULL_PTR)); + ? concat (formal_list, affix_data_type (this_type), NULL) + : concat (formal_list, data_type, NULL)); formal_type = TREE_CHAIN (formal_type); } @@ -240,10 +179,10 @@ gen_formal_list_for_type (fntype, style) petered out to a NULL (i.e. without being terminated by a void_type_node) then we need to tack on an ellipsis. */ if (!formal_type) - formal_list = concat (formal_list, ", ...", NULL_PTR); + formal_list = concat (formal_list, ", ...", NULL); } - return concat (" (", formal_list, ")", NULL_PTR); + return concat (" (", formal_list, ")", NULL); } /* For the generation of an ANSI prototype for a function definition, we have @@ -302,23 +241,23 @@ gen_formal_list_for_func_def (fndecl, style) const char *this_formal; if (*formal_list && ((style == ansi) || (style == k_and_r_names))) - formal_list = concat (formal_list, ", ", NULL_PTR); + formal_list = concat (formal_list, ", ", NULL); this_formal = gen_decl (formal_decl, 0, style); if (style == k_and_r_decls) - formal_list = concat (formal_list, this_formal, "; ", NULL_PTR); + formal_list = concat (formal_list, this_formal, "; ", NULL); else - formal_list = concat (formal_list, this_formal, NULL_PTR); + formal_list = concat (formal_list, this_formal, NULL); formal_decl = TREE_CHAIN (formal_decl); } if (style == ansi) { if (!DECL_ARGUMENTS (fndecl)) - formal_list = concat (formal_list, "void", NULL_PTR); + formal_list = concat (formal_list, "void", NULL); if (deserves_ellipsis (TREE_TYPE (fndecl))) - formal_list = concat (formal_list, ", ...", NULL_PTR); + formal_list = concat (formal_list, ", ...", NULL); } if ((style == ansi) || (style == k_and_r_names)) - formal_list = concat (" (", formal_list, ")", NULL_PTR); + formal_list = concat (" (", formal_list, ")", NULL); return formal_list; } @@ -380,32 +319,32 @@ gen_type (ret_val, t, style) { case POINTER_TYPE: if (TYPE_READONLY (t)) - ret_val = concat ("const ", ret_val, NULL_PTR); + ret_val = concat ("const ", ret_val, NULL); if (TYPE_VOLATILE (t)) - ret_val = concat ("volatile ", ret_val, NULL_PTR); + ret_val = concat ("volatile ", ret_val, NULL); - ret_val = concat ("*", ret_val, NULL_PTR); + ret_val = concat ("*", ret_val, NULL); if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE || TREE_CODE (TREE_TYPE (t)) == FUNCTION_TYPE) - ret_val = concat ("(", ret_val, ")", NULL_PTR); + ret_val = concat ("(", ret_val, ")", NULL); ret_val = gen_type (ret_val, TREE_TYPE (t), style); return ret_val; case ARRAY_TYPE: - if (TYPE_SIZE (t) == 0 || TREE_CODE (TYPE_SIZE (t)) != INTEGER_CST) - ret_val = gen_type (concat (ret_val, "[]", NULL_PTR), + if (!COMPLETE_TYPE_P (t) || TREE_CODE (TYPE_SIZE (t)) != INTEGER_CST) + ret_val = gen_type (concat (ret_val, "[]", NULL), TREE_TYPE (t), style); else if (int_size_in_bytes (t) == 0) - ret_val = gen_type (concat (ret_val, "[0]", NULL_PTR), + ret_val = gen_type (concat (ret_val, "[0]", NULL), TREE_TYPE (t), style); else { int size = (int_size_in_bytes (t) / int_size_in_bytes (TREE_TYPE (t))); char buff[10]; sprintf (buff, "[%d]", size); - ret_val = gen_type (concat (ret_val, buff, NULL_PTR), + ret_val = gen_type (concat (ret_val, buff, NULL), TREE_TYPE (t), style); } break; @@ -413,7 +352,7 @@ gen_type (ret_val, t, style) case FUNCTION_TYPE: ret_val = gen_type (concat (ret_val, gen_formal_list_for_type (t, style), - NULL_PTR), + NULL), TREE_TYPE (t), style); break; @@ -442,13 +381,13 @@ gen_type (ret_val, t, style) while (chain_p) { data_type = concat (data_type, gen_decl (chain_p, 0, ansi), - NULL_PTR); + NULL); chain_p = TREE_CHAIN (chain_p); - data_type = concat (data_type, "; ", NULL_PTR); + data_type = concat (data_type, "; ", NULL); } - data_type = concat ("{ ", data_type, "}", NULL_PTR); + data_type = concat ("{ ", data_type, "}", NULL); } - data_type = concat ("struct ", data_type, NULL_PTR); + data_type = concat ("struct ", data_type, NULL); break; case UNION_TYPE: @@ -461,13 +400,13 @@ gen_type (ret_val, t, style) while (chain_p) { data_type = concat (data_type, gen_decl (chain_p, 0, ansi), - NULL_PTR); + NULL); chain_p = TREE_CHAIN (chain_p); - data_type = concat (data_type, "; ", NULL_PTR); + data_type = concat (data_type, "; ", NULL); } - data_type = concat ("{ ", data_type, "}", NULL_PTR); + data_type = concat ("{ ", data_type, "}", NULL); } - data_type = concat ("union ", data_type, NULL_PTR); + data_type = concat ("union ", data_type, NULL); break; case ENUMERAL_TYPE: @@ -480,14 +419,14 @@ gen_type (ret_val, t, style) while (chain_p) { data_type = concat (data_type, - IDENTIFIER_POINTER (TREE_PURPOSE (chain_p)), NULL_PTR); + IDENTIFIER_POINTER (TREE_PURPOSE (chain_p)), NULL); chain_p = TREE_CHAIN (chain_p); if (chain_p) - data_type = concat (data_type, ", ", NULL_PTR); + data_type = concat (data_type, ", ", NULL); } - data_type = concat ("{ ", data_type, " }", NULL_PTR); + data_type = concat ("{ ", data_type, " }", NULL); } - data_type = concat ("enum ", data_type, NULL_PTR); + data_type = concat ("enum ", data_type, NULL); break; case TYPE_DECL: @@ -499,7 +438,7 @@ gen_type (ret_val, t, style) /* Normally, `unsigned' is part of the deal. Not so if it comes with a type qualifier. */ if (TREE_UNSIGNED (t) && TYPE_QUALS (t)) - data_type = concat ("unsigned ", data_type, NULL_PTR); + data_type = concat ("unsigned ", data_type, NULL); break; case REAL_TYPE: @@ -519,11 +458,11 @@ gen_type (ret_val, t, style) } } if (TYPE_READONLY (t)) - ret_val = concat ("const ", ret_val, NULL_PTR); + ret_val = concat ("const ", ret_val, NULL); if (TYPE_VOLATILE (t)) - ret_val = concat ("volatile ", ret_val, NULL_PTR); + ret_val = concat ("volatile ", ret_val, NULL); if (TYPE_RESTRICT (t)) - ret_val = concat ("restrict ", ret_val, NULL_PTR); + ret_val = concat ("restrict ", ret_val, NULL); return ret_val; } @@ -565,9 +504,9 @@ gen_decl (decl, is_func_definition, style) generate the qualifiers here. */ if (TREE_THIS_VOLATILE (decl)) - ret_val = concat ("volatile ", ret_val, NULL_PTR); + ret_val = concat ("volatile ", ret_val, NULL); if (TREE_READONLY (decl)) - ret_val = concat ("const ", ret_val, NULL_PTR); + ret_val = concat ("const ", ret_val, NULL); data_type = ""; @@ -586,7 +525,7 @@ gen_decl (decl, is_func_definition, style) if (TREE_CODE (decl) == FUNCTION_DECL && is_func_definition) { ret_val = concat (ret_val, gen_formal_list_for_func_def (decl, ansi), - NULL_PTR); + NULL); /* Since we have already added in the formals list stuff, here we don't add the whole "type" of the function we are considering (which @@ -603,11 +542,11 @@ gen_decl (decl, is_func_definition, style) ret_val = affix_data_type (ret_val); if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl)) - ret_val = concat ("register ", ret_val, NULL_PTR); + ret_val = concat ("register ", ret_val, NULL); if (TREE_PUBLIC (decl)) - ret_val = concat ("extern ", ret_val, NULL_PTR); + ret_val = concat ("extern ", ret_val, NULL); if (TREE_CODE (decl) == FUNCTION_DECL && !TREE_PUBLIC (decl)) - ret_val = concat ("static ", ret_val, NULL_PTR); + ret_val = concat ("static ", ret_val, NULL); return ret_val; } |