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