ScopeInfo.h revision 93962e5360a43200faa70939571afc4fb9326cf7
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//
10781472fe99a120098c631b0cbe33c89f8cef5e70John McCall//  This file defines FunctionScopeInfo and BlockScopeInfo.
11781472fe99a120098c631b0cbe33c89f8cef5e70John McCall//
12781472fe99a120098c631b0cbe33c89f8cef5e70John McCall//===----------------------------------------------------------------------===//
13781472fe99a120098c631b0cbe33c89f8cef5e70John McCall
14781472fe99a120098c631b0cbe33c89f8cef5e70John McCall#ifndef LLVM_CLANG_SEMA_SCOPE_INFO_H
15781472fe99a120098c631b0cbe33c89f8cef5e70John McCall#define LLVM_CLANG_SEMA_SCOPE_INFO_H
16781472fe99a120098c631b0cbe33c89f8cef5e70John McCall
17781472fe99a120098c631b0cbe33c89f8cef5e70John McCall#include "clang/AST/Type.h"
18351ba91eaa6d30e523587b2d7ed676a5172c6e56Ted Kremenek#include "clang/Basic/PartialDiagnostic.h"
19781472fe99a120098c631b0cbe33c89f8cef5e70John McCall#include "llvm/ADT/DenseMap.h"
20781472fe99a120098c631b0cbe33c89f8cef5e70John McCall#include "llvm/ADT/SmallVector.h"
21469a1eb996e1cb0be54f9b210f836afbddcbb2ccJohn McCall#include "llvm/ADT/SetVector.h"
22781472fe99a120098c631b0cbe33c89f8cef5e70John McCall
23781472fe99a120098c631b0cbe33c89f8cef5e70John McCallnamespace clang {
24781472fe99a120098c631b0cbe33c89f8cef5e70John McCall
25781472fe99a120098c631b0cbe33c89f8cef5e70John McCallclass BlockDecl;
26781472fe99a120098c631b0cbe33c89f8cef5e70John McCallclass IdentifierInfo;
27ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattnerclass LabelDecl;
28781472fe99a120098c631b0cbe33c89f8cef5e70John McCallclass ReturnStmt;
29781472fe99a120098c631b0cbe33c89f8cef5e70John McCallclass Scope;
30781472fe99a120098c631b0cbe33c89f8cef5e70John McCallclass SwitchStmt;
31781472fe99a120098c631b0cbe33c89f8cef5e70John McCall
32781472fe99a120098c631b0cbe33c89f8cef5e70John McCallnamespace sema {
33781472fe99a120098c631b0cbe33c89f8cef5e70John McCall
34351ba91eaa6d30e523587b2d7ed676a5172c6e56Ted Kremenekclass PossiblyUnreachableDiag {
35351ba91eaa6d30e523587b2d7ed676a5172c6e56Ted Kremenekpublic:
36351ba91eaa6d30e523587b2d7ed676a5172c6e56Ted Kremenek  PartialDiagnostic PD;
37351ba91eaa6d30e523587b2d7ed676a5172c6e56Ted Kremenek  SourceLocation Loc;
38351ba91eaa6d30e523587b2d7ed676a5172c6e56Ted Kremenek  const Stmt *stmt;
39351ba91eaa6d30e523587b2d7ed676a5172c6e56Ted Kremenek
40351ba91eaa6d30e523587b2d7ed676a5172c6e56Ted Kremenek  PossiblyUnreachableDiag(const PartialDiagnostic &PD, SourceLocation Loc,
41351ba91eaa6d30e523587b2d7ed676a5172c6e56Ted Kremenek                          const Stmt *stmt)
42351ba91eaa6d30e523587b2d7ed676a5172c6e56Ted Kremenek    : PD(PD), Loc(Loc), stmt(stmt) {}
43351ba91eaa6d30e523587b2d7ed676a5172c6e56Ted Kremenek};
44351ba91eaa6d30e523587b2d7ed676a5172c6e56Ted Kremenek
45781472fe99a120098c631b0cbe33c89f8cef5e70John McCall/// \brief Retains information about a function, method, or block that is
46781472fe99a120098c631b0cbe33c89f8cef5e70John McCall/// currently being parsed.
47781472fe99a120098c631b0cbe33c89f8cef5e70John McCallclass FunctionScopeInfo {
48ec9ea7200718478e8a976529defbe21942a11c9cEli Friedmanprotected:
49ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman  enum ScopeKind {
50ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman    SK_Function,
51ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman    SK_Block,
52ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman    SK_Lambda
53ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman  };
54ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman
55781472fe99a120098c631b0cbe33c89f8cef5e70John McCallpublic:
56ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman  /// \brief What kind of scope we are describing.
57ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman  ///
58ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman  ScopeKind Kind;
59781472fe99a120098c631b0cbe33c89f8cef5e70John McCall
60781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  /// \brief Whether this function contains a VLA, @try, try, C++
61781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  /// initializer, or anything else that can't be jumped past.
62781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  bool HasBranchProtectedScope;
63781472fe99a120098c631b0cbe33c89f8cef5e70John McCall
64781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  /// \brief Whether this function contains any switches or direct gotos.
65781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  bool HasBranchIntoScope;
66781472fe99a120098c631b0cbe33c89f8cef5e70John McCall
67781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  /// \brief Whether this function contains any indirect gotos.
68781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  bool HasIndirectGoto;
69781472fe99a120098c631b0cbe33c89f8cef5e70John McCall
708fc32d272bd57b0a59f61c874cb7b56d9005e89eArgyrios Kyrtzidis  /// \brief Used to determine if errors occurred in this function or block.
718fc32d272bd57b0a59f61c874cb7b56d9005e89eArgyrios Kyrtzidis  DiagnosticErrorTrap ErrorTrap;
72781472fe99a120098c631b0cbe33c89f8cef5e70John McCall
73781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  /// SwitchStack - This is the current set of active switch statements in the
74781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  /// block.
75686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<SwitchStmt*, 8> SwitchStack;
76781472fe99a120098c631b0cbe33c89f8cef5e70John McCall
77781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  /// \brief The list of return statements that occur within the function or
78781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  /// block, if there is any chance of applying the named return value
79781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  /// optimization.
80686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<ReturnStmt*, 4> Returns;
81351ba91eaa6d30e523587b2d7ed676a5172c6e56Ted Kremenek
82351ba91eaa6d30e523587b2d7ed676a5172c6e56Ted Kremenek  /// \brief A list of PartialDiagnostics created but delayed within the
83351ba91eaa6d30e523587b2d7ed676a5172c6e56Ted Kremenek  /// current function scope.  These diagnostics are vetted for reachability
84351ba91eaa6d30e523587b2d7ed676a5172c6e56Ted Kremenek  /// prior to being emitted.
85686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<PossiblyUnreachableDiag, 4> PossiblyUnreachableDiags;
86781472fe99a120098c631b0cbe33c89f8cef5e70John McCall
87781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  void setHasBranchIntoScope() {
88781472fe99a120098c631b0cbe33c89f8cef5e70John McCall    HasBranchIntoScope = true;
89781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  }
90781472fe99a120098c631b0cbe33c89f8cef5e70John McCall
91781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  void setHasBranchProtectedScope() {
92781472fe99a120098c631b0cbe33c89f8cef5e70John McCall    HasBranchProtectedScope = true;
93781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  }
94781472fe99a120098c631b0cbe33c89f8cef5e70John McCall
95781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  void setHasIndirectGoto() {
96781472fe99a120098c631b0cbe33c89f8cef5e70John McCall    HasIndirectGoto = true;
97781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  }
98781472fe99a120098c631b0cbe33c89f8cef5e70John McCall
99781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  bool NeedsScopeChecking() const {
100781472fe99a120098c631b0cbe33c89f8cef5e70John McCall    return HasIndirectGoto ||
101781472fe99a120098c631b0cbe33c89f8cef5e70John McCall          (HasBranchProtectedScope && HasBranchIntoScope);
102781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  }
103781472fe99a120098c631b0cbe33c89f8cef5e70John McCall
104d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie  FunctionScopeInfo(DiagnosticsEngine &Diag)
105ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman    : Kind(SK_Function),
106781472fe99a120098c631b0cbe33c89f8cef5e70John McCall      HasBranchProtectedScope(false),
107781472fe99a120098c631b0cbe33c89f8cef5e70John McCall      HasBranchIntoScope(false),
108781472fe99a120098c631b0cbe33c89f8cef5e70John McCall      HasIndirectGoto(false),
1098fc32d272bd57b0a59f61c874cb7b56d9005e89eArgyrios Kyrtzidis      ErrorTrap(Diag) { }
110781472fe99a120098c631b0cbe33c89f8cef5e70John McCall
111781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  virtual ~FunctionScopeInfo();
112781472fe99a120098c631b0cbe33c89f8cef5e70John McCall
113781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  /// \brief Clear out the information in this function scope, making it
114781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  /// suitable for reuse.
1158fc32d272bd57b0a59f61c874cb7b56d9005e89eArgyrios Kyrtzidis  void Clear();
116781472fe99a120098c631b0cbe33c89f8cef5e70John McCall
117781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  static bool classof(const FunctionScopeInfo *FSI) { return true; }
118781472fe99a120098c631b0cbe33c89f8cef5e70John McCall};
119781472fe99a120098c631b0cbe33c89f8cef5e70John McCall
120b69b42c55d56815bab62991bf839cdb41634d3afEli Friedmanclass CapturingScopeInfo : public FunctionScopeInfo {
121b69b42c55d56815bab62991bf839cdb41634d3afEli Friedmanpublic:
122b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman  enum ImplicitCaptureStyle {
123b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman    ImpCap_None, ImpCap_LambdaByval, ImpCap_LambdaByref, ImpCap_Block
124b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman  };
125b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman
126b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman  ImplicitCaptureStyle ImpCaptureStyle;
127b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman
128b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman  class Capture {
129b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman    enum CaptureKind {
130b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman      Cap_This, Cap_ByVal, Cap_ByRef
131b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman    };
132b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman
133b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman    // The variable being captured (if we are not capturing 'this'),
134b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman    // and misc bits descibing the capture.
135b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman    llvm::PointerIntPair<VarDecl*, 2, CaptureKind> VarAndKind;
136b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman
137b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman    // Expression to initialize a field of the given type, and whether this
138b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman    // is a nested capture; the expression is only required if we are
139b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman    // capturing ByVal and the variable's type has a non-trivial
140b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman    // copy constructor.
141b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman    llvm::PointerIntPair<Expr*, 1, bool> CopyExprAndNested;
142b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman
14393962e5360a43200faa70939571afc4fb9326cf7Douglas Gregor    /// \brief The source location at which the first capture occurred..
14493962e5360a43200faa70939571afc4fb9326cf7Douglas Gregor    SourceLocation Loc;
14593962e5360a43200faa70939571afc4fb9326cf7Douglas Gregor
146b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman  public:
14793962e5360a43200faa70939571afc4fb9326cf7Douglas Gregor    Capture(VarDecl *Var, bool isByref, bool isNested, SourceLocation Loc,
14893962e5360a43200faa70939571afc4fb9326cf7Douglas Gregor            Expr *Cpy)
149b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman      : VarAndKind(Var, isByref ? Cap_ByRef : Cap_ByVal),
150b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman        CopyExprAndNested(Cpy, isNested) {}
151b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman
152b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman    enum IsThisCapture { ThisCapture };
15393962e5360a43200faa70939571afc4fb9326cf7Douglas Gregor    Capture(IsThisCapture, bool isNested, SourceLocation Loc)
15493962e5360a43200faa70939571afc4fb9326cf7Douglas Gregor      : VarAndKind(0, Cap_This), CopyExprAndNested(0, isNested), Loc(Loc) {
155b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman    }
156b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman
157b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman    bool isThisCapture() const { return VarAndKind.getInt() == Cap_This; }
158b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman    bool isVariableCapture() const { return !isThisCapture(); }
159b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman    bool isCopyCapture() const { return VarAndKind.getInt() == Cap_ByVal; }
160b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman    bool isReferenceCapture() const { return VarAndKind.getInt() == Cap_ByRef; }
161b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman    bool isNested() { return CopyExprAndNested.getInt(); }
162b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman
163b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman    VarDecl *getVariable() const {
164b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman      return VarAndKind.getPointer();
165b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman    }
16693962e5360a43200faa70939571afc4fb9326cf7Douglas Gregor
16793962e5360a43200faa70939571afc4fb9326cf7Douglas Gregor    /// \brief Retrieve the location at which this variable was captured.
16893962e5360a43200faa70939571afc4fb9326cf7Douglas Gregor    SourceLocation getLocation() const { return Loc; }
16993962e5360a43200faa70939571afc4fb9326cf7Douglas Gregor
170b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman    Expr *getCopyExpr() const {
171b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman      return CopyExprAndNested.getPointer();
172b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman    }
173b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman  };
174b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman
175b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman  CapturingScopeInfo(DiagnosticsEngine &Diag, ImplicitCaptureStyle Style)
17684b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman    : FunctionScopeInfo(Diag), ImpCaptureStyle(Style), CXXThisCaptureIndex(0),
17784b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman      HasImplicitReturnType(false)
178b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman     {}
179b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman
180b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman  /// CaptureMap - A map of captured variables to (index+1) into Captures.
181b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman  llvm::DenseMap<VarDecl*, unsigned> CaptureMap;
182b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman
183b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman  /// CXXThisCaptureIndex - The (index+1) of the capture of 'this';
184b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman  /// zero if 'this' is not captured.
185b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman  unsigned CXXThisCaptureIndex;
186b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman
187b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman  /// Captures - The captures.
188b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman  SmallVector<Capture, 4> Captures;
189b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman
19084b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman  /// \brief - Whether the target type of return statements in this context
19184b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman  /// is deduced (e.g. a lambda or block with omitted return type).
19284b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman  bool HasImplicitReturnType;
19384b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman
19484b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman  /// ReturnType - The target type of return statements in this context,
19584b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman  /// or null if unknown.
19684b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman  QualType ReturnType;
19784b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman
19893962e5360a43200faa70939571afc4fb9326cf7Douglas Gregor  void AddCapture(VarDecl *Var, bool isByref, bool isNested, SourceLocation Loc,
19993962e5360a43200faa70939571afc4fb9326cf7Douglas Gregor                  Expr *Cpy) {
20093962e5360a43200faa70939571afc4fb9326cf7Douglas Gregor    Captures.push_back(Capture(Var, isByref, isNested, Loc, Cpy));
201b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman    CaptureMap[Var] = Captures.size();
202b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman  }
203b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman
20493962e5360a43200faa70939571afc4fb9326cf7Douglas Gregor  void AddThisCapture(bool isNested, SourceLocation Loc) {
20593962e5360a43200faa70939571afc4fb9326cf7Douglas Gregor    Captures.push_back(Capture(Capture::ThisCapture, isNested, Loc));
206b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman    CXXThisCaptureIndex = Captures.size();
207b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman  }
208b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman
209b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman  static bool classof(const FunctionScopeInfo *FSI) {
210b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman    return FSI->Kind == SK_Block || FSI->Kind == SK_Lambda;
211b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman  }
212b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman  static bool classof(const CapturingScopeInfo *BSI) { return true; }
213b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman};
214b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman
215781472fe99a120098c631b0cbe33c89f8cef5e70John McCall/// \brief Retains information about a block that is currently being parsed.
216b69b42c55d56815bab62991bf839cdb41634d3afEli Friedmanclass BlockScopeInfo : public CapturingScopeInfo {
217781472fe99a120098c631b0cbe33c89f8cef5e70John McCallpublic:
218781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  BlockDecl *TheDecl;
219781472fe99a120098c631b0cbe33c89f8cef5e70John McCall
220781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  /// TheScope - This is the scope for the block itself, which contains
221781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  /// arguments etc.
222781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  Scope *TheScope;
223781472fe99a120098c631b0cbe33c89f8cef5e70John McCall
224781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  /// BlockType - The function type of the block, if one was given.
225781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  /// Its return type may be BuiltinType::Dependent.
226781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  QualType FunctionType;
227781472fe99a120098c631b0cbe33c89f8cef5e70John McCall
228d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie  BlockScopeInfo(DiagnosticsEngine &Diag, Scope *BlockScope, BlockDecl *Block)
229b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman    : CapturingScopeInfo(Diag, ImpCap_Block), TheDecl(Block),
230b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman      TheScope(BlockScope)
231781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  {
232ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman    Kind = SK_Block;
233781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  }
234781472fe99a120098c631b0cbe33c89f8cef5e70John McCall
235781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  virtual ~BlockScopeInfo();
236781472fe99a120098c631b0cbe33c89f8cef5e70John McCall
237ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman  static bool classof(const FunctionScopeInfo *FSI) {
238ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman    return FSI->Kind == SK_Block;
239ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman  }
240781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  static bool classof(const BlockScopeInfo *BSI) { return true; }
241781472fe99a120098c631b0cbe33c89f8cef5e70John McCall};
242781472fe99a120098c631b0cbe33c89f8cef5e70John McCall
243b69b42c55d56815bab62991bf839cdb41634d3afEli Friedmanclass LambdaScopeInfo : public CapturingScopeInfo {
244ec9ea7200718478e8a976529defbe21942a11c9cEli Friedmanpublic:
245ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman  /// \brief The class that describes the lambda.
246ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman  CXXRecordDecl *Lambda;
247ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman
248ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman  /// \brief The number of captures in the \c Captures list that are
249ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman  /// explicit captures.
250ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman  unsigned NumExplicitCaptures;
25172899c34e3d1abfffa241ad0ce5c4bf175e5ea51Eli Friedman
252b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman  LambdaScopeInfo(DiagnosticsEngine &Diag, CXXRecordDecl *Lambda)
253b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman    : CapturingScopeInfo(Diag, ImpCap_None), Lambda(Lambda),
25484b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman      NumExplicitCaptures(0)
255ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman  {
256ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman    Kind = SK_Lambda;
257ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman  }
258b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman
259ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman  virtual ~LambdaScopeInfo();
260b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman
261ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman  static bool classof(const FunctionScopeInfo *FSI) {
262ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman    return FSI->Kind == SK_Lambda;
263ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman  }
264ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman  static bool classof(const LambdaScopeInfo *BSI) { return true; }
265ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman
266ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman};
267ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman
268781472fe99a120098c631b0cbe33c89f8cef5e70John McCall}
269781472fe99a120098c631b0cbe33c89f8cef5e70John McCall}
270781472fe99a120098c631b0cbe33c89f8cef5e70John McCall
271781472fe99a120098c631b0cbe33c89f8cef5e70John McCall#endif
272