[PATCH][RFC] Transition C++ FE to use TRANSLATION_UNIT_DECL context for globals

Jason Merrill jason@redhat.com
Fri Sep 24 20:31:00 GMT 2010


On 09/24/2010 11:12 AM, Richard Guenther wrote:
> On Fri, 24 Sep 2010, Jason Merrill wrote:
>
>> Rather than start setting *_CONTEXT of file-scope entities to the
>> TRANSLATION_UNIT_DECL, it seems like we might as well just set it to
>> global_namespace so we can do away with CP_*_CONTEXT and simplify logic.  And
>> then maybe mark global_namespace as DECL_IGNORED_P or just have the debug
>> backends know that a namespace immediately inside the TRANSLATION_UNIT_DECL
>> doesn't need to be represented.
>
> That would need adjustment to the middle-end DECL_FILE_SCOPE_P which
> would need to recognize this case specially as well.  But yes, it seems
> easier for the C++ frontend (but likely causes a similar amount of
> fallout).

True.  I guess your direction is fine, then, but rather than open-coding

> !   if (context
> !       && TREE_CODE (context) != TRANSLATION_UNIT_DECL

make that a macro.

>     for (depth = 0;
> !        type && TREE_CODE (type) != NAMESPACE_DECL
> !        && TREE_CODE (type) != TRANSLATION_UNIT_DECL;
>          type = (TREE_CODE (type) == FUNCTION_DECL)
>   	 ? CP_DECL_CONTEXT (type) : TYPE_CONTEXT (type))

And here just use CP_TYPE_CONTEXT rather than TYPE_CONTEXT.

Jason



More information about the Gcc-patches mailing list