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