/* Search table for identifier */
for (idp = hash_table[hi]; idp; idp = TREE_CHAIN (idp))
if (IDENTIFIER_LENGTH (idp) == len
&& !strcmp (IDENTIFIER_POINTER (idp), text))
return idp; /* <-- return if found */
因为#include <stdio.h>文件中就有printf()函数的声明,所以到main中已经产生了一个tree节点。
printf
<identifier_node 95540 printf permanent
<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 chain <function_decl 954d8 ungetc>
(symbol_ref:SI ("printf"))
(mem:QI (symbol_ref:SI ("printf")))
printf
<identifier_node 95540 printf public permanent
global <function_decl 95740 printf
type <function_type 956e8 type <integer_type 824d0* int>
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>
chain <function_type 959b0>
external public permanent QI file /usr/include/stdio.h line 214
align 1 size_unit 1 offset 0
chain <function_decl 954d8 ungetc type <function_type 8f4f0>
external public permanent QI file /usr/include/stdio.h line 212
align 1 size_unit 1 offset 0 chain <function_decl 95280 fputs>
经过下面的这句之后lastiddecl的值改变了
lastiddecl = lookup_name (yylval.ttype);
<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>
chain <function_type 959b0>
external public permanent used QI file /usr/include/stdio.h line 214
align 1 size_unit 1 offset 0 chain <function_decl 954d8 ungetc>
c-parse.tab.y语法文件中有下面这句。
primary:
IDENTIFIER
{ $$ = lastiddecl;
#define IDENTIFIER_GLOBAL_VALUE(NODE) \
(((struct lang_identifier *)(NODE))->global_value)