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