clang API Documentation

Sema.h
Go to the documentation of this file.
00001 //===--- Sema.h - Semantic Analysis & AST Building --------------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file defines the Sema class, which performs semantic analysis and
00011 // builds ASTs.
00012 //
00013 //===----------------------------------------------------------------------===//
00014 
00015 #ifndef LLVM_CLANG_SEMA_SEMA_H
00016 #define LLVM_CLANG_SEMA_SEMA_H
00017 
00018 #include "clang/Sema/Ownership.h"
00019 #include "clang/Sema/AnalysisBasedWarnings.h"
00020 #include "clang/Sema/IdentifierResolver.h"
00021 #include "clang/Sema/ObjCMethodList.h"
00022 #include "clang/Sema/DeclSpec.h"
00023 #include "clang/Sema/ExternalSemaSource.h"
00024 #include "clang/Sema/LocInfoType.h"
00025 #include "clang/Sema/TypoCorrection.h"
00026 #include "clang/Sema/Weak.h"
00027 #include "clang/AST/Expr.h"
00028 #include "clang/AST/ExprObjC.h"
00029 #include "clang/AST/DeclarationName.h"
00030 #include "clang/AST/ExternalASTSource.h"
00031 #include "clang/AST/TypeLoc.h"
00032 #include "clang/AST/NSAPI.h"
00033 #include "clang/Lex/ModuleLoader.h"
00034 #include "clang/Basic/Specifiers.h"
00035 #include "clang/Basic/TemplateKinds.h"
00036 #include "clang/Basic/TypeTraits.h"
00037 #include "clang/Basic/ExpressionTraits.h"
00038 #include "llvm/ADT/ArrayRef.h"
00039 #include "llvm/ADT/OwningPtr.h"
00040 #include "llvm/ADT/SmallPtrSet.h"
00041 #include "llvm/ADT/SmallVector.h"
00042 #include <deque>
00043 #include <string>
00044 
00045 namespace llvm {
00046   class APSInt;
00047   template <typename ValueT> struct DenseMapInfo;
00048   template <typename ValueT, typename ValueInfoT> class DenseSet;
00049   class SmallBitVector;
00050 }
00051 
00052 namespace clang {
00053   class ADLResult;
00054   class ASTConsumer;
00055   class ASTContext;
00056   class ASTMutationListener;
00057   class ASTReader;
00058   class ASTWriter;
00059   class ArrayType;
00060   class AttributeList;
00061   class BlockDecl;
00062   class CXXBasePath;
00063   class CXXBasePaths;
00064   class CXXBindTemporaryExpr;
00065   typedef SmallVector<CXXBaseSpecifier*, 4> CXXCastPath;
00066   class CXXConstructorDecl;
00067   class CXXConversionDecl;
00068   class CXXDestructorDecl;
00069   class CXXFieldCollector;
00070   class CXXMemberCallExpr;
00071   class CXXMethodDecl;
00072   class CXXScopeSpec;
00073   class CXXTemporary;
00074   class CXXTryStmt;
00075   class CallExpr;
00076   class ClassTemplateDecl;
00077   class ClassTemplatePartialSpecializationDecl;
00078   class ClassTemplateSpecializationDecl;
00079   class CodeCompleteConsumer;
00080   class CodeCompletionAllocator;
00081   class CodeCompletionTUInfo;
00082   class CodeCompletionResult;
00083   class Decl;
00084   class DeclAccessPair;
00085   class DeclContext;
00086   class DeclRefExpr;
00087   class DeclaratorDecl;
00088   class DeducedTemplateArgument;
00089   class DependentDiagnostic;
00090   class DesignatedInitExpr;
00091   class Designation;
00092   class EnumConstantDecl;
00093   class Expr;
00094   class ExtVectorType;
00095   class ExternalSemaSource;
00096   class FormatAttr;
00097   class FriendDecl;
00098   class FunctionDecl;
00099   class FunctionProtoType;
00100   class FunctionTemplateDecl;
00101   class ImplicitConversionSequence;
00102   class InitListExpr;
00103   class InitializationKind;
00104   class InitializationSequence;
00105   class InitializedEntity;
00106   class IntegerLiteral;
00107   class LabelStmt;
00108   class LambdaExpr;
00109   class LangOptions;
00110   class LocalInstantiationScope;
00111   class LookupResult;
00112   class MacroInfo;
00113   class MultiLevelTemplateArgumentList;
00114   class NamedDecl;
00115   class NonNullAttr;
00116   class ObjCCategoryDecl;
00117   class ObjCCategoryImplDecl;
00118   class ObjCCompatibleAliasDecl;
00119   class ObjCContainerDecl;
00120   class ObjCImplDecl;
00121   class ObjCImplementationDecl;
00122   class ObjCInterfaceDecl;
00123   class ObjCIvarDecl;
00124   template <class T> class ObjCList;
00125   class ObjCMessageExpr;
00126   class ObjCMethodDecl;
00127   class ObjCPropertyDecl;
00128   class ObjCProtocolDecl;
00129   class OverloadCandidateSet;
00130   class OverloadExpr;
00131   class ParenListExpr;
00132   class ParmVarDecl;
00133   class Preprocessor;
00134   class PseudoDestructorTypeStorage;
00135   class PseudoObjectExpr;
00136   class QualType;
00137   class StandardConversionSequence;
00138   class Stmt;
00139   class StringLiteral;
00140   class SwitchStmt;
00141   class TargetAttributesSema;
00142   class TemplateArgument;
00143   class TemplateArgumentList;
00144   class TemplateArgumentLoc;
00145   class TemplateDecl;
00146   class TemplateParameterList;
00147   class TemplatePartialOrderingContext;
00148   class TemplateTemplateParmDecl;
00149   class Token;
00150   class TypeAliasDecl;
00151   class TypedefDecl;
00152   class TypedefNameDecl;
00153   class TypeLoc;
00154   class UnqualifiedId;
00155   class UnresolvedLookupExpr;
00156   class UnresolvedMemberExpr;
00157   class UnresolvedSetImpl;
00158   class UnresolvedSetIterator;
00159   class UsingDecl;
00160   class UsingShadowDecl;
00161   class ValueDecl;
00162   class VarDecl;
00163   class VisibilityAttr;
00164   class VisibleDeclConsumer;
00165   class IndirectFieldDecl;
00166 
00167 namespace sema {
00168   class AccessedEntity;
00169   class BlockScopeInfo;
00170   class CompoundScopeInfo;
00171   class DelayedDiagnostic;
00172   class DelayedDiagnosticPool;
00173   class FunctionScopeInfo;
00174   class LambdaScopeInfo;
00175   class PossiblyUnreachableDiag;
00176   class TemplateDeductionInfo;
00177 }
00178 
00179 // FIXME: No way to easily map from TemplateTypeParmTypes to
00180 // TemplateTypeParmDecls, so we have this horrible PointerUnion.
00181 typedef std::pair<llvm::PointerUnion<const TemplateTypeParmType*, NamedDecl*>,
00182                   SourceLocation> UnexpandedParameterPack;
00183 
00184 /// Sema - This implements semantic analysis and AST building for C.
00185 class Sema {
00186   Sema(const Sema&);           // DO NOT IMPLEMENT
00187   void operator=(const Sema&); // DO NOT IMPLEMENT
00188   mutable const TargetAttributesSema* TheTargetAttributesSema;
00189 public:
00190   typedef OpaquePtr<DeclGroupRef> DeclGroupPtrTy;
00191   typedef OpaquePtr<TemplateName> TemplateTy;
00192   typedef OpaquePtr<QualType> TypeTy;
00193 
00194   OpenCLOptions OpenCLFeatures;
00195   FPOptions FPFeatures;
00196 
00197   const LangOptions &LangOpts;
00198   Preprocessor &PP;
00199   ASTContext &Context;
00200   ASTConsumer &Consumer;
00201   DiagnosticsEngine &Diags;
00202   SourceManager &SourceMgr;
00203 
00204   /// \brief Flag indicating whether or not to collect detailed statistics.
00205   bool CollectStats;
00206 
00207   /// \brief Source of additional semantic information.
00208   ExternalSemaSource *ExternalSource;
00209 
00210   /// \brief Code-completion consumer.
00211   CodeCompleteConsumer *CodeCompleter;
00212 
00213   /// CurContext - This is the current declaration context of parsing.
00214   DeclContext *CurContext;
00215 
00216   /// \brief Generally null except when we temporarily switch decl contexts,
00217   /// like in \see ActOnObjCTemporaryExitContainerContext.
00218   DeclContext *OriginalLexicalContext;
00219 
00220   /// VAListTagName - The declaration name corresponding to __va_list_tag.
00221   /// This is used as part of a hack to omit that class from ADL results.
00222   DeclarationName VAListTagName;
00223 
00224   /// PackContext - Manages the stack for #pragma pack. An alignment
00225   /// of 0 indicates default alignment.
00226   void *PackContext; // Really a "PragmaPackStack*"
00227 
00228   bool MSStructPragmaOn; // True when #pragma ms_struct on
00229 
00230   /// VisContext - Manages the stack for #pragma GCC visibility.
00231   void *VisContext; // Really a "PragmaVisStack*"
00232 
00233   /// ExprNeedsCleanups - True if the current evaluation context
00234   /// requires cleanups to be run at its conclusion.
00235   bool ExprNeedsCleanups;
00236 
00237   /// ExprCleanupObjects - This is the stack of objects requiring
00238   /// cleanup that are created by the current full expression.  The
00239   /// element type here is ExprWithCleanups::Object.
00240   SmallVector<BlockDecl*, 8> ExprCleanupObjects;
00241 
00242   llvm::SmallPtrSet<Expr*, 8> MaybeODRUseExprs;
00243 
00244   /// \brief Stack containing information about each of the nested
00245   /// function, block, and method scopes that are currently active.
00246   ///
00247   /// This array is never empty.  Clients should ignore the first
00248   /// element, which is used to cache a single FunctionScopeInfo
00249   /// that's used to parse every top-level function.
00250   SmallVector<sema::FunctionScopeInfo *, 4> FunctionScopes;
00251 
00252   typedef LazyVector<TypedefNameDecl *, ExternalSemaSource,
00253                      &ExternalSemaSource::ReadExtVectorDecls, 2, 2>
00254     ExtVectorDeclsType;
00255 
00256   /// ExtVectorDecls - This is a list all the extended vector types. This allows
00257   /// us to associate a raw vector type with one of the ext_vector type names.
00258   /// This is only necessary for issuing pretty diagnostics.
00259   ExtVectorDeclsType ExtVectorDecls;
00260 
00261   /// \brief The set of types for which we have already complained about the
00262   /// definitions being hidden.
00263   ///
00264   /// This set is used to suppress redundant diagnostics.
00265   llvm::SmallPtrSet<NamedDecl *, 4> HiddenDefinitions;
00266   
00267   /// FieldCollector - Collects CXXFieldDecls during parsing of C++ classes.
00268   OwningPtr<CXXFieldCollector> FieldCollector;
00269 
00270   typedef llvm::SmallPtrSet<const CXXRecordDecl*, 8> RecordDeclSetTy;
00271 
00272   /// PureVirtualClassDiagSet - a set of class declarations which we have
00273   /// emitted a list of pure virtual functions. Used to prevent emitting the
00274   /// same list more than once.
00275   OwningPtr<RecordDeclSetTy> PureVirtualClassDiagSet;
00276 
00277   /// ParsingInitForAutoVars - a set of declarations with auto types for which
00278   /// we are currently parsing the initializer.
00279   llvm::SmallPtrSet<const Decl*, 4> ParsingInitForAutoVars;
00280 
00281   /// \brief A mapping from external names to the most recent
00282   /// locally-scoped external declaration with that name.
00283   ///
00284   /// This map contains external declarations introduced in local
00285   /// scoped, e.g.,
00286   ///
00287   /// \code
00288   /// void f() {
00289   ///   void foo(int, int);
00290   /// }
00291   /// \endcode
00292   ///
00293   /// Here, the name "foo" will be associated with the declaration on
00294   /// "foo" within f. This name is not visible outside of
00295   /// "f". However, we still find it in two cases:
00296   ///
00297   ///   - If we are declaring another external with the name "foo", we
00298   ///     can find "foo" as a previous declaration, so that the types
00299   ///     of this external declaration can be checked for
00300   ///     compatibility.
00301   ///
00302   ///   - If we would implicitly declare "foo" (e.g., due to a call to
00303   ///     "foo" in C when no prototype or definition is visible), then
00304   ///     we find this declaration of "foo" and complain that it is
00305   ///     not visible.
00306   llvm::DenseMap<DeclarationName, NamedDecl *> LocallyScopedExternalDecls;
00307 
00308   /// \brief Look for a locally scoped external declaration by the given name.
00309   llvm::DenseMap<DeclarationName, NamedDecl *>::iterator
00310   findLocallyScopedExternalDecl(DeclarationName Name);
00311 
00312   typedef LazyVector<VarDecl *, ExternalSemaSource,
00313                      &ExternalSemaSource::ReadTentativeDefinitions, 2, 2>
00314     TentativeDefinitionsType;
00315 
00316   /// \brief All the tentative definitions encountered in the TU.
00317   TentativeDefinitionsType TentativeDefinitions;
00318 
00319   typedef LazyVector<const DeclaratorDecl *, ExternalSemaSource,
00320                      &ExternalSemaSource::ReadUnusedFileScopedDecls, 2, 2>
00321     UnusedFileScopedDeclsType;
00322 
00323   /// \brief The set of file scoped decls seen so far that have not been used
00324   /// and must warn if not used. Only contains the first declaration.
00325   UnusedFileScopedDeclsType UnusedFileScopedDecls;
00326 
00327   typedef LazyVector<CXXConstructorDecl *, ExternalSemaSource,
00328                      &ExternalSemaSource::ReadDelegatingConstructors, 2, 2>
00329     DelegatingCtorDeclsType;
00330 
00331   /// \brief All the delegating constructors seen so far in the file, used for
00332   /// cycle detection at the end of the TU.
00333   DelegatingCtorDeclsType DelegatingCtorDecls;
00334 
00335   /// \brief All the destructors seen during a class definition that had their
00336   /// exception spec computation delayed because it depended on an unparsed
00337   /// exception spec.
00338   SmallVector<CXXDestructorDecl*, 2> DelayedDestructorExceptionSpecs;
00339 
00340   /// \brief All the overriding destructors seen during a class definition
00341   /// (there could be multiple due to nested classes) that had their exception
00342   /// spec checks delayed, plus the overridden destructor.
00343   SmallVector<std::pair<const CXXDestructorDecl*,
00344                               const CXXDestructorDecl*>, 2>
00345       DelayedDestructorExceptionSpecChecks;
00346 
00347   /// \brief Callback to the parser to parse templated functions when needed.
00348   typedef void LateTemplateParserCB(void *P, const FunctionDecl *FD);
00349   LateTemplateParserCB *LateTemplateParser;
00350   void *OpaqueParser;
00351 
00352   void SetLateTemplateParser(LateTemplateParserCB *LTP, void *P) {
00353     LateTemplateParser = LTP;
00354     OpaqueParser = P;
00355   }
00356 
00357   class DelayedDiagnostics;
00358 
00359   class DelayedDiagnosticsState {
00360     sema::DelayedDiagnosticPool *SavedPool;
00361     friend class Sema::DelayedDiagnostics;
00362   };
00363   typedef DelayedDiagnosticsState ParsingDeclState;
00364   typedef DelayedDiagnosticsState ProcessingContextState;
00365 
00366   /// A class which encapsulates the logic for delaying diagnostics
00367   /// during parsing and other processing.
00368   class DelayedDiagnostics {
00369     /// \brief The current pool of diagnostics into which delayed
00370     /// diagnostics should go.
00371     sema::DelayedDiagnosticPool *CurPool;
00372 
00373   public:
00374     DelayedDiagnostics() : CurPool(0) {}
00375 
00376     /// Adds a delayed diagnostic.    
00377     void add(const sema::DelayedDiagnostic &diag); // in DelayedDiagnostic.h
00378 
00379     /// Determines whether diagnostics should be delayed.
00380     bool shouldDelayDiagnostics() { return CurPool != 0; }
00381 
00382     /// Returns the current delayed-diagnostics pool.
00383     sema::DelayedDiagnosticPool *getCurrentPool() const {
00384       return CurPool;
00385     }
00386 
00387     /// Enter a new scope.  Access and deprecation diagnostics will be
00388     /// collected in this pool.
00389     DelayedDiagnosticsState push(sema::DelayedDiagnosticPool &pool) {
00390       DelayedDiagnosticsState state;
00391       state.SavedPool = CurPool;
00392       CurPool = &pool;
00393       return state;
00394     }
00395 
00396     /// Leave a delayed-diagnostic state that was previously pushed.
00397     /// Do not emit any of the diagnostics.  This is performed as part
00398     /// of the bookkeeping of popping a pool "properly".
00399     void popWithoutEmitting(DelayedDiagnosticsState state) {
00400       CurPool = state.SavedPool;
00401     }
00402 
00403     /// Enter a new scope where access and deprecation diagnostics are
00404     /// not delayed.
00405     DelayedDiagnosticsState pushUndelayed() {
00406       DelayedDiagnosticsState state;
00407       state.SavedPool = CurPool;
00408       CurPool = 0;
00409       return state;
00410     }
00411 
00412     /// Undo a previous pushUndelayed().
00413     void popUndelayed(DelayedDiagnosticsState state) {
00414       assert(CurPool == NULL);
00415       CurPool = state.SavedPool;
00416     }
00417   } DelayedDiagnostics;
00418 
00419   /// A RAII object to temporarily push a declaration context.
00420   class ContextRAII {
00421   private:
00422     Sema &S;
00423     DeclContext *SavedContext;
00424     ProcessingContextState SavedContextState;
00425     QualType SavedCXXThisTypeOverride;
00426     
00427   public:
00428     ContextRAII(Sema &S, DeclContext *ContextToPush)
00429       : S(S), SavedContext(S.CurContext),
00430         SavedContextState(S.DelayedDiagnostics.pushUndelayed()),
00431         SavedCXXThisTypeOverride(S.CXXThisTypeOverride)
00432     {
00433       assert(ContextToPush && "pushing null context");
00434       S.CurContext = ContextToPush;
00435     }
00436 
00437     void pop() {
00438       if (!SavedContext) return;
00439       S.CurContext = SavedContext;
00440       S.DelayedDiagnostics.popUndelayed(SavedContextState);
00441       S.CXXThisTypeOverride = SavedCXXThisTypeOverride;
00442       SavedContext = 0;
00443     }
00444 
00445     ~ContextRAII() {
00446       pop();
00447     }
00448   };
00449 
00450   /// WeakUndeclaredIdentifiers - Identifiers contained in
00451   /// #pragma weak before declared. rare. may alias another
00452   /// identifier, declared or undeclared
00453   llvm::DenseMap<IdentifierInfo*,WeakInfo> WeakUndeclaredIdentifiers;
00454 
00455   /// ExtnameUndeclaredIdentifiers - Identifiers contained in
00456   /// #pragma redefine_extname before declared.  Used in Solaris system headers
00457   /// to define functions that occur in multiple standards to call the version
00458   /// in the currently selected standard.
00459   llvm::DenseMap<IdentifierInfo*,AsmLabelAttr*> ExtnameUndeclaredIdentifiers;
00460 
00461 
00462   /// \brief Load weak undeclared identifiers from the external source.
00463   void LoadExternalWeakUndeclaredIdentifiers();
00464 
00465   /// WeakTopLevelDecl - Translation-unit scoped declarations generated by
00466   /// #pragma weak during processing of other Decls.
00467   /// I couldn't figure out a clean way to generate these in-line, so
00468   /// we store them here and handle separately -- which is a hack.
00469   /// It would be best to refactor this.
00470   SmallVector<Decl*,2> WeakTopLevelDecl;
00471 
00472   IdentifierResolver IdResolver;
00473 
00474   /// Translation Unit Scope - useful to Objective-C actions that need
00475   /// to lookup file scope declarations in the "ordinary" C decl namespace.
00476   /// For example, user-defined classes, built-in "id" type, etc.
00477   Scope *TUScope;
00478 
00479   /// \brief The C++ "std" namespace, where the standard library resides.
00480   LazyDeclPtr StdNamespace;
00481 
00482   /// \brief The C++ "std::bad_alloc" class, which is defined by the C++
00483   /// standard library.
00484   LazyDeclPtr StdBadAlloc;
00485 
00486   /// \brief The C++ "std::initializer_list" template, which is defined in
00487   /// <initializer_list>.
00488   ClassTemplateDecl *StdInitializerList;
00489 
00490   /// \brief The C++ "type_info" declaration, which is defined in <typeinfo>.
00491   RecordDecl *CXXTypeInfoDecl;
00492 
00493   /// \brief The MSVC "_GUID" struct, which is defined in MSVC header files.
00494   RecordDecl *MSVCGuidDecl;
00495 
00496   /// \brief Caches identifiers/selectors for NSFoundation APIs.
00497   llvm::OwningPtr<NSAPI> NSAPIObj;
00498 
00499   /// \brief The declaration of the Objective-C NSNumber class.
00500   ObjCInterfaceDecl *NSNumberDecl;
00501   
00502   /// \brief Pointer to NSNumber type (NSNumber *).
00503   QualType NSNumberPointer;
00504   
00505   /// \brief The Objective-C NSNumber methods used to create NSNumber literals.
00506   ObjCMethodDecl *NSNumberLiteralMethods[NSAPI::NumNSNumberLiteralMethods];
00507   
00508   /// \brief The declaration of the Objective-C NSString class.
00509   ObjCInterfaceDecl *NSStringDecl;
00510 
00511   /// \brief Pointer to NSString type (NSString *).
00512   QualType NSStringPointer;
00513   
00514   /// \brief The declaration of the stringWithUTF8String: method.
00515   ObjCMethodDecl *StringWithUTF8StringMethod;
00516 
00517   /// \brief The declaration of the Objective-C NSArray class.
00518   ObjCInterfaceDecl *NSArrayDecl;
00519 
00520   /// \brief The declaration of the arrayWithObjects:count: method.
00521   ObjCMethodDecl *ArrayWithObjectsMethod;
00522   
00523   /// \brief The declaration of the Objective-C NSDictionary class.
00524   ObjCInterfaceDecl *NSDictionaryDecl;
00525 
00526   /// \brief The declaration of the dictionaryWithObjects:forKeys:count: method.
00527   ObjCMethodDecl *DictionaryWithObjectsMethod;
00528 
00529   /// \brief id<NSCopying> type.
00530   QualType QIDNSCopying;
00531 
00532   /// A flag to remember whether the implicit forms of operator new and delete
00533   /// have been declared.
00534   bool GlobalNewDeleteDeclared;
00535 
00536   /// A flag that is set when parsing a -dealloc method and no [super dealloc]
00537   /// call was found yet.
00538   bool ObjCShouldCallSuperDealloc;
00539   /// A flag that is set when parsing a -finalize method and no [super finalize]
00540   /// call was found yet.
00541   bool ObjCShouldCallSuperFinalize;
00542 
00543   /// \brief Describes how the expressions currently being parsed are
00544   /// evaluated at run-time, if at all.
00545   enum ExpressionEvaluationContext {
00546     /// \brief The current expression and its subexpressions occur within an
00547     /// unevaluated operand (C++11 [expr]p7), such as the subexpression of
00548     /// \c sizeof, where the type of the expression may be significant but
00549     /// no code will be generated to evaluate the value of the expression at
00550     /// run time.
00551     Unevaluated,
00552 
00553     /// \brief The current context is "potentially evaluated" in C++11 terms,
00554     /// but the expression is evaluated at compile-time (like the values of
00555     /// cases in a switch statment).
00556     ConstantEvaluated,
00557 
00558     /// \brief The current expression is potentially evaluated at run time,
00559     /// which means that code may be generated to evaluate the value of the
00560     /// expression at run time.
00561     PotentiallyEvaluated,
00562 
00563     /// \brief The current expression is potentially evaluated, but any
00564     /// declarations referenced inside that expression are only used if
00565     /// in fact the current expression is used.
00566     ///
00567     /// This value is used when parsing default function arguments, for which
00568     /// we would like to provide diagnostics (e.g., passing non-POD arguments
00569     /// through varargs) but do not want to mark declarations as "referenced"
00570     /// until the default argument is used.
00571     PotentiallyEvaluatedIfUsed
00572   };
00573 
00574   /// \brief Data structure used to record current or nested
00575   /// expression evaluation contexts.
00576   struct ExpressionEvaluationContextRecord {
00577     /// \brief The expression evaluation context.
00578     ExpressionEvaluationContext Context;
00579 
00580     /// \brief Whether the enclosing context needed a cleanup.
00581     bool ParentNeedsCleanups;
00582 
00583     /// \brief Whether we are in a decltype expression.
00584     bool IsDecltype;
00585 
00586     /// \brief The number of active cleanup objects when we entered
00587     /// this expression evaluation context.
00588     unsigned NumCleanupObjects;
00589 
00590     llvm::SmallPtrSet<Expr*, 8> SavedMaybeODRUseExprs;
00591 
00592     /// \brief The lambdas that are present within this context, if it
00593     /// is indeed an unevaluated context.
00594     llvm::SmallVector<LambdaExpr *, 2> Lambdas;
00595 
00596     /// \brief The declaration that provides context for the lambda expression
00597     /// if the normal declaration context does not suffice, e.g., in a 
00598     /// default function argument.
00599     Decl *LambdaContextDecl;
00600     
00601     /// \brief The context information used to mangle lambda expressions
00602     /// within this context.
00603     ///
00604     /// This mangling information is allocated lazily, since most contexts
00605     /// do not have lambda expressions.
00606     LambdaMangleContext *LambdaMangle;
00607 
00608     /// \brief If we are processing a decltype type, a set of call expressions
00609     /// for which we have deferred checking the completeness of the return type.
00610     llvm::SmallVector<CallExpr*, 8> DelayedDecltypeCalls;
00611 
00612     /// \brief If we are processing a decltype type, a set of temporary binding
00613     /// expressions for which we have deferred checking the destructor.
00614     llvm::SmallVector<CXXBindTemporaryExpr*, 8> DelayedDecltypeBinds;
00615     
00616     ExpressionEvaluationContextRecord(ExpressionEvaluationContext Context,
00617                                       unsigned NumCleanupObjects,
00618                                       bool ParentNeedsCleanups,
00619                                       Decl *LambdaContextDecl,
00620                                       bool IsDecltype)
00621       : Context(Context), ParentNeedsCleanups(ParentNeedsCleanups),
00622         IsDecltype(IsDecltype), NumCleanupObjects(NumCleanupObjects),
00623         LambdaContextDecl(LambdaContextDecl), LambdaMangle() { }
00624     
00625     ~ExpressionEvaluationContextRecord() {
00626       delete LambdaMangle;
00627     }
00628     
00629     /// \brief Retrieve the mangling context for lambdas.
00630     LambdaMangleContext &getLambdaMangleContext() {
00631       assert(LambdaContextDecl && "Need to have a lambda context declaration");
00632       if (!LambdaMangle)
00633         LambdaMangle = new LambdaMangleContext;
00634       return *LambdaMangle;
00635     }
00636   };
00637 
00638   /// A stack of expression evaluation contexts.
00639   SmallVector<ExpressionEvaluationContextRecord, 8> ExprEvalContexts;
00640   
00641   /// SpecialMemberOverloadResult - The overloading result for a special member
00642   /// function.
00643   ///
00644   /// This is basically a wrapper around PointerIntPair. The lowest bits of the
00645   /// integer are used to determine whether overload resolution succeeded.
00646   class SpecialMemberOverloadResult : public llvm::FastFoldingSetNode {
00647   public:
00648     enum Kind {
00649       NoMemberOrDeleted,
00650       Ambiguous,
00651       Success
00652     };
00653 
00654   private:
00655     llvm::PointerIntPair<CXXMethodDecl*, 2> Pair;
00656 
00657   public:
00658     SpecialMemberOverloadResult(const llvm::FoldingSetNodeID &ID)
00659       : FastFoldingSetNode(ID)
00660     {}
00661 
00662     CXXMethodDecl *getMethod() const { return Pair.getPointer(); }
00663     void setMethod(CXXMethodDecl *MD) { Pair.setPointer(MD); }
00664 
00665     Kind getKind() const { return static_cast<Kind>(Pair.getInt()); }
00666     void setKind(Kind K) { Pair.setInt(K); }
00667   };
00668 
00669   /// \brief A cache of special member function overload resolution results
00670   /// for C++ records.
00671   llvm::FoldingSet<SpecialMemberOverloadResult> SpecialMemberCache;
00672 
00673   /// \brief The kind of translation unit we are processing.
00674   ///
00675   /// When we're processing a complete translation unit, Sema will perform
00676   /// end-of-translation-unit semantic tasks (such as creating
00677   /// initializers for tentative definitions in C) once parsing has
00678   /// completed. Modules and precompiled headers perform different kinds of
00679   /// checks.
00680   TranslationUnitKind TUKind;
00681 
00682   llvm::BumpPtrAllocator BumpAlloc;
00683 
00684   /// \brief The number of SFINAE diagnostics that have been trapped.
00685   unsigned NumSFINAEErrors;
00686 
00687   typedef llvm::DenseMap<ParmVarDecl *, SmallVector<ParmVarDecl *, 1> >
00688     UnparsedDefaultArgInstantiationsMap;
00689 
00690   /// \brief A mapping from parameters with unparsed default arguments to the
00691   /// set of instantiations of each parameter.
00692   ///
00693   /// This mapping is a temporary data structure used when parsing
00694   /// nested class templates or nested classes of class templates,
00695   /// where we might end up instantiating an inner class before the
00696   /// default arguments of its methods have been parsed.
00697   UnparsedDefaultArgInstantiationsMap UnparsedDefaultArgInstantiations;
00698 
00699   // Contains the locations of the beginning of unparsed default
00700   // argument locations.
00701   llvm::DenseMap<ParmVarDecl *,SourceLocation> UnparsedDefaultArgLocs;
00702 
00703   /// UndefinedInternals - all the used, undefined objects with
00704   /// internal linkage in this translation unit.
00705   llvm::DenseMap<NamedDecl*, SourceLocation> UndefinedInternals;
00706 
00707   typedef std::pair<ObjCMethodList, ObjCMethodList> GlobalMethods;
00708   typedef llvm::DenseMap<Selector, GlobalMethods> GlobalMethodPool;
00709 
00710   /// Method Pool - allows efficient lookup when typechecking messages to "id".
00711   /// We need to maintain a list, since selectors can have differing signatures
00712   /// across classes. In Cocoa, this happens to be extremely uncommon (only 1%
00713   /// of selectors are "overloaded").
00714   GlobalMethodPool MethodPool;
00715 
00716   /// Method selectors used in a @selector expression. Used for implementation
00717   /// of -Wselector.
00718   llvm::DenseMap<Selector, SourceLocation> ReferencedSelectors;
00719 
00720   void ReadMethodPool(Selector Sel);
00721 
00722   /// Private Helper predicate to check for 'self'.
00723   bool isSelfExpr(Expr *RExpr);
00724 
00725   /// \brief Cause the active diagnostic on the DiagosticsEngine to be
00726   /// emitted. This is closely coupled to the SemaDiagnosticBuilder class and
00727   /// should not be used elsewhere.
00728   void EmitCurrentDiagnostic(unsigned DiagID);
00729 
00730 public:
00731   Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer,
00732        TranslationUnitKind TUKind = TU_Complete,
00733        CodeCompleteConsumer *CompletionConsumer = 0);
00734   ~Sema();
00735 
00736   /// \brief Perform initialization that occurs after the parser has been
00737   /// initialized but before it parses anything.
00738   void Initialize();
00739 
00740   const LangOptions &getLangOpts() const { return LangOpts; }
00741   OpenCLOptions &getOpenCLOptions() { return OpenCLFeatures; }
00742   FPOptions     &getFPOptions() { return FPFeatures; }
00743 
00744   DiagnosticsEngine &getDiagnostics() const { return Diags; }
00745   SourceManager &getSourceManager() const { return SourceMgr; }
00746   const TargetAttributesSema &getTargetAttributesSema() const;
00747   Preprocessor &getPreprocessor() const { return PP; }
00748   ASTContext &getASTContext() const { return Context; }
00749   ASTConsumer &getASTConsumer() const { return Consumer; }
00750   ASTMutationListener *getASTMutationListener() const;
00751 
00752   void PrintStats() const;
00753 
00754   /// \brief Helper class that creates diagnostics with optional
00755   /// template instantiation stacks.
00756   ///
00757   /// This class provides a wrapper around the basic DiagnosticBuilder
00758   /// class that emits diagnostics. SemaDiagnosticBuilder is
00759   /// responsible for emitting the diagnostic (as DiagnosticBuilder
00760   /// does) and, if the diagnostic comes from inside a template
00761   /// instantiation, printing the template instantiation stack as
00762   /// well.
00763   class SemaDiagnosticBuilder : public DiagnosticBuilder {
00764     Sema &SemaRef;
00765     unsigned DiagID;
00766 
00767   public:
00768     SemaDiagnosticBuilder(DiagnosticBuilder &DB, Sema &SemaRef, unsigned DiagID)
00769       : DiagnosticBuilder(DB), SemaRef(SemaRef), DiagID(DiagID) { }
00770 
00771     ~SemaDiagnosticBuilder() {
00772       // If we aren't active, there is nothing to do.
00773       if (!isActive()) return;
00774 
00775       // Otherwise, we need to emit the diagnostic. First flush the underlying
00776       // DiagnosticBuilder data, and clear the diagnostic builder itself so it
00777       // won't emit the diagnostic in its own destructor.
00778       //
00779       // This seems wasteful, in that as written the DiagnosticBuilder dtor will
00780       // do its own needless checks to see if the diagnostic needs to be
00781       // emitted. However, because we take care to ensure that the builder
00782       // objects never escape, a sufficiently smart compiler will be able to
00783       // eliminate that code.
00784       FlushCounts();
00785       Clear();
00786 
00787       // Dispatch to Sema to emit the diagnostic.
00788       SemaRef.EmitCurrentDiagnostic(DiagID);
00789     }
00790   };
00791 
00792   /// \brief Emit a diagnostic.
00793   SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) {
00794     DiagnosticBuilder DB = Diags.Report(Loc, DiagID);
00795     return SemaDiagnosticBuilder(DB, *this, DiagID);
00796   }
00797 
00798   /// \brief Emit a partial diagnostic.
00799   SemaDiagnosticBuilder Diag(SourceLocation Loc, const PartialDiagnostic& PD);
00800 
00801   /// \brief Build a partial diagnostic.
00802   PartialDiagnostic PDiag(unsigned DiagID = 0); // in SemaInternal.h
00803 
00804   bool findMacroSpelling(SourceLocation &loc, StringRef name);
00805 
00806   /// \brief Get a string to suggest for zero-initialization of a type.
00807   std::string getFixItZeroInitializerForType(QualType T) const;
00808   std::string getFixItZeroLiteralForType(QualType T) const;
00809 
00810   ExprResult Owned(Expr* E) { return E; }
00811   ExprResult Owned(ExprResult R) { return R; }
00812   StmtResult Owned(Stmt* S) { return S; }
00813 
00814   void ActOnEndOfTranslationUnit();
00815 
00816   void CheckDelegatingCtorCycles();
00817 
00818   Scope *getScopeForContext(DeclContext *Ctx);
00819 
00820   void PushFunctionScope();
00821   void PushBlockScope(Scope *BlockScope, BlockDecl *Block);
00822   void PushLambdaScope(CXXRecordDecl *Lambda, CXXMethodDecl *CallOperator);
00823   void PopFunctionScopeInfo(const sema::AnalysisBasedWarnings::Policy *WP =0,
00824                             const Decl *D = 0, const BlockExpr *blkExpr = 0);
00825 
00826   sema::FunctionScopeInfo *getCurFunction() const {
00827     return FunctionScopes.back();
00828   }
00829 
00830   void PushCompoundScope();
00831   void PopCompoundScope();
00832 
00833   sema::CompoundScopeInfo &getCurCompoundScope() const;
00834 
00835   bool hasAnyUnrecoverableErrorsInThisFunction() const;
00836 
00837   /// \brief Retrieve the current block, if any.
00838   sema::BlockScopeInfo *getCurBlock();
00839 
00840   /// \brief Retrieve the current lambda expression, if any.
00841   sema::LambdaScopeInfo *getCurLambda();
00842 
00843   /// WeakTopLevelDeclDecls - access to #pragma weak-generated Decls
00844   SmallVector<Decl*,2> &WeakTopLevelDecls() { return WeakTopLevelDecl; }
00845 
00846   //===--------------------------------------------------------------------===//
00847   // Type Analysis / Processing: SemaType.cpp.
00848   //
00849 
00850   QualType BuildQualifiedType(QualType T, SourceLocation Loc, Qualifiers Qs);
00851   QualType BuildQualifiedType(QualType T, SourceLocation Loc, unsigned CVR) {
00852     return BuildQualifiedType(T, Loc, Qualifiers::fromCVRMask(CVR));
00853   }
00854   QualType BuildPointerType(QualType T,
00855                             SourceLocation Loc, DeclarationName Entity);
00856   QualType BuildReferenceType(QualType T, bool LValueRef,
00857                               SourceLocation Loc, DeclarationName Entity);
00858   QualType BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM,
00859                           Expr *ArraySize, unsigned Quals,
00860                           SourceRange Brackets, DeclarationName Entity);
00861   QualType BuildExtVectorType(QualType T, Expr *ArraySize,
00862                               SourceLocation AttrLoc);
00863   QualType BuildFunctionType(QualType T,
00864                              QualType *ParamTypes, unsigned NumParamTypes,
00865                              bool Variadic, bool HasTrailingReturn,
00866                              unsigned Quals, RefQualifierKind RefQualifier,
00867                              SourceLocation Loc, DeclarationName Entity,
00868                              FunctionType::ExtInfo Info);
00869   QualType BuildMemberPointerType(QualType T, QualType Class,
00870                                   SourceLocation Loc,
00871                                   DeclarationName Entity);
00872   QualType BuildBlockPointerType(QualType T,
00873                                  SourceLocation Loc, DeclarationName Entity);
00874   QualType BuildParenType(QualType T);
00875   QualType BuildAtomicType(QualType T, SourceLocation Loc);
00876 
00877   TypeSourceInfo *GetTypeForDeclarator(Declarator &D, Scope *S);
00878   TypeSourceInfo *GetTypeForDeclaratorCast(Declarator &D, QualType FromTy);
00879   TypeSourceInfo *GetTypeSourceInfoForDeclarator(Declarator &D, QualType T,
00880                                                TypeSourceInfo *ReturnTypeInfo);
00881     
00882   /// \brief Package the given type and TSI into a ParsedType.
00883   ParsedType CreateParsedType(QualType T, TypeSourceInfo *TInfo);
00884   DeclarationNameInfo GetNameForDeclarator(Declarator &D);
00885   DeclarationNameInfo GetNameFromUnqualifiedId(const UnqualifiedId &Name);
00886   static QualType GetTypeFromParser(ParsedType Ty, TypeSourceInfo **TInfo = 0);
00887   CanThrowResult canThrow(const Expr *E);
00888   const FunctionProtoType *ResolveExceptionSpec(SourceLocation Loc,
00889                                                 const FunctionProtoType *FPT);
00890   bool CheckSpecifiedExceptionType(QualType T, const SourceRange &Range);
00891   bool CheckDistantExceptionSpec(QualType T);
00892   bool CheckEquivalentExceptionSpec(FunctionDecl *Old, FunctionDecl *New);
00893   bool CheckEquivalentExceptionSpec(
00894       const FunctionProtoType *Old, SourceLocation OldLoc,
00895       const FunctionProtoType *New, SourceLocation NewLoc);
00896   bool CheckEquivalentExceptionSpec(
00897       const PartialDiagnostic &DiagID, const PartialDiagnostic & NoteID,
00898       const FunctionProtoType *Old, SourceLocation OldLoc,
00899       const FunctionProtoType *New, SourceLocation NewLoc,
00900       bool *MissingExceptionSpecification = 0,
00901       bool *MissingEmptyExceptionSpecification = 0,
00902       bool AllowNoexceptAllMatchWithNoSpec = false,
00903       bool IsOperatorNew = false);
00904   bool CheckExceptionSpecSubset(
00905       const PartialDiagnostic &DiagID, const PartialDiagnostic & NoteID,
00906       const FunctionProtoType *Superset, SourceLocation SuperLoc,
00907       const FunctionProtoType *Subset, SourceLocation SubLoc);
00908   bool CheckParamExceptionSpec(const PartialDiagnostic & NoteID,
00909       const FunctionProtoType *Target, SourceLocation TargetLoc,
00910       const FunctionProtoType *Source, SourceLocation SourceLoc);
00911 
00912   TypeResult ActOnTypeName(Scope *S, Declarator &D);
00913 
00914   /// \brief The parser has parsed the context-sensitive type 'instancetype'
00915   /// in an Objective-C message declaration. Return the appropriate type.
00916   ParsedType ActOnObjCInstanceType(SourceLocation Loc);
00917 
00918   /// \brief Abstract class used to diagnose incomplete types.
00919   struct TypeDiagnoser {
00920     bool Suppressed;
00921     
00922     TypeDiagnoser(bool Suppressed = false) : Suppressed(Suppressed) { }
00923     
00924     virtual void diagnose(Sema &S, SourceLocation Loc, QualType T) = 0;
00925     virtual ~TypeDiagnoser() {}
00926   };
00927 
00928   static int getPrintable(int I) { return I; }
00929   static unsigned getPrintable(unsigned I) { return I; }
00930   static bool getPrintable(bool B) { return B; }
00931   static const char * getPrintable(const char *S) { return S; }
00932   static StringRef getPrintable(StringRef S) { return S; }
00933   static const std::string &getPrintable(const std::string &S) { return S; }
00934   static const IdentifierInfo *getPrintable(const IdentifierInfo *II) {
00935     return II;
00936   }
00937   static DeclarationName getPrintable(DeclarationName N) { return N; }
00938   static QualType getPrintable(QualType T) { return T; }
00939   static SourceRange getPrintable(SourceRange R) { return R; }
00940   static SourceRange getPrintable(SourceLocation L) { return L; }
00941   static SourceRange getPrintable(Expr *E) { return E->getSourceRange(); }
00942   static SourceRange getPrintable(TypeLoc TL) { return TL.getSourceRange();}
00943   
00944   template<typename T1>
00945   class BoundTypeDiagnoser1 : public TypeDiagnoser {
00946     unsigned DiagID;
00947     const T1 &Arg1;
00948     
00949   public:
00950     BoundTypeDiagnoser1(unsigned DiagID, const T1 &Arg1)
00951       : TypeDiagnoser(DiagID == 0), DiagID(DiagID), Arg1(Arg1) { }
00952     virtual void diagnose(Sema &S, SourceLocation Loc, QualType T) {
00953       if (Suppressed) return;
00954       S.Diag(Loc, DiagID) << getPrintable(Arg1) << T;
00955     }
00956     
00957     virtual ~BoundTypeDiagnoser1() { }
00958   };
00959 
00960   template<typename T1, typename T2>
00961   class BoundTypeDiagnoser2 : public TypeDiagnoser {
00962     unsigned DiagID;
00963     const T1 &Arg1;
00964     const T2 &Arg2;
00965     
00966   public:
00967     BoundTypeDiagnoser2(unsigned DiagID, const T1 &Arg1,
00968                                   const T2 &Arg2)
00969       : TypeDiagnoser(DiagID == 0), DiagID(DiagID), Arg1(Arg1),
00970         Arg2(Arg2) { }
00971     
00972     virtual void diagnose(Sema &S, SourceLocation Loc, QualType T) {
00973       if (Suppressed) return;
00974       S.Diag(Loc, DiagID) << getPrintable(Arg1) << getPrintable(Arg2) << T;
00975     }
00976     
00977     virtual ~BoundTypeDiagnoser2() { }
00978   };
00979 
00980   template<typename T1, typename T2, typename T3>
00981   class BoundTypeDiagnoser3 : public TypeDiagnoser {
00982     unsigned DiagID;
00983     const T1 &Arg1;
00984     const T2 &Arg2;
00985     const T3 &Arg3;
00986     
00987   public:
00988     BoundTypeDiagnoser3(unsigned DiagID, const T1 &Arg1,
00989                                   const T2 &Arg2, const T3 &Arg3)
00990     : TypeDiagnoser(DiagID == 0), DiagID(DiagID), Arg1(Arg1),
00991       Arg2(Arg2), Arg3(Arg3) { }
00992     
00993     virtual void diagnose(Sema &S, SourceLocation Loc, QualType T) {
00994       if (Suppressed) return;
00995       S.Diag(Loc, DiagID)
00996         << getPrintable(Arg1) << getPrintable(Arg2) << getPrintable(Arg3) << T;
00997     }
00998     
00999     virtual ~BoundTypeDiagnoser3() { }
01000   };
01001   
01002   bool RequireCompleteType(SourceLocation Loc, QualType T,
01003                            TypeDiagnoser &Diagnoser);
01004   bool RequireCompleteType(SourceLocation Loc, QualType T,
01005                            unsigned DiagID);
01006   
01007   template<typename T1>
01008   bool RequireCompleteType(SourceLocation Loc, QualType T,
01009                            unsigned DiagID, const T1 &Arg1) {
01010     BoundTypeDiagnoser1<T1> Diagnoser(DiagID, Arg1);
01011     return RequireCompleteType(Loc, T, Diagnoser);
01012   }
01013   
01014   template<typename T1, typename T2>
01015   bool RequireCompleteType(SourceLocation Loc, QualType T,
01016                            unsigned DiagID, const T1 &Arg1, const T2 &Arg2) {
01017     BoundTypeDiagnoser2<T1, T2> Diagnoser(DiagID, Arg1, Arg2);
01018     return RequireCompleteType(Loc, T, Diagnoser);
01019   }
01020 
01021   template<typename T1, typename T2, typename T3>
01022   bool RequireCompleteType(SourceLocation Loc, QualType T,
01023                            unsigned DiagID, const T1 &Arg1, const T2 &Arg2,
01024                            const T3 &Arg3) {
01025     BoundTypeDiagnoser3<T1, T2, T3> Diagnoser(DiagID, Arg1, Arg2,
01026                                                         Arg3);
01027     return RequireCompleteType(Loc, T, Diagnoser);
01028   }
01029 
01030   bool RequireCompleteExprType(Expr *E, TypeDiagnoser &Diagnoser);
01031   bool RequireCompleteExprType(Expr *E, unsigned DiagID);
01032 
01033   template<typename T1>
01034   bool RequireCompleteExprType(Expr *E, unsigned DiagID, const T1 &Arg1) {
01035     BoundTypeDiagnoser1<T1> Diagnoser(DiagID, Arg1);
01036     return RequireCompleteExprType(E, Diagnoser);
01037   }
01038 
01039   template<typename T1, typename T2>
01040   bool RequireCompleteExprType(Expr *E, unsigned DiagID, const T1 &Arg1,
01041                                const T2 &Arg2) {
01042     BoundTypeDiagnoser2<T1, T2> Diagnoser(DiagID, Arg1, Arg2);
01043     return RequireCompleteExprType(E, Diagnoser);
01044   }
01045 
01046   template<typename T1, typename T2, typename T3>
01047   bool RequireCompleteExprType(Expr *E, unsigned DiagID, const T1 &Arg1,
01048                                const T2 &Arg2, const T3 &Arg3) {
01049     BoundTypeDiagnoser3<T1, T2, T3> Diagnoser(DiagID, Arg1, Arg2,
01050                                                         Arg3);
01051     return RequireCompleteExprType(E, Diagnoser);
01052   }
01053 
01054   bool RequireLiteralType(SourceLocation Loc, QualType T,
01055                           TypeDiagnoser &Diagnoser);
01056   bool RequireLiteralType(SourceLocation Loc, QualType T, unsigned DiagID);
01057   
01058   template<typename T1>
01059   bool RequireLiteralType(SourceLocation Loc, QualType T,
01060                           unsigned DiagID, const T1 &Arg1) {
01061     BoundTypeDiagnoser1<T1> Diagnoser(DiagID, Arg1);
01062     return RequireLiteralType(Loc, T, Diagnoser);
01063   }
01064 
01065   template<typename T1, typename T2>
01066   bool RequireLiteralType(SourceLocation Loc, QualType T,
01067                           unsigned DiagID, const T1 &Arg1, const T2 &Arg2) {
01068     BoundTypeDiagnoser2<T1, T2> Diagnoser(DiagID, Arg1, Arg2);
01069     return RequireLiteralType(Loc, T, Diagnoser);
01070   }
01071 
01072   template<typename T1, typename T2, typename T3>
01073   bool RequireLiteralType(SourceLocation Loc, QualType T,
01074                           unsigned DiagID, const T1 &Arg1, const T2 &Arg2,
01075                           const T3 &Arg3) {
01076     BoundTypeDiagnoser3<T1, T2, T3> Diagnoser(DiagID, Arg1, Arg2,
01077                                                         Arg3);
01078     return RequireLiteralType(Loc, T, Diagnoser);
01079   }
01080 
01081   QualType getElaboratedType(ElaboratedTypeKeyword Keyword,
01082                              const CXXScopeSpec &SS, QualType T);
01083 
01084   QualType BuildTypeofExprType(Expr *E, SourceLocation Loc);
01085   QualType BuildDecltypeType(Expr *E, SourceLocation Loc);
01086   QualType BuildUnaryTransformType(QualType BaseType,
01087                                    UnaryTransformType::UTTKind UKind,
01088                                    SourceLocation Loc);
01089 
01090   //===--------------------------------------------------------------------===//
01091   // Symbol table / Decl tracking callbacks: SemaDecl.cpp.
01092   //
01093 
01094   /// List of decls defined in a function prototype. This contains EnumConstants
01095   /// that incorrectly end up in translation unit scope because there is no
01096   /// function to pin them on. ActOnFunctionDeclarator reads this list and patches
01097   /// them into the FunctionDecl.
01098   std::vector<NamedDecl*> DeclsInPrototypeScope;
01099   /// Nonzero if we are currently parsing a function declarator. This is a counter
01100   /// as opposed to a boolean so we can deal with nested function declarators
01101   /// such as:
01102   ///     void f(void (*g)(), ...)
01103   unsigned InFunctionDeclarator;
01104 
01105   DeclGroupPtrTy ConvertDeclToDeclGroup(Decl *Ptr, Decl *OwnedType = 0);
01106 
01107   void DiagnoseUseOfUnimplementedSelectors();
01108 
01109   ParsedType getTypeName(IdentifierInfo &II, SourceLocation NameLoc,
01110                          Scope *S, CXXScopeSpec *SS = 0,
01111                          bool isClassName = false,
01112                          bool HasTrailingDot = false,
01113                          ParsedType ObjectType = ParsedType(),
01114                          bool IsCtorOrDtorName = false,
01115                          bool WantNontrivialTypeSourceInfo = false,
01116                          IdentifierInfo **CorrectedII = 0);
01117   TypeSpecifierType isTagName(IdentifierInfo &II, Scope *S);
01118   bool isMicrosoftMissingTypename(const CXXScopeSpec *SS, Scope *S);
01119   bool DiagnoseUnknownTypeName(const IdentifierInfo &II,
01120                                SourceLocation IILoc,
01121                                Scope *S,
01122                                CXXScopeSpec *SS,
01123                                ParsedType &SuggestedType);
01124 
01125   /// \brief Describes the result of the name lookup and resolution performed
01126   /// by \c ClassifyName().
01127   enum NameClassificationKind {
01128     NC_Unknown,
01129     NC_Error,
01130     NC_Keyword,
01131     NC_Type,
01132     NC_Expression,
01133     NC_NestedNameSpecifier,
01134     NC_TypeTemplate,
01135     NC_FunctionTemplate
01136   };
01137 
01138   class NameClassification {
01139     NameClassificationKind Kind;
01140     ExprResult Expr;
01141     TemplateName Template;
01142     ParsedType Type;
01143     const IdentifierInfo *Keyword;
01144 
01145     explicit NameClassification(NameClassificationKind Kind) : Kind(Kind) {}
01146 
01147   public:
01148     NameClassification(ExprResult Expr) : Kind(NC_Expression), Expr(Expr) {}
01149 
01150     NameClassification(ParsedType Type) : Kind(NC_Type), Type(Type) {}
01151 
01152     NameClassification(const IdentifierInfo *Keyword)
01153       : Kind(NC_Keyword), Keyword(Keyword) { }
01154 
01155     static NameClassification Error() {
01156       return NameClassification(NC_Error);
01157     }
01158 
01159     static NameClassification Unknown() {
01160       return NameClassification(NC_Unknown);
01161     }
01162 
01163     static NameClassification NestedNameSpecifier() {
01164       return NameClassification(NC_NestedNameSpecifier);
01165     }
01166 
01167     static NameClassification TypeTemplate(TemplateName Name) {
01168       NameClassification Result(NC_TypeTemplate);
01169       Result.Template = Name;
01170       return Result;
01171     }
01172 
01173     static NameClassification FunctionTemplate(TemplateName Name) {
01174       NameClassification Result(NC_FunctionTemplate);
01175       Result.Template = Name;
01176       return Result;
01177     }
01178 
01179     NameClassificationKind getKind() const { return Kind; }
01180 
01181     ParsedType getType() const {
01182       assert(Kind == NC_Type);
01183       return Type;
01184     }
01185 
01186     ExprResult getExpression() const {
01187       assert(Kind == NC_Expression);
01188       return Expr;
01189     }
01190 
01191     TemplateName getTemplateName() const {
01192       assert(Kind == NC_TypeTemplate || Kind == NC_FunctionTemplate);
01193       return Template;
01194     }
01195 
01196     TemplateNameKind getTemplateNameKind() const {
01197       assert(Kind == NC_TypeTemplate || Kind == NC_FunctionTemplate);
01198       return Kind == NC_TypeTemplate? TNK_Type_template : TNK_Function_template;
01199     }
01200 };
01201 
01202   /// \brief Perform name lookup on the given name, classifying it based on
01203   /// the results of name lookup and the following token.
01204   ///
01205   /// This routine is used by the parser to resolve identifiers and help direct
01206   /// parsing. When the identifier cannot be found, this routine will attempt
01207   /// to correct the typo and classify based on the resulting name.
01208   ///
01209   /// \param S The scope in which we're performing name lookup.
01210   ///
01211   /// \param SS The nested-name-specifier that precedes the name.
01212   ///
01213   /// \param Name The identifier. If typo correction finds an alternative name,
01214   /// this pointer parameter will be updated accordingly.
01215   ///
01216   /// \param NameLoc The location of the identifier.
01217   ///
01218   /// \param NextToken The token following the identifier. Used to help
01219   /// disambiguate the name.
01220   NameClassification ClassifyName(Scope *S,
01221                                   CXXScopeSpec &SS,
01222                                   IdentifierInfo *&Name,
01223                                   SourceLocation NameLoc,
01224                                   const Token &NextToken);
01225 
01226   Decl *ActOnDeclarator(Scope *S, Declarator &D);
01227 
01228   Decl *HandleDeclarator(Scope *S, Declarator &D,
01229                          MultiTemplateParamsArg TemplateParameterLists);
01230   void RegisterLocallyScopedExternCDecl(NamedDecl *ND,
01231                                         const LookupResult &Previous,
01232                                         Scope *S);
01233   bool DiagnoseClassNameShadow(DeclContext *DC, DeclarationNameInfo Info);
01234   bool diagnoseQualifiedDeclaration(CXXScopeSpec &SS, DeclContext *DC,
01235                                     DeclarationName Name,
01236                                     SourceLocation Loc);
01237   void DiagnoseFunctionSpecifiers(Declarator& D);
01238   void CheckShadow(Scope *S, VarDecl *D, const LookupResult& R);
01239   void CheckShadow(Scope *S, VarDecl *D);
01240   void CheckCastAlign(Expr *Op, QualType T, SourceRange TRange);
01241   void CheckTypedefForVariablyModifiedType(Scope *S, TypedefNameDecl *D);
01242   NamedDecl* ActOnTypedefDeclarator(Scope* S, Declarator& D, DeclContext* DC,
01243                                     TypeSourceInfo *TInfo,
01244                                     LookupResult &Previous);
01245   NamedDecl* ActOnTypedefNameDecl(Scope* S, DeclContext* DC, TypedefNameDecl *D,
01246                                   LookupResult &Previous, bool &Redeclaration);
01247   NamedDecl* ActOnVariableDeclarator(Scope* S, Declarator& D, DeclContext* DC,
01248                                      TypeSourceInfo *TInfo,
01249                                      LookupResult &Previous,
01250                                      MultiTemplateParamsArg TemplateParamLists);
01251   // Returns true if the variable declaration is a redeclaration
01252   bool CheckVariableDeclaration(VarDecl *NewVD, LookupResult &Previous);
01253   void CheckCompleteVariableDeclaration(VarDecl *var);
01254   void ActOnStartFunctionDeclarator();
01255   void ActOnEndFunctionDeclarator();
01256   NamedDecl* ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
01257                                      TypeSourceInfo *TInfo,
01258                                      LookupResult &Previous,
01259                                      MultiTemplateParamsArg TemplateParamLists,
01260                                      bool &AddToScope);
01261   bool AddOverriddenMethods(CXXRecordDecl *DC, CXXMethodDecl *MD);
01262 
01263   bool CheckConstexprFunctionDecl(const FunctionDecl *FD);
01264   bool CheckConstexprFunctionBody(const FunctionDecl *FD, Stmt *Body);
01265 
01266   void DiagnoseHiddenVirtualMethods(CXXRecordDecl *DC, CXXMethodDecl *MD);
01267   // Returns true if the function declaration is a redeclaration
01268   bool CheckFunctionDeclaration(Scope *S,
01269                                 FunctionDecl *NewFD, LookupResult &Previous,
01270                                 bool IsExplicitSpecialization);
01271   void CheckMain(FunctionDecl *FD, const DeclSpec &D);
01272   Decl *ActOnParamDeclarator(Scope *S, Declarator &D);
01273   ParmVarDecl *BuildParmVarDeclForTypedef(DeclContext *DC,
01274                                           SourceLocation Loc,
01275                                           QualType T);
01276   ParmVarDecl *CheckParameter(DeclContext *DC, SourceLocation StartLoc,
01277                               SourceLocation NameLoc, IdentifierInfo *Name,
01278                               QualType T, TypeSourceInfo *TSInfo,
01279                               StorageClass SC, StorageClass SCAsWritten);
01280   void ActOnParamDefaultArgument(Decl *param,
01281                                  SourceLocation EqualLoc,
01282                                  Expr *defarg);
01283   void ActOnParamUnparsedDefaultArgument(Decl *param,
01284                                          SourceLocation EqualLoc,
01285                                          SourceLocation ArgLoc);
01286   void ActOnParamDefaultArgumentError(Decl *param);
01287   bool SetParamDefaultArgument(ParmVarDecl *Param, Expr *DefaultArg,
01288                                SourceLocation EqualLoc);
01289 
01290   void CheckSelfReference(Decl *OrigDecl, Expr *E);
01291   void AddInitializerToDecl(Decl *dcl, Expr *init, bool DirectInit,
01292                             bool TypeMayContainAuto);
01293   void ActOnUninitializedDecl(Decl *dcl, bool TypeMayContainAuto);
01294   void ActOnInitializerError(Decl *Dcl);
01295   void ActOnCXXForRangeDecl(Decl *D);
01296   void SetDeclDeleted(Decl *dcl, SourceLocation DelLoc);
01297   void SetDeclDefaulted(Decl *dcl, SourceLocation DefaultLoc);
01298   void FinalizeDeclaration(Decl *D);
01299   DeclGroupPtrTy FinalizeDeclaratorGroup(Scope *S, const DeclSpec &DS,
01300                                          Decl **Group,
01301                                          unsigned NumDecls);
01302   DeclGroupPtrTy BuildDeclaratorGroup(Decl **Group, unsigned NumDecls,
01303                                       bool TypeMayContainAuto = true);
01304   void ActOnFinishKNRParamDeclarations(Scope *S, Declarator &D,
01305                                        SourceLocation LocAfterDecls);
01306   void CheckForFunctionRedefinition(FunctionDecl *FD);
01307   Decl *ActOnStartOfFunctionDef(Scope *S, Declarator &D);
01308   Decl *ActOnStartOfFunctionDef(Scope *S, Decl *D);
01309   void ActOnStartOfObjCMethodDef(Scope *S, Decl *D);
01310 
01311   void computeNRVO(Stmt *Body, sema::FunctionScopeInfo *Scope);
01312   Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body);
01313   Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body, bool IsInstantiation);
01314 
01315   /// ActOnFinishDelayedAttribute - Invoked when we have finished parsing an
01316   /// attribute for which parsing is delayed.
01317   void ActOnFinishDelayedAttribute(Scope *S, Decl *D, ParsedAttributes &Attrs);
01318 
01319   /// \brief Diagnose any unused parameters in the given sequence of
01320   /// ParmVarDecl pointers.
01321   void DiagnoseUnusedParameters(ParmVarDecl * const *Begin,
01322                                 ParmVarDecl * const *End);
01323 
01324   /// \brief Diagnose whether the size of parameters or return value of a
01325   /// function or obj-c method definition is pass-by-value and larger than a
01326   /// specified threshold.
01327   void DiagnoseSizeOfParametersAndReturnValue(ParmVarDecl * const *Begin,
01328                                               ParmVarDecl * const *End,
01329                                               QualType ReturnTy,
01330                                               NamedDecl *D);
01331 
01332   void DiagnoseInvalidJumps(Stmt *Body);
01333   Decl *ActOnFileScopeAsmDecl(Expr *expr,
01334                               SourceLocation AsmLoc,
01335                               SourceLocation RParenLoc);
01336 
01337   /// \brief The parser has processed a module import declaration.
01338   ///
01339   /// \param AtLoc The location of the '@' symbol, if any.
01340   ///
01341   /// \param ImportLoc The location of the 'import' keyword.
01342   ///
01343   /// \param Path The module access path.
01344   DeclResult ActOnModuleImport(SourceLocation AtLoc, SourceLocation ImportLoc, 
01345                                ModuleIdPath Path);
01346 
01347   /// \brief Retrieve a suitable printing policy.
01348   PrintingPolicy getPrintingPolicy() const {
01349     return getPrintingPolicy(Context, PP);
01350   }
01351 
01352   /// \brief Retrieve a suitable printing policy.
01353   static PrintingPolicy getPrintingPolicy(const ASTContext &Ctx,
01354                                           const Preprocessor &PP);
01355 
01356   /// Scope actions.
01357   void ActOnPopScope(SourceLocation Loc, Scope *S);
01358   void ActOnTranslationUnitScope(Scope *S);
01359 
01360   Decl *ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS,
01361                                    DeclSpec &DS);
01362   Decl *ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS,
01363                                    DeclSpec &DS,
01364                                    MultiTemplateParamsArg TemplateParams);
01365 
01366   Decl *BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS,
01367                                     AccessSpecifier AS,
01368                                     RecordDecl *Record);
01369 
01370   Decl *BuildMicrosoftCAnonymousStruct(Scope *S, DeclSpec &DS,
01371                                        RecordDecl *Record);
01372 
01373   bool isAcceptableTagRedeclaration(const TagDecl *Previous,
01374                                     TagTypeKind NewTag, bool isDefinition,
01375                                     SourceLocation NewTagLoc,
01376                                     const IdentifierInfo &Name);
01377 
01378   enum TagUseKind {
01379     TUK_Reference,   // Reference to a tag:  'struct foo *X;'
01380     TUK_Declaration, // Fwd decl of a tag:   'struct foo;'
01381     TUK_Definition,  // Definition of a tag: 'struct foo { int X; } Y;'
01382     TUK_Friend       // Friend declaration:  'friend struct foo;'
01383   };
01384 
01385   Decl *ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK,
01386                  SourceLocation KWLoc, CXXScopeSpec &SS,
01387                  IdentifierInfo *Name, SourceLocation NameLoc,
01388                  AttributeList *Attr, AccessSpecifier AS,
01389                  SourceLocation ModulePrivateLoc,
01390                  MultiTemplateParamsArg TemplateParameterLists,
01391                  bool &OwnedDecl, bool &IsDependent,
01392                  SourceLocation ScopedEnumKWLoc,
01393                  bool ScopedEnumUsesClassTag, TypeResult UnderlyingType);
01394 
01395   Decl *ActOnTemplatedFriendTag(Scope *S, SourceLocation FriendLoc,
01396                                 unsigned TagSpec, SourceLocation TagLoc,
01397                                 CXXScopeSpec &SS,
01398                                 IdentifierInfo *Name, SourceLocation NameLoc,
01399                                 AttributeList *Attr,
01400                                 MultiTemplateParamsArg TempParamLists);
01401 
01402   TypeResult ActOnDependentTag(Scope *S,
01403                                unsigned TagSpec,
01404                                TagUseKind TUK,
01405                                const CXXScopeSpec &SS,
01406                                IdentifierInfo *Name,
01407                                SourceLocation TagLoc,
01408                                SourceLocation NameLoc);
01409 
01410   void ActOnDefs(Scope *S, Decl *TagD, SourceLocation DeclStart,
01411                  IdentifierInfo *ClassName,
01412                  SmallVectorImpl<Decl *> &Decls);
01413   Decl *ActOnField(Scope *S, Decl *TagD, SourceLocation DeclStart,
01414                    Declarator &D, Expr *BitfieldWidth);
01415 
01416   FieldDecl *HandleField(Scope *S, RecordDecl *TagD, SourceLocation DeclStart,
01417                          Declarator &D, Expr *BitfieldWidth, bool HasInit,
01418                          AccessSpecifier AS);
01419 
01420   FieldDecl *CheckFieldDecl(DeclarationName Name, QualType T,
01421                             TypeSourceInfo *TInfo,
01422                             RecordDecl *Record, SourceLocation Loc,
01423                             bool Mutable, Expr *BitfieldWidth, bool HasInit,
01424                             SourceLocation TSSL,
01425                             AccessSpecifier AS, NamedDecl *PrevDecl,
01426                             Declarator *D = 0);
01427 
01428   enum CXXSpecialMember {
01429     CXXDefaultConstructor,
01430     CXXCopyConstructor,
01431     CXXMoveConstructor,
01432     CXXCopyAssignment,
01433     CXXMoveAssignment,
01434     CXXDestructor,
01435     CXXInvalid
01436   };
01437   bool CheckNontrivialField(FieldDecl *FD);
01438   void DiagnoseNontrivial(const RecordType* Record, CXXSpecialMember mem);
01439   CXXSpecialMember getSpecialMember(const CXXMethodDecl *MD);
01440   void ActOnLastBitfield(SourceLocation DeclStart,
01441                          SmallVectorImpl<Decl *> &AllIvarDecls);
01442   Decl *ActOnIvar(Scope *S, SourceLocation DeclStart,
01443                   Declarator &D, Expr *BitfieldWidth,
01444                   tok::ObjCKeywordKind visibility);
01445 
01446   // This is used for both record definitions and ObjC interface declarations.
01447   void ActOnFields(Scope* S, SourceLocation RecLoc, Decl *TagDecl,
01448                    llvm::ArrayRef<Decl *> Fields,
01449                    SourceLocation LBrac, SourceLocation RBrac,
01450                    AttributeList *AttrList);
01451 
01452   /// ActOnTagStartDefinition - Invoked when we have entered the
01453   /// scope of a tag's definition (e.g., for an enumeration, class,
01454   /// struct, or union).
01455   void ActOnTagStartDefinition(Scope *S, Decl *TagDecl);
01456 
01457   Decl *ActOnObjCContainerStartDefinition(Decl *IDecl);
01458 
01459   /// ActOnStartCXXMemberDeclarations - Invoked when we have parsed a
01460   /// C++ record definition's base-specifiers clause and are starting its
01461   /// member declarations.
01462   void ActOnStartCXXMemberDeclarations(Scope *S, Decl *TagDecl,
01463                                        SourceLocation FinalLoc,
01464                                        SourceLocation LBraceLoc);
01465 
01466   /// ActOnTagFinishDefinition - Invoked once we have finished parsing
01467   /// the definition of a tag (enumeration, class, struct, or union).
01468   void ActOnTagFinishDefinition(Scope *S, Decl *TagDecl,
01469                                 SourceLocation RBraceLoc);
01470 
01471   void ActOnObjCContainerFinishDefinition();
01472 
01473   /// \brief Invoked when we must temporarily exit the objective-c container
01474   /// scope for parsing/looking-up C constructs.
01475   ///
01476   /// Must be followed by a call to \see ActOnObjCReenterContainerContext
01477   void ActOnObjCTemporaryExitContainerContext(DeclContext *DC);
01478   void ActOnObjCReenterContainerContext(DeclContext *DC);
01479 
01480   /// ActOnTagDefinitionError - Invoked when there was an unrecoverable
01481   /// error parsing the definition of a tag.
01482   void ActOnTagDefinitionError(Scope *S, Decl *TagDecl);
01483 
01484   EnumConstantDecl *CheckEnumConstant(EnumDecl *Enum,
01485                                       EnumConstantDecl *LastEnumConst,
01486                                       SourceLocation IdLoc,
01487                                       IdentifierInfo *Id,
01488                                       Expr *val);
01489   bool CheckEnumUnderlyingType(TypeSourceInfo *TI);
01490   bool CheckEnumRedeclaration(SourceLocation EnumLoc, bool IsScoped,
01491                               QualType EnumUnderlyingTy, const EnumDecl *Prev);
01492 
01493   Decl *ActOnEnumConstant(Scope *S, Decl *EnumDecl, Decl *LastEnumConstant,
01494                           SourceLocation IdLoc, IdentifierInfo *Id,
01495                           AttributeList *Attrs,
01496                           SourceLocation EqualLoc, Expr *Val);
01497   void ActOnEnumBody(SourceLocation EnumLoc, SourceLocation LBraceLoc,
01498                      SourceLocation RBraceLoc, Decl *EnumDecl,
01499                      Decl **Elements, unsigned NumElements,
01500                      Scope *S, AttributeList *Attr);
01501 
01502   DeclContext *getContainingDC(DeclContext *DC);
01503 
01504   /// Set the current declaration context until it gets popped.
01505   void PushDeclContext(Scope *S, DeclContext *DC);
01506   void PopDeclContext();
01507 
01508   /// EnterDeclaratorContext - Used when we must lookup names in the context
01509   /// of a declarator's nested name specifier.
01510   void EnterDeclaratorContext(Scope *S, DeclContext *DC);
01511   void ExitDeclaratorContext(Scope *S);
01512 
01513   /// Push the parameters of D, which must be a function, into scope.
01514   void ActOnReenterFunctionContext(Scope* S, Decl* D);
01515   void ActOnExitFunctionContext();
01516 
01517   DeclContext *getFunctionLevelDeclContext();
01518 
01519   /// getCurFunctionDecl - If inside of a function body, this returns a pointer
01520   /// to the function decl for the function being parsed.  If we're currently
01521   /// in a 'block', this returns the containing context.
01522   FunctionDecl *getCurFunctionDecl();
01523 
01524   /// getCurMethodDecl - If inside of a method body, this returns a pointer to
01525   /// the method decl for the method being parsed.  If we're currently
01526   /// in a 'block', this returns the containing context.
01527   ObjCMethodDecl *getCurMethodDecl();
01528 
01529   /// getCurFunctionOrMethodDecl - Return the Decl for the current ObjC method
01530   /// or C function we're in, otherwise return null.  If we're currently
01531   /// in a 'block', this returns the containing context.
01532   NamedDecl *getCurFunctionOrMethodDecl();
01533 
01534   /// Add this decl to the scope shadowed decl chains.
01535   void PushOnScopeChains(NamedDecl *D, Scope *S, bool AddToContext = true);
01536 
01537   /// \brief Make the given externally-produced declaration visible at the
01538   /// top level scope.
01539   ///
01540   /// \param D The externally-produced declaration to push.
01541   ///
01542   /// \param Name The name of the externally-produced declaration.
01543   void pushExternalDeclIntoScope(NamedDecl *D, DeclarationName Name);
01544 
01545   /// isDeclInScope - If 'Ctx' is a function/method, isDeclInScope returns true
01546   /// if 'D' is in Scope 'S', otherwise 'S' is ignored and isDeclInScope returns
01547   /// true if 'D' belongs to the given declaration context.
01548   ///
01549   /// \param ExplicitInstantiationOrSpecialization When true, we are checking
01550   /// whether the declaration is in scope for the purposes of explicit template
01551   /// instantiation or specialization. The default is false.
01552   bool isDeclInScope(NamedDecl *&D, DeclContext *Ctx, Scope *S = 0,
01553                      bool ExplicitInstantiationOrSpecialization = false);
01554 
01555   /// Finds the scope corresponding to the given decl context, if it
01556   /// happens to be an enclosing scope.  Otherwise return NULL.
01557   static Scope *getScopeForDeclContext(Scope *S, DeclContext *DC);
01558 
01559   /// Subroutines of ActOnDeclarator().
01560   TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, QualType T,
01561                                 TypeSourceInfo *TInfo);
01562   bool isIncompatibleTypedef(TypeDecl *Old, TypedefNameDecl *New);
01563 
01564   /// Attribute merging methods. Return true if a new attribute was added.
01565   AvailabilityAttr *mergeAvailabilityAttr(Decl *D, SourceRange Range,
01566                                           IdentifierInfo *Platform,
01567                                           VersionTuple Introduced,
01568                                           VersionTuple Deprecated,
01569                                           VersionTuple Obsoleted,
01570                                           bool IsUnavailable,
01571                                           StringRef Message);
01572   VisibilityAttr *mergeVisibilityAttr(Decl *D, SourceRange Range,
01573                                       VisibilityAttr::VisibilityType Vis);
01574   DLLImportAttr *mergeDLLImportAttr(Decl *D, SourceRange Range);
01575   DLLExportAttr *mergeDLLExportAttr(Decl *D, SourceRange Range);
01576   FormatAttr *mergeFormatAttr(Decl *D, SourceRange Range, StringRef Format,
01577                               int FormatIdx, int FirstArg);
01578   SectionAttr *mergeSectionAttr(Decl *D, SourceRange Range, StringRef Name);
01579   bool mergeDeclAttribute(Decl *New, InheritableAttr *Attr);
01580 
01581   void mergeDeclAttributes(Decl *New, Decl *Old, bool MergeDeprecation = true);
01582   void MergeTypedefNameDecl(TypedefNameDecl *New, LookupResult &OldDecls);
01583   bool MergeFunctionDecl(FunctionDecl *New, Decl *Old, Scope *S);
01584   bool MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old,
01585                                     Scope *S);
01586   void mergeObjCMethodDecls(ObjCMethodDecl *New, ObjCMethodDecl *Old);
01587   void MergeVarDecl(VarDecl *New, LookupResult &OldDecls);
01588   void MergeVarDeclTypes(VarDecl *New, VarDecl *Old);
01589   void MergeVarDeclExceptionSpecs(VarDecl *New, VarDecl *Old);
01590   bool MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old, Scope *S);
01591 
01592   // AssignmentAction - This is used by all the assignment diagnostic functions
01593   // to represent what is actually causing the operation
01594   enum AssignmentAction {
01595     AA_Assigning,
01596     AA_Passing,
01597     AA_Returning,
01598     AA_Converting,
01599     AA_Initializing,
01600     AA_Sending,
01601     AA_Casting
01602   };
01603 
01604   /// C++ Overloading.
01605   enum OverloadKind {
01606     /// This is a legitimate overload: the existing declarations are
01607     /// functions or function templates with different signatures.
01608     Ovl_Overload,
01609 
01610     /// This is not an overload because the signature exactly matches
01611     /// an existing declaration.
01612     Ovl_Match,
01613 
01614     /// This is not an overload because the lookup results contain a
01615     /// non-function.
01616     Ovl_NonFunction
01617   };
01618   OverloadKind CheckOverload(Scope *S,
01619                              FunctionDecl *New,
01620                              const LookupResult &OldDecls,
01621                              NamedDecl *&OldDecl,
01622                              bool IsForUsingDecl);
01623   bool IsOverload(FunctionDecl *New, FunctionDecl *Old, bool IsForUsingDecl);
01624 
01625   /// \brief Checks availability of the function depending on the current
01626   /// function context.Inside an unavailable function,unavailability is ignored.
01627   ///
01628   /// \returns true if \arg FD is unavailable and current context is inside
01629   /// an available function, false otherwise.
01630   bool isFunctionConsideredUnavailable(FunctionDecl *FD);
01631 
01632   ImplicitConversionSequence
01633   TryImplicitConversion(Expr *From, QualType ToType,
01634                         bool SuppressUserConversions,
01635                         bool AllowExplicit,
01636                         bool InOverloadResolution,
01637                         bool CStyle,
01638                         bool AllowObjCWritebackConversion);
01639 
01640   bool IsIntegralPromotion(Expr *From, QualType FromType, QualType ToType);
01641   bool IsFloatingPointPromotion(QualType FromType, QualType ToType);
01642   bool IsComplexPromotion(QualType FromType, QualType ToType);
01643   bool IsPointerConversion(Expr *From, QualType FromType, QualType ToType,
01644                            bool InOverloadResolution,
01645                            QualType& ConvertedType, bool &IncompatibleObjC);
01646   bool isObjCPointerConversion(QualType FromType, QualType ToType,
01647                                QualType& ConvertedType, bool &IncompatibleObjC);
01648   bool isObjCWritebackConversion(QualType FromType, QualType ToType,
01649                                  QualType &ConvertedType);
01650   bool IsBlockPointerConversion(QualType FromType, QualType ToType,
01651                                 QualType& ConvertedType);
01652   bool FunctionArgTypesAreEqual(const FunctionProtoType *OldType,
01653                                 const FunctionProtoType *NewType,
01654                                 unsigned *ArgPos = 0);
01655   void HandleFunctionTypeMismatch(PartialDiagnostic &PDiag,
01656                                   QualType FromType, QualType ToType);
01657 
01658   CastKind PrepareCastToObjCObjectPointer(ExprResult &E);
01659   bool CheckPointerConversion(Expr *From, QualType ToType,
01660                               CastKind &Kind,
01661                               CXXCastPath& BasePath,
01662                               bool IgnoreBaseAccess);
01663   bool IsMemberPointerConversion(Expr *From, QualType FromType, QualType ToType,
01664                                  bool InOverloadResolution,
01665                                  QualType &ConvertedType);
01666   bool CheckMemberPointerConversion(Expr *From, QualType ToType,
01667                                     CastKind &Kind,
01668                                     CXXCastPath &BasePath,
01669                                     bool IgnoreBaseAccess);
01670   bool IsQualificationConversion(QualType FromType, QualType ToType,
01671                                  bool CStyle, bool &ObjCLifetimeConversion);
01672   bool IsNoReturnConversion(QualType FromType, QualType ToType,
01673                             QualType &ResultTy);
01674   bool DiagnoseMultipleUserDefinedConversion(Expr *From, QualType ToType);
01675 
01676 
01677   ExprResult PerformMoveOrCopyInitialization(const InitializedEntity &Entity,
01678                                              const VarDecl *NRVOCandidate,
01679                                              QualType ResultType,
01680                                              Expr *Value,
01681                                              bool AllowNRVO = true);
01682 
01683   bool CanPerformCopyInitialization(const InitializedEntity &Entity,
01684                                     ExprResult Init);
01685   ExprResult PerformCopyInitialization(const InitializedEntity &Entity,
01686                                        SourceLocation EqualLoc,
01687                                        ExprResult Init,
01688                                        bool TopLevelOfInitList = false,
01689                                        bool AllowExplicit = false);
01690   ExprResult PerformObjectArgumentInitialization(Expr *From,
01691                                                  NestedNameSpecifier *Qualifier,
01692                                                  NamedDecl *FoundDecl,
01693                                                  CXXMethodDecl *Method);
01694 
01695   ExprResult PerformContextuallyConvertToBool(Expr *From);
01696   ExprResult PerformContextuallyConvertToObjCPointer(Expr *From);
01697 
01698   /// Contexts in which a converted constant expression is required.
01699   enum CCEKind {
01700     CCEK_CaseValue,  ///< Expression in a case label.
01701     CCEK_Enumerator, ///< Enumerator value with fixed underlying type.
01702     CCEK_TemplateArg ///< Value of a non-type template parameter.
01703   };
01704   ExprResult CheckConvertedConstantExpression(Expr *From, QualType T,
01705                                               llvm::APSInt &Value, CCEKind CCE);
01706 
01707   /// \brief Abstract base class used to diagnose problems that occur while
01708   /// trying to convert an expression to integral or enumeration type.
01709   class ICEConvertDiagnoser {
01710   public:
01711     bool Suppress;
01712     bool SuppressConversion;
01713     
01714     ICEConvertDiagnoser(bool Suppress = false,
01715                         bool SuppressConversion = false)
01716       : Suppress(Suppress), SuppressConversion(SuppressConversion) { }
01717     
01718     /// \brief Emits a diagnostic complaining that the expression does not have
01719     /// integral or enumeration type.
01720     virtual DiagnosticBuilder diagnoseNotInt(Sema &S, SourceLocation Loc,
01721                                              QualType T) = 0;
01722     
01723     /// \brief Emits a diagnostic when the expression has incomplete class type.
01724     virtual DiagnosticBuilder diagnoseIncomplete(Sema &S, SourceLocation Loc,
01725                                                  QualType T) = 0;
01726     
01727     /// \brief Emits a diagnostic when the only matching conversion function
01728     /// is explicit.
01729     virtual DiagnosticBuilder diagnoseExplicitConv(Sema &S, SourceLocation Loc,
01730                                                    QualType T,
01731                                                    QualType ConvTy) = 0;
01732 
01733     /// \brief Emits a note for the explicit conversion function.
01734     virtual DiagnosticBuilder
01735     noteExplicitConv(Sema &S, CXXConversionDecl *Conv, QualType ConvTy) = 0;
01736 
01737     /// \brief Emits a diagnostic when there are multiple possible conversion
01738     /// functions.
01739     virtual DiagnosticBuilder diagnoseAmbiguous(Sema &S, SourceLocation Loc,
01740                                                 QualType T) = 0;
01741 
01742     /// \brief Emits a note for one of the candidate conversions.
01743     virtual DiagnosticBuilder noteAmbiguous(Sema &S, CXXConversionDecl *Conv,
01744                                             QualType ConvTy) = 0;
01745 
01746     /// \brief Emits a diagnostic when we picked a conversion function
01747     /// (for cases when we are not allowed to pick a conversion function).
01748     virtual DiagnosticBuilder diagnoseConversion(Sema &S, SourceLocation Loc,
01749                                                  QualType T,
01750                                                  QualType ConvTy) = 0;
01751     
01752     virtual ~ICEConvertDiagnoser() {}
01753   };
01754 
01755   ExprResult
01756   ConvertToIntegralOrEnumerationType(SourceLocation Loc, Expr *FromE,
01757                                      ICEConvertDiagnoser &Diagnoser,
01758                                      bool AllowScopedEnumerations);
01759 
01760   enum ObjCSubscriptKind {
01761     OS_Array,
01762     OS_Dictionary,
01763     OS_Error
01764   };
01765   ObjCSubscriptKind CheckSubscriptingKind(Expr *FromE);
01766 
01767   ExprResult PerformObjectMemberConversion(Expr *From,
01768                                            NestedNameSpecifier *Qualifier,
01769                                            NamedDecl *FoundDecl,
01770                                            NamedDecl *Member);
01771 
01772   // Members have to be NamespaceDecl* or TranslationUnitDecl*.
01773   // TODO: make this is a typesafe union.
01774   typedef llvm::SmallPtrSet<DeclContext   *, 16> AssociatedNamespaceSet;
01775   typedef llvm::SmallPtrSet<CXXRecordDecl *, 16> AssociatedClassSet;
01776 
01777   void AddOverloadCandidate(FunctionDecl *Function,
01778                             DeclAccessPair FoundDecl,
01779                             llvm::ArrayRef<Expr *> Args,
01780                             OverloadCandidateSet& CandidateSet,
01781                             bool SuppressUserConversions = false,
01782                             bool PartialOverloading = false,
01783                             bool AllowExplicit = false);
01784   void AddFunctionCandidates(const UnresolvedSetImpl &Functions,
01785                              llvm::ArrayRef<Expr *> Args,
01786                              OverloadCandidateSet& CandidateSet,
01787                              bool SuppressUserConversions = false,
01788                             TemplateArgumentListInfo *ExplicitTemplateArgs = 0);
01789   void AddMethodCandidate(DeclAccessPair FoundDecl,
01790                           QualType ObjectType,
01791                           Expr::Classification ObjectClassification,
01792                           Expr **Args, unsigned NumArgs,
01793                           OverloadCandidateSet& CandidateSet,
01794                           bool SuppressUserConversion = false);
01795   void AddMethodCandidate(CXXMethodDecl *Method,
01796                           DeclAccessPair FoundDecl,
01797                           CXXRecordDecl *ActingContext, QualType ObjectType,
01798                           Expr::Classification ObjectClassification,
01799                           llvm::ArrayRef<Expr *> Args,
01800                           OverloadCandidateSet& CandidateSet,
01801                           bool SuppressUserConversions = false);
01802   void AddMethodTemplateCandidate(FunctionTemplateDecl *MethodTmpl,
01803                                   DeclAccessPair FoundDecl,
01804                                   CXXRecordDecl *ActingContext,
01805                                  TemplateArgumentListInfo *ExplicitTemplateArgs,
01806                                   QualType ObjectType,
01807                                   Expr::Classification ObjectClassification,
01808                                   llvm::ArrayRef<Expr *> Args,
01809                                   OverloadCandidateSet& CandidateSet,
01810                                   bool SuppressUserConversions = false);
01811   void AddTemplateOverloadCandidate(FunctionTemplateDecl *FunctionTemplate,
01812                                     DeclAccessPair FoundDecl,
01813                                  TemplateArgumentListInfo *ExplicitTemplateArgs,
01814                                     llvm::ArrayRef<Expr *> Args,
01815                                     OverloadCandidateSet& CandidateSet,
01816                                     bool SuppressUserConversions = false);
01817   void AddConversionCandidate(CXXConversionDecl *Conversion,
01818                               DeclAccessPair FoundDecl,
01819                               CXXRecordDecl *ActingContext,
01820                               Expr *From, QualType ToType,
01821                               OverloadCandidateSet& CandidateSet);
01822   void AddTemplateConversionCandidate(FunctionTemplateDecl *FunctionTemplate,
01823                                       DeclAccessPair FoundDecl,
01824                                       CXXRecordDecl *ActingContext,
01825                                       Expr *From, QualType ToType,
01826                                       OverloadCandidateSet &CandidateSet);
01827   void AddSurrogateCandidate(CXXConversionDecl *Conversion,
01828                              DeclAccessPair FoundDecl,
01829                              CXXRecordDecl *ActingContext,
01830                              const FunctionProtoType *Proto,
01831                              Expr *Object, llvm::ArrayRef<Expr*> Args,
01832                              OverloadCandidateSet& CandidateSet);
01833   void AddMemberOperatorCandidates(OverloadedOperatorKind Op,
01834                                    SourceLocation OpLoc,
01835                                    Expr **Args, unsigned NumArgs,
01836                                    OverloadCandidateSet& CandidateSet,
01837                                    SourceRange OpRange = SourceRange());
01838   void AddBuiltinCandidate(QualType ResultTy, QualType *ParamTys,
01839                            Expr **Args, unsigned NumArgs,
01840                            OverloadCandidateSet& CandidateSet,
01841                            bool IsAssignmentOperator = false,
01842                            unsigned NumContextualBoolArguments = 0);
01843   void AddBuiltinOperatorCandidates(OverloadedOperatorKind Op,
01844                                     SourceLocation OpLoc,
01845                                     Expr **Args, unsigned NumArgs,
01846                                     OverloadCandidateSet& CandidateSet);
01847   void AddArgumentDependentLookupCandidates(DeclarationName Name,
01848                                             bool Operator, SourceLocation Loc,
01849                                             llvm::ArrayRef<Expr *> Args,
01850                                 TemplateArgumentListInfo *ExplicitTemplateArgs,
01851                                             OverloadCandidateSet& CandidateSet,
01852                                             bool PartialOverloading = false,
01853                                         bool StdNamespaceIsAssociated = false);
01854 
01855   // Emit as a 'note' the specific overload candidate
01856   void NoteOverloadCandidate(FunctionDecl *Fn, QualType DestType = QualType());
01857 
01858   // Emit as a series of 'note's all template and non-templates
01859   // identified by the expression Expr
01860   void NoteAllOverloadCandidates(Expr* E, QualType DestType = QualType());
01861 
01862   // [PossiblyAFunctionType]  -->   [Return]
01863   // NonFunctionType --> NonFunctionType
01864   // R (A) --> R(A)
01865   // R (*)(A) --> R (A)
01866   // R (&)(A) --> R (A)
01867   // R (S::*)(A) --> R (A)
01868   QualType ExtractUnqualifiedFunctionType(QualType PossiblyAFunctionType);
01869 
01870   FunctionDecl *
01871   ResolveAddressOfOverloadedFunction(Expr *AddressOfExpr,
01872                                      QualType TargetType,
01873                                      bool Complain,
01874                                      DeclAccessPair &Found,
01875                                      bool *pHadMultipleCandidates = 0);
01876 
01877   FunctionDecl *ResolveSingleFunctionTemplateSpecialization(OverloadExpr *ovl,
01878                                                    bool Complain = false,
01879                                                    DeclAccessPair* Found = 0);
01880 
01881   bool ResolveAndFixSingleFunctionTemplateSpecialization(
01882                       ExprResult &SrcExpr,
01883                       bool DoFunctionPointerConverion = false,
01884                       bool Complain = false,
01885                       const SourceRange& OpRangeForComplaining = SourceRange(),
01886                       QualType DestTypeForComplaining = QualType(),
01887                       unsigned DiagIDForComplaining = 0);
01888 
01889 
01890   Expr *FixOverloadedFunctionReference(Expr *E,
01891                                        DeclAccessPair FoundDecl,
01892                                        FunctionDecl *Fn);
01893   ExprResult FixOverloadedFunctionReference(ExprResult,
01894                                             DeclAccessPair FoundDecl,
01895                                             FunctionDecl *Fn);
01896 
01897   void AddOverloadedCallCandidates(UnresolvedLookupExpr *ULE,
01898                                    llvm::ArrayRef<Expr *> Args,
01899                                    OverloadCandidateSet &CandidateSet,
01900                                    bool PartialOverloading = false);
01901 
01902   ExprResult BuildOverloadedCallExpr(Scope *S, Expr *Fn,
01903                                      UnresolvedLookupExpr *ULE,
01904                                      SourceLocation LParenLoc,
01905                                      Expr **Args, unsigned NumArgs,
01906                                      SourceLocation RParenLoc,
01907                                      Expr *ExecConfig,
01908                                      bool AllowTypoCorrection=true);
01909 
01910   ExprResult CreateOverloadedUnaryOp(SourceLocation OpLoc,
01911                                      unsigned Opc,
01912                                      const UnresolvedSetImpl &Fns,
01913                                      Expr *input);
01914 
01915   ExprResult CreateOverloadedBinOp(SourceLocation OpLoc,
01916                                    unsigned Opc,
01917                                    const UnresolvedSetImpl &Fns,
01918                                    Expr *LHS, Expr *RHS);
01919 
01920   ExprResult CreateOverloadedArraySubscriptExpr(SourceLocation LLoc,
01921                                                 SourceLocation RLoc,
01922                                                 Expr *Base,Expr *Idx);
01923 
01924   ExprResult
01925   BuildCallToMemberFunction(Scope *S, Expr *MemExpr,
01926                             SourceLocation LParenLoc, Expr **Args,
01927                             unsigned NumArgs, SourceLocation RParenLoc);
01928   ExprResult
01929   BuildCallToObjectOfClassType(Scope *S, Expr *Object, SourceLocation LParenLoc,
01930                                Expr **Args, unsigned NumArgs,
01931                                SourceLocation RParenLoc);
01932 
01933   ExprResult BuildOverloadedArrowExpr(Scope *S, Expr *Base,
01934                                       SourceLocation OpLoc);
01935 
01936   /// CheckCallReturnType - Checks that a call expression's return type is
01937   /// complete. Returns true on failure. The location passed in is the location
01938   /// that best represents the call.
01939   bool CheckCallReturnType(QualType ReturnType, SourceLocation Loc,
01940                            CallExpr *CE, FunctionDecl *FD);
01941 
01942   /// Helpers for dealing with blocks and functions.
01943   bool CheckParmsForFunctionDef(ParmVarDecl **Param, ParmVarDecl **ParamEnd,
01944                                 bool CheckParameterNames);
01945   void CheckCXXDefaultArguments(FunctionDecl *FD);
01946   void CheckExtraCXXDefaultArguments(Declarator &D);
01947   Scope *getNonFieldDeclScope(Scope *S);
01948 
01949   /// \name Name lookup
01950   ///
01951   /// These routines provide name lookup that is used during semantic
01952   /// analysis to resolve the various kinds of names (identifiers,
01953   /// overloaded operator names, constructor names, etc.) into zero or
01954   /// more declarations within a particular scope. The major entry
01955   /// points are LookupName, which performs unqualified name lookup,
01956   /// and LookupQualifiedName, which performs qualified name lookup.
01957   ///
01958   /// All name lookup is performed based on some specific criteria,
01959   /// which specify what names will be visible to name lookup and how
01960   /// far name lookup should work. These criteria are important both
01961   /// for capturing language semantics (certain lookups will ignore
01962   /// certain names, for example) and for performance, since name
01963   /// lookup is often a bottleneck in the compilation of C++. Name
01964   /// lookup criteria is specified via the LookupCriteria enumeration.
01965   ///
01966   /// The results of name lookup can vary based on the kind of name
01967   /// lookup performed, the current language, and the translation
01968   /// unit. In C, for example, name lookup will either return nothing
01969   /// (no entity found) or a single declaration. In C++, name lookup
01970   /// can additionally refer to a set of overloaded functions or
01971   /// result in an ambiguity. All of the possible results of name
01972   /// lookup are captured by the LookupResult class, which provides
01973   /// the ability to distinguish among them.
01974   //@{
01975 
01976   /// @brief Describes the kind of name lookup to perform.
01977   enum LookupNameKind {
01978     /// Ordinary name lookup, which finds ordinary names (functions,
01979     /// variables, typedefs, etc.) in C and most kinds of names
01980     /// (functions, variables, members, types, etc.) in C++.
01981     LookupOrdinaryName = 0,
01982     /// Tag name lookup, which finds the names of enums, classes,
01983     /// structs, and unions.
01984     LookupTagName,
01985     /// Label name lookup.
01986     LookupLabel,
01987     /// Member name lookup, which finds the names of
01988     /// class/struct/union members.
01989     LookupMemberName,
01990     /// Look up of an operator name (e.g., operator+) for use with
01991     /// operator overloading. This lookup is similar to ordinary name
01992     /// lookup, but will ignore any declarations that are class members.
01993     LookupOperatorName,
01994     /// Look up of a name that precedes the '::' scope resolution
01995     /// operator in C++. This lookup completely ignores operator, object,
01996     /// function, and enumerator names (C++ [basic.lookup.qual]p1).
01997     LookupNestedNameSpecifierName,
01998     /// Look up a namespace name within a C++ using directive or
01999     /// namespace alias definition, ignoring non-namespace names (C++
02000     /// [basic.lookup.udir]p1).
02001     LookupNamespaceName,
02002     /// Look up all declarations in a scope with the given name,
02003     /// including resolved using declarations.  This is appropriate
02004     /// for checking redeclarations for a using declaration.
02005     LookupUsingDeclName,
02006     /// Look up an ordinary name that is going to be redeclared as a
02007     /// name with linkage. This lookup ignores any declarations that
02008     /// are outside of the current scope unless they have linkage. See
02009     /// C99 6.2.2p4-5 and C++ [basic.link]p6.
02010     LookupRedeclarationWithLinkage,
02011     /// Look up the name of an Objective-C protocol.
02012     LookupObjCProtocolName,
02013     /// Look up implicit 'self' parameter of an objective-c method.
02014     LookupObjCImplicitSelfParam,
02015     /// \brief Look up any declaration with any name.
02016     LookupAnyName
02017   };
02018 
02019   /// \brief Specifies whether (or how) name lookup is being performed for a
02020   /// redeclaration (vs. a reference).
02021   enum RedeclarationKind {
02022     /// \brief The lookup is a reference to this name that is not for the
02023     /// purpose of redeclaring the name.
02024     NotForRedeclaration = 0,
02025     /// \brief The lookup results will be used for redeclaration of a name,
02026     /// if an entity by that name already exists.
02027     ForRedeclaration
02028   };
02029 
02030   /// \brief The possible outcomes of name lookup for a literal operator.
02031   enum LiteralOperatorLookupResult {
02032     /// \brief The lookup resulted in an error.
02033     LOLR_Error,
02034     /// \brief The lookup found a single 'cooked' literal operator, which
02035     /// expects a normal literal to be built and passed to it.
02036     LOLR_Cooked,
02037     /// \brief The lookup found a single 'raw' literal operator, which expects
02038     /// a string literal containing the spelling of the literal token.
02039     LOLR_Raw,
02040     /// \brief The lookup found an overload set of literal operator templates,
02041     /// which expect the characters of the spelling of the literal token to be
02042     /// passed as a non-type template argument pack.
02043     LOLR_Template
02044   };
02045 
02046   SpecialMemberOverloadResult *LookupSpecialMember(CXXRecordDecl *D,
02047                                                    CXXSpecialMember SM,
02048                                                    bool ConstArg,
02049                                                    bool VolatileArg,
02050                                                    bool RValueThis,
02051                                                    bool ConstThis,
02052                                                    bool VolatileThis);
02053 
02054 private:
02055   bool CppLookupName(LookupResult &R, Scope *S);
02056 
02057   // \brief The set of known/encountered (unique, canonicalized) NamespaceDecls.
02058   //
02059   // The boolean value will be true to indicate that the namespace was loaded
02060   // from an AST/PCH file, or false otherwise.
02061   llvm::DenseMap<NamespaceDecl*, bool> KnownNamespaces;
02062 
02063   /// \brief Whether we have already loaded known namespaces from an extenal
02064   /// source.
02065   bool LoadedExternalKnownNamespaces;
02066 
02067 public:
02068   /// \brief Look up a name, looking for a single declaration.  Return
02069   /// null if the results were absent, ambiguous, or overloaded.
02070   ///
02071   /// It is preferable to use the elaborated form and explicitly handle
02072   /// ambiguity and overloaded.
02073   NamedDecl *LookupSingleName(Scope *S, DeclarationName Name,
02074                               SourceLocation Loc,
02075                               LookupNameKind NameKind,
02076                               RedeclarationKind Redecl
02077                                 = NotForRedeclaration);
02078   bool LookupName(LookupResult &R, Scope *S,
02079                   bool AllowBuiltinCreation = false);
02080   bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx,
02081                            bool InUnqualifiedLookup = false);
02082   bool LookupParsedName(LookupResult &R, Scope *S, CXXScopeSpec *SS,
02083                         bool AllowBuiltinCreation = false,
02084                         bool EnteringContext = false);
02085   ObjCProtocolDecl *LookupProtocol(IdentifierInfo *II, SourceLocation IdLoc,
02086                                    RedeclarationKind Redecl
02087                                      = NotForRedeclaration);
02088 
02089   void LookupOverloadedOperatorName(OverloadedOperatorKind Op, Scope *S,
02090                                     QualType T1, QualType T2,
02091                                     UnresolvedSetImpl &Functions);
02092 
02093   LabelDecl *LookupOrCreateLabel(IdentifierInfo *II, SourceLocation IdentLoc,
02094                                  SourceLocation GnuLabelLoc = SourceLocation());
02095 
02096   DeclContextLookupResult LookupConstructors(CXXRecordDecl *Class);
02097   CXXConstructorDecl *LookupDefaultConstructor(CXXRecordDecl *Class);
02098   CXXConstructorDecl *LookupCopyingConstructor(CXXRecordDecl *Class,
02099                                                unsigned Quals);
02100   CXXMethodDecl *LookupCopyingAssignment(CXXRecordDecl *Class, unsigned Quals,
02101                                          bool RValueThis, unsigned ThisQuals);
02102   CXXConstructorDecl *LookupMovingConstructor(CXXRecordDecl *Class);
02103   CXXMethodDecl *LookupMovingAssignment(CXXRecordDecl *Class, bool RValueThis,
02104                                         unsigned ThisQuals);
02105   CXXDestructorDecl *LookupDestructor(CXXRecordDecl *Class);
02106 
02107   LiteralOperatorLookupResult LookupLiteralOperator(Scope *S, LookupResult &R,
02108                                                     ArrayRef<QualType> ArgTys,
02109                                                     bool AllowRawAndTemplate);
02110 
02111   void ArgumentDependentLookup(DeclarationName Name, bool Operator,
02112                                SourceLocation Loc,
02113                                llvm::ArrayRef<Expr *> Args,
02114                                ADLResult &Functions,
02115                                bool StdNamespaceIsAssociated = false);
02116 
02117   void LookupVisibleDecls(Scope *S, LookupNameKind Kind,
02118                           VisibleDeclConsumer &Consumer,
02119                           bool IncludeGlobalScope = true);
02120   void LookupVisibleDecls(DeclContext *Ctx, LookupNameKind Kind,
02121                           VisibleDeclConsumer &Consumer,
02122                           bool IncludeGlobalScope = true);
02123 
02124   TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo,
02125                              Sema::LookupNameKind LookupKind,
02126                              Scope *S, CXXScopeSpec *SS,
02127                              CorrectionCandidateCallback &CCC,
02128                              DeclContext *MemberContext = 0,
02129                              bool EnteringContext = false,
02130                              const ObjCObjectPointerType *OPT = 0);
02131 
02132   void FindAssociatedClassesAndNamespaces(llvm::ArrayRef<Expr *> Args,
02133                                    AssociatedNamespaceSet &AssociatedNamespaces,
02134                                    AssociatedClassSet &AssociatedClasses);
02135 
02136   void FilterLookupForScope(LookupResult &R, DeclContext *Ctx, Scope *S,
02137                             bool ConsiderLinkage,
02138                             bool ExplicitInstantiationOrSpecialization);
02139 
02140   bool DiagnoseAmbiguousLookup(LookupResult &Result);
02141   //@}
02142 
02143   ObjCInterfaceDecl *getObjCInterfaceDecl(IdentifierInfo *&Id,
02144                                           SourceLocation IdLoc,
02145                                           bool TypoCorrection = false);
02146   NamedDecl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID,
02147                                  Scope *S, bool ForRedeclaration,
02148                                  SourceLocation Loc);
02149   NamedDecl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II,
02150                                       Scope *S);
02151   void AddKnownFunctionAttributes(FunctionDecl *FD);
02152 
02153   // More parsing and symbol table subroutines.
02154 
02155   // Decl attributes - this routine is the top level dispatcher.
02156   void ProcessDeclAttributes(Scope *S, Decl *D, const Declarator &PD,
02157                            bool NonInheritable = true, bool Inheritable = true);
02158   void ProcessDeclAttributeList(Scope *S, Decl *D, const AttributeList *AL,
02159                            bool NonInheritable = true, bool Inheritable = true);
02160   bool ProcessAccessDeclAttributeList(AccessSpecDecl *ASDecl,
02161                                       const AttributeList *AttrList);
02162 
02163   void checkUnusedDeclAttributes(Declarator &D);
02164 
02165   bool CheckRegparmAttr(const AttributeList &attr, unsigned &value);
02166   bool CheckCallingConvAttr(const AttributeList &attr, CallingConv &CC);
02167   bool CheckNoReturnAttr(const AttributeList &attr);
02168 
02169   /// \brief Stmt attributes - this routine is the top level dispatcher.
02170   StmtResult ProcessStmtAttributes(Stmt *Stmt, AttributeList *Attrs,
02171                                    SourceRange Range);
02172 
02173   void WarnUndefinedMethod(SourceLocation ImpLoc, ObjCMethodDecl *method,
02174                            bool &IncompleteImpl, unsigned DiagID);
02175   void WarnConflictingTypedMethods(ObjCMethodDecl *Method,
02176                                    ObjCMethodDecl *MethodDecl,
02177                                    bool IsProtocolMethodDecl);
02178 
02179   void CheckConflictingOverridingMethod(ObjCMethodDecl *Method,
02180                                    ObjCMethodDecl *Overridden,
02181                                    bool IsProtocolMethodDecl);
02182 
02183   /// WarnExactTypedMethods - This routine issues a warning if method
02184   /// implementation declaration matches exactly that of its declaration.
02185   void WarnExactTypedMethods(ObjCMethodDecl *Method,
02186                              ObjCMethodDecl *MethodDecl,
02187                              bool IsProtocolMethodDecl);
02188 
02189   bool isPropertyReadonly(ObjCPropertyDecl *PropertyDecl,
02190                           ObjCInterfaceDecl *IDecl);
02191 
02192   typedef llvm::DenseSet<Selector, llvm::DenseMapInfo<Selector> > SelectorSet;
02193   typedef llvm::DenseMap<Selector, ObjCMethodDecl*> ProtocolsMethodsMap;
02194 
02195   /// CheckProtocolMethodDefs - This routine checks unimplemented
02196   /// methods declared in protocol, and those referenced by it.
02197   /// \param IDecl - Used for checking for methods which may have been
02198   /// inherited.
02199   void CheckProtocolMethodDefs(SourceLocation ImpLoc,
02200                                ObjCProtocolDecl *PDecl,
02201                                bool& IncompleteImpl,
02202                                const SelectorSet &InsMap,
02203                                const SelectorSet &ClsMap,
02204                                ObjCContainerDecl *CDecl);
02205 
02206   /// CheckImplementationIvars - This routine checks if the instance variables
02207   /// listed in the implelementation match those listed in the interface.
02208   void CheckImplementationIvars(ObjCImplementationDecl *ImpDecl,
02209                                 ObjCIvarDecl **Fields, unsigned nIvars,
02210                                 SourceLocation Loc);
02211 
02212   /// ImplMethodsVsClassMethods - This is main routine to warn if any method
02213   /// remains unimplemented in the class or category @implementation.
02214   void ImplMethodsVsClassMethods(Scope *S, ObjCImplDecl* IMPDecl,
02215                                  ObjCContainerDecl* IDecl,
02216                                  bool IncompleteImpl = false);
02217 
02218   /// DiagnoseUnimplementedProperties - This routine warns on those properties
02219   /// which must be implemented by this implementation.
02220   void DiagnoseUnimplementedProperties(Scope *S, ObjCImplDecl* IMPDecl,
02221                                        ObjCContainerDecl *CDecl,
02222                                        const SelectorSet &InsMap);
02223 
02224   /// DefaultSynthesizeProperties - This routine default synthesizes all
02225   /// properties which must be synthesized in class's @implementation.
02226   void DefaultSynthesizeProperties (Scope *S, ObjCImplDecl* IMPDecl,
02227                                     ObjCInterfaceDecl *IDecl);
02228   void DefaultSynthesizeProperties(Scope *S, Decl *D);
02229 
02230   /// CollectImmediateProperties - This routine collects all properties in
02231   /// the class and its conforming protocols; but not those it its super class.
02232   void CollectImmediateProperties(ObjCContainerDecl *CDecl,
02233             llvm::DenseMap<IdentifierInfo *, ObjCPropertyDecl*>& PropMap,
02234             llvm::DenseMap<IdentifierInfo *, ObjCPropertyDecl*>& SuperPropMap);
02235 
02236 
02237   /// LookupPropertyDecl - Looks up a property in the current class and all
02238   /// its protocols.
02239   ObjCPropertyDecl *LookupPropertyDecl(const ObjCContainerDecl *CDecl,
02240                                        IdentifierInfo *II);
02241 
02242   /// Called by ActOnProperty to handle @property declarations in
02243   ////  class extensions.
02244   Decl *HandlePropertyInClassExtension(Scope *S,
02245                                        SourceLocation AtLoc,
02246                                        SourceLocation LParenLoc,
02247                                        FieldDeclarator &FD,
02248                                        Selector GetterSel,
02249                                        Selector SetterSel,
02250                                        const bool isAssign,
02251                                        const bool isReadWrite,
02252                                        const unsigned Attributes,
02253                                        const unsigned AttributesAsWritten,
02254                                        bool *isOverridingProperty,
02255                                        TypeSourceInfo *T,
02256                                        tok::ObjCKeywordKind MethodImplKind);
02257 
02258   /// Called by ActOnProperty and HandlePropertyInClassExtension to
02259   ///  handle creating the ObjcPropertyDecl for a category or @interface.
02260   ObjCPropertyDecl *CreatePropertyDecl(Scope *S,
02261                                        ObjCContainerDecl *CDecl,
02262                                        SourceLocation AtLoc,
02263                                        SourceLocation LParenLoc,
02264                                        FieldDeclarator &FD,
02265                                        Selector GetterSel,
02266                                        Selector SetterSel,
02267                                        const bool isAssign,
02268                                        const bool isReadWrite,
02269                                        const unsigned Attributes,
02270                                        const unsigned AttributesAsWritten,
02271                                        TypeSourceInfo *T,
02272                                        tok::ObjCKeywordKind MethodImplKind,
02273                                        DeclContext *lexicalDC = 0);
02274 
02275   /// AtomicPropertySetterGetterRules - This routine enforces the rule (via
02276   /// warning) when atomic property has one but not the other user-declared
02277   /// setter or getter.
02278   void AtomicPropertySetterGetterRules(ObjCImplDecl* IMPDecl,
02279                                        ObjCContainerDecl* IDecl);
02280 
02281   void DiagnoseOwningPropertyGetterSynthesis(const ObjCImplementationDecl *D);
02282 
02283   void DiagnoseDuplicateIvars(ObjCInterfaceDecl *ID, ObjCInterfaceDecl *SID);
02284 
02285   enum MethodMatchStrategy {
02286     MMS_loose,
02287     MMS_strict
02288   };
02289 
02290   /// MatchTwoMethodDeclarations - Checks if two methods' type match and returns
02291   /// true, or false, accordingly.
02292   bool MatchTwoMethodDeclarations(const ObjCMethodDecl *Method,
02293                                   const ObjCMethodDecl *PrevMethod,
02294                                   MethodMatchStrategy strategy = MMS_strict);
02295 
02296   /// MatchAllMethodDeclarations - Check methods declaraed in interface or
02297   /// or protocol against those declared in their implementations.
02298   void MatchAllMethodDeclarations(const SelectorSet &InsMap,
02299                                   const SelectorSet &ClsMap,
02300                                   SelectorSet &InsMapSeen,
02301                                   SelectorSet &ClsMapSeen,
02302                                   ObjCImplDecl* IMPDecl,
02303                                   ObjCContainerDecl* IDecl,
02304                                   bool &IncompleteImpl,
02305                                   bool ImmediateClass,
02306                                   bool WarnCategoryMethodImpl=false);
02307 
02308   /// CheckCategoryVsClassMethodMatches - Checks that methods implemented in
02309   /// category matches with those implemented in its primary class and
02310   /// warns each time an exact match is found.
02311   void CheckCategoryVsClassMethodMatches(ObjCCategoryImplDecl *CatIMP);
02312 
02313   /// \brief Add the given method to the list of globally-known methods.
02314   void addMethodToGlobalList(ObjCMethodList *List, ObjCMethodDecl *Method);
02315   
02316 private:
02317   /// AddMethodToGlobalPool - Add an instance or factory method to the global
02318   /// pool. See descriptoin of AddInstanceMethodToGlobalPool.
02319   void AddMethodToGlobalPool(ObjCMethodDecl *Method, bool impl, bool instance);
02320 
02321   /// LookupMethodInGlobalPool - Returns the instance or factory method and
02322   /// optionally warns if there are multiple signatures.
02323   ObjCMethodDecl *LookupMethodInGlobalPool(Selector Sel, SourceRange R,
02324                                            bool receiverIdOrClass,
02325                                            bool warn, bool instance);
02326 
02327 public:
02328   /// AddInstanceMethodToGlobalPool - All instance methods in a translation
02329   /// unit are added to a global pool. This allows us to efficiently associate
02330   /// a selector with a method declaraation for purposes of typechecking
02331   /// messages sent to "id" (where the class of the object is unknown).
02332   void AddInstanceMethodToGlobalPool(ObjCMethodDecl *Method, bool impl=false) {
02333     AddMethodToGlobalPool(Method, impl, /*instance*/true);
02334   }
02335 
02336   /// AddFactoryMethodToGlobalPool - Same as above, but for factory methods.
02337   void AddFactoryMethodToGlobalPool(ObjCMethodDecl *Method, bool impl=false) {
02338     AddMethodToGlobalPool(Method, impl, /*instance*/false);
02339   }
02340 
02341   /// AddAnyMethodToGlobalPool - Add any method, instance or factory to global
02342   /// pool.
02343   void AddAnyMethodToGlobalPool(Decl *D);
02344 
02345   /// LookupInstanceMethodInGlobalPool - Returns the method and warns if
02346   /// there are multiple signatures.
02347   ObjCMethodDecl *LookupInstanceMethodInGlobalPool(Selector Sel, SourceRange R,
02348                                                    bool receiverIdOrClass=false,
02349                                                    bool warn=true) {
02350     return LookupMethodInGlobalPool(Sel, R, receiverIdOrClass,
02351                                     warn, /*instance*/true);
02352   }
02353 
02354   /// LookupFactoryMethodInGlobalPool - Returns the method and warns if
02355   /// there are multiple signatures.
02356   ObjCMethodDecl *LookupFactoryMethodInGlobalPool(Selector Sel, SourceRange R,
02357                                                   bool receiverIdOrClass=false,
02358                                                   bool warn=true) {
02359     return LookupMethodInGlobalPool(Sel, R, receiverIdOrClass,
02360                                     warn, /*instance*/false);
02361   }
02362 
02363   /// LookupImplementedMethodInGlobalPool - Returns the method which has an
02364   /// implementation.
02365   ObjCMethodDecl *LookupImplementedMethodInGlobalPool(Selector Sel);
02366 
02367   /// CollectIvarsToConstructOrDestruct - Collect those ivars which require
02368   /// initialization.
02369   void CollectIvarsToConstructOrDestruct(ObjCInterfaceDecl *OI,
02370                                   SmallVectorImpl<ObjCIvarDecl*> &Ivars);
02371 
02372   //===--------------------------------------------------------------------===//
02373   // Statement Parsing Callbacks: SemaStmt.cpp.
02374 public:
02375   class FullExprArg {
02376   public:
02377     FullExprArg(Sema &actions) : E(0) { }
02378 
02379     // FIXME: The const_cast here is ugly. RValue references would make this
02380     // much nicer (or we could duplicate a bunch of the move semantics
02381     // emulation code from Ownership.h).
02382     FullExprArg(const FullExprArg& Other) : E(Other.E) {}
02383 
02384     ExprResult release() {
02385       return move(E);
02386     }
02387 
02388     Expr *get() const { return E; }
02389 
02390     Expr *operator->() {
02391       return E;
02392     }
02393 
02394   private:
02395     // FIXME: No need to make the entire Sema class a friend when it's just
02396     // Sema::MakeFullExpr that needs access to the constructor below.
02397     friend class Sema;
02398 
02399     explicit FullExprArg(Expr *expr) : E(expr) {}
02400 
02401     Expr *E;
02402   };
02403 
02404   FullExprArg MakeFullExpr(Expr *Arg) {
02405     return MakeFullExpr(Arg, Arg ? Arg->getExprLoc() : SourceLocation());
02406   }
02407   FullExprArg MakeFullExpr(Expr *Arg, SourceLocation CC) {
02408     return FullExprArg(ActOnFinishFullExpr(Arg, CC).release());
02409   }
02410 
02411   StmtResult ActOnExprStmt(FullExprArg Expr);
02412 
02413   StmtResult ActOnNullStmt(SourceLocation SemiLoc,
02414                            bool HasLeadingEmptyMacro = false);
02415 
02416   void ActOnStartOfCompoundStmt();
02417   void ActOnFinishOfCompoundStmt();
02418   StmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R,
02419                                        MultiStmtArg Elts,
02420                                        bool isStmtExpr);
02421 
02422   /// \brief A RAII object to enter scope of a compound statement.
02423   class CompoundScopeRAII {
02424   public:
02425     CompoundScopeRAII(Sema &S): S(S) {
02426       S.ActOnStartOfCompoundStmt();
02427     }
02428 
02429     ~CompoundScopeRAII() {
02430       S.ActOnFinishOfCompoundStmt();
02431     }
02432 
02433   private:
02434     Sema &S;
02435   };
02436 
02437   StmtResult ActOnDeclStmt(DeclGroupPtrTy Decl,
02438                                    SourceLocation StartLoc,
02439                                    SourceLocation EndLoc);
02440   void ActOnForEachDeclStmt(DeclGroupPtrTy Decl);
02441   StmtResult ActOnForEachLValueExpr(Expr *E);
02442   StmtResult ActOnCaseStmt(SourceLocation CaseLoc, Expr *LHSVal,
02443                                    SourceLocation DotDotDotLoc, Expr *RHSVal,
02444                                    SourceLocation ColonLoc);
02445   void ActOnCaseStmtBody(Stmt *CaseStmt, Stmt *SubStmt);
02446 
02447   StmtResult ActOnDefaultStmt(SourceLocation DefaultLoc,
02448                                       SourceLocation ColonLoc,
02449                                       Stmt *SubStmt, Scope *CurScope);
02450   StmtResult ActOnLabelStmt(SourceLocation IdentLoc, LabelDecl *TheDecl,
02451                             SourceLocation ColonLoc, Stmt *SubStmt);
02452 
02453   StmtResult ActOnAttributedStmt(SourceLocation AttrLoc, const AttrVec &Attrs,
02454                                  Stmt *SubStmt);
02455 
02456   StmtResult ActOnIfStmt(SourceLocation IfLoc,
02457                          FullExprArg CondVal, Decl *CondVar,
02458                          Stmt *ThenVal,
02459                          SourceLocation ElseLoc, Stmt *ElseVal);
02460   StmtResult ActOnStartOfSwitchStmt(SourceLocation SwitchLoc,
02461                                             Expr *Cond,
02462                                             Decl *CondVar);
02463   StmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc,
02464                                            Stmt *Switch, Stmt *Body);
02465   StmtResult ActOnWhileStmt(SourceLocation WhileLoc,
02466                             FullExprArg Cond,
02467                             Decl *CondVar, Stmt *Body);
02468   StmtResult ActOnDoStmt(SourceLocation DoLoc, Stmt *Body,
02469                                  SourceLocation WhileLoc,
02470                                  SourceLocation CondLParen, Expr *Cond,
02471                                  SourceLocation CondRParen);
02472 
02473   StmtResult ActOnForStmt(SourceLocation ForLoc,
02474                           SourceLocation LParenLoc,
02475                           Stmt *First, FullExprArg Second,
02476                           Decl *SecondVar,
02477                           FullExprArg Third,
02478                           SourceLocation RParenLoc,
02479                           Stmt *Body);
02480   ExprResult ActOnObjCForCollectionOperand(SourceLocation forLoc,
02481                                            Expr *collection);
02482   StmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc,
02483                                         SourceLocation LParenLoc,
02484                                         Stmt *First, Expr *Second,
02485                                         SourceLocation RParenLoc, Stmt *Body);
02486   StmtResult ActOnCXXForRangeStmt(SourceLocation ForLoc,
02487                                   SourceLocation LParenLoc, Stmt *LoopVar,
02488                                   SourceLocation ColonLoc, Expr *Collection,
02489                                   SourceLocation RParenLoc);
02490   StmtResult BuildCXXForRangeStmt(SourceLocation ForLoc,
02491                                   SourceLocation ColonLoc,
02492                                   Stmt *RangeDecl, Stmt *BeginEndDecl,
02493                                   Expr *Cond, Expr *Inc,
02494                                   Stmt *LoopVarDecl,
02495                                   SourceLocation RParenLoc);
02496   StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body);
02497 
02498   StmtResult ActOnGotoStmt(SourceLocation GotoLoc,
02499                            SourceLocation LabelLoc,
02500                            LabelDecl *TheDecl);
02501   StmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc,
02502                                    SourceLocation StarLoc,
02503                                    Expr *DestExp);
02504   StmtResult ActOnContinueStmt(SourceLocation ContinueLoc, Scope *CurScope);
02505   StmtResult ActOnBreakStmt(SourceLocation GotoLoc, Scope *CurScope);
02506 
02507   const VarDecl *getCopyElisionCandidate(QualType ReturnType, Expr *E,
02508                                          bool AllowFunctionParameters);
02509 
02510   StmtResult ActOnReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp);
02511   StmtResult ActOnCapScopeReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp);
02512 
02513   StmtResult ActOnAsmStmt(SourceLocation AsmLoc,
02514                           bool IsSimple, bool IsVolatile,
02515                           unsigned NumOutputs, unsigned NumInputs,
02516                           IdentifierInfo **Names,
02517                           MultiExprArg Constraints,
02518                           MultiExprArg Exprs,
02519                           Expr *AsmString,
02520                           MultiExprArg Clobbers,
02521                           SourceLocation RParenLoc,
02522                           bool MSAsm = false);
02523 
02524 
02525   VarDecl *BuildObjCExceptionDecl(TypeSourceInfo *TInfo, QualType ExceptionType,
02526                                   SourceLocation StartLoc,
02527                                   SourceLocation IdLoc, IdentifierInfo *Id,
02528                                   bool Invalid = false);
02529 
02530   Decl *ActOnObjCExceptionDecl(Scope *S, Declarator &D);
02531 
02532   StmtResult ActOnObjCAtCatchStmt(SourceLocation AtLoc, SourceLocation RParen,
02533                                   Decl *Parm, Stmt *Body);
02534 
02535   StmtResult ActOnObjCAtFinallyStmt(SourceLocation AtLoc, Stmt *Body);
02536 
02537   StmtResult ActOnObjCAtTryStmt(SourceLocation AtLoc, Stmt *Try,
02538                                 MultiStmtArg Catch, Stmt *Finally);
02539 
02540   StmtResult BuildObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw);
02541   StmtResult ActOnObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw,
02542                                   Scope *CurScope);
02543   ExprResult ActOnObjCAtSynchronizedOperand(SourceLocation atLoc,
02544                                             Expr *operand);
02545   StmtResult ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc,
02546                                          Expr *SynchExpr,
02547                                          Stmt *SynchBody);
02548 
02549   StmtResult ActOnObjCAutoreleasePoolStmt(SourceLocation AtLoc, Stmt *Body);
02550 
02551   VarDecl *BuildExceptionDeclaration(Scope *S, TypeSourceInfo *TInfo,
02552                                      SourceLocation StartLoc,
02553                                      SourceLocation IdLoc,
02554                                      IdentifierInfo *Id);
02555 
02556   Decl *ActOnExceptionDeclarator(Scope *S, Declarator &D);
02557 
02558   StmtResult ActOnCXXCatchBlock(SourceLocation CatchLoc,
02559                                 Decl *ExDecl, Stmt *HandlerBlock);
02560   StmtResult ActOnCXXTryBlock(SourceLocation TryLoc, Stmt *TryBlock,
02561                               MultiStmtArg Handlers);
02562 
02563   StmtResult ActOnSEHTryBlock(bool IsCXXTry, // try (true) or __try (false) ?
02564                               SourceLocation TryLoc,
02565                               Stmt *TryBlock,
02566                               Stmt *Handler);
02567 
02568   StmtResult ActOnSEHExceptBlock(SourceLocation Loc,
02569                                  Expr *FilterExpr,
02570                                  Stmt *Block);
02571 
02572   StmtResult ActOnSEHFinallyBlock(SourceLocation Loc,
02573                                   Stmt *Block);
02574 
02575   void DiagnoseReturnInConstructorExceptionHandler(CXXTryStmt *TryBlock);
02576 
02577   bool ShouldWarnIfUnusedFileScopedDecl(const DeclaratorDecl *D) const;
02578 
02579   /// \brief If it's a file scoped decl that must warn if not used, keep track
02580   /// of it.
02581   void MarkUnusedFileScopedDecl(const DeclaratorDecl *D);
02582 
02583   /// DiagnoseUnusedExprResult - If the statement passed in is an expression
02584   /// whose result is unused, warn.
02585   void DiagnoseUnusedExprResult(const Stmt *S);
02586   void DiagnoseUnusedDecl(const NamedDecl *ND);
02587 
02588   /// Emit \p DiagID if statement located on \p StmtLoc has a suspicious null
02589   /// statement as a \p Body, and it is located on the same line.
02590   ///
02591   /// This helps prevent bugs due to typos, such as:
02592   ///     if (condition);
02593   ///       do_stuff();
02594   void DiagnoseEmptyStmtBody(SourceLocation StmtLoc,
02595                              const Stmt *Body,
02596                              unsigned DiagID);
02597 
02598   /// Warn if a for/while loop statement \p S, which is followed by
02599   /// \p PossibleBody, has a suspicious null statement as a body.
02600   void DiagnoseEmptyLoopBody(const Stmt *S,
02601                              const Stmt *PossibleBody);
02602 
02603   ParsingDeclState PushParsingDeclaration(sema::DelayedDiagnosticPool &pool) {
02604     return DelayedDiagnostics.push(pool);
02605   }
02606   void PopParsingDeclaration(ParsingDeclState state, Decl *decl);
02607 
02608   typedef ProcessingContextState ParsingClassState;
02609   ParsingClassState PushParsingClass() {
02610     return DelayedDiagnostics.pushUndelayed();
02611   }
02612   void PopParsingClass(ParsingClassState state) {
02613     DelayedDiagnostics.popUndelayed(state);
02614   }
02615 
02616   void redelayDiagnostics(sema::DelayedDiagnosticPool &pool);
02617 
02618   void EmitDeprecationWarning(NamedDecl *D, StringRef Message,
02619                               SourceLocation Loc,
02620                               const ObjCInterfaceDecl *UnknownObjCClass=0);
02621 
02622   void HandleDelayedDeprecationCheck(sema::DelayedDiagnostic &DD, Decl *Ctx);
02623 
02624   bool makeUnavailableInSystemHeader(SourceLocation loc,
02625                                      StringRef message);
02626 
02627   //===--------------------------------------------------------------------===//
02628   // Expression Parsing Callbacks: SemaExpr.cpp.
02629 
02630   bool CanUseDecl(NamedDecl *D);
02631   bool DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc,
02632                          const ObjCInterfaceDecl *UnknownObjCClass=0);
02633   void NoteDeletedFunction(FunctionDecl *FD);
02634   std::string getDeletedOrUnavailableSuffix(const FunctionDecl *FD);
02635   bool DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *PD,
02636                                         ObjCMethodDecl *Getter,
02637                                         SourceLocation Loc);
02638   void DiagnoseSentinelCalls(NamedDecl *D, SourceLocation Loc,
02639                              Expr **Args, unsigned NumArgs);
02640 
02641   void PushExpressionEvaluationContext(ExpressionEvaluationContext NewContext,
02642                                        Decl *LambdaContextDecl = 0,
02643                                        bool IsDecltype = false);
02644 
02645   void PopExpressionEvaluationContext();
02646 
02647   void DiscardCleanupsInEvaluationContext();
02648 
02649   ExprResult TranformToPotentiallyEvaluated(Expr *E);
02650   ExprResult HandleExprEvaluationContextForTypeof(Expr *E);
02651 
02652   ExprResult ActOnConstantExpression(ExprResult Res);
02653 
02654   // Functions for marking a declaration referenced.  These functions also
02655   // contain the relevant logic for marking if a reference to a function or
02656   // variable is an odr-use (in the C++11 sense).  There are separate variants
02657   // for expressions referring to a decl; these exist because odr-use marking
02658   // needs to be delayed for some constant variables when we build one of the
02659   // named expressions.
02660   void MarkAnyDeclReferenced(SourceLocation Loc, Decl *D);
02661   void MarkFunctionReferenced(SourceLocation Loc, FunctionDecl *Func);
02662   void MarkVariableReferenced(SourceLocation Loc, VarDecl *Var);
02663   void MarkDeclRefReferenced(DeclRefExpr *E);
02664   void MarkMemberReferenced(MemberExpr *E);
02665 
02666   void UpdateMarkingForLValueToRValue(Expr *E);
02667   void CleanupVarDeclMarking();
02668 
02669   enum TryCaptureKind {
02670     TryCapture_Implicit, TryCapture_ExplicitByVal, TryCapture_ExplicitByRef
02671   };
02672 
02673   /// \brief Try to capture the given variable.
02674   ///
02675   /// \param Var The variable to capture.
02676   ///
02677   /// \param Loc The location at which the capture occurs.
02678   ///
02679   /// \param Kind The kind of capture, which may be implicit (for either a 
02680   /// block or a lambda), or explicit by-value or by-reference (for a lambda).
02681   ///
02682   /// \param EllipsisLoc The location of the ellipsis, if one is provided in
02683   /// an explicit lambda capture.
02684   ///
02685   /// \param BuildAndDiagnose Whether we are actually supposed to add the 
02686   /// captures or diagnose errors. If false, this routine merely check whether
02687   /// the capture can occur without performing the capture itself or complaining
02688   /// if the variable cannot be captured.
02689   ///
02690   /// \param CaptureType Will be set to the type of the field used to capture
02691   /// this variable in the innermost block or lambda. Only valid when the
02692   /// variable can be captured.
02693   ///
02694   /// \param DeclRefType Will be set to the type of a refernce to the capture
02695   /// from within the current scope. Only valid when the variable can be 
02696   /// captured.
02697   ///
02698   /// \returns true if an error occurred (i.e., the variable cannot be
02699   /// captured) and false if the capture succeeded.
02700   bool tryCaptureVariable(VarDecl *Var, SourceLocation Loc, TryCaptureKind Kind,
02701                           SourceLocation EllipsisLoc, bool BuildAndDiagnose, 
02702                           QualType &CaptureType,
02703                           QualType &DeclRefType);
02704 
02705   /// \brief Try to capture the given variable.
02706   bool tryCaptureVariable(VarDecl *Var, SourceLocation Loc,
02707                           TryCaptureKind Kind = TryCapture_Implicit,
02708                           SourceLocation EllipsisLoc = SourceLocation());
02709   
02710   /// \brief Given a variable, determine the type that a reference to that
02711   /// variable will have in the given scope.
02712   QualType getCapturedDeclRefType(VarDecl *Var, SourceLocation Loc);
02713   
02714   void MarkDeclarationsReferencedInType(SourceLocation Loc, QualType T);
02715   void MarkDeclarationsReferencedInExpr(Expr *E, 
02716                                         bool SkipLocalVariables = false);
02717 
02718   /// \brief Try to recover by turning the given expression into a
02719   /// call.  Returns true if recovery was attempted or an error was
02720   /// emitted; this may also leave the ExprResult invalid.
02721   bool tryToRecoverWithCall(ExprResult &E, const PartialDiagnostic &PD,
02722                             bool ForceComplain = false,
02723                             bool (*IsPlausibleResult)(QualType) = 0);
02724 
02725   /// \brief Figure out if an expression could be turned into a call.
02726   bool isExprCallable(const Expr &E, QualType &ZeroArgCallReturnTy,
02727                       UnresolvedSetImpl &NonTemplateOverloads);
02728 
02729   /// \brief Conditionally issue a diagnostic based on the current
02730   /// evaluation context.
02731   ///
02732   /// \param stmt - If stmt is non-null, delay reporting the diagnostic until
02733   ///  the function body is parsed, and then do a basic reachability analysis to
02734   ///  determine if the statement is reachable.  If it is unreachable, the
02735   ///  diagnostic will not be emitted.
02736   bool DiagRuntimeBehavior(SourceLocation Loc, const Stmt *Statement,
02737                            const PartialDiagnostic &PD);
02738 
02739   // Primary Expressions.
02740   SourceRange getExprRange(Expr *E) const;
02741 
02742   ExprResult ActOnIdExpression(Scope *S, CXXScopeSpec &SS,
02743                                SourceLocation TemplateKWLoc,
02744                                UnqualifiedId &Id,
02745                                bool HasTrailingLParen, bool IsAddressOfOperand,
02746                                CorrectionCandidateCallback *CCC = 0);
02747 
02748   void DecomposeUnqualifiedId(const UnqualifiedId &Id,
02749                               TemplateArgumentListInfo &Buffer,
02750                               DeclarationNameInfo &NameInfo,
02751                               const TemplateArgumentListInfo *&TemplateArgs);
02752 
02753   bool DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R,
02754                            CorrectionCandidateCallback &CCC,
02755                            TemplateArgumentListInfo *ExplicitTemplateArgs = 0,
02756                        llvm::ArrayRef<Expr *> Args = llvm::ArrayRef<Expr *>());
02757 
02758   ExprResult LookupInObjCMethod(LookupResult &LookUp, Scope *S,
02759                                 IdentifierInfo *II,
02760                                 bool AllowBuiltinCreation=false);
02761 
02762   ExprResult ActOnDependentIdExpression(const CXXScopeSpec &SS,
02763                                         SourceLocation TemplateKWLoc,
02764                                         const DeclarationNameInfo &NameInfo,
02765                                         bool isAddressOfOperand,
02766                                 const TemplateArgumentListInfo *TemplateArgs);
02767 
02768   ExprResult BuildDeclRefExpr(ValueDecl *D, QualType Ty,
02769                               ExprValueKind VK,
02770                               SourceLocation Loc,
02771                               const CXXScopeSpec *SS = 0);
02772   ExprResult BuildDeclRefExpr(ValueDecl *D, QualType Ty,
02773                               ExprValueKind VK,
02774                               const DeclarationNameInfo &NameInfo,
02775                               const CXXScopeSpec *SS = 0);
02776   ExprResult
02777   BuildAnonymousStructUnionMemberReference(const CXXScopeSpec &SS,
02778                                            SourceLocation nameLoc,
02779                                            IndirectFieldDecl *indirectField,
02780                                            Expr *baseObjectExpr = 0,
02781                                       SourceLocation opLoc = SourceLocation());
02782   ExprResult BuildPossibleImplicitMemberExpr(const CXXScopeSpec &SS,
02783                                              SourceLocation TemplateKWLoc,
02784                                              LookupResult &R,
02785                                 const TemplateArgumentListInfo *TemplateArgs);
02786   ExprResult BuildImplicitMemberExpr(const CXXScopeSpec &SS,
02787                                      SourceLocation TemplateKWLoc,
02788                                      LookupResult &R,
02789                                 const TemplateArgumentListInfo *TemplateArgs,
02790                                      bool IsDefiniteInstance);
02791   bool UseArgumentDependentLookup(const CXXScopeSpec &SS,
02792                                   const LookupResult &R,
02793                                   bool HasTrailingLParen);
02794 
02795   ExprResult BuildQualifiedDeclarationNameExpr(CXXScopeSpec &SS,
02796                                          const DeclarationNameInfo &NameInfo);
02797   ExprResult BuildDependentDeclRefExpr(const CXXScopeSpec &SS,
02798                                        SourceLocation TemplateKWLoc,
02799                                 const DeclarationNameInfo &NameInfo,
02800                                 const TemplateArgumentListInfo *TemplateArgs);
02801 
02802   ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS,
02803                                       LookupResult &R,
02804                                       bool NeedsADL);
02805   ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS,
02806                                       const DeclarationNameInfo &NameInfo,
02807                                       NamedDecl *D);
02808 
02809   ExprResult BuildLiteralOperatorCall(LookupResult &R,
02810                                       DeclarationNameInfo &SuffixInfo,
02811                                       ArrayRef<Expr*> Args,
02812                                       SourceLocation LitEndLoc,
02813                             TemplateArgumentListInfo *ExplicitTemplateArgs = 0);
02814 
02815   ExprResult ActOnPredefinedExpr(SourceLocation Loc, tok::TokenKind Kind);
02816   ExprResult ActOnIntegerConstant(SourceLocation Loc, uint64_t Val);
02817   ExprResult ActOnNumericConstant(const Token &Tok, Scope *UDLScope = 0);
02818   ExprResult ActOnCharacterConstant(const Token &Tok, Scope *UDLScope = 0);
02819   ExprResult ActOnParenExpr(SourceLocation L, SourceLocation R, Expr *E);
02820   ExprResult ActOnParenListExpr(SourceLocation L,
02821                                 SourceLocation R,
02822                                 MultiExprArg Val);
02823 
02824   /// ActOnStringLiteral - The specified tokens were lexed as pasted string
02825   /// fragments (e.g. "foo" "bar" L"baz").
02826   ExprResult ActOnStringLiteral(const Token *StringToks, unsigned NumStringToks,
02827                                 Scope *UDLScope = 0);
02828 
02829   ExprResult ActOnGenericSelectionExpr(SourceLocation KeyLoc,
02830                                        SourceLocation DefaultLoc,
02831                                        SourceLocation RParenLoc,
02832                                        Expr *ControllingExpr,
02833                                        MultiTypeArg ArgTypes,
02834                                        MultiExprArg ArgExprs);
02835   ExprResult CreateGenericSelectionExpr(SourceLocation KeyLoc,
02836                                         SourceLocation DefaultLoc,
02837                                         SourceLocation RParenLoc,
02838                                         Expr *ControllingExpr,
02839                                         TypeSourceInfo **Types,
02840                                         Expr **Exprs,
02841                                         unsigned NumAssocs);
02842 
02843   // Binary/Unary Operators.  'Tok' is the token for the operator.
02844   ExprResult CreateBuiltinUnaryOp(SourceLocation OpLoc, UnaryOperatorKind Opc,
02845                                   Expr *InputExpr);
02846   ExprResult BuildUnaryOp(Scope *S, SourceLocation OpLoc,
02847                           UnaryOperatorKind Opc, Expr *Input);
02848   ExprResult ActOnUnaryOp(Scope *S, SourceLocation OpLoc,
02849                           tok::TokenKind Op, Expr *Input);
02850 
02851   ExprResult CreateUnaryExprOrTypeTraitExpr(TypeSourceInfo *TInfo,
02852                                             SourceLocation OpLoc,
02853                                             UnaryExprOrTypeTrait ExprKind,
02854                                             SourceRange R);
02855   ExprResult CreateUnaryExprOrTypeTraitExpr(Expr *E, SourceLocation OpLoc,
02856                                             UnaryExprOrTypeTrait ExprKind);
02857   ExprResult
02858     ActOnUnaryExprOrTypeTraitExpr(SourceLocation OpLoc,
02859                                   UnaryExprOrTypeTrait ExprKind,
02860                                   bool IsType, void *TyOrEx,
02861                                   const SourceRange &ArgRange);
02862 
02863   ExprResult CheckPlaceholderExpr(Expr *E);
02864   bool CheckVecStepExpr(Expr *E);
02865 
02866   bool CheckUnaryExprOrTypeTraitOperand(Expr *E, UnaryExprOrTypeTrait ExprKind);
02867   bool CheckUnaryExprOrTypeTraitOperand(QualType ExprType, SourceLocation OpLoc,
02868                                         SourceRange ExprRange,
02869                                         UnaryExprOrTypeTrait ExprKind);
02870   ExprResult ActOnSizeofParameterPackExpr(Scope *S,
02871                                           SourceLocation OpLoc,
02872                                           IdentifierInfo &Name,
02873                                           SourceLocation NameLoc,
02874                                           SourceLocation RParenLoc);
02875   ExprResult ActOnPostfixUnaryOp(Scope *S, SourceLocation OpLoc,
02876                                  tok::TokenKind Kind, Expr *Input);
02877 
02878   ExprResult ActOnArraySubscriptExpr(Scope *S, Expr *Base, SourceLocation LLoc,
02879                                      Expr *Idx, SourceLocation RLoc);
02880   ExprResult CreateBuiltinArraySubscriptExpr(Expr *Base, SourceLocation LLoc,
02881                                              Expr *Idx, SourceLocation RLoc);
02882 
02883   ExprResult BuildMemberReferenceExpr(Expr *Base, QualType BaseType,
02884                                       SourceLocation OpLoc, bool IsArrow,
02885                                       CXXScopeSpec &SS,
02886                                       SourceLocation TemplateKWLoc,
02887                                       NamedDecl *FirstQualifierInScope,
02888                                 const DeclarationNameInfo &NameInfo,
02889                                 const TemplateArgumentListInfo *TemplateArgs);
02890 
02891   // This struct is for use by ActOnMemberAccess to allow
02892   // BuildMemberReferenceExpr to be able to reinvoke ActOnMemberAccess after
02893   // changing the access operator from a '.' to a '->' (to see if that is the
02894   // change needed to fix an error about an unknown member, e.g. when the class
02895   // defines a custom operator->).
02896   struct ActOnMemberAccessExtraArgs {
02897     Scope *S;
02898     UnqualifiedId &Id;
02899     Decl *ObjCImpDecl;
02900     bool HasTrailingLParen;
02901   };
02902 
02903   ExprResult BuildMemberReferenceExpr(Expr *Base, QualType BaseType,
02904                                       SourceLocation OpLoc, bool IsArrow,
02905                                       const CXXScopeSpec &SS,
02906                                       SourceLocation TemplateKWLoc,
02907                                       NamedDecl *FirstQualifierInScope,
02908                                       LookupResult &R,
02909                                  const TemplateArgumentListInfo *TemplateArgs,
02910                                       bool SuppressQualifierCheck = false,
02911                                      ActOnMemberAccessExtraArgs *ExtraArgs = 0);
02912 
02913   ExprResult PerformMemberExprBaseConversion(Expr *Base, bool IsArrow);
02914   ExprResult LookupMemberExpr(LookupResult &R, ExprResult &Base,
02915                               bool &IsArrow, SourceLocation OpLoc,
02916                               CXXScopeSpec &SS,
02917                               Decl *ObjCImpDecl,
02918                               bool HasTemplateArgs);
02919 
02920   bool CheckQualifiedMemberReference(Expr *BaseExpr, QualType BaseType,
02921                                      const CXXScopeSpec &SS,
02922                                      const LookupResult &R);
02923 
02924   ExprResult ActOnDependentMemberExpr(Expr *Base, QualType BaseType,
02925                                       bool IsArrow, SourceLocation OpLoc,
02926                                       const CXXScopeSpec &SS,
02927                                       SourceLocation TemplateKWLoc,
02928                                       NamedDecl *FirstQualifierInScope,
02929                                const DeclarationNameInfo &NameInfo,
02930                                const TemplateArgumentListInfo *TemplateArgs);
02931 
02932   ExprResult ActOnMemberAccessExpr(Scope *S, Expr *Base,
02933                                    SourceLocation OpLoc,
02934                                    tok::TokenKind OpKind,
02935                                    CXXScopeSpec &SS,
02936                                    SourceLocation TemplateKWLoc,
02937                                    UnqualifiedId &Member,
02938                                    Decl *ObjCImpDecl,
02939                                    bool HasTrailingLParen);
02940 
02941   void ActOnDefaultCtorInitializers(Decl *CDtorDecl);
02942   bool ConvertArgumentsForCall(CallExpr *Call, Expr *Fn,
02943                                FunctionDecl *FDecl,
02944                                const FunctionProtoType *Proto,
02945                                Expr **Args, unsigned NumArgs,
02946                                SourceLocation RParenLoc,
02947                                bool ExecConfig = false);
02948   void CheckStaticArrayArgument(SourceLocation CallLoc,
02949                                 ParmVarDecl *Param,
02950                                 const Expr *ArgExpr);
02951 
02952   /// ActOnCallExpr - Handle a call to Fn with the specified array of arguments.
02953   /// This provides the location of the left/right parens and a list of comma
02954   /// locations.
02955   ExprResult ActOnCallExpr(Scope *S, Expr *Fn, SourceLocation LParenLoc,
02956                            MultiExprArg ArgExprs, SourceLocation RParenLoc,
02957                            Expr *ExecConfig = 0, bool IsExecConfig = false);
02958   ExprResult BuildResolvedCallExpr(Expr *Fn, NamedDecl *NDecl,
02959                                    SourceLocation LParenLoc,
02960                                    Expr **Args, unsigned NumArgs,
02961                                    SourceLocation RParenLoc,
02962                                    Expr *Config = 0,
02963                                    bool IsExecConfig = false);
02964 
02965   ExprResult ActOnCUDAExecConfigExpr(Scope *S, SourceLocation LLLLoc,
02966                                      MultiExprArg ExecConfig,
02967                                      SourceLocation GGGLoc);
02968 
02969   ExprResult ActOnCastExpr(Scope *S, SourceLocation LParenLoc,
02970                            Declarator &D, ParsedType &Ty,
02971                            SourceLocation RParenLoc, Expr *CastExpr);
02972   ExprResult BuildCStyleCastExpr(SourceLocation LParenLoc,
02973                                  TypeSourceInfo *Ty,
02974                                  SourceLocation RParenLoc,
02975                                  Expr *Op);
02976   CastKind PrepareScalarCast(ExprResult &src, QualType destType);
02977 
02978   /// \brief Build an altivec or OpenCL literal.
02979   ExprResult BuildVectorLiteral(SourceLocation LParenLoc,
02980                                 SourceLocation RParenLoc, Expr *E,
02981                                 TypeSourceInfo *TInfo);
02982 
02983   ExprResult MaybeConvertParenListExprToParenExpr(Scope *S, Expr *ME);
02984 
02985   ExprResult ActOnCompoundLiteral(SourceLocation LParenLoc,
02986                                   ParsedType Ty,
02987                                   SourceLocation RParenLoc,
02988                                   Expr *InitExpr);
02989 
02990   ExprResult BuildCompoundLiteralExpr(SourceLocation LParenLoc,
02991                                       TypeSourceInfo *TInfo,
02992                                       SourceLocation RParenLoc,
02993                                       Expr *LiteralExpr);
02994 
02995   ExprResult ActOnInitList(SourceLocation LBraceLoc,
02996                            MultiExprArg InitArgList,
02997                            SourceLocation RBraceLoc);
02998 
02999   ExprResult ActOnDesignatedInitializer(Designation &Desig,
03000                                         SourceLocation Loc,
03001                                         bool GNUSyntax,
03002                                         ExprResult Init);
03003 
03004   ExprResult ActOnBinOp(Scope *S, SourceLocation TokLoc,
03005                         tok::TokenKind Kind, Expr *LHSExpr, Expr *RHSExpr);
03006   ExprResult BuildBinOp(Scope *S, SourceLocation OpLoc,
03007                         BinaryOperatorKind Opc, Expr *LHSExpr, Expr *RHSExpr);
03008   ExprResult CreateBuiltinBinOp(SourceLocation OpLoc, BinaryOperatorKind Opc,
03009                                 Expr *LHSExpr, Expr *RHSExpr);
03010 
03011   /// ActOnConditionalOp - Parse a ?: operation.  Note that 'LHS' may be null
03012   /// in the case of a the GNU conditional expr extension.
03013   ExprResult ActOnConditionalOp(SourceLocation QuestionLoc,
03014                                 SourceLocation ColonLoc,
03015                                 Expr *CondExpr, Expr *LHSExpr, Expr *RHSExpr);
03016 
03017   /// ActOnAddrLabel - Parse the GNU address of label extension: "&&foo".
03018   ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc,
03019                             LabelDecl *TheDecl);
03020 
03021   void ActOnStartStmtExpr();
03022   ExprResult ActOnStmtExpr(SourceLocation LPLoc, Stmt *SubStmt,
03023                            SourceLocation RPLoc); // "({..})"
03024   void ActOnStmtExprError();
03025 
03026   // __builtin_offsetof(type, identifier(.identifier|[expr])*)
03027   struct OffsetOfComponent {
03028     SourceLocation LocStart, LocEnd;
03029     bool isBrackets;  // true if [expr], false if .ident
03030     union {
03031       IdentifierInfo *IdentInfo;
03032       Expr *E;
03033     } U;
03034   };
03035 
03036   /// __builtin_offsetof(type, a.b[123][456].c)
03037   ExprResult BuildBuiltinOffsetOf(SourceLocation BuiltinLoc,
03038                                   TypeSourceInfo *TInfo,
03039                                   OffsetOfComponent *CompPtr,
03040                                   unsigned NumComponents,
03041                                   SourceLocation RParenLoc);
03042   ExprResult ActOnBuiltinOffsetOf(Scope *S,
03043                                   SourceLocation BuiltinLoc,
03044                                   SourceLocation TypeLoc,
03045                                   ParsedType ParsedArgTy,
03046                                   OffsetOfComponent *CompPtr,
03047                                   unsigned NumComponents,
03048                                   SourceLocation RParenLoc);
03049 
03050   // __builtin_choose_expr(constExpr, expr1, expr2)
03051   ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc,
03052                              Expr *CondExpr, Expr *LHSExpr,
03053                              Expr *RHSExpr, SourceLocation RPLoc);
03054 
03055   // __builtin_va_arg(expr, type)
03056   ExprResult ActOnVAArg(SourceLocation BuiltinLoc, Expr *E, ParsedType Ty,
03057                         SourceLocation RPLoc);
03058   ExprResult BuildVAArgExpr(SourceLocation BuiltinLoc, Expr *E,
03059                             TypeSourceInfo *TInfo, SourceLocation RPLoc);
03060 
03061   // __null
03062   ExprResult ActOnGNUNullExpr(SourceLocation TokenLoc);
03063 
03064   bool CheckCaseExpression(Expr *E);
03065 
03066   /// \brief Describes the result of an "if-exists" condition check.
03067   enum IfExistsResult {
03068     /// \brief The symbol exists.
03069     IER_Exists,
03070 
03071     /// \brief The symbol does not exist.
03072     IER_DoesNotExist,
03073 
03074     /// \brief The name is a dependent name, so the results will differ
03075     /// from one instantiation to the next.
03076     IER_Dependent,
03077 
03078     /// \brief An error occurred.
03079     IER_Error
03080   };
03081 
03082   IfExistsResult
03083   CheckMicrosoftIfExistsSymbol(Scope *S, CXXScopeSpec &SS,
03084                                const DeclarationNameInfo &TargetNameInfo);
03085 
03086   IfExistsResult
03087   CheckMicrosoftIfExistsSymbol(Scope *S, SourceLocation KeywordLoc,
03088                                bool IsIfExists, CXXScopeSpec &SS,
03089                                UnqualifiedId &Name);
03090 
03091   StmtResult BuildMSDependentExistsStmt(SourceLocation KeywordLoc,
03092                                         bool IsIfExists,
03093                                         NestedNameSpecifierLoc QualifierLoc,
03094                                         DeclarationNameInfo NameInfo,
03095                                         Stmt *Nested);
03096   StmtResult ActOnMSDependentExistsStmt(SourceLocation KeywordLoc,
03097                                         bool IsIfExists,
03098                                         CXXScopeSpec &SS, UnqualifiedId &Name,
03099                                         Stmt *Nested);
03100 
03101   //===------------------------- "Block" Extension ------------------------===//
03102 
03103   /// ActOnBlockStart - This callback is invoked when a block literal is
03104   /// started.
03105   void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope);
03106 
03107   /// ActOnBlockArguments - This callback allows processing of block arguments.
03108   /// If there are no arguments, this is still invoked.
03109   void ActOnBlockArguments(Declarator &ParamInfo, Scope *CurScope);
03110 
03111   /// ActOnBlockError - If there is an error parsing a block, this callback
03112   /// is invoked to pop the information about the block from the action impl.
03113   void ActOnBlockError(SourceLocation CaretLoc, Scope *CurScope);
03114 
03115   /// ActOnBlockStmtExpr - This is called when the body of a block statement
03116   /// literal was successfully completed.  ^(int x){...}
03117   ExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc, Stmt *Body,
03118                                 Scope *CurScope);
03119 
03120   //===---------------------------- OpenCL Features -----------------------===//
03121 
03122   /// __builtin_astype(...)
03123   ExprResult ActOnAsTypeExpr(Expr *E, ParsedType ParsedDestTy,
03124                              SourceLocation BuiltinLoc,
03125                              SourceLocation RParenLoc);
03126 
03127   //===---------------------------- C++ Features --------------------------===//
03128 
03129   // Act on C++ namespaces
03130   Decl *ActOnStartNamespaceDef(Scope *S, SourceLocation InlineLoc,
03131                                SourceLocation NamespaceLoc,
03132                                SourceLocation IdentLoc,
03133                                IdentifierInfo *Ident,
03134                                SourceLocation LBrace,
03135                                AttributeList *AttrList);
03136   void ActOnFinishNamespaceDef(Decl *Dcl, SourceLocation RBrace);
03137 
03138   NamespaceDecl *getStdNamespace() const;
03139   NamespaceDecl *getOrCreateStdNamespace();
03140 
03141   CXXRecordDecl *getStdBadAlloc() const;
03142 
03143   /// \brief Tests whether Ty is an instance of std::initializer_list and, if
03144   /// it is and Element is not NULL, assigns the element type to Element.
03145   bool isStdInitializerList(QualType Ty, QualType *Element);
03146 
03147   /// \brief Looks for the std::initializer_list template and instantiates it
03148   /// with Element, or emits an error if it's not found.
03149   ///
03150   /// \returns The instantiated template, or null on error.
03151   QualType BuildStdInitializerList(QualType Element, SourceLocation Loc);
03152 
03153   /// \brief Determine whether Ctor is an initializer-list constructor, as
03154   /// defined in [dcl.init.list]p2.
03155   bool isInitListConstructor(const CXXConstructorDecl *Ctor);
03156 
03157   Decl *ActOnUsingDirective(Scope *CurScope,
03158                             SourceLocation UsingLoc,
03159                             SourceLocation NamespcLoc,
03160                             CXXScopeSpec &SS,
03161                             SourceLocation IdentLoc,
03162                             IdentifierInfo *NamespcName,
03163                             AttributeList *AttrList);
03164 
03165   void PushUsingDirective(Scope *S, UsingDirectiveDecl *UDir);
03166 
03167   Decl *ActOnNamespaceAliasDef(Scope *CurScope,
03168                                SourceLocation NamespaceLoc,
03169                                SourceLocation AliasLoc,
03170                                IdentifierInfo *Alias,
03171                                CXXScopeSpec &SS,
03172                                SourceLocation IdentLoc,
03173                                IdentifierInfo *Ident);
03174 
03175   void HideUsingShadowDecl(Scope *S, UsingShadowDecl *Shadow);
03176   bool CheckUsingShadowDecl(UsingDecl *UD, NamedDecl *Target,
03177                             const LookupResult &PreviousDecls);
03178   UsingShadowDecl *BuildUsingShadowDecl(Scope *S, UsingDecl *UD,
03179                                         NamedDecl *Target);
03180 
03181   bool CheckUsingDeclRedeclaration(SourceLocation UsingLoc,
03182                                    bool isTypeName,
03183                                    const CXXScopeSpec &SS,
03184                                    SourceLocation NameLoc,
03185                                    const LookupResult &Previous);
03186   bool CheckUsingDeclQualifier(SourceLocation UsingLoc,
03187                                const CXXScopeSpec &SS,
03188                                SourceLocation NameLoc);
03189 
03190   NamedDecl *BuildUsingDeclaration(Scope *S, AccessSpecifier AS,
03191                                    SourceLocation UsingLoc,
03192                                    CXXScopeSpec &SS,
03193                                    const DeclarationNameInfo &NameInfo,
03194                                    AttributeList *AttrList,
03195                                    bool IsInstantiation,
03196                                    bool IsTypeName,
03197                                    SourceLocation TypenameLoc);
03198 
03199   bool CheckInheritingConstructorUsingDecl(UsingDecl *UD);
03200 
03201   Decl *ActOnUsingDeclaration(Scope *CurScope,
03202                               AccessSpecifier AS,
03203                               bool HasUsingKeyword,
03204                               SourceLocation UsingLoc,
03205                               CXXScopeSpec &SS,
03206                               UnqualifiedId &Name,
03207                               AttributeList *AttrList,
03208                               bool IsTypeName,
03209                               SourceLocation TypenameLoc);
03210   Decl *ActOnAliasDeclaration(Scope *CurScope,
03211                               AccessSpecifier AS,
03212                               MultiTemplateParamsArg TemplateParams,
03213                               SourceLocation UsingLoc,
03214                               UnqualifiedId &Name,
03215                               TypeResult Type);
03216 
03217   /// InitializeVarWithConstructor - Creates an CXXConstructExpr
03218   /// and sets it as the initializer for the the passed in VarDecl.
03219   bool InitializeVarWithConstructor(VarDecl *VD,
03220                                     CXXConstructorDecl *Constructor,
03221                                     MultiExprArg Exprs,
03222                                     bool HadMultipleCandidates);
03223 
03224   /// BuildCXXConstructExpr - Creates a complete call to a constructor,
03225   /// including handling of its default argument expressions.
03226   ///
03227   /// \param ConstructKind - a CXXConstructExpr::ConstructionKind
03228   ExprResult
03229   BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType,
03230                         CXXConstructorDecl *Constructor, MultiExprArg Exprs,
03231                         bool HadMultipleCandidates, bool RequiresZeroInit,
03232                         unsigned ConstructKind, SourceRange ParenRange);
03233 
03234   // FIXME: Can re remove this and have the above BuildCXXConstructExpr check if
03235   // the constructor can be elidable?
03236   ExprResult
03237   BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType,
03238                         CXXConstructorDecl *Constructor, bool Elidable,
03239                         MultiExprArg Exprs, bool HadMultipleCandidates,
03240                         bool RequiresZeroInit, unsigned ConstructKind,
03241                         SourceRange ParenRange);
03242 
03243   /// BuildCXXDefaultArgExpr - Creates a CXXDefaultArgExpr, instantiating
03244   /// the default expr if needed.
03245   ExprResult BuildCXXDefaultArgExpr(SourceLocation CallLoc,
03246                                     FunctionDecl *FD,
03247                                     ParmVarDecl *Param);
03248 
03249   /// FinalizeVarWithDestructor - Prepare for calling destructor on the
03250   /// constructed variable.
03251   void FinalizeVarWithDestructor(VarDecl *VD, const RecordType *DeclInitType);
03252 
03253   /// \brief Helper class that collects exception specifications for
03254   /// implicitly-declared special member functions.
03255   class ImplicitExceptionSpecification {
03256     // Pointer to allow copying
03257     Sema *Self;
03258     // We order exception specifications thus:
03259     // noexcept is the most restrictive, but is only used in C++0x.
03260     // throw() comes next.
03261     // Then a throw(collected exceptions)
03262     // Finally no specification.
03263     // throw(...) is used instead if any called function uses it.
03264     //
03265     // If this exception specification cannot be known yet (for instance,
03266     // because this is the exception specification for a defaulted default
03267     // constructor and we haven't finished parsing the deferred parts of the
03268     // class yet), the C++0x standard does not specify how to behave. We
03269     // record this as an 'unknown' exception specification, which overrules
03270     // any other specification (even 'none', to keep this rule simple).
03271     ExceptionSpecificationType ComputedEST;
03272     llvm::SmallPtrSet<CanQualType, 4> ExceptionsSeen;
03273     SmallVector<QualType, 4> Exceptions;
03274 
03275     void ClearExceptions() {
03276       ExceptionsSeen.clear();
03277       Exceptions.clear();
03278     }
03279 
03280   public:
03281     explicit ImplicitExceptionSpecification(Sema &Self)
03282       : Self(&Self), ComputedEST(EST_BasicNoexcept) {
03283       if (!Self.Context.getLangOpts().CPlusPlus0x)
03284         ComputedEST = EST_DynamicNone;
03285     }
03286 
03287     /// \brief Get the computed exception specification type.
03288     ExceptionSpecificationType getExceptionSpecType() const {
03289       assert(ComputedEST != EST_ComputedNoexcept &&
03290              "noexcept(expr) should not be a possible result");
03291       return ComputedEST;
03292     }
03293 
03294     /// \brief The number of exceptions in the exception specification.
03295     unsigned size() const { return Exceptions.size(); }
03296 
03297     /// \brief The set of exceptions in the exception specification.
03298     const QualType *data() const { return Exceptions.data(); }
03299 
03300     /// \brief Integrate another called method into the collected data.
03301     void CalledDecl(SourceLocation CallLoc, CXXMethodDecl *Method);
03302 
03303     /// \brief Integrate an invoked expression into the collected data.
03304     void CalledExpr(Expr *E);
03305 
03306     /// \brief Specify that the exception specification can't be detemined yet.
03307     void SetDelayed() {
03308       ClearExceptions();
03309       ComputedEST = EST_Delayed;
03310     }
03311 
03312     /// \brief Have we been unable to compute this exception specification?
03313     bool isDelayed() {
03314       return ComputedEST == EST_Delayed;
03315     }
03316 
03317     /// \brief Overwrite an EPI's exception specification with this
03318     /// computed exception specification.
03319     void getEPI(FunctionProtoType::ExtProtoInfo &EPI) const {
03320       EPI.ExceptionSpecType = getExceptionSpecType();
03321       EPI.NumExceptions = size();
03322       EPI.Exceptions = data();
03323     }
03324     FunctionProtoType::ExtProtoInfo getEPI() const {
03325       FunctionProtoType::ExtProtoInfo EPI;
03326       getEPI(EPI);
03327       return EPI;
03328     }
03329   };
03330 
03331   /// \brief Determine what sort of exception specification a defaulted
03332   /// copy constructor of a class will have.
03333   ImplicitExceptionSpecification
03334   ComputeDefaultedDefaultCtorExceptionSpec(CXXRecordDecl *ClassDecl);
03335 
03336   /// \brief Determine what sort of exception specification a defaulted
03337   /// default constructor of a class will have, and whether the parameter
03338   /// will be const.
03339   std::pair<ImplicitExceptionSpecification, bool>
03340   ComputeDefaultedCopyCtorExceptionSpecAndConst(CXXRecordDecl *ClassDecl);
03341 
03342   /// \brief Determine what sort of exception specification a defautled
03343   /// copy assignment operator of a class will have, and whether the
03344   /// parameter will be const.
03345   std::pair<ImplicitExceptionSpecification, bool>
03346   ComputeDefaultedCopyAssignmentExceptionSpecAndConst(CXXRecordDecl *ClassDecl);
03347 
03348   /// \brief Determine what sort of exception specification a defaulted move
03349   /// constructor of a class will have.
03350   ImplicitExceptionSpecification
03351   ComputeDefaultedMoveCtorExceptionSpec(CXXRecordDecl *ClassDecl);
03352 
03353   /// \brief Determine what sort of exception specification a defaulted move
03354   /// assignment operator of a class will have.
03355   ImplicitExceptionSpecification
03356   ComputeDefaultedMoveAssignmentExceptionSpec(CXXRecordDecl *ClassDecl);
03357 
03358   /// \brief Determine what sort of exception specification a defaulted
03359   /// destructor of a class will have.
03360   ImplicitExceptionSpecification
03361   ComputeDefaultedDtorExceptionSpec(CXXRecordDecl *ClassDecl);
03362 
03363   /// \brief Check the given exception-specification and update the
03364   /// extended prototype information with the results.
03365   void checkExceptionSpecification(ExceptionSpecificationType EST,
03366                                    ArrayRef<ParsedType> DynamicExceptions,
03367                                    ArrayRef<SourceRange> DynamicExceptionRanges,
03368                                    Expr *NoexceptExpr,
03369                                    llvm::SmallVectorImpl<QualType> &Exceptions,
03370                                    FunctionProtoType::ExtProtoInfo &EPI);
03371 
03372   /// \brief Determine if a special member function should have a deleted
03373   /// definition when it is defaulted.
03374   bool ShouldDeleteSpecialMember(CXXMethodDecl *MD, CXXSpecialMember CSM,
03375                                  bool Diagnose = false);
03376 
03377   /// \brief Declare the implicit default constructor for the given class.
03378   ///
03379   /// \param ClassDecl The class declaration into which the implicit
03380   /// default constructor will be added.
03381   ///
03382   /// \returns The implicitly-declared default constructor.
03383   CXXConstructorDecl *DeclareImplicitDefaultConstructor(
03384                                                      CXXRecordDecl *ClassDecl);
03385 
03386   /// DefineImplicitDefaultConstructor - Checks for feasibility of
03387   /// defining this constructor as the default constructor.
03388   void DefineImplicitDefaultConstructor(SourceLocation CurrentLocation,
03389                                         CXXConstructorDecl *Constructor);
03390 
03391   /// \brief Declare the implicit destructor for the given class.
03392   ///
03393   /// \param ClassDecl The class declaration into which the implicit
03394   /// destructor will be added.
03395   ///
03396   /// \returns The implicitly-declared destructor.
03397   CXXDestructorDecl *DeclareImplicitDestructor(CXXRecordDecl *ClassDecl);
03398 
03399   /// DefineImplicitDestructor - Checks for feasibility of
03400   /// defining this destructor as the default destructor.
03401   void DefineImplicitDestructor(SourceLocation CurrentLocation,
03402                                 CXXDestructorDecl *Destructor);
03403 
03404   /// \brief Build an exception spec for destructors that don't have one.
03405   ///
03406   /// C++11 says that user-defined destructors with no exception spec get one
03407   /// that looks as if the destructor was implicitly declared.
03408   void AdjustDestructorExceptionSpec(CXXRecordDecl *ClassDecl,
03409                                      CXXDestructorDecl *Destructor,
03410                                      bool WasDelayed = false);
03411 
03412   /// \brief Declare all inherited constructors for the given class.
03413   ///
03414   /// \param ClassDecl The class declaration into which the inherited
03415   /// constructors will be added.
03416   void DeclareInheritedConstructors(CXXRecordDecl *ClassDecl);
03417 
03418   /// \brief Declare the implicit copy constructor for the given class.
03419   ///
03420   /// \param ClassDecl The class declaration into which the implicit
03421   /// copy constructor will be added.
03422   ///
03423   /// \returns The implicitly-declared copy constructor.
03424   CXXConstructorDecl *DeclareImplicitCopyConstructor(CXXRecordDecl *ClassDecl);
03425 
03426   /// DefineImplicitCopyConstructor - Checks for feasibility of
03427   /// defining this constructor as the copy constructor.
03428   void DefineImplicitCopyConstructor(SourceLocation CurrentLocation,
03429                                      CXXConstructorDecl *Constructor);
03430 
03431   /// \brief Declare the implicit move constructor for the given class.
03432   ///
03433   /// \param ClassDecl The Class declaration into which the implicit
03434   /// move constructor will be added.
03435   ///
03436   /// \returns The implicitly-declared move constructor, or NULL if it wasn't
03437   /// declared.
03438   CXXConstructorDecl *DeclareImplicitMoveConstructor(CXXRecordDecl *ClassDecl);
03439 
03440   /// DefineImplicitMoveConstructor - Checks for feasibility of
03441   /// defining this constructor as the move constructor.
03442   void DefineImplicitMoveConstructor(SourceLocation CurrentLocation,
03443                                      CXXConstructorDecl *Constructor);
03444 
03445   /// \brief Declare the implicit copy assignment operator for the given class.
03446   ///
03447   /// \param ClassDecl The class declaration into which the implicit
03448   /// copy assignment operator will be added.
03449   ///
03450   /// \returns The implicitly-declared copy assignment operator.
03451   CXXMethodDecl *DeclareImplicitCopyAssignment(CXXRecordDecl *ClassDecl);
03452 
03453   /// \brief Defines an implicitly-declared copy assignment operator.
03454   void DefineImplicitCopyAssignment(SourceLocation CurrentLocation,
03455                                     CXXMethodDecl *MethodDecl);
03456 
03457   /// \brief Declare the implicit move assignment operator for the given class.
03458   ///
03459   /// \param ClassDecl The Class declaration into which the implicit
03460   /// move assignment operator will be added.
03461   ///
03462   /// \returns The implicitly-declared move assignment operator, or NULL if it
03463   /// wasn't declared.
03464   CXXMethodDecl *DeclareImplicitMoveAssignment(CXXRecordDecl *ClassDecl);
03465 
03466   /// \brief Defines an implicitly-declared move assignment operator.
03467   void DefineImplicitMoveAssignment(SourceLocation CurrentLocation,
03468                                     CXXMethodDecl *MethodDecl);
03469 
03470   /// \brief Force the declaration of any implicitly-declared members of this
03471   /// class.
03472   void ForceDeclarationOfImplicitMembers(CXXRecordDecl *Class);
03473 
03474   /// \brief Determine whether the given function is an implicitly-deleted
03475   /// special member function.
03476   bool isImplicitlyDeleted(FunctionDecl *FD);
03477   
03478   /// \brief Check whether 'this' shows up in the type of a static member
03479   /// function after the (naturally empty) cv-qualifier-seq would be.
03480   ///
03481   /// \returns true if an error occurred.
03482   bool checkThisInStaticMemberFunctionType(CXXMethodDecl *Method);
03483 
03484   /// \brief Whether this' shows up in the exception specification of a static
03485   /// member function.
03486   bool checkThisInStaticMemberFunctionExceptionSpec(CXXMethodDecl *Method);
03487 
03488   /// \brief Check whether 'this' shows up in the attributes of the given
03489   /// static member function.
03490   ///
03491   /// \returns true if an error occurred.
03492   bool checkThisInStaticMemberFunctionAttributes(CXXMethodDecl *Method);
03493   
03494   /// MaybeBindToTemporary - If the passed in expression has a record type with
03495   /// a non-trivial destructor, this will return CXXBindTemporaryExpr. Otherwise
03496   /// it simply returns the passed in expression.
03497   ExprResult MaybeBindToTemporary(Expr *E);
03498 
03499   bool CompleteConstructorCall(CXXConstructorDecl *Constructor,
03500                                MultiExprArg ArgsPtr,
03501                                SourceLocation Loc,
03502                                ASTOwningVector<Expr*> &ConvertedArgs,
03503                                bool AllowExplicit = false);
03504 
03505   ParsedType getDestructorName(SourceLocation TildeLoc,
03506                                IdentifierInfo &II, SourceLocation NameLoc,
03507                                Scope *S, CXXScopeSpec &SS,
03508                                ParsedType ObjectType,
03509                                bool EnteringContext);
03510 
03511   ParsedType getDestructorType(const DeclSpec& DS, ParsedType ObjectType);
03512 
03513   // Checks that reinterpret casts don't have undefined behavior.
03514   void CheckCompatibleReinterpretCast(QualType SrcType, QualType DestType,
03515                                       bool IsDereference, SourceRange Range);
03516 
03517   /// ActOnCXXNamedCast - Parse {dynamic,static,reinterpret,const}_cast's.
03518   ExprResult ActOnCXXNamedCast(SourceLocation OpLoc,
03519                                tok::TokenKind Kind,
03520                                SourceLocation LAngleBracketLoc,
03521                                Declarator &D,
03522                                SourceLocation RAngleBracketLoc,
03523                                SourceLocation LParenLoc,
03524                                Expr *E,
03525                                SourceLocation RParenLoc);
03526 
03527   ExprResult BuildCXXNamedCast(SourceLocation OpLoc,
03528                                tok::TokenKind Kind,
03529                                TypeSourceInfo *Ty,
03530                                Expr *E,
03531                                SourceRange AngleBrackets,
03532                                SourceRange Parens);
03533 
03534   ExprResult BuildCXXTypeId(QualType TypeInfoType,
03535                             SourceLocation TypeidLoc,
03536                             TypeSourceInfo *Operand,
03537                             SourceLocation RParenLoc);
03538   ExprResult BuildCXXTypeId(QualType TypeInfoType,
03539                             SourceLocation TypeidLoc,
03540                             Expr *Operand,
03541                             SourceLocation RParenLoc);
03542 
03543   /// ActOnCXXTypeid - Parse typeid( something ).
03544   ExprResult ActOnCXXTypeid(SourceLocation OpLoc,
03545                             SourceLocation LParenLoc, bool isType,
03546                             void *TyOrExpr,
03547                             SourceLocation RParenLoc);
03548 
03549   ExprResult BuildCXXUuidof(QualType TypeInfoType,
03550                             SourceLocation TypeidLoc,
03551                             TypeSourceInfo *Operand,
03552                             SourceLocation RParenLoc);
03553   ExprResult BuildCXXUuidof(QualType TypeInfoType,
03554                             SourceLocation TypeidLoc,
03555                             Expr *Operand,
03556                             SourceLocation RParenLoc);
03557 
03558   /// ActOnCXXUuidof - Parse __uuidof( something ).
03559   ExprResult ActOnCXXUuidof(SourceLocation OpLoc,
03560                             SourceLocation LParenLoc, bool isType,
03561                             void *TyOrExpr,
03562                             SourceLocation RParenLoc);
03563 
03564 
03565   //// ActOnCXXThis -  Parse 'this' pointer.
03566   ExprResult ActOnCXXThis(SourceLocation loc);
03567 
03568   /// \brief Try to retrieve the type of the 'this' pointer.
03569   ///
03570   /// \param Capture If true, capture 'this' in this context.
03571   ///
03572   /// \returns The type of 'this', if possible. Otherwise, returns a NULL type.
03573   QualType getCurrentThisType();
03574 
03575   /// \brief When non-NULL, the C++ 'this' expression is allowed despite the 
03576   /// current context not being a non-static member function. In such cases,
03577   /// this provides the type used for 'this'.
03578   QualType CXXThisTypeOverride;
03579   
03580   /// \brief RAII object used to temporarily allow the C++ 'this' expression
03581   /// to be used, with the given qualifiers on the current class type.
03582   class CXXThisScopeRAII {
03583     Sema &S;
03584     QualType OldCXXThisTypeOverride;
03585     bool Enabled;
03586     
03587   public:
03588     /// \brief Introduce a new scope where 'this' may be allowed (when enabled),
03589     /// using the given declaration (which is either a class template or a 
03590     /// class) along with the given qualifiers.
03591     /// along with the qualifiers placed on '*this'.
03592     CXXThisScopeRAII(Sema &S, Decl *ContextDecl, unsigned CXXThisTypeQuals, 
03593                      bool Enabled = true);
03594     
03595     ~CXXThisScopeRAII();
03596   };
03597   
03598   /// \brief Make sure the value of 'this' is actually available in the current
03599   /// context, if it is a potentially evaluated context.
03600   ///
03601   /// \param Loc The location at which the capture of 'this' occurs.
03602   ///
03603   /// \param Explicit Whether 'this' is explicitly captured in a lambda
03604   /// capture list.
03605   void CheckCXXThisCapture(SourceLocation Loc, bool Explicit = false);
03606 
03607   /// \brief Determine whether the given type is the type of *this that is used
03608   /// outside of the body of a member function for a type that is currently 
03609   /// being defined.
03610   bool isThisOutsideMemberFunctionBody(QualType BaseType);
03611   
03612   /// ActOnCXXBoolLiteral - Parse {true,false} literals.
03613   ExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind);
03614   
03615   
03616   /// ActOnObjCBoolLiteral - Parse {__objc_yes,__objc_no} literals.
03617   ExprResult ActOnObjCBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind);
03618 
03619   /// ActOnCXXNullPtrLiteral - Parse 'nullptr'.
03620   ExprResult ActOnCXXNullPtrLiteral(SourceLocation Loc);
03621 
03622   //// ActOnCXXThrow -  Parse throw expressions.
03623   ExprResult ActOnCXXThrow(Scope *S, SourceLocation OpLoc, Expr *expr);
03624   ExprResult BuildCXXThrow(SourceLocation OpLoc, Expr *Ex,
03625                            bool IsThrownVarInScope);
03626   ExprResult CheckCXXThrowOperand(SourceLocation ThrowLoc, Expr *E,
03627                                   bool IsThrownVarInScope);
03628 
03629   /// ActOnCXXTypeConstructExpr - Parse construction of a specified type.
03630   /// Can be interpreted either as function-style casting ("int(x)")
03631   /// or class type construction ("ClassType(x,y,z)")
03632   /// or creation of a value-initialized type ("int()").
03633   ExprResult ActOnCXXTypeConstructExpr(ParsedType TypeRep,
03634                                        SourceLocation LParenLoc,
03635                                        MultiExprArg Exprs,
03636                                        SourceLocation RParenLoc);
03637 
03638   ExprResult BuildCXXTypeConstructExpr(TypeSourceInfo *Type,
03639                                        SourceLocation LParenLoc,
03640                                        MultiExprArg Exprs,
03641                                        SourceLocation RParenLoc);
03642 
03643   /// ActOnCXXNew - Parsed a C++ 'new' expression.
03644   ExprResult ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal,
03645                          SourceLocation PlacementLParen,
03646                          MultiExprArg PlacementArgs,
03647                          SourceLocation PlacementRParen,
03648                          SourceRange TypeIdParens, Declarator &D,
03649                          Expr *Initializer);
03650   ExprResult BuildCXXNew(SourceLocation StartLoc, bool UseGlobal,
03651                          SourceLocation PlacementLParen,
03652                          MultiExprArg PlacementArgs,
03653                          SourceLocation PlacementRParen,
03654                          SourceRange TypeIdParens,
03655                          QualType AllocType,
03656                          TypeSourceInfo *AllocTypeInfo,
03657                          Expr *ArraySize,
03658                          SourceRange DirectInitRange,
03659                          Expr *Initializer,
03660                          bool TypeMayContainAuto = true);
03661 
03662   bool CheckAllocatedType(QualType AllocType, SourceLocation Loc,
03663                           SourceRange R);
03664   bool FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range,
03665                                bool UseGlobal, QualType AllocType, bool IsArray,
03666                                Expr **PlaceArgs, unsigned NumPlaceArgs,
03667                                FunctionDecl *&OperatorNew,
03668                                FunctionDecl *&OperatorDelete);
03669   bool FindAllocationOverload(SourceLocation StartLoc, SourceRange Range,
03670                               DeclarationName Name, Expr** Args,
03671                               unsigned NumArgs, DeclContext *Ctx,
03672                               bool AllowMissing, FunctionDecl *&Operator,
03673                               bool Diagnose = true);
03674   void DeclareGlobalNewDelete();
03675   void DeclareGlobalAllocationFunction(DeclarationName Name, QualType Return,
03676                                        QualType Argument,
03677                                        bool addMallocAttr = false);
03678 
03679   bool FindDeallocationFunction(SourceLocation StartLoc, CXXRecordDecl *RD,
03680                                 DeclarationName Name, FunctionDecl* &Operator,
03681                                 bool Diagnose = true);
03682 
03683   /// ActOnCXXDelete - Parsed a C++ 'delete' expression
03684   ExprResult ActOnCXXDelete(SourceLocation StartLoc,
03685                             bool UseGlobal, bool ArrayForm,
03686                             Expr *Operand);
03687 
03688   DeclResult ActOnCXXConditionDeclaration(Scope *S, Declarator &D);
03689   ExprResult CheckConditionVariable(VarDecl *ConditionVar,
03690                                     SourceLocation StmtLoc,
03691                                     bool ConvertToBoolean);
03692 
03693   ExprResult ActOnNoexceptExpr(SourceLocation KeyLoc, SourceLocation LParen,
03694                                Expr *Operand, SourceLocation RParen);
03695   ExprResult BuildCXXNoexceptExpr(SourceLocation KeyLoc, Expr *Operand,
03696                                   SourceLocation RParen);
03697 
03698   /// ActOnUnaryTypeTrait - Parsed one of the unary type trait support
03699   /// pseudo-functions.
03700   ExprResult ActOnUnaryTypeTrait(UnaryTypeTrait OTT,
03701                                  SourceLocation KWLoc,
03702                                  ParsedType Ty,
03703                                  SourceLocation RParen);
03704 
03705   ExprResult BuildUnaryTypeTrait(UnaryTypeTrait OTT,
03706                                  SourceLocation KWLoc,
03707                                  TypeSourceInfo *T,
03708                                  SourceLocation RParen);
03709 
03710   /// ActOnBinaryTypeTrait - Parsed one of the bianry type trait support
03711   /// pseudo-functions.
03712   ExprResult ActOnBinaryTypeTrait(BinaryTypeTrait OTT,
03713                                   SourceLocation KWLoc,
03714                                   ParsedType LhsTy,
03715                                   ParsedType RhsTy,
03716                                   SourceLocation RParen);
03717 
03718   ExprResult BuildBinaryTypeTrait(BinaryTypeTrait BTT,
03719                                   SourceLocation KWLoc,
03720                                   TypeSourceInfo *LhsT,
03721                                   TypeSourceInfo *RhsT,
03722                                   SourceLocation RParen);
03723 
03724   /// \brief Parsed one of the type trait support pseudo-functions.
03725   ExprResult ActOnTypeTrait(TypeTrait Kind, SourceLocation KWLoc,
03726                             ArrayRef<ParsedType> Args,
03727                             SourceLocation RParenLoc);
03728   ExprResult BuildTypeTrait(TypeTrait Kind, SourceLocation KWLoc,
03729                             ArrayRef<TypeSourceInfo *> Args,
03730                             SourceLocation RParenLoc);
03731   
03732   /// ActOnArrayTypeTrait - Parsed one of the bianry type trait support
03733   /// pseudo-functions.
03734   ExprResult ActOnArrayTypeTrait(ArrayTypeTrait ATT,
03735                                  SourceLocation KWLoc,
03736                                  ParsedType LhsTy,
03737                                  Expr *DimExpr,
03738                                  SourceLocation RParen);
03739 
03740   ExprResult BuildArrayTypeTrait(ArrayTypeTrait ATT,
03741                                  SourceLocation KWLoc,
03742                                  TypeSourceInfo *TSInfo,
03743                                  Expr *DimExpr,
03744                                  SourceLocation RParen);
03745 
03746   /// ActOnExpressionTrait - Parsed one of the unary type trait support
03747   /// pseudo-functions.
03748   ExprResult ActOnExpressionTrait(ExpressionTrait OET,
03749                                   SourceLocation KWLoc,
03750                                   Expr *Queried,
03751                                   SourceLocation RParen);
03752 
03753   ExprResult BuildExpressionTrait(ExpressionTrait OET,
03754                                   SourceLocation KWLoc,
03755                                   Expr *Queried,
03756                                   SourceLocation RParen);
03757 
03758   ExprResult ActOnStartCXXMemberReference(Scope *S,
03759                                           Expr *Base,
03760                                           SourceLocation OpLoc,
03761                                           tok::TokenKind OpKind,
03762                                           ParsedType &ObjectType,
03763                                           bool &MayBePseudoDestructor);
03764 
03765   ExprResult DiagnoseDtorReference(SourceLocation NameLoc, Expr *MemExpr);
03766 
03767   ExprResult BuildPseudoDestructorExpr(Expr *Base,
03768                                        SourceLocation OpLoc,
03769                                        tok::TokenKind OpKind,
03770                                        const CXXScopeSpec &SS,
03771                                        TypeSourceInfo *ScopeType,
03772                                        SourceLocation CCLoc,
03773                                        SourceLocation TildeLoc,
03774                                      PseudoDestructorTypeStorage DestroyedType,
03775                                        bool HasTrailingLParen);
03776 
03777   ExprResult ActOnPseudoDestructorExpr(Scope *S, Expr *Base,
03778                                        SourceLocation OpLoc,
03779                                        tok::TokenKind OpKind,
03780                                        CXXScopeSpec &SS,
03781                                        UnqualifiedId &FirstTypeName,
03782                                        SourceLocation CCLoc,
03783                                        SourceLocation TildeLoc,
03784                                        UnqualifiedId &SecondTypeName,
03785                                        bool HasTrailingLParen);
03786 
03787   ExprResult ActOnPseudoDestructorExpr(Scope *S, Expr *Base,
03788                                        SourceLocation OpLoc,
03789                                        tok::TokenKind OpKind,
03790                                        SourceLocation TildeLoc, 
03791                                        const DeclSpec& DS,
03792                                        bool HasTrailingLParen);
03793 
03794   /// MaybeCreateExprWithCleanups - If the current full-expression
03795   /// requires any cleanups, surround it with a ExprWithCleanups node.
03796   /// Otherwise, just returns the passed-in expression.
03797   Expr *MaybeCreateExprWithCleanups(Expr *SubExpr);
03798   Stmt *MaybeCreateStmtWithCleanups(Stmt *SubStmt);
03799   ExprResult MaybeCreateExprWithCleanups(ExprResult SubExpr);
03800 
03801   ExprResult ActOnFinishFullExpr(Expr *Expr) {
03802     return ActOnFinishFullExpr(Expr, Expr ? Expr->getExprLoc()
03803                                           : SourceLocation());
03804   }
03805   ExprResult ActOnFinishFullExpr(Expr *Expr, SourceLocation CC);
03806   StmtResult ActOnFinishFullStmt(Stmt *Stmt);
03807 
03808   // Marks SS invalid if it represents an incomplete type.
03809   bool RequireCompleteDeclContext(CXXScopeSpec &SS, DeclContext *DC);
03810 
03811   DeclContext *computeDeclContext(QualType T);
03812   DeclContext *computeDeclContext(const CXXScopeSpec &SS,
03813                                   bool EnteringContext = false);
03814   bool isDependentScopeSpecifier(const CXXScopeSpec &SS);
03815   CXXRecordDecl *getCurrentInstantiationOf(NestedNameSpecifier *NNS);
03816   bool isUnknownSpecialization(const CXXScopeSpec &SS);
03817 
03818   /// \brief The parser has parsed a global nested-name-specifier '::'.
03819   ///
03820   /// \param S The scope in which this nested-name-specifier occurs.
03821   ///
03822   /// \param CCLoc The location of the '::'.
03823   ///
03824   /// \param SS The nested-name-specifier, which will be updated in-place
03825   /// to reflect the parsed nested-name-specifier.
03826   ///
03827   /// \returns true if an error occurred, false otherwise.
03828   bool ActOnCXXGlobalScopeSpecifier(Scope *S, SourceLocation CCLoc,
03829                                     CXXScopeSpec &SS);
03830 
03831   bool isAcceptableNestedNameSpecifier(NamedDecl *SD);
03832   NamedDecl *FindFirstQualifierInScope(Scope *S, NestedNameSpecifier *NNS);
03833 
03834   bool isNonTypeNestedNameSpecifier(Scope *S, CXXScopeSpec &SS,
03835                                     SourceLocation IdLoc,
03836                                     IdentifierInfo &II,
03837                                     ParsedType ObjectType);
03838 
03839   bool BuildCXXNestedNameSpecifier(Scope *S,
03840                                    IdentifierInfo &Identifier,
03841                                    SourceLocation IdentifierLoc,
03842                                    SourceLocation CCLoc,
03843                                    QualType ObjectType,
03844                                    bool EnteringContext,
03845                                    CXXScopeSpec &SS,
03846                                    NamedDecl *ScopeLookupResult,
03847                                    bool ErrorRecoveryLookup);
03848 
03849   /// \brief The parser has parsed a nested-name-specifier 'identifier::'.
03850   ///
03851   /// \param S The scope in which this nested-name-specifier occurs.
03852   ///
03853   /// \param Identifier The identifier preceding the '::'.
03854   ///
03855   /// \param IdentifierLoc The location of the identifier.
03856   ///
03857   /// \param CCLoc The location of the '::'.
03858   ///
03859   /// \param ObjectType The type of the object, if we're parsing
03860   /// nested-name-specifier in a member access expression.
03861   ///
03862   /// \param EnteringContext Whether we're entering the context nominated by
03863   /// this nested-name-specifier.
03864   ///
03865   /// \param SS The nested-name-specifier, which is both an input
03866   /// parameter (the nested-name-specifier before this type) and an
03867   /// output parameter (containing the full nested-name-specifier,
03868   /// including this new type).
03869   ///
03870   /// \returns true if an error occurred, false otherwise.
03871   bool ActOnCXXNestedNameSpecifier(Scope *S,
03872                                    IdentifierInfo &Identifier,
03873                                    SourceLocation IdentifierLoc,
03874                                    SourceLocation CCLoc,
03875                                    ParsedType ObjectType,
03876                                    bool EnteringContext,
03877                                    CXXScopeSpec &SS);
03878 
03879   ExprResult ActOnDecltypeExpression(Expr *E);
03880 
03881   bool ActOnCXXNestedNameSpecifierDecltype(CXXScopeSpec &SS,
03882                                            const DeclSpec &DS, 
03883                                            SourceLocation ColonColonLoc);
03884 
03885   bool IsInvalidUnlessNestedName(Scope *S, CXXScopeSpec &SS,
03886                                  IdentifierInfo &Identifier,
03887                                  SourceLocation IdentifierLoc,
03888                                  SourceLocation ColonLoc,
03889                                  ParsedType ObjectType,
03890                                  bool EnteringContext);
03891 
03892   /// \brief The parser has parsed a nested-name-specifier
03893   /// 'template[opt] template-name < template-args >::'.
03894   ///
03895   /// \param S The scope in which this nested-name-specifier occurs.
03896   ///
03897   /// \param SS The nested-name-specifier, which is both an input
03898   /// parameter (the nested-name-specifier before this type) and an
03899   /// output parameter (containing the full nested-name-specifier,
03900   /// including this new type).
03901   ///
03902   /// \param TemplateKWLoc the location of the 'template' keyword, if any.
03903   /// \param TemplateName The template name.
03904   /// \param TemplateNameLoc The location of the template name.
03905   /// \param LAngleLoc The location of the opening angle bracket  ('<').
03906   /// \param TemplateArgs The template arguments.
03907   /// \param RAngleLoc The location of the closing angle bracket  ('>').
03908   /// \param CCLoc The location of the '::'.
03909   ///
03910   /// \param EnteringContext Whether we're entering the context of the
03911   /// nested-name-specifier.
03912   ///
03913   ///
03914   /// \returns true if an error occurred, false otherwise.
03915   bool ActOnCXXNestedNameSpecifier(Scope *S,
03916                                    CXXScopeSpec &SS,
03917                                    SourceLocation TemplateKWLoc,
03918                                    TemplateTy Template,
03919                                    SourceLocation TemplateNameLoc,
03920                                    SourceLocation LAngleLoc,
03921                                    ASTTemplateArgsPtr TemplateArgs,
03922                                    SourceLocation RAngleLoc,
03923                                    SourceLocation CCLoc,
03924                                    bool EnteringContext);
03925 
03926   /// \brief Given a C++ nested-name-specifier, produce an annotation value
03927   /// that the parser can use later to reconstruct the given
03928   /// nested-name-specifier.
03929   ///
03930   /// \param SS A nested-name-specifier.
03931   ///
03932   /// \returns A pointer containing all of the information in the
03933   /// nested-name-specifier \p SS.
03934   void *SaveNestedNameSpecifierAnnotation(CXXScopeSpec &SS);
03935 
03936   /// \brief Given an annotation pointer for a nested-name-specifier, restore
03937   /// the nested-name-specifier structure.
03938   ///
03939   /// \param Annotation The annotation pointer, produced by
03940   /// \c SaveNestedNameSpecifierAnnotation().
03941   ///
03942   /// \param AnnotationRange The source range corresponding to the annotation.
03943   ///
03944   /// \param SS The nested-name-specifier that will be updated with the contents
03945   /// of the annotation pointer.
03946   void RestoreNestedNameSpecifierAnnotation(void *Annotation,
03947                                             SourceRange AnnotationRange,
03948                                             CXXScopeSpec &SS);
03949 
03950   bool ShouldEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS);
03951 
03952   /// ActOnCXXEnterDeclaratorScope - Called when a C++ scope specifier (global
03953   /// scope or nested-name-specifier) is parsed, part of a declarator-id.
03954   /// After this method is called, according to [C++ 3.4.3p3], names should be
03955   /// looked up in the declarator-id's scope, until the declarator is parsed and
03956   /// ActOnCXXExitDeclaratorScope is called.
03957   /// The 'SS' should be a non-empty valid CXXScopeSpec.
03958   bool ActOnCXXEnterDeclaratorScope(Scope *S, CXXScopeSpec &SS);
03959 
03960   /// ActOnCXXExitDeclaratorScope - Called when a declarator that previously
03961   /// invoked ActOnCXXEnterDeclaratorScope(), is finished. 'SS' is the same
03962   /// CXXScopeSpec that was passed to ActOnCXXEnterDeclaratorScope as well.
03963   /// Used to indicate that names should revert to being looked up in the
03964   /// defining scope.
03965   void ActOnCXXExitDeclaratorScope(Scope *S, const CXXScopeSpec &SS);
03966 
03967   /// ActOnCXXEnterDeclInitializer - Invoked when we are about to parse an
03968   /// initializer for the declaration 'Dcl'.
03969   /// After this method is called, according to [C++ 3.4.1p13], if 'Dcl' is a
03970   /// static data member of class X, names should be looked up in the scope of
03971   /// class X.
03972   void ActOnCXXEnterDeclInitializer(Scope *S, Decl *Dcl);
03973 
03974   /// ActOnCXXExitDeclInitializer - Invoked after we are finished parsing an
03975   /// initializer for the declaration 'Dcl'.
03976   void ActOnCXXExitDeclInitializer(Scope *S, Decl *Dcl);
03977 
03978   /// \brief Create a new lambda closure type.
03979   CXXRecordDecl *createLambdaClosureType(SourceRange IntroducerRange,
03980                                          bool KnownDependent = false);
03981   
03982   /// \brief Start the definition of a lambda expression.
03983   CXXMethodDecl *startLambdaDefinition(CXXRecordDecl *Class,
03984                                        SourceRange IntroducerRange,
03985                                        TypeSourceInfo *MethodType,
03986                                        SourceLocation EndLoc,
03987                                        llvm::ArrayRef<ParmVarDecl *> Params,
03988                                        llvm::Optional<unsigned> ManglingNumber 
03989                                          = llvm::Optional<unsigned>(),
03990                                        Decl *ContextDecl = 0);
03991   
03992   /// \brief Introduce the scope for a lambda expression.
03993   sema::LambdaScopeInfo *enterLambdaScope(CXXMethodDecl *CallOperator,
03994                                           SourceRange IntroducerRange,
03995                                           LambdaCaptureDefault CaptureDefault,
03996                                           bool ExplicitParams,
03997                                           bool ExplicitResultType,
03998                                           bool Mutable);
03999   
04000   /// \brief Note that we have finished the explicit captures for the
04001   /// given lambda.
04002   void finishLambdaExplicitCaptures(sema::LambdaScopeInfo *LSI);
04003   
04004   /// \brief Introduce the lambda parameters into scope.
04005   void addLambdaParameters(CXXMethodDecl *CallOperator, Scope *CurScope);
04006   
04007   /// ActOnStartOfLambdaDefinition - This is called just before we start
04008   /// parsing the body of a lambda; it analyzes the explicit captures and 
04009   /// arguments, and sets up various data-structures for the body of the
04010   /// lambda.
04011   void ActOnStartOfLambdaDefinition(LambdaIntroducer &Intro,
04012                                     Declarator &ParamInfo, Scope *CurScope);
04013 
04014   /// ActOnLambdaError - If there is an error parsing a lambda, this callback
04015   /// is invoked to pop the information about the lambda.
04016   void ActOnLambdaError(SourceLocation StartLoc, Scope *CurScope,
04017                         bool IsInstantiation = false);
04018 
04019   /// ActOnLambdaExpr - This is called when the body of a lambda expression
04020   /// was successfully completed.
04021   ExprResult ActOnLambdaExpr(SourceLocation StartLoc, Stmt *Body,
04022                              Scope *CurScope, 
04023                              bool IsInstantiation = false);
04024 
04025   /// \brief Define the "body" of the conversion from a lambda object to a 
04026   /// function pointer.
04027   ///
04028   /// This routine doesn't actually define a sensible body; rather, it fills
04029   /// in the initialization expression needed to copy the lambda object into
04030   /// the block, and IR generation actually generates the real body of the
04031   /// block pointer conversion.
04032   void DefineImplicitLambdaToFunctionPointerConversion(
04033          SourceLocation CurrentLoc, CXXConversionDecl *Conv);
04034 
04035   /// \brief Define the "body" of the conversion from a lambda object to a 
04036   /// block pointer.
04037   ///
04038   /// This routine doesn't actually define a sensible body; rather, it fills
04039   /// in the initialization expression needed to copy the lambda object into
04040   /// the block, and IR generation actually generates the real body of the
04041   /// block pointer conversion.
04042   void DefineImplicitLambdaToBlockPointerConversion(SourceLocation CurrentLoc,
04043                                                     CXXConversionDecl *Conv);
04044 
04045   ExprResult BuildBlockForLambdaConversion(SourceLocation CurrentLocation,
04046                                            SourceLocation ConvLocation,
04047                                            CXXConversionDecl *Conv,
04048                                            Expr *Src);
04049 
04050   // ParseObjCStringLiteral - Parse Objective-C string literals.
04051   ExprResult ParseObjCStringLiteral(SourceLocation *AtLocs,
04052                                     Expr **Strings,
04053                                     unsigned NumStrings);
04054     
04055   ExprResult BuildObjCStringLiteral(SourceLocation AtLoc, StringLiteral *S);
04056   
04057   /// BuildObjCNumericLiteral - builds an ObjCBoxedExpr AST node for the
04058   /// numeric literal expression. Type of the expression will be "NSNumber *"
04059   /// or "id" if NSNumber is unavailable.
04060   ExprResult BuildObjCNumericLiteral(SourceLocation AtLoc, Expr *Number);
04061   ExprResult ActOnObjCBoolLiteral(SourceLocation AtLoc, SourceLocation ValueLoc,
04062                                   bool Value);
04063   ExprResult BuildObjCArrayLiteral(SourceRange SR, MultiExprArg Elements);
04064   
04065   // BuildObjCBoxedExpr - builds an ObjCBoxedExpr AST node for the
04066   // '@' prefixed parenthesized expression. The type of the expression will
04067   // either be "NSNumber *" or "NSString *" depending on the type of
04068   // ValueType, which is allowed to be a built-in numeric type or
04069   // "char *" or "const char *".
04070   ExprResult BuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr);
04071   
04072   ExprResult BuildObjCSubscriptExpression(SourceLocation RB, Expr *BaseExpr,
04073                                           Expr *IndexExpr,
04074                                           ObjCMethodDecl *getterMethod,
04075                                           ObjCMethodDecl *setterMethod);
04076     
04077   ExprResult BuildObjCDictionaryLiteral(SourceRange SR,                                         
04078                                         ObjCDictionaryElement *Elements,
04079                                         unsigned NumElements);
04080  
04081   ExprResult BuildObjCEncodeExpression(SourceLocation AtLoc,
04082                                   TypeSourceInfo *EncodedTypeInfo,
04083                                   SourceLocation RParenLoc);
04084   ExprResult BuildCXXMemberCallExpr(Expr *Exp, NamedDecl *FoundDecl,
04085                                     CXXConversionDecl *Method,
04086                                     bool HadMultipleCandidates);
04087 
04088   ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc,
04089                                        SourceLocation EncodeLoc,
04090                                        SourceLocation LParenLoc,
04091                                        ParsedType Ty,
04092                                        SourceLocation RParenLoc);
04093 
04094   // ParseObjCSelectorExpression - Build selector expression for @selector
04095   ExprResult ParseObjCSelectorExpression(Selector Sel,
04096                                          SourceLocation AtLoc,
04097                                          SourceLocation SelLoc,
04098                                          SourceLocation LParenLoc,
04099                                          SourceLocation RParenLoc);
04100 
04101   // ParseObjCProtocolExpression - Build protocol expression for @protocol
04102   ExprResult ParseObjCProtocolExpression(IdentifierInfo * ProtocolName,
04103                                          SourceLocation AtLoc,
04104                                          SourceLocation ProtoLoc,
04105                                          SourceLocation LParenLoc,
04106                                          SourceLocation ProtoIdLoc,
04107                                          SourceLocation RParenLoc);
04108 
04109   //===--------------------------------------------------------------------===//
04110   // C++ Declarations
04111   //
04112   Decl *ActOnStartLinkageSpecification(Scope *S,
04113                                        SourceLocation ExternLoc,
04114                                        SourceLocation LangLoc,
04115                                        StringRef Lang,
04116                                        SourceLocation LBraceLoc);
04117   Decl *ActOnFinishLinkageSpecification(Scope *S,
04118                                         Decl *LinkageSpec,
04119                                         SourceLocation RBraceLoc);
04120 
04121 
04122   //===--------------------------------------------------------------------===//
04123   // C++ Classes
04124   //
04125   bool isCurrentClassName(const IdentifierInfo &II, Scope *S,
04126                           const CXXScopeSpec *SS = 0);
04127 
04128   bool ActOnAccessSpecifier(AccessSpecifier Access,
04129                             SourceLocation ASLoc,
04130                             SourceLocation ColonLoc,
04131                             AttributeList *Attrs = 0);
04132 
04133   Decl *ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS,
04134                                  Declarator &D,
04135                                  MultiTemplateParamsArg TemplateParameterLists,
04136                                  Expr *BitfieldWidth, const VirtSpecifiers &VS,
04137                                  bool HasDeferredInit);
04138   void ActOnCXXInClassMemberInitializer(Decl *VarDecl, SourceLocation EqualLoc,
04139                                         Expr *Init);
04140 
04141   MemInitResult ActOnMemInitializer(Decl *ConstructorD,
04142                                     Scope *S,
04143                                     CXXScopeSpec &SS,
04144                                     IdentifierInfo *MemberOrBase,
04145                                     ParsedType TemplateTypeTy,
04146                                     const DeclSpec &DS,
04147                                     SourceLocation IdLoc,
04148                                     SourceLocation LParenLoc,
04149                                     Expr **Args, unsigned NumArgs,
04150                                     SourceLocation RParenLoc,
04151                                     SourceLocation EllipsisLoc);
04152 
04153   MemInitResult ActOnMemInitializer(Decl *ConstructorD,
04154                                     Scope *S,
04155                                     CXXScopeSpec &SS,
04156                                     IdentifierInfo *MemberOrBase,
04157                                     ParsedType TemplateTypeTy,
04158                                     const DeclSpec &DS,
04159                                     SourceLocation IdLoc,
04160                                     Expr *InitList,
04161                                     SourceLocation EllipsisLoc);
04162 
04163   MemInitResult BuildMemInitializer(Decl *ConstructorD,
04164                                     Scope *S,
04165                                     CXXScopeSpec &SS,
04166                                     IdentifierInfo *MemberOrBase,
04167                                     ParsedType TemplateTypeTy,
04168                                     const DeclSpec &DS,
04169                                     SourceLocation IdLoc,
04170                                     Expr *Init,
04171                                     SourceLocation EllipsisLoc);
04172 
04173   MemInitResult BuildMemberInitializer(ValueDecl *Member,
04174                                        Expr *Init,
04175                                        SourceLocation IdLoc);
04176 
04177   MemInitResult BuildBaseInitializer(QualType BaseType,
04178                                      TypeSourceInfo *BaseTInfo,
04179                                      Expr *Init,
04180                                      CXXRecordDecl *ClassDecl,
04181                                      SourceLocation EllipsisLoc);
04182 
04183   MemInitResult BuildDelegatingInitializer(TypeSourceInfo *TInfo,
04184                                            Expr *Init,
04185                                            CXXRecordDecl *ClassDecl);
04186 
04187   bool SetDelegatingInitializer(CXXConstructorDecl *Constructor,
04188                                 CXXCtorInitializer *Initializer);
04189 
04190   bool SetCtorInitializers(CXXConstructorDecl *Constructor,
04191                            CXXCtorInitializer **Initializers,
04192                            unsigned NumInitializers, bool AnyErrors);
04193 
04194   void SetIvarInitializers(ObjCImplementationDecl *ObjCImplementation);
04195 
04196 
04197   /// MarkBaseAndMemberDestructorsReferenced - Given a record decl,
04198   /// mark all the non-trivial destructors of its members and bases as
04199   /// referenced.
04200   void MarkBaseAndMemberDestructorsReferenced(SourceLocation Loc,
04201                                               CXXRecordDecl *Record);
04202 
04203   /// \brief The list of classes whose vtables have been used within
04204   /// this translation unit, and the source locations at which the
04205   /// first use occurred.
04206   typedef std::pair<CXXRecordDecl*, SourceLocation> VTableUse;
04207 
04208   /// \brief The list of vtables that are required but have not yet been
04209   /// materialized.
04210   SmallVector<VTableUse, 16> VTableUses;
04211 
04212   /// \brief The set of classes whose vtables have been used within
04213   /// this translation unit, and a bit that will be true if the vtable is
04214   /// required to be emitted (otherwise, it should be emitted only if needed
04215   /// by code generation).
04216   llvm::DenseMap<CXXRecordDecl *, bool> VTablesUsed;
04217 
04218   /// \brief Load any externally-stored vtable uses.
04219   void LoadExternalVTableUses();
04220 
04221   typedef LazyVector<CXXRecordDecl *, ExternalSemaSource,
04222                      &ExternalSemaSource::ReadDynamicClasses, 2, 2>
04223     DynamicClassesType;
04224 
04225   /// \brief A list of all of the dynamic classes in this translation
04226   /// unit.
04227   DynamicClassesType DynamicClasses;
04228 
04229   /// \brief Note that the vtable for the given class was used at the
04230   /// given location.
04231   void MarkVTableUsed(SourceLocation Loc, CXXRecordDecl *Class,
04232                       bool DefinitionRequired = false);
04233 
04234   /// MarkVirtualMembersReferenced - Will mark all members of the given
04235   /// CXXRecordDecl referenced.
04236   void MarkVirtualMembersReferenced(SourceLocation Loc,
04237                                     const CXXRecordDecl *RD);
04238 
04239   /// \brief Define all of the vtables that have been used in this
04240   /// translation unit and reference any virtual members used by those
04241   /// vtables.
04242   ///
04243   /// \returns true if any work was done, false otherwise.
04244   bool DefineUsedVTables();
04245 
04246   void AddImplicitlyDeclaredMembersToClass(CXXRecordDecl *ClassDecl);
04247 
04248   void ActOnMemInitializers(Decl *ConstructorDecl,
04249                             SourceLocation ColonLoc,
04250                             CXXCtorInitializer **MemInits,
04251                             unsigned NumMemInits,
04252                             bool AnyErrors);
04253 
04254   void CheckCompletedCXXClass(CXXRecordDecl *Record);
04255   void ActOnFinishCXXMemberSpecification(Scope* S, SourceLocation RLoc,
04256                                          Decl *TagDecl,
04257                                          SourceLocation LBrac,
04258                                          SourceLocation RBrac,
04259                                          AttributeList *AttrList);
04260   void ActOnFinishCXXMemberDecls();
04261 
04262   void ActOnReenterTemplateScope(Scope *S, Decl *Template);
04263   void ActOnReenterDeclaratorTemplateScope(Scope *S, DeclaratorDecl *D);
04264   void ActOnStartDelayedMemberDeclarations(Scope *S, Decl *Record);
04265   void ActOnStartDelayedCXXMethodDeclaration(Scope *S, Decl *Method);
04266   void ActOnDelayedCXXMethodParameter(Scope *S, Decl *Param);
04267   void ActOnFinishDelayedMemberDeclarations(Scope *S, Decl *Record);
04268   void ActOnFinishDelayedCXXMethodDeclaration(Scope *S, Decl *Method);
04269   void ActOnFinishDelayedMemberInitializers(Decl *Record);
04270   void MarkAsLateParsedTemplate(FunctionDecl *FD, bool Flag = true);
04271   bool IsInsideALocalClassWithinATemplateFunction();
04272 
04273   Decl *ActOnStaticAssertDeclaration(SourceLocation StaticAssertLoc,
04274                                      Expr *AssertExpr,
04275                                      Expr *AssertMessageExpr,
04276                                      SourceLocation RParenLoc);
04277 
04278   FriendDecl *CheckFriendTypeDecl(SourceLocation Loc,
04279                                   SourceLocation FriendLoc,
04280                                   TypeSourceInfo *TSInfo);
04281   Decl *ActOnFriendTypeDecl(Scope *S, const DeclSpec &DS,
04282                             MultiTemplateParamsArg TemplateParams);
04283   Decl *ActOnFriendFunctionDecl(Scope *S, Declarator &D,
04284                                 MultiTemplateParamsArg TemplateParams);
04285 
04286   QualType CheckConstructorDeclarator(Declarator &D, QualType R,
04287                                       StorageClass& SC);
04288   void CheckConstructor(CXXConstructorDecl *Constructor);
04289   QualType CheckDestructorDeclarator(Declarator &D, QualType R,
04290                                      StorageClass& SC);
04291   bool CheckDestructor(CXXDestructorDecl *Destructor);
04292   void CheckConversionDeclarator(Declarator &D, QualType &R,
04293                                  StorageClass& SC);
04294   Decl *ActOnConversionDeclarator(CXXConversionDecl *Conversion);
04295 
04296   void CheckExplicitlyDefaultedMethods(CXXRecordDecl *Record);
04297   void CheckExplicitlyDefaultedSpecialMember(CXXMethodDecl *MD);
04298 
04299   //===--------------------------------------------------------------------===//
04300   // C++ Derived Classes
04301   //
04302 
04303   /// ActOnBaseSpecifier - Parsed a base specifier
04304   CXXBaseSpecifier *CheckBaseSpecifier(CXXRecordDecl *Class,
04305                                        SourceRange SpecifierRange,
04306                                        bool Virtual, AccessSpecifier Access,
04307                                        TypeSourceInfo *TInfo,
04308                                        SourceLocation EllipsisLoc);
04309 
04310   BaseResult ActOnBaseSpecifier(Decl *classdecl,
04311                                 SourceRange SpecifierRange,
04312                                 bool Virtual, AccessSpecifier Access,
04313                                 ParsedType basetype,
04314                                 SourceLocation BaseLoc,
04315                                 SourceLocation EllipsisLoc);
04316 
04317   bool AttachBaseSpecifiers(CXXRecordDecl *Class, CXXBaseSpecifier **Bases,
04318                             unsigned NumBases);
04319   void ActOnBaseSpecifiers(Decl *ClassDecl, CXXBaseSpecifier **Bases,
04320                            unsigned NumBases);
04321 
04322   bool IsDerivedFrom(QualType Derived, QualType Base);
04323   bool IsDerivedFrom(QualType Derived, QualType Base, CXXBasePaths &Paths);
04324 
04325   // FIXME: I don't like this name.
04326   void BuildBasePathArray(const CXXBasePaths &Paths, CXXCastPath &BasePath);
04327 
04328   bool BasePathInvolvesVirtualBase(const CXXCastPath &BasePath);
04329 
04330   bool CheckDerivedToBaseConversion(QualType Derived, QualType Base,
04331                                     SourceLocation Loc, SourceRange Range,
04332                                     CXXCastPath *BasePath = 0,
04333                                     bool IgnoreAccess = false);
04334   bool CheckDerivedToBaseConversion(QualType Derived, QualType Base,
04335                                     unsigned InaccessibleBaseID,
04336                                     unsigned AmbigiousBaseConvID,
04337                                     SourceLocation Loc, SourceRange Range,
04338                                     DeclarationName Name,
04339                                     CXXCastPath *BasePath);
04340 
04341   std::string getAmbiguousPathsDisplayString(CXXBasePaths &Paths);
04342 
04343   /// CheckOverridingFunctionReturnType - Checks whether the return types are
04344   /// covariant, according to C++ [class.virtual]p5.
04345   bool CheckOverridingFunctionReturnType(const CXXMethodDecl *New,
04346                                          const CXXMethodDecl *Old);
04347 
04348   /// CheckOverridingFunctionExceptionSpec - Checks whether the exception
04349   /// spec is a subset of base spec.
04350   bool CheckOverridingFunctionExceptionSpec(const CXXMethodDecl *New,
04351                                             const CXXMethodDecl *Old);
04352 
04353   bool CheckPureMethod(CXXMethodDecl *Method, SourceRange InitRange);
04354 
04355   /// CheckOverrideControl - Check C++0x override control semantics.
04356   void CheckOverrideControl(const Decl *D);
04357 
04358   /// CheckForFunctionMarkedFinal - Checks whether a virtual member function
04359   /// overrides a virtual member function marked 'final', according to
04360   /// C++0x [class.virtual]p3.
04361   bool CheckIfOverriddenFunctionIsMarkedFinal(const CXXMethodDecl *New,
04362                                               const CXXMethodDecl *Old);
04363 
04364 
04365   //===--------------------------------------------------------------------===//
04366   // C++ Access Control
04367   //
04368 
04369   enum AccessResult {
04370     AR_accessible,
04371     AR_inaccessible,
04372     AR_dependent,
04373     AR_delayed
04374   };
04375 
04376   bool SetMemberAccessSpecifier(NamedDecl *MemberDecl,
04377                                 NamedDecl *PrevMemberDecl,
04378                                 AccessSpecifier LexicalAS);
04379 
04380   AccessResult CheckUnresolvedMemberAccess(UnresolvedMemberExpr *E,
04381                                            DeclAccessPair FoundDecl);
04382   AccessResult CheckUnresolvedLookupAccess(UnresolvedLookupExpr *E,
04383                                            DeclAccessPair FoundDecl);
04384   AccessResult CheckAllocationAccess(SourceLocation OperatorLoc,
04385                                      SourceRange PlacementRange,
04386                                      CXXRecordDecl *NamingClass,
04387                                      DeclAccessPair FoundDecl,
04388                                      bool Diagnose = true);
04389   AccessResult CheckConstructorAccess(SourceLocation Loc,
04390                                       CXXConstructorDecl *D,
04391                                       const InitializedEntity &Entity,
04392                                       AccessSpecifier Access,
04393                                       bool IsCopyBindingRefToTemp = false);
04394   AccessResult CheckConstructorAccess(SourceLocation Loc,
04395                                       CXXConstructorDecl *D,
04396                                       const InitializedEntity &Entity,
04397                                       AccessSpecifier Access,
04398                                       const PartialDiagnostic &PDiag);
04399   AccessResult CheckDestructorAccess(SourceLocation Loc,
04400                                      CXXDestructorDecl *Dtor,
04401                                      const PartialDiagnostic &PDiag,
04402                                      QualType objectType = QualType());
04403   AccessResult CheckDirectMemberAccess(SourceLocation Loc,
04404                                        NamedDecl *D,
04405                                        const PartialDiagnostic &PDiag);
04406   AccessResult CheckMemberOperatorAccess(SourceLocation Loc,
04407                                          Expr *ObjectExpr,
04408                                          Expr *ArgExpr,
04409                                          DeclAccessPair FoundDecl);
04410   AccessResult CheckAddressOfMemberAccess(Expr *OvlExpr,
04411                                           DeclAccessPair FoundDecl);
04412   AccessResult CheckBaseClassAccess(SourceLocation AccessLoc,
04413                                     QualType Base, QualType Derived,
04414                                     const CXXBasePath &Path,
04415                                     unsigned DiagID,
04416                                     bool ForceCheck = false,
04417                                     bool ForceUnprivileged = false);
04418   void CheckLookupAccess(const LookupResult &R);
04419   bool IsSimplyAccessible(NamedDecl *decl, DeclContext *Ctx);
04420   bool isSpecialMemberAccessibleForDeletion(CXXMethodDecl *decl,
04421                                             AccessSpecifier access,
04422                                             QualType objectType);
04423 
04424   void HandleDependentAccessCheck(const DependentDiagnostic &DD,
04425                          const MultiLevelTemplateArgumentList &TemplateArgs);
04426   void PerformDependentDiagnostics(const DeclContext *Pattern,
04427                         const MultiLevelTemplateArgumentList &TemplateArgs);
04428 
04429   void HandleDelayedAccessCheck(sema::DelayedDiagnostic &DD, Decl *Ctx);
04430 
04431   /// \brief When true, access checking violations are treated as SFINAE
04432   /// failures rather than hard errors.
04433   bool AccessCheckingSFINAE;
04434 
04435   enum AbstractDiagSelID {
04436     AbstractNone = -1,
04437     AbstractReturnType,
04438     AbstractParamType,
04439     AbstractVariableType,
04440     AbstractFieldType,
04441     AbstractArrayType
04442   };
04443 
04444   bool RequireNonAbstractType(SourceLocation Loc, QualType T,
04445                               TypeDiagnoser &Diagnoser);
04446   template<typename T1>
04447   bool RequireNonAbstractType(SourceLocation Loc, QualType T,
04448                               unsigned DiagID,
04449                               const T1 &Arg1) {
04450     BoundTypeDiagnoser1<T1> Diagnoser(DiagID, Arg1);
04451     return RequireNonAbstractType(Loc, T, Diagnoser);
04452   }
04453 
04454   template<typename T1, typename T2>
04455   bool RequireNonAbstractType(SourceLocation Loc, QualType T,
04456                               unsigned DiagID,
04457                               const T1 &Arg1, const T2 &Arg2) {
04458     BoundTypeDiagnoser2<T1, T2> Diagnoser(DiagID, Arg1, Arg2);
04459     return RequireNonAbstractType(Loc, T, Diagnoser);
04460   }
04461 
04462   template<typename T1, typename T2, typename T3>
04463   bool RequireNonAbstractType(SourceLocation Loc, QualType T,
04464                               unsigned DiagID,
04465                               const T1 &Arg1, const T2 &Arg2, const T3 &Arg3) {
04466     BoundTypeDiagnoser3<T1, T2, T3> Diagnoser(DiagID, Arg1, Arg2, Arg3);
04467     return RequireNonAbstractType(Loc, T, Diagnoser);
04468   }
04469 
04470   void DiagnoseAbstractType(const CXXRecordDecl *RD);
04471 
04472   bool RequireNonAbstractType(SourceLocation Loc, QualType T, unsigned DiagID,
04473                               AbstractDiagSelID SelID = AbstractNone);
04474 
04475   //===--------------------------------------------------------------------===//
04476   // C++ Overloaded Operators [C++ 13.5]
04477   //
04478 
04479   bool CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl);
04480 
04481   bool CheckLiteralOperatorDeclaration(FunctionDecl *FnDecl);
04482 
04483   //===--------------------------------------------------------------------===//
04484   // C++ Templates [C++ 14]
04485   //
04486   void FilterAcceptableTemplateNames(LookupResult &R, 
04487                                      bool AllowFunctionTemplates = true);
04488   bool hasAnyAcceptableTemplateNames(LookupResult &R, 
04489                                      bool AllowFunctionTemplates = true);
04490 
04491   void LookupTemplateName(LookupResult &R, Scope *S, CXXScopeSpec &SS,
04492                           QualType ObjectType, bool EnteringContext,
04493                           bool &MemberOfUnknownSpecialization);
04494 
04495   TemplateNameKind isTemplateName(Scope *S,
04496                                   CXXScopeSpec &SS,
04497                                   bool hasTemplateKeyword,
04498                                   UnqualifiedId &Name,
04499                                   ParsedType ObjectType,
04500                                   bool EnteringContext,
04501                                   TemplateTy &Template,
04502                                   bool &MemberOfUnknownSpecialization);
04503 
04504   bool DiagnoseUnknownTemplateName(const IdentifierInfo &II,
04505                                    SourceLocation IILoc,
04506                                    Scope *S,
04507                                    const CXXScopeSpec *SS,
04508                                    TemplateTy &SuggestedTemplate,
04509                                    TemplateNameKind &SuggestedKind);
04510 
04511   void DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl);
04512   TemplateDecl *AdjustDeclIfTemplate(Decl *&Decl);
04513 
04514   Decl *ActOnTypeParameter(Scope *S, bool Typename, bool Ellipsis,
04515                            SourceLocation EllipsisLoc,
04516                            SourceLocation KeyLoc,
04517                            IdentifierInfo *ParamName,
04518                            SourceLocation ParamNameLoc,
04519                            unsigned Depth, unsigned Position,
04520                            SourceLocation EqualLoc,
04521                            ParsedType DefaultArg);
04522 
04523   QualType CheckNonTypeTemplateParameterType(QualType T, SourceLocation Loc);
04524   Decl *ActOnNonTypeTemplateParameter(Scope *S, Declarator &D,
04525                                       unsigned Depth,
04526                                       unsigned Position,
04527                                       SourceLocation EqualLoc,
04528                                       Expr *DefaultArg);
04529   Decl *ActOnTemplateTemplateParameter(Scope *S,
04530                                        SourceLocation TmpLoc,
04531                                        TemplateParameterList *Params,
04532                                        SourceLocation EllipsisLoc,
04533                                        IdentifierInfo *ParamName,
04534                                        SourceLocation ParamNameLoc,
04535                                        unsigned Depth,
04536                                        unsigned Position,
04537                                        SourceLocation EqualLoc,
04538                                        ParsedTemplateArgument DefaultArg);
04539 
04540   TemplateParameterList *
04541   ActOnTemplateParameterList(unsigned Depth,
04542                              SourceLocation ExportLoc,
04543                              SourceLocation TemplateLoc,
04544                              SourceLocation LAngleLoc,
04545                              Decl **Params, unsigned NumParams,
04546                              SourceLocation RAngleLoc);
04547 
04548   /// \brief The context in which we are checking a template parameter
04549   /// list.
04550   enum TemplateParamListContext {
04551     TPC_ClassTemplate,
04552     TPC_FunctionTemplate,
04553     TPC_ClassTemplateMember,
04554     TPC_FriendFunctionTemplate,
04555     TPC_FriendFunctionTemplateDefinition,
04556     TPC_TypeAliasTemplate
04557   };
04558 
04559   bool CheckTemplateParameterList(TemplateParameterList *NewParams,
04560                                   TemplateParameterList *OldParams,
04561                                   TemplateParamListContext TPC);
04562   TemplateParameterList *
04563   MatchTemplateParametersToScopeSpecifier(SourceLocation DeclStartLoc,
04564                                           SourceLocation DeclLoc,
04565                                           const CXXScopeSpec &SS,
04566                                           TemplateParameterList **ParamLists,
04567                                           unsigned NumParamLists,
04568                                           bool IsFriend,
04569                                           bool &IsExplicitSpecialization,
04570                                           bool &Invalid);
04571 
04572   DeclResult CheckClassTemplate(Scope *S, unsigned TagSpec, TagUseKind TUK,
04573                                 SourceLocation KWLoc, CXXScopeSpec &SS,
04574                                 IdentifierInfo *Name, SourceLocation NameLoc,
04575                                 AttributeList *Attr,
04576                                 TemplateParameterList *TemplateParams,
04577                                 AccessSpecifier AS,
04578                                 SourceLocation ModulePrivateLoc,
04579                                 unsigned NumOuterTemplateParamLists,
04580                             TemplateParameterList **OuterTemplateParamLists);
04581 
04582   void translateTemplateArguments(const ASTTemplateArgsPtr &In,
04583                                   TemplateArgumentListInfo &Out);
04584 
04585   void NoteAllFoundTemplates(TemplateName Name);
04586 
04587   QualType CheckTemplateIdType(TemplateName Template,
04588                                SourceLocation TemplateLoc,
04589                               TemplateArgumentListInfo &TemplateArgs);
04590 
04591   TypeResult
04592   ActOnTemplateIdType(CXXScopeSpec &SS, SourceLocation TemplateKWLoc,
04593                       TemplateTy Template, SourceLocation TemplateLoc,
04594                       SourceLocation LAngleLoc,
04595                       ASTTemplateArgsPtr TemplateArgs,
04596                       SourceLocation RAngleLoc,
04597                       bool IsCtorOrDtorName = false);
04598 
04599   /// \brief Parsed an elaborated-type-specifier that refers to a template-id,
04600   /// such as \c class T::template apply<U>.
04601   ///
04602   /// \param TUK
04603   TypeResult ActOnTagTemplateIdType(TagUseKind TUK,
04604                                     TypeSpecifierType TagSpec,
04605                                     SourceLocation TagLoc,
04606                                     CXXScopeSpec &SS,
04607                                     SourceLocation TemplateKWLoc,
04608                                     TemplateTy TemplateD,
04609                                     SourceLocation TemplateLoc,
04610                                     SourceLocation LAngleLoc,
04611                                     ASTTemplateArgsPtr TemplateArgsIn,
04612                                     SourceLocation RAngleLoc);
04613 
04614 
04615   ExprResult BuildTemplateIdExpr(const CXXScopeSpec &SS,
04616                                  SourceLocation TemplateKWLoc,
04617                                  LookupResult &R,
04618                                  bool RequiresADL,
04619                                const TemplateArgumentListInfo *TemplateArgs);
04620 
04621   ExprResult BuildQualifiedTemplateIdExpr(CXXScopeSpec &SS,
04622                                           SourceLocation TemplateKWLoc,
04623                                const DeclarationNameInfo &NameInfo,
04624                                const TemplateArgumentListInfo *TemplateArgs);
04625 
04626   TemplateNameKind ActOnDependentTemplateName(Scope *S,
04627                                               CXXScopeSpec &SS,
04628                                               SourceLocation TemplateKWLoc,
04629                                               UnqualifiedId &Name,
04630                                               ParsedType ObjectType,
04631                                               bool EnteringContext,
04632                                               TemplateTy &Template);
04633 
04634   DeclResult
04635   ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, TagUseKind TUK,
04636                                    SourceLocation KWLoc,
04637                                    SourceLocation ModulePrivateLoc,
04638                                    CXXScopeSpec &SS,
04639                                    TemplateTy Template,
04640                                    SourceLocation TemplateNameLoc,
04641                                    SourceLocation LAngleLoc,
04642                                    ASTTemplateArgsPtr TemplateArgs,
04643                                    SourceLocation RAngleLoc,
04644                                    AttributeList *Attr,
04645                                  MultiTemplateParamsArg TemplateParameterLists);
04646 
04647   Decl *ActOnTemplateDeclarator(Scope *S,
04648                                 MultiTemplateParamsArg TemplateParameterLists,
04649                                 Declarator &D);
04650 
04651   Decl *ActOnStartOfFunctionTemplateDef(Scope *FnBodyScope,
04652                                   MultiTemplateParamsArg TemplateParameterLists,
04653                                         Declarator &D);
04654 
04655   bool
04656   CheckSpecializationInstantiationRedecl(SourceLocation NewLoc,
04657                                          TemplateSpecializationKind NewTSK,
04658                                          NamedDecl *PrevDecl,
04659                                          TemplateSpecializationKind PrevTSK,
04660                                          SourceLocation PrevPtOfInstantiation,
04661                                          bool &SuppressNew);
04662 
04663   bool CheckDependentFunctionTemplateSpecialization(FunctionDecl *FD,
04664                     const TemplateArgumentListInfo &ExplicitTemplateArgs,
04665                                                     LookupResult &Previous);
04666 
04667   bool CheckFunctionTemplateSpecialization(FunctionDecl *FD,
04668                          TemplateArgumentListInfo *ExplicitTemplateArgs,
04669                                            LookupResult &Previous);
04670   bool CheckMemberSpecialization(NamedDecl *Member, LookupResult &Previous);
04671 
04672   DeclResult
04673   ActOnExplicitInstantiation(Scope *S,
04674                              SourceLocation ExternLoc,
04675                              SourceLocation TemplateLoc,
04676                              unsigned TagSpec,
04677                              SourceLocation KWLoc,
04678                              const CXXScopeSpec &SS,
04679                              TemplateTy Template,
04680                              SourceLocation TemplateNameLoc,
04681                              SourceLocation LAngleLoc,
04682                              ASTTemplateArgsPtr TemplateArgs,
04683                              SourceLocation RAngleLoc,
04684                              AttributeList *Attr);
04685 
04686   DeclResult
04687   ActOnExplicitInstantiation(Scope *S,
04688                              SourceLocation ExternLoc,
04689                              SourceLocation TemplateLoc,
04690                              unsigned TagSpec,
04691                              SourceLocation KWLoc,
04692                              CXXScopeSpec &SS,
04693                              IdentifierInfo *Name,
04694                              SourceLocation NameLoc,
04695                              AttributeList *Attr);
04696 
04697   DeclResult ActOnExplicitInstantiation(Scope *S,
04698                                         SourceLocation ExternLoc,
04699                                         SourceLocation TemplateLoc,
04700                                         Declarator &D);
04701 
04702   TemplateArgumentLoc
04703   SubstDefaultTemplateArgumentIfAvailable(TemplateDecl *Template,
04704                                           SourceLocation TemplateLoc,
04705                                           SourceLocation RAngleLoc,
04706                                           Decl *Param,
04707                           SmallVectorImpl<TemplateArgument> &Converted);
04708 
04709   /// \brief Specifies the context in which a particular template
04710   /// argument is being checked.
04711   enum CheckTemplateArgumentKind {
04712     /// \brief The template argument was specified in the code or was
04713     /// instantiated with some deduced template arguments.
04714     CTAK_Specified,
04715 
04716     /// \brief The template argument was deduced via template argument
04717     /// deduction.
04718     CTAK_Deduced,
04719 
04720     /// \brief The template argument was deduced from an array bound
04721     /// via template argument deduction.
04722     CTAK_DeducedFromArrayBound
04723   };
04724 
04725   bool CheckTemplateArgument(NamedDecl *Param,
04726                              const TemplateArgumentLoc &Arg,
04727                              NamedDecl *Template,
04728                              SourceLocation TemplateLoc,
04729                              SourceLocation RAngleLoc,
04730                              unsigned ArgumentPackIndex,
04731                            SmallVectorImpl<TemplateArgument> &Converted,
04732                              CheckTemplateArgumentKind CTAK = CTAK_Specified);
04733 
04734   /// \brief Check that the given template arguments can be be provided to
04735   /// the given template, converting the arguments along the way.
04736   ///
04737   /// \param Template The template to which the template arguments are being
04738   /// provided.
04739   ///
04740   /// \param TemplateLoc The location of the template name in the source.
04741   ///
04742   /// \param TemplateArgs The list of template arguments. If the template is
04743   /// a template template parameter, this function may extend the set of
04744   /// template arguments to also include substituted, defaulted template
04745   /// arguments.
04746   ///
04747   /// \param PartialTemplateArgs True if the list of template arguments is
04748   /// intentionally partial, e.g., because we're checking just the initial
04749   /// set of template arguments.
04750   ///
04751   /// \param Converted Will receive the converted, canonicalized template
04752   /// arguments.
04753   ///
04754   ///
04755   /// \param ExpansionIntoFixedList If non-NULL, will be set true to indicate
04756   /// when the template arguments contain a pack expansion that is being
04757   /// expanded into a fixed parameter list.
04758   ///
04759   /// \returns True if an error occurred, false otherwise.
04760   bool CheckTemplateArgumentList(TemplateDecl *Template,
04761                                  SourceLocation TemplateLoc,
04762                                  TemplateArgumentListInfo &TemplateArgs,
04763                                  bool PartialTemplateArgs,
04764                            SmallVectorImpl<TemplateArgument> &Converted,
04765                                  bool *ExpansionIntoFixedList = 0);
04766 
04767   bool CheckTemplateTypeArgument(TemplateTypeParmDecl *Param,
04768                                  const TemplateArgumentLoc &Arg,
04769                            SmallVectorImpl<TemplateArgument> &Converted);
04770 
04771   bool CheckTemplateArgument(TemplateTypeParmDecl *Param,
04772                              TypeSourceInfo *Arg);
04773   ExprResult CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
04774                                    QualType InstantiatedParamType, Expr *Arg,
04775                                    TemplateArgument &Converted,
04776                                CheckTemplateArgumentKind CTAK = CTAK_Specified);
04777   bool CheckTemplateArgument(TemplateTemplateParmDecl *Param,
04778                              const TemplateArgumentLoc &Arg);
04779 
04780   ExprResult
04781   BuildExpressionFromDeclTemplateArgument(const TemplateArgument &Arg,
04782                                           QualType ParamType,
04783                                           SourceLocation Loc);
04784   ExprResult
04785   BuildExpressionFromIntegralTemplateArgument(const TemplateArgument &Arg,
04786                                               SourceLocation Loc);
04787 
04788   /// \brief Enumeration describing how template parameter lists are compared
04789   /// for equality.
04790   enum TemplateParameterListEqualKind {
04791     /// \brief We are matching the template parameter lists of two templates
04792     /// that might be redeclarations.
04793     ///
04794     /// \code
04795     /// template<typename T> struct X;
04796     /// template<typename T> struct X;
04797     /// \endcode
04798     TPL_TemplateMatch,
04799 
04800     /// \brief We are matching the template parameter lists of two template
04801     /// template parameters as part of matching the template parameter lists
04802     /// of two templates that might be redeclarations.
04803     ///
04804     /// \code
04805     /// template<template<int I> class TT> struct X;
04806     /// template<template<int Value> class Other> struct X;
04807     /// \endcode
04808     TPL_TemplateTemplateParmMatch,
04809 
04810     /// \brief We are matching the template parameter lists of a template
04811     /// template argument against the template parameter lists of a template
04812     /// template parameter.
04813     ///
04814     /// \code
04815     /// template<template<int Value> class Metafun> struct X;
04816     /// template<int Value> struct integer_c;
04817     /// X<integer_c> xic;
04818     /// \endcode
04819     TPL_TemplateTemplateArgumentMatch
04820   };
04821 
04822   bool TemplateParameterListsAreEqual(TemplateParameterList *New,
04823                                       TemplateParameterList *Old,
04824                                       bool Complain,
04825                                       TemplateParameterListEqualKind Kind,
04826                                       SourceLocation TemplateArgLoc
04827                                         = SourceLocation());
04828 
04829   bool CheckTemplateDeclScope(Scope *S, TemplateParameterList *TemplateParams);
04830 
04831   /// \brief Called when the parser has parsed a C++ typename
04832   /// specifier, e.g., "typename T::type".
04833   ///
04834   /// \param S The scope in which this typename type occurs.
04835   /// \param TypenameLoc the location of the 'typename' keyword
04836   /// \param SS the nested-name-specifier following the typename (e.g., 'T::').
04837   /// \param II the identifier we're retrieving (e.g., 'type' in the example).
04838   /// \param IdLoc the location of the identifier.
04839   TypeResult
04840   ActOnTypenameType(Scope *S, SourceLocation TypenameLoc,
04841                     const CXXScopeSpec &SS, const IdentifierInfo &II,
04842                     SourceLocation IdLoc);
04843 
04844   /// \brief Called when the parser has parsed a C++ typename
04845   /// specifier that ends in a template-id, e.g.,
04846   /// "typename MetaFun::template apply<T1, T2>".
04847   ///
04848   /// \param S The scope in which this typename type occurs.
04849   /// \param TypenameLoc the location of the 'typename' keyword
04850   /// \param SS the nested-name-specifier following the typename (e.g., 'T::').
04851   /// \param TemplateLoc the location of the 'template' keyword, if any.
04852   /// \param TemplateName The template name.
04853   /// \param TemplateNameLoc The location of the template name.
04854   /// \param LAngleLoc The location of the opening angle bracket  ('<').
04855   /// \param TemplateArgs The template arguments.
04856   /// \param RAngleLoc The location of the closing angle bracket  ('>').
04857   TypeResult
04858   ActOnTypenameType(Scope *S, SourceLocation TypenameLoc,
04859                     const CXXScopeSpec &SS,
04860                     SourceLocation TemplateLoc,
04861                     TemplateTy Template,
04862                     SourceLocation TemplateNameLoc,
04863                     SourceLocation LAngleLoc,
04864                     ASTTemplateArgsPtr TemplateArgs,
04865                     SourceLocation RAngleLoc);
04866 
04867   QualType CheckTypenameType(ElaboratedTypeKeyword Keyword,
04868                              SourceLocation KeywordLoc,
04869                              NestedNameSpecifierLoc QualifierLoc,
04870                              const IdentifierInfo &II,
04871                              SourceLocation IILoc);
04872 
04873   TypeSourceInfo *RebuildTypeInCurrentInstantiation(TypeSourceInfo *T,
04874                                                     SourceLocation Loc,
04875                                                     DeclarationName Name);
04876   bool RebuildNestedNameSpecifierInCurrentInstantiation(CXXScopeSpec &SS);
04877 
04878   ExprResult RebuildExprInCurrentInstantiation(Expr *E);
04879   bool RebuildTemplateParamsInCurrentInstantiation(
04880                                                 TemplateParameterList *Params);
04881 
04882   std::string
04883   getTemplateArgumentBindingsText(const TemplateParameterList *Params,
04884                                   const TemplateArgumentList &Args);
04885 
04886   std::string
04887   getTemplateArgumentBindingsText(const TemplateParameterList *Params,
04888                                   const TemplateArgument *Args,
04889                                   unsigned NumArgs);
04890 
04891   //===--------------------------------------------------------------------===//
04892   // C++ Variadic Templates (C++0x [temp.variadic])
04893   //===--------------------------------------------------------------------===//
04894 
04895   /// \brief The context in which an unexpanded parameter pack is
04896   /// being diagnosed.
04897   ///
04898   /// Note that the values of this enumeration line up with the first
04899   /// argument to the \c err_unexpanded_parameter_pack diagnostic.
04900   enum UnexpandedParameterPackContext {
04901     /// \brief An arbitrary expression.
04902     UPPC_Expression = 0,
04903 
04904     /// \brief The base type of a class type.
04905     UPPC_BaseType,
04906 
04907     /// \brief The type of an arbitrary declaration.
04908     UPPC_DeclarationType,
04909 
04910     /// \brief The type of a data member.
04911     UPPC_DataMemberType,
04912 
04913     /// \brief The size of a bit-field.
04914     UPPC_BitFieldWidth,
04915 
04916     /// \brief The expression in a static assertion.
04917     UPPC_StaticAssertExpression,
04918 
04919     /// \brief The fixed underlying type of an enumeration.
04920     UPPC_FixedUnderlyingType,
04921 
04922     /// \brief The enumerator value.
04923     UPPC_EnumeratorValue,
04924 
04925     /// \brief A using declaration.
04926     UPPC_UsingDeclaration,
04927 
04928     /// \brief A friend declaration.
04929     UPPC_FriendDeclaration,
04930 
04931     /// \brief A declaration qualifier.
04932     UPPC_DeclarationQualifier,
04933 
04934     /// \brief An initializer.
04935     UPPC_Initializer,
04936 
04937     /// \brief A default argument.
04938     UPPC_DefaultArgument,
04939 
04940     /// \brief The type of a non-type template parameter.
04941     UPPC_NonTypeTemplateParameterType,
04942 
04943     /// \brief The type of an exception.
04944     UPPC_ExceptionType,
04945 
04946     /// \brief Partial specialization.
04947     UPPC_PartialSpecialization,
04948 
04949     /// \brief Microsoft __if_exists.
04950     UPPC_IfExists,
04951 
04952     /// \brief Microsoft __if_not_exists.
04953     UPPC_IfNotExists
04954 };
04955 
04956   /// \brief Diagnose unexpanded parameter packs.
04957   ///
04958   /// \param Loc The location at which we should emit the diagnostic.
04959   ///
04960   /// \param UPPC The context in which we are diagnosing unexpanded
04961   /// parameter packs.
04962   ///
04963   /// \param Unexpanded the set of unexpanded parameter packs.
04964   void DiagnoseUnexpandedParameterPacks(SourceLocation Loc,
04965                                         UnexpandedParameterPackContext UPPC,
04966                                   ArrayRef<UnexpandedParameterPack> Unexpanded);
04967 
04968   /// \brief If the given type contains an unexpanded parameter pack,
04969   /// diagnose the error.
04970   ///
04971   /// \param Loc The source location where a diagnostc should be emitted.
04972   ///
04973   /// \param T The type that is being checked for unexpanded parameter
04974   /// packs.
04975   ///
04976   /// \returns true if an error occurred, false otherwise.
04977   bool DiagnoseUnexpandedParameterPack(SourceLocation Loc, TypeSourceInfo *T,
04978                                        UnexpandedParameterPackContext UPPC);
04979 
04980   /// \brief If the given expression contains an unexpanded parameter
04981   /// pack, diagnose the error.
04982   ///
04983   /// \param E The expression that is being checked for unexpanded
04984   /// parameter packs.
04985   ///
04986   /// \returns true if an error occurred, false otherwise.
04987   bool DiagnoseUnexpandedParameterPack(Expr *E,
04988                        UnexpandedParameterPackContext UPPC = UPPC_Expression);
04989 
04990   /// \brief If the given nested-name-specifier contains an unexpanded
04991   /// parameter pack, diagnose the error.
04992   ///
04993   /// \param SS The nested-name-specifier that is being checked for
04994   /// unexpanded parameter packs.
04995   ///
04996   /// \returns true if an error occurred, false otherwise.
04997   bool DiagnoseUnexpandedParameterPack(const CXXScopeSpec &SS,
04998                                        UnexpandedParameterPackContext UPPC);
04999 
05000   /// \brief If the given name contains an unexpanded parameter pack,
05001   /// diagnose the error.
05002   ///
05003   /// \param NameInfo The name (with source location information) that
05004   /// is being checked for unexpanded parameter packs.
05005   ///
05006   /// \returns true if an error occurred, false otherwise.
05007   bool DiagnoseUnexpandedParameterPack(const DeclarationNameInfo &NameInfo,
05008                                        UnexpandedParameterPackContext UPPC);
05009 
05010   /// \brief If the given template name contains an unexpanded parameter pack,
05011   /// diagnose the error.
05012   ///
05013   /// \param Loc The location of the template name.
05014   ///
05015   /// \param Template The template name that is being checked for unexpanded
05016   /// parameter packs.
05017   ///
05018   /// \returns true if an error occurred, false otherwise.
05019   bool DiagnoseUnexpandedParameterPack(SourceLocation Loc,
05020                                        TemplateName Template,
05021                                        UnexpandedParameterPackContext UPPC);
05022 
05023   /// \brief If the given template argument contains an unexpanded parameter
05024   /// pack, diagnose the error.
05025   ///
05026   /// \param Arg The template argument that is being checked for unexpanded
05027   /// parameter packs.
05028   ///
05029   /// \returns true if an error occurred, false otherwise.
05030   bool DiagnoseUnexpandedParameterPack(TemplateArgumentLoc Arg,
05031                                        UnexpandedParameterPackContext UPPC);
05032 
05033   /// \brief Collect the set of unexpanded parameter packs within the given
05034   /// template argument.
05035   ///
05036   /// \param Arg The template argument that will be traversed to find
05037   /// unexpanded parameter packs.
05038   void collectUnexpandedParameterPacks(TemplateArgument Arg,
05039                    SmallVectorImpl<UnexpandedParameterPack> &Unexpanded);
05040 
05041   /// \brief Collect the set of unexpanded parameter packs within the given
05042   /// template argument.
05043   ///
05044   /// \param Arg The template argument that will be traversed to find
05045   /// unexpanded parameter packs.
05046   void collectUnexpandedParameterPacks(TemplateArgumentLoc Arg,
05047                     SmallVectorImpl<UnexpandedParameterPack> &Unexpanded);
05048 
05049   /// \brief Collect the set of unexpanded parameter packs within the given
05050   /// type.
05051   ///
05052   /// \param T The type that will be traversed to find
05053   /// unexpanded parameter packs.
05054   void collectUnexpandedParameterPacks(QualType T,
05055                    SmallVectorImpl<UnexpandedParameterPack> &Unexpanded);
05056 
05057   /// \brief Collect the set of unexpanded parameter packs within the given
05058   /// type.
05059   ///
05060   /// \param TL The type that will be traversed to find
05061   /// unexpanded parameter packs.
05062   void collectUnexpandedParameterPacks(TypeLoc TL,
05063                    SmallVectorImpl<UnexpandedParameterPack> &Unexpanded);
05064 
05065   /// \brief Collect the set of unexpanded parameter packs within the given
05066   /// nested-name-specifier.
05067   ///
05068   /// \param SS The nested-name-specifier that will be traversed to find
05069   /// unexpanded parameter packs.
05070   void collectUnexpandedParameterPacks(CXXScopeSpec &SS,
05071                          SmallVectorImpl<UnexpandedParameterPack> &Unexpanded);
05072 
05073   /// \brief Collect the set of unexpanded parameter packs within the given
05074   /// name.
05075   ///
05076   /// \param NameInfo The name that will be traversed to find
05077   /// unexpanded parameter packs.
05078   void collectUnexpandedParameterPacks(const DeclarationNameInfo &NameInfo,
05079                          SmallVectorImpl<UnexpandedParameterPack> &Unexpanded);
05080 
05081   /// \brief Invoked when parsing a template argument followed by an
05082   /// ellipsis, which creates a pack expansion.
05083   ///
05084   /// \param Arg The template argument preceding the ellipsis, which
05085   /// may already be invalid.
05086   ///
05087   /// \param EllipsisLoc The location of the ellipsis.
05088   ParsedTemplateArgument ActOnPackExpansion(const ParsedTemplateArgument &Arg,
05089                                             SourceLocation EllipsisLoc);
05090 
05091   /// \brief Invoked when parsing a type followed by an ellipsis, which
05092   /// creates a pack expansion.
05093   ///
05094   /// \param Type The type preceding the ellipsis, which will become
05095   /// the pattern of the pack expansion.
05096   ///
05097   /// \param EllipsisLoc The location of the ellipsis.
05098   TypeResult ActOnPackExpansion(ParsedType Type, SourceLocation EllipsisLoc);
05099 
05100   /// \brief Construct a pack expansion type from the pattern of the pack
05101   /// expansion.
05102   TypeSourceInfo *CheckPackExpansion(TypeSourceInfo *Pattern,
05103                                      SourceLocation EllipsisLoc,
05104                                      llvm::Optional<unsigned> NumExpansions);
05105 
05106   /// \brief Construct a pack expansion type from the pattern of the pack
05107   /// expansion.
05108   QualType CheckPackExpansion(QualType Pattern,
05109                               SourceRange PatternRange,
05110                               SourceLocation EllipsisLoc,
05111                               llvm::Optional<unsigned> NumExpansions);
05112 
05113   /// \brief Invoked when parsing an expression followed by an ellipsis, which
05114   /// creates a pack expansion.
05115   ///
05116   /// \param Pattern The expression preceding the ellipsis, which will become
05117   /// the pattern of the pack expansion.
05118   ///
05119   /// \param EllipsisLoc The location of the ellipsis.
05120   ExprResult ActOnPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc);
05121 
05122   /// \brief Invoked when parsing an expression followed by an ellipsis, which
05123   /// creates a pack expansion.
05124   ///
05125   /// \param Pattern The expression preceding the ellipsis, which will become
05126   /// the pattern of the pack expansion.
05127   ///
05128   /// \param EllipsisLoc The location of the ellipsis.
05129   ExprResult CheckPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
05130                                 llvm::Optional<unsigned> NumExpansions);
05131 
05132   /// \brief Determine whether we could expand a pack expansion with the
05133   /// given set of parameter packs into separate arguments by repeatedly
05134   /// transforming the pattern.
05135   ///
05136   /// \param EllipsisLoc The location of the ellipsis that identifies the
05137   /// pack expansion.
05138   ///
05139   /// \param PatternRange The source range that covers the entire pattern of
05140   /// the pack expansion.
05141   ///
05142   /// \param Unexpanded The set of unexpanded parameter packs within the
05143   /// pattern.
05144   ///
05145   /// \param NumUnexpanded The number of unexpanded parameter packs in
05146   /// \p Unexpanded.
05147   ///
05148   /// \param ShouldExpand Will be set to \c true if the transformer should
05149   /// expand the corresponding pack expansions into separate arguments. When
05150   /// set, \c NumExpansions must also be set.
05151   ///
05152   /// \param RetainExpansion Whether the caller should add an unexpanded
05153   /// pack expansion after all of the expanded arguments. This is used
05154   /// when extending explicitly-specified template argument packs per
05155   /// C++0x [temp.arg.explicit]p9.
05156   ///
05157   /// \param NumExpansions The number of separate arguments that will be in
05158   /// the expanded form of the corresponding pack expansion. This is both an
05159   /// input and an output parameter, which can be set by the caller if the
05160   /// number of expansions is known a priori (e.g., due to a prior substitution)
05161   /// and will be set by the callee when the number of expansions is known.
05162   /// The callee must set this value when \c ShouldExpand is \c true; it may
05163   /// set this value in other cases.
05164   ///
05165   /// \returns true if an error occurred (e.g., because the parameter packs
05166   /// are to be instantiated with arguments of different lengths), false
05167   /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
05168   /// must be set.
05169   bool CheckParameterPacksForExpansion(SourceLocation EllipsisLoc,
05170                                        SourceRange PatternRange,
05171                              llvm::ArrayRef<UnexpandedParameterPack> Unexpanded,
05172                              const MultiLevelTemplateArgumentList &TemplateArgs,
05173                                        bool &ShouldExpand,
05174                                        bool &RetainExpansion,
05175                                        llvm::Optional<unsigned> &NumExpansions);
05176 
05177   /// \brief Determine the number of arguments in the given pack expansion
05178   /// type.
05179   ///
05180   /// This routine already assumes that the pack expansion type can be
05181   /// expanded and that the number of arguments in the expansion is
05182   /// consistent across all of the unexpanded parameter packs in its pattern.
05183   unsigned getNumArgumentsInExpansion(QualType T,
05184                             const MultiLevelTemplateArgumentList &TemplateArgs);
05185 
05186   /// \brief Determine whether the given declarator contains any unexpanded
05187   /// parameter packs.
05188   ///
05189   /// This routine is used by the parser to disambiguate function declarators
05190   /// with an ellipsis prior to the ')', e.g.,
05191   ///
05192   /// \code
05193   ///   void f(T...);
05194   /// \endcode
05195   ///
05196   /// To determine whether we have an (unnamed) function parameter pack or
05197   /// a variadic function.
05198   ///
05199   /// \returns true if the declarator contains any unexpanded parameter packs,
05200   /// false otherwise.
05201   bool containsUnexpandedParameterPacks(Declarator &D);
05202 
05203   //===--------------------------------------------------------------------===//
05204   // C++ Template Argument Deduction (C++ [temp.deduct])
05205   //===--------------------------------------------------------------------===//
05206 
05207   /// \brief Describes the result of template argument deduction.
05208   ///
05209   /// The TemplateDeductionResult enumeration describes the result of
05210   /// template argument deduction, as returned from
05211   /// DeduceTemplateArguments(). The separate TemplateDeductionInfo
05212   /// structure provides additional information about the results of
05213   /// template argument deduction, e.g., the deduced template argument
05214   /// list (if successful) or the specific template parameters or
05215   /// deduced arguments that were involved in the failure.
05216   enum TemplateDeductionResult {
05217     /// \brief Template argument deduction was successful.
05218     TDK_Success = 0,
05219     /// \brief Template argument deduction exceeded the maximum template
05220     /// instantiation depth (which has already been diagnosed).
05221     TDK_InstantiationDepth,
05222     /// \brief Template argument deduction did not deduce a value
05223     /// for every template parameter.
05224     TDK_Incomplete,
05225     /// \brief Template argument deduction produced inconsistent
05226     /// deduced values for the given template parameter.
05227     TDK_Inconsistent,
05228     /// \brief Template argument deduction failed due to inconsistent
05229     /// cv-qualifiers on a template parameter type that would
05230     /// otherwise be deduced, e.g., we tried to deduce T in "const T"
05231     /// but were given a non-const "X".
05232     TDK_Underqualified,
05233     /// \brief Substitution of the deduced template argument values
05234     /// resulted in an error.
05235     TDK_SubstitutionFailure,
05236     /// \brief Substitution of the deduced template argument values
05237     /// into a non-deduced context produced a type or value that
05238     /// produces a type that does not match the original template
05239     /// arguments provided.
05240     TDK_NonDeducedMismatch,
05241     /// \brief When performing template argument deduction for a function
05242     /// template, there were too many call arguments.
05243     TDK_TooManyArguments,
05244     /// \brief When performing template argument deduction for a function
05245     /// template, there were too few call arguments.
05246     TDK_TooFewArguments,
05247     /// \brief The explicitly-specified template arguments were not valid
05248     /// template arguments for the given template.
05249     TDK_InvalidExplicitArguments,
05250     /// \brief The arguments included an overloaded function name that could
05251     /// not be resolved to a suitable function.
05252     TDK_FailedOverloadResolution
05253   };
05254 
05255   TemplateDeductionResult
05256   DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial,
05257                           const TemplateArgumentList &TemplateArgs,
05258                           sema::TemplateDeductionInfo &Info);
05259 
05260   TemplateDeductionResult
05261   SubstituteExplicitTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
05262                               TemplateArgumentListInfo &ExplicitTemplateArgs,
05263                       SmallVectorImpl<DeducedTemplateArgument> &Deduced,
05264                                  SmallVectorImpl<QualType> &ParamTypes,
05265                                       QualType *FunctionType,
05266                                       sema::TemplateDeductionInfo &Info);
05267 
05268   /// brief A function argument from which we performed template argument
05269   // deduction for a call.
05270   struct OriginalCallArg {
05271     OriginalCallArg(QualType OriginalParamType,
05272                     unsigned ArgIdx,
05273                     QualType OriginalArgType)
05274       : OriginalParamType(OriginalParamType), ArgIdx(ArgIdx),
05275         OriginalArgType(OriginalArgType) { }
05276 
05277     QualType OriginalParamType;
05278     unsigned ArgIdx;
05279     QualType OriginalArgType;
05280   };
05281 
05282   TemplateDeductionResult
05283   FinishTemplateArgumentDeduction(FunctionTemplateDecl *FunctionTemplate,
05284                       SmallVectorImpl<DeducedTemplateArgument> &Deduced,
05285                                   unsigned NumExplicitlySpecified,
05286                                   FunctionDecl *&Specialization,
05287                                   sema::TemplateDeductionInfo &Info,
05288            SmallVectorImpl<OriginalCallArg> const *OriginalCallArgs = 0);
05289 
05290   TemplateDeductionResult
05291   DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
05292                           TemplateArgumentListInfo *ExplicitTemplateArgs,
05293                           llvm::ArrayRef<Expr *> Args,
05294                           FunctionDecl *&Specialization,
05295                           sema::TemplateDeductionInfo &Info);
05296 
05297   TemplateDeductionResult
05298   DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
05299                           TemplateArgumentListInfo *ExplicitTemplateArgs,
05300                           QualType ArgFunctionType,
05301                           FunctionDecl *&Specialization,
05302                           sema::TemplateDeductionInfo &Info);
05303 
05304   TemplateDeductionResult
05305   DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
05306                           QualType ToType,
05307                           CXXConversionDecl *&Specialization,
05308                           sema::TemplateDeductionInfo &Info);
05309 
05310   TemplateDeductionResult
05311   DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
05312                           TemplateArgumentListInfo *ExplicitTemplateArgs,
05313                           FunctionDecl *&Specialization,
05314                           sema::TemplateDeductionInfo &Info);
05315 
05316   /// \brief Result type of DeduceAutoType.
05317   enum DeduceAutoResult {
05318     DAR_Succeeded,
05319     DAR_Failed,
05320     DAR_FailedAlreadyDiagnosed
05321   };
05322 
05323   DeduceAutoResult DeduceAutoType(TypeSourceInfo *AutoType, Expr *&Initializer,
05324                                   TypeSourceInfo *&Result);
05325   void DiagnoseAutoDeductionFailure(VarDecl *VDecl, Expr *Init);
05326 
05327   FunctionTemplateDecl *getMoreSpecializedTemplate(FunctionTemplateDecl *FT1,
05328                                                    FunctionTemplateDecl *FT2,
05329                                                    SourceLocation Loc,
05330                                            TemplatePartialOrderingContext TPOC,
05331                                                    unsigned NumCallArguments);
05332   UnresolvedSetIterator getMostSpecialized(UnresolvedSetIterator SBegin,
05333                                            UnresolvedSetIterator SEnd,
05334                                            TemplatePartialOrderingContext TPOC,
05335                                            unsigned NumCallArguments,
05336                                            SourceLocation Loc,
05337                                            const PartialDiagnostic &NoneDiag,
05338                                            const PartialDiagnostic &AmbigDiag,
05339                                         const PartialDiagnostic &CandidateDiag,
05340                                         bool Complain = true,
05341                                         QualType TargetType = QualType());
05342 
05343   ClassTemplatePartialSpecializationDecl *
05344   getMoreSpecializedPartialSpecialization(
05345                                   ClassTemplatePartialSpecializationDecl *PS1,
05346                                   ClassTemplatePartialSpecializationDecl *PS2,
05347                                   SourceLocation Loc);
05348 
05349   void MarkUsedTemplateParameters(const TemplateArgumentList &TemplateArgs,
05350                                   bool OnlyDeduced,
05351                                   unsigned Depth,
05352                                   llvm::SmallBitVector &Used);
05353   void MarkDeducedTemplateParameters(FunctionTemplateDecl *FunctionTemplate,
05354                                      llvm::SmallBitVector &Deduced) {
05355     return MarkDeducedTemplateParameters(Context, FunctionTemplate, Deduced);
05356   }
05357   static void MarkDeducedTemplateParameters(ASTContext &Ctx,
05358                                          FunctionTemplateDecl *FunctionTemplate,
05359                                          llvm::SmallBitVector &Deduced);
05360 
05361   //===--------------------------------------------------------------------===//
05362   // C++ Template Instantiation
05363   //
05364 
05365   MultiLevelTemplateArgumentList getTemplateInstantiationArgs(NamedDecl *D,
05366                                      const TemplateArgumentList *Innermost = 0,
05367                                                 bool RelativeToPrimary = false,
05368                                                const FunctionDecl *Pattern = 0);
05369 
05370   /// \brief A template instantiation that is currently in progress.
05371   struct ActiveTemplateInstantiation {
05372     /// \brief The kind of template instantiation we are performing
05373     enum InstantiationKind {
05374       /// We are instantiating a template declaration. The entity is
05375       /// the declaration we're instantiating (e.g., a CXXRecordDecl).
05376       TemplateInstantiation,
05377 
05378       /// We are instantiating a default argument for a template
05379       /// parameter. The Entity is the template, and
05380       /// TemplateArgs/NumTemplateArguments provides the template
05381       /// arguments as specified.
05382       /// FIXME: Use a TemplateArgumentList
05383       DefaultTemplateArgumentInstantiation,
05384 
05385       /// We are instantiating a default argument for a function.
05386       /// The Entity is the ParmVarDecl, and TemplateArgs/NumTemplateArgs
05387       /// provides the template arguments as specified.
05388       DefaultFunctionArgumentInstantiation,
05389 
05390       /// We are substituting explicit template arguments provided for
05391       /// a function template. The entity is a FunctionTemplateDecl.
05392       ExplicitTemplateArgumentSubstitution,
05393 
05394       /// We are substituting template argument determined as part of
05395       /// template argument deduction for either a class template
05396       /// partial specialization or a function template. The
05397       /// Entity is either a ClassTemplatePartialSpecializationDecl or
05398       /// a FunctionTemplateDecl.
05399       DeducedTemplateArgumentSubstitution,
05400 
05401       /// We are substituting prior template arguments into a new
05402       /// template parameter. The template parameter itself is either a
05403       /// NonTypeTemplateParmDecl or a TemplateTemplateParmDecl.
05404       PriorTemplateArgumentSubstitution,
05405 
05406       /// We are checking the validity of a default template argument that
05407       /// has been used when naming a template-id.
05408       DefaultTemplateArgumentChecking,
05409 
05410       /// We are instantiating the exception specification for a function
05411       /// template which was deferred until it was needed.
05412       ExceptionSpecInstantiation
05413     } Kind;
05414 
05415     /// \brief The point of instantiation within the source code.
05416     SourceLocation PointOfInstantiation;
05417 
05418     /// \brief The template (or partial specialization) in which we are
05419     /// performing the instantiation, for substitutions of prior template
05420     /// arguments.
05421     NamedDecl *Template;
05422 
05423     /// \brief The entity that is being instantiated.
05424     uintptr_t Entity;
05425 
05426     /// \brief The list of template arguments we are substituting, if they
05427     /// are not part of the entity.
05428     const TemplateArgument *TemplateArgs;
05429 
05430     /// \brief The number of template arguments in TemplateArgs.
05431     unsigned NumTemplateArgs;
05432 
05433     /// \brief The template deduction info object associated with the
05434     /// substitution or checking of explicit or deduced template arguments.
05435     sema::TemplateDeductionInfo *DeductionInfo;
05436 
05437     /// \brief The source range that covers the construct that cause
05438     /// the instantiation, e.g., the template-id that causes a class
05439     /// template instantiation.
05440     SourceRange InstantiationRange;
05441 
05442     ActiveTemplateInstantiation()
05443       : Kind(TemplateInstantiation), Template(0), Entity(0), TemplateArgs(0),
05444         NumTemplateArgs(0), DeductionInfo(0) {}
05445 
05446     /// \brief Determines whether this template is an actual instantiation
05447     /// that should be counted toward the maximum instantiation depth.
05448     bool isInstantiationRecord() const;
05449 
05450     friend bool operator==(const ActiveTemplateInstantiation &X,
05451                            const ActiveTemplateInstantiation &Y) {
05452       if (X.Kind != Y.Kind)
05453         return false;
05454 
05455       if (X.Entity != Y.Entity)
05456         return false;
05457 
05458       switch (X.Kind) {
05459       case TemplateInstantiation:
05460       case ExceptionSpecInstantiation:
05461         return true;
05462 
05463       case PriorTemplateArgumentSubstitution:
05464       case DefaultTemplateArgumentChecking:
05465         if (X.Template != Y.Template)
05466           return false;
05467 
05468         // Fall through
05469 
05470       case DefaultTemplateArgumentInstantiation:
05471       case ExplicitTemplateArgumentSubstitution:
05472       case DeducedTemplateArgumentSubstitution:
05473       case DefaultFunctionArgumentInstantiation:
05474         return X.TemplateArgs == Y.TemplateArgs;
05475 
05476       }
05477 
05478       llvm_unreachable("Invalid InstantiationKind!");
05479     }
05480 
05481     friend bool operator!=(const ActiveTemplateInstantiation &X,
05482                            const ActiveTemplateInstantiation &Y) {
05483       return !(X == Y);
05484     }
05485   };
05486 
05487   /// \brief List of active template instantiations.
05488   ///
05489   /// This vector is treated as a stack. As one template instantiation
05490   /// requires another template instantiation, additional
05491   /// instantiations are pushed onto the stack up to a
05492   /// user-configurable limit LangOptions::InstantiationDepth.
05493   SmallVector<ActiveTemplateInstantiation, 16>
05494     ActiveTemplateInstantiations;
05495 
05496   /// \brief Whether we are in a SFINAE context that is not associated with
05497   /// template instantiation.
05498   ///
05499   /// This is used when setting up a SFINAE trap (\c see SFINAETrap) outside
05500   /// of a template instantiation or template argument deduction.
05501   bool InNonInstantiationSFINAEContext;
05502 
05503   /// \brief The number of ActiveTemplateInstantiation entries in
05504   /// \c ActiveTemplateInstantiations that are not actual instantiations and,
05505   /// therefore, should not be counted as part of the instantiation depth.
05506   unsigned NonInstantiationEntries;
05507 
05508   /// \brief The last template from which a template instantiation
05509   /// error or warning was produced.
05510   ///
05511   /// This value is used to suppress printing of redundant template
05512   /// instantiation backtraces when there are multiple errors in the
05513   /// same instantiation. FIXME: Does this belong in Sema? It's tough
05514   /// to implement it anywhere else.
05515   ActiveTemplateInstantiation LastTemplateInstantiationErrorContext;
05516 
05517   /// \brief The current index into pack expansion arguments that will be
05518   /// used for substitution of parameter packs.
05519   ///
05520   /// The pack expansion index will be -1 to indicate that parameter packs
05521   /// should be instantiated as themselves. Otherwise, the index specifies
05522   /// which argument within the parameter pack will be used for substitution.
05523   int ArgumentPackSubstitutionIndex;
05524 
05525   /// \brief RAII object used to change the argument pack substitution index
05526   /// within a \c Sema object.
05527   ///
05528   /// See \c ArgumentPackSubstitutionIndex for more information.
05529   class ArgumentPackSubstitutionIndexRAII {
05530     Sema &Self;
05531     int OldSubstitutionIndex;
05532 
05533   public:
05534     ArgumentPackSubstitutionIndexRAII(Sema &Self, int NewSubstitutionIndex)
05535       : Self(Self), OldSubstitutionIndex(Self.ArgumentPackSubstitutionIndex) {
05536       Self.ArgumentPackSubstitutionIndex = NewSubstitutionIndex;
05537     }
05538 
05539     ~ArgumentPackSubstitutionIndexRAII() {
05540       Self.ArgumentPackSubstitutionIndex = OldSubstitutionIndex;
05541     }
05542   };
05543 
05544   friend class ArgumentPackSubstitutionRAII;
05545 
05546   /// \brief The stack of calls expression undergoing template instantiation.
05547   ///
05548   /// The top of this stack is used by a fixit instantiating unresolved
05549   /// function calls to fix the AST to match the textual change it prints.
05550   SmallVector<CallExpr *, 8> CallsUndergoingInstantiation;
05551 
05552   /// \brief For each declaration that involved template argument deduction, the
05553   /// set of diagnostics that were suppressed during that template argument
05554   /// deduction.
05555   ///
05556   /// FIXME: Serialize this structure to the AST file.
05557   llvm::DenseMap<Decl *, SmallVector<PartialDiagnosticAt, 1> >
05558     SuppressedDiagnostics;
05559 
05560   /// \brief A stack object to be created when performing template
05561   /// instantiation.
05562   ///
05563   /// Construction of an object of type \c InstantiatingTemplate
05564   /// pushes the current instantiation onto the stack of active
05565   /// instantiations. If the size of this stack exceeds the maximum
05566   /// number of recursive template instantiations, construction
05567   /// produces an error and evaluates true.
05568   ///
05569   /// Destruction of this object will pop the named instantiation off
05570   /// the stack.
05571   struct InstantiatingTemplate {
05572     /// \brief Note that we are instantiating a class template,
05573     /// function template, or a member thereof.
05574     InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
05575                           Decl *Entity,
05576                           SourceRange InstantiationRange = SourceRange());
05577 
05578     struct ExceptionSpecification {};
05579     /// \brief Note that we are instantiating an exception specification
05580     /// of a function template.
05581     InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
05582                           FunctionDecl *Entity, ExceptionSpecification,
05583                           SourceRange InstantiationRange = SourceRange());
05584 
05585     /// \brief Note that we are instantiating a default argument in a
05586     /// template-id.
05587     InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
05588                           TemplateDecl *Template,
05589                           const TemplateArgument *TemplateArgs,
05590                           unsigned NumTemplateArgs,
05591                           SourceRange InstantiationRange = SourceRange());
05592 
05593     /// \brief Note that we are instantiating a default argument in a
05594     /// template-id.
05595     InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
05596                           FunctionTemplateDecl *FunctionTemplate,
05597                           const TemplateArgument *TemplateArgs,
05598                           unsigned NumTemplateArgs,
05599                           ActiveTemplateInstantiation::InstantiationKind Kind,
05600                           sema::TemplateDeductionInfo &DeductionInfo,
05601                           SourceRange InstantiationRange = SourceRange());
05602 
05603     /// \brief Note that we are instantiating as part of template
05604     /// argument deduction for a class template partial
05605     /// specialization.
05606     InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
05607                           ClassTemplatePartialSpecializationDecl *PartialSpec,
05608                           const TemplateArgument *TemplateArgs,
05609                           unsigned NumTemplateArgs,
05610                           sema::TemplateDeductionInfo &DeductionInfo,
05611                           SourceRange InstantiationRange = SourceRange());
05612 
05613     InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
05614                           ParmVarDecl *Param,
05615                           const TemplateArgument *TemplateArgs,
05616                           unsigned NumTemplateArgs,
05617                           SourceRange InstantiationRange = SourceRange());
05618 
05619     /// \brief Note that we are substituting prior template arguments into a
05620     /// non-type or template template parameter.
05621     InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
05622                           NamedDecl *Template,
05623                           NonTypeTemplateParmDecl *Param,
05624                           const TemplateArgument *TemplateArgs,
05625                           unsigned NumTemplateArgs,
05626                           SourceRange InstantiationRange);
05627 
05628     InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
05629                           NamedDecl *Template,
05630                           TemplateTemplateParmDecl *Param,
05631                           const TemplateArgument *TemplateArgs,
05632                           unsigned NumTemplateArgs,
05633                           SourceRange InstantiationRange);
05634 
05635     /// \brief Note that we are checking the default template argument
05636     /// against the template parameter for a given template-id.
05637     InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
05638                           TemplateDecl *Template,
05639                           NamedDecl *Param,
05640                           const TemplateArgument *TemplateArgs,
05641                           unsigned NumTemplateArgs,
05642                           SourceRange InstantiationRange);
05643 
05644 
05645     /// \brief Note that we have finished instantiating this template.
05646     void Clear();
05647 
05648     ~InstantiatingTemplate() { Clear(); }
05649 
05650     /// \brief Determines whether we have exceeded the maximum
05651     /// recursive template instantiations.
05652     operator bool() const { return Invalid; }
05653 
05654   private:
05655     Sema &SemaRef;
05656     bool Invalid;
05657     bool SavedInNonInstantiationSFINAEContext;
05658     bool CheckInstantiationDepth(SourceLocation PointOfInstantiation,
05659                                  SourceRange InstantiationRange);
05660 
05661     InstantiatingTemplate(const InstantiatingTemplate&); // not implemented
05662 
05663     InstantiatingTemplate&
05664     operator=(const InstantiatingTemplate&); // not implemented
05665   };
05666 
05667   void PrintInstantiationStack();
05668 
05669   /// \brief Determines whether we are currently in a context where
05670   /// template argument substitution failures are not considered
05671   /// errors.
05672   ///
05673   /// \returns An empty \c llvm::Optional if we're not in a SFINAE context.
05674   /// Otherwise, contains a pointer that, if non-NULL, contains the nearest
05675   /// template-deduction context object, which can be used to capture
05676   /// diagnostics that will be suppressed.
05677   llvm::Optional<sema::TemplateDeductionInfo *> isSFINAEContext() const;
05678 
05679   /// \brief RAII class used to determine whether SFINAE has
05680   /// trapped any errors that occur during template argument
05681   /// deduction.`
05682   class SFINAETrap {
05683     Sema &SemaRef;
05684     unsigned PrevSFINAEErrors;
05685     bool PrevInNonInstantiationSFINAEContext;
05686     bool PrevAccessCheckingSFINAE;
05687 
05688   public:
05689     explicit SFINAETrap(Sema &SemaRef, bool AccessCheckingSFINAE = false)
05690       : SemaRef(SemaRef), PrevSFINAEErrors(SemaRef.NumSFINAEErrors),
05691         PrevInNonInstantiationSFINAEContext(
05692                                       SemaRef.InNonInstantiationSFINAEContext),
05693         PrevAccessCheckingSFINAE(SemaRef.AccessCheckingSFINAE)
05694     {
05695       if (!SemaRef.isSFINAEContext())
05696         SemaRef.InNonInstantiationSFINAEContext = true;
05697       SemaRef.AccessCheckingSFINAE = AccessCheckingSFINAE;
05698     }
05699 
05700     ~SFINAETrap() {
05701       SemaRef.NumSFINAEErrors = PrevSFINAEErrors;
05702       SemaRef.InNonInstantiationSFINAEContext
05703         = PrevInNonInstantiationSFINAEContext;
05704       SemaRef.AccessCheckingSFINAE = PrevAccessCheckingSFINAE;
05705     }
05706 
05707     /// \brief Determine whether any SFINAE errors have been trapped.
05708     bool hasErrorOccurred() const {
05709       return SemaRef.NumSFINAEErrors > PrevSFINAEErrors;
05710     }
05711   };
05712 
05713   /// \brief The current instantiation scope used to store local
05714   /// variables.
05715   LocalInstantiationScope *CurrentInstantiationScope;
05716 
05717   /// \brief The number of typos corrected by CorrectTypo.
05718   unsigned TyposCorrected;
05719 
05720   typedef llvm::DenseMap<IdentifierInfo *, TypoCorrection>
05721     UnqualifiedTyposCorrectedMap;
05722 
05723   /// \brief A cache containing the results of typo correction for unqualified
05724   /// name lookup.
05725   ///
05726   /// The string is the string that we corrected to (which may be empty, if
05727   /// there was no correction), while the boolean will be true when the
05728   /// string represents a keyword.
05729   UnqualifiedTyposCorrectedMap UnqualifiedTyposCorrected;
05730 
05731   /// \brief Worker object for performing CFG-based warnings.
05732   sema::AnalysisBasedWarnings AnalysisWarnings;
05733 
05734   /// \brief An entity for which implicit template instantiation is required.
05735   ///
05736   /// The source location associated with the declaration is the first place in
05737   /// the source code where the declaration was "used". It is not necessarily
05738   /// the point of instantiation (which will be either before or after the
05739   /// namespace-scope declaration that triggered this implicit instantiation),
05740   /// However, it is the location that diagnostics should generally refer to,
05741   /// because users will need to know what code triggered the instantiation.
05742   typedef std::pair<ValueDecl *, SourceLocation> PendingImplicitInstantiation;
05743 
05744   /// \brief The queue of implicit template instantiations that are required
05745   /// but have not yet been performed.
05746   std::deque<PendingImplicitInstantiation> PendingInstantiations;
05747 
05748   /// \brief The queue of implicit template instantiations that are required
05749   /// and must be performed within the current local scope.
05750   ///
05751   /// This queue is only used for member functions of local classes in
05752   /// templates, which must be instantiated in the same scope as their
05753   /// enclosing function, so that they can reference function-local
05754   /// types, static variables, enumerators, etc.
05755   std::deque<PendingImplicitInstantiation> PendingLocalImplicitInstantiations;
05756 
05757   void PerformPendingInstantiations(bool LocalOnly = false);
05758 
05759   TypeSourceInfo *SubstType(TypeSourceInfo *T,
05760                             const MultiLevelTemplateArgumentList &TemplateArgs,
05761                             SourceLocation Loc, DeclarationName Entity);
05762 
05763   QualType SubstType(QualType T,
05764                      const MultiLevelTemplateArgumentList &TemplateArgs,
05765                      SourceLocation Loc, DeclarationName Entity);
05766 
05767   TypeSourceInfo *SubstType(TypeLoc TL,
05768                             const MultiLevelTemplateArgumentList &TemplateArgs,
05769                             SourceLocation Loc, DeclarationName Entity);
05770 
05771   TypeSourceInfo *SubstFunctionDeclType(TypeSourceInfo *T,
05772                             const MultiLevelTemplateArgumentList &TemplateArgs,
05773                                         SourceLocation Loc,
05774                                         DeclarationName Entity,
05775                                         CXXRecordDecl *ThisContext,
05776                                         unsigned ThisTypeQuals);
05777   ParmVarDecl *SubstParmVarDecl(ParmVarDecl *D,
05778                             const MultiLevelTemplateArgumentList &TemplateArgs,
05779                                 int indexAdjustment,
05780                                 llvm::Optional<unsigned> NumExpansions,
05781                                 bool ExpectParameterPack);
05782   bool SubstParmTypes(SourceLocation Loc,
05783                       ParmVarDecl **Params, unsigned NumParams,
05784                       const MultiLevelTemplateArgumentList &TemplateArgs,
05785                       SmallVectorImpl<QualType> &ParamTypes,
05786                       SmallVectorImpl<ParmVarDecl *> *OutParams = 0);
05787   ExprResult SubstExpr(Expr *E,
05788                        const MultiLevelTemplateArgumentList &TemplateArgs);
05789 
05790   /// \brief Substitute the given template arguments into a list of
05791   /// expressions, expanding pack expansions if required.
05792   ///
05793   /// \param Exprs The list of expressions to substitute into.
05794   ///
05795   /// \param NumExprs The number of expressions in \p Exprs.
05796   ///
05797   /// \param IsCall Whether this is some form of call, in which case
05798   /// default arguments will be dropped.
05799   ///
05800   /// \param TemplateArgs The set of template arguments to substitute.
05801   ///
05802   /// \param Outputs Will receive all of the substituted arguments.
05803   ///
05804   /// \returns true if an error occurred, false otherwise.
05805   bool SubstExprs(Expr **Exprs, unsigned NumExprs, bool IsCall,
05806                   const MultiLevelTemplateArgumentList &TemplateArgs,
05807                   SmallVectorImpl<Expr *> &Outputs);
05808 
05809   StmtResult SubstStmt(Stmt *S,
05810                        const MultiLevelTemplateArgumentList &TemplateArgs);
05811 
05812   Decl *SubstDecl(Decl *D, DeclContext *Owner,
05813                   const MultiLevelTemplateArgumentList &TemplateArgs);
05814 
05815   ExprResult SubstInitializer(Expr *E,
05816                        const MultiLevelTemplateArgumentList &TemplateArgs,
05817                        bool CXXDirectInit);
05818 
05819   bool
05820   SubstBaseSpecifiers(CXXRecordDecl *Instantiation,
05821                       CXXRecordDecl *Pattern,
05822                       const MultiLevelTemplateArgumentList &TemplateArgs);
05823 
05824   bool
05825   InstantiateClass(SourceLocation PointOfInstantiation,
05826                    CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern,
05827                    const MultiLevelTemplateArgumentList &TemplateArgs,
05828                    TemplateSpecializationKind TSK,
05829                    bool Complain = true);
05830 
05831   bool InstantiateEnum(SourceLocation PointOfInstantiation,
05832                        EnumDecl *Instantiation, EnumDecl *Pattern,
05833                        const MultiLevelTemplateArgumentList &TemplateArgs,
05834                        TemplateSpecializationKind TSK);
05835 
05836   struct LateInstantiatedAttribute {
05837     const Attr *TmplAttr;
05838     LocalInstantiationScope *Scope;
05839     Decl *NewDecl;
05840 
05841     LateInstantiatedAttribute(const Attr *A, LocalInstantiationScope *S,
05842                               Decl *D)
05843       : TmplAttr(A), Scope(S), NewDecl(D)
05844     { }
05845   };
05846   typedef SmallVector<LateInstantiatedAttribute, 16> LateInstantiatedAttrVec;
05847 
05848   void InstantiateAttrs(const MultiLevelTemplateArgumentList &TemplateArgs,
05849                         const Decl *Pattern, Decl *Inst,
05850                         LateInstantiatedAttrVec *LateAttrs = 0,
05851                         LocalInstantiationScope *OuterMostScope = 0);
05852 
05853   bool
05854   InstantiateClassTemplateSpecialization(SourceLocation PointOfInstantiation,
05855                            ClassTemplateSpecializationDecl *ClassTemplateSpec,
05856                            TemplateSpecializationKind TSK,
05857                            bool Complain = true);
05858 
05859   void InstantiateClassMembers(SourceLocation PointOfInstantiation,
05860                                CXXRecordDecl *Instantiation,
05861                             const MultiLevelTemplateArgumentList &TemplateArgs,
05862                                TemplateSpecializationKind TSK);
05863 
05864   void InstantiateClassTemplateSpecializationMembers(
05865                                           SourceLocation PointOfInstantiation,
05866                            ClassTemplateSpecializationDecl *ClassTemplateSpec,
05867                                                 TemplateSpecializationKind TSK);
05868 
05869   NestedNameSpecifierLoc
05870   SubstNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
05871                            const MultiLevelTemplateArgumentList &TemplateArgs);
05872 
05873   DeclarationNameInfo
05874   SubstDeclarationNameInfo(const DeclarationNameInfo &NameInfo,
05875                            const MultiLevelTemplateArgumentList &TemplateArgs);
05876   TemplateName
05877   SubstTemplateName(NestedNameSpecifierLoc QualifierLoc, TemplateName Name,
05878                     SourceLocation Loc,
05879                     const MultiLevelTemplateArgumentList &TemplateArgs);
05880   bool Subst(const TemplateArgumentLoc *Args, unsigned NumArgs,
05881              TemplateArgumentListInfo &Result,
05882              const MultiLevelTemplateArgumentList &TemplateArgs);
05883 
05884   void InstantiateExceptionSpec(SourceLocation PointOfInstantiation,
05885                                 FunctionDecl *Function);
05886   void InstantiateFunctionDefinition(SourceLocation PointOfInstantiation,
05887                                      FunctionDecl *Function,
05888                                      bool Recursive = false,
05889                                      bool DefinitionRequired = false);
05890   void InstantiateStaticDataMemberDefinition(
05891                                      SourceLocation PointOfInstantiation,
05892                                      VarDecl *Var,
05893                                      bool Recursive = false,
05894                                      bool DefinitionRequired = false);
05895 
05896   void InstantiateMemInitializers(CXXConstructorDecl *New,
05897                                   const CXXConstructorDecl *Tmpl,
05898                             const MultiLevelTemplateArgumentList &TemplateArgs);
05899 
05900   NamedDecl *FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D,
05901                           const MultiLevelTemplateArgumentList &TemplateArgs);
05902   DeclContext *FindInstantiatedContext(SourceLocation Loc, DeclContext *DC,
05903                           const MultiLevelTemplateArgumentList &TemplateArgs);
05904 
05905   // Objective-C declarations.
05906   enum ObjCContainerKind {
05907     OCK_None = -1,
05908     OCK_Interface = 0,
05909     OCK_Protocol,
05910     OCK_Category,
05911     OCK_ClassExtension,
05912     OCK_Implementation,
05913     OCK_CategoryImplementation
05914   };
05915   ObjCContainerKind getObjCContainerKind() const;
05916 
05917   Decl *ActOnStartClassInterface(SourceLocation AtInterfaceLoc,
05918                                  IdentifierInfo *ClassName,
05919                                  SourceLocation ClassLoc,
05920                                  IdentifierInfo *SuperName,
05921                                  SourceLocation SuperLoc,
05922                                  Decl * const *ProtoRefs,
05923                                  unsigned NumProtoRefs,
05924                                  const SourceLocation *ProtoLocs,
05925                                  SourceLocation EndProtoLoc,
05926                                  AttributeList *AttrList);
05927 
05928   Decl *ActOnCompatiblityAlias(
05929                     SourceLocation AtCompatibilityAliasLoc,
05930                     IdentifierInfo *AliasName,  SourceLocation AliasLocation,
05931                     IdentifierInfo *ClassName, SourceLocation ClassLocation);
05932 
05933   bool CheckForwardProtocolDeclarationForCircularDependency(
05934     IdentifierInfo *PName,
05935     SourceLocation &PLoc, SourceLocation PrevLoc,
05936     const ObjCList<ObjCProtocolDecl> &PList);
05937 
05938   Decl *ActOnStartProtocolInterface(
05939                     SourceLocation AtProtoInterfaceLoc,
05940                     IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc,
05941                     Decl * const *ProtoRefNames, unsigned NumProtoRefs,
05942                     const SourceLocation *ProtoLocs,
05943                     SourceLocation EndProtoLoc,
05944                     AttributeList *AttrList);
05945 
05946   Decl *ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc,
05947                                     IdentifierInfo *ClassName,
05948                                     SourceLocation ClassLoc,
05949                                     IdentifierInfo *CategoryName,
05950                                     SourceLocation CategoryLoc,
05951                                     Decl * const *ProtoRefs,
05952                                     unsigned NumProtoRefs,
05953                                     const SourceLocation *ProtoLocs,
05954                                     SourceLocation EndProtoLoc);
05955 
05956   Decl *ActOnStartClassImplementation(
05957                     SourceLocation AtClassImplLoc,
05958                     IdentifierInfo *ClassName, SourceLocation ClassLoc,
05959                     IdentifierInfo *SuperClassname,
05960                     SourceLocation SuperClassLoc);
05961 
05962   Decl *ActOnStartCategoryImplementation(SourceLocation AtCatImplLoc,
05963                                          IdentifierInfo *ClassName,
05964                                          SourceLocation ClassLoc,
05965                                          IdentifierInfo *CatName,
05966                                          SourceLocation CatLoc);
05967 
05968   DeclGroupPtrTy ActOnFinishObjCImplementation(Decl *ObjCImpDecl,
05969                                                ArrayRef<Decl *> Decls);
05970 
05971   DeclGroupPtrTy ActOnForwardClassDeclaration(SourceLocation Loc,
05972                                      IdentifierInfo **IdentList,
05973                                      SourceLocation *IdentLocs,
05974                                      unsigned NumElts);
05975 
05976   DeclGroupPtrTy ActOnForwardProtocolDeclaration(SourceLocation AtProtoclLoc,
05977                                         const IdentifierLocPair *IdentList,
05978                                         unsigned NumElts,
05979                                         AttributeList *attrList);
05980 
05981   void FindProtocolDeclaration(bool WarnOnDeclarations,
05982                                const IdentifierLocPair *ProtocolId,
05983                                unsigned NumProtocols,
05984                                SmallVectorImpl<Decl *> &Protocols);
05985 
05986   /// Ensure attributes are consistent with type.
05987   /// \param [in, out] Attributes The attributes to check; they will
05988   /// be modified to be consistent with \arg PropertyTy.
05989   void CheckObjCPropertyAttributes(Decl *PropertyPtrTy,
05990                                    SourceLocation Loc,
05991                                    unsigned &Attributes);
05992 
05993   /// Process the specified property declaration and create decls for the
05994   /// setters and getters as needed.
05995   /// \param property The property declaration being processed
05996   /// \param DC The semantic container for the property
05997   /// \param redeclaredProperty Declaration for property if redeclared
05998   ///        in class extension.
05999   /// \param lexicalDC Container for redeclaredProperty.
06000   void ProcessPropertyDecl(ObjCPropertyDecl *property,
06001                            ObjCContainerDecl *DC,
06002                            ObjCPropertyDecl *redeclaredProperty = 0,
06003                            ObjCContainerDecl *lexicalDC = 0);
06004 
06005   void DiagnosePropertyMismatch(ObjCPropertyDecl *Property,
06006                                 ObjCPropertyDecl *SuperProperty,
06007                                 const IdentifierInfo *Name);
06008   void ComparePropertiesInBaseAndSuper(ObjCInterfaceDecl *IDecl);
06009 
06010 
06011   void CompareProperties(Decl *CDecl, Decl *MergeProtocols);
06012 
06013   void DiagnoseClassExtensionDupMethods(ObjCCategoryDecl *CAT,
06014                                         ObjCInterfaceDecl *ID);
06015 
06016   void MatchOneProtocolPropertiesInClass(Decl *CDecl,
06017                                          ObjCProtocolDecl *PDecl);
06018 
06019   Decl *ActOnAtEnd(Scope *S, SourceRange AtEnd,
06020                    Decl **allMethods = 0, unsigned allNum = 0,
06021                    Decl **allProperties = 0, unsigned pNum = 0,
06022                    DeclGroupPtrTy *allTUVars = 0, unsigned tuvNum = 0);
06023 
06024   Decl *ActOnProperty(Scope *S, SourceLocation AtLoc,
06025                       SourceLocation LParenLoc,
06026                       FieldDeclarator &FD, ObjCDeclSpec &ODS,
06027                       Selector GetterSel, Selector SetterSel,
06028                       bool *OverridingProperty,
06029                       tok::ObjCKeywordKind MethodImplKind,
06030                       DeclContext *lexicalDC = 0);
06031 
06032   Decl *ActOnPropertyImplDecl(Scope *S,
06033                               SourceLocation AtLoc,
06034                               SourceLocation PropertyLoc,
06035                               bool ImplKind,
06036                               IdentifierInfo *PropertyId,
06037                               IdentifierInfo *PropertyIvar,
06038                               SourceLocation PropertyIvarLoc);
06039 
06040   enum ObjCSpecialMethodKind {
06041     OSMK_None,
06042     OSMK_Alloc,
06043     OSMK_New,
06044     OSMK_Copy,
06045     OSMK_RetainingInit,
06046     OSMK_NonRetainingInit
06047   };
06048 
06049   struct ObjCArgInfo {
06050     IdentifierInfo *Name;
06051     SourceLocation NameLoc;
06052     // The Type is null if no type was specified, and the DeclSpec is invalid
06053     // in this case.
06054     ParsedType Type;
06055     ObjCDeclSpec DeclSpec;
06056 
06057     /// ArgAttrs - Attribute list for this argument.
06058     AttributeList *ArgAttrs;
06059   };
06060 
06061   Decl *ActOnMethodDeclaration(
06062     Scope *S,
06063     SourceLocation BeginLoc, // location of the + or -.
06064     SourceLocation EndLoc,   // location of the ; or {.
06065     tok::TokenKind MethodType,
06066     ObjCDeclSpec &ReturnQT, ParsedType ReturnType,
06067     ArrayRef<SourceLocation> SelectorLocs, Selector Sel,
06068     // optional arguments. The number of types/arguments is obtained
06069     // from the Sel.getNumArgs().
06070     ObjCArgInfo *ArgInfo,
06071     DeclaratorChunk::ParamInfo *CParamInfo, unsigned CNumArgs, // c-style args
06072     AttributeList *AttrList, tok::ObjCKeywordKind MethodImplKind,
06073     bool isVariadic, bool MethodDefinition);
06074 
06075   // Helper method for ActOnClassMethod/ActOnInstanceMethod.
06076   // Will search "local" class/category implementations for a method decl.
06077   // Will also search in class's root looking for instance method.
06078   // Returns 0 if no method is found.
06079   ObjCMethodDecl *LookupPrivateClassMethod(Selector Sel,
06080                                            ObjCInterfaceDecl *CDecl);
06081   ObjCMethodDecl *LookupPrivateInstanceMethod(Selector Sel,
06082                                               ObjCInterfaceDecl *ClassDecl);
06083   ObjCMethodDecl *LookupMethodInQualifiedType(Selector Sel,
06084                                               const ObjCObjectPointerType *OPT,
06085                                               bool IsInstance);
06086   ObjCMethodDecl *LookupMethodInObjectType(Selector Sel, QualType Ty,
06087                                            bool IsInstance);
06088 
06089   bool inferObjCARCLifetime(ValueDecl *decl);
06090 
06091   ExprResult
06092   HandleExprPropertyRefExpr(const ObjCObjectPointerType *OPT,
06093                             Expr *BaseExpr,
06094                             SourceLocation OpLoc,
06095                             DeclarationName MemberName,
06096                             SourceLocation MemberLoc,
06097                             SourceLocation SuperLoc, QualType SuperType,
06098                             bool Super);
06099 
06100   ExprResult
06101   ActOnClassPropertyRefExpr(IdentifierInfo &receiverName,
06102                             IdentifierInfo &propertyName,
06103                             SourceLocation receiverNameLoc,
06104                             SourceLocation propertyNameLoc);
06105 
06106   ObjCMethodDecl *tryCaptureObjCSelf(SourceLocation Loc);
06107 
06108   /// \brief Describes the kind of message expression indicated by a message
06109   /// send that starts with an identifier.
06110   enum ObjCMessageKind {
06111     /// \brief The message is sent to 'super'.
06112     ObjCSuperMessage,
06113     /// \brief The message is an instance message.
06114     ObjCInstanceMessage,
06115     /// \brief The message is a class message, and the identifier is a type
06116     /// name.
06117     ObjCClassMessage
06118   };
06119 
06120   ObjCMessageKind getObjCMessageKind(Scope *S,
06121                                      IdentifierInfo *Name,
06122                                      SourceLocation NameLoc,
06123                                      bool IsSuper,
06124                                      bool HasTrailingDot,
06125                                      ParsedType &ReceiverType);
06126 
06127   ExprResult ActOnSuperMessage(Scope *S, SourceLocation SuperLoc,
06128                                Selector Sel,
06129                                SourceLocation LBracLoc,
06130                                ArrayRef<SourceLocation> SelectorLocs,
06131                                SourceLocation RBracLoc,
06132                                MultiExprArg Args);
06133 
06134   ExprResult BuildClassMessage(TypeSourceInfo *ReceiverTypeInfo,
06135                                QualType ReceiverType,
06136                                SourceLocation SuperLoc,
06137                                Selector Sel,
06138                                ObjCMethodDecl *Method,
06139                                SourceLocation LBracLoc,
06140                                ArrayRef<SourceLocation> SelectorLocs,
06141                                SourceLocation RBracLoc,
06142                                MultiExprArg Args,
06143                                bool isImplicit = false);
06144 
06145   ExprResult BuildClassMessageImplicit(QualType ReceiverType,
06146                                        bool isSuperReceiver,
06147                                        SourceLocation Loc,
06148                                        Selector Sel,
06149                                        ObjCMethodDecl *Method,
06150                                        MultiExprArg Args);
06151 
06152   ExprResult ActOnClassMessage(Scope *S,
06153                                ParsedType Receiver,
06154                                Selector Sel,
06155                                SourceLocation LBracLoc,
06156                                ArrayRef<SourceLocation> SelectorLocs,
06157                                SourceLocation RBracLoc,
06158                                MultiExprArg Args);
06159 
06160   ExprResult BuildInstanceMessage(Expr *Receiver,
06161                                   QualType ReceiverType,
06162                                   SourceLocation SuperLoc,
06163                                   Selector Sel,
06164                                   ObjCMethodDecl *Method,
06165                                   SourceLocation LBracLoc,
06166                                   ArrayRef<SourceLocation> SelectorLocs,
06167                                   SourceLocation RBracLoc,
06168                                   MultiExprArg Args,
06169                                   bool isImplicit = false);
06170 
06171   ExprResult BuildInstanceMessageImplicit(Expr *Receiver,
06172                                           QualType ReceiverType,
06173                                           SourceLocation Loc,
06174                                           Selector Sel,
06175                                           ObjCMethodDecl *Method,
06176                                           MultiExprArg Args);
06177 
06178   ExprResult ActOnInstanceMessage(Scope *S,
06179                                   Expr *Receiver,
06180                                   Selector Sel,
06181                                   SourceLocation LBracLoc,
06182                                   ArrayRef<SourceLocation> SelectorLocs,
06183                                   SourceLocation RBracLoc,
06184                                   MultiExprArg Args);
06185 
06186   ExprResult BuildObjCBridgedCast(SourceLocation LParenLoc,
06187                                   ObjCBridgeCastKind Kind,
06188                                   SourceLocation BridgeKeywordLoc,
06189                                   TypeSourceInfo *TSInfo,
06190                                   Expr *SubExpr);
06191 
06192   ExprResult ActOnObjCBridgedCast(Scope *S,
06193                                   SourceLocation LParenLoc,
06194                                   ObjCBridgeCastKind Kind,
06195                                   SourceLocation BridgeKeywordLoc,
06196                                   ParsedType Type,
06197                                   SourceLocation RParenLoc,
06198                                   Expr *SubExpr);
06199 
06200   bool checkInitMethod(ObjCMethodDecl *method, QualType receiverTypeIfCall);
06201 
06202   /// \brief Check whether the given new method is a valid override of the
06203   /// given overridden method, and set any properties that should be inherited.
06204   void CheckObjCMethodOverride(ObjCMethodDecl *NewMethod,
06205                                const ObjCMethodDecl *Overridden,
06206                                bool IsImplementation);
06207 
06208   /// \brief Describes the compatibility of a result type with its method.
06209   enum ResultTypeCompatibilityKind {
06210     RTC_Compatible,
06211     RTC_Incompatible,
06212     RTC_Unknown
06213   };
06214 
06215   void CheckObjCMethodOverrides(ObjCMethodDecl *ObjCMethod,
06216                                 ObjCInterfaceDecl *CurrentClass,
06217                                 ResultTypeCompatibilityKind RTC);
06218 
06219   enum PragmaOptionsAlignKind {
06220     POAK_Native,  // #pragma options align=native
06221     POAK_Natural, // #pragma options align=natural
06222     POAK_Packed,  // #pragma options align=packed
06223     POAK_Power,   // #pragma options align=power
06224     POAK_Mac68k,  // #pragma options align=mac68k
06225     POAK_Reset    // #pragma options align=reset
06226   };
06227 
06228   /// ActOnPragmaOptionsAlign - Called on well formed #pragma options align.
06229   void ActOnPragmaOptionsAlign(PragmaOptionsAlignKind Kind,
06230                                SourceLocation PragmaLoc,
06231                                SourceLocation KindLoc);
06232 
06233   enum PragmaPackKind {
06234     PPK_Default, // #pragma pack([n])
06235     PPK_Show,    // #pragma pack(show), only supported by MSVC.
06236     PPK_Push,    // #pragma pack(push, [identifier], [n])
06237     PPK_Pop      // #pragma pack(pop, [identifier], [n])
06238   };
06239 
06240   enum PragmaMSStructKind {
06241     PMSST_OFF,  // #pragms ms_struct off
06242     PMSST_ON    // #pragms ms_struct on
06243   };
06244 
06245   /// ActOnPragmaPack - Called on well formed #pragma pack(...).
06246   void ActOnPragmaPack(PragmaPackKind Kind,
06247                        IdentifierInfo *Name,
06248                        Expr *Alignment,
06249                        SourceLocation PragmaLoc,
06250                        SourceLocation LParenLoc,
06251                        SourceLocation RParenLoc);
06252 
06253   /// ActOnPragmaMSStruct - Called on well formed #pragms ms_struct [on|off].
06254   void ActOnPragmaMSStruct(PragmaMSStructKind Kind);
06255 
06256   /// ActOnPragmaUnused - Called on well-formed '#pragma unused'.
06257   void ActOnPragmaUnused(const Token &Identifier,
06258                          Scope *curScope,
06259                          SourceLocation PragmaLoc);
06260 
06261   /// ActOnPragmaVisibility - Called on well formed #pragma GCC visibility... .
06262   void ActOnPragmaVisibility(const IdentifierInfo* VisType,
06263                              SourceLocation PragmaLoc);
06264 
06265   NamedDecl *DeclClonePragmaWeak(NamedDecl *ND, IdentifierInfo *II,
06266                                  SourceLocation Loc);
06267   void DeclApplyPragmaWeak(Scope *S, NamedDecl *ND, WeakInfo &W);
06268 
06269   /// ActOnPragmaWeakID - Called on well formed #pragma weak ident.
06270   void ActOnPragmaWeakID(IdentifierInfo* WeakName,
06271                          SourceLocation PragmaLoc,
06272                          SourceLocation WeakNameLoc);
06273 
06274   /// ActOnPragmaRedefineExtname - Called on well formed 
06275   /// #pragma redefine_extname oldname newname.
06276   void ActOnPragmaRedefineExtname(IdentifierInfo* WeakName,
06277                                   IdentifierInfo* AliasName,
06278                                   SourceLocation PragmaLoc,
06279                                   SourceLocation WeakNameLoc,
06280                                   SourceLocation AliasNameLoc);
06281 
06282   /// ActOnPragmaWeakAlias - Called on well formed #pragma weak ident = ident.
06283   void ActOnPragmaWeakAlias(IdentifierInfo* WeakName,
06284                             IdentifierInfo* AliasName,
06285                             SourceLocation PragmaLoc,
06286                             SourceLocation WeakNameLoc,
06287                             SourceLocation AliasNameLoc);
06288 
06289   /// ActOnPragmaFPContract - Called on well formed
06290   /// #pragma {STDC,OPENCL} FP_CONTRACT
06291   void ActOnPragmaFPContract(tok::OnOffSwitch OOS);
06292 
06293   /// AddAlignmentAttributesForRecord - Adds any needed alignment attributes to
06294   /// a the record decl, to handle '#pragma pack' and '#pragma options align'.
06295   void AddAlignmentAttributesForRecord(RecordDecl *RD);
06296 
06297   /// AddMsStructLayoutForRecord - Adds ms_struct layout attribute to record.
06298   void AddMsStructLayoutForRecord(RecordDecl *RD);
06299 
06300   /// FreePackedContext - Deallocate and null out PackContext.
06301   void FreePackedContext();
06302 
06303   /// PushNamespaceVisibilityAttr - Note that we've entered a
06304   /// namespace with a visibility attribute.
06305   void PushNamespaceVisibilityAttr(const VisibilityAttr *Attr,
06306                                    SourceLocation Loc);
06307 
06308   /// AddPushedVisibilityAttribute - If '#pragma GCC visibility' was used,
06309   /// add an appropriate visibility attribute.
06310   void AddPushedVisibilityAttribute(Decl *RD);
06311 
06312   /// PopPragmaVisibility - Pop the top element of the visibility stack; used
06313   /// for '#pragma GCC visibility' and visibility attributes on namespaces.
06314   void PopPragmaVisibility(bool IsNamespaceEnd, SourceLocation EndLoc);
06315 
06316   /// FreeVisContext - Deallocate and null out VisContext.
06317   void FreeVisContext();
06318 
06319   /// AddCFAuditedAttribute - Check whether we're currently within
06320   /// '#pragma clang arc_cf_code_audited' and, if so, consider adding
06321   /// the appropriate attribute.
06322   void AddCFAuditedAttribute(Decl *D);
06323 
06324   /// AddAlignedAttr - Adds an aligned attribute to a particular declaration.
06325   void AddAlignedAttr(SourceRange AttrRange, Decl *D, Expr *E);
06326   void AddAlignedAttr(SourceRange AttrRange, Decl *D, TypeSourceInfo *T);
06327 
06328   /// \brief The kind of conversion being performed.
06329   enum CheckedConversionKind {
06330     /// \brief An implicit conversion.
06331     CCK_ImplicitConversion,
06332     /// \brief A C-style cast.
06333     CCK_CStyleCast,
06334     /// \brief A functional-style cast.
06335     CCK_FunctionalCast,
06336     /// \brief A cast other than a C-style cast.
06337     CCK_OtherCast
06338   };
06339 
06340   /// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit
06341   /// cast.  If there is already an implicit cast, merge into the existing one.
06342   /// If isLvalue, the result of the cast is an lvalue.
06343   ExprResult ImpCastExprToType(Expr *E, QualType Type, CastKind CK,
06344                                ExprValueKind VK = VK_RValue,
06345                                const CXXCastPath *BasePath = 0,
06346                                CheckedConversionKind CCK
06347                                   = CCK_ImplicitConversion);
06348 
06349   /// ScalarTypeToBooleanCastKind - Returns the cast kind corresponding
06350   /// to the conversion from scalar type ScalarTy to the Boolean type.
06351   static CastKind ScalarTypeToBooleanCastKind(QualType ScalarTy);
06352 
06353   /// IgnoredValueConversions - Given that an expression's result is
06354   /// syntactically ignored, perform any conversions that are
06355   /// required.
06356   ExprResult IgnoredValueConversions(Expr *E);
06357 
06358   // UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts
06359   // functions and arrays to their respective pointers (C99 6.3.2.1).
06360   ExprResult UsualUnaryConversions(Expr *E);
06361 
06362   // DefaultFunctionArrayConversion - converts functions and arrays
06363   // to their respective pointers (C99 6.3.2.1).
06364   ExprResult DefaultFunctionArrayConversion(Expr *E);
06365 
06366   // DefaultFunctionArrayLvalueConversion - converts functions and
06367   // arrays to their respective pointers and performs the
06368   // lvalue-to-rvalue conversion.
06369   ExprResult DefaultFunctionArrayLvalueConversion(Expr *E);
06370 
06371   // DefaultLvalueConversion - performs lvalue-to-rvalue conversion on
06372   // the operand.  This is DefaultFunctionArrayLvalueConversion,
06373   // except that it assumes the operand isn't of function or array
06374   // type.
06375   ExprResult DefaultLvalueConversion(Expr *E);
06376 
06377   // DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that
06378   // do not have a prototype. Integer promotions are performed on each
06379   // argument, and arguments that have type float are promoted to double.
06380   ExprResult DefaultArgumentPromotion(Expr *E);
06381 
06382   // Used for emitting the right warning by DefaultVariadicArgumentPromotion
06383   enum VariadicCallType {
06384     VariadicFunction,
06385     VariadicBlock,
06386     VariadicMethod,
06387     VariadicConstructor,
06388     VariadicDoesNotApply
06389   };
06390 
06391   /// GatherArgumentsForCall - Collector argument expressions for various
06392   /// form of call prototypes.
06393   bool GatherArgumentsForCall(SourceLocation CallLoc,
06394                               FunctionDecl *FDecl,
06395                               const FunctionProtoType *Proto,
06396                               unsigned FirstProtoArg,
06397                               Expr **Args, unsigned NumArgs,
06398                               SmallVector<Expr *, 8> &AllArgs,
06399                               VariadicCallType CallType = VariadicDoesNotApply,
06400                               bool AllowExplicit = false);
06401 
06402   // DefaultVariadicArgumentPromotion - Like DefaultArgumentPromotion, but
06403   // will warn if the resulting type is not a POD type.
06404   ExprResult DefaultVariadicArgumentPromotion(Expr *E, VariadicCallType CT,
06405                                               FunctionDecl *FDecl);
06406 
06407   // UsualArithmeticConversions - performs the UsualUnaryConversions on it's
06408   // operands and then handles various conversions that are common to binary
06409   // operators (C99 6.3.1.8). If both operands aren't arithmetic, this
06410   // routine returns the first non-arithmetic type found. The client is
06411   // responsible for emitting appropriate error diagnostics.
06412   QualType UsualArithmeticConversions(ExprResult &LHS, ExprResult &RHS,
06413                                       bool IsCompAssign = false);
06414 
06415   /// AssignConvertType - All of the 'assignment' semantic checks return this
06416   /// enum to indicate whether the assignment was allowed.  These checks are
06417   /// done for simple assignments, as well as initialization, return from
06418   /// function, argument passing, etc.  The query is phrased in terms of a
06419   /// source and destination type.
06420   enum AssignConvertType {
06421     /// Compatible - the types are compatible according to the standard.
06422     Compatible,
06423 
06424     /// PointerToInt - The assignment converts a pointer to an int, which we
06425     /// accept as an extension.
06426     PointerToInt,
06427 
06428     /// IntToPointer - The assignment converts an int to a pointer, which we
06429     /// accept as an extension.
06430     IntToPointer,
06431 
06432     /// FunctionVoidPointer - The assignment is between a function pointer and
06433     /// void*, which the standard doesn't allow, but we accept as an extension.
06434     FunctionVoidPointer,
06435 
06436     /// IncompatiblePointer - The assignment is between two pointers types that
06437     /// are not compatible, but we accept them as an extension.
06438     IncompatiblePointer,
06439 
06440     /// IncompatiblePointer - The assignment is between two pointers types which
06441     /// point to integers which have a different sign, but are otherwise
06442     /// identical. This is a subset of the above, but broken out because it's by
06443     /// far the most common case of incompatible pointers.
06444     IncompatiblePointerSign,
06445 
06446     /// CompatiblePointerDiscardsQualifiers - The assignment discards
06447     /// c/v/r qualifiers, which we accept as an extension.
06448     CompatiblePointerDiscardsQualifiers,
06449 
06450     /// IncompatiblePointerDiscardsQualifiers - The assignment
06451     /// discards qualifiers that we don't permit to be discarded,
06452     /// like address spaces.
06453     IncompatiblePointerDiscardsQualifiers,
06454 
06455     /// IncompatibleNestedPointerQualifiers - The assignment is between two
06456     /// nested pointer types, and the qualifiers other than the first two
06457     /// levels differ e.g. char ** -> const char **, but we accept them as an
06458     /// extension.
06459     IncompatibleNestedPointerQualifiers,
06460 
06461     /// IncompatibleVectors - The assignment is between two vector types that
06462     /// have the same size, which we accept as an extension.
06463     IncompatibleVectors,
06464 
06465     /// IntToBlockPointer - The assignment converts an int to a block
06466     /// pointer. We disallow this.
06467     IntToBlockPointer,
06468 
06469     /// IncompatibleBlockPointer - The assignment is between two block
06470     /// pointers types that are not compatible.
06471     IncompatibleBlockPointer,
06472 
06473     /// IncompatibleObjCQualifiedId - The assignment is between a qualified
06474     /// id type and something else (that is incompatible with it). For example,
06475     /// "id <XXX>" = "Foo *", where "Foo *" doesn't implement the XXX protocol.
06476     IncompatibleObjCQualifiedId,
06477 
06478     /// IncompatibleObjCWeakRef - Assigning a weak-unavailable object to an
06479     /// object with __weak qualifier.
06480     IncompatibleObjCWeakRef,
06481 
06482     /// Incompatible - We reject this conversion outright, it is invalid to
06483     /// represent it in the AST.
06484     Incompatible
06485   };
06486 
06487   /// DiagnoseAssignmentResult - Emit a diagnostic, if required, for the
06488   /// assignment conversion type specified by ConvTy.  This returns true if the
06489   /// conversion was invalid or false if the conversion was accepted.
06490   bool DiagnoseAssignmentResult(AssignConvertType ConvTy,
06491                                 SourceLocation Loc,
06492                                 QualType DstType, QualType SrcType,
06493                                 Expr *SrcExpr, AssignmentAction Action,
06494                                 bool *Complained = 0);
06495 
06496   /// CheckAssignmentConstraints - Perform type checking for assignment,
06497   /// argument passing, variable initialization, and function return values.
06498   /// C99 6.5.16.
06499   AssignConvertType CheckAssignmentConstraints(SourceLocation Loc,
06500                                                QualType LHSType,
06501                                                QualType RHSType);
06502 
06503   /// Check assignment constraints and prepare for a conversion of the
06504   /// RHS to the LHS type.
06505   AssignConvertType CheckAssignmentConstraints(QualType LHSType,
06506                                                ExprResult &RHS,
06507                                                CastKind &Kind);
06508 
06509   // CheckSingleAssignmentConstraints - Currently used by
06510   // CheckAssignmentOperands, and ActOnReturnStmt. Prior to type checking,
06511   // this routine performs the default function/array converions.
06512   AssignConvertType CheckSingleAssignmentConstraints(QualType LHSType,
06513                                                      ExprResult &RHS,
06514                                                      bool Diagnose = true);
06515 
06516   // \brief If the lhs type is a transparent union, check whether we
06517   // can initialize the transparent union with the given expression.
06518   AssignConvertType CheckTransparentUnionArgumentConstraints(QualType ArgType,
06519                                                              ExprResult &RHS);
06520 
06521   bool IsStringLiteralToNonConstPointerConversion(Expr *From, QualType ToType);
06522 
06523   bool CheckExceptionSpecCompatibility(Expr *From, QualType ToType);
06524 
06525   ExprResult PerformImplicitConversion(Expr *From, QualType ToType,
06526                                        AssignmentAction Action,
06527                                        bool AllowExplicit = false);
06528   ExprResult PerformImplicitConversion(Expr *From, QualType ToType,
06529                                        AssignmentAction Action,
06530                                        bool AllowExplicit,
06531                                        ImplicitConversionSequence& ICS);
06532   ExprResult PerformImplicitConversion(Expr *From, QualType ToType,
06533                                        const ImplicitConversionSequence& ICS,
06534                                        AssignmentAction Action,
06535                                        CheckedConversionKind CCK
06536                                           = CCK_ImplicitConversion);
06537   ExprResult PerformImplicitConversion(Expr *From, QualType ToType,
06538                                        const StandardConversionSequence& SCS,
06539                                        AssignmentAction Action,
06540                                        CheckedConversionKind CCK);
06541 
06542   /// the following "Check" methods will return a valid/converted QualType
06543   /// or a null QualType (indicating an error diagnostic was issued).
06544 
06545   /// type checking binary operators (subroutines of CreateBuiltinBinOp).
06546   QualType InvalidOperands(SourceLocation Loc, ExprResult &LHS,
06547                            ExprResult &RHS);
06548   QualType CheckPointerToMemberOperands( // C++ 5.5
06549     ExprResult &LHS, ExprResult &RHS, ExprValueKind &VK,
06550     SourceLocation OpLoc, bool isIndirect);
06551   QualType CheckMultiplyDivideOperands( // C99 6.5.5
06552     ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, bool IsCompAssign,
06553     bool IsDivide);
06554   QualType CheckRemainderOperands( // C99 6.5.5
06555     ExprResult &LHS, ExprResult &RHS, SourceLocation Loc,
06556     bool IsCompAssign = false);
06557   QualType CheckAdditionOperands( // C99 6.5.6
06558     ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, unsigned Opc,
06559     QualType* CompLHSTy = 0);
06560   QualType CheckSubtractionOperands( // C99 6.5.6
06561     ExprResult &LHS, ExprResult &RHS, SourceLocation Loc,
06562     QualType* CompLHSTy = 0);
06563   QualType CheckShiftOperands( // C99 6.5.7
06564     ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, unsigned Opc,
06565     bool IsCompAssign = false);
06566   QualType CheckCompareOperands( // C99 6.5.8/9
06567     ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, unsigned OpaqueOpc,
06568                                 bool isRelational);
06569   QualType CheckBitwiseOperands( // C99 6.5.[10...12]
06570     ExprResult &LHS, ExprResult &RHS, SourceLocation Loc,
06571     bool IsCompAssign = false);
06572   QualType CheckLogicalOperands( // C99 6.5.[13,14]
06573     ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, unsigned Opc);
06574   // CheckAssignmentOperands is used for both simple and compound assignment.
06575   // For simple assignment, pass both expressions and a null converted type.
06576   // For compound assignment, pass both expressions and the converted type.
06577   QualType CheckAssignmentOperands( // C99 6.5.16.[1,2]
06578     Expr *LHSExpr, ExprResult &RHS, SourceLocation Loc, QualType CompoundType);
06579 
06580   ExprResult checkPseudoObjectIncDec(Scope *S, SourceLocation OpLoc,
06581                                      UnaryOperatorKind Opcode, Expr *Op);
06582   ExprResult checkPseudoObjectAssignment(Scope *S, SourceLocation OpLoc,
06583                                          BinaryOperatorKind Opcode,
06584                                          Expr *LHS, Expr *RHS);
06585   ExprResult checkPseudoObjectRValue(Expr *E);
06586   Expr *recreateSyntacticForm(PseudoObjectExpr *E);
06587 
06588   QualType CheckConditionalOperands( // C99 6.5.15
06589     ExprResult &Cond, ExprResult &LHS, ExprResult &RHS,
06590     ExprValueKind &VK, ExprObjectKind &OK, SourceLocation QuestionLoc);
06591   QualType CXXCheckConditionalOperands( // C++ 5.16
06592     ExprResult &cond, ExprResult &lhs, ExprResult &rhs,
06593     ExprValueKind &VK, ExprObjectKind &OK, SourceLocation questionLoc);
06594   QualType FindCompositePointerType(SourceLocation Loc, Expr *&E1, Expr *&E2,
06595                                     bool *NonStandardCompositeType = 0);
06596   QualType FindCompositePointerType(SourceLocation Loc,
06597                                     ExprResult &E1, ExprResult &E2,
06598                                     bool *NonStandardCompositeType = 0) {
06599     Expr *E1Tmp = E1.take(), *E2Tmp = E2.take();
06600     QualType Composite = FindCompositePointerType(Loc, E1Tmp, E2Tmp,
06601                                                   NonStandardCompositeType);
06602     E1 = Owned(E1Tmp);
06603     E2 = Owned(E2Tmp);
06604     return Composite;
06605   }
06606 
06607   QualType FindCompositeObjCPointerType(ExprResult &LHS, ExprResult &RHS,
06608                                         SourceLocation QuestionLoc);
06609 
06610   bool DiagnoseConditionalForNull(Expr *LHSExpr, Expr *RHSExpr,
06611                                   SourceLocation QuestionLoc);
06612 
06613   /// type checking for vector binary operators.
06614   QualType CheckVectorOperands(ExprResult &LHS, ExprResult &RHS,
06615                                SourceLocation Loc, bool IsCompAssign);
06616   QualType GetSignedVectorType(QualType V);
06617   QualType CheckVectorCompareOperands(ExprResult &LHS, ExprResult &RHS,
06618                                       SourceLocation Loc, bool isRelational);
06619   QualType CheckVectorLogicalOperands(ExprResult &LHS, ExprResult &RHS,
06620                                       SourceLocation Loc);
06621 
06622   /// type checking declaration initializers (C99 6.7.8)
06623   bool CheckForConstantInitializer(Expr *e, QualType t);
06624 
06625   // type checking C++ declaration initializers (C++ [dcl.init]).
06626 
06627   /// ReferenceCompareResult - Expresses the result of comparing two
06628   /// types (cv1 T1 and cv2 T2) to determine their compatibility for the
06629   /// purposes of initialization by reference (C++ [dcl.init.ref]p4).
06630   enum ReferenceCompareResult {
06631     /// Ref_Incompatible - The two types are incompatible, so direct
06632     /// reference binding is not possible.
06633     Ref_Incompatible = 0,
06634     /// Ref_Related - The two types are reference-related, which means
06635     /// that their unqualified forms (T1 and T2) are either the same
06636     /// or T1 is a base class of T2.
06637     Ref_Related,
06638     /// Ref_Compatible_With_Added_Qualification - The two types are
06639     /// reference-compatible with added qualification, meaning that
06640     /// they are reference-compatible and the qualifiers on T1 (cv1)
06641     /// are greater than the qualifiers on T2 (cv2).
06642     Ref_Compatible_With_Added_Qualification,
06643     /// Ref_Compatible - The two types are reference-compatible and
06644     /// have equivalent qualifiers (cv1 == cv2).
06645     Ref_Compatible
06646   };
06647 
06648   ReferenceCompareResult CompareReferenceRelationship(SourceLocation Loc,
06649                                                       QualType T1, QualType T2,
06650                                                       bool &DerivedToBase,
06651                                                       bool &ObjCConversion,
06652                                                 bool &ObjCLifetimeConversion);
06653 
06654   ExprResult checkUnknownAnyCast(SourceRange TypeRange, QualType CastType,
06655                                  Expr *CastExpr, CastKind &CastKind,
06656                                  ExprValueKind &VK, CXXCastPath &Path);
06657 
06658   /// \brief Force an expression with unknown-type to an expression of the
06659   /// given type.
06660   ExprResult forceUnknownAnyToType(Expr *E, QualType ToType);
06661                              
06662   // CheckVectorCast - check type constraints for vectors.
06663   // Since vectors are an extension, there are no C standard reference for this.
06664   // We allow casting between vectors and integer datatypes of the same size.
06665   // returns true if the cast is invalid
06666   bool CheckVectorCast(SourceRange R, QualType VectorTy, QualType Ty,
06667                        CastKind &Kind);
06668 
06669   // CheckExtVectorCast - check type constraints for extended vectors.
06670   // Since vectors are an extension, there are no C standard reference for this.
06671   // We allow casting between vectors and integer datatypes of the same size,
06672   // or vectors and the element type of that vector.
06673   // returns the cast expr
06674   ExprResult CheckExtVectorCast(SourceRange R, QualType DestTy, Expr *CastExpr,
06675                                 CastKind &Kind);
06676 
06677   ExprResult BuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
06678                                         SourceLocation LParenLoc,
06679                                         Expr *CastExpr,
06680                                         SourceLocation RParenLoc);
06681 
06682   enum ARCConversionResult { ACR_okay, ACR_unbridged };
06683 
06684   /// \brief Checks for invalid conversions and casts between
06685   /// retainable pointers and other pointer kinds.
06686   ARCConversionResult CheckObjCARCConversion(SourceRange castRange,
06687                                              QualType castType, Expr *&op,
06688                                              CheckedConversionKind CCK);
06689 
06690   Expr *stripARCUnbridgedCast(Expr *e);
06691   void diagnoseARCUnbridgedCast(Expr *e);
06692 
06693   bool CheckObjCARCUnavailableWeakConversion(QualType castType,
06694                                              QualType ExprType);
06695 
06696   /// checkRetainCycles - Check whether an Objective-C message send
06697   /// might create an obvious retain cycle.
06698   void checkRetainCycles(ObjCMessageExpr *msg);
06699   void checkRetainCycles(Expr *receiver, Expr *argument);
06700 
06701   /// checkUnsafeAssigns - Check whether +1 expr is being assigned
06702   /// to weak/__unsafe_unretained type.
06703   bool checkUnsafeAssigns(SourceLocation Loc, QualType LHS, Expr *RHS);
06704 
06705   /// checkUnsafeExprAssigns - Check whether +1 expr is being assigned
06706   /// to weak/__unsafe_unretained expression.
06707   void checkUnsafeExprAssigns(SourceLocation Loc, Expr *LHS, Expr *RHS);
06708 
06709   /// CheckMessageArgumentTypes - Check types in an Obj-C message send.
06710   /// \param Method - May be null.
06711   /// \param [out] ReturnType - The return type of the send.
06712   /// \return true iff there were any incompatible types.
06713   bool CheckMessageArgumentTypes(QualType ReceiverType,
06714                                  Expr **Args, unsigned NumArgs, Selector Sel,
06715                                  ObjCMethodDecl *Method, bool isClassMessage,
06716                                  bool isSuperMessage,
06717                                  SourceLocation lbrac, SourceLocation rbrac,
06718                                  QualType &ReturnType, ExprValueKind &VK);
06719 
06720   /// \brief Determine the result of a message send expression based on
06721   /// the type of the receiver, the method expected to receive the message,
06722   /// and the form of the message send.
06723   QualType getMessageSendResultType(QualType ReceiverType,
06724                                     ObjCMethodDecl *Method,
06725                                     bool isClassMessage, bool isSuperMessage);
06726 
06727   /// \brief If the given expression involves a message send to a method
06728   /// with a related result type, emit a note describing what happened.
06729   void EmitRelatedResultTypeNote(const Expr *E);
06730 
06731   /// CheckBooleanCondition - Diagnose problems involving the use of
06732   /// the given expression as a boolean condition (e.g. in an if
06733   /// statement).  Also performs the standard function and array
06734   /// decays, possibly changing the input variable.
06735   ///
06736   /// \param Loc - A location associated with the condition, e.g. the
06737   /// 'if' keyword.
06738   /// \return true iff there were any errors
06739   ExprResult CheckBooleanCondition(Expr *E, SourceLocation Loc);
06740 
06741   ExprResult ActOnBooleanCondition(Scope *S, SourceLocation Loc,
06742                                    Expr *SubExpr);
06743 
06744   /// DiagnoseAssignmentAsCondition - Given that an expression is
06745   /// being used as a boolean condition, warn if it's an assignment.
06746   void DiagnoseAssignmentAsCondition(Expr *E);
06747 
06748   /// \brief Redundant parentheses over an equality comparison can indicate
06749   /// that the user intended an assignment used as condition.
06750   void DiagnoseEqualityWithExtraParens(ParenExpr *ParenE);
06751 
06752   /// CheckCXXBooleanCondition - Returns true if conversion to bool is invalid.
06753   ExprResult CheckCXXBooleanCondition(Expr *CondExpr);
06754 
06755   /// ConvertIntegerToTypeWarnOnOverflow - Convert the specified APInt to have
06756   /// the specified width and sign.  If an overflow occurs, detect it and emit
06757   /// the specified diagnostic.
06758   void ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &OldVal,
06759                                           unsigned NewWidth, bool NewSign,
06760                                           SourceLocation Loc, unsigned DiagID);
06761 
06762   /// Checks that the Objective-C declaration is declared in the global scope.
06763   /// Emits an error and marks the declaration as invalid if it's not declared
06764   /// in the global scope.
06765   bool CheckObjCDeclScope(Decl *D);
06766 
06767   /// \brief Abstract base class used for diagnosing integer constant
06768   /// expression violations.
06769   class VerifyICEDiagnoser {
06770   public:
06771     bool Suppress;
06772     
06773     VerifyICEDiagnoser(bool Suppress = false) : Suppress(Suppress) { }
06774     
06775     virtual void diagnoseNotICE(Sema &S, SourceLocation Loc, SourceRange SR) =0;
06776     virtual void diagnoseFold(Sema &S, SourceLocation Loc, SourceRange SR);
06777     virtual ~VerifyICEDiagnoser() { }
06778   };
06779     
06780   /// VerifyIntegerConstantExpression - Verifies that an expression is an ICE,
06781   /// and reports the appropriate diagnostics. Returns false on success.
06782   /// Can optionally return the value of the expression.
06783   ExprResult VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result,
06784                                              VerifyICEDiagnoser &Diagnoser,
06785                                              bool AllowFold = true);
06786   ExprResult VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result,
06787                                              unsigned DiagID,
06788                                              bool AllowFold = true);
06789   ExprResult VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result=0);
06790 
06791   /// VerifyBitField - verifies that a bit field expression is an ICE and has
06792   /// the correct width, and that the field type is valid.
06793   /// Returns false on success.
06794   /// Can optionally return whether the bit-field is of width 0
06795   ExprResult VerifyBitField(SourceLocation FieldLoc, IdentifierInfo *FieldName,
06796                             QualType FieldTy, Expr *BitWidth,
06797                             bool *ZeroWidth = 0);
06798 
06799   enum CUDAFunctionTarget {
06800     CFT_Device,
06801     CFT_Global,
06802     CFT_Host,
06803     CFT_HostDevice
06804   };
06805 
06806   CUDAFunctionTarget IdentifyCUDATarget(const FunctionDecl *D);
06807 
06808   bool CheckCUDATarget(CUDAFunctionTarget CallerTarget,
06809                        CUDAFunctionTarget CalleeTarget);
06810 
06811   bool CheckCUDATarget(const FunctionDecl *Caller, const FunctionDecl *Callee) {
06812     return CheckCUDATarget(IdentifyCUDATarget(Caller),
06813                            IdentifyCUDATarget(Callee));
06814   }
06815 
06816   /// \name Code completion
06817   //@{
06818   /// \brief Describes the context in which code completion occurs.
06819   enum ParserCompletionContext {
06820     /// \brief Code completion occurs at top-level or namespace context.
06821     PCC_Namespace,
06822     /// \brief Code completion occurs within a class, struct, or union.
06823     PCC_Class,
06824     /// \brief Code completion occurs within an Objective-C interface, protocol,
06825     /// or category.
06826     PCC_ObjCInterface,
06827     /// \brief Code completion occurs within an Objective-C implementation or
06828     /// category implementation
06829     PCC_ObjCImplementation,
06830     /// \brief Code completion occurs within the list of instance variables
06831     /// in an Objective-C interface, protocol, category, or implementation.
06832     PCC_ObjCInstanceVariableList,
06833     /// \brief Code completion occurs following one or more template
06834     /// headers.
06835     PCC_Template,
06836     /// \brief Code completion occurs following one or more template
06837     /// headers within a class.
06838     PCC_MemberTemplate,
06839     /// \brief Code completion occurs within an expression.
06840     PCC_Expression,
06841     /// \brief Code completion occurs within a statement, which may
06842     /// also be an expression or a declaration.
06843     PCC_Statement,
06844     /// \brief Code completion occurs at the beginning of the
06845     /// initialization statement (or expression) in a for loop.
06846     PCC_ForInit,
06847     /// \brief Code completion occurs within the condition of an if,
06848     /// while, switch, or for statement.
06849     PCC_Condition,
06850     /// \brief Code completion occurs within the body of a function on a
06851     /// recovery path, where we do not have a specific handle on our position
06852     /// in the grammar.
06853     PCC_RecoveryInFunction,
06854     /// \brief Code completion occurs where only a type is permitted.
06855     PCC_Type,
06856     /// \brief Code completion occurs in a parenthesized expression, which
06857     /// might also be a type cast.
06858     PCC_ParenthesizedExpression,
06859     /// \brief Code completion occurs within a sequence of declaration
06860     /// specifiers within a function, method, or block.
06861     PCC_LocalDeclarationSpecifiers
06862   };
06863 
06864   void CodeCompleteModuleImport(SourceLocation ImportLoc, ModuleIdPath Path);
06865   void CodeCompleteOrdinaryName(Scope *S,
06866                                 ParserCompletionContext CompletionContext);
06867   void CodeCompleteDeclSpec(Scope *S, DeclSpec &DS,
06868                             bool AllowNonIdentifiers,
06869                             bool AllowNestedNameSpecifiers);
06870 
06871   struct CodeCompleteExpressionData;
06872   void CodeCompleteExpression(Scope *S,
06873                               const CodeCompleteExpressionData &Data);
06874   void CodeCompleteMemberReferenceExpr(Scope *S, Expr *Base,
06875                                        SourceLocation OpLoc,
06876                                        bool IsArrow);
06877   void CodeCompletePostfixExpression(Scope *S, ExprResult LHS);
06878   void CodeCompleteTag(Scope *S, unsigned TagSpec);
06879   void CodeCompleteTypeQualifiers(DeclSpec &DS);
06880   void CodeCompleteCase(Scope *S);
06881   void CodeCompleteCall(Scope *S, Expr *Fn, llvm::ArrayRef<Expr *> Args);
06882   void CodeCompleteInitializer(Scope *S, Decl *D);
06883   void CodeCompleteReturn(Scope *S);
06884   void CodeCompleteAfterIf(Scope *S);
06885   void CodeCompleteAssignmentRHS(Scope *S, Expr *LHS);
06886 
06887   void CodeCompleteQualifiedId(Scope *S, CXXScopeSpec &SS,
06888                                bool EnteringContext);
06889   void CodeCompleteUsing(Scope *S);
06890   void CodeCompleteUsingDirective(Scope *S);
06891   void CodeCompleteNamespaceDecl(Scope *S);
06892   void CodeCompleteNamespaceAliasDecl(Scope *S);
06893   void CodeCompleteOperatorName(Scope *S);
06894   void CodeCompleteConstructorInitializer(Decl *Constructor,
06895                                           CXXCtorInitializer** Initializers,
06896                                           unsigned NumInitializers);
06897   void CodeCompleteLambdaIntroducer(Scope *S, LambdaIntroducer &Intro,
06898                                     bool AfterAmpersand);
06899 
06900   void CodeCompleteObjCAtDirective(Scope *S);
06901   void CodeCompleteObjCAtVisibility(Scope *S);
06902   void CodeCompleteObjCAtStatement(Scope *S);
06903   void CodeCompleteObjCAtExpression(Scope *S);
06904   void CodeCompleteObjCPropertyFlags(Scope *S, ObjCDeclSpec &ODS);
06905   void CodeCompleteObjCPropertyGetter(Scope *S);
06906   void CodeCompleteObjCPropertySetter(Scope *S);
06907   void CodeCompleteObjCPassingType(Scope *S, ObjCDeclSpec &DS,
06908                                    bool IsParameter);
06909   void CodeCompleteObjCMessageReceiver(Scope *S);
06910   void CodeCompleteObjCSuperMessage(Scope *S, SourceLocation SuperLoc,
06911                                     IdentifierInfo **SelIdents,
06912                                     unsigned NumSelIdents,
06913                                     bool AtArgumentExpression);
06914   void CodeCompleteObjCClassMessage(Scope *S, ParsedType Receiver,
06915                                     IdentifierInfo **SelIdents,
06916                                     unsigned NumSelIdents,
06917                                     bool AtArgumentExpression,
06918                                     bool IsSuper = false);
06919   void CodeCompleteObjCInstanceMessage(Scope *S, Expr *Receiver,
06920                                        IdentifierInfo **SelIdents,
06921                                        unsigned NumSelIdents,
06922                                        bool AtArgumentExpression,
06923                                        ObjCInterfaceDecl *Super = 0);
06924   void CodeCompleteObjCForCollection(Scope *S,
06925                                      DeclGroupPtrTy IterationVar);
06926   void CodeCompleteObjCSelector(Scope *S,
06927                                 IdentifierInfo **SelIdents,
06928                                 unsigned NumSelIdents);
06929   void CodeCompleteObjCProtocolReferences(IdentifierLocPair *Protocols,
06930                                           unsigned NumProtocols);
06931   void CodeCompleteObjCProtocolDecl(Scope *S);
06932   void CodeCompleteObjCInterfaceDecl(Scope *S);
06933   void CodeCompleteObjCSuperclass(Scope *S,
06934                                   IdentifierInfo *ClassName,
06935                                   SourceLocation ClassNameLoc);
06936   void CodeCompleteObjCImplementationDecl(Scope *S);
06937   void CodeCompleteObjCInterfaceCategory(Scope *S,
06938                                          IdentifierInfo *ClassName,
06939                                          SourceLocation ClassNameLoc);
06940   void CodeCompleteObjCImplementationCategory(Scope *S,
06941                                               IdentifierInfo *ClassName,
06942                                               SourceLocation ClassNameLoc);
06943   void CodeCompleteObjCPropertyDefinition(Scope *S);
06944   void CodeCompleteObjCPropertySynthesizeIvar(Scope *S,
06945                                               IdentifierInfo *PropertyName);
06946   void CodeCompleteObjCMethodDecl(Scope *S,
06947                                   bool IsInstanceMethod,
06948                                   ParsedType ReturnType);
06949   void CodeCompleteObjCMethodDeclSelector(Scope *S,
06950                                           bool IsInstanceMethod,
06951                                           bool AtParameterName,
06952                                           ParsedType ReturnType,
06953                                           IdentifierInfo **SelIdents,
06954                                           unsigned NumSelIdents);
06955   void CodeCompletePreprocessorDirective(bool InConditional);
06956   void CodeCompleteInPreprocessorConditionalExclusion(Scope *S);
06957   void CodeCompletePreprocessorMacroName(bool IsDefinition);
06958   void CodeCompletePreprocessorExpression();
06959   void CodeCompletePreprocessorMacroArgument(Scope *S,
06960                                              IdentifierInfo *Macro,
06961                                              MacroInfo *MacroInfo,
06962                                              unsigned Argument);
06963   void CodeCompleteNaturalLanguage();
06964   void GatherGlobalCodeCompletions(CodeCompletionAllocator &Allocator,
06965                                    CodeCompletionTUInfo &CCTUInfo,
06966                   SmallVectorImpl<CodeCompletionResult> &Results);
06967   //@}
06968 
06969   //===--------------------------------------------------------------------===//
06970   // Extra semantic analysis beyond the C type system
06971 
06972 public:
06973   SourceLocation getLocationOfStringLiteralByte(const StringLiteral *SL,
06974                                                 unsigned ByteNo) const;
06975 
06976 private:
06977   void CheckArrayAccess(const Expr *BaseExpr, const Expr *IndexExpr,
06978                         const ArraySubscriptExpr *ASE=0,
06979                         bool AllowOnePastEnd=true, bool IndexNegated=false);
06980   void CheckArrayAccess(const Expr *E);
06981   bool CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall);
06982   bool CheckObjCMethodCall(ObjCMethodDecl *Method, SourceLocation loc, 
06983                            Expr **Args, unsigned NumArgs);
06984   bool CheckBlockCall(NamedDecl *NDecl, CallExpr *TheCall);
06985 
06986   bool CheckObjCString(Expr *Arg);
06987 
06988   ExprResult CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
06989   bool CheckARMBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
06990 
06991   bool SemaBuiltinVAStart(CallExpr *TheCall);
06992   bool SemaBuiltinUnorderedCompare(CallExpr *TheCall);
06993   bool SemaBuiltinFPClassification(CallExpr *TheCall, unsigned NumArgs);
06994 
06995 public:
06996   // Used by C++ template instantiation.
06997   ExprResult SemaBuiltinShuffleVector(CallExpr *TheCall);
06998 
06999 private:
07000   bool SemaBuiltinPrefetch(CallExpr *TheCall);
07001   bool SemaBuiltinObjectSize(CallExpr *TheCall);
07002   bool SemaBuiltinLongjmp(CallExpr *TheCall);
07003   ExprResult SemaBuiltinAtomicOverloaded(ExprResult TheCallResult);
07004   ExprResult SemaAtomicOpsOverloaded(ExprResult TheCallResult,
07005                                      AtomicExpr::AtomicOp Op);
07006   bool SemaBuiltinConstantArg(CallExpr *TheCall, int ArgNum,
07007                               llvm::APSInt &Result);
07008 
07009   enum FormatStringType {
07010     FST_Scanf,
07011     FST_Printf,
07012     FST_NSString,
07013     FST_Strftime,
07014     FST_Strfmon,
07015     FST_Kprintf,
07016     FST_Unknown
07017   };
07018   static FormatStringType GetFormatStringType(const FormatAttr *Format);
07019   bool SemaCheckStringLiteral(const Expr *E, Expr **Args, unsigned NumArgs,
07020                               bool HasVAListArg, unsigned format_idx,
07021                               unsigned firstDataArg, FormatStringType Type,
07022                               bool inFunctionCall = true);
07023 
07024   void CheckFormatString(const StringLiteral *FExpr, const Expr *OrigFormatExpr,
07025                          Expr **Args, unsigned NumArgs, bool HasVAListArg,
07026                          unsigned format_idx, unsigned firstDataArg,
07027                          FormatStringType Type, bool inFunctionCall);
07028 
07029   void CheckFormatArguments(const FormatAttr *Format, CallExpr *TheCall);
07030   void CheckFormatArguments(const FormatAttr *Format, Expr **Args,
07031                             unsigned NumArgs, bool IsCXXMember,
07032                             SourceLocation Loc, SourceRange Range);
07033   void CheckFormatArguments(Expr **Args, unsigned NumArgs,
07034                             bool HasVAListArg, unsigned format_idx,
07035                             unsigned firstDataArg, FormatStringType Type,
07036                             SourceLocation Loc, SourceRange range);
07037 
07038   void CheckNonNullArguments(const NonNullAttr *NonNull,
07039                              const Expr * const *ExprArgs,
07040                              SourceLocation CallSiteLoc);
07041 
07042   void CheckMemaccessArguments(const CallExpr *Call,
07043                                unsigned BId,
07044                                IdentifierInfo *FnName);
07045 
07046   void CheckStrlcpycatArguments(const CallExpr *Call,
07047                                 IdentifierInfo *FnName);
07048 
07049   void CheckStrncatArguments(const CallExpr *Call,
07050                              IdentifierInfo *FnName);
07051 
07052   void CheckReturnStackAddr(Expr *RetValExp, QualType lhsType,
07053                             SourceLocation ReturnLoc);
07054   void CheckFloatComparison(SourceLocation Loc, Expr* LHS, Expr* RHS);
07055   void CheckImplicitConversions(Expr *E, SourceLocation CC = SourceLocation());
07056 
07057   void CheckBitFieldInitialization(SourceLocation InitLoc, FieldDecl *Field,
07058                                    Expr *Init);
07059 
07060   /// \brief The parser's current scope.
07061   ///
07062   /// The parser maintains this state here.
07063   Scope *CurScope;
07064 
07065 protected:
07066   friend class Parser;
07067   friend class InitializationSequence;
07068   friend class ASTReader;
07069   friend class ASTWriter;
07070 
07071 public:
07072   /// \brief Retrieve the parser's current scope.
07073   ///
07074   /// This routine must only be used when it is certain that semantic analysis
07075   /// and the parser are in precisely the same context, which is not the case
07076   /// when, e.g., we are performing any kind of template instantiation.
07077   /// Therefore, the only safe places to use this scope are in the parser
07078   /// itself and in routines directly invoked from the parser and *never* from
07079   /// template substitution or instantiation.
07080   Scope *getCurScope() const { return CurScope; }
07081 
07082   Decl *getObjCDeclContext() const;
07083 
07084   DeclContext *getCurLexicalContext() const {
07085     return OriginalLexicalContext ? OriginalLexicalContext : CurContext;
07086   }
07087 
07088   AvailabilityResult getCurContextAvailability() const;
07089 };
07090 
07091 /// \brief RAII object that enters a new expression evaluation context.
07092 class EnterExpressionEvaluationContext {
07093   Sema &Actions;
07094 
07095 public:
07096   EnterExpressionEvaluationContext(Sema &Actions,
07097                                    Sema::ExpressionEvaluationContext NewContext,
07098                                    Decl *LambdaContextDecl = 0,
07099                                    bool IsDecltype = false)
07100     : Actions(Actions) {
07101     Actions.PushExpressionEvaluationContext(NewContext, LambdaContextDecl,
07102                                             IsDecltype);
07103   }
07104 
07105   ~EnterExpressionEvaluationContext() {
07106     Actions.PopExpressionEvaluationContext();
07107   }
07108 };
07109 
07110 }  // end namespace clang
07111 
07112 #endif