[cfe-commits] [PATCH] Sema and AST for C++0x Lambda Expressions

John Freeman jfreeman at cse.tamu.edu
Sun Aug 14 10:50:15 PDT 2011


On 8/12/11 5:26 PM, Douglas Gregor wrote:
> +/// LambdaDecl - Represents a C++0x lambda expression.
> +class LambdaDecl : public Decl, public DeclContext {
>
> It would help if the comment here showed an example lambda expression, and pointed out the main pieces (capture list, body, etc.).
>
> Please add more source-location information to LambdaDecl, so we have at least enough source-location information to implement getSourceRange() for LambdaDecl, covering the entire declaration. We'll need this source information for diagnostics and indexing.
>
> +/// LambdaExpr - Adaptor class for mixing a LambdaDecl with expressions.
> +class LambdaExpr : public Expr {
> +  LambdaDecl *Lambda;
> +
>
> It's really not just an "adaptor", is it? It's the actual lambda expression. Please expand the comment with an example lambda expression. The commenting here is actually more important than for LambdaDecl, since lambdas are an expression in the language.


Yeah, I'm still trying to figure out the LambdaDecl/LambdaExpr 
distinction myself. I based it off of the BlockDecl/BlockExpr design. 
Here is my current theory: LambdaExpr should be the AST node returned 
from ParseLambdaExpression. It holds a LambdaDecl that contains all the 
declarations related to the lambda expression: Captures, CXXMethodDecl, 
CXXRecordDecl. Location information for the whole expression will be 
stored in LambdaExpr. Components will have their location information 
stored in their respective Captures, ParmVarDecls, Stmt, etc.

I'm starting to wonder, though, if we even need a LambdaDecl. Why not 
just put everything in the LambdaExpr? I have not come across a need for 
a Decl or DeclContext for lambdas, but I might have just not hit it yet.

- John



More information about the cfe-commits mailing list