ScopeInfo.h revision ecb5819a9e64fb654d46a3b270a286cc570c58ff
1//===--- ScopeInfo.h - Information about a semantic context -----*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file defines FunctionScopeInfo and its subclasses, which contain
11// information about a single function, block, lambda, or method body.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_CLANG_SEMA_SCOPE_INFO_H
16#define LLVM_CLANG_SEMA_SCOPE_INFO_H
17
18#include "clang/AST/Type.h"
19#include "clang/Basic/CapturedStmt.h"
20#include "clang/Basic/PartialDiagnostic.h"
21#include "llvm/ADT/DenseMap.h"
22#include "llvm/ADT/SmallVector.h"
23
24namespace clang {
25
26class Decl;
27class BlockDecl;
28class CapturedDecl;
29class CXXMethodDecl;
30class FieldDecl;
31class ObjCPropertyDecl;
32class IdentifierInfo;
33class ImplicitParamDecl;
34class LabelDecl;
35class ReturnStmt;
36class Scope;
37class SwitchStmt;
38class TemplateTypeParmDecl;
39class TemplateParameterList;
40class VarDecl;
41class DeclRefExpr;
42class ObjCIvarRefExpr;
43class ObjCPropertyRefExpr;
44class ObjCMessageExpr;
45
46namespace sema {
47
48/// \brief Contains information about the compound statement currently being
49/// parsed.
50class CompoundScopeInfo {
51public:
52  CompoundScopeInfo()
53    : HasEmptyLoopBodies(false) { }
54
55  /// \brief Whether this compound stamement contains `for' or `while' loops
56  /// with empty bodies.
57  bool HasEmptyLoopBodies;
58
59  void setHasEmptyLoopBodies() {
60    HasEmptyLoopBodies = true;
61  }
62};
63
64class PossiblyUnreachableDiag {
65public:
66  PartialDiagnostic PD;
67  SourceLocation Loc;
68  const Stmt *stmt;
69
70  PossiblyUnreachableDiag(const PartialDiagnostic &PD, SourceLocation Loc,
71                          const Stmt *stmt)
72    : PD(PD), Loc(Loc), stmt(stmt) {}
73};
74
75/// \brief Retains information about a function, method, or block that is
76/// currently being parsed.
77class FunctionScopeInfo {
78protected:
79  enum ScopeKind {
80    SK_Function,
81    SK_Block,
82    SK_Lambda,
83    SK_CapturedRegion
84  };
85
86public:
87  /// \brief What kind of scope we are describing.
88  ///
89  ScopeKind Kind;
90
91  /// \brief Whether this function contains a VLA, \@try, try, C++
92  /// initializer, or anything else that can't be jumped past.
93  bool HasBranchProtectedScope;
94
95  /// \brief Whether this function contains any switches or direct gotos.
96  bool HasBranchIntoScope;
97
98  /// \brief Whether this function contains any indirect gotos.
99  bool HasIndirectGoto;
100
101  /// \brief Whether a statement was dropped because it was invalid.
102  bool HasDroppedStmt;
103
104  /// A flag that is set when parsing a method that must call super's
105  /// implementation, such as \c -dealloc, \c -finalize, or any method marked
106  /// with \c __attribute__((objc_requires_super)).
107  bool ObjCShouldCallSuper;
108
109  /// \brief Used to determine if errors occurred in this function or block.
110  DiagnosticErrorTrap ErrorTrap;
111
112  /// SwitchStack - This is the current set of active switch statements in the
113  /// block.
114  SmallVector<SwitchStmt*, 8> SwitchStack;
115
116  /// \brief The list of return statements that occur within the function or
117  /// block, if there is any chance of applying the named return value
118  /// optimization, or if we need to infer a return type.
119  SmallVector<ReturnStmt*, 4> Returns;
120
121  /// \brief The stack of currently active compound stamement scopes in the
122  /// function.
123  SmallVector<CompoundScopeInfo, 4> CompoundScopes;
124
125  /// \brief A list of PartialDiagnostics created but delayed within the
126  /// current function scope.  These diagnostics are vetted for reachability
127  /// prior to being emitted.
128  SmallVector<PossiblyUnreachableDiag, 4> PossiblyUnreachableDiags;
129
130public:
131  /// Represents a simple identification of a weak object.
132  ///
133  /// Part of the implementation of -Wrepeated-use-of-weak.
134  ///
135  /// This is used to determine if two weak accesses refer to the same object.
136  /// Here are some examples of how various accesses are "profiled":
137  ///
138  /// Access Expression |     "Base" Decl     |          "Property" Decl
139  /// :---------------: | :-----------------: | :------------------------------:
140  /// self.property     | self (VarDecl)      | property (ObjCPropertyDecl)
141  /// self.implicitProp | self (VarDecl)      | -implicitProp (ObjCMethodDecl)
142  /// self->ivar.prop   | ivar (ObjCIvarDecl) | prop (ObjCPropertyDecl)
143  /// cxxObj.obj.prop   | obj (FieldDecl)     | prop (ObjCPropertyDecl)
144  /// [self foo].prop   | 0 (unknown)         | prop (ObjCPropertyDecl)
145  /// self.prop1.prop2  | prop1 (ObjCPropertyDecl)    | prop2 (ObjCPropertyDecl)
146  /// MyClass.prop      | MyClass (ObjCInterfaceDecl) | -prop (ObjCMethodDecl)
147  /// weakVar           | 0 (known)           | weakVar (VarDecl)
148  /// self->weakIvar    | self (VarDecl)      | weakIvar (ObjCIvarDecl)
149  ///
150  /// Objects are identified with only two Decls to make it reasonably fast to
151  /// compare them.
152  class WeakObjectProfileTy {
153    /// The base object decl, as described in the class documentation.
154    ///
155    /// The extra flag is "true" if the Base and Property are enough to uniquely
156    /// identify the object in memory.
157    ///
158    /// \sa isExactProfile()
159    typedef llvm::PointerIntPair<const NamedDecl *, 1, bool> BaseInfoTy;
160    BaseInfoTy Base;
161
162    /// The "property" decl, as described in the class documentation.
163    ///
164    /// Note that this may not actually be an ObjCPropertyDecl, e.g. in the
165    /// case of "implicit" properties (regular methods accessed via dot syntax).
166    const NamedDecl *Property;
167
168    /// Used to find the proper base profile for a given base expression.
169    static BaseInfoTy getBaseInfo(const Expr *BaseE);
170
171    // For use in DenseMap.
172    friend class DenseMapInfo;
173    inline WeakObjectProfileTy();
174    static inline WeakObjectProfileTy getSentinel();
175
176  public:
177    WeakObjectProfileTy(const ObjCPropertyRefExpr *RE);
178    WeakObjectProfileTy(const Expr *Base, const ObjCPropertyDecl *Property);
179    WeakObjectProfileTy(const DeclRefExpr *RE);
180    WeakObjectProfileTy(const ObjCIvarRefExpr *RE);
181
182    const NamedDecl *getBase() const { return Base.getPointer(); }
183    const NamedDecl *getProperty() const { return Property; }
184
185    /// Returns true if the object base specifies a known object in memory,
186    /// rather than, say, an instance variable or property of another object.
187    ///
188    /// Note that this ignores the effects of aliasing; that is, \c foo.bar is
189    /// considered an exact profile if \c foo is a local variable, even if
190    /// another variable \c foo2 refers to the same object as \c foo.
191    ///
192    /// For increased precision, accesses with base variables that are
193    /// properties or ivars of 'self' (e.g. self.prop1.prop2) are considered to
194    /// be exact, though this is not true for arbitrary variables
195    /// (foo.prop1.prop2).
196    bool isExactProfile() const {
197      return Base.getInt();
198    }
199
200    bool operator==(const WeakObjectProfileTy &Other) const {
201      return Base == Other.Base && Property == Other.Property;
202    }
203
204    // For use in DenseMap.
205    // We can't specialize the usual llvm::DenseMapInfo at the end of the file
206    // because by that point the DenseMap in FunctionScopeInfo has already been
207    // instantiated.
208    class DenseMapInfo {
209    public:
210      static inline WeakObjectProfileTy getEmptyKey() {
211        return WeakObjectProfileTy();
212      }
213      static inline WeakObjectProfileTy getTombstoneKey() {
214        return WeakObjectProfileTy::getSentinel();
215      }
216
217      static unsigned getHashValue(const WeakObjectProfileTy &Val) {
218        typedef std::pair<BaseInfoTy, const NamedDecl *> Pair;
219        return llvm::DenseMapInfo<Pair>::getHashValue(Pair(Val.Base,
220                                                           Val.Property));
221      }
222
223      static bool isEqual(const WeakObjectProfileTy &LHS,
224                          const WeakObjectProfileTy &RHS) {
225        return LHS == RHS;
226      }
227    };
228  };
229
230  /// Represents a single use of a weak object.
231  ///
232  /// Stores both the expression and whether the access is potentially unsafe
233  /// (i.e. it could potentially be warned about).
234  ///
235  /// Part of the implementation of -Wrepeated-use-of-weak.
236  class WeakUseTy {
237    llvm::PointerIntPair<const Expr *, 1, bool> Rep;
238  public:
239    WeakUseTy(const Expr *Use, bool IsRead) : Rep(Use, IsRead) {}
240
241    const Expr *getUseExpr() const { return Rep.getPointer(); }
242    bool isUnsafe() const { return Rep.getInt(); }
243    void markSafe() { Rep.setInt(false); }
244
245    bool operator==(const WeakUseTy &Other) const {
246      return Rep == Other.Rep;
247    }
248  };
249
250  /// Used to collect uses of a particular weak object in a function body.
251  ///
252  /// Part of the implementation of -Wrepeated-use-of-weak.
253  typedef SmallVector<WeakUseTy, 4> WeakUseVector;
254
255  /// Used to collect all uses of weak objects in a function body.
256  ///
257  /// Part of the implementation of -Wrepeated-use-of-weak.
258  typedef llvm::SmallDenseMap<WeakObjectProfileTy, WeakUseVector, 8,
259                              WeakObjectProfileTy::DenseMapInfo>
260          WeakObjectUseMap;
261
262private:
263  /// Used to collect all uses of weak objects in this function body.
264  ///
265  /// Part of the implementation of -Wrepeated-use-of-weak.
266  WeakObjectUseMap WeakObjectUses;
267
268public:
269  /// Record that a weak object was accessed.
270  ///
271  /// Part of the implementation of -Wrepeated-use-of-weak.
272  template <typename ExprT>
273  inline void recordUseOfWeak(const ExprT *E, bool IsRead = true);
274
275  void recordUseOfWeak(const ObjCMessageExpr *Msg,
276                       const ObjCPropertyDecl *Prop);
277
278  /// Record that a given expression is a "safe" access of a weak object (e.g.
279  /// assigning it to a strong variable.)
280  ///
281  /// Part of the implementation of -Wrepeated-use-of-weak.
282  void markSafeWeakUse(const Expr *E);
283
284  const WeakObjectUseMap &getWeakObjectUses() const {
285    return WeakObjectUses;
286  }
287
288  void setHasBranchIntoScope() {
289    HasBranchIntoScope = true;
290  }
291
292  void setHasBranchProtectedScope() {
293    HasBranchProtectedScope = true;
294  }
295
296  void setHasIndirectGoto() {
297    HasIndirectGoto = true;
298  }
299
300  void setHasDroppedStmt() {
301    HasDroppedStmt = true;
302  }
303
304  bool NeedsScopeChecking() const {
305    return !HasDroppedStmt &&
306        (HasIndirectGoto ||
307          (HasBranchProtectedScope && HasBranchIntoScope));
308  }
309
310  FunctionScopeInfo(DiagnosticsEngine &Diag)
311    : Kind(SK_Function),
312      HasBranchProtectedScope(false),
313      HasBranchIntoScope(false),
314      HasIndirectGoto(false),
315      HasDroppedStmt(false),
316      ObjCShouldCallSuper(false),
317      ErrorTrap(Diag) { }
318
319  virtual ~FunctionScopeInfo();
320
321  /// \brief Clear out the information in this function scope, making it
322  /// suitable for reuse.
323  void Clear();
324};
325
326class CapturingScopeInfo : public FunctionScopeInfo {
327public:
328  enum ImplicitCaptureStyle {
329    ImpCap_None, ImpCap_LambdaByval, ImpCap_LambdaByref, ImpCap_Block,
330    ImpCap_CapturedRegion
331  };
332
333  ImplicitCaptureStyle ImpCaptureStyle;
334
335  class Capture {
336    // There are three categories of capture: capturing 'this', capturing
337    // local variables, and C++1y initialized captures (which can have an
338    // arbitrary initializer, and don't really capture in the traditional
339    // sense at all).
340    //
341    // There are three ways to capture a local variable:
342    //  - capture by copy in the C++11 sense,
343    //  - capture by reference in the C++11 sense, and
344    //  - __block capture.
345    // Lambdas explicitly specify capture by copy or capture by reference.
346    // For blocks, __block capture applies to variables with that annotation,
347    // variables of reference type are captured by reference, and other
348    // variables are captured by copy.
349    enum CaptureKind {
350      Cap_ByCopy, Cap_ByRef, Cap_Block, Cap_ThisOrInit
351    };
352
353    // The variable being captured (if we are not capturing 'this', and whether
354    // this is a nested capture; the expression is only required if we are
355    // capturing ByVal and the variable's type has a non-trivial copy
356    // constructor, or for an initialized capture.
357    typedef llvm::PointerIntPair<VarDecl*, 1, bool> VarAndNested;
358
359    // The variable being captured, or the implicitly-generated field for
360    // an init-capture.
361    llvm::PointerUnion<VarAndNested, FieldDecl*> VarOrField;
362
363    // Expression to initialize a field of the given type, and the kind of
364    // capture (if this is a capture and not an init-capture).
365    llvm::PointerIntPair<Expr*, 2, CaptureKind> InitExprAndCaptureKind;
366
367    /// \brief The source location at which the first capture occurred.
368    SourceLocation Loc;
369
370    /// \brief The location of the ellipsis that expands a parameter pack.
371    SourceLocation EllipsisLoc;
372
373    /// \brief The type as it was captured, which is in effect the type of the
374    /// non-static data member that would hold the capture.
375    QualType CaptureType;
376
377  public:
378    Capture(VarDecl *Var, bool Block, bool ByRef, bool IsNested,
379            SourceLocation Loc, SourceLocation EllipsisLoc,
380            QualType CaptureType, Expr *Cpy)
381        : VarOrField(VarAndNested(Var, IsNested)),
382          InitExprAndCaptureKind(Cpy, Block ? Cap_Block :
383                                      ByRef ? Cap_ByRef : Cap_ByCopy),
384          Loc(Loc), EllipsisLoc(EllipsisLoc), CaptureType(CaptureType) {}
385
386    enum IsThisCapture { ThisCapture };
387    Capture(IsThisCapture, bool IsNested, SourceLocation Loc,
388            QualType CaptureType, Expr *Cpy)
389        : VarOrField(VarAndNested(0, IsNested)),
390          InitExprAndCaptureKind(Cpy, Cap_ThisOrInit),
391          Loc(Loc), EllipsisLoc(), CaptureType(CaptureType) {}
392
393    Capture(FieldDecl *Field, Expr *Init)
394        : VarOrField(Field), InitExprAndCaptureKind(Init, Cap_ThisOrInit),
395          Loc(), EllipsisLoc(), CaptureType() {}
396
397    bool isThisCapture() const {
398      return InitExprAndCaptureKind.getInt() == Cap_ThisOrInit &&
399             VarOrField.is<VarAndNested>();
400    }
401    bool isVariableCapture() const {
402      return InitExprAndCaptureKind.getInt() != Cap_ThisOrInit;
403    }
404    bool isInitCapture() const {
405      return VarOrField.is<FieldDecl*>();
406    }
407    bool isCopyCapture() const {
408      return InitExprAndCaptureKind.getInt() == Cap_ByCopy;
409    }
410    bool isReferenceCapture() const {
411      return InitExprAndCaptureKind.getInt() == Cap_ByRef;
412    }
413    bool isBlockCapture() const {
414      return InitExprAndCaptureKind.getInt() == Cap_Block;
415    }
416    bool isNested() { return VarOrField.dyn_cast<VarAndNested>().getInt(); }
417
418    VarDecl *getVariable() const {
419      return VarOrField.dyn_cast<VarAndNested>().getPointer();
420    }
421    FieldDecl *getInitCaptureField() const {
422      return VarOrField.dyn_cast<FieldDecl*>();
423    }
424
425    /// \brief Retrieve the location at which this variable was captured.
426    SourceLocation getLocation() const { return Loc; }
427
428    /// \brief Retrieve the source location of the ellipsis, whose presence
429    /// indicates that the capture is a pack expansion.
430    SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
431
432    /// \brief Retrieve the capture type for this capture, which is effectively
433    /// the type of the non-static data member in the lambda/block structure
434    /// that would store this capture.
435    QualType getCaptureType() const { return CaptureType; }
436
437    Expr *getInitExpr() const {
438      return InitExprAndCaptureKind.getPointer();
439    }
440  };
441
442  CapturingScopeInfo(DiagnosticsEngine &Diag, ImplicitCaptureStyle Style)
443    : FunctionScopeInfo(Diag), ImpCaptureStyle(Style), CXXThisCaptureIndex(0),
444      HasImplicitReturnType(false)
445     {}
446
447  /// CaptureMap - A map of captured variables to (index+1) into Captures.
448  llvm::DenseMap<VarDecl*, unsigned> CaptureMap;
449
450  /// CXXThisCaptureIndex - The (index+1) of the capture of 'this';
451  /// zero if 'this' is not captured.
452  unsigned CXXThisCaptureIndex;
453
454  /// Captures - The captures.
455  SmallVector<Capture, 4> Captures;
456
457  /// \brief - Whether the target type of return statements in this context
458  /// is deduced (e.g. a lambda or block with omitted return type).
459  bool HasImplicitReturnType;
460
461  /// ReturnType - The target type of return statements in this context,
462  /// or null if unknown.
463  QualType ReturnType;
464
465  void addCapture(VarDecl *Var, bool isBlock, bool isByref, bool isNested,
466                  SourceLocation Loc, SourceLocation EllipsisLoc,
467                  QualType CaptureType, Expr *Cpy) {
468    Captures.push_back(Capture(Var, isBlock, isByref, isNested, Loc,
469                               EllipsisLoc, CaptureType, Cpy));
470    CaptureMap[Var] = Captures.size();
471  }
472
473  void addThisCapture(bool isNested, SourceLocation Loc, QualType CaptureType,
474                      Expr *Cpy);
475
476  void addInitCapture(FieldDecl *Field, Expr *Init) {
477    Captures.push_back(Capture(Field, Init));
478  }
479
480  /// \brief Determine whether the C++ 'this' is captured.
481  bool isCXXThisCaptured() const { return CXXThisCaptureIndex != 0; }
482
483  /// \brief Retrieve the capture of C++ 'this', if it has been captured.
484  Capture &getCXXThisCapture() {
485    assert(isCXXThisCaptured() && "this has not been captured");
486    return Captures[CXXThisCaptureIndex - 1];
487  }
488
489  /// \brief Determine whether the given variable has been captured.
490  bool isCaptured(VarDecl *Var) const {
491    return CaptureMap.count(Var);
492  }
493
494  /// \brief Retrieve the capture of the given variable, if it has been
495  /// captured already.
496  Capture &getCapture(VarDecl *Var) {
497    assert(isCaptured(Var) && "Variable has not been captured");
498    return Captures[CaptureMap[Var] - 1];
499  }
500
501  const Capture &getCapture(VarDecl *Var) const {
502    llvm::DenseMap<VarDecl*, unsigned>::const_iterator Known
503      = CaptureMap.find(Var);
504    assert(Known != CaptureMap.end() && "Variable has not been captured");
505    return Captures[Known->second - 1];
506  }
507
508  static bool classof(const FunctionScopeInfo *FSI) {
509    return FSI->Kind == SK_Block || FSI->Kind == SK_Lambda
510                                 || FSI->Kind == SK_CapturedRegion;
511  }
512};
513
514/// \brief Retains information about a block that is currently being parsed.
515class BlockScopeInfo : public CapturingScopeInfo {
516public:
517  BlockDecl *TheDecl;
518
519  /// TheScope - This is the scope for the block itself, which contains
520  /// arguments etc.
521  Scope *TheScope;
522
523  /// BlockType - The function type of the block, if one was given.
524  /// Its return type may be BuiltinType::Dependent.
525  QualType FunctionType;
526
527  BlockScopeInfo(DiagnosticsEngine &Diag, Scope *BlockScope, BlockDecl *Block)
528    : CapturingScopeInfo(Diag, ImpCap_Block), TheDecl(Block),
529      TheScope(BlockScope)
530  {
531    Kind = SK_Block;
532  }
533
534  virtual ~BlockScopeInfo();
535
536  static bool classof(const FunctionScopeInfo *FSI) {
537    return FSI->Kind == SK_Block;
538  }
539};
540
541/// \brief Retains information about a captured region.
542class CapturedRegionScopeInfo: public CapturingScopeInfo {
543public:
544  /// \brief The CapturedDecl for this statement.
545  CapturedDecl *TheCapturedDecl;
546  /// \brief The captured record type.
547  RecordDecl *TheRecordDecl;
548  /// \brief This is the enclosing scope of the captured region.
549  Scope *TheScope;
550  /// \brief The implicit parameter for the captured variables.
551  ImplicitParamDecl *ContextParam;
552  /// \brief The kind of captured region.
553  CapturedRegionKind CapRegionKind;
554
555  CapturedRegionScopeInfo(DiagnosticsEngine &Diag, Scope *S, CapturedDecl *CD,
556                          RecordDecl *RD, ImplicitParamDecl *Context,
557                          CapturedRegionKind K)
558    : CapturingScopeInfo(Diag, ImpCap_CapturedRegion),
559      TheCapturedDecl(CD), TheRecordDecl(RD), TheScope(S),
560      ContextParam(Context), CapRegionKind(K)
561  {
562    Kind = SK_CapturedRegion;
563  }
564
565  virtual ~CapturedRegionScopeInfo();
566
567  /// \brief A descriptive name for the kind of captured region this is.
568  StringRef getRegionName() const {
569    switch (CapRegionKind) {
570    case CR_Default:
571      return "default captured statement";
572    }
573    llvm_unreachable("Invalid captured region kind!");
574  }
575
576  static bool classof(const FunctionScopeInfo *FSI) {
577    return FSI->Kind == SK_CapturedRegion;
578  }
579};
580
581class LambdaScopeInfo : public CapturingScopeInfo {
582public:
583  /// \brief The class that describes the lambda.
584  CXXRecordDecl *Lambda;
585
586  /// \brief The lambda's compiler-generated \c operator().
587  CXXMethodDecl *CallOperator;
588
589  /// \brief Source range covering the lambda introducer [...].
590  SourceRange IntroducerRange;
591
592  /// \brief Source location of the '&' or '=' specifying the default capture
593  /// type, if any.
594  SourceLocation CaptureDefaultLoc;
595
596  /// \brief The number of captures in the \c Captures list that are
597  /// explicit captures.
598  unsigned NumExplicitCaptures;
599
600  /// \brief Whether this is a mutable lambda.
601  bool Mutable;
602
603  /// \brief Whether the (empty) parameter list is explicit.
604  bool ExplicitParams;
605
606  /// \brief Whether any of the capture expressions requires cleanups.
607  bool ExprNeedsCleanups;
608
609  /// \brief Whether the lambda contains an unexpanded parameter pack.
610  bool ContainsUnexpandedParameterPack;
611
612  /// \brief Variables used to index into by-copy array captures.
613  SmallVector<VarDecl *, 4> ArrayIndexVars;
614
615  /// \brief Offsets into the ArrayIndexVars array at which each capture starts
616  /// its list of array index variables.
617  SmallVector<unsigned, 4> ArrayIndexStarts;
618
619  /// \brief If this is a generic lambda, use this as the depth of
620  /// each 'auto' parameter, during initial AST construction.
621  unsigned AutoTemplateParameterDepth;
622
623  // If this is a generic lambda, store the list of the auto
624  // parameters converted into TemplateTypeParmDecls into a vector
625  // that can be used to construct the generic lambda's template
626  // parameter list, during initial AST construction.
627  /// \brief Store the list of the auto parameters for a generic lambda.
628  SmallVector<TemplateTypeParmDecl*, 4> AutoTemplateParams;
629
630  // If this is a generic lambda, store its template parameter list.
631  TemplateParameterList *GLTemplateParameterList;
632
633  LambdaScopeInfo(DiagnosticsEngine &Diag)
634    : CapturingScopeInfo(Diag, ImpCap_None), Lambda(0),
635      CallOperator(0), NumExplicitCaptures(0), Mutable(false),
636      ExprNeedsCleanups(false), ContainsUnexpandedParameterPack(false),
637      AutoTemplateParameterDepth(0),
638      GLTemplateParameterList(0)
639  {
640    Kind = SK_Lambda;
641  }
642
643  virtual ~LambdaScopeInfo();
644
645  /// \brief Note when all explicit captures have been added.
646  void finishedExplicitCaptures() {
647    NumExplicitCaptures = Captures.size();
648  }
649
650  static bool classof(const FunctionScopeInfo *FSI) {
651    return FSI->Kind == SK_Lambda;
652  }
653
654
655};
656
657
658FunctionScopeInfo::WeakObjectProfileTy::WeakObjectProfileTy()
659  : Base(0, false), Property(0) {}
660
661FunctionScopeInfo::WeakObjectProfileTy
662FunctionScopeInfo::WeakObjectProfileTy::getSentinel() {
663  FunctionScopeInfo::WeakObjectProfileTy Result;
664  Result.Base.setInt(true);
665  return Result;
666}
667
668template <typename ExprT>
669void FunctionScopeInfo::recordUseOfWeak(const ExprT *E, bool IsRead) {
670  assert(E);
671  WeakUseVector &Uses = WeakObjectUses[WeakObjectProfileTy(E)];
672  Uses.push_back(WeakUseTy(E, IsRead));
673}
674
675inline void
676CapturingScopeInfo::addThisCapture(bool isNested, SourceLocation Loc,
677                                   QualType CaptureType, Expr *Cpy) {
678  Captures.push_back(Capture(Capture::ThisCapture, isNested, Loc, CaptureType,
679                             Cpy));
680  CXXThisCaptureIndex = Captures.size();
681
682  if (LambdaScopeInfo *LSI = dyn_cast<LambdaScopeInfo>(this))
683    LSI->ArrayIndexStarts.push_back(LSI->ArrayIndexVars.size());
684}
685
686} // end namespace sema
687} // end namespace clang
688
689#endif
690