[cfe-commits] r147723 - in /cfe/trunk: include/clang/AST/DeclCXX.h include/clang/Basic/DiagnosticSemaKinds.td include/clang/Sema/ScopeInfo.h include/clang/Sema/Sema.h lib/AST/DeclCXX.cpp lib/Sema/Sema.cpp lib/Sema/SemaCodeComplete.cpp lib/Sema/SemaExpr.cpp lib/Sema/SemaExprCXX.cpp lib/Sema/SemaExprMember.cpp lib/Sema/SemaOverload.cpp test/Parser/objcxx0x-lambda-expressions.mm test/SemaCXX/lambda-expressions.cpp

John McCall rjmccall at apple.com
Mon Jan 9 09:26:50 PST 2012


On Jan 6, 2012, at 8:59 PM, Eli Friedman wrote:
> Modified: cfe/trunk/include/clang/Sema/ScopeInfo.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/ScopeInfo.h?rev=147723&r1=147722&r2=147723&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Sema/ScopeInfo.h (original)
> +++ cfe/trunk/include/clang/Sema/ScopeInfo.h Fri Jan  6 22:59:52 2012
> @@ -189,15 +189,20 @@
>   /// \brief A mapping from the set of captured variables to the 
>   /// fields (within the lambda class) that represent the captured variables.
>   llvm::DenseMap<VarDecl *, FieldDecl *> CapturedVariables;
> -  
> +
>   /// \brief The list of captured variables, starting with the explicit 
>   /// captures and then finishing with any implicit captures.
>   llvm::SmallVector<Capture, 4> Captures;
> -  
> +
> +  // \brief Whether we have already captured 'this'.
> +  bool CapturesCXXThis;
> +
>   /// \brief The number of captures in the \c Captures list that are 
>   /// explicit captures.
>   unsigned NumExplicitCaptures;
> -  
> +
> +  LambdaCaptureDefault Default;
> +
>   /// \brief The field associated with the captured 'this' pointer.
>   FieldDecl *ThisCapture;
> 
> @@ -208,8 +213,9 @@
>   QualType ReturnType;
> 
>   LambdaScopeInfo(DiagnosticsEngine &Diag, CXXRecordDecl *Lambda) 
> -    : FunctionScopeInfo(Diag), Lambda(Lambda), 
> -      NumExplicitCaptures(0), ThisCapture(0) , HasImplicitReturnType(false)
> +    : FunctionScopeInfo(Diag), Lambda(Lambda), CapturesCXXThis(false),
> +      NumExplicitCaptures(0), Default(LCD_None), ThisCapture(0),
> +      HasImplicitReturnType(false)
>   {
>     Kind = SK_Lambda;
>   }

Please do abstract out the common capture functionality between this and
BlockScopeInfo.  There's at least one more kind of capture (VLA typedef)
that really ought to go here in both cases.

> Modified: cfe/trunk/lib/Sema/Sema.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.cpp?rev=147723&r1=147722&r2=147723&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/Sema.cpp (original)
> +++ cfe/trunk/lib/Sema/Sema.cpp Fri Jan  6 22:59:52 2012
> @@ -636,8 +636,16 @@
> DeclContext *Sema::getFunctionLevelDeclContext() {
>   DeclContext *DC = CurContext;
> 
> -  while (isa<BlockDecl>(DC) || isa<EnumDecl>(DC))
> -    DC = DC->getParent();
> +  while (true) {
> +    if (isa<BlockDecl>(DC) || isa<EnumDecl>(DC)) {
> +      DC = DC->getParent();
> +    } else if (isa<CXXMethodDecl>(DC) &&
> +               cast<CXXRecordDecl>(DC->getParent())->hasDefinition() &&
> +               cast<CXXRecordDecl>(DC->getParent())->isLambda()) {
> +      DC = DC->getParent()->getParent();
> +    }
> +    else break;
> +  }
> 
>   return DC;
> }

The isLambda() check should be sufficient and much cheaper.

John.



More information about the cfe-commits mailing list