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