现在的位置: 首页 > 综合 > 正文

Studying note of GCC-3.4.6 source (53)

2013年09月20日 ⁄ 综合 ⁄ 共 4920字 ⁄ 字号 评论关闭
4.3.1.7.2.4.      Entity for global namespace

The identifier of global namespace is global_scope_name, and its front-end tree node has code NAMESPACE_DECL. As namespace hasn’t type information, so parameter type of below function is void_type_node.

 

687    tree

688    build_lang_decl (enum tree_code code, tree name, tree type)                              in lex.c

689    {

690      tree t;

691   

692      t = build_decl (code, name, type);

693      retrofit_lang_decl (t);

694   

695      return t;

696    }

 

For every declaration, it has a node of tree_decl going with. As declaration is part of the language, we can find following field in tree_decl definition.

 

1647 struct tree_decl GTY(())

1648 {

        ...

1748   struct lang_decl *lang_specific;

1749 };

 

Field lang_decl records the information of the language. In C++, the definition of lang_decl is following.

 

1661 struct lang_decl GTY(())                                                                            in cp-tree.h

1662 {

1663   struct lang_decl_flags decl_flags;

1664

1665   union lang_decl_u4

1666   {

1667     struct full_lang_decl

1668     {

1669       /* For a non-thunk function decl, this is a tree list of

1670         friendly classes. For a thunk function decl, it is the

1671         thunked to function decl.  */

1672       tree befriending_classes;

1673  

1674       /* For a non-virtual FUNCTION_DECL, this is

1675         DECL_FRIEND_CONTEXT. For a virtual FUNCTION_DECL for which

1676         DECL_THIS_THUNK_P does not hold, this is DECL_THUNKS. Both

1677         this pointer and result pointer adjusting thunks are

1678         chained here. This pointer thunks to return pointer thunks

1679         will be chained on the return pointer thunk.  */

1680       tree context;

1681

1682       /* In a FUNCTION_DECL, this is DECL_CLONED_FUNCTION.  */

1683       tree cloned_function;

1684  

1685       /* In a FUNCTION_DECL for which THUNK_P holds, this is

1686         THUNK_FIXED_OFFSET.  */

1687       HOST_WIDE_INT fixed_offset;

1688

1689       /* In an overloaded operator, this is the value of

1690         DECL_OVERLOADED_OPERATOR_P.  */

1691       enum tree_code operator_code;

1692

1693       unsigned u3sel : 1;

1694       unsigned pending_inline_p : 1;

1695  

1696       union lang_decl_u3

1697       {

1698         struct sorted_fields_type * GTY ((tag ("0"), reorder ("resort_sorted_fields")))

1699               sorted_fields;

1700         struct cp_token_cache * GTY ((tag ("2"))) pending_inline_info;

1701         struct language_function * GTY ((tag ("1")))

1702               saved_language_function;

1703       } GTY ((desc ("%1.u3sel + %1.pending_inline_p"))) u;

1704     } GTY ((tag ("1"))) f;

1705   } GTY ((desc ("%1.decl_flags.can_be_full"))) u;

1706 };

 

See that lang_decl_flags is the first element of lang_decl. So these two types can be used exchangable but need pay attention to not to exceed the boundary of lang_decl_flags when handling it as lang_decl. Field can_be_full in lang_decl_flags tells which type the node is, lang_decl_flags or lang_decl.

 

1601 struct lang_decl_flags GTY(())                                                                   in cp-tree.h

1602 {

1603   ENUM_BITFIELD(languages) language : 8;

1604

1605   unsigned operator_attr : 1;

1606   unsigned constructor_attr : 1;

1607   unsigned destructor_attr : 1;

1608   unsigned friend_attr : 1;

1609   unsigned static_function : 1;

1610   unsigned pure_virtual : 1;

1611   unsigned has_in_charge_parm_p : 1;

1612   unsigned has_vtt_parm_p : 1;

1613

1614   unsigned deferred : 1;

1615   unsigned use_template : 2;

1616   unsigned nonconverting : 1;

1617   unsigned not_really_extern : 1;

1618   unsigned needs_final_overrider : 1;

1619   unsigned initialized_in_class : 1;

1620   unsigned assignment_operator_p : 1;

1621

1622   unsigned global_ctor_p : 1;

1623   unsigned global_dtor_p : 1;

1624   unsigned anticipated_p : 1;

1625   unsigned template_conv_p : 1;

1626   unsigned u1sel : 1;

1627   unsigned u2sel : 1;

1628   unsigned can_be_full : 1;

1629   unsigned this_thunk_p : 1;

1630

1631   union lang_decl_u {

1632     /* In a FUNCTION_DECL for which DECL_THUNK_P does not hold,

1633       VAR_DECL, TYPE_DECL, or TEMPLATE_DECL, this is

1634       DECL_TEMPLATE_INFO.  */

1635     tree GTY ((tag ("0"))) template_info;

1636

1637     /* In a NAMESPACE_DECL, this is NAMESPACE_LEVEL.  */

1638     struct cp_binding_level * GTY ((tag ("1"))) level;

1639

1640     /* In a FUNCTION_DECL for which DECL_THUNK_P holds, this is

1641       THUNK_ALIAS.  */

1642     tree GTY ((tag ("2"))) thunk_alias;

1643   } GTY ((desc ("%1.u1sel"))) u;

1644

1645   union lang_decl_u2 {

1646     /* This is DECL_ACCESS.  */

1647     tree GTY ((tag ("0"))) access;

1648

1649     /* For VAR_DECL in function, this is DECL_DISCRIMINATOR.  */

1650     int GTY ((tag ("1"))) discriminator;

1651

1652     /* In a FUNCTION_DECL for which DECL_THUNK_P holds, this is

1653       THUNK_VIRTUAL_OFFSET.  */

1654     tree GTY((tag ("2"))) virtual_offset;

1655   } GTY ((desc ("%1.u2sel"))) u2;

1656 };

 

Notice that fields u[num]sel above, if nonzero indicates lang_decl_u[num] field in lang_decl/lang_decl_flags will be used.

This complex structure is created and initialized by retrofit_lang_decl according to the type of declaration.

 

701    void

702    retrofit_lang_decl (tree t)                                                                                 in lex.c

703    {

704      struct lang_decl *ld;

705      size_t size;

706   

707      if (CAN_HAVE_FULL_LANG_DECL_P (t))

708       size = sizeof (struct lang_decl);

709      else

710        size = sizeof (struct lang_decl_flags);

711    

抱歉!评论已关闭.