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