[cfe-dev] Trouble understand DeclContext

David Fontaine via cfe-dev cfe-dev at lists.llvm.org
Mon Feb 6 18:41:32 PST 2017


Thank you Serge.


I was the person asking earlier about named parameter scoping rules in function pointer declarations.  Currently, these declarations are not in the AST.  I would like to add them ?so that they can be referenced by attribute expressions.


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


Based on this, it seems that VarDecl and FieldDecl should also inherit DeclContext, because a function pointer declaration, which may contain named parameters, would be one of those two.  Any opinion on this?



-David


________________________________
From: Serge Pavlov <sepavloff at gmail.com>
Sent: Monday, February 6, 2017 6:11 PM
To: David Fontaine
Cc: cfe-dev at lists.llvm.org
Subject: Re: [cfe-dev] Trouble understand DeclContext

2017-02-07 6:08 GMT+07:00 David Fontaine via cfe-dev <cfe-dev at lists.llvm.org<mailto: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<mailto: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/c855e9ad/attachment.html>


More information about the cfe-dev mailing list