[cfe-commits] [PATCH] Parsing C++0x lambda expressions

Douglas Gregor dgregor at apple.com
Thu Jul 14 08:39:57 PDT 2011


On Jul 13, 2011, at 7:07 PM, John Freeman wrote:

> On 7/13/2011 6:23 PM, Douglas Gregor wrote:
>> Do we want to save the locate not the '&' or '='? I guess it isn't necessary.
> 
> I can add it later if we need it.
> 
>> Should we have a custom diagnostic for &this?
> 
> Will tok::identifier match 'this'? Even if it does, I was trying to defer as many checks as possible to Sema. What is the recommended approach?

As you noted later, I was just asking for a custom diagnostic for &this, since I could imagine someone writing that.

> 
> Attached is an updated patch with suggested fixes.

More comments.

+  /// CXX0XLambdaCaptureList - Represents a complete lambda introducer.
+  /// FIXME: Rename to CXX0XLambdaIntroducer? 
+  struct CXX0XLambdaCaptureList {
+    SourceRange Range;
+    CXX0XLambdaCaptureDefault Default;
+    llvm::SmallVector<CXX0XLambdaCapture, 4> Captures;
+
+    CXX0XLambdaCaptureList()
+      : Default(LCD_None) {}
+  };

I like the name CXX0XLambdaIntroducer.

+/// If we are not looking at a lambda expression, returns ExprError().
+ExprResult Parser::TryParseCXX0XLambdaExpression() {
+  assert(getLang().CPlusPlus0x
+         && Tok.is(tok::l_square)
+         && "Not at the start of a possible lambda expression.");
+
+  const Token &Next = NextToken(), &After = GetLookAheadToken(2);

It's not super-important, but Next and After shouldn't be references... they'll just end up binding to a temporary anyway, and Tokens are small/cheap to copy.

+    // FIXME: Have to set this at the end of each thing parsed above.
+    SourceLocation DeclEndLoc;

This should be fairly easy to do, no?

This is looking great. A few minor tweaks requested above, plus we'll need a bunch of test cases to go into test/Parser to test out basic parsing, error recovery, etc.

	- Doug



More information about the cfe-commits mailing list