1212795Sdim//===--- Sema.h - Semantic Analysis & AST Building --------------*- C++ -*-===//
2212795Sdim//
3212795Sdim//                     The LLVM Compiler Infrastructure
4212795Sdim//
5212795Sdim// This file is distributed under the University of Illinois Open Source
6212795Sdim// License. See LICENSE.TXT for details.
7212795Sdim//
8212795Sdim//===----------------------------------------------------------------------===//
9212795Sdim//
10212795Sdim// This file defines the Sema class, which performs semantic analysis and
11212795Sdim// builds ASTs.
12212795Sdim//
13212795Sdim//===----------------------------------------------------------------------===//
14212795Sdim
15212795Sdim#ifndef LLVM_CLANG_SEMA_SEMA_H
16212795Sdim#define LLVM_CLANG_SEMA_SEMA_H
17212795Sdim
18249423Sdim#include "clang/AST/Attr.h"
19249423Sdim#include "clang/AST/DeclarationName.h"
20218893Sdim#include "clang/AST/Expr.h"
21234353Sdim#include "clang/AST/ExprObjC.h"
22212795Sdim#include "clang/AST/ExternalASTSource.h"
23239462Sdim#include "clang/AST/LambdaMangleContext.h"
24249423Sdim#include "clang/AST/NSAPI.h"
25249423Sdim#include "clang/AST/PrettyPrinter.h"
26218893Sdim#include "clang/AST/TypeLoc.h"
27249423Sdim#include "clang/Basic/ExpressionTraits.h"
28249423Sdim#include "clang/Basic/LangOptions.h"
29212795Sdim#include "clang/Basic/Specifiers.h"
30212795Sdim#include "clang/Basic/TemplateKinds.h"
31212795Sdim#include "clang/Basic/TypeTraits.h"
32249423Sdim#include "clang/Lex/ModuleLoader.h"
33249423Sdim#include "clang/Sema/AnalysisBasedWarnings.h"
34249423Sdim#include "clang/Sema/DeclSpec.h"
35249423Sdim#include "clang/Sema/ExternalSemaSource.h"
36249423Sdim#include "clang/Sema/IdentifierResolver.h"
37249423Sdim#include "clang/Sema/LocInfoType.h"
38249423Sdim#include "clang/Sema/ObjCMethodList.h"
39249423Sdim#include "clang/Sema/Ownership.h"
40251662Sdim#include "clang/Sema/ScopeInfo.h"
41249423Sdim#include "clang/Sema/TypoCorrection.h"
42249423Sdim#include "clang/Sema/Weak.h"
43226633Sdim#include "llvm/ADT/ArrayRef.h"
44239462Sdim#include "llvm/ADT/Optional.h"
45212795Sdim#include "llvm/ADT/OwningPtr.h"
46239462Sdim#include "llvm/ADT/SetVector.h"
47212795Sdim#include "llvm/ADT/SmallPtrSet.h"
48212795Sdim#include "llvm/ADT/SmallVector.h"
49251662Sdim#include "llvm/MC/MCParser/MCAsmParser.h"
50212795Sdim#include <deque>
51212795Sdim#include <string>
52212795Sdim
53212795Sdimnamespace llvm {
54212795Sdim  class APSInt;
55212795Sdim  template <typename ValueT> struct DenseMapInfo;
56212795Sdim  template <typename ValueT, typename ValueInfoT> class DenseSet;
57234353Sdim  class SmallBitVector;
58212795Sdim}
59212795Sdim
60212795Sdimnamespace clang {
61212795Sdim  class ADLResult;
62212795Sdim  class ASTConsumer;
63212795Sdim  class ASTContext;
64221345Sdim  class ASTMutationListener;
65224145Sdim  class ASTReader;
66224145Sdim  class ASTWriter;
67212795Sdim  class ArrayType;
68212795Sdim  class AttributeList;
69212795Sdim  class BlockDecl;
70251662Sdim  class CapturedDecl;
71212795Sdim  class CXXBasePath;
72212795Sdim  class CXXBasePaths;
73234353Sdim  class CXXBindTemporaryExpr;
74226633Sdim  typedef SmallVector<CXXBaseSpecifier*, 4> CXXCastPath;
75212795Sdim  class CXXConstructorDecl;
76212795Sdim  class CXXConversionDecl;
77212795Sdim  class CXXDestructorDecl;
78212795Sdim  class CXXFieldCollector;
79212795Sdim  class CXXMemberCallExpr;
80212795Sdim  class CXXMethodDecl;
81212795Sdim  class CXXScopeSpec;
82212795Sdim  class CXXTemporary;
83212795Sdim  class CXXTryStmt;
84212795Sdim  class CallExpr;
85212795Sdim  class ClassTemplateDecl;
86212795Sdim  class ClassTemplatePartialSpecializationDecl;
87212795Sdim  class ClassTemplateSpecializationDecl;
88212795Sdim  class CodeCompleteConsumer;
89218893Sdim  class CodeCompletionAllocator;
90234353Sdim  class CodeCompletionTUInfo;
91212795Sdim  class CodeCompletionResult;
92212795Sdim  class Decl;
93212795Sdim  class DeclAccessPair;
94212795Sdim  class DeclContext;
95212795Sdim  class DeclRefExpr;
96212795Sdim  class DeclaratorDecl;
97212795Sdim  class DeducedTemplateArgument;
98212795Sdim  class DependentDiagnostic;
99212795Sdim  class DesignatedInitExpr;
100212795Sdim  class Designation;
101212795Sdim  class EnumConstantDecl;
102212795Sdim  class Expr;
103212795Sdim  class ExtVectorType;
104212795Sdim  class ExternalSemaSource;
105212795Sdim  class FormatAttr;
106212795Sdim  class FriendDecl;
107212795Sdim  class FunctionDecl;
108212795Sdim  class FunctionProtoType;
109212795Sdim  class FunctionTemplateDecl;
110212795Sdim  class ImplicitConversionSequence;
111212795Sdim  class InitListExpr;
112212795Sdim  class InitializationKind;
113212795Sdim  class InitializationSequence;
114212795Sdim  class InitializedEntity;
115212795Sdim  class IntegerLiteral;
116212795Sdim  class LabelStmt;
117234353Sdim  class LambdaExpr;
118212795Sdim  class LangOptions;
119212795Sdim  class LocalInstantiationScope;
120212795Sdim  class LookupResult;
121212795Sdim  class MacroInfo;
122212795Sdim  class MultiLevelTemplateArgumentList;
123212795Sdim  class NamedDecl;
124212795Sdim  class NonNullAttr;
125212795Sdim  class ObjCCategoryDecl;
126212795Sdim  class ObjCCategoryImplDecl;
127212795Sdim  class ObjCCompatibleAliasDecl;
128212795Sdim  class ObjCContainerDecl;
129212795Sdim  class ObjCImplDecl;
130212795Sdim  class ObjCImplementationDecl;
131212795Sdim  class ObjCInterfaceDecl;
132212795Sdim  class ObjCIvarDecl;
133212795Sdim  template <class T> class ObjCList;
134224145Sdim  class ObjCMessageExpr;
135212795Sdim  class ObjCMethodDecl;
136212795Sdim  class ObjCPropertyDecl;
137212795Sdim  class ObjCProtocolDecl;
138249423Sdim  class OMPThreadPrivateDecl;
139212795Sdim  class OverloadCandidateSet;
140221345Sdim  class OverloadExpr;
141212795Sdim  class ParenListExpr;
142212795Sdim  class ParmVarDecl;
143212795Sdim  class Preprocessor;
144212795Sdim  class PseudoDestructorTypeStorage;
145234353Sdim  class PseudoObjectExpr;
146212795Sdim  class QualType;
147212795Sdim  class StandardConversionSequence;
148212795Sdim  class Stmt;
149212795Sdim  class StringLiteral;
150212795Sdim  class SwitchStmt;
151212795Sdim  class TargetAttributesSema;
152212795Sdim  class TemplateArgument;
153212795Sdim  class TemplateArgumentList;
154212795Sdim  class TemplateArgumentLoc;
155212795Sdim  class TemplateDecl;
156212795Sdim  class TemplateParameterList;
157212795Sdim  class TemplatePartialOrderingContext;
158212795Sdim  class TemplateTemplateParmDecl;
159212795Sdim  class Token;
160221345Sdim  class TypeAliasDecl;
161212795Sdim  class TypedefDecl;
162221345Sdim  class TypedefNameDecl;
163218893Sdim  class TypeLoc;
164212795Sdim  class UnqualifiedId;
165212795Sdim  class UnresolvedLookupExpr;
166212795Sdim  class UnresolvedMemberExpr;
167212795Sdim  class UnresolvedSetImpl;
168212795Sdim  class UnresolvedSetIterator;
169212795Sdim  class UsingDecl;
170212795Sdim  class UsingShadowDecl;
171212795Sdim  class ValueDecl;
172212795Sdim  class VarDecl;
173212795Sdim  class VisibilityAttr;
174212795Sdim  class VisibleDeclConsumer;
175218893Sdim  class IndirectFieldDecl;
176234353Sdim
177212795Sdimnamespace sema {
178212795Sdim  class AccessedEntity;
179212795Sdim  class BlockScopeInfo;
180251662Sdim  class CapturedRegionScopeInfo;
181239462Sdim  class CapturingScopeInfo;
182234353Sdim  class CompoundScopeInfo;
183212795Sdim  class DelayedDiagnostic;
184239462Sdim  class DelayedDiagnosticPool;
185212795Sdim  class FunctionScopeInfo;
186234353Sdim  class LambdaScopeInfo;
187234353Sdim  class PossiblyUnreachableDiag;
188212795Sdim  class TemplateDeductionInfo;
189212795Sdim}
190212795Sdim
191218893Sdim// FIXME: No way to easily map from TemplateTypeParmTypes to
192218893Sdim// TemplateTypeParmDecls, so we have this horrible PointerUnion.
193218893Sdimtypedef std::pair<llvm::PointerUnion<const TemplateTypeParmType*, NamedDecl*>,
194218893Sdim                  SourceLocation> UnexpandedParameterPack;
195218893Sdim
196212795Sdim/// Sema - This implements semantic analysis and AST building for C.
197212795Sdimclass Sema {
198243830Sdim  Sema(const Sema &) LLVM_DELETED_FUNCTION;
199243830Sdim  void operator=(const Sema &) LLVM_DELETED_FUNCTION;
200212795Sdim  mutable const TargetAttributesSema* TheTargetAttributesSema;
201243830Sdim
202243830Sdim  ///\brief Source of additional semantic information.
203243830Sdim  ExternalSemaSource *ExternalSource;
204243830Sdim
205243830Sdim  ///\brief Whether Sema has generated a multiplexer and has to delete it.
206243830Sdim  bool isMultiplexExternalSource;
207243830Sdim
208249423Sdim  static bool mightHaveNonExternalLinkage(const DeclaratorDecl *FD);
209249423Sdim
210251662Sdim  static bool
211251662Sdim  shouldLinkPossiblyHiddenDecl(const NamedDecl *Old, const NamedDecl *New) {
212251662Sdim    // We are about to link these. It is now safe to compute the linkage of
213251662Sdim    // the new decl. If the new decl has external linkage, we will
214251662Sdim    // link it with the hidden decl (which also has external linkage) and
215251662Sdim    // it will keep having external linkage. If it has internal linkage, we
216251662Sdim    // will not link it. Since it has no previous decls, it will remain
217251662Sdim    // with internal linkage.
218251662Sdim    return !Old->isHidden() || New->hasExternalLinkage();
219251662Sdim  }
220251662Sdim
221212795Sdimpublic:
222212795Sdim  typedef OpaquePtr<DeclGroupRef> DeclGroupPtrTy;
223212795Sdim  typedef OpaquePtr<TemplateName> TemplateTy;
224212795Sdim  typedef OpaquePtr<QualType> TypeTy;
225212795Sdim
226218893Sdim  OpenCLOptions OpenCLFeatures;
227218893Sdim  FPOptions FPFeatures;
228218893Sdim
229212795Sdim  const LangOptions &LangOpts;
230212795Sdim  Preprocessor &PP;
231212795Sdim  ASTContext &Context;
232212795Sdim  ASTConsumer &Consumer;
233226633Sdim  DiagnosticsEngine &Diags;
234212795Sdim  SourceManager &SourceMgr;
235212795Sdim
236224145Sdim  /// \brief Flag indicating whether or not to collect detailed statistics.
237224145Sdim  bool CollectStats;
238224145Sdim
239212795Sdim  /// \brief Code-completion consumer.
240212795Sdim  CodeCompleteConsumer *CodeCompleter;
241212795Sdim
242212795Sdim  /// CurContext - This is the current declaration context of parsing.
243212795Sdim  DeclContext *CurContext;
244212795Sdim
245226633Sdim  /// \brief Generally null except when we temporarily switch decl contexts,
246226633Sdim  /// like in \see ActOnObjCTemporaryExitContainerContext.
247226633Sdim  DeclContext *OriginalLexicalContext;
248226633Sdim
249212795Sdim  /// VAListTagName - The declaration name corresponding to __va_list_tag.
250212795Sdim  /// This is used as part of a hack to omit that class from ADL results.
251212795Sdim  DeclarationName VAListTagName;
252212795Sdim
253239462Sdim  /// PackContext - Manages the stack for \#pragma pack. An alignment
254212795Sdim  /// of 0 indicates default alignment.
255212795Sdim  void *PackContext; // Really a "PragmaPackStack*"
256234353Sdim
257239462Sdim  bool MSStructPragmaOn; // True when \#pragma ms_struct on
258212795Sdim
259239462Sdim  /// VisContext - Manages the stack for \#pragma GCC visibility.
260212795Sdim  void *VisContext; // Really a "PragmaVisStack*"
261212795Sdim
262243830Sdim  /// \brief Flag indicating if Sema is building a recovery call expression.
263243830Sdim  ///
264243830Sdim  /// This flag is used to avoid building recovery call expressions
265243830Sdim  /// if Sema is already doing so, which would cause infinite recursions.
266243830Sdim  bool IsBuildingRecoveryCallExpr;
267243830Sdim
268224145Sdim  /// ExprNeedsCleanups - True if the current evaluation context
269224145Sdim  /// requires cleanups to be run at its conclusion.
270224145Sdim  bool ExprNeedsCleanups;
271224145Sdim
272234353Sdim  /// ExprCleanupObjects - This is the stack of objects requiring
273234353Sdim  /// cleanup that are created by the current full expression.  The
274234353Sdim  /// element type here is ExprWithCleanups::Object.
275234353Sdim  SmallVector<BlockDecl*, 8> ExprCleanupObjects;
276234353Sdim
277249423Sdim  llvm::SmallPtrSet<Expr*, 2> MaybeODRUseExprs;
278234353Sdim
279212795Sdim  /// \brief Stack containing information about each of the nested
280212795Sdim  /// function, block, and method scopes that are currently active.
281212795Sdim  ///
282212795Sdim  /// This array is never empty.  Clients should ignore the first
283212795Sdim  /// element, which is used to cache a single FunctionScopeInfo
284212795Sdim  /// that's used to parse every top-level function.
285226633Sdim  SmallVector<sema::FunctionScopeInfo *, 4> FunctionScopes;
286212795Sdim
287234353Sdim  typedef LazyVector<TypedefNameDecl *, ExternalSemaSource,
288226633Sdim                     &ExternalSemaSource::ReadExtVectorDecls, 2, 2>
289226633Sdim    ExtVectorDeclsType;
290226633Sdim
291212795Sdim  /// ExtVectorDecls - This is a list all the extended vector types. This allows
292212795Sdim  /// us to associate a raw vector type with one of the ext_vector type names.
293212795Sdim  /// This is only necessary for issuing pretty diagnostics.
294226633Sdim  ExtVectorDeclsType ExtVectorDecls;
295212795Sdim
296212795Sdim  /// FieldCollector - Collects CXXFieldDecls during parsing of C++ classes.
297234353Sdim  OwningPtr<CXXFieldCollector> FieldCollector;
298212795Sdim
299239462Sdim  typedef llvm::SmallSetVector<const NamedDecl*, 16> NamedDeclSetType;
300239462Sdim
301239462Sdim  /// \brief Set containing all declared private fields that are not used.
302239462Sdim  NamedDeclSetType UnusedPrivateFields;
303239462Sdim
304212795Sdim  typedef llvm::SmallPtrSet<const CXXRecordDecl*, 8> RecordDeclSetTy;
305212795Sdim
306212795Sdim  /// PureVirtualClassDiagSet - a set of class declarations which we have
307212795Sdim  /// emitted a list of pure virtual functions. Used to prevent emitting the
308212795Sdim  /// same list more than once.
309234353Sdim  OwningPtr<RecordDeclSetTy> PureVirtualClassDiagSet;
310212795Sdim
311219077Sdim  /// ParsingInitForAutoVars - a set of declarations with auto types for which
312219077Sdim  /// we are currently parsing the initializer.
313219077Sdim  llvm::SmallPtrSet<const Decl*, 4> ParsingInitForAutoVars;
314219077Sdim
315212795Sdim  /// \brief A mapping from external names to the most recent
316249423Sdim  /// locally-scoped extern "C" declaration with that name.
317212795Sdim  ///
318212795Sdim  /// This map contains external declarations introduced in local
319249423Sdim  /// scopes, e.g.,
320212795Sdim  ///
321212795Sdim  /// \code
322249423Sdim  /// extern "C" void f() {
323212795Sdim  ///   void foo(int, int);
324212795Sdim  /// }
325212795Sdim  /// \endcode
326212795Sdim  ///
327249423Sdim  /// Here, the name "foo" will be associated with the declaration of
328212795Sdim  /// "foo" within f. This name is not visible outside of
329212795Sdim  /// "f". However, we still find it in two cases:
330212795Sdim  ///
331249423Sdim  ///   - If we are declaring another global or extern "C" entity with
332249423Sdim  ///     the name "foo", we can find "foo" as a previous declaration,
333249423Sdim  ///     so that the types of this external declaration can be checked
334249423Sdim  ///     for compatibility.
335212795Sdim  ///
336212795Sdim  ///   - If we would implicitly declare "foo" (e.g., due to a call to
337212795Sdim  ///     "foo" in C when no prototype or definition is visible), then
338212795Sdim  ///     we find this declaration of "foo" and complain that it is
339212795Sdim  ///     not visible.
340249423Sdim  llvm::DenseMap<DeclarationName, NamedDecl *> LocallyScopedExternCDecls;
341234353Sdim
342249423Sdim  /// \brief Look for a locally scoped extern "C" declaration by the given name.
343226633Sdim  llvm::DenseMap<DeclarationName, NamedDecl *>::iterator
344249423Sdim  findLocallyScopedExternCDecl(DeclarationName Name);
345234353Sdim
346234353Sdim  typedef LazyVector<VarDecl *, ExternalSemaSource,
347226633Sdim                     &ExternalSemaSource::ReadTentativeDefinitions, 2, 2>
348226633Sdim    TentativeDefinitionsType;
349212795Sdim
350212795Sdim  /// \brief All the tentative definitions encountered in the TU.
351226633Sdim  TentativeDefinitionsType TentativeDefinitions;
352212795Sdim
353234353Sdim  typedef LazyVector<const DeclaratorDecl *, ExternalSemaSource,
354226633Sdim                     &ExternalSemaSource::ReadUnusedFileScopedDecls, 2, 2>
355226633Sdim    UnusedFileScopedDeclsType;
356234353Sdim
357212795Sdim  /// \brief The set of file scoped decls seen so far that have not been used
358212795Sdim  /// and must warn if not used. Only contains the first declaration.
359226633Sdim  UnusedFileScopedDeclsType UnusedFileScopedDecls;
360212795Sdim
361234353Sdim  typedef LazyVector<CXXConstructorDecl *, ExternalSemaSource,
362226633Sdim                     &ExternalSemaSource::ReadDelegatingConstructors, 2, 2>
363226633Sdim    DelegatingCtorDeclsType;
364226633Sdim
365223017Sdim  /// \brief All the delegating constructors seen so far in the file, used for
366223017Sdim  /// cycle detection at the end of the TU.
367226633Sdim  DelegatingCtorDeclsType DelegatingCtorDecls;
368223017Sdim
369235864Sdim  /// \brief All the destructors seen during a class definition that had their
370235864Sdim  /// exception spec computation delayed because it depended on an unparsed
371235864Sdim  /// exception spec.
372235864Sdim  SmallVector<CXXDestructorDecl*, 2> DelayedDestructorExceptionSpecs;
373235864Sdim
374223017Sdim  /// \brief All the overriding destructors seen during a class definition
375223017Sdim  /// (there could be multiple due to nested classes) that had their exception
376223017Sdim  /// spec checks delayed, plus the overridden destructor.
377226633Sdim  SmallVector<std::pair<const CXXDestructorDecl*,
378223017Sdim                              const CXXDestructorDecl*>, 2>
379223017Sdim      DelayedDestructorExceptionSpecChecks;
380223017Sdim
381249423Sdim  /// \brief All the members seen during a class definition which were both
382249423Sdim  /// explicitly defaulted and had explicitly-specified exception
383249423Sdim  /// specifications, along with the function type containing their
384249423Sdim  /// user-specified exception specification. Those exception specifications
385249423Sdim  /// were overridden with the default specifications, but we still need to
386249423Sdim  /// check whether they are compatible with the default specification, and
387249423Sdim  /// we can't do that until the nesting set of class definitions is complete.
388249423Sdim  SmallVector<std::pair<CXXMethodDecl*, const FunctionProtoType*>, 2>
389249423Sdim    DelayedDefaultedMemberExceptionSpecs;
390249423Sdim
391221345Sdim  /// \brief Callback to the parser to parse templated functions when needed.
392221345Sdim  typedef void LateTemplateParserCB(void *P, const FunctionDecl *FD);
393221345Sdim  LateTemplateParserCB *LateTemplateParser;
394234353Sdim  void *OpaqueParser;
395221345Sdim
396221345Sdim  void SetLateTemplateParser(LateTemplateParserCB *LTP, void *P) {
397221345Sdim    LateTemplateParser = LTP;
398234353Sdim    OpaqueParser = P;
399221345Sdim  }
400221345Sdim
401218893Sdim  class DelayedDiagnostics;
402212795Sdim
403239462Sdim  class DelayedDiagnosticsState {
404239462Sdim    sema::DelayedDiagnosticPool *SavedPool;
405218893Sdim    friend class Sema::DelayedDiagnostics;
406218893Sdim  };
407239462Sdim  typedef DelayedDiagnosticsState ParsingDeclState;
408239462Sdim  typedef DelayedDiagnosticsState ProcessingContextState;
409212795Sdim
410218893Sdim  /// A class which encapsulates the logic for delaying diagnostics
411218893Sdim  /// during parsing and other processing.
412218893Sdim  class DelayedDiagnostics {
413239462Sdim    /// \brief The current pool of diagnostics into which delayed
414239462Sdim    /// diagnostics should go.
415239462Sdim    sema::DelayedDiagnosticPool *CurPool;
416218893Sdim
417218893Sdim  public:
418239462Sdim    DelayedDiagnostics() : CurPool(0) {}
419218893Sdim
420218893Sdim    /// Adds a delayed diagnostic.
421239462Sdim    void add(const sema::DelayedDiagnostic &diag); // in DelayedDiagnostic.h
422218893Sdim
423218893Sdim    /// Determines whether diagnostics should be delayed.
424239462Sdim    bool shouldDelayDiagnostics() { return CurPool != 0; }
425218893Sdim
426239462Sdim    /// Returns the current delayed-diagnostics pool.
427239462Sdim    sema::DelayedDiagnosticPool *getCurrentPool() const {
428239462Sdim      return CurPool;
429239462Sdim    }
430218893Sdim
431239462Sdim    /// Enter a new scope.  Access and deprecation diagnostics will be
432239462Sdim    /// collected in this pool.
433239462Sdim    DelayedDiagnosticsState push(sema::DelayedDiagnosticPool &pool) {
434239462Sdim      DelayedDiagnosticsState state;
435239462Sdim      state.SavedPool = CurPool;
436239462Sdim      CurPool = &pool;
437218893Sdim      return state;
438218893Sdim    }
439218893Sdim
440239462Sdim    /// Leave a delayed-diagnostic state that was previously pushed.
441239462Sdim    /// Do not emit any of the diagnostics.  This is performed as part
442239462Sdim    /// of the bookkeeping of popping a pool "properly".
443239462Sdim    void popWithoutEmitting(DelayedDiagnosticsState state) {
444239462Sdim      CurPool = state.SavedPool;
445239462Sdim    }
446218893Sdim
447239462Sdim    /// Enter a new scope where access and deprecation diagnostics are
448239462Sdim    /// not delayed.
449239462Sdim    DelayedDiagnosticsState pushUndelayed() {
450239462Sdim      DelayedDiagnosticsState state;
451239462Sdim      state.SavedPool = CurPool;
452239462Sdim      CurPool = 0;
453218893Sdim      return state;
454218893Sdim    }
455218893Sdim
456239462Sdim    /// Undo a previous pushUndelayed().
457239462Sdim    void popUndelayed(DelayedDiagnosticsState state) {
458239462Sdim      assert(CurPool == NULL);
459239462Sdim      CurPool = state.SavedPool;
460234353Sdim    }
461218893Sdim  } DelayedDiagnostics;
462218893Sdim
463218893Sdim  /// A RAII object to temporarily push a declaration context.
464218893Sdim  class ContextRAII {
465218893Sdim  private:
466218893Sdim    Sema &S;
467218893Sdim    DeclContext *SavedContext;
468218893Sdim    ProcessingContextState SavedContextState;
469234982Sdim    QualType SavedCXXThisTypeOverride;
470239462Sdim
471218893Sdim  public:
472218893Sdim    ContextRAII(Sema &S, DeclContext *ContextToPush)
473234353Sdim      : S(S), SavedContext(S.CurContext),
474239462Sdim        SavedContextState(S.DelayedDiagnostics.pushUndelayed()),
475234982Sdim        SavedCXXThisTypeOverride(S.CXXThisTypeOverride)
476218893Sdim    {
477218893Sdim      assert(ContextToPush && "pushing null context");
478218893Sdim      S.CurContext = ContextToPush;
479218893Sdim    }
480218893Sdim
481218893Sdim    void pop() {
482218893Sdim      if (!SavedContext) return;
483218893Sdim      S.CurContext = SavedContext;
484239462Sdim      S.DelayedDiagnostics.popUndelayed(SavedContextState);
485234982Sdim      S.CXXThisTypeOverride = SavedCXXThisTypeOverride;
486218893Sdim      SavedContext = 0;
487218893Sdim    }
488218893Sdim
489218893Sdim    ~ContextRAII() {
490218893Sdim      pop();
491218893Sdim    }
492218893Sdim  };
493218893Sdim
494243830Sdim  /// \brief RAII object to handle the state changes required to synthesize
495243830Sdim  /// a function body.
496243830Sdim  class SynthesizedFunctionScope {
497243830Sdim    Sema &S;
498243830Sdim    Sema::ContextRAII SavedContext;
499243830Sdim
500243830Sdim  public:
501243830Sdim    SynthesizedFunctionScope(Sema &S, DeclContext *DC)
502243830Sdim      : S(S), SavedContext(S, DC)
503243830Sdim    {
504243830Sdim      S.PushFunctionScope();
505243830Sdim      S.PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
506243830Sdim    }
507243830Sdim
508243830Sdim    ~SynthesizedFunctionScope() {
509243830Sdim      S.PopExpressionEvaluationContext();
510243830Sdim      S.PopFunctionScopeInfo();
511243830Sdim    }
512243830Sdim  };
513243830Sdim
514212795Sdim  /// WeakUndeclaredIdentifiers - Identifiers contained in
515239462Sdim  /// \#pragma weak before declared. rare. may alias another
516212795Sdim  /// identifier, declared or undeclared
517212795Sdim  llvm::DenseMap<IdentifierInfo*,WeakInfo> WeakUndeclaredIdentifiers;
518212795Sdim
519234353Sdim  /// ExtnameUndeclaredIdentifiers - Identifiers contained in
520239462Sdim  /// \#pragma redefine_extname before declared.  Used in Solaris system headers
521234353Sdim  /// to define functions that occur in multiple standards to call the version
522234353Sdim  /// in the currently selected standard.
523234353Sdim  llvm::DenseMap<IdentifierInfo*,AsmLabelAttr*> ExtnameUndeclaredIdentifiers;
524234353Sdim
525234353Sdim
526226633Sdim  /// \brief Load weak undeclared identifiers from the external source.
527226633Sdim  void LoadExternalWeakUndeclaredIdentifiers();
528234353Sdim
529212795Sdim  /// WeakTopLevelDecl - Translation-unit scoped declarations generated by
530239462Sdim  /// \#pragma weak during processing of other Decls.
531212795Sdim  /// I couldn't figure out a clean way to generate these in-line, so
532212795Sdim  /// we store them here and handle separately -- which is a hack.
533212795Sdim  /// It would be best to refactor this.
534226633Sdim  SmallVector<Decl*,2> WeakTopLevelDecl;
535212795Sdim
536212795Sdim  IdentifierResolver IdResolver;
537212795Sdim
538212795Sdim  /// Translation Unit Scope - useful to Objective-C actions that need
539212795Sdim  /// to lookup file scope declarations in the "ordinary" C decl namespace.
540212795Sdim  /// For example, user-defined classes, built-in "id" type, etc.
541212795Sdim  Scope *TUScope;
542212795Sdim
543212795Sdim  /// \brief The C++ "std" namespace, where the standard library resides.
544212795Sdim  LazyDeclPtr StdNamespace;
545212795Sdim
546212795Sdim  /// \brief The C++ "std::bad_alloc" class, which is defined by the C++
547212795Sdim  /// standard library.
548212795Sdim  LazyDeclPtr StdBadAlloc;
549212795Sdim
550234353Sdim  /// \brief The C++ "std::initializer_list" template, which is defined in
551239462Sdim  /// \<initializer_list>.
552234353Sdim  ClassTemplateDecl *StdInitializerList;
553234353Sdim
554239462Sdim  /// \brief The C++ "type_info" declaration, which is defined in \<typeinfo>.
555218893Sdim  RecordDecl *CXXTypeInfoDecl;
556234353Sdim
557218893Sdim  /// \brief The MSVC "_GUID" struct, which is defined in MSVC header files.
558218893Sdim  RecordDecl *MSVCGuidDecl;
559218893Sdim
560234353Sdim  /// \brief Caches identifiers/selectors for NSFoundation APIs.
561249423Sdim  OwningPtr<NSAPI> NSAPIObj;
562234353Sdim
563234353Sdim  /// \brief The declaration of the Objective-C NSNumber class.
564234353Sdim  ObjCInterfaceDecl *NSNumberDecl;
565239462Sdim
566239462Sdim  /// \brief Pointer to NSNumber type (NSNumber *).
567239462Sdim  QualType NSNumberPointer;
568239462Sdim
569234353Sdim  /// \brief The Objective-C NSNumber methods used to create NSNumber literals.
570234353Sdim  ObjCMethodDecl *NSNumberLiteralMethods[NSAPI::NumNSNumberLiteralMethods];
571239462Sdim
572239462Sdim  /// \brief The declaration of the Objective-C NSString class.
573239462Sdim  ObjCInterfaceDecl *NSStringDecl;
574239462Sdim
575239462Sdim  /// \brief Pointer to NSString type (NSString *).
576239462Sdim  QualType NSStringPointer;
577239462Sdim
578239462Sdim  /// \brief The declaration of the stringWithUTF8String: method.
579239462Sdim  ObjCMethodDecl *StringWithUTF8StringMethod;
580239462Sdim
581234353Sdim  /// \brief The declaration of the Objective-C NSArray class.
582234353Sdim  ObjCInterfaceDecl *NSArrayDecl;
583234353Sdim
584234353Sdim  /// \brief The declaration of the arrayWithObjects:count: method.
585234353Sdim  ObjCMethodDecl *ArrayWithObjectsMethod;
586239462Sdim
587234353Sdim  /// \brief The declaration of the Objective-C NSDictionary class.
588234353Sdim  ObjCInterfaceDecl *NSDictionaryDecl;
589234353Sdim
590234353Sdim  /// \brief The declaration of the dictionaryWithObjects:forKeys:count: method.
591234353Sdim  ObjCMethodDecl *DictionaryWithObjectsMethod;
592234353Sdim
593234353Sdim  /// \brief id<NSCopying> type.
594234353Sdim  QualType QIDNSCopying;
595234353Sdim
596249423Sdim  /// \brief will hold 'respondsToSelector:'
597249423Sdim  Selector RespondsToSelectorSel;
598249423Sdim
599212795Sdim  /// A flag to remember whether the implicit forms of operator new and delete
600212795Sdim  /// have been declared.
601212795Sdim  bool GlobalNewDeleteDeclared;
602212795Sdim
603251662Sdim  /// A flag to indicate that we're in a context that permits abstract
604251662Sdim  /// references to fields.  This is really a
605251662Sdim  bool AllowAbstractFieldReference;
606251662Sdim
607212795Sdim  /// \brief Describes how the expressions currently being parsed are
608212795Sdim  /// evaluated at run-time, if at all.
609212795Sdim  enum ExpressionEvaluationContext {
610212795Sdim    /// \brief The current expression and its subexpressions occur within an
611234353Sdim    /// unevaluated operand (C++11 [expr]p7), such as the subexpression of
612234353Sdim    /// \c sizeof, where the type of the expression may be significant but
613234353Sdim    /// no code will be generated to evaluate the value of the expression at
614234353Sdim    /// run time.
615212795Sdim    Unevaluated,
616212795Sdim
617251662Sdim    /// \brief The current expression occurs within an unevaluated
618251662Sdim    /// operand that unconditionally permits abstract references to
619251662Sdim    /// fields, such as a SIZE operator in MS-style inline assembly.
620251662Sdim    UnevaluatedAbstract,
621251662Sdim
622234353Sdim    /// \brief The current context is "potentially evaluated" in C++11 terms,
623234353Sdim    /// but the expression is evaluated at compile-time (like the values of
624234353Sdim    /// cases in a switch statment).
625234353Sdim    ConstantEvaluated,
626234353Sdim
627212795Sdim    /// \brief The current expression is potentially evaluated at run time,
628212795Sdim    /// which means that code may be generated to evaluate the value of the
629212795Sdim    /// expression at run time.
630212795Sdim    PotentiallyEvaluated,
631212795Sdim
632218893Sdim    /// \brief The current expression is potentially evaluated, but any
633218893Sdim    /// declarations referenced inside that expression are only used if
634218893Sdim    /// in fact the current expression is used.
635218893Sdim    ///
636218893Sdim    /// This value is used when parsing default function arguments, for which
637218893Sdim    /// we would like to provide diagnostics (e.g., passing non-POD arguments
638218893Sdim    /// through varargs) but do not want to mark declarations as "referenced"
639218893Sdim    /// until the default argument is used.
640218893Sdim    PotentiallyEvaluatedIfUsed
641212795Sdim  };
642212795Sdim
643212795Sdim  /// \brief Data structure used to record current or nested
644212795Sdim  /// expression evaluation contexts.
645212795Sdim  struct ExpressionEvaluationContextRecord {
646212795Sdim    /// \brief The expression evaluation context.
647212795Sdim    ExpressionEvaluationContext Context;
648212795Sdim
649224145Sdim    /// \brief Whether the enclosing context needed a cleanup.
650224145Sdim    bool ParentNeedsCleanups;
651224145Sdim
652234353Sdim    /// \brief Whether we are in a decltype expression.
653234353Sdim    bool IsDecltype;
654212795Sdim
655234353Sdim    /// \brief The number of active cleanup objects when we entered
656234353Sdim    /// this expression evaluation context.
657234353Sdim    unsigned NumCleanupObjects;
658234353Sdim
659249423Sdim    llvm::SmallPtrSet<Expr*, 2> SavedMaybeODRUseExprs;
660234353Sdim
661234353Sdim    /// \brief The lambdas that are present within this context, if it
662234353Sdim    /// is indeed an unevaluated context.
663249423Sdim    SmallVector<LambdaExpr *, 2> Lambdas;
664234353Sdim
665234353Sdim    /// \brief The declaration that provides context for the lambda expression
666239462Sdim    /// if the normal declaration context does not suffice, e.g., in a
667234353Sdim    /// default function argument.
668234353Sdim    Decl *LambdaContextDecl;
669239462Sdim
670234353Sdim    /// \brief The context information used to mangle lambda expressions
671234353Sdim    /// within this context.
672212795Sdim    ///
673234353Sdim    /// This mangling information is allocated lazily, since most contexts
674234353Sdim    /// do not have lambda expressions.
675249423Sdim    IntrusiveRefCntPtr<LambdaMangleContext> LambdaMangle;
676212795Sdim
677234353Sdim    /// \brief If we are processing a decltype type, a set of call expressions
678234353Sdim    /// for which we have deferred checking the completeness of the return type.
679249423Sdim    SmallVector<CallExpr *, 8> DelayedDecltypeCalls;
680212795Sdim
681234353Sdim    /// \brief If we are processing a decltype type, a set of temporary binding
682234353Sdim    /// expressions for which we have deferred checking the destructor.
683249423Sdim    SmallVector<CXXBindTemporaryExpr *, 8> DelayedDecltypeBinds;
684239462Sdim
685212795Sdim    ExpressionEvaluationContextRecord(ExpressionEvaluationContext Context,
686234353Sdim                                      unsigned NumCleanupObjects,
687234353Sdim                                      bool ParentNeedsCleanups,
688234353Sdim                                      Decl *LambdaContextDecl,
689234353Sdim                                      bool IsDecltype)
690224145Sdim      : Context(Context), ParentNeedsCleanups(ParentNeedsCleanups),
691234353Sdim        IsDecltype(IsDecltype), NumCleanupObjects(NumCleanupObjects),
692234353Sdim        LambdaContextDecl(LambdaContextDecl), LambdaMangle() { }
693239462Sdim
694234353Sdim    /// \brief Retrieve the mangling context for lambdas.
695234353Sdim    LambdaMangleContext &getLambdaMangleContext() {
696234353Sdim      assert(LambdaContextDecl && "Need to have a lambda context declaration");
697234353Sdim      if (!LambdaMangle)
698234353Sdim        LambdaMangle = new LambdaMangleContext;
699234353Sdim      return *LambdaMangle;
700212795Sdim    }
701251662Sdim
702251662Sdim    bool isUnevaluated() const {
703251662Sdim      return Context == Unevaluated || Context == UnevaluatedAbstract;
704251662Sdim    }
705212795Sdim  };
706212795Sdim
707212795Sdim  /// A stack of expression evaluation contexts.
708226633Sdim  SmallVector<ExpressionEvaluationContextRecord, 8> ExprEvalContexts;
709239462Sdim
710223017Sdim  /// SpecialMemberOverloadResult - The overloading result for a special member
711223017Sdim  /// function.
712223017Sdim  ///
713235864Sdim  /// This is basically a wrapper around PointerIntPair. The lowest bits of the
714239462Sdim  /// integer are used to determine whether overload resolution succeeded.
715223017Sdim  class SpecialMemberOverloadResult : public llvm::FastFoldingSetNode {
716234353Sdim  public:
717234353Sdim    enum Kind {
718234353Sdim      NoMemberOrDeleted,
719234353Sdim      Ambiguous,
720235864Sdim      Success
721234353Sdim    };
722234353Sdim
723234353Sdim  private:
724223017Sdim    llvm::PointerIntPair<CXXMethodDecl*, 2> Pair;
725234353Sdim
726223017Sdim  public:
727223017Sdim    SpecialMemberOverloadResult(const llvm::FoldingSetNodeID &ID)
728223017Sdim      : FastFoldingSetNode(ID)
729223017Sdim    {}
730223017Sdim
731223017Sdim    CXXMethodDecl *getMethod() const { return Pair.getPointer(); }
732223017Sdim    void setMethod(CXXMethodDecl *MD) { Pair.setPointer(MD); }
733223017Sdim
734234353Sdim    Kind getKind() const { return static_cast<Kind>(Pair.getInt()); }
735234353Sdim    void setKind(Kind K) { Pair.setInt(K); }
736223017Sdim  };
737223017Sdim
738223017Sdim  /// \brief A cache of special member function overload resolution results
739223017Sdim  /// for C++ records.
740223017Sdim  llvm::FoldingSet<SpecialMemberOverloadResult> SpecialMemberCache;
741223017Sdim
742226633Sdim  /// \brief The kind of translation unit we are processing.
743212795Sdim  ///
744226633Sdim  /// When we're processing a complete translation unit, Sema will perform
745212795Sdim  /// end-of-translation-unit semantic tasks (such as creating
746212795Sdim  /// initializers for tentative definitions in C) once parsing has
747226633Sdim  /// completed. Modules and precompiled headers perform different kinds of
748226633Sdim  /// checks.
749226633Sdim  TranslationUnitKind TUKind;
750212795Sdim
751212795Sdim  llvm::BumpPtrAllocator BumpAlloc;
752212795Sdim
753212795Sdim  /// \brief The number of SFINAE diagnostics that have been trapped.
754212795Sdim  unsigned NumSFINAEErrors;
755212795Sdim
756226633Sdim  typedef llvm::DenseMap<ParmVarDecl *, SmallVector<ParmVarDecl *, 1> >
757218893Sdim    UnparsedDefaultArgInstantiationsMap;
758234353Sdim
759218893Sdim  /// \brief A mapping from parameters with unparsed default arguments to the
760218893Sdim  /// set of instantiations of each parameter.
761218893Sdim  ///
762218893Sdim  /// This mapping is a temporary data structure used when parsing
763218893Sdim  /// nested class templates or nested classes of class templates,
764218893Sdim  /// where we might end up instantiating an inner class before the
765234353Sdim  /// default arguments of its methods have been parsed.
766218893Sdim  UnparsedDefaultArgInstantiationsMap UnparsedDefaultArgInstantiations;
767234353Sdim
768218893Sdim  // Contains the locations of the beginning of unparsed default
769218893Sdim  // argument locations.
770249423Sdim  llvm::DenseMap<ParmVarDecl *, SourceLocation> UnparsedDefaultArgLocs;
771218893Sdim
772249423Sdim  /// UndefinedInternals - all the used, undefined objects which require a
773249423Sdim  /// definition in this translation unit.
774249423Sdim  llvm::DenseMap<NamedDecl *, SourceLocation> UndefinedButUsed;
775218893Sdim
776249423Sdim  /// Obtain a sorted list of functions that are undefined but ODR-used.
777249423Sdim  void getUndefinedButUsed(
778249423Sdim    llvm::SmallVectorImpl<std::pair<NamedDecl *, SourceLocation> > &Undefined);
779249423Sdim
780212795Sdim  typedef std::pair<ObjCMethodList, ObjCMethodList> GlobalMethods;
781212795Sdim  typedef llvm::DenseMap<Selector, GlobalMethods> GlobalMethodPool;
782212795Sdim
783212795Sdim  /// Method Pool - allows efficient lookup when typechecking messages to "id".
784212795Sdim  /// We need to maintain a list, since selectors can have differing signatures
785212795Sdim  /// across classes. In Cocoa, this happens to be extremely uncommon (only 1%
786212795Sdim  /// of selectors are "overloaded").
787251662Sdim  /// At the head of the list it is recorded whether there were 0, 1, or >= 2
788251662Sdim  /// methods inside categories with a particular selector.
789212795Sdim  GlobalMethodPool MethodPool;
790212795Sdim
791239462Sdim  /// Method selectors used in a \@selector expression. Used for implementation
792212795Sdim  /// of -Wselector.
793212795Sdim  llvm::DenseMap<Selector, SourceLocation> ReferencedSelectors;
794212795Sdim
795249423Sdim  /// Kinds of C++ special members.
796249423Sdim  enum CXXSpecialMember {
797249423Sdim    CXXDefaultConstructor,
798249423Sdim    CXXCopyConstructor,
799249423Sdim    CXXMoveConstructor,
800249423Sdim    CXXCopyAssignment,
801249423Sdim    CXXMoveAssignment,
802249423Sdim    CXXDestructor,
803249423Sdim    CXXInvalid
804249423Sdim  };
805249423Sdim
806249423Sdim  typedef std::pair<CXXRecordDecl*, CXXSpecialMember> SpecialMemberDecl;
807249423Sdim
808249423Sdim  /// The C++ special members which we are currently in the process of
809249423Sdim  /// declaring. If this process recursively triggers the declaration of the
810249423Sdim  /// same special member, we should act as if it is not yet declared.
811249423Sdim  llvm::SmallSet<SpecialMemberDecl, 4> SpecialMembersBeingDeclared;
812249423Sdim
813234353Sdim  void ReadMethodPool(Selector Sel);
814212795Sdim
815212795Sdim  /// Private Helper predicate to check for 'self'.
816212795Sdim  bool isSelfExpr(Expr *RExpr);
817234353Sdim
818234353Sdim  /// \brief Cause the active diagnostic on the DiagosticsEngine to be
819234353Sdim  /// emitted. This is closely coupled to the SemaDiagnosticBuilder class and
820234353Sdim  /// should not be used elsewhere.
821234353Sdim  void EmitCurrentDiagnostic(unsigned DiagID);
822234353Sdim
823243830Sdim  /// Records and restores the FP_CONTRACT state on entry/exit of compound
824243830Sdim  /// statements.
825243830Sdim  class FPContractStateRAII {
826243830Sdim  public:
827243830Sdim    FPContractStateRAII(Sema& S)
828243830Sdim      : S(S), OldFPContractState(S.FPFeatures.fp_contract) {}
829243830Sdim    ~FPContractStateRAII() {
830243830Sdim      S.FPFeatures.fp_contract = OldFPContractState;
831243830Sdim    }
832243830Sdim  private:
833243830Sdim    Sema& S;
834243830Sdim    bool OldFPContractState : 1;
835243830Sdim  };
836243830Sdim
837251662Sdim  typedef llvm::MCAsmParserSemaCallback::InlineAsmIdentifierInfo
838251662Sdim    InlineAsmIdentifierInfo;
839251662Sdim
840212795Sdimpublic:
841212795Sdim  Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer,
842226633Sdim       TranslationUnitKind TUKind = TU_Complete,
843212795Sdim       CodeCompleteConsumer *CompletionConsumer = 0);
844212795Sdim  ~Sema();
845234353Sdim
846212795Sdim  /// \brief Perform initialization that occurs after the parser has been
847212795Sdim  /// initialized but before it parses anything.
848212795Sdim  void Initialize();
849234353Sdim
850234353Sdim  const LangOptions &getLangOpts() const { return LangOpts; }
851218893Sdim  OpenCLOptions &getOpenCLOptions() { return OpenCLFeatures; }
852218893Sdim  FPOptions     &getFPOptions() { return FPFeatures; }
853218893Sdim
854226633Sdim  DiagnosticsEngine &getDiagnostics() const { return Diags; }
855212795Sdim  SourceManager &getSourceManager() const { return SourceMgr; }
856212795Sdim  const TargetAttributesSema &getTargetAttributesSema() const;
857212795Sdim  Preprocessor &getPreprocessor() const { return PP; }
858212795Sdim  ASTContext &getASTContext() const { return Context; }
859212795Sdim  ASTConsumer &getASTConsumer() const { return Consumer; }
860221345Sdim  ASTMutationListener *getASTMutationListener() const;
861243830Sdim  ExternalSemaSource* getExternalSource() const { return ExternalSource; }
862224145Sdim
863243830Sdim  ///\brief Registers an external source. If an external source already exists,
864243830Sdim  /// creates a multiplex external source and appends to it.
865243830Sdim  ///
866243830Sdim  ///\param[in] E - A non-null external sema source.
867243830Sdim  ///
868243830Sdim  void addExternalSource(ExternalSemaSource *E);
869243830Sdim
870224145Sdim  void PrintStats() const;
871224145Sdim
872212795Sdim  /// \brief Helper class that creates diagnostics with optional
873212795Sdim  /// template instantiation stacks.
874212795Sdim  ///
875212795Sdim  /// This class provides a wrapper around the basic DiagnosticBuilder
876212795Sdim  /// class that emits diagnostics. SemaDiagnosticBuilder is
877212795Sdim  /// responsible for emitting the diagnostic (as DiagnosticBuilder
878212795Sdim  /// does) and, if the diagnostic comes from inside a template
879212795Sdim  /// instantiation, printing the template instantiation stack as
880212795Sdim  /// well.
881212795Sdim  class SemaDiagnosticBuilder : public DiagnosticBuilder {
882212795Sdim    Sema &SemaRef;
883212795Sdim    unsigned DiagID;
884212795Sdim
885212795Sdim  public:
886212795Sdim    SemaDiagnosticBuilder(DiagnosticBuilder &DB, Sema &SemaRef, unsigned DiagID)
887212795Sdim      : DiagnosticBuilder(DB), SemaRef(SemaRef), DiagID(DiagID) { }
888212795Sdim
889234353Sdim    ~SemaDiagnosticBuilder() {
890234353Sdim      // If we aren't active, there is nothing to do.
891234353Sdim      if (!isActive()) return;
892212795Sdim
893234353Sdim      // Otherwise, we need to emit the diagnostic. First flush the underlying
894234353Sdim      // DiagnosticBuilder data, and clear the diagnostic builder itself so it
895234353Sdim      // won't emit the diagnostic in its own destructor.
896234353Sdim      //
897234353Sdim      // This seems wasteful, in that as written the DiagnosticBuilder dtor will
898234353Sdim      // do its own needless checks to see if the diagnostic needs to be
899234353Sdim      // emitted. However, because we take care to ensure that the builder
900234353Sdim      // objects never escape, a sufficiently smart compiler will be able to
901234353Sdim      // eliminate that code.
902234353Sdim      FlushCounts();
903234353Sdim      Clear();
904234353Sdim
905234353Sdim      // Dispatch to Sema to emit the diagnostic.
906234353Sdim      SemaRef.EmitCurrentDiagnostic(DiagID);
907234353Sdim    }
908212795Sdim  };
909212795Sdim
910212795Sdim  /// \brief Emit a diagnostic.
911234353Sdim  SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) {
912234353Sdim    DiagnosticBuilder DB = Diags.Report(Loc, DiagID);
913234353Sdim    return SemaDiagnosticBuilder(DB, *this, DiagID);
914234353Sdim  }
915212795Sdim
916212795Sdim  /// \brief Emit a partial diagnostic.
917212795Sdim  SemaDiagnosticBuilder Diag(SourceLocation Loc, const PartialDiagnostic& PD);
918212795Sdim
919212795Sdim  /// \brief Build a partial diagnostic.
920212795Sdim  PartialDiagnostic PDiag(unsigned DiagID = 0); // in SemaInternal.h
921212795Sdim
922226633Sdim  bool findMacroSpelling(SourceLocation &loc, StringRef name);
923221345Sdim
924234353Sdim  /// \brief Get a string to suggest for zero-initialization of a type.
925239462Sdim  std::string getFixItZeroInitializerForType(QualType T) const;
926239462Sdim  std::string getFixItZeroLiteralForType(QualType T) const;
927234353Sdim
928212795Sdim  ExprResult Owned(Expr* E) { return E; }
929212795Sdim  ExprResult Owned(ExprResult R) { return R; }
930212795Sdim  StmtResult Owned(Stmt* S) { return S; }
931212795Sdim
932212795Sdim  void ActOnEndOfTranslationUnit();
933212795Sdim
934223017Sdim  void CheckDelegatingCtorCycles();
935223017Sdim
936212795Sdim  Scope *getScopeForContext(DeclContext *Ctx);
937212795Sdim
938212795Sdim  void PushFunctionScope();
939212795Sdim  void PushBlockScope(Scope *BlockScope, BlockDecl *Block);
940234353Sdim  void PushLambdaScope(CXXRecordDecl *Lambda, CXXMethodDecl *CallOperator);
941251662Sdim  void PushCapturedRegionScope(Scope *RegionScope, CapturedDecl *CD,
942251662Sdim                               RecordDecl *RD,
943251662Sdim                               CapturedRegionKind K);
944234353Sdim  void PopFunctionScopeInfo(const sema::AnalysisBasedWarnings::Policy *WP =0,
945234353Sdim                            const Decl *D = 0, const BlockExpr *blkExpr = 0);
946212795Sdim
947212795Sdim  sema::FunctionScopeInfo *getCurFunction() const {
948212795Sdim    return FunctionScopes.back();
949212795Sdim  }
950212795Sdim
951234353Sdim  void PushCompoundScope();
952234353Sdim  void PopCompoundScope();
953234353Sdim
954234353Sdim  sema::CompoundScopeInfo &getCurCompoundScope() const;
955234353Sdim
956224145Sdim  bool hasAnyUnrecoverableErrorsInThisFunction() const;
957212795Sdim
958212795Sdim  /// \brief Retrieve the current block, if any.
959212795Sdim  sema::BlockScopeInfo *getCurBlock();
960212795Sdim
961234353Sdim  /// \brief Retrieve the current lambda expression, if any.
962234353Sdim  sema::LambdaScopeInfo *getCurLambda();
963234353Sdim
964251662Sdim  /// \brief Retrieve the current captured region, if any.
965251662Sdim  sema::CapturedRegionScopeInfo *getCurCapturedRegion();
966251662Sdim
967239462Sdim  /// WeakTopLevelDeclDecls - access to \#pragma weak-generated Decls
968226633Sdim  SmallVector<Decl*,2> &WeakTopLevelDecls() { return WeakTopLevelDecl; }
969212795Sdim
970239462Sdim  void ActOnComment(SourceRange Comment);
971239462Sdim
972212795Sdim  //===--------------------------------------------------------------------===//
973212795Sdim  // Type Analysis / Processing: SemaType.cpp.
974212795Sdim  //
975212795Sdim
976249423Sdim  QualType BuildQualifiedType(QualType T, SourceLocation Loc, Qualifiers Qs,
977249423Sdim                              const DeclSpec *DS = 0);
978249423Sdim  QualType BuildQualifiedType(QualType T, SourceLocation Loc, unsigned CVRA,
979249423Sdim                              const DeclSpec *DS = 0);
980212795Sdim  QualType BuildPointerType(QualType T,
981212795Sdim                            SourceLocation Loc, DeclarationName Entity);
982212795Sdim  QualType BuildReferenceType(QualType T, bool LValueRef,
983212795Sdim                              SourceLocation Loc, DeclarationName Entity);
984212795Sdim  QualType BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM,
985212795Sdim                          Expr *ArraySize, unsigned Quals,
986212795Sdim                          SourceRange Brackets, DeclarationName Entity);
987212795Sdim  QualType BuildExtVectorType(QualType T, Expr *ArraySize,
988212795Sdim                              SourceLocation AttrLoc);
989249423Sdim
990249423Sdim  /// \brief Build a function type.
991249423Sdim  ///
992249423Sdim  /// This routine checks the function type according to C++ rules and
993249423Sdim  /// under the assumption that the result type and parameter types have
994249423Sdim  /// just been instantiated from a template. It therefore duplicates
995249423Sdim  /// some of the behavior of GetTypeForDeclarator, but in a much
996249423Sdim  /// simpler form that is only suitable for this narrow use case.
997249423Sdim  ///
998249423Sdim  /// \param T The return type of the function.
999249423Sdim  ///
1000249423Sdim  /// \param ParamTypes The parameter types of the function. This array
1001249423Sdim  /// will be modified to account for adjustments to the types of the
1002249423Sdim  /// function parameters.
1003249423Sdim  ///
1004249423Sdim  /// \param Loc The location of the entity whose type involves this
1005249423Sdim  /// function type or, if there is no such entity, the location of the
1006249423Sdim  /// type that will have function type.
1007249423Sdim  ///
1008249423Sdim  /// \param Entity The name of the entity that involves the function
1009249423Sdim  /// type, if known.
1010249423Sdim  ///
1011249423Sdim  /// \param EPI Extra information about the function type. Usually this will
1012249423Sdim  /// be taken from an existing function with the same prototype.
1013249423Sdim  ///
1014249423Sdim  /// \returns A suitable function type, if there are no errors. The
1015249423Sdim  /// unqualified type will always be a FunctionProtoType.
1016249423Sdim  /// Otherwise, returns a NULL type.
1017212795Sdim  QualType BuildFunctionType(QualType T,
1018249423Sdim                             llvm::MutableArrayRef<QualType> ParamTypes,
1019212795Sdim                             SourceLocation Loc, DeclarationName Entity,
1020249423Sdim                             const FunctionProtoType::ExtProtoInfo &EPI);
1021249423Sdim
1022212795Sdim  QualType BuildMemberPointerType(QualType T, QualType Class,
1023212795Sdim                                  SourceLocation Loc,
1024212795Sdim                                  DeclarationName Entity);
1025212795Sdim  QualType BuildBlockPointerType(QualType T,
1026212795Sdim                                 SourceLocation Loc, DeclarationName Entity);
1027218893Sdim  QualType BuildParenType(QualType T);
1028226633Sdim  QualType BuildAtomicType(QualType T, SourceLocation Loc);
1029218893Sdim
1030224145Sdim  TypeSourceInfo *GetTypeForDeclarator(Declarator &D, Scope *S);
1031224145Sdim  TypeSourceInfo *GetTypeForDeclaratorCast(Declarator &D, QualType FromTy);
1032212795Sdim  TypeSourceInfo *GetTypeSourceInfoForDeclarator(Declarator &D, QualType T,
1033212795Sdim                                               TypeSourceInfo *ReturnTypeInfo);
1034239462Sdim
1035212795Sdim  /// \brief Package the given type and TSI into a ParsedType.
1036212795Sdim  ParsedType CreateParsedType(QualType T, TypeSourceInfo *TInfo);
1037212795Sdim  DeclarationNameInfo GetNameForDeclarator(Declarator &D);
1038212795Sdim  DeclarationNameInfo GetNameFromUnqualifiedId(const UnqualifiedId &Name);
1039212795Sdim  static QualType GetTypeFromParser(ParsedType Ty, TypeSourceInfo **TInfo = 0);
1040234982Sdim  CanThrowResult canThrow(const Expr *E);
1041234982Sdim  const FunctionProtoType *ResolveExceptionSpec(SourceLocation Loc,
1042234982Sdim                                                const FunctionProtoType *FPT);
1043249423Sdim  bool CheckSpecifiedExceptionType(QualType &T, const SourceRange &Range);
1044212795Sdim  bool CheckDistantExceptionSpec(QualType T);
1045212795Sdim  bool CheckEquivalentExceptionSpec(FunctionDecl *Old, FunctionDecl *New);
1046212795Sdim  bool CheckEquivalentExceptionSpec(
1047212795Sdim      const FunctionProtoType *Old, SourceLocation OldLoc,
1048212795Sdim      const FunctionProtoType *New, SourceLocation NewLoc);
1049212795Sdim  bool CheckEquivalentExceptionSpec(
1050212795Sdim      const PartialDiagnostic &DiagID, const PartialDiagnostic & NoteID,
1051212795Sdim      const FunctionProtoType *Old, SourceLocation OldLoc,
1052212795Sdim      const FunctionProtoType *New, SourceLocation NewLoc,
1053212795Sdim      bool *MissingExceptionSpecification = 0,
1054221345Sdim      bool *MissingEmptyExceptionSpecification = 0,
1055221345Sdim      bool AllowNoexceptAllMatchWithNoSpec = false,
1056221345Sdim      bool IsOperatorNew = false);
1057212795Sdim  bool CheckExceptionSpecSubset(
1058212795Sdim      const PartialDiagnostic &DiagID, const PartialDiagnostic & NoteID,
1059212795Sdim      const FunctionProtoType *Superset, SourceLocation SuperLoc,
1060212795Sdim      const FunctionProtoType *Subset, SourceLocation SubLoc);
1061212795Sdim  bool CheckParamExceptionSpec(const PartialDiagnostic & NoteID,
1062212795Sdim      const FunctionProtoType *Target, SourceLocation TargetLoc,
1063212795Sdim      const FunctionProtoType *Source, SourceLocation SourceLoc);
1064212795Sdim
1065212795Sdim  TypeResult ActOnTypeName(Scope *S, Declarator &D);
1066234353Sdim
1067226633Sdim  /// \brief The parser has parsed the context-sensitive type 'instancetype'
1068226633Sdim  /// in an Objective-C message declaration. Return the appropriate type.
1069226633Sdim  ParsedType ActOnObjCInstanceType(SourceLocation Loc);
1070234353Sdim
1071239462Sdim  /// \brief Abstract class used to diagnose incomplete types.
1072239462Sdim  struct TypeDiagnoser {
1073239462Sdim    bool Suppressed;
1074239462Sdim
1075239462Sdim    TypeDiagnoser(bool Suppressed = false) : Suppressed(Suppressed) { }
1076239462Sdim
1077239462Sdim    virtual void diagnose(Sema &S, SourceLocation Loc, QualType T) = 0;
1078239462Sdim    virtual ~TypeDiagnoser() {}
1079239462Sdim  };
1080239462Sdim
1081239462Sdim  static int getPrintable(int I) { return I; }
1082239462Sdim  static unsigned getPrintable(unsigned I) { return I; }
1083239462Sdim  static bool getPrintable(bool B) { return B; }
1084239462Sdim  static const char * getPrintable(const char *S) { return S; }
1085239462Sdim  static StringRef getPrintable(StringRef S) { return S; }
1086239462Sdim  static const std::string &getPrintable(const std::string &S) { return S; }
1087239462Sdim  static const IdentifierInfo *getPrintable(const IdentifierInfo *II) {
1088239462Sdim    return II;
1089239462Sdim  }
1090239462Sdim  static DeclarationName getPrintable(DeclarationName N) { return N; }
1091239462Sdim  static QualType getPrintable(QualType T) { return T; }
1092239462Sdim  static SourceRange getPrintable(SourceRange R) { return R; }
1093239462Sdim  static SourceRange getPrintable(SourceLocation L) { return L; }
1094239462Sdim  static SourceRange getPrintable(Expr *E) { return E->getSourceRange(); }
1095239462Sdim  static SourceRange getPrintable(TypeLoc TL) { return TL.getSourceRange();}
1096239462Sdim
1097239462Sdim  template<typename T1>
1098239462Sdim  class BoundTypeDiagnoser1 : public TypeDiagnoser {
1099239462Sdim    unsigned DiagID;
1100239462Sdim    const T1 &Arg1;
1101239462Sdim
1102239462Sdim  public:
1103239462Sdim    BoundTypeDiagnoser1(unsigned DiagID, const T1 &Arg1)
1104239462Sdim      : TypeDiagnoser(DiagID == 0), DiagID(DiagID), Arg1(Arg1) { }
1105239462Sdim    virtual void diagnose(Sema &S, SourceLocation Loc, QualType T) {
1106239462Sdim      if (Suppressed) return;
1107239462Sdim      S.Diag(Loc, DiagID) << getPrintable(Arg1) << T;
1108239462Sdim    }
1109239462Sdim
1110239462Sdim    virtual ~BoundTypeDiagnoser1() { }
1111239462Sdim  };
1112239462Sdim
1113239462Sdim  template<typename T1, typename T2>
1114239462Sdim  class BoundTypeDiagnoser2 : public TypeDiagnoser {
1115239462Sdim    unsigned DiagID;
1116239462Sdim    const T1 &Arg1;
1117239462Sdim    const T2 &Arg2;
1118239462Sdim
1119239462Sdim  public:
1120239462Sdim    BoundTypeDiagnoser2(unsigned DiagID, const T1 &Arg1,
1121239462Sdim                                  const T2 &Arg2)
1122239462Sdim      : TypeDiagnoser(DiagID == 0), DiagID(DiagID), Arg1(Arg1),
1123239462Sdim        Arg2(Arg2) { }
1124239462Sdim
1125239462Sdim    virtual void diagnose(Sema &S, SourceLocation Loc, QualType T) {
1126239462Sdim      if (Suppressed) return;
1127239462Sdim      S.Diag(Loc, DiagID) << getPrintable(Arg1) << getPrintable(Arg2) << T;
1128239462Sdim    }
1129239462Sdim
1130239462Sdim    virtual ~BoundTypeDiagnoser2() { }
1131239462Sdim  };
1132239462Sdim
1133239462Sdim  template<typename T1, typename T2, typename T3>
1134239462Sdim  class BoundTypeDiagnoser3 : public TypeDiagnoser {
1135239462Sdim    unsigned DiagID;
1136239462Sdim    const T1 &Arg1;
1137239462Sdim    const T2 &Arg2;
1138239462Sdim    const T3 &Arg3;
1139239462Sdim
1140239462Sdim  public:
1141239462Sdim    BoundTypeDiagnoser3(unsigned DiagID, const T1 &Arg1,
1142239462Sdim                                  const T2 &Arg2, const T3 &Arg3)
1143239462Sdim    : TypeDiagnoser(DiagID == 0), DiagID(DiagID), Arg1(Arg1),
1144239462Sdim      Arg2(Arg2), Arg3(Arg3) { }
1145239462Sdim
1146239462Sdim    virtual void diagnose(Sema &S, SourceLocation Loc, QualType T) {
1147239462Sdim      if (Suppressed) return;
1148239462Sdim      S.Diag(Loc, DiagID)
1149239462Sdim        << getPrintable(Arg1) << getPrintable(Arg2) << getPrintable(Arg3) << T;
1150239462Sdim    }
1151239462Sdim
1152239462Sdim    virtual ~BoundTypeDiagnoser3() { }
1153239462Sdim  };
1154239462Sdim
1155212795Sdim  bool RequireCompleteType(SourceLocation Loc, QualType T,
1156239462Sdim                           TypeDiagnoser &Diagnoser);
1157212795Sdim  bool RequireCompleteType(SourceLocation Loc, QualType T,
1158212795Sdim                           unsigned DiagID);
1159212795Sdim
1160239462Sdim  template<typename T1>
1161239462Sdim  bool RequireCompleteType(SourceLocation Loc, QualType T,
1162239462Sdim                           unsigned DiagID, const T1 &Arg1) {
1163239462Sdim    BoundTypeDiagnoser1<T1> Diagnoser(DiagID, Arg1);
1164239462Sdim    return RequireCompleteType(Loc, T, Diagnoser);
1165239462Sdim  }
1166239462Sdim
1167239462Sdim  template<typename T1, typename T2>
1168239462Sdim  bool RequireCompleteType(SourceLocation Loc, QualType T,
1169239462Sdim                           unsigned DiagID, const T1 &Arg1, const T2 &Arg2) {
1170239462Sdim    BoundTypeDiagnoser2<T1, T2> Diagnoser(DiagID, Arg1, Arg2);
1171239462Sdim    return RequireCompleteType(Loc, T, Diagnoser);
1172239462Sdim  }
1173239462Sdim
1174239462Sdim  template<typename T1, typename T2, typename T3>
1175239462Sdim  bool RequireCompleteType(SourceLocation Loc, QualType T,
1176239462Sdim                           unsigned DiagID, const T1 &Arg1, const T2 &Arg2,
1177239462Sdim                           const T3 &Arg3) {
1178239462Sdim    BoundTypeDiagnoser3<T1, T2, T3> Diagnoser(DiagID, Arg1, Arg2,
1179239462Sdim                                                        Arg3);
1180239462Sdim    return RequireCompleteType(Loc, T, Diagnoser);
1181239462Sdim  }
1182239462Sdim
1183239462Sdim  bool RequireCompleteExprType(Expr *E, TypeDiagnoser &Diagnoser);
1184239462Sdim  bool RequireCompleteExprType(Expr *E, unsigned DiagID);
1185239462Sdim
1186239462Sdim  template<typename T1>
1187239462Sdim  bool RequireCompleteExprType(Expr *E, unsigned DiagID, const T1 &Arg1) {
1188239462Sdim    BoundTypeDiagnoser1<T1> Diagnoser(DiagID, Arg1);
1189239462Sdim    return RequireCompleteExprType(E, Diagnoser);
1190239462Sdim  }
1191239462Sdim
1192239462Sdim  template<typename T1, typename T2>
1193239462Sdim  bool RequireCompleteExprType(Expr *E, unsigned DiagID, const T1 &Arg1,
1194239462Sdim                               const T2 &Arg2) {
1195239462Sdim    BoundTypeDiagnoser2<T1, T2> Diagnoser(DiagID, Arg1, Arg2);
1196239462Sdim    return RequireCompleteExprType(E, Diagnoser);
1197239462Sdim  }
1198239462Sdim
1199239462Sdim  template<typename T1, typename T2, typename T3>
1200239462Sdim  bool RequireCompleteExprType(Expr *E, unsigned DiagID, const T1 &Arg1,
1201239462Sdim                               const T2 &Arg2, const T3 &Arg3) {
1202239462Sdim    BoundTypeDiagnoser3<T1, T2, T3> Diagnoser(DiagID, Arg1, Arg2,
1203239462Sdim                                                        Arg3);
1204239462Sdim    return RequireCompleteExprType(E, Diagnoser);
1205239462Sdim  }
1206239462Sdim
1207226633Sdim  bool RequireLiteralType(SourceLocation Loc, QualType T,
1208239462Sdim                          TypeDiagnoser &Diagnoser);
1209239462Sdim  bool RequireLiteralType(SourceLocation Loc, QualType T, unsigned DiagID);
1210223017Sdim
1211239462Sdim  template<typename T1>
1212239462Sdim  bool RequireLiteralType(SourceLocation Loc, QualType T,
1213239462Sdim                          unsigned DiagID, const T1 &Arg1) {
1214239462Sdim    BoundTypeDiagnoser1<T1> Diagnoser(DiagID, Arg1);
1215239462Sdim    return RequireLiteralType(Loc, T, Diagnoser);
1216239462Sdim  }
1217239462Sdim
1218239462Sdim  template<typename T1, typename T2>
1219239462Sdim  bool RequireLiteralType(SourceLocation Loc, QualType T,
1220239462Sdim                          unsigned DiagID, const T1 &Arg1, const T2 &Arg2) {
1221239462Sdim    BoundTypeDiagnoser2<T1, T2> Diagnoser(DiagID, Arg1, Arg2);
1222239462Sdim    return RequireLiteralType(Loc, T, Diagnoser);
1223239462Sdim  }
1224239462Sdim
1225239462Sdim  template<typename T1, typename T2, typename T3>
1226239462Sdim  bool RequireLiteralType(SourceLocation Loc, QualType T,
1227239462Sdim                          unsigned DiagID, const T1 &Arg1, const T2 &Arg2,
1228239462Sdim                          const T3 &Arg3) {
1229239462Sdim    BoundTypeDiagnoser3<T1, T2, T3> Diagnoser(DiagID, Arg1, Arg2,
1230239462Sdim                                                        Arg3);
1231239462Sdim    return RequireLiteralType(Loc, T, Diagnoser);
1232239462Sdim  }
1233239462Sdim
1234212795Sdim  QualType getElaboratedType(ElaboratedTypeKeyword Keyword,
1235212795Sdim                             const CXXScopeSpec &SS, QualType T);
1236212795Sdim
1237218893Sdim  QualType BuildTypeofExprType(Expr *E, SourceLocation Loc);
1238218893Sdim  QualType BuildDecltypeType(Expr *E, SourceLocation Loc);
1239223017Sdim  QualType BuildUnaryTransformType(QualType BaseType,
1240223017Sdim                                   UnaryTransformType::UTTKind UKind,
1241223017Sdim                                   SourceLocation Loc);
1242212795Sdim
1243212795Sdim  //===--------------------------------------------------------------------===//
1244212795Sdim  // Symbol table / Decl tracking callbacks: SemaDecl.cpp.
1245212795Sdim  //
1246212795Sdim
1247234353Sdim  /// List of decls defined in a function prototype. This contains EnumConstants
1248234353Sdim  /// that incorrectly end up in translation unit scope because there is no
1249234353Sdim  /// function to pin them on. ActOnFunctionDeclarator reads this list and patches
1250234353Sdim  /// them into the FunctionDecl.
1251234353Sdim  std::vector<NamedDecl*> DeclsInPrototypeScope;
1252234353Sdim  /// Nonzero if we are currently parsing a function declarator. This is a counter
1253234353Sdim  /// as opposed to a boolean so we can deal with nested function declarators
1254234353Sdim  /// such as:
1255234353Sdim  ///     void f(void (*g)(), ...)
1256234353Sdim  unsigned InFunctionDeclarator;
1257234353Sdim
1258224145Sdim  DeclGroupPtrTy ConvertDeclToDeclGroup(Decl *Ptr, Decl *OwnedType = 0);
1259212795Sdim
1260212795Sdim  void DiagnoseUseOfUnimplementedSelectors();
1261212795Sdim
1262239462Sdim  bool isSimpleTypeSpecifier(tok::TokenKind Kind) const;
1263239462Sdim
1264251662Sdim  ParsedType getTypeName(const IdentifierInfo &II, SourceLocation NameLoc,
1265212795Sdim                         Scope *S, CXXScopeSpec *SS = 0,
1266212795Sdim                         bool isClassName = false,
1267218893Sdim                         bool HasTrailingDot = false,
1268221345Sdim                         ParsedType ObjectType = ParsedType(),
1269234353Sdim                         bool IsCtorOrDtorName = false,
1270226633Sdim                         bool WantNontrivialTypeSourceInfo = false,
1271226633Sdim                         IdentifierInfo **CorrectedII = 0);
1272212795Sdim  TypeSpecifierType isTagName(IdentifierInfo &II, Scope *S);
1273226633Sdim  bool isMicrosoftMissingTypename(const CXXScopeSpec *SS, Scope *S);
1274239462Sdim  bool DiagnoseUnknownTypeName(IdentifierInfo *&II,
1275212795Sdim                               SourceLocation IILoc,
1276212795Sdim                               Scope *S,
1277212795Sdim                               CXXScopeSpec *SS,
1278212795Sdim                               ParsedType &SuggestedType);
1279212795Sdim
1280221345Sdim  /// \brief Describes the result of the name lookup and resolution performed
1281221345Sdim  /// by \c ClassifyName().
1282221345Sdim  enum NameClassificationKind {
1283221345Sdim    NC_Unknown,
1284221345Sdim    NC_Error,
1285221345Sdim    NC_Keyword,
1286221345Sdim    NC_Type,
1287221345Sdim    NC_Expression,
1288221345Sdim    NC_NestedNameSpecifier,
1289221345Sdim    NC_TypeTemplate,
1290221345Sdim    NC_FunctionTemplate
1291221345Sdim  };
1292234353Sdim
1293221345Sdim  class NameClassification {
1294221345Sdim    NameClassificationKind Kind;
1295221345Sdim    ExprResult Expr;
1296221345Sdim    TemplateName Template;
1297221345Sdim    ParsedType Type;
1298221345Sdim    const IdentifierInfo *Keyword;
1299234353Sdim
1300221345Sdim    explicit NameClassification(NameClassificationKind Kind) : Kind(Kind) {}
1301234353Sdim
1302221345Sdim  public:
1303221345Sdim    NameClassification(ExprResult Expr) : Kind(NC_Expression), Expr(Expr) {}
1304234353Sdim
1305221345Sdim    NameClassification(ParsedType Type) : Kind(NC_Type), Type(Type) {}
1306234353Sdim
1307234353Sdim    NameClassification(const IdentifierInfo *Keyword)
1308221345Sdim      : Kind(NC_Keyword), Keyword(Keyword) { }
1309234353Sdim
1310234353Sdim    static NameClassification Error() {
1311234353Sdim      return NameClassification(NC_Error);
1312221345Sdim    }
1313234353Sdim
1314234353Sdim    static NameClassification Unknown() {
1315234353Sdim      return NameClassification(NC_Unknown);
1316221345Sdim    }
1317234353Sdim
1318221345Sdim    static NameClassification NestedNameSpecifier() {
1319221345Sdim      return NameClassification(NC_NestedNameSpecifier);
1320221345Sdim    }
1321234353Sdim
1322221345Sdim    static NameClassification TypeTemplate(TemplateName Name) {
1323221345Sdim      NameClassification Result(NC_TypeTemplate);
1324221345Sdim      Result.Template = Name;
1325221345Sdim      return Result;
1326221345Sdim    }
1327221345Sdim
1328221345Sdim    static NameClassification FunctionTemplate(TemplateName Name) {
1329221345Sdim      NameClassification Result(NC_FunctionTemplate);
1330221345Sdim      Result.Template = Name;
1331221345Sdim      return Result;
1332221345Sdim    }
1333234353Sdim
1334221345Sdim    NameClassificationKind getKind() const { return Kind; }
1335234353Sdim
1336221345Sdim    ParsedType getType() const {
1337221345Sdim      assert(Kind == NC_Type);
1338221345Sdim      return Type;
1339221345Sdim    }
1340234353Sdim
1341221345Sdim    ExprResult getExpression() const {
1342221345Sdim      assert(Kind == NC_Expression);
1343221345Sdim      return Expr;
1344221345Sdim    }
1345234353Sdim
1346221345Sdim    TemplateName getTemplateName() const {
1347221345Sdim      assert(Kind == NC_TypeTemplate || Kind == NC_FunctionTemplate);
1348221345Sdim      return Template;
1349221345Sdim    }
1350221345Sdim
1351221345Sdim    TemplateNameKind getTemplateNameKind() const {
1352221345Sdim      assert(Kind == NC_TypeTemplate || Kind == NC_FunctionTemplate);
1353221345Sdim      return Kind == NC_TypeTemplate? TNK_Type_template : TNK_Function_template;
1354221345Sdim    }
1355243830Sdim  };
1356234353Sdim
1357221345Sdim  /// \brief Perform name lookup on the given name, classifying it based on
1358221345Sdim  /// the results of name lookup and the following token.
1359221345Sdim  ///
1360221345Sdim  /// This routine is used by the parser to resolve identifiers and help direct
1361221345Sdim  /// parsing. When the identifier cannot be found, this routine will attempt
1362221345Sdim  /// to correct the typo and classify based on the resulting name.
1363221345Sdim  ///
1364221345Sdim  /// \param S The scope in which we're performing name lookup.
1365221345Sdim  ///
1366221345Sdim  /// \param SS The nested-name-specifier that precedes the name.
1367221345Sdim  ///
1368221345Sdim  /// \param Name The identifier. If typo correction finds an alternative name,
1369221345Sdim  /// this pointer parameter will be updated accordingly.
1370221345Sdim  ///
1371221345Sdim  /// \param NameLoc The location of the identifier.
1372221345Sdim  ///
1373234353Sdim  /// \param NextToken The token following the identifier. Used to help
1374221345Sdim  /// disambiguate the name.
1375243830Sdim  ///
1376243830Sdim  /// \param IsAddressOfOperand True if this name is the operand of a unary
1377243830Sdim  ///        address of ('&') expression, assuming it is classified as an
1378243830Sdim  ///        expression.
1379243830Sdim  ///
1380243830Sdim  /// \param CCC The correction callback, if typo correction is desired.
1381221345Sdim  NameClassification ClassifyName(Scope *S,
1382221345Sdim                                  CXXScopeSpec &SS,
1383221345Sdim                                  IdentifierInfo *&Name,
1384221345Sdim                                  SourceLocation NameLoc,
1385243830Sdim                                  const Token &NextToken,
1386243830Sdim                                  bool IsAddressOfOperand,
1387243830Sdim                                  CorrectionCandidateCallback *CCC = 0);
1388234353Sdim
1389224145Sdim  Decl *ActOnDeclarator(Scope *S, Declarator &D);
1390212795Sdim
1391249423Sdim  NamedDecl *HandleDeclarator(Scope *S, Declarator &D,
1392249423Sdim                              MultiTemplateParamsArg TemplateParameterLists);
1393212795Sdim  void RegisterLocallyScopedExternCDecl(NamedDecl *ND,
1394212795Sdim                                        const LookupResult &Previous,
1395212795Sdim                                        Scope *S);
1396221345Sdim  bool DiagnoseClassNameShadow(DeclContext *DC, DeclarationNameInfo Info);
1397234353Sdim  bool diagnoseQualifiedDeclaration(CXXScopeSpec &SS, DeclContext *DC,
1398234353Sdim                                    DeclarationName Name,
1399234353Sdim                                    SourceLocation Loc);
1400249423Sdim  void DiagnoseFunctionSpecifiers(const DeclSpec &DS);
1401212795Sdim  void CheckShadow(Scope *S, VarDecl *D, const LookupResult& R);
1402212795Sdim  void CheckShadow(Scope *S, VarDecl *D);
1403212795Sdim  void CheckCastAlign(Expr *Op, QualType T, SourceRange TRange);
1404223017Sdim  void CheckTypedefForVariablyModifiedType(Scope *S, TypedefNameDecl *D);
1405212795Sdim  NamedDecl* ActOnTypedefDeclarator(Scope* S, Declarator& D, DeclContext* DC,
1406226633Sdim                                    TypeSourceInfo *TInfo,
1407226633Sdim                                    LookupResult &Previous);
1408221345Sdim  NamedDecl* ActOnTypedefNameDecl(Scope* S, DeclContext* DC, TypedefNameDecl *D,
1409221345Sdim                                  LookupResult &Previous, bool &Redeclaration);
1410212795Sdim  NamedDecl* ActOnVariableDeclarator(Scope* S, Declarator& D, DeclContext* DC,
1411226633Sdim                                     TypeSourceInfo *TInfo,
1412212795Sdim                                     LookupResult &Previous,
1413226633Sdim                                     MultiTemplateParamsArg TemplateParamLists);
1414226633Sdim  // Returns true if the variable declaration is a redeclaration
1415226633Sdim  bool CheckVariableDeclaration(VarDecl *NewVD, LookupResult &Previous);
1416251662Sdim  void CheckVariableDeclarationType(VarDecl *NewVD);
1417218893Sdim  void CheckCompleteVariableDeclaration(VarDecl *var);
1418249423Sdim  void MaybeSuggestAddingStaticToDecl(const FunctionDecl *D);
1419234353Sdim  void ActOnStartFunctionDeclarator();
1420234353Sdim  void ActOnEndFunctionDeclarator();
1421212795Sdim  NamedDecl* ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
1422226633Sdim                                     TypeSourceInfo *TInfo,
1423212795Sdim                                     LookupResult &Previous,
1424212795Sdim                                     MultiTemplateParamsArg TemplateParamLists,
1425226633Sdim                                     bool &AddToScope);
1426218893Sdim  bool AddOverriddenMethods(CXXRecordDecl *DC, CXXMethodDecl *MD);
1427243830Sdim  void checkVoidParamDecl(ParmVarDecl *Param);
1428226633Sdim
1429234353Sdim  bool CheckConstexprFunctionDecl(const FunctionDecl *FD);
1430226633Sdim  bool CheckConstexprFunctionBody(const FunctionDecl *FD, Stmt *Body);
1431226633Sdim
1432218893Sdim  void DiagnoseHiddenVirtualMethods(CXXRecordDecl *DC, CXXMethodDecl *MD);
1433226633Sdim  // Returns true if the function declaration is a redeclaration
1434226633Sdim  bool CheckFunctionDeclaration(Scope *S,
1435212795Sdim                                FunctionDecl *NewFD, LookupResult &Previous,
1436226633Sdim                                bool IsExplicitSpecialization);
1437226633Sdim  void CheckMain(FunctionDecl *FD, const DeclSpec &D);
1438212795Sdim  Decl *ActOnParamDeclarator(Scope *S, Declarator &D);
1439212795Sdim  ParmVarDecl *BuildParmVarDeclForTypedef(DeclContext *DC,
1440212795Sdim                                          SourceLocation Loc,
1441212795Sdim                                          QualType T);
1442221345Sdim  ParmVarDecl *CheckParameter(DeclContext *DC, SourceLocation StartLoc,
1443221345Sdim                              SourceLocation NameLoc, IdentifierInfo *Name,
1444221345Sdim                              QualType T, TypeSourceInfo *TSInfo,
1445249423Sdim                              StorageClass SC);
1446212795Sdim  void ActOnParamDefaultArgument(Decl *param,
1447212795Sdim                                 SourceLocation EqualLoc,
1448212795Sdim                                 Expr *defarg);
1449212795Sdim  void ActOnParamUnparsedDefaultArgument(Decl *param,
1450212795Sdim                                         SourceLocation EqualLoc,
1451212795Sdim                                         SourceLocation ArgLoc);
1452212795Sdim  void ActOnParamDefaultArgumentError(Decl *param);
1453212795Sdim  bool SetParamDefaultArgument(ParmVarDecl *Param, Expr *DefaultArg,
1454212795Sdim                               SourceLocation EqualLoc);
1455212795Sdim
1456218893Sdim  void AddInitializerToDecl(Decl *dcl, Expr *init, bool DirectInit,
1457218893Sdim                            bool TypeMayContainAuto);
1458218893Sdim  void ActOnUninitializedDecl(Decl *dcl, bool TypeMayContainAuto);
1459212795Sdim  void ActOnInitializerError(Decl *Dcl);
1460221345Sdim  void ActOnCXXForRangeDecl(Decl *D);
1461212795Sdim  void SetDeclDeleted(Decl *dcl, SourceLocation DelLoc);
1462223017Sdim  void SetDeclDefaulted(Decl *dcl, SourceLocation DefaultLoc);
1463219077Sdim  void FinalizeDeclaration(Decl *D);
1464212795Sdim  DeclGroupPtrTy FinalizeDeclaratorGroup(Scope *S, const DeclSpec &DS,
1465212795Sdim                                         Decl **Group,
1466212795Sdim                                         unsigned NumDecls);
1467219077Sdim  DeclGroupPtrTy BuildDeclaratorGroup(Decl **Group, unsigned NumDecls,
1468219077Sdim                                      bool TypeMayContainAuto = true);
1469239462Sdim
1470239462Sdim  /// Should be called on all declarations that might have attached
1471239462Sdim  /// documentation comments.
1472239462Sdim  void ActOnDocumentableDecl(Decl *D);
1473239462Sdim  void ActOnDocumentableDecls(Decl **Group, unsigned NumDecls);
1474239462Sdim
1475212795Sdim  void ActOnFinishKNRParamDeclarations(Scope *S, Declarator &D,
1476212795Sdim                                       SourceLocation LocAfterDecls);
1477221345Sdim  void CheckForFunctionRedefinition(FunctionDecl *FD);
1478212795Sdim  Decl *ActOnStartOfFunctionDef(Scope *S, Declarator &D);
1479212795Sdim  Decl *ActOnStartOfFunctionDef(Scope *S, Decl *D);
1480212795Sdim  void ActOnStartOfObjCMethodDef(Scope *S, Decl *D);
1481239462Sdim  bool isObjCMethodDecl(Decl *D) {
1482239462Sdim    return D && isa<ObjCMethodDecl>(D);
1483239462Sdim  }
1484212795Sdim
1485249423Sdim  /// \brief Determine whether we can skip parsing the body of a function
1486249423Sdim  /// definition, assuming we don't care about analyzing its body or emitting
1487249423Sdim  /// code for that function.
1488249423Sdim  ///
1489249423Sdim  /// This will be \c false only if we may need the body of the function in
1490249423Sdim  /// order to parse the rest of the program (for instance, if it is
1491249423Sdim  /// \c constexpr in C++11 or has an 'auto' return type in C++14).
1492249423Sdim  bool canSkipFunctionBody(Decl *D);
1493249423Sdim
1494226633Sdim  void computeNRVO(Stmt *Body, sema::FunctionScopeInfo *Scope);
1495212795Sdim  Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body);
1496212795Sdim  Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body, bool IsInstantiation);
1497249423Sdim  Decl *ActOnSkippedFunctionBody(Decl *Decl);
1498212795Sdim
1499226633Sdim  /// ActOnFinishDelayedAttribute - Invoked when we have finished parsing an
1500226633Sdim  /// attribute for which parsing is delayed.
1501226633Sdim  void ActOnFinishDelayedAttribute(Scope *S, Decl *D, ParsedAttributes &Attrs);
1502226633Sdim
1503212795Sdim  /// \brief Diagnose any unused parameters in the given sequence of
1504212795Sdim  /// ParmVarDecl pointers.
1505212795Sdim  void DiagnoseUnusedParameters(ParmVarDecl * const *Begin,
1506212795Sdim                                ParmVarDecl * const *End);
1507212795Sdim
1508218893Sdim  /// \brief Diagnose whether the size of parameters or return value of a
1509218893Sdim  /// function or obj-c method definition is pass-by-value and larger than a
1510218893Sdim  /// specified threshold.
1511218893Sdim  void DiagnoseSizeOfParametersAndReturnValue(ParmVarDecl * const *Begin,
1512218893Sdim                                              ParmVarDecl * const *End,
1513218893Sdim                                              QualType ReturnTy,
1514218893Sdim                                              NamedDecl *D);
1515218893Sdim
1516212795Sdim  void DiagnoseInvalidJumps(Stmt *Body);
1517221345Sdim  Decl *ActOnFileScopeAsmDecl(Expr *expr,
1518221345Sdim                              SourceLocation AsmLoc,
1519221345Sdim                              SourceLocation RParenLoc);
1520212795Sdim
1521249423Sdim  /// \brief Handle a C++11 empty-declaration and attribute-declaration.
1522249423Sdim  Decl *ActOnEmptyDeclaration(Scope *S,
1523249423Sdim                              AttributeList *AttrList,
1524249423Sdim                              SourceLocation SemiLoc);
1525249423Sdim
1526226633Sdim  /// \brief The parser has processed a module import declaration.
1527226633Sdim  ///
1528234353Sdim  /// \param AtLoc The location of the '@' symbol, if any.
1529226633Sdim  ///
1530234353Sdim  /// \param ImportLoc The location of the 'import' keyword.
1531226633Sdim  ///
1532234353Sdim  /// \param Path The module access path.
1533239462Sdim  DeclResult ActOnModuleImport(SourceLocation AtLoc, SourceLocation ImportLoc,
1534234353Sdim                               ModuleIdPath Path);
1535234353Sdim
1536249423Sdim  /// \brief Create an implicit import of the given module at the given
1537249423Sdim  /// source location.
1538249423Sdim  ///
1539249423Sdim  /// This routine is typically used for error recovery, when the entity found
1540249423Sdim  /// by name lookup is actually hidden within a module that we know about but
1541249423Sdim  /// the user has forgotten to import.
1542249423Sdim  void createImplicitModuleImport(SourceLocation Loc, Module *Mod);
1543249423Sdim
1544226633Sdim  /// \brief Retrieve a suitable printing policy.
1545234353Sdim  PrintingPolicy getPrintingPolicy() const {
1546234353Sdim    return getPrintingPolicy(Context, PP);
1547234353Sdim  }
1548226633Sdim
1549234353Sdim  /// \brief Retrieve a suitable printing policy.
1550234353Sdim  static PrintingPolicy getPrintingPolicy(const ASTContext &Ctx,
1551234353Sdim                                          const Preprocessor &PP);
1552234353Sdim
1553212795Sdim  /// Scope actions.
1554212795Sdim  void ActOnPopScope(SourceLocation Loc, Scope *S);
1555212795Sdim  void ActOnTranslationUnitScope(Scope *S);
1556212795Sdim
1557212795Sdim  Decl *ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS,
1558212795Sdim                                   DeclSpec &DS);
1559223017Sdim  Decl *ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS,
1560223017Sdim                                   DeclSpec &DS,
1561249423Sdim                                   MultiTemplateParamsArg TemplateParams,
1562249423Sdim                                   bool IsExplicitInstantiation = false);
1563212795Sdim
1564212795Sdim  Decl *BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS,
1565212795Sdim                                    AccessSpecifier AS,
1566212795Sdim                                    RecordDecl *Record);
1567212795Sdim
1568234353Sdim  Decl *BuildMicrosoftCAnonymousStruct(Scope *S, DeclSpec &DS,
1569218893Sdim                                       RecordDecl *Record);
1570218893Sdim
1571212795Sdim  bool isAcceptableTagRedeclaration(const TagDecl *Previous,
1572223017Sdim                                    TagTypeKind NewTag, bool isDefinition,
1573212795Sdim                                    SourceLocation NewTagLoc,
1574212795Sdim                                    const IdentifierInfo &Name);
1575212795Sdim
1576212795Sdim  enum TagUseKind {
1577212795Sdim    TUK_Reference,   // Reference to a tag:  'struct foo *X;'
1578212795Sdim    TUK_Declaration, // Fwd decl of a tag:   'struct foo;'
1579212795Sdim    TUK_Definition,  // Definition of a tag: 'struct foo { int X; } Y;'
1580212795Sdim    TUK_Friend       // Friend declaration:  'friend struct foo;'
1581212795Sdim  };
1582212795Sdim
1583212795Sdim  Decl *ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK,
1584212795Sdim                 SourceLocation KWLoc, CXXScopeSpec &SS,
1585212795Sdim                 IdentifierInfo *Name, SourceLocation NameLoc,
1586212795Sdim                 AttributeList *Attr, AccessSpecifier AS,
1587226633Sdim                 SourceLocation ModulePrivateLoc,
1588212795Sdim                 MultiTemplateParamsArg TemplateParameterLists,
1589234353Sdim                 bool &OwnedDecl, bool &IsDependent,
1590234353Sdim                 SourceLocation ScopedEnumKWLoc,
1591218893Sdim                 bool ScopedEnumUsesClassTag, TypeResult UnderlyingType);
1592212795Sdim
1593218893Sdim  Decl *ActOnTemplatedFriendTag(Scope *S, SourceLocation FriendLoc,
1594218893Sdim                                unsigned TagSpec, SourceLocation TagLoc,
1595218893Sdim                                CXXScopeSpec &SS,
1596218893Sdim                                IdentifierInfo *Name, SourceLocation NameLoc,
1597218893Sdim                                AttributeList *Attr,
1598218893Sdim                                MultiTemplateParamsArg TempParamLists);
1599218893Sdim
1600212795Sdim  TypeResult ActOnDependentTag(Scope *S,
1601212795Sdim                               unsigned TagSpec,
1602212795Sdim                               TagUseKind TUK,
1603212795Sdim                               const CXXScopeSpec &SS,
1604212795Sdim                               IdentifierInfo *Name,
1605212795Sdim                               SourceLocation TagLoc,
1606212795Sdim                               SourceLocation NameLoc);
1607212795Sdim
1608212795Sdim  void ActOnDefs(Scope *S, Decl *TagD, SourceLocation DeclStart,
1609212795Sdim                 IdentifierInfo *ClassName,
1610226633Sdim                 SmallVectorImpl<Decl *> &Decls);
1611212795Sdim  Decl *ActOnField(Scope *S, Decl *TagD, SourceLocation DeclStart,
1612212795Sdim                   Declarator &D, Expr *BitfieldWidth);
1613212795Sdim
1614212795Sdim  FieldDecl *HandleField(Scope *S, RecordDecl *TagD, SourceLocation DeclStart,
1615239462Sdim                         Declarator &D, Expr *BitfieldWidth,
1616239462Sdim                         InClassInitStyle InitStyle,
1617212795Sdim                         AccessSpecifier AS);
1618251662Sdim  MSPropertyDecl *HandleMSProperty(Scope *S, RecordDecl *TagD,
1619251662Sdim                                   SourceLocation DeclStart,
1620251662Sdim                                   Declarator &D, Expr *BitfieldWidth,
1621251662Sdim                                   InClassInitStyle InitStyle,
1622251662Sdim                                   AccessSpecifier AS,
1623251662Sdim                                   AttributeList *MSPropertyAttr);
1624212795Sdim
1625212795Sdim  FieldDecl *CheckFieldDecl(DeclarationName Name, QualType T,
1626212795Sdim                            TypeSourceInfo *TInfo,
1627212795Sdim                            RecordDecl *Record, SourceLocation Loc,
1628239462Sdim                            bool Mutable, Expr *BitfieldWidth,
1629239462Sdim                            InClassInitStyle InitStyle,
1630212795Sdim                            SourceLocation TSSL,
1631212795Sdim                            AccessSpecifier AS, NamedDecl *PrevDecl,
1632212795Sdim                            Declarator *D = 0);
1633212795Sdim
1634212795Sdim  bool CheckNontrivialField(FieldDecl *FD);
1635249423Sdim  void DiagnoseNontrivial(const CXXRecordDecl *Record, CXXSpecialMember CSM);
1636249423Sdim  bool SpecialMemberIsTrivial(CXXMethodDecl *MD, CXXSpecialMember CSM,
1637249423Sdim                              bool Diagnose = false);
1638212795Sdim  CXXSpecialMember getSpecialMember(const CXXMethodDecl *MD);
1639234353Sdim  void ActOnLastBitfield(SourceLocation DeclStart,
1640226633Sdim                         SmallVectorImpl<Decl *> &AllIvarDecls);
1641226633Sdim  Decl *ActOnIvar(Scope *S, SourceLocation DeclStart,
1642212795Sdim                  Declarator &D, Expr *BitfieldWidth,
1643212795Sdim                  tok::ObjCKeywordKind visibility);
1644212795Sdim
1645212795Sdim  // This is used for both record definitions and ObjC interface declarations.
1646212795Sdim  void ActOnFields(Scope* S, SourceLocation RecLoc, Decl *TagDecl,
1647249423Sdim                   ArrayRef<Decl *> Fields,
1648212795Sdim                   SourceLocation LBrac, SourceLocation RBrac,
1649212795Sdim                   AttributeList *AttrList);
1650212795Sdim
1651212795Sdim  /// ActOnTagStartDefinition - Invoked when we have entered the
1652212795Sdim  /// scope of a tag's definition (e.g., for an enumeration, class,
1653212795Sdim  /// struct, or union).
1654212795Sdim  void ActOnTagStartDefinition(Scope *S, Decl *TagDecl);
1655212795Sdim
1656226633Sdim  Decl *ActOnObjCContainerStartDefinition(Decl *IDecl);
1657226633Sdim
1658212795Sdim  /// ActOnStartCXXMemberDeclarations - Invoked when we have parsed a
1659212795Sdim  /// C++ record definition's base-specifiers clause and are starting its
1660212795Sdim  /// member declarations.
1661212795Sdim  void ActOnStartCXXMemberDeclarations(Scope *S, Decl *TagDecl,
1662221345Sdim                                       SourceLocation FinalLoc,
1663212795Sdim                                       SourceLocation LBraceLoc);
1664212795Sdim
1665212795Sdim  /// ActOnTagFinishDefinition - Invoked once we have finished parsing
1666212795Sdim  /// the definition of a tag (enumeration, class, struct, or union).
1667212795Sdim  void ActOnTagFinishDefinition(Scope *S, Decl *TagDecl,
1668212795Sdim                                SourceLocation RBraceLoc);
1669212795Sdim
1670226633Sdim  void ActOnObjCContainerFinishDefinition();
1671226633Sdim
1672226633Sdim  /// \brief Invoked when we must temporarily exit the objective-c container
1673226633Sdim  /// scope for parsing/looking-up C constructs.
1674226633Sdim  ///
1675226633Sdim  /// Must be followed by a call to \see ActOnObjCReenterContainerContext
1676234353Sdim  void ActOnObjCTemporaryExitContainerContext(DeclContext *DC);
1677234353Sdim  void ActOnObjCReenterContainerContext(DeclContext *DC);
1678226633Sdim
1679212795Sdim  /// ActOnTagDefinitionError - Invoked when there was an unrecoverable
1680212795Sdim  /// error parsing the definition of a tag.
1681212795Sdim  void ActOnTagDefinitionError(Scope *S, Decl *TagDecl);
1682212795Sdim
1683212795Sdim  EnumConstantDecl *CheckEnumConstant(EnumDecl *Enum,
1684212795Sdim                                      EnumConstantDecl *LastEnumConst,
1685212795Sdim                                      SourceLocation IdLoc,
1686212795Sdim                                      IdentifierInfo *Id,
1687212795Sdim                                      Expr *val);
1688234353Sdim  bool CheckEnumUnderlyingType(TypeSourceInfo *TI);
1689234353Sdim  bool CheckEnumRedeclaration(SourceLocation EnumLoc, bool IsScoped,
1690234353Sdim                              QualType EnumUnderlyingTy, const EnumDecl *Prev);
1691212795Sdim
1692212795Sdim  Decl *ActOnEnumConstant(Scope *S, Decl *EnumDecl, Decl *LastEnumConstant,
1693212795Sdim                          SourceLocation IdLoc, IdentifierInfo *Id,
1694218893Sdim                          AttributeList *Attrs,
1695212795Sdim                          SourceLocation EqualLoc, Expr *Val);
1696212795Sdim  void ActOnEnumBody(SourceLocation EnumLoc, SourceLocation LBraceLoc,
1697212795Sdim                     SourceLocation RBraceLoc, Decl *EnumDecl,
1698251662Sdim                     ArrayRef<Decl *> Elements,
1699212795Sdim                     Scope *S, AttributeList *Attr);
1700212795Sdim
1701212795Sdim  DeclContext *getContainingDC(DeclContext *DC);
1702212795Sdim
1703212795Sdim  /// Set the current declaration context until it gets popped.
1704212795Sdim  void PushDeclContext(Scope *S, DeclContext *DC);
1705212795Sdim  void PopDeclContext();
1706212795Sdim
1707212795Sdim  /// EnterDeclaratorContext - Used when we must lookup names in the context
1708212795Sdim  /// of a declarator's nested name specifier.
1709212795Sdim  void EnterDeclaratorContext(Scope *S, DeclContext *DC);
1710212795Sdim  void ExitDeclaratorContext(Scope *S);
1711212795Sdim
1712226633Sdim  /// Push the parameters of D, which must be a function, into scope.
1713226633Sdim  void ActOnReenterFunctionContext(Scope* S, Decl* D);
1714234353Sdim  void ActOnExitFunctionContext();
1715226633Sdim
1716212795Sdim  DeclContext *getFunctionLevelDeclContext();
1717212795Sdim
1718212795Sdim  /// getCurFunctionDecl - If inside of a function body, this returns a pointer
1719212795Sdim  /// to the function decl for the function being parsed.  If we're currently
1720212795Sdim  /// in a 'block', this returns the containing context.
1721212795Sdim  FunctionDecl *getCurFunctionDecl();
1722212795Sdim
1723212795Sdim  /// getCurMethodDecl - If inside of a method body, this returns a pointer to
1724212795Sdim  /// the method decl for the method being parsed.  If we're currently
1725212795Sdim  /// in a 'block', this returns the containing context.
1726212795Sdim  ObjCMethodDecl *getCurMethodDecl();
1727212795Sdim
1728212795Sdim  /// getCurFunctionOrMethodDecl - Return the Decl for the current ObjC method
1729212795Sdim  /// or C function we're in, otherwise return null.  If we're currently
1730212795Sdim  /// in a 'block', this returns the containing context.
1731212795Sdim  NamedDecl *getCurFunctionOrMethodDecl();
1732212795Sdim
1733212795Sdim  /// Add this decl to the scope shadowed decl chains.
1734212795Sdim  void PushOnScopeChains(NamedDecl *D, Scope *S, bool AddToContext = true);
1735212795Sdim
1736234353Sdim  /// \brief Make the given externally-produced declaration visible at the
1737234353Sdim  /// top level scope.
1738234353Sdim  ///
1739234353Sdim  /// \param D The externally-produced declaration to push.
1740234353Sdim  ///
1741234353Sdim  /// \param Name The name of the externally-produced declaration.
1742234353Sdim  void pushExternalDeclIntoScope(NamedDecl *D, DeclarationName Name);
1743234353Sdim
1744212795Sdim  /// isDeclInScope - If 'Ctx' is a function/method, isDeclInScope returns true
1745212795Sdim  /// if 'D' is in Scope 'S', otherwise 'S' is ignored and isDeclInScope returns
1746212795Sdim  /// true if 'D' belongs to the given declaration context.
1747221345Sdim  ///
1748221345Sdim  /// \param ExplicitInstantiationOrSpecialization When true, we are checking
1749221345Sdim  /// whether the declaration is in scope for the purposes of explicit template
1750221345Sdim  /// instantiation or specialization. The default is false.
1751221345Sdim  bool isDeclInScope(NamedDecl *&D, DeclContext *Ctx, Scope *S = 0,
1752221345Sdim                     bool ExplicitInstantiationOrSpecialization = false);
1753212795Sdim
1754212795Sdim  /// Finds the scope corresponding to the given decl context, if it
1755212795Sdim  /// happens to be an enclosing scope.  Otherwise return NULL.
1756212795Sdim  static Scope *getScopeForDeclContext(Scope *S, DeclContext *DC);
1757212795Sdim
1758212795Sdim  /// Subroutines of ActOnDeclarator().
1759212795Sdim  TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, QualType T,
1760212795Sdim                                TypeSourceInfo *TInfo);
1761234353Sdim  bool isIncompatibleTypedef(TypeDecl *Old, TypedefNameDecl *New);
1762239462Sdim
1763239462Sdim  /// Attribute merging methods. Return true if a new attribute was added.
1764249423Sdim  AvailabilityAttr *mergeAvailabilityAttr(NamedDecl *D, SourceRange Range,
1765239462Sdim                                          IdentifierInfo *Platform,
1766239462Sdim                                          VersionTuple Introduced,
1767239462Sdim                                          VersionTuple Deprecated,
1768239462Sdim                                          VersionTuple Obsoleted,
1769239462Sdim                                          bool IsUnavailable,
1770249423Sdim                                          StringRef Message,
1771249423Sdim                                          bool Override,
1772249423Sdim                                          unsigned AttrSpellingListIndex);
1773249423Sdim  TypeVisibilityAttr *mergeTypeVisibilityAttr(Decl *D, SourceRange Range,
1774249423Sdim                                       TypeVisibilityAttr::VisibilityType Vis,
1775249423Sdim                                              unsigned AttrSpellingListIndex);
1776239462Sdim  VisibilityAttr *mergeVisibilityAttr(Decl *D, SourceRange Range,
1777249423Sdim                                      VisibilityAttr::VisibilityType Vis,
1778249423Sdim                                      unsigned AttrSpellingListIndex);
1779249423Sdim  DLLImportAttr *mergeDLLImportAttr(Decl *D, SourceRange Range,
1780249423Sdim                                    unsigned AttrSpellingListIndex);
1781249423Sdim  DLLExportAttr *mergeDLLExportAttr(Decl *D, SourceRange Range,
1782249423Sdim                                    unsigned AttrSpellingListIndex);
1783239462Sdim  FormatAttr *mergeFormatAttr(Decl *D, SourceRange Range, StringRef Format,
1784249423Sdim                              int FormatIdx, int FirstArg,
1785249423Sdim                              unsigned AttrSpellingListIndex);
1786249423Sdim  SectionAttr *mergeSectionAttr(Decl *D, SourceRange Range, StringRef Name,
1787249423Sdim                                unsigned AttrSpellingListIndex);
1788239462Sdim
1789249423Sdim  /// \brief Describes the kind of merge to perform for availability
1790249423Sdim  /// attributes (including "deprecated", "unavailable", and "availability").
1791249423Sdim  enum AvailabilityMergeKind {
1792249423Sdim    /// \brief Don't merge availability attributes at all.
1793249423Sdim    AMK_None,
1794249423Sdim    /// \brief Merge availability attributes for a redeclaration, which requires
1795249423Sdim    /// an exact match.
1796249423Sdim    AMK_Redeclaration,
1797249423Sdim    /// \brief Merge availability attributes for an override, which requires
1798249423Sdim    /// an exact match or a weakening of constraints.
1799249423Sdim    AMK_Override
1800249423Sdim  };
1801249423Sdim
1802249423Sdim  void mergeDeclAttributes(NamedDecl *New, Decl *Old,
1803249423Sdim                           AvailabilityMergeKind AMK = AMK_Redeclaration);
1804221345Sdim  void MergeTypedefNameDecl(TypedefNameDecl *New, LookupResult &OldDecls);
1805234353Sdim  bool MergeFunctionDecl(FunctionDecl *New, Decl *Old, Scope *S);
1806234353Sdim  bool MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old,
1807234353Sdim                                    Scope *S);
1808234353Sdim  void mergeObjCMethodDecls(ObjCMethodDecl *New, ObjCMethodDecl *Old);
1809249423Sdim  void MergeVarDecl(VarDecl *New, LookupResult &OldDecls,
1810249423Sdim                    bool OldDeclsWereHidden);
1811249423Sdim  void MergeVarDeclTypes(VarDecl *New, VarDecl *Old, bool OldIsHidden);
1812221345Sdim  void MergeVarDeclExceptionSpecs(VarDecl *New, VarDecl *Old);
1813234353Sdim  bool MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old, Scope *S);
1814212795Sdim
1815212795Sdim  // AssignmentAction - This is used by all the assignment diagnostic functions
1816212795Sdim  // to represent what is actually causing the operation
1817212795Sdim  enum AssignmentAction {
1818212795Sdim    AA_Assigning,
1819212795Sdim    AA_Passing,
1820212795Sdim    AA_Returning,
1821212795Sdim    AA_Converting,
1822212795Sdim    AA_Initializing,
1823212795Sdim    AA_Sending,
1824212795Sdim    AA_Casting
1825212795Sdim  };
1826212795Sdim
1827212795Sdim  /// C++ Overloading.
1828212795Sdim  enum OverloadKind {
1829212795Sdim    /// This is a legitimate overload: the existing declarations are
1830212795Sdim    /// functions or function templates with different signatures.
1831212795Sdim    Ovl_Overload,
1832212795Sdim
1833212795Sdim    /// This is not an overload because the signature exactly matches
1834212795Sdim    /// an existing declaration.
1835212795Sdim    Ovl_Match,
1836212795Sdim
1837212795Sdim    /// This is not an overload because the lookup results contain a
1838212795Sdim    /// non-function.
1839212795Sdim    Ovl_NonFunction
1840212795Sdim  };
1841212795Sdim  OverloadKind CheckOverload(Scope *S,
1842234353Sdim                             FunctionDecl *New,
1843212795Sdim                             const LookupResult &OldDecls,
1844212795Sdim                             NamedDecl *&OldDecl,
1845212795Sdim                             bool IsForUsingDecl);
1846212795Sdim  bool IsOverload(FunctionDecl *New, FunctionDecl *Old, bool IsForUsingDecl);
1847212795Sdim
1848224145Sdim  /// \brief Checks availability of the function depending on the current
1849224145Sdim  /// function context.Inside an unavailable function,unavailability is ignored.
1850224145Sdim  ///
1851243830Sdim  /// \returns true if \p FD is unavailable and current context is inside
1852224145Sdim  /// an available function, false otherwise.
1853224145Sdim  bool isFunctionConsideredUnavailable(FunctionDecl *FD);
1854212795Sdim
1855224145Sdim  ImplicitConversionSequence
1856224145Sdim  TryImplicitConversion(Expr *From, QualType ToType,
1857224145Sdim                        bool SuppressUserConversions,
1858224145Sdim                        bool AllowExplicit,
1859224145Sdim                        bool InOverloadResolution,
1860224145Sdim                        bool CStyle,
1861224145Sdim                        bool AllowObjCWritebackConversion);
1862224145Sdim
1863212795Sdim  bool IsIntegralPromotion(Expr *From, QualType FromType, QualType ToType);
1864212795Sdim  bool IsFloatingPointPromotion(QualType FromType, QualType ToType);
1865212795Sdim  bool IsComplexPromotion(QualType FromType, QualType ToType);
1866212795Sdim  bool IsPointerConversion(Expr *From, QualType FromType, QualType ToType,
1867212795Sdim                           bool InOverloadResolution,
1868212795Sdim                           QualType& ConvertedType, bool &IncompatibleObjC);
1869212795Sdim  bool isObjCPointerConversion(QualType FromType, QualType ToType,
1870212795Sdim                               QualType& ConvertedType, bool &IncompatibleObjC);
1871224145Sdim  bool isObjCWritebackConversion(QualType FromType, QualType ToType,
1872224145Sdim                                 QualType &ConvertedType);
1873218893Sdim  bool IsBlockPointerConversion(QualType FromType, QualType ToType,
1874218893Sdim                                QualType& ConvertedType);
1875234353Sdim  bool FunctionArgTypesAreEqual(const FunctionProtoType *OldType,
1876234353Sdim                                const FunctionProtoType *NewType,
1877234353Sdim                                unsigned *ArgPos = 0);
1878234353Sdim  void HandleFunctionTypeMismatch(PartialDiagnostic &PDiag,
1879234353Sdim                                  QualType FromType, QualType ToType);
1880234353Sdim
1881226633Sdim  CastKind PrepareCastToObjCObjectPointer(ExprResult &E);
1882212795Sdim  bool CheckPointerConversion(Expr *From, QualType ToType,
1883212795Sdim                              CastKind &Kind,
1884212795Sdim                              CXXCastPath& BasePath,
1885212795Sdim                              bool IgnoreBaseAccess);
1886212795Sdim  bool IsMemberPointerConversion(Expr *From, QualType FromType, QualType ToType,
1887212795Sdim                                 bool InOverloadResolution,
1888212795Sdim                                 QualType &ConvertedType);
1889212795Sdim  bool CheckMemberPointerConversion(Expr *From, QualType ToType,
1890212795Sdim                                    CastKind &Kind,
1891212795Sdim                                    CXXCastPath &BasePath,
1892212795Sdim                                    bool IgnoreBaseAccess);
1893218893Sdim  bool IsQualificationConversion(QualType FromType, QualType ToType,
1894224145Sdim                                 bool CStyle, bool &ObjCLifetimeConversion);
1895224145Sdim  bool IsNoReturnConversion(QualType FromType, QualType ToType,
1896224145Sdim                            QualType &ResultTy);
1897212795Sdim  bool DiagnoseMultipleUserDefinedConversion(Expr *From, QualType ToType);
1898251662Sdim  bool isSameOrCompatibleFunctionType(CanQualType Param, CanQualType Arg);
1899212795Sdim
1900218893Sdim  ExprResult PerformMoveOrCopyInitialization(const InitializedEntity &Entity,
1901218893Sdim                                             const VarDecl *NRVOCandidate,
1902218893Sdim                                             QualType ResultType,
1903224145Sdim                                             Expr *Value,
1904224145Sdim                                             bool AllowNRVO = true);
1905226633Sdim
1906223017Sdim  bool CanPerformCopyInitialization(const InitializedEntity &Entity,
1907223017Sdim                                    ExprResult Init);
1908212795Sdim  ExprResult PerformCopyInitialization(const InitializedEntity &Entity,
1909212795Sdim                                       SourceLocation EqualLoc,
1910226633Sdim                                       ExprResult Init,
1911234353Sdim                                       bool TopLevelOfInitList = false,
1912234353Sdim                                       bool AllowExplicit = false);
1913221345Sdim  ExprResult PerformObjectArgumentInitialization(Expr *From,
1914221345Sdim                                                 NestedNameSpecifier *Qualifier,
1915221345Sdim                                                 NamedDecl *FoundDecl,
1916221345Sdim                                                 CXXMethodDecl *Method);
1917212795Sdim
1918221345Sdim  ExprResult PerformContextuallyConvertToBool(Expr *From);
1919226633Sdim  ExprResult PerformContextuallyConvertToObjCPointer(Expr *From);
1920212795Sdim
1921234353Sdim  /// Contexts in which a converted constant expression is required.
1922234353Sdim  enum CCEKind {
1923234353Sdim    CCEK_CaseValue,  ///< Expression in a case label.
1924234353Sdim    CCEK_Enumerator, ///< Enumerator value with fixed underlying type.
1925234353Sdim    CCEK_TemplateArg ///< Value of a non-type template parameter.
1926234353Sdim  };
1927234353Sdim  ExprResult CheckConvertedConstantExpression(Expr *From, QualType T,
1928234353Sdim                                              llvm::APSInt &Value, CCEKind CCE);
1929234353Sdim
1930239462Sdim  /// \brief Abstract base class used to diagnose problems that occur while
1931239462Sdim  /// trying to convert an expression to integral or enumeration type.
1932239462Sdim  class ICEConvertDiagnoser {
1933239462Sdim  public:
1934239462Sdim    bool Suppress;
1935239462Sdim    bool SuppressConversion;
1936239462Sdim
1937239462Sdim    ICEConvertDiagnoser(bool Suppress = false,
1938239462Sdim                        bool SuppressConversion = false)
1939239462Sdim      : Suppress(Suppress), SuppressConversion(SuppressConversion) { }
1940239462Sdim
1941239462Sdim    /// \brief Emits a diagnostic complaining that the expression does not have
1942239462Sdim    /// integral or enumeration type.
1943239462Sdim    virtual DiagnosticBuilder diagnoseNotInt(Sema &S, SourceLocation Loc,
1944239462Sdim                                             QualType T) = 0;
1945239462Sdim
1946239462Sdim    /// \brief Emits a diagnostic when the expression has incomplete class type.
1947239462Sdim    virtual DiagnosticBuilder diagnoseIncomplete(Sema &S, SourceLocation Loc,
1948239462Sdim                                                 QualType T) = 0;
1949239462Sdim
1950239462Sdim    /// \brief Emits a diagnostic when the only matching conversion function
1951239462Sdim    /// is explicit.
1952239462Sdim    virtual DiagnosticBuilder diagnoseExplicitConv(Sema &S, SourceLocation Loc,
1953239462Sdim                                                   QualType T,
1954239462Sdim                                                   QualType ConvTy) = 0;
1955239462Sdim
1956239462Sdim    /// \brief Emits a note for the explicit conversion function.
1957239462Sdim    virtual DiagnosticBuilder
1958239462Sdim    noteExplicitConv(Sema &S, CXXConversionDecl *Conv, QualType ConvTy) = 0;
1959239462Sdim
1960239462Sdim    /// \brief Emits a diagnostic when there are multiple possible conversion
1961239462Sdim    /// functions.
1962239462Sdim    virtual DiagnosticBuilder diagnoseAmbiguous(Sema &S, SourceLocation Loc,
1963239462Sdim                                                QualType T) = 0;
1964239462Sdim
1965239462Sdim    /// \brief Emits a note for one of the candidate conversions.
1966239462Sdim    virtual DiagnosticBuilder noteAmbiguous(Sema &S, CXXConversionDecl *Conv,
1967239462Sdim                                            QualType ConvTy) = 0;
1968239462Sdim
1969239462Sdim    /// \brief Emits a diagnostic when we picked a conversion function
1970239462Sdim    /// (for cases when we are not allowed to pick a conversion function).
1971239462Sdim    virtual DiagnosticBuilder diagnoseConversion(Sema &S, SourceLocation Loc,
1972239462Sdim                                                 QualType T,
1973239462Sdim                                                 QualType ConvTy) = 0;
1974239462Sdim
1975239462Sdim    virtual ~ICEConvertDiagnoser() {}
1976239462Sdim  };
1977239462Sdim
1978234353Sdim  ExprResult
1979212795Sdim  ConvertToIntegralOrEnumerationType(SourceLocation Loc, Expr *FromE,
1980239462Sdim                                     ICEConvertDiagnoser &Diagnoser,
1981234353Sdim                                     bool AllowScopedEnumerations);
1982239462Sdim
1983234353Sdim  enum ObjCSubscriptKind {
1984234353Sdim    OS_Array,
1985234353Sdim    OS_Dictionary,
1986234353Sdim    OS_Error
1987234353Sdim  };
1988234353Sdim  ObjCSubscriptKind CheckSubscriptingKind(Expr *FromE);
1989234353Sdim
1990249423Sdim  // Note that LK_String is intentionally after the other literals, as
1991249423Sdim  // this is used for diagnostics logic.
1992249423Sdim  enum ObjCLiteralKind {
1993249423Sdim    LK_Array,
1994249423Sdim    LK_Dictionary,
1995249423Sdim    LK_Numeric,
1996249423Sdim    LK_Boxed,
1997249423Sdim    LK_String,
1998249423Sdim    LK_Block,
1999249423Sdim    LK_None
2000249423Sdim  };
2001249423Sdim  ObjCLiteralKind CheckLiteralKind(Expr *FromE);
2002249423Sdim
2003221345Sdim  ExprResult PerformObjectMemberConversion(Expr *From,
2004221345Sdim                                           NestedNameSpecifier *Qualifier,
2005221345Sdim                                           NamedDecl *FoundDecl,
2006221345Sdim                                           NamedDecl *Member);
2007212795Sdim
2008212795Sdim  // Members have to be NamespaceDecl* or TranslationUnitDecl*.
2009212795Sdim  // TODO: make this is a typesafe union.
2010212795Sdim  typedef llvm::SmallPtrSet<DeclContext   *, 16> AssociatedNamespaceSet;
2011212795Sdim  typedef llvm::SmallPtrSet<CXXRecordDecl *, 16> AssociatedClassSet;
2012212795Sdim
2013212795Sdim  void AddOverloadCandidate(FunctionDecl *Function,
2014212795Sdim                            DeclAccessPair FoundDecl,
2015249423Sdim                            ArrayRef<Expr *> Args,
2016212795Sdim                            OverloadCandidateSet& CandidateSet,
2017212795Sdim                            bool SuppressUserConversions = false,
2018234353Sdim                            bool PartialOverloading = false,
2019234353Sdim                            bool AllowExplicit = false);
2020212795Sdim  void AddFunctionCandidates(const UnresolvedSetImpl &Functions,
2021249423Sdim                             ArrayRef<Expr *> Args,
2022212795Sdim                             OverloadCandidateSet& CandidateSet,
2023234353Sdim                             bool SuppressUserConversions = false,
2024234353Sdim                            TemplateArgumentListInfo *ExplicitTemplateArgs = 0);
2025212795Sdim  void AddMethodCandidate(DeclAccessPair FoundDecl,
2026212795Sdim                          QualType ObjectType,
2027218893Sdim                          Expr::Classification ObjectClassification,
2028251662Sdim                          ArrayRef<Expr *> Args,
2029212795Sdim                          OverloadCandidateSet& CandidateSet,
2030212795Sdim                          bool SuppressUserConversion = false);
2031212795Sdim  void AddMethodCandidate(CXXMethodDecl *Method,
2032212795Sdim                          DeclAccessPair FoundDecl,
2033212795Sdim                          CXXRecordDecl *ActingContext, QualType ObjectType,
2034218893Sdim                          Expr::Classification ObjectClassification,
2035249423Sdim                          ArrayRef<Expr *> Args,
2036212795Sdim                          OverloadCandidateSet& CandidateSet,
2037212795Sdim                          bool SuppressUserConversions = false);
2038212795Sdim  void AddMethodTemplateCandidate(FunctionTemplateDecl *MethodTmpl,
2039212795Sdim                                  DeclAccessPair FoundDecl,
2040212795Sdim                                  CXXRecordDecl *ActingContext,
2041221345Sdim                                 TemplateArgumentListInfo *ExplicitTemplateArgs,
2042212795Sdim                                  QualType ObjectType,
2043218893Sdim                                  Expr::Classification ObjectClassification,
2044249423Sdim                                  ArrayRef<Expr *> Args,
2045212795Sdim                                  OverloadCandidateSet& CandidateSet,
2046212795Sdim                                  bool SuppressUserConversions = false);
2047212795Sdim  void AddTemplateOverloadCandidate(FunctionTemplateDecl *FunctionTemplate,
2048212795Sdim                                    DeclAccessPair FoundDecl,
2049221345Sdim                                 TemplateArgumentListInfo *ExplicitTemplateArgs,
2050249423Sdim                                    ArrayRef<Expr *> Args,
2051212795Sdim                                    OverloadCandidateSet& CandidateSet,
2052212795Sdim                                    bool SuppressUserConversions = false);
2053212795Sdim  void AddConversionCandidate(CXXConversionDecl *Conversion,
2054212795Sdim                              DeclAccessPair FoundDecl,
2055212795Sdim                              CXXRecordDecl *ActingContext,
2056212795Sdim                              Expr *From, QualType ToType,
2057212795Sdim                              OverloadCandidateSet& CandidateSet);
2058212795Sdim  void AddTemplateConversionCandidate(FunctionTemplateDecl *FunctionTemplate,
2059212795Sdim                                      DeclAccessPair FoundDecl,
2060212795Sdim                                      CXXRecordDecl *ActingContext,
2061212795Sdim                                      Expr *From, QualType ToType,
2062212795Sdim                                      OverloadCandidateSet &CandidateSet);
2063212795Sdim  void AddSurrogateCandidate(CXXConversionDecl *Conversion,
2064212795Sdim                             DeclAccessPair FoundDecl,
2065212795Sdim                             CXXRecordDecl *ActingContext,
2066212795Sdim                             const FunctionProtoType *Proto,
2067249423Sdim                             Expr *Object, ArrayRef<Expr *> Args,
2068212795Sdim                             OverloadCandidateSet& CandidateSet);
2069212795Sdim  void AddMemberOperatorCandidates(OverloadedOperatorKind Op,
2070251662Sdim                                   SourceLocation OpLoc, ArrayRef<Expr *> Args,
2071212795Sdim                                   OverloadCandidateSet& CandidateSet,
2072212795Sdim                                   SourceRange OpRange = SourceRange());
2073212795Sdim  void AddBuiltinCandidate(QualType ResultTy, QualType *ParamTys,
2074251662Sdim                           ArrayRef<Expr *> Args,
2075212795Sdim                           OverloadCandidateSet& CandidateSet,
2076212795Sdim                           bool IsAssignmentOperator = false,
2077212795Sdim                           unsigned NumContextualBoolArguments = 0);
2078212795Sdim  void AddBuiltinOperatorCandidates(OverloadedOperatorKind Op,
2079251662Sdim                                    SourceLocation OpLoc, ArrayRef<Expr *> Args,
2080212795Sdim                                    OverloadCandidateSet& CandidateSet);
2081212795Sdim  void AddArgumentDependentLookupCandidates(DeclarationName Name,
2082234353Sdim                                            bool Operator, SourceLocation Loc,
2083249423Sdim                                            ArrayRef<Expr *> Args,
2084221345Sdim                                TemplateArgumentListInfo *ExplicitTemplateArgs,
2085212795Sdim                                            OverloadCandidateSet& CandidateSet,
2086243830Sdim                                            bool PartialOverloading = false);
2087212795Sdim
2088218893Sdim  // Emit as a 'note' the specific overload candidate
2089234353Sdim  void NoteOverloadCandidate(FunctionDecl *Fn, QualType DestType = QualType());
2090234353Sdim
2091218893Sdim  // Emit as a series of 'note's all template and non-templates
2092218893Sdim  // identified by the expression Expr
2093234353Sdim  void NoteAllOverloadCandidates(Expr* E, QualType DestType = QualType());
2094234353Sdim
2095218893Sdim  // [PossiblyAFunctionType]  -->   [Return]
2096218893Sdim  // NonFunctionType --> NonFunctionType
2097218893Sdim  // R (A) --> R(A)
2098218893Sdim  // R (*)(A) --> R (A)
2099218893Sdim  // R (&)(A) --> R (A)
2100218893Sdim  // R (S::*)(A) --> R (A)
2101218893Sdim  QualType ExtractUnqualifiedFunctionType(QualType PossiblyAFunctionType);
2102212795Sdim
2103234353Sdim  FunctionDecl *
2104234353Sdim  ResolveAddressOfOverloadedFunction(Expr *AddressOfExpr,
2105234353Sdim                                     QualType TargetType,
2106234353Sdim                                     bool Complain,
2107234353Sdim                                     DeclAccessPair &Found,
2108234353Sdim                                     bool *pHadMultipleCandidates = 0);
2109212795Sdim
2110221345Sdim  FunctionDecl *ResolveSingleFunctionTemplateSpecialization(OverloadExpr *ovl,
2111218893Sdim                                                   bool Complain = false,
2112218893Sdim                                                   DeclAccessPair* Found = 0);
2113218893Sdim
2114226633Sdim  bool ResolveAndFixSingleFunctionTemplateSpecialization(
2115226633Sdim                      ExprResult &SrcExpr,
2116226633Sdim                      bool DoFunctionPointerConverion = false,
2117234353Sdim                      bool Complain = false,
2118234353Sdim                      const SourceRange& OpRangeForComplaining = SourceRange(),
2119234353Sdim                      QualType DestTypeForComplaining = QualType(),
2120221345Sdim                      unsigned DiagIDForComplaining = 0);
2121221345Sdim
2122221345Sdim
2123212795Sdim  Expr *FixOverloadedFunctionReference(Expr *E,
2124212795Sdim                                       DeclAccessPair FoundDecl,
2125212795Sdim                                       FunctionDecl *Fn);
2126212795Sdim  ExprResult FixOverloadedFunctionReference(ExprResult,
2127212795Sdim                                            DeclAccessPair FoundDecl,
2128212795Sdim                                            FunctionDecl *Fn);
2129212795Sdim
2130212795Sdim  void AddOverloadedCallCandidates(UnresolvedLookupExpr *ULE,
2131249423Sdim                                   ArrayRef<Expr *> Args,
2132212795Sdim                                   OverloadCandidateSet &CandidateSet,
2133212795Sdim                                   bool PartialOverloading = false);
2134212795Sdim
2135243830Sdim  // An enum used to represent the different possible results of building a
2136243830Sdim  // range-based for loop.
2137243830Sdim  enum ForRangeStatus {
2138243830Sdim    FRS_Success,
2139243830Sdim    FRS_NoViableFunction,
2140243830Sdim    FRS_DiagnosticIssued
2141243830Sdim  };
2142243830Sdim
2143243830Sdim  // An enum to represent whether something is dealing with a call to begin()
2144243830Sdim  // or a call to end() in a range-based for loop.
2145243830Sdim  enum BeginEndFunction {
2146243830Sdim    BEF_begin,
2147243830Sdim    BEF_end
2148243830Sdim  };
2149243830Sdim
2150243830Sdim  ForRangeStatus BuildForRangeBeginEndCall(Scope *S, SourceLocation Loc,
2151243830Sdim                                           SourceLocation RangeLoc,
2152243830Sdim                                           VarDecl *Decl,
2153243830Sdim                                           BeginEndFunction BEF,
2154243830Sdim                                           const DeclarationNameInfo &NameInfo,
2155243830Sdim                                           LookupResult &MemberLookup,
2156243830Sdim                                           OverloadCandidateSet *CandidateSet,
2157243830Sdim                                           Expr *Range, ExprResult *CallExpr);
2158243830Sdim
2159212795Sdim  ExprResult BuildOverloadedCallExpr(Scope *S, Expr *Fn,
2160212795Sdim                                     UnresolvedLookupExpr *ULE,
2161212795Sdim                                     SourceLocation LParenLoc,
2162212795Sdim                                     Expr **Args, unsigned NumArgs,
2163218893Sdim                                     SourceLocation RParenLoc,
2164234353Sdim                                     Expr *ExecConfig,
2165234353Sdim                                     bool AllowTypoCorrection=true);
2166212795Sdim
2167243830Sdim  bool buildOverloadedCallSet(Scope *S, Expr *Fn, UnresolvedLookupExpr *ULE,
2168243830Sdim                              Expr **Args, unsigned NumArgs,
2169243830Sdim                              SourceLocation RParenLoc,
2170243830Sdim                              OverloadCandidateSet *CandidateSet,
2171243830Sdim                              ExprResult *Result);
2172243830Sdim
2173212795Sdim  ExprResult CreateOverloadedUnaryOp(SourceLocation OpLoc,
2174212795Sdim                                     unsigned Opc,
2175212795Sdim                                     const UnresolvedSetImpl &Fns,
2176212795Sdim                                     Expr *input);
2177212795Sdim
2178212795Sdim  ExprResult CreateOverloadedBinOp(SourceLocation OpLoc,
2179212795Sdim                                   unsigned Opc,
2180212795Sdim                                   const UnresolvedSetImpl &Fns,
2181212795Sdim                                   Expr *LHS, Expr *RHS);
2182212795Sdim
2183212795Sdim  ExprResult CreateOverloadedArraySubscriptExpr(SourceLocation LLoc,
2184212795Sdim                                                SourceLocation RLoc,
2185212795Sdim                                                Expr *Base,Expr *Idx);
2186212795Sdim
2187212795Sdim  ExprResult
2188212795Sdim  BuildCallToMemberFunction(Scope *S, Expr *MemExpr,
2189212795Sdim                            SourceLocation LParenLoc, Expr **Args,
2190218893Sdim                            unsigned NumArgs, SourceLocation RParenLoc);
2191212795Sdim  ExprResult
2192212795Sdim  BuildCallToObjectOfClassType(Scope *S, Expr *Object, SourceLocation LParenLoc,
2193212795Sdim                               Expr **Args, unsigned NumArgs,
2194212795Sdim                               SourceLocation RParenLoc);
2195212795Sdim
2196212795Sdim  ExprResult BuildOverloadedArrowExpr(Scope *S, Expr *Base,
2197212795Sdim                                      SourceLocation OpLoc);
2198212795Sdim
2199212795Sdim  /// CheckCallReturnType - Checks that a call expression's return type is
2200212795Sdim  /// complete. Returns true on failure. The location passed in is the location
2201212795Sdim  /// that best represents the call.
2202212795Sdim  bool CheckCallReturnType(QualType ReturnType, SourceLocation Loc,
2203212795Sdim                           CallExpr *CE, FunctionDecl *FD);
2204212795Sdim
2205212795Sdim  /// Helpers for dealing with blocks and functions.
2206218893Sdim  bool CheckParmsForFunctionDef(ParmVarDecl **Param, ParmVarDecl **ParamEnd,
2207218893Sdim                                bool CheckParameterNames);
2208212795Sdim  void CheckCXXDefaultArguments(FunctionDecl *FD);
2209212795Sdim  void CheckExtraCXXDefaultArguments(Declarator &D);
2210212795Sdim  Scope *getNonFieldDeclScope(Scope *S);
2211212795Sdim
2212212795Sdim  /// \name Name lookup
2213212795Sdim  ///
2214212795Sdim  /// These routines provide name lookup that is used during semantic
2215212795Sdim  /// analysis to resolve the various kinds of names (identifiers,
2216212795Sdim  /// overloaded operator names, constructor names, etc.) into zero or
2217212795Sdim  /// more declarations within a particular scope. The major entry
2218212795Sdim  /// points are LookupName, which performs unqualified name lookup,
2219212795Sdim  /// and LookupQualifiedName, which performs qualified name lookup.
2220212795Sdim  ///
2221212795Sdim  /// All name lookup is performed based on some specific criteria,
2222212795Sdim  /// which specify what names will be visible to name lookup and how
2223212795Sdim  /// far name lookup should work. These criteria are important both
2224212795Sdim  /// for capturing language semantics (certain lookups will ignore
2225212795Sdim  /// certain names, for example) and for performance, since name
2226212795Sdim  /// lookup is often a bottleneck in the compilation of C++. Name
2227212795Sdim  /// lookup criteria is specified via the LookupCriteria enumeration.
2228212795Sdim  ///
2229212795Sdim  /// The results of name lookup can vary based on the kind of name
2230212795Sdim  /// lookup performed, the current language, and the translation
2231212795Sdim  /// unit. In C, for example, name lookup will either return nothing
2232212795Sdim  /// (no entity found) or a single declaration. In C++, name lookup
2233212795Sdim  /// can additionally refer to a set of overloaded functions or
2234212795Sdim  /// result in an ambiguity. All of the possible results of name
2235212795Sdim  /// lookup are captured by the LookupResult class, which provides
2236212795Sdim  /// the ability to distinguish among them.
2237212795Sdim  //@{
2238212795Sdim
2239212795Sdim  /// @brief Describes the kind of name lookup to perform.
2240212795Sdim  enum LookupNameKind {
2241212795Sdim    /// Ordinary name lookup, which finds ordinary names (functions,
2242212795Sdim    /// variables, typedefs, etc.) in C and most kinds of names
2243212795Sdim    /// (functions, variables, members, types, etc.) in C++.
2244212795Sdim    LookupOrdinaryName = 0,
2245212795Sdim    /// Tag name lookup, which finds the names of enums, classes,
2246212795Sdim    /// structs, and unions.
2247212795Sdim    LookupTagName,
2248218893Sdim    /// Label name lookup.
2249218893Sdim    LookupLabel,
2250212795Sdim    /// Member name lookup, which finds the names of
2251212795Sdim    /// class/struct/union members.
2252212795Sdim    LookupMemberName,
2253218893Sdim    /// Look up of an operator name (e.g., operator+) for use with
2254218893Sdim    /// operator overloading. This lookup is similar to ordinary name
2255218893Sdim    /// lookup, but will ignore any declarations that are class members.
2256212795Sdim    LookupOperatorName,
2257212795Sdim    /// Look up of a name that precedes the '::' scope resolution
2258212795Sdim    /// operator in C++. This lookup completely ignores operator, object,
2259212795Sdim    /// function, and enumerator names (C++ [basic.lookup.qual]p1).
2260212795Sdim    LookupNestedNameSpecifierName,
2261212795Sdim    /// Look up a namespace name within a C++ using directive or
2262212795Sdim    /// namespace alias definition, ignoring non-namespace names (C++
2263212795Sdim    /// [basic.lookup.udir]p1).
2264212795Sdim    LookupNamespaceName,
2265212795Sdim    /// Look up all declarations in a scope with the given name,
2266212795Sdim    /// including resolved using declarations.  This is appropriate
2267212795Sdim    /// for checking redeclarations for a using declaration.
2268212795Sdim    LookupUsingDeclName,
2269212795Sdim    /// Look up an ordinary name that is going to be redeclared as a
2270212795Sdim    /// name with linkage. This lookup ignores any declarations that
2271212795Sdim    /// are outside of the current scope unless they have linkage. See
2272212795Sdim    /// C99 6.2.2p4-5 and C++ [basic.link]p6.
2273212795Sdim    LookupRedeclarationWithLinkage,
2274212795Sdim    /// Look up the name of an Objective-C protocol.
2275212795Sdim    LookupObjCProtocolName,
2276224145Sdim    /// Look up implicit 'self' parameter of an objective-c method.
2277224145Sdim    LookupObjCImplicitSelfParam,
2278212795Sdim    /// \brief Look up any declaration with any name.
2279212795Sdim    LookupAnyName
2280212795Sdim  };
2281212795Sdim
2282212795Sdim  /// \brief Specifies whether (or how) name lookup is being performed for a
2283212795Sdim  /// redeclaration (vs. a reference).
2284212795Sdim  enum RedeclarationKind {
2285212795Sdim    /// \brief The lookup is a reference to this name that is not for the
2286212795Sdim    /// purpose of redeclaring the name.
2287212795Sdim    NotForRedeclaration = 0,
2288212795Sdim    /// \brief The lookup results will be used for redeclaration of a name,
2289212795Sdim    /// if an entity by that name already exists.
2290212795Sdim    ForRedeclaration
2291212795Sdim  };
2292212795Sdim
2293234353Sdim  /// \brief The possible outcomes of name lookup for a literal operator.
2294234353Sdim  enum LiteralOperatorLookupResult {
2295234353Sdim    /// \brief The lookup resulted in an error.
2296234353Sdim    LOLR_Error,
2297234353Sdim    /// \brief The lookup found a single 'cooked' literal operator, which
2298234353Sdim    /// expects a normal literal to be built and passed to it.
2299234353Sdim    LOLR_Cooked,
2300234353Sdim    /// \brief The lookup found a single 'raw' literal operator, which expects
2301234353Sdim    /// a string literal containing the spelling of the literal token.
2302234353Sdim    LOLR_Raw,
2303234353Sdim    /// \brief The lookup found an overload set of literal operator templates,
2304234353Sdim    /// which expect the characters of the spelling of the literal token to be
2305234353Sdim    /// passed as a non-type template argument pack.
2306234353Sdim    LOLR_Template
2307234353Sdim  };
2308212795Sdim
2309223017Sdim  SpecialMemberOverloadResult *LookupSpecialMember(CXXRecordDecl *D,
2310223017Sdim                                                   CXXSpecialMember SM,
2311223017Sdim                                                   bool ConstArg,
2312223017Sdim                                                   bool VolatileArg,
2313223017Sdim                                                   bool RValueThis,
2314223017Sdim                                                   bool ConstThis,
2315223017Sdim                                                   bool VolatileThis);
2316223017Sdim
2317234353Sdimprivate:
2318234353Sdim  bool CppLookupName(LookupResult &R, Scope *S);
2319234353Sdim
2320224145Sdim  // \brief The set of known/encountered (unique, canonicalized) NamespaceDecls.
2321224145Sdim  //
2322224145Sdim  // The boolean value will be true to indicate that the namespace was loaded
2323224145Sdim  // from an AST/PCH file, or false otherwise.
2324249423Sdim  llvm::MapVector<NamespaceDecl*, bool> KnownNamespaces;
2325224145Sdim
2326224145Sdim  /// \brief Whether we have already loaded known namespaces from an extenal
2327224145Sdim  /// source.
2328224145Sdim  bool LoadedExternalKnownNamespaces;
2329234353Sdim
2330212795Sdimpublic:
2331212795Sdim  /// \brief Look up a name, looking for a single declaration.  Return
2332212795Sdim  /// null if the results were absent, ambiguous, or overloaded.
2333212795Sdim  ///
2334212795Sdim  /// It is preferable to use the elaborated form and explicitly handle
2335212795Sdim  /// ambiguity and overloaded.
2336212795Sdim  NamedDecl *LookupSingleName(Scope *S, DeclarationName Name,
2337212795Sdim                              SourceLocation Loc,
2338212795Sdim                              LookupNameKind NameKind,
2339212795Sdim                              RedeclarationKind Redecl
2340212795Sdim                                = NotForRedeclaration);
2341212795Sdim  bool LookupName(LookupResult &R, Scope *S,
2342212795Sdim                  bool AllowBuiltinCreation = false);
2343212795Sdim  bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx,
2344212795Sdim                           bool InUnqualifiedLookup = false);
2345212795Sdim  bool LookupParsedName(LookupResult &R, Scope *S, CXXScopeSpec *SS,
2346212795Sdim                        bool AllowBuiltinCreation = false,
2347212795Sdim                        bool EnteringContext = false);
2348234353Sdim  ObjCProtocolDecl *LookupProtocol(IdentifierInfo *II, SourceLocation IdLoc,
2349234353Sdim                                   RedeclarationKind Redecl
2350234353Sdim                                     = NotForRedeclaration);
2351212795Sdim
2352212795Sdim  void LookupOverloadedOperatorName(OverloadedOperatorKind Op, Scope *S,
2353212795Sdim                                    QualType T1, QualType T2,
2354212795Sdim                                    UnresolvedSetImpl &Functions);
2355212795Sdim
2356221345Sdim  LabelDecl *LookupOrCreateLabel(IdentifierInfo *II, SourceLocation IdentLoc,
2357221345Sdim                                 SourceLocation GnuLabelLoc = SourceLocation());
2358221345Sdim
2359212795Sdim  DeclContextLookupResult LookupConstructors(CXXRecordDecl *Class);
2360223017Sdim  CXXConstructorDecl *LookupDefaultConstructor(CXXRecordDecl *Class);
2361224145Sdim  CXXConstructorDecl *LookupCopyingConstructor(CXXRecordDecl *Class,
2362235864Sdim                                               unsigned Quals);
2363224145Sdim  CXXMethodDecl *LookupCopyingAssignment(CXXRecordDecl *Class, unsigned Quals,
2364235864Sdim                                         bool RValueThis, unsigned ThisQuals);
2365239462Sdim  CXXConstructorDecl *LookupMovingConstructor(CXXRecordDecl *Class,
2366239462Sdim                                              unsigned Quals);
2367239462Sdim  CXXMethodDecl *LookupMovingAssignment(CXXRecordDecl *Class, unsigned Quals,
2368239462Sdim                                        bool RValueThis, unsigned ThisQuals);
2369212795Sdim  CXXDestructorDecl *LookupDestructor(CXXRecordDecl *Class);
2370212795Sdim
2371234353Sdim  LiteralOperatorLookupResult LookupLiteralOperator(Scope *S, LookupResult &R,
2372234353Sdim                                                    ArrayRef<QualType> ArgTys,
2373234353Sdim                                                    bool AllowRawAndTemplate);
2374239462Sdim  bool isKnownName(StringRef name);
2375234353Sdim
2376212795Sdim  void ArgumentDependentLookup(DeclarationName Name, bool Operator,
2377234353Sdim                               SourceLocation Loc,
2378249423Sdim                               ArrayRef<Expr *> Args,
2379243830Sdim                               ADLResult &Functions);
2380212795Sdim
2381212795Sdim  void LookupVisibleDecls(Scope *S, LookupNameKind Kind,
2382212795Sdim                          VisibleDeclConsumer &Consumer,
2383212795Sdim                          bool IncludeGlobalScope = true);
2384212795Sdim  void LookupVisibleDecls(DeclContext *Ctx, LookupNameKind Kind,
2385212795Sdim                          VisibleDeclConsumer &Consumer,
2386212795Sdim                          bool IncludeGlobalScope = true);
2387212795Sdim
2388224145Sdim  TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo,
2389224145Sdim                             Sema::LookupNameKind LookupKind,
2390224145Sdim                             Scope *S, CXXScopeSpec *SS,
2391234353Sdim                             CorrectionCandidateCallback &CCC,
2392234353Sdim                             DeclContext *MemberContext = 0,
2393224145Sdim                             bool EnteringContext = false,
2394234353Sdim                             const ObjCObjectPointerType *OPT = 0);
2395212795Sdim
2396243830Sdim  void FindAssociatedClassesAndNamespaces(SourceLocation InstantiationLoc,
2397249423Sdim                                          ArrayRef<Expr *> Args,
2398212795Sdim                                   AssociatedNamespaceSet &AssociatedNamespaces,
2399212795Sdim                                   AssociatedClassSet &AssociatedClasses);
2400212795Sdim
2401223017Sdim  void FilterLookupForScope(LookupResult &R, DeclContext *Ctx, Scope *S,
2402223017Sdim                            bool ConsiderLinkage,
2403223017Sdim                            bool ExplicitInstantiationOrSpecialization);
2404223017Sdim
2405212795Sdim  bool DiagnoseAmbiguousLookup(LookupResult &Result);
2406212795Sdim  //@}
2407212795Sdim
2408212795Sdim  ObjCInterfaceDecl *getObjCInterfaceDecl(IdentifierInfo *&Id,
2409212795Sdim                                          SourceLocation IdLoc,
2410212795Sdim                                          bool TypoCorrection = false);
2411212795Sdim  NamedDecl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID,
2412212795Sdim                                 Scope *S, bool ForRedeclaration,
2413212795Sdim                                 SourceLocation Loc);
2414212795Sdim  NamedDecl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II,
2415212795Sdim                                      Scope *S);
2416212795Sdim  void AddKnownFunctionAttributes(FunctionDecl *FD);
2417212795Sdim
2418212795Sdim  // More parsing and symbol table subroutines.
2419212795Sdim
2420249423Sdim  void ProcessPragmaWeak(Scope *S, Decl *D);
2421212795Sdim  // Decl attributes - this routine is the top level dispatcher.
2422218893Sdim  void ProcessDeclAttributes(Scope *S, Decl *D, const Declarator &PD,
2423249423Sdim                             bool NonInheritable = true,
2424249423Sdim                             bool Inheritable = true);
2425218893Sdim  void ProcessDeclAttributeList(Scope *S, Decl *D, const AttributeList *AL,
2426249423Sdim                                bool NonInheritable = true,
2427249423Sdim                                bool Inheritable = true,
2428249423Sdim                                bool IncludeCXX11Attributes = true);
2429226633Sdim  bool ProcessAccessDeclAttributeList(AccessSpecDecl *ASDecl,
2430226633Sdim                                      const AttributeList *AttrList);
2431212795Sdim
2432226633Sdim  void checkUnusedDeclAttributes(Declarator &D);
2433226633Sdim
2434218893Sdim  bool CheckRegparmAttr(const AttributeList &attr, unsigned &value);
2435249423Sdim  bool CheckCallingConvAttr(const AttributeList &attr, CallingConv &CC,
2436249423Sdim                            const FunctionDecl *FD = 0);
2437218893Sdim  bool CheckNoReturnAttr(const AttributeList &attr);
2438249423Sdim  void CheckAlignasUnderalignment(Decl *D);
2439218893Sdim
2440234982Sdim  /// \brief Stmt attributes - this routine is the top level dispatcher.
2441234982Sdim  StmtResult ProcessStmtAttributes(Stmt *Stmt, AttributeList *Attrs,
2442234982Sdim                                   SourceRange Range);
2443234982Sdim
2444212795Sdim  void WarnUndefinedMethod(SourceLocation ImpLoc, ObjCMethodDecl *method,
2445212795Sdim                           bool &IncompleteImpl, unsigned DiagID);
2446226633Sdim  void WarnConflictingTypedMethods(ObjCMethodDecl *Method,
2447219077Sdim                                   ObjCMethodDecl *MethodDecl,
2448219077Sdim                                   bool IsProtocolMethodDecl);
2449234353Sdim
2450226633Sdim  void CheckConflictingOverridingMethod(ObjCMethodDecl *Method,
2451226633Sdim                                   ObjCMethodDecl *Overridden,
2452226633Sdim                                   bool IsProtocolMethodDecl);
2453212795Sdim
2454226633Sdim  /// WarnExactTypedMethods - This routine issues a warning if method
2455226633Sdim  /// implementation declaration matches exactly that of its declaration.
2456226633Sdim  void WarnExactTypedMethods(ObjCMethodDecl *Method,
2457226633Sdim                             ObjCMethodDecl *MethodDecl,
2458226633Sdim                             bool IsProtocolMethodDecl);
2459226633Sdim
2460212795Sdim  bool isPropertyReadonly(ObjCPropertyDecl *PropertyDecl,
2461212795Sdim                          ObjCInterfaceDecl *IDecl);
2462212795Sdim
2463239462Sdim  typedef llvm::SmallPtrSet<Selector, 8> SelectorSet;
2464226633Sdim  typedef llvm::DenseMap<Selector, ObjCMethodDecl*> ProtocolsMethodsMap;
2465234353Sdim
2466212795Sdim  /// CheckProtocolMethodDefs - This routine checks unimplemented
2467212795Sdim  /// methods declared in protocol, and those referenced by it.
2468212795Sdim  void CheckProtocolMethodDefs(SourceLocation ImpLoc,
2469212795Sdim                               ObjCProtocolDecl *PDecl,
2470212795Sdim                               bool& IncompleteImpl,
2471212795Sdim                               const SelectorSet &InsMap,
2472212795Sdim                               const SelectorSet &ClsMap,
2473212795Sdim                               ObjCContainerDecl *CDecl);
2474212795Sdim
2475212795Sdim  /// CheckImplementationIvars - This routine checks if the instance variables
2476212795Sdim  /// listed in the implelementation match those listed in the interface.
2477212795Sdim  void CheckImplementationIvars(ObjCImplementationDecl *ImpDecl,
2478212795Sdim                                ObjCIvarDecl **Fields, unsigned nIvars,
2479212795Sdim                                SourceLocation Loc);
2480212795Sdim
2481212795Sdim  /// ImplMethodsVsClassMethods - This is main routine to warn if any method
2482239462Sdim  /// remains unimplemented in the class or category \@implementation.
2483212795Sdim  void ImplMethodsVsClassMethods(Scope *S, ObjCImplDecl* IMPDecl,
2484212795Sdim                                 ObjCContainerDecl* IDecl,
2485212795Sdim                                 bool IncompleteImpl = false);
2486212795Sdim
2487212795Sdim  /// DiagnoseUnimplementedProperties - This routine warns on those properties
2488212795Sdim  /// which must be implemented by this implementation.
2489212795Sdim  void DiagnoseUnimplementedProperties(Scope *S, ObjCImplDecl* IMPDecl,
2490251662Sdim                                       ObjCContainerDecl *CDecl);
2491212795Sdim
2492234353Sdim  /// DefaultSynthesizeProperties - This routine default synthesizes all
2493239462Sdim  /// properties which must be synthesized in the class's \@implementation.
2494212795Sdim  void DefaultSynthesizeProperties (Scope *S, ObjCImplDecl* IMPDecl,
2495212795Sdim                                    ObjCInterfaceDecl *IDecl);
2496226633Sdim  void DefaultSynthesizeProperties(Scope *S, Decl *D);
2497234353Sdim
2498212795Sdim  /// CollectImmediateProperties - This routine collects all properties in
2499212795Sdim  /// the class and its conforming protocols; but not those it its super class.
2500212795Sdim  void CollectImmediateProperties(ObjCContainerDecl *CDecl,
2501212795Sdim            llvm::DenseMap<IdentifierInfo *, ObjCPropertyDecl*>& PropMap,
2502212795Sdim            llvm::DenseMap<IdentifierInfo *, ObjCPropertyDecl*>& SuperPropMap);
2503243830Sdim
2504249423Sdim  /// IvarBacksCurrentMethodAccessor - This routine returns 'true' if 'IV' is
2505249423Sdim  /// an ivar synthesized for 'Method' and 'Method' is a property accessor
2506249423Sdim  /// declared in class 'IFace'.
2507249423Sdim  bool IvarBacksCurrentMethodAccessor(ObjCInterfaceDecl *IFace,
2508249423Sdim                                      ObjCMethodDecl *Method, ObjCIvarDecl *IV);
2509249423Sdim
2510239462Sdim  /// Called by ActOnProperty to handle \@property declarations in
2511239462Sdim  /// class extensions.
2512249423Sdim  ObjCPropertyDecl *HandlePropertyInClassExtension(Scope *S,
2513249423Sdim                      SourceLocation AtLoc,
2514249423Sdim                      SourceLocation LParenLoc,
2515249423Sdim                      FieldDeclarator &FD,
2516249423Sdim                      Selector GetterSel,
2517249423Sdim                      Selector SetterSel,
2518249423Sdim                      const bool isAssign,
2519249423Sdim                      const bool isReadWrite,
2520249423Sdim                      const unsigned Attributes,
2521249423Sdim                      const unsigned AttributesAsWritten,
2522249423Sdim                      bool *isOverridingProperty,
2523249423Sdim                      TypeSourceInfo *T,
2524249423Sdim                      tok::ObjCKeywordKind MethodImplKind);
2525212795Sdim
2526212795Sdim  /// Called by ActOnProperty and HandlePropertyInClassExtension to
2527239462Sdim  /// handle creating the ObjcPropertyDecl for a category or \@interface.
2528212795Sdim  ObjCPropertyDecl *CreatePropertyDecl(Scope *S,
2529212795Sdim                                       ObjCContainerDecl *CDecl,
2530212795Sdim                                       SourceLocation AtLoc,
2531234353Sdim                                       SourceLocation LParenLoc,
2532212795Sdim                                       FieldDeclarator &FD,
2533212795Sdim                                       Selector GetterSel,
2534212795Sdim                                       Selector SetterSel,
2535212795Sdim                                       const bool isAssign,
2536212795Sdim                                       const bool isReadWrite,
2537212795Sdim                                       const unsigned Attributes,
2538234353Sdim                                       const unsigned AttributesAsWritten,
2539212795Sdim                                       TypeSourceInfo *T,
2540212795Sdim                                       tok::ObjCKeywordKind MethodImplKind,
2541212795Sdim                                       DeclContext *lexicalDC = 0);
2542212795Sdim
2543212795Sdim  /// AtomicPropertySetterGetterRules - This routine enforces the rule (via
2544212795Sdim  /// warning) when atomic property has one but not the other user-declared
2545212795Sdim  /// setter or getter.
2546212795Sdim  void AtomicPropertySetterGetterRules(ObjCImplDecl* IMPDecl,
2547212795Sdim                                       ObjCContainerDecl* IDecl);
2548212795Sdim
2549224145Sdim  void DiagnoseOwningPropertyGetterSynthesis(const ObjCImplementationDecl *D);
2550224145Sdim
2551212795Sdim  void DiagnoseDuplicateIvars(ObjCInterfaceDecl *ID, ObjCInterfaceDecl *SID);
2552212795Sdim
2553224145Sdim  enum MethodMatchStrategy {
2554224145Sdim    MMS_loose,
2555224145Sdim    MMS_strict
2556224145Sdim  };
2557224145Sdim
2558212795Sdim  /// MatchTwoMethodDeclarations - Checks if two methods' type match and returns
2559212795Sdim  /// true, or false, accordingly.
2560212795Sdim  bool MatchTwoMethodDeclarations(const ObjCMethodDecl *Method,
2561212795Sdim                                  const ObjCMethodDecl *PrevMethod,
2562224145Sdim                                  MethodMatchStrategy strategy = MMS_strict);
2563212795Sdim
2564212795Sdim  /// MatchAllMethodDeclarations - Check methods declaraed in interface or
2565212795Sdim  /// or protocol against those declared in their implementations.
2566212795Sdim  void MatchAllMethodDeclarations(const SelectorSet &InsMap,
2567212795Sdim                                  const SelectorSet &ClsMap,
2568212795Sdim                                  SelectorSet &InsMapSeen,
2569212795Sdim                                  SelectorSet &ClsMapSeen,
2570212795Sdim                                  ObjCImplDecl* IMPDecl,
2571212795Sdim                                  ObjCContainerDecl* IDecl,
2572212795Sdim                                  bool &IncompleteImpl,
2573226633Sdim                                  bool ImmediateClass,
2574234353Sdim                                  bool WarnCategoryMethodImpl=false);
2575212795Sdim
2576226633Sdim  /// CheckCategoryVsClassMethodMatches - Checks that methods implemented in
2577226633Sdim  /// category matches with those implemented in its primary class and
2578234353Sdim  /// warns each time an exact match is found.
2579226633Sdim  void CheckCategoryVsClassMethodMatches(ObjCCategoryImplDecl *CatIMP);
2580226633Sdim
2581234353Sdim  /// \brief Add the given method to the list of globally-known methods.
2582234353Sdim  void addMethodToGlobalList(ObjCMethodList *List, ObjCMethodDecl *Method);
2583239462Sdim
2584212795Sdimprivate:
2585212795Sdim  /// AddMethodToGlobalPool - Add an instance or factory method to the global
2586212795Sdim  /// pool. See descriptoin of AddInstanceMethodToGlobalPool.
2587212795Sdim  void AddMethodToGlobalPool(ObjCMethodDecl *Method, bool impl, bool instance);
2588212795Sdim
2589212795Sdim  /// LookupMethodInGlobalPool - Returns the instance or factory method and
2590212795Sdim  /// optionally warns if there are multiple signatures.
2591212795Sdim  ObjCMethodDecl *LookupMethodInGlobalPool(Selector Sel, SourceRange R,
2592212795Sdim                                           bool receiverIdOrClass,
2593212795Sdim                                           bool warn, bool instance);
2594212795Sdim
2595212795Sdimpublic:
2596212795Sdim  /// AddInstanceMethodToGlobalPool - All instance methods in a translation
2597212795Sdim  /// unit are added to a global pool. This allows us to efficiently associate
2598212795Sdim  /// a selector with a method declaraation for purposes of typechecking
2599212795Sdim  /// messages sent to "id" (where the class of the object is unknown).
2600212795Sdim  void AddInstanceMethodToGlobalPool(ObjCMethodDecl *Method, bool impl=false) {
2601212795Sdim    AddMethodToGlobalPool(Method, impl, /*instance*/true);
2602212795Sdim  }
2603212795Sdim
2604212795Sdim  /// AddFactoryMethodToGlobalPool - Same as above, but for factory methods.
2605212795Sdim  void AddFactoryMethodToGlobalPool(ObjCMethodDecl *Method, bool impl=false) {
2606212795Sdim    AddMethodToGlobalPool(Method, impl, /*instance*/false);
2607212795Sdim  }
2608212795Sdim
2609226633Sdim  /// AddAnyMethodToGlobalPool - Add any method, instance or factory to global
2610226633Sdim  /// pool.
2611226633Sdim  void AddAnyMethodToGlobalPool(Decl *D);
2612226633Sdim
2613212795Sdim  /// LookupInstanceMethodInGlobalPool - Returns the method and warns if
2614212795Sdim  /// there are multiple signatures.
2615212795Sdim  ObjCMethodDecl *LookupInstanceMethodInGlobalPool(Selector Sel, SourceRange R,
2616212795Sdim                                                   bool receiverIdOrClass=false,
2617212795Sdim                                                   bool warn=true) {
2618234353Sdim    return LookupMethodInGlobalPool(Sel, R, receiverIdOrClass,
2619212795Sdim                                    warn, /*instance*/true);
2620212795Sdim  }
2621212795Sdim
2622212795Sdim  /// LookupFactoryMethodInGlobalPool - Returns the method and warns if
2623212795Sdim  /// there are multiple signatures.
2624212795Sdim  ObjCMethodDecl *LookupFactoryMethodInGlobalPool(Selector Sel, SourceRange R,
2625212795Sdim                                                  bool receiverIdOrClass=false,
2626212795Sdim                                                  bool warn=true) {
2627212795Sdim    return LookupMethodInGlobalPool(Sel, R, receiverIdOrClass,
2628212795Sdim                                    warn, /*instance*/false);
2629212795Sdim  }
2630212795Sdim
2631212795Sdim  /// LookupImplementedMethodInGlobalPool - Returns the method which has an
2632212795Sdim  /// implementation.
2633212795Sdim  ObjCMethodDecl *LookupImplementedMethodInGlobalPool(Selector Sel);
2634212795Sdim
2635212795Sdim  /// CollectIvarsToConstructOrDestruct - Collect those ivars which require
2636212795Sdim  /// initialization.
2637212795Sdim  void CollectIvarsToConstructOrDestruct(ObjCInterfaceDecl *OI,
2638226633Sdim                                  SmallVectorImpl<ObjCIvarDecl*> &Ivars);
2639221345Sdim
2640212795Sdim  //===--------------------------------------------------------------------===//
2641212795Sdim  // Statement Parsing Callbacks: SemaStmt.cpp.
2642212795Sdimpublic:
2643212795Sdim  class FullExprArg {
2644212795Sdim  public:
2645212795Sdim    FullExprArg(Sema &actions) : E(0) { }
2646234353Sdim
2647212795Sdim    // FIXME: The const_cast here is ugly. RValue references would make this
2648212795Sdim    // much nicer (or we could duplicate a bunch of the move semantics
2649212795Sdim    // emulation code from Ownership.h).
2650218893Sdim    FullExprArg(const FullExprArg& Other) : E(Other.E) {}
2651212795Sdim
2652212795Sdim    ExprResult release() {
2653243830Sdim      return E;
2654212795Sdim    }
2655212795Sdim
2656212795Sdim    Expr *get() const { return E; }
2657212795Sdim
2658212795Sdim    Expr *operator->() {
2659212795Sdim      return E;
2660212795Sdim    }
2661212795Sdim
2662212795Sdim  private:
2663212795Sdim    // FIXME: No need to make the entire Sema class a friend when it's just
2664218893Sdim    // Sema::MakeFullExpr that needs access to the constructor below.
2665212795Sdim    friend class Sema;
2666212795Sdim
2667212795Sdim    explicit FullExprArg(Expr *expr) : E(expr) {}
2668212795Sdim
2669212795Sdim    Expr *E;
2670212795Sdim  };
2671212795Sdim
2672212795Sdim  FullExprArg MakeFullExpr(Expr *Arg) {
2673239462Sdim    return MakeFullExpr(Arg, Arg ? Arg->getExprLoc() : SourceLocation());
2674212795Sdim  }
2675239462Sdim  FullExprArg MakeFullExpr(Expr *Arg, SourceLocation CC) {
2676239462Sdim    return FullExprArg(ActOnFinishFullExpr(Arg, CC).release());
2677239462Sdim  }
2678249423Sdim  FullExprArg MakeFullDiscardedValueExpr(Expr *Arg) {
2679249423Sdim    ExprResult FE =
2680249423Sdim      ActOnFinishFullExpr(Arg, Arg ? Arg->getExprLoc() : SourceLocation(),
2681249423Sdim                          /*DiscardedValue*/ true);
2682249423Sdim    return FullExprArg(FE.release());
2683249423Sdim  }
2684212795Sdim
2685249423Sdim  StmtResult ActOnExprStmt(ExprResult Arg);
2686249423Sdim  StmtResult ActOnExprStmtError();
2687212795Sdim
2688218893Sdim  StmtResult ActOnNullStmt(SourceLocation SemiLoc,
2689226633Sdim                           bool HasLeadingEmptyMacro = false);
2690234353Sdim
2691234353Sdim  void ActOnStartOfCompoundStmt();
2692234353Sdim  void ActOnFinishOfCompoundStmt();
2693212795Sdim  StmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R,
2694212795Sdim                                       MultiStmtArg Elts,
2695212795Sdim                                       bool isStmtExpr);
2696234353Sdim
2697234353Sdim  /// \brief A RAII object to enter scope of a compound statement.
2698234353Sdim  class CompoundScopeRAII {
2699234353Sdim  public:
2700234353Sdim    CompoundScopeRAII(Sema &S): S(S) {
2701234353Sdim      S.ActOnStartOfCompoundStmt();
2702234353Sdim    }
2703234353Sdim
2704234353Sdim    ~CompoundScopeRAII() {
2705234353Sdim      S.ActOnFinishOfCompoundStmt();
2706234353Sdim    }
2707234353Sdim
2708234353Sdim  private:
2709234353Sdim    Sema &S;
2710234353Sdim  };
2711234353Sdim
2712212795Sdim  StmtResult ActOnDeclStmt(DeclGroupPtrTy Decl,
2713212795Sdim                                   SourceLocation StartLoc,
2714212795Sdim                                   SourceLocation EndLoc);
2715212795Sdim  void ActOnForEachDeclStmt(DeclGroupPtrTy Decl);
2716218893Sdim  StmtResult ActOnForEachLValueExpr(Expr *E);
2717212795Sdim  StmtResult ActOnCaseStmt(SourceLocation CaseLoc, Expr *LHSVal,
2718212795Sdim                                   SourceLocation DotDotDotLoc, Expr *RHSVal,
2719212795Sdim                                   SourceLocation ColonLoc);
2720212795Sdim  void ActOnCaseStmtBody(Stmt *CaseStmt, Stmt *SubStmt);
2721212795Sdim
2722212795Sdim  StmtResult ActOnDefaultStmt(SourceLocation DefaultLoc,
2723212795Sdim                                      SourceLocation ColonLoc,
2724212795Sdim                                      Stmt *SubStmt, Scope *CurScope);
2725218893Sdim  StmtResult ActOnLabelStmt(SourceLocation IdentLoc, LabelDecl *TheDecl,
2726218893Sdim                            SourceLocation ColonLoc, Stmt *SubStmt);
2727234353Sdim
2728239462Sdim  StmtResult ActOnAttributedStmt(SourceLocation AttrLoc,
2729239462Sdim                                 ArrayRef<const Attr*> Attrs,
2730234982Sdim                                 Stmt *SubStmt);
2731234982Sdim
2732212795Sdim  StmtResult ActOnIfStmt(SourceLocation IfLoc,
2733218893Sdim                         FullExprArg CondVal, Decl *CondVar,
2734218893Sdim                         Stmt *ThenVal,
2735218893Sdim                         SourceLocation ElseLoc, Stmt *ElseVal);
2736212795Sdim  StmtResult ActOnStartOfSwitchStmt(SourceLocation SwitchLoc,
2737212795Sdim                                            Expr *Cond,
2738212795Sdim                                            Decl *CondVar);
2739212795Sdim  StmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc,
2740212795Sdim                                           Stmt *Switch, Stmt *Body);
2741212795Sdim  StmtResult ActOnWhileStmt(SourceLocation WhileLoc,
2742218893Sdim                            FullExprArg Cond,
2743218893Sdim                            Decl *CondVar, Stmt *Body);
2744212795Sdim  StmtResult ActOnDoStmt(SourceLocation DoLoc, Stmt *Body,
2745212795Sdim                                 SourceLocation WhileLoc,
2746212795Sdim                                 SourceLocation CondLParen, Expr *Cond,
2747212795Sdim                                 SourceLocation CondRParen);
2748212795Sdim
2749212795Sdim  StmtResult ActOnForStmt(SourceLocation ForLoc,
2750212795Sdim                          SourceLocation LParenLoc,
2751212795Sdim                          Stmt *First, FullExprArg Second,
2752212795Sdim                          Decl *SecondVar,
2753212795Sdim                          FullExprArg Third,
2754212795Sdim                          SourceLocation RParenLoc,
2755212795Sdim                          Stmt *Body);
2756239462Sdim  ExprResult CheckObjCForCollectionOperand(SourceLocation forLoc,
2757226633Sdim                                           Expr *collection);
2758212795Sdim  StmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc,
2759239462Sdim                                        Stmt *First, Expr *collection,
2760239462Sdim                                        SourceLocation RParenLoc);
2761239462Sdim  StmtResult FinishObjCForCollectionStmt(Stmt *ForCollection, Stmt *Body);
2762239462Sdim
2763243830Sdim  enum BuildForRangeKind {
2764243830Sdim    /// Initial building of a for-range statement.
2765243830Sdim    BFRK_Build,
2766243830Sdim    /// Instantiation or recovery rebuild of a for-range statement. Don't
2767243830Sdim    /// attempt any typo-correction.
2768243830Sdim    BFRK_Rebuild,
2769243830Sdim    /// Determining whether a for-range statement could be built. Avoid any
2770243830Sdim    /// unnecessary or irreversible actions.
2771243830Sdim    BFRK_Check
2772243830Sdim  };
2773243830Sdim
2774239462Sdim  StmtResult ActOnCXXForRangeStmt(SourceLocation ForLoc, Stmt *LoopVar,
2775221345Sdim                                  SourceLocation ColonLoc, Expr *Collection,
2776243830Sdim                                  SourceLocation RParenLoc,
2777243830Sdim                                  BuildForRangeKind Kind);
2778221345Sdim  StmtResult BuildCXXForRangeStmt(SourceLocation ForLoc,
2779221345Sdim                                  SourceLocation ColonLoc,
2780221345Sdim                                  Stmt *RangeDecl, Stmt *BeginEndDecl,
2781221345Sdim                                  Expr *Cond, Expr *Inc,
2782221345Sdim                                  Stmt *LoopVarDecl,
2783243830Sdim                                  SourceLocation RParenLoc,
2784243830Sdim                                  BuildForRangeKind Kind);
2785221345Sdim  StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body);
2786212795Sdim
2787212795Sdim  StmtResult ActOnGotoStmt(SourceLocation GotoLoc,
2788212795Sdim                           SourceLocation LabelLoc,
2789218893Sdim                           LabelDecl *TheDecl);
2790212795Sdim  StmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc,
2791212795Sdim                                   SourceLocation StarLoc,
2792212795Sdim                                   Expr *DestExp);
2793212795Sdim  StmtResult ActOnContinueStmt(SourceLocation ContinueLoc, Scope *CurScope);
2794249423Sdim  StmtResult ActOnBreakStmt(SourceLocation BreakLoc, Scope *CurScope);
2795212795Sdim
2796251662Sdim  void ActOnCapturedRegionStart(SourceLocation Loc, Scope *CurScope,
2797251662Sdim                                CapturedRegionKind Kind, unsigned NumParams);
2798251662Sdim  StmtResult ActOnCapturedRegionEnd(Stmt *S);
2799251662Sdim  void ActOnCapturedRegionError();
2800251662Sdim  RecordDecl *CreateCapturedStmtRecordDecl(CapturedDecl *&CD,
2801251662Sdim                                           SourceLocation Loc,
2802251662Sdim                                           unsigned NumParams);
2803218893Sdim  const VarDecl *getCopyElisionCandidate(QualType ReturnType, Expr *E,
2804218893Sdim                                         bool AllowFunctionParameters);
2805234353Sdim
2806212795Sdim  StmtResult ActOnReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp);
2807234353Sdim  StmtResult ActOnCapScopeReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp);
2808212795Sdim
2809243830Sdim  StmtResult ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
2810243830Sdim                             bool IsVolatile, unsigned NumOutputs,
2811243830Sdim                             unsigned NumInputs, IdentifierInfo **Names,
2812243830Sdim                             MultiExprArg Constraints, MultiExprArg Exprs,
2813243830Sdim                             Expr *AsmString, MultiExprArg Clobbers,
2814243830Sdim                             SourceLocation RParenLoc);
2815212795Sdim
2816251662Sdim  ExprResult LookupInlineAsmIdentifier(CXXScopeSpec &SS,
2817251662Sdim                                       SourceLocation TemplateKWLoc,
2818251662Sdim                                       UnqualifiedId &Id,
2819251662Sdim                                       InlineAsmIdentifierInfo &Info,
2820251662Sdim                                       bool IsUnevaluatedContext);
2821243830Sdim  bool LookupInlineAsmField(StringRef Base, StringRef Member,
2822243830Sdim                            unsigned &Offset, SourceLocation AsmLoc);
2823243830Sdim  StmtResult ActOnMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
2824251662Sdim                            ArrayRef<Token> AsmToks,
2825251662Sdim                            StringRef AsmString,
2826251662Sdim                            unsigned NumOutputs, unsigned NumInputs,
2827251662Sdim                            ArrayRef<StringRef> Constraints,
2828251662Sdim                            ArrayRef<StringRef> Clobbers,
2829251662Sdim                            ArrayRef<Expr*> Exprs,
2830251662Sdim                            SourceLocation EndLoc);
2831212795Sdim
2832212795Sdim  VarDecl *BuildObjCExceptionDecl(TypeSourceInfo *TInfo, QualType ExceptionType,
2833221345Sdim                                  SourceLocation StartLoc,
2834221345Sdim                                  SourceLocation IdLoc, IdentifierInfo *Id,
2835212795Sdim                                  bool Invalid = false);
2836212795Sdim
2837212795Sdim  Decl *ActOnObjCExceptionDecl(Scope *S, Declarator &D);
2838212795Sdim
2839212795Sdim  StmtResult ActOnObjCAtCatchStmt(SourceLocation AtLoc, SourceLocation RParen,
2840212795Sdim                                  Decl *Parm, Stmt *Body);
2841212795Sdim
2842212795Sdim  StmtResult ActOnObjCAtFinallyStmt(SourceLocation AtLoc, Stmt *Body);
2843212795Sdim
2844212795Sdim  StmtResult ActOnObjCAtTryStmt(SourceLocation AtLoc, Stmt *Try,
2845212795Sdim                                MultiStmtArg Catch, Stmt *Finally);
2846212795Sdim
2847212795Sdim  StmtResult BuildObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw);
2848212795Sdim  StmtResult ActOnObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw,
2849212795Sdim                                  Scope *CurScope);
2850226633Sdim  ExprResult ActOnObjCAtSynchronizedOperand(SourceLocation atLoc,
2851226633Sdim                                            Expr *operand);
2852212795Sdim  StmtResult ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc,
2853212795Sdim                                         Expr *SynchExpr,
2854212795Sdim                                         Stmt *SynchBody);
2855212795Sdim
2856224145Sdim  StmtResult ActOnObjCAutoreleasePoolStmt(SourceLocation AtLoc, Stmt *Body);
2857224145Sdim
2858221345Sdim  VarDecl *BuildExceptionDeclaration(Scope *S, TypeSourceInfo *TInfo,
2859221345Sdim                                     SourceLocation StartLoc,
2860221345Sdim                                     SourceLocation IdLoc,
2861221345Sdim                                     IdentifierInfo *Id);
2862224145Sdim
2863212795Sdim  Decl *ActOnExceptionDeclarator(Scope *S, Declarator &D);
2864212795Sdim
2865212795Sdim  StmtResult ActOnCXXCatchBlock(SourceLocation CatchLoc,
2866212795Sdim                                Decl *ExDecl, Stmt *HandlerBlock);
2867212795Sdim  StmtResult ActOnCXXTryBlock(SourceLocation TryLoc, Stmt *TryBlock,
2868212795Sdim                              MultiStmtArg Handlers);
2869221345Sdim
2870221345Sdim  StmtResult ActOnSEHTryBlock(bool IsCXXTry, // try (true) or __try (false) ?
2871221345Sdim                              SourceLocation TryLoc,
2872221345Sdim                              Stmt *TryBlock,
2873221345Sdim                              Stmt *Handler);
2874221345Sdim
2875221345Sdim  StmtResult ActOnSEHExceptBlock(SourceLocation Loc,
2876221345Sdim                                 Expr *FilterExpr,
2877221345Sdim                                 Stmt *Block);
2878221345Sdim
2879221345Sdim  StmtResult ActOnSEHFinallyBlock(SourceLocation Loc,
2880221345Sdim                                  Stmt *Block);
2881221345Sdim
2882212795Sdim  void DiagnoseReturnInConstructorExceptionHandler(CXXTryStmt *TryBlock);
2883212795Sdim
2884212795Sdim  bool ShouldWarnIfUnusedFileScopedDecl(const DeclaratorDecl *D) const;
2885234353Sdim
2886212795Sdim  /// \brief If it's a file scoped decl that must warn if not used, keep track
2887212795Sdim  /// of it.
2888212795Sdim  void MarkUnusedFileScopedDecl(const DeclaratorDecl *D);
2889212795Sdim
2890212795Sdim  /// DiagnoseUnusedExprResult - If the statement passed in is an expression
2891212795Sdim  /// whose result is unused, warn.
2892212795Sdim  void DiagnoseUnusedExprResult(const Stmt *S);
2893212795Sdim  void DiagnoseUnusedDecl(const NamedDecl *ND);
2894234353Sdim
2895234353Sdim  /// Emit \p DiagID if statement located on \p StmtLoc has a suspicious null
2896234353Sdim  /// statement as a \p Body, and it is located on the same line.
2897234353Sdim  ///
2898234353Sdim  /// This helps prevent bugs due to typos, such as:
2899234353Sdim  ///     if (condition);
2900234353Sdim  ///       do_stuff();
2901234353Sdim  void DiagnoseEmptyStmtBody(SourceLocation StmtLoc,
2902234353Sdim                             const Stmt *Body,
2903234353Sdim                             unsigned DiagID);
2904234353Sdim
2905234353Sdim  /// Warn if a for/while loop statement \p S, which is followed by
2906234353Sdim  /// \p PossibleBody, has a suspicious null statement as a body.
2907234353Sdim  void DiagnoseEmptyLoopBody(const Stmt *S,
2908234353Sdim                             const Stmt *PossibleBody);
2909234353Sdim
2910239462Sdim  ParsingDeclState PushParsingDeclaration(sema::DelayedDiagnosticPool &pool) {
2911239462Sdim    return DelayedDiagnostics.push(pool);
2912218893Sdim  }
2913239462Sdim  void PopParsingDeclaration(ParsingDeclState state, Decl *decl);
2914212795Sdim
2915218893Sdim  typedef ProcessingContextState ParsingClassState;
2916218893Sdim  ParsingClassState PushParsingClass() {
2917239462Sdim    return DelayedDiagnostics.pushUndelayed();
2918218893Sdim  }
2919218893Sdim  void PopParsingClass(ParsingClassState state) {
2920239462Sdim    DelayedDiagnostics.popUndelayed(state);
2921218893Sdim  }
2922212795Sdim
2923239462Sdim  void redelayDiagnostics(sema::DelayedDiagnosticPool &pool);
2924239462Sdim
2925226633Sdim  void EmitDeprecationWarning(NamedDecl *D, StringRef Message,
2926234353Sdim                              SourceLocation Loc,
2927243830Sdim                              const ObjCInterfaceDecl *UnknownObjCClass,
2928243830Sdim                              const ObjCPropertyDecl  *ObjCProperty);
2929218893Sdim
2930212795Sdim  void HandleDelayedDeprecationCheck(sema::DelayedDiagnostic &DD, Decl *Ctx);
2931212795Sdim
2932224145Sdim  bool makeUnavailableInSystemHeader(SourceLocation loc,
2933226633Sdim                                     StringRef message);
2934224145Sdim
2935212795Sdim  //===--------------------------------------------------------------------===//
2936212795Sdim  // Expression Parsing Callbacks: SemaExpr.cpp.
2937212795Sdim
2938226633Sdim  bool CanUseDecl(NamedDecl *D);
2939226633Sdim  bool DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc,
2940221345Sdim                         const ObjCInterfaceDecl *UnknownObjCClass=0);
2941234353Sdim  void NoteDeletedFunction(FunctionDecl *FD);
2942221345Sdim  std::string getDeletedOrUnavailableSuffix(const FunctionDecl *FD);
2943212795Sdim  bool DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *PD,
2944212795Sdim                                        ObjCMethodDecl *Getter,
2945212795Sdim                                        SourceLocation Loc);
2946212795Sdim  void DiagnoseSentinelCalls(NamedDecl *D, SourceLocation Loc,
2947212795Sdim                             Expr **Args, unsigned NumArgs);
2948212795Sdim
2949234353Sdim  void PushExpressionEvaluationContext(ExpressionEvaluationContext NewContext,
2950234353Sdim                                       Decl *LambdaContextDecl = 0,
2951234353Sdim                                       bool IsDecltype = false);
2952243830Sdim  enum ReuseLambdaContextDecl_t { ReuseLambdaContextDecl };
2953243830Sdim  void PushExpressionEvaluationContext(ExpressionEvaluationContext NewContext,
2954243830Sdim                                       ReuseLambdaContextDecl_t,
2955243830Sdim                                       bool IsDecltype = false);
2956212795Sdim  void PopExpressionEvaluationContext();
2957212795Sdim
2958224145Sdim  void DiscardCleanupsInEvaluationContext();
2959224145Sdim
2960249423Sdim  ExprResult TransformToPotentiallyEvaluated(Expr *E);
2961234353Sdim  ExprResult HandleExprEvaluationContextForTypeof(Expr *E);
2962234353Sdim
2963234353Sdim  ExprResult ActOnConstantExpression(ExprResult Res);
2964234353Sdim
2965234353Sdim  // Functions for marking a declaration referenced.  These functions also
2966234353Sdim  // contain the relevant logic for marking if a reference to a function or
2967234353Sdim  // variable is an odr-use (in the C++11 sense).  There are separate variants
2968234353Sdim  // for expressions referring to a decl; these exist because odr-use marking
2969234353Sdim  // needs to be delayed for some constant variables when we build one of the
2970234353Sdim  // named expressions.
2971249423Sdim  void MarkAnyDeclReferenced(SourceLocation Loc, Decl *D, bool OdrUse);
2972234353Sdim  void MarkFunctionReferenced(SourceLocation Loc, FunctionDecl *Func);
2973234353Sdim  void MarkVariableReferenced(SourceLocation Loc, VarDecl *Var);
2974234353Sdim  void MarkDeclRefReferenced(DeclRefExpr *E);
2975234353Sdim  void MarkMemberReferenced(MemberExpr *E);
2976234353Sdim
2977234353Sdim  void UpdateMarkingForLValueToRValue(Expr *E);
2978234353Sdim  void CleanupVarDeclMarking();
2979234353Sdim
2980234353Sdim  enum TryCaptureKind {
2981234353Sdim    TryCapture_Implicit, TryCapture_ExplicitByVal, TryCapture_ExplicitByRef
2982234353Sdim  };
2983234353Sdim
2984234353Sdim  /// \brief Try to capture the given variable.
2985234353Sdim  ///
2986234353Sdim  /// \param Var The variable to capture.
2987234353Sdim  ///
2988234353Sdim  /// \param Loc The location at which the capture occurs.
2989234353Sdim  ///
2990239462Sdim  /// \param Kind The kind of capture, which may be implicit (for either a
2991234353Sdim  /// block or a lambda), or explicit by-value or by-reference (for a lambda).
2992234353Sdim  ///
2993234353Sdim  /// \param EllipsisLoc The location of the ellipsis, if one is provided in
2994234353Sdim  /// an explicit lambda capture.
2995234353Sdim  ///
2996239462Sdim  /// \param BuildAndDiagnose Whether we are actually supposed to add the
2997234353Sdim  /// captures or diagnose errors. If false, this routine merely check whether
2998234353Sdim  /// the capture can occur without performing the capture itself or complaining
2999234353Sdim  /// if the variable cannot be captured.
3000234353Sdim  ///
3001234353Sdim  /// \param CaptureType Will be set to the type of the field used to capture
3002234353Sdim  /// this variable in the innermost block or lambda. Only valid when the
3003234353Sdim  /// variable can be captured.
3004234353Sdim  ///
3005239462Sdim  /// \param DeclRefType Will be set to the type of a reference to the capture
3006239462Sdim  /// from within the current scope. Only valid when the variable can be
3007234353Sdim  /// captured.
3008234353Sdim  ///
3009234353Sdim  /// \returns true if an error occurred (i.e., the variable cannot be
3010234353Sdim  /// captured) and false if the capture succeeded.
3011234353Sdim  bool tryCaptureVariable(VarDecl *Var, SourceLocation Loc, TryCaptureKind Kind,
3012239462Sdim                          SourceLocation EllipsisLoc, bool BuildAndDiagnose,
3013234353Sdim                          QualType &CaptureType,
3014234353Sdim                          QualType &DeclRefType);
3015234353Sdim
3016234353Sdim  /// \brief Try to capture the given variable.
3017234353Sdim  bool tryCaptureVariable(VarDecl *Var, SourceLocation Loc,
3018234353Sdim                          TryCaptureKind Kind = TryCapture_Implicit,
3019234353Sdim                          SourceLocation EllipsisLoc = SourceLocation());
3020239462Sdim
3021234353Sdim  /// \brief Given a variable, determine the type that a reference to that
3022234353Sdim  /// variable will have in the given scope.
3023234353Sdim  QualType getCapturedDeclRefType(VarDecl *Var, SourceLocation Loc);
3024239462Sdim
3025212795Sdim  void MarkDeclarationsReferencedInType(SourceLocation Loc, QualType T);
3026239462Sdim  void MarkDeclarationsReferencedInExpr(Expr *E,
3027234353Sdim                                        bool SkipLocalVariables = false);
3028223017Sdim
3029226633Sdim  /// \brief Try to recover by turning the given expression into a
3030226633Sdim  /// call.  Returns true if recovery was attempted or an error was
3031226633Sdim  /// emitted; this may also leave the ExprResult invalid.
3032226633Sdim  bool tryToRecoverWithCall(ExprResult &E, const PartialDiagnostic &PD,
3033226633Sdim                            bool ForceComplain = false,
3034226633Sdim                            bool (*IsPlausibleResult)(QualType) = 0);
3035226633Sdim
3036223017Sdim  /// \brief Figure out if an expression could be turned into a call.
3037223017Sdim  bool isExprCallable(const Expr &E, QualType &ZeroArgCallReturnTy,
3038223017Sdim                      UnresolvedSetImpl &NonTemplateOverloads);
3039223017Sdim
3040219077Sdim  /// \brief Conditionally issue a diagnostic based on the current
3041219077Sdim  /// evaluation context.
3042219077Sdim  ///
3043239462Sdim  /// \param Statement If Statement is non-null, delay reporting the
3044239462Sdim  /// diagnostic until the function body is parsed, and then do a basic
3045239462Sdim  /// reachability analysis to determine if the statement is reachable.
3046239462Sdim  /// If it is unreachable, the diagnostic will not be emitted.
3047226633Sdim  bool DiagRuntimeBehavior(SourceLocation Loc, const Stmt *Statement,
3048219077Sdim                           const PartialDiagnostic &PD);
3049212795Sdim
3050212795Sdim  // Primary Expressions.
3051212795Sdim  SourceRange getExprRange(Expr *E) const;
3052212795Sdim
3053234353Sdim  ExprResult ActOnIdExpression(Scope *S, CXXScopeSpec &SS,
3054234353Sdim                               SourceLocation TemplateKWLoc,
3055234353Sdim                               UnqualifiedId &Id,
3056234353Sdim                               bool HasTrailingLParen, bool IsAddressOfOperand,
3057234353Sdim                               CorrectionCandidateCallback *CCC = 0);
3058234353Sdim
3059224145Sdim  void DecomposeUnqualifiedId(const UnqualifiedId &Id,
3060224145Sdim                              TemplateArgumentListInfo &Buffer,
3061224145Sdim                              DeclarationNameInfo &NameInfo,
3062224145Sdim                              const TemplateArgumentListInfo *&TemplateArgs);
3063224145Sdim
3064212795Sdim  bool DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R,
3065234353Sdim                           CorrectionCandidateCallback &CCC,
3066226633Sdim                           TemplateArgumentListInfo *ExplicitTemplateArgs = 0,
3067251662Sdim                           ArrayRef<Expr *> Args = None);
3068212795Sdim
3069226633Sdim  ExprResult LookupInObjCMethod(LookupResult &LookUp, Scope *S,
3070226633Sdim                                IdentifierInfo *II,
3071212795Sdim                                bool AllowBuiltinCreation=false);
3072212795Sdim
3073212795Sdim  ExprResult ActOnDependentIdExpression(const CXXScopeSpec &SS,
3074234353Sdim                                        SourceLocation TemplateKWLoc,
3075212795Sdim                                        const DeclarationNameInfo &NameInfo,
3076212795Sdim                                        bool isAddressOfOperand,
3077212795Sdim                                const TemplateArgumentListInfo *TemplateArgs);
3078212795Sdim
3079212795Sdim  ExprResult BuildDeclRefExpr(ValueDecl *D, QualType Ty,
3080218893Sdim                              ExprValueKind VK,
3081212795Sdim                              SourceLocation Loc,
3082212795Sdim                              const CXXScopeSpec *SS = 0);
3083212795Sdim  ExprResult BuildDeclRefExpr(ValueDecl *D, QualType Ty,
3084218893Sdim                              ExprValueKind VK,
3085212795Sdim                              const DeclarationNameInfo &NameInfo,
3086249423Sdim                              const CXXScopeSpec *SS = 0,
3087249423Sdim                              NamedDecl *FoundD = 0);
3088212795Sdim  ExprResult
3089218893Sdim  BuildAnonymousStructUnionMemberReference(const CXXScopeSpec &SS,
3090218893Sdim                                           SourceLocation nameLoc,
3091218893Sdim                                           IndirectFieldDecl *indirectField,
3092218893Sdim                                           Expr *baseObjectExpr = 0,
3093218893Sdim                                      SourceLocation opLoc = SourceLocation());
3094212795Sdim  ExprResult BuildPossibleImplicitMemberExpr(const CXXScopeSpec &SS,
3095234353Sdim                                             SourceLocation TemplateKWLoc,
3096212795Sdim                                             LookupResult &R,
3097212795Sdim                                const TemplateArgumentListInfo *TemplateArgs);
3098212795Sdim  ExprResult BuildImplicitMemberExpr(const CXXScopeSpec &SS,
3099234353Sdim                                     SourceLocation TemplateKWLoc,
3100212795Sdim                                     LookupResult &R,
3101212795Sdim                                const TemplateArgumentListInfo *TemplateArgs,
3102212795Sdim                                     bool IsDefiniteInstance);
3103212795Sdim  bool UseArgumentDependentLookup(const CXXScopeSpec &SS,
3104212795Sdim                                  const LookupResult &R,
3105212795Sdim                                  bool HasTrailingLParen);
3106212795Sdim
3107212795Sdim  ExprResult BuildQualifiedDeclarationNameExpr(CXXScopeSpec &SS,
3108243830Sdim                                         const DeclarationNameInfo &NameInfo,
3109243830Sdim                                               bool IsAddressOfOperand);
3110212795Sdim  ExprResult BuildDependentDeclRefExpr(const CXXScopeSpec &SS,
3111234353Sdim                                       SourceLocation TemplateKWLoc,
3112212795Sdim                                const DeclarationNameInfo &NameInfo,
3113212795Sdim                                const TemplateArgumentListInfo *TemplateArgs);
3114212795Sdim
3115212795Sdim  ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS,
3116212795Sdim                                      LookupResult &R,
3117226633Sdim                                      bool NeedsADL);
3118212795Sdim  ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS,
3119212795Sdim                                      const DeclarationNameInfo &NameInfo,
3120249423Sdim                                      NamedDecl *D, NamedDecl *FoundD = 0);
3121212795Sdim
3122234353Sdim  ExprResult BuildLiteralOperatorCall(LookupResult &R,
3123234353Sdim                                      DeclarationNameInfo &SuffixInfo,
3124234353Sdim                                      ArrayRef<Expr*> Args,
3125234353Sdim                                      SourceLocation LitEndLoc,
3126234353Sdim                            TemplateArgumentListInfo *ExplicitTemplateArgs = 0);
3127234353Sdim
3128212795Sdim  ExprResult ActOnPredefinedExpr(SourceLocation Loc, tok::TokenKind Kind);
3129234353Sdim  ExprResult ActOnIntegerConstant(SourceLocation Loc, uint64_t Val);
3130234353Sdim  ExprResult ActOnNumericConstant(const Token &Tok, Scope *UDLScope = 0);
3131234353Sdim  ExprResult ActOnCharacterConstant(const Token &Tok, Scope *UDLScope = 0);
3132226633Sdim  ExprResult ActOnParenExpr(SourceLocation L, SourceLocation R, Expr *E);
3133234353Sdim  ExprResult ActOnParenListExpr(SourceLocation L,
3134234353Sdim                                SourceLocation R,
3135234353Sdim                                MultiExprArg Val);
3136212795Sdim
3137212795Sdim  /// ActOnStringLiteral - The specified tokens were lexed as pasted string
3138212795Sdim  /// fragments (e.g. "foo" "bar" L"baz").
3139234353Sdim  ExprResult ActOnStringLiteral(const Token *StringToks, unsigned NumStringToks,
3140234353Sdim                                Scope *UDLScope = 0);
3141212795Sdim
3142221345Sdim  ExprResult ActOnGenericSelectionExpr(SourceLocation KeyLoc,
3143221345Sdim                                       SourceLocation DefaultLoc,
3144221345Sdim                                       SourceLocation RParenLoc,
3145221345Sdim                                       Expr *ControllingExpr,
3146226633Sdim                                       MultiTypeArg ArgTypes,
3147226633Sdim                                       MultiExprArg ArgExprs);
3148221345Sdim  ExprResult CreateGenericSelectionExpr(SourceLocation KeyLoc,
3149221345Sdim                                        SourceLocation DefaultLoc,
3150221345Sdim                                        SourceLocation RParenLoc,
3151221345Sdim                                        Expr *ControllingExpr,
3152221345Sdim                                        TypeSourceInfo **Types,
3153221345Sdim                                        Expr **Exprs,
3154221345Sdim                                        unsigned NumAssocs);
3155221345Sdim
3156212795Sdim  // Binary/Unary Operators.  'Tok' is the token for the operator.
3157218893Sdim  ExprResult CreateBuiltinUnaryOp(SourceLocation OpLoc, UnaryOperatorKind Opc,
3158226633Sdim                                  Expr *InputExpr);
3159212795Sdim  ExprResult BuildUnaryOp(Scope *S, SourceLocation OpLoc,
3160226633Sdim                          UnaryOperatorKind Opc, Expr *Input);
3161212795Sdim  ExprResult ActOnUnaryOp(Scope *S, SourceLocation OpLoc,
3162212795Sdim                          tok::TokenKind Op, Expr *Input);
3163212795Sdim
3164226633Sdim  ExprResult CreateUnaryExprOrTypeTraitExpr(TypeSourceInfo *TInfo,
3165221345Sdim                                            SourceLocation OpLoc,
3166221345Sdim                                            UnaryExprOrTypeTrait ExprKind,
3167221345Sdim                                            SourceRange R);
3168221345Sdim  ExprResult CreateUnaryExprOrTypeTraitExpr(Expr *E, SourceLocation OpLoc,
3169223017Sdim                                            UnaryExprOrTypeTrait ExprKind);
3170212795Sdim  ExprResult
3171221345Sdim    ActOnUnaryExprOrTypeTraitExpr(SourceLocation OpLoc,
3172221345Sdim                                  UnaryExprOrTypeTrait ExprKind,
3173226633Sdim                                  bool IsType, void *TyOrEx,
3174221345Sdim                                  const SourceRange &ArgRange);
3175212795Sdim
3176221345Sdim  ExprResult CheckPlaceholderExpr(Expr *E);
3177223017Sdim  bool CheckVecStepExpr(Expr *E);
3178218893Sdim
3179223017Sdim  bool CheckUnaryExprOrTypeTraitOperand(Expr *E, UnaryExprOrTypeTrait ExprKind);
3180226633Sdim  bool CheckUnaryExprOrTypeTraitOperand(QualType ExprType, SourceLocation OpLoc,
3181226633Sdim                                        SourceRange ExprRange,
3182221345Sdim                                        UnaryExprOrTypeTrait ExprKind);
3183218893Sdim  ExprResult ActOnSizeofParameterPackExpr(Scope *S,
3184218893Sdim                                          SourceLocation OpLoc,
3185218893Sdim                                          IdentifierInfo &Name,
3186218893Sdim                                          SourceLocation NameLoc,
3187218893Sdim                                          SourceLocation RParenLoc);
3188212795Sdim  ExprResult ActOnPostfixUnaryOp(Scope *S, SourceLocation OpLoc,
3189212795Sdim                                 tok::TokenKind Kind, Expr *Input);
3190212795Sdim
3191212795Sdim  ExprResult ActOnArraySubscriptExpr(Scope *S, Expr *Base, SourceLocation LLoc,
3192212795Sdim                                     Expr *Idx, SourceLocation RLoc);
3193212795Sdim  ExprResult CreateBuiltinArraySubscriptExpr(Expr *Base, SourceLocation LLoc,
3194212795Sdim                                             Expr *Idx, SourceLocation RLoc);
3195212795Sdim
3196212795Sdim  ExprResult BuildMemberReferenceExpr(Expr *Base, QualType BaseType,
3197212795Sdim                                      SourceLocation OpLoc, bool IsArrow,
3198212795Sdim                                      CXXScopeSpec &SS,
3199234353Sdim                                      SourceLocation TemplateKWLoc,
3200212795Sdim                                      NamedDecl *FirstQualifierInScope,
3201212795Sdim                                const DeclarationNameInfo &NameInfo,
3202212795Sdim                                const TemplateArgumentListInfo *TemplateArgs);
3203212795Sdim
3204239462Sdim  // This struct is for use by ActOnMemberAccess to allow
3205239462Sdim  // BuildMemberReferenceExpr to be able to reinvoke ActOnMemberAccess after
3206239462Sdim  // changing the access operator from a '.' to a '->' (to see if that is the
3207239462Sdim  // change needed to fix an error about an unknown member, e.g. when the class
3208239462Sdim  // defines a custom operator->).
3209239462Sdim  struct ActOnMemberAccessExtraArgs {
3210239462Sdim    Scope *S;
3211239462Sdim    UnqualifiedId &Id;
3212239462Sdim    Decl *ObjCImpDecl;
3213239462Sdim    bool HasTrailingLParen;
3214239462Sdim  };
3215239462Sdim
3216212795Sdim  ExprResult BuildMemberReferenceExpr(Expr *Base, QualType BaseType,
3217212795Sdim                                      SourceLocation OpLoc, bool IsArrow,
3218212795Sdim                                      const CXXScopeSpec &SS,
3219234353Sdim                                      SourceLocation TemplateKWLoc,
3220212795Sdim                                      NamedDecl *FirstQualifierInScope,
3221212795Sdim                                      LookupResult &R,
3222212795Sdim                                 const TemplateArgumentListInfo *TemplateArgs,
3223239462Sdim                                      bool SuppressQualifierCheck = false,
3224239462Sdim                                     ActOnMemberAccessExtraArgs *ExtraArgs = 0);
3225212795Sdim
3226234353Sdim  ExprResult PerformMemberExprBaseConversion(Expr *Base, bool IsArrow);
3227221345Sdim  ExprResult LookupMemberExpr(LookupResult &R, ExprResult &Base,
3228212795Sdim                              bool &IsArrow, SourceLocation OpLoc,
3229212795Sdim                              CXXScopeSpec &SS,
3230212795Sdim                              Decl *ObjCImpDecl,
3231212795Sdim                              bool HasTemplateArgs);
3232212795Sdim
3233212795Sdim  bool CheckQualifiedMemberReference(Expr *BaseExpr, QualType BaseType,
3234212795Sdim                                     const CXXScopeSpec &SS,
3235212795Sdim                                     const LookupResult &R);
3236212795Sdim
3237212795Sdim  ExprResult ActOnDependentMemberExpr(Expr *Base, QualType BaseType,
3238212795Sdim                                      bool IsArrow, SourceLocation OpLoc,
3239212795Sdim                                      const CXXScopeSpec &SS,
3240234353Sdim                                      SourceLocation TemplateKWLoc,
3241212795Sdim                                      NamedDecl *FirstQualifierInScope,
3242212795Sdim                               const DeclarationNameInfo &NameInfo,
3243212795Sdim                               const TemplateArgumentListInfo *TemplateArgs);
3244212795Sdim
3245212795Sdim  ExprResult ActOnMemberAccessExpr(Scope *S, Expr *Base,
3246212795Sdim                                   SourceLocation OpLoc,
3247212795Sdim                                   tok::TokenKind OpKind,
3248212795Sdim                                   CXXScopeSpec &SS,
3249234353Sdim                                   SourceLocation TemplateKWLoc,
3250212795Sdim                                   UnqualifiedId &Member,
3251212795Sdim                                   Decl *ObjCImpDecl,
3252212795Sdim                                   bool HasTrailingLParen);
3253212795Sdim
3254212795Sdim  void ActOnDefaultCtorInitializers(Decl *CDtorDecl);
3255212795Sdim  bool ConvertArgumentsForCall(CallExpr *Call, Expr *Fn,
3256212795Sdim                               FunctionDecl *FDecl,
3257212795Sdim                               const FunctionProtoType *Proto,
3258212795Sdim                               Expr **Args, unsigned NumArgs,
3259226633Sdim                               SourceLocation RParenLoc,
3260226633Sdim                               bool ExecConfig = false);
3261234353Sdim  void CheckStaticArrayArgument(SourceLocation CallLoc,
3262234353Sdim                                ParmVarDecl *Param,
3263234353Sdim                                const Expr *ArgExpr);
3264212795Sdim
3265212795Sdim  /// ActOnCallExpr - Handle a call to Fn with the specified array of arguments.
3266212795Sdim  /// This provides the location of the left/right parens and a list of comma
3267212795Sdim  /// locations.
3268212795Sdim  ExprResult ActOnCallExpr(Scope *S, Expr *Fn, SourceLocation LParenLoc,
3269226633Sdim                           MultiExprArg ArgExprs, SourceLocation RParenLoc,
3270226633Sdim                           Expr *ExecConfig = 0, bool IsExecConfig = false);
3271212795Sdim  ExprResult BuildResolvedCallExpr(Expr *Fn, NamedDecl *NDecl,
3272212795Sdim                                   SourceLocation LParenLoc,
3273212795Sdim                                   Expr **Args, unsigned NumArgs,
3274218893Sdim                                   SourceLocation RParenLoc,
3275226633Sdim                                   Expr *Config = 0,
3276226633Sdim                                   bool IsExecConfig = false);
3277212795Sdim
3278218893Sdim  ExprResult ActOnCUDAExecConfigExpr(Scope *S, SourceLocation LLLLoc,
3279226633Sdim                                     MultiExprArg ExecConfig,
3280226633Sdim                                     SourceLocation GGGLoc);
3281218893Sdim
3282212795Sdim  ExprResult ActOnCastExpr(Scope *S, SourceLocation LParenLoc,
3283224145Sdim                           Declarator &D, ParsedType &Ty,
3284226633Sdim                           SourceLocation RParenLoc, Expr *CastExpr);
3285212795Sdim  ExprResult BuildCStyleCastExpr(SourceLocation LParenLoc,
3286212795Sdim                                 TypeSourceInfo *Ty,
3287212795Sdim                                 SourceLocation RParenLoc,
3288212795Sdim                                 Expr *Op);
3289226633Sdim  CastKind PrepareScalarCast(ExprResult &src, QualType destType);
3290212795Sdim
3291224145Sdim  /// \brief Build an altivec or OpenCL literal.
3292224145Sdim  ExprResult BuildVectorLiteral(SourceLocation LParenLoc,
3293224145Sdim                                SourceLocation RParenLoc, Expr *E,
3294224145Sdim                                TypeSourceInfo *TInfo);
3295212795Sdim
3296212795Sdim  ExprResult MaybeConvertParenListExprToParenExpr(Scope *S, Expr *ME);
3297212795Sdim
3298212795Sdim  ExprResult ActOnCompoundLiteral(SourceLocation LParenLoc,
3299212795Sdim                                  ParsedType Ty,
3300212795Sdim                                  SourceLocation RParenLoc,
3301226633Sdim                                  Expr *InitExpr);
3302212795Sdim
3303212795Sdim  ExprResult BuildCompoundLiteralExpr(SourceLocation LParenLoc,
3304212795Sdim                                      TypeSourceInfo *TInfo,
3305212795Sdim                                      SourceLocation RParenLoc,
3306226633Sdim                                      Expr *LiteralExpr);
3307212795Sdim
3308226633Sdim  ExprResult ActOnInitList(SourceLocation LBraceLoc,
3309226633Sdim                           MultiExprArg InitArgList,
3310226633Sdim                           SourceLocation RBraceLoc);
3311212795Sdim
3312212795Sdim  ExprResult ActOnDesignatedInitializer(Designation &Desig,
3313212795Sdim                                        SourceLocation Loc,
3314212795Sdim                                        bool GNUSyntax,
3315212795Sdim                                        ExprResult Init);
3316212795Sdim
3317212795Sdim  ExprResult ActOnBinOp(Scope *S, SourceLocation TokLoc,
3318226633Sdim                        tok::TokenKind Kind, Expr *LHSExpr, Expr *RHSExpr);
3319212795Sdim  ExprResult BuildBinOp(Scope *S, SourceLocation OpLoc,
3320226633Sdim                        BinaryOperatorKind Opc, Expr *LHSExpr, Expr *RHSExpr);
3321226633Sdim  ExprResult CreateBuiltinBinOp(SourceLocation OpLoc, BinaryOperatorKind Opc,
3322226633Sdim                                Expr *LHSExpr, Expr *RHSExpr);
3323212795Sdim
3324212795Sdim  /// ActOnConditionalOp - Parse a ?: operation.  Note that 'LHS' may be null
3325212795Sdim  /// in the case of a the GNU conditional expr extension.
3326212795Sdim  ExprResult ActOnConditionalOp(SourceLocation QuestionLoc,
3327212795Sdim                                SourceLocation ColonLoc,
3328226633Sdim                                Expr *CondExpr, Expr *LHSExpr, Expr *RHSExpr);
3329212795Sdim
3330212795Sdim  /// ActOnAddrLabel - Parse the GNU address of label extension: "&&foo".
3331218893Sdim  ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc,
3332226633Sdim                            LabelDecl *TheDecl);
3333234353Sdim
3334234353Sdim  void ActOnStartStmtExpr();
3335212795Sdim  ExprResult ActOnStmtExpr(SourceLocation LPLoc, Stmt *SubStmt,
3336212795Sdim                           SourceLocation RPLoc); // "({..})"
3337234353Sdim  void ActOnStmtExprError();
3338212795Sdim
3339212795Sdim  // __builtin_offsetof(type, identifier(.identifier|[expr])*)
3340212795Sdim  struct OffsetOfComponent {
3341212795Sdim    SourceLocation LocStart, LocEnd;
3342212795Sdim    bool isBrackets;  // true if [expr], false if .ident
3343212795Sdim    union {
3344212795Sdim      IdentifierInfo *IdentInfo;
3345226633Sdim      Expr *E;
3346212795Sdim    } U;
3347212795Sdim  };
3348212795Sdim
3349212795Sdim  /// __builtin_offsetof(type, a.b[123][456].c)
3350212795Sdim  ExprResult BuildBuiltinOffsetOf(SourceLocation BuiltinLoc,
3351212795Sdim                                  TypeSourceInfo *TInfo,
3352212795Sdim                                  OffsetOfComponent *CompPtr,
3353212795Sdim                                  unsigned NumComponents,
3354212795Sdim                                  SourceLocation RParenLoc);
3355212795Sdim  ExprResult ActOnBuiltinOffsetOf(Scope *S,
3356212795Sdim                                  SourceLocation BuiltinLoc,
3357212795Sdim                                  SourceLocation TypeLoc,
3358226633Sdim                                  ParsedType ParsedArgTy,
3359212795Sdim                                  OffsetOfComponent *CompPtr,
3360212795Sdim                                  unsigned NumComponents,
3361212795Sdim                                  SourceLocation RParenLoc);
3362212795Sdim
3363212795Sdim  // __builtin_choose_expr(constExpr, expr1, expr2)
3364212795Sdim  ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc,
3365226633Sdim                             Expr *CondExpr, Expr *LHSExpr,
3366226633Sdim                             Expr *RHSExpr, SourceLocation RPLoc);
3367212795Sdim
3368212795Sdim  // __builtin_va_arg(expr, type)
3369226633Sdim  ExprResult ActOnVAArg(SourceLocation BuiltinLoc, Expr *E, ParsedType Ty,
3370212795Sdim                        SourceLocation RPLoc);
3371226633Sdim  ExprResult BuildVAArgExpr(SourceLocation BuiltinLoc, Expr *E,
3372226633Sdim                            TypeSourceInfo *TInfo, SourceLocation RPLoc);
3373212795Sdim
3374212795Sdim  // __null
3375212795Sdim  ExprResult ActOnGNUNullExpr(SourceLocation TokenLoc);
3376212795Sdim
3377226633Sdim  bool CheckCaseExpression(Expr *E);
3378221345Sdim
3379234353Sdim  /// \brief Describes the result of an "if-exists" condition check.
3380234353Sdim  enum IfExistsResult {
3381234353Sdim    /// \brief The symbol exists.
3382234353Sdim    IER_Exists,
3383223017Sdim
3384234353Sdim    /// \brief The symbol does not exist.
3385234353Sdim    IER_DoesNotExist,
3386234353Sdim
3387234353Sdim    /// \brief The name is a dependent name, so the results will differ
3388234353Sdim    /// from one instantiation to the next.
3389234353Sdim    IER_Dependent,
3390234353Sdim
3391234353Sdim    /// \brief An error occurred.
3392234353Sdim    IER_Error
3393234353Sdim  };
3394234353Sdim
3395234353Sdim  IfExistsResult
3396234353Sdim  CheckMicrosoftIfExistsSymbol(Scope *S, CXXScopeSpec &SS,
3397234353Sdim                               const DeclarationNameInfo &TargetNameInfo);
3398234353Sdim
3399234353Sdim  IfExistsResult
3400234353Sdim  CheckMicrosoftIfExistsSymbol(Scope *S, SourceLocation KeywordLoc,
3401234353Sdim                               bool IsIfExists, CXXScopeSpec &SS,
3402234353Sdim                               UnqualifiedId &Name);
3403234353Sdim
3404234353Sdim  StmtResult BuildMSDependentExistsStmt(SourceLocation KeywordLoc,
3405234353Sdim                                        bool IsIfExists,
3406234353Sdim                                        NestedNameSpecifierLoc QualifierLoc,
3407234353Sdim                                        DeclarationNameInfo NameInfo,
3408234353Sdim                                        Stmt *Nested);
3409234353Sdim  StmtResult ActOnMSDependentExistsStmt(SourceLocation KeywordLoc,
3410234353Sdim                                        bool IsIfExists,
3411234353Sdim                                        CXXScopeSpec &SS, UnqualifiedId &Name,
3412234353Sdim                                        Stmt *Nested);
3413234353Sdim
3414212795Sdim  //===------------------------- "Block" Extension ------------------------===//
3415212795Sdim
3416212795Sdim  /// ActOnBlockStart - This callback is invoked when a block literal is
3417212795Sdim  /// started.
3418212795Sdim  void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope);
3419212795Sdim
3420212795Sdim  /// ActOnBlockArguments - This callback allows processing of block arguments.
3421212795Sdim  /// If there are no arguments, this is still invoked.
3422239462Sdim  void ActOnBlockArguments(SourceLocation CaretLoc, Declarator &ParamInfo,
3423239462Sdim                           Scope *CurScope);
3424212795Sdim
3425212795Sdim  /// ActOnBlockError - If there is an error parsing a block, this callback
3426212795Sdim  /// is invoked to pop the information about the block from the action impl.
3427212795Sdim  void ActOnBlockError(SourceLocation CaretLoc, Scope *CurScope);
3428212795Sdim
3429212795Sdim  /// ActOnBlockStmtExpr - This is called when the body of a block statement
3430212795Sdim  /// literal was successfully completed.  ^(int x){...}
3431226633Sdim  ExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc, Stmt *Body,
3432226633Sdim                                Scope *CurScope);
3433212795Sdim
3434223017Sdim  //===---------------------------- OpenCL Features -----------------------===//
3435234353Sdim
3436223017Sdim  /// __builtin_astype(...)
3437226633Sdim  ExprResult ActOnAsTypeExpr(Expr *E, ParsedType ParsedDestTy,
3438234353Sdim                             SourceLocation BuiltinLoc,
3439223017Sdim                             SourceLocation RParenLoc);
3440234353Sdim
3441212795Sdim  //===---------------------------- C++ Features --------------------------===//
3442212795Sdim
3443212795Sdim  // Act on C++ namespaces
3444212795Sdim  Decl *ActOnStartNamespaceDef(Scope *S, SourceLocation InlineLoc,
3445221345Sdim                               SourceLocation NamespaceLoc,
3446212795Sdim                               SourceLocation IdentLoc,
3447212795Sdim                               IdentifierInfo *Ident,
3448212795Sdim                               SourceLocation LBrace,
3449212795Sdim                               AttributeList *AttrList);
3450212795Sdim  void ActOnFinishNamespaceDef(Decl *Dcl, SourceLocation RBrace);
3451212795Sdim
3452212795Sdim  NamespaceDecl *getStdNamespace() const;
3453212795Sdim  NamespaceDecl *getOrCreateStdNamespace();
3454212795Sdim
3455212795Sdim  CXXRecordDecl *getStdBadAlloc() const;
3456212795Sdim
3457234353Sdim  /// \brief Tests whether Ty is an instance of std::initializer_list and, if
3458234353Sdim  /// it is and Element is not NULL, assigns the element type to Element.
3459234353Sdim  bool isStdInitializerList(QualType Ty, QualType *Element);
3460234353Sdim
3461234353Sdim  /// \brief Looks for the std::initializer_list template and instantiates it
3462234353Sdim  /// with Element, or emits an error if it's not found.
3463234353Sdim  ///
3464234353Sdim  /// \returns The instantiated template, or null on error.
3465234353Sdim  QualType BuildStdInitializerList(QualType Element, SourceLocation Loc);
3466234353Sdim
3467234353Sdim  /// \brief Determine whether Ctor is an initializer-list constructor, as
3468234353Sdim  /// defined in [dcl.init.list]p2.
3469234353Sdim  bool isInitListConstructor(const CXXConstructorDecl *Ctor);
3470234353Sdim
3471212795Sdim  Decl *ActOnUsingDirective(Scope *CurScope,
3472212795Sdim                            SourceLocation UsingLoc,
3473212795Sdim                            SourceLocation NamespcLoc,
3474212795Sdim                            CXXScopeSpec &SS,
3475212795Sdim                            SourceLocation IdentLoc,
3476212795Sdim                            IdentifierInfo *NamespcName,
3477212795Sdim                            AttributeList *AttrList);
3478212795Sdim
3479212795Sdim  void PushUsingDirective(Scope *S, UsingDirectiveDecl *UDir);
3480212795Sdim
3481212795Sdim  Decl *ActOnNamespaceAliasDef(Scope *CurScope,
3482212795Sdim                               SourceLocation NamespaceLoc,
3483212795Sdim                               SourceLocation AliasLoc,
3484212795Sdim                               IdentifierInfo *Alias,
3485212795Sdim                               CXXScopeSpec &SS,
3486212795Sdim                               SourceLocation IdentLoc,
3487212795Sdim                               IdentifierInfo *Ident);
3488212795Sdim
3489212795Sdim  void HideUsingShadowDecl(Scope *S, UsingShadowDecl *Shadow);
3490212795Sdim  bool CheckUsingShadowDecl(UsingDecl *UD, NamedDecl *Target,
3491212795Sdim                            const LookupResult &PreviousDecls);
3492212795Sdim  UsingShadowDecl *BuildUsingShadowDecl(Scope *S, UsingDecl *UD,
3493212795Sdim                                        NamedDecl *Target);
3494212795Sdim
3495212795Sdim  bool CheckUsingDeclRedeclaration(SourceLocation UsingLoc,
3496212795Sdim                                   bool isTypeName,
3497212795Sdim                                   const CXXScopeSpec &SS,
3498212795Sdim                                   SourceLocation NameLoc,
3499212795Sdim                                   const LookupResult &Previous);
3500212795Sdim  bool CheckUsingDeclQualifier(SourceLocation UsingLoc,
3501212795Sdim                               const CXXScopeSpec &SS,
3502212795Sdim                               SourceLocation NameLoc);
3503212795Sdim
3504212795Sdim  NamedDecl *BuildUsingDeclaration(Scope *S, AccessSpecifier AS,
3505212795Sdim                                   SourceLocation UsingLoc,
3506212795Sdim                                   CXXScopeSpec &SS,
3507212795Sdim                                   const DeclarationNameInfo &NameInfo,
3508212795Sdim                                   AttributeList *AttrList,
3509212795Sdim                                   bool IsInstantiation,
3510212795Sdim                                   bool IsTypeName,
3511212795Sdim                                   SourceLocation TypenameLoc);
3512212795Sdim
3513234353Sdim  bool CheckInheritingConstructorUsingDecl(UsingDecl *UD);
3514218893Sdim
3515212795Sdim  Decl *ActOnUsingDeclaration(Scope *CurScope,
3516212795Sdim                              AccessSpecifier AS,
3517212795Sdim                              bool HasUsingKeyword,
3518212795Sdim                              SourceLocation UsingLoc,
3519212795Sdim                              CXXScopeSpec &SS,
3520212795Sdim                              UnqualifiedId &Name,
3521212795Sdim                              AttributeList *AttrList,
3522212795Sdim                              bool IsTypeName,
3523212795Sdim                              SourceLocation TypenameLoc);
3524221345Sdim  Decl *ActOnAliasDeclaration(Scope *CurScope,
3525221345Sdim                              AccessSpecifier AS,
3526223017Sdim                              MultiTemplateParamsArg TemplateParams,
3527221345Sdim                              SourceLocation UsingLoc,
3528221345Sdim                              UnqualifiedId &Name,
3529249423Sdim                              AttributeList *AttrList,
3530221345Sdim                              TypeResult Type);
3531212795Sdim
3532212795Sdim  /// BuildCXXConstructExpr - Creates a complete call to a constructor,
3533212795Sdim  /// including handling of its default argument expressions.
3534212795Sdim  ///
3535212795Sdim  /// \param ConstructKind - a CXXConstructExpr::ConstructionKind
3536212795Sdim  ExprResult
3537212795Sdim  BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType,
3538212795Sdim                        CXXConstructorDecl *Constructor, MultiExprArg Exprs,
3539249423Sdim                        bool HadMultipleCandidates, bool IsListInitialization,
3540249423Sdim                        bool RequiresZeroInit, unsigned ConstructKind,
3541249423Sdim                        SourceRange ParenRange);
3542212795Sdim
3543212795Sdim  // FIXME: Can re remove this and have the above BuildCXXConstructExpr check if
3544212795Sdim  // the constructor can be elidable?
3545212795Sdim  ExprResult
3546212795Sdim  BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType,
3547212795Sdim                        CXXConstructorDecl *Constructor, bool Elidable,
3548226633Sdim                        MultiExprArg Exprs, bool HadMultipleCandidates,
3549249423Sdim                        bool IsListInitialization, bool RequiresZeroInit,
3550249423Sdim                        unsigned ConstructKind, SourceRange ParenRange);
3551212795Sdim
3552212795Sdim  /// BuildCXXDefaultArgExpr - Creates a CXXDefaultArgExpr, instantiating
3553212795Sdim  /// the default expr if needed.
3554212795Sdim  ExprResult BuildCXXDefaultArgExpr(SourceLocation CallLoc,
3555212795Sdim                                    FunctionDecl *FD,
3556212795Sdim                                    ParmVarDecl *Param);
3557212795Sdim
3558212795Sdim  /// FinalizeVarWithDestructor - Prepare for calling destructor on the
3559212795Sdim  /// constructed variable.
3560212795Sdim  void FinalizeVarWithDestructor(VarDecl *VD, const RecordType *DeclInitType);
3561212795Sdim
3562234353Sdim  /// \brief Helper class that collects exception specifications for
3563223017Sdim  /// implicitly-declared special member functions.
3564223017Sdim  class ImplicitExceptionSpecification {
3565223017Sdim    // Pointer to allow copying
3566234982Sdim    Sema *Self;
3567223017Sdim    // We order exception specifications thus:
3568243830Sdim    // noexcept is the most restrictive, but is only used in C++11.
3569223017Sdim    // throw() comes next.
3570223017Sdim    // Then a throw(collected exceptions)
3571243830Sdim    // Finally no specification, which is expressed as noexcept(false).
3572223017Sdim    // throw(...) is used instead if any called function uses it.
3573223017Sdim    ExceptionSpecificationType ComputedEST;
3574223017Sdim    llvm::SmallPtrSet<CanQualType, 4> ExceptionsSeen;
3575226633Sdim    SmallVector<QualType, 4> Exceptions;
3576223017Sdim
3577223017Sdim    void ClearExceptions() {
3578223017Sdim      ExceptionsSeen.clear();
3579223017Sdim      Exceptions.clear();
3580223017Sdim    }
3581223017Sdim
3582223017Sdim  public:
3583234982Sdim    explicit ImplicitExceptionSpecification(Sema &Self)
3584234982Sdim      : Self(&Self), ComputedEST(EST_BasicNoexcept) {
3585249423Sdim      if (!Self.getLangOpts().CPlusPlus11)
3586223017Sdim        ComputedEST = EST_DynamicNone;
3587223017Sdim    }
3588223017Sdim
3589223017Sdim    /// \brief Get the computed exception specification type.
3590223017Sdim    ExceptionSpecificationType getExceptionSpecType() const {
3591223017Sdim      assert(ComputedEST != EST_ComputedNoexcept &&
3592223017Sdim             "noexcept(expr) should not be a possible result");
3593223017Sdim      return ComputedEST;
3594223017Sdim    }
3595223017Sdim
3596223017Sdim    /// \brief The number of exceptions in the exception specification.
3597223017Sdim    unsigned size() const { return Exceptions.size(); }
3598223017Sdim
3599223017Sdim    /// \brief The set of exceptions in the exception specification.
3600223017Sdim    const QualType *data() const { return Exceptions.data(); }
3601223017Sdim
3602223017Sdim    /// \brief Integrate another called method into the collected data.
3603251662Sdim    void CalledDecl(SourceLocation CallLoc, const CXXMethodDecl *Method);
3604223017Sdim
3605223017Sdim    /// \brief Integrate an invoked expression into the collected data.
3606223017Sdim    void CalledExpr(Expr *E);
3607223017Sdim
3608239462Sdim    /// \brief Overwrite an EPI's exception specification with this
3609239462Sdim    /// computed exception specification.
3610239462Sdim    void getEPI(FunctionProtoType::ExtProtoInfo &EPI) const {
3611239462Sdim      EPI.ExceptionSpecType = getExceptionSpecType();
3612243830Sdim      if (EPI.ExceptionSpecType == EST_Dynamic) {
3613243830Sdim        EPI.NumExceptions = size();
3614243830Sdim        EPI.Exceptions = data();
3615243830Sdim      } else if (EPI.ExceptionSpecType == EST_None) {
3616243830Sdim        /// C++11 [except.spec]p14:
3617243830Sdim        ///   The exception-specification is noexcept(false) if the set of
3618243830Sdim        ///   potential exceptions of the special member function contains "any"
3619243830Sdim        EPI.ExceptionSpecType = EST_ComputedNoexcept;
3620243830Sdim        EPI.NoexceptExpr = Self->ActOnCXXBoolLiteral(SourceLocation(),
3621243830Sdim                                                     tok::kw_false).take();
3622243830Sdim      }
3623223017Sdim    }
3624223017Sdim    FunctionProtoType::ExtProtoInfo getEPI() const {
3625223017Sdim      FunctionProtoType::ExtProtoInfo EPI;
3626239462Sdim      getEPI(EPI);
3627223017Sdim      return EPI;
3628223017Sdim    }
3629223017Sdim  };
3630223017Sdim
3631223017Sdim  /// \brief Determine what sort of exception specification a defaulted
3632223017Sdim  /// copy constructor of a class will have.
3633223017Sdim  ImplicitExceptionSpecification
3634239462Sdim  ComputeDefaultedDefaultCtorExceptionSpec(SourceLocation Loc,
3635239462Sdim                                           CXXMethodDecl *MD);
3636223017Sdim
3637223017Sdim  /// \brief Determine what sort of exception specification a defaulted
3638223017Sdim  /// default constructor of a class will have, and whether the parameter
3639223017Sdim  /// will be const.
3640239462Sdim  ImplicitExceptionSpecification
3641239462Sdim  ComputeDefaultedCopyCtorExceptionSpec(CXXMethodDecl *MD);
3642223017Sdim
3643223017Sdim  /// \brief Determine what sort of exception specification a defautled
3644223017Sdim  /// copy assignment operator of a class will have, and whether the
3645223017Sdim  /// parameter will be const.
3646239462Sdim  ImplicitExceptionSpecification
3647239462Sdim  ComputeDefaultedCopyAssignmentExceptionSpec(CXXMethodDecl *MD);
3648223017Sdim
3649226633Sdim  /// \brief Determine what sort of exception specification a defaulted move
3650226633Sdim  /// constructor of a class will have.
3651226633Sdim  ImplicitExceptionSpecification
3652239462Sdim  ComputeDefaultedMoveCtorExceptionSpec(CXXMethodDecl *MD);
3653226633Sdim
3654226633Sdim  /// \brief Determine what sort of exception specification a defaulted move
3655226633Sdim  /// assignment operator of a class will have.
3656226633Sdim  ImplicitExceptionSpecification
3657239462Sdim  ComputeDefaultedMoveAssignmentExceptionSpec(CXXMethodDecl *MD);
3658226633Sdim
3659223017Sdim  /// \brief Determine what sort of exception specification a defaulted
3660223017Sdim  /// destructor of a class will have.
3661223017Sdim  ImplicitExceptionSpecification
3662239462Sdim  ComputeDefaultedDtorExceptionSpec(CXXMethodDecl *MD);
3663223017Sdim
3664249423Sdim  /// \brief Determine what sort of exception specification an inheriting
3665249423Sdim  /// constructor of a class will have.
3666249423Sdim  ImplicitExceptionSpecification
3667251662Sdim  ComputeInheritingCtorExceptionSpec(CXXConstructorDecl *CD);
3668249423Sdim
3669239462Sdim  /// \brief Evaluate the implicit exception specification for a defaulted
3670239462Sdim  /// special member function.
3671239462Sdim  void EvaluateImplicitExceptionSpec(SourceLocation Loc, CXXMethodDecl *MD);
3672239462Sdim
3673234982Sdim  /// \brief Check the given exception-specification and update the
3674234982Sdim  /// extended prototype information with the results.
3675234982Sdim  void checkExceptionSpecification(ExceptionSpecificationType EST,
3676234982Sdim                                   ArrayRef<ParsedType> DynamicExceptions,
3677234982Sdim                                   ArrayRef<SourceRange> DynamicExceptionRanges,
3678234982Sdim                                   Expr *NoexceptExpr,
3679249423Sdim                                   SmallVectorImpl<QualType> &Exceptions,
3680234982Sdim                                   FunctionProtoType::ExtProtoInfo &EPI);
3681234982Sdim
3682226633Sdim  /// \brief Determine if a special member function should have a deleted
3683226633Sdim  /// definition when it is defaulted.
3684234353Sdim  bool ShouldDeleteSpecialMember(CXXMethodDecl *MD, CXXSpecialMember CSM,
3685234353Sdim                                 bool Diagnose = false);
3686223017Sdim
3687212795Sdim  /// \brief Declare the implicit default constructor for the given class.
3688212795Sdim  ///
3689234353Sdim  /// \param ClassDecl The class declaration into which the implicit
3690212795Sdim  /// default constructor will be added.
3691212795Sdim  ///
3692212795Sdim  /// \returns The implicitly-declared default constructor.
3693212795Sdim  CXXConstructorDecl *DeclareImplicitDefaultConstructor(
3694212795Sdim                                                     CXXRecordDecl *ClassDecl);
3695234353Sdim
3696212795Sdim  /// DefineImplicitDefaultConstructor - Checks for feasibility of
3697212795Sdim  /// defining this constructor as the default constructor.
3698212795Sdim  void DefineImplicitDefaultConstructor(SourceLocation CurrentLocation,
3699212795Sdim                                        CXXConstructorDecl *Constructor);
3700212795Sdim
3701212795Sdim  /// \brief Declare the implicit destructor for the given class.
3702212795Sdim  ///
3703234353Sdim  /// \param ClassDecl The class declaration into which the implicit
3704212795Sdim  /// destructor will be added.
3705212795Sdim  ///
3706212795Sdim  /// \returns The implicitly-declared destructor.
3707212795Sdim  CXXDestructorDecl *DeclareImplicitDestructor(CXXRecordDecl *ClassDecl);
3708234353Sdim
3709212795Sdim  /// DefineImplicitDestructor - Checks for feasibility of
3710212795Sdim  /// defining this destructor as the default destructor.
3711212795Sdim  void DefineImplicitDestructor(SourceLocation CurrentLocation,
3712212795Sdim                                CXXDestructorDecl *Destructor);
3713212795Sdim
3714223017Sdim  /// \brief Build an exception spec for destructors that don't have one.
3715223017Sdim  ///
3716223017Sdim  /// C++11 says that user-defined destructors with no exception spec get one
3717223017Sdim  /// that looks as if the destructor was implicitly declared.
3718223017Sdim  void AdjustDestructorExceptionSpec(CXXRecordDecl *ClassDecl,
3719239462Sdim                                     CXXDestructorDecl *Destructor);
3720223017Sdim
3721249423Sdim  /// \brief Declare all inheriting constructors for the given class.
3722218893Sdim  ///
3723249423Sdim  /// \param ClassDecl The class declaration into which the inheriting
3724218893Sdim  /// constructors will be added.
3725249423Sdim  void DeclareInheritingConstructors(CXXRecordDecl *ClassDecl);
3726218893Sdim
3727249423Sdim  /// \brief Define the specified inheriting constructor.
3728249423Sdim  void DefineInheritingConstructor(SourceLocation UseLoc,
3729249423Sdim                                   CXXConstructorDecl *Constructor);
3730249423Sdim
3731212795Sdim  /// \brief Declare the implicit copy constructor for the given class.
3732212795Sdim  ///
3733234353Sdim  /// \param ClassDecl The class declaration into which the implicit
3734212795Sdim  /// copy constructor will be added.
3735212795Sdim  ///
3736212795Sdim  /// \returns The implicitly-declared copy constructor.
3737212795Sdim  CXXConstructorDecl *DeclareImplicitCopyConstructor(CXXRecordDecl *ClassDecl);
3738234353Sdim
3739212795Sdim  /// DefineImplicitCopyConstructor - Checks for feasibility of
3740212795Sdim  /// defining this constructor as the copy constructor.
3741212795Sdim  void DefineImplicitCopyConstructor(SourceLocation CurrentLocation,
3742223017Sdim                                     CXXConstructorDecl *Constructor);
3743212795Sdim
3744226633Sdim  /// \brief Declare the implicit move constructor for the given class.
3745226633Sdim  ///
3746226633Sdim  /// \param ClassDecl The Class declaration into which the implicit
3747226633Sdim  /// move constructor will be added.
3748226633Sdim  ///
3749226633Sdim  /// \returns The implicitly-declared move constructor, or NULL if it wasn't
3750226633Sdim  /// declared.
3751226633Sdim  CXXConstructorDecl *DeclareImplicitMoveConstructor(CXXRecordDecl *ClassDecl);
3752234353Sdim
3753226633Sdim  /// DefineImplicitMoveConstructor - Checks for feasibility of
3754226633Sdim  /// defining this constructor as the move constructor.
3755226633Sdim  void DefineImplicitMoveConstructor(SourceLocation CurrentLocation,
3756226633Sdim                                     CXXConstructorDecl *Constructor);
3757226633Sdim
3758212795Sdim  /// \brief Declare the implicit copy assignment operator for the given class.
3759212795Sdim  ///
3760234353Sdim  /// \param ClassDecl The class declaration into which the implicit
3761226633Sdim  /// copy assignment operator will be added.
3762212795Sdim  ///
3763212795Sdim  /// \returns The implicitly-declared copy assignment operator.
3764212795Sdim  CXXMethodDecl *DeclareImplicitCopyAssignment(CXXRecordDecl *ClassDecl);
3765234353Sdim
3766226633Sdim  /// \brief Defines an implicitly-declared copy assignment operator.
3767212795Sdim  void DefineImplicitCopyAssignment(SourceLocation CurrentLocation,
3768212795Sdim                                    CXXMethodDecl *MethodDecl);
3769212795Sdim
3770226633Sdim  /// \brief Declare the implicit move assignment operator for the given class.
3771226633Sdim  ///
3772226633Sdim  /// \param ClassDecl The Class declaration into which the implicit
3773226633Sdim  /// move assignment operator will be added.
3774226633Sdim  ///
3775226633Sdim  /// \returns The implicitly-declared move assignment operator, or NULL if it
3776226633Sdim  /// wasn't declared.
3777226633Sdim  CXXMethodDecl *DeclareImplicitMoveAssignment(CXXRecordDecl *ClassDecl);
3778234353Sdim
3779226633Sdim  /// \brief Defines an implicitly-declared move assignment operator.
3780226633Sdim  void DefineImplicitMoveAssignment(SourceLocation CurrentLocation,
3781226633Sdim                                    CXXMethodDecl *MethodDecl);
3782226633Sdim
3783212795Sdim  /// \brief Force the declaration of any implicitly-declared members of this
3784212795Sdim  /// class.
3785212795Sdim  void ForceDeclarationOfImplicitMembers(CXXRecordDecl *Class);
3786234353Sdim
3787234353Sdim  /// \brief Determine whether the given function is an implicitly-deleted
3788234353Sdim  /// special member function.
3789234353Sdim  bool isImplicitlyDeleted(FunctionDecl *FD);
3790239462Sdim
3791234982Sdim  /// \brief Check whether 'this' shows up in the type of a static member
3792234982Sdim  /// function after the (naturally empty) cv-qualifier-seq would be.
3793234982Sdim  ///
3794234982Sdim  /// \returns true if an error occurred.
3795234982Sdim  bool checkThisInStaticMemberFunctionType(CXXMethodDecl *Method);
3796234982Sdim
3797234982Sdim  /// \brief Whether this' shows up in the exception specification of a static
3798234982Sdim  /// member function.
3799234982Sdim  bool checkThisInStaticMemberFunctionExceptionSpec(CXXMethodDecl *Method);
3800234982Sdim
3801234982Sdim  /// \brief Check whether 'this' shows up in the attributes of the given
3802234982Sdim  /// static member function.
3803234982Sdim  ///
3804234982Sdim  /// \returns true if an error occurred.
3805234982Sdim  bool checkThisInStaticMemberFunctionAttributes(CXXMethodDecl *Method);
3806239462Sdim
3807212795Sdim  /// MaybeBindToTemporary - If the passed in expression has a record type with
3808212795Sdim  /// a non-trivial destructor, this will return CXXBindTemporaryExpr. Otherwise
3809212795Sdim  /// it simply returns the passed in expression.
3810212795Sdim  ExprResult MaybeBindToTemporary(Expr *E);
3811212795Sdim
3812212795Sdim  bool CompleteConstructorCall(CXXConstructorDecl *Constructor,
3813212795Sdim                               MultiExprArg ArgsPtr,
3814212795Sdim                               SourceLocation Loc,
3815243830Sdim                               SmallVectorImpl<Expr*> &ConvertedArgs,
3816249423Sdim                               bool AllowExplicit = false,
3817249423Sdim                               bool IsListInitialization = false);
3818212795Sdim
3819249423Sdim  ParsedType getInheritingConstructorName(CXXScopeSpec &SS,
3820249423Sdim                                          SourceLocation NameLoc,
3821249423Sdim                                          IdentifierInfo &Name);
3822249423Sdim
3823212795Sdim  ParsedType getDestructorName(SourceLocation TildeLoc,
3824212795Sdim                               IdentifierInfo &II, SourceLocation NameLoc,
3825212795Sdim                               Scope *S, CXXScopeSpec &SS,
3826212795Sdim                               ParsedType ObjectType,
3827212795Sdim                               bool EnteringContext);
3828212795Sdim
3829234353Sdim  ParsedType getDestructorType(const DeclSpec& DS, ParsedType ObjectType);
3830234353Sdim
3831223017Sdim  // Checks that reinterpret casts don't have undefined behavior.
3832223017Sdim  void CheckCompatibleReinterpretCast(QualType SrcType, QualType DestType,
3833223017Sdim                                      bool IsDereference, SourceRange Range);
3834223017Sdim
3835212795Sdim  /// ActOnCXXNamedCast - Parse {dynamic,static,reinterpret,const}_cast's.
3836212795Sdim  ExprResult ActOnCXXNamedCast(SourceLocation OpLoc,
3837212795Sdim                               tok::TokenKind Kind,
3838212795Sdim                               SourceLocation LAngleBracketLoc,
3839224145Sdim                               Declarator &D,
3840212795Sdim                               SourceLocation RAngleBracketLoc,
3841212795Sdim                               SourceLocation LParenLoc,
3842212795Sdim                               Expr *E,
3843212795Sdim                               SourceLocation RParenLoc);
3844212795Sdim
3845212795Sdim  ExprResult BuildCXXNamedCast(SourceLocation OpLoc,
3846212795Sdim                               tok::TokenKind Kind,
3847212795Sdim                               TypeSourceInfo *Ty,
3848212795Sdim                               Expr *E,
3849212795Sdim                               SourceRange AngleBrackets,
3850212795Sdim                               SourceRange Parens);
3851212795Sdim
3852212795Sdim  ExprResult BuildCXXTypeId(QualType TypeInfoType,
3853212795Sdim                            SourceLocation TypeidLoc,
3854212795Sdim                            TypeSourceInfo *Operand,
3855212795Sdim                            SourceLocation RParenLoc);
3856212795Sdim  ExprResult BuildCXXTypeId(QualType TypeInfoType,
3857212795Sdim                            SourceLocation TypeidLoc,
3858212795Sdim                            Expr *Operand,
3859212795Sdim                            SourceLocation RParenLoc);
3860212795Sdim
3861212795Sdim  /// ActOnCXXTypeid - Parse typeid( something ).
3862212795Sdim  ExprResult ActOnCXXTypeid(SourceLocation OpLoc,
3863212795Sdim                            SourceLocation LParenLoc, bool isType,
3864212795Sdim                            void *TyOrExpr,
3865212795Sdim                            SourceLocation RParenLoc);
3866212795Sdim
3867218893Sdim  ExprResult BuildCXXUuidof(QualType TypeInfoType,
3868218893Sdim                            SourceLocation TypeidLoc,
3869218893Sdim                            TypeSourceInfo *Operand,
3870218893Sdim                            SourceLocation RParenLoc);
3871218893Sdim  ExprResult BuildCXXUuidof(QualType TypeInfoType,
3872218893Sdim                            SourceLocation TypeidLoc,
3873218893Sdim                            Expr *Operand,
3874218893Sdim                            SourceLocation RParenLoc);
3875218893Sdim
3876218893Sdim  /// ActOnCXXUuidof - Parse __uuidof( something ).
3877218893Sdim  ExprResult ActOnCXXUuidof(SourceLocation OpLoc,
3878218893Sdim                            SourceLocation LParenLoc, bool isType,
3879218893Sdim                            void *TyOrExpr,
3880218893Sdim                            SourceLocation RParenLoc);
3881218893Sdim
3882218893Sdim
3883212795Sdim  //// ActOnCXXThis -  Parse 'this' pointer.
3884218893Sdim  ExprResult ActOnCXXThis(SourceLocation loc);
3885212795Sdim
3886234353Sdim  /// \brief Try to retrieve the type of the 'this' pointer.
3887234353Sdim  ///
3888234353Sdim  /// \returns The type of 'this', if possible. Otherwise, returns a NULL type.
3889234353Sdim  QualType getCurrentThisType();
3890218893Sdim
3891239462Sdim  /// \brief When non-NULL, the C++ 'this' expression is allowed despite the
3892234982Sdim  /// current context not being a non-static member function. In such cases,
3893234982Sdim  /// this provides the type used for 'this'.
3894234982Sdim  QualType CXXThisTypeOverride;
3895239462Sdim
3896234982Sdim  /// \brief RAII object used to temporarily allow the C++ 'this' expression
3897234982Sdim  /// to be used, with the given qualifiers on the current class type.
3898234982Sdim  class CXXThisScopeRAII {
3899234982Sdim    Sema &S;
3900234982Sdim    QualType OldCXXThisTypeOverride;
3901234982Sdim    bool Enabled;
3902239462Sdim
3903234982Sdim  public:
3904234982Sdim    /// \brief Introduce a new scope where 'this' may be allowed (when enabled),
3905239462Sdim    /// using the given declaration (which is either a class template or a
3906234982Sdim    /// class) along with the given qualifiers.
3907234982Sdim    /// along with the qualifiers placed on '*this'.
3908239462Sdim    CXXThisScopeRAII(Sema &S, Decl *ContextDecl, unsigned CXXThisTypeQuals,
3909234982Sdim                     bool Enabled = true);
3910239462Sdim
3911234982Sdim    ~CXXThisScopeRAII();
3912234982Sdim  };
3913239462Sdim
3914234353Sdim  /// \brief Make sure the value of 'this' is actually available in the current
3915234353Sdim  /// context, if it is a potentially evaluated context.
3916234353Sdim  ///
3917234353Sdim  /// \param Loc The location at which the capture of 'this' occurs.
3918234353Sdim  ///
3919234353Sdim  /// \param Explicit Whether 'this' is explicitly captured in a lambda
3920234353Sdim  /// capture list.
3921234353Sdim  void CheckCXXThisCapture(SourceLocation Loc, bool Explicit = false);
3922234353Sdim
3923234982Sdim  /// \brief Determine whether the given type is the type of *this that is used
3924239462Sdim  /// outside of the body of a member function for a type that is currently
3925234982Sdim  /// being defined.
3926234982Sdim  bool isThisOutsideMemberFunctionBody(QualType BaseType);
3927239462Sdim
3928212795Sdim  /// ActOnCXXBoolLiteral - Parse {true,false} literals.
3929212795Sdim  ExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind);
3930239462Sdim
3931239462Sdim
3932234353Sdim  /// ActOnObjCBoolLiteral - Parse {__objc_yes,__objc_no} literals.
3933234353Sdim  ExprResult ActOnObjCBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind);
3934212795Sdim
3935212795Sdim  /// ActOnCXXNullPtrLiteral - Parse 'nullptr'.
3936212795Sdim  ExprResult ActOnCXXNullPtrLiteral(SourceLocation Loc);
3937212795Sdim
3938212795Sdim  //// ActOnCXXThrow -  Parse throw expressions.
3939224145Sdim  ExprResult ActOnCXXThrow(Scope *S, SourceLocation OpLoc, Expr *expr);
3940234353Sdim  ExprResult BuildCXXThrow(SourceLocation OpLoc, Expr *Ex,
3941224145Sdim                           bool IsThrownVarInScope);
3942234353Sdim  ExprResult CheckCXXThrowOperand(SourceLocation ThrowLoc, Expr *E,
3943224145Sdim                                  bool IsThrownVarInScope);
3944212795Sdim
3945212795Sdim  /// ActOnCXXTypeConstructExpr - Parse construction of a specified type.
3946212795Sdim  /// Can be interpreted either as function-style casting ("int(x)")
3947212795Sdim  /// or class type construction ("ClassType(x,y,z)")
3948212795Sdim  /// or creation of a value-initialized type ("int()").
3949218893Sdim  ExprResult ActOnCXXTypeConstructExpr(ParsedType TypeRep,
3950212795Sdim                                       SourceLocation LParenLoc,
3951212795Sdim                                       MultiExprArg Exprs,
3952212795Sdim                                       SourceLocation RParenLoc);
3953212795Sdim
3954218893Sdim  ExprResult BuildCXXTypeConstructExpr(TypeSourceInfo *Type,
3955218893Sdim                                       SourceLocation LParenLoc,
3956218893Sdim                                       MultiExprArg Exprs,
3957218893Sdim                                       SourceLocation RParenLoc);
3958218893Sdim
3959212795Sdim  /// ActOnCXXNew - Parsed a C++ 'new' expression.
3960212795Sdim  ExprResult ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal,
3961212795Sdim                         SourceLocation PlacementLParen,
3962212795Sdim                         MultiExprArg PlacementArgs,
3963212795Sdim                         SourceLocation PlacementRParen,
3964212795Sdim                         SourceRange TypeIdParens, Declarator &D,
3965234353Sdim                         Expr *Initializer);
3966243830Sdim  ExprResult BuildCXXNew(SourceRange Range, bool UseGlobal,
3967212795Sdim                         SourceLocation PlacementLParen,
3968212795Sdim                         MultiExprArg PlacementArgs,
3969212795Sdim                         SourceLocation PlacementRParen,
3970212795Sdim                         SourceRange TypeIdParens,
3971212795Sdim                         QualType AllocType,
3972218893Sdim                         TypeSourceInfo *AllocTypeInfo,
3973212795Sdim                         Expr *ArraySize,
3974234353Sdim                         SourceRange DirectInitRange,
3975234353Sdim                         Expr *Initializer,
3976218893Sdim                         bool TypeMayContainAuto = true);
3977212795Sdim
3978212795Sdim  bool CheckAllocatedType(QualType AllocType, SourceLocation Loc,
3979212795Sdim                          SourceRange R);
3980212795Sdim  bool FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range,
3981212795Sdim                               bool UseGlobal, QualType AllocType, bool IsArray,
3982212795Sdim                               Expr **PlaceArgs, unsigned NumPlaceArgs,
3983212795Sdim                               FunctionDecl *&OperatorNew,
3984212795Sdim                               FunctionDecl *&OperatorDelete);
3985212795Sdim  bool FindAllocationOverload(SourceLocation StartLoc, SourceRange Range,
3986212795Sdim                              DeclarationName Name, Expr** Args,
3987212795Sdim                              unsigned NumArgs, DeclContext *Ctx,
3988223017Sdim                              bool AllowMissing, FunctionDecl *&Operator,
3989223017Sdim                              bool Diagnose = true);
3990212795Sdim  void DeclareGlobalNewDelete();
3991212795Sdim  void DeclareGlobalAllocationFunction(DeclarationName Name, QualType Return,
3992212795Sdim                                       QualType Argument,
3993212795Sdim                                       bool addMallocAttr = false);
3994212795Sdim
3995212795Sdim  bool FindDeallocationFunction(SourceLocation StartLoc, CXXRecordDecl *RD,
3996223017Sdim                                DeclarationName Name, FunctionDecl* &Operator,
3997223017Sdim                                bool Diagnose = true);
3998212795Sdim
3999212795Sdim  /// ActOnCXXDelete - Parsed a C++ 'delete' expression
4000212795Sdim  ExprResult ActOnCXXDelete(SourceLocation StartLoc,
4001212795Sdim                            bool UseGlobal, bool ArrayForm,
4002212795Sdim                            Expr *Operand);
4003212795Sdim
4004212795Sdim  DeclResult ActOnCXXConditionDeclaration(Scope *S, Declarator &D);
4005212795Sdim  ExprResult CheckConditionVariable(VarDecl *ConditionVar,
4006212795Sdim                                    SourceLocation StmtLoc,
4007212795Sdim                                    bool ConvertToBoolean);
4008212795Sdim
4009218893Sdim  ExprResult ActOnNoexceptExpr(SourceLocation KeyLoc, SourceLocation LParen,
4010218893Sdim                               Expr *Operand, SourceLocation RParen);
4011218893Sdim  ExprResult BuildCXXNoexceptExpr(SourceLocation KeyLoc, Expr *Operand,
4012218893Sdim                                  SourceLocation RParen);
4013218893Sdim
4014212795Sdim  /// ActOnUnaryTypeTrait - Parsed one of the unary type trait support
4015212795Sdim  /// pseudo-functions.
4016212795Sdim  ExprResult ActOnUnaryTypeTrait(UnaryTypeTrait OTT,
4017212795Sdim                                 SourceLocation KWLoc,
4018212795Sdim                                 ParsedType Ty,
4019212795Sdim                                 SourceLocation RParen);
4020212795Sdim
4021218893Sdim  ExprResult BuildUnaryTypeTrait(UnaryTypeTrait OTT,
4022218893Sdim                                 SourceLocation KWLoc,
4023218893Sdim                                 TypeSourceInfo *T,
4024218893Sdim                                 SourceLocation RParen);
4025218893Sdim
4026218893Sdim  /// ActOnBinaryTypeTrait - Parsed one of the bianry type trait support
4027218893Sdim  /// pseudo-functions.
4028218893Sdim  ExprResult ActOnBinaryTypeTrait(BinaryTypeTrait OTT,
4029218893Sdim                                  SourceLocation KWLoc,
4030218893Sdim                                  ParsedType LhsTy,
4031218893Sdim                                  ParsedType RhsTy,
4032218893Sdim                                  SourceLocation RParen);
4033218893Sdim
4034218893Sdim  ExprResult BuildBinaryTypeTrait(BinaryTypeTrait BTT,
4035218893Sdim                                  SourceLocation KWLoc,
4036218893Sdim                                  TypeSourceInfo *LhsT,
4037218893Sdim                                  TypeSourceInfo *RhsT,
4038218893Sdim                                  SourceLocation RParen);
4039218893Sdim
4040234353Sdim  /// \brief Parsed one of the type trait support pseudo-functions.
4041234353Sdim  ExprResult ActOnTypeTrait(TypeTrait Kind, SourceLocation KWLoc,
4042234353Sdim                            ArrayRef<ParsedType> Args,
4043234353Sdim                            SourceLocation RParenLoc);
4044234353Sdim  ExprResult BuildTypeTrait(TypeTrait Kind, SourceLocation KWLoc,
4045234353Sdim                            ArrayRef<TypeSourceInfo *> Args,
4046234353Sdim                            SourceLocation RParenLoc);
4047239462Sdim
4048221345Sdim  /// ActOnArrayTypeTrait - Parsed one of the bianry type trait support
4049221345Sdim  /// pseudo-functions.
4050221345Sdim  ExprResult ActOnArrayTypeTrait(ArrayTypeTrait ATT,
4051221345Sdim                                 SourceLocation KWLoc,
4052221345Sdim                                 ParsedType LhsTy,
4053221345Sdim                                 Expr *DimExpr,
4054221345Sdim                                 SourceLocation RParen);
4055221345Sdim
4056221345Sdim  ExprResult BuildArrayTypeTrait(ArrayTypeTrait ATT,
4057221345Sdim                                 SourceLocation KWLoc,
4058221345Sdim                                 TypeSourceInfo *TSInfo,
4059221345Sdim                                 Expr *DimExpr,
4060221345Sdim                                 SourceLocation RParen);
4061221345Sdim
4062221345Sdim  /// ActOnExpressionTrait - Parsed one of the unary type trait support
4063221345Sdim  /// pseudo-functions.
4064221345Sdim  ExprResult ActOnExpressionTrait(ExpressionTrait OET,
4065221345Sdim                                  SourceLocation KWLoc,
4066221345Sdim                                  Expr *Queried,
4067221345Sdim                                  SourceLocation RParen);
4068221345Sdim
4069221345Sdim  ExprResult BuildExpressionTrait(ExpressionTrait OET,
4070221345Sdim                                  SourceLocation KWLoc,
4071221345Sdim                                  Expr *Queried,
4072221345Sdim                                  SourceLocation RParen);
4073221345Sdim
4074212795Sdim  ExprResult ActOnStartCXXMemberReference(Scope *S,
4075212795Sdim                                          Expr *Base,
4076212795Sdim                                          SourceLocation OpLoc,
4077212795Sdim                                          tok::TokenKind OpKind,
4078212795Sdim                                          ParsedType &ObjectType,
4079212795Sdim                                          bool &MayBePseudoDestructor);
4080212795Sdim
4081212795Sdim  ExprResult DiagnoseDtorReference(SourceLocation NameLoc, Expr *MemExpr);
4082212795Sdim
4083212795Sdim  ExprResult BuildPseudoDestructorExpr(Expr *Base,
4084212795Sdim                                       SourceLocation OpLoc,
4085212795Sdim                                       tok::TokenKind OpKind,
4086212795Sdim                                       const CXXScopeSpec &SS,
4087212795Sdim                                       TypeSourceInfo *ScopeType,
4088212795Sdim                                       SourceLocation CCLoc,
4089212795Sdim                                       SourceLocation TildeLoc,
4090212795Sdim                                     PseudoDestructorTypeStorage DestroyedType,
4091212795Sdim                                       bool HasTrailingLParen);
4092212795Sdim
4093212795Sdim  ExprResult ActOnPseudoDestructorExpr(Scope *S, Expr *Base,
4094212795Sdim                                       SourceLocation OpLoc,
4095212795Sdim                                       tok::TokenKind OpKind,
4096212795Sdim                                       CXXScopeSpec &SS,
4097212795Sdim                                       UnqualifiedId &FirstTypeName,
4098212795Sdim                                       SourceLocation CCLoc,
4099212795Sdim                                       SourceLocation TildeLoc,
4100212795Sdim                                       UnqualifiedId &SecondTypeName,
4101212795Sdim                                       bool HasTrailingLParen);
4102212795Sdim
4103234353Sdim  ExprResult ActOnPseudoDestructorExpr(Scope *S, Expr *Base,
4104234353Sdim                                       SourceLocation OpLoc,
4105234353Sdim                                       tok::TokenKind OpKind,
4106239462Sdim                                       SourceLocation TildeLoc,
4107234353Sdim                                       const DeclSpec& DS,
4108234353Sdim                                       bool HasTrailingLParen);
4109234353Sdim
4110218893Sdim  /// MaybeCreateExprWithCleanups - If the current full-expression
4111218893Sdim  /// requires any cleanups, surround it with a ExprWithCleanups node.
4112218893Sdim  /// Otherwise, just returns the passed-in expression.
4113218893Sdim  Expr *MaybeCreateExprWithCleanups(Expr *SubExpr);
4114218893Sdim  Stmt *MaybeCreateStmtWithCleanups(Stmt *SubStmt);
4115218893Sdim  ExprResult MaybeCreateExprWithCleanups(ExprResult SubExpr);
4116212795Sdim
4117239462Sdim  ExprResult ActOnFinishFullExpr(Expr *Expr) {
4118239462Sdim    return ActOnFinishFullExpr(Expr, Expr ? Expr->getExprLoc()
4119239462Sdim                                          : SourceLocation());
4120239462Sdim  }
4121249423Sdim  ExprResult ActOnFinishFullExpr(Expr *Expr, SourceLocation CC,
4122249423Sdim                                 bool DiscardedValue = false,
4123249423Sdim                                 bool IsConstexpr = false);
4124218893Sdim  StmtResult ActOnFinishFullStmt(Stmt *Stmt);
4125212795Sdim
4126212795Sdim  // Marks SS invalid if it represents an incomplete type.
4127212795Sdim  bool RequireCompleteDeclContext(CXXScopeSpec &SS, DeclContext *DC);
4128212795Sdim
4129212795Sdim  DeclContext *computeDeclContext(QualType T);
4130212795Sdim  DeclContext *computeDeclContext(const CXXScopeSpec &SS,
4131212795Sdim                                  bool EnteringContext = false);
4132212795Sdim  bool isDependentScopeSpecifier(const CXXScopeSpec &SS);
4133212795Sdim  CXXRecordDecl *getCurrentInstantiationOf(NestedNameSpecifier *NNS);
4134212795Sdim  bool isUnknownSpecialization(const CXXScopeSpec &SS);
4135212795Sdim
4136219077Sdim  /// \brief The parser has parsed a global nested-name-specifier '::'.
4137219077Sdim  ///
4138219077Sdim  /// \param S The scope in which this nested-name-specifier occurs.
4139219077Sdim  ///
4140219077Sdim  /// \param CCLoc The location of the '::'.
4141219077Sdim  ///
4142219077Sdim  /// \param SS The nested-name-specifier, which will be updated in-place
4143219077Sdim  /// to reflect the parsed nested-name-specifier.
4144219077Sdim  ///
4145219077Sdim  /// \returns true if an error occurred, false otherwise.
4146219077Sdim  bool ActOnCXXGlobalScopeSpecifier(Scope *S, SourceLocation CCLoc,
4147219077Sdim                                    CXXScopeSpec &SS);
4148234353Sdim
4149249423Sdim  bool isAcceptableNestedNameSpecifier(const NamedDecl *SD);
4150212795Sdim  NamedDecl *FindFirstQualifierInScope(Scope *S, NestedNameSpecifier *NNS);
4151212795Sdim
4152212795Sdim  bool isNonTypeNestedNameSpecifier(Scope *S, CXXScopeSpec &SS,
4153212795Sdim                                    SourceLocation IdLoc,
4154212795Sdim                                    IdentifierInfo &II,
4155212795Sdim                                    ParsedType ObjectType);
4156212795Sdim
4157219077Sdim  bool BuildCXXNestedNameSpecifier(Scope *S,
4158219077Sdim                                   IdentifierInfo &Identifier,
4159219077Sdim                                   SourceLocation IdentifierLoc,
4160219077Sdim                                   SourceLocation CCLoc,
4161219077Sdim                                   QualType ObjectType,
4162219077Sdim                                   bool EnteringContext,
4163219077Sdim                                   CXXScopeSpec &SS,
4164219077Sdim                                   NamedDecl *ScopeLookupResult,
4165219077Sdim                                   bool ErrorRecoveryLookup);
4166212795Sdim
4167219077Sdim  /// \brief The parser has parsed a nested-name-specifier 'identifier::'.
4168219077Sdim  ///
4169219077Sdim  /// \param S The scope in which this nested-name-specifier occurs.
4170219077Sdim  ///
4171219077Sdim  /// \param Identifier The identifier preceding the '::'.
4172219077Sdim  ///
4173219077Sdim  /// \param IdentifierLoc The location of the identifier.
4174219077Sdim  ///
4175219077Sdim  /// \param CCLoc The location of the '::'.
4176219077Sdim  ///
4177234353Sdim  /// \param ObjectType The type of the object, if we're parsing
4178219077Sdim  /// nested-name-specifier in a member access expression.
4179219077Sdim  ///
4180219077Sdim  /// \param EnteringContext Whether we're entering the context nominated by
4181219077Sdim  /// this nested-name-specifier.
4182219077Sdim  ///
4183219077Sdim  /// \param SS The nested-name-specifier, which is both an input
4184219077Sdim  /// parameter (the nested-name-specifier before this type) and an
4185219077Sdim  /// output parameter (containing the full nested-name-specifier,
4186219077Sdim  /// including this new type).
4187219077Sdim  ///
4188219077Sdim  /// \returns true if an error occurred, false otherwise.
4189219077Sdim  bool ActOnCXXNestedNameSpecifier(Scope *S,
4190219077Sdim                                   IdentifierInfo &Identifier,
4191219077Sdim                                   SourceLocation IdentifierLoc,
4192219077Sdim                                   SourceLocation CCLoc,
4193219077Sdim                                   ParsedType ObjectType,
4194219077Sdim                                   bool EnteringContext,
4195219077Sdim                                   CXXScopeSpec &SS);
4196212795Sdim
4197234353Sdim  ExprResult ActOnDecltypeExpression(Expr *E);
4198234353Sdim
4199234353Sdim  bool ActOnCXXNestedNameSpecifierDecltype(CXXScopeSpec &SS,
4200239462Sdim                                           const DeclSpec &DS,
4201234353Sdim                                           SourceLocation ColonColonLoc);
4202234353Sdim
4203212795Sdim  bool IsInvalidUnlessNestedName(Scope *S, CXXScopeSpec &SS,
4204219077Sdim                                 IdentifierInfo &Identifier,
4205219077Sdim                                 SourceLocation IdentifierLoc,
4206219077Sdim                                 SourceLocation ColonLoc,
4207212795Sdim                                 ParsedType ObjectType,
4208212795Sdim                                 bool EnteringContext);
4209212795Sdim
4210234353Sdim  /// \brief The parser has parsed a nested-name-specifier
4211221345Sdim  /// 'template[opt] template-name < template-args >::'.
4212219077Sdim  ///
4213219077Sdim  /// \param S The scope in which this nested-name-specifier occurs.
4214219077Sdim  ///
4215219077Sdim  /// \param SS The nested-name-specifier, which is both an input
4216219077Sdim  /// parameter (the nested-name-specifier before this type) and an
4217219077Sdim  /// output parameter (containing the full nested-name-specifier,
4218219077Sdim  /// including this new type).
4219234353Sdim  ///
4220234353Sdim  /// \param TemplateKWLoc the location of the 'template' keyword, if any.
4221239462Sdim  /// \param TemplateName the template name.
4222221345Sdim  /// \param TemplateNameLoc The location of the template name.
4223221345Sdim  /// \param LAngleLoc The location of the opening angle bracket  ('<').
4224221345Sdim  /// \param TemplateArgs The template arguments.
4225221345Sdim  /// \param RAngleLoc The location of the closing angle bracket  ('>').
4226221345Sdim  /// \param CCLoc The location of the '::'.
4227234353Sdim  ///
4228234353Sdim  /// \param EnteringContext Whether we're entering the context of the
4229221345Sdim  /// nested-name-specifier.
4230219077Sdim  ///
4231221345Sdim  ///
4232219077Sdim  /// \returns true if an error occurred, false otherwise.
4233219077Sdim  bool ActOnCXXNestedNameSpecifier(Scope *S,
4234234353Sdim                                   CXXScopeSpec &SS,
4235234353Sdim                                   SourceLocation TemplateKWLoc,
4236239462Sdim                                   TemplateTy TemplateName,
4237221345Sdim                                   SourceLocation TemplateNameLoc,
4238221345Sdim                                   SourceLocation LAngleLoc,
4239221345Sdim                                   ASTTemplateArgsPtr TemplateArgs,
4240221345Sdim                                   SourceLocation RAngleLoc,
4241219077Sdim                                   SourceLocation CCLoc,
4242221345Sdim                                   bool EnteringContext);
4243212795Sdim
4244219077Sdim  /// \brief Given a C++ nested-name-specifier, produce an annotation value
4245234353Sdim  /// that the parser can use later to reconstruct the given
4246219077Sdim  /// nested-name-specifier.
4247219077Sdim  ///
4248219077Sdim  /// \param SS A nested-name-specifier.
4249219077Sdim  ///
4250234353Sdim  /// \returns A pointer containing all of the information in the
4251219077Sdim  /// nested-name-specifier \p SS.
4252219077Sdim  void *SaveNestedNameSpecifierAnnotation(CXXScopeSpec &SS);
4253234353Sdim
4254234353Sdim  /// \brief Given an annotation pointer for a nested-name-specifier, restore
4255219077Sdim  /// the nested-name-specifier structure.
4256219077Sdim  ///
4257234353Sdim  /// \param Annotation The annotation pointer, produced by
4258219077Sdim  /// \c SaveNestedNameSpecifierAnnotation().
4259219077Sdim  ///
4260219077Sdim  /// \param AnnotationRange The source range corresponding to the annotation.
4261219077Sdim  ///
4262219077Sdim  /// \param SS The nested-name-specifier that will be updated with the contents
4263219077Sdim  /// of the annotation pointer.
4264234353Sdim  void RestoreNestedNameSpecifierAnnotation(void *Annotation,
4265219077Sdim                                            SourceRange AnnotationRange,
4266219077Sdim                                            CXXScopeSpec &SS);
4267234353Sdim
4268212795Sdim  bool ShouldEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS);
4269212795Sdim
4270212795Sdim  /// ActOnCXXEnterDeclaratorScope - Called when a C++ scope specifier (global
4271212795Sdim  /// scope or nested-name-specifier) is parsed, part of a declarator-id.
4272212795Sdim  /// After this method is called, according to [C++ 3.4.3p3], names should be
4273212795Sdim  /// looked up in the declarator-id's scope, until the declarator is parsed and
4274212795Sdim  /// ActOnCXXExitDeclaratorScope is called.
4275212795Sdim  /// The 'SS' should be a non-empty valid CXXScopeSpec.
4276212795Sdim  bool ActOnCXXEnterDeclaratorScope(Scope *S, CXXScopeSpec &SS);
4277212795Sdim
4278212795Sdim  /// ActOnCXXExitDeclaratorScope - Called when a declarator that previously
4279212795Sdim  /// invoked ActOnCXXEnterDeclaratorScope(), is finished. 'SS' is the same
4280212795Sdim  /// CXXScopeSpec that was passed to ActOnCXXEnterDeclaratorScope as well.
4281212795Sdim  /// Used to indicate that names should revert to being looked up in the
4282212795Sdim  /// defining scope.
4283212795Sdim  void ActOnCXXExitDeclaratorScope(Scope *S, const CXXScopeSpec &SS);
4284212795Sdim
4285212795Sdim  /// ActOnCXXEnterDeclInitializer - Invoked when we are about to parse an
4286212795Sdim  /// initializer for the declaration 'Dcl'.
4287212795Sdim  /// After this method is called, according to [C++ 3.4.1p13], if 'Dcl' is a
4288212795Sdim  /// static data member of class X, names should be looked up in the scope of
4289212795Sdim  /// class X.
4290212795Sdim  void ActOnCXXEnterDeclInitializer(Scope *S, Decl *Dcl);
4291212795Sdim
4292212795Sdim  /// ActOnCXXExitDeclInitializer - Invoked after we are finished parsing an
4293212795Sdim  /// initializer for the declaration 'Dcl'.
4294212795Sdim  void ActOnCXXExitDeclInitializer(Scope *S, Decl *Dcl);
4295212795Sdim
4296234353Sdim  /// \brief Create a new lambda closure type.
4297234353Sdim  CXXRecordDecl *createLambdaClosureType(SourceRange IntroducerRange,
4298243830Sdim                                         TypeSourceInfo *Info,
4299243830Sdim                                         bool KnownDependent);
4300239462Sdim
4301234353Sdim  /// \brief Start the definition of a lambda expression.
4302234353Sdim  CXXMethodDecl *startLambdaDefinition(CXXRecordDecl *Class,
4303234353Sdim                                       SourceRange IntroducerRange,
4304234353Sdim                                       TypeSourceInfo *MethodType,
4305234353Sdim                                       SourceLocation EndLoc,
4306249423Sdim                                       ArrayRef<ParmVarDecl *> Params);
4307239462Sdim
4308234353Sdim  /// \brief Introduce the scope for a lambda expression.
4309234353Sdim  sema::LambdaScopeInfo *enterLambdaScope(CXXMethodDecl *CallOperator,
4310234353Sdim                                          SourceRange IntroducerRange,
4311234353Sdim                                          LambdaCaptureDefault CaptureDefault,
4312234353Sdim                                          bool ExplicitParams,
4313234353Sdim                                          bool ExplicitResultType,
4314234353Sdim                                          bool Mutable);
4315239462Sdim
4316234353Sdim  /// \brief Note that we have finished the explicit captures for the
4317234353Sdim  /// given lambda.
4318234353Sdim  void finishLambdaExplicitCaptures(sema::LambdaScopeInfo *LSI);
4319239462Sdim
4320234353Sdim  /// \brief Introduce the lambda parameters into scope.
4321234353Sdim  void addLambdaParameters(CXXMethodDecl *CallOperator, Scope *CurScope);
4322239462Sdim
4323239462Sdim  /// \brief Deduce a block or lambda's return type based on the return
4324239462Sdim  /// statements present in the body.
4325239462Sdim  void deduceClosureReturnType(sema::CapturingScopeInfo &CSI);
4326239462Sdim
4327234353Sdim  /// ActOnStartOfLambdaDefinition - This is called just before we start
4328239462Sdim  /// parsing the body of a lambda; it analyzes the explicit captures and
4329234353Sdim  /// arguments, and sets up various data-structures for the body of the
4330234353Sdim  /// lambda.
4331234353Sdim  void ActOnStartOfLambdaDefinition(LambdaIntroducer &Intro,
4332234353Sdim                                    Declarator &ParamInfo, Scope *CurScope);
4333234353Sdim
4334234353Sdim  /// ActOnLambdaError - If there is an error parsing a lambda, this callback
4335234353Sdim  /// is invoked to pop the information about the lambda.
4336234353Sdim  void ActOnLambdaError(SourceLocation StartLoc, Scope *CurScope,
4337234353Sdim                        bool IsInstantiation = false);
4338234353Sdim
4339234353Sdim  /// ActOnLambdaExpr - This is called when the body of a lambda expression
4340234353Sdim  /// was successfully completed.
4341234353Sdim  ExprResult ActOnLambdaExpr(SourceLocation StartLoc, Stmt *Body,
4342239462Sdim                             Scope *CurScope,
4343234353Sdim                             bool IsInstantiation = false);
4344234353Sdim
4345239462Sdim  /// \brief Define the "body" of the conversion from a lambda object to a
4346234353Sdim  /// function pointer.
4347234353Sdim  ///
4348234353Sdim  /// This routine doesn't actually define a sensible body; rather, it fills
4349234353Sdim  /// in the initialization expression needed to copy the lambda object into
4350234353Sdim  /// the block, and IR generation actually generates the real body of the
4351234353Sdim  /// block pointer conversion.
4352234353Sdim  void DefineImplicitLambdaToFunctionPointerConversion(
4353234353Sdim         SourceLocation CurrentLoc, CXXConversionDecl *Conv);
4354234353Sdim
4355239462Sdim  /// \brief Define the "body" of the conversion from a lambda object to a
4356234353Sdim  /// block pointer.
4357234353Sdim  ///
4358234353Sdim  /// This routine doesn't actually define a sensible body; rather, it fills
4359234353Sdim  /// in the initialization expression needed to copy the lambda object into
4360234353Sdim  /// the block, and IR generation actually generates the real body of the
4361234353Sdim  /// block pointer conversion.
4362234353Sdim  void DefineImplicitLambdaToBlockPointerConversion(SourceLocation CurrentLoc,
4363234353Sdim                                                    CXXConversionDecl *Conv);
4364234353Sdim
4365234353Sdim  ExprResult BuildBlockForLambdaConversion(SourceLocation CurrentLocation,
4366234353Sdim                                           SourceLocation ConvLocation,
4367234353Sdim                                           CXXConversionDecl *Conv,
4368234353Sdim                                           Expr *Src);
4369234353Sdim
4370212795Sdim  // ParseObjCStringLiteral - Parse Objective-C string literals.
4371212795Sdim  ExprResult ParseObjCStringLiteral(SourceLocation *AtLocs,
4372212795Sdim                                    Expr **Strings,
4373212795Sdim                                    unsigned NumStrings);
4374239462Sdim
4375234353Sdim  ExprResult BuildObjCStringLiteral(SourceLocation AtLoc, StringLiteral *S);
4376239462Sdim
4377239462Sdim  /// BuildObjCNumericLiteral - builds an ObjCBoxedExpr AST node for the
4378234353Sdim  /// numeric literal expression. Type of the expression will be "NSNumber *"
4379234353Sdim  /// or "id" if NSNumber is unavailable.
4380234353Sdim  ExprResult BuildObjCNumericLiteral(SourceLocation AtLoc, Expr *Number);
4381234353Sdim  ExprResult ActOnObjCBoolLiteral(SourceLocation AtLoc, SourceLocation ValueLoc,
4382234353Sdim                                  bool Value);
4383234353Sdim  ExprResult BuildObjCArrayLiteral(SourceRange SR, MultiExprArg Elements);
4384239462Sdim
4385239462Sdim  /// BuildObjCBoxedExpr - builds an ObjCBoxedExpr AST node for the
4386239462Sdim  /// '@' prefixed parenthesized expression. The type of the expression will
4387239462Sdim  /// either be "NSNumber *" or "NSString *" depending on the type of
4388239462Sdim  /// ValueType, which is allowed to be a built-in numeric type or
4389239462Sdim  /// "char *" or "const char *".
4390239462Sdim  ExprResult BuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr);
4391239462Sdim
4392234353Sdim  ExprResult BuildObjCSubscriptExpression(SourceLocation RB, Expr *BaseExpr,
4393234353Sdim                                          Expr *IndexExpr,
4394234353Sdim                                          ObjCMethodDecl *getterMethod,
4395234353Sdim                                          ObjCMethodDecl *setterMethod);
4396239462Sdim
4397239462Sdim  ExprResult BuildObjCDictionaryLiteral(SourceRange SR,
4398234353Sdim                                        ObjCDictionaryElement *Elements,
4399234353Sdim                                        unsigned NumElements);
4400239462Sdim
4401223017Sdim  ExprResult BuildObjCEncodeExpression(SourceLocation AtLoc,
4402212795Sdim                                  TypeSourceInfo *EncodedTypeInfo,
4403212795Sdim                                  SourceLocation RParenLoc);
4404218893Sdim  ExprResult BuildCXXMemberCallExpr(Expr *Exp, NamedDecl *FoundDecl,
4405234353Sdim                                    CXXConversionDecl *Method,
4406226633Sdim                                    bool HadMultipleCandidates);
4407212795Sdim
4408212795Sdim  ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc,
4409212795Sdim                                       SourceLocation EncodeLoc,
4410212795Sdim                                       SourceLocation LParenLoc,
4411212795Sdim                                       ParsedType Ty,
4412212795Sdim                                       SourceLocation RParenLoc);
4413212795Sdim
4414239462Sdim  /// ParseObjCSelectorExpression - Build selector expression for \@selector
4415212795Sdim  ExprResult ParseObjCSelectorExpression(Selector Sel,
4416212795Sdim                                         SourceLocation AtLoc,
4417212795Sdim                                         SourceLocation SelLoc,
4418212795Sdim                                         SourceLocation LParenLoc,
4419212795Sdim                                         SourceLocation RParenLoc);
4420212795Sdim
4421239462Sdim  /// ParseObjCProtocolExpression - Build protocol expression for \@protocol
4422212795Sdim  ExprResult ParseObjCProtocolExpression(IdentifierInfo * ProtocolName,
4423212795Sdim                                         SourceLocation AtLoc,
4424212795Sdim                                         SourceLocation ProtoLoc,
4425212795Sdim                                         SourceLocation LParenLoc,
4426239462Sdim                                         SourceLocation ProtoIdLoc,
4427212795Sdim                                         SourceLocation RParenLoc);
4428212795Sdim
4429212795Sdim  //===--------------------------------------------------------------------===//
4430212795Sdim  // C++ Declarations
4431212795Sdim  //
4432212795Sdim  Decl *ActOnStartLinkageSpecification(Scope *S,
4433212795Sdim                                       SourceLocation ExternLoc,
4434212795Sdim                                       SourceLocation LangLoc,
4435226633Sdim                                       StringRef Lang,
4436212795Sdim                                       SourceLocation LBraceLoc);
4437212795Sdim  Decl *ActOnFinishLinkageSpecification(Scope *S,
4438212795Sdim                                        Decl *LinkageSpec,
4439212795Sdim                                        SourceLocation RBraceLoc);
4440212795Sdim
4441212795Sdim
4442212795Sdim  //===--------------------------------------------------------------------===//
4443212795Sdim  // C++ Classes
4444212795Sdim  //
4445212795Sdim  bool isCurrentClassName(const IdentifierInfo &II, Scope *S,
4446212795Sdim                          const CXXScopeSpec *SS = 0);
4447212795Sdim
4448226633Sdim  bool ActOnAccessSpecifier(AccessSpecifier Access,
4449226633Sdim                            SourceLocation ASLoc,
4450226633Sdim                            SourceLocation ColonLoc,
4451226633Sdim                            AttributeList *Attrs = 0);
4452212795Sdim
4453249423Sdim  NamedDecl *ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS,
4454212795Sdim                                 Declarator &D,
4455212795Sdim                                 MultiTemplateParamsArg TemplateParameterLists,
4456218893Sdim                                 Expr *BitfieldWidth, const VirtSpecifiers &VS,
4457239462Sdim                                 InClassInitStyle InitStyle);
4458223017Sdim  void ActOnCXXInClassMemberInitializer(Decl *VarDecl, SourceLocation EqualLoc,
4459223017Sdim                                        Expr *Init);
4460212795Sdim
4461212795Sdim  MemInitResult ActOnMemInitializer(Decl *ConstructorD,
4462212795Sdim                                    Scope *S,
4463212795Sdim                                    CXXScopeSpec &SS,
4464212795Sdim                                    IdentifierInfo *MemberOrBase,
4465212795Sdim                                    ParsedType TemplateTypeTy,
4466234353Sdim                                    const DeclSpec &DS,
4467212795Sdim                                    SourceLocation IdLoc,
4468212795Sdim                                    SourceLocation LParenLoc,
4469212795Sdim                                    Expr **Args, unsigned NumArgs,
4470218893Sdim                                    SourceLocation RParenLoc,
4471218893Sdim                                    SourceLocation EllipsisLoc);
4472212795Sdim
4473226633Sdim  MemInitResult ActOnMemInitializer(Decl *ConstructorD,
4474226633Sdim                                    Scope *S,
4475226633Sdim                                    CXXScopeSpec &SS,
4476226633Sdim                                    IdentifierInfo *MemberOrBase,
4477226633Sdim                                    ParsedType TemplateTypeTy,
4478234353Sdim                                    const DeclSpec &DS,
4479226633Sdim                                    SourceLocation IdLoc,
4480226633Sdim                                    Expr *InitList,
4481226633Sdim                                    SourceLocation EllipsisLoc);
4482212795Sdim
4483226633Sdim  MemInitResult BuildMemInitializer(Decl *ConstructorD,
4484226633Sdim                                    Scope *S,
4485226633Sdim                                    CXXScopeSpec &SS,
4486226633Sdim                                    IdentifierInfo *MemberOrBase,
4487226633Sdim                                    ParsedType TemplateTypeTy,
4488234353Sdim                                    const DeclSpec &DS,
4489226633Sdim                                    SourceLocation IdLoc,
4490234353Sdim                                    Expr *Init,
4491226633Sdim                                    SourceLocation EllipsisLoc);
4492226633Sdim
4493226633Sdim  MemInitResult BuildMemberInitializer(ValueDecl *Member,
4494234353Sdim                                       Expr *Init,
4495226633Sdim                                       SourceLocation IdLoc);
4496226633Sdim
4497212795Sdim  MemInitResult BuildBaseInitializer(QualType BaseType,
4498212795Sdim                                     TypeSourceInfo *BaseTInfo,
4499234353Sdim                                     Expr *Init,
4500218893Sdim                                     CXXRecordDecl *ClassDecl,
4501218893Sdim                                     SourceLocation EllipsisLoc);
4502212795Sdim
4503218893Sdim  MemInitResult BuildDelegatingInitializer(TypeSourceInfo *TInfo,
4504234353Sdim                                           Expr *Init,
4505221345Sdim                                           CXXRecordDecl *ClassDecl);
4506218893Sdim
4507221345Sdim  bool SetDelegatingInitializer(CXXConstructorDecl *Constructor,
4508221345Sdim                                CXXCtorInitializer *Initializer);
4509221345Sdim
4510249423Sdim  bool SetCtorInitializers(CXXConstructorDecl *Constructor, bool AnyErrors,
4511251662Sdim                           ArrayRef<CXXCtorInitializer *> Initializers = None);
4512234353Sdim
4513212795Sdim  void SetIvarInitializers(ObjCImplementationDecl *ObjCImplementation);
4514212795Sdim
4515234353Sdim
4516212795Sdim  /// MarkBaseAndMemberDestructorsReferenced - Given a record decl,
4517212795Sdim  /// mark all the non-trivial destructors of its members and bases as
4518212795Sdim  /// referenced.
4519212795Sdim  void MarkBaseAndMemberDestructorsReferenced(SourceLocation Loc,
4520212795Sdim                                              CXXRecordDecl *Record);
4521212795Sdim
4522212795Sdim  /// \brief The list of classes whose vtables have been used within
4523212795Sdim  /// this translation unit, and the source locations at which the
4524212795Sdim  /// first use occurred.
4525218893Sdim  typedef std::pair<CXXRecordDecl*, SourceLocation> VTableUse;
4526212795Sdim
4527218893Sdim  /// \brief The list of vtables that are required but have not yet been
4528218893Sdim  /// materialized.
4529226633Sdim  SmallVector<VTableUse, 16> VTableUses;
4530218893Sdim
4531212795Sdim  /// \brief The set of classes whose vtables have been used within
4532212795Sdim  /// this translation unit, and a bit that will be true if the vtable is
4533212795Sdim  /// required to be emitted (otherwise, it should be emitted only if needed
4534212795Sdim  /// by code generation).
4535212795Sdim  llvm::DenseMap<CXXRecordDecl *, bool> VTablesUsed;
4536212795Sdim
4537226633Sdim  /// \brief Load any externally-stored vtable uses.
4538226633Sdim  void LoadExternalVTableUses();
4539234353Sdim
4540234353Sdim  typedef LazyVector<CXXRecordDecl *, ExternalSemaSource,
4541226633Sdim                     &ExternalSemaSource::ReadDynamicClasses, 2, 2>
4542226633Sdim    DynamicClassesType;
4543226633Sdim
4544212795Sdim  /// \brief A list of all of the dynamic classes in this translation
4545212795Sdim  /// unit.
4546226633Sdim  DynamicClassesType DynamicClasses;
4547212795Sdim
4548212795Sdim  /// \brief Note that the vtable for the given class was used at the
4549212795Sdim  /// given location.
4550212795Sdim  void MarkVTableUsed(SourceLocation Loc, CXXRecordDecl *Class,
4551212795Sdim                      bool DefinitionRequired = false);
4552212795Sdim
4553239462Sdim  /// \brief Mark the exception specifications of all virtual member functions
4554239462Sdim  /// in the given class as needed.
4555239462Sdim  void MarkVirtualMemberExceptionSpecsNeeded(SourceLocation Loc,
4556239462Sdim                                             const CXXRecordDecl *RD);
4557239462Sdim
4558212795Sdim  /// MarkVirtualMembersReferenced - Will mark all members of the given
4559212795Sdim  /// CXXRecordDecl referenced.
4560212795Sdim  void MarkVirtualMembersReferenced(SourceLocation Loc,
4561212795Sdim                                    const CXXRecordDecl *RD);
4562212795Sdim
4563212795Sdim  /// \brief Define all of the vtables that have been used in this
4564212795Sdim  /// translation unit and reference any virtual members used by those
4565212795Sdim  /// vtables.
4566212795Sdim  ///
4567212795Sdim  /// \returns true if any work was done, false otherwise.
4568212795Sdim  bool DefineUsedVTables();
4569212795Sdim
4570212795Sdim  void AddImplicitlyDeclaredMembersToClass(CXXRecordDecl *ClassDecl);
4571212795Sdim
4572212795Sdim  void ActOnMemInitializers(Decl *ConstructorDecl,
4573212795Sdim                            SourceLocation ColonLoc,
4574249423Sdim                            ArrayRef<CXXCtorInitializer*> MemInits,
4575212795Sdim                            bool AnyErrors);
4576212795Sdim
4577212795Sdim  void CheckCompletedCXXClass(CXXRecordDecl *Record);
4578212795Sdim  void ActOnFinishCXXMemberSpecification(Scope* S, SourceLocation RLoc,
4579212795Sdim                                         Decl *TagDecl,
4580212795Sdim                                         SourceLocation LBrac,
4581212795Sdim                                         SourceLocation RBrac,
4582212795Sdim                                         AttributeList *AttrList);
4583235864Sdim  void ActOnFinishCXXMemberDecls();
4584212795Sdim
4585212795Sdim  void ActOnReenterTemplateScope(Scope *S, Decl *Template);
4586221345Sdim  void ActOnReenterDeclaratorTemplateScope(Scope *S, DeclaratorDecl *D);
4587212795Sdim  void ActOnStartDelayedMemberDeclarations(Scope *S, Decl *Record);
4588212795Sdim  void ActOnStartDelayedCXXMethodDeclaration(Scope *S, Decl *Method);
4589212795Sdim  void ActOnDelayedCXXMethodParameter(Scope *S, Decl *Param);
4590223017Sdim  void ActOnFinishDelayedMemberDeclarations(Scope *S, Decl *Record);
4591212795Sdim  void ActOnFinishDelayedCXXMethodDeclaration(Scope *S, Decl *Method);
4592223017Sdim  void ActOnFinishDelayedMemberInitializers(Decl *Record);
4593221345Sdim  void MarkAsLateParsedTemplate(FunctionDecl *FD, bool Flag = true);
4594221345Sdim  bool IsInsideALocalClassWithinATemplateFunction();
4595212795Sdim
4596221345Sdim  Decl *ActOnStaticAssertDeclaration(SourceLocation StaticAssertLoc,
4597212795Sdim                                     Expr *AssertExpr,
4598221345Sdim                                     Expr *AssertMessageExpr,
4599221345Sdim                                     SourceLocation RParenLoc);
4600239462Sdim  Decl *BuildStaticAssertDeclaration(SourceLocation StaticAssertLoc,
4601239462Sdim                                     Expr *AssertExpr,
4602239462Sdim                                     StringLiteral *AssertMessageExpr,
4603239462Sdim                                     SourceLocation RParenLoc,
4604239462Sdim                                     bool Failed);
4605212795Sdim
4606243830Sdim  FriendDecl *CheckFriendTypeDecl(SourceLocation LocStart,
4607234353Sdim                                  SourceLocation FriendLoc,
4608212795Sdim                                  TypeSourceInfo *TSInfo);
4609212795Sdim  Decl *ActOnFriendTypeDecl(Scope *S, const DeclSpec &DS,
4610226633Sdim                            MultiTemplateParamsArg TemplateParams);
4611249423Sdim  NamedDecl *ActOnFriendFunctionDecl(Scope *S, Declarator &D,
4612249423Sdim                                     MultiTemplateParamsArg TemplateParams);
4613212795Sdim
4614212795Sdim  QualType CheckConstructorDeclarator(Declarator &D, QualType R,
4615212795Sdim                                      StorageClass& SC);
4616212795Sdim  void CheckConstructor(CXXConstructorDecl *Constructor);
4617212795Sdim  QualType CheckDestructorDeclarator(Declarator &D, QualType R,
4618212795Sdim                                     StorageClass& SC);
4619212795Sdim  bool CheckDestructor(CXXDestructorDecl *Destructor);
4620212795Sdim  void CheckConversionDeclarator(Declarator &D, QualType &R,
4621212795Sdim                                 StorageClass& SC);
4622212795Sdim  Decl *ActOnConversionDeclarator(CXXConversionDecl *Conversion);
4623212795Sdim
4624239462Sdim  void CheckExplicitlyDefaultedSpecialMember(CXXMethodDecl *MD);
4625249423Sdim  void CheckExplicitlyDefaultedMemberExceptionSpec(CXXMethodDecl *MD,
4626249423Sdim                                                   const FunctionProtoType *T);
4627249423Sdim  void CheckDelayedExplicitlyDefaultedMemberExceptionSpecs();
4628223017Sdim
4629212795Sdim  //===--------------------------------------------------------------------===//
4630212795Sdim  // C++ Derived Classes
4631212795Sdim  //
4632212795Sdim
4633212795Sdim  /// ActOnBaseSpecifier - Parsed a base specifier
4634212795Sdim  CXXBaseSpecifier *CheckBaseSpecifier(CXXRecordDecl *Class,
4635212795Sdim                                       SourceRange SpecifierRange,
4636212795Sdim                                       bool Virtual, AccessSpecifier Access,
4637218893Sdim                                       TypeSourceInfo *TInfo,
4638218893Sdim                                       SourceLocation EllipsisLoc);
4639212795Sdim
4640212795Sdim  BaseResult ActOnBaseSpecifier(Decl *classdecl,
4641212795Sdim                                SourceRange SpecifierRange,
4642249423Sdim                                ParsedAttributes &Attrs,
4643212795Sdim                                bool Virtual, AccessSpecifier Access,
4644234353Sdim                                ParsedType basetype,
4645218893Sdim                                SourceLocation BaseLoc,
4646218893Sdim                                SourceLocation EllipsisLoc);
4647212795Sdim
4648212795Sdim  bool AttachBaseSpecifiers(CXXRecordDecl *Class, CXXBaseSpecifier **Bases,
4649212795Sdim                            unsigned NumBases);
4650226633Sdim  void ActOnBaseSpecifiers(Decl *ClassDecl, CXXBaseSpecifier **Bases,
4651226633Sdim                           unsigned NumBases);
4652212795Sdim
4653212795Sdim  bool IsDerivedFrom(QualType Derived, QualType Base);
4654212795Sdim  bool IsDerivedFrom(QualType Derived, QualType Base, CXXBasePaths &Paths);
4655212795Sdim
4656212795Sdim  // FIXME: I don't like this name.
4657212795Sdim  void BuildBasePathArray(const CXXBasePaths &Paths, CXXCastPath &BasePath);
4658212795Sdim
4659212795Sdim  bool BasePathInvolvesVirtualBase(const CXXCastPath &BasePath);
4660212795Sdim
4661212795Sdim  bool CheckDerivedToBaseConversion(QualType Derived, QualType Base,
4662212795Sdim                                    SourceLocation Loc, SourceRange Range,
4663212795Sdim                                    CXXCastPath *BasePath = 0,
4664212795Sdim                                    bool IgnoreAccess = false);
4665212795Sdim  bool CheckDerivedToBaseConversion(QualType Derived, QualType Base,
4666212795Sdim                                    unsigned InaccessibleBaseID,
4667212795Sdim                                    unsigned AmbigiousBaseConvID,
4668212795Sdim                                    SourceLocation Loc, SourceRange Range,
4669212795Sdim                                    DeclarationName Name,
4670212795Sdim                                    CXXCastPath *BasePath);
4671212795Sdim
4672212795Sdim  std::string getAmbiguousPathsDisplayString(CXXBasePaths &Paths);
4673212795Sdim
4674249423Sdim  bool CheckOverridingFunctionAttributes(const CXXMethodDecl *New,
4675249423Sdim                                         const CXXMethodDecl *Old);
4676249423Sdim
4677212795Sdim  /// CheckOverridingFunctionReturnType - Checks whether the return types are
4678212795Sdim  /// covariant, according to C++ [class.virtual]p5.
4679212795Sdim  bool CheckOverridingFunctionReturnType(const CXXMethodDecl *New,
4680212795Sdim                                         const CXXMethodDecl *Old);
4681212795Sdim
4682212795Sdim  /// CheckOverridingFunctionExceptionSpec - Checks whether the exception
4683212795Sdim  /// spec is a subset of base spec.
4684212795Sdim  bool CheckOverridingFunctionExceptionSpec(const CXXMethodDecl *New,
4685212795Sdim                                            const CXXMethodDecl *Old);
4686212795Sdim
4687212795Sdim  bool CheckPureMethod(CXXMethodDecl *Method, SourceRange InitRange);
4688212795Sdim
4689239462Sdim  /// CheckOverrideControl - Check C++11 override control semantics.
4690239462Sdim  void CheckOverrideControl(Decl *D);
4691218893Sdim
4692218893Sdim  /// CheckForFunctionMarkedFinal - Checks whether a virtual member function
4693218893Sdim  /// overrides a virtual member function marked 'final', according to
4694239462Sdim  /// C++11 [class.virtual]p4.
4695218893Sdim  bool CheckIfOverriddenFunctionIsMarkedFinal(const CXXMethodDecl *New,
4696218893Sdim                                              const CXXMethodDecl *Old);
4697218893Sdim
4698234353Sdim
4699212795Sdim  //===--------------------------------------------------------------------===//
4700212795Sdim  // C++ Access Control
4701212795Sdim  //
4702212795Sdim
4703212795Sdim  enum AccessResult {
4704212795Sdim    AR_accessible,
4705212795Sdim    AR_inaccessible,
4706212795Sdim    AR_dependent,
4707212795Sdim    AR_delayed
4708212795Sdim  };
4709212795Sdim
4710212795Sdim  bool SetMemberAccessSpecifier(NamedDecl *MemberDecl,
4711212795Sdim                                NamedDecl *PrevMemberDecl,
4712212795Sdim                                AccessSpecifier LexicalAS);
4713212795Sdim
4714212795Sdim  AccessResult CheckUnresolvedMemberAccess(UnresolvedMemberExpr *E,
4715212795Sdim                                           DeclAccessPair FoundDecl);
4716212795Sdim  AccessResult CheckUnresolvedLookupAccess(UnresolvedLookupExpr *E,
4717212795Sdim                                           DeclAccessPair FoundDecl);
4718212795Sdim  AccessResult CheckAllocationAccess(SourceLocation OperatorLoc,
4719212795Sdim                                     SourceRange PlacementRange,
4720212795Sdim                                     CXXRecordDecl *NamingClass,
4721223017Sdim                                     DeclAccessPair FoundDecl,
4722223017Sdim                                     bool Diagnose = true);
4723212795Sdim  AccessResult CheckConstructorAccess(SourceLocation Loc,
4724212795Sdim                                      CXXConstructorDecl *D,
4725212795Sdim                                      const InitializedEntity &Entity,
4726212795Sdim                                      AccessSpecifier Access,
4727212795Sdim                                      bool IsCopyBindingRefToTemp = false);
4728223017Sdim  AccessResult CheckConstructorAccess(SourceLocation Loc,
4729223017Sdim                                      CXXConstructorDecl *D,
4730234353Sdim                                      const InitializedEntity &Entity,
4731223017Sdim                                      AccessSpecifier Access,
4732234353Sdim                                      const PartialDiagnostic &PDiag);
4733212795Sdim  AccessResult CheckDestructorAccess(SourceLocation Loc,
4734212795Sdim                                     CXXDestructorDecl *Dtor,
4735234353Sdim                                     const PartialDiagnostic &PDiag,
4736234353Sdim                                     QualType objectType = QualType());
4737239462Sdim  AccessResult CheckFriendAccess(NamedDecl *D);
4738212795Sdim  AccessResult CheckMemberOperatorAccess(SourceLocation Loc,
4739212795Sdim                                         Expr *ObjectExpr,
4740212795Sdim                                         Expr *ArgExpr,
4741212795Sdim                                         DeclAccessPair FoundDecl);
4742212795Sdim  AccessResult CheckAddressOfMemberAccess(Expr *OvlExpr,
4743212795Sdim                                          DeclAccessPair FoundDecl);
4744212795Sdim  AccessResult CheckBaseClassAccess(SourceLocation AccessLoc,
4745212795Sdim                                    QualType Base, QualType Derived,
4746212795Sdim                                    const CXXBasePath &Path,
4747212795Sdim                                    unsigned DiagID,
4748212795Sdim                                    bool ForceCheck = false,
4749212795Sdim                                    bool ForceUnprivileged = false);
4750212795Sdim  void CheckLookupAccess(const LookupResult &R);
4751234353Sdim  bool IsSimplyAccessible(NamedDecl *decl, DeclContext *Ctx);
4752234353Sdim  bool isSpecialMemberAccessibleForDeletion(CXXMethodDecl *decl,
4753234353Sdim                                            AccessSpecifier access,
4754234353Sdim                                            QualType objectType);
4755212795Sdim
4756212795Sdim  void HandleDependentAccessCheck(const DependentDiagnostic &DD,
4757212795Sdim                         const MultiLevelTemplateArgumentList &TemplateArgs);
4758212795Sdim  void PerformDependentDiagnostics(const DeclContext *Pattern,
4759212795Sdim                        const MultiLevelTemplateArgumentList &TemplateArgs);
4760212795Sdim
4761212795Sdim  void HandleDelayedAccessCheck(sema::DelayedDiagnostic &DD, Decl *Ctx);
4762212795Sdim
4763218893Sdim  /// \brief When true, access checking violations are treated as SFINAE
4764218893Sdim  /// failures rather than hard errors.
4765218893Sdim  bool AccessCheckingSFINAE;
4766234353Sdim
4767212795Sdim  enum AbstractDiagSelID {
4768212795Sdim    AbstractNone = -1,
4769212795Sdim    AbstractReturnType,
4770212795Sdim    AbstractParamType,
4771212795Sdim    AbstractVariableType,
4772212795Sdim    AbstractFieldType,
4773239462Sdim    AbstractIvarType,
4774212795Sdim    AbstractArrayType
4775212795Sdim  };
4776212795Sdim
4777212795Sdim  bool RequireNonAbstractType(SourceLocation Loc, QualType T,
4778239462Sdim                              TypeDiagnoser &Diagnoser);
4779239462Sdim  template<typename T1>
4780239462Sdim  bool RequireNonAbstractType(SourceLocation Loc, QualType T,
4781239462Sdim                              unsigned DiagID,
4782239462Sdim                              const T1 &Arg1) {
4783239462Sdim    BoundTypeDiagnoser1<T1> Diagnoser(DiagID, Arg1);
4784239462Sdim    return RequireNonAbstractType(Loc, T, Diagnoser);
4785239462Sdim  }
4786239462Sdim
4787239462Sdim  template<typename T1, typename T2>
4788239462Sdim  bool RequireNonAbstractType(SourceLocation Loc, QualType T,
4789239462Sdim                              unsigned DiagID,
4790239462Sdim                              const T1 &Arg1, const T2 &Arg2) {
4791239462Sdim    BoundTypeDiagnoser2<T1, T2> Diagnoser(DiagID, Arg1, Arg2);
4792239462Sdim    return RequireNonAbstractType(Loc, T, Diagnoser);
4793239462Sdim  }
4794239462Sdim
4795239462Sdim  template<typename T1, typename T2, typename T3>
4796239462Sdim  bool RequireNonAbstractType(SourceLocation Loc, QualType T,
4797239462Sdim                              unsigned DiagID,
4798239462Sdim                              const T1 &Arg1, const T2 &Arg2, const T3 &Arg3) {
4799239462Sdim    BoundTypeDiagnoser3<T1, T2, T3> Diagnoser(DiagID, Arg1, Arg2, Arg3);
4800239462Sdim    return RequireNonAbstractType(Loc, T, Diagnoser);
4801239462Sdim  }
4802239462Sdim
4803212795Sdim  void DiagnoseAbstractType(const CXXRecordDecl *RD);
4804212795Sdim
4805212795Sdim  bool RequireNonAbstractType(SourceLocation Loc, QualType T, unsigned DiagID,
4806212795Sdim                              AbstractDiagSelID SelID = AbstractNone);
4807212795Sdim
4808212795Sdim  //===--------------------------------------------------------------------===//
4809212795Sdim  // C++ Overloaded Operators [C++ 13.5]
4810212795Sdim  //
4811212795Sdim
4812212795Sdim  bool CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl);
4813212795Sdim
4814212795Sdim  bool CheckLiteralOperatorDeclaration(FunctionDecl *FnDecl);
4815212795Sdim
4816212795Sdim  //===--------------------------------------------------------------------===//
4817212795Sdim  // C++ Templates [C++ 14]
4818212795Sdim  //
4819239462Sdim  void FilterAcceptableTemplateNames(LookupResult &R,
4820234353Sdim                                     bool AllowFunctionTemplates = true);
4821239462Sdim  bool hasAnyAcceptableTemplateNames(LookupResult &R,
4822234353Sdim                                     bool AllowFunctionTemplates = true);
4823234353Sdim
4824212795Sdim  void LookupTemplateName(LookupResult &R, Scope *S, CXXScopeSpec &SS,
4825212795Sdim                          QualType ObjectType, bool EnteringContext,
4826212795Sdim                          bool &MemberOfUnknownSpecialization);
4827212795Sdim
4828212795Sdim  TemplateNameKind isTemplateName(Scope *S,
4829221345Sdim                                  CXXScopeSpec &SS,
4830221345Sdim                                  bool hasTemplateKeyword,
4831221345Sdim                                  UnqualifiedId &Name,
4832221345Sdim                                  ParsedType ObjectType,
4833221345Sdim                                  bool EnteringContext,
4834221345Sdim                                  TemplateTy &Template,
4835221345Sdim                                  bool &MemberOfUnknownSpecialization);
4836212795Sdim
4837212795Sdim  bool DiagnoseUnknownTemplateName(const IdentifierInfo &II,
4838212795Sdim                                   SourceLocation IILoc,
4839212795Sdim                                   Scope *S,
4840212795Sdim                                   const CXXScopeSpec *SS,
4841212795Sdim                                   TemplateTy &SuggestedTemplate,
4842212795Sdim                                   TemplateNameKind &SuggestedKind);
4843212795Sdim
4844234353Sdim  void DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl);
4845212795Sdim  TemplateDecl *AdjustDeclIfTemplate(Decl *&Decl);
4846212795Sdim
4847212795Sdim  Decl *ActOnTypeParameter(Scope *S, bool Typename, bool Ellipsis,
4848212795Sdim                           SourceLocation EllipsisLoc,
4849212795Sdim                           SourceLocation KeyLoc,
4850212795Sdim                           IdentifierInfo *ParamName,
4851212795Sdim                           SourceLocation ParamNameLoc,
4852212795Sdim                           unsigned Depth, unsigned Position,
4853212795Sdim                           SourceLocation EqualLoc,
4854212795Sdim                           ParsedType DefaultArg);
4855212795Sdim
4856212795Sdim  QualType CheckNonTypeTemplateParameterType(QualType T, SourceLocation Loc);
4857212795Sdim  Decl *ActOnNonTypeTemplateParameter(Scope *S, Declarator &D,
4858212795Sdim                                      unsigned Depth,
4859212795Sdim                                      unsigned Position,
4860212795Sdim                                      SourceLocation EqualLoc,
4861212795Sdim                                      Expr *DefaultArg);
4862212795Sdim  Decl *ActOnTemplateTemplateParameter(Scope *S,
4863212795Sdim                                       SourceLocation TmpLoc,
4864226633Sdim                                       TemplateParameterList *Params,
4865218893Sdim                                       SourceLocation EllipsisLoc,
4866212795Sdim                                       IdentifierInfo *ParamName,
4867212795Sdim                                       SourceLocation ParamNameLoc,
4868212795Sdim                                       unsigned Depth,
4869212795Sdim                                       unsigned Position,
4870212795Sdim                                       SourceLocation EqualLoc,
4871218893Sdim                                       ParsedTemplateArgument DefaultArg);
4872212795Sdim
4873226633Sdim  TemplateParameterList *
4874212795Sdim  ActOnTemplateParameterList(unsigned Depth,
4875212795Sdim                             SourceLocation ExportLoc,
4876212795Sdim                             SourceLocation TemplateLoc,
4877212795Sdim                             SourceLocation LAngleLoc,
4878212795Sdim                             Decl **Params, unsigned NumParams,
4879212795Sdim                             SourceLocation RAngleLoc);
4880212795Sdim
4881212795Sdim  /// \brief The context in which we are checking a template parameter
4882212795Sdim  /// list.
4883212795Sdim  enum TemplateParamListContext {
4884212795Sdim    TPC_ClassTemplate,
4885212795Sdim    TPC_FunctionTemplate,
4886212795Sdim    TPC_ClassTemplateMember,
4887218893Sdim    TPC_FriendFunctionTemplate,
4888223017Sdim    TPC_FriendFunctionTemplateDefinition,
4889223017Sdim    TPC_TypeAliasTemplate
4890212795Sdim  };
4891212795Sdim
4892212795Sdim  bool CheckTemplateParameterList(TemplateParameterList *NewParams,
4893212795Sdim                                  TemplateParameterList *OldParams,
4894212795Sdim                                  TemplateParamListContext TPC);
4895212795Sdim  TemplateParameterList *
4896212795Sdim  MatchTemplateParametersToScopeSpecifier(SourceLocation DeclStartLoc,
4897223017Sdim                                          SourceLocation DeclLoc,
4898212795Sdim                                          const CXXScopeSpec &SS,
4899212795Sdim                                          TemplateParameterList **ParamLists,
4900212795Sdim                                          unsigned NumParamLists,
4901212795Sdim                                          bool IsFriend,
4902212795Sdim                                          bool &IsExplicitSpecialization,
4903212795Sdim                                          bool &Invalid);
4904212795Sdim
4905212795Sdim  DeclResult CheckClassTemplate(Scope *S, unsigned TagSpec, TagUseKind TUK,
4906212795Sdim                                SourceLocation KWLoc, CXXScopeSpec &SS,
4907212795Sdim                                IdentifierInfo *Name, SourceLocation NameLoc,
4908212795Sdim                                AttributeList *Attr,
4909212795Sdim                                TemplateParameterList *TemplateParams,
4910234353Sdim                                AccessSpecifier AS,
4911226633Sdim                                SourceLocation ModulePrivateLoc,
4912221345Sdim                                unsigned NumOuterTemplateParamLists,
4913221345Sdim                            TemplateParameterList **OuterTemplateParamLists);
4914212795Sdim
4915212795Sdim  void translateTemplateArguments(const ASTTemplateArgsPtr &In,
4916212795Sdim                                  TemplateArgumentListInfo &Out);
4917212795Sdim
4918221345Sdim  void NoteAllFoundTemplates(TemplateName Name);
4919234353Sdim
4920212795Sdim  QualType CheckTemplateIdType(TemplateName Template,
4921212795Sdim                               SourceLocation TemplateLoc,
4922221345Sdim                              TemplateArgumentListInfo &TemplateArgs);
4923212795Sdim
4924212795Sdim  TypeResult
4925234353Sdim  ActOnTemplateIdType(CXXScopeSpec &SS, SourceLocation TemplateKWLoc,
4926221345Sdim                      TemplateTy Template, SourceLocation TemplateLoc,
4927212795Sdim                      SourceLocation LAngleLoc,
4928212795Sdim                      ASTTemplateArgsPtr TemplateArgs,
4929234353Sdim                      SourceLocation RAngleLoc,
4930234353Sdim                      bool IsCtorOrDtorName = false);
4931212795Sdim
4932221345Sdim  /// \brief Parsed an elaborated-type-specifier that refers to a template-id,
4933221345Sdim  /// such as \c class T::template apply<U>.
4934221345Sdim  TypeResult ActOnTagTemplateIdType(TagUseKind TUK,
4935218893Sdim                                    TypeSpecifierType TagSpec,
4936221345Sdim                                    SourceLocation TagLoc,
4937221345Sdim                                    CXXScopeSpec &SS,
4938234353Sdim                                    SourceLocation TemplateKWLoc,
4939234353Sdim                                    TemplateTy TemplateD,
4940221345Sdim                                    SourceLocation TemplateLoc,
4941221345Sdim                                    SourceLocation LAngleLoc,
4942221345Sdim                                    ASTTemplateArgsPtr TemplateArgsIn,
4943221345Sdim                                    SourceLocation RAngleLoc);
4944212795Sdim
4945234353Sdim
4946212795Sdim  ExprResult BuildTemplateIdExpr(const CXXScopeSpec &SS,
4947234353Sdim                                 SourceLocation TemplateKWLoc,
4948212795Sdim                                 LookupResult &R,
4949212795Sdim                                 bool RequiresADL,
4950234353Sdim                               const TemplateArgumentListInfo *TemplateArgs);
4951234353Sdim
4952212795Sdim  ExprResult BuildQualifiedTemplateIdExpr(CXXScopeSpec &SS,
4953234353Sdim                                          SourceLocation TemplateKWLoc,
4954212795Sdim                               const DeclarationNameInfo &NameInfo,
4955234353Sdim                               const TemplateArgumentListInfo *TemplateArgs);
4956212795Sdim
4957212795Sdim  TemplateNameKind ActOnDependentTemplateName(Scope *S,
4958234353Sdim                                              CXXScopeSpec &SS,
4959212795Sdim                                              SourceLocation TemplateKWLoc,
4960212795Sdim                                              UnqualifiedId &Name,
4961212795Sdim                                              ParsedType ObjectType,
4962212795Sdim                                              bool EnteringContext,
4963212795Sdim                                              TemplateTy &Template);
4964212795Sdim
4965212795Sdim  DeclResult
4966212795Sdim  ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, TagUseKind TUK,
4967212795Sdim                                   SourceLocation KWLoc,
4968226633Sdim                                   SourceLocation ModulePrivateLoc,
4969212795Sdim                                   CXXScopeSpec &SS,
4970212795Sdim                                   TemplateTy Template,
4971212795Sdim                                   SourceLocation TemplateNameLoc,
4972212795Sdim                                   SourceLocation LAngleLoc,
4973212795Sdim                                   ASTTemplateArgsPtr TemplateArgs,
4974212795Sdim                                   SourceLocation RAngleLoc,
4975212795Sdim                                   AttributeList *Attr,
4976212795Sdim                                 MultiTemplateParamsArg TemplateParameterLists);
4977212795Sdim
4978212795Sdim  Decl *ActOnTemplateDeclarator(Scope *S,
4979212795Sdim                                MultiTemplateParamsArg TemplateParameterLists,
4980212795Sdim                                Declarator &D);
4981212795Sdim
4982212795Sdim  Decl *ActOnStartOfFunctionTemplateDef(Scope *FnBodyScope,
4983212795Sdim                                  MultiTemplateParamsArg TemplateParameterLists,
4984212795Sdim                                        Declarator &D);
4985212795Sdim
4986212795Sdim  bool
4987212795Sdim  CheckSpecializationInstantiationRedecl(SourceLocation NewLoc,
4988212795Sdim                                         TemplateSpecializationKind NewTSK,
4989212795Sdim                                         NamedDecl *PrevDecl,
4990212795Sdim                                         TemplateSpecializationKind PrevTSK,
4991212795Sdim                                         SourceLocation PrevPtOfInstantiation,
4992212795Sdim                                         bool &SuppressNew);
4993212795Sdim
4994212795Sdim  bool CheckDependentFunctionTemplateSpecialization(FunctionDecl *FD,
4995212795Sdim                    const TemplateArgumentListInfo &ExplicitTemplateArgs,
4996212795Sdim                                                    LookupResult &Previous);
4997212795Sdim
4998212795Sdim  bool CheckFunctionTemplateSpecialization(FunctionDecl *FD,
4999221345Sdim                         TemplateArgumentListInfo *ExplicitTemplateArgs,
5000212795Sdim                                           LookupResult &Previous);
5001212795Sdim  bool CheckMemberSpecialization(NamedDecl *Member, LookupResult &Previous);
5002212795Sdim
5003212795Sdim  DeclResult
5004212795Sdim  ActOnExplicitInstantiation(Scope *S,
5005212795Sdim                             SourceLocation ExternLoc,
5006212795Sdim                             SourceLocation TemplateLoc,
5007212795Sdim                             unsigned TagSpec,
5008212795Sdim                             SourceLocation KWLoc,
5009212795Sdim                             const CXXScopeSpec &SS,
5010212795Sdim                             TemplateTy Template,
5011212795Sdim                             SourceLocation TemplateNameLoc,
5012212795Sdim                             SourceLocation LAngleLoc,
5013212795Sdim                             ASTTemplateArgsPtr TemplateArgs,
5014212795Sdim                             SourceLocation RAngleLoc,
5015212795Sdim                             AttributeList *Attr);
5016212795Sdim
5017212795Sdim  DeclResult
5018212795Sdim  ActOnExplicitInstantiation(Scope *S,
5019212795Sdim                             SourceLocation ExternLoc,
5020212795Sdim                             SourceLocation TemplateLoc,
5021212795Sdim                             unsigned TagSpec,
5022212795Sdim                             SourceLocation KWLoc,
5023212795Sdim                             CXXScopeSpec &SS,
5024212795Sdim                             IdentifierInfo *Name,
5025212795Sdim                             SourceLocation NameLoc,
5026212795Sdim                             AttributeList *Attr);
5027212795Sdim
5028212795Sdim  DeclResult ActOnExplicitInstantiation(Scope *S,
5029212795Sdim                                        SourceLocation ExternLoc,
5030212795Sdim                                        SourceLocation TemplateLoc,
5031212795Sdim                                        Declarator &D);
5032212795Sdim
5033212795Sdim  TemplateArgumentLoc
5034212795Sdim  SubstDefaultTemplateArgumentIfAvailable(TemplateDecl *Template,
5035212795Sdim                                          SourceLocation TemplateLoc,
5036212795Sdim                                          SourceLocation RAngleLoc,
5037212795Sdim                                          Decl *Param,
5038226633Sdim                          SmallVectorImpl<TemplateArgument> &Converted);
5039212795Sdim
5040212795Sdim  /// \brief Specifies the context in which a particular template
5041212795Sdim  /// argument is being checked.
5042212795Sdim  enum CheckTemplateArgumentKind {
5043212795Sdim    /// \brief The template argument was specified in the code or was
5044212795Sdim    /// instantiated with some deduced template arguments.
5045212795Sdim    CTAK_Specified,
5046212795Sdim
5047212795Sdim    /// \brief The template argument was deduced via template argument
5048212795Sdim    /// deduction.
5049212795Sdim    CTAK_Deduced,
5050212795Sdim
5051212795Sdim    /// \brief The template argument was deduced from an array bound
5052212795Sdim    /// via template argument deduction.
5053212795Sdim    CTAK_DeducedFromArrayBound
5054212795Sdim  };
5055212795Sdim
5056212795Sdim  bool CheckTemplateArgument(NamedDecl *Param,
5057212795Sdim                             const TemplateArgumentLoc &Arg,
5058218893Sdim                             NamedDecl *Template,
5059212795Sdim                             SourceLocation TemplateLoc,
5060212795Sdim                             SourceLocation RAngleLoc,
5061218893Sdim                             unsigned ArgumentPackIndex,
5062226633Sdim                           SmallVectorImpl<TemplateArgument> &Converted,
5063212795Sdim                             CheckTemplateArgumentKind CTAK = CTAK_Specified);
5064212795Sdim
5065221345Sdim  /// \brief Check that the given template arguments can be be provided to
5066221345Sdim  /// the given template, converting the arguments along the way.
5067221345Sdim  ///
5068221345Sdim  /// \param Template The template to which the template arguments are being
5069221345Sdim  /// provided.
5070221345Sdim  ///
5071221345Sdim  /// \param TemplateLoc The location of the template name in the source.
5072221345Sdim  ///
5073221345Sdim  /// \param TemplateArgs The list of template arguments. If the template is
5074221345Sdim  /// a template template parameter, this function may extend the set of
5075221345Sdim  /// template arguments to also include substituted, defaulted template
5076221345Sdim  /// arguments.
5077221345Sdim  ///
5078221345Sdim  /// \param PartialTemplateArgs True if the list of template arguments is
5079221345Sdim  /// intentionally partial, e.g., because we're checking just the initial
5080221345Sdim  /// set of template arguments.
5081221345Sdim  ///
5082221345Sdim  /// \param Converted Will receive the converted, canonicalized template
5083221345Sdim  /// arguments.
5084221345Sdim  ///
5085234353Sdim  ///
5086234353Sdim  /// \param ExpansionIntoFixedList If non-NULL, will be set true to indicate
5087234353Sdim  /// when the template arguments contain a pack expansion that is being
5088234353Sdim  /// expanded into a fixed parameter list.
5089234353Sdim  ///
5090221345Sdim  /// \returns True if an error occurred, false otherwise.
5091212795Sdim  bool CheckTemplateArgumentList(TemplateDecl *Template,
5092212795Sdim                                 SourceLocation TemplateLoc,
5093221345Sdim                                 TemplateArgumentListInfo &TemplateArgs,
5094212795Sdim                                 bool PartialTemplateArgs,
5095234353Sdim                           SmallVectorImpl<TemplateArgument> &Converted,
5096234353Sdim                                 bool *ExpansionIntoFixedList = 0);
5097212795Sdim
5098212795Sdim  bool CheckTemplateTypeArgument(TemplateTypeParmDecl *Param,
5099212795Sdim                                 const TemplateArgumentLoc &Arg,
5100226633Sdim                           SmallVectorImpl<TemplateArgument> &Converted);
5101212795Sdim
5102212795Sdim  bool CheckTemplateArgument(TemplateTypeParmDecl *Param,
5103212795Sdim                             TypeSourceInfo *Arg);
5104221345Sdim  ExprResult CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
5105221345Sdim                                   QualType InstantiatedParamType, Expr *Arg,
5106221345Sdim                                   TemplateArgument &Converted,
5107234353Sdim                               CheckTemplateArgumentKind CTAK = CTAK_Specified);
5108212795Sdim  bool CheckTemplateArgument(TemplateTemplateParmDecl *Param,
5109243830Sdim                             const TemplateArgumentLoc &Arg,
5110243830Sdim                             unsigned ArgumentPackIndex);
5111212795Sdim
5112212795Sdim  ExprResult
5113212795Sdim  BuildExpressionFromDeclTemplateArgument(const TemplateArgument &Arg,
5114212795Sdim                                          QualType ParamType,
5115212795Sdim                                          SourceLocation Loc);
5116212795Sdim  ExprResult
5117212795Sdim  BuildExpressionFromIntegralTemplateArgument(const TemplateArgument &Arg,
5118212795Sdim                                              SourceLocation Loc);
5119212795Sdim
5120212795Sdim  /// \brief Enumeration describing how template parameter lists are compared
5121212795Sdim  /// for equality.
5122212795Sdim  enum TemplateParameterListEqualKind {
5123212795Sdim    /// \brief We are matching the template parameter lists of two templates
5124212795Sdim    /// that might be redeclarations.
5125212795Sdim    ///
5126212795Sdim    /// \code
5127212795Sdim    /// template<typename T> struct X;
5128212795Sdim    /// template<typename T> struct X;
5129212795Sdim    /// \endcode
5130212795Sdim    TPL_TemplateMatch,
5131212795Sdim
5132212795Sdim    /// \brief We are matching the template parameter lists of two template
5133212795Sdim    /// template parameters as part of matching the template parameter lists
5134212795Sdim    /// of two templates that might be redeclarations.
5135212795Sdim    ///
5136212795Sdim    /// \code
5137212795Sdim    /// template<template<int I> class TT> struct X;
5138212795Sdim    /// template<template<int Value> class Other> struct X;
5139212795Sdim    /// \endcode
5140212795Sdim    TPL_TemplateTemplateParmMatch,
5141212795Sdim
5142212795Sdim    /// \brief We are matching the template parameter lists of a template
5143212795Sdim    /// template argument against the template parameter lists of a template
5144212795Sdim    /// template parameter.
5145212795Sdim    ///
5146212795Sdim    /// \code
5147212795Sdim    /// template<template<int Value> class Metafun> struct X;
5148212795Sdim    /// template<int Value> struct integer_c;
5149212795Sdim    /// X<integer_c> xic;
5150212795Sdim    /// \endcode
5151212795Sdim    TPL_TemplateTemplateArgumentMatch
5152212795Sdim  };
5153212795Sdim
5154212795Sdim  bool TemplateParameterListsAreEqual(TemplateParameterList *New,
5155212795Sdim                                      TemplateParameterList *Old,
5156212795Sdim                                      bool Complain,
5157212795Sdim                                      TemplateParameterListEqualKind Kind,
5158212795Sdim                                      SourceLocation TemplateArgLoc
5159212795Sdim                                        = SourceLocation());
5160212795Sdim
5161212795Sdim  bool CheckTemplateDeclScope(Scope *S, TemplateParameterList *TemplateParams);
5162212795Sdim
5163212795Sdim  /// \brief Called when the parser has parsed a C++ typename
5164212795Sdim  /// specifier, e.g., "typename T::type".
5165212795Sdim  ///
5166212795Sdim  /// \param S The scope in which this typename type occurs.
5167212795Sdim  /// \param TypenameLoc the location of the 'typename' keyword
5168212795Sdim  /// \param SS the nested-name-specifier following the typename (e.g., 'T::').
5169212795Sdim  /// \param II the identifier we're retrieving (e.g., 'type' in the example).
5170212795Sdim  /// \param IdLoc the location of the identifier.
5171212795Sdim  TypeResult
5172234353Sdim  ActOnTypenameType(Scope *S, SourceLocation TypenameLoc,
5173234353Sdim                    const CXXScopeSpec &SS, const IdentifierInfo &II,
5174212795Sdim                    SourceLocation IdLoc);
5175212795Sdim
5176212795Sdim  /// \brief Called when the parser has parsed a C++ typename
5177212795Sdim  /// specifier that ends in a template-id, e.g.,
5178212795Sdim  /// "typename MetaFun::template apply<T1, T2>".
5179212795Sdim  ///
5180212795Sdim  /// \param S The scope in which this typename type occurs.
5181212795Sdim  /// \param TypenameLoc the location of the 'typename' keyword
5182212795Sdim  /// \param SS the nested-name-specifier following the typename (e.g., 'T::').
5183212795Sdim  /// \param TemplateLoc the location of the 'template' keyword, if any.
5184221345Sdim  /// \param TemplateName The template name.
5185221345Sdim  /// \param TemplateNameLoc The location of the template name.
5186221345Sdim  /// \param LAngleLoc The location of the opening angle bracket  ('<').
5187221345Sdim  /// \param TemplateArgs The template arguments.
5188221345Sdim  /// \param RAngleLoc The location of the closing angle bracket  ('>').
5189212795Sdim  TypeResult
5190234353Sdim  ActOnTypenameType(Scope *S, SourceLocation TypenameLoc,
5191234353Sdim                    const CXXScopeSpec &SS,
5192234353Sdim                    SourceLocation TemplateLoc,
5193239462Sdim                    TemplateTy TemplateName,
5194221345Sdim                    SourceLocation TemplateNameLoc,
5195221345Sdim                    SourceLocation LAngleLoc,
5196221345Sdim                    ASTTemplateArgsPtr TemplateArgs,
5197221345Sdim                    SourceLocation RAngleLoc);
5198212795Sdim
5199212795Sdim  QualType CheckTypenameType(ElaboratedTypeKeyword Keyword,
5200221345Sdim                             SourceLocation KeywordLoc,
5201221345Sdim                             NestedNameSpecifierLoc QualifierLoc,
5202212795Sdim                             const IdentifierInfo &II,
5203212795Sdim                             SourceLocation IILoc);
5204212795Sdim
5205212795Sdim  TypeSourceInfo *RebuildTypeInCurrentInstantiation(TypeSourceInfo *T,
5206212795Sdim                                                    SourceLocation Loc,
5207212795Sdim                                                    DeclarationName Name);
5208212795Sdim  bool RebuildNestedNameSpecifierInCurrentInstantiation(CXXScopeSpec &SS);
5209212795Sdim
5210212795Sdim  ExprResult RebuildExprInCurrentInstantiation(Expr *E);
5211226633Sdim  bool RebuildTemplateParamsInCurrentInstantiation(
5212226633Sdim                                                TemplateParameterList *Params);
5213234353Sdim
5214212795Sdim  std::string
5215212795Sdim  getTemplateArgumentBindingsText(const TemplateParameterList *Params,
5216212795Sdim                                  const TemplateArgumentList &Args);
5217212795Sdim
5218212795Sdim  std::string
5219212795Sdim  getTemplateArgumentBindingsText(const TemplateParameterList *Params,
5220212795Sdim                                  const TemplateArgument *Args,
5221212795Sdim                                  unsigned NumArgs);
5222212795Sdim
5223218893Sdim  //===--------------------------------------------------------------------===//
5224218893Sdim  // C++ Variadic Templates (C++0x [temp.variadic])
5225218893Sdim  //===--------------------------------------------------------------------===//
5226218893Sdim
5227218893Sdim  /// \brief The context in which an unexpanded parameter pack is
5228218893Sdim  /// being diagnosed.
5229218893Sdim  ///
5230218893Sdim  /// Note that the values of this enumeration line up with the first
5231218893Sdim  /// argument to the \c err_unexpanded_parameter_pack diagnostic.
5232218893Sdim  enum UnexpandedParameterPackContext {
5233218893Sdim    /// \brief An arbitrary expression.
5234218893Sdim    UPPC_Expression = 0,
5235218893Sdim
5236218893Sdim    /// \brief The base type of a class type.
5237218893Sdim    UPPC_BaseType,
5238218893Sdim
5239218893Sdim    /// \brief The type of an arbitrary declaration.
5240218893Sdim    UPPC_DeclarationType,
5241218893Sdim
5242218893Sdim    /// \brief The type of a data member.
5243218893Sdim    UPPC_DataMemberType,
5244218893Sdim
5245218893Sdim    /// \brief The size of a bit-field.
5246218893Sdim    UPPC_BitFieldWidth,
5247218893Sdim
5248218893Sdim    /// \brief The expression in a static assertion.
5249218893Sdim    UPPC_StaticAssertExpression,
5250218893Sdim
5251218893Sdim    /// \brief The fixed underlying type of an enumeration.
5252218893Sdim    UPPC_FixedUnderlyingType,
5253218893Sdim
5254218893Sdim    /// \brief The enumerator value.
5255218893Sdim    UPPC_EnumeratorValue,
5256218893Sdim
5257218893Sdim    /// \brief A using declaration.
5258218893Sdim    UPPC_UsingDeclaration,
5259218893Sdim
5260218893Sdim    /// \brief A friend declaration.
5261218893Sdim    UPPC_FriendDeclaration,
5262218893Sdim
5263218893Sdim    /// \brief A declaration qualifier.
5264218893Sdim    UPPC_DeclarationQualifier,
5265218893Sdim
5266218893Sdim    /// \brief An initializer.
5267218893Sdim    UPPC_Initializer,
5268234353Sdim
5269218893Sdim    /// \brief A default argument.
5270218893Sdim    UPPC_DefaultArgument,
5271234353Sdim
5272218893Sdim    /// \brief The type of a non-type template parameter.
5273218893Sdim    UPPC_NonTypeTemplateParameterType,
5274218893Sdim
5275218893Sdim    /// \brief The type of an exception.
5276218893Sdim    UPPC_ExceptionType,
5277234353Sdim
5278218893Sdim    /// \brief Partial specialization.
5279234353Sdim    UPPC_PartialSpecialization,
5280218893Sdim
5281234353Sdim    /// \brief Microsoft __if_exists.
5282234353Sdim    UPPC_IfExists,
5283234353Sdim
5284234353Sdim    /// \brief Microsoft __if_not_exists.
5285239462Sdim    UPPC_IfNotExists,
5286239462Sdim
5287239462Sdim    /// \brief Lambda expression.
5288239462Sdim    UPPC_Lambda,
5289239462Sdim
5290239462Sdim    /// \brief Block expression,
5291239462Sdim    UPPC_Block
5292234353Sdim};
5293234353Sdim
5294234353Sdim  /// \brief Diagnose unexpanded parameter packs.
5295234353Sdim  ///
5296234353Sdim  /// \param Loc The location at which we should emit the diagnostic.
5297234353Sdim  ///
5298234353Sdim  /// \param UPPC The context in which we are diagnosing unexpanded
5299234353Sdim  /// parameter packs.
5300234353Sdim  ///
5301234353Sdim  /// \param Unexpanded the set of unexpanded parameter packs.
5302239462Sdim  ///
5303239462Sdim  /// \returns true if an error occurred, false otherwise.
5304239462Sdim  bool DiagnoseUnexpandedParameterPacks(SourceLocation Loc,
5305234353Sdim                                        UnexpandedParameterPackContext UPPC,
5306234353Sdim                                  ArrayRef<UnexpandedParameterPack> Unexpanded);
5307234353Sdim
5308218893Sdim  /// \brief If the given type contains an unexpanded parameter pack,
5309218893Sdim  /// diagnose the error.
5310218893Sdim  ///
5311218893Sdim  /// \param Loc The source location where a diagnostc should be emitted.
5312218893Sdim  ///
5313218893Sdim  /// \param T The type that is being checked for unexpanded parameter
5314218893Sdim  /// packs.
5315218893Sdim  ///
5316221345Sdim  /// \returns true if an error occurred, false otherwise.
5317218893Sdim  bool DiagnoseUnexpandedParameterPack(SourceLocation Loc, TypeSourceInfo *T,
5318218893Sdim                                       UnexpandedParameterPackContext UPPC);
5319218893Sdim
5320218893Sdim  /// \brief If the given expression contains an unexpanded parameter
5321218893Sdim  /// pack, diagnose the error.
5322218893Sdim  ///
5323218893Sdim  /// \param E The expression that is being checked for unexpanded
5324218893Sdim  /// parameter packs.
5325218893Sdim  ///
5326221345Sdim  /// \returns true if an error occurred, false otherwise.
5327218893Sdim  bool DiagnoseUnexpandedParameterPack(Expr *E,
5328218893Sdim                       UnexpandedParameterPackContext UPPC = UPPC_Expression);
5329218893Sdim
5330218893Sdim  /// \brief If the given nested-name-specifier contains an unexpanded
5331218893Sdim  /// parameter pack, diagnose the error.
5332218893Sdim  ///
5333218893Sdim  /// \param SS The nested-name-specifier that is being checked for
5334218893Sdim  /// unexpanded parameter packs.
5335218893Sdim  ///
5336221345Sdim  /// \returns true if an error occurred, false otherwise.
5337218893Sdim  bool DiagnoseUnexpandedParameterPack(const CXXScopeSpec &SS,
5338218893Sdim                                       UnexpandedParameterPackContext UPPC);
5339218893Sdim
5340218893Sdim  /// \brief If the given name contains an unexpanded parameter pack,
5341218893Sdim  /// diagnose the error.
5342218893Sdim  ///
5343218893Sdim  /// \param NameInfo The name (with source location information) that
5344218893Sdim  /// is being checked for unexpanded parameter packs.
5345218893Sdim  ///
5346221345Sdim  /// \returns true if an error occurred, false otherwise.
5347218893Sdim  bool DiagnoseUnexpandedParameterPack(const DeclarationNameInfo &NameInfo,
5348218893Sdim                                       UnexpandedParameterPackContext UPPC);
5349218893Sdim
5350218893Sdim  /// \brief If the given template name contains an unexpanded parameter pack,
5351218893Sdim  /// diagnose the error.
5352218893Sdim  ///
5353218893Sdim  /// \param Loc The location of the template name.
5354218893Sdim  ///
5355234353Sdim  /// \param Template The template name that is being checked for unexpanded
5356218893Sdim  /// parameter packs.
5357218893Sdim  ///
5358221345Sdim  /// \returns true if an error occurred, false otherwise.
5359218893Sdim  bool DiagnoseUnexpandedParameterPack(SourceLocation Loc,
5360218893Sdim                                       TemplateName Template,
5361218893Sdim                                       UnexpandedParameterPackContext UPPC);
5362218893Sdim
5363234353Sdim  /// \brief If the given template argument contains an unexpanded parameter
5364218893Sdim  /// pack, diagnose the error.
5365218893Sdim  ///
5366234353Sdim  /// \param Arg The template argument that is being checked for unexpanded
5367218893Sdim  /// parameter packs.
5368218893Sdim  ///
5369221345Sdim  /// \returns true if an error occurred, false otherwise.
5370218893Sdim  bool DiagnoseUnexpandedParameterPack(TemplateArgumentLoc Arg,
5371218893Sdim                                       UnexpandedParameterPackContext UPPC);
5372234353Sdim
5373218893Sdim  /// \brief Collect the set of unexpanded parameter packs within the given
5374234353Sdim  /// template argument.
5375218893Sdim  ///
5376218893Sdim  /// \param Arg The template argument that will be traversed to find
5377218893Sdim  /// unexpanded parameter packs.
5378218893Sdim  void collectUnexpandedParameterPacks(TemplateArgument Arg,
5379226633Sdim                   SmallVectorImpl<UnexpandedParameterPack> &Unexpanded);
5380218893Sdim
5381218893Sdim  /// \brief Collect the set of unexpanded parameter packs within the given
5382234353Sdim  /// template argument.
5383218893Sdim  ///
5384218893Sdim  /// \param Arg The template argument that will be traversed to find
5385218893Sdim  /// unexpanded parameter packs.
5386218893Sdim  void collectUnexpandedParameterPacks(TemplateArgumentLoc Arg,
5387226633Sdim                    SmallVectorImpl<UnexpandedParameterPack> &Unexpanded);
5388218893Sdim
5389218893Sdim  /// \brief Collect the set of unexpanded parameter packs within the given
5390234353Sdim  /// type.
5391218893Sdim  ///
5392218893Sdim  /// \param T The type that will be traversed to find
5393218893Sdim  /// unexpanded parameter packs.
5394218893Sdim  void collectUnexpandedParameterPacks(QualType T,
5395226633Sdim                   SmallVectorImpl<UnexpandedParameterPack> &Unexpanded);
5396218893Sdim
5397218893Sdim  /// \brief Collect the set of unexpanded parameter packs within the given
5398234353Sdim  /// type.
5399218893Sdim  ///
5400218893Sdim  /// \param TL The type that will be traversed to find
5401218893Sdim  /// unexpanded parameter packs.
5402218893Sdim  void collectUnexpandedParameterPacks(TypeLoc TL,
5403226633Sdim                   SmallVectorImpl<UnexpandedParameterPack> &Unexpanded);
5404218893Sdim
5405234353Sdim  /// \brief Collect the set of unexpanded parameter packs within the given
5406234353Sdim  /// nested-name-specifier.
5407234353Sdim  ///
5408234353Sdim  /// \param SS The nested-name-specifier that will be traversed to find
5409234353Sdim  /// unexpanded parameter packs.
5410234353Sdim  void collectUnexpandedParameterPacks(CXXScopeSpec &SS,
5411234353Sdim                         SmallVectorImpl<UnexpandedParameterPack> &Unexpanded);
5412234353Sdim
5413234353Sdim  /// \brief Collect the set of unexpanded parameter packs within the given
5414234353Sdim  /// name.
5415234353Sdim  ///
5416234353Sdim  /// \param NameInfo The name that will be traversed to find
5417234353Sdim  /// unexpanded parameter packs.
5418234353Sdim  void collectUnexpandedParameterPacks(const DeclarationNameInfo &NameInfo,
5419234353Sdim                         SmallVectorImpl<UnexpandedParameterPack> &Unexpanded);
5420234353Sdim
5421218893Sdim  /// \brief Invoked when parsing a template argument followed by an
5422218893Sdim  /// ellipsis, which creates a pack expansion.
5423218893Sdim  ///
5424218893Sdim  /// \param Arg The template argument preceding the ellipsis, which
5425218893Sdim  /// may already be invalid.
5426218893Sdim  ///
5427218893Sdim  /// \param EllipsisLoc The location of the ellipsis.
5428218893Sdim  ParsedTemplateArgument ActOnPackExpansion(const ParsedTemplateArgument &Arg,
5429218893Sdim                                            SourceLocation EllipsisLoc);
5430218893Sdim
5431218893Sdim  /// \brief Invoked when parsing a type followed by an ellipsis, which
5432218893Sdim  /// creates a pack expansion.
5433218893Sdim  ///
5434218893Sdim  /// \param Type The type preceding the ellipsis, which will become
5435218893Sdim  /// the pattern of the pack expansion.
5436218893Sdim  ///
5437218893Sdim  /// \param EllipsisLoc The location of the ellipsis.
5438218893Sdim  TypeResult ActOnPackExpansion(ParsedType Type, SourceLocation EllipsisLoc);
5439218893Sdim
5440218893Sdim  /// \brief Construct a pack expansion type from the pattern of the pack
5441218893Sdim  /// expansion.
5442218893Sdim  TypeSourceInfo *CheckPackExpansion(TypeSourceInfo *Pattern,
5443218893Sdim                                     SourceLocation EllipsisLoc,
5444249423Sdim                                     Optional<unsigned> NumExpansions);
5445218893Sdim
5446218893Sdim  /// \brief Construct a pack expansion type from the pattern of the pack
5447218893Sdim  /// expansion.
5448218893Sdim  QualType CheckPackExpansion(QualType Pattern,
5449218893Sdim                              SourceRange PatternRange,
5450218893Sdim                              SourceLocation EllipsisLoc,
5451249423Sdim                              Optional<unsigned> NumExpansions);
5452218893Sdim
5453218893Sdim  /// \brief Invoked when parsing an expression followed by an ellipsis, which
5454218893Sdim  /// creates a pack expansion.
5455218893Sdim  ///
5456218893Sdim  /// \param Pattern The expression preceding the ellipsis, which will become
5457218893Sdim  /// the pattern of the pack expansion.
5458218893Sdim  ///
5459218893Sdim  /// \param EllipsisLoc The location of the ellipsis.
5460218893Sdim  ExprResult ActOnPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc);
5461218893Sdim
5462218893Sdim  /// \brief Invoked when parsing an expression followed by an ellipsis, which
5463218893Sdim  /// creates a pack expansion.
5464218893Sdim  ///
5465218893Sdim  /// \param Pattern The expression preceding the ellipsis, which will become
5466218893Sdim  /// the pattern of the pack expansion.
5467218893Sdim  ///
5468218893Sdim  /// \param EllipsisLoc The location of the ellipsis.
5469218893Sdim  ExprResult CheckPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
5470249423Sdim                                Optional<unsigned> NumExpansions);
5471218893Sdim
5472218893Sdim  /// \brief Determine whether we could expand a pack expansion with the
5473218893Sdim  /// given set of parameter packs into separate arguments by repeatedly
5474218893Sdim  /// transforming the pattern.
5475218893Sdim  ///
5476218893Sdim  /// \param EllipsisLoc The location of the ellipsis that identifies the
5477218893Sdim  /// pack expansion.
5478218893Sdim  ///
5479218893Sdim  /// \param PatternRange The source range that covers the entire pattern of
5480218893Sdim  /// the pack expansion.
5481218893Sdim  ///
5482234353Sdim  /// \param Unexpanded The set of unexpanded parameter packs within the
5483218893Sdim  /// pattern.
5484218893Sdim  ///
5485218893Sdim  /// \param ShouldExpand Will be set to \c true if the transformer should
5486218893Sdim  /// expand the corresponding pack expansions into separate arguments. When
5487218893Sdim  /// set, \c NumExpansions must also be set.
5488218893Sdim  ///
5489218893Sdim  /// \param RetainExpansion Whether the caller should add an unexpanded
5490218893Sdim  /// pack expansion after all of the expanded arguments. This is used
5491218893Sdim  /// when extending explicitly-specified template argument packs per
5492218893Sdim  /// C++0x [temp.arg.explicit]p9.
5493218893Sdim  ///
5494218893Sdim  /// \param NumExpansions The number of separate arguments that will be in
5495218893Sdim  /// the expanded form of the corresponding pack expansion. This is both an
5496218893Sdim  /// input and an output parameter, which can be set by the caller if the
5497218893Sdim  /// number of expansions is known a priori (e.g., due to a prior substitution)
5498218893Sdim  /// and will be set by the callee when the number of expansions is known.
5499218893Sdim  /// The callee must set this value when \c ShouldExpand is \c true; it may
5500218893Sdim  /// set this value in other cases.
5501218893Sdim  ///
5502234353Sdim  /// \returns true if an error occurred (e.g., because the parameter packs
5503234353Sdim  /// are to be instantiated with arguments of different lengths), false
5504234353Sdim  /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
5505218893Sdim  /// must be set.
5506218893Sdim  bool CheckParameterPacksForExpansion(SourceLocation EllipsisLoc,
5507218893Sdim                                       SourceRange PatternRange,
5508249423Sdim                             ArrayRef<UnexpandedParameterPack> Unexpanded,
5509218893Sdim                             const MultiLevelTemplateArgumentList &TemplateArgs,
5510218893Sdim                                       bool &ShouldExpand,
5511218893Sdim                                       bool &RetainExpansion,
5512249423Sdim                                       Optional<unsigned> &NumExpansions);
5513218893Sdim
5514218893Sdim  /// \brief Determine the number of arguments in the given pack expansion
5515218893Sdim  /// type.
5516218893Sdim  ///
5517239462Sdim  /// This routine assumes that the number of arguments in the expansion is
5518218893Sdim  /// consistent across all of the unexpanded parameter packs in its pattern.
5519239462Sdim  ///
5520239462Sdim  /// Returns an empty Optional if the type can't be expanded.
5521249423Sdim  Optional<unsigned> getNumArgumentsInExpansion(QualType T,
5522249423Sdim      const MultiLevelTemplateArgumentList &TemplateArgs);
5523234353Sdim
5524218893Sdim  /// \brief Determine whether the given declarator contains any unexpanded
5525218893Sdim  /// parameter packs.
5526218893Sdim  ///
5527218893Sdim  /// This routine is used by the parser to disambiguate function declarators
5528218893Sdim  /// with an ellipsis prior to the ')', e.g.,
5529218893Sdim  ///
5530218893Sdim  /// \code
5531218893Sdim  ///   void f(T...);
5532218893Sdim  /// \endcode
5533218893Sdim  ///
5534218893Sdim  /// To determine whether we have an (unnamed) function parameter pack or
5535218893Sdim  /// a variadic function.
5536218893Sdim  ///
5537218893Sdim  /// \returns true if the declarator contains any unexpanded parameter packs,
5538218893Sdim  /// false otherwise.
5539218893Sdim  bool containsUnexpandedParameterPacks(Declarator &D);
5540234353Sdim
5541218893Sdim  //===--------------------------------------------------------------------===//
5542218893Sdim  // C++ Template Argument Deduction (C++ [temp.deduct])
5543218893Sdim  //===--------------------------------------------------------------------===//
5544234353Sdim
5545212795Sdim  /// \brief Describes the result of template argument deduction.
5546212795Sdim  ///
5547212795Sdim  /// The TemplateDeductionResult enumeration describes the result of
5548212795Sdim  /// template argument deduction, as returned from
5549212795Sdim  /// DeduceTemplateArguments(). The separate TemplateDeductionInfo
5550212795Sdim  /// structure provides additional information about the results of
5551212795Sdim  /// template argument deduction, e.g., the deduced template argument
5552212795Sdim  /// list (if successful) or the specific template parameters or
5553212795Sdim  /// deduced arguments that were involved in the failure.
5554212795Sdim  enum TemplateDeductionResult {
5555212795Sdim    /// \brief Template argument deduction was successful.
5556212795Sdim    TDK_Success = 0,
5557243830Sdim    /// \brief The declaration was invalid; do nothing.
5558243830Sdim    TDK_Invalid,
5559212795Sdim    /// \brief Template argument deduction exceeded the maximum template
5560212795Sdim    /// instantiation depth (which has already been diagnosed).
5561212795Sdim    TDK_InstantiationDepth,
5562212795Sdim    /// \brief Template argument deduction did not deduce a value
5563212795Sdim    /// for every template parameter.
5564212795Sdim    TDK_Incomplete,
5565212795Sdim    /// \brief Template argument deduction produced inconsistent
5566212795Sdim    /// deduced values for the given template parameter.
5567212795Sdim    TDK_Inconsistent,
5568212795Sdim    /// \brief Template argument deduction failed due to inconsistent
5569212795Sdim    /// cv-qualifiers on a template parameter type that would
5570212795Sdim    /// otherwise be deduced, e.g., we tried to deduce T in "const T"
5571212795Sdim    /// but were given a non-const "X".
5572212795Sdim    TDK_Underqualified,
5573212795Sdim    /// \brief Substitution of the deduced template argument values
5574212795Sdim    /// resulted in an error.
5575212795Sdim    TDK_SubstitutionFailure,
5576249423Sdim    /// \brief A non-depnedent component of the parameter did not match the
5577249423Sdim    /// corresponding component of the argument.
5578212795Sdim    TDK_NonDeducedMismatch,
5579212795Sdim    /// \brief When performing template argument deduction for a function
5580212795Sdim    /// template, there were too many call arguments.
5581212795Sdim    TDK_TooManyArguments,
5582212795Sdim    /// \brief When performing template argument deduction for a function
5583212795Sdim    /// template, there were too few call arguments.
5584212795Sdim    TDK_TooFewArguments,
5585212795Sdim    /// \brief The explicitly-specified template arguments were not valid
5586212795Sdim    /// template arguments for the given template.
5587212795Sdim    TDK_InvalidExplicitArguments,
5588212795Sdim    /// \brief The arguments included an overloaded function name that could
5589212795Sdim    /// not be resolved to a suitable function.
5590249423Sdim    TDK_FailedOverloadResolution,
5591249423Sdim    /// \brief Deduction failed; that's all we know.
5592249423Sdim    TDK_MiscellaneousDeductionFailure
5593212795Sdim  };
5594212795Sdim
5595212795Sdim  TemplateDeductionResult
5596212795Sdim  DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial,
5597212795Sdim                          const TemplateArgumentList &TemplateArgs,
5598212795Sdim                          sema::TemplateDeductionInfo &Info);
5599212795Sdim
5600212795Sdim  TemplateDeductionResult
5601212795Sdim  SubstituteExplicitTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
5602221345Sdim                              TemplateArgumentListInfo &ExplicitTemplateArgs,
5603226633Sdim                      SmallVectorImpl<DeducedTemplateArgument> &Deduced,
5604226633Sdim                                 SmallVectorImpl<QualType> &ParamTypes,
5605212795Sdim                                      QualType *FunctionType,
5606212795Sdim                                      sema::TemplateDeductionInfo &Info);
5607212795Sdim
5608234353Sdim  /// brief A function argument from which we performed template argument
5609224145Sdim  // deduction for a call.
5610224145Sdim  struct OriginalCallArg {
5611224145Sdim    OriginalCallArg(QualType OriginalParamType,
5612224145Sdim                    unsigned ArgIdx,
5613224145Sdim                    QualType OriginalArgType)
5614234353Sdim      : OriginalParamType(OriginalParamType), ArgIdx(ArgIdx),
5615224145Sdim        OriginalArgType(OriginalArgType) { }
5616234353Sdim
5617224145Sdim    QualType OriginalParamType;
5618224145Sdim    unsigned ArgIdx;
5619224145Sdim    QualType OriginalArgType;
5620224145Sdim  };
5621234353Sdim
5622212795Sdim  TemplateDeductionResult
5623212795Sdim  FinishTemplateArgumentDeduction(FunctionTemplateDecl *FunctionTemplate,
5624226633Sdim                      SmallVectorImpl<DeducedTemplateArgument> &Deduced,
5625212795Sdim                                  unsigned NumExplicitlySpecified,
5626212795Sdim                                  FunctionDecl *&Specialization,
5627224145Sdim                                  sema::TemplateDeductionInfo &Info,
5628226633Sdim           SmallVectorImpl<OriginalCallArg> const *OriginalCallArgs = 0);
5629212795Sdim
5630212795Sdim  TemplateDeductionResult
5631212795Sdim  DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
5632221345Sdim                          TemplateArgumentListInfo *ExplicitTemplateArgs,
5633249423Sdim                          ArrayRef<Expr *> Args,
5634212795Sdim                          FunctionDecl *&Specialization,
5635212795Sdim                          sema::TemplateDeductionInfo &Info);
5636212795Sdim
5637212795Sdim  TemplateDeductionResult
5638212795Sdim  DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
5639221345Sdim                          TemplateArgumentListInfo *ExplicitTemplateArgs,
5640212795Sdim                          QualType ArgFunctionType,
5641212795Sdim                          FunctionDecl *&Specialization,
5642251662Sdim                          sema::TemplateDeductionInfo &Info,
5643251662Sdim                          bool InOverloadResolution = false);
5644212795Sdim
5645212795Sdim  TemplateDeductionResult
5646212795Sdim  DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
5647212795Sdim                          QualType ToType,
5648212795Sdim                          CXXConversionDecl *&Specialization,
5649212795Sdim                          sema::TemplateDeductionInfo &Info);
5650212795Sdim
5651212795Sdim  TemplateDeductionResult
5652212795Sdim  DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
5653221345Sdim                          TemplateArgumentListInfo *ExplicitTemplateArgs,
5654212795Sdim                          FunctionDecl *&Specialization,
5655251662Sdim                          sema::TemplateDeductionInfo &Info,
5656251662Sdim                          bool InOverloadResolution = false);
5657212795Sdim
5658234353Sdim  /// \brief Result type of DeduceAutoType.
5659234353Sdim  enum DeduceAutoResult {
5660234353Sdim    DAR_Succeeded,
5661234353Sdim    DAR_Failed,
5662234353Sdim    DAR_FailedAlreadyDiagnosed
5663234353Sdim  };
5664218893Sdim
5665234353Sdim  DeduceAutoResult DeduceAutoType(TypeSourceInfo *AutoType, Expr *&Initializer,
5666251662Sdim                                  QualType &Result);
5667251662Sdim  DeduceAutoResult DeduceAutoType(TypeLoc AutoTypeLoc, Expr *&Initializer,
5668251662Sdim                                  QualType &Result);
5669251662Sdim  QualType SubstAutoType(QualType TypeWithAuto, QualType Replacement);
5670234353Sdim  void DiagnoseAutoDeductionFailure(VarDecl *VDecl, Expr *Init);
5671251662Sdim  bool DeduceReturnType(FunctionDecl *FD, SourceLocation Loc,
5672251662Sdim                        bool Diagnose = true);
5673234353Sdim
5674251662Sdim  bool DeduceFunctionTypeFromReturnExpr(FunctionDecl *FD,
5675251662Sdim                                        SourceLocation ReturnLoc,
5676251662Sdim                                        Expr *&RetExpr, AutoType *AT);
5677251662Sdim
5678212795Sdim  FunctionTemplateDecl *getMoreSpecializedTemplate(FunctionTemplateDecl *FT1,
5679212795Sdim                                                   FunctionTemplateDecl *FT2,
5680212795Sdim                                                   SourceLocation Loc,
5681218893Sdim                                           TemplatePartialOrderingContext TPOC,
5682218893Sdim                                                   unsigned NumCallArguments);
5683212795Sdim  UnresolvedSetIterator getMostSpecialized(UnresolvedSetIterator SBegin,
5684212795Sdim                                           UnresolvedSetIterator SEnd,
5685212795Sdim                                           TemplatePartialOrderingContext TPOC,
5686218893Sdim                                           unsigned NumCallArguments,
5687212795Sdim                                           SourceLocation Loc,
5688212795Sdim                                           const PartialDiagnostic &NoneDiag,
5689212795Sdim                                           const PartialDiagnostic &AmbigDiag,
5690218893Sdim                                        const PartialDiagnostic &CandidateDiag,
5691234353Sdim                                        bool Complain = true,
5692234353Sdim                                        QualType TargetType = QualType());
5693212795Sdim
5694212795Sdim  ClassTemplatePartialSpecializationDecl *
5695212795Sdim  getMoreSpecializedPartialSpecialization(
5696212795Sdim                                  ClassTemplatePartialSpecializationDecl *PS1,
5697212795Sdim                                  ClassTemplatePartialSpecializationDecl *PS2,
5698212795Sdim                                  SourceLocation Loc);
5699212795Sdim
5700212795Sdim  void MarkUsedTemplateParameters(const TemplateArgumentList &TemplateArgs,
5701212795Sdim                                  bool OnlyDeduced,
5702212795Sdim                                  unsigned Depth,
5703234353Sdim                                  llvm::SmallBitVector &Used);
5704249423Sdim  void MarkDeducedTemplateParameters(
5705249423Sdim                                  const FunctionTemplateDecl *FunctionTemplate,
5706249423Sdim                                  llvm::SmallBitVector &Deduced) {
5707234353Sdim    return MarkDeducedTemplateParameters(Context, FunctionTemplate, Deduced);
5708234353Sdim  }
5709234353Sdim  static void MarkDeducedTemplateParameters(ASTContext &Ctx,
5710249423Sdim                                  const FunctionTemplateDecl *FunctionTemplate,
5711249423Sdim                                  llvm::SmallBitVector &Deduced);
5712212795Sdim
5713212795Sdim  //===--------------------------------------------------------------------===//
5714212795Sdim  // C++ Template Instantiation
5715212795Sdim  //
5716212795Sdim
5717212795Sdim  MultiLevelTemplateArgumentList getTemplateInstantiationArgs(NamedDecl *D,
5718212795Sdim                                     const TemplateArgumentList *Innermost = 0,
5719212795Sdim                                                bool RelativeToPrimary = false,
5720212795Sdim                                               const FunctionDecl *Pattern = 0);
5721212795Sdim
5722212795Sdim  /// \brief A template instantiation that is currently in progress.
5723212795Sdim  struct ActiveTemplateInstantiation {
5724212795Sdim    /// \brief The kind of template instantiation we are performing
5725212795Sdim    enum InstantiationKind {
5726212795Sdim      /// We are instantiating a template declaration. The entity is
5727212795Sdim      /// the declaration we're instantiating (e.g., a CXXRecordDecl).
5728212795Sdim      TemplateInstantiation,
5729212795Sdim
5730212795Sdim      /// We are instantiating a default argument for a template
5731212795Sdim      /// parameter. The Entity is the template, and
5732212795Sdim      /// TemplateArgs/NumTemplateArguments provides the template
5733212795Sdim      /// arguments as specified.
5734212795Sdim      /// FIXME: Use a TemplateArgumentList
5735212795Sdim      DefaultTemplateArgumentInstantiation,
5736212795Sdim
5737212795Sdim      /// We are instantiating a default argument for a function.
5738212795Sdim      /// The Entity is the ParmVarDecl, and TemplateArgs/NumTemplateArgs
5739212795Sdim      /// provides the template arguments as specified.
5740212795Sdim      DefaultFunctionArgumentInstantiation,
5741212795Sdim
5742212795Sdim      /// We are substituting explicit template arguments provided for
5743212795Sdim      /// a function template. The entity is a FunctionTemplateDecl.
5744212795Sdim      ExplicitTemplateArgumentSubstitution,
5745212795Sdim
5746212795Sdim      /// We are substituting template argument determined as part of
5747212795Sdim      /// template argument deduction for either a class template
5748212795Sdim      /// partial specialization or a function template. The
5749212795Sdim      /// Entity is either a ClassTemplatePartialSpecializationDecl or
5750212795Sdim      /// a FunctionTemplateDecl.
5751212795Sdim      DeducedTemplateArgumentSubstitution,
5752212795Sdim
5753212795Sdim      /// We are substituting prior template arguments into a new
5754212795Sdim      /// template parameter. The template parameter itself is either a
5755212795Sdim      /// NonTypeTemplateParmDecl or a TemplateTemplateParmDecl.
5756212795Sdim      PriorTemplateArgumentSubstitution,
5757212795Sdim
5758212795Sdim      /// We are checking the validity of a default template argument that
5759212795Sdim      /// has been used when naming a template-id.
5760234982Sdim      DefaultTemplateArgumentChecking,
5761234982Sdim
5762234982Sdim      /// We are instantiating the exception specification for a function
5763234982Sdim      /// template which was deferred until it was needed.
5764234982Sdim      ExceptionSpecInstantiation
5765212795Sdim    } Kind;
5766212795Sdim
5767212795Sdim    /// \brief The point of instantiation within the source code.
5768212795Sdim    SourceLocation PointOfInstantiation;
5769212795Sdim
5770234353Sdim    /// \brief The template (or partial specialization) in which we are
5771234353Sdim    /// performing the instantiation, for substitutions of prior template
5772218893Sdim    /// arguments.
5773218893Sdim    NamedDecl *Template;
5774212795Sdim
5775212795Sdim    /// \brief The entity that is being instantiated.
5776249423Sdim    Decl *Entity;
5777212795Sdim
5778212795Sdim    /// \brief The list of template arguments we are substituting, if they
5779212795Sdim    /// are not part of the entity.
5780212795Sdim    const TemplateArgument *TemplateArgs;
5781212795Sdim
5782212795Sdim    /// \brief The number of template arguments in TemplateArgs.
5783212795Sdim    unsigned NumTemplateArgs;
5784212795Sdim
5785234353Sdim    /// \brief The template deduction info object associated with the
5786218893Sdim    /// substitution or checking of explicit or deduced template arguments.
5787218893Sdim    sema::TemplateDeductionInfo *DeductionInfo;
5788218893Sdim
5789212795Sdim    /// \brief The source range that covers the construct that cause
5790212795Sdim    /// the instantiation, e.g., the template-id that causes a class
5791212795Sdim    /// template instantiation.
5792212795Sdim    SourceRange InstantiationRange;
5793212795Sdim
5794212795Sdim    ActiveTemplateInstantiation()
5795212795Sdim      : Kind(TemplateInstantiation), Template(0), Entity(0), TemplateArgs(0),
5796218893Sdim        NumTemplateArgs(0), DeductionInfo(0) {}
5797212795Sdim
5798212795Sdim    /// \brief Determines whether this template is an actual instantiation
5799212795Sdim    /// that should be counted toward the maximum instantiation depth.
5800212795Sdim    bool isInstantiationRecord() const;
5801212795Sdim
5802212795Sdim    friend bool operator==(const ActiveTemplateInstantiation &X,
5803212795Sdim                           const ActiveTemplateInstantiation &Y) {
5804212795Sdim      if (X.Kind != Y.Kind)
5805212795Sdim        return false;
5806212795Sdim
5807212795Sdim      if (X.Entity != Y.Entity)
5808212795Sdim        return false;
5809212795Sdim
5810212795Sdim      switch (X.Kind) {
5811212795Sdim      case TemplateInstantiation:
5812234982Sdim      case ExceptionSpecInstantiation:
5813212795Sdim        return true;
5814212795Sdim
5815212795Sdim      case PriorTemplateArgumentSubstitution:
5816212795Sdim      case DefaultTemplateArgumentChecking:
5817212795Sdim        if (X.Template != Y.Template)
5818212795Sdim          return false;
5819212795Sdim
5820212795Sdim        // Fall through
5821212795Sdim
5822212795Sdim      case DefaultTemplateArgumentInstantiation:
5823212795Sdim      case ExplicitTemplateArgumentSubstitution:
5824212795Sdim      case DeducedTemplateArgumentSubstitution:
5825212795Sdim      case DefaultFunctionArgumentInstantiation:
5826212795Sdim        return X.TemplateArgs == Y.TemplateArgs;
5827212795Sdim
5828212795Sdim      }
5829212795Sdim
5830234353Sdim      llvm_unreachable("Invalid InstantiationKind!");
5831212795Sdim    }
5832212795Sdim
5833212795Sdim    friend bool operator!=(const ActiveTemplateInstantiation &X,
5834212795Sdim                           const ActiveTemplateInstantiation &Y) {
5835212795Sdim      return !(X == Y);
5836212795Sdim    }
5837212795Sdim  };
5838212795Sdim
5839212795Sdim  /// \brief List of active template instantiations.
5840212795Sdim  ///
5841212795Sdim  /// This vector is treated as a stack. As one template instantiation
5842212795Sdim  /// requires another template instantiation, additional
5843212795Sdim  /// instantiations are pushed onto the stack up to a
5844212795Sdim  /// user-configurable limit LangOptions::InstantiationDepth.
5845226633Sdim  SmallVector<ActiveTemplateInstantiation, 16>
5846212795Sdim    ActiveTemplateInstantiations;
5847212795Sdim
5848218893Sdim  /// \brief Whether we are in a SFINAE context that is not associated with
5849218893Sdim  /// template instantiation.
5850218893Sdim  ///
5851218893Sdim  /// This is used when setting up a SFINAE trap (\c see SFINAETrap) outside
5852218893Sdim  /// of a template instantiation or template argument deduction.
5853218893Sdim  bool InNonInstantiationSFINAEContext;
5854234353Sdim
5855212795Sdim  /// \brief The number of ActiveTemplateInstantiation entries in
5856212795Sdim  /// \c ActiveTemplateInstantiations that are not actual instantiations and,
5857212795Sdim  /// therefore, should not be counted as part of the instantiation depth.
5858212795Sdim  unsigned NonInstantiationEntries;
5859212795Sdim
5860212795Sdim  /// \brief The last template from which a template instantiation
5861212795Sdim  /// error or warning was produced.
5862212795Sdim  ///
5863212795Sdim  /// This value is used to suppress printing of redundant template
5864212795Sdim  /// instantiation backtraces when there are multiple errors in the
5865212795Sdim  /// same instantiation. FIXME: Does this belong in Sema? It's tough
5866212795Sdim  /// to implement it anywhere else.
5867212795Sdim  ActiveTemplateInstantiation LastTemplateInstantiationErrorContext;
5868212795Sdim
5869218893Sdim  /// \brief The current index into pack expansion arguments that will be
5870218893Sdim  /// used for substitution of parameter packs.
5871218893Sdim  ///
5872234353Sdim  /// The pack expansion index will be -1 to indicate that parameter packs
5873218893Sdim  /// should be instantiated as themselves. Otherwise, the index specifies
5874218893Sdim  /// which argument within the parameter pack will be used for substitution.
5875218893Sdim  int ArgumentPackSubstitutionIndex;
5876218893Sdim
5877218893Sdim  /// \brief RAII object used to change the argument pack substitution index
5878218893Sdim  /// within a \c Sema object.
5879218893Sdim  ///
5880218893Sdim  /// See \c ArgumentPackSubstitutionIndex for more information.
5881218893Sdim  class ArgumentPackSubstitutionIndexRAII {
5882218893Sdim    Sema &Self;
5883218893Sdim    int OldSubstitutionIndex;
5884234353Sdim
5885218893Sdim  public:
5886218893Sdim    ArgumentPackSubstitutionIndexRAII(Sema &Self, int NewSubstitutionIndex)
5887218893Sdim      : Self(Self), OldSubstitutionIndex(Self.ArgumentPackSubstitutionIndex) {
5888218893Sdim      Self.ArgumentPackSubstitutionIndex = NewSubstitutionIndex;
5889218893Sdim    }
5890234353Sdim
5891218893Sdim    ~ArgumentPackSubstitutionIndexRAII() {
5892218893Sdim      Self.ArgumentPackSubstitutionIndex = OldSubstitutionIndex;
5893218893Sdim    }
5894218893Sdim  };
5895234353Sdim
5896218893Sdim  friend class ArgumentPackSubstitutionRAII;
5897234353Sdim
5898212795Sdim  /// \brief The stack of calls expression undergoing template instantiation.
5899212795Sdim  ///
5900212795Sdim  /// The top of this stack is used by a fixit instantiating unresolved
5901212795Sdim  /// function calls to fix the AST to match the textual change it prints.
5902226633Sdim  SmallVector<CallExpr *, 8> CallsUndergoingInstantiation;
5903234353Sdim
5904218893Sdim  /// \brief For each declaration that involved template argument deduction, the
5905218893Sdim  /// set of diagnostics that were suppressed during that template argument
5906218893Sdim  /// deduction.
5907218893Sdim  ///
5908218893Sdim  /// FIXME: Serialize this structure to the AST file.
5909226633Sdim  llvm::DenseMap<Decl *, SmallVector<PartialDiagnosticAt, 1> >
5910218893Sdim    SuppressedDiagnostics;
5911234353Sdim
5912212795Sdim  /// \brief A stack object to be created when performing template
5913212795Sdim  /// instantiation.
5914212795Sdim  ///
5915212795Sdim  /// Construction of an object of type \c InstantiatingTemplate
5916212795Sdim  /// pushes the current instantiation onto the stack of active
5917212795Sdim  /// instantiations. If the size of this stack exceeds the maximum
5918212795Sdim  /// number of recursive template instantiations, construction
5919212795Sdim  /// produces an error and evaluates true.
5920212795Sdim  ///
5921212795Sdim  /// Destruction of this object will pop the named instantiation off
5922212795Sdim  /// the stack.
5923212795Sdim  struct InstantiatingTemplate {
5924212795Sdim    /// \brief Note that we are instantiating a class template,
5925212795Sdim    /// function template, or a member thereof.
5926212795Sdim    InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
5927212795Sdim                          Decl *Entity,
5928212795Sdim                          SourceRange InstantiationRange = SourceRange());
5929212795Sdim
5930234982Sdim    struct ExceptionSpecification {};
5931234982Sdim    /// \brief Note that we are instantiating an exception specification
5932234982Sdim    /// of a function template.
5933234982Sdim    InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
5934234982Sdim                          FunctionDecl *Entity, ExceptionSpecification,
5935234982Sdim                          SourceRange InstantiationRange = SourceRange());
5936234982Sdim
5937212795Sdim    /// \brief Note that we are instantiating a default argument in a
5938212795Sdim    /// template-id.
5939212795Sdim    InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
5940212795Sdim                          TemplateDecl *Template,
5941239462Sdim                          ArrayRef<TemplateArgument> TemplateArgs,
5942212795Sdim                          SourceRange InstantiationRange = SourceRange());
5943212795Sdim
5944212795Sdim    /// \brief Note that we are instantiating a default argument in a
5945212795Sdim    /// template-id.
5946212795Sdim    InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
5947212795Sdim                          FunctionTemplateDecl *FunctionTemplate,
5948239462Sdim                          ArrayRef<TemplateArgument> TemplateArgs,
5949212795Sdim                          ActiveTemplateInstantiation::InstantiationKind Kind,
5950218893Sdim                          sema::TemplateDeductionInfo &DeductionInfo,
5951212795Sdim                          SourceRange InstantiationRange = SourceRange());
5952212795Sdim
5953212795Sdim    /// \brief Note that we are instantiating as part of template
5954212795Sdim    /// argument deduction for a class template partial
5955212795Sdim    /// specialization.
5956212795Sdim    InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
5957212795Sdim                          ClassTemplatePartialSpecializationDecl *PartialSpec,
5958239462Sdim                          ArrayRef<TemplateArgument> TemplateArgs,
5959218893Sdim                          sema::TemplateDeductionInfo &DeductionInfo,
5960212795Sdim                          SourceRange InstantiationRange = SourceRange());
5961212795Sdim
5962212795Sdim    InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
5963212795Sdim                          ParmVarDecl *Param,
5964239462Sdim                          ArrayRef<TemplateArgument> TemplateArgs,
5965212795Sdim                          SourceRange InstantiationRange = SourceRange());
5966212795Sdim
5967212795Sdim    /// \brief Note that we are substituting prior template arguments into a
5968212795Sdim    /// non-type or template template parameter.
5969212795Sdim    InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
5970218893Sdim                          NamedDecl *Template,
5971212795Sdim                          NonTypeTemplateParmDecl *Param,
5972239462Sdim                          ArrayRef<TemplateArgument> TemplateArgs,
5973212795Sdim                          SourceRange InstantiationRange);
5974212795Sdim
5975212795Sdim    InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
5976218893Sdim                          NamedDecl *Template,
5977212795Sdim                          TemplateTemplateParmDecl *Param,
5978239462Sdim                          ArrayRef<TemplateArgument> TemplateArgs,
5979212795Sdim                          SourceRange InstantiationRange);
5980212795Sdim
5981212795Sdim    /// \brief Note that we are checking the default template argument
5982212795Sdim    /// against the template parameter for a given template-id.
5983212795Sdim    InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
5984212795Sdim                          TemplateDecl *Template,
5985212795Sdim                          NamedDecl *Param,
5986239462Sdim                          ArrayRef<TemplateArgument> TemplateArgs,
5987212795Sdim                          SourceRange InstantiationRange);
5988212795Sdim
5989212795Sdim
5990212795Sdim    /// \brief Note that we have finished instantiating this template.
5991212795Sdim    void Clear();
5992212795Sdim
5993212795Sdim    ~InstantiatingTemplate() { Clear(); }
5994212795Sdim
5995212795Sdim    /// \brief Determines whether we have exceeded the maximum
5996212795Sdim    /// recursive template instantiations.
5997212795Sdim    operator bool() const { return Invalid; }
5998212795Sdim
5999212795Sdim  private:
6000212795Sdim    Sema &SemaRef;
6001212795Sdim    bool Invalid;
6002218893Sdim    bool SavedInNonInstantiationSFINAEContext;
6003212795Sdim    bool CheckInstantiationDepth(SourceLocation PointOfInstantiation,
6004212795Sdim                                 SourceRange InstantiationRange);
6005212795Sdim
6006243830Sdim    InstantiatingTemplate(const InstantiatingTemplate&) LLVM_DELETED_FUNCTION;
6007212795Sdim
6008212795Sdim    InstantiatingTemplate&
6009243830Sdim    operator=(const InstantiatingTemplate&) LLVM_DELETED_FUNCTION;
6010212795Sdim  };
6011212795Sdim
6012212795Sdim  void PrintInstantiationStack();
6013234353Sdim
6014212795Sdim  /// \brief Determines whether we are currently in a context where
6015212795Sdim  /// template argument substitution failures are not considered
6016212795Sdim  /// errors.
6017212795Sdim  ///
6018249423Sdim  /// \returns An empty \c Optional if we're not in a SFINAE context.
6019234353Sdim  /// Otherwise, contains a pointer that, if non-NULL, contains the nearest
6020234353Sdim  /// template-deduction context object, which can be used to capture
6021234353Sdim  /// diagnostics that will be suppressed.
6022249423Sdim  Optional<sema::TemplateDeductionInfo *> isSFINAEContext() const;
6023212795Sdim
6024239462Sdim  /// \brief Determines whether we are currently in a context that
6025239462Sdim  /// is not evaluated as per C++ [expr] p5.
6026239462Sdim  bool isUnevaluatedContext() const {
6027239462Sdim    assert(!ExprEvalContexts.empty() &&
6028239462Sdim           "Must be in an expression evaluation context");
6029251662Sdim    return ExprEvalContexts.back().isUnevaluated();
6030239462Sdim  }
6031239462Sdim
6032212795Sdim  /// \brief RAII class used to determine whether SFINAE has
6033212795Sdim  /// trapped any errors that occur during template argument
6034218893Sdim  /// deduction.`
6035212795Sdim  class SFINAETrap {
6036212795Sdim    Sema &SemaRef;
6037212795Sdim    unsigned PrevSFINAEErrors;
6038218893Sdim    bool PrevInNonInstantiationSFINAEContext;
6039218893Sdim    bool PrevAccessCheckingSFINAE;
6040234353Sdim
6041212795Sdim  public:
6042218893Sdim    explicit SFINAETrap(Sema &SemaRef, bool AccessCheckingSFINAE = false)
6043218893Sdim      : SemaRef(SemaRef), PrevSFINAEErrors(SemaRef.NumSFINAEErrors),
6044218893Sdim        PrevInNonInstantiationSFINAEContext(
6045218893Sdim                                      SemaRef.InNonInstantiationSFINAEContext),
6046218893Sdim        PrevAccessCheckingSFINAE(SemaRef.AccessCheckingSFINAE)
6047234353Sdim    {
6048218893Sdim      if (!SemaRef.isSFINAEContext())
6049218893Sdim        SemaRef.InNonInstantiationSFINAEContext = true;
6050218893Sdim      SemaRef.AccessCheckingSFINAE = AccessCheckingSFINAE;
6051218893Sdim    }
6052212795Sdim
6053234353Sdim    ~SFINAETrap() {
6054234353Sdim      SemaRef.NumSFINAEErrors = PrevSFINAEErrors;
6055234353Sdim      SemaRef.InNonInstantiationSFINAEContext
6056218893Sdim        = PrevInNonInstantiationSFINAEContext;
6057218893Sdim      SemaRef.AccessCheckingSFINAE = PrevAccessCheckingSFINAE;
6058218893Sdim    }
6059212795Sdim
6060212795Sdim    /// \brief Determine whether any SFINAE errors have been trapped.
6061212795Sdim    bool hasErrorOccurred() const {
6062212795Sdim      return SemaRef.NumSFINAEErrors > PrevSFINAEErrors;
6063212795Sdim    }
6064212795Sdim  };
6065212795Sdim
6066212795Sdim  /// \brief The current instantiation scope used to store local
6067212795Sdim  /// variables.
6068212795Sdim  LocalInstantiationScope *CurrentInstantiationScope;
6069212795Sdim
6070212795Sdim  /// \brief The number of typos corrected by CorrectTypo.
6071212795Sdim  unsigned TyposCorrected;
6072212795Sdim
6073224145Sdim  typedef llvm::DenseMap<IdentifierInfo *, TypoCorrection>
6074218893Sdim    UnqualifiedTyposCorrectedMap;
6075234353Sdim
6076218893Sdim  /// \brief A cache containing the results of typo correction for unqualified
6077218893Sdim  /// name lookup.
6078218893Sdim  ///
6079218893Sdim  /// The string is the string that we corrected to (which may be empty, if
6080218893Sdim  /// there was no correction), while the boolean will be true when the
6081218893Sdim  /// string represents a keyword.
6082218893Sdim  UnqualifiedTyposCorrectedMap UnqualifiedTyposCorrected;
6083234353Sdim
6084212795Sdim  /// \brief Worker object for performing CFG-based warnings.
6085212795Sdim  sema::AnalysisBasedWarnings AnalysisWarnings;
6086212795Sdim
6087212795Sdim  /// \brief An entity for which implicit template instantiation is required.
6088212795Sdim  ///
6089212795Sdim  /// The source location associated with the declaration is the first place in
6090212795Sdim  /// the source code where the declaration was "used". It is not necessarily
6091212795Sdim  /// the point of instantiation (which will be either before or after the
6092212795Sdim  /// namespace-scope declaration that triggered this implicit instantiation),
6093212795Sdim  /// However, it is the location that diagnostics should generally refer to,
6094212795Sdim  /// because users will need to know what code triggered the instantiation.
6095212795Sdim  typedef std::pair<ValueDecl *, SourceLocation> PendingImplicitInstantiation;
6096212795Sdim
6097212795Sdim  /// \brief The queue of implicit template instantiations that are required
6098212795Sdim  /// but have not yet been performed.
6099212795Sdim  std::deque<PendingImplicitInstantiation> PendingInstantiations;
6100212795Sdim
6101212795Sdim  /// \brief The queue of implicit template instantiations that are required
6102212795Sdim  /// and must be performed within the current local scope.
6103212795Sdim  ///
6104212795Sdim  /// This queue is only used for member functions of local classes in
6105212795Sdim  /// templates, which must be instantiated in the same scope as their
6106212795Sdim  /// enclosing function, so that they can reference function-local
6107212795Sdim  /// types, static variables, enumerators, etc.
6108212795Sdim  std::deque<PendingImplicitInstantiation> PendingLocalImplicitInstantiations;
6109212795Sdim
6110223017Sdim  void PerformPendingInstantiations(bool LocalOnly = false);
6111212795Sdim
6112212795Sdim  TypeSourceInfo *SubstType(TypeSourceInfo *T,
6113212795Sdim                            const MultiLevelTemplateArgumentList &TemplateArgs,
6114212795Sdim                            SourceLocation Loc, DeclarationName Entity);
6115212795Sdim
6116212795Sdim  QualType SubstType(QualType T,
6117212795Sdim                     const MultiLevelTemplateArgumentList &TemplateArgs,
6118212795Sdim                     SourceLocation Loc, DeclarationName Entity);
6119212795Sdim
6120218893Sdim  TypeSourceInfo *SubstType(TypeLoc TL,
6121218893Sdim                            const MultiLevelTemplateArgumentList &TemplateArgs,
6122218893Sdim                            SourceLocation Loc, DeclarationName Entity);
6123218893Sdim
6124212795Sdim  TypeSourceInfo *SubstFunctionDeclType(TypeSourceInfo *T,
6125212795Sdim                            const MultiLevelTemplateArgumentList &TemplateArgs,
6126212795Sdim                                        SourceLocation Loc,
6127234982Sdim                                        DeclarationName Entity,
6128234982Sdim                                        CXXRecordDecl *ThisContext,
6129234982Sdim                                        unsigned ThisTypeQuals);
6130212795Sdim  ParmVarDecl *SubstParmVarDecl(ParmVarDecl *D,
6131218893Sdim                            const MultiLevelTemplateArgumentList &TemplateArgs,
6132221345Sdim                                int indexAdjustment,
6133249423Sdim                                Optional<unsigned> NumExpansions,
6134234353Sdim                                bool ExpectParameterPack);
6135234353Sdim  bool SubstParmTypes(SourceLocation Loc,
6136218893Sdim                      ParmVarDecl **Params, unsigned NumParams,
6137218893Sdim                      const MultiLevelTemplateArgumentList &TemplateArgs,
6138226633Sdim                      SmallVectorImpl<QualType> &ParamTypes,
6139226633Sdim                      SmallVectorImpl<ParmVarDecl *> *OutParams = 0);
6140212795Sdim  ExprResult SubstExpr(Expr *E,
6141212795Sdim                       const MultiLevelTemplateArgumentList &TemplateArgs);
6142234353Sdim
6143218893Sdim  /// \brief Substitute the given template arguments into a list of
6144218893Sdim  /// expressions, expanding pack expansions if required.
6145218893Sdim  ///
6146218893Sdim  /// \param Exprs The list of expressions to substitute into.
6147218893Sdim  ///
6148218893Sdim  /// \param NumExprs The number of expressions in \p Exprs.
6149218893Sdim  ///
6150218893Sdim  /// \param IsCall Whether this is some form of call, in which case
6151218893Sdim  /// default arguments will be dropped.
6152218893Sdim  ///
6153218893Sdim  /// \param TemplateArgs The set of template arguments to substitute.
6154218893Sdim  ///
6155218893Sdim  /// \param Outputs Will receive all of the substituted arguments.
6156218893Sdim  ///
6157218893Sdim  /// \returns true if an error occurred, false otherwise.
6158218893Sdim  bool SubstExprs(Expr **Exprs, unsigned NumExprs, bool IsCall,
6159218893Sdim                  const MultiLevelTemplateArgumentList &TemplateArgs,
6160226633Sdim                  SmallVectorImpl<Expr *> &Outputs);
6161212795Sdim
6162212795Sdim  StmtResult SubstStmt(Stmt *S,
6163212795Sdim                       const MultiLevelTemplateArgumentList &TemplateArgs);
6164212795Sdim
6165212795Sdim  Decl *SubstDecl(Decl *D, DeclContext *Owner,
6166212795Sdim                  const MultiLevelTemplateArgumentList &TemplateArgs);
6167212795Sdim
6168234353Sdim  ExprResult SubstInitializer(Expr *E,
6169234353Sdim                       const MultiLevelTemplateArgumentList &TemplateArgs,
6170234353Sdim                       bool CXXDirectInit);
6171234353Sdim
6172212795Sdim  bool
6173212795Sdim  SubstBaseSpecifiers(CXXRecordDecl *Instantiation,
6174212795Sdim                      CXXRecordDecl *Pattern,
6175212795Sdim                      const MultiLevelTemplateArgumentList &TemplateArgs);
6176212795Sdim
6177212795Sdim  bool
6178212795Sdim  InstantiateClass(SourceLocation PointOfInstantiation,
6179212795Sdim                   CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern,
6180212795Sdim                   const MultiLevelTemplateArgumentList &TemplateArgs,
6181212795Sdim                   TemplateSpecializationKind TSK,
6182212795Sdim                   bool Complain = true);
6183212795Sdim
6184234353Sdim  bool InstantiateEnum(SourceLocation PointOfInstantiation,
6185234353Sdim                       EnumDecl *Instantiation, EnumDecl *Pattern,
6186234353Sdim                       const MultiLevelTemplateArgumentList &TemplateArgs,
6187234353Sdim                       TemplateSpecializationKind TSK);
6188234353Sdim
6189234353Sdim  struct LateInstantiatedAttribute {
6190234353Sdim    const Attr *TmplAttr;
6191234353Sdim    LocalInstantiationScope *Scope;
6192234353Sdim    Decl *NewDecl;
6193234353Sdim
6194234353Sdim    LateInstantiatedAttribute(const Attr *A, LocalInstantiationScope *S,
6195234353Sdim                              Decl *D)
6196234353Sdim      : TmplAttr(A), Scope(S), NewDecl(D)
6197234353Sdim    { }
6198234353Sdim  };
6199234353Sdim  typedef SmallVector<LateInstantiatedAttribute, 16> LateInstantiatedAttrVec;
6200234353Sdim
6201212795Sdim  void InstantiateAttrs(const MultiLevelTemplateArgumentList &TemplateArgs,
6202234353Sdim                        const Decl *Pattern, Decl *Inst,
6203234353Sdim                        LateInstantiatedAttrVec *LateAttrs = 0,
6204234353Sdim                        LocalInstantiationScope *OuterMostScope = 0);
6205212795Sdim
6206212795Sdim  bool
6207212795Sdim  InstantiateClassTemplateSpecialization(SourceLocation PointOfInstantiation,
6208212795Sdim                           ClassTemplateSpecializationDecl *ClassTemplateSpec,
6209212795Sdim                           TemplateSpecializationKind TSK,
6210212795Sdim                           bool Complain = true);
6211212795Sdim
6212212795Sdim  void InstantiateClassMembers(SourceLocation PointOfInstantiation,
6213212795Sdim                               CXXRecordDecl *Instantiation,
6214212795Sdim                            const MultiLevelTemplateArgumentList &TemplateArgs,
6215212795Sdim                               TemplateSpecializationKind TSK);
6216212795Sdim
6217212795Sdim  void InstantiateClassTemplateSpecializationMembers(
6218212795Sdim                                          SourceLocation PointOfInstantiation,
6219212795Sdim                           ClassTemplateSpecializationDecl *ClassTemplateSpec,
6220212795Sdim                                                TemplateSpecializationKind TSK);
6221212795Sdim
6222219077Sdim  NestedNameSpecifierLoc
6223219077Sdim  SubstNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
6224219077Sdim                           const MultiLevelTemplateArgumentList &TemplateArgs);
6225219077Sdim
6226212795Sdim  DeclarationNameInfo
6227212795Sdim  SubstDeclarationNameInfo(const DeclarationNameInfo &NameInfo,
6228212795Sdim                           const MultiLevelTemplateArgumentList &TemplateArgs);
6229212795Sdim  TemplateName
6230234353Sdim  SubstTemplateName(NestedNameSpecifierLoc QualifierLoc, TemplateName Name,
6231221345Sdim                    SourceLocation Loc,
6232212795Sdim                    const MultiLevelTemplateArgumentList &TemplateArgs);
6233218893Sdim  bool Subst(const TemplateArgumentLoc *Args, unsigned NumArgs,
6234218893Sdim             TemplateArgumentListInfo &Result,
6235212795Sdim             const MultiLevelTemplateArgumentList &TemplateArgs);
6236212795Sdim
6237234982Sdim  void InstantiateExceptionSpec(SourceLocation PointOfInstantiation,
6238234982Sdim                                FunctionDecl *Function);
6239212795Sdim  void InstantiateFunctionDefinition(SourceLocation PointOfInstantiation,
6240212795Sdim                                     FunctionDecl *Function,
6241212795Sdim                                     bool Recursive = false,
6242212795Sdim                                     bool DefinitionRequired = false);
6243212795Sdim  void InstantiateStaticDataMemberDefinition(
6244212795Sdim                                     SourceLocation PointOfInstantiation,
6245212795Sdim                                     VarDecl *Var,
6246212795Sdim                                     bool Recursive = false,
6247212795Sdim                                     bool DefinitionRequired = false);
6248212795Sdim
6249212795Sdim  void InstantiateMemInitializers(CXXConstructorDecl *New,
6250212795Sdim                                  const CXXConstructorDecl *Tmpl,
6251212795Sdim                            const MultiLevelTemplateArgumentList &TemplateArgs);
6252212795Sdim
6253212795Sdim  NamedDecl *FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D,
6254212795Sdim                          const MultiLevelTemplateArgumentList &TemplateArgs);
6255212795Sdim  DeclContext *FindInstantiatedContext(SourceLocation Loc, DeclContext *DC,
6256212795Sdim                          const MultiLevelTemplateArgumentList &TemplateArgs);
6257212795Sdim
6258212795Sdim  // Objective-C declarations.
6259234353Sdim  enum ObjCContainerKind {
6260234353Sdim    OCK_None = -1,
6261234353Sdim    OCK_Interface = 0,
6262234353Sdim    OCK_Protocol,
6263234353Sdim    OCK_Category,
6264234353Sdim    OCK_ClassExtension,
6265234353Sdim    OCK_Implementation,
6266234353Sdim    OCK_CategoryImplementation
6267234353Sdim  };
6268234353Sdim  ObjCContainerKind getObjCContainerKind() const;
6269234353Sdim
6270212795Sdim  Decl *ActOnStartClassInterface(SourceLocation AtInterfaceLoc,
6271212795Sdim                                 IdentifierInfo *ClassName,
6272212795Sdim                                 SourceLocation ClassLoc,
6273212795Sdim                                 IdentifierInfo *SuperName,
6274212795Sdim                                 SourceLocation SuperLoc,
6275212795Sdim                                 Decl * const *ProtoRefs,
6276212795Sdim                                 unsigned NumProtoRefs,
6277212795Sdim                                 const SourceLocation *ProtoLocs,
6278212795Sdim                                 SourceLocation EndProtoLoc,
6279212795Sdim                                 AttributeList *AttrList);
6280212795Sdim
6281239462Sdim  Decl *ActOnCompatibilityAlias(
6282212795Sdim                    SourceLocation AtCompatibilityAliasLoc,
6283212795Sdim                    IdentifierInfo *AliasName,  SourceLocation AliasLocation,
6284212795Sdim                    IdentifierInfo *ClassName, SourceLocation ClassLocation);
6285212795Sdim
6286223017Sdim  bool CheckForwardProtocolDeclarationForCircularDependency(
6287212795Sdim    IdentifierInfo *PName,
6288212795Sdim    SourceLocation &PLoc, SourceLocation PrevLoc,
6289212795Sdim    const ObjCList<ObjCProtocolDecl> &PList);
6290212795Sdim
6291212795Sdim  Decl *ActOnStartProtocolInterface(
6292212795Sdim                    SourceLocation AtProtoInterfaceLoc,
6293212795Sdim                    IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc,
6294212795Sdim                    Decl * const *ProtoRefNames, unsigned NumProtoRefs,
6295212795Sdim                    const SourceLocation *ProtoLocs,
6296212795Sdim                    SourceLocation EndProtoLoc,
6297212795Sdim                    AttributeList *AttrList);
6298212795Sdim
6299212795Sdim  Decl *ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc,
6300212795Sdim                                    IdentifierInfo *ClassName,
6301212795Sdim                                    SourceLocation ClassLoc,
6302212795Sdim                                    IdentifierInfo *CategoryName,
6303212795Sdim                                    SourceLocation CategoryLoc,
6304212795Sdim                                    Decl * const *ProtoRefs,
6305212795Sdim                                    unsigned NumProtoRefs,
6306212795Sdim                                    const SourceLocation *ProtoLocs,
6307212795Sdim                                    SourceLocation EndProtoLoc);
6308212795Sdim
6309212795Sdim  Decl *ActOnStartClassImplementation(
6310212795Sdim                    SourceLocation AtClassImplLoc,
6311212795Sdim                    IdentifierInfo *ClassName, SourceLocation ClassLoc,
6312212795Sdim                    IdentifierInfo *SuperClassname,
6313212795Sdim                    SourceLocation SuperClassLoc);
6314212795Sdim
6315212795Sdim  Decl *ActOnStartCategoryImplementation(SourceLocation AtCatImplLoc,
6316212795Sdim                                         IdentifierInfo *ClassName,
6317212795Sdim                                         SourceLocation ClassLoc,
6318212795Sdim                                         IdentifierInfo *CatName,
6319212795Sdim                                         SourceLocation CatLoc);
6320212795Sdim
6321234353Sdim  DeclGroupPtrTy ActOnFinishObjCImplementation(Decl *ObjCImpDecl,
6322234353Sdim                                               ArrayRef<Decl *> Decls);
6323234353Sdim
6324226633Sdim  DeclGroupPtrTy ActOnForwardClassDeclaration(SourceLocation Loc,
6325212795Sdim                                     IdentifierInfo **IdentList,
6326212795Sdim                                     SourceLocation *IdentLocs,
6327212795Sdim                                     unsigned NumElts);
6328212795Sdim
6329234353Sdim  DeclGroupPtrTy ActOnForwardProtocolDeclaration(SourceLocation AtProtoclLoc,
6330212795Sdim                                        const IdentifierLocPair *IdentList,
6331212795Sdim                                        unsigned NumElts,
6332212795Sdim                                        AttributeList *attrList);
6333212795Sdim
6334212795Sdim  void FindProtocolDeclaration(bool WarnOnDeclarations,
6335212795Sdim                               const IdentifierLocPair *ProtocolId,
6336212795Sdim                               unsigned NumProtocols,
6337226633Sdim                               SmallVectorImpl<Decl *> &Protocols);
6338212795Sdim
6339212795Sdim  /// Ensure attributes are consistent with type.
6340212795Sdim  /// \param [in, out] Attributes The attributes to check; they will
6341243830Sdim  /// be modified to be consistent with \p PropertyTy.
6342212795Sdim  void CheckObjCPropertyAttributes(Decl *PropertyPtrTy,
6343212795Sdim                                   SourceLocation Loc,
6344239462Sdim                                   unsigned &Attributes,
6345239462Sdim                                   bool propertyInPrimaryClass);
6346218893Sdim
6347218893Sdim  /// Process the specified property declaration and create decls for the
6348218893Sdim  /// setters and getters as needed.
6349218893Sdim  /// \param property The property declaration being processed
6350239462Sdim  /// \param CD The semantic container for the property
6351234353Sdim  /// \param redeclaredProperty Declaration for property if redeclared
6352218893Sdim  ///        in class extension.
6353218893Sdim  /// \param lexicalDC Container for redeclaredProperty.
6354218893Sdim  void ProcessPropertyDecl(ObjCPropertyDecl *property,
6355239462Sdim                           ObjCContainerDecl *CD,
6356218893Sdim                           ObjCPropertyDecl *redeclaredProperty = 0,
6357218893Sdim                           ObjCContainerDecl *lexicalDC = 0);
6358218893Sdim
6359239462Sdim
6360212795Sdim  void DiagnosePropertyMismatch(ObjCPropertyDecl *Property,
6361212795Sdim                                ObjCPropertyDecl *SuperProperty,
6362212795Sdim                                const IdentifierInfo *Name);
6363212795Sdim
6364212795Sdim  void DiagnoseClassExtensionDupMethods(ObjCCategoryDecl *CAT,
6365212795Sdim                                        ObjCInterfaceDecl *ID);
6366212795Sdim
6367212795Sdim  void MatchOneProtocolPropertiesInClass(Decl *CDecl,
6368212795Sdim                                         ObjCProtocolDecl *PDecl);
6369212795Sdim
6370234353Sdim  Decl *ActOnAtEnd(Scope *S, SourceRange AtEnd,
6371234353Sdim                   Decl **allMethods = 0, unsigned allNum = 0,
6372234353Sdim                   Decl **allProperties = 0, unsigned pNum = 0,
6373234353Sdim                   DeclGroupPtrTy *allTUVars = 0, unsigned tuvNum = 0);
6374212795Sdim
6375212795Sdim  Decl *ActOnProperty(Scope *S, SourceLocation AtLoc,
6376234353Sdim                      SourceLocation LParenLoc,
6377212795Sdim                      FieldDeclarator &FD, ObjCDeclSpec &ODS,
6378212795Sdim                      Selector GetterSel, Selector SetterSel,
6379212795Sdim                      bool *OverridingProperty,
6380218893Sdim                      tok::ObjCKeywordKind MethodImplKind,
6381218893Sdim                      DeclContext *lexicalDC = 0);
6382212795Sdim
6383212795Sdim  Decl *ActOnPropertyImplDecl(Scope *S,
6384212795Sdim                              SourceLocation AtLoc,
6385212795Sdim                              SourceLocation PropertyLoc,
6386226633Sdim                              bool ImplKind,
6387212795Sdim                              IdentifierInfo *PropertyId,
6388218893Sdim                              IdentifierInfo *PropertyIvar,
6389218893Sdim                              SourceLocation PropertyIvarLoc);
6390212795Sdim
6391224145Sdim  enum ObjCSpecialMethodKind {
6392224145Sdim    OSMK_None,
6393224145Sdim    OSMK_Alloc,
6394224145Sdim    OSMK_New,
6395224145Sdim    OSMK_Copy,
6396224145Sdim    OSMK_RetainingInit,
6397224145Sdim    OSMK_NonRetainingInit
6398224145Sdim  };
6399224145Sdim
6400212795Sdim  struct ObjCArgInfo {
6401212795Sdim    IdentifierInfo *Name;
6402212795Sdim    SourceLocation NameLoc;
6403212795Sdim    // The Type is null if no type was specified, and the DeclSpec is invalid
6404212795Sdim    // in this case.
6405212795Sdim    ParsedType Type;
6406212795Sdim    ObjCDeclSpec DeclSpec;
6407212795Sdim
6408212795Sdim    /// ArgAttrs - Attribute list for this argument.
6409212795Sdim    AttributeList *ArgAttrs;
6410212795Sdim  };
6411212795Sdim
6412212795Sdim  Decl *ActOnMethodDeclaration(
6413218893Sdim    Scope *S,
6414212795Sdim    SourceLocation BeginLoc, // location of the + or -.
6415212795Sdim    SourceLocation EndLoc,   // location of the ; or {.
6416212795Sdim    tok::TokenKind MethodType,
6417226633Sdim    ObjCDeclSpec &ReturnQT, ParsedType ReturnType,
6418226633Sdim    ArrayRef<SourceLocation> SelectorLocs, Selector Sel,
6419212795Sdim    // optional arguments. The number of types/arguments is obtained
6420212795Sdim    // from the Sel.getNumArgs().
6421212795Sdim    ObjCArgInfo *ArgInfo,
6422212795Sdim    DeclaratorChunk::ParamInfo *CParamInfo, unsigned CNumArgs, // c-style args
6423212795Sdim    AttributeList *AttrList, tok::ObjCKeywordKind MethodImplKind,
6424221345Sdim    bool isVariadic, bool MethodDefinition);
6425212795Sdim
6426221345Sdim  ObjCMethodDecl *LookupMethodInQualifiedType(Selector Sel,
6427221345Sdim                                              const ObjCObjectPointerType *OPT,
6428221345Sdim                                              bool IsInstance);
6429234353Sdim  ObjCMethodDecl *LookupMethodInObjectType(Selector Sel, QualType Ty,
6430234353Sdim                                           bool IsInstance);
6431212795Sdim
6432249423Sdim  bool CheckARCMethodDecl(ObjCMethodDecl *method);
6433224145Sdim  bool inferObjCARCLifetime(ValueDecl *decl);
6434234353Sdim
6435212795Sdim  ExprResult
6436212795Sdim  HandleExprPropertyRefExpr(const ObjCObjectPointerType *OPT,
6437212795Sdim                            Expr *BaseExpr,
6438224145Sdim                            SourceLocation OpLoc,
6439212795Sdim                            DeclarationName MemberName,
6440218893Sdim                            SourceLocation MemberLoc,
6441218893Sdim                            SourceLocation SuperLoc, QualType SuperType,
6442218893Sdim                            bool Super);
6443212795Sdim
6444212795Sdim  ExprResult
6445212795Sdim  ActOnClassPropertyRefExpr(IdentifierInfo &receiverName,
6446212795Sdim                            IdentifierInfo &propertyName,
6447212795Sdim                            SourceLocation receiverNameLoc,
6448212795Sdim                            SourceLocation propertyNameLoc);
6449212795Sdim
6450234353Sdim  ObjCMethodDecl *tryCaptureObjCSelf(SourceLocation Loc);
6451218893Sdim
6452212795Sdim  /// \brief Describes the kind of message expression indicated by a message
6453212795Sdim  /// send that starts with an identifier.
6454212795Sdim  enum ObjCMessageKind {
6455212795Sdim    /// \brief The message is sent to 'super'.
6456212795Sdim    ObjCSuperMessage,
6457212795Sdim    /// \brief The message is an instance message.
6458212795Sdim    ObjCInstanceMessage,
6459212795Sdim    /// \brief The message is a class message, and the identifier is a type
6460212795Sdim    /// name.
6461212795Sdim    ObjCClassMessage
6462212795Sdim  };
6463234353Sdim
6464212795Sdim  ObjCMessageKind getObjCMessageKind(Scope *S,
6465212795Sdim                                     IdentifierInfo *Name,
6466212795Sdim                                     SourceLocation NameLoc,
6467212795Sdim                                     bool IsSuper,
6468212795Sdim                                     bool HasTrailingDot,
6469212795Sdim                                     ParsedType &ReceiverType);
6470212795Sdim
6471212795Sdim  ExprResult ActOnSuperMessage(Scope *S, SourceLocation SuperLoc,
6472212795Sdim                               Selector Sel,
6473212795Sdim                               SourceLocation LBracLoc,
6474226633Sdim                               ArrayRef<SourceLocation> SelectorLocs,
6475212795Sdim                               SourceLocation RBracLoc,
6476212795Sdim                               MultiExprArg Args);
6477212795Sdim
6478212795Sdim  ExprResult BuildClassMessage(TypeSourceInfo *ReceiverTypeInfo,
6479212795Sdim                               QualType ReceiverType,
6480212795Sdim                               SourceLocation SuperLoc,
6481212795Sdim                               Selector Sel,
6482212795Sdim                               ObjCMethodDecl *Method,
6483212795Sdim                               SourceLocation LBracLoc,
6484226633Sdim                               ArrayRef<SourceLocation> SelectorLocs,
6485212795Sdim                               SourceLocation RBracLoc,
6486234353Sdim                               MultiExprArg Args,
6487234353Sdim                               bool isImplicit = false);
6488212795Sdim
6489234353Sdim  ExprResult BuildClassMessageImplicit(QualType ReceiverType,
6490234353Sdim                                       bool isSuperReceiver,
6491234353Sdim                                       SourceLocation Loc,
6492234353Sdim                                       Selector Sel,
6493234353Sdim                                       ObjCMethodDecl *Method,
6494234353Sdim                                       MultiExprArg Args);
6495234353Sdim
6496212795Sdim  ExprResult ActOnClassMessage(Scope *S,
6497212795Sdim                               ParsedType Receiver,
6498212795Sdim                               Selector Sel,
6499212795Sdim                               SourceLocation LBracLoc,
6500226633Sdim                               ArrayRef<SourceLocation> SelectorLocs,
6501212795Sdim                               SourceLocation RBracLoc,
6502212795Sdim                               MultiExprArg Args);
6503212795Sdim
6504212795Sdim  ExprResult BuildInstanceMessage(Expr *Receiver,
6505212795Sdim                                  QualType ReceiverType,
6506212795Sdim                                  SourceLocation SuperLoc,
6507212795Sdim                                  Selector Sel,
6508212795Sdim                                  ObjCMethodDecl *Method,
6509212795Sdim                                  SourceLocation LBracLoc,
6510226633Sdim                                  ArrayRef<SourceLocation> SelectorLocs,
6511212795Sdim                                  SourceLocation RBracLoc,
6512234353Sdim                                  MultiExprArg Args,
6513234353Sdim                                  bool isImplicit = false);
6514212795Sdim
6515234353Sdim  ExprResult BuildInstanceMessageImplicit(Expr *Receiver,
6516234353Sdim                                          QualType ReceiverType,
6517234353Sdim                                          SourceLocation Loc,
6518234353Sdim                                          Selector Sel,
6519234353Sdim                                          ObjCMethodDecl *Method,
6520234353Sdim                                          MultiExprArg Args);
6521234353Sdim
6522212795Sdim  ExprResult ActOnInstanceMessage(Scope *S,
6523212795Sdim                                  Expr *Receiver,
6524212795Sdim                                  Selector Sel,
6525212795Sdim                                  SourceLocation LBracLoc,
6526226633Sdim                                  ArrayRef<SourceLocation> SelectorLocs,
6527212795Sdim                                  SourceLocation RBracLoc,
6528212795Sdim                                  MultiExprArg Args);
6529212795Sdim
6530224145Sdim  ExprResult BuildObjCBridgedCast(SourceLocation LParenLoc,
6531224145Sdim                                  ObjCBridgeCastKind Kind,
6532224145Sdim                                  SourceLocation BridgeKeywordLoc,
6533224145Sdim                                  TypeSourceInfo *TSInfo,
6534224145Sdim                                  Expr *SubExpr);
6535234353Sdim
6536224145Sdim  ExprResult ActOnObjCBridgedCast(Scope *S,
6537224145Sdim                                  SourceLocation LParenLoc,
6538224145Sdim                                  ObjCBridgeCastKind Kind,
6539224145Sdim                                  SourceLocation BridgeKeywordLoc,
6540224145Sdim                                  ParsedType Type,
6541224145Sdim                                  SourceLocation RParenLoc,
6542224145Sdim                                  Expr *SubExpr);
6543249423Sdim
6544224145Sdim  bool checkInitMethod(ObjCMethodDecl *method, QualType receiverTypeIfCall);
6545234353Sdim
6546223017Sdim  /// \brief Check whether the given new method is a valid override of the
6547223017Sdim  /// given overridden method, and set any properties that should be inherited.
6548234353Sdim  void CheckObjCMethodOverride(ObjCMethodDecl *NewMethod,
6549249423Sdim                               const ObjCMethodDecl *Overridden);
6550224145Sdim
6551239462Sdim  /// \brief Describes the compatibility of a result type with its method.
6552239462Sdim  enum ResultTypeCompatibilityKind {
6553239462Sdim    RTC_Compatible,
6554239462Sdim    RTC_Incompatible,
6555239462Sdim    RTC_Unknown
6556239462Sdim  };
6557234353Sdim
6558239462Sdim  void CheckObjCMethodOverrides(ObjCMethodDecl *ObjCMethod,
6559239462Sdim                                ObjCInterfaceDecl *CurrentClass,
6560239462Sdim                                ResultTypeCompatibilityKind RTC);
6561239462Sdim
6562212795Sdim  enum PragmaOptionsAlignKind {
6563212795Sdim    POAK_Native,  // #pragma options align=native
6564212795Sdim    POAK_Natural, // #pragma options align=natural
6565212795Sdim    POAK_Packed,  // #pragma options align=packed
6566212795Sdim    POAK_Power,   // #pragma options align=power
6567212795Sdim    POAK_Mac68k,  // #pragma options align=mac68k
6568212795Sdim    POAK_Reset    // #pragma options align=reset
6569212795Sdim  };
6570212795Sdim
6571239462Sdim  /// ActOnPragmaOptionsAlign - Called on well formed \#pragma options align.
6572212795Sdim  void ActOnPragmaOptionsAlign(PragmaOptionsAlignKind Kind,
6573243830Sdim                               SourceLocation PragmaLoc);
6574212795Sdim
6575212795Sdim  enum PragmaPackKind {
6576212795Sdim    PPK_Default, // #pragma pack([n])
6577212795Sdim    PPK_Show,    // #pragma pack(show), only supported by MSVC.
6578212795Sdim    PPK_Push,    // #pragma pack(push, [identifier], [n])
6579212795Sdim    PPK_Pop      // #pragma pack(pop, [identifier], [n])
6580212795Sdim  };
6581212795Sdim
6582221345Sdim  enum PragmaMSStructKind {
6583221345Sdim    PMSST_OFF,  // #pragms ms_struct off
6584221345Sdim    PMSST_ON    // #pragms ms_struct on
6585221345Sdim  };
6586221345Sdim
6587239462Sdim  /// ActOnPragmaPack - Called on well formed \#pragma pack(...).
6588212795Sdim  void ActOnPragmaPack(PragmaPackKind Kind,
6589212795Sdim                       IdentifierInfo *Name,
6590212795Sdim                       Expr *Alignment,
6591212795Sdim                       SourceLocation PragmaLoc,
6592212795Sdim                       SourceLocation LParenLoc,
6593212795Sdim                       SourceLocation RParenLoc);
6594234353Sdim
6595239462Sdim  /// ActOnPragmaMSStruct - Called on well formed \#pragma ms_struct [on|off].
6596221345Sdim  void ActOnPragmaMSStruct(PragmaMSStructKind Kind);
6597212795Sdim
6598239462Sdim  /// ActOnPragmaUnused - Called on well-formed '\#pragma unused'.
6599218893Sdim  void ActOnPragmaUnused(const Token &Identifier,
6600218893Sdim                         Scope *curScope,
6601218893Sdim                         SourceLocation PragmaLoc);
6602212795Sdim
6603239462Sdim  /// ActOnPragmaVisibility - Called on well formed \#pragma GCC visibility... .
6604234353Sdim  void ActOnPragmaVisibility(const IdentifierInfo* VisType,
6605212795Sdim                             SourceLocation PragmaLoc);
6606212795Sdim
6607226633Sdim  NamedDecl *DeclClonePragmaWeak(NamedDecl *ND, IdentifierInfo *II,
6608226633Sdim                                 SourceLocation Loc);
6609212795Sdim  void DeclApplyPragmaWeak(Scope *S, NamedDecl *ND, WeakInfo &W);
6610212795Sdim
6611239462Sdim  /// ActOnPragmaWeakID - Called on well formed \#pragma weak ident.
6612212795Sdim  void ActOnPragmaWeakID(IdentifierInfo* WeakName,
6613212795Sdim                         SourceLocation PragmaLoc,
6614212795Sdim                         SourceLocation WeakNameLoc);
6615212795Sdim
6616239462Sdim  /// ActOnPragmaRedefineExtname - Called on well formed
6617239462Sdim  /// \#pragma redefine_extname oldname newname.
6618234353Sdim  void ActOnPragmaRedefineExtname(IdentifierInfo* WeakName,
6619234353Sdim                                  IdentifierInfo* AliasName,
6620234353Sdim                                  SourceLocation PragmaLoc,
6621234353Sdim                                  SourceLocation WeakNameLoc,
6622234353Sdim                                  SourceLocation AliasNameLoc);
6623234353Sdim
6624239462Sdim  /// ActOnPragmaWeakAlias - Called on well formed \#pragma weak ident = ident.
6625212795Sdim  void ActOnPragmaWeakAlias(IdentifierInfo* WeakName,
6626212795Sdim                            IdentifierInfo* AliasName,
6627212795Sdim                            SourceLocation PragmaLoc,
6628212795Sdim                            SourceLocation WeakNameLoc,
6629212795Sdim                            SourceLocation AliasNameLoc);
6630212795Sdim
6631218893Sdim  /// ActOnPragmaFPContract - Called on well formed
6632239462Sdim  /// \#pragma {STDC,OPENCL} FP_CONTRACT
6633218893Sdim  void ActOnPragmaFPContract(tok::OnOffSwitch OOS);
6634218893Sdim
6635212795Sdim  /// AddAlignmentAttributesForRecord - Adds any needed alignment attributes to
6636239462Sdim  /// a the record decl, to handle '\#pragma pack' and '\#pragma options align'.
6637212795Sdim  void AddAlignmentAttributesForRecord(RecordDecl *RD);
6638212795Sdim
6639221345Sdim  /// AddMsStructLayoutForRecord - Adds ms_struct layout attribute to record.
6640221345Sdim  void AddMsStructLayoutForRecord(RecordDecl *RD);
6641221345Sdim
6642212795Sdim  /// FreePackedContext - Deallocate and null out PackContext.
6643212795Sdim  void FreePackedContext();
6644212795Sdim
6645218893Sdim  /// PushNamespaceVisibilityAttr - Note that we've entered a
6646218893Sdim  /// namespace with a visibility attribute.
6647234353Sdim  void PushNamespaceVisibilityAttr(const VisibilityAttr *Attr,
6648234353Sdim                                   SourceLocation Loc);
6649212795Sdim
6650239462Sdim  /// AddPushedVisibilityAttribute - If '\#pragma GCC visibility' was used,
6651212795Sdim  /// add an appropriate visibility attribute.
6652212795Sdim  void AddPushedVisibilityAttribute(Decl *RD);
6653212795Sdim
6654212795Sdim  /// PopPragmaVisibility - Pop the top element of the visibility stack; used
6655239462Sdim  /// for '\#pragma GCC visibility' and visibility attributes on namespaces.
6656234353Sdim  void PopPragmaVisibility(bool IsNamespaceEnd, SourceLocation EndLoc);
6657212795Sdim
6658212795Sdim  /// FreeVisContext - Deallocate and null out VisContext.
6659212795Sdim  void FreeVisContext();
6660212795Sdim
6661226633Sdim  /// AddCFAuditedAttribute - Check whether we're currently within
6662239462Sdim  /// '\#pragma clang arc_cf_code_audited' and, if so, consider adding
6663226633Sdim  /// the appropriate attribute.
6664226633Sdim  void AddCFAuditedAttribute(Decl *D);
6665226633Sdim
6666212795Sdim  /// AddAlignedAttr - Adds an aligned attribute to a particular declaration.
6667239462Sdim  void AddAlignedAttr(SourceRange AttrRange, Decl *D, Expr *E,
6668249423Sdim                      unsigned SpellingListIndex, bool IsPackExpansion);
6669239462Sdim  void AddAlignedAttr(SourceRange AttrRange, Decl *D, TypeSourceInfo *T,
6670249423Sdim                      unsigned SpellingListIndex, bool IsPackExpansion);
6671212795Sdim
6672249423Sdim  // OpenMP directives and clauses.
6673249423Sdim
6674249423Sdim  /// \brief Called on well-formed '#pragma omp threadprivate'.
6675249423Sdim  DeclGroupPtrTy ActOnOpenMPThreadprivateDirective(
6676249423Sdim                        SourceLocation Loc,
6677249423Sdim                        Scope *CurScope,
6678249423Sdim                        ArrayRef<DeclarationNameInfo> IdList);
6679249423Sdim  /// \brief Build a new OpenMPThreadPrivateDecl and check its correctness.
6680249423Sdim  OMPThreadPrivateDecl *CheckOMPThreadPrivateDecl(
6681249423Sdim                        SourceLocation Loc,
6682249423Sdim                        ArrayRef<DeclRefExpr *> VarList);
6683249423Sdim
6684224145Sdim  /// \brief The kind of conversion being performed.
6685224145Sdim  enum CheckedConversionKind {
6686224145Sdim    /// \brief An implicit conversion.
6687224145Sdim    CCK_ImplicitConversion,
6688224145Sdim    /// \brief A C-style cast.
6689224145Sdim    CCK_CStyleCast,
6690224145Sdim    /// \brief A functional-style cast.
6691224145Sdim    CCK_FunctionalCast,
6692224145Sdim    /// \brief A cast other than a C-style cast.
6693224145Sdim    CCK_OtherCast
6694224145Sdim  };
6695224145Sdim
6696212795Sdim  /// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit
6697212795Sdim  /// cast.  If there is already an implicit cast, merge into the existing one.
6698212795Sdim  /// If isLvalue, the result of the cast is an lvalue.
6699221345Sdim  ExprResult ImpCastExprToType(Expr *E, QualType Type, CastKind CK,
6700221345Sdim                               ExprValueKind VK = VK_RValue,
6701224145Sdim                               const CXXCastPath *BasePath = 0,
6702234353Sdim                               CheckedConversionKind CCK
6703224145Sdim                                  = CCK_ImplicitConversion);
6704212795Sdim
6705221345Sdim  /// ScalarTypeToBooleanCastKind - Returns the cast kind corresponding
6706221345Sdim  /// to the conversion from scalar type ScalarTy to the Boolean type.
6707221345Sdim  static CastKind ScalarTypeToBooleanCastKind(QualType ScalarTy);
6708221345Sdim
6709218893Sdim  /// IgnoredValueConversions - Given that an expression's result is
6710218893Sdim  /// syntactically ignored, perform any conversions that are
6711218893Sdim  /// required.
6712221345Sdim  ExprResult IgnoredValueConversions(Expr *E);
6713218893Sdim
6714212795Sdim  // UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts
6715212795Sdim  // functions and arrays to their respective pointers (C99 6.3.2.1).
6716221345Sdim  ExprResult UsualUnaryConversions(Expr *E);
6717212795Sdim
6718212795Sdim  // DefaultFunctionArrayConversion - converts functions and arrays
6719212795Sdim  // to their respective pointers (C99 6.3.2.1).
6720221345Sdim  ExprResult DefaultFunctionArrayConversion(Expr *E);
6721212795Sdim
6722212795Sdim  // DefaultFunctionArrayLvalueConversion - converts functions and
6723212795Sdim  // arrays to their respective pointers and performs the
6724212795Sdim  // lvalue-to-rvalue conversion.
6725221345Sdim  ExprResult DefaultFunctionArrayLvalueConversion(Expr *E);
6726212795Sdim
6727218893Sdim  // DefaultLvalueConversion - performs lvalue-to-rvalue conversion on
6728218893Sdim  // the operand.  This is DefaultFunctionArrayLvalueConversion,
6729218893Sdim  // except that it assumes the operand isn't of function or array
6730218893Sdim  // type.
6731221345Sdim  ExprResult DefaultLvalueConversion(Expr *E);
6732218893Sdim
6733212795Sdim  // DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that
6734212795Sdim  // do not have a prototype. Integer promotions are performed on each
6735212795Sdim  // argument, and arguments that have type float are promoted to double.
6736221345Sdim  ExprResult DefaultArgumentPromotion(Expr *E);
6737212795Sdim
6738212795Sdim  // Used for emitting the right warning by DefaultVariadicArgumentPromotion
6739212795Sdim  enum VariadicCallType {
6740212795Sdim    VariadicFunction,
6741212795Sdim    VariadicBlock,
6742212795Sdim    VariadicMethod,
6743212795Sdim    VariadicConstructor,
6744212795Sdim    VariadicDoesNotApply
6745212795Sdim  };
6746212795Sdim
6747239462Sdim  VariadicCallType getVariadicCallType(FunctionDecl *FDecl,
6748239462Sdim                                       const FunctionProtoType *Proto,
6749239462Sdim                                       Expr *Fn);
6750239462Sdim
6751239462Sdim  // Used for determining in which context a type is allowed to be passed to a
6752239462Sdim  // vararg function.
6753239462Sdim  enum VarArgKind {
6754239462Sdim    VAK_Valid,
6755239462Sdim    VAK_ValidInCXX11,
6756239462Sdim    VAK_Invalid
6757239462Sdim  };
6758239462Sdim
6759239462Sdim  // Determines which VarArgKind fits an expression.
6760239462Sdim  VarArgKind isValidVarArgType(const QualType &Ty);
6761239462Sdim
6762212795Sdim  /// GatherArgumentsForCall - Collector argument expressions for various
6763212795Sdim  /// form of call prototypes.
6764212795Sdim  bool GatherArgumentsForCall(SourceLocation CallLoc,
6765212795Sdim                              FunctionDecl *FDecl,
6766212795Sdim                              const FunctionProtoType *Proto,
6767212795Sdim                              unsigned FirstProtoArg,
6768212795Sdim                              Expr **Args, unsigned NumArgs,
6769226633Sdim                              SmallVector<Expr *, 8> &AllArgs,
6770234353Sdim                              VariadicCallType CallType = VariadicDoesNotApply,
6771249423Sdim                              bool AllowExplicit = false,
6772249423Sdim                              bool IsListInitialization = false);
6773212795Sdim
6774212795Sdim  // DefaultVariadicArgumentPromotion - Like DefaultArgumentPromotion, but
6775239462Sdim  // will create a runtime trap if the resulting type is not a POD type.
6776221345Sdim  ExprResult DefaultVariadicArgumentPromotion(Expr *E, VariadicCallType CT,
6777221345Sdim                                              FunctionDecl *FDecl);
6778212795Sdim
6779239462Sdim  /// Checks to see if the given expression is a valid argument to a variadic
6780239462Sdim  /// function, issuing a diagnostic and returning NULL if not.
6781239462Sdim  bool variadicArgumentPODCheck(const Expr *E, VariadicCallType CT);
6782239462Sdim
6783212795Sdim  // UsualArithmeticConversions - performs the UsualUnaryConversions on it's
6784212795Sdim  // operands and then handles various conversions that are common to binary
6785212795Sdim  // operators (C99 6.3.1.8). If both operands aren't arithmetic, this
6786212795Sdim  // routine returns the first non-arithmetic type found. The client is
6787212795Sdim  // responsible for emitting appropriate error diagnostics.
6788226633Sdim  QualType UsualArithmeticConversions(ExprResult &LHS, ExprResult &RHS,
6789226633Sdim                                      bool IsCompAssign = false);
6790212795Sdim
6791212795Sdim  /// AssignConvertType - All of the 'assignment' semantic checks return this
6792212795Sdim  /// enum to indicate whether the assignment was allowed.  These checks are
6793212795Sdim  /// done for simple assignments, as well as initialization, return from
6794212795Sdim  /// function, argument passing, etc.  The query is phrased in terms of a
6795212795Sdim  /// source and destination type.
6796212795Sdim  enum AssignConvertType {
6797212795Sdim    /// Compatible - the types are compatible according to the standard.
6798212795Sdim    Compatible,
6799212795Sdim
6800212795Sdim    /// PointerToInt - The assignment converts a pointer to an int, which we
6801212795Sdim    /// accept as an extension.
6802212795Sdim    PointerToInt,
6803212795Sdim
6804212795Sdim    /// IntToPointer - The assignment converts an int to a pointer, which we
6805212795Sdim    /// accept as an extension.
6806212795Sdim    IntToPointer,
6807212795Sdim
6808212795Sdim    /// FunctionVoidPointer - The assignment is between a function pointer and
6809212795Sdim    /// void*, which the standard doesn't allow, but we accept as an extension.
6810212795Sdim    FunctionVoidPointer,
6811212795Sdim
6812212795Sdim    /// IncompatiblePointer - The assignment is between two pointers types that
6813212795Sdim    /// are not compatible, but we accept them as an extension.
6814212795Sdim    IncompatiblePointer,
6815212795Sdim
6816212795Sdim    /// IncompatiblePointer - The assignment is between two pointers types which
6817234353Sdim    /// point to integers which have a different sign, but are otherwise
6818234353Sdim    /// identical. This is a subset of the above, but broken out because it's by
6819234353Sdim    /// far the most common case of incompatible pointers.
6820212795Sdim    IncompatiblePointerSign,
6821212795Sdim
6822212795Sdim    /// CompatiblePointerDiscardsQualifiers - The assignment discards
6823212795Sdim    /// c/v/r qualifiers, which we accept as an extension.
6824212795Sdim    CompatiblePointerDiscardsQualifiers,
6825212795Sdim
6826218893Sdim    /// IncompatiblePointerDiscardsQualifiers - The assignment
6827218893Sdim    /// discards qualifiers that we don't permit to be discarded,
6828218893Sdim    /// like address spaces.
6829218893Sdim    IncompatiblePointerDiscardsQualifiers,
6830218893Sdim
6831212795Sdim    /// IncompatibleNestedPointerQualifiers - The assignment is between two
6832212795Sdim    /// nested pointer types, and the qualifiers other than the first two
6833212795Sdim    /// levels differ e.g. char ** -> const char **, but we accept them as an
6834212795Sdim    /// extension.
6835212795Sdim    IncompatibleNestedPointerQualifiers,
6836212795Sdim
6837212795Sdim    /// IncompatibleVectors - The assignment is between two vector types that
6838212795Sdim    /// have the same size, which we accept as an extension.
6839212795Sdim    IncompatibleVectors,
6840212795Sdim
6841212795Sdim    /// IntToBlockPointer - The assignment converts an int to a block
6842212795Sdim    /// pointer. We disallow this.
6843212795Sdim    IntToBlockPointer,
6844212795Sdim
6845212795Sdim    /// IncompatibleBlockPointer - The assignment is between two block
6846212795Sdim    /// pointers types that are not compatible.
6847212795Sdim    IncompatibleBlockPointer,
6848212795Sdim
6849212795Sdim    /// IncompatibleObjCQualifiedId - The assignment is between a qualified
6850212795Sdim    /// id type and something else (that is incompatible with it). For example,
6851212795Sdim    /// "id <XXX>" = "Foo *", where "Foo *" doesn't implement the XXX protocol.
6852212795Sdim    IncompatibleObjCQualifiedId,
6853212795Sdim
6854224145Sdim    /// IncompatibleObjCWeakRef - Assigning a weak-unavailable object to an
6855224145Sdim    /// object with __weak qualifier.
6856224145Sdim    IncompatibleObjCWeakRef,
6857224145Sdim
6858212795Sdim    /// Incompatible - We reject this conversion outright, it is invalid to
6859212795Sdim    /// represent it in the AST.
6860212795Sdim    Incompatible
6861212795Sdim  };
6862212795Sdim
6863212795Sdim  /// DiagnoseAssignmentResult - Emit a diagnostic, if required, for the
6864212795Sdim  /// assignment conversion type specified by ConvTy.  This returns true if the
6865212795Sdim  /// conversion was invalid or false if the conversion was accepted.
6866212795Sdim  bool DiagnoseAssignmentResult(AssignConvertType ConvTy,
6867212795Sdim                                SourceLocation Loc,
6868212795Sdim                                QualType DstType, QualType SrcType,
6869212795Sdim                                Expr *SrcExpr, AssignmentAction Action,
6870212795Sdim                                bool *Complained = 0);
6871212795Sdim
6872239462Sdim  /// DiagnoseAssignmentEnum - Warn if assignment to enum is a constant
6873239462Sdim  /// integer not in the range of enum values.
6874239462Sdim  void DiagnoseAssignmentEnum(QualType DstType, QualType SrcType,
6875239462Sdim                              Expr *SrcExpr);
6876239462Sdim
6877212795Sdim  /// CheckAssignmentConstraints - Perform type checking for assignment,
6878212795Sdim  /// argument passing, variable initialization, and function return values.
6879218893Sdim  /// C99 6.5.16.
6880218893Sdim  AssignConvertType CheckAssignmentConstraints(SourceLocation Loc,
6881226633Sdim                                               QualType LHSType,
6882226633Sdim                                               QualType RHSType);
6883212795Sdim
6884218893Sdim  /// Check assignment constraints and prepare for a conversion of the
6885218893Sdim  /// RHS to the LHS type.
6886226633Sdim  AssignConvertType CheckAssignmentConstraints(QualType LHSType,
6887226633Sdim                                               ExprResult &RHS,
6888218893Sdim                                               CastKind &Kind);
6889218893Sdim
6890212795Sdim  // CheckSingleAssignmentConstraints - Currently used by
6891212795Sdim  // CheckAssignmentOperands, and ActOnReturnStmt. Prior to type checking,
6892212795Sdim  // this routine performs the default function/array converions.
6893226633Sdim  AssignConvertType CheckSingleAssignmentConstraints(QualType LHSType,
6894226633Sdim                                                     ExprResult &RHS,
6895226633Sdim                                                     bool Diagnose = true);
6896212795Sdim
6897212795Sdim  // \brief If the lhs type is a transparent union, check whether we
6898212795Sdim  // can initialize the transparent union with the given expression.
6899226633Sdim  AssignConvertType CheckTransparentUnionArgumentConstraints(QualType ArgType,
6900226633Sdim                                                             ExprResult &RHS);
6901212795Sdim
6902212795Sdim  bool IsStringLiteralToNonConstPointerConversion(Expr *From, QualType ToType);
6903212795Sdim
6904212795Sdim  bool CheckExceptionSpecCompatibility(Expr *From, QualType ToType);
6905212795Sdim
6906221345Sdim  ExprResult PerformImplicitConversion(Expr *From, QualType ToType,
6907221345Sdim                                       AssignmentAction Action,
6908234353Sdim                                       bool AllowExplicit = false);
6909221345Sdim  ExprResult PerformImplicitConversion(Expr *From, QualType ToType,
6910221345Sdim                                       AssignmentAction Action,
6911221345Sdim                                       bool AllowExplicit,
6912234353Sdim                                       ImplicitConversionSequence& ICS);
6913221345Sdim  ExprResult PerformImplicitConversion(Expr *From, QualType ToType,
6914221345Sdim                                       const ImplicitConversionSequence& ICS,
6915221345Sdim                                       AssignmentAction Action,
6916224145Sdim                                       CheckedConversionKind CCK
6917224145Sdim                                          = CCK_ImplicitConversion);
6918221345Sdim  ExprResult PerformImplicitConversion(Expr *From, QualType ToType,
6919221345Sdim                                       const StandardConversionSequence& SCS,
6920221345Sdim                                       AssignmentAction Action,
6921224145Sdim                                       CheckedConversionKind CCK);
6922212795Sdim
6923212795Sdim  /// the following "Check" methods will return a valid/converted QualType
6924212795Sdim  /// or a null QualType (indicating an error diagnostic was issued).
6925212795Sdim
6926212795Sdim  /// type checking binary operators (subroutines of CreateBuiltinBinOp).
6927226633Sdim  QualType InvalidOperands(SourceLocation Loc, ExprResult &LHS,
6928226633Sdim                           ExprResult &RHS);
6929212795Sdim  QualType CheckPointerToMemberOperands( // C++ 5.5
6930226633Sdim    ExprResult &LHS, ExprResult &RHS, ExprValueKind &VK,
6931218893Sdim    SourceLocation OpLoc, bool isIndirect);
6932212795Sdim  QualType CheckMultiplyDivideOperands( // C99 6.5.5
6933226633Sdim    ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, bool IsCompAssign,
6934226633Sdim    bool IsDivide);
6935212795Sdim  QualType CheckRemainderOperands( // C99 6.5.5
6936226633Sdim    ExprResult &LHS, ExprResult &RHS, SourceLocation Loc,
6937226633Sdim    bool IsCompAssign = false);
6938212795Sdim  QualType CheckAdditionOperands( // C99 6.5.6
6939234353Sdim    ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, unsigned Opc,
6940226633Sdim    QualType* CompLHSTy = 0);
6941212795Sdim  QualType CheckSubtractionOperands( // C99 6.5.6
6942226633Sdim    ExprResult &LHS, ExprResult &RHS, SourceLocation Loc,
6943226633Sdim    QualType* CompLHSTy = 0);
6944212795Sdim  QualType CheckShiftOperands( // C99 6.5.7
6945226633Sdim    ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, unsigned Opc,
6946226633Sdim    bool IsCompAssign = false);
6947212795Sdim  QualType CheckCompareOperands( // C99 6.5.8/9
6948226633Sdim    ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, unsigned OpaqueOpc,
6949212795Sdim                                bool isRelational);
6950212795Sdim  QualType CheckBitwiseOperands( // C99 6.5.[10...12]
6951226633Sdim    ExprResult &LHS, ExprResult &RHS, SourceLocation Loc,
6952226633Sdim    bool IsCompAssign = false);
6953212795Sdim  QualType CheckLogicalOperands( // C99 6.5.[13,14]
6954226633Sdim    ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, unsigned Opc);
6955212795Sdim  // CheckAssignmentOperands is used for both simple and compound assignment.
6956212795Sdim  // For simple assignment, pass both expressions and a null converted type.
6957212795Sdim  // For compound assignment, pass both expressions and the converted type.
6958212795Sdim  QualType CheckAssignmentOperands( // C99 6.5.16.[1,2]
6959226633Sdim    Expr *LHSExpr, ExprResult &RHS, SourceLocation Loc, QualType CompoundType);
6960234353Sdim
6961234353Sdim  ExprResult checkPseudoObjectIncDec(Scope *S, SourceLocation OpLoc,
6962234353Sdim                                     UnaryOperatorKind Opcode, Expr *Op);
6963234353Sdim  ExprResult checkPseudoObjectAssignment(Scope *S, SourceLocation OpLoc,
6964234353Sdim                                         BinaryOperatorKind Opcode,
6965234353Sdim                                         Expr *LHS, Expr *RHS);
6966234353Sdim  ExprResult checkPseudoObjectRValue(Expr *E);
6967234353Sdim  Expr *recreateSyntacticForm(PseudoObjectExpr *E);
6968234353Sdim
6969212795Sdim  QualType CheckConditionalOperands( // C99 6.5.15
6970226633Sdim    ExprResult &Cond, ExprResult &LHS, ExprResult &RHS,
6971226633Sdim    ExprValueKind &VK, ExprObjectKind &OK, SourceLocation QuestionLoc);
6972212795Sdim  QualType CXXCheckConditionalOperands( // C++ 5.16
6973221345Sdim    ExprResult &cond, ExprResult &lhs, ExprResult &rhs,
6974218893Sdim    ExprValueKind &VK, ExprObjectKind &OK, SourceLocation questionLoc);
6975212795Sdim  QualType FindCompositePointerType(SourceLocation Loc, Expr *&E1, Expr *&E2,
6976212795Sdim                                    bool *NonStandardCompositeType = 0);
6977234353Sdim  QualType FindCompositePointerType(SourceLocation Loc,
6978234353Sdim                                    ExprResult &E1, ExprResult &E2,
6979221345Sdim                                    bool *NonStandardCompositeType = 0) {
6980221345Sdim    Expr *E1Tmp = E1.take(), *E2Tmp = E2.take();
6981234353Sdim    QualType Composite = FindCompositePointerType(Loc, E1Tmp, E2Tmp,
6982234353Sdim                                                  NonStandardCompositeType);
6983221345Sdim    E1 = Owned(E1Tmp);
6984221345Sdim    E2 = Owned(E2Tmp);
6985221345Sdim    return Composite;
6986221345Sdim  }
6987212795Sdim
6988221345Sdim  QualType FindCompositeObjCPointerType(ExprResult &LHS, ExprResult &RHS,
6989226633Sdim                                        SourceLocation QuestionLoc);
6990212795Sdim
6991226633Sdim  bool DiagnoseConditionalForNull(Expr *LHSExpr, Expr *RHSExpr,
6992218893Sdim                                  SourceLocation QuestionLoc);
6993218893Sdim
6994212795Sdim  /// type checking for vector binary operators.
6995226633Sdim  QualType CheckVectorOperands(ExprResult &LHS, ExprResult &RHS,
6996226633Sdim                               SourceLocation Loc, bool IsCompAssign);
6997234353Sdim  QualType GetSignedVectorType(QualType V);
6998226633Sdim  QualType CheckVectorCompareOperands(ExprResult &LHS, ExprResult &RHS,
6999226633Sdim                                      SourceLocation Loc, bool isRelational);
7000234353Sdim  QualType CheckVectorLogicalOperands(ExprResult &LHS, ExprResult &RHS,
7001234353Sdim                                      SourceLocation Loc);
7002212795Sdim
7003212795Sdim  /// type checking declaration initializers (C99 6.7.8)
7004212795Sdim  bool CheckForConstantInitializer(Expr *e, QualType t);
7005212795Sdim
7006212795Sdim  // type checking C++ declaration initializers (C++ [dcl.init]).
7007212795Sdim
7008212795Sdim  /// ReferenceCompareResult - Expresses the result of comparing two
7009212795Sdim  /// types (cv1 T1 and cv2 T2) to determine their compatibility for the
7010212795Sdim  /// purposes of initialization by reference (C++ [dcl.init.ref]p4).
7011212795Sdim  enum ReferenceCompareResult {
7012212795Sdim    /// Ref_Incompatible - The two types are incompatible, so direct
7013212795Sdim    /// reference binding is not possible.
7014212795Sdim    Ref_Incompatible = 0,
7015212795Sdim    /// Ref_Related - The two types are reference-related, which means
7016212795Sdim    /// that their unqualified forms (T1 and T2) are either the same
7017212795Sdim    /// or T1 is a base class of T2.
7018212795Sdim    Ref_Related,
7019212795Sdim    /// Ref_Compatible_With_Added_Qualification - The two types are
7020212795Sdim    /// reference-compatible with added qualification, meaning that
7021212795Sdim    /// they are reference-compatible and the qualifiers on T1 (cv1)
7022212795Sdim    /// are greater than the qualifiers on T2 (cv2).
7023212795Sdim    Ref_Compatible_With_Added_Qualification,
7024212795Sdim    /// Ref_Compatible - The two types are reference-compatible and
7025212795Sdim    /// have equivalent qualifiers (cv1 == cv2).
7026212795Sdim    Ref_Compatible
7027212795Sdim  };
7028212795Sdim
7029212795Sdim  ReferenceCompareResult CompareReferenceRelationship(SourceLocation Loc,
7030212795Sdim                                                      QualType T1, QualType T2,
7031212795Sdim                                                      bool &DerivedToBase,
7032224145Sdim                                                      bool &ObjCConversion,
7033224145Sdim                                                bool &ObjCLifetimeConversion);
7034212795Sdim
7035226633Sdim  ExprResult checkUnknownAnyCast(SourceRange TypeRange, QualType CastType,
7036226633Sdim                                 Expr *CastExpr, CastKind &CastKind,
7037226633Sdim                                 ExprValueKind &VK, CXXCastPath &Path);
7038212795Sdim
7039234353Sdim  /// \brief Force an expression with unknown-type to an expression of the
7040234353Sdim  /// given type.
7041234353Sdim  ExprResult forceUnknownAnyToType(Expr *E, QualType ToType);
7042239462Sdim
7043249423Sdim  /// \brief Type-check an expression that's being passed to an
7044249423Sdim  /// __unknown_anytype parameter.
7045249423Sdim  ExprResult checkUnknownAnyArg(SourceLocation callLoc,
7046249423Sdim                                Expr *result, QualType &paramType);
7047249423Sdim
7048212795Sdim  // CheckVectorCast - check type constraints for vectors.
7049212795Sdim  // Since vectors are an extension, there are no C standard reference for this.
7050212795Sdim  // We allow casting between vectors and integer datatypes of the same size.
7051212795Sdim  // returns true if the cast is invalid
7052212795Sdim  bool CheckVectorCast(SourceRange R, QualType VectorTy, QualType Ty,
7053212795Sdim                       CastKind &Kind);
7054212795Sdim
7055212795Sdim  // CheckExtVectorCast - check type constraints for extended vectors.
7056212795Sdim  // Since vectors are an extension, there are no C standard reference for this.
7057212795Sdim  // We allow casting between vectors and integer datatypes of the same size,
7058212795Sdim  // or vectors and the element type of that vector.
7059221345Sdim  // returns the cast expr
7060226633Sdim  ExprResult CheckExtVectorCast(SourceRange R, QualType DestTy, Expr *CastExpr,
7061221345Sdim                                CastKind &Kind);
7062212795Sdim
7063226633Sdim  ExprResult BuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
7064226633Sdim                                        SourceLocation LParenLoc,
7065226633Sdim                                        Expr *CastExpr,
7066226633Sdim                                        SourceLocation RParenLoc);
7067226633Sdim
7068234353Sdim  enum ARCConversionResult { ACR_okay, ACR_unbridged };
7069234353Sdim
7070224145Sdim  /// \brief Checks for invalid conversions and casts between
7071224145Sdim  /// retainable pointers and other pointer kinds.
7072234353Sdim  ARCConversionResult CheckObjCARCConversion(SourceRange castRange,
7073234353Sdim                                             QualType castType, Expr *&op,
7074234353Sdim                                             CheckedConversionKind CCK);
7075234353Sdim
7076234353Sdim  Expr *stripARCUnbridgedCast(Expr *e);
7077234353Sdim  void diagnoseARCUnbridgedCast(Expr *e);
7078234353Sdim
7079224145Sdim  bool CheckObjCARCUnavailableWeakConversion(QualType castType,
7080224145Sdim                                             QualType ExprType);
7081212795Sdim
7082224145Sdim  /// checkRetainCycles - Check whether an Objective-C message send
7083224145Sdim  /// might create an obvious retain cycle.
7084224145Sdim  void checkRetainCycles(ObjCMessageExpr *msg);
7085224145Sdim  void checkRetainCycles(Expr *receiver, Expr *argument);
7086243830Sdim  void checkRetainCycles(VarDecl *Var, Expr *Init);
7087224145Sdim
7088224145Sdim  /// checkUnsafeAssigns - Check whether +1 expr is being assigned
7089224145Sdim  /// to weak/__unsafe_unretained type.
7090224145Sdim  bool checkUnsafeAssigns(SourceLocation Loc, QualType LHS, Expr *RHS);
7091224145Sdim
7092224145Sdim  /// checkUnsafeExprAssigns - Check whether +1 expr is being assigned
7093224145Sdim  /// to weak/__unsafe_unretained expression.
7094224145Sdim  void checkUnsafeExprAssigns(SourceLocation Loc, Expr *LHS, Expr *RHS);
7095224145Sdim
7096212795Sdim  /// CheckMessageArgumentTypes - Check types in an Obj-C message send.
7097212795Sdim  /// \param Method - May be null.
7098212795Sdim  /// \param [out] ReturnType - The return type of the send.
7099212795Sdim  /// \return true iff there were any incompatible types.
7100223017Sdim  bool CheckMessageArgumentTypes(QualType ReceiverType,
7101223017Sdim                                 Expr **Args, unsigned NumArgs, Selector Sel,
7102243830Sdim                                 ArrayRef<SourceLocation> SelectorLocs,
7103212795Sdim                                 ObjCMethodDecl *Method, bool isClassMessage,
7104223017Sdim                                 bool isSuperMessage,
7105212795Sdim                                 SourceLocation lbrac, SourceLocation rbrac,
7106218893Sdim                                 QualType &ReturnType, ExprValueKind &VK);
7107212795Sdim
7108223017Sdim  /// \brief Determine the result of a message send expression based on
7109223017Sdim  /// the type of the receiver, the method expected to receive the message,
7110223017Sdim  /// and the form of the message send.
7111223017Sdim  QualType getMessageSendResultType(QualType ReceiverType,
7112223017Sdim                                    ObjCMethodDecl *Method,
7113223017Sdim                                    bool isClassMessage, bool isSuperMessage);
7114224145Sdim
7115223017Sdim  /// \brief If the given expression involves a message send to a method
7116223017Sdim  /// with a related result type, emit a note describing what happened.
7117223017Sdim  void EmitRelatedResultTypeNote(const Expr *E);
7118234353Sdim
7119249423Sdim  /// \brief Given that we had incompatible pointer types in a return
7120249423Sdim  /// statement, check whether we're in a method with a related result
7121249423Sdim  /// type, and if so, emit a note describing what happened.
7122249423Sdim  void EmitRelatedResultTypeNoteForReturn(QualType destType);
7123249423Sdim
7124212795Sdim  /// CheckBooleanCondition - Diagnose problems involving the use of
7125212795Sdim  /// the given expression as a boolean condition (e.g. in an if
7126212795Sdim  /// statement).  Also performs the standard function and array
7127212795Sdim  /// decays, possibly changing the input variable.
7128212795Sdim  ///
7129212795Sdim  /// \param Loc - A location associated with the condition, e.g. the
7130212795Sdim  /// 'if' keyword.
7131212795Sdim  /// \return true iff there were any errors
7132226633Sdim  ExprResult CheckBooleanCondition(Expr *E, SourceLocation Loc);
7133212795Sdim
7134212795Sdim  ExprResult ActOnBooleanCondition(Scope *S, SourceLocation Loc,
7135226633Sdim                                   Expr *SubExpr);
7136234353Sdim
7137212795Sdim  /// DiagnoseAssignmentAsCondition - Given that an expression is
7138212795Sdim  /// being used as a boolean condition, warn if it's an assignment.
7139212795Sdim  void DiagnoseAssignmentAsCondition(Expr *E);
7140212795Sdim
7141218893Sdim  /// \brief Redundant parentheses over an equality comparison can indicate
7142218893Sdim  /// that the user intended an assignment used as condition.
7143226633Sdim  void DiagnoseEqualityWithExtraParens(ParenExpr *ParenE);
7144218893Sdim
7145212795Sdim  /// CheckCXXBooleanCondition - Returns true if conversion to bool is invalid.
7146221345Sdim  ExprResult CheckCXXBooleanCondition(Expr *CondExpr);
7147212795Sdim
7148212795Sdim  /// ConvertIntegerToTypeWarnOnOverflow - Convert the specified APInt to have
7149212795Sdim  /// the specified width and sign.  If an overflow occurs, detect it and emit
7150212795Sdim  /// the specified diagnostic.
7151212795Sdim  void ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &OldVal,
7152212795Sdim                                          unsigned NewWidth, bool NewSign,
7153212795Sdim                                          SourceLocation Loc, unsigned DiagID);
7154212795Sdim
7155212795Sdim  /// Checks that the Objective-C declaration is declared in the global scope.
7156212795Sdim  /// Emits an error and marks the declaration as invalid if it's not declared
7157212795Sdim  /// in the global scope.
7158212795Sdim  bool CheckObjCDeclScope(Decl *D);
7159212795Sdim
7160239462Sdim  /// \brief Abstract base class used for diagnosing integer constant
7161239462Sdim  /// expression violations.
7162239462Sdim  class VerifyICEDiagnoser {
7163239462Sdim  public:
7164239462Sdim    bool Suppress;
7165239462Sdim
7166239462Sdim    VerifyICEDiagnoser(bool Suppress = false) : Suppress(Suppress) { }
7167239462Sdim
7168239462Sdim    virtual void diagnoseNotICE(Sema &S, SourceLocation Loc, SourceRange SR) =0;
7169239462Sdim    virtual void diagnoseFold(Sema &S, SourceLocation Loc, SourceRange SR);
7170239462Sdim    virtual ~VerifyICEDiagnoser() { }
7171239462Sdim  };
7172239462Sdim
7173234353Sdim  /// VerifyIntegerConstantExpression - Verifies that an expression is an ICE,
7174212795Sdim  /// and reports the appropriate diagnostics. Returns false on success.
7175212795Sdim  /// Can optionally return the value of the expression.
7176234353Sdim  ExprResult VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result,
7177239462Sdim                                             VerifyICEDiagnoser &Diagnoser,
7178239462Sdim                                             bool AllowFold = true);
7179234353Sdim  ExprResult VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result,
7180239462Sdim                                             unsigned DiagID,
7181239462Sdim                                             bool AllowFold = true);
7182239462Sdim  ExprResult VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result=0);
7183212795Sdim
7184212795Sdim  /// VerifyBitField - verifies that a bit field expression is an ICE and has
7185212795Sdim  /// the correct width, and that the field type is valid.
7186212795Sdim  /// Returns false on success.
7187212795Sdim  /// Can optionally return whether the bit-field is of width 0
7188234353Sdim  ExprResult VerifyBitField(SourceLocation FieldLoc, IdentifierInfo *FieldName,
7189234353Sdim                            QualType FieldTy, Expr *BitWidth,
7190234353Sdim                            bool *ZeroWidth = 0);
7191212795Sdim
7192226633Sdim  enum CUDAFunctionTarget {
7193226633Sdim    CFT_Device,
7194226633Sdim    CFT_Global,
7195226633Sdim    CFT_Host,
7196226633Sdim    CFT_HostDevice
7197226633Sdim  };
7198226633Sdim
7199226633Sdim  CUDAFunctionTarget IdentifyCUDATarget(const FunctionDecl *D);
7200226633Sdim
7201226633Sdim  bool CheckCUDATarget(CUDAFunctionTarget CallerTarget,
7202226633Sdim                       CUDAFunctionTarget CalleeTarget);
7203226633Sdim
7204226633Sdim  bool CheckCUDATarget(const FunctionDecl *Caller, const FunctionDecl *Callee) {
7205226633Sdim    return CheckCUDATarget(IdentifyCUDATarget(Caller),
7206226633Sdim                           IdentifyCUDATarget(Callee));
7207226633Sdim  }
7208226633Sdim
7209212795Sdim  /// \name Code completion
7210212795Sdim  //@{
7211212795Sdim  /// \brief Describes the context in which code completion occurs.
7212212795Sdim  enum ParserCompletionContext {
7213212795Sdim    /// \brief Code completion occurs at top-level or namespace context.
7214212795Sdim    PCC_Namespace,
7215212795Sdim    /// \brief Code completion occurs within a class, struct, or union.
7216212795Sdim    PCC_Class,
7217212795Sdim    /// \brief Code completion occurs within an Objective-C interface, protocol,
7218212795Sdim    /// or category.
7219212795Sdim    PCC_ObjCInterface,
7220212795Sdim    /// \brief Code completion occurs within an Objective-C implementation or
7221212795Sdim    /// category implementation
7222212795Sdim    PCC_ObjCImplementation,
7223212795Sdim    /// \brief Code completion occurs within the list of instance variables
7224212795Sdim    /// in an Objective-C interface, protocol, category, or implementation.
7225212795Sdim    PCC_ObjCInstanceVariableList,
7226212795Sdim    /// \brief Code completion occurs following one or more template
7227212795Sdim    /// headers.
7228212795Sdim    PCC_Template,
7229212795Sdim    /// \brief Code completion occurs following one or more template
7230212795Sdim    /// headers within a class.
7231212795Sdim    PCC_MemberTemplate,
7232212795Sdim    /// \brief Code completion occurs within an expression.
7233212795Sdim    PCC_Expression,
7234212795Sdim    /// \brief Code completion occurs within a statement, which may
7235212795Sdim    /// also be an expression or a declaration.
7236212795Sdim    PCC_Statement,
7237212795Sdim    /// \brief Code completion occurs at the beginning of the
7238212795Sdim    /// initialization statement (or expression) in a for loop.
7239212795Sdim    PCC_ForInit,
7240212795Sdim    /// \brief Code completion occurs within the condition of an if,
7241212795Sdim    /// while, switch, or for statement.
7242212795Sdim    PCC_Condition,
7243234353Sdim    /// \brief Code completion occurs within the body of a function on a
7244212795Sdim    /// recovery path, where we do not have a specific handle on our position
7245212795Sdim    /// in the grammar.
7246212795Sdim    PCC_RecoveryInFunction,
7247212795Sdim    /// \brief Code completion occurs where only a type is permitted.
7248218893Sdim    PCC_Type,
7249218893Sdim    /// \brief Code completion occurs in a parenthesized expression, which
7250218893Sdim    /// might also be a type cast.
7251218893Sdim    PCC_ParenthesizedExpression,
7252234353Sdim    /// \brief Code completion occurs within a sequence of declaration
7253218893Sdim    /// specifiers within a function, method, or block.
7254218893Sdim    PCC_LocalDeclarationSpecifiers
7255212795Sdim  };
7256212795Sdim
7257234353Sdim  void CodeCompleteModuleImport(SourceLocation ImportLoc, ModuleIdPath Path);
7258212795Sdim  void CodeCompleteOrdinaryName(Scope *S,
7259212795Sdim                                ParserCompletionContext CompletionContext);
7260218893Sdim  void CodeCompleteDeclSpec(Scope *S, DeclSpec &DS,
7261218893Sdim                            bool AllowNonIdentifiers,
7262218893Sdim                            bool AllowNestedNameSpecifiers);
7263234353Sdim
7264212795Sdim  struct CodeCompleteExpressionData;
7265234353Sdim  void CodeCompleteExpression(Scope *S,
7266212795Sdim                              const CodeCompleteExpressionData &Data);
7267212795Sdim  void CodeCompleteMemberReferenceExpr(Scope *S, Expr *Base,
7268212795Sdim                                       SourceLocation OpLoc,
7269212795Sdim                                       bool IsArrow);
7270218893Sdim  void CodeCompletePostfixExpression(Scope *S, ExprResult LHS);
7271212795Sdim  void CodeCompleteTag(Scope *S, unsigned TagSpec);
7272212795Sdim  void CodeCompleteTypeQualifiers(DeclSpec &DS);
7273212795Sdim  void CodeCompleteCase(Scope *S);
7274249423Sdim  void CodeCompleteCall(Scope *S, Expr *Fn, ArrayRef<Expr *> Args);
7275212795Sdim  void CodeCompleteInitializer(Scope *S, Decl *D);
7276212795Sdim  void CodeCompleteReturn(Scope *S);
7277226633Sdim  void CodeCompleteAfterIf(Scope *S);
7278212795Sdim  void CodeCompleteAssignmentRHS(Scope *S, Expr *LHS);
7279234353Sdim
7280212795Sdim  void CodeCompleteQualifiedId(Scope *S, CXXScopeSpec &SS,
7281212795Sdim                               bool EnteringContext);
7282212795Sdim  void CodeCompleteUsing(Scope *S);
7283212795Sdim  void CodeCompleteUsingDirective(Scope *S);
7284212795Sdim  void CodeCompleteNamespaceDecl(Scope *S);
7285212795Sdim  void CodeCompleteNamespaceAliasDecl(Scope *S);
7286212795Sdim  void CodeCompleteOperatorName(Scope *S);
7287212795Sdim  void CodeCompleteConstructorInitializer(Decl *Constructor,
7288218893Sdim                                          CXXCtorInitializer** Initializers,
7289212795Sdim                                          unsigned NumInitializers);
7290234353Sdim  void CodeCompleteLambdaIntroducer(Scope *S, LambdaIntroducer &Intro,
7291234353Sdim                                    bool AfterAmpersand);
7292234353Sdim
7293226633Sdim  void CodeCompleteObjCAtDirective(Scope *S);
7294212795Sdim  void CodeCompleteObjCAtVisibility(Scope *S);
7295212795Sdim  void CodeCompleteObjCAtStatement(Scope *S);
7296212795Sdim  void CodeCompleteObjCAtExpression(Scope *S);
7297212795Sdim  void CodeCompleteObjCPropertyFlags(Scope *S, ObjCDeclSpec &ODS);
7298226633Sdim  void CodeCompleteObjCPropertyGetter(Scope *S);
7299226633Sdim  void CodeCompleteObjCPropertySetter(Scope *S);
7300234353Sdim  void CodeCompleteObjCPassingType(Scope *S, ObjCDeclSpec &DS,
7301218893Sdim                                   bool IsParameter);
7302212795Sdim  void CodeCompleteObjCMessageReceiver(Scope *S);
7303212795Sdim  void CodeCompleteObjCSuperMessage(Scope *S, SourceLocation SuperLoc,
7304212795Sdim                                    IdentifierInfo **SelIdents,
7305218893Sdim                                    unsigned NumSelIdents,
7306218893Sdim                                    bool AtArgumentExpression);
7307212795Sdim  void CodeCompleteObjCClassMessage(Scope *S, ParsedType Receiver,
7308212795Sdim                                    IdentifierInfo **SelIdents,
7309212795Sdim                                    unsigned NumSelIdents,
7310218893Sdim                                    bool AtArgumentExpression,
7311218893Sdim                                    bool IsSuper = false);
7312226633Sdim  void CodeCompleteObjCInstanceMessage(Scope *S, Expr *Receiver,
7313212795Sdim                                       IdentifierInfo **SelIdents,
7314218893Sdim                                       unsigned NumSelIdents,
7315218893Sdim                                       bool AtArgumentExpression,
7316218893Sdim                                       ObjCInterfaceDecl *Super = 0);
7317234353Sdim  void CodeCompleteObjCForCollection(Scope *S,
7318212795Sdim                                     DeclGroupPtrTy IterationVar);
7319212795Sdim  void CodeCompleteObjCSelector(Scope *S,
7320212795Sdim                                IdentifierInfo **SelIdents,
7321212795Sdim                                unsigned NumSelIdents);
7322212795Sdim  void CodeCompleteObjCProtocolReferences(IdentifierLocPair *Protocols,
7323212795Sdim                                          unsigned NumProtocols);
7324212795Sdim  void CodeCompleteObjCProtocolDecl(Scope *S);
7325212795Sdim  void CodeCompleteObjCInterfaceDecl(Scope *S);
7326212795Sdim  void CodeCompleteObjCSuperclass(Scope *S,
7327212795Sdim                                  IdentifierInfo *ClassName,
7328212795Sdim                                  SourceLocation ClassNameLoc);
7329212795Sdim  void CodeCompleteObjCImplementationDecl(Scope *S);
7330212795Sdim  void CodeCompleteObjCInterfaceCategory(Scope *S,
7331212795Sdim                                         IdentifierInfo *ClassName,
7332212795Sdim                                         SourceLocation ClassNameLoc);
7333212795Sdim  void CodeCompleteObjCImplementationCategory(Scope *S,
7334212795Sdim                                              IdentifierInfo *ClassName,
7335212795Sdim                                              SourceLocation ClassNameLoc);
7336226633Sdim  void CodeCompleteObjCPropertyDefinition(Scope *S);
7337212795Sdim  void CodeCompleteObjCPropertySynthesizeIvar(Scope *S,
7338226633Sdim                                              IdentifierInfo *PropertyName);
7339212795Sdim  void CodeCompleteObjCMethodDecl(Scope *S,
7340212795Sdim                                  bool IsInstanceMethod,
7341226633Sdim                                  ParsedType ReturnType);
7342234353Sdim  void CodeCompleteObjCMethodDeclSelector(Scope *S,
7343212795Sdim                                          bool IsInstanceMethod,
7344212795Sdim                                          bool AtParameterName,
7345212795Sdim                                          ParsedType ReturnType,
7346212795Sdim                                          IdentifierInfo **SelIdents,
7347212795Sdim                                          unsigned NumSelIdents);
7348212795Sdim  void CodeCompletePreprocessorDirective(bool InConditional);
7349212795Sdim  void CodeCompleteInPreprocessorConditionalExclusion(Scope *S);
7350212795Sdim  void CodeCompletePreprocessorMacroName(bool IsDefinition);
7351212795Sdim  void CodeCompletePreprocessorExpression();
7352212795Sdim  void CodeCompletePreprocessorMacroArgument(Scope *S,
7353212795Sdim                                             IdentifierInfo *Macro,
7354212795Sdim                                             MacroInfo *MacroInfo,
7355212795Sdim                                             unsigned Argument);
7356212795Sdim  void CodeCompleteNaturalLanguage();
7357218893Sdim  void GatherGlobalCodeCompletions(CodeCompletionAllocator &Allocator,
7358234353Sdim                                   CodeCompletionTUInfo &CCTUInfo,
7359226633Sdim                  SmallVectorImpl<CodeCompletionResult> &Results);
7360212795Sdim  //@}
7361212795Sdim
7362212795Sdim  //===--------------------------------------------------------------------===//
7363212795Sdim  // Extra semantic analysis beyond the C type system
7364212795Sdim
7365212795Sdimpublic:
7366212795Sdim  SourceLocation getLocationOfStringLiteralByte(const StringLiteral *SL,
7367212795Sdim                                                unsigned ByteNo) const;
7368212795Sdim
7369234353Sdimprivate:
7370226633Sdim  void CheckArrayAccess(const Expr *BaseExpr, const Expr *IndexExpr,
7371234353Sdim                        const ArraySubscriptExpr *ASE=0,
7372234353Sdim                        bool AllowOnePastEnd=true, bool IndexNegated=false);
7373221345Sdim  void CheckArrayAccess(const Expr *E);
7374239462Sdim  // Used to grab the relevant information from a FormatAttr and a
7375239462Sdim  // FunctionDeclaration.
7376239462Sdim  struct FormatStringInfo {
7377239462Sdim    unsigned FormatIdx;
7378239462Sdim    unsigned FirstDataArg;
7379239462Sdim    bool HasVAListArg;
7380239462Sdim  };
7381239462Sdim
7382239462Sdim  bool getFormatStringInfo(const FormatAttr *Format, bool IsCXXMember,
7383239462Sdim                           FormatStringInfo *FSI);
7384239462Sdim  bool CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall,
7385239462Sdim                         const FunctionProtoType *Proto);
7386239462Sdim  bool CheckObjCMethodCall(ObjCMethodDecl *Method, SourceLocation loc,
7387251662Sdim                           ArrayRef<const Expr *> Args);
7388239462Sdim  bool CheckBlockCall(NamedDecl *NDecl, CallExpr *TheCall,
7389239462Sdim                      const FunctionProtoType *Proto);
7390239462Sdim  void CheckConstructorCall(FunctionDecl *FDecl,
7391249423Sdim                            ArrayRef<const Expr *> Args,
7392239462Sdim                            const FunctionProtoType *Proto,
7393239462Sdim                            SourceLocation Loc);
7394212795Sdim
7395249423Sdim  void checkCall(NamedDecl *FDecl, ArrayRef<const Expr *> Args,
7396239462Sdim                 unsigned NumProtoArgs, bool IsMemberFunction,
7397239462Sdim                 SourceLocation Loc, SourceRange Range,
7398239462Sdim                 VariadicCallType CallType);
7399239462Sdim
7400239462Sdim
7401212795Sdim  bool CheckObjCString(Expr *Arg);
7402212795Sdim
7403212795Sdim  ExprResult CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
7404212795Sdim  bool CheckARMBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
7405239462Sdim  bool CheckMipsBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
7406212795Sdim
7407212795Sdim  bool SemaBuiltinVAStart(CallExpr *TheCall);
7408212795Sdim  bool SemaBuiltinUnorderedCompare(CallExpr *TheCall);
7409212795Sdim  bool SemaBuiltinFPClassification(CallExpr *TheCall, unsigned NumArgs);
7410212795Sdim
7411212795Sdimpublic:
7412212795Sdim  // Used by C++ template instantiation.
7413212795Sdim  ExprResult SemaBuiltinShuffleVector(CallExpr *TheCall);
7414212795Sdim
7415212795Sdimprivate:
7416212795Sdim  bool SemaBuiltinPrefetch(CallExpr *TheCall);
7417212795Sdim  bool SemaBuiltinObjectSize(CallExpr *TheCall);
7418212795Sdim  bool SemaBuiltinLongjmp(CallExpr *TheCall);
7419212795Sdim  ExprResult SemaBuiltinAtomicOverloaded(ExprResult TheCallResult);
7420226633Sdim  ExprResult SemaAtomicOpsOverloaded(ExprResult TheCallResult,
7421226633Sdim                                     AtomicExpr::AtomicOp Op);
7422212795Sdim  bool SemaBuiltinConstantArg(CallExpr *TheCall, int ArgNum,
7423212795Sdim                              llvm::APSInt &Result);
7424212795Sdim
7425234353Sdim  enum FormatStringType {
7426234353Sdim    FST_Scanf,
7427234353Sdim    FST_Printf,
7428234353Sdim    FST_NSString,
7429234353Sdim    FST_Strftime,
7430234353Sdim    FST_Strfmon,
7431234353Sdim    FST_Kprintf,
7432234353Sdim    FST_Unknown
7433234353Sdim  };
7434234353Sdim  static FormatStringType GetFormatStringType(const FormatAttr *Format);
7435212795Sdim
7436239462Sdim  enum StringLiteralCheckType {
7437239462Sdim    SLCT_NotALiteral,
7438239462Sdim    SLCT_UncheckedLiteral,
7439239462Sdim    SLCT_CheckedLiteral
7440239462Sdim  };
7441239462Sdim
7442239462Sdim  StringLiteralCheckType checkFormatStringExpr(const Expr *E,
7443249423Sdim                                               ArrayRef<const Expr *> Args,
7444239462Sdim                                               bool HasVAListArg,
7445239462Sdim                                               unsigned format_idx,
7446239462Sdim                                               unsigned firstDataArg,
7447239462Sdim                                               FormatStringType Type,
7448239462Sdim                                               VariadicCallType CallType,
7449239462Sdim                                               bool inFunctionCall = true);
7450239462Sdim
7451212795Sdim  void CheckFormatString(const StringLiteral *FExpr, const Expr *OrigFormatExpr,
7452249423Sdim                         ArrayRef<const Expr *> Args, bool HasVAListArg,
7453212795Sdim                         unsigned format_idx, unsigned firstDataArg,
7454239462Sdim                         FormatStringType Type, bool inFunctionCall,
7455239462Sdim                         VariadicCallType CallType);
7456212795Sdim
7457249423Sdim  bool CheckFormatArguments(const FormatAttr *Format,
7458249423Sdim                            ArrayRef<const Expr *> Args,
7459249423Sdim                            bool IsCXXMember,
7460239462Sdim                            VariadicCallType CallType,
7461234353Sdim                            SourceLocation Loc, SourceRange Range);
7462249423Sdim  bool CheckFormatArguments(ArrayRef<const Expr *> Args,
7463234353Sdim                            bool HasVAListArg, unsigned format_idx,
7464234353Sdim                            unsigned firstDataArg, FormatStringType Type,
7465239462Sdim                            VariadicCallType CallType,
7466234353Sdim                            SourceLocation Loc, SourceRange range);
7467234353Sdim
7468212795Sdim  void CheckNonNullArguments(const NonNullAttr *NonNull,
7469221345Sdim                             const Expr * const *ExprArgs,
7470221345Sdim                             SourceLocation CallSiteLoc);
7471212795Sdim
7472234353Sdim  void CheckMemaccessArguments(const CallExpr *Call,
7473234353Sdim                               unsigned BId,
7474226633Sdim                               IdentifierInfo *FnName);
7475221345Sdim
7476226633Sdim  void CheckStrlcpycatArguments(const CallExpr *Call,
7477226633Sdim                                IdentifierInfo *FnName);
7478226633Sdim
7479234353Sdim  void CheckStrncatArguments(const CallExpr *Call,
7480234353Sdim                             IdentifierInfo *FnName);
7481234353Sdim
7482212795Sdim  void CheckReturnStackAddr(Expr *RetValExp, QualType lhsType,
7483212795Sdim                            SourceLocation ReturnLoc);
7484226633Sdim  void CheckFloatComparison(SourceLocation Loc, Expr* LHS, Expr* RHS);
7485218893Sdim  void CheckImplicitConversions(Expr *E, SourceLocation CC = SourceLocation());
7486249423Sdim  void CheckForIntOverflow(Expr *E);
7487249423Sdim  void CheckUnsequencedOperations(Expr *E);
7488212795Sdim
7489249423Sdim  /// \brief Perform semantic checks on a completed expression. This will either
7490249423Sdim  /// be a full-expression or a default argument expression.
7491249423Sdim  void CheckCompletedExpr(Expr *E, SourceLocation CheckLoc = SourceLocation(),
7492249423Sdim                          bool IsConstexpr = false);
7493249423Sdim
7494218893Sdim  void CheckBitFieldInitialization(SourceLocation InitLoc, FieldDecl *Field,
7495218893Sdim                                   Expr *Init);
7496218893Sdim
7497239462Sdimpublic:
7498239462Sdim  /// \brief Register a magic integral constant to be used as a type tag.
7499239462Sdim  void RegisterTypeTagForDatatype(const IdentifierInfo *ArgumentKind,
7500239462Sdim                                  uint64_t MagicValue, QualType Type,
7501239462Sdim                                  bool LayoutCompatible, bool MustBeNull);
7502239462Sdim
7503239462Sdim  struct TypeTagData {
7504239462Sdim    TypeTagData() {}
7505239462Sdim
7506239462Sdim    TypeTagData(QualType Type, bool LayoutCompatible, bool MustBeNull) :
7507239462Sdim        Type(Type), LayoutCompatible(LayoutCompatible),
7508239462Sdim        MustBeNull(MustBeNull)
7509239462Sdim    {}
7510239462Sdim
7511239462Sdim    QualType Type;
7512239462Sdim
7513239462Sdim    /// If true, \c Type should be compared with other expression's types for
7514239462Sdim    /// layout-compatibility.
7515239462Sdim    unsigned LayoutCompatible : 1;
7516239462Sdim    unsigned MustBeNull : 1;
7517239462Sdim  };
7518239462Sdim
7519239462Sdim  /// A pair of ArgumentKind identifier and magic value.  This uniquely
7520239462Sdim  /// identifies the magic value.
7521239462Sdim  typedef std::pair<const IdentifierInfo *, uint64_t> TypeTagMagicValue;
7522239462Sdim
7523239462Sdimprivate:
7524239462Sdim  /// \brief A map from magic value to type information.
7525239462Sdim  OwningPtr<llvm::DenseMap<TypeTagMagicValue, TypeTagData> >
7526239462Sdim      TypeTagForDatatypeMagicValues;
7527239462Sdim
7528239462Sdim  /// \brief Peform checks on a call of a function with argument_with_type_tag
7529239462Sdim  /// or pointer_with_type_tag attributes.
7530239462Sdim  void CheckArgumentWithTypeTag(const ArgumentWithTypeTagAttr *Attr,
7531239462Sdim                                const Expr * const *ExprArgs);
7532239462Sdim
7533212795Sdim  /// \brief The parser's current scope.
7534212795Sdim  ///
7535212795Sdim  /// The parser maintains this state here.
7536212795Sdim  Scope *CurScope;
7537234353Sdim
7538249423Sdim  mutable IdentifierInfo *Ident_super;
7539249423Sdim
7540212795Sdimprotected:
7541212795Sdim  friend class Parser;
7542234353Sdim  friend class InitializationSequence;
7543224145Sdim  friend class ASTReader;
7544224145Sdim  friend class ASTWriter;
7545234353Sdim
7546224145Sdimpublic:
7547212795Sdim  /// \brief Retrieve the parser's current scope.
7548224145Sdim  ///
7549224145Sdim  /// This routine must only be used when it is certain that semantic analysis
7550224145Sdim  /// and the parser are in precisely the same context, which is not the case
7551224145Sdim  /// when, e.g., we are performing any kind of template instantiation.
7552224145Sdim  /// Therefore, the only safe places to use this scope are in the parser
7553224145Sdim  /// itself and in routines directly invoked from the parser and *never* from
7554224145Sdim  /// template substitution or instantiation.
7555224145Sdim  Scope *getCurScope() const { return CurScope; }
7556234353Sdim
7557249423Sdim  IdentifierInfo *getSuperIdentifier() const;
7558249423Sdim
7559226633Sdim  Decl *getObjCDeclContext() const;
7560226633Sdim
7561226633Sdim  DeclContext *getCurLexicalContext() const {
7562226633Sdim    return OriginalLexicalContext ? OriginalLexicalContext : CurContext;
7563226633Sdim  }
7564226633Sdim
7565226633Sdim  AvailabilityResult getCurContextAvailability() const;
7566243830Sdim
7567243830Sdim  const DeclContext *getCurObjCLexicalContext() const {
7568243830Sdim    const DeclContext *DC = getCurLexicalContext();
7569243830Sdim    // A category implicitly has the attribute of the interface.
7570243830Sdim    if (const ObjCCategoryDecl *CatD = dyn_cast<ObjCCategoryDecl>(DC))
7571243830Sdim      DC = CatD->getClassInterface();
7572243830Sdim    return DC;
7573243830Sdim  }
7574212795Sdim};
7575212795Sdim
7576212795Sdim/// \brief RAII object that enters a new expression evaluation context.
7577212795Sdimclass EnterExpressionEvaluationContext {
7578212795Sdim  Sema &Actions;
7579212795Sdim
7580212795Sdimpublic:
7581212795Sdim  EnterExpressionEvaluationContext(Sema &Actions,
7582234353Sdim                                   Sema::ExpressionEvaluationContext NewContext,
7583234353Sdim                                   Decl *LambdaContextDecl = 0,
7584234353Sdim                                   bool IsDecltype = false)
7585212795Sdim    : Actions(Actions) {
7586234353Sdim    Actions.PushExpressionEvaluationContext(NewContext, LambdaContextDecl,
7587234353Sdim                                            IsDecltype);
7588212795Sdim  }
7589243830Sdim  EnterExpressionEvaluationContext(Sema &Actions,
7590243830Sdim                                   Sema::ExpressionEvaluationContext NewContext,
7591243830Sdim                                   Sema::ReuseLambdaContextDecl_t,
7592243830Sdim                                   bool IsDecltype = false)
7593243830Sdim    : Actions(Actions) {
7594243830Sdim    Actions.PushExpressionEvaluationContext(NewContext,
7595243830Sdim                                            Sema::ReuseLambdaContextDecl,
7596243830Sdim                                            IsDecltype);
7597243830Sdim  }
7598212795Sdim
7599212795Sdim  ~EnterExpressionEvaluationContext() {
7600212795Sdim    Actions.PopExpressionEvaluationContext();
7601212795Sdim  }
7602212795Sdim};
7603212795Sdim
7604212795Sdim}  // end namespace clang
7605212795Sdim
7606212795Sdim#endif
7607