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