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