grokdeclarator ()函数有2次被调用的情况。
第一种情况在函数push_parm_decl ()函数中。
/* Given a parsed parameter declaration,
decode it into a PARM_DECL and push that on the current binding level. */
void
push_parm_decl (parm)
tree parm;
{
register tree decl = grokdeclarator (TREE_VALUE (parm), TREE_PURPOSE (parm),
PARM, 0);
/* Add this decl to the current binding level. */
finish_decl (pushdecl (decl), NULL_TREE, NULL_TREE);
}
grokdeclarator ()函数中的部分代码:
if (initialized)
error ("parameter `%s' is initialized", name);
decl = build_decl (PARM_DECL, declarator, type);
调试结果:
align 32 size_unit 8 offset 0 arguments <pointer_type 9117c>
第二种情况在函数start_decl ()函数中。
tree
start_decl (declarator, declspecs, initialized)
tree declspecs, declarator;
int initialized;
{
register tree decl = grokdeclarator (declarator, declspecs,
NORMAL, initialized);
参数调试结果:
align 1 size_unit 1 offset 0
grokdeclarator ()函数返回结果:
<function_decl 95740 printf
type <function_type 956e8
type <integer_type 824d0 int permanent SI
size <integer_cst 8254c literal permanent 4
align 32 size_unit 8 sep_unit 32 symtab 0
sep <integer_cst 8251c literal permanent -2147483648 precision 32 min <integer_cst 8251c -2147483648>
max <integer_cst 82534 literal permanent 2147483647
pointer_to_this <pointer_type 88b4c> chain <integer_type 825bc* char>
permanent EP
size <integer_cst 82dd8 literal permanent 8
align 32 size_unit 8 sep_unit 0 symtab 0
arg-types <tree_list 95698 permanent value <pointer_type 9117c>
external public permanent QI file /usr/include/stdio.h line 214
align 1 size_unit 1 offset 0
...
arg_types = grokparms (TREE_OPERAND (declarator, 1),
funcdef_flag
/* Say it's a definition
only for the CALL_EXPR
closest to the identifier. */
&& TREE_CODE (TREE_OPERAND (declarator, 0)) == IDENTIFIER_NODE);
#if 0 /* This seems to be false. We turn off temporary allocation
above in this function if -traditional.
And this code caused inconsistent results with prototypes:
callers would ignore them, and pass arguments wrong. */
/* Omit the arg types if -traditional, since the arg types
and the list links might not be permanent. */
type = build_function_type (type, flag_traditional ? 0 : arg_types);
#endif
type = build_function_type (type, arg_types);
declarator = TREE_OPERAND (declarator, 0);
arg_types = grokparms (之后为
<tree_list 95698 permanent
value <pointer_type 9117c
type <integer_type 91130 char readonly permanent QI
size <integer_cst 82638 literal permanent 1
align 8 size_unit 8 sep_unit 8 symtab 0
sep <integer_cst 82608 literal permanent -128 precision 8 min <integer_cst 82608 -128>
max <integer_cst 82620 literal permanent 127
pointer_to_this <pointer_type 9117c>
permanent unsigned SI
size <integer_cst 8254c literal permanent 4
align 32 size_unit 8 sep_unit 32 symtab 0
chain <function_type 912c0>
type = build_function_type ( 之前type为:
<integer_type 824d0 int permanent SI
size <integer_cst 8254c type <integer_type 82848* unsigned int> literal permanent 4
align 32 size_unit 8 sep_unit 32 symtab 0
sep <integer_cst 8251c type <integer_type 824d0* int> literal permanent -2147483648 precision 32 min <integer_cst 8251c -2147483648>
max <integer_cst 82534 type <integer_type 824d0* int> literal permanent 2147483647
pointer_to_this <pointer_type 88b4c> chain <integer_type 825bc* char>
type = build_function_type ( 之后type为:
<function_type 956e8
type <integer_type 824d0 int permanent SI
size <integer_cst 8254c literal permanent 4
align 32 size_unit 8 sep_unit 32 symtab 0
sep <integer_cst 8251c literal permanent -2147483648 precision 32 min <integer_cst 8251c -2147483648>
max <integer_cst 82534 literal permanent 2147483647
pointer_to_this <pointer_type 88b4c> chain <integer_type 825bc* char>
permanent EP
size <integer_cst 82dd8 type <integer_type 82848* unsigned int> literal permanent 8
align 32 size_unit 8 sep_unit 0 symtab 0
arg-types <tree_list 95698 permanent
value <pointer_type 9117c type <integer_type 91130* char>
permanent unsigned SI size <integer_cst 8254c 4>
align 32 size_unit 8 sep_unit 32 symtab 0
chain <function_type 912c0>
else if (TREE_CODE (type) == FUNCTION_TYPE)
{
...
调用build_decl函数之前 declarator为
<identifier_node 95540 printf permanent
调用build_decl函数之前type 为
<function_type 956e8
type <integer_type 824d0 int permanent SI
size <integer_cst 8254c literal permanent 4
align 32 size_unit 8 sep_unit 32 symtab 0
sep <integer_cst 8251c literal permanent -2147483648 precision 32 min <integer_cst 8251c -2147483648>
max <integer_cst 82534 literal permanent 2147483647
pointer_to_this <pointer_type 88b4c> chain <integer_type 825bc* char>
permanent EP
size <integer_cst 82dd8 type <integer_type 82848* unsigned int> literal permanent 8
align 32 size_unit 8 sep_unit 0 symtab 0
arg-types <tree_list 95698 permanent
value <pointer_type 9117c type <integer_type 91130* char>
permanent unsigned SI size <integer_cst 8254c 4>
align 32 size_unit 8 sep_unit 32 symtab 0
chain <function_type 912c0>
decl = build_decl (FUNCTION_DECL, declarator, type);
调用build_decl函数之后
<function_decl 95740 printf
type <function_type 956e8
type <integer_type 824d0 int permanent SI
size <integer_cst 8254c literal permanent 4
align 32 size_unit 8 sep_unit 32 symtab 0
sep <integer_cst 8251c literal permanent -2147483648 precision 32 min <integer_cst 8251c -2147483648>
max <integer_cst 82534 literal permanent 2147483647
pointer_to_this <pointer_type 88b4c> chain <integer_type 825bc* char>
permanent EP
size <integer_cst 82dd8 literal permanent 8
align 32 size_unit 8 sep_unit 0 symtab 0
arg-types <tree_list 95698 permanent value <pointer_type 9117c>
permanent QI file /usr/include/stdio.h line 214
align 1 size_unit 1 offset 0