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