[cfe-dev] Trouble understand DeclContext

Serge Pavlov via cfe-dev cfe-dev at lists.llvm.org
Mon Feb 6 18:11:19 PST 2017


2017-02-07 6:08 GMT+07:00 David Fontaine via cfe-dev <cfe-dev at lists.llvm.org
>:

> Hi,
>
>
> I'm having trouble understanding the semantics of DeclContext.  The
> documentation on this class (as of 3.9) refers to "declaration contexts"
> which it does not define and which does not seem to be a concept from the
> standard.
>
>
> How was it determined which classes should inherit DeclContext?  When
> should a nested DeclContext be added and when is it okay to use an existing
> DeclContext?
>
>
> The DeclContext is a declaration that is a container for other
declarations. All non-leaf nodes of AST inherit it. If a contained
declaration itself can contain other declarations (nested class, method of
a class etc), it will be a nested DeclContext.

For example, DeclContext cannot correspond directly to declarative regions
> as defined in [basic.scope.declarative] (3.3.1) because only Decl subtypes
> inherit it.  A block, for example, is something that opens a new region,
> and in the AST it is a CompoundStmt, which is not a Decl.
>
>
> Declarative regions contained in expressions, like CompoundStmt, are
organized using Scope objects. However Scope is a parser notion, and is not
represented in AST.

> Also, how bad of an idea would it be to change the type hierarchy so more
> classes inherit DeclContext?
>
>
> Thanks,
>
> David Fontaine
> ------------------------------
> This email message is for the sole use of the intended recipient(s) and
> may contain confidential information.  Any unauthorized review, use,
> disclosure or distribution is prohibited.  If you are not the intended
> recipient, please contact the sender by reply email and destroy all copies
> of the original message.
> ------------------------------
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170207/e3555f74/attachment.html>


More information about the cfe-dev mailing list