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