gcc源代码分析,grokdeclarator()函数分析 ,第二部分

50 篇文章 2 订阅
41 篇文章 3 订阅

函数声明的类型tree是如何生成的?

grokdeclarator()函数的第二个参数为:

 <tree_list 95608 permanent
    value <identifier_node 82008 int permanent
        global <type_decl 82564 int type <integer_type 824d0* int>
            permanent VOID file (null) line 0
            align 1 size_unit 1 offset 0



      type = build_function_type (type, arg_types);  之后的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>


下面是和type有关的代码,如何找出type的关键代码:

  for (spec = declspecs; spec; spec = TREE_CHAIN (spec))
    {
      register int i;
      register tree id = TREE_VALUE (spec);

      if (id == ridpointers[(int) RID_INT])
    explicit_int = 1;
      if (id == ridpointers[(int) RID_CHAR])
    explicit_char = 1;

      if (TREE_CODE (id) == IDENTIFIER_NODE)
    for (i = (int) RID_FIRST_MODIFIER; i < (int) RID_MAX; i++)
      {
        if (ridpointers[i] == id)
          {
        if (i == (int) RID_LONG && specbits & (1<<i))
          {
            if (pedantic)
              warning ("duplicate `%s'", IDENTIFIER_POINTER (id));
            else if (longlong)
              warning ("`long long long' is too long for GCC");
            else
              longlong = 1;
          }
        else if (specbits & (1 << i))
          warning ("duplicate `%s'", IDENTIFIER_POINTER (id));
        specbits |= 1 << i;
        goto found;
          }
      }
      if (type)
    error ("two or more data types in declaration of `%s'", name);
      else if (TREE_CODE (id) == IDENTIFIER_NODE)
    {
      register tree t = lookup_name (id);
      if (!t || TREE_CODE (t) != TYPE_DECL)
        error ("`%s' fails to be a typedef or built in type",
           IDENTIFIER_POINTER (id));
      else type = TREE_TYPE (t);
    }
      else if (TREE_CODE (id) != ERROR_MARK)
    type = id;

    found: {}
    }

debug_tree(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>
 <identifier_node 95540 printf permanent





  debug_tree(type);的结果是

    /* Now figure out the structure of the declarator proper.
     Descend through it, creating more complex types, until we reach
     the declared identifier (or NULL_TREE, in an absolute declarator).  */

  while (declarator && TREE_CODE (declarator) != IDENTIFIER_NODE)


 <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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值