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