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