ScopeInfo.h revision fad9e13f3cb85198f0ee5af620ba81cd78574faa
1781472fe99a120098c631b0cbe33c89f8cef5e70John McCall//===--- ScopeInfo.h - Information about a semantic context -----*- C++ -*-===// 2781472fe99a120098c631b0cbe33c89f8cef5e70John McCall// 3781472fe99a120098c631b0cbe33c89f8cef5e70John McCall// The LLVM Compiler Infrastructure 4781472fe99a120098c631b0cbe33c89f8cef5e70John McCall// 5781472fe99a120098c631b0cbe33c89f8cef5e70John McCall// This file is distributed under the University of Illinois Open Source 6781472fe99a120098c631b0cbe33c89f8cef5e70John McCall// License. See LICENSE.TXT for details. 7781472fe99a120098c631b0cbe33c89f8cef5e70John McCall// 8781472fe99a120098c631b0cbe33c89f8cef5e70John McCall//===----------------------------------------------------------------------===// 9781472fe99a120098c631b0cbe33c89f8cef5e70John McCall// 10a55d32d1b8f799bf58c02540983976368c42d895Jordan Rose// This file defines FunctionScopeInfo and its subclasses, which contain 11a55d32d1b8f799bf58c02540983976368c42d895Jordan Rose// information about a single function, block, lambda, or method body. 12781472fe99a120098c631b0cbe33c89f8cef5e70John McCall// 13781472fe99a120098c631b0cbe33c89f8cef5e70John McCall//===----------------------------------------------------------------------===// 14781472fe99a120098c631b0cbe33c89f8cef5e70John McCall 15781472fe99a120098c631b0cbe33c89f8cef5e70John McCall#ifndef LLVM_CLANG_SEMA_SCOPE_INFO_H 16781472fe99a120098c631b0cbe33c89f8cef5e70John McCall#define LLVM_CLANG_SEMA_SCOPE_INFO_H 17781472fe99a120098c631b0cbe33c89f8cef5e70John McCall 18781472fe99a120098c631b0cbe33c89f8cef5e70John McCall#include "clang/AST/Type.h" 193a2f91280a49f4747063f983dc6a3296bd9359d2Ben Langmuir#include "clang/Basic/CapturedStmt.h" 20351ba91eaa6d30e523587b2d7ed676a5172c6e56Ted Kremenek#include "clang/Basic/PartialDiagnostic.h" 21781472fe99a120098c631b0cbe33c89f8cef5e70John McCall#include "llvm/ADT/DenseMap.h" 22781472fe99a120098c631b0cbe33c89f8cef5e70John McCall#include "llvm/ADT/SmallVector.h" 23781472fe99a120098c631b0cbe33c89f8cef5e70John McCall 24781472fe99a120098c631b0cbe33c89f8cef5e70John McCallnamespace clang { 25781472fe99a120098c631b0cbe33c89f8cef5e70John McCall 2658b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Roseclass Decl; 27781472fe99a120098c631b0cbe33c89f8cef5e70John McCallclass BlockDecl; 286afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Sirajclass CapturedDecl; 29f8af98286022f72157d84951b48fde5fb369ab29Douglas Gregorclass CXXMethodDecl; 300d8e9646bc000bab521ce52ed294209a92298cefRichard Smithclass FieldDecl; 317fffce781e6ecbf4058b24df7e5ae3037569aa56Jordan Roseclass ObjCPropertyDecl; 32781472fe99a120098c631b0cbe33c89f8cef5e70John McCallclass IdentifierInfo; 338c045ace381972f41d385b0a661ccf172834f459Ben Langmuirclass ImplicitParamDecl; 34ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattnerclass LabelDecl; 35781472fe99a120098c631b0cbe33c89f8cef5e70John McCallclass ReturnStmt; 36781472fe99a120098c631b0cbe33c89f8cef5e70John McCallclass Scope; 37781472fe99a120098c631b0cbe33c89f8cef5e70John McCallclass SwitchStmt; 38fad9e13f3cb85198f0ee5af620ba81cd78574faaFaisal Valiclass TemplateTypeParmDecl; 39fad9e13f3cb85198f0ee5af620ba81cd78574faaFaisal Valiclass TemplateParameterList; 40f8af98286022f72157d84951b48fde5fb369ab29Douglas Gregorclass VarDecl; 417a2704800943fbb69207e125d28186278712af36Jordan Roseclass DeclRefExpr; 427a2704800943fbb69207e125d28186278712af36Jordan Roseclass ObjCIvarRefExpr; 4358b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Roseclass ObjCPropertyRefExpr; 447fffce781e6ecbf4058b24df7e5ae3037569aa56Jordan Roseclass ObjCMessageExpr; 45781472fe99a120098c631b0cbe33c89f8cef5e70John McCall 46781472fe99a120098c631b0cbe33c89f8cef5e70John McCallnamespace sema { 47781472fe99a120098c631b0cbe33c89f8cef5e70John McCall 48625bb569df0c34feec0d52c0ec5215f21ef2e054Dmitri Gribenko/// \brief Contains information about the compound statement currently being 49625bb569df0c34feec0d52c0ec5215f21ef2e054Dmitri Gribenko/// parsed. 50625bb569df0c34feec0d52c0ec5215f21ef2e054Dmitri Gribenkoclass CompoundScopeInfo { 51625bb569df0c34feec0d52c0ec5215f21ef2e054Dmitri Gribenkopublic: 52625bb569df0c34feec0d52c0ec5215f21ef2e054Dmitri Gribenko CompoundScopeInfo() 53625bb569df0c34feec0d52c0ec5215f21ef2e054Dmitri Gribenko : HasEmptyLoopBodies(false) { } 54625bb569df0c34feec0d52c0ec5215f21ef2e054Dmitri Gribenko 55625bb569df0c34feec0d52c0ec5215f21ef2e054Dmitri Gribenko /// \brief Whether this compound stamement contains `for' or `while' loops 56625bb569df0c34feec0d52c0ec5215f21ef2e054Dmitri Gribenko /// with empty bodies. 57625bb569df0c34feec0d52c0ec5215f21ef2e054Dmitri Gribenko bool HasEmptyLoopBodies; 58625bb569df0c34feec0d52c0ec5215f21ef2e054Dmitri Gribenko 59625bb569df0c34feec0d52c0ec5215f21ef2e054Dmitri Gribenko void setHasEmptyLoopBodies() { 60625bb569df0c34feec0d52c0ec5215f21ef2e054Dmitri Gribenko HasEmptyLoopBodies = true; 61625bb569df0c34feec0d52c0ec5215f21ef2e054Dmitri Gribenko } 62625bb569df0c34feec0d52c0ec5215f21ef2e054Dmitri Gribenko}; 63625bb569df0c34feec0d52c0ec5215f21ef2e054Dmitri Gribenko 64351ba91eaa6d30e523587b2d7ed676a5172c6e56Ted Kremenekclass PossiblyUnreachableDiag { 65351ba91eaa6d30e523587b2d7ed676a5172c6e56Ted Kremenekpublic: 66351ba91eaa6d30e523587b2d7ed676a5172c6e56Ted Kremenek PartialDiagnostic PD; 67351ba91eaa6d30e523587b2d7ed676a5172c6e56Ted Kremenek SourceLocation Loc; 68351ba91eaa6d30e523587b2d7ed676a5172c6e56Ted Kremenek const Stmt *stmt; 69351ba91eaa6d30e523587b2d7ed676a5172c6e56Ted Kremenek 70351ba91eaa6d30e523587b2d7ed676a5172c6e56Ted Kremenek PossiblyUnreachableDiag(const PartialDiagnostic &PD, SourceLocation Loc, 71351ba91eaa6d30e523587b2d7ed676a5172c6e56Ted Kremenek const Stmt *stmt) 72351ba91eaa6d30e523587b2d7ed676a5172c6e56Ted Kremenek : PD(PD), Loc(Loc), stmt(stmt) {} 73351ba91eaa6d30e523587b2d7ed676a5172c6e56Ted Kremenek}; 74351ba91eaa6d30e523587b2d7ed676a5172c6e56Ted Kremenek 75781472fe99a120098c631b0cbe33c89f8cef5e70John McCall/// \brief Retains information about a function, method, or block that is 76781472fe99a120098c631b0cbe33c89f8cef5e70John McCall/// currently being parsed. 77781472fe99a120098c631b0cbe33c89f8cef5e70John McCallclass FunctionScopeInfo { 78ec9ea7200718478e8a976529defbe21942a11c9cEli Friedmanprotected: 79ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman enum ScopeKind { 80ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman SK_Function, 81ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman SK_Block, 826afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj SK_Lambda, 836afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj SK_CapturedRegion 84ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman }; 85ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman 86781472fe99a120098c631b0cbe33c89f8cef5e70John McCallpublic: 87ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman /// \brief What kind of scope we are describing. 88ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman /// 89ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman ScopeKind Kind; 90781472fe99a120098c631b0cbe33c89f8cef5e70John McCall 91809d1be9820039b4cf6efa48246a0d70ffa13394James Dennett /// \brief Whether this function contains a VLA, \@try, try, C++ 92781472fe99a120098c631b0cbe33c89f8cef5e70John McCall /// initializer, or anything else that can't be jumped past. 93781472fe99a120098c631b0cbe33c89f8cef5e70John McCall bool HasBranchProtectedScope; 94781472fe99a120098c631b0cbe33c89f8cef5e70John McCall 95781472fe99a120098c631b0cbe33c89f8cef5e70John McCall /// \brief Whether this function contains any switches or direct gotos. 96781472fe99a120098c631b0cbe33c89f8cef5e70John McCall bool HasBranchIntoScope; 97781472fe99a120098c631b0cbe33c89f8cef5e70John McCall 98781472fe99a120098c631b0cbe33c89f8cef5e70John McCall /// \brief Whether this function contains any indirect gotos. 99781472fe99a120098c631b0cbe33c89f8cef5e70John McCall bool HasIndirectGoto; 100781472fe99a120098c631b0cbe33c89f8cef5e70John McCall 101820b23dc924a4ae7af07d5a75d6b1d781c267d57Argyrios Kyrtzidis /// \brief Whether a statement was dropped because it was invalid. 102820b23dc924a4ae7af07d5a75d6b1d781c267d57Argyrios Kyrtzidis bool HasDroppedStmt; 103820b23dc924a4ae7af07d5a75d6b1d781c267d57Argyrios Kyrtzidis 104535a5d001b2035a7aa68ee368fbe44ec90e33740Jordan Rose /// A flag that is set when parsing a method that must call super's 105535a5d001b2035a7aa68ee368fbe44ec90e33740Jordan Rose /// implementation, such as \c -dealloc, \c -finalize, or any method marked 106535a5d001b2035a7aa68ee368fbe44ec90e33740Jordan Rose /// with \c __attribute__((objc_requires_super)). 107535a5d001b2035a7aa68ee368fbe44ec90e33740Jordan Rose bool ObjCShouldCallSuper; 10895aac15936e8362aeb4813f95bc255dee6473592Eli Friedman 1098fc32d272bd57b0a59f61c874cb7b56d9005e89eArgyrios Kyrtzidis /// \brief Used to determine if errors occurred in this function or block. 1108fc32d272bd57b0a59f61c874cb7b56d9005e89eArgyrios Kyrtzidis DiagnosticErrorTrap ErrorTrap; 111781472fe99a120098c631b0cbe33c89f8cef5e70John McCall 112781472fe99a120098c631b0cbe33c89f8cef5e70John McCall /// SwitchStack - This is the current set of active switch statements in the 113781472fe99a120098c631b0cbe33c89f8cef5e70John McCall /// block. 114686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<SwitchStmt*, 8> SwitchStack; 115781472fe99a120098c631b0cbe33c89f8cef5e70John McCall 116781472fe99a120098c631b0cbe33c89f8cef5e70John McCall /// \brief The list of return statements that occur within the function or 117781472fe99a120098c631b0cbe33c89f8cef5e70John McCall /// block, if there is any chance of applying the named return value 1187dd900ed308506f9cf1cb72c70db1652f94cab37Jordan Rose /// optimization, or if we need to infer a return type. 119686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<ReturnStmt*, 4> Returns; 120625bb569df0c34feec0d52c0ec5215f21ef2e054Dmitri Gribenko 121625bb569df0c34feec0d52c0ec5215f21ef2e054Dmitri Gribenko /// \brief The stack of currently active compound stamement scopes in the 122625bb569df0c34feec0d52c0ec5215f21ef2e054Dmitri Gribenko /// function. 123625bb569df0c34feec0d52c0ec5215f21ef2e054Dmitri Gribenko SmallVector<CompoundScopeInfo, 4> CompoundScopes; 124625bb569df0c34feec0d52c0ec5215f21ef2e054Dmitri Gribenko 125351ba91eaa6d30e523587b2d7ed676a5172c6e56Ted Kremenek /// \brief A list of PartialDiagnostics created but delayed within the 126351ba91eaa6d30e523587b2d7ed676a5172c6e56Ted Kremenek /// current function scope. These diagnostics are vetted for reachability 127351ba91eaa6d30e523587b2d7ed676a5172c6e56Ted Kremenek /// prior to being emitted. 128686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<PossiblyUnreachableDiag, 4> PossiblyUnreachableDiags; 129781472fe99a120098c631b0cbe33c89f8cef5e70John McCall 13058b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rosepublic: 13158b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose /// Represents a simple identification of a weak object. 13258b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose /// 13358b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose /// Part of the implementation of -Wrepeated-use-of-weak. 13458b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose /// 13558b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose /// This is used to determine if two weak accesses refer to the same object. 13658b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose /// Here are some examples of how various accesses are "profiled": 13758b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose /// 13858b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose /// Access Expression | "Base" Decl | "Property" Decl 13958b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose /// :---------------: | :-----------------: | :------------------------------: 14058b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose /// self.property | self (VarDecl) | property (ObjCPropertyDecl) 14158b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose /// self.implicitProp | self (VarDecl) | -implicitProp (ObjCMethodDecl) 14258b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose /// self->ivar.prop | ivar (ObjCIvarDecl) | prop (ObjCPropertyDecl) 14358b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose /// cxxObj.obj.prop | obj (FieldDecl) | prop (ObjCPropertyDecl) 14458b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose /// [self foo].prop | 0 (unknown) | prop (ObjCPropertyDecl) 14558b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose /// self.prop1.prop2 | prop1 (ObjCPropertyDecl) | prop2 (ObjCPropertyDecl) 14658b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose /// MyClass.prop | MyClass (ObjCInterfaceDecl) | -prop (ObjCMethodDecl) 1477a2704800943fbb69207e125d28186278712af36Jordan Rose /// weakVar | 0 (known) | weakVar (VarDecl) 1487a2704800943fbb69207e125d28186278712af36Jordan Rose /// self->weakIvar | self (VarDecl) | weakIvar (ObjCIvarDecl) 14958b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose /// 15058b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose /// Objects are identified with only two Decls to make it reasonably fast to 15158b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose /// compare them. 15258b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose class WeakObjectProfileTy { 15358b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose /// The base object decl, as described in the class documentation. 15458b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose /// 15558b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose /// The extra flag is "true" if the Base and Property are enough to uniquely 15658b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose /// identify the object in memory. 15758b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose /// 15858b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose /// \sa isExactProfile() 15958b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose typedef llvm::PointerIntPair<const NamedDecl *, 1, bool> BaseInfoTy; 16058b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose BaseInfoTy Base; 16158b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose 16258b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose /// The "property" decl, as described in the class documentation. 16358b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose /// 16458b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose /// Note that this may not actually be an ObjCPropertyDecl, e.g. in the 16558b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose /// case of "implicit" properties (regular methods accessed via dot syntax). 16658b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose const NamedDecl *Property; 16758b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose 1687a2704800943fbb69207e125d28186278712af36Jordan Rose /// Used to find the proper base profile for a given base expression. 1697a2704800943fbb69207e125d28186278712af36Jordan Rose static BaseInfoTy getBaseInfo(const Expr *BaseE); 1707a2704800943fbb69207e125d28186278712af36Jordan Rose 17158b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose // For use in DenseMap. 172b6d80fe68d30ebd14b20c96643c252c36041df8dJordan Rose friend class DenseMapInfo; 17358b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose inline WeakObjectProfileTy(); 17458b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose static inline WeakObjectProfileTy getSentinel(); 17558b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose 17658b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose public: 17758b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose WeakObjectProfileTy(const ObjCPropertyRefExpr *RE); 1787fffce781e6ecbf4058b24df7e5ae3037569aa56Jordan Rose WeakObjectProfileTy(const Expr *Base, const ObjCPropertyDecl *Property); 1797a2704800943fbb69207e125d28186278712af36Jordan Rose WeakObjectProfileTy(const DeclRefExpr *RE); 1807a2704800943fbb69207e125d28186278712af36Jordan Rose WeakObjectProfileTy(const ObjCIvarRefExpr *RE); 18158b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose 182c0e44454bd78b8b4f3d70f08cf1edd5466b0c798Jordan Rose const NamedDecl *getBase() const { return Base.getPointer(); } 18358b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose const NamedDecl *getProperty() const { return Property; } 18458b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose 18558b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose /// Returns true if the object base specifies a known object in memory, 18658b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose /// rather than, say, an instance variable or property of another object. 18758b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose /// 18858b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose /// Note that this ignores the effects of aliasing; that is, \c foo.bar is 18958b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose /// considered an exact profile if \c foo is a local variable, even if 19058b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose /// another variable \c foo2 refers to the same object as \c foo. 19158b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose /// 19258b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose /// For increased precision, accesses with base variables that are 19358b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose /// properties or ivars of 'self' (e.g. self.prop1.prop2) are considered to 19458b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose /// be exact, though this is not true for arbitrary variables 19558b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose /// (foo.prop1.prop2). 19658b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose bool isExactProfile() const { 19758b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose return Base.getInt(); 19858b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose } 19958b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose 20058b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose bool operator==(const WeakObjectProfileTy &Other) const { 20158b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose return Base == Other.Base && Property == Other.Property; 20258b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose } 203b6d80fe68d30ebd14b20c96643c252c36041df8dJordan Rose 204b6d80fe68d30ebd14b20c96643c252c36041df8dJordan Rose // For use in DenseMap. 205b6d80fe68d30ebd14b20c96643c252c36041df8dJordan Rose // We can't specialize the usual llvm::DenseMapInfo at the end of the file 206b6d80fe68d30ebd14b20c96643c252c36041df8dJordan Rose // because by that point the DenseMap in FunctionScopeInfo has already been 207b6d80fe68d30ebd14b20c96643c252c36041df8dJordan Rose // instantiated. 208b6d80fe68d30ebd14b20c96643c252c36041df8dJordan Rose class DenseMapInfo { 209b6d80fe68d30ebd14b20c96643c252c36041df8dJordan Rose public: 210b6d80fe68d30ebd14b20c96643c252c36041df8dJordan Rose static inline WeakObjectProfileTy getEmptyKey() { 211b6d80fe68d30ebd14b20c96643c252c36041df8dJordan Rose return WeakObjectProfileTy(); 212b6d80fe68d30ebd14b20c96643c252c36041df8dJordan Rose } 213b6d80fe68d30ebd14b20c96643c252c36041df8dJordan Rose static inline WeakObjectProfileTy getTombstoneKey() { 214b6d80fe68d30ebd14b20c96643c252c36041df8dJordan Rose return WeakObjectProfileTy::getSentinel(); 215b6d80fe68d30ebd14b20c96643c252c36041df8dJordan Rose } 216b6d80fe68d30ebd14b20c96643c252c36041df8dJordan Rose 217b6d80fe68d30ebd14b20c96643c252c36041df8dJordan Rose static unsigned getHashValue(const WeakObjectProfileTy &Val) { 218b6d80fe68d30ebd14b20c96643c252c36041df8dJordan Rose typedef std::pair<BaseInfoTy, const NamedDecl *> Pair; 219b6d80fe68d30ebd14b20c96643c252c36041df8dJordan Rose return llvm::DenseMapInfo<Pair>::getHashValue(Pair(Val.Base, 220b6d80fe68d30ebd14b20c96643c252c36041df8dJordan Rose Val.Property)); 221b6d80fe68d30ebd14b20c96643c252c36041df8dJordan Rose } 222b6d80fe68d30ebd14b20c96643c252c36041df8dJordan Rose 223b6d80fe68d30ebd14b20c96643c252c36041df8dJordan Rose static bool isEqual(const WeakObjectProfileTy &LHS, 224b6d80fe68d30ebd14b20c96643c252c36041df8dJordan Rose const WeakObjectProfileTy &RHS) { 225b6d80fe68d30ebd14b20c96643c252c36041df8dJordan Rose return LHS == RHS; 226b6d80fe68d30ebd14b20c96643c252c36041df8dJordan Rose } 227b6d80fe68d30ebd14b20c96643c252c36041df8dJordan Rose }; 22858b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose }; 22958b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose 23058b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose /// Represents a single use of a weak object. 23158b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose /// 23258b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose /// Stores both the expression and whether the access is potentially unsafe 23358b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose /// (i.e. it could potentially be warned about). 23458b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose /// 23558b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose /// Part of the implementation of -Wrepeated-use-of-weak. 23658b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose class WeakUseTy { 23758b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose llvm::PointerIntPair<const Expr *, 1, bool> Rep; 23858b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose public: 23958b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose WeakUseTy(const Expr *Use, bool IsRead) : Rep(Use, IsRead) {} 24058b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose 24158b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose const Expr *getUseExpr() const { return Rep.getPointer(); } 24258b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose bool isUnsafe() const { return Rep.getInt(); } 24358b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose void markSafe() { Rep.setInt(false); } 24458b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose 24558b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose bool operator==(const WeakUseTy &Other) const { 24658b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose return Rep == Other.Rep; 24758b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose } 24858b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose }; 24958b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose 25058b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose /// Used to collect uses of a particular weak object in a function body. 25158b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose /// 25258b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose /// Part of the implementation of -Wrepeated-use-of-weak. 25358b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose typedef SmallVector<WeakUseTy, 4> WeakUseVector; 25458b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose 25558b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose /// Used to collect all uses of weak objects in a function body. 25658b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose /// 25758b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose /// Part of the implementation of -Wrepeated-use-of-weak. 258b6d80fe68d30ebd14b20c96643c252c36041df8dJordan Rose typedef llvm::SmallDenseMap<WeakObjectProfileTy, WeakUseVector, 8, 259b6d80fe68d30ebd14b20c96643c252c36041df8dJordan Rose WeakObjectProfileTy::DenseMapInfo> 26058b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose WeakObjectUseMap; 26158b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose 26258b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Roseprivate: 26358b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose /// Used to collect all uses of weak objects in this function body. 26458b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose /// 26558b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose /// Part of the implementation of -Wrepeated-use-of-weak. 26658b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose WeakObjectUseMap WeakObjectUses; 26758b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose 26858b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rosepublic: 2697a2704800943fbb69207e125d28186278712af36Jordan Rose /// Record that a weak object was accessed. 27058b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose /// 27158b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose /// Part of the implementation of -Wrepeated-use-of-weak. 2727a2704800943fbb69207e125d28186278712af36Jordan Rose template <typename ExprT> 2737a2704800943fbb69207e125d28186278712af36Jordan Rose inline void recordUseOfWeak(const ExprT *E, bool IsRead = true); 27458b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose 2757fffce781e6ecbf4058b24df7e5ae3037569aa56Jordan Rose void recordUseOfWeak(const ObjCMessageExpr *Msg, 2767fffce781e6ecbf4058b24df7e5ae3037569aa56Jordan Rose const ObjCPropertyDecl *Prop); 2777fffce781e6ecbf4058b24df7e5ae3037569aa56Jordan Rose 27858b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose /// Record that a given expression is a "safe" access of a weak object (e.g. 27958b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose /// assigning it to a strong variable.) 28058b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose /// 28158b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose /// Part of the implementation of -Wrepeated-use-of-weak. 28258b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose void markSafeWeakUse(const Expr *E); 28358b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose 28458b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose const WeakObjectUseMap &getWeakObjectUses() const { 28558b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose return WeakObjectUses; 28658b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose } 28758b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose 288781472fe99a120098c631b0cbe33c89f8cef5e70John McCall void setHasBranchIntoScope() { 289781472fe99a120098c631b0cbe33c89f8cef5e70John McCall HasBranchIntoScope = true; 290781472fe99a120098c631b0cbe33c89f8cef5e70John McCall } 291781472fe99a120098c631b0cbe33c89f8cef5e70John McCall 292781472fe99a120098c631b0cbe33c89f8cef5e70John McCall void setHasBranchProtectedScope() { 293781472fe99a120098c631b0cbe33c89f8cef5e70John McCall HasBranchProtectedScope = true; 294781472fe99a120098c631b0cbe33c89f8cef5e70John McCall } 295781472fe99a120098c631b0cbe33c89f8cef5e70John McCall 296781472fe99a120098c631b0cbe33c89f8cef5e70John McCall void setHasIndirectGoto() { 297781472fe99a120098c631b0cbe33c89f8cef5e70John McCall HasIndirectGoto = true; 298781472fe99a120098c631b0cbe33c89f8cef5e70John McCall } 299781472fe99a120098c631b0cbe33c89f8cef5e70John McCall 300820b23dc924a4ae7af07d5a75d6b1d781c267d57Argyrios Kyrtzidis void setHasDroppedStmt() { 301820b23dc924a4ae7af07d5a75d6b1d781c267d57Argyrios Kyrtzidis HasDroppedStmt = true; 302820b23dc924a4ae7af07d5a75d6b1d781c267d57Argyrios Kyrtzidis } 303820b23dc924a4ae7af07d5a75d6b1d781c267d57Argyrios Kyrtzidis 304781472fe99a120098c631b0cbe33c89f8cef5e70John McCall bool NeedsScopeChecking() const { 305820b23dc924a4ae7af07d5a75d6b1d781c267d57Argyrios Kyrtzidis return !HasDroppedStmt && 306820b23dc924a4ae7af07d5a75d6b1d781c267d57Argyrios Kyrtzidis (HasIndirectGoto || 307820b23dc924a4ae7af07d5a75d6b1d781c267d57Argyrios Kyrtzidis (HasBranchProtectedScope && HasBranchIntoScope)); 308781472fe99a120098c631b0cbe33c89f8cef5e70John McCall } 309781472fe99a120098c631b0cbe33c89f8cef5e70John McCall 310d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie FunctionScopeInfo(DiagnosticsEngine &Diag) 311ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman : Kind(SK_Function), 312781472fe99a120098c631b0cbe33c89f8cef5e70John McCall HasBranchProtectedScope(false), 313781472fe99a120098c631b0cbe33c89f8cef5e70John McCall HasBranchIntoScope(false), 314781472fe99a120098c631b0cbe33c89f8cef5e70John McCall HasIndirectGoto(false), 315820b23dc924a4ae7af07d5a75d6b1d781c267d57Argyrios Kyrtzidis HasDroppedStmt(false), 316535a5d001b2035a7aa68ee368fbe44ec90e33740Jordan Rose ObjCShouldCallSuper(false), 3178fc32d272bd57b0a59f61c874cb7b56d9005e89eArgyrios Kyrtzidis ErrorTrap(Diag) { } 318781472fe99a120098c631b0cbe33c89f8cef5e70John McCall 319781472fe99a120098c631b0cbe33c89f8cef5e70John McCall virtual ~FunctionScopeInfo(); 320781472fe99a120098c631b0cbe33c89f8cef5e70John McCall 321781472fe99a120098c631b0cbe33c89f8cef5e70John McCall /// \brief Clear out the information in this function scope, making it 322781472fe99a120098c631b0cbe33c89f8cef5e70John McCall /// suitable for reuse. 3238fc32d272bd57b0a59f61c874cb7b56d9005e89eArgyrios Kyrtzidis void Clear(); 324781472fe99a120098c631b0cbe33c89f8cef5e70John McCall}; 325781472fe99a120098c631b0cbe33c89f8cef5e70John McCall 326b69b42c55d56815bab62991bf839cdb41634d3afEli Friedmanclass CapturingScopeInfo : public FunctionScopeInfo { 327b69b42c55d56815bab62991bf839cdb41634d3afEli Friedmanpublic: 328b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman enum ImplicitCaptureStyle { 3296afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj ImpCap_None, ImpCap_LambdaByval, ImpCap_LambdaByref, ImpCap_Block, 3306afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj ImpCap_CapturedRegion 331b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman }; 332b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman 333b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman ImplicitCaptureStyle ImpCaptureStyle; 334b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman 335b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman class Capture { 3360d8e9646bc000bab521ce52ed294209a92298cefRichard Smith // There are three categories of capture: capturing 'this', capturing 3370d8e9646bc000bab521ce52ed294209a92298cefRichard Smith // local variables, and C++1y initialized captures (which can have an 3380d8e9646bc000bab521ce52ed294209a92298cefRichard Smith // arbitrary initializer, and don't really capture in the traditional 3390d8e9646bc000bab521ce52ed294209a92298cefRichard Smith // sense at all). 3400d8e9646bc000bab521ce52ed294209a92298cefRichard Smith // 3410d8e9646bc000bab521ce52ed294209a92298cefRichard Smith // There are three ways to capture a local variable: 3420d8e9646bc000bab521ce52ed294209a92298cefRichard Smith // - capture by copy in the C++11 sense, 3430d8e9646bc000bab521ce52ed294209a92298cefRichard Smith // - capture by reference in the C++11 sense, and 3440d8e9646bc000bab521ce52ed294209a92298cefRichard Smith // - __block capture. 3450d8e9646bc000bab521ce52ed294209a92298cefRichard Smith // Lambdas explicitly specify capture by copy or capture by reference. 3460d8e9646bc000bab521ce52ed294209a92298cefRichard Smith // For blocks, __block capture applies to variables with that annotation, 3470d8e9646bc000bab521ce52ed294209a92298cefRichard Smith // variables of reference type are captured by reference, and other 3480d8e9646bc000bab521ce52ed294209a92298cefRichard Smith // variables are captured by copy. 349b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman enum CaptureKind { 3500d8e9646bc000bab521ce52ed294209a92298cefRichard Smith Cap_ByCopy, Cap_ByRef, Cap_Block, Cap_ThisOrInit 351b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman }; 352b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman 3530d8e9646bc000bab521ce52ed294209a92298cefRichard Smith // The variable being captured (if we are not capturing 'this', and whether 3540d8e9646bc000bab521ce52ed294209a92298cefRichard Smith // this is a nested capture; the expression is only required if we are 3550d8e9646bc000bab521ce52ed294209a92298cefRichard Smith // capturing ByVal and the variable's type has a non-trivial copy 3560d8e9646bc000bab521ce52ed294209a92298cefRichard Smith // constructor, or for an initialized capture. 3570d8e9646bc000bab521ce52ed294209a92298cefRichard Smith typedef llvm::PointerIntPair<VarDecl*, 1, bool> VarAndNested; 358b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman 3590d8e9646bc000bab521ce52ed294209a92298cefRichard Smith // The variable being captured, or the implicitly-generated field for 3600d8e9646bc000bab521ce52ed294209a92298cefRichard Smith // an init-capture. 3610d8e9646bc000bab521ce52ed294209a92298cefRichard Smith llvm::PointerUnion<VarAndNested, FieldDecl*> VarOrField; 362b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman 3630d8e9646bc000bab521ce52ed294209a92298cefRichard Smith // Expression to initialize a field of the given type, and the kind of 3640d8e9646bc000bab521ce52ed294209a92298cefRichard Smith // capture (if this is a capture and not an init-capture). 3650d8e9646bc000bab521ce52ed294209a92298cefRichard Smith llvm::PointerIntPair<Expr*, 2, CaptureKind> InitExprAndCaptureKind; 3660d8e9646bc000bab521ce52ed294209a92298cefRichard Smith 3670d8e9646bc000bab521ce52ed294209a92298cefRichard Smith /// \brief The source location at which the first capture occurred. 36893962e5360a43200faa70939571afc4fb9326cf7Douglas Gregor SourceLocation Loc; 3690d8e9646bc000bab521ce52ed294209a92298cefRichard Smith 370a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor /// \brief The location of the ellipsis that expands a parameter pack. 371a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor SourceLocation EllipsisLoc; 3720d8e9646bc000bab521ce52ed294209a92298cefRichard Smith 373999713eea940f4e087cc3ac878689c5c5c7a7225Douglas Gregor /// \brief The type as it was captured, which is in effect the type of the 374999713eea940f4e087cc3ac878689c5c5c7a7225Douglas Gregor /// non-static data member that would hold the capture. 375999713eea940f4e087cc3ac878689c5c5c7a7225Douglas Gregor QualType CaptureType; 3760d8e9646bc000bab521ce52ed294209a92298cefRichard Smith 377b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman public: 3780d8e9646bc000bab521ce52ed294209a92298cefRichard Smith Capture(VarDecl *Var, bool Block, bool ByRef, bool IsNested, 3790d8e9646bc000bab521ce52ed294209a92298cefRichard Smith SourceLocation Loc, SourceLocation EllipsisLoc, 380999713eea940f4e087cc3ac878689c5c5c7a7225Douglas Gregor QualType CaptureType, Expr *Cpy) 3810d8e9646bc000bab521ce52ed294209a92298cefRichard Smith : VarOrField(VarAndNested(Var, IsNested)), 3820d8e9646bc000bab521ce52ed294209a92298cefRichard Smith InitExprAndCaptureKind(Cpy, Block ? Cap_Block : 3830d8e9646bc000bab521ce52ed294209a92298cefRichard Smith ByRef ? Cap_ByRef : Cap_ByCopy), 3840d8e9646bc000bab521ce52ed294209a92298cefRichard Smith Loc(Loc), EllipsisLoc(EllipsisLoc), CaptureType(CaptureType) {} 385b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman 386b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman enum IsThisCapture { ThisCapture }; 3870d8e9646bc000bab521ce52ed294209a92298cefRichard Smith Capture(IsThisCapture, bool IsNested, SourceLocation Loc, 388999713eea940f4e087cc3ac878689c5c5c7a7225Douglas Gregor QualType CaptureType, Expr *Cpy) 3890d8e9646bc000bab521ce52ed294209a92298cefRichard Smith : VarOrField(VarAndNested(0, IsNested)), 3900d8e9646bc000bab521ce52ed294209a92298cefRichard Smith InitExprAndCaptureKind(Cpy, Cap_ThisOrInit), 3910d8e9646bc000bab521ce52ed294209a92298cefRichard Smith Loc(Loc), EllipsisLoc(), CaptureType(CaptureType) {} 392b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman 3930d8e9646bc000bab521ce52ed294209a92298cefRichard Smith Capture(FieldDecl *Field, Expr *Init) 3940d8e9646bc000bab521ce52ed294209a92298cefRichard Smith : VarOrField(Field), InitExprAndCaptureKind(Init, Cap_ThisOrInit), 3950d8e9646bc000bab521ce52ed294209a92298cefRichard Smith Loc(), EllipsisLoc(), CaptureType() {} 3960d8e9646bc000bab521ce52ed294209a92298cefRichard Smith 3970d8e9646bc000bab521ce52ed294209a92298cefRichard Smith bool isThisCapture() const { 3980d8e9646bc000bab521ce52ed294209a92298cefRichard Smith return InitExprAndCaptureKind.getInt() == Cap_ThisOrInit && 3990d8e9646bc000bab521ce52ed294209a92298cefRichard Smith VarOrField.is<VarAndNested>(); 4000d8e9646bc000bab521ce52ed294209a92298cefRichard Smith } 4010d8e9646bc000bab521ce52ed294209a92298cefRichard Smith bool isVariableCapture() const { 4020d8e9646bc000bab521ce52ed294209a92298cefRichard Smith return InitExprAndCaptureKind.getInt() != Cap_ThisOrInit; 4030d8e9646bc000bab521ce52ed294209a92298cefRichard Smith } 4040d8e9646bc000bab521ce52ed294209a92298cefRichard Smith bool isInitCapture() const { 4050d8e9646bc000bab521ce52ed294209a92298cefRichard Smith return VarOrField.is<FieldDecl*>(); 4060d8e9646bc000bab521ce52ed294209a92298cefRichard Smith } 4070d8e9646bc000bab521ce52ed294209a92298cefRichard Smith bool isCopyCapture() const { 4080d8e9646bc000bab521ce52ed294209a92298cefRichard Smith return InitExprAndCaptureKind.getInt() == Cap_ByCopy; 4090d8e9646bc000bab521ce52ed294209a92298cefRichard Smith } 4100d8e9646bc000bab521ce52ed294209a92298cefRichard Smith bool isReferenceCapture() const { 4110d8e9646bc000bab521ce52ed294209a92298cefRichard Smith return InitExprAndCaptureKind.getInt() == Cap_ByRef; 4120d8e9646bc000bab521ce52ed294209a92298cefRichard Smith } 4130d8e9646bc000bab521ce52ed294209a92298cefRichard Smith bool isBlockCapture() const { 4140d8e9646bc000bab521ce52ed294209a92298cefRichard Smith return InitExprAndCaptureKind.getInt() == Cap_Block; 4150d8e9646bc000bab521ce52ed294209a92298cefRichard Smith } 4160d8e9646bc000bab521ce52ed294209a92298cefRichard Smith bool isNested() { return VarOrField.dyn_cast<VarAndNested>().getInt(); } 417b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman 418b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman VarDecl *getVariable() const { 4190d8e9646bc000bab521ce52ed294209a92298cefRichard Smith return VarOrField.dyn_cast<VarAndNested>().getPointer(); 4200d8e9646bc000bab521ce52ed294209a92298cefRichard Smith } 4210d8e9646bc000bab521ce52ed294209a92298cefRichard Smith FieldDecl *getInitCaptureField() const { 4220d8e9646bc000bab521ce52ed294209a92298cefRichard Smith return VarOrField.dyn_cast<FieldDecl*>(); 423b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman } 42493962e5360a43200faa70939571afc4fb9326cf7Douglas Gregor 42593962e5360a43200faa70939571afc4fb9326cf7Douglas Gregor /// \brief Retrieve the location at which this variable was captured. 42693962e5360a43200faa70939571afc4fb9326cf7Douglas Gregor SourceLocation getLocation() const { return Loc; } 42793962e5360a43200faa70939571afc4fb9326cf7Douglas Gregor 428a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor /// \brief Retrieve the source location of the ellipsis, whose presence 429a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor /// indicates that the capture is a pack expansion. 430a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor SourceLocation getEllipsisLoc() const { return EllipsisLoc; } 431a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor 432999713eea940f4e087cc3ac878689c5c5c7a7225Douglas Gregor /// \brief Retrieve the capture type for this capture, which is effectively 433999713eea940f4e087cc3ac878689c5c5c7a7225Douglas Gregor /// the type of the non-static data member in the lambda/block structure 434999713eea940f4e087cc3ac878689c5c5c7a7225Douglas Gregor /// that would store this capture. 435999713eea940f4e087cc3ac878689c5c5c7a7225Douglas Gregor QualType getCaptureType() const { return CaptureType; } 436999713eea940f4e087cc3ac878689c5c5c7a7225Douglas Gregor 4370d8e9646bc000bab521ce52ed294209a92298cefRichard Smith Expr *getInitExpr() const { 4380d8e9646bc000bab521ce52ed294209a92298cefRichard Smith return InitExprAndCaptureKind.getPointer(); 439b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman } 440b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman }; 441b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman 442b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman CapturingScopeInfo(DiagnosticsEngine &Diag, ImplicitCaptureStyle Style) 44384b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman : FunctionScopeInfo(Diag), ImpCaptureStyle(Style), CXXThisCaptureIndex(0), 44484b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman HasImplicitReturnType(false) 445b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman {} 446b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman 447b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman /// CaptureMap - A map of captured variables to (index+1) into Captures. 448b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman llvm::DenseMap<VarDecl*, unsigned> CaptureMap; 449b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman 450b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman /// CXXThisCaptureIndex - The (index+1) of the capture of 'this'; 451b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman /// zero if 'this' is not captured. 452b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman unsigned CXXThisCaptureIndex; 453b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman 454b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman /// Captures - The captures. 455b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman SmallVector<Capture, 4> Captures; 456b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman 45784b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman /// \brief - Whether the target type of return statements in this context 45884b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman /// is deduced (e.g. a lambda or block with omitted return type). 45984b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman bool HasImplicitReturnType; 46084b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman 46184b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman /// ReturnType - The target type of return statements in this context, 46284b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman /// or null if unknown. 46384b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman QualType ReturnType; 46484b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman 465999713eea940f4e087cc3ac878689c5c5c7a7225Douglas Gregor void addCapture(VarDecl *Var, bool isBlock, bool isByref, bool isNested, 466999713eea940f4e087cc3ac878689c5c5c7a7225Douglas Gregor SourceLocation Loc, SourceLocation EllipsisLoc, 467999713eea940f4e087cc3ac878689c5c5c7a7225Douglas Gregor QualType CaptureType, Expr *Cpy) { 468a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor Captures.push_back(Capture(Var, isBlock, isByref, isNested, Loc, 469999713eea940f4e087cc3ac878689c5c5c7a7225Douglas Gregor EllipsisLoc, CaptureType, Cpy)); 470b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman CaptureMap[Var] = Captures.size(); 471b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman } 472b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman 473999713eea940f4e087cc3ac878689c5c5c7a7225Douglas Gregor void addThisCapture(bool isNested, SourceLocation Loc, QualType CaptureType, 474c3f1742bdd1ae0091d51168e111cd63861587b13Douglas Gregor Expr *Cpy); 475b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman 4760d8e9646bc000bab521ce52ed294209a92298cefRichard Smith void addInitCapture(FieldDecl *Field, Expr *Init) { 4770d8e9646bc000bab521ce52ed294209a92298cefRichard Smith Captures.push_back(Capture(Field, Init)); 4780d8e9646bc000bab521ce52ed294209a92298cefRichard Smith } 4790d8e9646bc000bab521ce52ed294209a92298cefRichard Smith 480a1f2114d9e81923c750f6b439302ac03552c37dbDouglas Gregor /// \brief Determine whether the C++ 'this' is captured. 481a1f2114d9e81923c750f6b439302ac03552c37dbDouglas Gregor bool isCXXThisCaptured() const { return CXXThisCaptureIndex != 0; } 482a1f2114d9e81923c750f6b439302ac03552c37dbDouglas Gregor 483a1f2114d9e81923c750f6b439302ac03552c37dbDouglas Gregor /// \brief Retrieve the capture of C++ 'this', if it has been captured. 484a1f2114d9e81923c750f6b439302ac03552c37dbDouglas Gregor Capture &getCXXThisCapture() { 485a1f2114d9e81923c750f6b439302ac03552c37dbDouglas Gregor assert(isCXXThisCaptured() && "this has not been captured"); 486a1f2114d9e81923c750f6b439302ac03552c37dbDouglas Gregor return Captures[CXXThisCaptureIndex - 1]; 487a1f2114d9e81923c750f6b439302ac03552c37dbDouglas Gregor } 488a1f2114d9e81923c750f6b439302ac03552c37dbDouglas Gregor 489a1f2114d9e81923c750f6b439302ac03552c37dbDouglas Gregor /// \brief Determine whether the given variable has been captured. 490a1f2114d9e81923c750f6b439302ac03552c37dbDouglas Gregor bool isCaptured(VarDecl *Var) const { 491b11a7fd2f2204c7aadd74f870c98667d461997f5Aaron Ballman return CaptureMap.count(Var); 492a1f2114d9e81923c750f6b439302ac03552c37dbDouglas Gregor } 493a1f2114d9e81923c750f6b439302ac03552c37dbDouglas Gregor 494a1f2114d9e81923c750f6b439302ac03552c37dbDouglas Gregor /// \brief Retrieve the capture of the given variable, if it has been 495a1f2114d9e81923c750f6b439302ac03552c37dbDouglas Gregor /// captured already. 496a1f2114d9e81923c750f6b439302ac03552c37dbDouglas Gregor Capture &getCapture(VarDecl *Var) { 497a1f2114d9e81923c750f6b439302ac03552c37dbDouglas Gregor assert(isCaptured(Var) && "Variable has not been captured"); 498a1f2114d9e81923c750f6b439302ac03552c37dbDouglas Gregor return Captures[CaptureMap[Var] - 1]; 499a1f2114d9e81923c750f6b439302ac03552c37dbDouglas Gregor } 500a1f2114d9e81923c750f6b439302ac03552c37dbDouglas Gregor 501a1f2114d9e81923c750f6b439302ac03552c37dbDouglas Gregor const Capture &getCapture(VarDecl *Var) const { 502a1f2114d9e81923c750f6b439302ac03552c37dbDouglas Gregor llvm::DenseMap<VarDecl*, unsigned>::const_iterator Known 503a1f2114d9e81923c750f6b439302ac03552c37dbDouglas Gregor = CaptureMap.find(Var); 504a1f2114d9e81923c750f6b439302ac03552c37dbDouglas Gregor assert(Known != CaptureMap.end() && "Variable has not been captured"); 505a1f2114d9e81923c750f6b439302ac03552c37dbDouglas Gregor return Captures[Known->second - 1]; 506a1f2114d9e81923c750f6b439302ac03552c37dbDouglas Gregor } 507a1f2114d9e81923c750f6b439302ac03552c37dbDouglas Gregor 508b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman static bool classof(const FunctionScopeInfo *FSI) { 5096afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj return FSI->Kind == SK_Block || FSI->Kind == SK_Lambda 5106afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj || FSI->Kind == SK_CapturedRegion; 511b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman } 512b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman}; 513b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman 514781472fe99a120098c631b0cbe33c89f8cef5e70John McCall/// \brief Retains information about a block that is currently being parsed. 515b69b42c55d56815bab62991bf839cdb41634d3afEli Friedmanclass BlockScopeInfo : public CapturingScopeInfo { 516781472fe99a120098c631b0cbe33c89f8cef5e70John McCallpublic: 517781472fe99a120098c631b0cbe33c89f8cef5e70John McCall BlockDecl *TheDecl; 518781472fe99a120098c631b0cbe33c89f8cef5e70John McCall 519781472fe99a120098c631b0cbe33c89f8cef5e70John McCall /// TheScope - This is the scope for the block itself, which contains 520781472fe99a120098c631b0cbe33c89f8cef5e70John McCall /// arguments etc. 521781472fe99a120098c631b0cbe33c89f8cef5e70John McCall Scope *TheScope; 522781472fe99a120098c631b0cbe33c89f8cef5e70John McCall 523781472fe99a120098c631b0cbe33c89f8cef5e70John McCall /// BlockType - The function type of the block, if one was given. 524781472fe99a120098c631b0cbe33c89f8cef5e70John McCall /// Its return type may be BuiltinType::Dependent. 525781472fe99a120098c631b0cbe33c89f8cef5e70John McCall QualType FunctionType; 526781472fe99a120098c631b0cbe33c89f8cef5e70John McCall 527d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie BlockScopeInfo(DiagnosticsEngine &Diag, Scope *BlockScope, BlockDecl *Block) 528b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman : CapturingScopeInfo(Diag, ImpCap_Block), TheDecl(Block), 529b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman TheScope(BlockScope) 530781472fe99a120098c631b0cbe33c89f8cef5e70John McCall { 531ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman Kind = SK_Block; 532781472fe99a120098c631b0cbe33c89f8cef5e70John McCall } 533781472fe99a120098c631b0cbe33c89f8cef5e70John McCall 534781472fe99a120098c631b0cbe33c89f8cef5e70John McCall virtual ~BlockScopeInfo(); 535781472fe99a120098c631b0cbe33c89f8cef5e70John McCall 536ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman static bool classof(const FunctionScopeInfo *FSI) { 537ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman return FSI->Kind == SK_Block; 538ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman } 539781472fe99a120098c631b0cbe33c89f8cef5e70John McCall}; 540781472fe99a120098c631b0cbe33c89f8cef5e70John McCall 5416afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj/// \brief Retains information about a captured region. 5426afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Sirajclass CapturedRegionScopeInfo: public CapturingScopeInfo { 5436afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Sirajpublic: 5446afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj /// \brief The CapturedDecl for this statement. 5456afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj CapturedDecl *TheCapturedDecl; 5466afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj /// \brief The captured record type. 5476afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj RecordDecl *TheRecordDecl; 5486afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj /// \brief This is the enclosing scope of the captured region. 5496afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj Scope *TheScope; 5508c045ace381972f41d385b0a661ccf172834f459Ben Langmuir /// \brief The implicit parameter for the captured variables. 5518c045ace381972f41d385b0a661ccf172834f459Ben Langmuir ImplicitParamDecl *ContextParam; 5526afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj /// \brief The kind of captured region. 5536afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj CapturedRegionKind CapRegionKind; 5546afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj 5556afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj CapturedRegionScopeInfo(DiagnosticsEngine &Diag, Scope *S, CapturedDecl *CD, 5568c045ace381972f41d385b0a661ccf172834f459Ben Langmuir RecordDecl *RD, ImplicitParamDecl *Context, 5578c045ace381972f41d385b0a661ccf172834f459Ben Langmuir CapturedRegionKind K) 5586afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj : CapturingScopeInfo(Diag, ImpCap_CapturedRegion), 5598c045ace381972f41d385b0a661ccf172834f459Ben Langmuir TheCapturedDecl(CD), TheRecordDecl(RD), TheScope(S), 5608c045ace381972f41d385b0a661ccf172834f459Ben Langmuir ContextParam(Context), CapRegionKind(K) 5616afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj { 5626afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj Kind = SK_CapturedRegion; 5636afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj } 5646afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj 5656afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj virtual ~CapturedRegionScopeInfo(); 5666afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj 5676afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj /// \brief A descriptive name for the kind of captured region this is. 5686afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj StringRef getRegionName() const { 5696afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj switch (CapRegionKind) { 5706afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj case CR_Default: 5716afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj return "default captured statement"; 5720c018357b8bbb1f96bbf622a5807421e626b4228Alexey Bataev case CR_OpenMP: 5730c018357b8bbb1f96bbf622a5807421e626b4228Alexey Bataev return "OpenMP region"; 5746afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj } 5750579c165aa54840898956703ebd63bdd1f4dd907Benjamin Kramer llvm_unreachable("Invalid captured region kind!"); 5766afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj } 5776afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj 5786afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj static bool classof(const FunctionScopeInfo *FSI) { 5796afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj return FSI->Kind == SK_CapturedRegion; 5806afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj } 5816afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj}; 5826afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj 583b69b42c55d56815bab62991bf839cdb41634d3afEli Friedmanclass LambdaScopeInfo : public CapturingScopeInfo { 584ec9ea7200718478e8a976529defbe21942a11c9cEli Friedmanpublic: 585ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman /// \brief The class that describes the lambda. 586ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman CXXRecordDecl *Lambda; 58701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 588f68af647dda5cca00b49be27d24f62b0a7fff986James Dennett /// \brief The lambda's compiler-generated \c operator(). 58976e3da57b0e8cf72d221f44d54566ef206341668Douglas Gregor CXXMethodDecl *CallOperator; 59076e3da57b0e8cf72d221f44d54566ef206341668Douglas Gregor 59101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Source range covering the lambda introducer [...]. 59201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor SourceRange IntroducerRange; 59301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 594f68af647dda5cca00b49be27d24f62b0a7fff986James Dennett /// \brief Source location of the '&' or '=' specifying the default capture 595f68af647dda5cca00b49be27d24f62b0a7fff986James Dennett /// type, if any. 596f68af647dda5cca00b49be27d24f62b0a7fff986James Dennett SourceLocation CaptureDefaultLoc; 597f68af647dda5cca00b49be27d24f62b0a7fff986James Dennett 598f68af647dda5cca00b49be27d24f62b0a7fff986James Dennett /// \brief The number of captures in the \c Captures list that are 599ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman /// explicit captures. 600ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman unsigned NumExplicitCaptures; 60172899c34e3d1abfffa241ad0ce5c4bf175e5ea51Eli Friedman 602503384f731b5abcbf870b0a5224eb920e631db0aDouglas Gregor /// \brief Whether this is a mutable lambda. 603d67d0cc40f31956b40b44b6ee3619d17a0f73294Eli Friedman bool Mutable; 604f68af647dda5cca00b49be27d24f62b0a7fff986James Dennett 60501d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor /// \brief Whether the (empty) parameter list is explicit. 60601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor bool ExplicitParams; 607d67d0cc40f31956b40b44b6ee3619d17a0f73294Eli Friedman 608503384f731b5abcbf870b0a5224eb920e631db0aDouglas Gregor /// \brief Whether any of the capture expressions requires cleanups. 609503384f731b5abcbf870b0a5224eb920e631db0aDouglas Gregor bool ExprNeedsCleanups; 610503384f731b5abcbf870b0a5224eb920e631db0aDouglas Gregor 611612409ece080e814f79e06772c690d603f45fbd6Richard Smith /// \brief Whether the lambda contains an unexpanded parameter pack. 612612409ece080e814f79e06772c690d603f45fbd6Richard Smith bool ContainsUnexpandedParameterPack; 613612409ece080e814f79e06772c690d603f45fbd6Richard Smith 6149daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor /// \brief Variables used to index into by-copy array captures. 615cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko SmallVector<VarDecl *, 4> ArrayIndexVars; 6169daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor 6179daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor /// \brief Offsets into the ArrayIndexVars array at which each capture starts 6189daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor /// its list of array index variables. 619cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko SmallVector<unsigned, 4> ArrayIndexStarts; 620fad9e13f3cb85198f0ee5af620ba81cd78574faaFaisal Vali 621fad9e13f3cb85198f0ee5af620ba81cd78574faaFaisal Vali /// \brief If this is a generic lambda, use this as the depth of 622fad9e13f3cb85198f0ee5af620ba81cd78574faaFaisal Vali /// each 'auto' parameter, during initial AST construction. 623fad9e13f3cb85198f0ee5af620ba81cd78574faaFaisal Vali unsigned AutoTemplateParameterDepth; 624fad9e13f3cb85198f0ee5af620ba81cd78574faaFaisal Vali 625fad9e13f3cb85198f0ee5af620ba81cd78574faaFaisal Vali /// \brief Store the list of the auto parameters for a generic lambda. 626fad9e13f3cb85198f0ee5af620ba81cd78574faaFaisal Vali /// If this is a generic lambda, store the list of the auto 627fad9e13f3cb85198f0ee5af620ba81cd78574faaFaisal Vali /// parameters converted into TemplateTypeParmDecls into a vector 628fad9e13f3cb85198f0ee5af620ba81cd78574faaFaisal Vali /// that can be used to construct the generic lambda's template 629fad9e13f3cb85198f0ee5af620ba81cd78574faaFaisal Vali /// parameter list, during initial AST construction. 630fad9e13f3cb85198f0ee5af620ba81cd78574faaFaisal Vali SmallVector<TemplateTypeParmDecl*, 4> AutoTemplateParams; 631fad9e13f3cb85198f0ee5af620ba81cd78574faaFaisal Vali 632fad9e13f3cb85198f0ee5af620ba81cd78574faaFaisal Vali /// If this is a generic lambda, and the template parameter 633fad9e13f3cb85198f0ee5af620ba81cd78574faaFaisal Vali /// list has been created (from the AutoTemplateParams) then 634fad9e13f3cb85198f0ee5af620ba81cd78574faaFaisal Vali /// store a reference to it (cache it to avoid reconstructing it). 635fad9e13f3cb85198f0ee5af620ba81cd78574faaFaisal Vali TemplateParameterList *GLTemplateParameterList; 636fad9e13f3cb85198f0ee5af620ba81cd78574faaFaisal Vali 637fad9e13f3cb85198f0ee5af620ba81cd78574faaFaisal Vali LambdaScopeInfo(DiagnosticsEngine &Diag) 638fad9e13f3cb85198f0ee5af620ba81cd78574faaFaisal Vali : CapturingScopeInfo(Diag, ImpCap_None), Lambda(0), 639fad9e13f3cb85198f0ee5af620ba81cd78574faaFaisal Vali CallOperator(0), NumExplicitCaptures(0), Mutable(false), 640fad9e13f3cb85198f0ee5af620ba81cd78574faaFaisal Vali ExprNeedsCleanups(false), ContainsUnexpandedParameterPack(false), 641fad9e13f3cb85198f0ee5af620ba81cd78574faaFaisal Vali AutoTemplateParameterDepth(0), 642fad9e13f3cb85198f0ee5af620ba81cd78574faaFaisal Vali GLTemplateParameterList(0) 643ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman { 644ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman Kind = SK_Lambda; 645ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman } 646b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman 647ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman virtual ~LambdaScopeInfo(); 648b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman 649f68af647dda5cca00b49be27d24f62b0a7fff986James Dennett /// \brief Note when all explicit captures have been added. 650a1f2114d9e81923c750f6b439302ac03552c37dbDouglas Gregor void finishedExplicitCaptures() { 651a1f2114d9e81923c750f6b439302ac03552c37dbDouglas Gregor NumExplicitCaptures = Captures.size(); 652a1f2114d9e81923c750f6b439302ac03552c37dbDouglas Gregor } 653c3f1742bdd1ae0091d51168e111cd63861587b13Douglas Gregor 654c3f1742bdd1ae0091d51168e111cd63861587b13Douglas Gregor static bool classof(const FunctionScopeInfo *FSI) { 655152b4e4652baedfceba1cd8115515629225e713fManuel Klimek return FSI->Kind == SK_Lambda; 656ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman } 657ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman}; 658ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman 659c3f1742bdd1ae0091d51168e111cd63861587b13Douglas Gregor 66058b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan RoseFunctionScopeInfo::WeakObjectProfileTy::WeakObjectProfileTy() 66158b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose : Base(0, false), Property(0) {} 66258b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose 66358b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan RoseFunctionScopeInfo::WeakObjectProfileTy 66458b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan RoseFunctionScopeInfo::WeakObjectProfileTy::getSentinel() { 66558b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose FunctionScopeInfo::WeakObjectProfileTy Result; 66658b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose Result.Base.setInt(true); 66758b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose return Result; 66858b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose} 66958b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose 6707a2704800943fbb69207e125d28186278712af36Jordan Rosetemplate <typename ExprT> 6717a2704800943fbb69207e125d28186278712af36Jordan Rosevoid FunctionScopeInfo::recordUseOfWeak(const ExprT *E, bool IsRead) { 6727a2704800943fbb69207e125d28186278712af36Jordan Rose assert(E); 6737a2704800943fbb69207e125d28186278712af36Jordan Rose WeakUseVector &Uses = WeakObjectUses[WeakObjectProfileTy(E)]; 6747a2704800943fbb69207e125d28186278712af36Jordan Rose Uses.push_back(WeakUseTy(E, IsRead)); 675781472fe99a120098c631b0cbe33c89f8cef5e70John McCall} 6767a2704800943fbb69207e125d28186278712af36Jordan Rose 677c3f1742bdd1ae0091d51168e111cd63861587b13Douglas Gregorinline void 678c3f1742bdd1ae0091d51168e111cd63861587b13Douglas GregorCapturingScopeInfo::addThisCapture(bool isNested, SourceLocation Loc, 679c3f1742bdd1ae0091d51168e111cd63861587b13Douglas Gregor QualType CaptureType, Expr *Cpy) { 680c3f1742bdd1ae0091d51168e111cd63861587b13Douglas Gregor Captures.push_back(Capture(Capture::ThisCapture, isNested, Loc, CaptureType, 681c3f1742bdd1ae0091d51168e111cd63861587b13Douglas Gregor Cpy)); 682c3f1742bdd1ae0091d51168e111cd63861587b13Douglas Gregor CXXThisCaptureIndex = Captures.size(); 683c3f1742bdd1ae0091d51168e111cd63861587b13Douglas Gregor 684c3f1742bdd1ae0091d51168e111cd63861587b13Douglas Gregor if (LambdaScopeInfo *LSI = dyn_cast<LambdaScopeInfo>(this)) 685c3f1742bdd1ae0091d51168e111cd63861587b13Douglas Gregor LSI->ArrayIndexStarts.push_back(LSI->ArrayIndexVars.size()); 686c3f1742bdd1ae0091d51168e111cd63861587b13Douglas Gregor} 687c3f1742bdd1ae0091d51168e111cd63861587b13Douglas Gregor 6887a2704800943fbb69207e125d28186278712af36Jordan Rose} // end namespace sema 6897a2704800943fbb69207e125d28186278712af36Jordan Rose} // end namespace clang 690781472fe99a120098c631b0cbe33c89f8cef5e70John McCall 691781472fe99a120098c631b0cbe33c89f8cef5e70John McCall#endif 692