Sema.h revision 84b007fae6c0cd30fa07074d34fbe2bf61fa44f9
18b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project//===--- Sema.h - Semantic Analysis & AST Building --------------*- C++ -*-===//
28b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project//
38b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project//                     The LLVM Compiler Infrastructure
48b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project//
58b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project// This file is distributed under the University of Illinois Open Source
68b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project// License. See LICENSE.TXT for details.
78b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project//
88b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project//===----------------------------------------------------------------------===//
98b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project//
108b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project// This file defines the Sema class, which performs semantic analysis and
118b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project// builds ASTs.
128b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project//
138b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project//===----------------------------------------------------------------------===//
148b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
158b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#ifndef LLVM_CLANG_SEMA_SEMA_H
168b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define LLVM_CLANG_SEMA_SEMA_H
175d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner
185d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner#include "clang/Sema/Ownership.h"
198b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#include "clang/Sema/AnalysisBasedWarnings.h"
205d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner#include "clang/Sema/IdentifierResolver.h"
218b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#include "clang/Sema/ObjCMethodList.h"
228b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#include "clang/Sema/DeclSpec.h"
238b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#include "clang/Sema/ExternalSemaSource.h"
248b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#include "clang/Sema/LocInfoType.h"
258b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#include "clang/Sema/MultiInitializer.h"
268b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#include "clang/Sema/TypoCorrection.h"
278b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#include "clang/Sema/Weak.h"
288b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#include "clang/AST/Expr.h"
298b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#include "clang/AST/DeclarationName.h"
308b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#include "clang/AST/ExternalASTSource.h"
318b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#include "clang/AST/TypeLoc.h"
328b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#include "clang/Lex/ModuleLoader.h"
338b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#include "clang/Basic/Specifiers.h"
348b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#include "clang/Basic/TemplateKinds.h"
355d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner#include "clang/Basic/TypeTraits.h"
365d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner#include "clang/Basic/ExpressionTraits.h"
375d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner#include "llvm/ADT/ArrayRef.h"
388b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#include "llvm/ADT/OwningPtr.h"
398b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#include "llvm/ADT/SmallPtrSet.h"
408b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#include "llvm/ADT/SmallVector.h"
418b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#include <deque>
428b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#include <string>
438b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
448b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Projectnamespace llvm {
455d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner  class APSInt;
468b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  template <typename ValueT> struct DenseMapInfo;
478b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  template <typename ValueT, typename ValueInfoT> class DenseSet;
488b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project}
498b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
508b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Projectnamespace clang {
518b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class ADLResult;
528b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class ASTConsumer;
538b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class ASTContext;
548b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class ASTMutationListener;
558b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class ASTReader;
568b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class ASTWriter;
578b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class ArrayType;
588b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class AttributeList;
598b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class BlockDecl;
608b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class CXXBasePath;
618b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class CXXBasePaths;
628b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  typedef SmallVector<CXXBaseSpecifier*, 4> CXXCastPath;
638b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class CXXConstructorDecl;
648b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class CXXConversionDecl;
658b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class CXXDestructorDecl;
668b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class CXXFieldCollector;
678b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class CXXMemberCallExpr;
688b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class CXXMethodDecl;
698b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class CXXScopeSpec;
708b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class CXXTemporary;
718b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class CXXTryStmt;
728b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class CallExpr;
738b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class ClassTemplateDecl;
748b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class ClassTemplatePartialSpecializationDecl;
758b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class ClassTemplateSpecializationDecl;
768b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class CodeCompleteConsumer;
778b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class CodeCompletionAllocator;
788b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class CodeCompletionResult;
798b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class Decl;
805d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner  class DeclAccessPair;
818b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class DeclContext;
828b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class DeclRefExpr;
838b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class DeclaratorDecl;
848b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class DeducedTemplateArgument;
858b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class DependentDiagnostic;
868b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class DesignatedInitExpr;
878b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class Designation;
888b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class EnumConstantDecl;
898b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class Expr;
908b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class ExtVectorType;
918b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class ExternalSemaSource;
928b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class FormatAttr;
938b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class FriendDecl;
948b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class FunctionDecl;
958b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class FunctionProtoType;
968b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class FunctionTemplateDecl;
978b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class ImplicitConversionSequence;
985d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner  class InitListExpr;
998b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class InitializationKind;
1008b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class InitializationSequence;
1018b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class InitializedEntity;
1028b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class IntegerLiteral;
1038b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class LabelStmt;
1048b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class LangOptions;
1058b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class LocalInstantiationScope;
1068b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class LookupResult;
1078b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class MacroInfo;
1088b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class MultiLevelTemplateArgumentList;
1098b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class NamedDecl;
1108b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class NonNullAttr;
1118b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class ObjCCategoryDecl;
1128b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class ObjCCategoryImplDecl;
1138b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class ObjCCompatibleAliasDecl;
1148b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class ObjCContainerDecl;
1158b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class ObjCImplDecl;
1168b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class ObjCImplementationDecl;
1178b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class ObjCInterfaceDecl;
1188b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class ObjCIvarDecl;
1198b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  template <class T> class ObjCList;
1208b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class ObjCMessageExpr;
1218b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class ObjCMethodDecl;
1228b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class ObjCPropertyDecl;
1238b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class ObjCProtocolDecl;
1248b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class OverloadCandidateSet;
1258b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class OverloadExpr;
1268b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class ParenListExpr;
1278b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class ParmVarDecl;
1288b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class Preprocessor;
1298b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class PseudoDestructorTypeStorage;
1308b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class PseudoObjectExpr;
1318b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class QualType;
1328b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class StandardConversionSequence;
1338b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class Stmt;
1348b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class StringLiteral;
1358b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class SwitchStmt;
1368b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class TargetAttributesSema;
1378b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class TemplateArgument;
1388b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class TemplateArgumentList;
1398b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class TemplateArgumentLoc;
1408b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class TemplateDecl;
1418b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class TemplateParameterList;
1428b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class TemplatePartialOrderingContext;
1438b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class TemplateTemplateParmDecl;
1448b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class Token;
1458b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class TypeAliasDecl;
1468b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class TypedefDecl;
1478b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class TypedefNameDecl;
1488b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class TypeLoc;
1498b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class UnqualifiedId;
1508b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class UnresolvedLookupExpr;
1518b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class UnresolvedMemberExpr;
1528b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class UnresolvedSetImpl;
1538b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class UnresolvedSetIterator;
1548b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class UsingDecl;
1558b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class UsingShadowDecl;
1568b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class ValueDecl;
1578b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class VarDecl;
1588b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class VisibilityAttr;
1598b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class VisibleDeclConsumer;
1608b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class IndirectFieldDecl;
1618b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
1628b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Projectnamespace sema {
1638b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class AccessedEntity;
1648b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class BlockScopeInfo;
1658b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class DelayedDiagnostic;
1668b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class FunctionScopeInfo;
1678b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class LambdaScopeInfo;
1688b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class PossiblyUnreachableDiag;
1698b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class TemplateDeductionInfo;
1708b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project}
1718b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
1728b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project// FIXME: No way to easily map from TemplateTypeParmTypes to
1738b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project// TemplateTypeParmDecls, so we have this horrible PointerUnion.
1748b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Projecttypedef std::pair<llvm::PointerUnion<const TemplateTypeParmType*, NamedDecl*>,
1758b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project                  SourceLocation> UnexpandedParameterPack;
1768b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
1778b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project/// Sema - This implements semantic analysis and AST building for C.
1788b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Projectclass Sema {
1798b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  Sema(const Sema&);           // DO NOT IMPLEMENT
1808b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  void operator=(const Sema&); // DO NOT IMPLEMENT
1818b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  mutable const TargetAttributesSema* TheTargetAttributesSema;
1828b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Projectpublic:
1838b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  typedef OpaquePtr<DeclGroupRef> DeclGroupPtrTy;
1848b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  typedef OpaquePtr<TemplateName> TemplateTy;
1858b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  typedef OpaquePtr<QualType> TypeTy;
1868b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
1878b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  OpenCLOptions OpenCLFeatures;
1888b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  FPOptions FPFeatures;
1898b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
1908b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  const LangOptions &LangOpts;
1918b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  Preprocessor &PP;
1928b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  ASTContext &Context;
1938b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  ASTConsumer &Consumer;
1948b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  DiagnosticsEngine &Diags;
1958b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  SourceManager &SourceMgr;
1968b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
1978b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// \brief Flag indicating whether or not to collect detailed statistics.
1988b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  bool CollectStats;
1998b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
2008b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// \brief Source of additional semantic information.
2018b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  ExternalSemaSource *ExternalSource;
2028b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
2038b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// \brief Code-completion consumer.
2048b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  CodeCompleteConsumer *CodeCompleter;
2058b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
2068b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// CurContext - This is the current declaration context of parsing.
2078b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  DeclContext *CurContext;
2088b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
2098b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// \brief Generally null except when we temporarily switch decl contexts,
2108b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// like in \see ActOnObjCTemporaryExitContainerContext.
2118b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  DeclContext *OriginalLexicalContext;
2128b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
2138b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// VAListTagName - The declaration name corresponding to __va_list_tag.
2148b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// This is used as part of a hack to omit that class from ADL results.
2158b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  DeclarationName VAListTagName;
2168b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
2178b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// PackContext - Manages the stack for #pragma pack. An alignment
2188b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// of 0 indicates default alignment.
2198b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  void *PackContext; // Really a "PragmaPackStack*"
2208b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
2218b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  bool MSStructPragmaOn; // True when #pragma ms_struct on
2228b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
2238b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// VisContext - Manages the stack for #pragma GCC visibility.
2248b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  void *VisContext; // Really a "PragmaVisStack*"
2258b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
2268b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// ExprNeedsCleanups - True if the current evaluation context
2278b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// requires cleanups to be run at its conclusion.
2288b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  bool ExprNeedsCleanups;
2298b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
2308b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// ExprCleanupObjects - This is the stack of objects requiring
2318b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// cleanup that are created by the current full expression.  The
2328b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// element type here is ExprWithCleanups::Object.
2338b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  SmallVector<BlockDecl*, 8> ExprCleanupObjects;
2348b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
2358b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// \brief Stack containing information about each of the nested
2368b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// function, block, and method scopes that are currently active.
2378b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  ///
2388b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// This array is never empty.  Clients should ignore the first
2398b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// element, which is used to cache a single FunctionScopeInfo
2408b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// that's used to parse every top-level function.
241bcde1092aca184dbd7860078af020de7d1e4e22fDavid 'Digit' Turner  SmallVector<sema::FunctionScopeInfo *, 4> FunctionScopes;
2428b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
2438b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  typedef LazyVector<TypedefNameDecl *, ExternalSemaSource,
2448b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project                     &ExternalSemaSource::ReadExtVectorDecls, 2, 2>
2458b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    ExtVectorDeclsType;
2468b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
2478b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// ExtVectorDecls - This is a list all the extended vector types. This allows
2488b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// us to associate a raw vector type with one of the ext_vector type names.
2498b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// This is only necessary for issuing pretty diagnostics.
2508b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  ExtVectorDeclsType ExtVectorDecls;
2518b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
2528b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// \brief The set of types for which we have already complained about the
2538b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// definitions being hidden.
2548b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  ///
2558b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// This set is used to suppress redundant diagnostics.
2568b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  llvm::SmallPtrSet<NamedDecl *, 4> HiddenDefinitions;
2578b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
2588b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// FieldCollector - Collects CXXFieldDecls during parsing of C++ classes.
2598b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  llvm::OwningPtr<CXXFieldCollector> FieldCollector;
2608b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
2618b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  typedef llvm::SmallPtrSet<const CXXRecordDecl*, 8> RecordDeclSetTy;
2628b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
2638b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// PureVirtualClassDiagSet - a set of class declarations which we have
2648b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// emitted a list of pure virtual functions. Used to prevent emitting the
2658b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// same list more than once.
2668b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  llvm::OwningPtr<RecordDeclSetTy> PureVirtualClassDiagSet;
2678b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
2688b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// ParsingInitForAutoVars - a set of declarations with auto types for which
2698b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// we are currently parsing the initializer.
2708b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  llvm::SmallPtrSet<const Decl*, 4> ParsingInitForAutoVars;
2718b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
2728b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// \brief A mapping from external names to the most recent
2738b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// locally-scoped external declaration with that name.
2748b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  ///
2758b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// This map contains external declarations introduced in local
2768b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// scoped, e.g.,
2778b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  ///
2788b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// \code
2798b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// void f() {
2808b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  ///   void foo(int, int);
2818b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// }
2828b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// \endcode
2838b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  ///
2848b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// Here, the name "foo" will be associated with the declaration on
2858b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// "foo" within f. This name is not visible outside of
2868b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// "f". However, we still find it in two cases:
2878b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  ///
2888b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  ///   - If we are declaring another external with the name "foo", we
2898b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  ///     can find "foo" as a previous declaration, so that the types
2908b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  ///     of this external declaration can be checked for
2918b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  ///     compatibility.
2928b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  ///
2938b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  ///   - If we would implicitly declare "foo" (e.g., due to a call to
2948b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  ///     "foo" in C when no prototype or definition is visible), then
2958b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  ///     we find this declaration of "foo" and complain that it is
2968b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  ///     not visible.
2978b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  llvm::DenseMap<DeclarationName, NamedDecl *> LocallyScopedExternalDecls;
2988b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
2998b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// \brief Look for a locally scoped external declaration by the given name.
3008b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  llvm::DenseMap<DeclarationName, NamedDecl *>::iterator
3018b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  findLocallyScopedExternalDecl(DeclarationName Name);
3028b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
3038b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  typedef LazyVector<VarDecl *, ExternalSemaSource,
3048b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project                     &ExternalSemaSource::ReadTentativeDefinitions, 2, 2>
3058b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    TentativeDefinitionsType;
3068b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
3078b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// \brief All the tentative definitions encountered in the TU.
3088b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  TentativeDefinitionsType TentativeDefinitions;
3098b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
3108b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  typedef LazyVector<const DeclaratorDecl *, ExternalSemaSource,
3118b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project                     &ExternalSemaSource::ReadUnusedFileScopedDecls, 2, 2>
3128b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    UnusedFileScopedDeclsType;
3138b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
3148b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// \brief The set of file scoped decls seen so far that have not been used
3158b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// and must warn if not used. Only contains the first declaration.
3168b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  UnusedFileScopedDeclsType UnusedFileScopedDecls;
3178b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
3188b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  typedef LazyVector<CXXConstructorDecl *, ExternalSemaSource,
3198b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project                     &ExternalSemaSource::ReadDelegatingConstructors, 2, 2>
3208b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    DelegatingCtorDeclsType;
3218b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
3228b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// \brief All the delegating constructors seen so far in the file, used for
3238b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// cycle detection at the end of the TU.
3248b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  DelegatingCtorDeclsType DelegatingCtorDecls;
3258b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
3268b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// \brief All the overriding destructors seen during a class definition
3278b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// (there could be multiple due to nested classes) that had their exception
3288b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// spec checks delayed, plus the overridden destructor.
3298b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  SmallVector<std::pair<const CXXDestructorDecl*,
3308b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project                              const CXXDestructorDecl*>, 2>
3318b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project      DelayedDestructorExceptionSpecChecks;
3328b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
3338b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// \brief Callback to the parser to parse templated functions when needed.
3348b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  typedef void LateTemplateParserCB(void *P, const FunctionDecl *FD);
3358b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  LateTemplateParserCB *LateTemplateParser;
3368b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  void *OpaqueParser;
3378b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
3388b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  void SetLateTemplateParser(LateTemplateParserCB *LTP, void *P) {
3398b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    LateTemplateParser = LTP;
3408b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    OpaqueParser = P;
3418b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  }
3428b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
3438b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class DelayedDiagnostics;
3448b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
3458b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class ParsingDeclState {
3468b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    unsigned SavedStackSize;
3475d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner    friend class Sema::DelayedDiagnostics;
3488b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  };
3498b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
3508b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class ProcessingContextState {
351bcde1092aca184dbd7860078af020de7d1e4e22fDavid 'Digit' Turner    unsigned SavedParsingDepth;
3528b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    unsigned SavedActiveStackBase;
3538b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    friend class Sema::DelayedDiagnostics;
3548b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  };
3558b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
3568b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// A class which encapsulates the logic for delaying diagnostics
3578b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// during parsing and other processing.
3588b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class DelayedDiagnostics {
359bcde1092aca184dbd7860078af020de7d1e4e22fDavid 'Digit' Turner    /// \brief The stack of diagnostics that were delayed due to being
3608b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    /// produced during the parsing of a declaration.
3618b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    sema::DelayedDiagnostic *Stack;
3628b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
3638b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    /// \brief The number of objects on the delayed-diagnostics stack.
3648b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    unsigned StackSize;
3655d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner
3668b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    /// \brief The current capacity of the delayed-diagnostics stack.
3675d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner    unsigned StackCapacity;
3688b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
3698b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    /// \brief The index of the first "active" delayed diagnostic in
3708b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    /// the stack.  When parsing class definitions, we ignore active
3718b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    /// delayed diagnostics from the surrounding context.
3728b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    unsigned ActiveStackBase;
3738b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
374bcde1092aca184dbd7860078af020de7d1e4e22fDavid 'Digit' Turner    /// \brief The depth of the declarations we're currently parsing.
3758b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    /// This gets saved and reset whenever we enter a class definition.
3768b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    unsigned ParsingDepth;
3778b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
3788b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  public:
3798b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    DelayedDiagnostics() : Stack(0), StackSize(0), StackCapacity(0),
3808b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project      ActiveStackBase(0), ParsingDepth(0) {}
3818b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
3828b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    ~DelayedDiagnostics() {
3838b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project      delete[] reinterpret_cast<char*>(Stack);
3848b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    }
3858b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
3868b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    /// Adds a delayed diagnostic.
3878b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    void add(const sema::DelayedDiagnostic &diag);
3888b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
3898b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    /// Determines whether diagnostics should be delayed.
3908b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    bool shouldDelayDiagnostics() { return ParsingDepth > 0; }
3918b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
3928b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    /// Observe that we've started parsing a declaration.  Access and
3938b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    /// deprecation diagnostics will be delayed; when the declaration
3948b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    /// is completed, all active delayed diagnostics will be evaluated
3958b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    /// in its context, and then active diagnostics stack will be
3968b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    /// popped down to the saved depth.
3978b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    ParsingDeclState pushParsingDecl() {
3988b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project      ParsingDepth++;
3998b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
4008b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project      ParsingDeclState state;
4018b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project      state.SavedStackSize = StackSize;
4028b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project      return state;
4038b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    }
4048b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
4058b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    /// Observe that we're completed parsing a declaration.
4068b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    static void popParsingDecl(Sema &S, ParsingDeclState state, Decl *decl);
4078b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
4088b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    /// Observe that we've started processing a different context, the
4098b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    /// contents of which are semantically separate from the
4108b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    /// declarations it may lexically appear in.  This sets aside the
4118b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    /// current stack of active diagnostics and starts afresh.
4128b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    ProcessingContextState pushContext() {
4138b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project      assert(StackSize >= ActiveStackBase);
4148b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
4158b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project      ProcessingContextState state;
4168b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project      state.SavedParsingDepth = ParsingDepth;
4178b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project      state.SavedActiveStackBase = ActiveStackBase;
4188b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
4198b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project      ActiveStackBase = StackSize;
4208b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project      ParsingDepth = 0;
4218b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
4228b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project      return state;
4238b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    }
4248b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
4258b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    /// Observe that we've stopped processing a context.  This
4268b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    /// restores the previous stack of active diagnostics.
4278b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    void popContext(ProcessingContextState state) {
4288b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project      assert(ActiveStackBase == StackSize);
4298b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project      assert(ParsingDepth == 0);
4308b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project      ActiveStackBase = state.SavedActiveStackBase;
4318b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project      ParsingDepth = state.SavedParsingDepth;
4328b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    }
4338b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  } DelayedDiagnostics;
4348b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
4358b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// A RAII object to temporarily push a declaration context.
4368b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class ContextRAII {
4378b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  private:
4388b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    Sema &S;
4398b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    DeclContext *SavedContext;
4408b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    ProcessingContextState SavedContextState;
4418b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
4428b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  public:
4438b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    ContextRAII(Sema &S, DeclContext *ContextToPush)
4448b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project      : S(S), SavedContext(S.CurContext),
4458b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project        SavedContextState(S.DelayedDiagnostics.pushContext())
4468b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    {
4478b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project      assert(ContextToPush && "pushing null context");
4488b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project      S.CurContext = ContextToPush;
4498b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    }
4508b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
4518b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    void pop() {
4528b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project      if (!SavedContext) return;
4538b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project      S.CurContext = SavedContext;
4548b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project      S.DelayedDiagnostics.popContext(SavedContextState);
4558b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project      SavedContext = 0;
4568b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    }
4578b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
4588b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    ~ContextRAII() {
4598b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project      pop();
4608b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    }
4618b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  };
4628b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
4638b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// WeakUndeclaredIdentifiers - Identifiers contained in
4648b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// #pragma weak before declared. rare. may alias another
4658b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// identifier, declared or undeclared
4668b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  llvm::DenseMap<IdentifierInfo*,WeakInfo> WeakUndeclaredIdentifiers;
4678b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
4688b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// \brief Load weak undeclared identifiers from the external source.
4698b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  void LoadExternalWeakUndeclaredIdentifiers();
4708b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
4718b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// WeakTopLevelDecl - Translation-unit scoped declarations generated by
4728b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// #pragma weak during processing of other Decls.
4738b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// I couldn't figure out a clean way to generate these in-line, so
4748b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// we store them here and handle separately -- which is a hack.
4758b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// It would be best to refactor this.
4768b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  SmallVector<Decl*,2> WeakTopLevelDecl;
4778b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
4788b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  IdentifierResolver IdResolver;
4798b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
4808b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// Translation Unit Scope - useful to Objective-C actions that need
4818b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// to lookup file scope declarations in the "ordinary" C decl namespace.
4828b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// For example, user-defined classes, built-in "id" type, etc.
4838b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  Scope *TUScope;
4848b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
4858b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// \brief The C++ "std" namespace, where the standard library resides.
4868b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  LazyDeclPtr StdNamespace;
4878b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
4888b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// \brief The C++ "std::bad_alloc" class, which is defined by the C++
4898b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// standard library.
4908b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  LazyDeclPtr StdBadAlloc;
4918b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
4928b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// \brief The C++ "std::initializer_list" template, which is defined in
4938b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// <initializer_list>.
4948b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  ClassTemplateDecl *StdInitializerList;
4958b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
4968b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// \brief The C++ "type_info" declaration, which is defined in <typeinfo>.
4978b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  RecordDecl *CXXTypeInfoDecl;
4988b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
4998b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// \brief The MSVC "_GUID" struct, which is defined in MSVC header files.
5008b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  RecordDecl *MSVCGuidDecl;
5018b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
5028b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// A flag to remember whether the implicit forms of operator new and delete
5038b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// have been declared.
5048b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  bool GlobalNewDeleteDeclared;
5058b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
5068b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
5078b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// A flag that is set when parsing a -dealloc method and no [super dealloc]
5088b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// call was found yet.
5095d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner  bool ObjCShouldCallSuperDealloc;
5108b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// A flag that is set when parsing a -finalize method and no [super finalize]
5118b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// call was found yet.
512bcde1092aca184dbd7860078af020de7d1e4e22fDavid 'Digit' Turner  bool ObjCShouldCallSuperFinalize;
5138b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
5148b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// \brief Describes how the expressions currently being parsed are
5158b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// evaluated at run-time, if at all.
5168b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  enum ExpressionEvaluationContext {
5178b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    /// \brief The current expression and its subexpressions occur within an
5188b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    /// unevaluated operand (C++11 [expr]p7), such as the subexpression of
519bcde1092aca184dbd7860078af020de7d1e4e22fDavid 'Digit' Turner    /// \c sizeof, where the type of the expression may be significant but
5208b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    /// no code will be generated to evaluate the value of the expression at
5218b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    /// run time.
5228b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    Unevaluated,
5238b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
5248b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    /// \brief The current context is "potentially evaluated" in C++11 terms,
5255d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner    /// but the expression is evaluated at compile-time (like the values of
5268b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    /// cases in a switch statment).
5275d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner    ConstantEvaluated,
5288b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
5298b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    /// \brief The current expression is potentially evaluated at run time,
5308b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    /// which means that code may be generated to evaluate the value of the
5315d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner    /// expression at run time.
5328b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    PotentiallyEvaluated,
5338b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
5348b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    /// \brief The current expression is potentially evaluated, but any
5358b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    /// declarations referenced inside that expression are only used if
5368b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    /// in fact the current expression is used.
5378b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    ///
5388b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    /// This value is used when parsing default function arguments, for which
5398b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    /// we would like to provide diagnostics (e.g., passing non-POD arguments
5408b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    /// through varargs) but do not want to mark declarations as "referenced"
5418b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    /// until the default argument is used.
5428b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    PotentiallyEvaluatedIfUsed
5438b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  };
5448b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
5458b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// \brief Data structure used to record current or nested
5468b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// expression evaluation contexts.
5478b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  struct ExpressionEvaluationContextRecord {
5488b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    /// \brief The expression evaluation context.
5498b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    ExpressionEvaluationContext Context;
5508b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
5518b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    /// \brief Whether the enclosing context needed a cleanup.
5528b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    bool ParentNeedsCleanups;
5538b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
5548b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    /// \brief The number of active cleanup objects when we entered
5558b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    /// this expression evaluation context.
5568b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    unsigned NumCleanupObjects;
5578b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
5588b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    ExpressionEvaluationContextRecord(ExpressionEvaluationContext Context,
5598b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project                                      unsigned NumCleanupObjects,
5608b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project                                      bool ParentNeedsCleanups)
5618b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project      : Context(Context), ParentNeedsCleanups(ParentNeedsCleanups),
5628b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project        NumCleanupObjects(NumCleanupObjects) { }
5638b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  };
5648b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
5658b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// A stack of expression evaluation contexts.
5668b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  SmallVector<ExpressionEvaluationContextRecord, 8> ExprEvalContexts;
5678b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
5688b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// SpecialMemberOverloadResult - The overloading result for a special member
5698b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// function.
5708b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  ///
5718b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// This is basically a wrapper around PointerIntPair. The lowest bit of the
5728b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// integer is used to determine whether we have a parameter qualification
5738b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// match, the second-lowest is whether we had success in resolving the
5748b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// overload to a unique non-deleted function.
5758b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  ///
5768b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// The ConstParamMatch bit represents whether, when looking up a copy
5778b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// constructor or assignment operator, we found a potential copy
5788b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// constructor/assignment operator whose first parameter is const-qualified.
5798b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// This is used for determining parameter types of other objects and is
5808b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// utterly meaningless on other types of special members.
5818b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class SpecialMemberOverloadResult : public llvm::FastFoldingSetNode {
5828b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    llvm::PointerIntPair<CXXMethodDecl*, 2> Pair;
5838b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  public:
5848b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    SpecialMemberOverloadResult(const llvm::FoldingSetNodeID &ID)
5858b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project      : FastFoldingSetNode(ID)
5868b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    {}
5878b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
5888b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    CXXMethodDecl *getMethod() const { return Pair.getPointer(); }
5898b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    void setMethod(CXXMethodDecl *MD) { Pair.setPointer(MD); }
5908b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
5915d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner    bool hasSuccess() const { return Pair.getInt() & 0x1; }
5928b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    void setSuccess(bool B) {
5938b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project      Pair.setInt(unsigned(B) | hasConstParamMatch() << 1);
5948b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    }
5958b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
5968b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    bool hasConstParamMatch() const { return Pair.getInt() & 0x2; }
5978b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    void setConstParamMatch(bool B) {
5988b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project      Pair.setInt(B << 1 | unsigned(hasSuccess()));
5998b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    }
6008b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  };
6018b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
6028b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// \brief A cache of special member function overload resolution results
6038b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// for C++ records.
6048b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  llvm::FoldingSet<SpecialMemberOverloadResult> SpecialMemberCache;
6058b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
6068b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// \brief The kind of translation unit we are processing.
6078b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  ///
6088b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// When we're processing a complete translation unit, Sema will perform
6098b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// end-of-translation-unit semantic tasks (such as creating
6108b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// initializers for tentative definitions in C) once parsing has
6118b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// completed. Modules and precompiled headers perform different kinds of
6125d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner  /// checks.
6138b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  TranslationUnitKind TUKind;
6148b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
6158b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  llvm::BumpPtrAllocator BumpAlloc;
6168b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
6178b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// \brief The number of SFINAE diagnostics that have been trapped.
6188b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  unsigned NumSFINAEErrors;
6198b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
6208b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  typedef llvm::DenseMap<ParmVarDecl *, SmallVector<ParmVarDecl *, 1> >
6218b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    UnparsedDefaultArgInstantiationsMap;
6228b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
6238b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// \brief A mapping from parameters with unparsed default arguments to the
6248b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// set of instantiations of each parameter.
6258b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  ///
6268b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// This mapping is a temporary data structure used when parsing
6278b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// nested class templates or nested classes of class templates,
6288b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// where we might end up instantiating an inner class before the
6298b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// default arguments of its methods have been parsed.
6308b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  UnparsedDefaultArgInstantiationsMap UnparsedDefaultArgInstantiations;
6318b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
6328b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  // Contains the locations of the beginning of unparsed default
6338b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  // argument locations.
6348b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  llvm::DenseMap<ParmVarDecl *,SourceLocation> UnparsedDefaultArgLocs;
6358b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
6368b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// UndefinedInternals - all the used, undefined objects with
6378b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// internal linkage in this translation unit.
6388b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  llvm::DenseMap<NamedDecl*, SourceLocation> UndefinedInternals;
6398b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
6408b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  typedef std::pair<ObjCMethodList, ObjCMethodList> GlobalMethods;
6418b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  typedef llvm::DenseMap<Selector, GlobalMethods> GlobalMethodPool;
6428b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
6438b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// Method Pool - allows efficient lookup when typechecking messages to "id".
6448b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// We need to maintain a list, since selectors can have differing signatures
6458b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// across classes. In Cocoa, this happens to be extremely uncommon (only 1%
6468b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// of selectors are "overloaded").
6478b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  GlobalMethodPool MethodPool;
6488b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
6498b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// Method selectors used in a @selector expression. Used for implementation
6508b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// of -Wselector.
6518b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  llvm::DenseMap<Selector, SourceLocation> ReferencedSelectors;
6528b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
6538b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  void ReadMethodPool(Selector Sel);
6548b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
6558b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// Private Helper predicate to check for 'self'.
6568b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  bool isSelfExpr(Expr *RExpr);
6578b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Projectpublic:
6588b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer,
6598b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project       TranslationUnitKind TUKind = TU_Complete,
6608b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project       CodeCompleteConsumer *CompletionConsumer = 0);
6618b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  ~Sema();
6628b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
6638b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// \brief Perform initialization that occurs after the parser has been
6648b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// initialized but before it parses anything.
6658b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  void Initialize();
6668b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
6678b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  const LangOptions &getLangOptions() const { return LangOpts; }
6688b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  OpenCLOptions &getOpenCLOptions() { return OpenCLFeatures; }
6698b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  FPOptions     &getFPOptions() { return FPFeatures; }
6708b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
6718b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  DiagnosticsEngine &getDiagnostics() const { return Diags; }
6728b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  SourceManager &getSourceManager() const { return SourceMgr; }
6738b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  const TargetAttributesSema &getTargetAttributesSema() const;
6748b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  Preprocessor &getPreprocessor() const { return PP; }
6758b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  ASTContext &getASTContext() const { return Context; }
6768b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  ASTConsumer &getASTConsumer() const { return Consumer; }
6778b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  ASTMutationListener *getASTMutationListener() const;
6788b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
6798b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  void PrintStats() const;
6808b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
6818b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// \brief Helper class that creates diagnostics with optional
6828b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// template instantiation stacks.
6838b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  ///
6848b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// This class provides a wrapper around the basic DiagnosticBuilder
6858b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// class that emits diagnostics. SemaDiagnosticBuilder is
6868b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// responsible for emitting the diagnostic (as DiagnosticBuilder
6878b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// does) and, if the diagnostic comes from inside a template
6888b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// instantiation, printing the template instantiation stack as
6898b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// well.
6908b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  class SemaDiagnosticBuilder : public DiagnosticBuilder {
6918b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    Sema &SemaRef;
6928b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    unsigned DiagID;
6938b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
6948b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  public:
6958b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    SemaDiagnosticBuilder(DiagnosticBuilder &DB, Sema &SemaRef, unsigned DiagID)
6968b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project      : DiagnosticBuilder(DB), SemaRef(SemaRef), DiagID(DiagID) { }
6978b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
6988b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    explicit SemaDiagnosticBuilder(Sema &SemaRef)
6998b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project      : DiagnosticBuilder(DiagnosticBuilder::Suppress), SemaRef(SemaRef) { }
7008b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
7018b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project    ~SemaDiagnosticBuilder();
7028b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  };
7038b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
7048b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// \brief Emit a diagnostic.
7058b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID);
7068b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
7078b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// \brief Emit a partial diagnostic.
7088b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  SemaDiagnosticBuilder Diag(SourceLocation Loc, const PartialDiagnostic& PD);
7098b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
7108b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// \brief Build a partial diagnostic.
7118b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  PartialDiagnostic PDiag(unsigned DiagID = 0); // in SemaInternal.h
7128b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
7138b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  bool findMacroSpelling(SourceLocation &loc, StringRef name);
7148b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
7158b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  /// \brief Get a string to suggest for zero-initialization of a type.
7168b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  const char *getFixItZeroInitializerForType(QualType T) const;
7178b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
7188b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  ExprResult Owned(Expr* E) { return E; }
7198b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  ExprResult Owned(ExprResult R) { return R; }
7205d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner  StmtResult Owned(Stmt* S) { return S; }
7218b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
7228b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  void ActOnEndOfTranslationUnit();
7238b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
7245d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner  void CheckDelegatingCtorCycles();
7258b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
7265d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner  Scope *getScopeForContext(DeclContext *Ctx);
7278b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
7285d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner  void PushFunctionScope();
7295d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner  void PushBlockScope(Scope *BlockScope, BlockDecl *Block);
7308b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  void PushLambdaScope(CXXRecordDecl *Lambda);
7315cb5c0b8c5145dc0002b24e1421a3fa7a697475eDavid 'Digit' Turner  void PopFunctionScopeInfo(const sema::AnalysisBasedWarnings::Policy *WP =0,
7325cb5c0b8c5145dc0002b24e1421a3fa7a697475eDavid 'Digit' Turner                            const Decl *D = 0, const BlockExpr *blkExpr = 0);
7335cb5c0b8c5145dc0002b24e1421a3fa7a697475eDavid 'Digit' Turner
7345cb5c0b8c5145dc0002b24e1421a3fa7a697475eDavid 'Digit' Turner  sema::FunctionScopeInfo *getCurFunction() const {
7355cb5c0b8c5145dc0002b24e1421a3fa7a697475eDavid 'Digit' Turner    return FunctionScopes.back();
7365cb5c0b8c5145dc0002b24e1421a3fa7a697475eDavid 'Digit' Turner  }
7375cb5c0b8c5145dc0002b24e1421a3fa7a697475eDavid 'Digit' Turner
7388b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project  bool hasAnyUnrecoverableErrorsInThisFunction() const;
739
740  /// \brief Retrieve the current block, if any.
741  sema::BlockScopeInfo *getCurBlock();
742
743  /// \brief Retrieve the current lambda expression, if any.
744  sema::LambdaScopeInfo *getCurLambda();
745
746  /// WeakTopLevelDeclDecls - access to #pragma weak-generated Decls
747  SmallVector<Decl*,2> &WeakTopLevelDecls() { return WeakTopLevelDecl; }
748
749  //===--------------------------------------------------------------------===//
750  // Type Analysis / Processing: SemaType.cpp.
751  //
752
753  QualType BuildQualifiedType(QualType T, SourceLocation Loc, Qualifiers Qs);
754  QualType BuildQualifiedType(QualType T, SourceLocation Loc, unsigned CVR) {
755    return BuildQualifiedType(T, Loc, Qualifiers::fromCVRMask(CVR));
756  }
757  QualType BuildPointerType(QualType T,
758                            SourceLocation Loc, DeclarationName Entity);
759  QualType BuildReferenceType(QualType T, bool LValueRef,
760                              SourceLocation Loc, DeclarationName Entity);
761  QualType BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM,
762                          Expr *ArraySize, unsigned Quals,
763                          SourceRange Brackets, DeclarationName Entity);
764  QualType BuildExtVectorType(QualType T, Expr *ArraySize,
765                              SourceLocation AttrLoc);
766  QualType BuildFunctionType(QualType T,
767                             QualType *ParamTypes, unsigned NumParamTypes,
768                             bool Variadic, unsigned Quals,
769                             RefQualifierKind RefQualifier,
770                             SourceLocation Loc, DeclarationName Entity,
771                             FunctionType::ExtInfo Info);
772  QualType BuildMemberPointerType(QualType T, QualType Class,
773                                  SourceLocation Loc,
774                                  DeclarationName Entity);
775  QualType BuildBlockPointerType(QualType T,
776                                 SourceLocation Loc, DeclarationName Entity);
777  QualType BuildParenType(QualType T);
778  QualType BuildAtomicType(QualType T, SourceLocation Loc);
779
780  TypeSourceInfo *GetTypeForDeclarator(Declarator &D, Scope *S);
781  TypeSourceInfo *GetTypeForDeclaratorCast(Declarator &D, QualType FromTy);
782  TypeSourceInfo *GetTypeSourceInfoForDeclarator(Declarator &D, QualType T,
783                                               TypeSourceInfo *ReturnTypeInfo);
784  /// \brief Package the given type and TSI into a ParsedType.
785  ParsedType CreateParsedType(QualType T, TypeSourceInfo *TInfo);
786  DeclarationNameInfo GetNameForDeclarator(Declarator &D);
787  DeclarationNameInfo GetNameFromUnqualifiedId(const UnqualifiedId &Name);
788  static QualType GetTypeFromParser(ParsedType Ty, TypeSourceInfo **TInfo = 0);
789  bool CheckSpecifiedExceptionType(QualType T, const SourceRange &Range);
790  bool CheckDistantExceptionSpec(QualType T);
791  bool CheckEquivalentExceptionSpec(FunctionDecl *Old, FunctionDecl *New);
792  bool CheckEquivalentExceptionSpec(
793      const FunctionProtoType *Old, SourceLocation OldLoc,
794      const FunctionProtoType *New, SourceLocation NewLoc);
795  bool CheckEquivalentExceptionSpec(
796      const PartialDiagnostic &DiagID, const PartialDiagnostic & NoteID,
797      const FunctionProtoType *Old, SourceLocation OldLoc,
798      const FunctionProtoType *New, SourceLocation NewLoc,
799      bool *MissingExceptionSpecification = 0,
800      bool *MissingEmptyExceptionSpecification = 0,
801      bool AllowNoexceptAllMatchWithNoSpec = false,
802      bool IsOperatorNew = false);
803  bool CheckExceptionSpecSubset(
804      const PartialDiagnostic &DiagID, const PartialDiagnostic & NoteID,
805      const FunctionProtoType *Superset, SourceLocation SuperLoc,
806      const FunctionProtoType *Subset, SourceLocation SubLoc);
807  bool CheckParamExceptionSpec(const PartialDiagnostic & NoteID,
808      const FunctionProtoType *Target, SourceLocation TargetLoc,
809      const FunctionProtoType *Source, SourceLocation SourceLoc);
810
811  TypeResult ActOnTypeName(Scope *S, Declarator &D);
812
813  /// \brief The parser has parsed the context-sensitive type 'instancetype'
814  /// in an Objective-C message declaration. Return the appropriate type.
815  ParsedType ActOnObjCInstanceType(SourceLocation Loc);
816
817  bool RequireCompleteType(SourceLocation Loc, QualType T,
818                           const PartialDiagnostic &PD,
819                           std::pair<SourceLocation, PartialDiagnostic> Note);
820  bool RequireCompleteType(SourceLocation Loc, QualType T,
821                           const PartialDiagnostic &PD);
822  bool RequireCompleteType(SourceLocation Loc, QualType T,
823                           unsigned DiagID);
824  bool RequireCompleteExprType(Expr *E, const PartialDiagnostic &PD,
825                               std::pair<SourceLocation,
826                                         PartialDiagnostic> Note);
827
828  bool RequireLiteralType(SourceLocation Loc, QualType T,
829                          const PartialDiagnostic &PD,
830                          bool AllowIncompleteType = false);
831
832  QualType getElaboratedType(ElaboratedTypeKeyword Keyword,
833                             const CXXScopeSpec &SS, QualType T);
834
835  QualType BuildTypeofExprType(Expr *E, SourceLocation Loc);
836  QualType BuildDecltypeType(Expr *E, SourceLocation Loc);
837  QualType BuildUnaryTransformType(QualType BaseType,
838                                   UnaryTransformType::UTTKind UKind,
839                                   SourceLocation Loc);
840
841  //===--------------------------------------------------------------------===//
842  // Symbol table / Decl tracking callbacks: SemaDecl.cpp.
843  //
844
845  DeclGroupPtrTy ConvertDeclToDeclGroup(Decl *Ptr, Decl *OwnedType = 0);
846
847  void DiagnoseUseOfUnimplementedSelectors();
848
849  ParsedType getTypeName(IdentifierInfo &II, SourceLocation NameLoc,
850                         Scope *S, CXXScopeSpec *SS = 0,
851                         bool isClassName = false,
852                         bool HasTrailingDot = false,
853                         ParsedType ObjectType = ParsedType(),
854                         bool WantNontrivialTypeSourceInfo = false,
855                         IdentifierInfo **CorrectedII = 0);
856  TypeSpecifierType isTagName(IdentifierInfo &II, Scope *S);
857  bool isMicrosoftMissingTypename(const CXXScopeSpec *SS, Scope *S);
858  bool DiagnoseUnknownTypeName(const IdentifierInfo &II,
859                               SourceLocation IILoc,
860                               Scope *S,
861                               CXXScopeSpec *SS,
862                               ParsedType &SuggestedType);
863
864  /// \brief Describes the result of the name lookup and resolution performed
865  /// by \c ClassifyName().
866  enum NameClassificationKind {
867    NC_Unknown,
868    NC_Error,
869    NC_Keyword,
870    NC_Type,
871    NC_Expression,
872    NC_NestedNameSpecifier,
873    NC_TypeTemplate,
874    NC_FunctionTemplate
875  };
876
877  class NameClassification {
878    NameClassificationKind Kind;
879    ExprResult Expr;
880    TemplateName Template;
881    ParsedType Type;
882    const IdentifierInfo *Keyword;
883
884    explicit NameClassification(NameClassificationKind Kind) : Kind(Kind) {}
885
886  public:
887    NameClassification(ExprResult Expr) : Kind(NC_Expression), Expr(Expr) {}
888
889    NameClassification(ParsedType Type) : Kind(NC_Type), Type(Type) {}
890
891    NameClassification(const IdentifierInfo *Keyword)
892      : Kind(NC_Keyword), Keyword(Keyword) { }
893
894    static NameClassification Error() {
895      return NameClassification(NC_Error);
896    }
897
898    static NameClassification Unknown() {
899      return NameClassification(NC_Unknown);
900    }
901
902    static NameClassification NestedNameSpecifier() {
903      return NameClassification(NC_NestedNameSpecifier);
904    }
905
906    static NameClassification TypeTemplate(TemplateName Name) {
907      NameClassification Result(NC_TypeTemplate);
908      Result.Template = Name;
909      return Result;
910    }
911
912    static NameClassification FunctionTemplate(TemplateName Name) {
913      NameClassification Result(NC_FunctionTemplate);
914      Result.Template = Name;
915      return Result;
916    }
917
918    NameClassificationKind getKind() const { return Kind; }
919
920    ParsedType getType() const {
921      assert(Kind == NC_Type);
922      return Type;
923    }
924
925    ExprResult getExpression() const {
926      assert(Kind == NC_Expression);
927      return Expr;
928    }
929
930    TemplateName getTemplateName() const {
931      assert(Kind == NC_TypeTemplate || Kind == NC_FunctionTemplate);
932      return Template;
933    }
934
935    TemplateNameKind getTemplateNameKind() const {
936      assert(Kind == NC_TypeTemplate || Kind == NC_FunctionTemplate);
937      return Kind == NC_TypeTemplate? TNK_Type_template : TNK_Function_template;
938    }
939};
940
941  /// \brief Perform name lookup on the given name, classifying it based on
942  /// the results of name lookup and the following token.
943  ///
944  /// This routine is used by the parser to resolve identifiers and help direct
945  /// parsing. When the identifier cannot be found, this routine will attempt
946  /// to correct the typo and classify based on the resulting name.
947  ///
948  /// \param S The scope in which we're performing name lookup.
949  ///
950  /// \param SS The nested-name-specifier that precedes the name.
951  ///
952  /// \param Name The identifier. If typo correction finds an alternative name,
953  /// this pointer parameter will be updated accordingly.
954  ///
955  /// \param NameLoc The location of the identifier.
956  ///
957  /// \param NextToken The token following the identifier. Used to help
958  /// disambiguate the name.
959  NameClassification ClassifyName(Scope *S,
960                                  CXXScopeSpec &SS,
961                                  IdentifierInfo *&Name,
962                                  SourceLocation NameLoc,
963                                  const Token &NextToken);
964
965  Decl *ActOnDeclarator(Scope *S, Declarator &D);
966
967  Decl *HandleDeclarator(Scope *S, Declarator &D,
968                         MultiTemplateParamsArg TemplateParameterLists);
969  void RegisterLocallyScopedExternCDecl(NamedDecl *ND,
970                                        const LookupResult &Previous,
971                                        Scope *S);
972  bool DiagnoseClassNameShadow(DeclContext *DC, DeclarationNameInfo Info);
973  void DiagnoseFunctionSpecifiers(Declarator& D);
974  void CheckShadow(Scope *S, VarDecl *D, const LookupResult& R);
975  void CheckShadow(Scope *S, VarDecl *D);
976  void CheckCastAlign(Expr *Op, QualType T, SourceRange TRange);
977  void CheckTypedefForVariablyModifiedType(Scope *S, TypedefNameDecl *D);
978  NamedDecl* ActOnTypedefDeclarator(Scope* S, Declarator& D, DeclContext* DC,
979                                    TypeSourceInfo *TInfo,
980                                    LookupResult &Previous);
981  NamedDecl* ActOnTypedefNameDecl(Scope* S, DeclContext* DC, TypedefNameDecl *D,
982                                  LookupResult &Previous, bool &Redeclaration);
983  NamedDecl* ActOnVariableDeclarator(Scope* S, Declarator& D, DeclContext* DC,
984                                     TypeSourceInfo *TInfo,
985                                     LookupResult &Previous,
986                                     MultiTemplateParamsArg TemplateParamLists);
987  // Returns true if the variable declaration is a redeclaration
988  bool CheckVariableDeclaration(VarDecl *NewVD, LookupResult &Previous);
989  void CheckCompleteVariableDeclaration(VarDecl *var);
990  NamedDecl* ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
991                                     TypeSourceInfo *TInfo,
992                                     LookupResult &Previous,
993                                     MultiTemplateParamsArg TemplateParamLists,
994                                     bool &AddToScope);
995  bool AddOverriddenMethods(CXXRecordDecl *DC, CXXMethodDecl *MD);
996
997  /// \brief The kind of constexpr declaration checking we are performing.
998  ///
999  /// The kind affects which diagnostics (if any) are emitted if the function
1000  /// does not satisfy the requirements of a constexpr function declaration.
1001  enum CheckConstexprKind {
1002    /// \brief Check a constexpr function declaration, and produce errors if it
1003    /// does not satisfy the requirements.
1004    CCK_Declaration,
1005    /// \brief Check a constexpr function template instantiation.
1006    CCK_Instantiation,
1007    /// \brief Produce notes explaining why an instantiation was not constexpr.
1008    CCK_NoteNonConstexprInstantiation
1009  };
1010  bool CheckConstexprFunctionDecl(const FunctionDecl *FD,
1011                                  CheckConstexprKind CCK);
1012  bool CheckConstexprFunctionBody(const FunctionDecl *FD, Stmt *Body);
1013
1014  void DiagnoseHiddenVirtualMethods(CXXRecordDecl *DC, CXXMethodDecl *MD);
1015  // Returns true if the function declaration is a redeclaration
1016  bool CheckFunctionDeclaration(Scope *S,
1017                                FunctionDecl *NewFD, LookupResult &Previous,
1018                                bool IsExplicitSpecialization);
1019  void CheckMain(FunctionDecl *FD, const DeclSpec &D);
1020  Decl *ActOnParamDeclarator(Scope *S, Declarator &D);
1021  ParmVarDecl *BuildParmVarDeclForTypedef(DeclContext *DC,
1022                                          SourceLocation Loc,
1023                                          QualType T);
1024  ParmVarDecl *CheckParameter(DeclContext *DC, SourceLocation StartLoc,
1025                              SourceLocation NameLoc, IdentifierInfo *Name,
1026                              QualType T, TypeSourceInfo *TSInfo,
1027                              StorageClass SC, StorageClass SCAsWritten);
1028  void ActOnParamDefaultArgument(Decl *param,
1029                                 SourceLocation EqualLoc,
1030                                 Expr *defarg);
1031  void ActOnParamUnparsedDefaultArgument(Decl *param,
1032                                         SourceLocation EqualLoc,
1033                                         SourceLocation ArgLoc);
1034  void ActOnParamDefaultArgumentError(Decl *param);
1035  bool SetParamDefaultArgument(ParmVarDecl *Param, Expr *DefaultArg,
1036                               SourceLocation EqualLoc);
1037
1038  void CheckSelfReference(Decl *OrigDecl, Expr *E);
1039  void AddInitializerToDecl(Decl *dcl, Expr *init, bool DirectInit,
1040                            bool TypeMayContainAuto);
1041  void ActOnUninitializedDecl(Decl *dcl, bool TypeMayContainAuto);
1042  void ActOnInitializerError(Decl *Dcl);
1043  void ActOnCXXForRangeDecl(Decl *D);
1044  void SetDeclDeleted(Decl *dcl, SourceLocation DelLoc);
1045  void SetDeclDefaulted(Decl *dcl, SourceLocation DefaultLoc);
1046  void FinalizeDeclaration(Decl *D);
1047  DeclGroupPtrTy FinalizeDeclaratorGroup(Scope *S, const DeclSpec &DS,
1048                                         Decl **Group,
1049                                         unsigned NumDecls);
1050  DeclGroupPtrTy BuildDeclaratorGroup(Decl **Group, unsigned NumDecls,
1051                                      bool TypeMayContainAuto = true);
1052  void ActOnFinishKNRParamDeclarations(Scope *S, Declarator &D,
1053                                       SourceLocation LocAfterDecls);
1054  void CheckForFunctionRedefinition(FunctionDecl *FD);
1055  Decl *ActOnStartOfFunctionDef(Scope *S, Declarator &D);
1056  Decl *ActOnStartOfFunctionDef(Scope *S, Decl *D);
1057  void ActOnStartOfObjCMethodDef(Scope *S, Decl *D);
1058
1059  void computeNRVO(Stmt *Body, sema::FunctionScopeInfo *Scope);
1060  Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body);
1061  Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body, bool IsInstantiation);
1062
1063  /// ActOnFinishDelayedAttribute - Invoked when we have finished parsing an
1064  /// attribute for which parsing is delayed.
1065  void ActOnFinishDelayedAttribute(Scope *S, Decl *D, ParsedAttributes &Attrs);
1066
1067  /// \brief Diagnose any unused parameters in the given sequence of
1068  /// ParmVarDecl pointers.
1069  void DiagnoseUnusedParameters(ParmVarDecl * const *Begin,
1070                                ParmVarDecl * const *End);
1071
1072  /// \brief Diagnose whether the size of parameters or return value of a
1073  /// function or obj-c method definition is pass-by-value and larger than a
1074  /// specified threshold.
1075  void DiagnoseSizeOfParametersAndReturnValue(ParmVarDecl * const *Begin,
1076                                              ParmVarDecl * const *End,
1077                                              QualType ReturnTy,
1078                                              NamedDecl *D);
1079
1080  void DiagnoseInvalidJumps(Stmt *Body);
1081  Decl *ActOnFileScopeAsmDecl(Expr *expr,
1082                              SourceLocation AsmLoc,
1083                              SourceLocation RParenLoc);
1084
1085  /// \brief The parser has processed a module import declaration.
1086  ///
1087  /// \param AtLoc The location of the '@' symbol, if any.
1088  ///
1089  /// \param ImportLoc The location of the 'import' keyword.
1090  ///
1091  /// \param Path The module access path.
1092  DeclResult ActOnModuleImport(SourceLocation AtLoc, SourceLocation ImportLoc,
1093                               ModuleIdPath Path);
1094
1095  /// \brief Retrieve a suitable printing policy.
1096  PrintingPolicy getPrintingPolicy() const {
1097    return getPrintingPolicy(Context, PP);
1098  }
1099
1100  /// \brief Retrieve a suitable printing policy.
1101  static PrintingPolicy getPrintingPolicy(const ASTContext &Ctx,
1102                                          const Preprocessor &PP);
1103
1104  /// Scope actions.
1105  void ActOnPopScope(SourceLocation Loc, Scope *S);
1106  void ActOnTranslationUnitScope(Scope *S);
1107
1108  Decl *ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS,
1109                                   DeclSpec &DS);
1110  Decl *ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS,
1111                                   DeclSpec &DS,
1112                                   MultiTemplateParamsArg TemplateParams);
1113
1114  Decl *BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS,
1115                                    AccessSpecifier AS,
1116                                    RecordDecl *Record);
1117
1118  Decl *BuildMicrosoftCAnonymousStruct(Scope *S, DeclSpec &DS,
1119                                       RecordDecl *Record);
1120
1121  bool isAcceptableTagRedeclaration(const TagDecl *Previous,
1122                                    TagTypeKind NewTag, bool isDefinition,
1123                                    SourceLocation NewTagLoc,
1124                                    const IdentifierInfo &Name);
1125
1126  enum TagUseKind {
1127    TUK_Reference,   // Reference to a tag:  'struct foo *X;'
1128    TUK_Declaration, // Fwd decl of a tag:   'struct foo;'
1129    TUK_Definition,  // Definition of a tag: 'struct foo { int X; } Y;'
1130    TUK_Friend       // Friend declaration:  'friend struct foo;'
1131  };
1132
1133  Decl *ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK,
1134                 SourceLocation KWLoc, CXXScopeSpec &SS,
1135                 IdentifierInfo *Name, SourceLocation NameLoc,
1136                 AttributeList *Attr, AccessSpecifier AS,
1137                 SourceLocation ModulePrivateLoc,
1138                 MultiTemplateParamsArg TemplateParameterLists,
1139                 bool &OwnedDecl, bool &IsDependent,
1140                 SourceLocation ScopedEnumKWLoc,
1141                 bool ScopedEnumUsesClassTag, TypeResult UnderlyingType);
1142
1143  Decl *ActOnTemplatedFriendTag(Scope *S, SourceLocation FriendLoc,
1144                                unsigned TagSpec, SourceLocation TagLoc,
1145                                CXXScopeSpec &SS,
1146                                IdentifierInfo *Name, SourceLocation NameLoc,
1147                                AttributeList *Attr,
1148                                MultiTemplateParamsArg TempParamLists);
1149
1150  TypeResult ActOnDependentTag(Scope *S,
1151                               unsigned TagSpec,
1152                               TagUseKind TUK,
1153                               const CXXScopeSpec &SS,
1154                               IdentifierInfo *Name,
1155                               SourceLocation TagLoc,
1156                               SourceLocation NameLoc);
1157
1158  void ActOnDefs(Scope *S, Decl *TagD, SourceLocation DeclStart,
1159                 IdentifierInfo *ClassName,
1160                 SmallVectorImpl<Decl *> &Decls);
1161  Decl *ActOnField(Scope *S, Decl *TagD, SourceLocation DeclStart,
1162                   Declarator &D, Expr *BitfieldWidth);
1163
1164  FieldDecl *HandleField(Scope *S, RecordDecl *TagD, SourceLocation DeclStart,
1165                         Declarator &D, Expr *BitfieldWidth, bool HasInit,
1166                         AccessSpecifier AS);
1167
1168  FieldDecl *CheckFieldDecl(DeclarationName Name, QualType T,
1169                            TypeSourceInfo *TInfo,
1170                            RecordDecl *Record, SourceLocation Loc,
1171                            bool Mutable, Expr *BitfieldWidth, bool HasInit,
1172                            SourceLocation TSSL,
1173                            AccessSpecifier AS, NamedDecl *PrevDecl,
1174                            Declarator *D = 0);
1175
1176  enum CXXSpecialMember {
1177    CXXDefaultConstructor,
1178    CXXCopyConstructor,
1179    CXXMoveConstructor,
1180    CXXCopyAssignment,
1181    CXXMoveAssignment,
1182    CXXDestructor,
1183    CXXInvalid
1184  };
1185  bool CheckNontrivialField(FieldDecl *FD);
1186  void DiagnoseNontrivial(const RecordType* Record, CXXSpecialMember mem);
1187  CXXSpecialMember getSpecialMember(const CXXMethodDecl *MD);
1188  void ActOnLastBitfield(SourceLocation DeclStart,
1189                         SmallVectorImpl<Decl *> &AllIvarDecls);
1190  Decl *ActOnIvar(Scope *S, SourceLocation DeclStart,
1191                  Declarator &D, Expr *BitfieldWidth,
1192                  tok::ObjCKeywordKind visibility);
1193
1194  // This is used for both record definitions and ObjC interface declarations.
1195  void ActOnFields(Scope* S, SourceLocation RecLoc, Decl *TagDecl,
1196                   llvm::ArrayRef<Decl *> Fields,
1197                   SourceLocation LBrac, SourceLocation RBrac,
1198                   AttributeList *AttrList);
1199
1200  /// ActOnTagStartDefinition - Invoked when we have entered the
1201  /// scope of a tag's definition (e.g., for an enumeration, class,
1202  /// struct, or union).
1203  void ActOnTagStartDefinition(Scope *S, Decl *TagDecl);
1204
1205  Decl *ActOnObjCContainerStartDefinition(Decl *IDecl);
1206
1207  /// ActOnStartCXXMemberDeclarations - Invoked when we have parsed a
1208  /// C++ record definition's base-specifiers clause and are starting its
1209  /// member declarations.
1210  void ActOnStartCXXMemberDeclarations(Scope *S, Decl *TagDecl,
1211                                       SourceLocation FinalLoc,
1212                                       SourceLocation LBraceLoc);
1213
1214  /// ActOnTagFinishDefinition - Invoked once we have finished parsing
1215  /// the definition of a tag (enumeration, class, struct, or union).
1216  void ActOnTagFinishDefinition(Scope *S, Decl *TagDecl,
1217                                SourceLocation RBraceLoc);
1218
1219  void ActOnObjCContainerFinishDefinition();
1220
1221  /// \brief Invoked when we must temporarily exit the objective-c container
1222  /// scope for parsing/looking-up C constructs.
1223  ///
1224  /// Must be followed by a call to \see ActOnObjCReenterContainerContext
1225  void ActOnObjCTemporaryExitContainerContext(DeclContext *DC);
1226  void ActOnObjCReenterContainerContext(DeclContext *DC);
1227
1228  /// ActOnTagDefinitionError - Invoked when there was an unrecoverable
1229  /// error parsing the definition of a tag.
1230  void ActOnTagDefinitionError(Scope *S, Decl *TagDecl);
1231
1232  EnumConstantDecl *CheckEnumConstant(EnumDecl *Enum,
1233                                      EnumConstantDecl *LastEnumConst,
1234                                      SourceLocation IdLoc,
1235                                      IdentifierInfo *Id,
1236                                      Expr *val);
1237
1238  Decl *ActOnEnumConstant(Scope *S, Decl *EnumDecl, Decl *LastEnumConstant,
1239                          SourceLocation IdLoc, IdentifierInfo *Id,
1240                          AttributeList *Attrs,
1241                          SourceLocation EqualLoc, Expr *Val);
1242  void ActOnEnumBody(SourceLocation EnumLoc, SourceLocation LBraceLoc,
1243                     SourceLocation RBraceLoc, Decl *EnumDecl,
1244                     Decl **Elements, unsigned NumElements,
1245                     Scope *S, AttributeList *Attr);
1246
1247  DeclContext *getContainingDC(DeclContext *DC);
1248
1249  /// Set the current declaration context until it gets popped.
1250  void PushDeclContext(Scope *S, DeclContext *DC);
1251  void PopDeclContext();
1252
1253  /// EnterDeclaratorContext - Used when we must lookup names in the context
1254  /// of a declarator's nested name specifier.
1255  void EnterDeclaratorContext(Scope *S, DeclContext *DC);
1256  void ExitDeclaratorContext(Scope *S);
1257
1258  /// Push the parameters of D, which must be a function, into scope.
1259  void ActOnReenterFunctionContext(Scope* S, Decl* D);
1260  void ActOnExitFunctionContext() { PopDeclContext(); }
1261
1262  DeclContext *getFunctionLevelDeclContext();
1263
1264  /// getCurFunctionDecl - If inside of a function body, this returns a pointer
1265  /// to the function decl for the function being parsed.  If we're currently
1266  /// in a 'block', this returns the containing context.
1267  FunctionDecl *getCurFunctionDecl();
1268
1269  /// getCurMethodDecl - If inside of a method body, this returns a pointer to
1270  /// the method decl for the method being parsed.  If we're currently
1271  /// in a 'block', this returns the containing context.
1272  ObjCMethodDecl *getCurMethodDecl();
1273
1274  /// getCurFunctionOrMethodDecl - Return the Decl for the current ObjC method
1275  /// or C function we're in, otherwise return null.  If we're currently
1276  /// in a 'block', this returns the containing context.
1277  NamedDecl *getCurFunctionOrMethodDecl();
1278
1279  /// Add this decl to the scope shadowed decl chains.
1280  void PushOnScopeChains(NamedDecl *D, Scope *S, bool AddToContext = true);
1281
1282  /// \brief Make the given externally-produced declaration visible at the
1283  /// top level scope.
1284  ///
1285  /// \param D The externally-produced declaration to push.
1286  ///
1287  /// \param Name The name of the externally-produced declaration.
1288  void pushExternalDeclIntoScope(NamedDecl *D, DeclarationName Name);
1289
1290  /// isDeclInScope - If 'Ctx' is a function/method, isDeclInScope returns true
1291  /// if 'D' is in Scope 'S', otherwise 'S' is ignored and isDeclInScope returns
1292  /// true if 'D' belongs to the given declaration context.
1293  ///
1294  /// \param ExplicitInstantiationOrSpecialization When true, we are checking
1295  /// whether the declaration is in scope for the purposes of explicit template
1296  /// instantiation or specialization. The default is false.
1297  bool isDeclInScope(NamedDecl *&D, DeclContext *Ctx, Scope *S = 0,
1298                     bool ExplicitInstantiationOrSpecialization = false);
1299
1300  /// Finds the scope corresponding to the given decl context, if it
1301  /// happens to be an enclosing scope.  Otherwise return NULL.
1302  static Scope *getScopeForDeclContext(Scope *S, DeclContext *DC);
1303
1304  /// Subroutines of ActOnDeclarator().
1305  TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, QualType T,
1306                                TypeSourceInfo *TInfo);
1307  bool isIncompatibleTypedef(TypeDecl *Old, TypedefNameDecl *New);
1308  void mergeDeclAttributes(Decl *New, Decl *Old, bool MergeDeprecation = true);
1309  void MergeTypedefNameDecl(TypedefNameDecl *New, LookupResult &OldDecls);
1310  bool MergeFunctionDecl(FunctionDecl *New, Decl *Old);
1311  bool MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old);
1312  void mergeObjCMethodDecls(ObjCMethodDecl *New, ObjCMethodDecl *Old);
1313  void MergeVarDecl(VarDecl *New, LookupResult &OldDecls);
1314  void MergeVarDeclTypes(VarDecl *New, VarDecl *Old);
1315  void MergeVarDeclExceptionSpecs(VarDecl *New, VarDecl *Old);
1316  bool MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old);
1317
1318  // AssignmentAction - This is used by all the assignment diagnostic functions
1319  // to represent what is actually causing the operation
1320  enum AssignmentAction {
1321    AA_Assigning,
1322    AA_Passing,
1323    AA_Returning,
1324    AA_Converting,
1325    AA_Initializing,
1326    AA_Sending,
1327    AA_Casting
1328  };
1329
1330  /// C++ Overloading.
1331  enum OverloadKind {
1332    /// This is a legitimate overload: the existing declarations are
1333    /// functions or function templates with different signatures.
1334    Ovl_Overload,
1335
1336    /// This is not an overload because the signature exactly matches
1337    /// an existing declaration.
1338    Ovl_Match,
1339
1340    /// This is not an overload because the lookup results contain a
1341    /// non-function.
1342    Ovl_NonFunction
1343  };
1344  OverloadKind CheckOverload(Scope *S,
1345                             FunctionDecl *New,
1346                             const LookupResult &OldDecls,
1347                             NamedDecl *&OldDecl,
1348                             bool IsForUsingDecl);
1349  bool IsOverload(FunctionDecl *New, FunctionDecl *Old, bool IsForUsingDecl);
1350
1351  /// \brief Checks availability of the function depending on the current
1352  /// function context.Inside an unavailable function,unavailability is ignored.
1353  ///
1354  /// \returns true if \arg FD is unavailable and current context is inside
1355  /// an available function, false otherwise.
1356  bool isFunctionConsideredUnavailable(FunctionDecl *FD);
1357
1358  ImplicitConversionSequence
1359  TryImplicitConversion(Expr *From, QualType ToType,
1360                        bool SuppressUserConversions,
1361                        bool AllowExplicit,
1362                        bool InOverloadResolution,
1363                        bool CStyle,
1364                        bool AllowObjCWritebackConversion);
1365
1366  bool IsIntegralPromotion(Expr *From, QualType FromType, QualType ToType);
1367  bool IsFloatingPointPromotion(QualType FromType, QualType ToType);
1368  bool IsComplexPromotion(QualType FromType, QualType ToType);
1369  bool IsPointerConversion(Expr *From, QualType FromType, QualType ToType,
1370                           bool InOverloadResolution,
1371                           QualType& ConvertedType, bool &IncompatibleObjC);
1372  bool isObjCPointerConversion(QualType FromType, QualType ToType,
1373                               QualType& ConvertedType, bool &IncompatibleObjC);
1374  bool isObjCWritebackConversion(QualType FromType, QualType ToType,
1375                                 QualType &ConvertedType);
1376  bool IsBlockPointerConversion(QualType FromType, QualType ToType,
1377                                QualType& ConvertedType);
1378  bool isSentinelNullExpr(const Expr *E) const;
1379  bool FunctionArgTypesAreEqual(const FunctionProtoType *OldType,
1380                                const FunctionProtoType *NewType,
1381                                unsigned *ArgPos = 0);
1382  void HandleFunctionTypeMismatch(PartialDiagnostic &PDiag,
1383                                  QualType FromType, QualType ToType);
1384
1385  CastKind PrepareCastToObjCObjectPointer(ExprResult &E);
1386  bool CheckPointerConversion(Expr *From, QualType ToType,
1387                              CastKind &Kind,
1388                              CXXCastPath& BasePath,
1389                              bool IgnoreBaseAccess);
1390  bool IsMemberPointerConversion(Expr *From, QualType FromType, QualType ToType,
1391                                 bool InOverloadResolution,
1392                                 QualType &ConvertedType);
1393  bool CheckMemberPointerConversion(Expr *From, QualType ToType,
1394                                    CastKind &Kind,
1395                                    CXXCastPath &BasePath,
1396                                    bool IgnoreBaseAccess);
1397  bool IsQualificationConversion(QualType FromType, QualType ToType,
1398                                 bool CStyle, bool &ObjCLifetimeConversion);
1399  bool IsNoReturnConversion(QualType FromType, QualType ToType,
1400                            QualType &ResultTy);
1401  bool DiagnoseMultipleUserDefinedConversion(Expr *From, QualType ToType);
1402
1403
1404  ExprResult PerformMoveOrCopyInitialization(const InitializedEntity &Entity,
1405                                             const VarDecl *NRVOCandidate,
1406                                             QualType ResultType,
1407                                             Expr *Value,
1408                                             bool AllowNRVO = true);
1409
1410  bool CanPerformCopyInitialization(const InitializedEntity &Entity,
1411                                    ExprResult Init);
1412  ExprResult PerformCopyInitialization(const InitializedEntity &Entity,
1413                                       SourceLocation EqualLoc,
1414                                       ExprResult Init,
1415                                       bool TopLevelOfInitList = false);
1416  ExprResult PerformObjectArgumentInitialization(Expr *From,
1417                                                 NestedNameSpecifier *Qualifier,
1418                                                 NamedDecl *FoundDecl,
1419                                                 CXXMethodDecl *Method);
1420
1421  ExprResult PerformContextuallyConvertToBool(Expr *From);
1422  ExprResult PerformContextuallyConvertToObjCPointer(Expr *From);
1423
1424  /// Contexts in which a converted constant expression is required.
1425  enum CCEKind {
1426    CCEK_CaseValue,  ///< Expression in a case label.
1427    CCEK_Enumerator, ///< Enumerator value with fixed underlying type.
1428    CCEK_TemplateArg ///< Value of a non-type template parameter.
1429  };
1430  ExprResult CheckConvertedConstantExpression(Expr *From, QualType T,
1431                                              llvm::APSInt &Value, CCEKind CCE);
1432
1433  ExprResult
1434  ConvertToIntegralOrEnumerationType(SourceLocation Loc, Expr *FromE,
1435                                     const PartialDiagnostic &NotIntDiag,
1436                                     const PartialDiagnostic &IncompleteDiag,
1437                                     const PartialDiagnostic &ExplicitConvDiag,
1438                                     const PartialDiagnostic &ExplicitConvNote,
1439                                     const PartialDiagnostic &AmbigDiag,
1440                                     const PartialDiagnostic &AmbigNote,
1441                                     const PartialDiagnostic &ConvDiag);
1442
1443  ExprResult PerformObjectMemberConversion(Expr *From,
1444                                           NestedNameSpecifier *Qualifier,
1445                                           NamedDecl *FoundDecl,
1446                                           NamedDecl *Member);
1447
1448  // Members have to be NamespaceDecl* or TranslationUnitDecl*.
1449  // TODO: make this is a typesafe union.
1450  typedef llvm::SmallPtrSet<DeclContext   *, 16> AssociatedNamespaceSet;
1451  typedef llvm::SmallPtrSet<CXXRecordDecl *, 16> AssociatedClassSet;
1452
1453  void AddOverloadCandidate(NamedDecl *Function,
1454                            DeclAccessPair FoundDecl,
1455                            Expr **Args, unsigned NumArgs,
1456                            OverloadCandidateSet &CandidateSet);
1457
1458  void AddOverloadCandidate(FunctionDecl *Function,
1459                            DeclAccessPair FoundDecl,
1460                            Expr **Args, unsigned NumArgs,
1461                            OverloadCandidateSet& CandidateSet,
1462                            bool SuppressUserConversions = false,
1463                            bool PartialOverloading = false);
1464  void AddFunctionCandidates(const UnresolvedSetImpl &Functions,
1465                             Expr **Args, unsigned NumArgs,
1466                             OverloadCandidateSet& CandidateSet,
1467                             bool SuppressUserConversions = false);
1468  void AddMethodCandidate(DeclAccessPair FoundDecl,
1469                          QualType ObjectType,
1470                          Expr::Classification ObjectClassification,
1471                          Expr **Args, unsigned NumArgs,
1472                          OverloadCandidateSet& CandidateSet,
1473                          bool SuppressUserConversion = false);
1474  void AddMethodCandidate(CXXMethodDecl *Method,
1475                          DeclAccessPair FoundDecl,
1476                          CXXRecordDecl *ActingContext, QualType ObjectType,
1477                          Expr::Classification ObjectClassification,
1478                          Expr **Args, unsigned NumArgs,
1479                          OverloadCandidateSet& CandidateSet,
1480                          bool SuppressUserConversions = false);
1481  void AddMethodTemplateCandidate(FunctionTemplateDecl *MethodTmpl,
1482                                  DeclAccessPair FoundDecl,
1483                                  CXXRecordDecl *ActingContext,
1484                                 TemplateArgumentListInfo *ExplicitTemplateArgs,
1485                                  QualType ObjectType,
1486                                  Expr::Classification ObjectClassification,
1487                                  Expr **Args, unsigned NumArgs,
1488                                  OverloadCandidateSet& CandidateSet,
1489                                  bool SuppressUserConversions = false);
1490  void AddTemplateOverloadCandidate(FunctionTemplateDecl *FunctionTemplate,
1491                                    DeclAccessPair FoundDecl,
1492                                 TemplateArgumentListInfo *ExplicitTemplateArgs,
1493                                    Expr **Args, unsigned NumArgs,
1494                                    OverloadCandidateSet& CandidateSet,
1495                                    bool SuppressUserConversions = false);
1496  void AddConversionCandidate(CXXConversionDecl *Conversion,
1497                              DeclAccessPair FoundDecl,
1498                              CXXRecordDecl *ActingContext,
1499                              Expr *From, QualType ToType,
1500                              OverloadCandidateSet& CandidateSet);
1501  void AddTemplateConversionCandidate(FunctionTemplateDecl *FunctionTemplate,
1502                                      DeclAccessPair FoundDecl,
1503                                      CXXRecordDecl *ActingContext,
1504                                      Expr *From, QualType ToType,
1505                                      OverloadCandidateSet &CandidateSet);
1506  void AddSurrogateCandidate(CXXConversionDecl *Conversion,
1507                             DeclAccessPair FoundDecl,
1508                             CXXRecordDecl *ActingContext,
1509                             const FunctionProtoType *Proto,
1510                             Expr *Object, Expr **Args, unsigned NumArgs,
1511                             OverloadCandidateSet& CandidateSet);
1512  void AddMemberOperatorCandidates(OverloadedOperatorKind Op,
1513                                   SourceLocation OpLoc,
1514                                   Expr **Args, unsigned NumArgs,
1515                                   OverloadCandidateSet& CandidateSet,
1516                                   SourceRange OpRange = SourceRange());
1517  void AddBuiltinCandidate(QualType ResultTy, QualType *ParamTys,
1518                           Expr **Args, unsigned NumArgs,
1519                           OverloadCandidateSet& CandidateSet,
1520                           bool IsAssignmentOperator = false,
1521                           unsigned NumContextualBoolArguments = 0);
1522  void AddBuiltinOperatorCandidates(OverloadedOperatorKind Op,
1523                                    SourceLocation OpLoc,
1524                                    Expr **Args, unsigned NumArgs,
1525                                    OverloadCandidateSet& CandidateSet);
1526  void AddArgumentDependentLookupCandidates(DeclarationName Name,
1527                                            bool Operator,
1528                                            Expr **Args, unsigned NumArgs,
1529                                TemplateArgumentListInfo *ExplicitTemplateArgs,
1530                                            OverloadCandidateSet& CandidateSet,
1531                                            bool PartialOverloading = false,
1532                                        bool StdNamespaceIsAssociated = false);
1533
1534  // Emit as a 'note' the specific overload candidate
1535  void NoteOverloadCandidate(FunctionDecl *Fn, QualType DestType = QualType());
1536
1537  // Emit as a series of 'note's all template and non-templates
1538  // identified by the expression Expr
1539  void NoteAllOverloadCandidates(Expr* E, QualType DestType = QualType());
1540
1541  // [PossiblyAFunctionType]  -->   [Return]
1542  // NonFunctionType --> NonFunctionType
1543  // R (A) --> R(A)
1544  // R (*)(A) --> R (A)
1545  // R (&)(A) --> R (A)
1546  // R (S::*)(A) --> R (A)
1547  QualType ExtractUnqualifiedFunctionType(QualType PossiblyAFunctionType);
1548
1549  FunctionDecl *
1550  ResolveAddressOfOverloadedFunction(Expr *AddressOfExpr,
1551                                     QualType TargetType,
1552                                     bool Complain,
1553                                     DeclAccessPair &Found,
1554                                     bool *pHadMultipleCandidates = 0);
1555
1556  FunctionDecl *ResolveSingleFunctionTemplateSpecialization(OverloadExpr *ovl,
1557                                                   bool Complain = false,
1558                                                   DeclAccessPair* Found = 0);
1559
1560  bool ResolveAndFixSingleFunctionTemplateSpecialization(
1561                      ExprResult &SrcExpr,
1562                      bool DoFunctionPointerConverion = false,
1563                      bool Complain = false,
1564                      const SourceRange& OpRangeForComplaining = SourceRange(),
1565                      QualType DestTypeForComplaining = QualType(),
1566                      unsigned DiagIDForComplaining = 0);
1567
1568
1569  Expr *FixOverloadedFunctionReference(Expr *E,
1570                                       DeclAccessPair FoundDecl,
1571                                       FunctionDecl *Fn);
1572  ExprResult FixOverloadedFunctionReference(ExprResult,
1573                                            DeclAccessPair FoundDecl,
1574                                            FunctionDecl *Fn);
1575
1576  void AddOverloadedCallCandidates(UnresolvedLookupExpr *ULE,
1577                                   Expr **Args, unsigned NumArgs,
1578                                   OverloadCandidateSet &CandidateSet,
1579                                   bool PartialOverloading = false);
1580
1581  ExprResult BuildOverloadedCallExpr(Scope *S, Expr *Fn,
1582                                     UnresolvedLookupExpr *ULE,
1583                                     SourceLocation LParenLoc,
1584                                     Expr **Args, unsigned NumArgs,
1585                                     SourceLocation RParenLoc,
1586                                     Expr *ExecConfig,
1587                                     bool AllowTypoCorrection=true);
1588
1589  ExprResult CreateOverloadedUnaryOp(SourceLocation OpLoc,
1590                                     unsigned Opc,
1591                                     const UnresolvedSetImpl &Fns,
1592                                     Expr *input);
1593
1594  ExprResult CreateOverloadedBinOp(SourceLocation OpLoc,
1595                                   unsigned Opc,
1596                                   const UnresolvedSetImpl &Fns,
1597                                   Expr *LHS, Expr *RHS);
1598
1599  ExprResult CreateOverloadedArraySubscriptExpr(SourceLocation LLoc,
1600                                                SourceLocation RLoc,
1601                                                Expr *Base,Expr *Idx);
1602
1603  ExprResult
1604  BuildCallToMemberFunction(Scope *S, Expr *MemExpr,
1605                            SourceLocation LParenLoc, Expr **Args,
1606                            unsigned NumArgs, SourceLocation RParenLoc);
1607  ExprResult
1608  BuildCallToObjectOfClassType(Scope *S, Expr *Object, SourceLocation LParenLoc,
1609                               Expr **Args, unsigned NumArgs,
1610                               SourceLocation RParenLoc);
1611
1612  ExprResult BuildOverloadedArrowExpr(Scope *S, Expr *Base,
1613                                      SourceLocation OpLoc);
1614
1615  /// CheckCallReturnType - Checks that a call expression's return type is
1616  /// complete. Returns true on failure. The location passed in is the location
1617  /// that best represents the call.
1618  bool CheckCallReturnType(QualType ReturnType, SourceLocation Loc,
1619                           CallExpr *CE, FunctionDecl *FD);
1620
1621  /// Helpers for dealing with blocks and functions.
1622  bool CheckParmsForFunctionDef(ParmVarDecl **Param, ParmVarDecl **ParamEnd,
1623                                bool CheckParameterNames);
1624  void CheckCXXDefaultArguments(FunctionDecl *FD);
1625  void CheckExtraCXXDefaultArguments(Declarator &D);
1626  Scope *getNonFieldDeclScope(Scope *S);
1627
1628  /// \name Name lookup
1629  ///
1630  /// These routines provide name lookup that is used during semantic
1631  /// analysis to resolve the various kinds of names (identifiers,
1632  /// overloaded operator names, constructor names, etc.) into zero or
1633  /// more declarations within a particular scope. The major entry
1634  /// points are LookupName, which performs unqualified name lookup,
1635  /// and LookupQualifiedName, which performs qualified name lookup.
1636  ///
1637  /// All name lookup is performed based on some specific criteria,
1638  /// which specify what names will be visible to name lookup and how
1639  /// far name lookup should work. These criteria are important both
1640  /// for capturing language semantics (certain lookups will ignore
1641  /// certain names, for example) and for performance, since name
1642  /// lookup is often a bottleneck in the compilation of C++. Name
1643  /// lookup criteria is specified via the LookupCriteria enumeration.
1644  ///
1645  /// The results of name lookup can vary based on the kind of name
1646  /// lookup performed, the current language, and the translation
1647  /// unit. In C, for example, name lookup will either return nothing
1648  /// (no entity found) or a single declaration. In C++, name lookup
1649  /// can additionally refer to a set of overloaded functions or
1650  /// result in an ambiguity. All of the possible results of name
1651  /// lookup are captured by the LookupResult class, which provides
1652  /// the ability to distinguish among them.
1653  //@{
1654
1655  /// @brief Describes the kind of name lookup to perform.
1656  enum LookupNameKind {
1657    /// Ordinary name lookup, which finds ordinary names (functions,
1658    /// variables, typedefs, etc.) in C and most kinds of names
1659    /// (functions, variables, members, types, etc.) in C++.
1660    LookupOrdinaryName = 0,
1661    /// Tag name lookup, which finds the names of enums, classes,
1662    /// structs, and unions.
1663    LookupTagName,
1664    /// Label name lookup.
1665    LookupLabel,
1666    /// Member name lookup, which finds the names of
1667    /// class/struct/union members.
1668    LookupMemberName,
1669    /// Look up of an operator name (e.g., operator+) for use with
1670    /// operator overloading. This lookup is similar to ordinary name
1671    /// lookup, but will ignore any declarations that are class members.
1672    LookupOperatorName,
1673    /// Look up of a name that precedes the '::' scope resolution
1674    /// operator in C++. This lookup completely ignores operator, object,
1675    /// function, and enumerator names (C++ [basic.lookup.qual]p1).
1676    LookupNestedNameSpecifierName,
1677    /// Look up a namespace name within a C++ using directive or
1678    /// namespace alias definition, ignoring non-namespace names (C++
1679    /// [basic.lookup.udir]p1).
1680    LookupNamespaceName,
1681    /// Look up all declarations in a scope with the given name,
1682    /// including resolved using declarations.  This is appropriate
1683    /// for checking redeclarations for a using declaration.
1684    LookupUsingDeclName,
1685    /// Look up an ordinary name that is going to be redeclared as a
1686    /// name with linkage. This lookup ignores any declarations that
1687    /// are outside of the current scope unless they have linkage. See
1688    /// C99 6.2.2p4-5 and C++ [basic.link]p6.
1689    LookupRedeclarationWithLinkage,
1690    /// Look up the name of an Objective-C protocol.
1691    LookupObjCProtocolName,
1692    /// Look up implicit 'self' parameter of an objective-c method.
1693    LookupObjCImplicitSelfParam,
1694    /// \brief Look up any declaration with any name.
1695    LookupAnyName
1696  };
1697
1698  /// \brief Specifies whether (or how) name lookup is being performed for a
1699  /// redeclaration (vs. a reference).
1700  enum RedeclarationKind {
1701    /// \brief The lookup is a reference to this name that is not for the
1702    /// purpose of redeclaring the name.
1703    NotForRedeclaration = 0,
1704    /// \brief The lookup results will be used for redeclaration of a name,
1705    /// if an entity by that name already exists.
1706    ForRedeclaration
1707  };
1708
1709private:
1710  bool CppLookupName(LookupResult &R, Scope *S);
1711
1712  SpecialMemberOverloadResult *LookupSpecialMember(CXXRecordDecl *D,
1713                                                   CXXSpecialMember SM,
1714                                                   bool ConstArg,
1715                                                   bool VolatileArg,
1716                                                   bool RValueThis,
1717                                                   bool ConstThis,
1718                                                   bool VolatileThis);
1719
1720  // \brief The set of known/encountered (unique, canonicalized) NamespaceDecls.
1721  //
1722  // The boolean value will be true to indicate that the namespace was loaded
1723  // from an AST/PCH file, or false otherwise.
1724  llvm::DenseMap<NamespaceDecl*, bool> KnownNamespaces;
1725
1726  /// \brief Whether we have already loaded known namespaces from an extenal
1727  /// source.
1728  bool LoadedExternalKnownNamespaces;
1729
1730public:
1731  /// \brief Look up a name, looking for a single declaration.  Return
1732  /// null if the results were absent, ambiguous, or overloaded.
1733  ///
1734  /// It is preferable to use the elaborated form and explicitly handle
1735  /// ambiguity and overloaded.
1736  NamedDecl *LookupSingleName(Scope *S, DeclarationName Name,
1737                              SourceLocation Loc,
1738                              LookupNameKind NameKind,
1739                              RedeclarationKind Redecl
1740                                = NotForRedeclaration);
1741  bool LookupName(LookupResult &R, Scope *S,
1742                  bool AllowBuiltinCreation = false);
1743  bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx,
1744                           bool InUnqualifiedLookup = false);
1745  bool LookupParsedName(LookupResult &R, Scope *S, CXXScopeSpec *SS,
1746                        bool AllowBuiltinCreation = false,
1747                        bool EnteringContext = false);
1748  ObjCProtocolDecl *LookupProtocol(IdentifierInfo *II, SourceLocation IdLoc,
1749                                   RedeclarationKind Redecl
1750                                     = NotForRedeclaration);
1751
1752  void LookupOverloadedOperatorName(OverloadedOperatorKind Op, Scope *S,
1753                                    QualType T1, QualType T2,
1754                                    UnresolvedSetImpl &Functions);
1755
1756  LabelDecl *LookupOrCreateLabel(IdentifierInfo *II, SourceLocation IdentLoc,
1757                                 SourceLocation GnuLabelLoc = SourceLocation());
1758
1759  DeclContextLookupResult LookupConstructors(CXXRecordDecl *Class);
1760  CXXConstructorDecl *LookupDefaultConstructor(CXXRecordDecl *Class);
1761  CXXConstructorDecl *LookupCopyingConstructor(CXXRecordDecl *Class,
1762                                               unsigned Quals,
1763                                               bool *ConstParam = 0);
1764  CXXMethodDecl *LookupCopyingAssignment(CXXRecordDecl *Class, unsigned Quals,
1765                                         bool RValueThis, unsigned ThisQuals,
1766                                         bool *ConstParam = 0);
1767  CXXConstructorDecl *LookupMovingConstructor(CXXRecordDecl *Class);
1768  CXXMethodDecl *LookupMovingAssignment(CXXRecordDecl *Class, bool RValueThis,
1769                                        unsigned ThisQuals);
1770  CXXDestructorDecl *LookupDestructor(CXXRecordDecl *Class);
1771
1772  void ArgumentDependentLookup(DeclarationName Name, bool Operator,
1773                               Expr **Args, unsigned NumArgs,
1774                               ADLResult &Functions,
1775                               bool StdNamespaceIsAssociated = false);
1776
1777  void LookupVisibleDecls(Scope *S, LookupNameKind Kind,
1778                          VisibleDeclConsumer &Consumer,
1779                          bool IncludeGlobalScope = true);
1780  void LookupVisibleDecls(DeclContext *Ctx, LookupNameKind Kind,
1781                          VisibleDeclConsumer &Consumer,
1782                          bool IncludeGlobalScope = true);
1783
1784  TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo,
1785                             Sema::LookupNameKind LookupKind,
1786                             Scope *S, CXXScopeSpec *SS,
1787                             CorrectionCandidateCallback *CCC,
1788                             DeclContext *MemberContext = 0,
1789                             bool EnteringContext = false,
1790                             const ObjCObjectPointerType *OPT = 0);
1791
1792  void FindAssociatedClassesAndNamespaces(Expr **Args, unsigned NumArgs,
1793                                   AssociatedNamespaceSet &AssociatedNamespaces,
1794                                   AssociatedClassSet &AssociatedClasses);
1795
1796  void FilterLookupForScope(LookupResult &R, DeclContext *Ctx, Scope *S,
1797                            bool ConsiderLinkage,
1798                            bool ExplicitInstantiationOrSpecialization);
1799
1800  bool DiagnoseAmbiguousLookup(LookupResult &Result);
1801  //@}
1802
1803  ObjCInterfaceDecl *getObjCInterfaceDecl(IdentifierInfo *&Id,
1804                                          SourceLocation IdLoc,
1805                                          bool TypoCorrection = false);
1806  NamedDecl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID,
1807                                 Scope *S, bool ForRedeclaration,
1808                                 SourceLocation Loc);
1809  NamedDecl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II,
1810                                      Scope *S);
1811  void AddKnownFunctionAttributes(FunctionDecl *FD);
1812
1813  // More parsing and symbol table subroutines.
1814
1815  // Decl attributes - this routine is the top level dispatcher.
1816  void ProcessDeclAttributes(Scope *S, Decl *D, const Declarator &PD,
1817                           bool NonInheritable = true, bool Inheritable = true);
1818  void ProcessDeclAttributeList(Scope *S, Decl *D, const AttributeList *AL,
1819                           bool NonInheritable = true, bool Inheritable = true);
1820  bool ProcessAccessDeclAttributeList(AccessSpecDecl *ASDecl,
1821                                      const AttributeList *AttrList);
1822
1823  void checkUnusedDeclAttributes(Declarator &D);
1824
1825  bool CheckRegparmAttr(const AttributeList &attr, unsigned &value);
1826  bool CheckCallingConvAttr(const AttributeList &attr, CallingConv &CC);
1827  bool CheckNoReturnAttr(const AttributeList &attr);
1828
1829  void WarnUndefinedMethod(SourceLocation ImpLoc, ObjCMethodDecl *method,
1830                           bool &IncompleteImpl, unsigned DiagID);
1831  void WarnConflictingTypedMethods(ObjCMethodDecl *Method,
1832                                   ObjCMethodDecl *MethodDecl,
1833                                   bool IsProtocolMethodDecl);
1834
1835  void CheckConflictingOverridingMethod(ObjCMethodDecl *Method,
1836                                   ObjCMethodDecl *Overridden,
1837                                   bool IsProtocolMethodDecl);
1838
1839  /// WarnExactTypedMethods - This routine issues a warning if method
1840  /// implementation declaration matches exactly that of its declaration.
1841  void WarnExactTypedMethods(ObjCMethodDecl *Method,
1842                             ObjCMethodDecl *MethodDecl,
1843                             bool IsProtocolMethodDecl);
1844
1845  bool isPropertyReadonly(ObjCPropertyDecl *PropertyDecl,
1846                          ObjCInterfaceDecl *IDecl);
1847
1848  typedef llvm::DenseSet<Selector, llvm::DenseMapInfo<Selector> > SelectorSet;
1849  typedef llvm::DenseMap<Selector, ObjCMethodDecl*> ProtocolsMethodsMap;
1850
1851  /// CheckProtocolMethodDefs - This routine checks unimplemented
1852  /// methods declared in protocol, and those referenced by it.
1853  /// \param IDecl - Used for checking for methods which may have been
1854  /// inherited.
1855  void CheckProtocolMethodDefs(SourceLocation ImpLoc,
1856                               ObjCProtocolDecl *PDecl,
1857                               bool& IncompleteImpl,
1858                               const SelectorSet &InsMap,
1859                               const SelectorSet &ClsMap,
1860                               ObjCContainerDecl *CDecl);
1861
1862  /// CheckImplementationIvars - This routine checks if the instance variables
1863  /// listed in the implelementation match those listed in the interface.
1864  void CheckImplementationIvars(ObjCImplementationDecl *ImpDecl,
1865                                ObjCIvarDecl **Fields, unsigned nIvars,
1866                                SourceLocation Loc);
1867
1868  /// ImplMethodsVsClassMethods - This is main routine to warn if any method
1869  /// remains unimplemented in the class or category @implementation.
1870  void ImplMethodsVsClassMethods(Scope *S, ObjCImplDecl* IMPDecl,
1871                                 ObjCContainerDecl* IDecl,
1872                                 bool IncompleteImpl = false);
1873
1874  /// DiagnoseUnimplementedProperties - This routine warns on those properties
1875  /// which must be implemented by this implementation.
1876  void DiagnoseUnimplementedProperties(Scope *S, ObjCImplDecl* IMPDecl,
1877                                       ObjCContainerDecl *CDecl,
1878                                       const SelectorSet &InsMap);
1879
1880  /// DefaultSynthesizeProperties - This routine default synthesizes all
1881  /// properties which must be synthesized in class's @implementation.
1882  void DefaultSynthesizeProperties (Scope *S, ObjCImplDecl* IMPDecl,
1883                                    ObjCInterfaceDecl *IDecl);
1884  void DefaultSynthesizeProperties(Scope *S, Decl *D);
1885
1886  /// CollectImmediateProperties - This routine collects all properties in
1887  /// the class and its conforming protocols; but not those it its super class.
1888  void CollectImmediateProperties(ObjCContainerDecl *CDecl,
1889            llvm::DenseMap<IdentifierInfo *, ObjCPropertyDecl*>& PropMap,
1890            llvm::DenseMap<IdentifierInfo *, ObjCPropertyDecl*>& SuperPropMap);
1891
1892
1893  /// LookupPropertyDecl - Looks up a property in the current class and all
1894  /// its protocols.
1895  ObjCPropertyDecl *LookupPropertyDecl(const ObjCContainerDecl *CDecl,
1896                                       IdentifierInfo *II);
1897
1898  /// Called by ActOnProperty to handle @property declarations in
1899  ////  class extensions.
1900  Decl *HandlePropertyInClassExtension(Scope *S,
1901                                       SourceLocation AtLoc,
1902                                       FieldDeclarator &FD,
1903                                       Selector GetterSel,
1904                                       Selector SetterSel,
1905                                       const bool isAssign,
1906                                       const bool isReadWrite,
1907                                       const unsigned Attributes,
1908                                       const unsigned AttributesAsWritten,
1909                                       bool *isOverridingProperty,
1910                                       TypeSourceInfo *T,
1911                                       tok::ObjCKeywordKind MethodImplKind);
1912
1913  /// Called by ActOnProperty and HandlePropertyInClassExtension to
1914  ///  handle creating the ObjcPropertyDecl for a category or @interface.
1915  ObjCPropertyDecl *CreatePropertyDecl(Scope *S,
1916                                       ObjCContainerDecl *CDecl,
1917                                       SourceLocation AtLoc,
1918                                       FieldDeclarator &FD,
1919                                       Selector GetterSel,
1920                                       Selector SetterSel,
1921                                       const bool isAssign,
1922                                       const bool isReadWrite,
1923                                       const unsigned Attributes,
1924                                       const unsigned AttributesAsWritten,
1925                                       TypeSourceInfo *T,
1926                                       tok::ObjCKeywordKind MethodImplKind,
1927                                       DeclContext *lexicalDC = 0);
1928
1929  /// AtomicPropertySetterGetterRules - This routine enforces the rule (via
1930  /// warning) when atomic property has one but not the other user-declared
1931  /// setter or getter.
1932  void AtomicPropertySetterGetterRules(ObjCImplDecl* IMPDecl,
1933                                       ObjCContainerDecl* IDecl);
1934
1935  void DiagnoseOwningPropertyGetterSynthesis(const ObjCImplementationDecl *D);
1936
1937  void DiagnoseDuplicateIvars(ObjCInterfaceDecl *ID, ObjCInterfaceDecl *SID);
1938
1939  enum MethodMatchStrategy {
1940    MMS_loose,
1941    MMS_strict
1942  };
1943
1944  /// MatchTwoMethodDeclarations - Checks if two methods' type match and returns
1945  /// true, or false, accordingly.
1946  bool MatchTwoMethodDeclarations(const ObjCMethodDecl *Method,
1947                                  const ObjCMethodDecl *PrevMethod,
1948                                  MethodMatchStrategy strategy = MMS_strict);
1949
1950  /// MatchAllMethodDeclarations - Check methods declaraed in interface or
1951  /// or protocol against those declared in their implementations.
1952  void MatchAllMethodDeclarations(const SelectorSet &InsMap,
1953                                  const SelectorSet &ClsMap,
1954                                  SelectorSet &InsMapSeen,
1955                                  SelectorSet &ClsMapSeen,
1956                                  ObjCImplDecl* IMPDecl,
1957                                  ObjCContainerDecl* IDecl,
1958                                  bool &IncompleteImpl,
1959                                  bool ImmediateClass,
1960                                  bool WarnExactMatch=false);
1961
1962  /// CheckCategoryVsClassMethodMatches - Checks that methods implemented in
1963  /// category matches with those implemented in its primary class and
1964  /// warns each time an exact match is found.
1965  void CheckCategoryVsClassMethodMatches(ObjCCategoryImplDecl *CatIMP);
1966
1967  /// \brief Add the given method to the list of globally-known methods.
1968  void addMethodToGlobalList(ObjCMethodList *List, ObjCMethodDecl *Method);
1969
1970private:
1971  /// AddMethodToGlobalPool - Add an instance or factory method to the global
1972  /// pool. See descriptoin of AddInstanceMethodToGlobalPool.
1973  void AddMethodToGlobalPool(ObjCMethodDecl *Method, bool impl, bool instance);
1974
1975  /// LookupMethodInGlobalPool - Returns the instance or factory method and
1976  /// optionally warns if there are multiple signatures.
1977  ObjCMethodDecl *LookupMethodInGlobalPool(Selector Sel, SourceRange R,
1978                                           bool receiverIdOrClass,
1979                                           bool warn, bool instance);
1980
1981public:
1982  /// AddInstanceMethodToGlobalPool - All instance methods in a translation
1983  /// unit are added to a global pool. This allows us to efficiently associate
1984  /// a selector with a method declaraation for purposes of typechecking
1985  /// messages sent to "id" (where the class of the object is unknown).
1986  void AddInstanceMethodToGlobalPool(ObjCMethodDecl *Method, bool impl=false) {
1987    AddMethodToGlobalPool(Method, impl, /*instance*/true);
1988  }
1989
1990  /// AddFactoryMethodToGlobalPool - Same as above, but for factory methods.
1991  void AddFactoryMethodToGlobalPool(ObjCMethodDecl *Method, bool impl=false) {
1992    AddMethodToGlobalPool(Method, impl, /*instance*/false);
1993  }
1994
1995  /// AddAnyMethodToGlobalPool - Add any method, instance or factory to global
1996  /// pool.
1997  void AddAnyMethodToGlobalPool(Decl *D);
1998
1999  /// LookupInstanceMethodInGlobalPool - Returns the method and warns if
2000  /// there are multiple signatures.
2001  ObjCMethodDecl *LookupInstanceMethodInGlobalPool(Selector Sel, SourceRange R,
2002                                                   bool receiverIdOrClass=false,
2003                                                   bool warn=true) {
2004    return LookupMethodInGlobalPool(Sel, R, receiverIdOrClass,
2005                                    warn, /*instance*/true);
2006  }
2007
2008  /// LookupFactoryMethodInGlobalPool - Returns the method and warns if
2009  /// there are multiple signatures.
2010  ObjCMethodDecl *LookupFactoryMethodInGlobalPool(Selector Sel, SourceRange R,
2011                                                  bool receiverIdOrClass=false,
2012                                                  bool warn=true) {
2013    return LookupMethodInGlobalPool(Sel, R, receiverIdOrClass,
2014                                    warn, /*instance*/false);
2015  }
2016
2017  /// LookupImplementedMethodInGlobalPool - Returns the method which has an
2018  /// implementation.
2019  ObjCMethodDecl *LookupImplementedMethodInGlobalPool(Selector Sel);
2020
2021  /// CollectIvarsToConstructOrDestruct - Collect those ivars which require
2022  /// initialization.
2023  void CollectIvarsToConstructOrDestruct(ObjCInterfaceDecl *OI,
2024                                  SmallVectorImpl<ObjCIvarDecl*> &Ivars);
2025
2026  //===--------------------------------------------------------------------===//
2027  // Statement Parsing Callbacks: SemaStmt.cpp.
2028public:
2029  class FullExprArg {
2030  public:
2031    FullExprArg(Sema &actions) : E(0) { }
2032
2033    // FIXME: The const_cast here is ugly. RValue references would make this
2034    // much nicer (or we could duplicate a bunch of the move semantics
2035    // emulation code from Ownership.h).
2036    FullExprArg(const FullExprArg& Other) : E(Other.E) {}
2037
2038    ExprResult release() {
2039      return move(E);
2040    }
2041
2042    Expr *get() const { return E; }
2043
2044    Expr *operator->() {
2045      return E;
2046    }
2047
2048  private:
2049    // FIXME: No need to make the entire Sema class a friend when it's just
2050    // Sema::MakeFullExpr that needs access to the constructor below.
2051    friend class Sema;
2052
2053    explicit FullExprArg(Expr *expr) : E(expr) {}
2054
2055    Expr *E;
2056  };
2057
2058  FullExprArg MakeFullExpr(Expr *Arg) {
2059    return FullExprArg(ActOnFinishFullExpr(Arg).release());
2060  }
2061
2062  StmtResult ActOnExprStmt(FullExprArg Expr);
2063
2064  StmtResult ActOnNullStmt(SourceLocation SemiLoc,
2065                           bool HasLeadingEmptyMacro = false);
2066  StmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R,
2067                                       MultiStmtArg Elts,
2068                                       bool isStmtExpr);
2069  StmtResult ActOnDeclStmt(DeclGroupPtrTy Decl,
2070                                   SourceLocation StartLoc,
2071                                   SourceLocation EndLoc);
2072  void ActOnForEachDeclStmt(DeclGroupPtrTy Decl);
2073  StmtResult ActOnForEachLValueExpr(Expr *E);
2074  StmtResult ActOnCaseStmt(SourceLocation CaseLoc, Expr *LHSVal,
2075                                   SourceLocation DotDotDotLoc, Expr *RHSVal,
2076                                   SourceLocation ColonLoc);
2077  void ActOnCaseStmtBody(Stmt *CaseStmt, Stmt *SubStmt);
2078
2079  StmtResult ActOnDefaultStmt(SourceLocation DefaultLoc,
2080                                      SourceLocation ColonLoc,
2081                                      Stmt *SubStmt, Scope *CurScope);
2082  StmtResult ActOnLabelStmt(SourceLocation IdentLoc, LabelDecl *TheDecl,
2083                            SourceLocation ColonLoc, Stmt *SubStmt);
2084
2085  StmtResult ActOnIfStmt(SourceLocation IfLoc,
2086                         FullExprArg CondVal, Decl *CondVar,
2087                         Stmt *ThenVal,
2088                         SourceLocation ElseLoc, Stmt *ElseVal);
2089  StmtResult ActOnStartOfSwitchStmt(SourceLocation SwitchLoc,
2090                                            Expr *Cond,
2091                                            Decl *CondVar);
2092  StmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc,
2093                                           Stmt *Switch, Stmt *Body);
2094  StmtResult ActOnWhileStmt(SourceLocation WhileLoc,
2095                            FullExprArg Cond,
2096                            Decl *CondVar, Stmt *Body);
2097  StmtResult ActOnDoStmt(SourceLocation DoLoc, Stmt *Body,
2098                                 SourceLocation WhileLoc,
2099                                 SourceLocation CondLParen, Expr *Cond,
2100                                 SourceLocation CondRParen);
2101
2102  StmtResult ActOnForStmt(SourceLocation ForLoc,
2103                          SourceLocation LParenLoc,
2104                          Stmt *First, FullExprArg Second,
2105                          Decl *SecondVar,
2106                          FullExprArg Third,
2107                          SourceLocation RParenLoc,
2108                          Stmt *Body);
2109  ExprResult ActOnObjCForCollectionOperand(SourceLocation forLoc,
2110                                           Expr *collection);
2111  StmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc,
2112                                        SourceLocation LParenLoc,
2113                                        Stmt *First, Expr *Second,
2114                                        SourceLocation RParenLoc, Stmt *Body);
2115  StmtResult ActOnCXXForRangeStmt(SourceLocation ForLoc,
2116                                  SourceLocation LParenLoc, Stmt *LoopVar,
2117                                  SourceLocation ColonLoc, Expr *Collection,
2118                                  SourceLocation RParenLoc);
2119  StmtResult BuildCXXForRangeStmt(SourceLocation ForLoc,
2120                                  SourceLocation ColonLoc,
2121                                  Stmt *RangeDecl, Stmt *BeginEndDecl,
2122                                  Expr *Cond, Expr *Inc,
2123                                  Stmt *LoopVarDecl,
2124                                  SourceLocation RParenLoc);
2125  StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body);
2126
2127  StmtResult ActOnGotoStmt(SourceLocation GotoLoc,
2128                           SourceLocation LabelLoc,
2129                           LabelDecl *TheDecl);
2130  StmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc,
2131                                   SourceLocation StarLoc,
2132                                   Expr *DestExp);
2133  StmtResult ActOnContinueStmt(SourceLocation ContinueLoc, Scope *CurScope);
2134  StmtResult ActOnBreakStmt(SourceLocation GotoLoc, Scope *CurScope);
2135
2136  const VarDecl *getCopyElisionCandidate(QualType ReturnType, Expr *E,
2137                                         bool AllowFunctionParameters);
2138
2139  StmtResult ActOnReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp);
2140  StmtResult ActOnCapScopeReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp);
2141
2142  StmtResult ActOnAsmStmt(SourceLocation AsmLoc,
2143                          bool IsSimple, bool IsVolatile,
2144                          unsigned NumOutputs, unsigned NumInputs,
2145                          IdentifierInfo **Names,
2146                          MultiExprArg Constraints,
2147                          MultiExprArg Exprs,
2148                          Expr *AsmString,
2149                          MultiExprArg Clobbers,
2150                          SourceLocation RParenLoc,
2151                          bool MSAsm = false);
2152
2153
2154  VarDecl *BuildObjCExceptionDecl(TypeSourceInfo *TInfo, QualType ExceptionType,
2155                                  SourceLocation StartLoc,
2156                                  SourceLocation IdLoc, IdentifierInfo *Id,
2157                                  bool Invalid = false);
2158
2159  Decl *ActOnObjCExceptionDecl(Scope *S, Declarator &D);
2160
2161  StmtResult ActOnObjCAtCatchStmt(SourceLocation AtLoc, SourceLocation RParen,
2162                                  Decl *Parm, Stmt *Body);
2163
2164  StmtResult ActOnObjCAtFinallyStmt(SourceLocation AtLoc, Stmt *Body);
2165
2166  StmtResult ActOnObjCAtTryStmt(SourceLocation AtLoc, Stmt *Try,
2167                                MultiStmtArg Catch, Stmt *Finally);
2168
2169  StmtResult BuildObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw);
2170  StmtResult ActOnObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw,
2171                                  Scope *CurScope);
2172  ExprResult ActOnObjCAtSynchronizedOperand(SourceLocation atLoc,
2173                                            Expr *operand);
2174  StmtResult ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc,
2175                                         Expr *SynchExpr,
2176                                         Stmt *SynchBody);
2177
2178  StmtResult ActOnObjCAutoreleasePoolStmt(SourceLocation AtLoc, Stmt *Body);
2179
2180  VarDecl *BuildExceptionDeclaration(Scope *S, TypeSourceInfo *TInfo,
2181                                     SourceLocation StartLoc,
2182                                     SourceLocation IdLoc,
2183                                     IdentifierInfo *Id);
2184
2185  Decl *ActOnExceptionDeclarator(Scope *S, Declarator &D);
2186
2187  StmtResult ActOnCXXCatchBlock(SourceLocation CatchLoc,
2188                                Decl *ExDecl, Stmt *HandlerBlock);
2189  StmtResult ActOnCXXTryBlock(SourceLocation TryLoc, Stmt *TryBlock,
2190                              MultiStmtArg Handlers);
2191
2192  StmtResult ActOnSEHTryBlock(bool IsCXXTry, // try (true) or __try (false) ?
2193                              SourceLocation TryLoc,
2194                              Stmt *TryBlock,
2195                              Stmt *Handler);
2196
2197  StmtResult ActOnSEHExceptBlock(SourceLocation Loc,
2198                                 Expr *FilterExpr,
2199                                 Stmt *Block);
2200
2201  StmtResult ActOnSEHFinallyBlock(SourceLocation Loc,
2202                                  Stmt *Block);
2203
2204  void DiagnoseReturnInConstructorExceptionHandler(CXXTryStmt *TryBlock);
2205
2206  bool ShouldWarnIfUnusedFileScopedDecl(const DeclaratorDecl *D) const;
2207
2208  /// \brief If it's a file scoped decl that must warn if not used, keep track
2209  /// of it.
2210  void MarkUnusedFileScopedDecl(const DeclaratorDecl *D);
2211
2212  /// DiagnoseUnusedExprResult - If the statement passed in is an expression
2213  /// whose result is unused, warn.
2214  void DiagnoseUnusedExprResult(const Stmt *S);
2215  void DiagnoseUnusedDecl(const NamedDecl *ND);
2216
2217  ParsingDeclState PushParsingDeclaration() {
2218    return DelayedDiagnostics.pushParsingDecl();
2219  }
2220  void PopParsingDeclaration(ParsingDeclState state, Decl *decl) {
2221    DelayedDiagnostics::popParsingDecl(*this, state, decl);
2222  }
2223
2224  typedef ProcessingContextState ParsingClassState;
2225  ParsingClassState PushParsingClass() {
2226    return DelayedDiagnostics.pushContext();
2227  }
2228  void PopParsingClass(ParsingClassState state) {
2229    DelayedDiagnostics.popContext(state);
2230  }
2231
2232  void EmitDeprecationWarning(NamedDecl *D, StringRef Message,
2233                              SourceLocation Loc,
2234                              const ObjCInterfaceDecl *UnknownObjCClass=0);
2235
2236  void HandleDelayedDeprecationCheck(sema::DelayedDiagnostic &DD, Decl *Ctx);
2237
2238  bool makeUnavailableInSystemHeader(SourceLocation loc,
2239                                     StringRef message);
2240
2241  //===--------------------------------------------------------------------===//
2242  // Expression Parsing Callbacks: SemaExpr.cpp.
2243
2244  bool CanUseDecl(NamedDecl *D);
2245  bool DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc,
2246                         const ObjCInterfaceDecl *UnknownObjCClass=0);
2247  AvailabilityResult DiagnoseAvailabilityOfDecl(NamedDecl *D,
2248                              SourceLocation Loc,
2249                              const ObjCInterfaceDecl *UnknownObjCClass);
2250  std::string getDeletedOrUnavailableSuffix(const FunctionDecl *FD);
2251  bool DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *PD,
2252                                        ObjCMethodDecl *Getter,
2253                                        SourceLocation Loc);
2254  void DiagnoseSentinelCalls(NamedDecl *D, SourceLocation Loc,
2255                             Expr **Args, unsigned NumArgs);
2256
2257  void PushExpressionEvaluationContext(ExpressionEvaluationContext NewContext);
2258
2259  void PopExpressionEvaluationContext();
2260
2261  void DiscardCleanupsInEvaluationContext();
2262
2263  ExprResult TranformToPotentiallyEvaluated(Expr *E);
2264  ExprResult HandleExprEvaluationContextForTypeof(Expr *E);
2265
2266  void MarkDeclarationReferenced(SourceLocation Loc, Decl *D);
2267  void MarkDeclarationsReferencedInType(SourceLocation Loc, QualType T);
2268  void MarkDeclarationsReferencedInExpr(Expr *E);
2269
2270  /// \brief Try to recover by turning the given expression into a
2271  /// call.  Returns true if recovery was attempted or an error was
2272  /// emitted; this may also leave the ExprResult invalid.
2273  bool tryToRecoverWithCall(ExprResult &E, const PartialDiagnostic &PD,
2274                            bool ForceComplain = false,
2275                            bool (*IsPlausibleResult)(QualType) = 0);
2276
2277  /// \brief Figure out if an expression could be turned into a call.
2278  bool isExprCallable(const Expr &E, QualType &ZeroArgCallReturnTy,
2279                      UnresolvedSetImpl &NonTemplateOverloads);
2280
2281  /// \brief Conditionally issue a diagnostic based on the current
2282  /// evaluation context.
2283  ///
2284  /// \param stmt - If stmt is non-null, delay reporting the diagnostic until
2285  ///  the function body is parsed, and then do a basic reachability analysis to
2286  ///  determine if the statement is reachable.  If it is unreachable, the
2287  ///  diagnostic will not be emitted.
2288  bool DiagRuntimeBehavior(SourceLocation Loc, const Stmt *Statement,
2289                           const PartialDiagnostic &PD);
2290
2291  // Primary Expressions.
2292  SourceRange getExprRange(Expr *E) const;
2293
2294  ExprResult ActOnIdExpression(Scope *S, CXXScopeSpec &SS, UnqualifiedId &Id,
2295                               bool HasTrailingLParen, bool IsAddressOfOperand,
2296                               CorrectionCandidateCallback *CCC = 0);
2297
2298  void DecomposeUnqualifiedId(const UnqualifiedId &Id,
2299                              TemplateArgumentListInfo &Buffer,
2300                              DeclarationNameInfo &NameInfo,
2301                              const TemplateArgumentListInfo *&TemplateArgs);
2302
2303  bool DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R,
2304                           CorrectionCandidateCallback &CCC,
2305                           TemplateArgumentListInfo *ExplicitTemplateArgs = 0,
2306                           Expr **Args = 0, unsigned NumArgs = 0);
2307
2308  ExprResult LookupInObjCMethod(LookupResult &LookUp, Scope *S,
2309                                IdentifierInfo *II,
2310                                bool AllowBuiltinCreation=false);
2311
2312  ExprResult ActOnDependentIdExpression(const CXXScopeSpec &SS,
2313                                        const DeclarationNameInfo &NameInfo,
2314                                        bool isAddressOfOperand,
2315                                const TemplateArgumentListInfo *TemplateArgs);
2316
2317  ExprResult BuildDeclRefExpr(ValueDecl *D, QualType Ty,
2318                              ExprValueKind VK,
2319                              SourceLocation Loc,
2320                              const CXXScopeSpec *SS = 0);
2321  ExprResult BuildDeclRefExpr(ValueDecl *D, QualType Ty,
2322                              ExprValueKind VK,
2323                              const DeclarationNameInfo &NameInfo,
2324                              const CXXScopeSpec *SS = 0);
2325  ExprResult
2326  BuildAnonymousStructUnionMemberReference(const CXXScopeSpec &SS,
2327                                           SourceLocation nameLoc,
2328                                           IndirectFieldDecl *indirectField,
2329                                           Expr *baseObjectExpr = 0,
2330                                      SourceLocation opLoc = SourceLocation());
2331  ExprResult BuildPossibleImplicitMemberExpr(const CXXScopeSpec &SS,
2332                                             LookupResult &R,
2333                                const TemplateArgumentListInfo *TemplateArgs);
2334  ExprResult BuildImplicitMemberExpr(const CXXScopeSpec &SS,
2335                                     LookupResult &R,
2336                                const TemplateArgumentListInfo *TemplateArgs,
2337                                     bool IsDefiniteInstance);
2338  bool UseArgumentDependentLookup(const CXXScopeSpec &SS,
2339                                  const LookupResult &R,
2340                                  bool HasTrailingLParen);
2341
2342  ExprResult BuildQualifiedDeclarationNameExpr(CXXScopeSpec &SS,
2343                                         const DeclarationNameInfo &NameInfo);
2344  ExprResult BuildDependentDeclRefExpr(const CXXScopeSpec &SS,
2345                                const DeclarationNameInfo &NameInfo,
2346                                const TemplateArgumentListInfo *TemplateArgs);
2347
2348  ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS,
2349                                      LookupResult &R,
2350                                      bool NeedsADL);
2351  ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS,
2352                                      const DeclarationNameInfo &NameInfo,
2353                                      NamedDecl *D);
2354
2355  ExprResult ActOnPredefinedExpr(SourceLocation Loc, tok::TokenKind Kind);
2356  ExprResult ActOnNumericConstant(const Token &Tok);
2357  ExprResult ActOnCharacterConstant(const Token &Tok);
2358  ExprResult ActOnParenExpr(SourceLocation L, SourceLocation R, Expr *E);
2359  ExprResult ActOnParenOrParenListExpr(SourceLocation L,
2360                                       SourceLocation R,
2361                                       MultiExprArg Val);
2362
2363  /// ActOnStringLiteral - The specified tokens were lexed as pasted string
2364  /// fragments (e.g. "foo" "bar" L"baz").
2365  ExprResult ActOnStringLiteral(const Token *StringToks,
2366                                unsigned NumStringToks);
2367
2368  ExprResult ActOnGenericSelectionExpr(SourceLocation KeyLoc,
2369                                       SourceLocation DefaultLoc,
2370                                       SourceLocation RParenLoc,
2371                                       Expr *ControllingExpr,
2372                                       MultiTypeArg ArgTypes,
2373                                       MultiExprArg ArgExprs);
2374  ExprResult CreateGenericSelectionExpr(SourceLocation KeyLoc,
2375                                        SourceLocation DefaultLoc,
2376                                        SourceLocation RParenLoc,
2377                                        Expr *ControllingExpr,
2378                                        TypeSourceInfo **Types,
2379                                        Expr **Exprs,
2380                                        unsigned NumAssocs);
2381
2382  // Binary/Unary Operators.  'Tok' is the token for the operator.
2383  ExprResult CreateBuiltinUnaryOp(SourceLocation OpLoc, UnaryOperatorKind Opc,
2384                                  Expr *InputExpr);
2385  ExprResult BuildUnaryOp(Scope *S, SourceLocation OpLoc,
2386                          UnaryOperatorKind Opc, Expr *Input);
2387  ExprResult ActOnUnaryOp(Scope *S, SourceLocation OpLoc,
2388                          tok::TokenKind Op, Expr *Input);
2389
2390  ExprResult CreateUnaryExprOrTypeTraitExpr(TypeSourceInfo *TInfo,
2391                                            SourceLocation OpLoc,
2392                                            UnaryExprOrTypeTrait ExprKind,
2393                                            SourceRange R);
2394  ExprResult CreateUnaryExprOrTypeTraitExpr(Expr *E, SourceLocation OpLoc,
2395                                            UnaryExprOrTypeTrait ExprKind);
2396  ExprResult
2397    ActOnUnaryExprOrTypeTraitExpr(SourceLocation OpLoc,
2398                                  UnaryExprOrTypeTrait ExprKind,
2399                                  bool IsType, void *TyOrEx,
2400                                  const SourceRange &ArgRange);
2401
2402  ExprResult CheckPlaceholderExpr(Expr *E);
2403  bool CheckVecStepExpr(Expr *E);
2404
2405  bool CheckUnaryExprOrTypeTraitOperand(Expr *E, UnaryExprOrTypeTrait ExprKind);
2406  bool CheckUnaryExprOrTypeTraitOperand(QualType ExprType, SourceLocation OpLoc,
2407                                        SourceRange ExprRange,
2408                                        UnaryExprOrTypeTrait ExprKind);
2409  ExprResult ActOnSizeofParameterPackExpr(Scope *S,
2410                                          SourceLocation OpLoc,
2411                                          IdentifierInfo &Name,
2412                                          SourceLocation NameLoc,
2413                                          SourceLocation RParenLoc);
2414  ExprResult ActOnPostfixUnaryOp(Scope *S, SourceLocation OpLoc,
2415                                 tok::TokenKind Kind, Expr *Input);
2416
2417  ExprResult ActOnArraySubscriptExpr(Scope *S, Expr *Base, SourceLocation LLoc,
2418                                     Expr *Idx, SourceLocation RLoc);
2419  ExprResult CreateBuiltinArraySubscriptExpr(Expr *Base, SourceLocation LLoc,
2420                                             Expr *Idx, SourceLocation RLoc);
2421
2422  ExprResult BuildMemberReferenceExpr(Expr *Base, QualType BaseType,
2423                                      SourceLocation OpLoc, bool IsArrow,
2424                                      CXXScopeSpec &SS,
2425                                      NamedDecl *FirstQualifierInScope,
2426                                const DeclarationNameInfo &NameInfo,
2427                                const TemplateArgumentListInfo *TemplateArgs);
2428
2429  ExprResult BuildMemberReferenceExpr(Expr *Base, QualType BaseType,
2430                                      SourceLocation OpLoc, bool IsArrow,
2431                                      const CXXScopeSpec &SS,
2432                                      NamedDecl *FirstQualifierInScope,
2433                                      LookupResult &R,
2434                                 const TemplateArgumentListInfo *TemplateArgs,
2435                                      bool SuppressQualifierCheck = false);
2436
2437  ExprResult PerformMemberExprBaseConversion(Expr *Base, bool IsArrow);
2438  ExprResult LookupMemberExpr(LookupResult &R, ExprResult &Base,
2439                              bool &IsArrow, SourceLocation OpLoc,
2440                              CXXScopeSpec &SS,
2441                              Decl *ObjCImpDecl,
2442                              bool HasTemplateArgs);
2443
2444  bool CheckQualifiedMemberReference(Expr *BaseExpr, QualType BaseType,
2445                                     const CXXScopeSpec &SS,
2446                                     const LookupResult &R);
2447
2448  ExprResult ActOnDependentMemberExpr(Expr *Base, QualType BaseType,
2449                                      bool IsArrow, SourceLocation OpLoc,
2450                                      const CXXScopeSpec &SS,
2451                                      NamedDecl *FirstQualifierInScope,
2452                               const DeclarationNameInfo &NameInfo,
2453                               const TemplateArgumentListInfo *TemplateArgs);
2454
2455  ExprResult ActOnMemberAccessExpr(Scope *S, Expr *Base,
2456                                   SourceLocation OpLoc,
2457                                   tok::TokenKind OpKind,
2458                                   CXXScopeSpec &SS,
2459                                   UnqualifiedId &Member,
2460                                   Decl *ObjCImpDecl,
2461                                   bool HasTrailingLParen);
2462
2463  void ActOnDefaultCtorInitializers(Decl *CDtorDecl);
2464  bool ConvertArgumentsForCall(CallExpr *Call, Expr *Fn,
2465                               FunctionDecl *FDecl,
2466                               const FunctionProtoType *Proto,
2467                               Expr **Args, unsigned NumArgs,
2468                               SourceLocation RParenLoc,
2469                               bool ExecConfig = false);
2470  void CheckStaticArrayArgument(SourceLocation CallLoc,
2471                                ParmVarDecl *Param,
2472                                const Expr *ArgExpr);
2473
2474  /// ActOnCallExpr - Handle a call to Fn with the specified array of arguments.
2475  /// This provides the location of the left/right parens and a list of comma
2476  /// locations.
2477  ExprResult ActOnCallExpr(Scope *S, Expr *Fn, SourceLocation LParenLoc,
2478                           MultiExprArg ArgExprs, SourceLocation RParenLoc,
2479                           Expr *ExecConfig = 0, bool IsExecConfig = false);
2480  ExprResult BuildResolvedCallExpr(Expr *Fn, NamedDecl *NDecl,
2481                                   SourceLocation LParenLoc,
2482                                   Expr **Args, unsigned NumArgs,
2483                                   SourceLocation RParenLoc,
2484                                   Expr *Config = 0,
2485                                   bool IsExecConfig = false);
2486
2487  ExprResult ActOnCUDAExecConfigExpr(Scope *S, SourceLocation LLLLoc,
2488                                     MultiExprArg ExecConfig,
2489                                     SourceLocation GGGLoc);
2490
2491  ExprResult ActOnCastExpr(Scope *S, SourceLocation LParenLoc,
2492                           Declarator &D, ParsedType &Ty,
2493                           SourceLocation RParenLoc, Expr *CastExpr);
2494  ExprResult BuildCStyleCastExpr(SourceLocation LParenLoc,
2495                                 TypeSourceInfo *Ty,
2496                                 SourceLocation RParenLoc,
2497                                 Expr *Op);
2498  CastKind PrepareScalarCast(ExprResult &src, QualType destType);
2499
2500  /// \brief Build an altivec or OpenCL literal.
2501  ExprResult BuildVectorLiteral(SourceLocation LParenLoc,
2502                                SourceLocation RParenLoc, Expr *E,
2503                                TypeSourceInfo *TInfo);
2504
2505  ExprResult MaybeConvertParenListExprToParenExpr(Scope *S, Expr *ME);
2506
2507  ExprResult ActOnCompoundLiteral(SourceLocation LParenLoc,
2508                                  ParsedType Ty,
2509                                  SourceLocation RParenLoc,
2510                                  Expr *InitExpr);
2511
2512  ExprResult BuildCompoundLiteralExpr(SourceLocation LParenLoc,
2513                                      TypeSourceInfo *TInfo,
2514                                      SourceLocation RParenLoc,
2515                                      Expr *LiteralExpr);
2516
2517  ExprResult ActOnInitList(SourceLocation LBraceLoc,
2518                           MultiExprArg InitArgList,
2519                           SourceLocation RBraceLoc);
2520
2521  ExprResult ActOnDesignatedInitializer(Designation &Desig,
2522                                        SourceLocation Loc,
2523                                        bool GNUSyntax,
2524                                        ExprResult Init);
2525
2526  ExprResult ActOnBinOp(Scope *S, SourceLocation TokLoc,
2527                        tok::TokenKind Kind, Expr *LHSExpr, Expr *RHSExpr);
2528  ExprResult BuildBinOp(Scope *S, SourceLocation OpLoc,
2529                        BinaryOperatorKind Opc, Expr *LHSExpr, Expr *RHSExpr);
2530  ExprResult CreateBuiltinBinOp(SourceLocation OpLoc, BinaryOperatorKind Opc,
2531                                Expr *LHSExpr, Expr *RHSExpr);
2532
2533  /// ActOnConditionalOp - Parse a ?: operation.  Note that 'LHS' may be null
2534  /// in the case of a the GNU conditional expr extension.
2535  ExprResult ActOnConditionalOp(SourceLocation QuestionLoc,
2536                                SourceLocation ColonLoc,
2537                                Expr *CondExpr, Expr *LHSExpr, Expr *RHSExpr);
2538
2539  /// ActOnAddrLabel - Parse the GNU address of label extension: "&&foo".
2540  ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc,
2541                            LabelDecl *TheDecl);
2542
2543  ExprResult ActOnStmtExpr(SourceLocation LPLoc, Stmt *SubStmt,
2544                           SourceLocation RPLoc); // "({..})"
2545
2546  // __builtin_offsetof(type, identifier(.identifier|[expr])*)
2547  struct OffsetOfComponent {
2548    SourceLocation LocStart, LocEnd;
2549    bool isBrackets;  // true if [expr], false if .ident
2550    union {
2551      IdentifierInfo *IdentInfo;
2552      Expr *E;
2553    } U;
2554  };
2555
2556  /// __builtin_offsetof(type, a.b[123][456].c)
2557  ExprResult BuildBuiltinOffsetOf(SourceLocation BuiltinLoc,
2558                                  TypeSourceInfo *TInfo,
2559                                  OffsetOfComponent *CompPtr,
2560                                  unsigned NumComponents,
2561                                  SourceLocation RParenLoc);
2562  ExprResult ActOnBuiltinOffsetOf(Scope *S,
2563                                  SourceLocation BuiltinLoc,
2564                                  SourceLocation TypeLoc,
2565                                  ParsedType ParsedArgTy,
2566                                  OffsetOfComponent *CompPtr,
2567                                  unsigned NumComponents,
2568                                  SourceLocation RParenLoc);
2569
2570  // __builtin_choose_expr(constExpr, expr1, expr2)
2571  ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc,
2572                             Expr *CondExpr, Expr *LHSExpr,
2573                             Expr *RHSExpr, SourceLocation RPLoc);
2574
2575  // __builtin_va_arg(expr, type)
2576  ExprResult ActOnVAArg(SourceLocation BuiltinLoc, Expr *E, ParsedType Ty,
2577                        SourceLocation RPLoc);
2578  ExprResult BuildVAArgExpr(SourceLocation BuiltinLoc, Expr *E,
2579                            TypeSourceInfo *TInfo, SourceLocation RPLoc);
2580
2581  // __null
2582  ExprResult ActOnGNUNullExpr(SourceLocation TokenLoc);
2583
2584  bool CheckCaseExpression(Expr *E);
2585
2586  /// \brief Describes the result of an "if-exists" condition check.
2587  enum IfExistsResult {
2588    /// \brief The symbol exists.
2589    IER_Exists,
2590
2591    /// \brief The symbol does not exist.
2592    IER_DoesNotExist,
2593
2594    /// \brief The name is a dependent name, so the results will differ
2595    /// from one instantiation to the next.
2596    IER_Dependent,
2597
2598    /// \brief An error occurred.
2599    IER_Error
2600  };
2601
2602  IfExistsResult
2603  CheckMicrosoftIfExistsSymbol(Scope *S, CXXScopeSpec &SS,
2604                               const DeclarationNameInfo &TargetNameInfo);
2605
2606  IfExistsResult
2607  CheckMicrosoftIfExistsSymbol(Scope *S, SourceLocation KeywordLoc,
2608                               bool IsIfExists, CXXScopeSpec &SS,
2609                               UnqualifiedId &Name);
2610
2611  StmtResult BuildMSDependentExistsStmt(SourceLocation KeywordLoc,
2612                                        bool IsIfExists,
2613                                        NestedNameSpecifierLoc QualifierLoc,
2614                                        DeclarationNameInfo NameInfo,
2615                                        Stmt *Nested);
2616  StmtResult ActOnMSDependentExistsStmt(SourceLocation KeywordLoc,
2617                                        bool IsIfExists,
2618                                        CXXScopeSpec &SS, UnqualifiedId &Name,
2619                                        Stmt *Nested);
2620
2621  //===------------------------- "Block" Extension ------------------------===//
2622
2623  /// ActOnBlockStart - This callback is invoked when a block literal is
2624  /// started.
2625  void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope);
2626
2627  /// ActOnBlockArguments - This callback allows processing of block arguments.
2628  /// If there are no arguments, this is still invoked.
2629  void ActOnBlockArguments(Declarator &ParamInfo, Scope *CurScope);
2630
2631  /// ActOnBlockError - If there is an error parsing a block, this callback
2632  /// is invoked to pop the information about the block from the action impl.
2633  void ActOnBlockError(SourceLocation CaretLoc, Scope *CurScope);
2634
2635  /// ActOnBlockStmtExpr - This is called when the body of a block statement
2636  /// literal was successfully completed.  ^(int x){...}
2637  ExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc, Stmt *Body,
2638                                Scope *CurScope);
2639
2640  //===---------------------------- OpenCL Features -----------------------===//
2641
2642  /// __builtin_astype(...)
2643  ExprResult ActOnAsTypeExpr(Expr *E, ParsedType ParsedDestTy,
2644                             SourceLocation BuiltinLoc,
2645                             SourceLocation RParenLoc);
2646
2647  //===---------------------------- C++ Features --------------------------===//
2648
2649  // Act on C++ namespaces
2650  Decl *ActOnStartNamespaceDef(Scope *S, SourceLocation InlineLoc,
2651                               SourceLocation NamespaceLoc,
2652                               SourceLocation IdentLoc,
2653                               IdentifierInfo *Ident,
2654                               SourceLocation LBrace,
2655                               AttributeList *AttrList);
2656  void ActOnFinishNamespaceDef(Decl *Dcl, SourceLocation RBrace);
2657
2658  NamespaceDecl *getStdNamespace() const;
2659  NamespaceDecl *getOrCreateStdNamespace();
2660
2661  CXXRecordDecl *getStdBadAlloc() const;
2662
2663  /// \brief Tests whether Ty is an instance of std::initializer_list and, if
2664  /// it is and Element is not NULL, assigns the element type to Element.
2665  bool isStdInitializerList(QualType Ty, QualType *Element);
2666
2667  /// \brief Looks for the std::initializer_list template and instantiates it
2668  /// with Element, or emits an error if it's not found.
2669  ///
2670  /// \returns The instantiated template, or null on error.
2671  QualType BuildStdInitializerList(QualType Element, SourceLocation Loc);
2672
2673  /// \brief Determine whether Ctor is an initializer-list constructor, as
2674  /// defined in [dcl.init.list]p2.
2675  bool isInitListConstructor(const CXXConstructorDecl *Ctor);
2676
2677  Decl *ActOnUsingDirective(Scope *CurScope,
2678                            SourceLocation UsingLoc,
2679                            SourceLocation NamespcLoc,
2680                            CXXScopeSpec &SS,
2681                            SourceLocation IdentLoc,
2682                            IdentifierInfo *NamespcName,
2683                            AttributeList *AttrList);
2684
2685  void PushUsingDirective(Scope *S, UsingDirectiveDecl *UDir);
2686
2687  Decl *ActOnNamespaceAliasDef(Scope *CurScope,
2688                               SourceLocation NamespaceLoc,
2689                               SourceLocation AliasLoc,
2690                               IdentifierInfo *Alias,
2691                               CXXScopeSpec &SS,
2692                               SourceLocation IdentLoc,
2693                               IdentifierInfo *Ident);
2694
2695  void HideUsingShadowDecl(Scope *S, UsingShadowDecl *Shadow);
2696  bool CheckUsingShadowDecl(UsingDecl *UD, NamedDecl *Target,
2697                            const LookupResult &PreviousDecls);
2698  UsingShadowDecl *BuildUsingShadowDecl(Scope *S, UsingDecl *UD,
2699                                        NamedDecl *Target);
2700
2701  bool CheckUsingDeclRedeclaration(SourceLocation UsingLoc,
2702                                   bool isTypeName,
2703                                   const CXXScopeSpec &SS,
2704                                   SourceLocation NameLoc,
2705                                   const LookupResult &Previous);
2706  bool CheckUsingDeclQualifier(SourceLocation UsingLoc,
2707                               const CXXScopeSpec &SS,
2708                               SourceLocation NameLoc);
2709
2710  NamedDecl *BuildUsingDeclaration(Scope *S, AccessSpecifier AS,
2711                                   SourceLocation UsingLoc,
2712                                   CXXScopeSpec &SS,
2713                                   const DeclarationNameInfo &NameInfo,
2714                                   AttributeList *AttrList,
2715                                   bool IsInstantiation,
2716                                   bool IsTypeName,
2717                                   SourceLocation TypenameLoc);
2718
2719  bool CheckInheritedConstructorUsingDecl(UsingDecl *UD);
2720
2721  Decl *ActOnUsingDeclaration(Scope *CurScope,
2722                              AccessSpecifier AS,
2723                              bool HasUsingKeyword,
2724                              SourceLocation UsingLoc,
2725                              CXXScopeSpec &SS,
2726                              UnqualifiedId &Name,
2727                              AttributeList *AttrList,
2728                              bool IsTypeName,
2729                              SourceLocation TypenameLoc);
2730  Decl *ActOnAliasDeclaration(Scope *CurScope,
2731                              AccessSpecifier AS,
2732                              MultiTemplateParamsArg TemplateParams,
2733                              SourceLocation UsingLoc,
2734                              UnqualifiedId &Name,
2735                              TypeResult Type);
2736
2737  /// AddCXXDirectInitializerToDecl - This action is called immediately after
2738  /// ActOnDeclarator, when a C++ direct initializer is present.
2739  /// e.g: "int x(1);"
2740  void AddCXXDirectInitializerToDecl(Decl *Dcl,
2741                                     SourceLocation LParenLoc,
2742                                     MultiExprArg Exprs,
2743                                     SourceLocation RParenLoc,
2744                                     bool TypeMayContainAuto);
2745
2746  /// InitializeVarWithConstructor - Creates an CXXConstructExpr
2747  /// and sets it as the initializer for the the passed in VarDecl.
2748  bool InitializeVarWithConstructor(VarDecl *VD,
2749                                    CXXConstructorDecl *Constructor,
2750                                    MultiExprArg Exprs,
2751                                    bool HadMultipleCandidates);
2752
2753  /// BuildCXXConstructExpr - Creates a complete call to a constructor,
2754  /// including handling of its default argument expressions.
2755  ///
2756  /// \param ConstructKind - a CXXConstructExpr::ConstructionKind
2757  ExprResult
2758  BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType,
2759                        CXXConstructorDecl *Constructor, MultiExprArg Exprs,
2760                        bool HadMultipleCandidates, bool RequiresZeroInit,
2761                        unsigned ConstructKind, SourceRange ParenRange);
2762
2763  // FIXME: Can re remove this and have the above BuildCXXConstructExpr check if
2764  // the constructor can be elidable?
2765  ExprResult
2766  BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType,
2767                        CXXConstructorDecl *Constructor, bool Elidable,
2768                        MultiExprArg Exprs, bool HadMultipleCandidates,
2769                        bool RequiresZeroInit, unsigned ConstructKind,
2770                        SourceRange ParenRange);
2771
2772  /// BuildCXXDefaultArgExpr - Creates a CXXDefaultArgExpr, instantiating
2773  /// the default expr if needed.
2774  ExprResult BuildCXXDefaultArgExpr(SourceLocation CallLoc,
2775                                    FunctionDecl *FD,
2776                                    ParmVarDecl *Param);
2777
2778  /// FinalizeVarWithDestructor - Prepare for calling destructor on the
2779  /// constructed variable.
2780  void FinalizeVarWithDestructor(VarDecl *VD, const RecordType *DeclInitType);
2781
2782  /// \brief Helper class that collects exception specifications for
2783  /// implicitly-declared special member functions.
2784  class ImplicitExceptionSpecification {
2785    // Pointer to allow copying
2786    ASTContext *Context;
2787    // We order exception specifications thus:
2788    // noexcept is the most restrictive, but is only used in C++0x.
2789    // throw() comes next.
2790    // Then a throw(collected exceptions)
2791    // Finally no specification.
2792    // throw(...) is used instead if any called function uses it.
2793    //
2794    // If this exception specification cannot be known yet (for instance,
2795    // because this is the exception specification for a defaulted default
2796    // constructor and we haven't finished parsing the deferred parts of the
2797    // class yet), the C++0x standard does not specify how to behave. We
2798    // record this as an 'unknown' exception specification, which overrules
2799    // any other specification (even 'none', to keep this rule simple).
2800    ExceptionSpecificationType ComputedEST;
2801    llvm::SmallPtrSet<CanQualType, 4> ExceptionsSeen;
2802    SmallVector<QualType, 4> Exceptions;
2803
2804    void ClearExceptions() {
2805      ExceptionsSeen.clear();
2806      Exceptions.clear();
2807    }
2808
2809  public:
2810    explicit ImplicitExceptionSpecification(ASTContext &Context)
2811      : Context(&Context), ComputedEST(EST_BasicNoexcept) {
2812      if (!Context.getLangOptions().CPlusPlus0x)
2813        ComputedEST = EST_DynamicNone;
2814    }
2815
2816    /// \brief Get the computed exception specification type.
2817    ExceptionSpecificationType getExceptionSpecType() const {
2818      assert(ComputedEST != EST_ComputedNoexcept &&
2819             "noexcept(expr) should not be a possible result");
2820      return ComputedEST;
2821    }
2822
2823    /// \brief The number of exceptions in the exception specification.
2824    unsigned size() const { return Exceptions.size(); }
2825
2826    /// \brief The set of exceptions in the exception specification.
2827    const QualType *data() const { return Exceptions.data(); }
2828
2829    /// \brief Integrate another called method into the collected data.
2830    void CalledDecl(CXXMethodDecl *Method);
2831
2832    /// \brief Integrate an invoked expression into the collected data.
2833    void CalledExpr(Expr *E);
2834
2835    /// \brief Specify that the exception specification can't be detemined yet.
2836    void SetDelayed() {
2837      ClearExceptions();
2838      ComputedEST = EST_Delayed;
2839    }
2840
2841    FunctionProtoType::ExtProtoInfo getEPI() const {
2842      FunctionProtoType::ExtProtoInfo EPI;
2843      EPI.ExceptionSpecType = getExceptionSpecType();
2844      EPI.NumExceptions = size();
2845      EPI.Exceptions = data();
2846      return EPI;
2847    }
2848  };
2849
2850  /// \brief Determine what sort of exception specification a defaulted
2851  /// copy constructor of a class will have.
2852  ImplicitExceptionSpecification
2853  ComputeDefaultedDefaultCtorExceptionSpec(CXXRecordDecl *ClassDecl);
2854
2855  /// \brief Determine what sort of exception specification a defaulted
2856  /// default constructor of a class will have, and whether the parameter
2857  /// will be const.
2858  std::pair<ImplicitExceptionSpecification, bool>
2859  ComputeDefaultedCopyCtorExceptionSpecAndConst(CXXRecordDecl *ClassDecl);
2860
2861  /// \brief Determine what sort of exception specification a defautled
2862  /// copy assignment operator of a class will have, and whether the
2863  /// parameter will be const.
2864  std::pair<ImplicitExceptionSpecification, bool>
2865  ComputeDefaultedCopyAssignmentExceptionSpecAndConst(CXXRecordDecl *ClassDecl);
2866
2867  /// \brief Determine what sort of exception specification a defaulted move
2868  /// constructor of a class will have.
2869  ImplicitExceptionSpecification
2870  ComputeDefaultedMoveCtorExceptionSpec(CXXRecordDecl *ClassDecl);
2871
2872  /// \brief Determine what sort of exception specification a defaulted move
2873  /// assignment operator of a class will have.
2874  ImplicitExceptionSpecification
2875  ComputeDefaultedMoveAssignmentExceptionSpec(CXXRecordDecl *ClassDecl);
2876
2877  /// \brief Determine what sort of exception specification a defaulted
2878  /// destructor of a class will have.
2879  ImplicitExceptionSpecification
2880  ComputeDefaultedDtorExceptionSpec(CXXRecordDecl *ClassDecl);
2881
2882  /// \brief Determine if a special member function should have a deleted
2883  /// definition when it is defaulted.
2884  bool ShouldDeleteSpecialMember(CXXMethodDecl *MD, CXXSpecialMember CSM);
2885
2886  /// \brief Determine if a defaulted copy assignment operator ought to be
2887  /// deleted.
2888  bool ShouldDeleteCopyAssignmentOperator(CXXMethodDecl *MD);
2889
2890  /// \brief Determine if a defaulted move assignment operator ought to be
2891  /// deleted.
2892  bool ShouldDeleteMoveAssignmentOperator(CXXMethodDecl *MD);
2893
2894  /// \brief Determine if a defaulted destructor ought to be deleted.
2895  bool ShouldDeleteDestructor(CXXDestructorDecl *DD);
2896
2897  /// \brief Declare the implicit default constructor for the given class.
2898  ///
2899  /// \param ClassDecl The class declaration into which the implicit
2900  /// default constructor will be added.
2901  ///
2902  /// \returns The implicitly-declared default constructor.
2903  CXXConstructorDecl *DeclareImplicitDefaultConstructor(
2904                                                     CXXRecordDecl *ClassDecl);
2905
2906  /// DefineImplicitDefaultConstructor - Checks for feasibility of
2907  /// defining this constructor as the default constructor.
2908  void DefineImplicitDefaultConstructor(SourceLocation CurrentLocation,
2909                                        CXXConstructorDecl *Constructor);
2910
2911  /// \brief Declare the implicit destructor for the given class.
2912  ///
2913  /// \param ClassDecl The class declaration into which the implicit
2914  /// destructor will be added.
2915  ///
2916  /// \returns The implicitly-declared destructor.
2917  CXXDestructorDecl *DeclareImplicitDestructor(CXXRecordDecl *ClassDecl);
2918
2919  /// DefineImplicitDestructor - Checks for feasibility of
2920  /// defining this destructor as the default destructor.
2921  void DefineImplicitDestructor(SourceLocation CurrentLocation,
2922                                CXXDestructorDecl *Destructor);
2923
2924  /// \brief Build an exception spec for destructors that don't have one.
2925  ///
2926  /// C++11 says that user-defined destructors with no exception spec get one
2927  /// that looks as if the destructor was implicitly declared.
2928  void AdjustDestructorExceptionSpec(CXXRecordDecl *ClassDecl,
2929                                     CXXDestructorDecl *Destructor);
2930
2931  /// \brief Declare all inherited constructors for the given class.
2932  ///
2933  /// \param ClassDecl The class declaration into which the inherited
2934  /// constructors will be added.
2935  void DeclareInheritedConstructors(CXXRecordDecl *ClassDecl);
2936
2937  /// \brief Declare the implicit copy constructor for the given class.
2938  ///
2939  /// \param ClassDecl The class declaration into which the implicit
2940  /// copy constructor will be added.
2941  ///
2942  /// \returns The implicitly-declared copy constructor.
2943  CXXConstructorDecl *DeclareImplicitCopyConstructor(CXXRecordDecl *ClassDecl);
2944
2945  /// DefineImplicitCopyConstructor - Checks for feasibility of
2946  /// defining this constructor as the copy constructor.
2947  void DefineImplicitCopyConstructor(SourceLocation CurrentLocation,
2948                                     CXXConstructorDecl *Constructor);
2949
2950  /// \brief Declare the implicit move constructor for the given class.
2951  ///
2952  /// \param ClassDecl The Class declaration into which the implicit
2953  /// move constructor will be added.
2954  ///
2955  /// \returns The implicitly-declared move constructor, or NULL if it wasn't
2956  /// declared.
2957  CXXConstructorDecl *DeclareImplicitMoveConstructor(CXXRecordDecl *ClassDecl);
2958
2959  /// DefineImplicitMoveConstructor - Checks for feasibility of
2960  /// defining this constructor as the move constructor.
2961  void DefineImplicitMoveConstructor(SourceLocation CurrentLocation,
2962                                     CXXConstructorDecl *Constructor);
2963
2964  /// \brief Declare the implicit copy assignment operator for the given class.
2965  ///
2966  /// \param ClassDecl The class declaration into which the implicit
2967  /// copy assignment operator will be added.
2968  ///
2969  /// \returns The implicitly-declared copy assignment operator.
2970  CXXMethodDecl *DeclareImplicitCopyAssignment(CXXRecordDecl *ClassDecl);
2971
2972  /// \brief Defines an implicitly-declared copy assignment operator.
2973  void DefineImplicitCopyAssignment(SourceLocation CurrentLocation,
2974                                    CXXMethodDecl *MethodDecl);
2975
2976  /// \brief Declare the implicit move assignment operator for the given class.
2977  ///
2978  /// \param ClassDecl The Class declaration into which the implicit
2979  /// move assignment operator will be added.
2980  ///
2981  /// \returns The implicitly-declared move assignment operator, or NULL if it
2982  /// wasn't declared.
2983  CXXMethodDecl *DeclareImplicitMoveAssignment(CXXRecordDecl *ClassDecl);
2984
2985  /// \brief Defines an implicitly-declared move assignment operator.
2986  void DefineImplicitMoveAssignment(SourceLocation CurrentLocation,
2987                                    CXXMethodDecl *MethodDecl);
2988
2989  /// \brief Force the declaration of any implicitly-declared members of this
2990  /// class.
2991  void ForceDeclarationOfImplicitMembers(CXXRecordDecl *Class);
2992
2993  /// MaybeBindToTemporary - If the passed in expression has a record type with
2994  /// a non-trivial destructor, this will return CXXBindTemporaryExpr. Otherwise
2995  /// it simply returns the passed in expression.
2996  ExprResult MaybeBindToTemporary(Expr *E);
2997
2998  bool CompleteConstructorCall(CXXConstructorDecl *Constructor,
2999                               MultiExprArg ArgsPtr,
3000                               SourceLocation Loc,
3001                               ASTOwningVector<Expr*> &ConvertedArgs);
3002
3003  ParsedType getDestructorName(SourceLocation TildeLoc,
3004                               IdentifierInfo &II, SourceLocation NameLoc,
3005                               Scope *S, CXXScopeSpec &SS,
3006                               ParsedType ObjectType,
3007                               bool EnteringContext);
3008
3009  ParsedType getDestructorType(const DeclSpec& DS, ParsedType ObjectType);
3010
3011  // Checks that reinterpret casts don't have undefined behavior.
3012  void CheckCompatibleReinterpretCast(QualType SrcType, QualType DestType,
3013                                      bool IsDereference, SourceRange Range);
3014
3015  /// ActOnCXXNamedCast - Parse {dynamic,static,reinterpret,const}_cast's.
3016  ExprResult ActOnCXXNamedCast(SourceLocation OpLoc,
3017                               tok::TokenKind Kind,
3018                               SourceLocation LAngleBracketLoc,
3019                               Declarator &D,
3020                               SourceLocation RAngleBracketLoc,
3021                               SourceLocation LParenLoc,
3022                               Expr *E,
3023                               SourceLocation RParenLoc);
3024
3025  ExprResult BuildCXXNamedCast(SourceLocation OpLoc,
3026                               tok::TokenKind Kind,
3027                               TypeSourceInfo *Ty,
3028                               Expr *E,
3029                               SourceRange AngleBrackets,
3030                               SourceRange Parens);
3031
3032  ExprResult BuildCXXTypeId(QualType TypeInfoType,
3033                            SourceLocation TypeidLoc,
3034                            TypeSourceInfo *Operand,
3035                            SourceLocation RParenLoc);
3036  ExprResult BuildCXXTypeId(QualType TypeInfoType,
3037                            SourceLocation TypeidLoc,
3038                            Expr *Operand,
3039                            SourceLocation RParenLoc);
3040
3041  /// ActOnCXXTypeid - Parse typeid( something ).
3042  ExprResult ActOnCXXTypeid(SourceLocation OpLoc,
3043                            SourceLocation LParenLoc, bool isType,
3044                            void *TyOrExpr,
3045                            SourceLocation RParenLoc);
3046
3047  ExprResult BuildCXXUuidof(QualType TypeInfoType,
3048                            SourceLocation TypeidLoc,
3049                            TypeSourceInfo *Operand,
3050                            SourceLocation RParenLoc);
3051  ExprResult BuildCXXUuidof(QualType TypeInfoType,
3052                            SourceLocation TypeidLoc,
3053                            Expr *Operand,
3054                            SourceLocation RParenLoc);
3055
3056  /// ActOnCXXUuidof - Parse __uuidof( something ).
3057  ExprResult ActOnCXXUuidof(SourceLocation OpLoc,
3058                            SourceLocation LParenLoc, bool isType,
3059                            void *TyOrExpr,
3060                            SourceLocation RParenLoc);
3061
3062
3063  //// ActOnCXXThis -  Parse 'this' pointer.
3064  ExprResult ActOnCXXThis(SourceLocation loc);
3065
3066  /// \brief Try to retrieve the type of the 'this' pointer.
3067  ///
3068  /// \param Capture If true, capture 'this' in this context.
3069  ///
3070  /// \returns The type of 'this', if possible. Otherwise, returns a NULL type.
3071  QualType getCurrentThisType();
3072
3073  /// \brief Make sure the value of 'this' is actually available in the current
3074  /// context, if it is a potentially evaluated context.
3075  void CheckCXXThisCapture(SourceLocation Loc);
3076
3077  /// ActOnCXXBoolLiteral - Parse {true,false} literals.
3078  ExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind);
3079
3080  /// ActOnCXXNullPtrLiteral - Parse 'nullptr'.
3081  ExprResult ActOnCXXNullPtrLiteral(SourceLocation Loc);
3082
3083  //// ActOnCXXThrow -  Parse throw expressions.
3084  ExprResult ActOnCXXThrow(Scope *S, SourceLocation OpLoc, Expr *expr);
3085  ExprResult BuildCXXThrow(SourceLocation OpLoc, Expr *Ex,
3086                           bool IsThrownVarInScope);
3087  ExprResult CheckCXXThrowOperand(SourceLocation ThrowLoc, Expr *E,
3088                                  bool IsThrownVarInScope);
3089
3090  /// ActOnCXXTypeConstructExpr - Parse construction of a specified type.
3091  /// Can be interpreted either as function-style casting ("int(x)")
3092  /// or class type construction ("ClassType(x,y,z)")
3093  /// or creation of a value-initialized type ("int()").
3094  ExprResult ActOnCXXTypeConstructExpr(ParsedType TypeRep,
3095                                       SourceLocation LParenLoc,
3096                                       MultiExprArg Exprs,
3097                                       SourceLocation RParenLoc);
3098
3099  ExprResult BuildCXXTypeConstructExpr(TypeSourceInfo *Type,
3100                                       SourceLocation LParenLoc,
3101                                       MultiExprArg Exprs,
3102                                       SourceLocation RParenLoc);
3103
3104  /// ActOnCXXNew - Parsed a C++ 'new' expression.
3105  ExprResult ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal,
3106                         SourceLocation PlacementLParen,
3107                         MultiExprArg PlacementArgs,
3108                         SourceLocation PlacementRParen,
3109                         SourceRange TypeIdParens, Declarator &D,
3110                         SourceLocation ConstructorLParen,
3111                         MultiExprArg ConstructorArgs,
3112                         SourceLocation ConstructorRParen);
3113  ExprResult BuildCXXNew(SourceLocation StartLoc, bool UseGlobal,
3114                         SourceLocation PlacementLParen,
3115                         MultiExprArg PlacementArgs,
3116                         SourceLocation PlacementRParen,
3117                         SourceRange TypeIdParens,
3118                         QualType AllocType,
3119                         TypeSourceInfo *AllocTypeInfo,
3120                         Expr *ArraySize,
3121                         SourceLocation ConstructorLParen,
3122                         MultiExprArg ConstructorArgs,
3123                         SourceLocation ConstructorRParen,
3124                         bool TypeMayContainAuto = true);
3125
3126  bool CheckAllocatedType(QualType AllocType, SourceLocation Loc,
3127                          SourceRange R);
3128  bool FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range,
3129                               bool UseGlobal, QualType AllocType, bool IsArray,
3130                               Expr **PlaceArgs, unsigned NumPlaceArgs,
3131                               FunctionDecl *&OperatorNew,
3132                               FunctionDecl *&OperatorDelete);
3133  bool FindAllocationOverload(SourceLocation StartLoc, SourceRange Range,
3134                              DeclarationName Name, Expr** Args,
3135                              unsigned NumArgs, DeclContext *Ctx,
3136                              bool AllowMissing, FunctionDecl *&Operator,
3137                              bool Diagnose = true);
3138  void DeclareGlobalNewDelete();
3139  void DeclareGlobalAllocationFunction(DeclarationName Name, QualType Return,
3140                                       QualType Argument,
3141                                       bool addMallocAttr = false);
3142
3143  bool FindDeallocationFunction(SourceLocation StartLoc, CXXRecordDecl *RD,
3144                                DeclarationName Name, FunctionDecl* &Operator,
3145                                bool Diagnose = true);
3146
3147  /// ActOnCXXDelete - Parsed a C++ 'delete' expression
3148  ExprResult ActOnCXXDelete(SourceLocation StartLoc,
3149                            bool UseGlobal, bool ArrayForm,
3150                            Expr *Operand);
3151
3152  DeclResult ActOnCXXConditionDeclaration(Scope *S, Declarator &D);
3153  ExprResult CheckConditionVariable(VarDecl *ConditionVar,
3154                                    SourceLocation StmtLoc,
3155                                    bool ConvertToBoolean);
3156
3157  ExprResult ActOnNoexceptExpr(SourceLocation KeyLoc, SourceLocation LParen,
3158                               Expr *Operand, SourceLocation RParen);
3159  ExprResult BuildCXXNoexceptExpr(SourceLocation KeyLoc, Expr *Operand,
3160                                  SourceLocation RParen);
3161
3162  /// ActOnUnaryTypeTrait - Parsed one of the unary type trait support
3163  /// pseudo-functions.
3164  ExprResult ActOnUnaryTypeTrait(UnaryTypeTrait OTT,
3165                                 SourceLocation KWLoc,
3166                                 ParsedType Ty,
3167                                 SourceLocation RParen);
3168
3169  ExprResult BuildUnaryTypeTrait(UnaryTypeTrait OTT,
3170                                 SourceLocation KWLoc,
3171                                 TypeSourceInfo *T,
3172                                 SourceLocation RParen);
3173
3174  /// ActOnBinaryTypeTrait - Parsed one of the bianry type trait support
3175  /// pseudo-functions.
3176  ExprResult ActOnBinaryTypeTrait(BinaryTypeTrait OTT,
3177                                  SourceLocation KWLoc,
3178                                  ParsedType LhsTy,
3179                                  ParsedType RhsTy,
3180                                  SourceLocation RParen);
3181
3182  ExprResult BuildBinaryTypeTrait(BinaryTypeTrait BTT,
3183                                  SourceLocation KWLoc,
3184                                  TypeSourceInfo *LhsT,
3185                                  TypeSourceInfo *RhsT,
3186                                  SourceLocation RParen);
3187
3188  /// ActOnArrayTypeTrait - Parsed one of the bianry type trait support
3189  /// pseudo-functions.
3190  ExprResult ActOnArrayTypeTrait(ArrayTypeTrait ATT,
3191                                 SourceLocation KWLoc,
3192                                 ParsedType LhsTy,
3193                                 Expr *DimExpr,
3194                                 SourceLocation RParen);
3195
3196  ExprResult BuildArrayTypeTrait(ArrayTypeTrait ATT,
3197                                 SourceLocation KWLoc,
3198                                 TypeSourceInfo *TSInfo,
3199                                 Expr *DimExpr,
3200                                 SourceLocation RParen);
3201
3202  /// ActOnExpressionTrait - Parsed one of the unary type trait support
3203  /// pseudo-functions.
3204  ExprResult ActOnExpressionTrait(ExpressionTrait OET,
3205                                  SourceLocation KWLoc,
3206                                  Expr *Queried,
3207                                  SourceLocation RParen);
3208
3209  ExprResult BuildExpressionTrait(ExpressionTrait OET,
3210                                  SourceLocation KWLoc,
3211                                  Expr *Queried,
3212                                  SourceLocation RParen);
3213
3214  ExprResult ActOnStartCXXMemberReference(Scope *S,
3215                                          Expr *Base,
3216                                          SourceLocation OpLoc,
3217                                          tok::TokenKind OpKind,
3218                                          ParsedType &ObjectType,
3219                                          bool &MayBePseudoDestructor);
3220
3221  ExprResult DiagnoseDtorReference(SourceLocation NameLoc, Expr *MemExpr);
3222
3223  ExprResult BuildPseudoDestructorExpr(Expr *Base,
3224                                       SourceLocation OpLoc,
3225                                       tok::TokenKind OpKind,
3226                                       const CXXScopeSpec &SS,
3227                                       TypeSourceInfo *ScopeType,
3228                                       SourceLocation CCLoc,
3229                                       SourceLocation TildeLoc,
3230                                     PseudoDestructorTypeStorage DestroyedType,
3231                                       bool HasTrailingLParen);
3232
3233  ExprResult ActOnPseudoDestructorExpr(Scope *S, Expr *Base,
3234                                       SourceLocation OpLoc,
3235                                       tok::TokenKind OpKind,
3236                                       CXXScopeSpec &SS,
3237                                       UnqualifiedId &FirstTypeName,
3238                                       SourceLocation CCLoc,
3239                                       SourceLocation TildeLoc,
3240                                       UnqualifiedId &SecondTypeName,
3241                                       bool HasTrailingLParen);
3242
3243  ExprResult ActOnPseudoDestructorExpr(Scope *S, Expr *Base,
3244                                       SourceLocation OpLoc,
3245                                       tok::TokenKind OpKind,
3246                                       SourceLocation TildeLoc,
3247                                       const DeclSpec& DS,
3248                                       bool HasTrailingLParen);
3249
3250  /// MaybeCreateExprWithCleanups - If the current full-expression
3251  /// requires any cleanups, surround it with a ExprWithCleanups node.
3252  /// Otherwise, just returns the passed-in expression.
3253  Expr *MaybeCreateExprWithCleanups(Expr *SubExpr);
3254  Stmt *MaybeCreateStmtWithCleanups(Stmt *SubStmt);
3255  ExprResult MaybeCreateExprWithCleanups(ExprResult SubExpr);
3256
3257  ExprResult ActOnFinishFullExpr(Expr *Expr);
3258  StmtResult ActOnFinishFullStmt(Stmt *Stmt);
3259
3260  // Marks SS invalid if it represents an incomplete type.
3261  bool RequireCompleteDeclContext(CXXScopeSpec &SS, DeclContext *DC);
3262
3263  DeclContext *computeDeclContext(QualType T);
3264  DeclContext *computeDeclContext(const CXXScopeSpec &SS,
3265                                  bool EnteringContext = false);
3266  bool isDependentScopeSpecifier(const CXXScopeSpec &SS);
3267  CXXRecordDecl *getCurrentInstantiationOf(NestedNameSpecifier *NNS);
3268  bool isUnknownSpecialization(const CXXScopeSpec &SS);
3269
3270  /// \brief The parser has parsed a global nested-name-specifier '::'.
3271  ///
3272  /// \param S The scope in which this nested-name-specifier occurs.
3273  ///
3274  /// \param CCLoc The location of the '::'.
3275  ///
3276  /// \param SS The nested-name-specifier, which will be updated in-place
3277  /// to reflect the parsed nested-name-specifier.
3278  ///
3279  /// \returns true if an error occurred, false otherwise.
3280  bool ActOnCXXGlobalScopeSpecifier(Scope *S, SourceLocation CCLoc,
3281                                    CXXScopeSpec &SS);
3282
3283  bool isAcceptableNestedNameSpecifier(NamedDecl *SD);
3284  NamedDecl *FindFirstQualifierInScope(Scope *S, NestedNameSpecifier *NNS);
3285
3286  bool isNonTypeNestedNameSpecifier(Scope *S, CXXScopeSpec &SS,
3287                                    SourceLocation IdLoc,
3288                                    IdentifierInfo &II,
3289                                    ParsedType ObjectType);
3290
3291  bool BuildCXXNestedNameSpecifier(Scope *S,
3292                                   IdentifierInfo &Identifier,
3293                                   SourceLocation IdentifierLoc,
3294                                   SourceLocation CCLoc,
3295                                   QualType ObjectType,
3296                                   bool EnteringContext,
3297                                   CXXScopeSpec &SS,
3298                                   NamedDecl *ScopeLookupResult,
3299                                   bool ErrorRecoveryLookup);
3300
3301  /// \brief The parser has parsed a nested-name-specifier 'identifier::'.
3302  ///
3303  /// \param S The scope in which this nested-name-specifier occurs.
3304  ///
3305  /// \param Identifier The identifier preceding the '::'.
3306  ///
3307  /// \param IdentifierLoc The location of the identifier.
3308  ///
3309  /// \param CCLoc The location of the '::'.
3310  ///
3311  /// \param ObjectType The type of the object, if we're parsing
3312  /// nested-name-specifier in a member access expression.
3313  ///
3314  /// \param EnteringContext Whether we're entering the context nominated by
3315  /// this nested-name-specifier.
3316  ///
3317  /// \param SS The nested-name-specifier, which is both an input
3318  /// parameter (the nested-name-specifier before this type) and an
3319  /// output parameter (containing the full nested-name-specifier,
3320  /// including this new type).
3321  ///
3322  /// \returns true if an error occurred, false otherwise.
3323  bool ActOnCXXNestedNameSpecifier(Scope *S,
3324                                   IdentifierInfo &Identifier,
3325                                   SourceLocation IdentifierLoc,
3326                                   SourceLocation CCLoc,
3327                                   ParsedType ObjectType,
3328                                   bool EnteringContext,
3329                                   CXXScopeSpec &SS);
3330
3331  bool ActOnCXXNestedNameSpecifierDecltype(CXXScopeSpec &SS,
3332                                           const DeclSpec &DS,
3333                                           SourceLocation ColonColonLoc);
3334
3335  bool IsInvalidUnlessNestedName(Scope *S, CXXScopeSpec &SS,
3336                                 IdentifierInfo &Identifier,
3337                                 SourceLocation IdentifierLoc,
3338                                 SourceLocation ColonLoc,
3339                                 ParsedType ObjectType,
3340                                 bool EnteringContext);
3341
3342  /// \brief The parser has parsed a nested-name-specifier
3343  /// 'template[opt] template-name < template-args >::'.
3344  ///
3345  /// \param S The scope in which this nested-name-specifier occurs.
3346  ///
3347  /// \param TemplateLoc The location of the 'template' keyword, if any.
3348  ///
3349  /// \param SS The nested-name-specifier, which is both an input
3350  /// parameter (the nested-name-specifier before this type) and an
3351  /// output parameter (containing the full nested-name-specifier,
3352  /// including this new type).
3353  ///
3354  /// \param TemplateLoc the location of the 'template' keyword, if any.
3355  /// \param TemplateName The template name.
3356  /// \param TemplateNameLoc The location of the template name.
3357  /// \param LAngleLoc The location of the opening angle bracket  ('<').
3358  /// \param TemplateArgs The template arguments.
3359  /// \param RAngleLoc The location of the closing angle bracket  ('>').
3360  /// \param CCLoc The location of the '::'.
3361
3362  /// \param EnteringContext Whether we're entering the context of the
3363  /// nested-name-specifier.
3364  ///
3365  ///
3366  /// \returns true if an error occurred, false otherwise.
3367  bool ActOnCXXNestedNameSpecifier(Scope *S,
3368                                   SourceLocation TemplateLoc,
3369                                   CXXScopeSpec &SS,
3370                                   TemplateTy Template,
3371                                   SourceLocation TemplateNameLoc,
3372                                   SourceLocation LAngleLoc,
3373                                   ASTTemplateArgsPtr TemplateArgs,
3374                                   SourceLocation RAngleLoc,
3375                                   SourceLocation CCLoc,
3376                                   bool EnteringContext);
3377
3378  /// \brief Given a C++ nested-name-specifier, produce an annotation value
3379  /// that the parser can use later to reconstruct the given
3380  /// nested-name-specifier.
3381  ///
3382  /// \param SS A nested-name-specifier.
3383  ///
3384  /// \returns A pointer containing all of the information in the
3385  /// nested-name-specifier \p SS.
3386  void *SaveNestedNameSpecifierAnnotation(CXXScopeSpec &SS);
3387
3388  /// \brief Given an annotation pointer for a nested-name-specifier, restore
3389  /// the nested-name-specifier structure.
3390  ///
3391  /// \param Annotation The annotation pointer, produced by
3392  /// \c SaveNestedNameSpecifierAnnotation().
3393  ///
3394  /// \param AnnotationRange The source range corresponding to the annotation.
3395  ///
3396  /// \param SS The nested-name-specifier that will be updated with the contents
3397  /// of the annotation pointer.
3398  void RestoreNestedNameSpecifierAnnotation(void *Annotation,
3399                                            SourceRange AnnotationRange,
3400                                            CXXScopeSpec &SS);
3401
3402  bool ShouldEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS);
3403
3404  /// ActOnCXXEnterDeclaratorScope - Called when a C++ scope specifier (global
3405  /// scope or nested-name-specifier) is parsed, part of a declarator-id.
3406  /// After this method is called, according to [C++ 3.4.3p3], names should be
3407  /// looked up in the declarator-id's scope, until the declarator is parsed and
3408  /// ActOnCXXExitDeclaratorScope is called.
3409  /// The 'SS' should be a non-empty valid CXXScopeSpec.
3410  bool ActOnCXXEnterDeclaratorScope(Scope *S, CXXScopeSpec &SS);
3411
3412  /// ActOnCXXExitDeclaratorScope - Called when a declarator that previously
3413  /// invoked ActOnCXXEnterDeclaratorScope(), is finished. 'SS' is the same
3414  /// CXXScopeSpec that was passed to ActOnCXXEnterDeclaratorScope as well.
3415  /// Used to indicate that names should revert to being looked up in the
3416  /// defining scope.
3417  void ActOnCXXExitDeclaratorScope(Scope *S, const CXXScopeSpec &SS);
3418
3419  /// ActOnCXXEnterDeclInitializer - Invoked when we are about to parse an
3420  /// initializer for the declaration 'Dcl'.
3421  /// After this method is called, according to [C++ 3.4.1p13], if 'Dcl' is a
3422  /// static data member of class X, names should be looked up in the scope of
3423  /// class X.
3424  void ActOnCXXEnterDeclInitializer(Scope *S, Decl *Dcl);
3425
3426  /// ActOnCXXExitDeclInitializer - Invoked after we are finished parsing an
3427  /// initializer for the declaration 'Dcl'.
3428  void ActOnCXXExitDeclInitializer(Scope *S, Decl *Dcl);
3429
3430  /// ActOnStartOfLambdaDefinition - This is called just before we start
3431  /// parsing the body of a lambda; it analyzes the explicit captures and
3432  /// arguments, and sets up various data-structures for the body of the
3433  /// lambda.
3434  void ActOnStartOfLambdaDefinition(LambdaIntroducer &Intro,
3435                                    Declarator &ParamInfo, Scope *CurScope);
3436
3437  /// ActOnLambdaError - If there is an error parsing a lambda, this callback
3438  /// is invoked to pop the information about the lambda.
3439  void ActOnLambdaError(SourceLocation StartLoc, Scope *CurScope);
3440
3441  /// ActOnLambdaExpr - This is called when the body of a lambda expression
3442  /// was successfully completed.
3443  ExprResult ActOnLambdaExpr(SourceLocation StartLoc, Stmt *Body,
3444                             Scope *CurScope);
3445
3446  // ParseObjCStringLiteral - Parse Objective-C string literals.
3447  ExprResult ParseObjCStringLiteral(SourceLocation *AtLocs,
3448                                    Expr **Strings,
3449                                    unsigned NumStrings);
3450
3451  ExprResult BuildObjCEncodeExpression(SourceLocation AtLoc,
3452                                  TypeSourceInfo *EncodedTypeInfo,
3453                                  SourceLocation RParenLoc);
3454  ExprResult BuildCXXMemberCallExpr(Expr *Exp, NamedDecl *FoundDecl,
3455                                    CXXMethodDecl *Method,
3456                                    bool HadMultipleCandidates);
3457
3458  ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc,
3459                                       SourceLocation EncodeLoc,
3460                                       SourceLocation LParenLoc,
3461                                       ParsedType Ty,
3462                                       SourceLocation RParenLoc);
3463
3464  // ParseObjCSelectorExpression - Build selector expression for @selector
3465  ExprResult ParseObjCSelectorExpression(Selector Sel,
3466                                         SourceLocation AtLoc,
3467                                         SourceLocation SelLoc,
3468                                         SourceLocation LParenLoc,
3469                                         SourceLocation RParenLoc);
3470
3471  // ParseObjCProtocolExpression - Build protocol expression for @protocol
3472  ExprResult ParseObjCProtocolExpression(IdentifierInfo * ProtocolName,
3473                                         SourceLocation AtLoc,
3474                                         SourceLocation ProtoLoc,
3475                                         SourceLocation LParenLoc,
3476                                         SourceLocation RParenLoc);
3477
3478  //===--------------------------------------------------------------------===//
3479  // C++ Declarations
3480  //
3481  Decl *ActOnStartLinkageSpecification(Scope *S,
3482                                       SourceLocation ExternLoc,
3483                                       SourceLocation LangLoc,
3484                                       StringRef Lang,
3485                                       SourceLocation LBraceLoc);
3486  Decl *ActOnFinishLinkageSpecification(Scope *S,
3487                                        Decl *LinkageSpec,
3488                                        SourceLocation RBraceLoc);
3489
3490
3491  //===--------------------------------------------------------------------===//
3492  // C++ Classes
3493  //
3494  bool isCurrentClassName(const IdentifierInfo &II, Scope *S,
3495                          const CXXScopeSpec *SS = 0);
3496
3497  bool ActOnAccessSpecifier(AccessSpecifier Access,
3498                            SourceLocation ASLoc,
3499                            SourceLocation ColonLoc,
3500                            AttributeList *Attrs = 0);
3501
3502  Decl *ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS,
3503                                 Declarator &D,
3504                                 MultiTemplateParamsArg TemplateParameterLists,
3505                                 Expr *BitfieldWidth, const VirtSpecifiers &VS,
3506                                 bool HasDeferredInit);
3507  void ActOnCXXInClassMemberInitializer(Decl *VarDecl, SourceLocation EqualLoc,
3508                                        Expr *Init);
3509
3510  MemInitResult ActOnMemInitializer(Decl *ConstructorD,
3511                                    Scope *S,
3512                                    CXXScopeSpec &SS,
3513                                    IdentifierInfo *MemberOrBase,
3514                                    ParsedType TemplateTypeTy,
3515                                    const DeclSpec &DS,
3516                                    SourceLocation IdLoc,
3517                                    SourceLocation LParenLoc,
3518                                    Expr **Args, unsigned NumArgs,
3519                                    SourceLocation RParenLoc,
3520                                    SourceLocation EllipsisLoc);
3521
3522  MemInitResult ActOnMemInitializer(Decl *ConstructorD,
3523                                    Scope *S,
3524                                    CXXScopeSpec &SS,
3525                                    IdentifierInfo *MemberOrBase,
3526                                    ParsedType TemplateTypeTy,
3527                                    const DeclSpec &DS,
3528                                    SourceLocation IdLoc,
3529                                    Expr *InitList,
3530                                    SourceLocation EllipsisLoc);
3531
3532  MemInitResult BuildMemInitializer(Decl *ConstructorD,
3533                                    Scope *S,
3534                                    CXXScopeSpec &SS,
3535                                    IdentifierInfo *MemberOrBase,
3536                                    ParsedType TemplateTypeTy,
3537                                    const DeclSpec &DS,
3538                                    SourceLocation IdLoc,
3539                                    const MultiInitializer &Init,
3540                                    SourceLocation EllipsisLoc);
3541
3542  MemInitResult BuildMemberInitializer(ValueDecl *Member,
3543                                       const MultiInitializer &Args,
3544                                       SourceLocation IdLoc);
3545
3546  MemInitResult BuildBaseInitializer(QualType BaseType,
3547                                     TypeSourceInfo *BaseTInfo,
3548                                     const MultiInitializer &Args,
3549                                     CXXRecordDecl *ClassDecl,
3550                                     SourceLocation EllipsisLoc);
3551
3552  MemInitResult BuildDelegatingInitializer(TypeSourceInfo *TInfo,
3553                                           const MultiInitializer &Args,
3554                                           CXXRecordDecl *ClassDecl);
3555
3556  bool SetDelegatingInitializer(CXXConstructorDecl *Constructor,
3557                                CXXCtorInitializer *Initializer);
3558
3559  bool SetCtorInitializers(CXXConstructorDecl *Constructor,
3560                           CXXCtorInitializer **Initializers,
3561                           unsigned NumInitializers, bool AnyErrors);
3562
3563  void SetIvarInitializers(ObjCImplementationDecl *ObjCImplementation);
3564
3565
3566  /// MarkBaseAndMemberDestructorsReferenced - Given a record decl,
3567  /// mark all the non-trivial destructors of its members and bases as
3568  /// referenced.
3569  void MarkBaseAndMemberDestructorsReferenced(SourceLocation Loc,
3570                                              CXXRecordDecl *Record);
3571
3572  /// \brief The list of classes whose vtables have been used within
3573  /// this translation unit, and the source locations at which the
3574  /// first use occurred.
3575  typedef std::pair<CXXRecordDecl*, SourceLocation> VTableUse;
3576
3577  /// \brief The list of vtables that are required but have not yet been
3578  /// materialized.
3579  SmallVector<VTableUse, 16> VTableUses;
3580
3581  /// \brief The set of classes whose vtables have been used within
3582  /// this translation unit, and a bit that will be true if the vtable is
3583  /// required to be emitted (otherwise, it should be emitted only if needed
3584  /// by code generation).
3585  llvm::DenseMap<CXXRecordDecl *, bool> VTablesUsed;
3586
3587  /// \brief Load any externally-stored vtable uses.
3588  void LoadExternalVTableUses();
3589
3590  typedef LazyVector<CXXRecordDecl *, ExternalSemaSource,
3591                     &ExternalSemaSource::ReadDynamicClasses, 2, 2>
3592    DynamicClassesType;
3593
3594  /// \brief A list of all of the dynamic classes in this translation
3595  /// unit.
3596  DynamicClassesType DynamicClasses;
3597
3598  /// \brief Note that the vtable for the given class was used at the
3599  /// given location.
3600  void MarkVTableUsed(SourceLocation Loc, CXXRecordDecl *Class,
3601                      bool DefinitionRequired = false);
3602
3603  /// MarkVirtualMembersReferenced - Will mark all members of the given
3604  /// CXXRecordDecl referenced.
3605  void MarkVirtualMembersReferenced(SourceLocation Loc,
3606                                    const CXXRecordDecl *RD);
3607
3608  /// \brief Define all of the vtables that have been used in this
3609  /// translation unit and reference any virtual members used by those
3610  /// vtables.
3611  ///
3612  /// \returns true if any work was done, false otherwise.
3613  bool DefineUsedVTables();
3614
3615  void AddImplicitlyDeclaredMembersToClass(CXXRecordDecl *ClassDecl);
3616
3617  void ActOnMemInitializers(Decl *ConstructorDecl,
3618                            SourceLocation ColonLoc,
3619                            CXXCtorInitializer **MemInits,
3620                            unsigned NumMemInits,
3621                            bool AnyErrors);
3622
3623  void CheckCompletedCXXClass(CXXRecordDecl *Record);
3624  void ActOnFinishCXXMemberSpecification(Scope* S, SourceLocation RLoc,
3625                                         Decl *TagDecl,
3626                                         SourceLocation LBrac,
3627                                         SourceLocation RBrac,
3628                                         AttributeList *AttrList);
3629
3630  void ActOnReenterTemplateScope(Scope *S, Decl *Template);
3631  void ActOnReenterDeclaratorTemplateScope(Scope *S, DeclaratorDecl *D);
3632  void ActOnStartDelayedMemberDeclarations(Scope *S, Decl *Record);
3633  void ActOnStartDelayedCXXMethodDeclaration(Scope *S, Decl *Method);
3634  void ActOnDelayedCXXMethodParameter(Scope *S, Decl *Param);
3635  void ActOnFinishDelayedMemberDeclarations(Scope *S, Decl *Record);
3636  void ActOnFinishDelayedCXXMethodDeclaration(Scope *S, Decl *Method);
3637  void ActOnFinishDelayedMemberInitializers(Decl *Record);
3638  void MarkAsLateParsedTemplate(FunctionDecl *FD, bool Flag = true);
3639  bool IsInsideALocalClassWithinATemplateFunction();
3640
3641  Decl *ActOnStaticAssertDeclaration(SourceLocation StaticAssertLoc,
3642                                     Expr *AssertExpr,
3643                                     Expr *AssertMessageExpr,
3644                                     SourceLocation RParenLoc);
3645
3646  FriendDecl *CheckFriendTypeDecl(SourceLocation Loc,
3647                                  SourceLocation FriendLoc,
3648                                  TypeSourceInfo *TSInfo);
3649  Decl *ActOnFriendTypeDecl(Scope *S, const DeclSpec &DS,
3650                            MultiTemplateParamsArg TemplateParams);
3651  Decl *ActOnFriendFunctionDecl(Scope *S, Declarator &D,
3652                                MultiTemplateParamsArg TemplateParams);
3653
3654  QualType CheckConstructorDeclarator(Declarator &D, QualType R,
3655                                      StorageClass& SC);
3656  void CheckConstructor(CXXConstructorDecl *Constructor);
3657  QualType CheckDestructorDeclarator(Declarator &D, QualType R,
3658                                     StorageClass& SC);
3659  bool CheckDestructor(CXXDestructorDecl *Destructor);
3660  void CheckConversionDeclarator(Declarator &D, QualType &R,
3661                                 StorageClass& SC);
3662  Decl *ActOnConversionDeclarator(CXXConversionDecl *Conversion);
3663
3664  void CheckExplicitlyDefaultedMethods(CXXRecordDecl *Record);
3665  void CheckExplicitlyDefaultedDefaultConstructor(CXXConstructorDecl *Ctor);
3666  void CheckExplicitlyDefaultedCopyConstructor(CXXConstructorDecl *Ctor);
3667  void CheckExplicitlyDefaultedCopyAssignment(CXXMethodDecl *Method);
3668  void CheckExplicitlyDefaultedMoveConstructor(CXXConstructorDecl *Ctor);
3669  void CheckExplicitlyDefaultedMoveAssignment(CXXMethodDecl *Method);
3670  void CheckExplicitlyDefaultedDestructor(CXXDestructorDecl *Dtor);
3671
3672  //===--------------------------------------------------------------------===//
3673  // C++ Derived Classes
3674  //
3675
3676  /// ActOnBaseSpecifier - Parsed a base specifier
3677  CXXBaseSpecifier *CheckBaseSpecifier(CXXRecordDecl *Class,
3678                                       SourceRange SpecifierRange,
3679                                       bool Virtual, AccessSpecifier Access,
3680                                       TypeSourceInfo *TInfo,
3681                                       SourceLocation EllipsisLoc);
3682
3683  BaseResult ActOnBaseSpecifier(Decl *classdecl,
3684                                SourceRange SpecifierRange,
3685                                bool Virtual, AccessSpecifier Access,
3686                                ParsedType basetype,
3687                                SourceLocation BaseLoc,
3688                                SourceLocation EllipsisLoc);
3689
3690  bool AttachBaseSpecifiers(CXXRecordDecl *Class, CXXBaseSpecifier **Bases,
3691                            unsigned NumBases);
3692  void ActOnBaseSpecifiers(Decl *ClassDecl, CXXBaseSpecifier **Bases,
3693                           unsigned NumBases);
3694
3695  bool IsDerivedFrom(QualType Derived, QualType Base);
3696  bool IsDerivedFrom(QualType Derived, QualType Base, CXXBasePaths &Paths);
3697
3698  // FIXME: I don't like this name.
3699  void BuildBasePathArray(const CXXBasePaths &Paths, CXXCastPath &BasePath);
3700
3701  bool BasePathInvolvesVirtualBase(const CXXCastPath &BasePath);
3702
3703  bool CheckDerivedToBaseConversion(QualType Derived, QualType Base,
3704                                    SourceLocation Loc, SourceRange Range,
3705                                    CXXCastPath *BasePath = 0,
3706                                    bool IgnoreAccess = false);
3707  bool CheckDerivedToBaseConversion(QualType Derived, QualType Base,
3708                                    unsigned InaccessibleBaseID,
3709                                    unsigned AmbigiousBaseConvID,
3710                                    SourceLocation Loc, SourceRange Range,
3711                                    DeclarationName Name,
3712                                    CXXCastPath *BasePath);
3713
3714  std::string getAmbiguousPathsDisplayString(CXXBasePaths &Paths);
3715
3716  /// CheckOverridingFunctionReturnType - Checks whether the return types are
3717  /// covariant, according to C++ [class.virtual]p5.
3718  bool CheckOverridingFunctionReturnType(const CXXMethodDecl *New,
3719                                         const CXXMethodDecl *Old);
3720
3721  /// CheckOverridingFunctionExceptionSpec - Checks whether the exception
3722  /// spec is a subset of base spec.
3723  bool CheckOverridingFunctionExceptionSpec(const CXXMethodDecl *New,
3724                                            const CXXMethodDecl *Old);
3725
3726  bool CheckPureMethod(CXXMethodDecl *Method, SourceRange InitRange);
3727
3728  /// CheckOverrideControl - Check C++0x override control semantics.
3729  void CheckOverrideControl(const Decl *D);
3730
3731  /// CheckForFunctionMarkedFinal - Checks whether a virtual member function
3732  /// overrides a virtual member function marked 'final', according to
3733  /// C++0x [class.virtual]p3.
3734  bool CheckIfOverriddenFunctionIsMarkedFinal(const CXXMethodDecl *New,
3735                                              const CXXMethodDecl *Old);
3736
3737
3738  //===--------------------------------------------------------------------===//
3739  // C++ Access Control
3740  //
3741
3742  enum AccessResult {
3743    AR_accessible,
3744    AR_inaccessible,
3745    AR_dependent,
3746    AR_delayed
3747  };
3748
3749  bool SetMemberAccessSpecifier(NamedDecl *MemberDecl,
3750                                NamedDecl *PrevMemberDecl,
3751                                AccessSpecifier LexicalAS);
3752
3753  AccessResult CheckUnresolvedMemberAccess(UnresolvedMemberExpr *E,
3754                                           DeclAccessPair FoundDecl);
3755  AccessResult CheckUnresolvedLookupAccess(UnresolvedLookupExpr *E,
3756                                           DeclAccessPair FoundDecl);
3757  AccessResult CheckAllocationAccess(SourceLocation OperatorLoc,
3758                                     SourceRange PlacementRange,
3759                                     CXXRecordDecl *NamingClass,
3760                                     DeclAccessPair FoundDecl,
3761                                     bool Diagnose = true);
3762  AccessResult CheckConstructorAccess(SourceLocation Loc,
3763                                      CXXConstructorDecl *D,
3764                                      const InitializedEntity &Entity,
3765                                      AccessSpecifier Access,
3766                                      bool IsCopyBindingRefToTemp = false);
3767  AccessResult CheckConstructorAccess(SourceLocation Loc,
3768                                      CXXConstructorDecl *D,
3769                                      AccessSpecifier Access,
3770                                      PartialDiagnostic PD);
3771  AccessResult CheckDestructorAccess(SourceLocation Loc,
3772                                     CXXDestructorDecl *Dtor,
3773                                     const PartialDiagnostic &PDiag);
3774  AccessResult CheckDirectMemberAccess(SourceLocation Loc,
3775                                       NamedDecl *D,
3776                                       const PartialDiagnostic &PDiag);
3777  AccessResult CheckMemberOperatorAccess(SourceLocation Loc,
3778                                         Expr *ObjectExpr,
3779                                         Expr *ArgExpr,
3780                                         DeclAccessPair FoundDecl);
3781  AccessResult CheckAddressOfMemberAccess(Expr *OvlExpr,
3782                                          DeclAccessPair FoundDecl);
3783  AccessResult CheckBaseClassAccess(SourceLocation AccessLoc,
3784                                    QualType Base, QualType Derived,
3785                                    const CXXBasePath &Path,
3786                                    unsigned DiagID,
3787                                    bool ForceCheck = false,
3788                                    bool ForceUnprivileged = false);
3789  void CheckLookupAccess(const LookupResult &R);
3790  bool IsSimplyAccessible(NamedDecl *decl, DeclContext *Ctx);
3791
3792  void HandleDependentAccessCheck(const DependentDiagnostic &DD,
3793                         const MultiLevelTemplateArgumentList &TemplateArgs);
3794  void PerformDependentDiagnostics(const DeclContext *Pattern,
3795                        const MultiLevelTemplateArgumentList &TemplateArgs);
3796
3797  void HandleDelayedAccessCheck(sema::DelayedDiagnostic &DD, Decl *Ctx);
3798
3799  /// A flag to suppress access checking.
3800  bool SuppressAccessChecking;
3801
3802  /// \brief When true, access checking violations are treated as SFINAE
3803  /// failures rather than hard errors.
3804  bool AccessCheckingSFINAE;
3805
3806  void ActOnStartSuppressingAccessChecks();
3807  void ActOnStopSuppressingAccessChecks();
3808
3809  enum AbstractDiagSelID {
3810    AbstractNone = -1,
3811    AbstractReturnType,
3812    AbstractParamType,
3813    AbstractVariableType,
3814    AbstractFieldType,
3815    AbstractArrayType
3816  };
3817
3818  bool RequireNonAbstractType(SourceLocation Loc, QualType T,
3819                              const PartialDiagnostic &PD);
3820  void DiagnoseAbstractType(const CXXRecordDecl *RD);
3821
3822  bool RequireNonAbstractType(SourceLocation Loc, QualType T, unsigned DiagID,
3823                              AbstractDiagSelID SelID = AbstractNone);
3824
3825  //===--------------------------------------------------------------------===//
3826  // C++ Overloaded Operators [C++ 13.5]
3827  //
3828
3829  bool CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl);
3830
3831  bool CheckLiteralOperatorDeclaration(FunctionDecl *FnDecl);
3832
3833  //===--------------------------------------------------------------------===//
3834  // C++ Templates [C++ 14]
3835  //
3836  void FilterAcceptableTemplateNames(LookupResult &R);
3837  bool hasAnyAcceptableTemplateNames(LookupResult &R);
3838
3839  void LookupTemplateName(LookupResult &R, Scope *S, CXXScopeSpec &SS,
3840                          QualType ObjectType, bool EnteringContext,
3841                          bool &MemberOfUnknownSpecialization);
3842
3843  TemplateNameKind isTemplateName(Scope *S,
3844                                  CXXScopeSpec &SS,
3845                                  bool hasTemplateKeyword,
3846                                  UnqualifiedId &Name,
3847                                  ParsedType ObjectType,
3848                                  bool EnteringContext,
3849                                  TemplateTy &Template,
3850                                  bool &MemberOfUnknownSpecialization);
3851
3852  bool DiagnoseUnknownTemplateName(const IdentifierInfo &II,
3853                                   SourceLocation IILoc,
3854                                   Scope *S,
3855                                   const CXXScopeSpec *SS,
3856                                   TemplateTy &SuggestedTemplate,
3857                                   TemplateNameKind &SuggestedKind);
3858
3859  void DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl);
3860  TemplateDecl *AdjustDeclIfTemplate(Decl *&Decl);
3861
3862  Decl *ActOnTypeParameter(Scope *S, bool Typename, bool Ellipsis,
3863                           SourceLocation EllipsisLoc,
3864                           SourceLocation KeyLoc,
3865                           IdentifierInfo *ParamName,
3866                           SourceLocation ParamNameLoc,
3867                           unsigned Depth, unsigned Position,
3868                           SourceLocation EqualLoc,
3869                           ParsedType DefaultArg);
3870
3871  QualType CheckNonTypeTemplateParameterType(QualType T, SourceLocation Loc);
3872  Decl *ActOnNonTypeTemplateParameter(Scope *S, Declarator &D,
3873                                      unsigned Depth,
3874                                      unsigned Position,
3875                                      SourceLocation EqualLoc,
3876                                      Expr *DefaultArg);
3877  Decl *ActOnTemplateTemplateParameter(Scope *S,
3878                                       SourceLocation TmpLoc,
3879                                       TemplateParameterList *Params,
3880                                       SourceLocation EllipsisLoc,
3881                                       IdentifierInfo *ParamName,
3882                                       SourceLocation ParamNameLoc,
3883                                       unsigned Depth,
3884                                       unsigned Position,
3885                                       SourceLocation EqualLoc,
3886                                       ParsedTemplateArgument DefaultArg);
3887
3888  TemplateParameterList *
3889  ActOnTemplateParameterList(unsigned Depth,
3890                             SourceLocation ExportLoc,
3891                             SourceLocation TemplateLoc,
3892                             SourceLocation LAngleLoc,
3893                             Decl **Params, unsigned NumParams,
3894                             SourceLocation RAngleLoc);
3895
3896  /// \brief The context in which we are checking a template parameter
3897  /// list.
3898  enum TemplateParamListContext {
3899    TPC_ClassTemplate,
3900    TPC_FunctionTemplate,
3901    TPC_ClassTemplateMember,
3902    TPC_FriendFunctionTemplate,
3903    TPC_FriendFunctionTemplateDefinition,
3904    TPC_TypeAliasTemplate
3905  };
3906
3907  bool CheckTemplateParameterList(TemplateParameterList *NewParams,
3908                                  TemplateParameterList *OldParams,
3909                                  TemplateParamListContext TPC);
3910  TemplateParameterList *
3911  MatchTemplateParametersToScopeSpecifier(SourceLocation DeclStartLoc,
3912                                          SourceLocation DeclLoc,
3913                                          const CXXScopeSpec &SS,
3914                                          TemplateParameterList **ParamLists,
3915                                          unsigned NumParamLists,
3916                                          bool IsFriend,
3917                                          bool &IsExplicitSpecialization,
3918                                          bool &Invalid);
3919
3920  DeclResult CheckClassTemplate(Scope *S, unsigned TagSpec, TagUseKind TUK,
3921                                SourceLocation KWLoc, CXXScopeSpec &SS,
3922                                IdentifierInfo *Name, SourceLocation NameLoc,
3923                                AttributeList *Attr,
3924                                TemplateParameterList *TemplateParams,
3925                                AccessSpecifier AS,
3926                                SourceLocation ModulePrivateLoc,
3927                                unsigned NumOuterTemplateParamLists,
3928                            TemplateParameterList **OuterTemplateParamLists);
3929
3930  void translateTemplateArguments(const ASTTemplateArgsPtr &In,
3931                                  TemplateArgumentListInfo &Out);
3932
3933  void NoteAllFoundTemplates(TemplateName Name);
3934
3935  QualType CheckTemplateIdType(TemplateName Template,
3936                               SourceLocation TemplateLoc,
3937                              TemplateArgumentListInfo &TemplateArgs);
3938
3939  TypeResult
3940  ActOnTemplateIdType(CXXScopeSpec &SS,
3941                      TemplateTy Template, SourceLocation TemplateLoc,
3942                      SourceLocation LAngleLoc,
3943                      ASTTemplateArgsPtr TemplateArgs,
3944                      SourceLocation RAngleLoc);
3945
3946  /// \brief Parsed an elaborated-type-specifier that refers to a template-id,
3947  /// such as \c class T::template apply<U>.
3948  ///
3949  /// \param TUK
3950  TypeResult ActOnTagTemplateIdType(TagUseKind TUK,
3951                                    TypeSpecifierType TagSpec,
3952                                    SourceLocation TagLoc,
3953                                    CXXScopeSpec &SS,
3954                                    TemplateTy TemplateD,
3955                                    SourceLocation TemplateLoc,
3956                                    SourceLocation LAngleLoc,
3957                                    ASTTemplateArgsPtr TemplateArgsIn,
3958                                    SourceLocation RAngleLoc);
3959
3960
3961  ExprResult BuildTemplateIdExpr(const CXXScopeSpec &SS,
3962                                 LookupResult &R,
3963                                 bool RequiresADL,
3964                               const TemplateArgumentListInfo &TemplateArgs);
3965  ExprResult BuildQualifiedTemplateIdExpr(CXXScopeSpec &SS,
3966                               const DeclarationNameInfo &NameInfo,
3967                               const TemplateArgumentListInfo &TemplateArgs);
3968
3969  TemplateNameKind ActOnDependentTemplateName(Scope *S,
3970                                              SourceLocation TemplateKWLoc,
3971                                              CXXScopeSpec &SS,
3972                                              UnqualifiedId &Name,
3973                                              ParsedType ObjectType,
3974                                              bool EnteringContext,
3975                                              TemplateTy &Template);
3976
3977  DeclResult
3978  ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, TagUseKind TUK,
3979                                   SourceLocation KWLoc,
3980                                   SourceLocation ModulePrivateLoc,
3981                                   CXXScopeSpec &SS,
3982                                   TemplateTy Template,
3983                                   SourceLocation TemplateNameLoc,
3984                                   SourceLocation LAngleLoc,
3985                                   ASTTemplateArgsPtr TemplateArgs,
3986                                   SourceLocation RAngleLoc,
3987                                   AttributeList *Attr,
3988                                 MultiTemplateParamsArg TemplateParameterLists);
3989
3990  Decl *ActOnTemplateDeclarator(Scope *S,
3991                                MultiTemplateParamsArg TemplateParameterLists,
3992                                Declarator &D);
3993
3994  Decl *ActOnStartOfFunctionTemplateDef(Scope *FnBodyScope,
3995                                  MultiTemplateParamsArg TemplateParameterLists,
3996                                        Declarator &D);
3997
3998  bool
3999  CheckSpecializationInstantiationRedecl(SourceLocation NewLoc,
4000                                         TemplateSpecializationKind NewTSK,
4001                                         NamedDecl *PrevDecl,
4002                                         TemplateSpecializationKind PrevTSK,
4003                                         SourceLocation PrevPtOfInstantiation,
4004                                         bool &SuppressNew);
4005
4006  bool CheckDependentFunctionTemplateSpecialization(FunctionDecl *FD,
4007                    const TemplateArgumentListInfo &ExplicitTemplateArgs,
4008                                                    LookupResult &Previous);
4009
4010  bool CheckFunctionTemplateSpecialization(FunctionDecl *FD,
4011                         TemplateArgumentListInfo *ExplicitTemplateArgs,
4012                                           LookupResult &Previous);
4013  bool CheckMemberSpecialization(NamedDecl *Member, LookupResult &Previous);
4014
4015  DeclResult
4016  ActOnExplicitInstantiation(Scope *S,
4017                             SourceLocation ExternLoc,
4018                             SourceLocation TemplateLoc,
4019                             unsigned TagSpec,
4020                             SourceLocation KWLoc,
4021                             const CXXScopeSpec &SS,
4022                             TemplateTy Template,
4023                             SourceLocation TemplateNameLoc,
4024                             SourceLocation LAngleLoc,
4025                             ASTTemplateArgsPtr TemplateArgs,
4026                             SourceLocation RAngleLoc,
4027                             AttributeList *Attr);
4028
4029  DeclResult
4030  ActOnExplicitInstantiation(Scope *S,
4031                             SourceLocation ExternLoc,
4032                             SourceLocation TemplateLoc,
4033                             unsigned TagSpec,
4034                             SourceLocation KWLoc,
4035                             CXXScopeSpec &SS,
4036                             IdentifierInfo *Name,
4037                             SourceLocation NameLoc,
4038                             AttributeList *Attr);
4039
4040  DeclResult ActOnExplicitInstantiation(Scope *S,
4041                                        SourceLocation ExternLoc,
4042                                        SourceLocation TemplateLoc,
4043                                        Declarator &D);
4044
4045  TemplateArgumentLoc
4046  SubstDefaultTemplateArgumentIfAvailable(TemplateDecl *Template,
4047                                          SourceLocation TemplateLoc,
4048                                          SourceLocation RAngleLoc,
4049                                          Decl *Param,
4050                          SmallVectorImpl<TemplateArgument> &Converted);
4051
4052  /// \brief Specifies the context in which a particular template
4053  /// argument is being checked.
4054  enum CheckTemplateArgumentKind {
4055    /// \brief The template argument was specified in the code or was
4056    /// instantiated with some deduced template arguments.
4057    CTAK_Specified,
4058
4059    /// \brief The template argument was deduced via template argument
4060    /// deduction.
4061    CTAK_Deduced,
4062
4063    /// \brief The template argument was deduced from an array bound
4064    /// via template argument deduction.
4065    CTAK_DeducedFromArrayBound
4066  };
4067
4068  bool CheckTemplateArgument(NamedDecl *Param,
4069                             const TemplateArgumentLoc &Arg,
4070                             NamedDecl *Template,
4071                             SourceLocation TemplateLoc,
4072                             SourceLocation RAngleLoc,
4073                             unsigned ArgumentPackIndex,
4074                           SmallVectorImpl<TemplateArgument> &Converted,
4075                             CheckTemplateArgumentKind CTAK = CTAK_Specified);
4076
4077  /// \brief Check that the given template arguments can be be provided to
4078  /// the given template, converting the arguments along the way.
4079  ///
4080  /// \param Template The template to which the template arguments are being
4081  /// provided.
4082  ///
4083  /// \param TemplateLoc The location of the template name in the source.
4084  ///
4085  /// \param TemplateArgs The list of template arguments. If the template is
4086  /// a template template parameter, this function may extend the set of
4087  /// template arguments to also include substituted, defaulted template
4088  /// arguments.
4089  ///
4090  /// \param PartialTemplateArgs True if the list of template arguments is
4091  /// intentionally partial, e.g., because we're checking just the initial
4092  /// set of template arguments.
4093  ///
4094  /// \param Converted Will receive the converted, canonicalized template
4095  /// arguments.
4096  ///
4097  /// \returns True if an error occurred, false otherwise.
4098  bool CheckTemplateArgumentList(TemplateDecl *Template,
4099                                 SourceLocation TemplateLoc,
4100                                 TemplateArgumentListInfo &TemplateArgs,
4101                                 bool PartialTemplateArgs,
4102                           SmallVectorImpl<TemplateArgument> &Converted);
4103
4104  bool CheckTemplateTypeArgument(TemplateTypeParmDecl *Param,
4105                                 const TemplateArgumentLoc &Arg,
4106                           SmallVectorImpl<TemplateArgument> &Converted);
4107
4108  bool CheckTemplateArgument(TemplateTypeParmDecl *Param,
4109                             TypeSourceInfo *Arg);
4110  bool CheckTemplateArgumentPointerToMember(Expr *Arg,
4111                                            TemplateArgument &Converted);
4112  ExprResult CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
4113                                   QualType InstantiatedParamType, Expr *Arg,
4114                                   TemplateArgument &Converted,
4115                               CheckTemplateArgumentKind CTAK = CTAK_Specified);
4116  bool CheckTemplateArgument(TemplateTemplateParmDecl *Param,
4117                             const TemplateArgumentLoc &Arg);
4118
4119  ExprResult
4120  BuildExpressionFromDeclTemplateArgument(const TemplateArgument &Arg,
4121                                          QualType ParamType,
4122                                          SourceLocation Loc);
4123  ExprResult
4124  BuildExpressionFromIntegralTemplateArgument(const TemplateArgument &Arg,
4125                                              SourceLocation Loc);
4126
4127  /// \brief Enumeration describing how template parameter lists are compared
4128  /// for equality.
4129  enum TemplateParameterListEqualKind {
4130    /// \brief We are matching the template parameter lists of two templates
4131    /// that might be redeclarations.
4132    ///
4133    /// \code
4134    /// template<typename T> struct X;
4135    /// template<typename T> struct X;
4136    /// \endcode
4137    TPL_TemplateMatch,
4138
4139    /// \brief We are matching the template parameter lists of two template
4140    /// template parameters as part of matching the template parameter lists
4141    /// of two templates that might be redeclarations.
4142    ///
4143    /// \code
4144    /// template<template<int I> class TT> struct X;
4145    /// template<template<int Value> class Other> struct X;
4146    /// \endcode
4147    TPL_TemplateTemplateParmMatch,
4148
4149    /// \brief We are matching the template parameter lists of a template
4150    /// template argument against the template parameter lists of a template
4151    /// template parameter.
4152    ///
4153    /// \code
4154    /// template<template<int Value> class Metafun> struct X;
4155    /// template<int Value> struct integer_c;
4156    /// X<integer_c> xic;
4157    /// \endcode
4158    TPL_TemplateTemplateArgumentMatch
4159  };
4160
4161  bool TemplateParameterListsAreEqual(TemplateParameterList *New,
4162                                      TemplateParameterList *Old,
4163                                      bool Complain,
4164                                      TemplateParameterListEqualKind Kind,
4165                                      SourceLocation TemplateArgLoc
4166                                        = SourceLocation());
4167
4168  bool CheckTemplateDeclScope(Scope *S, TemplateParameterList *TemplateParams);
4169
4170  /// \brief Called when the parser has parsed a C++ typename
4171  /// specifier, e.g., "typename T::type".
4172  ///
4173  /// \param S The scope in which this typename type occurs.
4174  /// \param TypenameLoc the location of the 'typename' keyword
4175  /// \param SS the nested-name-specifier following the typename (e.g., 'T::').
4176  /// \param II the identifier we're retrieving (e.g., 'type' in the example).
4177  /// \param IdLoc the location of the identifier.
4178  TypeResult
4179  ActOnTypenameType(Scope *S, SourceLocation TypenameLoc,
4180                    const CXXScopeSpec &SS, const IdentifierInfo &II,
4181                    SourceLocation IdLoc);
4182
4183  /// \brief Called when the parser has parsed a C++ typename
4184  /// specifier that ends in a template-id, e.g.,
4185  /// "typename MetaFun::template apply<T1, T2>".
4186  ///
4187  /// \param S The scope in which this typename type occurs.
4188  /// \param TypenameLoc the location of the 'typename' keyword
4189  /// \param SS the nested-name-specifier following the typename (e.g., 'T::').
4190  /// \param TemplateLoc the location of the 'template' keyword, if any.
4191  /// \param TemplateName The template name.
4192  /// \param TemplateNameLoc The location of the template name.
4193  /// \param LAngleLoc The location of the opening angle bracket  ('<').
4194  /// \param TemplateArgs The template arguments.
4195  /// \param RAngleLoc The location of the closing angle bracket  ('>').
4196  TypeResult
4197  ActOnTypenameType(Scope *S, SourceLocation TypenameLoc,
4198                    const CXXScopeSpec &SS,
4199                    SourceLocation TemplateLoc,
4200                    TemplateTy Template,
4201                    SourceLocation TemplateNameLoc,
4202                    SourceLocation LAngleLoc,
4203                    ASTTemplateArgsPtr TemplateArgs,
4204                    SourceLocation RAngleLoc);
4205
4206  QualType CheckTypenameType(ElaboratedTypeKeyword Keyword,
4207                             SourceLocation KeywordLoc,
4208                             NestedNameSpecifierLoc QualifierLoc,
4209                             const IdentifierInfo &II,
4210                             SourceLocation IILoc);
4211
4212  TypeSourceInfo *RebuildTypeInCurrentInstantiation(TypeSourceInfo *T,
4213                                                    SourceLocation Loc,
4214                                                    DeclarationName Name);
4215  bool RebuildNestedNameSpecifierInCurrentInstantiation(CXXScopeSpec &SS);
4216
4217  ExprResult RebuildExprInCurrentInstantiation(Expr *E);
4218  bool RebuildTemplateParamsInCurrentInstantiation(
4219                                                TemplateParameterList *Params);
4220
4221  std::string
4222  getTemplateArgumentBindingsText(const TemplateParameterList *Params,
4223                                  const TemplateArgumentList &Args);
4224
4225  std::string
4226  getTemplateArgumentBindingsText(const TemplateParameterList *Params,
4227                                  const TemplateArgument *Args,
4228                                  unsigned NumArgs);
4229
4230  //===--------------------------------------------------------------------===//
4231  // C++ Variadic Templates (C++0x [temp.variadic])
4232  //===--------------------------------------------------------------------===//
4233
4234  /// \brief The context in which an unexpanded parameter pack is
4235  /// being diagnosed.
4236  ///
4237  /// Note that the values of this enumeration line up with the first
4238  /// argument to the \c err_unexpanded_parameter_pack diagnostic.
4239  enum UnexpandedParameterPackContext {
4240    /// \brief An arbitrary expression.
4241    UPPC_Expression = 0,
4242
4243    /// \brief The base type of a class type.
4244    UPPC_BaseType,
4245
4246    /// \brief The type of an arbitrary declaration.
4247    UPPC_DeclarationType,
4248
4249    /// \brief The type of a data member.
4250    UPPC_DataMemberType,
4251
4252    /// \brief The size of a bit-field.
4253    UPPC_BitFieldWidth,
4254
4255    /// \brief The expression in a static assertion.
4256    UPPC_StaticAssertExpression,
4257
4258    /// \brief The fixed underlying type of an enumeration.
4259    UPPC_FixedUnderlyingType,
4260
4261    /// \brief The enumerator value.
4262    UPPC_EnumeratorValue,
4263
4264    /// \brief A using declaration.
4265    UPPC_UsingDeclaration,
4266
4267    /// \brief A friend declaration.
4268    UPPC_FriendDeclaration,
4269
4270    /// \brief A declaration qualifier.
4271    UPPC_DeclarationQualifier,
4272
4273    /// \brief An initializer.
4274    UPPC_Initializer,
4275
4276    /// \brief A default argument.
4277    UPPC_DefaultArgument,
4278
4279    /// \brief The type of a non-type template parameter.
4280    UPPC_NonTypeTemplateParameterType,
4281
4282    /// \brief The type of an exception.
4283    UPPC_ExceptionType,
4284
4285    /// \brief Partial specialization.
4286    UPPC_PartialSpecialization,
4287
4288    /// \brief Microsoft __if_exists.
4289    UPPC_IfExists,
4290
4291    /// \brief Microsoft __if_not_exists.
4292    UPPC_IfNotExists
4293};
4294
4295  /// \brief Diagnose unexpanded parameter packs.
4296  ///
4297  /// \param Loc The location at which we should emit the diagnostic.
4298  ///
4299  /// \param UPPC The context in which we are diagnosing unexpanded
4300  /// parameter packs.
4301  ///
4302  /// \param Unexpanded the set of unexpanded parameter packs.
4303  void DiagnoseUnexpandedParameterPacks(SourceLocation Loc,
4304                                        UnexpandedParameterPackContext UPPC,
4305                    const SmallVectorImpl<UnexpandedParameterPack> &Unexpanded);
4306
4307  /// \brief If the given type contains an unexpanded parameter pack,
4308  /// diagnose the error.
4309  ///
4310  /// \param Loc The source location where a diagnostc should be emitted.
4311  ///
4312  /// \param T The type that is being checked for unexpanded parameter
4313  /// packs.
4314  ///
4315  /// \returns true if an error occurred, false otherwise.
4316  bool DiagnoseUnexpandedParameterPack(SourceLocation Loc, TypeSourceInfo *T,
4317                                       UnexpandedParameterPackContext UPPC);
4318
4319  /// \brief If the given expression contains an unexpanded parameter
4320  /// pack, diagnose the error.
4321  ///
4322  /// \param E The expression that is being checked for unexpanded
4323  /// parameter packs.
4324  ///
4325  /// \returns true if an error occurred, false otherwise.
4326  bool DiagnoseUnexpandedParameterPack(Expr *E,
4327                       UnexpandedParameterPackContext UPPC = UPPC_Expression);
4328
4329  /// \brief If the given nested-name-specifier contains an unexpanded
4330  /// parameter pack, diagnose the error.
4331  ///
4332  /// \param SS The nested-name-specifier that is being checked for
4333  /// unexpanded parameter packs.
4334  ///
4335  /// \returns true if an error occurred, false otherwise.
4336  bool DiagnoseUnexpandedParameterPack(const CXXScopeSpec &SS,
4337                                       UnexpandedParameterPackContext UPPC);
4338
4339  /// \brief If the given name contains an unexpanded parameter pack,
4340  /// diagnose the error.
4341  ///
4342  /// \param NameInfo The name (with source location information) that
4343  /// is being checked for unexpanded parameter packs.
4344  ///
4345  /// \returns true if an error occurred, false otherwise.
4346  bool DiagnoseUnexpandedParameterPack(const DeclarationNameInfo &NameInfo,
4347                                       UnexpandedParameterPackContext UPPC);
4348
4349  /// \brief If the given template name contains an unexpanded parameter pack,
4350  /// diagnose the error.
4351  ///
4352  /// \param Loc The location of the template name.
4353  ///
4354  /// \param Template The template name that is being checked for unexpanded
4355  /// parameter packs.
4356  ///
4357  /// \returns true if an error occurred, false otherwise.
4358  bool DiagnoseUnexpandedParameterPack(SourceLocation Loc,
4359                                       TemplateName Template,
4360                                       UnexpandedParameterPackContext UPPC);
4361
4362  /// \brief If the given template argument contains an unexpanded parameter
4363  /// pack, diagnose the error.
4364  ///
4365  /// \param Arg The template argument that is being checked for unexpanded
4366  /// parameter packs.
4367  ///
4368  /// \returns true if an error occurred, false otherwise.
4369  bool DiagnoseUnexpandedParameterPack(TemplateArgumentLoc Arg,
4370                                       UnexpandedParameterPackContext UPPC);
4371
4372  /// \brief Collect the set of unexpanded parameter packs within the given
4373  /// template argument.
4374  ///
4375  /// \param Arg The template argument that will be traversed to find
4376  /// unexpanded parameter packs.
4377  void collectUnexpandedParameterPacks(TemplateArgument Arg,
4378                   SmallVectorImpl<UnexpandedParameterPack> &Unexpanded);
4379
4380  /// \brief Collect the set of unexpanded parameter packs within the given
4381  /// template argument.
4382  ///
4383  /// \param Arg The template argument that will be traversed to find
4384  /// unexpanded parameter packs.
4385  void collectUnexpandedParameterPacks(TemplateArgumentLoc Arg,
4386                    SmallVectorImpl<UnexpandedParameterPack> &Unexpanded);
4387
4388  /// \brief Collect the set of unexpanded parameter packs within the given
4389  /// type.
4390  ///
4391  /// \param T The type that will be traversed to find
4392  /// unexpanded parameter packs.
4393  void collectUnexpandedParameterPacks(QualType T,
4394                   SmallVectorImpl<UnexpandedParameterPack> &Unexpanded);
4395
4396  /// \brief Collect the set of unexpanded parameter packs within the given
4397  /// type.
4398  ///
4399  /// \param TL The type that will be traversed to find
4400  /// unexpanded parameter packs.
4401  void collectUnexpandedParameterPacks(TypeLoc TL,
4402                   SmallVectorImpl<UnexpandedParameterPack> &Unexpanded);
4403
4404  /// \brief Collect the set of unexpanded parameter packs within the given
4405  /// nested-name-specifier.
4406  ///
4407  /// \param SS The nested-name-specifier that will be traversed to find
4408  /// unexpanded parameter packs.
4409  void collectUnexpandedParameterPacks(CXXScopeSpec &SS,
4410                         SmallVectorImpl<UnexpandedParameterPack> &Unexpanded);
4411
4412  /// \brief Collect the set of unexpanded parameter packs within the given
4413  /// name.
4414  ///
4415  /// \param NameInfo The name that will be traversed to find
4416  /// unexpanded parameter packs.
4417  void collectUnexpandedParameterPacks(const DeclarationNameInfo &NameInfo,
4418                         SmallVectorImpl<UnexpandedParameterPack> &Unexpanded);
4419
4420  /// \brief Invoked when parsing a template argument followed by an
4421  /// ellipsis, which creates a pack expansion.
4422  ///
4423  /// \param Arg The template argument preceding the ellipsis, which
4424  /// may already be invalid.
4425  ///
4426  /// \param EllipsisLoc The location of the ellipsis.
4427  ParsedTemplateArgument ActOnPackExpansion(const ParsedTemplateArgument &Arg,
4428                                            SourceLocation EllipsisLoc);
4429
4430  /// \brief Invoked when parsing a type followed by an ellipsis, which
4431  /// creates a pack expansion.
4432  ///
4433  /// \param Type The type preceding the ellipsis, which will become
4434  /// the pattern of the pack expansion.
4435  ///
4436  /// \param EllipsisLoc The location of the ellipsis.
4437  TypeResult ActOnPackExpansion(ParsedType Type, SourceLocation EllipsisLoc);
4438
4439  /// \brief Construct a pack expansion type from the pattern of the pack
4440  /// expansion.
4441  TypeSourceInfo *CheckPackExpansion(TypeSourceInfo *Pattern,
4442                                     SourceLocation EllipsisLoc,
4443                                     llvm::Optional<unsigned> NumExpansions);
4444
4445  /// \brief Construct a pack expansion type from the pattern of the pack
4446  /// expansion.
4447  QualType CheckPackExpansion(QualType Pattern,
4448                              SourceRange PatternRange,
4449                              SourceLocation EllipsisLoc,
4450                              llvm::Optional<unsigned> NumExpansions);
4451
4452  /// \brief Invoked when parsing an expression followed by an ellipsis, which
4453  /// creates a pack expansion.
4454  ///
4455  /// \param Pattern The expression preceding the ellipsis, which will become
4456  /// the pattern of the pack expansion.
4457  ///
4458  /// \param EllipsisLoc The location of the ellipsis.
4459  ExprResult ActOnPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc);
4460
4461  /// \brief Invoked when parsing an expression followed by an ellipsis, which
4462  /// creates a pack expansion.
4463  ///
4464  /// \param Pattern The expression preceding the ellipsis, which will become
4465  /// the pattern of the pack expansion.
4466  ///
4467  /// \param EllipsisLoc The location of the ellipsis.
4468  ExprResult CheckPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
4469                                llvm::Optional<unsigned> NumExpansions);
4470
4471  /// \brief Determine whether we could expand a pack expansion with the
4472  /// given set of parameter packs into separate arguments by repeatedly
4473  /// transforming the pattern.
4474  ///
4475  /// \param EllipsisLoc The location of the ellipsis that identifies the
4476  /// pack expansion.
4477  ///
4478  /// \param PatternRange The source range that covers the entire pattern of
4479  /// the pack expansion.
4480  ///
4481  /// \param Unexpanded The set of unexpanded parameter packs within the
4482  /// pattern.
4483  ///
4484  /// \param NumUnexpanded The number of unexpanded parameter packs in
4485  /// \p Unexpanded.
4486  ///
4487  /// \param ShouldExpand Will be set to \c true if the transformer should
4488  /// expand the corresponding pack expansions into separate arguments. When
4489  /// set, \c NumExpansions must also be set.
4490  ///
4491  /// \param RetainExpansion Whether the caller should add an unexpanded
4492  /// pack expansion after all of the expanded arguments. This is used
4493  /// when extending explicitly-specified template argument packs per
4494  /// C++0x [temp.arg.explicit]p9.
4495  ///
4496  /// \param NumExpansions The number of separate arguments that will be in
4497  /// the expanded form of the corresponding pack expansion. This is both an
4498  /// input and an output parameter, which can be set by the caller if the
4499  /// number of expansions is known a priori (e.g., due to a prior substitution)
4500  /// and will be set by the callee when the number of expansions is known.
4501  /// The callee must set this value when \c ShouldExpand is \c true; it may
4502  /// set this value in other cases.
4503  ///
4504  /// \returns true if an error occurred (e.g., because the parameter packs
4505  /// are to be instantiated with arguments of different lengths), false
4506  /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
4507  /// must be set.
4508  bool CheckParameterPacksForExpansion(SourceLocation EllipsisLoc,
4509                                       SourceRange PatternRange,
4510                             llvm::ArrayRef<UnexpandedParameterPack> Unexpanded,
4511                             const MultiLevelTemplateArgumentList &TemplateArgs,
4512                                       bool &ShouldExpand,
4513                                       bool &RetainExpansion,
4514                                       llvm::Optional<unsigned> &NumExpansions);
4515
4516  /// \brief Determine the number of arguments in the given pack expansion
4517  /// type.
4518  ///
4519  /// This routine already assumes that the pack expansion type can be
4520  /// expanded and that the number of arguments in the expansion is
4521  /// consistent across all of the unexpanded parameter packs in its pattern.
4522  unsigned getNumArgumentsInExpansion(QualType T,
4523                            const MultiLevelTemplateArgumentList &TemplateArgs);
4524
4525  /// \brief Determine whether the given declarator contains any unexpanded
4526  /// parameter packs.
4527  ///
4528  /// This routine is used by the parser to disambiguate function declarators
4529  /// with an ellipsis prior to the ')', e.g.,
4530  ///
4531  /// \code
4532  ///   void f(T...);
4533  /// \endcode
4534  ///
4535  /// To determine whether we have an (unnamed) function parameter pack or
4536  /// a variadic function.
4537  ///
4538  /// \returns true if the declarator contains any unexpanded parameter packs,
4539  /// false otherwise.
4540  bool containsUnexpandedParameterPacks(Declarator &D);
4541
4542  //===--------------------------------------------------------------------===//
4543  // C++ Template Argument Deduction (C++ [temp.deduct])
4544  //===--------------------------------------------------------------------===//
4545
4546  /// \brief Describes the result of template argument deduction.
4547  ///
4548  /// The TemplateDeductionResult enumeration describes the result of
4549  /// template argument deduction, as returned from
4550  /// DeduceTemplateArguments(). The separate TemplateDeductionInfo
4551  /// structure provides additional information about the results of
4552  /// template argument deduction, e.g., the deduced template argument
4553  /// list (if successful) or the specific template parameters or
4554  /// deduced arguments that were involved in the failure.
4555  enum TemplateDeductionResult {
4556    /// \brief Template argument deduction was successful.
4557    TDK_Success = 0,
4558    /// \brief Template argument deduction exceeded the maximum template
4559    /// instantiation depth (which has already been diagnosed).
4560    TDK_InstantiationDepth,
4561    /// \brief Template argument deduction did not deduce a value
4562    /// for every template parameter.
4563    TDK_Incomplete,
4564    /// \brief Template argument deduction produced inconsistent
4565    /// deduced values for the given template parameter.
4566    TDK_Inconsistent,
4567    /// \brief Template argument deduction failed due to inconsistent
4568    /// cv-qualifiers on a template parameter type that would
4569    /// otherwise be deduced, e.g., we tried to deduce T in "const T"
4570    /// but were given a non-const "X".
4571    TDK_Underqualified,
4572    /// \brief Substitution of the deduced template argument values
4573    /// resulted in an error.
4574    TDK_SubstitutionFailure,
4575    /// \brief Substitution of the deduced template argument values
4576    /// into a non-deduced context produced a type or value that
4577    /// produces a type that does not match the original template
4578    /// arguments provided.
4579    TDK_NonDeducedMismatch,
4580    /// \brief When performing template argument deduction for a function
4581    /// template, there were too many call arguments.
4582    TDK_TooManyArguments,
4583    /// \brief When performing template argument deduction for a function
4584    /// template, there were too few call arguments.
4585    TDK_TooFewArguments,
4586    /// \brief The explicitly-specified template arguments were not valid
4587    /// template arguments for the given template.
4588    TDK_InvalidExplicitArguments,
4589    /// \brief The arguments included an overloaded function name that could
4590    /// not be resolved to a suitable function.
4591    TDK_FailedOverloadResolution
4592  };
4593
4594  TemplateDeductionResult
4595  DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial,
4596                          const TemplateArgumentList &TemplateArgs,
4597                          sema::TemplateDeductionInfo &Info);
4598
4599  TemplateDeductionResult
4600  SubstituteExplicitTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
4601                              TemplateArgumentListInfo &ExplicitTemplateArgs,
4602                      SmallVectorImpl<DeducedTemplateArgument> &Deduced,
4603                                 SmallVectorImpl<QualType> &ParamTypes,
4604                                      QualType *FunctionType,
4605                                      sema::TemplateDeductionInfo &Info);
4606
4607  /// brief A function argument from which we performed template argument
4608  // deduction for a call.
4609  struct OriginalCallArg {
4610    OriginalCallArg(QualType OriginalParamType,
4611                    unsigned ArgIdx,
4612                    QualType OriginalArgType)
4613      : OriginalParamType(OriginalParamType), ArgIdx(ArgIdx),
4614        OriginalArgType(OriginalArgType) { }
4615
4616    QualType OriginalParamType;
4617    unsigned ArgIdx;
4618    QualType OriginalArgType;
4619  };
4620
4621  TemplateDeductionResult
4622  FinishTemplateArgumentDeduction(FunctionTemplateDecl *FunctionTemplate,
4623                      SmallVectorImpl<DeducedTemplateArgument> &Deduced,
4624                                  unsigned NumExplicitlySpecified,
4625                                  FunctionDecl *&Specialization,
4626                                  sema::TemplateDeductionInfo &Info,
4627           SmallVectorImpl<OriginalCallArg> const *OriginalCallArgs = 0);
4628
4629  TemplateDeductionResult
4630  DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
4631                          TemplateArgumentListInfo *ExplicitTemplateArgs,
4632                          Expr **Args, unsigned NumArgs,
4633                          FunctionDecl *&Specialization,
4634                          sema::TemplateDeductionInfo &Info);
4635
4636  TemplateDeductionResult
4637  DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
4638                          TemplateArgumentListInfo *ExplicitTemplateArgs,
4639                          QualType ArgFunctionType,
4640                          FunctionDecl *&Specialization,
4641                          sema::TemplateDeductionInfo &Info);
4642
4643  TemplateDeductionResult
4644  DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
4645                          QualType ToType,
4646                          CXXConversionDecl *&Specialization,
4647                          sema::TemplateDeductionInfo &Info);
4648
4649  TemplateDeductionResult
4650  DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
4651                          TemplateArgumentListInfo *ExplicitTemplateArgs,
4652                          FunctionDecl *&Specialization,
4653                          sema::TemplateDeductionInfo &Info);
4654
4655  /// \brief Result type of DeduceAutoType.
4656  enum DeduceAutoResult {
4657    DAR_Succeeded,
4658    DAR_Failed,
4659    DAR_FailedAlreadyDiagnosed
4660  };
4661
4662  DeduceAutoResult DeduceAutoType(TypeSourceInfo *AutoType, Expr *&Initializer,
4663                                  TypeSourceInfo *&Result);
4664  void DiagnoseAutoDeductionFailure(VarDecl *VDecl, Expr *Init);
4665
4666  FunctionTemplateDecl *getMoreSpecializedTemplate(FunctionTemplateDecl *FT1,
4667                                                   FunctionTemplateDecl *FT2,
4668                                                   SourceLocation Loc,
4669                                           TemplatePartialOrderingContext TPOC,
4670                                                   unsigned NumCallArguments);
4671  UnresolvedSetIterator getMostSpecialized(UnresolvedSetIterator SBegin,
4672                                           UnresolvedSetIterator SEnd,
4673                                           TemplatePartialOrderingContext TPOC,
4674                                           unsigned NumCallArguments,
4675                                           SourceLocation Loc,
4676                                           const PartialDiagnostic &NoneDiag,
4677                                           const PartialDiagnostic &AmbigDiag,
4678                                        const PartialDiagnostic &CandidateDiag,
4679                                        bool Complain = true,
4680                                        QualType TargetType = QualType());
4681
4682  ClassTemplatePartialSpecializationDecl *
4683  getMoreSpecializedPartialSpecialization(
4684                                  ClassTemplatePartialSpecializationDecl *PS1,
4685                                  ClassTemplatePartialSpecializationDecl *PS2,
4686                                  SourceLocation Loc);
4687
4688  void MarkUsedTemplateParameters(const TemplateArgumentList &TemplateArgs,
4689                                  bool OnlyDeduced,
4690                                  unsigned Depth,
4691                                  SmallVectorImpl<bool> &Used);
4692  void MarkDeducedTemplateParameters(FunctionTemplateDecl *FunctionTemplate,
4693                                     SmallVectorImpl<bool> &Deduced) {
4694    return MarkDeducedTemplateParameters(Context, FunctionTemplate, Deduced);
4695  }
4696  static void MarkDeducedTemplateParameters(ASTContext &Ctx,
4697                                         FunctionTemplateDecl *FunctionTemplate,
4698                                         SmallVectorImpl<bool> &Deduced);
4699
4700  //===--------------------------------------------------------------------===//
4701  // C++ Template Instantiation
4702  //
4703
4704  MultiLevelTemplateArgumentList getTemplateInstantiationArgs(NamedDecl *D,
4705                                     const TemplateArgumentList *Innermost = 0,
4706                                                bool RelativeToPrimary = false,
4707                                               const FunctionDecl *Pattern = 0);
4708
4709  /// \brief A template instantiation that is currently in progress.
4710  struct ActiveTemplateInstantiation {
4711    /// \brief The kind of template instantiation we are performing
4712    enum InstantiationKind {
4713      /// We are instantiating a template declaration. The entity is
4714      /// the declaration we're instantiating (e.g., a CXXRecordDecl).
4715      TemplateInstantiation,
4716
4717      /// We are instantiating a default argument for a template
4718      /// parameter. The Entity is the template, and
4719      /// TemplateArgs/NumTemplateArguments provides the template
4720      /// arguments as specified.
4721      /// FIXME: Use a TemplateArgumentList
4722      DefaultTemplateArgumentInstantiation,
4723
4724      /// We are instantiating a default argument for a function.
4725      /// The Entity is the ParmVarDecl, and TemplateArgs/NumTemplateArgs
4726      /// provides the template arguments as specified.
4727      DefaultFunctionArgumentInstantiation,
4728
4729      /// We are substituting explicit template arguments provided for
4730      /// a function template. The entity is a FunctionTemplateDecl.
4731      ExplicitTemplateArgumentSubstitution,
4732
4733      /// We are substituting template argument determined as part of
4734      /// template argument deduction for either a class template
4735      /// partial specialization or a function template. The
4736      /// Entity is either a ClassTemplatePartialSpecializationDecl or
4737      /// a FunctionTemplateDecl.
4738      DeducedTemplateArgumentSubstitution,
4739
4740      /// We are substituting prior template arguments into a new
4741      /// template parameter. The template parameter itself is either a
4742      /// NonTypeTemplateParmDecl or a TemplateTemplateParmDecl.
4743      PriorTemplateArgumentSubstitution,
4744
4745      /// We are checking the validity of a default template argument that
4746      /// has been used when naming a template-id.
4747      DefaultTemplateArgumentChecking
4748    } Kind;
4749
4750    /// \brief The point of instantiation within the source code.
4751    SourceLocation PointOfInstantiation;
4752
4753    /// \brief The template (or partial specialization) in which we are
4754    /// performing the instantiation, for substitutions of prior template
4755    /// arguments.
4756    NamedDecl *Template;
4757
4758    /// \brief The entity that is being instantiated.
4759    uintptr_t Entity;
4760
4761    /// \brief The list of template arguments we are substituting, if they
4762    /// are not part of the entity.
4763    const TemplateArgument *TemplateArgs;
4764
4765    /// \brief The number of template arguments in TemplateArgs.
4766    unsigned NumTemplateArgs;
4767
4768    /// \brief The template deduction info object associated with the
4769    /// substitution or checking of explicit or deduced template arguments.
4770    sema::TemplateDeductionInfo *DeductionInfo;
4771
4772    /// \brief The source range that covers the construct that cause
4773    /// the instantiation, e.g., the template-id that causes a class
4774    /// template instantiation.
4775    SourceRange InstantiationRange;
4776
4777    ActiveTemplateInstantiation()
4778      : Kind(TemplateInstantiation), Template(0), Entity(0), TemplateArgs(0),
4779        NumTemplateArgs(0), DeductionInfo(0) {}
4780
4781    /// \brief Determines whether this template is an actual instantiation
4782    /// that should be counted toward the maximum instantiation depth.
4783    bool isInstantiationRecord() const;
4784
4785    friend bool operator==(const ActiveTemplateInstantiation &X,
4786                           const ActiveTemplateInstantiation &Y) {
4787      if (X.Kind != Y.Kind)
4788        return false;
4789
4790      if (X.Entity != Y.Entity)
4791        return false;
4792
4793      switch (X.Kind) {
4794      case TemplateInstantiation:
4795        return true;
4796
4797      case PriorTemplateArgumentSubstitution:
4798      case DefaultTemplateArgumentChecking:
4799        if (X.Template != Y.Template)
4800          return false;
4801
4802        // Fall through
4803
4804      case DefaultTemplateArgumentInstantiation:
4805      case ExplicitTemplateArgumentSubstitution:
4806      case DeducedTemplateArgumentSubstitution:
4807      case DefaultFunctionArgumentInstantiation:
4808        return X.TemplateArgs == Y.TemplateArgs;
4809
4810      }
4811
4812      llvm_unreachable("Invalid InstantiationKind!");
4813    }
4814
4815    friend bool operator!=(const ActiveTemplateInstantiation &X,
4816                           const ActiveTemplateInstantiation &Y) {
4817      return !(X == Y);
4818    }
4819  };
4820
4821  /// \brief List of active template instantiations.
4822  ///
4823  /// This vector is treated as a stack. As one template instantiation
4824  /// requires another template instantiation, additional
4825  /// instantiations are pushed onto the stack up to a
4826  /// user-configurable limit LangOptions::InstantiationDepth.
4827  SmallVector<ActiveTemplateInstantiation, 16>
4828    ActiveTemplateInstantiations;
4829
4830  /// \brief Whether we are in a SFINAE context that is not associated with
4831  /// template instantiation.
4832  ///
4833  /// This is used when setting up a SFINAE trap (\c see SFINAETrap) outside
4834  /// of a template instantiation or template argument deduction.
4835  bool InNonInstantiationSFINAEContext;
4836
4837  /// \brief The number of ActiveTemplateInstantiation entries in
4838  /// \c ActiveTemplateInstantiations that are not actual instantiations and,
4839  /// therefore, should not be counted as part of the instantiation depth.
4840  unsigned NonInstantiationEntries;
4841
4842  /// \brief The last template from which a template instantiation
4843  /// error or warning was produced.
4844  ///
4845  /// This value is used to suppress printing of redundant template
4846  /// instantiation backtraces when there are multiple errors in the
4847  /// same instantiation. FIXME: Does this belong in Sema? It's tough
4848  /// to implement it anywhere else.
4849  ActiveTemplateInstantiation LastTemplateInstantiationErrorContext;
4850
4851  /// \brief The current index into pack expansion arguments that will be
4852  /// used for substitution of parameter packs.
4853  ///
4854  /// The pack expansion index will be -1 to indicate that parameter packs
4855  /// should be instantiated as themselves. Otherwise, the index specifies
4856  /// which argument within the parameter pack will be used for substitution.
4857  int ArgumentPackSubstitutionIndex;
4858
4859  /// \brief RAII object used to change the argument pack substitution index
4860  /// within a \c Sema object.
4861  ///
4862  /// See \c ArgumentPackSubstitutionIndex for more information.
4863  class ArgumentPackSubstitutionIndexRAII {
4864    Sema &Self;
4865    int OldSubstitutionIndex;
4866
4867  public:
4868    ArgumentPackSubstitutionIndexRAII(Sema &Self, int NewSubstitutionIndex)
4869      : Self(Self), OldSubstitutionIndex(Self.ArgumentPackSubstitutionIndex) {
4870      Self.ArgumentPackSubstitutionIndex = NewSubstitutionIndex;
4871    }
4872
4873    ~ArgumentPackSubstitutionIndexRAII() {
4874      Self.ArgumentPackSubstitutionIndex = OldSubstitutionIndex;
4875    }
4876  };
4877
4878  friend class ArgumentPackSubstitutionRAII;
4879
4880  /// \brief The stack of calls expression undergoing template instantiation.
4881  ///
4882  /// The top of this stack is used by a fixit instantiating unresolved
4883  /// function calls to fix the AST to match the textual change it prints.
4884  SmallVector<CallExpr *, 8> CallsUndergoingInstantiation;
4885
4886  /// \brief For each declaration that involved template argument deduction, the
4887  /// set of diagnostics that were suppressed during that template argument
4888  /// deduction.
4889  ///
4890  /// FIXME: Serialize this structure to the AST file.
4891  llvm::DenseMap<Decl *, SmallVector<PartialDiagnosticAt, 1> >
4892    SuppressedDiagnostics;
4893
4894  /// \brief A stack object to be created when performing template
4895  /// instantiation.
4896  ///
4897  /// Construction of an object of type \c InstantiatingTemplate
4898  /// pushes the current instantiation onto the stack of active
4899  /// instantiations. If the size of this stack exceeds the maximum
4900  /// number of recursive template instantiations, construction
4901  /// produces an error and evaluates true.
4902  ///
4903  /// Destruction of this object will pop the named instantiation off
4904  /// the stack.
4905  struct InstantiatingTemplate {
4906    /// \brief Note that we are instantiating a class template,
4907    /// function template, or a member thereof.
4908    InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
4909                          Decl *Entity,
4910                          SourceRange InstantiationRange = SourceRange());
4911
4912    /// \brief Note that we are instantiating a default argument in a
4913    /// template-id.
4914    InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
4915                          TemplateDecl *Template,
4916                          const TemplateArgument *TemplateArgs,
4917                          unsigned NumTemplateArgs,
4918                          SourceRange InstantiationRange = SourceRange());
4919
4920    /// \brief Note that we are instantiating a default argument in a
4921    /// template-id.
4922    InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
4923                          FunctionTemplateDecl *FunctionTemplate,
4924                          const TemplateArgument *TemplateArgs,
4925                          unsigned NumTemplateArgs,
4926                          ActiveTemplateInstantiation::InstantiationKind Kind,
4927                          sema::TemplateDeductionInfo &DeductionInfo,
4928                          SourceRange InstantiationRange = SourceRange());
4929
4930    /// \brief Note that we are instantiating as part of template
4931    /// argument deduction for a class template partial
4932    /// specialization.
4933    InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
4934                          ClassTemplatePartialSpecializationDecl *PartialSpec,
4935                          const TemplateArgument *TemplateArgs,
4936                          unsigned NumTemplateArgs,
4937                          sema::TemplateDeductionInfo &DeductionInfo,
4938                          SourceRange InstantiationRange = SourceRange());
4939
4940    InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
4941                          ParmVarDecl *Param,
4942                          const TemplateArgument *TemplateArgs,
4943                          unsigned NumTemplateArgs,
4944                          SourceRange InstantiationRange = SourceRange());
4945
4946    /// \brief Note that we are substituting prior template arguments into a
4947    /// non-type or template template parameter.
4948    InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
4949                          NamedDecl *Template,
4950                          NonTypeTemplateParmDecl *Param,
4951                          const TemplateArgument *TemplateArgs,
4952                          unsigned NumTemplateArgs,
4953                          SourceRange InstantiationRange);
4954
4955    InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
4956                          NamedDecl *Template,
4957                          TemplateTemplateParmDecl *Param,
4958                          const TemplateArgument *TemplateArgs,
4959                          unsigned NumTemplateArgs,
4960                          SourceRange InstantiationRange);
4961
4962    /// \brief Note that we are checking the default template argument
4963    /// against the template parameter for a given template-id.
4964    InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
4965                          TemplateDecl *Template,
4966                          NamedDecl *Param,
4967                          const TemplateArgument *TemplateArgs,
4968                          unsigned NumTemplateArgs,
4969                          SourceRange InstantiationRange);
4970
4971
4972    /// \brief Note that we have finished instantiating this template.
4973    void Clear();
4974
4975    ~InstantiatingTemplate() { Clear(); }
4976
4977    /// \brief Determines whether we have exceeded the maximum
4978    /// recursive template instantiations.
4979    operator bool() const { return Invalid; }
4980
4981  private:
4982    Sema &SemaRef;
4983    bool Invalid;
4984    bool SavedInNonInstantiationSFINAEContext;
4985    bool CheckInstantiationDepth(SourceLocation PointOfInstantiation,
4986                                 SourceRange InstantiationRange);
4987
4988    InstantiatingTemplate(const InstantiatingTemplate&); // not implemented
4989
4990    InstantiatingTemplate&
4991    operator=(const InstantiatingTemplate&); // not implemented
4992  };
4993
4994  void PrintInstantiationStack();
4995
4996  /// \brief Determines whether we are currently in a context where
4997  /// template argument substitution failures are not considered
4998  /// errors.
4999  ///
5000  /// \returns An empty \c llvm::Optional if we're not in a SFINAE context.
5001  /// Otherwise, contains a pointer that, if non-NULL, contains the nearest
5002  /// template-deduction context object, which can be used to capture
5003  /// diagnostics that will be suppressed.
5004  llvm::Optional<sema::TemplateDeductionInfo *> isSFINAEContext() const;
5005
5006  /// \brief RAII class used to determine whether SFINAE has
5007  /// trapped any errors that occur during template argument
5008  /// deduction.`
5009  class SFINAETrap {
5010    Sema &SemaRef;
5011    unsigned PrevSFINAEErrors;
5012    bool PrevInNonInstantiationSFINAEContext;
5013    bool PrevAccessCheckingSFINAE;
5014
5015  public:
5016    explicit SFINAETrap(Sema &SemaRef, bool AccessCheckingSFINAE = false)
5017      : SemaRef(SemaRef), PrevSFINAEErrors(SemaRef.NumSFINAEErrors),
5018        PrevInNonInstantiationSFINAEContext(
5019                                      SemaRef.InNonInstantiationSFINAEContext),
5020        PrevAccessCheckingSFINAE(SemaRef.AccessCheckingSFINAE)
5021    {
5022      if (!SemaRef.isSFINAEContext())
5023        SemaRef.InNonInstantiationSFINAEContext = true;
5024      SemaRef.AccessCheckingSFINAE = AccessCheckingSFINAE;
5025    }
5026
5027    ~SFINAETrap() {
5028      SemaRef.NumSFINAEErrors = PrevSFINAEErrors;
5029      SemaRef.InNonInstantiationSFINAEContext
5030        = PrevInNonInstantiationSFINAEContext;
5031      SemaRef.AccessCheckingSFINAE = PrevAccessCheckingSFINAE;
5032    }
5033
5034    /// \brief Determine whether any SFINAE errors have been trapped.
5035    bool hasErrorOccurred() const {
5036      return SemaRef.NumSFINAEErrors > PrevSFINAEErrors;
5037    }
5038  };
5039
5040  /// \brief The current instantiation scope used to store local
5041  /// variables.
5042  LocalInstantiationScope *CurrentInstantiationScope;
5043
5044  /// \brief The number of typos corrected by CorrectTypo.
5045  unsigned TyposCorrected;
5046
5047  typedef llvm::DenseMap<IdentifierInfo *, TypoCorrection>
5048    UnqualifiedTyposCorrectedMap;
5049
5050  /// \brief A cache containing the results of typo correction for unqualified
5051  /// name lookup.
5052  ///
5053  /// The string is the string that we corrected to (which may be empty, if
5054  /// there was no correction), while the boolean will be true when the
5055  /// string represents a keyword.
5056  UnqualifiedTyposCorrectedMap UnqualifiedTyposCorrected;
5057
5058  /// \brief Worker object for performing CFG-based warnings.
5059  sema::AnalysisBasedWarnings AnalysisWarnings;
5060
5061  /// \brief An entity for which implicit template instantiation is required.
5062  ///
5063  /// The source location associated with the declaration is the first place in
5064  /// the source code where the declaration was "used". It is not necessarily
5065  /// the point of instantiation (which will be either before or after the
5066  /// namespace-scope declaration that triggered this implicit instantiation),
5067  /// However, it is the location that diagnostics should generally refer to,
5068  /// because users will need to know what code triggered the instantiation.
5069  typedef std::pair<ValueDecl *, SourceLocation> PendingImplicitInstantiation;
5070
5071  /// \brief The queue of implicit template instantiations that are required
5072  /// but have not yet been performed.
5073  std::deque<PendingImplicitInstantiation> PendingInstantiations;
5074
5075  /// \brief The queue of implicit template instantiations that are required
5076  /// and must be performed within the current local scope.
5077  ///
5078  /// This queue is only used for member functions of local classes in
5079  /// templates, which must be instantiated in the same scope as their
5080  /// enclosing function, so that they can reference function-local
5081  /// types, static variables, enumerators, etc.
5082  std::deque<PendingImplicitInstantiation> PendingLocalImplicitInstantiations;
5083
5084  void PerformPendingInstantiations(bool LocalOnly = false);
5085
5086  TypeSourceInfo *SubstType(TypeSourceInfo *T,
5087                            const MultiLevelTemplateArgumentList &TemplateArgs,
5088                            SourceLocation Loc, DeclarationName Entity);
5089
5090  QualType SubstType(QualType T,
5091                     const MultiLevelTemplateArgumentList &TemplateArgs,
5092                     SourceLocation Loc, DeclarationName Entity);
5093
5094  TypeSourceInfo *SubstType(TypeLoc TL,
5095                            const MultiLevelTemplateArgumentList &TemplateArgs,
5096                            SourceLocation Loc, DeclarationName Entity);
5097
5098  TypeSourceInfo *SubstFunctionDeclType(TypeSourceInfo *T,
5099                            const MultiLevelTemplateArgumentList &TemplateArgs,
5100                                        SourceLocation Loc,
5101                                        DeclarationName Entity);
5102  ParmVarDecl *SubstParmVarDecl(ParmVarDecl *D,
5103                            const MultiLevelTemplateArgumentList &TemplateArgs,
5104                                int indexAdjustment,
5105                                llvm::Optional<unsigned> NumExpansions,
5106                                bool ExpectParameterPack);
5107  bool SubstParmTypes(SourceLocation Loc,
5108                      ParmVarDecl **Params, unsigned NumParams,
5109                      const MultiLevelTemplateArgumentList &TemplateArgs,
5110                      SmallVectorImpl<QualType> &ParamTypes,
5111                      SmallVectorImpl<ParmVarDecl *> *OutParams = 0);
5112  ExprResult SubstExpr(Expr *E,
5113                       const MultiLevelTemplateArgumentList &TemplateArgs);
5114
5115  /// \brief Substitute the given template arguments into a list of
5116  /// expressions, expanding pack expansions if required.
5117  ///
5118  /// \param Exprs The list of expressions to substitute into.
5119  ///
5120  /// \param NumExprs The number of expressions in \p Exprs.
5121  ///
5122  /// \param IsCall Whether this is some form of call, in which case
5123  /// default arguments will be dropped.
5124  ///
5125  /// \param TemplateArgs The set of template arguments to substitute.
5126  ///
5127  /// \param Outputs Will receive all of the substituted arguments.
5128  ///
5129  /// \returns true if an error occurred, false otherwise.
5130  bool SubstExprs(Expr **Exprs, unsigned NumExprs, bool IsCall,
5131                  const MultiLevelTemplateArgumentList &TemplateArgs,
5132                  SmallVectorImpl<Expr *> &Outputs);
5133
5134  StmtResult SubstStmt(Stmt *S,
5135                       const MultiLevelTemplateArgumentList &TemplateArgs);
5136
5137  Decl *SubstDecl(Decl *D, DeclContext *Owner,
5138                  const MultiLevelTemplateArgumentList &TemplateArgs);
5139
5140  bool
5141  SubstBaseSpecifiers(CXXRecordDecl *Instantiation,
5142                      CXXRecordDecl *Pattern,
5143                      const MultiLevelTemplateArgumentList &TemplateArgs);
5144
5145  bool
5146  InstantiateClass(SourceLocation PointOfInstantiation,
5147                   CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern,
5148                   const MultiLevelTemplateArgumentList &TemplateArgs,
5149                   TemplateSpecializationKind TSK,
5150                   bool Complain = true);
5151
5152  struct LateInstantiatedAttribute {
5153    const Attr *TmplAttr;
5154    LocalInstantiationScope *Scope;
5155    Decl *NewDecl;
5156
5157    LateInstantiatedAttribute(const Attr *A, LocalInstantiationScope *S,
5158                              Decl *D)
5159      : TmplAttr(A), Scope(S), NewDecl(D)
5160    { }
5161  };
5162  typedef SmallVector<LateInstantiatedAttribute, 16> LateInstantiatedAttrVec;
5163
5164  void InstantiateAttrs(const MultiLevelTemplateArgumentList &TemplateArgs,
5165                        const Decl *Pattern, Decl *Inst,
5166                        LateInstantiatedAttrVec *LateAttrs = 0,
5167                        LocalInstantiationScope *OuterMostScope = 0);
5168
5169  bool
5170  InstantiateClassTemplateSpecialization(SourceLocation PointOfInstantiation,
5171                           ClassTemplateSpecializationDecl *ClassTemplateSpec,
5172                           TemplateSpecializationKind TSK,
5173                           bool Complain = true);
5174
5175  void InstantiateClassMembers(SourceLocation PointOfInstantiation,
5176                               CXXRecordDecl *Instantiation,
5177                            const MultiLevelTemplateArgumentList &TemplateArgs,
5178                               TemplateSpecializationKind TSK);
5179
5180  void InstantiateClassTemplateSpecializationMembers(
5181                                          SourceLocation PointOfInstantiation,
5182                           ClassTemplateSpecializationDecl *ClassTemplateSpec,
5183                                                TemplateSpecializationKind TSK);
5184
5185  NestedNameSpecifierLoc
5186  SubstNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
5187                           const MultiLevelTemplateArgumentList &TemplateArgs);
5188
5189  DeclarationNameInfo
5190  SubstDeclarationNameInfo(const DeclarationNameInfo &NameInfo,
5191                           const MultiLevelTemplateArgumentList &TemplateArgs);
5192  TemplateName
5193  SubstTemplateName(NestedNameSpecifierLoc QualifierLoc, TemplateName Name,
5194                    SourceLocation Loc,
5195                    const MultiLevelTemplateArgumentList &TemplateArgs);
5196  bool Subst(const TemplateArgumentLoc *Args, unsigned NumArgs,
5197             TemplateArgumentListInfo &Result,
5198             const MultiLevelTemplateArgumentList &TemplateArgs);
5199
5200  void InstantiateFunctionDefinition(SourceLocation PointOfInstantiation,
5201                                     FunctionDecl *Function,
5202                                     bool Recursive = false,
5203                                     bool DefinitionRequired = false);
5204  void InstantiateStaticDataMemberDefinition(
5205                                     SourceLocation PointOfInstantiation,
5206                                     VarDecl *Var,
5207                                     bool Recursive = false,
5208                                     bool DefinitionRequired = false);
5209
5210  void InstantiateMemInitializers(CXXConstructorDecl *New,
5211                                  const CXXConstructorDecl *Tmpl,
5212                            const MultiLevelTemplateArgumentList &TemplateArgs);
5213  bool InstantiateInitializer(Expr *Init,
5214                            const MultiLevelTemplateArgumentList &TemplateArgs,
5215                              SourceLocation &LParenLoc,
5216                              ASTOwningVector<Expr*> &NewArgs,
5217                              SourceLocation &RParenLoc);
5218
5219  NamedDecl *FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D,
5220                          const MultiLevelTemplateArgumentList &TemplateArgs);
5221  DeclContext *FindInstantiatedContext(SourceLocation Loc, DeclContext *DC,
5222                          const MultiLevelTemplateArgumentList &TemplateArgs);
5223
5224  // Objective-C declarations.
5225  enum ObjCContainerKind {
5226    OCK_None = -1,
5227    OCK_Interface = 0,
5228    OCK_Protocol,
5229    OCK_Category,
5230    OCK_ClassExtension,
5231    OCK_Implementation,
5232    OCK_CategoryImplementation
5233  };
5234  ObjCContainerKind getObjCContainerKind() const;
5235
5236  Decl *ActOnStartClassInterface(SourceLocation AtInterfaceLoc,
5237                                 IdentifierInfo *ClassName,
5238                                 SourceLocation ClassLoc,
5239                                 IdentifierInfo *SuperName,
5240                                 SourceLocation SuperLoc,
5241                                 Decl * const *ProtoRefs,
5242                                 unsigned NumProtoRefs,
5243                                 const SourceLocation *ProtoLocs,
5244                                 SourceLocation EndProtoLoc,
5245                                 AttributeList *AttrList);
5246
5247  Decl *ActOnCompatiblityAlias(
5248                    SourceLocation AtCompatibilityAliasLoc,
5249                    IdentifierInfo *AliasName,  SourceLocation AliasLocation,
5250                    IdentifierInfo *ClassName, SourceLocation ClassLocation);
5251
5252  bool CheckForwardProtocolDeclarationForCircularDependency(
5253    IdentifierInfo *PName,
5254    SourceLocation &PLoc, SourceLocation PrevLoc,
5255    const ObjCList<ObjCProtocolDecl> &PList);
5256
5257  Decl *ActOnStartProtocolInterface(
5258                    SourceLocation AtProtoInterfaceLoc,
5259                    IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc,
5260                    Decl * const *ProtoRefNames, unsigned NumProtoRefs,
5261                    const SourceLocation *ProtoLocs,
5262                    SourceLocation EndProtoLoc,
5263                    AttributeList *AttrList);
5264
5265  Decl *ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc,
5266                                    IdentifierInfo *ClassName,
5267                                    SourceLocation ClassLoc,
5268                                    IdentifierInfo *CategoryName,
5269                                    SourceLocation CategoryLoc,
5270                                    Decl * const *ProtoRefs,
5271                                    unsigned NumProtoRefs,
5272                                    const SourceLocation *ProtoLocs,
5273                                    SourceLocation EndProtoLoc);
5274
5275  Decl *ActOnStartClassImplementation(
5276                    SourceLocation AtClassImplLoc,
5277                    IdentifierInfo *ClassName, SourceLocation ClassLoc,
5278                    IdentifierInfo *SuperClassname,
5279                    SourceLocation SuperClassLoc);
5280
5281  Decl *ActOnStartCategoryImplementation(SourceLocation AtCatImplLoc,
5282                                         IdentifierInfo *ClassName,
5283                                         SourceLocation ClassLoc,
5284                                         IdentifierInfo *CatName,
5285                                         SourceLocation CatLoc);
5286
5287  DeclGroupPtrTy ActOnForwardClassDeclaration(SourceLocation Loc,
5288                                     IdentifierInfo **IdentList,
5289                                     SourceLocation *IdentLocs,
5290                                     unsigned NumElts);
5291
5292  DeclGroupPtrTy ActOnForwardProtocolDeclaration(SourceLocation AtProtoclLoc,
5293                                        const IdentifierLocPair *IdentList,
5294                                        unsigned NumElts,
5295                                        AttributeList *attrList);
5296
5297  void FindProtocolDeclaration(bool WarnOnDeclarations,
5298                               const IdentifierLocPair *ProtocolId,
5299                               unsigned NumProtocols,
5300                               SmallVectorImpl<Decl *> &Protocols);
5301
5302  /// Ensure attributes are consistent with type.
5303  /// \param [in, out] Attributes The attributes to check; they will
5304  /// be modified to be consistent with \arg PropertyTy.
5305  void CheckObjCPropertyAttributes(Decl *PropertyPtrTy,
5306                                   SourceLocation Loc,
5307                                   unsigned &Attributes);
5308
5309  /// Process the specified property declaration and create decls for the
5310  /// setters and getters as needed.
5311  /// \param property The property declaration being processed
5312  /// \param DC The semantic container for the property
5313  /// \param redeclaredProperty Declaration for property if redeclared
5314  ///        in class extension.
5315  /// \param lexicalDC Container for redeclaredProperty.
5316  void ProcessPropertyDecl(ObjCPropertyDecl *property,
5317                           ObjCContainerDecl *DC,
5318                           ObjCPropertyDecl *redeclaredProperty = 0,
5319                           ObjCContainerDecl *lexicalDC = 0);
5320
5321  void DiagnosePropertyMismatch(ObjCPropertyDecl *Property,
5322                                ObjCPropertyDecl *SuperProperty,
5323                                const IdentifierInfo *Name);
5324  void ComparePropertiesInBaseAndSuper(ObjCInterfaceDecl *IDecl);
5325
5326  void CompareMethodParamsInBaseAndSuper(Decl *IDecl,
5327                                         ObjCMethodDecl *MethodDecl,
5328                                         bool IsInstance);
5329
5330  void CompareProperties(Decl *CDecl, Decl *MergeProtocols);
5331
5332  void DiagnoseClassExtensionDupMethods(ObjCCategoryDecl *CAT,
5333                                        ObjCInterfaceDecl *ID);
5334
5335  void MatchOneProtocolPropertiesInClass(Decl *CDecl,
5336                                         ObjCProtocolDecl *PDecl);
5337
5338  Decl *ActOnAtEnd(Scope *S, SourceRange AtEnd,
5339                   Decl **allMethods = 0, unsigned allNum = 0,
5340                   Decl **allProperties = 0, unsigned pNum = 0,
5341                   DeclGroupPtrTy *allTUVars = 0, unsigned tuvNum = 0);
5342
5343  Decl *ActOnProperty(Scope *S, SourceLocation AtLoc,
5344                      FieldDeclarator &FD, ObjCDeclSpec &ODS,
5345                      Selector GetterSel, Selector SetterSel,
5346                      bool *OverridingProperty,
5347                      tok::ObjCKeywordKind MethodImplKind,
5348                      DeclContext *lexicalDC = 0);
5349
5350  Decl *ActOnPropertyImplDecl(Scope *S,
5351                              SourceLocation AtLoc,
5352                              SourceLocation PropertyLoc,
5353                              bool ImplKind,
5354                              IdentifierInfo *PropertyId,
5355                              IdentifierInfo *PropertyIvar,
5356                              SourceLocation PropertyIvarLoc);
5357
5358  enum ObjCSpecialMethodKind {
5359    OSMK_None,
5360    OSMK_Alloc,
5361    OSMK_New,
5362    OSMK_Copy,
5363    OSMK_RetainingInit,
5364    OSMK_NonRetainingInit
5365  };
5366
5367  struct ObjCArgInfo {
5368    IdentifierInfo *Name;
5369    SourceLocation NameLoc;
5370    // The Type is null if no type was specified, and the DeclSpec is invalid
5371    // in this case.
5372    ParsedType Type;
5373    ObjCDeclSpec DeclSpec;
5374
5375    /// ArgAttrs - Attribute list for this argument.
5376    AttributeList *ArgAttrs;
5377  };
5378
5379  Decl *ActOnMethodDeclaration(
5380    Scope *S,
5381    SourceLocation BeginLoc, // location of the + or -.
5382    SourceLocation EndLoc,   // location of the ; or {.
5383    tok::TokenKind MethodType,
5384    ObjCDeclSpec &ReturnQT, ParsedType ReturnType,
5385    ArrayRef<SourceLocation> SelectorLocs, Selector Sel,
5386    // optional arguments. The number of types/arguments is obtained
5387    // from the Sel.getNumArgs().
5388    ObjCArgInfo *ArgInfo,
5389    DeclaratorChunk::ParamInfo *CParamInfo, unsigned CNumArgs, // c-style args
5390    AttributeList *AttrList, tok::ObjCKeywordKind MethodImplKind,
5391    bool isVariadic, bool MethodDefinition);
5392
5393  // Helper method for ActOnClassMethod/ActOnInstanceMethod.
5394  // Will search "local" class/category implementations for a method decl.
5395  // Will also search in class's root looking for instance method.
5396  // Returns 0 if no method is found.
5397  ObjCMethodDecl *LookupPrivateClassMethod(Selector Sel,
5398                                           ObjCInterfaceDecl *CDecl);
5399  ObjCMethodDecl *LookupPrivateInstanceMethod(Selector Sel,
5400                                              ObjCInterfaceDecl *ClassDecl);
5401  ObjCMethodDecl *LookupMethodInQualifiedType(Selector Sel,
5402                                              const ObjCObjectPointerType *OPT,
5403                                              bool IsInstance);
5404  ObjCMethodDecl *LookupMethodInObjectType(Selector Sel, QualType Ty,
5405                                           bool IsInstance);
5406
5407  bool inferObjCARCLifetime(ValueDecl *decl);
5408
5409  ExprResult
5410  HandleExprPropertyRefExpr(const ObjCObjectPointerType *OPT,
5411                            Expr *BaseExpr,
5412                            SourceLocation OpLoc,
5413                            DeclarationName MemberName,
5414                            SourceLocation MemberLoc,
5415                            SourceLocation SuperLoc, QualType SuperType,
5416                            bool Super);
5417
5418  ExprResult
5419  ActOnClassPropertyRefExpr(IdentifierInfo &receiverName,
5420                            IdentifierInfo &propertyName,
5421                            SourceLocation receiverNameLoc,
5422                            SourceLocation propertyNameLoc);
5423
5424  ObjCMethodDecl *tryCaptureObjCSelf();
5425
5426  /// \brief Describes the kind of message expression indicated by a message
5427  /// send that starts with an identifier.
5428  enum ObjCMessageKind {
5429    /// \brief The message is sent to 'super'.
5430    ObjCSuperMessage,
5431    /// \brief The message is an instance message.
5432    ObjCInstanceMessage,
5433    /// \brief The message is a class message, and the identifier is a type
5434    /// name.
5435    ObjCClassMessage
5436  };
5437
5438  ObjCMessageKind getObjCMessageKind(Scope *S,
5439                                     IdentifierInfo *Name,
5440                                     SourceLocation NameLoc,
5441                                     bool IsSuper,
5442                                     bool HasTrailingDot,
5443                                     ParsedType &ReceiverType);
5444
5445  ExprResult ActOnSuperMessage(Scope *S, SourceLocation SuperLoc,
5446                               Selector Sel,
5447                               SourceLocation LBracLoc,
5448                               ArrayRef<SourceLocation> SelectorLocs,
5449                               SourceLocation RBracLoc,
5450                               MultiExprArg Args);
5451
5452  ExprResult BuildClassMessage(TypeSourceInfo *ReceiverTypeInfo,
5453                               QualType ReceiverType,
5454                               SourceLocation SuperLoc,
5455                               Selector Sel,
5456                               ObjCMethodDecl *Method,
5457                               SourceLocation LBracLoc,
5458                               ArrayRef<SourceLocation> SelectorLocs,
5459                               SourceLocation RBracLoc,
5460                               MultiExprArg Args,
5461                               bool isImplicit = false);
5462
5463  ExprResult BuildClassMessageImplicit(QualType ReceiverType,
5464                                       bool isSuperReceiver,
5465                                       SourceLocation Loc,
5466                                       Selector Sel,
5467                                       ObjCMethodDecl *Method,
5468                                       MultiExprArg Args);
5469
5470  ExprResult ActOnClassMessage(Scope *S,
5471                               ParsedType Receiver,
5472                               Selector Sel,
5473                               SourceLocation LBracLoc,
5474                               ArrayRef<SourceLocation> SelectorLocs,
5475                               SourceLocation RBracLoc,
5476                               MultiExprArg Args);
5477
5478  ExprResult BuildInstanceMessage(Expr *Receiver,
5479                                  QualType ReceiverType,
5480                                  SourceLocation SuperLoc,
5481                                  Selector Sel,
5482                                  ObjCMethodDecl *Method,
5483                                  SourceLocation LBracLoc,
5484                                  ArrayRef<SourceLocation> SelectorLocs,
5485                                  SourceLocation RBracLoc,
5486                                  MultiExprArg Args,
5487                                  bool isImplicit = false);
5488
5489  ExprResult BuildInstanceMessageImplicit(Expr *Receiver,
5490                                          QualType ReceiverType,
5491                                          SourceLocation Loc,
5492                                          Selector Sel,
5493                                          ObjCMethodDecl *Method,
5494                                          MultiExprArg Args);
5495
5496  ExprResult ActOnInstanceMessage(Scope *S,
5497                                  Expr *Receiver,
5498                                  Selector Sel,
5499                                  SourceLocation LBracLoc,
5500                                  ArrayRef<SourceLocation> SelectorLocs,
5501                                  SourceLocation RBracLoc,
5502                                  MultiExprArg Args);
5503
5504  ExprResult BuildObjCBridgedCast(SourceLocation LParenLoc,
5505                                  ObjCBridgeCastKind Kind,
5506                                  SourceLocation BridgeKeywordLoc,
5507                                  TypeSourceInfo *TSInfo,
5508                                  Expr *SubExpr);
5509
5510  ExprResult ActOnObjCBridgedCast(Scope *S,
5511                                  SourceLocation LParenLoc,
5512                                  ObjCBridgeCastKind Kind,
5513                                  SourceLocation BridgeKeywordLoc,
5514                                  ParsedType Type,
5515                                  SourceLocation RParenLoc,
5516                                  Expr *SubExpr);
5517
5518  bool checkInitMethod(ObjCMethodDecl *method, QualType receiverTypeIfCall);
5519
5520  /// \brief Check whether the given new method is a valid override of the
5521  /// given overridden method, and set any properties that should be inherited.
5522  void CheckObjCMethodOverride(ObjCMethodDecl *NewMethod,
5523                               const ObjCMethodDecl *Overridden,
5524                               bool IsImplementation);
5525
5526  /// \brief Check whether the given method overrides any methods in its class,
5527  /// calling \c CheckObjCMethodOverride for each overridden method.
5528  bool CheckObjCMethodOverrides(ObjCMethodDecl *NewMethod, DeclContext *DC);
5529
5530  enum PragmaOptionsAlignKind {
5531    POAK_Native,  // #pragma options align=native
5532    POAK_Natural, // #pragma options align=natural
5533    POAK_Packed,  // #pragma options align=packed
5534    POAK_Power,   // #pragma options align=power
5535    POAK_Mac68k,  // #pragma options align=mac68k
5536    POAK_Reset    // #pragma options align=reset
5537  };
5538
5539  /// ActOnPragmaOptionsAlign - Called on well formed #pragma options align.
5540  void ActOnPragmaOptionsAlign(PragmaOptionsAlignKind Kind,
5541                               SourceLocation PragmaLoc,
5542                               SourceLocation KindLoc);
5543
5544  enum PragmaPackKind {
5545    PPK_Default, // #pragma pack([n])
5546    PPK_Show,    // #pragma pack(show), only supported by MSVC.
5547    PPK_Push,    // #pragma pack(push, [identifier], [n])
5548    PPK_Pop      // #pragma pack(pop, [identifier], [n])
5549  };
5550
5551  enum PragmaMSStructKind {
5552    PMSST_OFF,  // #pragms ms_struct off
5553    PMSST_ON    // #pragms ms_struct on
5554  };
5555
5556  /// ActOnPragmaPack - Called on well formed #pragma pack(...).
5557  void ActOnPragmaPack(PragmaPackKind Kind,
5558                       IdentifierInfo *Name,
5559                       Expr *Alignment,
5560                       SourceLocation PragmaLoc,
5561                       SourceLocation LParenLoc,
5562                       SourceLocation RParenLoc);
5563
5564  /// ActOnPragmaMSStruct - Called on well formed #pragms ms_struct [on|off].
5565  void ActOnPragmaMSStruct(PragmaMSStructKind Kind);
5566
5567  /// ActOnPragmaUnused - Called on well-formed '#pragma unused'.
5568  void ActOnPragmaUnused(const Token &Identifier,
5569                         Scope *curScope,
5570                         SourceLocation PragmaLoc);
5571
5572  /// ActOnPragmaVisibility - Called on well formed #pragma GCC visibility... .
5573  void ActOnPragmaVisibility(const IdentifierInfo* VisType,
5574                             SourceLocation PragmaLoc);
5575
5576  NamedDecl *DeclClonePragmaWeak(NamedDecl *ND, IdentifierInfo *II,
5577                                 SourceLocation Loc);
5578  void DeclApplyPragmaWeak(Scope *S, NamedDecl *ND, WeakInfo &W);
5579
5580  /// ActOnPragmaWeakID - Called on well formed #pragma weak ident.
5581  void ActOnPragmaWeakID(IdentifierInfo* WeakName,
5582                         SourceLocation PragmaLoc,
5583                         SourceLocation WeakNameLoc);
5584
5585  /// ActOnPragmaWeakAlias - Called on well formed #pragma weak ident = ident.
5586  void ActOnPragmaWeakAlias(IdentifierInfo* WeakName,
5587                            IdentifierInfo* AliasName,
5588                            SourceLocation PragmaLoc,
5589                            SourceLocation WeakNameLoc,
5590                            SourceLocation AliasNameLoc);
5591
5592  /// ActOnPragmaFPContract - Called on well formed
5593  /// #pragma {STDC,OPENCL} FP_CONTRACT
5594  void ActOnPragmaFPContract(tok::OnOffSwitch OOS);
5595
5596  /// AddAlignmentAttributesForRecord - Adds any needed alignment attributes to
5597  /// a the record decl, to handle '#pragma pack' and '#pragma options align'.
5598  void AddAlignmentAttributesForRecord(RecordDecl *RD);
5599
5600  /// AddMsStructLayoutForRecord - Adds ms_struct layout attribute to record.
5601  void AddMsStructLayoutForRecord(RecordDecl *RD);
5602
5603  /// FreePackedContext - Deallocate and null out PackContext.
5604  void FreePackedContext();
5605
5606  /// PushNamespaceVisibilityAttr - Note that we've entered a
5607  /// namespace with a visibility attribute.
5608  void PushNamespaceVisibilityAttr(const VisibilityAttr *Attr);
5609
5610  /// AddPushedVisibilityAttribute - If '#pragma GCC visibility' was used,
5611  /// add an appropriate visibility attribute.
5612  void AddPushedVisibilityAttribute(Decl *RD);
5613
5614  /// PopPragmaVisibility - Pop the top element of the visibility stack; used
5615  /// for '#pragma GCC visibility' and visibility attributes on namespaces.
5616  void PopPragmaVisibility();
5617
5618  /// FreeVisContext - Deallocate and null out VisContext.
5619  void FreeVisContext();
5620
5621  /// AddCFAuditedAttribute - Check whether we're currently within
5622  /// '#pragma clang arc_cf_code_audited' and, if so, consider adding
5623  /// the appropriate attribute.
5624  void AddCFAuditedAttribute(Decl *D);
5625
5626  /// AddAlignedAttr - Adds an aligned attribute to a particular declaration.
5627  void AddAlignedAttr(SourceRange AttrRange, Decl *D, Expr *E);
5628  void AddAlignedAttr(SourceRange AttrRange, Decl *D, TypeSourceInfo *T);
5629
5630  /// \brief The kind of conversion being performed.
5631  enum CheckedConversionKind {
5632    /// \brief An implicit conversion.
5633    CCK_ImplicitConversion,
5634    /// \brief A C-style cast.
5635    CCK_CStyleCast,
5636    /// \brief A functional-style cast.
5637    CCK_FunctionalCast,
5638    /// \brief A cast other than a C-style cast.
5639    CCK_OtherCast
5640  };
5641
5642  /// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit
5643  /// cast.  If there is already an implicit cast, merge into the existing one.
5644  /// If isLvalue, the result of the cast is an lvalue.
5645  ExprResult ImpCastExprToType(Expr *E, QualType Type, CastKind CK,
5646                               ExprValueKind VK = VK_RValue,
5647                               const CXXCastPath *BasePath = 0,
5648                               CheckedConversionKind CCK
5649                                  = CCK_ImplicitConversion);
5650
5651  /// ScalarTypeToBooleanCastKind - Returns the cast kind corresponding
5652  /// to the conversion from scalar type ScalarTy to the Boolean type.
5653  static CastKind ScalarTypeToBooleanCastKind(QualType ScalarTy);
5654
5655  /// IgnoredValueConversions - Given that an expression's result is
5656  /// syntactically ignored, perform any conversions that are
5657  /// required.
5658  ExprResult IgnoredValueConversions(Expr *E);
5659
5660  // UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts
5661  // functions and arrays to their respective pointers (C99 6.3.2.1).
5662  ExprResult UsualUnaryConversions(Expr *E);
5663
5664  // DefaultFunctionArrayConversion - converts functions and arrays
5665  // to their respective pointers (C99 6.3.2.1).
5666  ExprResult DefaultFunctionArrayConversion(Expr *E);
5667
5668  // DefaultFunctionArrayLvalueConversion - converts functions and
5669  // arrays to their respective pointers and performs the
5670  // lvalue-to-rvalue conversion.
5671  ExprResult DefaultFunctionArrayLvalueConversion(Expr *E);
5672
5673  // DefaultLvalueConversion - performs lvalue-to-rvalue conversion on
5674  // the operand.  This is DefaultFunctionArrayLvalueConversion,
5675  // except that it assumes the operand isn't of function or array
5676  // type.
5677  ExprResult DefaultLvalueConversion(Expr *E);
5678
5679  // DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that
5680  // do not have a prototype. Integer promotions are performed on each
5681  // argument, and arguments that have type float are promoted to double.
5682  ExprResult DefaultArgumentPromotion(Expr *E);
5683
5684  // Used for emitting the right warning by DefaultVariadicArgumentPromotion
5685  enum VariadicCallType {
5686    VariadicFunction,
5687    VariadicBlock,
5688    VariadicMethod,
5689    VariadicConstructor,
5690    VariadicDoesNotApply
5691  };
5692
5693  /// GatherArgumentsForCall - Collector argument expressions for various
5694  /// form of call prototypes.
5695  bool GatherArgumentsForCall(SourceLocation CallLoc,
5696                              FunctionDecl *FDecl,
5697                              const FunctionProtoType *Proto,
5698                              unsigned FirstProtoArg,
5699                              Expr **Args, unsigned NumArgs,
5700                              SmallVector<Expr *, 8> &AllArgs,
5701                              VariadicCallType CallType = VariadicDoesNotApply);
5702
5703  // DefaultVariadicArgumentPromotion - Like DefaultArgumentPromotion, but
5704  // will warn if the resulting type is not a POD type.
5705  ExprResult DefaultVariadicArgumentPromotion(Expr *E, VariadicCallType CT,
5706                                              FunctionDecl *FDecl);
5707
5708  // UsualArithmeticConversions - performs the UsualUnaryConversions on it's
5709  // operands and then handles various conversions that are common to binary
5710  // operators (C99 6.3.1.8). If both operands aren't arithmetic, this
5711  // routine returns the first non-arithmetic type found. The client is
5712  // responsible for emitting appropriate error diagnostics.
5713  QualType UsualArithmeticConversions(ExprResult &LHS, ExprResult &RHS,
5714                                      bool IsCompAssign = false);
5715
5716  /// AssignConvertType - All of the 'assignment' semantic checks return this
5717  /// enum to indicate whether the assignment was allowed.  These checks are
5718  /// done for simple assignments, as well as initialization, return from
5719  /// function, argument passing, etc.  The query is phrased in terms of a
5720  /// source and destination type.
5721  enum AssignConvertType {
5722    /// Compatible - the types are compatible according to the standard.
5723    Compatible,
5724
5725    /// PointerToInt - The assignment converts a pointer to an int, which we
5726    /// accept as an extension.
5727    PointerToInt,
5728
5729    /// IntToPointer - The assignment converts an int to a pointer, which we
5730    /// accept as an extension.
5731    IntToPointer,
5732
5733    /// FunctionVoidPointer - The assignment is between a function pointer and
5734    /// void*, which the standard doesn't allow, but we accept as an extension.
5735    FunctionVoidPointer,
5736
5737    /// IncompatiblePointer - The assignment is between two pointers types that
5738    /// are not compatible, but we accept them as an extension.
5739    IncompatiblePointer,
5740
5741    /// IncompatiblePointer - The assignment is between two pointers types which
5742    /// point to integers which have a different sign, but are otherwise
5743    /// identical. This is a subset of the above, but broken out because it's by
5744    /// far the most common case of incompatible pointers.
5745    IncompatiblePointerSign,
5746
5747    /// CompatiblePointerDiscardsQualifiers - The assignment discards
5748    /// c/v/r qualifiers, which we accept as an extension.
5749    CompatiblePointerDiscardsQualifiers,
5750
5751    /// IncompatiblePointerDiscardsQualifiers - The assignment
5752    /// discards qualifiers that we don't permit to be discarded,
5753    /// like address spaces.
5754    IncompatiblePointerDiscardsQualifiers,
5755
5756    /// IncompatibleNestedPointerQualifiers - The assignment is between two
5757    /// nested pointer types, and the qualifiers other than the first two
5758    /// levels differ e.g. char ** -> const char **, but we accept them as an
5759    /// extension.
5760    IncompatibleNestedPointerQualifiers,
5761
5762    /// IncompatibleVectors - The assignment is between two vector types that
5763    /// have the same size, which we accept as an extension.
5764    IncompatibleVectors,
5765
5766    /// IntToBlockPointer - The assignment converts an int to a block
5767    /// pointer. We disallow this.
5768    IntToBlockPointer,
5769
5770    /// IncompatibleBlockPointer - The assignment is between two block
5771    /// pointers types that are not compatible.
5772    IncompatibleBlockPointer,
5773
5774    /// IncompatibleObjCQualifiedId - The assignment is between a qualified
5775    /// id type and something else (that is incompatible with it). For example,
5776    /// "id <XXX>" = "Foo *", where "Foo *" doesn't implement the XXX protocol.
5777    IncompatibleObjCQualifiedId,
5778
5779    /// IncompatibleObjCWeakRef - Assigning a weak-unavailable object to an
5780    /// object with __weak qualifier.
5781    IncompatibleObjCWeakRef,
5782
5783    /// Incompatible - We reject this conversion outright, it is invalid to
5784    /// represent it in the AST.
5785    Incompatible
5786  };
5787
5788  /// DiagnoseAssignmentResult - Emit a diagnostic, if required, for the
5789  /// assignment conversion type specified by ConvTy.  This returns true if the
5790  /// conversion was invalid or false if the conversion was accepted.
5791  bool DiagnoseAssignmentResult(AssignConvertType ConvTy,
5792                                SourceLocation Loc,
5793                                QualType DstType, QualType SrcType,
5794                                Expr *SrcExpr, AssignmentAction Action,
5795                                bool *Complained = 0);
5796
5797  /// CheckAssignmentConstraints - Perform type checking for assignment,
5798  /// argument passing, variable initialization, and function return values.
5799  /// C99 6.5.16.
5800  AssignConvertType CheckAssignmentConstraints(SourceLocation Loc,
5801                                               QualType LHSType,
5802                                               QualType RHSType);
5803
5804  /// Check assignment constraints and prepare for a conversion of the
5805  /// RHS to the LHS type.
5806  AssignConvertType CheckAssignmentConstraints(QualType LHSType,
5807                                               ExprResult &RHS,
5808                                               CastKind &Kind);
5809
5810  // CheckSingleAssignmentConstraints - Currently used by
5811  // CheckAssignmentOperands, and ActOnReturnStmt. Prior to type checking,
5812  // this routine performs the default function/array converions.
5813  AssignConvertType CheckSingleAssignmentConstraints(QualType LHSType,
5814                                                     ExprResult &RHS,
5815                                                     bool Diagnose = true);
5816
5817  // \brief If the lhs type is a transparent union, check whether we
5818  // can initialize the transparent union with the given expression.
5819  AssignConvertType CheckTransparentUnionArgumentConstraints(QualType ArgType,
5820                                                             ExprResult &RHS);
5821
5822  bool IsStringLiteralToNonConstPointerConversion(Expr *From, QualType ToType);
5823
5824  bool CheckExceptionSpecCompatibility(Expr *From, QualType ToType);
5825
5826  ExprResult PerformImplicitConversion(Expr *From, QualType ToType,
5827                                       AssignmentAction Action,
5828                                       bool AllowExplicit = false);
5829  ExprResult PerformImplicitConversion(Expr *From, QualType ToType,
5830                                       AssignmentAction Action,
5831                                       bool AllowExplicit,
5832                                       ImplicitConversionSequence& ICS);
5833  ExprResult PerformImplicitConversion(Expr *From, QualType ToType,
5834                                       const ImplicitConversionSequence& ICS,
5835                                       AssignmentAction Action,
5836                                       CheckedConversionKind CCK
5837                                          = CCK_ImplicitConversion);
5838  ExprResult PerformImplicitConversion(Expr *From, QualType ToType,
5839                                       const StandardConversionSequence& SCS,
5840                                       AssignmentAction Action,
5841                                       CheckedConversionKind CCK);
5842
5843  /// the following "Check" methods will return a valid/converted QualType
5844  /// or a null QualType (indicating an error diagnostic was issued).
5845
5846  /// type checking binary operators (subroutines of CreateBuiltinBinOp).
5847  QualType InvalidOperands(SourceLocation Loc, ExprResult &LHS,
5848                           ExprResult &RHS);
5849  QualType CheckPointerToMemberOperands( // C++ 5.5
5850    ExprResult &LHS, ExprResult &RHS, ExprValueKind &VK,
5851    SourceLocation OpLoc, bool isIndirect);
5852  QualType CheckMultiplyDivideOperands( // C99 6.5.5
5853    ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, bool IsCompAssign,
5854    bool IsDivide);
5855  QualType CheckRemainderOperands( // C99 6.5.5
5856    ExprResult &LHS, ExprResult &RHS, SourceLocation Loc,
5857    bool IsCompAssign = false);
5858  QualType CheckAdditionOperands( // C99 6.5.6
5859    ExprResult &LHS, ExprResult &RHS, SourceLocation Loc,
5860    QualType* CompLHSTy = 0);
5861  QualType CheckSubtractionOperands( // C99 6.5.6
5862    ExprResult &LHS, ExprResult &RHS, SourceLocation Loc,
5863    QualType* CompLHSTy = 0);
5864  QualType CheckShiftOperands( // C99 6.5.7
5865    ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, unsigned Opc,
5866    bool IsCompAssign = false);
5867  QualType CheckCompareOperands( // C99 6.5.8/9
5868    ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, unsigned OpaqueOpc,
5869                                bool isRelational);
5870  QualType CheckBitwiseOperands( // C99 6.5.[10...12]
5871    ExprResult &LHS, ExprResult &RHS, SourceLocation Loc,
5872    bool IsCompAssign = false);
5873  QualType CheckLogicalOperands( // C99 6.5.[13,14]
5874    ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, unsigned Opc);
5875  // CheckAssignmentOperands is used for both simple and compound assignment.
5876  // For simple assignment, pass both expressions and a null converted type.
5877  // For compound assignment, pass both expressions and the converted type.
5878  QualType CheckAssignmentOperands( // C99 6.5.16.[1,2]
5879    Expr *LHSExpr, ExprResult &RHS, SourceLocation Loc, QualType CompoundType);
5880
5881  ExprResult checkPseudoObjectIncDec(Scope *S, SourceLocation OpLoc,
5882                                     UnaryOperatorKind Opcode, Expr *Op);
5883  ExprResult checkPseudoObjectAssignment(Scope *S, SourceLocation OpLoc,
5884                                         BinaryOperatorKind Opcode,
5885                                         Expr *LHS, Expr *RHS);
5886  ExprResult checkPseudoObjectRValue(Expr *E);
5887  Expr *recreateSyntacticForm(PseudoObjectExpr *E);
5888
5889  QualType CheckConditionalOperands( // C99 6.5.15
5890    ExprResult &Cond, ExprResult &LHS, ExprResult &RHS,
5891    ExprValueKind &VK, ExprObjectKind &OK, SourceLocation QuestionLoc);
5892  QualType CXXCheckConditionalOperands( // C++ 5.16
5893    ExprResult &cond, ExprResult &lhs, ExprResult &rhs,
5894    ExprValueKind &VK, ExprObjectKind &OK, SourceLocation questionLoc);
5895  QualType FindCompositePointerType(SourceLocation Loc, Expr *&E1, Expr *&E2,
5896                                    bool *NonStandardCompositeType = 0);
5897  QualType FindCompositePointerType(SourceLocation Loc,
5898                                    ExprResult &E1, ExprResult &E2,
5899                                    bool *NonStandardCompositeType = 0) {
5900    Expr *E1Tmp = E1.take(), *E2Tmp = E2.take();
5901    QualType Composite = FindCompositePointerType(Loc, E1Tmp, E2Tmp,
5902                                                  NonStandardCompositeType);
5903    E1 = Owned(E1Tmp);
5904    E2 = Owned(E2Tmp);
5905    return Composite;
5906  }
5907
5908  QualType FindCompositeObjCPointerType(ExprResult &LHS, ExprResult &RHS,
5909                                        SourceLocation QuestionLoc);
5910
5911  bool DiagnoseConditionalForNull(Expr *LHSExpr, Expr *RHSExpr,
5912                                  SourceLocation QuestionLoc);
5913
5914  /// type checking for vector binary operators.
5915  QualType CheckVectorOperands(ExprResult &LHS, ExprResult &RHS,
5916                               SourceLocation Loc, bool IsCompAssign);
5917  QualType GetSignedVectorType(QualType V);
5918  QualType CheckVectorCompareOperands(ExprResult &LHS, ExprResult &RHS,
5919                                      SourceLocation Loc, bool isRelational);
5920  QualType CheckVectorLogicalOperands(ExprResult &LHS, ExprResult &RHS,
5921                                      SourceLocation Loc);
5922
5923  /// type checking declaration initializers (C99 6.7.8)
5924  bool CheckForConstantInitializer(Expr *e, QualType t);
5925
5926  // type checking C++ declaration initializers (C++ [dcl.init]).
5927
5928  /// ReferenceCompareResult - Expresses the result of comparing two
5929  /// types (cv1 T1 and cv2 T2) to determine their compatibility for the
5930  /// purposes of initialization by reference (C++ [dcl.init.ref]p4).
5931  enum ReferenceCompareResult {
5932    /// Ref_Incompatible - The two types are incompatible, so direct
5933    /// reference binding is not possible.
5934    Ref_Incompatible = 0,
5935    /// Ref_Related - The two types are reference-related, which means
5936    /// that their unqualified forms (T1 and T2) are either the same
5937    /// or T1 is a base class of T2.
5938    Ref_Related,
5939    /// Ref_Compatible_With_Added_Qualification - The two types are
5940    /// reference-compatible with added qualification, meaning that
5941    /// they are reference-compatible and the qualifiers on T1 (cv1)
5942    /// are greater than the qualifiers on T2 (cv2).
5943    Ref_Compatible_With_Added_Qualification,
5944    /// Ref_Compatible - The two types are reference-compatible and
5945    /// have equivalent qualifiers (cv1 == cv2).
5946    Ref_Compatible
5947  };
5948
5949  ReferenceCompareResult CompareReferenceRelationship(SourceLocation Loc,
5950                                                      QualType T1, QualType T2,
5951                                                      bool &DerivedToBase,
5952                                                      bool &ObjCConversion,
5953                                                bool &ObjCLifetimeConversion);
5954
5955  ExprResult checkUnknownAnyCast(SourceRange TypeRange, QualType CastType,
5956                                 Expr *CastExpr, CastKind &CastKind,
5957                                 ExprValueKind &VK, CXXCastPath &Path);
5958
5959  /// \brief Force an expression with unknown-type to an expression of the
5960  /// given type.
5961  ExprResult forceUnknownAnyToType(Expr *E, QualType ToType);
5962
5963  // CheckVectorCast - check type constraints for vectors.
5964  // Since vectors are an extension, there are no C standard reference for this.
5965  // We allow casting between vectors and integer datatypes of the same size.
5966  // returns true if the cast is invalid
5967  bool CheckVectorCast(SourceRange R, QualType VectorTy, QualType Ty,
5968                       CastKind &Kind);
5969
5970  // CheckExtVectorCast - check type constraints for extended vectors.
5971  // Since vectors are an extension, there are no C standard reference for this.
5972  // We allow casting between vectors and integer datatypes of the same size,
5973  // or vectors and the element type of that vector.
5974  // returns the cast expr
5975  ExprResult CheckExtVectorCast(SourceRange R, QualType DestTy, Expr *CastExpr,
5976                                CastKind &Kind);
5977
5978  ExprResult BuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
5979                                        SourceLocation LParenLoc,
5980                                        Expr *CastExpr,
5981                                        SourceLocation RParenLoc);
5982
5983  enum ARCConversionResult { ACR_okay, ACR_unbridged };
5984
5985  /// \brief Checks for invalid conversions and casts between
5986  /// retainable pointers and other pointer kinds.
5987  ARCConversionResult CheckObjCARCConversion(SourceRange castRange,
5988                                             QualType castType, Expr *&op,
5989                                             CheckedConversionKind CCK);
5990
5991  Expr *stripARCUnbridgedCast(Expr *e);
5992  void diagnoseARCUnbridgedCast(Expr *e);
5993
5994  bool CheckObjCARCUnavailableWeakConversion(QualType castType,
5995                                             QualType ExprType);
5996
5997  /// checkRetainCycles - Check whether an Objective-C message send
5998  /// might create an obvious retain cycle.
5999  void checkRetainCycles(ObjCMessageExpr *msg);
6000  void checkRetainCycles(Expr *receiver, Expr *argument);
6001
6002  /// checkUnsafeAssigns - Check whether +1 expr is being assigned
6003  /// to weak/__unsafe_unretained type.
6004  bool checkUnsafeAssigns(SourceLocation Loc, QualType LHS, Expr *RHS);
6005
6006  /// checkUnsafeExprAssigns - Check whether +1 expr is being assigned
6007  /// to weak/__unsafe_unretained expression.
6008  void checkUnsafeExprAssigns(SourceLocation Loc, Expr *LHS, Expr *RHS);
6009
6010  /// CheckMessageArgumentTypes - Check types in an Obj-C message send.
6011  /// \param Method - May be null.
6012  /// \param [out] ReturnType - The return type of the send.
6013  /// \return true iff there were any incompatible types.
6014  bool CheckMessageArgumentTypes(QualType ReceiverType,
6015                                 Expr **Args, unsigned NumArgs, Selector Sel,
6016                                 ObjCMethodDecl *Method, bool isClassMessage,
6017                                 bool isSuperMessage,
6018                                 SourceLocation lbrac, SourceLocation rbrac,
6019                                 QualType &ReturnType, ExprValueKind &VK);
6020
6021  /// \brief Determine the result of a message send expression based on
6022  /// the type of the receiver, the method expected to receive the message,
6023  /// and the form of the message send.
6024  QualType getMessageSendResultType(QualType ReceiverType,
6025                                    ObjCMethodDecl *Method,
6026                                    bool isClassMessage, bool isSuperMessage);
6027
6028  /// \brief If the given expression involves a message send to a method
6029  /// with a related result type, emit a note describing what happened.
6030  void EmitRelatedResultTypeNote(const Expr *E);
6031
6032  /// CheckBooleanCondition - Diagnose problems involving the use of
6033  /// the given expression as a boolean condition (e.g. in an if
6034  /// statement).  Also performs the standard function and array
6035  /// decays, possibly changing the input variable.
6036  ///
6037  /// \param Loc - A location associated with the condition, e.g. the
6038  /// 'if' keyword.
6039  /// \return true iff there were any errors
6040  ExprResult CheckBooleanCondition(Expr *E, SourceLocation Loc);
6041
6042  ExprResult ActOnBooleanCondition(Scope *S, SourceLocation Loc,
6043                                   Expr *SubExpr);
6044
6045  /// DiagnoseAssignmentAsCondition - Given that an expression is
6046  /// being used as a boolean condition, warn if it's an assignment.
6047  void DiagnoseAssignmentAsCondition(Expr *E);
6048
6049  /// \brief Redundant parentheses over an equality comparison can indicate
6050  /// that the user intended an assignment used as condition.
6051  void DiagnoseEqualityWithExtraParens(ParenExpr *ParenE);
6052
6053  /// CheckCXXBooleanCondition - Returns true if conversion to bool is invalid.
6054  ExprResult CheckCXXBooleanCondition(Expr *CondExpr);
6055
6056  /// ConvertIntegerToTypeWarnOnOverflow - Convert the specified APInt to have
6057  /// the specified width and sign.  If an overflow occurs, detect it and emit
6058  /// the specified diagnostic.
6059  void ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &OldVal,
6060                                          unsigned NewWidth, bool NewSign,
6061                                          SourceLocation Loc, unsigned DiagID);
6062
6063  /// Checks that the Objective-C declaration is declared in the global scope.
6064  /// Emits an error and marks the declaration as invalid if it's not declared
6065  /// in the global scope.
6066  bool CheckObjCDeclScope(Decl *D);
6067
6068  /// VerifyIntegerConstantExpression - Verifies that an expression is an ICE,
6069  /// and reports the appropriate diagnostics. Returns false on success.
6070  /// Can optionally return the value of the expression.
6071  bool VerifyIntegerConstantExpression(const Expr *E, llvm::APSInt *Result = 0,
6072                                       unsigned DiagId = 0,
6073                                       bool AllowFold = true);
6074
6075  /// VerifyBitField - verifies that a bit field expression is an ICE and has
6076  /// the correct width, and that the field type is valid.
6077  /// Returns false on success.
6078  /// Can optionally return whether the bit-field is of width 0
6079  bool VerifyBitField(SourceLocation FieldLoc, IdentifierInfo *FieldName,
6080                      QualType FieldTy, const Expr *BitWidth,
6081                      bool *ZeroWidth = 0);
6082
6083  enum CUDAFunctionTarget {
6084    CFT_Device,
6085    CFT_Global,
6086    CFT_Host,
6087    CFT_HostDevice
6088  };
6089
6090  CUDAFunctionTarget IdentifyCUDATarget(const FunctionDecl *D);
6091
6092  bool CheckCUDATarget(CUDAFunctionTarget CallerTarget,
6093                       CUDAFunctionTarget CalleeTarget);
6094
6095  bool CheckCUDATarget(const FunctionDecl *Caller, const FunctionDecl *Callee) {
6096    return CheckCUDATarget(IdentifyCUDATarget(Caller),
6097                           IdentifyCUDATarget(Callee));
6098  }
6099
6100  /// \name Code completion
6101  //@{
6102  /// \brief Describes the context in which code completion occurs.
6103  enum ParserCompletionContext {
6104    /// \brief Code completion occurs at top-level or namespace context.
6105    PCC_Namespace,
6106    /// \brief Code completion occurs within a class, struct, or union.
6107    PCC_Class,
6108    /// \brief Code completion occurs within an Objective-C interface, protocol,
6109    /// or category.
6110    PCC_ObjCInterface,
6111    /// \brief Code completion occurs within an Objective-C implementation or
6112    /// category implementation
6113    PCC_ObjCImplementation,
6114    /// \brief Code completion occurs within the list of instance variables
6115    /// in an Objective-C interface, protocol, category, or implementation.
6116    PCC_ObjCInstanceVariableList,
6117    /// \brief Code completion occurs following one or more template
6118    /// headers.
6119    PCC_Template,
6120    /// \brief Code completion occurs following one or more template
6121    /// headers within a class.
6122    PCC_MemberTemplate,
6123    /// \brief Code completion occurs within an expression.
6124    PCC_Expression,
6125    /// \brief Code completion occurs within a statement, which may
6126    /// also be an expression or a declaration.
6127    PCC_Statement,
6128    /// \brief Code completion occurs at the beginning of the
6129    /// initialization statement (or expression) in a for loop.
6130    PCC_ForInit,
6131    /// \brief Code completion occurs within the condition of an if,
6132    /// while, switch, or for statement.
6133    PCC_Condition,
6134    /// \brief Code completion occurs within the body of a function on a
6135    /// recovery path, where we do not have a specific handle on our position
6136    /// in the grammar.
6137    PCC_RecoveryInFunction,
6138    /// \brief Code completion occurs where only a type is permitted.
6139    PCC_Type,
6140    /// \brief Code completion occurs in a parenthesized expression, which
6141    /// might also be a type cast.
6142    PCC_ParenthesizedExpression,
6143    /// \brief Code completion occurs within a sequence of declaration
6144    /// specifiers within a function, method, or block.
6145    PCC_LocalDeclarationSpecifiers
6146  };
6147
6148  void CodeCompleteOrdinaryName(Scope *S,
6149                                ParserCompletionContext CompletionContext);
6150  void CodeCompleteDeclSpec(Scope *S, DeclSpec &DS,
6151                            bool AllowNonIdentifiers,
6152                            bool AllowNestedNameSpecifiers);
6153
6154  struct CodeCompleteExpressionData;
6155  void CodeCompleteExpression(Scope *S,
6156                              const CodeCompleteExpressionData &Data);
6157  void CodeCompleteMemberReferenceExpr(Scope *S, Expr *Base,
6158                                       SourceLocation OpLoc,
6159                                       bool IsArrow);
6160  void CodeCompletePostfixExpression(Scope *S, ExprResult LHS);
6161  void CodeCompleteTag(Scope *S, unsigned TagSpec);
6162  void CodeCompleteTypeQualifiers(DeclSpec &DS);
6163  void CodeCompleteCase(Scope *S);
6164  void CodeCompleteCall(Scope *S, Expr *Fn, Expr **Args, unsigned NumArgs);
6165  void CodeCompleteInitializer(Scope *S, Decl *D);
6166  void CodeCompleteReturn(Scope *S);
6167  void CodeCompleteAfterIf(Scope *S);
6168  void CodeCompleteAssignmentRHS(Scope *S, Expr *LHS);
6169
6170  void CodeCompleteQualifiedId(Scope *S, CXXScopeSpec &SS,
6171                               bool EnteringContext);
6172  void CodeCompleteUsing(Scope *S);
6173  void CodeCompleteUsingDirective(Scope *S);
6174  void CodeCompleteNamespaceDecl(Scope *S);
6175  void CodeCompleteNamespaceAliasDecl(Scope *S);
6176  void CodeCompleteOperatorName(Scope *S);
6177  void CodeCompleteConstructorInitializer(Decl *Constructor,
6178                                          CXXCtorInitializer** Initializers,
6179                                          unsigned NumInitializers);
6180
6181  void CodeCompleteObjCAtDirective(Scope *S);
6182  void CodeCompleteObjCAtVisibility(Scope *S);
6183  void CodeCompleteObjCAtStatement(Scope *S);
6184  void CodeCompleteObjCAtExpression(Scope *S);
6185  void CodeCompleteObjCPropertyFlags(Scope *S, ObjCDeclSpec &ODS);
6186  void CodeCompleteObjCPropertyGetter(Scope *S);
6187  void CodeCompleteObjCPropertySetter(Scope *S);
6188  void CodeCompleteObjCPassingType(Scope *S, ObjCDeclSpec &DS,
6189                                   bool IsParameter);
6190  void CodeCompleteObjCMessageReceiver(Scope *S);
6191  void CodeCompleteObjCSuperMessage(Scope *S, SourceLocation SuperLoc,
6192                                    IdentifierInfo **SelIdents,
6193                                    unsigned NumSelIdents,
6194                                    bool AtArgumentExpression);
6195  void CodeCompleteObjCClassMessage(Scope *S, ParsedType Receiver,
6196                                    IdentifierInfo **SelIdents,
6197                                    unsigned NumSelIdents,
6198                                    bool AtArgumentExpression,
6199                                    bool IsSuper = false);
6200  void CodeCompleteObjCInstanceMessage(Scope *S, Expr *Receiver,
6201                                       IdentifierInfo **SelIdents,
6202                                       unsigned NumSelIdents,
6203                                       bool AtArgumentExpression,
6204                                       ObjCInterfaceDecl *Super = 0);
6205  void CodeCompleteObjCForCollection(Scope *S,
6206                                     DeclGroupPtrTy IterationVar);
6207  void CodeCompleteObjCSelector(Scope *S,
6208                                IdentifierInfo **SelIdents,
6209                                unsigned NumSelIdents);
6210  void CodeCompleteObjCProtocolReferences(IdentifierLocPair *Protocols,
6211                                          unsigned NumProtocols);
6212  void CodeCompleteObjCProtocolDecl(Scope *S);
6213  void CodeCompleteObjCInterfaceDecl(Scope *S);
6214  void CodeCompleteObjCSuperclass(Scope *S,
6215                                  IdentifierInfo *ClassName,
6216                                  SourceLocation ClassNameLoc);
6217  void CodeCompleteObjCImplementationDecl(Scope *S);
6218  void CodeCompleteObjCInterfaceCategory(Scope *S,
6219                                         IdentifierInfo *ClassName,
6220                                         SourceLocation ClassNameLoc);
6221  void CodeCompleteObjCImplementationCategory(Scope *S,
6222                                              IdentifierInfo *ClassName,
6223                                              SourceLocation ClassNameLoc);
6224  void CodeCompleteObjCPropertyDefinition(Scope *S);
6225  void CodeCompleteObjCPropertySynthesizeIvar(Scope *S,
6226                                              IdentifierInfo *PropertyName);
6227  void CodeCompleteObjCMethodDecl(Scope *S,
6228                                  bool IsInstanceMethod,
6229                                  ParsedType ReturnType);
6230  void CodeCompleteObjCMethodDeclSelector(Scope *S,
6231                                          bool IsInstanceMethod,
6232                                          bool AtParameterName,
6233                                          ParsedType ReturnType,
6234                                          IdentifierInfo **SelIdents,
6235                                          unsigned NumSelIdents);
6236  void CodeCompletePreprocessorDirective(bool InConditional);
6237  void CodeCompleteInPreprocessorConditionalExclusion(Scope *S);
6238  void CodeCompletePreprocessorMacroName(bool IsDefinition);
6239  void CodeCompletePreprocessorExpression();
6240  void CodeCompletePreprocessorMacroArgument(Scope *S,
6241                                             IdentifierInfo *Macro,
6242                                             MacroInfo *MacroInfo,
6243                                             unsigned Argument);
6244  void CodeCompleteNaturalLanguage();
6245  void GatherGlobalCodeCompletions(CodeCompletionAllocator &Allocator,
6246                  SmallVectorImpl<CodeCompletionResult> &Results);
6247  //@}
6248
6249  //===--------------------------------------------------------------------===//
6250  // Extra semantic analysis beyond the C type system
6251
6252public:
6253  SourceLocation getLocationOfStringLiteralByte(const StringLiteral *SL,
6254                                                unsigned ByteNo) const;
6255
6256private:
6257  void CheckArrayAccess(const Expr *BaseExpr, const Expr *IndexExpr,
6258                        const ArraySubscriptExpr *ASE=0,
6259                        bool AllowOnePastEnd=true, bool IndexNegated=false);
6260  void CheckArrayAccess(const Expr *E);
6261  bool CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall);
6262  bool CheckObjCMethodCall(ObjCMethodDecl *Method, SourceLocation loc,
6263                           Expr **Args, unsigned NumArgs);
6264  bool CheckBlockCall(NamedDecl *NDecl, CallExpr *TheCall);
6265
6266  bool CheckablePrintfAttr(const FormatAttr *Format, Expr **Args,
6267                           unsigned NumArgs, bool IsCXXMemberCall);
6268  bool CheckObjCString(Expr *Arg);
6269
6270  ExprResult CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
6271  bool CheckARMBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
6272
6273  bool SemaBuiltinVAStart(CallExpr *TheCall);
6274  bool SemaBuiltinUnorderedCompare(CallExpr *TheCall);
6275  bool SemaBuiltinFPClassification(CallExpr *TheCall, unsigned NumArgs);
6276
6277public:
6278  // Used by C++ template instantiation.
6279  ExprResult SemaBuiltinShuffleVector(CallExpr *TheCall);
6280
6281private:
6282  bool SemaBuiltinPrefetch(CallExpr *TheCall);
6283  bool SemaBuiltinObjectSize(CallExpr *TheCall);
6284  bool SemaBuiltinLongjmp(CallExpr *TheCall);
6285  ExprResult SemaBuiltinAtomicOverloaded(ExprResult TheCallResult);
6286  ExprResult SemaAtomicOpsOverloaded(ExprResult TheCallResult,
6287                                     AtomicExpr::AtomicOp Op);
6288  bool SemaBuiltinConstantArg(CallExpr *TheCall, int ArgNum,
6289                              llvm::APSInt &Result);
6290
6291  bool SemaCheckStringLiteral(const Expr *E, Expr **Args, unsigned NumArgs,
6292                              bool HasVAListArg, unsigned format_idx,
6293                              unsigned firstDataArg, bool isPrintf,
6294                              bool inFunctionCall = true);
6295
6296  void CheckFormatString(const StringLiteral *FExpr, const Expr *OrigFormatExpr,
6297                         Expr **Args, unsigned NumArgs, bool HasVAListArg,
6298                         unsigned format_idx, unsigned firstDataArg,
6299                         bool isPrintf, bool inFunctionCall);
6300
6301  void CheckNonNullArguments(const NonNullAttr *NonNull,
6302                             const Expr * const *ExprArgs,
6303                             SourceLocation CallSiteLoc);
6304
6305  void CheckFormatArguments(const FormatAttr *Format, CallExpr *TheCall);
6306  void CheckFormatArguments(const FormatAttr *Format, Expr **Args,
6307                            unsigned NumArgs, bool IsCXXMember,
6308                            SourceLocation Loc, SourceRange Range);
6309  void CheckPrintfScanfArguments(Expr **Args, unsigned NumArgs,
6310                                 bool HasVAListArg, unsigned format_idx,
6311                                 unsigned firstDataArg, bool isPrintf,
6312                                 SourceLocation Loc, SourceRange range);
6313
6314  void CheckMemaccessArguments(const CallExpr *Call,
6315                               unsigned BId,
6316                               IdentifierInfo *FnName);
6317
6318  void CheckStrlcpycatArguments(const CallExpr *Call,
6319                                IdentifierInfo *FnName);
6320
6321  void CheckReturnStackAddr(Expr *RetValExp, QualType lhsType,
6322                            SourceLocation ReturnLoc);
6323  void CheckFloatComparison(SourceLocation Loc, Expr* LHS, Expr* RHS);
6324  void CheckImplicitConversions(Expr *E, SourceLocation CC = SourceLocation());
6325
6326  void CheckBitFieldInitialization(SourceLocation InitLoc, FieldDecl *Field,
6327                                   Expr *Init);
6328
6329  /// \brief The parser's current scope.
6330  ///
6331  /// The parser maintains this state here.
6332  Scope *CurScope;
6333
6334protected:
6335  friend class Parser;
6336  friend class InitializationSequence;
6337  friend class ASTReader;
6338  friend class ASTWriter;
6339
6340public:
6341  /// \brief Retrieve the parser's current scope.
6342  ///
6343  /// This routine must only be used when it is certain that semantic analysis
6344  /// and the parser are in precisely the same context, which is not the case
6345  /// when, e.g., we are performing any kind of template instantiation.
6346  /// Therefore, the only safe places to use this scope are in the parser
6347  /// itself and in routines directly invoked from the parser and *never* from
6348  /// template substitution or instantiation.
6349  Scope *getCurScope() const { return CurScope; }
6350
6351  Decl *getObjCDeclContext() const;
6352
6353  DeclContext *getCurLexicalContext() const {
6354    return OriginalLexicalContext ? OriginalLexicalContext : CurContext;
6355  }
6356
6357  AvailabilityResult getCurContextAvailability() const;
6358};
6359
6360/// \brief RAII object that enters a new expression evaluation context.
6361class EnterExpressionEvaluationContext {
6362  Sema &Actions;
6363
6364public:
6365  EnterExpressionEvaluationContext(Sema &Actions,
6366                                   Sema::ExpressionEvaluationContext NewContext)
6367    : Actions(Actions) {
6368    Actions.PushExpressionEvaluationContext(NewContext);
6369  }
6370
6371  ~EnterExpressionEvaluationContext() {
6372    Actions.PopExpressionEvaluationContext();
6373  }
6374};
6375
6376}  // end namespace clang
6377
6378#endif
6379