Sema.h revision 2b90f7637e846ea555dedac14e7f5065d85c5d3b
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 destructors seen during a class definition that had their 335 /// exception spec computation delayed because it depended on an unparsed 336 /// exception spec. 337 SmallVector<CXXDestructorDecl*, 2> DelayedDestructorExceptionSpecs; 338 339 /// \brief All the overriding destructors seen during a class definition 340 /// (there could be multiple due to nested classes) that had their exception 341 /// spec checks delayed, plus the overridden destructor. 342 SmallVector<std::pair<const CXXDestructorDecl*, 343 const CXXDestructorDecl*>, 2> 344 DelayedDestructorExceptionSpecChecks; 345 346 /// \brief Callback to the parser to parse templated functions when needed. 347 typedef void LateTemplateParserCB(void *P, const FunctionDecl *FD); 348 LateTemplateParserCB *LateTemplateParser; 349 void *OpaqueParser; 350 351 void SetLateTemplateParser(LateTemplateParserCB *LTP, void *P) { 352 LateTemplateParser = LTP; 353 OpaqueParser = P; 354 } 355 356 class DelayedDiagnostics; 357 358 class ParsingDeclState { 359 unsigned SavedStackSize; 360 friend class Sema::DelayedDiagnostics; 361 }; 362 363 class ProcessingContextState { 364 unsigned SavedParsingDepth; 365 unsigned SavedActiveStackBase; 366 friend class Sema::DelayedDiagnostics; 367 }; 368 369 /// A class which encapsulates the logic for delaying diagnostics 370 /// during parsing and other processing. 371 class DelayedDiagnostics { 372 /// \brief The stack of diagnostics that were delayed due to being 373 /// produced during the parsing of a declaration. 374 sema::DelayedDiagnostic *Stack; 375 376 /// \brief The number of objects on the delayed-diagnostics stack. 377 unsigned StackSize; 378 379 /// \brief The current capacity of the delayed-diagnostics stack. 380 unsigned StackCapacity; 381 382 /// \brief The index of the first "active" delayed diagnostic in 383 /// the stack. When parsing class definitions, we ignore active 384 /// delayed diagnostics from the surrounding context. 385 unsigned ActiveStackBase; 386 387 /// \brief The depth of the declarations we're currently parsing. 388 /// This gets saved and reset whenever we enter a class definition. 389 unsigned ParsingDepth; 390 391 public: 392 DelayedDiagnostics() : Stack(0), StackSize(0), StackCapacity(0), 393 ActiveStackBase(0), ParsingDepth(0) {} 394 395 ~DelayedDiagnostics() { 396 delete[] reinterpret_cast<char*>(Stack); 397 } 398 399 /// Adds a delayed diagnostic. 400 void add(const sema::DelayedDiagnostic &diag); 401 402 /// Determines whether diagnostics should be delayed. 403 bool shouldDelayDiagnostics() { return ParsingDepth > 0; } 404 405 /// Observe that we've started parsing a declaration. Access and 406 /// deprecation diagnostics will be delayed; when the declaration 407 /// is completed, all active delayed diagnostics will be evaluated 408 /// in its context, and then active diagnostics stack will be 409 /// popped down to the saved depth. 410 ParsingDeclState pushParsingDecl() { 411 ParsingDepth++; 412 413 ParsingDeclState state; 414 state.SavedStackSize = StackSize; 415 return state; 416 } 417 418 /// Observe that we're completed parsing a declaration. 419 static void popParsingDecl(Sema &S, ParsingDeclState state, Decl *decl); 420 421 /// Observe that we've started processing a different context, the 422 /// contents of which are semantically separate from the 423 /// declarations it may lexically appear in. This sets aside the 424 /// current stack of active diagnostics and starts afresh. 425 ProcessingContextState pushContext() { 426 assert(StackSize >= ActiveStackBase); 427 428 ProcessingContextState state; 429 state.SavedParsingDepth = ParsingDepth; 430 state.SavedActiveStackBase = ActiveStackBase; 431 432 ActiveStackBase = StackSize; 433 ParsingDepth = 0; 434 435 return state; 436 } 437 438 /// Observe that we've stopped processing a context. This 439 /// restores the previous stack of active diagnostics. 440 void popContext(ProcessingContextState state) { 441 assert(ActiveStackBase == StackSize); 442 assert(ParsingDepth == 0); 443 ActiveStackBase = state.SavedActiveStackBase; 444 ParsingDepth = state.SavedParsingDepth; 445 } 446 } DelayedDiagnostics; 447 448 /// A RAII object to temporarily push a declaration context. 449 class ContextRAII { 450 private: 451 Sema &S; 452 DeclContext *SavedContext; 453 ProcessingContextState SavedContextState; 454 QualType SavedCXXThisTypeOverride; 455 456 public: 457 ContextRAII(Sema &S, DeclContext *ContextToPush) 458 : S(S), SavedContext(S.CurContext), 459 SavedContextState(S.DelayedDiagnostics.pushContext()), 460 SavedCXXThisTypeOverride(S.CXXThisTypeOverride) 461 { 462 assert(ContextToPush && "pushing null context"); 463 S.CurContext = ContextToPush; 464 } 465 466 void pop() { 467 if (!SavedContext) return; 468 S.CurContext = SavedContext; 469 S.DelayedDiagnostics.popContext(SavedContextState); 470 S.CXXThisTypeOverride = SavedCXXThisTypeOverride; 471 SavedContext = 0; 472 } 473 474 ~ContextRAII() { 475 pop(); 476 } 477 }; 478 479 /// WeakUndeclaredIdentifiers - Identifiers contained in 480 /// #pragma weak before declared. rare. may alias another 481 /// identifier, declared or undeclared 482 llvm::DenseMap<IdentifierInfo*,WeakInfo> WeakUndeclaredIdentifiers; 483 484 /// ExtnameUndeclaredIdentifiers - Identifiers contained in 485 /// #pragma redefine_extname before declared. Used in Solaris system headers 486 /// to define functions that occur in multiple standards to call the version 487 /// in the currently selected standard. 488 llvm::DenseMap<IdentifierInfo*,AsmLabelAttr*> ExtnameUndeclaredIdentifiers; 489 490 491 /// \brief Load weak undeclared identifiers from the external source. 492 void LoadExternalWeakUndeclaredIdentifiers(); 493 494 /// WeakTopLevelDecl - Translation-unit scoped declarations generated by 495 /// #pragma weak during processing of other Decls. 496 /// I couldn't figure out a clean way to generate these in-line, so 497 /// we store them here and handle separately -- which is a hack. 498 /// It would be best to refactor this. 499 SmallVector<Decl*,2> WeakTopLevelDecl; 500 501 IdentifierResolver IdResolver; 502 503 /// Translation Unit Scope - useful to Objective-C actions that need 504 /// to lookup file scope declarations in the "ordinary" C decl namespace. 505 /// For example, user-defined classes, built-in "id" type, etc. 506 Scope *TUScope; 507 508 /// \brief The C++ "std" namespace, where the standard library resides. 509 LazyDeclPtr StdNamespace; 510 511 /// \brief The C++ "std::bad_alloc" class, which is defined by the C++ 512 /// standard library. 513 LazyDeclPtr StdBadAlloc; 514 515 /// \brief The C++ "std::initializer_list" template, which is defined in 516 /// <initializer_list>. 517 ClassTemplateDecl *StdInitializerList; 518 519 /// \brief The C++ "type_info" declaration, which is defined in <typeinfo>. 520 RecordDecl *CXXTypeInfoDecl; 521 522 /// \brief The MSVC "_GUID" struct, which is defined in MSVC header files. 523 RecordDecl *MSVCGuidDecl; 524 525 /// \brief Caches identifiers/selectors for NSFoundation APIs. 526 llvm::OwningPtr<NSAPI> NSAPIObj; 527 528 /// \brief The declaration of the Objective-C NSNumber class. 529 ObjCInterfaceDecl *NSNumberDecl; 530 531 /// \brief Pointer to NSNumber type (NSNumber *). 532 QualType NSNumberPointer; 533 534 /// \brief The Objective-C NSNumber methods used to create NSNumber literals. 535 ObjCMethodDecl *NSNumberLiteralMethods[NSAPI::NumNSNumberLiteralMethods]; 536 537 /// \brief The declaration of the Objective-C NSString class. 538 ObjCInterfaceDecl *NSStringDecl; 539 540 /// \brief Pointer to NSString type (NSString *). 541 QualType NSStringPointer; 542 543 /// \brief The declaration of the stringWithUTF8String: method. 544 ObjCMethodDecl *StringWithUTF8StringMethod; 545 546 /// \brief The declaration of the Objective-C NSArray class. 547 ObjCInterfaceDecl *NSArrayDecl; 548 549 /// \brief The declaration of the arrayWithObjects:count: method. 550 ObjCMethodDecl *ArrayWithObjectsMethod; 551 552 /// \brief The declaration of the Objective-C NSDictionary class. 553 ObjCInterfaceDecl *NSDictionaryDecl; 554 555 /// \brief The declaration of the dictionaryWithObjects:forKeys:count: method. 556 ObjCMethodDecl *DictionaryWithObjectsMethod; 557 558 /// \brief id<NSCopying> type. 559 QualType QIDNSCopying; 560 561 /// A flag to remember whether the implicit forms of operator new and delete 562 /// have been declared. 563 bool GlobalNewDeleteDeclared; 564 565 /// A flag that is set when parsing a -dealloc method and no [super dealloc] 566 /// call was found yet. 567 bool ObjCShouldCallSuperDealloc; 568 /// A flag that is set when parsing a -finalize method and no [super finalize] 569 /// call was found yet. 570 bool ObjCShouldCallSuperFinalize; 571 572 /// \brief Describes how the expressions currently being parsed are 573 /// evaluated at run-time, if at all. 574 enum ExpressionEvaluationContext { 575 /// \brief The current expression and its subexpressions occur within an 576 /// unevaluated operand (C++11 [expr]p7), such as the subexpression of 577 /// \c sizeof, where the type of the expression may be significant but 578 /// no code will be generated to evaluate the value of the expression at 579 /// run time. 580 Unevaluated, 581 582 /// \brief The current context is "potentially evaluated" in C++11 terms, 583 /// but the expression is evaluated at compile-time (like the values of 584 /// cases in a switch statment). 585 ConstantEvaluated, 586 587 /// \brief The current expression is potentially evaluated at run time, 588 /// which means that code may be generated to evaluate the value of the 589 /// expression at run time. 590 PotentiallyEvaluated, 591 592 /// \brief The current expression is potentially evaluated, but any 593 /// declarations referenced inside that expression are only used if 594 /// in fact the current expression is used. 595 /// 596 /// This value is used when parsing default function arguments, for which 597 /// we would like to provide diagnostics (e.g., passing non-POD arguments 598 /// through varargs) but do not want to mark declarations as "referenced" 599 /// until the default argument is used. 600 PotentiallyEvaluatedIfUsed 601 }; 602 603 /// \brief Data structure used to record current or nested 604 /// expression evaluation contexts. 605 struct ExpressionEvaluationContextRecord { 606 /// \brief The expression evaluation context. 607 ExpressionEvaluationContext Context; 608 609 /// \brief Whether the enclosing context needed a cleanup. 610 bool ParentNeedsCleanups; 611 612 /// \brief Whether we are in a decltype expression. 613 bool IsDecltype; 614 615 /// \brief The number of active cleanup objects when we entered 616 /// this expression evaluation context. 617 unsigned NumCleanupObjects; 618 619 llvm::SmallPtrSet<Expr*, 8> SavedMaybeODRUseExprs; 620 621 /// \brief The lambdas that are present within this context, if it 622 /// is indeed an unevaluated context. 623 llvm::SmallVector<LambdaExpr *, 2> Lambdas; 624 625 /// \brief The declaration that provides context for the lambda expression 626 /// if the normal declaration context does not suffice, e.g., in a 627 /// default function argument. 628 Decl *LambdaContextDecl; 629 630 /// \brief The context information used to mangle lambda expressions 631 /// within this context. 632 /// 633 /// This mangling information is allocated lazily, since most contexts 634 /// do not have lambda expressions. 635 LambdaMangleContext *LambdaMangle; 636 637 /// \brief If we are processing a decltype type, a set of call expressions 638 /// for which we have deferred checking the completeness of the return type. 639 llvm::SmallVector<CallExpr*, 8> DelayedDecltypeCalls; 640 641 /// \brief If we are processing a decltype type, a set of temporary binding 642 /// expressions for which we have deferred checking the destructor. 643 llvm::SmallVector<CXXBindTemporaryExpr*, 8> DelayedDecltypeBinds; 644 645 ExpressionEvaluationContextRecord(ExpressionEvaluationContext Context, 646 unsigned NumCleanupObjects, 647 bool ParentNeedsCleanups, 648 Decl *LambdaContextDecl, 649 bool IsDecltype) 650 : Context(Context), ParentNeedsCleanups(ParentNeedsCleanups), 651 IsDecltype(IsDecltype), NumCleanupObjects(NumCleanupObjects), 652 LambdaContextDecl(LambdaContextDecl), LambdaMangle() { } 653 654 ~ExpressionEvaluationContextRecord() { 655 delete LambdaMangle; 656 } 657 658 /// \brief Retrieve the mangling context for lambdas. 659 LambdaMangleContext &getLambdaMangleContext() { 660 assert(LambdaContextDecl && "Need to have a lambda context declaration"); 661 if (!LambdaMangle) 662 LambdaMangle = new LambdaMangleContext; 663 return *LambdaMangle; 664 } 665 }; 666 667 /// A stack of expression evaluation contexts. 668 SmallVector<ExpressionEvaluationContextRecord, 8> ExprEvalContexts; 669 670 /// SpecialMemberOverloadResult - The overloading result for a special member 671 /// function. 672 /// 673 /// This is basically a wrapper around PointerIntPair. The lowest bits of the 674 /// integer are used to determine whether overload resolution succeeded. 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 // This struct is for use by ActOnMemberAccess to allow 2707 // BuildMemberReferenceExpr to be able to reinvoke ActOnMemberAccess after 2708 // changing the access operator from a '.' to a '->' (to see if that is the 2709 // change needed to fix an error about an unknown member, e.g. when the class 2710 // defines a custom operator->). 2711 struct ActOnMemberAccessExtraArgs { 2712 Scope *S; 2713 UnqualifiedId &Id; 2714 Decl *ObjCImpDecl; 2715 bool HasTrailingLParen; 2716 }; 2717 2718 ExprResult BuildMemberReferenceExpr(Expr *Base, QualType BaseType, 2719 SourceLocation OpLoc, bool IsArrow, 2720 const CXXScopeSpec &SS, 2721 SourceLocation TemplateKWLoc, 2722 NamedDecl *FirstQualifierInScope, 2723 LookupResult &R, 2724 const TemplateArgumentListInfo *TemplateArgs, 2725 bool SuppressQualifierCheck = false, 2726 ActOnMemberAccessExtraArgs *ExtraArgs = 0); 2727 2728 ExprResult PerformMemberExprBaseConversion(Expr *Base, bool IsArrow); 2729 ExprResult LookupMemberExpr(LookupResult &R, ExprResult &Base, 2730 bool &IsArrow, SourceLocation OpLoc, 2731 CXXScopeSpec &SS, 2732 Decl *ObjCImpDecl, 2733 bool HasTemplateArgs); 2734 2735 bool CheckQualifiedMemberReference(Expr *BaseExpr, QualType BaseType, 2736 const CXXScopeSpec &SS, 2737 const LookupResult &R); 2738 2739 ExprResult ActOnDependentMemberExpr(Expr *Base, QualType BaseType, 2740 bool IsArrow, SourceLocation OpLoc, 2741 const CXXScopeSpec &SS, 2742 SourceLocation TemplateKWLoc, 2743 NamedDecl *FirstQualifierInScope, 2744 const DeclarationNameInfo &NameInfo, 2745 const TemplateArgumentListInfo *TemplateArgs); 2746 2747 ExprResult ActOnMemberAccessExpr(Scope *S, Expr *Base, 2748 SourceLocation OpLoc, 2749 tok::TokenKind OpKind, 2750 CXXScopeSpec &SS, 2751 SourceLocation TemplateKWLoc, 2752 UnqualifiedId &Member, 2753 Decl *ObjCImpDecl, 2754 bool HasTrailingLParen); 2755 2756 void ActOnDefaultCtorInitializers(Decl *CDtorDecl); 2757 bool ConvertArgumentsForCall(CallExpr *Call, Expr *Fn, 2758 FunctionDecl *FDecl, 2759 const FunctionProtoType *Proto, 2760 Expr **Args, unsigned NumArgs, 2761 SourceLocation RParenLoc, 2762 bool ExecConfig = false); 2763 void CheckStaticArrayArgument(SourceLocation CallLoc, 2764 ParmVarDecl *Param, 2765 const Expr *ArgExpr); 2766 2767 /// ActOnCallExpr - Handle a call to Fn with the specified array of arguments. 2768 /// This provides the location of the left/right parens and a list of comma 2769 /// locations. 2770 ExprResult ActOnCallExpr(Scope *S, Expr *Fn, SourceLocation LParenLoc, 2771 MultiExprArg ArgExprs, SourceLocation RParenLoc, 2772 Expr *ExecConfig = 0, bool IsExecConfig = false); 2773 ExprResult BuildResolvedCallExpr(Expr *Fn, NamedDecl *NDecl, 2774 SourceLocation LParenLoc, 2775 Expr **Args, unsigned NumArgs, 2776 SourceLocation RParenLoc, 2777 Expr *Config = 0, 2778 bool IsExecConfig = false); 2779 2780 ExprResult ActOnCUDAExecConfigExpr(Scope *S, SourceLocation LLLLoc, 2781 MultiExprArg ExecConfig, 2782 SourceLocation GGGLoc); 2783 2784 ExprResult ActOnCastExpr(Scope *S, SourceLocation LParenLoc, 2785 Declarator &D, ParsedType &Ty, 2786 SourceLocation RParenLoc, Expr *CastExpr); 2787 ExprResult BuildCStyleCastExpr(SourceLocation LParenLoc, 2788 TypeSourceInfo *Ty, 2789 SourceLocation RParenLoc, 2790 Expr *Op); 2791 CastKind PrepareScalarCast(ExprResult &src, QualType destType); 2792 2793 /// \brief Build an altivec or OpenCL literal. 2794 ExprResult BuildVectorLiteral(SourceLocation LParenLoc, 2795 SourceLocation RParenLoc, Expr *E, 2796 TypeSourceInfo *TInfo); 2797 2798 ExprResult MaybeConvertParenListExprToParenExpr(Scope *S, Expr *ME); 2799 2800 ExprResult ActOnCompoundLiteral(SourceLocation LParenLoc, 2801 ParsedType Ty, 2802 SourceLocation RParenLoc, 2803 Expr *InitExpr); 2804 2805 ExprResult BuildCompoundLiteralExpr(SourceLocation LParenLoc, 2806 TypeSourceInfo *TInfo, 2807 SourceLocation RParenLoc, 2808 Expr *LiteralExpr); 2809 2810 ExprResult ActOnInitList(SourceLocation LBraceLoc, 2811 MultiExprArg InitArgList, 2812 SourceLocation RBraceLoc); 2813 2814 ExprResult ActOnDesignatedInitializer(Designation &Desig, 2815 SourceLocation Loc, 2816 bool GNUSyntax, 2817 ExprResult Init); 2818 2819 ExprResult ActOnBinOp(Scope *S, SourceLocation TokLoc, 2820 tok::TokenKind Kind, Expr *LHSExpr, Expr *RHSExpr); 2821 ExprResult BuildBinOp(Scope *S, SourceLocation OpLoc, 2822 BinaryOperatorKind Opc, Expr *LHSExpr, Expr *RHSExpr); 2823 ExprResult CreateBuiltinBinOp(SourceLocation OpLoc, BinaryOperatorKind Opc, 2824 Expr *LHSExpr, Expr *RHSExpr); 2825 2826 /// ActOnConditionalOp - Parse a ?: operation. Note that 'LHS' may be null 2827 /// in the case of a the GNU conditional expr extension. 2828 ExprResult ActOnConditionalOp(SourceLocation QuestionLoc, 2829 SourceLocation ColonLoc, 2830 Expr *CondExpr, Expr *LHSExpr, Expr *RHSExpr); 2831 2832 /// ActOnAddrLabel - Parse the GNU address of label extension: "&&foo". 2833 ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc, 2834 LabelDecl *TheDecl); 2835 2836 void ActOnStartStmtExpr(); 2837 ExprResult ActOnStmtExpr(SourceLocation LPLoc, Stmt *SubStmt, 2838 SourceLocation RPLoc); // "({..})" 2839 void ActOnStmtExprError(); 2840 2841 // __builtin_offsetof(type, identifier(.identifier|[expr])*) 2842 struct OffsetOfComponent { 2843 SourceLocation LocStart, LocEnd; 2844 bool isBrackets; // true if [expr], false if .ident 2845 union { 2846 IdentifierInfo *IdentInfo; 2847 Expr *E; 2848 } U; 2849 }; 2850 2851 /// __builtin_offsetof(type, a.b[123][456].c) 2852 ExprResult BuildBuiltinOffsetOf(SourceLocation BuiltinLoc, 2853 TypeSourceInfo *TInfo, 2854 OffsetOfComponent *CompPtr, 2855 unsigned NumComponents, 2856 SourceLocation RParenLoc); 2857 ExprResult ActOnBuiltinOffsetOf(Scope *S, 2858 SourceLocation BuiltinLoc, 2859 SourceLocation TypeLoc, 2860 ParsedType ParsedArgTy, 2861 OffsetOfComponent *CompPtr, 2862 unsigned NumComponents, 2863 SourceLocation RParenLoc); 2864 2865 // __builtin_choose_expr(constExpr, expr1, expr2) 2866 ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc, 2867 Expr *CondExpr, Expr *LHSExpr, 2868 Expr *RHSExpr, SourceLocation RPLoc); 2869 2870 // __builtin_va_arg(expr, type) 2871 ExprResult ActOnVAArg(SourceLocation BuiltinLoc, Expr *E, ParsedType Ty, 2872 SourceLocation RPLoc); 2873 ExprResult BuildVAArgExpr(SourceLocation BuiltinLoc, Expr *E, 2874 TypeSourceInfo *TInfo, SourceLocation RPLoc); 2875 2876 // __null 2877 ExprResult ActOnGNUNullExpr(SourceLocation TokenLoc); 2878 2879 bool CheckCaseExpression(Expr *E); 2880 2881 /// \brief Describes the result of an "if-exists" condition check. 2882 enum IfExistsResult { 2883 /// \brief The symbol exists. 2884 IER_Exists, 2885 2886 /// \brief The symbol does not exist. 2887 IER_DoesNotExist, 2888 2889 /// \brief The name is a dependent name, so the results will differ 2890 /// from one instantiation to the next. 2891 IER_Dependent, 2892 2893 /// \brief An error occurred. 2894 IER_Error 2895 }; 2896 2897 IfExistsResult 2898 CheckMicrosoftIfExistsSymbol(Scope *S, CXXScopeSpec &SS, 2899 const DeclarationNameInfo &TargetNameInfo); 2900 2901 IfExistsResult 2902 CheckMicrosoftIfExistsSymbol(Scope *S, SourceLocation KeywordLoc, 2903 bool IsIfExists, CXXScopeSpec &SS, 2904 UnqualifiedId &Name); 2905 2906 StmtResult BuildMSDependentExistsStmt(SourceLocation KeywordLoc, 2907 bool IsIfExists, 2908 NestedNameSpecifierLoc QualifierLoc, 2909 DeclarationNameInfo NameInfo, 2910 Stmt *Nested); 2911 StmtResult ActOnMSDependentExistsStmt(SourceLocation KeywordLoc, 2912 bool IsIfExists, 2913 CXXScopeSpec &SS, UnqualifiedId &Name, 2914 Stmt *Nested); 2915 2916 //===------------------------- "Block" Extension ------------------------===// 2917 2918 /// ActOnBlockStart - This callback is invoked when a block literal is 2919 /// started. 2920 void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope); 2921 2922 /// ActOnBlockArguments - This callback allows processing of block arguments. 2923 /// If there are no arguments, this is still invoked. 2924 void ActOnBlockArguments(Declarator &ParamInfo, Scope *CurScope); 2925 2926 /// ActOnBlockError - If there is an error parsing a block, this callback 2927 /// is invoked to pop the information about the block from the action impl. 2928 void ActOnBlockError(SourceLocation CaretLoc, Scope *CurScope); 2929 2930 /// ActOnBlockStmtExpr - This is called when the body of a block statement 2931 /// literal was successfully completed. ^(int x){...} 2932 ExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc, Stmt *Body, 2933 Scope *CurScope); 2934 2935 //===---------------------------- OpenCL Features -----------------------===// 2936 2937 /// __builtin_astype(...) 2938 ExprResult ActOnAsTypeExpr(Expr *E, ParsedType ParsedDestTy, 2939 SourceLocation BuiltinLoc, 2940 SourceLocation RParenLoc); 2941 2942 //===---------------------------- C++ Features --------------------------===// 2943 2944 // Act on C++ namespaces 2945 Decl *ActOnStartNamespaceDef(Scope *S, SourceLocation InlineLoc, 2946 SourceLocation NamespaceLoc, 2947 SourceLocation IdentLoc, 2948 IdentifierInfo *Ident, 2949 SourceLocation LBrace, 2950 AttributeList *AttrList); 2951 void ActOnFinishNamespaceDef(Decl *Dcl, SourceLocation RBrace); 2952 2953 NamespaceDecl *getStdNamespace() const; 2954 NamespaceDecl *getOrCreateStdNamespace(); 2955 2956 CXXRecordDecl *getStdBadAlloc() const; 2957 2958 /// \brief Tests whether Ty is an instance of std::initializer_list and, if 2959 /// it is and Element is not NULL, assigns the element type to Element. 2960 bool isStdInitializerList(QualType Ty, QualType *Element); 2961 2962 /// \brief Looks for the std::initializer_list template and instantiates it 2963 /// with Element, or emits an error if it's not found. 2964 /// 2965 /// \returns The instantiated template, or null on error. 2966 QualType BuildStdInitializerList(QualType Element, SourceLocation Loc); 2967 2968 /// \brief Determine whether Ctor is an initializer-list constructor, as 2969 /// defined in [dcl.init.list]p2. 2970 bool isInitListConstructor(const CXXConstructorDecl *Ctor); 2971 2972 Decl *ActOnUsingDirective(Scope *CurScope, 2973 SourceLocation UsingLoc, 2974 SourceLocation NamespcLoc, 2975 CXXScopeSpec &SS, 2976 SourceLocation IdentLoc, 2977 IdentifierInfo *NamespcName, 2978 AttributeList *AttrList); 2979 2980 void PushUsingDirective(Scope *S, UsingDirectiveDecl *UDir); 2981 2982 Decl *ActOnNamespaceAliasDef(Scope *CurScope, 2983 SourceLocation NamespaceLoc, 2984 SourceLocation AliasLoc, 2985 IdentifierInfo *Alias, 2986 CXXScopeSpec &SS, 2987 SourceLocation IdentLoc, 2988 IdentifierInfo *Ident); 2989 2990 void HideUsingShadowDecl(Scope *S, UsingShadowDecl *Shadow); 2991 bool CheckUsingShadowDecl(UsingDecl *UD, NamedDecl *Target, 2992 const LookupResult &PreviousDecls); 2993 UsingShadowDecl *BuildUsingShadowDecl(Scope *S, UsingDecl *UD, 2994 NamedDecl *Target); 2995 2996 bool CheckUsingDeclRedeclaration(SourceLocation UsingLoc, 2997 bool isTypeName, 2998 const CXXScopeSpec &SS, 2999 SourceLocation NameLoc, 3000 const LookupResult &Previous); 3001 bool CheckUsingDeclQualifier(SourceLocation UsingLoc, 3002 const CXXScopeSpec &SS, 3003 SourceLocation NameLoc); 3004 3005 NamedDecl *BuildUsingDeclaration(Scope *S, AccessSpecifier AS, 3006 SourceLocation UsingLoc, 3007 CXXScopeSpec &SS, 3008 const DeclarationNameInfo &NameInfo, 3009 AttributeList *AttrList, 3010 bool IsInstantiation, 3011 bool IsTypeName, 3012 SourceLocation TypenameLoc); 3013 3014 bool CheckInheritingConstructorUsingDecl(UsingDecl *UD); 3015 3016 Decl *ActOnUsingDeclaration(Scope *CurScope, 3017 AccessSpecifier AS, 3018 bool HasUsingKeyword, 3019 SourceLocation UsingLoc, 3020 CXXScopeSpec &SS, 3021 UnqualifiedId &Name, 3022 AttributeList *AttrList, 3023 bool IsTypeName, 3024 SourceLocation TypenameLoc); 3025 Decl *ActOnAliasDeclaration(Scope *CurScope, 3026 AccessSpecifier AS, 3027 MultiTemplateParamsArg TemplateParams, 3028 SourceLocation UsingLoc, 3029 UnqualifiedId &Name, 3030 TypeResult Type); 3031 3032 /// InitializeVarWithConstructor - Creates an CXXConstructExpr 3033 /// and sets it as the initializer for the the passed in VarDecl. 3034 bool InitializeVarWithConstructor(VarDecl *VD, 3035 CXXConstructorDecl *Constructor, 3036 MultiExprArg Exprs, 3037 bool HadMultipleCandidates); 3038 3039 /// BuildCXXConstructExpr - Creates a complete call to a constructor, 3040 /// including handling of its default argument expressions. 3041 /// 3042 /// \param ConstructKind - a CXXConstructExpr::ConstructionKind 3043 ExprResult 3044 BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType, 3045 CXXConstructorDecl *Constructor, MultiExprArg Exprs, 3046 bool HadMultipleCandidates, bool RequiresZeroInit, 3047 unsigned ConstructKind, SourceRange ParenRange); 3048 3049 // FIXME: Can re remove this and have the above BuildCXXConstructExpr check if 3050 // the constructor can be elidable? 3051 ExprResult 3052 BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType, 3053 CXXConstructorDecl *Constructor, bool Elidable, 3054 MultiExprArg Exprs, bool HadMultipleCandidates, 3055 bool RequiresZeroInit, unsigned ConstructKind, 3056 SourceRange ParenRange); 3057 3058 /// BuildCXXDefaultArgExpr - Creates a CXXDefaultArgExpr, instantiating 3059 /// the default expr if needed. 3060 ExprResult BuildCXXDefaultArgExpr(SourceLocation CallLoc, 3061 FunctionDecl *FD, 3062 ParmVarDecl *Param); 3063 3064 /// FinalizeVarWithDestructor - Prepare for calling destructor on the 3065 /// constructed variable. 3066 void FinalizeVarWithDestructor(VarDecl *VD, const RecordType *DeclInitType); 3067 3068 /// \brief Helper class that collects exception specifications for 3069 /// implicitly-declared special member functions. 3070 class ImplicitExceptionSpecification { 3071 // Pointer to allow copying 3072 Sema *Self; 3073 // We order exception specifications thus: 3074 // noexcept is the most restrictive, but is only used in C++0x. 3075 // throw() comes next. 3076 // Then a throw(collected exceptions) 3077 // Finally no specification. 3078 // throw(...) is used instead if any called function uses it. 3079 // 3080 // If this exception specification cannot be known yet (for instance, 3081 // because this is the exception specification for a defaulted default 3082 // constructor and we haven't finished parsing the deferred parts of the 3083 // class yet), the C++0x standard does not specify how to behave. We 3084 // record this as an 'unknown' exception specification, which overrules 3085 // any other specification (even 'none', to keep this rule simple). 3086 ExceptionSpecificationType ComputedEST; 3087 llvm::SmallPtrSet<CanQualType, 4> ExceptionsSeen; 3088 SmallVector<QualType, 4> Exceptions; 3089 3090 void ClearExceptions() { 3091 ExceptionsSeen.clear(); 3092 Exceptions.clear(); 3093 } 3094 3095 public: 3096 explicit ImplicitExceptionSpecification(Sema &Self) 3097 : Self(&Self), ComputedEST(EST_BasicNoexcept) { 3098 if (!Self.Context.getLangOpts().CPlusPlus0x) 3099 ComputedEST = EST_DynamicNone; 3100 } 3101 3102 /// \brief Get the computed exception specification type. 3103 ExceptionSpecificationType getExceptionSpecType() const { 3104 assert(ComputedEST != EST_ComputedNoexcept && 3105 "noexcept(expr) should not be a possible result"); 3106 return ComputedEST; 3107 } 3108 3109 /// \brief The number of exceptions in the exception specification. 3110 unsigned size() const { return Exceptions.size(); } 3111 3112 /// \brief The set of exceptions in the exception specification. 3113 const QualType *data() const { return Exceptions.data(); } 3114 3115 /// \brief Integrate another called method into the collected data. 3116 void CalledDecl(SourceLocation CallLoc, CXXMethodDecl *Method); 3117 3118 /// \brief Integrate an invoked expression into the collected data. 3119 void CalledExpr(Expr *E); 3120 3121 /// \brief Specify that the exception specification can't be detemined yet. 3122 void SetDelayed() { 3123 ClearExceptions(); 3124 ComputedEST = EST_Delayed; 3125 } 3126 3127 FunctionProtoType::ExtProtoInfo getEPI() const { 3128 FunctionProtoType::ExtProtoInfo EPI; 3129 EPI.ExceptionSpecType = getExceptionSpecType(); 3130 EPI.NumExceptions = size(); 3131 EPI.Exceptions = data(); 3132 return EPI; 3133 } 3134 }; 3135 3136 /// \brief Determine what sort of exception specification a defaulted 3137 /// copy constructor of a class will have. 3138 ImplicitExceptionSpecification 3139 ComputeDefaultedDefaultCtorExceptionSpec(CXXRecordDecl *ClassDecl); 3140 3141 /// \brief Determine what sort of exception specification a defaulted 3142 /// default constructor of a class will have, and whether the parameter 3143 /// will be const. 3144 std::pair<ImplicitExceptionSpecification, bool> 3145 ComputeDefaultedCopyCtorExceptionSpecAndConst(CXXRecordDecl *ClassDecl); 3146 3147 /// \brief Determine what sort of exception specification a defautled 3148 /// copy assignment operator of a class will have, and whether the 3149 /// parameter will be const. 3150 std::pair<ImplicitExceptionSpecification, bool> 3151 ComputeDefaultedCopyAssignmentExceptionSpecAndConst(CXXRecordDecl *ClassDecl); 3152 3153 /// \brief Determine what sort of exception specification a defaulted move 3154 /// constructor of a class will have. 3155 ImplicitExceptionSpecification 3156 ComputeDefaultedMoveCtorExceptionSpec(CXXRecordDecl *ClassDecl); 3157 3158 /// \brief Determine what sort of exception specification a defaulted move 3159 /// assignment operator of a class will have. 3160 ImplicitExceptionSpecification 3161 ComputeDefaultedMoveAssignmentExceptionSpec(CXXRecordDecl *ClassDecl); 3162 3163 /// \brief Determine what sort of exception specification a defaulted 3164 /// destructor of a class will have. 3165 ImplicitExceptionSpecification 3166 ComputeDefaultedDtorExceptionSpec(CXXRecordDecl *ClassDecl); 3167 3168 /// \brief Check the given exception-specification and update the 3169 /// extended prototype information with the results. 3170 void checkExceptionSpecification(ExceptionSpecificationType EST, 3171 ArrayRef<ParsedType> DynamicExceptions, 3172 ArrayRef<SourceRange> DynamicExceptionRanges, 3173 Expr *NoexceptExpr, 3174 llvm::SmallVectorImpl<QualType> &Exceptions, 3175 FunctionProtoType::ExtProtoInfo &EPI); 3176 3177 /// \brief Add an exception-specification to the given member function 3178 /// (or member function template). The exception-specification was parsed 3179 /// after the method itself was declared. 3180 void actOnDelayedExceptionSpecification(Decl *Method, 3181 ExceptionSpecificationType EST, 3182 SourceRange SpecificationRange, 3183 ArrayRef<ParsedType> DynamicExceptions, 3184 ArrayRef<SourceRange> DynamicExceptionRanges, 3185 Expr *NoexceptExpr); 3186 3187 /// \brief Determine if a special member function should have a deleted 3188 /// definition when it is defaulted. 3189 bool ShouldDeleteSpecialMember(CXXMethodDecl *MD, CXXSpecialMember CSM, 3190 bool Diagnose = false); 3191 3192 /// \brief Declare the implicit default constructor for the given class. 3193 /// 3194 /// \param ClassDecl The class declaration into which the implicit 3195 /// default constructor will be added. 3196 /// 3197 /// \returns The implicitly-declared default constructor. 3198 CXXConstructorDecl *DeclareImplicitDefaultConstructor( 3199 CXXRecordDecl *ClassDecl); 3200 3201 /// DefineImplicitDefaultConstructor - Checks for feasibility of 3202 /// defining this constructor as the default constructor. 3203 void DefineImplicitDefaultConstructor(SourceLocation CurrentLocation, 3204 CXXConstructorDecl *Constructor); 3205 3206 /// \brief Declare the implicit destructor for the given class. 3207 /// 3208 /// \param ClassDecl The class declaration into which the implicit 3209 /// destructor will be added. 3210 /// 3211 /// \returns The implicitly-declared destructor. 3212 CXXDestructorDecl *DeclareImplicitDestructor(CXXRecordDecl *ClassDecl); 3213 3214 /// DefineImplicitDestructor - Checks for feasibility of 3215 /// defining this destructor as the default destructor. 3216 void DefineImplicitDestructor(SourceLocation CurrentLocation, 3217 CXXDestructorDecl *Destructor); 3218 3219 /// \brief Build an exception spec for destructors that don't have one. 3220 /// 3221 /// C++11 says that user-defined destructors with no exception spec get one 3222 /// that looks as if the destructor was implicitly declared. 3223 void AdjustDestructorExceptionSpec(CXXRecordDecl *ClassDecl, 3224 CXXDestructorDecl *Destructor, 3225 bool WasDelayed = false); 3226 3227 /// \brief Declare all inherited constructors for the given class. 3228 /// 3229 /// \param ClassDecl The class declaration into which the inherited 3230 /// constructors will be added. 3231 void DeclareInheritedConstructors(CXXRecordDecl *ClassDecl); 3232 3233 /// \brief Declare the implicit copy constructor for the given class. 3234 /// 3235 /// \param ClassDecl The class declaration into which the implicit 3236 /// copy constructor will be added. 3237 /// 3238 /// \returns The implicitly-declared copy constructor. 3239 CXXConstructorDecl *DeclareImplicitCopyConstructor(CXXRecordDecl *ClassDecl); 3240 3241 /// DefineImplicitCopyConstructor - Checks for feasibility of 3242 /// defining this constructor as the copy constructor. 3243 void DefineImplicitCopyConstructor(SourceLocation CurrentLocation, 3244 CXXConstructorDecl *Constructor); 3245 3246 /// \brief Declare the implicit move constructor for the given class. 3247 /// 3248 /// \param ClassDecl The Class declaration into which the implicit 3249 /// move constructor will be added. 3250 /// 3251 /// \returns The implicitly-declared move constructor, or NULL if it wasn't 3252 /// declared. 3253 CXXConstructorDecl *DeclareImplicitMoveConstructor(CXXRecordDecl *ClassDecl); 3254 3255 /// DefineImplicitMoveConstructor - Checks for feasibility of 3256 /// defining this constructor as the move constructor. 3257 void DefineImplicitMoveConstructor(SourceLocation CurrentLocation, 3258 CXXConstructorDecl *Constructor); 3259 3260 /// \brief Declare the implicit copy assignment operator for the given class. 3261 /// 3262 /// \param ClassDecl The class declaration into which the implicit 3263 /// copy assignment operator will be added. 3264 /// 3265 /// \returns The implicitly-declared copy assignment operator. 3266 CXXMethodDecl *DeclareImplicitCopyAssignment(CXXRecordDecl *ClassDecl); 3267 3268 /// \brief Defines an implicitly-declared copy assignment operator. 3269 void DefineImplicitCopyAssignment(SourceLocation CurrentLocation, 3270 CXXMethodDecl *MethodDecl); 3271 3272 /// \brief Declare the implicit move assignment operator for the given class. 3273 /// 3274 /// \param ClassDecl The Class declaration into which the implicit 3275 /// move assignment operator will be added. 3276 /// 3277 /// \returns The implicitly-declared move assignment operator, or NULL if it 3278 /// wasn't declared. 3279 CXXMethodDecl *DeclareImplicitMoveAssignment(CXXRecordDecl *ClassDecl); 3280 3281 /// \brief Defines an implicitly-declared move assignment operator. 3282 void DefineImplicitMoveAssignment(SourceLocation CurrentLocation, 3283 CXXMethodDecl *MethodDecl); 3284 3285 /// \brief Force the declaration of any implicitly-declared members of this 3286 /// class. 3287 void ForceDeclarationOfImplicitMembers(CXXRecordDecl *Class); 3288 3289 /// \brief Determine whether the given function is an implicitly-deleted 3290 /// special member function. 3291 bool isImplicitlyDeleted(FunctionDecl *FD); 3292 3293 /// \brief Check whether 'this' shows up in the type of a static member 3294 /// function after the (naturally empty) cv-qualifier-seq would be. 3295 /// 3296 /// \returns true if an error occurred. 3297 bool checkThisInStaticMemberFunctionType(CXXMethodDecl *Method); 3298 3299 /// \brief Whether this' shows up in the exception specification of a static 3300 /// member function. 3301 bool checkThisInStaticMemberFunctionExceptionSpec(CXXMethodDecl *Method); 3302 3303 /// \brief Check whether 'this' shows up in the attributes of the given 3304 /// static member function. 3305 /// 3306 /// \returns true if an error occurred. 3307 bool checkThisInStaticMemberFunctionAttributes(CXXMethodDecl *Method); 3308 3309 /// MaybeBindToTemporary - If the passed in expression has a record type with 3310 /// a non-trivial destructor, this will return CXXBindTemporaryExpr. Otherwise 3311 /// it simply returns the passed in expression. 3312 ExprResult MaybeBindToTemporary(Expr *E); 3313 3314 bool CompleteConstructorCall(CXXConstructorDecl *Constructor, 3315 MultiExprArg ArgsPtr, 3316 SourceLocation Loc, 3317 ASTOwningVector<Expr*> &ConvertedArgs, 3318 bool AllowExplicit = false); 3319 3320 ParsedType getDestructorName(SourceLocation TildeLoc, 3321 IdentifierInfo &II, SourceLocation NameLoc, 3322 Scope *S, CXXScopeSpec &SS, 3323 ParsedType ObjectType, 3324 bool EnteringContext); 3325 3326 ParsedType getDestructorType(const DeclSpec& DS, ParsedType ObjectType); 3327 3328 // Checks that reinterpret casts don't have undefined behavior. 3329 void CheckCompatibleReinterpretCast(QualType SrcType, QualType DestType, 3330 bool IsDereference, SourceRange Range); 3331 3332 /// ActOnCXXNamedCast - Parse {dynamic,static,reinterpret,const}_cast's. 3333 ExprResult ActOnCXXNamedCast(SourceLocation OpLoc, 3334 tok::TokenKind Kind, 3335 SourceLocation LAngleBracketLoc, 3336 Declarator &D, 3337 SourceLocation RAngleBracketLoc, 3338 SourceLocation LParenLoc, 3339 Expr *E, 3340 SourceLocation RParenLoc); 3341 3342 ExprResult BuildCXXNamedCast(SourceLocation OpLoc, 3343 tok::TokenKind Kind, 3344 TypeSourceInfo *Ty, 3345 Expr *E, 3346 SourceRange AngleBrackets, 3347 SourceRange Parens); 3348 3349 ExprResult BuildCXXTypeId(QualType TypeInfoType, 3350 SourceLocation TypeidLoc, 3351 TypeSourceInfo *Operand, 3352 SourceLocation RParenLoc); 3353 ExprResult BuildCXXTypeId(QualType TypeInfoType, 3354 SourceLocation TypeidLoc, 3355 Expr *Operand, 3356 SourceLocation RParenLoc); 3357 3358 /// ActOnCXXTypeid - Parse typeid( something ). 3359 ExprResult ActOnCXXTypeid(SourceLocation OpLoc, 3360 SourceLocation LParenLoc, bool isType, 3361 void *TyOrExpr, 3362 SourceLocation RParenLoc); 3363 3364 ExprResult BuildCXXUuidof(QualType TypeInfoType, 3365 SourceLocation TypeidLoc, 3366 TypeSourceInfo *Operand, 3367 SourceLocation RParenLoc); 3368 ExprResult BuildCXXUuidof(QualType TypeInfoType, 3369 SourceLocation TypeidLoc, 3370 Expr *Operand, 3371 SourceLocation RParenLoc); 3372 3373 /// ActOnCXXUuidof - Parse __uuidof( something ). 3374 ExprResult ActOnCXXUuidof(SourceLocation OpLoc, 3375 SourceLocation LParenLoc, bool isType, 3376 void *TyOrExpr, 3377 SourceLocation RParenLoc); 3378 3379 3380 //// ActOnCXXThis - Parse 'this' pointer. 3381 ExprResult ActOnCXXThis(SourceLocation loc); 3382 3383 /// \brief Try to retrieve the type of the 'this' pointer. 3384 /// 3385 /// \param Capture If true, capture 'this' in this context. 3386 /// 3387 /// \returns The type of 'this', if possible. Otherwise, returns a NULL type. 3388 QualType getCurrentThisType(); 3389 3390 /// \brief When non-NULL, the C++ 'this' expression is allowed despite the 3391 /// current context not being a non-static member function. In such cases, 3392 /// this provides the type used for 'this'. 3393 QualType CXXThisTypeOverride; 3394 3395 /// \brief RAII object used to temporarily allow the C++ 'this' expression 3396 /// to be used, with the given qualifiers on the current class type. 3397 class CXXThisScopeRAII { 3398 Sema &S; 3399 QualType OldCXXThisTypeOverride; 3400 bool Enabled; 3401 3402 public: 3403 /// \brief Introduce a new scope where 'this' may be allowed (when enabled), 3404 /// using the given declaration (which is either a class template or a 3405 /// class) along with the given qualifiers. 3406 /// along with the qualifiers placed on '*this'. 3407 CXXThisScopeRAII(Sema &S, Decl *ContextDecl, unsigned CXXThisTypeQuals, 3408 bool Enabled = true); 3409 3410 ~CXXThisScopeRAII(); 3411 }; 3412 3413 /// \brief Make sure the value of 'this' is actually available in the current 3414 /// context, if it is a potentially evaluated context. 3415 /// 3416 /// \param Loc The location at which the capture of 'this' occurs. 3417 /// 3418 /// \param Explicit Whether 'this' is explicitly captured in a lambda 3419 /// capture list. 3420 void CheckCXXThisCapture(SourceLocation Loc, bool Explicit = false); 3421 3422 /// \brief Determine whether the given type is the type of *this that is used 3423 /// outside of the body of a member function for a type that is currently 3424 /// being defined. 3425 bool isThisOutsideMemberFunctionBody(QualType BaseType); 3426 3427 /// ActOnCXXBoolLiteral - Parse {true,false} literals. 3428 ExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind); 3429 3430 3431 /// ActOnObjCBoolLiteral - Parse {__objc_yes,__objc_no} literals. 3432 ExprResult ActOnObjCBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind); 3433 3434 /// ActOnCXXNullPtrLiteral - Parse 'nullptr'. 3435 ExprResult ActOnCXXNullPtrLiteral(SourceLocation Loc); 3436 3437 //// ActOnCXXThrow - Parse throw expressions. 3438 ExprResult ActOnCXXThrow(Scope *S, SourceLocation OpLoc, Expr *expr); 3439 ExprResult BuildCXXThrow(SourceLocation OpLoc, Expr *Ex, 3440 bool IsThrownVarInScope); 3441 ExprResult CheckCXXThrowOperand(SourceLocation ThrowLoc, Expr *E, 3442 bool IsThrownVarInScope); 3443 3444 /// ActOnCXXTypeConstructExpr - Parse construction of a specified type. 3445 /// Can be interpreted either as function-style casting ("int(x)") 3446 /// or class type construction ("ClassType(x,y,z)") 3447 /// or creation of a value-initialized type ("int()"). 3448 ExprResult ActOnCXXTypeConstructExpr(ParsedType TypeRep, 3449 SourceLocation LParenLoc, 3450 MultiExprArg Exprs, 3451 SourceLocation RParenLoc); 3452 3453 ExprResult BuildCXXTypeConstructExpr(TypeSourceInfo *Type, 3454 SourceLocation LParenLoc, 3455 MultiExprArg Exprs, 3456 SourceLocation RParenLoc); 3457 3458 /// ActOnCXXNew - Parsed a C++ 'new' expression. 3459 ExprResult ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal, 3460 SourceLocation PlacementLParen, 3461 MultiExprArg PlacementArgs, 3462 SourceLocation PlacementRParen, 3463 SourceRange TypeIdParens, Declarator &D, 3464 Expr *Initializer); 3465 ExprResult BuildCXXNew(SourceLocation StartLoc, bool UseGlobal, 3466 SourceLocation PlacementLParen, 3467 MultiExprArg PlacementArgs, 3468 SourceLocation PlacementRParen, 3469 SourceRange TypeIdParens, 3470 QualType AllocType, 3471 TypeSourceInfo *AllocTypeInfo, 3472 Expr *ArraySize, 3473 SourceRange DirectInitRange, 3474 Expr *Initializer, 3475 bool TypeMayContainAuto = true); 3476 3477 bool CheckAllocatedType(QualType AllocType, SourceLocation Loc, 3478 SourceRange R); 3479 bool FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range, 3480 bool UseGlobal, QualType AllocType, bool IsArray, 3481 Expr **PlaceArgs, unsigned NumPlaceArgs, 3482 FunctionDecl *&OperatorNew, 3483 FunctionDecl *&OperatorDelete); 3484 bool FindAllocationOverload(SourceLocation StartLoc, SourceRange Range, 3485 DeclarationName Name, Expr** Args, 3486 unsigned NumArgs, DeclContext *Ctx, 3487 bool AllowMissing, FunctionDecl *&Operator, 3488 bool Diagnose = true); 3489 void DeclareGlobalNewDelete(); 3490 void DeclareGlobalAllocationFunction(DeclarationName Name, QualType Return, 3491 QualType Argument, 3492 bool addMallocAttr = false); 3493 3494 bool FindDeallocationFunction(SourceLocation StartLoc, CXXRecordDecl *RD, 3495 DeclarationName Name, FunctionDecl* &Operator, 3496 bool Diagnose = true); 3497 3498 /// ActOnCXXDelete - Parsed a C++ 'delete' expression 3499 ExprResult ActOnCXXDelete(SourceLocation StartLoc, 3500 bool UseGlobal, bool ArrayForm, 3501 Expr *Operand); 3502 3503 DeclResult ActOnCXXConditionDeclaration(Scope *S, Declarator &D); 3504 ExprResult CheckConditionVariable(VarDecl *ConditionVar, 3505 SourceLocation StmtLoc, 3506 bool ConvertToBoolean); 3507 3508 ExprResult ActOnNoexceptExpr(SourceLocation KeyLoc, SourceLocation LParen, 3509 Expr *Operand, SourceLocation RParen); 3510 ExprResult BuildCXXNoexceptExpr(SourceLocation KeyLoc, Expr *Operand, 3511 SourceLocation RParen); 3512 3513 /// ActOnUnaryTypeTrait - Parsed one of the unary type trait support 3514 /// pseudo-functions. 3515 ExprResult ActOnUnaryTypeTrait(UnaryTypeTrait OTT, 3516 SourceLocation KWLoc, 3517 ParsedType Ty, 3518 SourceLocation RParen); 3519 3520 ExprResult BuildUnaryTypeTrait(UnaryTypeTrait OTT, 3521 SourceLocation KWLoc, 3522 TypeSourceInfo *T, 3523 SourceLocation RParen); 3524 3525 /// ActOnBinaryTypeTrait - Parsed one of the bianry type trait support 3526 /// pseudo-functions. 3527 ExprResult ActOnBinaryTypeTrait(BinaryTypeTrait OTT, 3528 SourceLocation KWLoc, 3529 ParsedType LhsTy, 3530 ParsedType RhsTy, 3531 SourceLocation RParen); 3532 3533 ExprResult BuildBinaryTypeTrait(BinaryTypeTrait BTT, 3534 SourceLocation KWLoc, 3535 TypeSourceInfo *LhsT, 3536 TypeSourceInfo *RhsT, 3537 SourceLocation RParen); 3538 3539 /// \brief Parsed one of the type trait support pseudo-functions. 3540 ExprResult ActOnTypeTrait(TypeTrait Kind, SourceLocation KWLoc, 3541 ArrayRef<ParsedType> Args, 3542 SourceLocation RParenLoc); 3543 ExprResult BuildTypeTrait(TypeTrait Kind, SourceLocation KWLoc, 3544 ArrayRef<TypeSourceInfo *> Args, 3545 SourceLocation RParenLoc); 3546 3547 /// ActOnArrayTypeTrait - Parsed one of the bianry type trait support 3548 /// pseudo-functions. 3549 ExprResult ActOnArrayTypeTrait(ArrayTypeTrait ATT, 3550 SourceLocation KWLoc, 3551 ParsedType LhsTy, 3552 Expr *DimExpr, 3553 SourceLocation RParen); 3554 3555 ExprResult BuildArrayTypeTrait(ArrayTypeTrait ATT, 3556 SourceLocation KWLoc, 3557 TypeSourceInfo *TSInfo, 3558 Expr *DimExpr, 3559 SourceLocation RParen); 3560 3561 /// ActOnExpressionTrait - Parsed one of the unary type trait support 3562 /// pseudo-functions. 3563 ExprResult ActOnExpressionTrait(ExpressionTrait OET, 3564 SourceLocation KWLoc, 3565 Expr *Queried, 3566 SourceLocation RParen); 3567 3568 ExprResult BuildExpressionTrait(ExpressionTrait OET, 3569 SourceLocation KWLoc, 3570 Expr *Queried, 3571 SourceLocation RParen); 3572 3573 ExprResult ActOnStartCXXMemberReference(Scope *S, 3574 Expr *Base, 3575 SourceLocation OpLoc, 3576 tok::TokenKind OpKind, 3577 ParsedType &ObjectType, 3578 bool &MayBePseudoDestructor); 3579 3580 ExprResult DiagnoseDtorReference(SourceLocation NameLoc, Expr *MemExpr); 3581 3582 ExprResult BuildPseudoDestructorExpr(Expr *Base, 3583 SourceLocation OpLoc, 3584 tok::TokenKind OpKind, 3585 const CXXScopeSpec &SS, 3586 TypeSourceInfo *ScopeType, 3587 SourceLocation CCLoc, 3588 SourceLocation TildeLoc, 3589 PseudoDestructorTypeStorage DestroyedType, 3590 bool HasTrailingLParen); 3591 3592 ExprResult ActOnPseudoDestructorExpr(Scope *S, Expr *Base, 3593 SourceLocation OpLoc, 3594 tok::TokenKind OpKind, 3595 CXXScopeSpec &SS, 3596 UnqualifiedId &FirstTypeName, 3597 SourceLocation CCLoc, 3598 SourceLocation TildeLoc, 3599 UnqualifiedId &SecondTypeName, 3600 bool HasTrailingLParen); 3601 3602 ExprResult ActOnPseudoDestructorExpr(Scope *S, Expr *Base, 3603 SourceLocation OpLoc, 3604 tok::TokenKind OpKind, 3605 SourceLocation TildeLoc, 3606 const DeclSpec& DS, 3607 bool HasTrailingLParen); 3608 3609 /// MaybeCreateExprWithCleanups - If the current full-expression 3610 /// requires any cleanups, surround it with a ExprWithCleanups node. 3611 /// Otherwise, just returns the passed-in expression. 3612 Expr *MaybeCreateExprWithCleanups(Expr *SubExpr); 3613 Stmt *MaybeCreateStmtWithCleanups(Stmt *SubStmt); 3614 ExprResult MaybeCreateExprWithCleanups(ExprResult SubExpr); 3615 3616 ExprResult ActOnFinishFullExpr(Expr *Expr); 3617 StmtResult ActOnFinishFullStmt(Stmt *Stmt); 3618 3619 // Marks SS invalid if it represents an incomplete type. 3620 bool RequireCompleteDeclContext(CXXScopeSpec &SS, DeclContext *DC); 3621 3622 DeclContext *computeDeclContext(QualType T); 3623 DeclContext *computeDeclContext(const CXXScopeSpec &SS, 3624 bool EnteringContext = false); 3625 bool isDependentScopeSpecifier(const CXXScopeSpec &SS); 3626 CXXRecordDecl *getCurrentInstantiationOf(NestedNameSpecifier *NNS); 3627 bool isUnknownSpecialization(const CXXScopeSpec &SS); 3628 3629 /// \brief The parser has parsed a global nested-name-specifier '::'. 3630 /// 3631 /// \param S The scope in which this nested-name-specifier occurs. 3632 /// 3633 /// \param CCLoc The location of the '::'. 3634 /// 3635 /// \param SS The nested-name-specifier, which will be updated in-place 3636 /// to reflect the parsed nested-name-specifier. 3637 /// 3638 /// \returns true if an error occurred, false otherwise. 3639 bool ActOnCXXGlobalScopeSpecifier(Scope *S, SourceLocation CCLoc, 3640 CXXScopeSpec &SS); 3641 3642 bool isAcceptableNestedNameSpecifier(NamedDecl *SD); 3643 NamedDecl *FindFirstQualifierInScope(Scope *S, NestedNameSpecifier *NNS); 3644 3645 bool isNonTypeNestedNameSpecifier(Scope *S, CXXScopeSpec &SS, 3646 SourceLocation IdLoc, 3647 IdentifierInfo &II, 3648 ParsedType ObjectType); 3649 3650 bool BuildCXXNestedNameSpecifier(Scope *S, 3651 IdentifierInfo &Identifier, 3652 SourceLocation IdentifierLoc, 3653 SourceLocation CCLoc, 3654 QualType ObjectType, 3655 bool EnteringContext, 3656 CXXScopeSpec &SS, 3657 NamedDecl *ScopeLookupResult, 3658 bool ErrorRecoveryLookup); 3659 3660 /// \brief The parser has parsed a nested-name-specifier 'identifier::'. 3661 /// 3662 /// \param S The scope in which this nested-name-specifier occurs. 3663 /// 3664 /// \param Identifier The identifier preceding the '::'. 3665 /// 3666 /// \param IdentifierLoc The location of the identifier. 3667 /// 3668 /// \param CCLoc The location of the '::'. 3669 /// 3670 /// \param ObjectType The type of the object, if we're parsing 3671 /// nested-name-specifier in a member access expression. 3672 /// 3673 /// \param EnteringContext Whether we're entering the context nominated by 3674 /// this nested-name-specifier. 3675 /// 3676 /// \param SS The nested-name-specifier, which is both an input 3677 /// parameter (the nested-name-specifier before this type) and an 3678 /// output parameter (containing the full nested-name-specifier, 3679 /// including this new type). 3680 /// 3681 /// \returns true if an error occurred, false otherwise. 3682 bool ActOnCXXNestedNameSpecifier(Scope *S, 3683 IdentifierInfo &Identifier, 3684 SourceLocation IdentifierLoc, 3685 SourceLocation CCLoc, 3686 ParsedType ObjectType, 3687 bool EnteringContext, 3688 CXXScopeSpec &SS); 3689 3690 ExprResult ActOnDecltypeExpression(Expr *E); 3691 3692 bool ActOnCXXNestedNameSpecifierDecltype(CXXScopeSpec &SS, 3693 const DeclSpec &DS, 3694 SourceLocation ColonColonLoc); 3695 3696 bool IsInvalidUnlessNestedName(Scope *S, CXXScopeSpec &SS, 3697 IdentifierInfo &Identifier, 3698 SourceLocation IdentifierLoc, 3699 SourceLocation ColonLoc, 3700 ParsedType ObjectType, 3701 bool EnteringContext); 3702 3703 /// \brief The parser has parsed a nested-name-specifier 3704 /// 'template[opt] template-name < template-args >::'. 3705 /// 3706 /// \param S The scope in which this nested-name-specifier occurs. 3707 /// 3708 /// \param SS The nested-name-specifier, which is both an input 3709 /// parameter (the nested-name-specifier before this type) and an 3710 /// output parameter (containing the full nested-name-specifier, 3711 /// including this new type). 3712 /// 3713 /// \param TemplateKWLoc the location of the 'template' keyword, if any. 3714 /// \param TemplateName The template name. 3715 /// \param TemplateNameLoc The location of the template name. 3716 /// \param LAngleLoc The location of the opening angle bracket ('<'). 3717 /// \param TemplateArgs The template arguments. 3718 /// \param RAngleLoc The location of the closing angle bracket ('>'). 3719 /// \param CCLoc The location of the '::'. 3720 /// 3721 /// \param EnteringContext Whether we're entering the context of the 3722 /// nested-name-specifier. 3723 /// 3724 /// 3725 /// \returns true if an error occurred, false otherwise. 3726 bool ActOnCXXNestedNameSpecifier(Scope *S, 3727 CXXScopeSpec &SS, 3728 SourceLocation TemplateKWLoc, 3729 TemplateTy Template, 3730 SourceLocation TemplateNameLoc, 3731 SourceLocation LAngleLoc, 3732 ASTTemplateArgsPtr TemplateArgs, 3733 SourceLocation RAngleLoc, 3734 SourceLocation CCLoc, 3735 bool EnteringContext); 3736 3737 /// \brief Given a C++ nested-name-specifier, produce an annotation value 3738 /// that the parser can use later to reconstruct the given 3739 /// nested-name-specifier. 3740 /// 3741 /// \param SS A nested-name-specifier. 3742 /// 3743 /// \returns A pointer containing all of the information in the 3744 /// nested-name-specifier \p SS. 3745 void *SaveNestedNameSpecifierAnnotation(CXXScopeSpec &SS); 3746 3747 /// \brief Given an annotation pointer for a nested-name-specifier, restore 3748 /// the nested-name-specifier structure. 3749 /// 3750 /// \param Annotation The annotation pointer, produced by 3751 /// \c SaveNestedNameSpecifierAnnotation(). 3752 /// 3753 /// \param AnnotationRange The source range corresponding to the annotation. 3754 /// 3755 /// \param SS The nested-name-specifier that will be updated with the contents 3756 /// of the annotation pointer. 3757 void RestoreNestedNameSpecifierAnnotation(void *Annotation, 3758 SourceRange AnnotationRange, 3759 CXXScopeSpec &SS); 3760 3761 bool ShouldEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS); 3762 3763 /// ActOnCXXEnterDeclaratorScope - Called when a C++ scope specifier (global 3764 /// scope or nested-name-specifier) is parsed, part of a declarator-id. 3765 /// After this method is called, according to [C++ 3.4.3p3], names should be 3766 /// looked up in the declarator-id's scope, until the declarator is parsed and 3767 /// ActOnCXXExitDeclaratorScope is called. 3768 /// The 'SS' should be a non-empty valid CXXScopeSpec. 3769 bool ActOnCXXEnterDeclaratorScope(Scope *S, CXXScopeSpec &SS); 3770 3771 /// ActOnCXXExitDeclaratorScope - Called when a declarator that previously 3772 /// invoked ActOnCXXEnterDeclaratorScope(), is finished. 'SS' is the same 3773 /// CXXScopeSpec that was passed to ActOnCXXEnterDeclaratorScope as well. 3774 /// Used to indicate that names should revert to being looked up in the 3775 /// defining scope. 3776 void ActOnCXXExitDeclaratorScope(Scope *S, const CXXScopeSpec &SS); 3777 3778 /// ActOnCXXEnterDeclInitializer - Invoked when we are about to parse an 3779 /// initializer for the declaration 'Dcl'. 3780 /// After this method is called, according to [C++ 3.4.1p13], if 'Dcl' is a 3781 /// static data member of class X, names should be looked up in the scope of 3782 /// class X. 3783 void ActOnCXXEnterDeclInitializer(Scope *S, Decl *Dcl); 3784 3785 /// ActOnCXXExitDeclInitializer - Invoked after we are finished parsing an 3786 /// initializer for the declaration 'Dcl'. 3787 void ActOnCXXExitDeclInitializer(Scope *S, Decl *Dcl); 3788 3789 /// \brief Create a new lambda closure type. 3790 CXXRecordDecl *createLambdaClosureType(SourceRange IntroducerRange, 3791 bool KnownDependent = false); 3792 3793 /// \brief Start the definition of a lambda expression. 3794 CXXMethodDecl *startLambdaDefinition(CXXRecordDecl *Class, 3795 SourceRange IntroducerRange, 3796 TypeSourceInfo *MethodType, 3797 SourceLocation EndLoc, 3798 llvm::ArrayRef<ParmVarDecl *> Params, 3799 llvm::Optional<unsigned> ManglingNumber 3800 = llvm::Optional<unsigned>(), 3801 Decl *ContextDecl = 0); 3802 3803 /// \brief Introduce the scope for a lambda expression. 3804 sema::LambdaScopeInfo *enterLambdaScope(CXXMethodDecl *CallOperator, 3805 SourceRange IntroducerRange, 3806 LambdaCaptureDefault CaptureDefault, 3807 bool ExplicitParams, 3808 bool ExplicitResultType, 3809 bool Mutable); 3810 3811 /// \brief Note that we have finished the explicit captures for the 3812 /// given lambda. 3813 void finishLambdaExplicitCaptures(sema::LambdaScopeInfo *LSI); 3814 3815 /// \brief Introduce the lambda parameters into scope. 3816 void addLambdaParameters(CXXMethodDecl *CallOperator, Scope *CurScope); 3817 3818 /// ActOnStartOfLambdaDefinition - This is called just before we start 3819 /// parsing the body of a lambda; it analyzes the explicit captures and 3820 /// arguments, and sets up various data-structures for the body of the 3821 /// lambda. 3822 void ActOnStartOfLambdaDefinition(LambdaIntroducer &Intro, 3823 Declarator &ParamInfo, Scope *CurScope); 3824 3825 /// ActOnLambdaError - If there is an error parsing a lambda, this callback 3826 /// is invoked to pop the information about the lambda. 3827 void ActOnLambdaError(SourceLocation StartLoc, Scope *CurScope, 3828 bool IsInstantiation = false); 3829 3830 /// ActOnLambdaExpr - This is called when the body of a lambda expression 3831 /// was successfully completed. 3832 ExprResult ActOnLambdaExpr(SourceLocation StartLoc, Stmt *Body, 3833 Scope *CurScope, 3834 bool IsInstantiation = false); 3835 3836 /// \brief Define the "body" of the conversion from a lambda object to a 3837 /// function pointer. 3838 /// 3839 /// This routine doesn't actually define a sensible body; rather, it fills 3840 /// in the initialization expression needed to copy the lambda object into 3841 /// the block, and IR generation actually generates the real body of the 3842 /// block pointer conversion. 3843 void DefineImplicitLambdaToFunctionPointerConversion( 3844 SourceLocation CurrentLoc, CXXConversionDecl *Conv); 3845 3846 /// \brief Define the "body" of the conversion from a lambda object to a 3847 /// block pointer. 3848 /// 3849 /// This routine doesn't actually define a sensible body; rather, it fills 3850 /// in the initialization expression needed to copy the lambda object into 3851 /// the block, and IR generation actually generates the real body of the 3852 /// block pointer conversion. 3853 void DefineImplicitLambdaToBlockPointerConversion(SourceLocation CurrentLoc, 3854 CXXConversionDecl *Conv); 3855 3856 ExprResult BuildBlockForLambdaConversion(SourceLocation CurrentLocation, 3857 SourceLocation ConvLocation, 3858 CXXConversionDecl *Conv, 3859 Expr *Src); 3860 3861 // ParseObjCStringLiteral - Parse Objective-C string literals. 3862 ExprResult ParseObjCStringLiteral(SourceLocation *AtLocs, 3863 Expr **Strings, 3864 unsigned NumStrings); 3865 3866 ExprResult BuildObjCStringLiteral(SourceLocation AtLoc, StringLiteral *S); 3867 3868 /// BuildObjCNumericLiteral - builds an ObjCBoxedExpr AST node for the 3869 /// numeric literal expression. Type of the expression will be "NSNumber *" 3870 /// or "id" if NSNumber is unavailable. 3871 ExprResult BuildObjCNumericLiteral(SourceLocation AtLoc, Expr *Number); 3872 ExprResult ActOnObjCBoolLiteral(SourceLocation AtLoc, SourceLocation ValueLoc, 3873 bool Value); 3874 ExprResult BuildObjCArrayLiteral(SourceRange SR, MultiExprArg Elements); 3875 3876 // BuildObjCBoxedExpr - builds an ObjCBoxedExpr AST node for the 3877 // '@' prefixed parenthesized expression. The type of the expression will 3878 // either be "NSNumber *" or "NSString *" depending on the type of 3879 // ValueType, which is allowed to be a built-in numeric type or 3880 // "char *" or "const char *". 3881 ExprResult BuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr); 3882 3883 ExprResult BuildObjCSubscriptExpression(SourceLocation RB, Expr *BaseExpr, 3884 Expr *IndexExpr, 3885 ObjCMethodDecl *getterMethod, 3886 ObjCMethodDecl *setterMethod); 3887 3888 ExprResult BuildObjCDictionaryLiteral(SourceRange SR, 3889 ObjCDictionaryElement *Elements, 3890 unsigned NumElements); 3891 3892 ExprResult BuildObjCEncodeExpression(SourceLocation AtLoc, 3893 TypeSourceInfo *EncodedTypeInfo, 3894 SourceLocation RParenLoc); 3895 ExprResult BuildCXXMemberCallExpr(Expr *Exp, NamedDecl *FoundDecl, 3896 CXXConversionDecl *Method, 3897 bool HadMultipleCandidates); 3898 3899 ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc, 3900 SourceLocation EncodeLoc, 3901 SourceLocation LParenLoc, 3902 ParsedType Ty, 3903 SourceLocation RParenLoc); 3904 3905 // ParseObjCSelectorExpression - Build selector expression for @selector 3906 ExprResult ParseObjCSelectorExpression(Selector Sel, 3907 SourceLocation AtLoc, 3908 SourceLocation SelLoc, 3909 SourceLocation LParenLoc, 3910 SourceLocation RParenLoc); 3911 3912 // ParseObjCProtocolExpression - Build protocol expression for @protocol 3913 ExprResult ParseObjCProtocolExpression(IdentifierInfo * ProtocolName, 3914 SourceLocation AtLoc, 3915 SourceLocation ProtoLoc, 3916 SourceLocation LParenLoc, 3917 SourceLocation RParenLoc); 3918 3919 //===--------------------------------------------------------------------===// 3920 // C++ Declarations 3921 // 3922 Decl *ActOnStartLinkageSpecification(Scope *S, 3923 SourceLocation ExternLoc, 3924 SourceLocation LangLoc, 3925 StringRef Lang, 3926 SourceLocation LBraceLoc); 3927 Decl *ActOnFinishLinkageSpecification(Scope *S, 3928 Decl *LinkageSpec, 3929 SourceLocation RBraceLoc); 3930 3931 3932 //===--------------------------------------------------------------------===// 3933 // C++ Classes 3934 // 3935 bool isCurrentClassName(const IdentifierInfo &II, Scope *S, 3936 const CXXScopeSpec *SS = 0); 3937 3938 bool ActOnAccessSpecifier(AccessSpecifier Access, 3939 SourceLocation ASLoc, 3940 SourceLocation ColonLoc, 3941 AttributeList *Attrs = 0); 3942 3943 Decl *ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS, 3944 Declarator &D, 3945 MultiTemplateParamsArg TemplateParameterLists, 3946 Expr *BitfieldWidth, const VirtSpecifiers &VS, 3947 bool HasDeferredInit); 3948 void ActOnCXXInClassMemberInitializer(Decl *VarDecl, SourceLocation EqualLoc, 3949 Expr *Init); 3950 3951 MemInitResult ActOnMemInitializer(Decl *ConstructorD, 3952 Scope *S, 3953 CXXScopeSpec &SS, 3954 IdentifierInfo *MemberOrBase, 3955 ParsedType TemplateTypeTy, 3956 const DeclSpec &DS, 3957 SourceLocation IdLoc, 3958 SourceLocation LParenLoc, 3959 Expr **Args, unsigned NumArgs, 3960 SourceLocation RParenLoc, 3961 SourceLocation EllipsisLoc); 3962 3963 MemInitResult ActOnMemInitializer(Decl *ConstructorD, 3964 Scope *S, 3965 CXXScopeSpec &SS, 3966 IdentifierInfo *MemberOrBase, 3967 ParsedType TemplateTypeTy, 3968 const DeclSpec &DS, 3969 SourceLocation IdLoc, 3970 Expr *InitList, 3971 SourceLocation EllipsisLoc); 3972 3973 MemInitResult BuildMemInitializer(Decl *ConstructorD, 3974 Scope *S, 3975 CXXScopeSpec &SS, 3976 IdentifierInfo *MemberOrBase, 3977 ParsedType TemplateTypeTy, 3978 const DeclSpec &DS, 3979 SourceLocation IdLoc, 3980 Expr *Init, 3981 SourceLocation EllipsisLoc); 3982 3983 MemInitResult BuildMemberInitializer(ValueDecl *Member, 3984 Expr *Init, 3985 SourceLocation IdLoc); 3986 3987 MemInitResult BuildBaseInitializer(QualType BaseType, 3988 TypeSourceInfo *BaseTInfo, 3989 Expr *Init, 3990 CXXRecordDecl *ClassDecl, 3991 SourceLocation EllipsisLoc); 3992 3993 MemInitResult BuildDelegatingInitializer(TypeSourceInfo *TInfo, 3994 Expr *Init, 3995 CXXRecordDecl *ClassDecl); 3996 3997 bool SetDelegatingInitializer(CXXConstructorDecl *Constructor, 3998 CXXCtorInitializer *Initializer); 3999 4000 bool SetCtorInitializers(CXXConstructorDecl *Constructor, 4001 CXXCtorInitializer **Initializers, 4002 unsigned NumInitializers, bool AnyErrors); 4003 4004 void SetIvarInitializers(ObjCImplementationDecl *ObjCImplementation); 4005 4006 4007 /// MarkBaseAndMemberDestructorsReferenced - Given a record decl, 4008 /// mark all the non-trivial destructors of its members and bases as 4009 /// referenced. 4010 void MarkBaseAndMemberDestructorsReferenced(SourceLocation Loc, 4011 CXXRecordDecl *Record); 4012 4013 /// \brief The list of classes whose vtables have been used within 4014 /// this translation unit, and the source locations at which the 4015 /// first use occurred. 4016 typedef std::pair<CXXRecordDecl*, SourceLocation> VTableUse; 4017 4018 /// \brief The list of vtables that are required but have not yet been 4019 /// materialized. 4020 SmallVector<VTableUse, 16> VTableUses; 4021 4022 /// \brief The set of classes whose vtables have been used within 4023 /// this translation unit, and a bit that will be true if the vtable is 4024 /// required to be emitted (otherwise, it should be emitted only if needed 4025 /// by code generation). 4026 llvm::DenseMap<CXXRecordDecl *, bool> VTablesUsed; 4027 4028 /// \brief Load any externally-stored vtable uses. 4029 void LoadExternalVTableUses(); 4030 4031 typedef LazyVector<CXXRecordDecl *, ExternalSemaSource, 4032 &ExternalSemaSource::ReadDynamicClasses, 2, 2> 4033 DynamicClassesType; 4034 4035 /// \brief A list of all of the dynamic classes in this translation 4036 /// unit. 4037 DynamicClassesType DynamicClasses; 4038 4039 /// \brief Note that the vtable for the given class was used at the 4040 /// given location. 4041 void MarkVTableUsed(SourceLocation Loc, CXXRecordDecl *Class, 4042 bool DefinitionRequired = false); 4043 4044 /// MarkVirtualMembersReferenced - Will mark all members of the given 4045 /// CXXRecordDecl referenced. 4046 void MarkVirtualMembersReferenced(SourceLocation Loc, 4047 const CXXRecordDecl *RD); 4048 4049 /// \brief Define all of the vtables that have been used in this 4050 /// translation unit and reference any virtual members used by those 4051 /// vtables. 4052 /// 4053 /// \returns true if any work was done, false otherwise. 4054 bool DefineUsedVTables(); 4055 4056 void AddImplicitlyDeclaredMembersToClass(CXXRecordDecl *ClassDecl); 4057 4058 void ActOnMemInitializers(Decl *ConstructorDecl, 4059 SourceLocation ColonLoc, 4060 CXXCtorInitializer **MemInits, 4061 unsigned NumMemInits, 4062 bool AnyErrors); 4063 4064 void CheckCompletedCXXClass(CXXRecordDecl *Record); 4065 void ActOnFinishCXXMemberSpecification(Scope* S, SourceLocation RLoc, 4066 Decl *TagDecl, 4067 SourceLocation LBrac, 4068 SourceLocation RBrac, 4069 AttributeList *AttrList); 4070 void ActOnFinishCXXMemberDecls(); 4071 4072 void ActOnReenterTemplateScope(Scope *S, Decl *Template); 4073 void ActOnReenterDeclaratorTemplateScope(Scope *S, DeclaratorDecl *D); 4074 void ActOnStartDelayedMemberDeclarations(Scope *S, Decl *Record); 4075 void ActOnStartDelayedCXXMethodDeclaration(Scope *S, Decl *Method); 4076 void ActOnDelayedCXXMethodParameter(Scope *S, Decl *Param); 4077 void ActOnFinishDelayedMemberDeclarations(Scope *S, Decl *Record); 4078 void ActOnFinishDelayedCXXMethodDeclaration(Scope *S, Decl *Method); 4079 void ActOnFinishDelayedMemberInitializers(Decl *Record); 4080 void MarkAsLateParsedTemplate(FunctionDecl *FD, bool Flag = true); 4081 bool IsInsideALocalClassWithinATemplateFunction(); 4082 4083 Decl *ActOnStaticAssertDeclaration(SourceLocation StaticAssertLoc, 4084 Expr *AssertExpr, 4085 Expr *AssertMessageExpr, 4086 SourceLocation RParenLoc); 4087 4088 FriendDecl *CheckFriendTypeDecl(SourceLocation Loc, 4089 SourceLocation FriendLoc, 4090 TypeSourceInfo *TSInfo); 4091 Decl *ActOnFriendTypeDecl(Scope *S, const DeclSpec &DS, 4092 MultiTemplateParamsArg TemplateParams); 4093 Decl *ActOnFriendFunctionDecl(Scope *S, Declarator &D, 4094 MultiTemplateParamsArg TemplateParams); 4095 4096 QualType CheckConstructorDeclarator(Declarator &D, QualType R, 4097 StorageClass& SC); 4098 void CheckConstructor(CXXConstructorDecl *Constructor); 4099 QualType CheckDestructorDeclarator(Declarator &D, QualType R, 4100 StorageClass& SC); 4101 bool CheckDestructor(CXXDestructorDecl *Destructor); 4102 void CheckConversionDeclarator(Declarator &D, QualType &R, 4103 StorageClass& SC); 4104 Decl *ActOnConversionDeclarator(CXXConversionDecl *Conversion); 4105 4106 void CheckExplicitlyDefaultedMethods(CXXRecordDecl *Record); 4107 void CheckExplicitlyDefaultedDefaultConstructor(CXXConstructorDecl *Ctor); 4108 void CheckExplicitlyDefaultedCopyConstructor(CXXConstructorDecl *Ctor); 4109 void CheckExplicitlyDefaultedCopyAssignment(CXXMethodDecl *Method); 4110 void CheckExplicitlyDefaultedMoveConstructor(CXXConstructorDecl *Ctor); 4111 void CheckExplicitlyDefaultedMoveAssignment(CXXMethodDecl *Method); 4112 void CheckExplicitlyDefaultedDestructor(CXXDestructorDecl *Dtor); 4113 4114 //===--------------------------------------------------------------------===// 4115 // C++ Derived Classes 4116 // 4117 4118 /// ActOnBaseSpecifier - Parsed a base specifier 4119 CXXBaseSpecifier *CheckBaseSpecifier(CXXRecordDecl *Class, 4120 SourceRange SpecifierRange, 4121 bool Virtual, AccessSpecifier Access, 4122 TypeSourceInfo *TInfo, 4123 SourceLocation EllipsisLoc); 4124 4125 BaseResult ActOnBaseSpecifier(Decl *classdecl, 4126 SourceRange SpecifierRange, 4127 bool Virtual, AccessSpecifier Access, 4128 ParsedType basetype, 4129 SourceLocation BaseLoc, 4130 SourceLocation EllipsisLoc); 4131 4132 bool AttachBaseSpecifiers(CXXRecordDecl *Class, CXXBaseSpecifier **Bases, 4133 unsigned NumBases); 4134 void ActOnBaseSpecifiers(Decl *ClassDecl, CXXBaseSpecifier **Bases, 4135 unsigned NumBases); 4136 4137 bool IsDerivedFrom(QualType Derived, QualType Base); 4138 bool IsDerivedFrom(QualType Derived, QualType Base, CXXBasePaths &Paths); 4139 4140 // FIXME: I don't like this name. 4141 void BuildBasePathArray(const CXXBasePaths &Paths, CXXCastPath &BasePath); 4142 4143 bool BasePathInvolvesVirtualBase(const CXXCastPath &BasePath); 4144 4145 bool CheckDerivedToBaseConversion(QualType Derived, QualType Base, 4146 SourceLocation Loc, SourceRange Range, 4147 CXXCastPath *BasePath = 0, 4148 bool IgnoreAccess = false); 4149 bool CheckDerivedToBaseConversion(QualType Derived, QualType Base, 4150 unsigned InaccessibleBaseID, 4151 unsigned AmbigiousBaseConvID, 4152 SourceLocation Loc, SourceRange Range, 4153 DeclarationName Name, 4154 CXXCastPath *BasePath); 4155 4156 std::string getAmbiguousPathsDisplayString(CXXBasePaths &Paths); 4157 4158 /// CheckOverridingFunctionReturnType - Checks whether the return types are 4159 /// covariant, according to C++ [class.virtual]p5. 4160 bool CheckOverridingFunctionReturnType(const CXXMethodDecl *New, 4161 const CXXMethodDecl *Old); 4162 4163 /// CheckOverridingFunctionExceptionSpec - Checks whether the exception 4164 /// spec is a subset of base spec. 4165 bool CheckOverridingFunctionExceptionSpec(const CXXMethodDecl *New, 4166 const CXXMethodDecl *Old); 4167 4168 bool CheckPureMethod(CXXMethodDecl *Method, SourceRange InitRange); 4169 4170 /// CheckOverrideControl - Check C++0x override control semantics. 4171 void CheckOverrideControl(const Decl *D); 4172 4173 /// CheckForFunctionMarkedFinal - Checks whether a virtual member function 4174 /// overrides a virtual member function marked 'final', according to 4175 /// C++0x [class.virtual]p3. 4176 bool CheckIfOverriddenFunctionIsMarkedFinal(const CXXMethodDecl *New, 4177 const CXXMethodDecl *Old); 4178 4179 4180 //===--------------------------------------------------------------------===// 4181 // C++ Access Control 4182 // 4183 4184 enum AccessResult { 4185 AR_accessible, 4186 AR_inaccessible, 4187 AR_dependent, 4188 AR_delayed 4189 }; 4190 4191 bool SetMemberAccessSpecifier(NamedDecl *MemberDecl, 4192 NamedDecl *PrevMemberDecl, 4193 AccessSpecifier LexicalAS); 4194 4195 AccessResult CheckUnresolvedMemberAccess(UnresolvedMemberExpr *E, 4196 DeclAccessPair FoundDecl); 4197 AccessResult CheckUnresolvedLookupAccess(UnresolvedLookupExpr *E, 4198 DeclAccessPair FoundDecl); 4199 AccessResult CheckAllocationAccess(SourceLocation OperatorLoc, 4200 SourceRange PlacementRange, 4201 CXXRecordDecl *NamingClass, 4202 DeclAccessPair FoundDecl, 4203 bool Diagnose = true); 4204 AccessResult CheckConstructorAccess(SourceLocation Loc, 4205 CXXConstructorDecl *D, 4206 const InitializedEntity &Entity, 4207 AccessSpecifier Access, 4208 bool IsCopyBindingRefToTemp = false); 4209 AccessResult CheckConstructorAccess(SourceLocation Loc, 4210 CXXConstructorDecl *D, 4211 const InitializedEntity &Entity, 4212 AccessSpecifier Access, 4213 const PartialDiagnostic &PDiag); 4214 AccessResult CheckDestructorAccess(SourceLocation Loc, 4215 CXXDestructorDecl *Dtor, 4216 const PartialDiagnostic &PDiag, 4217 QualType objectType = QualType()); 4218 AccessResult CheckDirectMemberAccess(SourceLocation Loc, 4219 NamedDecl *D, 4220 const PartialDiagnostic &PDiag); 4221 AccessResult CheckMemberOperatorAccess(SourceLocation Loc, 4222 Expr *ObjectExpr, 4223 Expr *ArgExpr, 4224 DeclAccessPair FoundDecl); 4225 AccessResult CheckAddressOfMemberAccess(Expr *OvlExpr, 4226 DeclAccessPair FoundDecl); 4227 AccessResult CheckBaseClassAccess(SourceLocation AccessLoc, 4228 QualType Base, QualType Derived, 4229 const CXXBasePath &Path, 4230 unsigned DiagID, 4231 bool ForceCheck = false, 4232 bool ForceUnprivileged = false); 4233 void CheckLookupAccess(const LookupResult &R); 4234 bool IsSimplyAccessible(NamedDecl *decl, DeclContext *Ctx); 4235 bool isSpecialMemberAccessibleForDeletion(CXXMethodDecl *decl, 4236 AccessSpecifier access, 4237 QualType objectType); 4238 4239 void HandleDependentAccessCheck(const DependentDiagnostic &DD, 4240 const MultiLevelTemplateArgumentList &TemplateArgs); 4241 void PerformDependentDiagnostics(const DeclContext *Pattern, 4242 const MultiLevelTemplateArgumentList &TemplateArgs); 4243 4244 void HandleDelayedAccessCheck(sema::DelayedDiagnostic &DD, Decl *Ctx); 4245 4246 /// A flag to suppress access checking. 4247 bool SuppressAccessChecking; 4248 4249 /// \brief When true, access checking violations are treated as SFINAE 4250 /// failures rather than hard errors. 4251 bool AccessCheckingSFINAE; 4252 4253 /// \brief RAII object used to temporarily suppress access checking. 4254 class SuppressAccessChecksRAII { 4255 Sema &S; 4256 bool SuppressingAccess; 4257 4258 public: 4259 SuppressAccessChecksRAII(Sema &S, bool Suppress) 4260 : S(S), SuppressingAccess(Suppress) { 4261 if (Suppress) S.ActOnStartSuppressingAccessChecks(); 4262 } 4263 ~SuppressAccessChecksRAII() { 4264 done(); 4265 } 4266 void done() { 4267 if (!SuppressingAccess) return; 4268 S.ActOnStopSuppressingAccessChecks(); 4269 SuppressingAccess = false; 4270 } 4271 }; 4272 4273 void ActOnStartSuppressingAccessChecks(); 4274 void ActOnStopSuppressingAccessChecks(); 4275 4276 enum AbstractDiagSelID { 4277 AbstractNone = -1, 4278 AbstractReturnType, 4279 AbstractParamType, 4280 AbstractVariableType, 4281 AbstractFieldType, 4282 AbstractArrayType 4283 }; 4284 4285 bool RequireNonAbstractType(SourceLocation Loc, QualType T, 4286 const PartialDiagnostic &PD); 4287 void DiagnoseAbstractType(const CXXRecordDecl *RD); 4288 4289 bool RequireNonAbstractType(SourceLocation Loc, QualType T, unsigned DiagID, 4290 AbstractDiagSelID SelID = AbstractNone); 4291 4292 //===--------------------------------------------------------------------===// 4293 // C++ Overloaded Operators [C++ 13.5] 4294 // 4295 4296 bool CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl); 4297 4298 bool CheckLiteralOperatorDeclaration(FunctionDecl *FnDecl); 4299 4300 //===--------------------------------------------------------------------===// 4301 // C++ Templates [C++ 14] 4302 // 4303 void FilterAcceptableTemplateNames(LookupResult &R, 4304 bool AllowFunctionTemplates = true); 4305 bool hasAnyAcceptableTemplateNames(LookupResult &R, 4306 bool AllowFunctionTemplates = true); 4307 4308 void LookupTemplateName(LookupResult &R, Scope *S, CXXScopeSpec &SS, 4309 QualType ObjectType, bool EnteringContext, 4310 bool &MemberOfUnknownSpecialization); 4311 4312 TemplateNameKind isTemplateName(Scope *S, 4313 CXXScopeSpec &SS, 4314 bool hasTemplateKeyword, 4315 UnqualifiedId &Name, 4316 ParsedType ObjectType, 4317 bool EnteringContext, 4318 TemplateTy &Template, 4319 bool &MemberOfUnknownSpecialization); 4320 4321 bool DiagnoseUnknownTemplateName(const IdentifierInfo &II, 4322 SourceLocation IILoc, 4323 Scope *S, 4324 const CXXScopeSpec *SS, 4325 TemplateTy &SuggestedTemplate, 4326 TemplateNameKind &SuggestedKind); 4327 4328 void DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl); 4329 TemplateDecl *AdjustDeclIfTemplate(Decl *&Decl); 4330 4331 Decl *ActOnTypeParameter(Scope *S, bool Typename, bool Ellipsis, 4332 SourceLocation EllipsisLoc, 4333 SourceLocation KeyLoc, 4334 IdentifierInfo *ParamName, 4335 SourceLocation ParamNameLoc, 4336 unsigned Depth, unsigned Position, 4337 SourceLocation EqualLoc, 4338 ParsedType DefaultArg); 4339 4340 QualType CheckNonTypeTemplateParameterType(QualType T, SourceLocation Loc); 4341 Decl *ActOnNonTypeTemplateParameter(Scope *S, Declarator &D, 4342 unsigned Depth, 4343 unsigned Position, 4344 SourceLocation EqualLoc, 4345 Expr *DefaultArg); 4346 Decl *ActOnTemplateTemplateParameter(Scope *S, 4347 SourceLocation TmpLoc, 4348 TemplateParameterList *Params, 4349 SourceLocation EllipsisLoc, 4350 IdentifierInfo *ParamName, 4351 SourceLocation ParamNameLoc, 4352 unsigned Depth, 4353 unsigned Position, 4354 SourceLocation EqualLoc, 4355 ParsedTemplateArgument DefaultArg); 4356 4357 TemplateParameterList * 4358 ActOnTemplateParameterList(unsigned Depth, 4359 SourceLocation ExportLoc, 4360 SourceLocation TemplateLoc, 4361 SourceLocation LAngleLoc, 4362 Decl **Params, unsigned NumParams, 4363 SourceLocation RAngleLoc); 4364 4365 /// \brief The context in which we are checking a template parameter 4366 /// list. 4367 enum TemplateParamListContext { 4368 TPC_ClassTemplate, 4369 TPC_FunctionTemplate, 4370 TPC_ClassTemplateMember, 4371 TPC_FriendFunctionTemplate, 4372 TPC_FriendFunctionTemplateDefinition, 4373 TPC_TypeAliasTemplate 4374 }; 4375 4376 bool CheckTemplateParameterList(TemplateParameterList *NewParams, 4377 TemplateParameterList *OldParams, 4378 TemplateParamListContext TPC); 4379 TemplateParameterList * 4380 MatchTemplateParametersToScopeSpecifier(SourceLocation DeclStartLoc, 4381 SourceLocation DeclLoc, 4382 const CXXScopeSpec &SS, 4383 TemplateParameterList **ParamLists, 4384 unsigned NumParamLists, 4385 bool IsFriend, 4386 bool &IsExplicitSpecialization, 4387 bool &Invalid); 4388 4389 DeclResult CheckClassTemplate(Scope *S, unsigned TagSpec, TagUseKind TUK, 4390 SourceLocation KWLoc, CXXScopeSpec &SS, 4391 IdentifierInfo *Name, SourceLocation NameLoc, 4392 AttributeList *Attr, 4393 TemplateParameterList *TemplateParams, 4394 AccessSpecifier AS, 4395 SourceLocation ModulePrivateLoc, 4396 unsigned NumOuterTemplateParamLists, 4397 TemplateParameterList **OuterTemplateParamLists); 4398 4399 void translateTemplateArguments(const ASTTemplateArgsPtr &In, 4400 TemplateArgumentListInfo &Out); 4401 4402 void NoteAllFoundTemplates(TemplateName Name); 4403 4404 QualType CheckTemplateIdType(TemplateName Template, 4405 SourceLocation TemplateLoc, 4406 TemplateArgumentListInfo &TemplateArgs); 4407 4408 TypeResult 4409 ActOnTemplateIdType(CXXScopeSpec &SS, SourceLocation TemplateKWLoc, 4410 TemplateTy Template, SourceLocation TemplateLoc, 4411 SourceLocation LAngleLoc, 4412 ASTTemplateArgsPtr TemplateArgs, 4413 SourceLocation RAngleLoc, 4414 bool IsCtorOrDtorName = false); 4415 4416 /// \brief Parsed an elaborated-type-specifier that refers to a template-id, 4417 /// such as \c class T::template apply<U>. 4418 /// 4419 /// \param TUK 4420 TypeResult ActOnTagTemplateIdType(TagUseKind TUK, 4421 TypeSpecifierType TagSpec, 4422 SourceLocation TagLoc, 4423 CXXScopeSpec &SS, 4424 SourceLocation TemplateKWLoc, 4425 TemplateTy TemplateD, 4426 SourceLocation TemplateLoc, 4427 SourceLocation LAngleLoc, 4428 ASTTemplateArgsPtr TemplateArgsIn, 4429 SourceLocation RAngleLoc); 4430 4431 4432 ExprResult BuildTemplateIdExpr(const CXXScopeSpec &SS, 4433 SourceLocation TemplateKWLoc, 4434 LookupResult &R, 4435 bool RequiresADL, 4436 const TemplateArgumentListInfo *TemplateArgs); 4437 4438 ExprResult BuildQualifiedTemplateIdExpr(CXXScopeSpec &SS, 4439 SourceLocation TemplateKWLoc, 4440 const DeclarationNameInfo &NameInfo, 4441 const TemplateArgumentListInfo *TemplateArgs); 4442 4443 TemplateNameKind ActOnDependentTemplateName(Scope *S, 4444 CXXScopeSpec &SS, 4445 SourceLocation TemplateKWLoc, 4446 UnqualifiedId &Name, 4447 ParsedType ObjectType, 4448 bool EnteringContext, 4449 TemplateTy &Template); 4450 4451 DeclResult 4452 ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, TagUseKind TUK, 4453 SourceLocation KWLoc, 4454 SourceLocation ModulePrivateLoc, 4455 CXXScopeSpec &SS, 4456 TemplateTy Template, 4457 SourceLocation TemplateNameLoc, 4458 SourceLocation LAngleLoc, 4459 ASTTemplateArgsPtr TemplateArgs, 4460 SourceLocation RAngleLoc, 4461 AttributeList *Attr, 4462 MultiTemplateParamsArg TemplateParameterLists); 4463 4464 Decl *ActOnTemplateDeclarator(Scope *S, 4465 MultiTemplateParamsArg TemplateParameterLists, 4466 Declarator &D); 4467 4468 Decl *ActOnStartOfFunctionTemplateDef(Scope *FnBodyScope, 4469 MultiTemplateParamsArg TemplateParameterLists, 4470 Declarator &D); 4471 4472 bool 4473 CheckSpecializationInstantiationRedecl(SourceLocation NewLoc, 4474 TemplateSpecializationKind NewTSK, 4475 NamedDecl *PrevDecl, 4476 TemplateSpecializationKind PrevTSK, 4477 SourceLocation PrevPtOfInstantiation, 4478 bool &SuppressNew); 4479 4480 bool CheckDependentFunctionTemplateSpecialization(FunctionDecl *FD, 4481 const TemplateArgumentListInfo &ExplicitTemplateArgs, 4482 LookupResult &Previous); 4483 4484 bool CheckFunctionTemplateSpecialization(FunctionDecl *FD, 4485 TemplateArgumentListInfo *ExplicitTemplateArgs, 4486 LookupResult &Previous); 4487 bool CheckMemberSpecialization(NamedDecl *Member, LookupResult &Previous); 4488 4489 DeclResult 4490 ActOnExplicitInstantiation(Scope *S, 4491 SourceLocation ExternLoc, 4492 SourceLocation TemplateLoc, 4493 unsigned TagSpec, 4494 SourceLocation KWLoc, 4495 const CXXScopeSpec &SS, 4496 TemplateTy Template, 4497 SourceLocation TemplateNameLoc, 4498 SourceLocation LAngleLoc, 4499 ASTTemplateArgsPtr TemplateArgs, 4500 SourceLocation RAngleLoc, 4501 AttributeList *Attr); 4502 4503 DeclResult 4504 ActOnExplicitInstantiation(Scope *S, 4505 SourceLocation ExternLoc, 4506 SourceLocation TemplateLoc, 4507 unsigned TagSpec, 4508 SourceLocation KWLoc, 4509 CXXScopeSpec &SS, 4510 IdentifierInfo *Name, 4511 SourceLocation NameLoc, 4512 AttributeList *Attr); 4513 4514 DeclResult ActOnExplicitInstantiation(Scope *S, 4515 SourceLocation ExternLoc, 4516 SourceLocation TemplateLoc, 4517 Declarator &D); 4518 4519 TemplateArgumentLoc 4520 SubstDefaultTemplateArgumentIfAvailable(TemplateDecl *Template, 4521 SourceLocation TemplateLoc, 4522 SourceLocation RAngleLoc, 4523 Decl *Param, 4524 SmallVectorImpl<TemplateArgument> &Converted); 4525 4526 /// \brief Specifies the context in which a particular template 4527 /// argument is being checked. 4528 enum CheckTemplateArgumentKind { 4529 /// \brief The template argument was specified in the code or was 4530 /// instantiated with some deduced template arguments. 4531 CTAK_Specified, 4532 4533 /// \brief The template argument was deduced via template argument 4534 /// deduction. 4535 CTAK_Deduced, 4536 4537 /// \brief The template argument was deduced from an array bound 4538 /// via template argument deduction. 4539 CTAK_DeducedFromArrayBound 4540 }; 4541 4542 bool CheckTemplateArgument(NamedDecl *Param, 4543 const TemplateArgumentLoc &Arg, 4544 NamedDecl *Template, 4545 SourceLocation TemplateLoc, 4546 SourceLocation RAngleLoc, 4547 unsigned ArgumentPackIndex, 4548 SmallVectorImpl<TemplateArgument> &Converted, 4549 CheckTemplateArgumentKind CTAK = CTAK_Specified); 4550 4551 /// \brief Check that the given template arguments can be be provided to 4552 /// the given template, converting the arguments along the way. 4553 /// 4554 /// \param Template The template to which the template arguments are being 4555 /// provided. 4556 /// 4557 /// \param TemplateLoc The location of the template name in the source. 4558 /// 4559 /// \param TemplateArgs The list of template arguments. If the template is 4560 /// a template template parameter, this function may extend the set of 4561 /// template arguments to also include substituted, defaulted template 4562 /// arguments. 4563 /// 4564 /// \param PartialTemplateArgs True if the list of template arguments is 4565 /// intentionally partial, e.g., because we're checking just the initial 4566 /// set of template arguments. 4567 /// 4568 /// \param Converted Will receive the converted, canonicalized template 4569 /// arguments. 4570 /// 4571 /// 4572 /// \param ExpansionIntoFixedList If non-NULL, will be set true to indicate 4573 /// when the template arguments contain a pack expansion that is being 4574 /// expanded into a fixed parameter list. 4575 /// 4576 /// \returns True if an error occurred, false otherwise. 4577 bool CheckTemplateArgumentList(TemplateDecl *Template, 4578 SourceLocation TemplateLoc, 4579 TemplateArgumentListInfo &TemplateArgs, 4580 bool PartialTemplateArgs, 4581 SmallVectorImpl<TemplateArgument> &Converted, 4582 bool *ExpansionIntoFixedList = 0); 4583 4584 bool CheckTemplateTypeArgument(TemplateTypeParmDecl *Param, 4585 const TemplateArgumentLoc &Arg, 4586 SmallVectorImpl<TemplateArgument> &Converted); 4587 4588 bool CheckTemplateArgument(TemplateTypeParmDecl *Param, 4589 TypeSourceInfo *Arg); 4590 ExprResult CheckTemplateArgument(NonTypeTemplateParmDecl *Param, 4591 QualType InstantiatedParamType, Expr *Arg, 4592 TemplateArgument &Converted, 4593 CheckTemplateArgumentKind CTAK = CTAK_Specified); 4594 bool CheckTemplateArgument(TemplateTemplateParmDecl *Param, 4595 const TemplateArgumentLoc &Arg); 4596 4597 ExprResult 4598 BuildExpressionFromDeclTemplateArgument(const TemplateArgument &Arg, 4599 QualType ParamType, 4600 SourceLocation Loc); 4601 ExprResult 4602 BuildExpressionFromIntegralTemplateArgument(const TemplateArgument &Arg, 4603 SourceLocation Loc); 4604 4605 /// \brief Enumeration describing how template parameter lists are compared 4606 /// for equality. 4607 enum TemplateParameterListEqualKind { 4608 /// \brief We are matching the template parameter lists of two templates 4609 /// that might be redeclarations. 4610 /// 4611 /// \code 4612 /// template<typename T> struct X; 4613 /// template<typename T> struct X; 4614 /// \endcode 4615 TPL_TemplateMatch, 4616 4617 /// \brief We are matching the template parameter lists of two template 4618 /// template parameters as part of matching the template parameter lists 4619 /// of two templates that might be redeclarations. 4620 /// 4621 /// \code 4622 /// template<template<int I> class TT> struct X; 4623 /// template<template<int Value> class Other> struct X; 4624 /// \endcode 4625 TPL_TemplateTemplateParmMatch, 4626 4627 /// \brief We are matching the template parameter lists of a template 4628 /// template argument against the template parameter lists of a template 4629 /// template parameter. 4630 /// 4631 /// \code 4632 /// template<template<int Value> class Metafun> struct X; 4633 /// template<int Value> struct integer_c; 4634 /// X<integer_c> xic; 4635 /// \endcode 4636 TPL_TemplateTemplateArgumentMatch 4637 }; 4638 4639 bool TemplateParameterListsAreEqual(TemplateParameterList *New, 4640 TemplateParameterList *Old, 4641 bool Complain, 4642 TemplateParameterListEqualKind Kind, 4643 SourceLocation TemplateArgLoc 4644 = SourceLocation()); 4645 4646 bool CheckTemplateDeclScope(Scope *S, TemplateParameterList *TemplateParams); 4647 4648 /// \brief Called when the parser has parsed a C++ typename 4649 /// specifier, e.g., "typename T::type". 4650 /// 4651 /// \param S The scope in which this typename type occurs. 4652 /// \param TypenameLoc the location of the 'typename' keyword 4653 /// \param SS the nested-name-specifier following the typename (e.g., 'T::'). 4654 /// \param II the identifier we're retrieving (e.g., 'type' in the example). 4655 /// \param IdLoc the location of the identifier. 4656 TypeResult 4657 ActOnTypenameType(Scope *S, SourceLocation TypenameLoc, 4658 const CXXScopeSpec &SS, const IdentifierInfo &II, 4659 SourceLocation IdLoc); 4660 4661 /// \brief Called when the parser has parsed a C++ typename 4662 /// specifier that ends in a template-id, e.g., 4663 /// "typename MetaFun::template apply<T1, T2>". 4664 /// 4665 /// \param S The scope in which this typename type occurs. 4666 /// \param TypenameLoc the location of the 'typename' keyword 4667 /// \param SS the nested-name-specifier following the typename (e.g., 'T::'). 4668 /// \param TemplateLoc the location of the 'template' keyword, if any. 4669 /// \param TemplateName The template name. 4670 /// \param TemplateNameLoc The location of the template name. 4671 /// \param LAngleLoc The location of the opening angle bracket ('<'). 4672 /// \param TemplateArgs The template arguments. 4673 /// \param RAngleLoc The location of the closing angle bracket ('>'). 4674 TypeResult 4675 ActOnTypenameType(Scope *S, SourceLocation TypenameLoc, 4676 const CXXScopeSpec &SS, 4677 SourceLocation TemplateLoc, 4678 TemplateTy Template, 4679 SourceLocation TemplateNameLoc, 4680 SourceLocation LAngleLoc, 4681 ASTTemplateArgsPtr TemplateArgs, 4682 SourceLocation RAngleLoc); 4683 4684 QualType CheckTypenameType(ElaboratedTypeKeyword Keyword, 4685 SourceLocation KeywordLoc, 4686 NestedNameSpecifierLoc QualifierLoc, 4687 const IdentifierInfo &II, 4688 SourceLocation IILoc); 4689 4690 TypeSourceInfo *RebuildTypeInCurrentInstantiation(TypeSourceInfo *T, 4691 SourceLocation Loc, 4692 DeclarationName Name); 4693 bool RebuildNestedNameSpecifierInCurrentInstantiation(CXXScopeSpec &SS); 4694 4695 ExprResult RebuildExprInCurrentInstantiation(Expr *E); 4696 bool RebuildTemplateParamsInCurrentInstantiation( 4697 TemplateParameterList *Params); 4698 4699 std::string 4700 getTemplateArgumentBindingsText(const TemplateParameterList *Params, 4701 const TemplateArgumentList &Args); 4702 4703 std::string 4704 getTemplateArgumentBindingsText(const TemplateParameterList *Params, 4705 const TemplateArgument *Args, 4706 unsigned NumArgs); 4707 4708 //===--------------------------------------------------------------------===// 4709 // C++ Variadic Templates (C++0x [temp.variadic]) 4710 //===--------------------------------------------------------------------===// 4711 4712 /// \brief The context in which an unexpanded parameter pack is 4713 /// being diagnosed. 4714 /// 4715 /// Note that the values of this enumeration line up with the first 4716 /// argument to the \c err_unexpanded_parameter_pack diagnostic. 4717 enum UnexpandedParameterPackContext { 4718 /// \brief An arbitrary expression. 4719 UPPC_Expression = 0, 4720 4721 /// \brief The base type of a class type. 4722 UPPC_BaseType, 4723 4724 /// \brief The type of an arbitrary declaration. 4725 UPPC_DeclarationType, 4726 4727 /// \brief The type of a data member. 4728 UPPC_DataMemberType, 4729 4730 /// \brief The size of a bit-field. 4731 UPPC_BitFieldWidth, 4732 4733 /// \brief The expression in a static assertion. 4734 UPPC_StaticAssertExpression, 4735 4736 /// \brief The fixed underlying type of an enumeration. 4737 UPPC_FixedUnderlyingType, 4738 4739 /// \brief The enumerator value. 4740 UPPC_EnumeratorValue, 4741 4742 /// \brief A using declaration. 4743 UPPC_UsingDeclaration, 4744 4745 /// \brief A friend declaration. 4746 UPPC_FriendDeclaration, 4747 4748 /// \brief A declaration qualifier. 4749 UPPC_DeclarationQualifier, 4750 4751 /// \brief An initializer. 4752 UPPC_Initializer, 4753 4754 /// \brief A default argument. 4755 UPPC_DefaultArgument, 4756 4757 /// \brief The type of a non-type template parameter. 4758 UPPC_NonTypeTemplateParameterType, 4759 4760 /// \brief The type of an exception. 4761 UPPC_ExceptionType, 4762 4763 /// \brief Partial specialization. 4764 UPPC_PartialSpecialization, 4765 4766 /// \brief Microsoft __if_exists. 4767 UPPC_IfExists, 4768 4769 /// \brief Microsoft __if_not_exists. 4770 UPPC_IfNotExists 4771}; 4772 4773 /// \brief Diagnose unexpanded parameter packs. 4774 /// 4775 /// \param Loc The location at which we should emit the diagnostic. 4776 /// 4777 /// \param UPPC The context in which we are diagnosing unexpanded 4778 /// parameter packs. 4779 /// 4780 /// \param Unexpanded the set of unexpanded parameter packs. 4781 void DiagnoseUnexpandedParameterPacks(SourceLocation Loc, 4782 UnexpandedParameterPackContext UPPC, 4783 ArrayRef<UnexpandedParameterPack> Unexpanded); 4784 4785 /// \brief If the given type contains an unexpanded parameter pack, 4786 /// diagnose the error. 4787 /// 4788 /// \param Loc The source location where a diagnostc should be emitted. 4789 /// 4790 /// \param T The type that is being checked for unexpanded parameter 4791 /// packs. 4792 /// 4793 /// \returns true if an error occurred, false otherwise. 4794 bool DiagnoseUnexpandedParameterPack(SourceLocation Loc, TypeSourceInfo *T, 4795 UnexpandedParameterPackContext UPPC); 4796 4797 /// \brief If the given expression contains an unexpanded parameter 4798 /// pack, diagnose the error. 4799 /// 4800 /// \param E The expression that is being checked for unexpanded 4801 /// parameter packs. 4802 /// 4803 /// \returns true if an error occurred, false otherwise. 4804 bool DiagnoseUnexpandedParameterPack(Expr *E, 4805 UnexpandedParameterPackContext UPPC = UPPC_Expression); 4806 4807 /// \brief If the given nested-name-specifier contains an unexpanded 4808 /// parameter pack, diagnose the error. 4809 /// 4810 /// \param SS The nested-name-specifier that is being checked for 4811 /// unexpanded parameter packs. 4812 /// 4813 /// \returns true if an error occurred, false otherwise. 4814 bool DiagnoseUnexpandedParameterPack(const CXXScopeSpec &SS, 4815 UnexpandedParameterPackContext UPPC); 4816 4817 /// \brief If the given name contains an unexpanded parameter pack, 4818 /// diagnose the error. 4819 /// 4820 /// \param NameInfo The name (with source location information) that 4821 /// is being checked for unexpanded parameter packs. 4822 /// 4823 /// \returns true if an error occurred, false otherwise. 4824 bool DiagnoseUnexpandedParameterPack(const DeclarationNameInfo &NameInfo, 4825 UnexpandedParameterPackContext UPPC); 4826 4827 /// \brief If the given template name contains an unexpanded parameter pack, 4828 /// diagnose the error. 4829 /// 4830 /// \param Loc The location of the template name. 4831 /// 4832 /// \param Template The template name that is being checked for unexpanded 4833 /// parameter packs. 4834 /// 4835 /// \returns true if an error occurred, false otherwise. 4836 bool DiagnoseUnexpandedParameterPack(SourceLocation Loc, 4837 TemplateName Template, 4838 UnexpandedParameterPackContext UPPC); 4839 4840 /// \brief If the given template argument contains an unexpanded parameter 4841 /// pack, diagnose the error. 4842 /// 4843 /// \param Arg The template argument that is being checked for unexpanded 4844 /// parameter packs. 4845 /// 4846 /// \returns true if an error occurred, false otherwise. 4847 bool DiagnoseUnexpandedParameterPack(TemplateArgumentLoc Arg, 4848 UnexpandedParameterPackContext UPPC); 4849 4850 /// \brief Collect the set of unexpanded parameter packs within the given 4851 /// template argument. 4852 /// 4853 /// \param Arg The template argument that will be traversed to find 4854 /// unexpanded parameter packs. 4855 void collectUnexpandedParameterPacks(TemplateArgument Arg, 4856 SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); 4857 4858 /// \brief Collect the set of unexpanded parameter packs within the given 4859 /// template argument. 4860 /// 4861 /// \param Arg The template argument that will be traversed to find 4862 /// unexpanded parameter packs. 4863 void collectUnexpandedParameterPacks(TemplateArgumentLoc Arg, 4864 SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); 4865 4866 /// \brief Collect the set of unexpanded parameter packs within the given 4867 /// type. 4868 /// 4869 /// \param T The type that will be traversed to find 4870 /// unexpanded parameter packs. 4871 void collectUnexpandedParameterPacks(QualType T, 4872 SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); 4873 4874 /// \brief Collect the set of unexpanded parameter packs within the given 4875 /// type. 4876 /// 4877 /// \param TL The type that will be traversed to find 4878 /// unexpanded parameter packs. 4879 void collectUnexpandedParameterPacks(TypeLoc TL, 4880 SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); 4881 4882 /// \brief Collect the set of unexpanded parameter packs within the given 4883 /// nested-name-specifier. 4884 /// 4885 /// \param SS The nested-name-specifier that will be traversed to find 4886 /// unexpanded parameter packs. 4887 void collectUnexpandedParameterPacks(CXXScopeSpec &SS, 4888 SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); 4889 4890 /// \brief Collect the set of unexpanded parameter packs within the given 4891 /// name. 4892 /// 4893 /// \param NameInfo The name that will be traversed to find 4894 /// unexpanded parameter packs. 4895 void collectUnexpandedParameterPacks(const DeclarationNameInfo &NameInfo, 4896 SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); 4897 4898 /// \brief Invoked when parsing a template argument followed by an 4899 /// ellipsis, which creates a pack expansion. 4900 /// 4901 /// \param Arg The template argument preceding the ellipsis, which 4902 /// may already be invalid. 4903 /// 4904 /// \param EllipsisLoc The location of the ellipsis. 4905 ParsedTemplateArgument ActOnPackExpansion(const ParsedTemplateArgument &Arg, 4906 SourceLocation EllipsisLoc); 4907 4908 /// \brief Invoked when parsing a type followed by an ellipsis, which 4909 /// creates a pack expansion. 4910 /// 4911 /// \param Type The type preceding the ellipsis, which will become 4912 /// the pattern of the pack expansion. 4913 /// 4914 /// \param EllipsisLoc The location of the ellipsis. 4915 TypeResult ActOnPackExpansion(ParsedType Type, SourceLocation EllipsisLoc); 4916 4917 /// \brief Construct a pack expansion type from the pattern of the pack 4918 /// expansion. 4919 TypeSourceInfo *CheckPackExpansion(TypeSourceInfo *Pattern, 4920 SourceLocation EllipsisLoc, 4921 llvm::Optional<unsigned> NumExpansions); 4922 4923 /// \brief Construct a pack expansion type from the pattern of the pack 4924 /// expansion. 4925 QualType CheckPackExpansion(QualType Pattern, 4926 SourceRange PatternRange, 4927 SourceLocation EllipsisLoc, 4928 llvm::Optional<unsigned> NumExpansions); 4929 4930 /// \brief Invoked when parsing an expression followed by an ellipsis, which 4931 /// creates a pack expansion. 4932 /// 4933 /// \param Pattern The expression preceding the ellipsis, which will become 4934 /// the pattern of the pack expansion. 4935 /// 4936 /// \param EllipsisLoc The location of the ellipsis. 4937 ExprResult ActOnPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc); 4938 4939 /// \brief Invoked when parsing an expression followed by an ellipsis, which 4940 /// creates a pack expansion. 4941 /// 4942 /// \param Pattern The expression preceding the ellipsis, which will become 4943 /// the pattern of the pack expansion. 4944 /// 4945 /// \param EllipsisLoc The location of the ellipsis. 4946 ExprResult CheckPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc, 4947 llvm::Optional<unsigned> NumExpansions); 4948 4949 /// \brief Determine whether we could expand a pack expansion with the 4950 /// given set of parameter packs into separate arguments by repeatedly 4951 /// transforming the pattern. 4952 /// 4953 /// \param EllipsisLoc The location of the ellipsis that identifies the 4954 /// pack expansion. 4955 /// 4956 /// \param PatternRange The source range that covers the entire pattern of 4957 /// the pack expansion. 4958 /// 4959 /// \param Unexpanded The set of unexpanded parameter packs within the 4960 /// pattern. 4961 /// 4962 /// \param NumUnexpanded The number of unexpanded parameter packs in 4963 /// \p Unexpanded. 4964 /// 4965 /// \param ShouldExpand Will be set to \c true if the transformer should 4966 /// expand the corresponding pack expansions into separate arguments. When 4967 /// set, \c NumExpansions must also be set. 4968 /// 4969 /// \param RetainExpansion Whether the caller should add an unexpanded 4970 /// pack expansion after all of the expanded arguments. This is used 4971 /// when extending explicitly-specified template argument packs per 4972 /// C++0x [temp.arg.explicit]p9. 4973 /// 4974 /// \param NumExpansions The number of separate arguments that will be in 4975 /// the expanded form of the corresponding pack expansion. This is both an 4976 /// input and an output parameter, which can be set by the caller if the 4977 /// number of expansions is known a priori (e.g., due to a prior substitution) 4978 /// and will be set by the callee when the number of expansions is known. 4979 /// The callee must set this value when \c ShouldExpand is \c true; it may 4980 /// set this value in other cases. 4981 /// 4982 /// \returns true if an error occurred (e.g., because the parameter packs 4983 /// are to be instantiated with arguments of different lengths), false 4984 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions) 4985 /// must be set. 4986 bool CheckParameterPacksForExpansion(SourceLocation EllipsisLoc, 4987 SourceRange PatternRange, 4988 llvm::ArrayRef<UnexpandedParameterPack> Unexpanded, 4989 const MultiLevelTemplateArgumentList &TemplateArgs, 4990 bool &ShouldExpand, 4991 bool &RetainExpansion, 4992 llvm::Optional<unsigned> &NumExpansions); 4993 4994 /// \brief Determine the number of arguments in the given pack expansion 4995 /// type. 4996 /// 4997 /// This routine already assumes that the pack expansion type can be 4998 /// expanded and that the number of arguments in the expansion is 4999 /// consistent across all of the unexpanded parameter packs in its pattern. 5000 unsigned getNumArgumentsInExpansion(QualType T, 5001 const MultiLevelTemplateArgumentList &TemplateArgs); 5002 5003 /// \brief Determine whether the given declarator contains any unexpanded 5004 /// parameter packs. 5005 /// 5006 /// This routine is used by the parser to disambiguate function declarators 5007 /// with an ellipsis prior to the ')', e.g., 5008 /// 5009 /// \code 5010 /// void f(T...); 5011 /// \endcode 5012 /// 5013 /// To determine whether we have an (unnamed) function parameter pack or 5014 /// a variadic function. 5015 /// 5016 /// \returns true if the declarator contains any unexpanded parameter packs, 5017 /// false otherwise. 5018 bool containsUnexpandedParameterPacks(Declarator &D); 5019 5020 //===--------------------------------------------------------------------===// 5021 // C++ Template Argument Deduction (C++ [temp.deduct]) 5022 //===--------------------------------------------------------------------===// 5023 5024 /// \brief Describes the result of template argument deduction. 5025 /// 5026 /// The TemplateDeductionResult enumeration describes the result of 5027 /// template argument deduction, as returned from 5028 /// DeduceTemplateArguments(). The separate TemplateDeductionInfo 5029 /// structure provides additional information about the results of 5030 /// template argument deduction, e.g., the deduced template argument 5031 /// list (if successful) or the specific template parameters or 5032 /// deduced arguments that were involved in the failure. 5033 enum TemplateDeductionResult { 5034 /// \brief Template argument deduction was successful. 5035 TDK_Success = 0, 5036 /// \brief Template argument deduction exceeded the maximum template 5037 /// instantiation depth (which has already been diagnosed). 5038 TDK_InstantiationDepth, 5039 /// \brief Template argument deduction did not deduce a value 5040 /// for every template parameter. 5041 TDK_Incomplete, 5042 /// \brief Template argument deduction produced inconsistent 5043 /// deduced values for the given template parameter. 5044 TDK_Inconsistent, 5045 /// \brief Template argument deduction failed due to inconsistent 5046 /// cv-qualifiers on a template parameter type that would 5047 /// otherwise be deduced, e.g., we tried to deduce T in "const T" 5048 /// but were given a non-const "X". 5049 TDK_Underqualified, 5050 /// \brief Substitution of the deduced template argument values 5051 /// resulted in an error. 5052 TDK_SubstitutionFailure, 5053 /// \brief Substitution of the deduced template argument values 5054 /// into a non-deduced context produced a type or value that 5055 /// produces a type that does not match the original template 5056 /// arguments provided. 5057 TDK_NonDeducedMismatch, 5058 /// \brief When performing template argument deduction for a function 5059 /// template, there were too many call arguments. 5060 TDK_TooManyArguments, 5061 /// \brief When performing template argument deduction for a function 5062 /// template, there were too few call arguments. 5063 TDK_TooFewArguments, 5064 /// \brief The explicitly-specified template arguments were not valid 5065 /// template arguments for the given template. 5066 TDK_InvalidExplicitArguments, 5067 /// \brief The arguments included an overloaded function name that could 5068 /// not be resolved to a suitable function. 5069 TDK_FailedOverloadResolution 5070 }; 5071 5072 TemplateDeductionResult 5073 DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial, 5074 const TemplateArgumentList &TemplateArgs, 5075 sema::TemplateDeductionInfo &Info); 5076 5077 TemplateDeductionResult 5078 SubstituteExplicitTemplateArguments(FunctionTemplateDecl *FunctionTemplate, 5079 TemplateArgumentListInfo &ExplicitTemplateArgs, 5080 SmallVectorImpl<DeducedTemplateArgument> &Deduced, 5081 SmallVectorImpl<QualType> &ParamTypes, 5082 QualType *FunctionType, 5083 sema::TemplateDeductionInfo &Info); 5084 5085 /// brief A function argument from which we performed template argument 5086 // deduction for a call. 5087 struct OriginalCallArg { 5088 OriginalCallArg(QualType OriginalParamType, 5089 unsigned ArgIdx, 5090 QualType OriginalArgType) 5091 : OriginalParamType(OriginalParamType), ArgIdx(ArgIdx), 5092 OriginalArgType(OriginalArgType) { } 5093 5094 QualType OriginalParamType; 5095 unsigned ArgIdx; 5096 QualType OriginalArgType; 5097 }; 5098 5099 TemplateDeductionResult 5100 FinishTemplateArgumentDeduction(FunctionTemplateDecl *FunctionTemplate, 5101 SmallVectorImpl<DeducedTemplateArgument> &Deduced, 5102 unsigned NumExplicitlySpecified, 5103 FunctionDecl *&Specialization, 5104 sema::TemplateDeductionInfo &Info, 5105 SmallVectorImpl<OriginalCallArg> const *OriginalCallArgs = 0); 5106 5107 TemplateDeductionResult 5108 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, 5109 TemplateArgumentListInfo *ExplicitTemplateArgs, 5110 llvm::ArrayRef<Expr *> Args, 5111 FunctionDecl *&Specialization, 5112 sema::TemplateDeductionInfo &Info); 5113 5114 TemplateDeductionResult 5115 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, 5116 TemplateArgumentListInfo *ExplicitTemplateArgs, 5117 QualType ArgFunctionType, 5118 FunctionDecl *&Specialization, 5119 sema::TemplateDeductionInfo &Info); 5120 5121 TemplateDeductionResult 5122 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, 5123 QualType ToType, 5124 CXXConversionDecl *&Specialization, 5125 sema::TemplateDeductionInfo &Info); 5126 5127 TemplateDeductionResult 5128 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, 5129 TemplateArgumentListInfo *ExplicitTemplateArgs, 5130 FunctionDecl *&Specialization, 5131 sema::TemplateDeductionInfo &Info); 5132 5133 /// \brief Result type of DeduceAutoType. 5134 enum DeduceAutoResult { 5135 DAR_Succeeded, 5136 DAR_Failed, 5137 DAR_FailedAlreadyDiagnosed 5138 }; 5139 5140 DeduceAutoResult DeduceAutoType(TypeSourceInfo *AutoType, Expr *&Initializer, 5141 TypeSourceInfo *&Result); 5142 void DiagnoseAutoDeductionFailure(VarDecl *VDecl, Expr *Init); 5143 5144 FunctionTemplateDecl *getMoreSpecializedTemplate(FunctionTemplateDecl *FT1, 5145 FunctionTemplateDecl *FT2, 5146 SourceLocation Loc, 5147 TemplatePartialOrderingContext TPOC, 5148 unsigned NumCallArguments); 5149 UnresolvedSetIterator getMostSpecialized(UnresolvedSetIterator SBegin, 5150 UnresolvedSetIterator SEnd, 5151 TemplatePartialOrderingContext TPOC, 5152 unsigned NumCallArguments, 5153 SourceLocation Loc, 5154 const PartialDiagnostic &NoneDiag, 5155 const PartialDiagnostic &AmbigDiag, 5156 const PartialDiagnostic &CandidateDiag, 5157 bool Complain = true, 5158 QualType TargetType = QualType()); 5159 5160 ClassTemplatePartialSpecializationDecl * 5161 getMoreSpecializedPartialSpecialization( 5162 ClassTemplatePartialSpecializationDecl *PS1, 5163 ClassTemplatePartialSpecializationDecl *PS2, 5164 SourceLocation Loc); 5165 5166 void MarkUsedTemplateParameters(const TemplateArgumentList &TemplateArgs, 5167 bool OnlyDeduced, 5168 unsigned Depth, 5169 llvm::SmallBitVector &Used); 5170 void MarkDeducedTemplateParameters(FunctionTemplateDecl *FunctionTemplate, 5171 llvm::SmallBitVector &Deduced) { 5172 return MarkDeducedTemplateParameters(Context, FunctionTemplate, Deduced); 5173 } 5174 static void MarkDeducedTemplateParameters(ASTContext &Ctx, 5175 FunctionTemplateDecl *FunctionTemplate, 5176 llvm::SmallBitVector &Deduced); 5177 5178 //===--------------------------------------------------------------------===// 5179 // C++ Template Instantiation 5180 // 5181 5182 MultiLevelTemplateArgumentList getTemplateInstantiationArgs(NamedDecl *D, 5183 const TemplateArgumentList *Innermost = 0, 5184 bool RelativeToPrimary = false, 5185 const FunctionDecl *Pattern = 0); 5186 5187 /// \brief A template instantiation that is currently in progress. 5188 struct ActiveTemplateInstantiation { 5189 /// \brief The kind of template instantiation we are performing 5190 enum InstantiationKind { 5191 /// We are instantiating a template declaration. The entity is 5192 /// the declaration we're instantiating (e.g., a CXXRecordDecl). 5193 TemplateInstantiation, 5194 5195 /// We are instantiating a default argument for a template 5196 /// parameter. The Entity is the template, and 5197 /// TemplateArgs/NumTemplateArguments provides the template 5198 /// arguments as specified. 5199 /// FIXME: Use a TemplateArgumentList 5200 DefaultTemplateArgumentInstantiation, 5201 5202 /// We are instantiating a default argument for a function. 5203 /// The Entity is the ParmVarDecl, and TemplateArgs/NumTemplateArgs 5204 /// provides the template arguments as specified. 5205 DefaultFunctionArgumentInstantiation, 5206 5207 /// We are substituting explicit template arguments provided for 5208 /// a function template. The entity is a FunctionTemplateDecl. 5209 ExplicitTemplateArgumentSubstitution, 5210 5211 /// We are substituting template argument determined as part of 5212 /// template argument deduction for either a class template 5213 /// partial specialization or a function template. The 5214 /// Entity is either a ClassTemplatePartialSpecializationDecl or 5215 /// a FunctionTemplateDecl. 5216 DeducedTemplateArgumentSubstitution, 5217 5218 /// We are substituting prior template arguments into a new 5219 /// template parameter. The template parameter itself is either a 5220 /// NonTypeTemplateParmDecl or a TemplateTemplateParmDecl. 5221 PriorTemplateArgumentSubstitution, 5222 5223 /// We are checking the validity of a default template argument that 5224 /// has been used when naming a template-id. 5225 DefaultTemplateArgumentChecking, 5226 5227 /// We are instantiating the exception specification for a function 5228 /// template which was deferred until it was needed. 5229 ExceptionSpecInstantiation 5230 } Kind; 5231 5232 /// \brief The point of instantiation within the source code. 5233 SourceLocation PointOfInstantiation; 5234 5235 /// \brief The template (or partial specialization) in which we are 5236 /// performing the instantiation, for substitutions of prior template 5237 /// arguments. 5238 NamedDecl *Template; 5239 5240 /// \brief The entity that is being instantiated. 5241 uintptr_t Entity; 5242 5243 /// \brief The list of template arguments we are substituting, if they 5244 /// are not part of the entity. 5245 const TemplateArgument *TemplateArgs; 5246 5247 /// \brief The number of template arguments in TemplateArgs. 5248 unsigned NumTemplateArgs; 5249 5250 /// \brief The template deduction info object associated with the 5251 /// substitution or checking of explicit or deduced template arguments. 5252 sema::TemplateDeductionInfo *DeductionInfo; 5253 5254 /// \brief The source range that covers the construct that cause 5255 /// the instantiation, e.g., the template-id that causes a class 5256 /// template instantiation. 5257 SourceRange InstantiationRange; 5258 5259 ActiveTemplateInstantiation() 5260 : Kind(TemplateInstantiation), Template(0), Entity(0), TemplateArgs(0), 5261 NumTemplateArgs(0), DeductionInfo(0) {} 5262 5263 /// \brief Determines whether this template is an actual instantiation 5264 /// that should be counted toward the maximum instantiation depth. 5265 bool isInstantiationRecord() const; 5266 5267 friend bool operator==(const ActiveTemplateInstantiation &X, 5268 const ActiveTemplateInstantiation &Y) { 5269 if (X.Kind != Y.Kind) 5270 return false; 5271 5272 if (X.Entity != Y.Entity) 5273 return false; 5274 5275 switch (X.Kind) { 5276 case TemplateInstantiation: 5277 case ExceptionSpecInstantiation: 5278 return true; 5279 5280 case PriorTemplateArgumentSubstitution: 5281 case DefaultTemplateArgumentChecking: 5282 if (X.Template != Y.Template) 5283 return false; 5284 5285 // Fall through 5286 5287 case DefaultTemplateArgumentInstantiation: 5288 case ExplicitTemplateArgumentSubstitution: 5289 case DeducedTemplateArgumentSubstitution: 5290 case DefaultFunctionArgumentInstantiation: 5291 return X.TemplateArgs == Y.TemplateArgs; 5292 5293 } 5294 5295 llvm_unreachable("Invalid InstantiationKind!"); 5296 } 5297 5298 friend bool operator!=(const ActiveTemplateInstantiation &X, 5299 const ActiveTemplateInstantiation &Y) { 5300 return !(X == Y); 5301 } 5302 }; 5303 5304 /// \brief List of active template instantiations. 5305 /// 5306 /// This vector is treated as a stack. As one template instantiation 5307 /// requires another template instantiation, additional 5308 /// instantiations are pushed onto the stack up to a 5309 /// user-configurable limit LangOptions::InstantiationDepth. 5310 SmallVector<ActiveTemplateInstantiation, 16> 5311 ActiveTemplateInstantiations; 5312 5313 /// \brief Whether we are in a SFINAE context that is not associated with 5314 /// template instantiation. 5315 /// 5316 /// This is used when setting up a SFINAE trap (\c see SFINAETrap) outside 5317 /// of a template instantiation or template argument deduction. 5318 bool InNonInstantiationSFINAEContext; 5319 5320 /// \brief The number of ActiveTemplateInstantiation entries in 5321 /// \c ActiveTemplateInstantiations that are not actual instantiations and, 5322 /// therefore, should not be counted as part of the instantiation depth. 5323 unsigned NonInstantiationEntries; 5324 5325 /// \brief The last template from which a template instantiation 5326 /// error or warning was produced. 5327 /// 5328 /// This value is used to suppress printing of redundant template 5329 /// instantiation backtraces when there are multiple errors in the 5330 /// same instantiation. FIXME: Does this belong in Sema? It's tough 5331 /// to implement it anywhere else. 5332 ActiveTemplateInstantiation LastTemplateInstantiationErrorContext; 5333 5334 /// \brief The current index into pack expansion arguments that will be 5335 /// used for substitution of parameter packs. 5336 /// 5337 /// The pack expansion index will be -1 to indicate that parameter packs 5338 /// should be instantiated as themselves. Otherwise, the index specifies 5339 /// which argument within the parameter pack will be used for substitution. 5340 int ArgumentPackSubstitutionIndex; 5341 5342 /// \brief RAII object used to change the argument pack substitution index 5343 /// within a \c Sema object. 5344 /// 5345 /// See \c ArgumentPackSubstitutionIndex for more information. 5346 class ArgumentPackSubstitutionIndexRAII { 5347 Sema &Self; 5348 int OldSubstitutionIndex; 5349 5350 public: 5351 ArgumentPackSubstitutionIndexRAII(Sema &Self, int NewSubstitutionIndex) 5352 : Self(Self), OldSubstitutionIndex(Self.ArgumentPackSubstitutionIndex) { 5353 Self.ArgumentPackSubstitutionIndex = NewSubstitutionIndex; 5354 } 5355 5356 ~ArgumentPackSubstitutionIndexRAII() { 5357 Self.ArgumentPackSubstitutionIndex = OldSubstitutionIndex; 5358 } 5359 }; 5360 5361 friend class ArgumentPackSubstitutionRAII; 5362 5363 /// \brief The stack of calls expression undergoing template instantiation. 5364 /// 5365 /// The top of this stack is used by a fixit instantiating unresolved 5366 /// function calls to fix the AST to match the textual change it prints. 5367 SmallVector<CallExpr *, 8> CallsUndergoingInstantiation; 5368 5369 /// \brief For each declaration that involved template argument deduction, the 5370 /// set of diagnostics that were suppressed during that template argument 5371 /// deduction. 5372 /// 5373 /// FIXME: Serialize this structure to the AST file. 5374 llvm::DenseMap<Decl *, SmallVector<PartialDiagnosticAt, 1> > 5375 SuppressedDiagnostics; 5376 5377 /// \brief A stack object to be created when performing template 5378 /// instantiation. 5379 /// 5380 /// Construction of an object of type \c InstantiatingTemplate 5381 /// pushes the current instantiation onto the stack of active 5382 /// instantiations. If the size of this stack exceeds the maximum 5383 /// number of recursive template instantiations, construction 5384 /// produces an error and evaluates true. 5385 /// 5386 /// Destruction of this object will pop the named instantiation off 5387 /// the stack. 5388 struct InstantiatingTemplate { 5389 /// \brief Note that we are instantiating a class template, 5390 /// function template, or a member thereof. 5391 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 5392 Decl *Entity, 5393 SourceRange InstantiationRange = SourceRange()); 5394 5395 struct ExceptionSpecification {}; 5396 /// \brief Note that we are instantiating an exception specification 5397 /// of a function template. 5398 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 5399 FunctionDecl *Entity, ExceptionSpecification, 5400 SourceRange InstantiationRange = SourceRange()); 5401 5402 /// \brief Note that we are instantiating a default argument in a 5403 /// template-id. 5404 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 5405 TemplateDecl *Template, 5406 const TemplateArgument *TemplateArgs, 5407 unsigned NumTemplateArgs, 5408 SourceRange InstantiationRange = SourceRange()); 5409 5410 /// \brief Note that we are instantiating a default argument in a 5411 /// template-id. 5412 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 5413 FunctionTemplateDecl *FunctionTemplate, 5414 const TemplateArgument *TemplateArgs, 5415 unsigned NumTemplateArgs, 5416 ActiveTemplateInstantiation::InstantiationKind Kind, 5417 sema::TemplateDeductionInfo &DeductionInfo, 5418 SourceRange InstantiationRange = SourceRange()); 5419 5420 /// \brief Note that we are instantiating as part of template 5421 /// argument deduction for a class template partial 5422 /// specialization. 5423 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 5424 ClassTemplatePartialSpecializationDecl *PartialSpec, 5425 const TemplateArgument *TemplateArgs, 5426 unsigned NumTemplateArgs, 5427 sema::TemplateDeductionInfo &DeductionInfo, 5428 SourceRange InstantiationRange = SourceRange()); 5429 5430 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 5431 ParmVarDecl *Param, 5432 const TemplateArgument *TemplateArgs, 5433 unsigned NumTemplateArgs, 5434 SourceRange InstantiationRange = SourceRange()); 5435 5436 /// \brief Note that we are substituting prior template arguments into a 5437 /// non-type or template template parameter. 5438 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 5439 NamedDecl *Template, 5440 NonTypeTemplateParmDecl *Param, 5441 const TemplateArgument *TemplateArgs, 5442 unsigned NumTemplateArgs, 5443 SourceRange InstantiationRange); 5444 5445 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 5446 NamedDecl *Template, 5447 TemplateTemplateParmDecl *Param, 5448 const TemplateArgument *TemplateArgs, 5449 unsigned NumTemplateArgs, 5450 SourceRange InstantiationRange); 5451 5452 /// \brief Note that we are checking the default template argument 5453 /// against the template parameter for a given template-id. 5454 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 5455 TemplateDecl *Template, 5456 NamedDecl *Param, 5457 const TemplateArgument *TemplateArgs, 5458 unsigned NumTemplateArgs, 5459 SourceRange InstantiationRange); 5460 5461 5462 /// \brief Note that we have finished instantiating this template. 5463 void Clear(); 5464 5465 ~InstantiatingTemplate() { Clear(); } 5466 5467 /// \brief Determines whether we have exceeded the maximum 5468 /// recursive template instantiations. 5469 operator bool() const { return Invalid; } 5470 5471 private: 5472 Sema &SemaRef; 5473 bool Invalid; 5474 bool SavedInNonInstantiationSFINAEContext; 5475 bool CheckInstantiationDepth(SourceLocation PointOfInstantiation, 5476 SourceRange InstantiationRange); 5477 5478 InstantiatingTemplate(const InstantiatingTemplate&); // not implemented 5479 5480 InstantiatingTemplate& 5481 operator=(const InstantiatingTemplate&); // not implemented 5482 }; 5483 5484 void PrintInstantiationStack(); 5485 5486 /// \brief Determines whether we are currently in a context where 5487 /// template argument substitution failures are not considered 5488 /// errors. 5489 /// 5490 /// \returns An empty \c llvm::Optional if we're not in a SFINAE context. 5491 /// Otherwise, contains a pointer that, if non-NULL, contains the nearest 5492 /// template-deduction context object, which can be used to capture 5493 /// diagnostics that will be suppressed. 5494 llvm::Optional<sema::TemplateDeductionInfo *> isSFINAEContext() const; 5495 5496 /// \brief RAII class used to determine whether SFINAE has 5497 /// trapped any errors that occur during template argument 5498 /// deduction.` 5499 class SFINAETrap { 5500 Sema &SemaRef; 5501 unsigned PrevSFINAEErrors; 5502 bool PrevInNonInstantiationSFINAEContext; 5503 bool PrevAccessCheckingSFINAE; 5504 5505 public: 5506 explicit SFINAETrap(Sema &SemaRef, bool AccessCheckingSFINAE = false) 5507 : SemaRef(SemaRef), PrevSFINAEErrors(SemaRef.NumSFINAEErrors), 5508 PrevInNonInstantiationSFINAEContext( 5509 SemaRef.InNonInstantiationSFINAEContext), 5510 PrevAccessCheckingSFINAE(SemaRef.AccessCheckingSFINAE) 5511 { 5512 if (!SemaRef.isSFINAEContext()) 5513 SemaRef.InNonInstantiationSFINAEContext = true; 5514 SemaRef.AccessCheckingSFINAE = AccessCheckingSFINAE; 5515 } 5516 5517 ~SFINAETrap() { 5518 SemaRef.NumSFINAEErrors = PrevSFINAEErrors; 5519 SemaRef.InNonInstantiationSFINAEContext 5520 = PrevInNonInstantiationSFINAEContext; 5521 SemaRef.AccessCheckingSFINAE = PrevAccessCheckingSFINAE; 5522 } 5523 5524 /// \brief Determine whether any SFINAE errors have been trapped. 5525 bool hasErrorOccurred() const { 5526 return SemaRef.NumSFINAEErrors > PrevSFINAEErrors; 5527 } 5528 }; 5529 5530 /// \brief The current instantiation scope used to store local 5531 /// variables. 5532 LocalInstantiationScope *CurrentInstantiationScope; 5533 5534 /// \brief The number of typos corrected by CorrectTypo. 5535 unsigned TyposCorrected; 5536 5537 typedef llvm::DenseMap<IdentifierInfo *, TypoCorrection> 5538 UnqualifiedTyposCorrectedMap; 5539 5540 /// \brief A cache containing the results of typo correction for unqualified 5541 /// name lookup. 5542 /// 5543 /// The string is the string that we corrected to (which may be empty, if 5544 /// there was no correction), while the boolean will be true when the 5545 /// string represents a keyword. 5546 UnqualifiedTyposCorrectedMap UnqualifiedTyposCorrected; 5547 5548 /// \brief Worker object for performing CFG-based warnings. 5549 sema::AnalysisBasedWarnings AnalysisWarnings; 5550 5551 /// \brief An entity for which implicit template instantiation is required. 5552 /// 5553 /// The source location associated with the declaration is the first place in 5554 /// the source code where the declaration was "used". It is not necessarily 5555 /// the point of instantiation (which will be either before or after the 5556 /// namespace-scope declaration that triggered this implicit instantiation), 5557 /// However, it is the location that diagnostics should generally refer to, 5558 /// because users will need to know what code triggered the instantiation. 5559 typedef std::pair<ValueDecl *, SourceLocation> PendingImplicitInstantiation; 5560 5561 /// \brief The queue of implicit template instantiations that are required 5562 /// but have not yet been performed. 5563 std::deque<PendingImplicitInstantiation> PendingInstantiations; 5564 5565 /// \brief The queue of implicit template instantiations that are required 5566 /// and must be performed within the current local scope. 5567 /// 5568 /// This queue is only used for member functions of local classes in 5569 /// templates, which must be instantiated in the same scope as their 5570 /// enclosing function, so that they can reference function-local 5571 /// types, static variables, enumerators, etc. 5572 std::deque<PendingImplicitInstantiation> PendingLocalImplicitInstantiations; 5573 5574 void PerformPendingInstantiations(bool LocalOnly = false); 5575 5576 TypeSourceInfo *SubstType(TypeSourceInfo *T, 5577 const MultiLevelTemplateArgumentList &TemplateArgs, 5578 SourceLocation Loc, DeclarationName Entity); 5579 5580 QualType SubstType(QualType T, 5581 const MultiLevelTemplateArgumentList &TemplateArgs, 5582 SourceLocation Loc, DeclarationName Entity); 5583 5584 TypeSourceInfo *SubstType(TypeLoc TL, 5585 const MultiLevelTemplateArgumentList &TemplateArgs, 5586 SourceLocation Loc, DeclarationName Entity); 5587 5588 TypeSourceInfo *SubstFunctionDeclType(TypeSourceInfo *T, 5589 const MultiLevelTemplateArgumentList &TemplateArgs, 5590 SourceLocation Loc, 5591 DeclarationName Entity, 5592 CXXRecordDecl *ThisContext, 5593 unsigned ThisTypeQuals); 5594 ParmVarDecl *SubstParmVarDecl(ParmVarDecl *D, 5595 const MultiLevelTemplateArgumentList &TemplateArgs, 5596 int indexAdjustment, 5597 llvm::Optional<unsigned> NumExpansions, 5598 bool ExpectParameterPack); 5599 bool SubstParmTypes(SourceLocation Loc, 5600 ParmVarDecl **Params, unsigned NumParams, 5601 const MultiLevelTemplateArgumentList &TemplateArgs, 5602 SmallVectorImpl<QualType> &ParamTypes, 5603 SmallVectorImpl<ParmVarDecl *> *OutParams = 0); 5604 ExprResult SubstExpr(Expr *E, 5605 const MultiLevelTemplateArgumentList &TemplateArgs); 5606 5607 /// \brief Substitute the given template arguments into a list of 5608 /// expressions, expanding pack expansions if required. 5609 /// 5610 /// \param Exprs The list of expressions to substitute into. 5611 /// 5612 /// \param NumExprs The number of expressions in \p Exprs. 5613 /// 5614 /// \param IsCall Whether this is some form of call, in which case 5615 /// default arguments will be dropped. 5616 /// 5617 /// \param TemplateArgs The set of template arguments to substitute. 5618 /// 5619 /// \param Outputs Will receive all of the substituted arguments. 5620 /// 5621 /// \returns true if an error occurred, false otherwise. 5622 bool SubstExprs(Expr **Exprs, unsigned NumExprs, bool IsCall, 5623 const MultiLevelTemplateArgumentList &TemplateArgs, 5624 SmallVectorImpl<Expr *> &Outputs); 5625 5626 StmtResult SubstStmt(Stmt *S, 5627 const MultiLevelTemplateArgumentList &TemplateArgs); 5628 5629 Decl *SubstDecl(Decl *D, DeclContext *Owner, 5630 const MultiLevelTemplateArgumentList &TemplateArgs); 5631 5632 ExprResult SubstInitializer(Expr *E, 5633 const MultiLevelTemplateArgumentList &TemplateArgs, 5634 bool CXXDirectInit); 5635 5636 bool 5637 SubstBaseSpecifiers(CXXRecordDecl *Instantiation, 5638 CXXRecordDecl *Pattern, 5639 const MultiLevelTemplateArgumentList &TemplateArgs); 5640 5641 bool 5642 InstantiateClass(SourceLocation PointOfInstantiation, 5643 CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern, 5644 const MultiLevelTemplateArgumentList &TemplateArgs, 5645 TemplateSpecializationKind TSK, 5646 bool Complain = true); 5647 5648 bool InstantiateEnum(SourceLocation PointOfInstantiation, 5649 EnumDecl *Instantiation, EnumDecl *Pattern, 5650 const MultiLevelTemplateArgumentList &TemplateArgs, 5651 TemplateSpecializationKind TSK); 5652 5653 struct LateInstantiatedAttribute { 5654 const Attr *TmplAttr; 5655 LocalInstantiationScope *Scope; 5656 Decl *NewDecl; 5657 5658 LateInstantiatedAttribute(const Attr *A, LocalInstantiationScope *S, 5659 Decl *D) 5660 : TmplAttr(A), Scope(S), NewDecl(D) 5661 { } 5662 }; 5663 typedef SmallVector<LateInstantiatedAttribute, 16> LateInstantiatedAttrVec; 5664 5665 void InstantiateAttrs(const MultiLevelTemplateArgumentList &TemplateArgs, 5666 const Decl *Pattern, Decl *Inst, 5667 LateInstantiatedAttrVec *LateAttrs = 0, 5668 LocalInstantiationScope *OuterMostScope = 0); 5669 5670 bool 5671 InstantiateClassTemplateSpecialization(SourceLocation PointOfInstantiation, 5672 ClassTemplateSpecializationDecl *ClassTemplateSpec, 5673 TemplateSpecializationKind TSK, 5674 bool Complain = true); 5675 5676 void InstantiateClassMembers(SourceLocation PointOfInstantiation, 5677 CXXRecordDecl *Instantiation, 5678 const MultiLevelTemplateArgumentList &TemplateArgs, 5679 TemplateSpecializationKind TSK); 5680 5681 void InstantiateClassTemplateSpecializationMembers( 5682 SourceLocation PointOfInstantiation, 5683 ClassTemplateSpecializationDecl *ClassTemplateSpec, 5684 TemplateSpecializationKind TSK); 5685 5686 NestedNameSpecifierLoc 5687 SubstNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, 5688 const MultiLevelTemplateArgumentList &TemplateArgs); 5689 5690 DeclarationNameInfo 5691 SubstDeclarationNameInfo(const DeclarationNameInfo &NameInfo, 5692 const MultiLevelTemplateArgumentList &TemplateArgs); 5693 TemplateName 5694 SubstTemplateName(NestedNameSpecifierLoc QualifierLoc, TemplateName Name, 5695 SourceLocation Loc, 5696 const MultiLevelTemplateArgumentList &TemplateArgs); 5697 bool Subst(const TemplateArgumentLoc *Args, unsigned NumArgs, 5698 TemplateArgumentListInfo &Result, 5699 const MultiLevelTemplateArgumentList &TemplateArgs); 5700 5701 void InstantiateExceptionSpec(SourceLocation PointOfInstantiation, 5702 FunctionDecl *Function); 5703 void InstantiateFunctionDefinition(SourceLocation PointOfInstantiation, 5704 FunctionDecl *Function, 5705 bool Recursive = false, 5706 bool DefinitionRequired = false); 5707 void InstantiateStaticDataMemberDefinition( 5708 SourceLocation PointOfInstantiation, 5709 VarDecl *Var, 5710 bool Recursive = false, 5711 bool DefinitionRequired = false); 5712 5713 void InstantiateMemInitializers(CXXConstructorDecl *New, 5714 const CXXConstructorDecl *Tmpl, 5715 const MultiLevelTemplateArgumentList &TemplateArgs); 5716 5717 NamedDecl *FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D, 5718 const MultiLevelTemplateArgumentList &TemplateArgs); 5719 DeclContext *FindInstantiatedContext(SourceLocation Loc, DeclContext *DC, 5720 const MultiLevelTemplateArgumentList &TemplateArgs); 5721 5722 // Objective-C declarations. 5723 enum ObjCContainerKind { 5724 OCK_None = -1, 5725 OCK_Interface = 0, 5726 OCK_Protocol, 5727 OCK_Category, 5728 OCK_ClassExtension, 5729 OCK_Implementation, 5730 OCK_CategoryImplementation 5731 }; 5732 ObjCContainerKind getObjCContainerKind() const; 5733 5734 Decl *ActOnStartClassInterface(SourceLocation AtInterfaceLoc, 5735 IdentifierInfo *ClassName, 5736 SourceLocation ClassLoc, 5737 IdentifierInfo *SuperName, 5738 SourceLocation SuperLoc, 5739 Decl * const *ProtoRefs, 5740 unsigned NumProtoRefs, 5741 const SourceLocation *ProtoLocs, 5742 SourceLocation EndProtoLoc, 5743 AttributeList *AttrList); 5744 5745 Decl *ActOnCompatiblityAlias( 5746 SourceLocation AtCompatibilityAliasLoc, 5747 IdentifierInfo *AliasName, SourceLocation AliasLocation, 5748 IdentifierInfo *ClassName, SourceLocation ClassLocation); 5749 5750 bool CheckForwardProtocolDeclarationForCircularDependency( 5751 IdentifierInfo *PName, 5752 SourceLocation &PLoc, SourceLocation PrevLoc, 5753 const ObjCList<ObjCProtocolDecl> &PList); 5754 5755 Decl *ActOnStartProtocolInterface( 5756 SourceLocation AtProtoInterfaceLoc, 5757 IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc, 5758 Decl * const *ProtoRefNames, unsigned NumProtoRefs, 5759 const SourceLocation *ProtoLocs, 5760 SourceLocation EndProtoLoc, 5761 AttributeList *AttrList); 5762 5763 Decl *ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc, 5764 IdentifierInfo *ClassName, 5765 SourceLocation ClassLoc, 5766 IdentifierInfo *CategoryName, 5767 SourceLocation CategoryLoc, 5768 Decl * const *ProtoRefs, 5769 unsigned NumProtoRefs, 5770 const SourceLocation *ProtoLocs, 5771 SourceLocation EndProtoLoc); 5772 5773 Decl *ActOnStartClassImplementation( 5774 SourceLocation AtClassImplLoc, 5775 IdentifierInfo *ClassName, SourceLocation ClassLoc, 5776 IdentifierInfo *SuperClassname, 5777 SourceLocation SuperClassLoc); 5778 5779 Decl *ActOnStartCategoryImplementation(SourceLocation AtCatImplLoc, 5780 IdentifierInfo *ClassName, 5781 SourceLocation ClassLoc, 5782 IdentifierInfo *CatName, 5783 SourceLocation CatLoc); 5784 5785 DeclGroupPtrTy ActOnFinishObjCImplementation(Decl *ObjCImpDecl, 5786 ArrayRef<Decl *> Decls); 5787 5788 DeclGroupPtrTy ActOnForwardClassDeclaration(SourceLocation Loc, 5789 IdentifierInfo **IdentList, 5790 SourceLocation *IdentLocs, 5791 unsigned NumElts); 5792 5793 DeclGroupPtrTy ActOnForwardProtocolDeclaration(SourceLocation AtProtoclLoc, 5794 const IdentifierLocPair *IdentList, 5795 unsigned NumElts, 5796 AttributeList *attrList); 5797 5798 void FindProtocolDeclaration(bool WarnOnDeclarations, 5799 const IdentifierLocPair *ProtocolId, 5800 unsigned NumProtocols, 5801 SmallVectorImpl<Decl *> &Protocols); 5802 5803 /// Ensure attributes are consistent with type. 5804 /// \param [in, out] Attributes The attributes to check; they will 5805 /// be modified to be consistent with \arg PropertyTy. 5806 void CheckObjCPropertyAttributes(Decl *PropertyPtrTy, 5807 SourceLocation Loc, 5808 unsigned &Attributes); 5809 5810 /// Process the specified property declaration and create decls for the 5811 /// setters and getters as needed. 5812 /// \param property The property declaration being processed 5813 /// \param DC The semantic container for the property 5814 /// \param redeclaredProperty Declaration for property if redeclared 5815 /// in class extension. 5816 /// \param lexicalDC Container for redeclaredProperty. 5817 void ProcessPropertyDecl(ObjCPropertyDecl *property, 5818 ObjCContainerDecl *DC, 5819 ObjCPropertyDecl *redeclaredProperty = 0, 5820 ObjCContainerDecl *lexicalDC = 0); 5821 5822 void DiagnosePropertyMismatch(ObjCPropertyDecl *Property, 5823 ObjCPropertyDecl *SuperProperty, 5824 const IdentifierInfo *Name); 5825 void ComparePropertiesInBaseAndSuper(ObjCInterfaceDecl *IDecl); 5826 5827 void CompareMethodParamsInBaseAndSuper(Decl *IDecl, 5828 ObjCMethodDecl *MethodDecl, 5829 bool IsInstance); 5830 5831 void CompareProperties(Decl *CDecl, Decl *MergeProtocols); 5832 5833 void DiagnoseClassExtensionDupMethods(ObjCCategoryDecl *CAT, 5834 ObjCInterfaceDecl *ID); 5835 5836 void MatchOneProtocolPropertiesInClass(Decl *CDecl, 5837 ObjCProtocolDecl *PDecl); 5838 5839 Decl *ActOnAtEnd(Scope *S, SourceRange AtEnd, 5840 Decl **allMethods = 0, unsigned allNum = 0, 5841 Decl **allProperties = 0, unsigned pNum = 0, 5842 DeclGroupPtrTy *allTUVars = 0, unsigned tuvNum = 0); 5843 5844 Decl *ActOnProperty(Scope *S, SourceLocation AtLoc, 5845 SourceLocation LParenLoc, 5846 FieldDeclarator &FD, ObjCDeclSpec &ODS, 5847 Selector GetterSel, Selector SetterSel, 5848 bool *OverridingProperty, 5849 tok::ObjCKeywordKind MethodImplKind, 5850 DeclContext *lexicalDC = 0); 5851 5852 Decl *ActOnPropertyImplDecl(Scope *S, 5853 SourceLocation AtLoc, 5854 SourceLocation PropertyLoc, 5855 bool ImplKind, 5856 IdentifierInfo *PropertyId, 5857 IdentifierInfo *PropertyIvar, 5858 SourceLocation PropertyIvarLoc); 5859 5860 enum ObjCSpecialMethodKind { 5861 OSMK_None, 5862 OSMK_Alloc, 5863 OSMK_New, 5864 OSMK_Copy, 5865 OSMK_RetainingInit, 5866 OSMK_NonRetainingInit 5867 }; 5868 5869 struct ObjCArgInfo { 5870 IdentifierInfo *Name; 5871 SourceLocation NameLoc; 5872 // The Type is null if no type was specified, and the DeclSpec is invalid 5873 // in this case. 5874 ParsedType Type; 5875 ObjCDeclSpec DeclSpec; 5876 5877 /// ArgAttrs - Attribute list for this argument. 5878 AttributeList *ArgAttrs; 5879 }; 5880 5881 Decl *ActOnMethodDeclaration( 5882 Scope *S, 5883 SourceLocation BeginLoc, // location of the + or -. 5884 SourceLocation EndLoc, // location of the ; or {. 5885 tok::TokenKind MethodType, 5886 ObjCDeclSpec &ReturnQT, ParsedType ReturnType, 5887 ArrayRef<SourceLocation> SelectorLocs, Selector Sel, 5888 // optional arguments. The number of types/arguments is obtained 5889 // from the Sel.getNumArgs(). 5890 ObjCArgInfo *ArgInfo, 5891 DeclaratorChunk::ParamInfo *CParamInfo, unsigned CNumArgs, // c-style args 5892 AttributeList *AttrList, tok::ObjCKeywordKind MethodImplKind, 5893 bool isVariadic, bool MethodDefinition); 5894 5895 // Helper method for ActOnClassMethod/ActOnInstanceMethod. 5896 // Will search "local" class/category implementations for a method decl. 5897 // Will also search in class's root looking for instance method. 5898 // Returns 0 if no method is found. 5899 ObjCMethodDecl *LookupPrivateClassMethod(Selector Sel, 5900 ObjCInterfaceDecl *CDecl); 5901 ObjCMethodDecl *LookupPrivateInstanceMethod(Selector Sel, 5902 ObjCInterfaceDecl *ClassDecl); 5903 ObjCMethodDecl *LookupMethodInQualifiedType(Selector Sel, 5904 const ObjCObjectPointerType *OPT, 5905 bool IsInstance); 5906 ObjCMethodDecl *LookupMethodInObjectType(Selector Sel, QualType Ty, 5907 bool IsInstance); 5908 5909 bool inferObjCARCLifetime(ValueDecl *decl); 5910 5911 ExprResult 5912 HandleExprPropertyRefExpr(const ObjCObjectPointerType *OPT, 5913 Expr *BaseExpr, 5914 SourceLocation OpLoc, 5915 DeclarationName MemberName, 5916 SourceLocation MemberLoc, 5917 SourceLocation SuperLoc, QualType SuperType, 5918 bool Super); 5919 5920 ExprResult 5921 ActOnClassPropertyRefExpr(IdentifierInfo &receiverName, 5922 IdentifierInfo &propertyName, 5923 SourceLocation receiverNameLoc, 5924 SourceLocation propertyNameLoc); 5925 5926 ObjCMethodDecl *tryCaptureObjCSelf(SourceLocation Loc); 5927 5928 /// \brief Describes the kind of message expression indicated by a message 5929 /// send that starts with an identifier. 5930 enum ObjCMessageKind { 5931 /// \brief The message is sent to 'super'. 5932 ObjCSuperMessage, 5933 /// \brief The message is an instance message. 5934 ObjCInstanceMessage, 5935 /// \brief The message is a class message, and the identifier is a type 5936 /// name. 5937 ObjCClassMessage 5938 }; 5939 5940 ObjCMessageKind getObjCMessageKind(Scope *S, 5941 IdentifierInfo *Name, 5942 SourceLocation NameLoc, 5943 bool IsSuper, 5944 bool HasTrailingDot, 5945 ParsedType &ReceiverType); 5946 5947 ExprResult ActOnSuperMessage(Scope *S, SourceLocation SuperLoc, 5948 Selector Sel, 5949 SourceLocation LBracLoc, 5950 ArrayRef<SourceLocation> SelectorLocs, 5951 SourceLocation RBracLoc, 5952 MultiExprArg Args); 5953 5954 ExprResult BuildClassMessage(TypeSourceInfo *ReceiverTypeInfo, 5955 QualType ReceiverType, 5956 SourceLocation SuperLoc, 5957 Selector Sel, 5958 ObjCMethodDecl *Method, 5959 SourceLocation LBracLoc, 5960 ArrayRef<SourceLocation> SelectorLocs, 5961 SourceLocation RBracLoc, 5962 MultiExprArg Args, 5963 bool isImplicit = false); 5964 5965 ExprResult BuildClassMessageImplicit(QualType ReceiverType, 5966 bool isSuperReceiver, 5967 SourceLocation Loc, 5968 Selector Sel, 5969 ObjCMethodDecl *Method, 5970 MultiExprArg Args); 5971 5972 ExprResult ActOnClassMessage(Scope *S, 5973 ParsedType Receiver, 5974 Selector Sel, 5975 SourceLocation LBracLoc, 5976 ArrayRef<SourceLocation> SelectorLocs, 5977 SourceLocation RBracLoc, 5978 MultiExprArg Args); 5979 5980 ExprResult BuildInstanceMessage(Expr *Receiver, 5981 QualType ReceiverType, 5982 SourceLocation SuperLoc, 5983 Selector Sel, 5984 ObjCMethodDecl *Method, 5985 SourceLocation LBracLoc, 5986 ArrayRef<SourceLocation> SelectorLocs, 5987 SourceLocation RBracLoc, 5988 MultiExprArg Args, 5989 bool isImplicit = false); 5990 5991 ExprResult BuildInstanceMessageImplicit(Expr *Receiver, 5992 QualType ReceiverType, 5993 SourceLocation Loc, 5994 Selector Sel, 5995 ObjCMethodDecl *Method, 5996 MultiExprArg Args); 5997 5998 ExprResult ActOnInstanceMessage(Scope *S, 5999 Expr *Receiver, 6000 Selector Sel, 6001 SourceLocation LBracLoc, 6002 ArrayRef<SourceLocation> SelectorLocs, 6003 SourceLocation RBracLoc, 6004 MultiExprArg Args); 6005 6006 ExprResult BuildObjCBridgedCast(SourceLocation LParenLoc, 6007 ObjCBridgeCastKind Kind, 6008 SourceLocation BridgeKeywordLoc, 6009 TypeSourceInfo *TSInfo, 6010 Expr *SubExpr); 6011 6012 ExprResult ActOnObjCBridgedCast(Scope *S, 6013 SourceLocation LParenLoc, 6014 ObjCBridgeCastKind Kind, 6015 SourceLocation BridgeKeywordLoc, 6016 ParsedType Type, 6017 SourceLocation RParenLoc, 6018 Expr *SubExpr); 6019 6020 bool checkInitMethod(ObjCMethodDecl *method, QualType receiverTypeIfCall); 6021 6022 /// \brief Check whether the given new method is a valid override of the 6023 /// given overridden method, and set any properties that should be inherited. 6024 void CheckObjCMethodOverride(ObjCMethodDecl *NewMethod, 6025 const ObjCMethodDecl *Overridden, 6026 bool IsImplementation); 6027 6028 /// \brief Check whether the given method overrides any methods in its class, 6029 /// calling \c CheckObjCMethodOverride for each overridden method. 6030 bool CheckObjCMethodOverrides(ObjCMethodDecl *NewMethod, DeclContext *DC); 6031 6032 enum PragmaOptionsAlignKind { 6033 POAK_Native, // #pragma options align=native 6034 POAK_Natural, // #pragma options align=natural 6035 POAK_Packed, // #pragma options align=packed 6036 POAK_Power, // #pragma options align=power 6037 POAK_Mac68k, // #pragma options align=mac68k 6038 POAK_Reset // #pragma options align=reset 6039 }; 6040 6041 /// ActOnPragmaOptionsAlign - Called on well formed #pragma options align. 6042 void ActOnPragmaOptionsAlign(PragmaOptionsAlignKind Kind, 6043 SourceLocation PragmaLoc, 6044 SourceLocation KindLoc); 6045 6046 enum PragmaPackKind { 6047 PPK_Default, // #pragma pack([n]) 6048 PPK_Show, // #pragma pack(show), only supported by MSVC. 6049 PPK_Push, // #pragma pack(push, [identifier], [n]) 6050 PPK_Pop // #pragma pack(pop, [identifier], [n]) 6051 }; 6052 6053 enum PragmaMSStructKind { 6054 PMSST_OFF, // #pragms ms_struct off 6055 PMSST_ON // #pragms ms_struct on 6056 }; 6057 6058 /// ActOnPragmaPack - Called on well formed #pragma pack(...). 6059 void ActOnPragmaPack(PragmaPackKind Kind, 6060 IdentifierInfo *Name, 6061 Expr *Alignment, 6062 SourceLocation PragmaLoc, 6063 SourceLocation LParenLoc, 6064 SourceLocation RParenLoc); 6065 6066 /// ActOnPragmaMSStruct - Called on well formed #pragms ms_struct [on|off]. 6067 void ActOnPragmaMSStruct(PragmaMSStructKind Kind); 6068 6069 /// ActOnPragmaUnused - Called on well-formed '#pragma unused'. 6070 void ActOnPragmaUnused(const Token &Identifier, 6071 Scope *curScope, 6072 SourceLocation PragmaLoc); 6073 6074 /// ActOnPragmaVisibility - Called on well formed #pragma GCC visibility... . 6075 void ActOnPragmaVisibility(const IdentifierInfo* VisType, 6076 SourceLocation PragmaLoc); 6077 6078 NamedDecl *DeclClonePragmaWeak(NamedDecl *ND, IdentifierInfo *II, 6079 SourceLocation Loc); 6080 void DeclApplyPragmaWeak(Scope *S, NamedDecl *ND, WeakInfo &W); 6081 6082 /// ActOnPragmaWeakID - Called on well formed #pragma weak ident. 6083 void ActOnPragmaWeakID(IdentifierInfo* WeakName, 6084 SourceLocation PragmaLoc, 6085 SourceLocation WeakNameLoc); 6086 6087 /// ActOnPragmaRedefineExtname - Called on well formed 6088 /// #pragma redefine_extname oldname newname. 6089 void ActOnPragmaRedefineExtname(IdentifierInfo* WeakName, 6090 IdentifierInfo* AliasName, 6091 SourceLocation PragmaLoc, 6092 SourceLocation WeakNameLoc, 6093 SourceLocation AliasNameLoc); 6094 6095 /// ActOnPragmaWeakAlias - Called on well formed #pragma weak ident = ident. 6096 void ActOnPragmaWeakAlias(IdentifierInfo* WeakName, 6097 IdentifierInfo* AliasName, 6098 SourceLocation PragmaLoc, 6099 SourceLocation WeakNameLoc, 6100 SourceLocation AliasNameLoc); 6101 6102 /// ActOnPragmaFPContract - Called on well formed 6103 /// #pragma {STDC,OPENCL} FP_CONTRACT 6104 void ActOnPragmaFPContract(tok::OnOffSwitch OOS); 6105 6106 /// AddAlignmentAttributesForRecord - Adds any needed alignment attributes to 6107 /// a the record decl, to handle '#pragma pack' and '#pragma options align'. 6108 void AddAlignmentAttributesForRecord(RecordDecl *RD); 6109 6110 /// AddMsStructLayoutForRecord - Adds ms_struct layout attribute to record. 6111 void AddMsStructLayoutForRecord(RecordDecl *RD); 6112 6113 /// FreePackedContext - Deallocate and null out PackContext. 6114 void FreePackedContext(); 6115 6116 /// PushNamespaceVisibilityAttr - Note that we've entered a 6117 /// namespace with a visibility attribute. 6118 void PushNamespaceVisibilityAttr(const VisibilityAttr *Attr, 6119 SourceLocation Loc); 6120 6121 /// AddPushedVisibilityAttribute - If '#pragma GCC visibility' was used, 6122 /// add an appropriate visibility attribute. 6123 void AddPushedVisibilityAttribute(Decl *RD); 6124 6125 /// PopPragmaVisibility - Pop the top element of the visibility stack; used 6126 /// for '#pragma GCC visibility' and visibility attributes on namespaces. 6127 void PopPragmaVisibility(bool IsNamespaceEnd, SourceLocation EndLoc); 6128 6129 /// FreeVisContext - Deallocate and null out VisContext. 6130 void FreeVisContext(); 6131 6132 /// AddCFAuditedAttribute - Check whether we're currently within 6133 /// '#pragma clang arc_cf_code_audited' and, if so, consider adding 6134 /// the appropriate attribute. 6135 void AddCFAuditedAttribute(Decl *D); 6136 6137 /// AddAlignedAttr - Adds an aligned attribute to a particular declaration. 6138 void AddAlignedAttr(SourceRange AttrRange, Decl *D, Expr *E); 6139 void AddAlignedAttr(SourceRange AttrRange, Decl *D, TypeSourceInfo *T); 6140 6141 /// \brief The kind of conversion being performed. 6142 enum CheckedConversionKind { 6143 /// \brief An implicit conversion. 6144 CCK_ImplicitConversion, 6145 /// \brief A C-style cast. 6146 CCK_CStyleCast, 6147 /// \brief A functional-style cast. 6148 CCK_FunctionalCast, 6149 /// \brief A cast other than a C-style cast. 6150 CCK_OtherCast 6151 }; 6152 6153 /// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit 6154 /// cast. If there is already an implicit cast, merge into the existing one. 6155 /// If isLvalue, the result of the cast is an lvalue. 6156 ExprResult ImpCastExprToType(Expr *E, QualType Type, CastKind CK, 6157 ExprValueKind VK = VK_RValue, 6158 const CXXCastPath *BasePath = 0, 6159 CheckedConversionKind CCK 6160 = CCK_ImplicitConversion); 6161 6162 /// ScalarTypeToBooleanCastKind - Returns the cast kind corresponding 6163 /// to the conversion from scalar type ScalarTy to the Boolean type. 6164 static CastKind ScalarTypeToBooleanCastKind(QualType ScalarTy); 6165 6166 /// IgnoredValueConversions - Given that an expression's result is 6167 /// syntactically ignored, perform any conversions that are 6168 /// required. 6169 ExprResult IgnoredValueConversions(Expr *E); 6170 6171 // UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts 6172 // functions and arrays to their respective pointers (C99 6.3.2.1). 6173 ExprResult UsualUnaryConversions(Expr *E); 6174 6175 // DefaultFunctionArrayConversion - converts functions and arrays 6176 // to their respective pointers (C99 6.3.2.1). 6177 ExprResult DefaultFunctionArrayConversion(Expr *E); 6178 6179 // DefaultFunctionArrayLvalueConversion - converts functions and 6180 // arrays to their respective pointers and performs the 6181 // lvalue-to-rvalue conversion. 6182 ExprResult DefaultFunctionArrayLvalueConversion(Expr *E); 6183 6184 // DefaultLvalueConversion - performs lvalue-to-rvalue conversion on 6185 // the operand. This is DefaultFunctionArrayLvalueConversion, 6186 // except that it assumes the operand isn't of function or array 6187 // type. 6188 ExprResult DefaultLvalueConversion(Expr *E); 6189 6190 // DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that 6191 // do not have a prototype. Integer promotions are performed on each 6192 // argument, and arguments that have type float are promoted to double. 6193 ExprResult DefaultArgumentPromotion(Expr *E); 6194 6195 // Used for emitting the right warning by DefaultVariadicArgumentPromotion 6196 enum VariadicCallType { 6197 VariadicFunction, 6198 VariadicBlock, 6199 VariadicMethod, 6200 VariadicConstructor, 6201 VariadicDoesNotApply 6202 }; 6203 6204 /// GatherArgumentsForCall - Collector argument expressions for various 6205 /// form of call prototypes. 6206 bool GatherArgumentsForCall(SourceLocation CallLoc, 6207 FunctionDecl *FDecl, 6208 const FunctionProtoType *Proto, 6209 unsigned FirstProtoArg, 6210 Expr **Args, unsigned NumArgs, 6211 SmallVector<Expr *, 8> &AllArgs, 6212 VariadicCallType CallType = VariadicDoesNotApply, 6213 bool AllowExplicit = false); 6214 6215 // DefaultVariadicArgumentPromotion - Like DefaultArgumentPromotion, but 6216 // will warn if the resulting type is not a POD type. 6217 ExprResult DefaultVariadicArgumentPromotion(Expr *E, VariadicCallType CT, 6218 FunctionDecl *FDecl); 6219 6220 // UsualArithmeticConversions - performs the UsualUnaryConversions on it's 6221 // operands and then handles various conversions that are common to binary 6222 // operators (C99 6.3.1.8). If both operands aren't arithmetic, this 6223 // routine returns the first non-arithmetic type found. The client is 6224 // responsible for emitting appropriate error diagnostics. 6225 QualType UsualArithmeticConversions(ExprResult &LHS, ExprResult &RHS, 6226 bool IsCompAssign = false); 6227 6228 /// AssignConvertType - All of the 'assignment' semantic checks return this 6229 /// enum to indicate whether the assignment was allowed. These checks are 6230 /// done for simple assignments, as well as initialization, return from 6231 /// function, argument passing, etc. The query is phrased in terms of a 6232 /// source and destination type. 6233 enum AssignConvertType { 6234 /// Compatible - the types are compatible according to the standard. 6235 Compatible, 6236 6237 /// PointerToInt - The assignment converts a pointer to an int, which we 6238 /// accept as an extension. 6239 PointerToInt, 6240 6241 /// IntToPointer - The assignment converts an int to a pointer, which we 6242 /// accept as an extension. 6243 IntToPointer, 6244 6245 /// FunctionVoidPointer - The assignment is between a function pointer and 6246 /// void*, which the standard doesn't allow, but we accept as an extension. 6247 FunctionVoidPointer, 6248 6249 /// IncompatiblePointer - The assignment is between two pointers types that 6250 /// are not compatible, but we accept them as an extension. 6251 IncompatiblePointer, 6252 6253 /// IncompatiblePointer - The assignment is between two pointers types which 6254 /// point to integers which have a different sign, but are otherwise 6255 /// identical. This is a subset of the above, but broken out because it's by 6256 /// far the most common case of incompatible pointers. 6257 IncompatiblePointerSign, 6258 6259 /// CompatiblePointerDiscardsQualifiers - The assignment discards 6260 /// c/v/r qualifiers, which we accept as an extension. 6261 CompatiblePointerDiscardsQualifiers, 6262 6263 /// IncompatiblePointerDiscardsQualifiers - The assignment 6264 /// discards qualifiers that we don't permit to be discarded, 6265 /// like address spaces. 6266 IncompatiblePointerDiscardsQualifiers, 6267 6268 /// IncompatibleNestedPointerQualifiers - The assignment is between two 6269 /// nested pointer types, and the qualifiers other than the first two 6270 /// levels differ e.g. char ** -> const char **, but we accept them as an 6271 /// extension. 6272 IncompatibleNestedPointerQualifiers, 6273 6274 /// IncompatibleVectors - The assignment is between two vector types that 6275 /// have the same size, which we accept as an extension. 6276 IncompatibleVectors, 6277 6278 /// IntToBlockPointer - The assignment converts an int to a block 6279 /// pointer. We disallow this. 6280 IntToBlockPointer, 6281 6282 /// IncompatibleBlockPointer - The assignment is between two block 6283 /// pointers types that are not compatible. 6284 IncompatibleBlockPointer, 6285 6286 /// IncompatibleObjCQualifiedId - The assignment is between a qualified 6287 /// id type and something else (that is incompatible with it). For example, 6288 /// "id <XXX>" = "Foo *", where "Foo *" doesn't implement the XXX protocol. 6289 IncompatibleObjCQualifiedId, 6290 6291 /// IncompatibleObjCWeakRef - Assigning a weak-unavailable object to an 6292 /// object with __weak qualifier. 6293 IncompatibleObjCWeakRef, 6294 6295 /// Incompatible - We reject this conversion outright, it is invalid to 6296 /// represent it in the AST. 6297 Incompatible 6298 }; 6299 6300 /// DiagnoseAssignmentResult - Emit a diagnostic, if required, for the 6301 /// assignment conversion type specified by ConvTy. This returns true if the 6302 /// conversion was invalid or false if the conversion was accepted. 6303 bool DiagnoseAssignmentResult(AssignConvertType ConvTy, 6304 SourceLocation Loc, 6305 QualType DstType, QualType SrcType, 6306 Expr *SrcExpr, AssignmentAction Action, 6307 bool *Complained = 0); 6308 6309 /// CheckAssignmentConstraints - Perform type checking for assignment, 6310 /// argument passing, variable initialization, and function return values. 6311 /// C99 6.5.16. 6312 AssignConvertType CheckAssignmentConstraints(SourceLocation Loc, 6313 QualType LHSType, 6314 QualType RHSType); 6315 6316 /// Check assignment constraints and prepare for a conversion of the 6317 /// RHS to the LHS type. 6318 AssignConvertType CheckAssignmentConstraints(QualType LHSType, 6319 ExprResult &RHS, 6320 CastKind &Kind); 6321 6322 // CheckSingleAssignmentConstraints - Currently used by 6323 // CheckAssignmentOperands, and ActOnReturnStmt. Prior to type checking, 6324 // this routine performs the default function/array converions. 6325 AssignConvertType CheckSingleAssignmentConstraints(QualType LHSType, 6326 ExprResult &RHS, 6327 bool Diagnose = true); 6328 6329 // \brief If the lhs type is a transparent union, check whether we 6330 // can initialize the transparent union with the given expression. 6331 AssignConvertType CheckTransparentUnionArgumentConstraints(QualType ArgType, 6332 ExprResult &RHS); 6333 6334 bool IsStringLiteralToNonConstPointerConversion(Expr *From, QualType ToType); 6335 6336 bool CheckExceptionSpecCompatibility(Expr *From, QualType ToType); 6337 6338 ExprResult PerformImplicitConversion(Expr *From, QualType ToType, 6339 AssignmentAction Action, 6340 bool AllowExplicit = false); 6341 ExprResult PerformImplicitConversion(Expr *From, QualType ToType, 6342 AssignmentAction Action, 6343 bool AllowExplicit, 6344 ImplicitConversionSequence& ICS); 6345 ExprResult PerformImplicitConversion(Expr *From, QualType ToType, 6346 const ImplicitConversionSequence& ICS, 6347 AssignmentAction Action, 6348 CheckedConversionKind CCK 6349 = CCK_ImplicitConversion); 6350 ExprResult PerformImplicitConversion(Expr *From, QualType ToType, 6351 const StandardConversionSequence& SCS, 6352 AssignmentAction Action, 6353 CheckedConversionKind CCK); 6354 6355 /// the following "Check" methods will return a valid/converted QualType 6356 /// or a null QualType (indicating an error diagnostic was issued). 6357 6358 /// type checking binary operators (subroutines of CreateBuiltinBinOp). 6359 QualType InvalidOperands(SourceLocation Loc, ExprResult &LHS, 6360 ExprResult &RHS); 6361 QualType CheckPointerToMemberOperands( // C++ 5.5 6362 ExprResult &LHS, ExprResult &RHS, ExprValueKind &VK, 6363 SourceLocation OpLoc, bool isIndirect); 6364 QualType CheckMultiplyDivideOperands( // C99 6.5.5 6365 ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, bool IsCompAssign, 6366 bool IsDivide); 6367 QualType CheckRemainderOperands( // C99 6.5.5 6368 ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, 6369 bool IsCompAssign = false); 6370 QualType CheckAdditionOperands( // C99 6.5.6 6371 ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, unsigned Opc, 6372 QualType* CompLHSTy = 0); 6373 QualType CheckSubtractionOperands( // C99 6.5.6 6374 ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, 6375 QualType* CompLHSTy = 0); 6376 QualType CheckShiftOperands( // C99 6.5.7 6377 ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, unsigned Opc, 6378 bool IsCompAssign = false); 6379 QualType CheckCompareOperands( // C99 6.5.8/9 6380 ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, unsigned OpaqueOpc, 6381 bool isRelational); 6382 QualType CheckBitwiseOperands( // C99 6.5.[10...12] 6383 ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, 6384 bool IsCompAssign = false); 6385 QualType CheckLogicalOperands( // C99 6.5.[13,14] 6386 ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, unsigned Opc); 6387 // CheckAssignmentOperands is used for both simple and compound assignment. 6388 // For simple assignment, pass both expressions and a null converted type. 6389 // For compound assignment, pass both expressions and the converted type. 6390 QualType CheckAssignmentOperands( // C99 6.5.16.[1,2] 6391 Expr *LHSExpr, ExprResult &RHS, SourceLocation Loc, QualType CompoundType); 6392 6393 ExprResult checkPseudoObjectIncDec(Scope *S, SourceLocation OpLoc, 6394 UnaryOperatorKind Opcode, Expr *Op); 6395 ExprResult checkPseudoObjectAssignment(Scope *S, SourceLocation OpLoc, 6396 BinaryOperatorKind Opcode, 6397 Expr *LHS, Expr *RHS); 6398 ExprResult checkPseudoObjectRValue(Expr *E); 6399 Expr *recreateSyntacticForm(PseudoObjectExpr *E); 6400 6401 QualType CheckConditionalOperands( // C99 6.5.15 6402 ExprResult &Cond, ExprResult &LHS, ExprResult &RHS, 6403 ExprValueKind &VK, ExprObjectKind &OK, SourceLocation QuestionLoc); 6404 QualType CXXCheckConditionalOperands( // C++ 5.16 6405 ExprResult &cond, ExprResult &lhs, ExprResult &rhs, 6406 ExprValueKind &VK, ExprObjectKind &OK, SourceLocation questionLoc); 6407 QualType FindCompositePointerType(SourceLocation Loc, Expr *&E1, Expr *&E2, 6408 bool *NonStandardCompositeType = 0); 6409 QualType FindCompositePointerType(SourceLocation Loc, 6410 ExprResult &E1, ExprResult &E2, 6411 bool *NonStandardCompositeType = 0) { 6412 Expr *E1Tmp = E1.take(), *E2Tmp = E2.take(); 6413 QualType Composite = FindCompositePointerType(Loc, E1Tmp, E2Tmp, 6414 NonStandardCompositeType); 6415 E1 = Owned(E1Tmp); 6416 E2 = Owned(E2Tmp); 6417 return Composite; 6418 } 6419 6420 QualType FindCompositeObjCPointerType(ExprResult &LHS, ExprResult &RHS, 6421 SourceLocation QuestionLoc); 6422 6423 bool DiagnoseConditionalForNull(Expr *LHSExpr, Expr *RHSExpr, 6424 SourceLocation QuestionLoc); 6425 6426 /// type checking for vector binary operators. 6427 QualType CheckVectorOperands(ExprResult &LHS, ExprResult &RHS, 6428 SourceLocation Loc, bool IsCompAssign); 6429 QualType GetSignedVectorType(QualType V); 6430 QualType CheckVectorCompareOperands(ExprResult &LHS, ExprResult &RHS, 6431 SourceLocation Loc, bool isRelational); 6432 QualType CheckVectorLogicalOperands(ExprResult &LHS, ExprResult &RHS, 6433 SourceLocation Loc); 6434 6435 /// type checking declaration initializers (C99 6.7.8) 6436 bool CheckForConstantInitializer(Expr *e, QualType t); 6437 6438 // type checking C++ declaration initializers (C++ [dcl.init]). 6439 6440 /// ReferenceCompareResult - Expresses the result of comparing two 6441 /// types (cv1 T1 and cv2 T2) to determine their compatibility for the 6442 /// purposes of initialization by reference (C++ [dcl.init.ref]p4). 6443 enum ReferenceCompareResult { 6444 /// Ref_Incompatible - The two types are incompatible, so direct 6445 /// reference binding is not possible. 6446 Ref_Incompatible = 0, 6447 /// Ref_Related - The two types are reference-related, which means 6448 /// that their unqualified forms (T1 and T2) are either the same 6449 /// or T1 is a base class of T2. 6450 Ref_Related, 6451 /// Ref_Compatible_With_Added_Qualification - The two types are 6452 /// reference-compatible with added qualification, meaning that 6453 /// they are reference-compatible and the qualifiers on T1 (cv1) 6454 /// are greater than the qualifiers on T2 (cv2). 6455 Ref_Compatible_With_Added_Qualification, 6456 /// Ref_Compatible - The two types are reference-compatible and 6457 /// have equivalent qualifiers (cv1 == cv2). 6458 Ref_Compatible 6459 }; 6460 6461 ReferenceCompareResult CompareReferenceRelationship(SourceLocation Loc, 6462 QualType T1, QualType T2, 6463 bool &DerivedToBase, 6464 bool &ObjCConversion, 6465 bool &ObjCLifetimeConversion); 6466 6467 ExprResult checkUnknownAnyCast(SourceRange TypeRange, QualType CastType, 6468 Expr *CastExpr, CastKind &CastKind, 6469 ExprValueKind &VK, CXXCastPath &Path); 6470 6471 /// \brief Force an expression with unknown-type to an expression of the 6472 /// given type. 6473 ExprResult forceUnknownAnyToType(Expr *E, QualType ToType); 6474 6475 // CheckVectorCast - check type constraints for vectors. 6476 // Since vectors are an extension, there are no C standard reference for this. 6477 // We allow casting between vectors and integer datatypes of the same size. 6478 // returns true if the cast is invalid 6479 bool CheckVectorCast(SourceRange R, QualType VectorTy, QualType Ty, 6480 CastKind &Kind); 6481 6482 // CheckExtVectorCast - check type constraints for extended vectors. 6483 // Since vectors are an extension, there are no C standard reference for this. 6484 // We allow casting between vectors and integer datatypes of the same size, 6485 // or vectors and the element type of that vector. 6486 // returns the cast expr 6487 ExprResult CheckExtVectorCast(SourceRange R, QualType DestTy, Expr *CastExpr, 6488 CastKind &Kind); 6489 6490 ExprResult BuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo, 6491 SourceLocation LParenLoc, 6492 Expr *CastExpr, 6493 SourceLocation RParenLoc); 6494 6495 enum ARCConversionResult { ACR_okay, ACR_unbridged }; 6496 6497 /// \brief Checks for invalid conversions and casts between 6498 /// retainable pointers and other pointer kinds. 6499 ARCConversionResult CheckObjCARCConversion(SourceRange castRange, 6500 QualType castType, Expr *&op, 6501 CheckedConversionKind CCK); 6502 6503 Expr *stripARCUnbridgedCast(Expr *e); 6504 void diagnoseARCUnbridgedCast(Expr *e); 6505 6506 bool CheckObjCARCUnavailableWeakConversion(QualType castType, 6507 QualType ExprType); 6508 6509 /// checkRetainCycles - Check whether an Objective-C message send 6510 /// might create an obvious retain cycle. 6511 void checkRetainCycles(ObjCMessageExpr *msg); 6512 void checkRetainCycles(Expr *receiver, Expr *argument); 6513 6514 /// checkUnsafeAssigns - Check whether +1 expr is being assigned 6515 /// to weak/__unsafe_unretained type. 6516 bool checkUnsafeAssigns(SourceLocation Loc, QualType LHS, Expr *RHS); 6517 6518 /// checkUnsafeExprAssigns - Check whether +1 expr is being assigned 6519 /// to weak/__unsafe_unretained expression. 6520 void checkUnsafeExprAssigns(SourceLocation Loc, Expr *LHS, Expr *RHS); 6521 6522 /// CheckMessageArgumentTypes - Check types in an Obj-C message send. 6523 /// \param Method - May be null. 6524 /// \param [out] ReturnType - The return type of the send. 6525 /// \return true iff there were any incompatible types. 6526 bool CheckMessageArgumentTypes(QualType ReceiverType, 6527 Expr **Args, unsigned NumArgs, Selector Sel, 6528 ObjCMethodDecl *Method, bool isClassMessage, 6529 bool isSuperMessage, 6530 SourceLocation lbrac, SourceLocation rbrac, 6531 QualType &ReturnType, ExprValueKind &VK); 6532 6533 /// \brief Determine the result of a message send expression based on 6534 /// the type of the receiver, the method expected to receive the message, 6535 /// and the form of the message send. 6536 QualType getMessageSendResultType(QualType ReceiverType, 6537 ObjCMethodDecl *Method, 6538 bool isClassMessage, bool isSuperMessage); 6539 6540 /// \brief If the given expression involves a message send to a method 6541 /// with a related result type, emit a note describing what happened. 6542 void EmitRelatedResultTypeNote(const Expr *E); 6543 6544 /// CheckBooleanCondition - Diagnose problems involving the use of 6545 /// the given expression as a boolean condition (e.g. in an if 6546 /// statement). Also performs the standard function and array 6547 /// decays, possibly changing the input variable. 6548 /// 6549 /// \param Loc - A location associated with the condition, e.g. the 6550 /// 'if' keyword. 6551 /// \return true iff there were any errors 6552 ExprResult CheckBooleanCondition(Expr *E, SourceLocation Loc); 6553 6554 ExprResult ActOnBooleanCondition(Scope *S, SourceLocation Loc, 6555 Expr *SubExpr); 6556 6557 /// DiagnoseAssignmentAsCondition - Given that an expression is 6558 /// being used as a boolean condition, warn if it's an assignment. 6559 void DiagnoseAssignmentAsCondition(Expr *E); 6560 6561 /// \brief Redundant parentheses over an equality comparison can indicate 6562 /// that the user intended an assignment used as condition. 6563 void DiagnoseEqualityWithExtraParens(ParenExpr *ParenE); 6564 6565 /// CheckCXXBooleanCondition - Returns true if conversion to bool is invalid. 6566 ExprResult CheckCXXBooleanCondition(Expr *CondExpr); 6567 6568 /// ConvertIntegerToTypeWarnOnOverflow - Convert the specified APInt to have 6569 /// the specified width and sign. If an overflow occurs, detect it and emit 6570 /// the specified diagnostic. 6571 void ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &OldVal, 6572 unsigned NewWidth, bool NewSign, 6573 SourceLocation Loc, unsigned DiagID); 6574 6575 /// Checks that the Objective-C declaration is declared in the global scope. 6576 /// Emits an error and marks the declaration as invalid if it's not declared 6577 /// in the global scope. 6578 bool CheckObjCDeclScope(Decl *D); 6579 6580 /// VerifyIntegerConstantExpression - Verifies that an expression is an ICE, 6581 /// and reports the appropriate diagnostics. Returns false on success. 6582 /// Can optionally return the value of the expression. 6583 ExprResult VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result, 6584 const PartialDiagnostic &Diag, 6585 bool AllowFold, 6586 const PartialDiagnostic &FoldDiag); 6587 ExprResult VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result, 6588 const PartialDiagnostic &Diag, 6589 bool AllowFold = true) { 6590 return VerifyIntegerConstantExpression(E, Result, Diag, AllowFold, 6591 PDiag(0)); 6592 } 6593 ExprResult VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result = 0); 6594 6595 /// VerifyBitField - verifies that a bit field expression is an ICE and has 6596 /// the correct width, and that the field type is valid. 6597 /// Returns false on success. 6598 /// Can optionally return whether the bit-field is of width 0 6599 ExprResult VerifyBitField(SourceLocation FieldLoc, IdentifierInfo *FieldName, 6600 QualType FieldTy, Expr *BitWidth, 6601 bool *ZeroWidth = 0); 6602 6603 enum CUDAFunctionTarget { 6604 CFT_Device, 6605 CFT_Global, 6606 CFT_Host, 6607 CFT_HostDevice 6608 }; 6609 6610 CUDAFunctionTarget IdentifyCUDATarget(const FunctionDecl *D); 6611 6612 bool CheckCUDATarget(CUDAFunctionTarget CallerTarget, 6613 CUDAFunctionTarget CalleeTarget); 6614 6615 bool CheckCUDATarget(const FunctionDecl *Caller, const FunctionDecl *Callee) { 6616 return CheckCUDATarget(IdentifyCUDATarget(Caller), 6617 IdentifyCUDATarget(Callee)); 6618 } 6619 6620 /// \name Code completion 6621 //@{ 6622 /// \brief Describes the context in which code completion occurs. 6623 enum ParserCompletionContext { 6624 /// \brief Code completion occurs at top-level or namespace context. 6625 PCC_Namespace, 6626 /// \brief Code completion occurs within a class, struct, or union. 6627 PCC_Class, 6628 /// \brief Code completion occurs within an Objective-C interface, protocol, 6629 /// or category. 6630 PCC_ObjCInterface, 6631 /// \brief Code completion occurs within an Objective-C implementation or 6632 /// category implementation 6633 PCC_ObjCImplementation, 6634 /// \brief Code completion occurs within the list of instance variables 6635 /// in an Objective-C interface, protocol, category, or implementation. 6636 PCC_ObjCInstanceVariableList, 6637 /// \brief Code completion occurs following one or more template 6638 /// headers. 6639 PCC_Template, 6640 /// \brief Code completion occurs following one or more template 6641 /// headers within a class. 6642 PCC_MemberTemplate, 6643 /// \brief Code completion occurs within an expression. 6644 PCC_Expression, 6645 /// \brief Code completion occurs within a statement, which may 6646 /// also be an expression or a declaration. 6647 PCC_Statement, 6648 /// \brief Code completion occurs at the beginning of the 6649 /// initialization statement (or expression) in a for loop. 6650 PCC_ForInit, 6651 /// \brief Code completion occurs within the condition of an if, 6652 /// while, switch, or for statement. 6653 PCC_Condition, 6654 /// \brief Code completion occurs within the body of a function on a 6655 /// recovery path, where we do not have a specific handle on our position 6656 /// in the grammar. 6657 PCC_RecoveryInFunction, 6658 /// \brief Code completion occurs where only a type is permitted. 6659 PCC_Type, 6660 /// \brief Code completion occurs in a parenthesized expression, which 6661 /// might also be a type cast. 6662 PCC_ParenthesizedExpression, 6663 /// \brief Code completion occurs within a sequence of declaration 6664 /// specifiers within a function, method, or block. 6665 PCC_LocalDeclarationSpecifiers 6666 }; 6667 6668 void CodeCompleteModuleImport(SourceLocation ImportLoc, ModuleIdPath Path); 6669 void CodeCompleteOrdinaryName(Scope *S, 6670 ParserCompletionContext CompletionContext); 6671 void CodeCompleteDeclSpec(Scope *S, DeclSpec &DS, 6672 bool AllowNonIdentifiers, 6673 bool AllowNestedNameSpecifiers); 6674 6675 struct CodeCompleteExpressionData; 6676 void CodeCompleteExpression(Scope *S, 6677 const CodeCompleteExpressionData &Data); 6678 void CodeCompleteMemberReferenceExpr(Scope *S, Expr *Base, 6679 SourceLocation OpLoc, 6680 bool IsArrow); 6681 void CodeCompletePostfixExpression(Scope *S, ExprResult LHS); 6682 void CodeCompleteTag(Scope *S, unsigned TagSpec); 6683 void CodeCompleteTypeQualifiers(DeclSpec &DS); 6684 void CodeCompleteCase(Scope *S); 6685 void CodeCompleteCall(Scope *S, Expr *Fn, llvm::ArrayRef<Expr *> Args); 6686 void CodeCompleteInitializer(Scope *S, Decl *D); 6687 void CodeCompleteReturn(Scope *S); 6688 void CodeCompleteAfterIf(Scope *S); 6689 void CodeCompleteAssignmentRHS(Scope *S, Expr *LHS); 6690 6691 void CodeCompleteQualifiedId(Scope *S, CXXScopeSpec &SS, 6692 bool EnteringContext); 6693 void CodeCompleteUsing(Scope *S); 6694 void CodeCompleteUsingDirective(Scope *S); 6695 void CodeCompleteNamespaceDecl(Scope *S); 6696 void CodeCompleteNamespaceAliasDecl(Scope *S); 6697 void CodeCompleteOperatorName(Scope *S); 6698 void CodeCompleteConstructorInitializer(Decl *Constructor, 6699 CXXCtorInitializer** Initializers, 6700 unsigned NumInitializers); 6701 void CodeCompleteLambdaIntroducer(Scope *S, LambdaIntroducer &Intro, 6702 bool AfterAmpersand); 6703 6704 void CodeCompleteObjCAtDirective(Scope *S); 6705 void CodeCompleteObjCAtVisibility(Scope *S); 6706 void CodeCompleteObjCAtStatement(Scope *S); 6707 void CodeCompleteObjCAtExpression(Scope *S); 6708 void CodeCompleteObjCPropertyFlags(Scope *S, ObjCDeclSpec &ODS); 6709 void CodeCompleteObjCPropertyGetter(Scope *S); 6710 void CodeCompleteObjCPropertySetter(Scope *S); 6711 void CodeCompleteObjCPassingType(Scope *S, ObjCDeclSpec &DS, 6712 bool IsParameter); 6713 void CodeCompleteObjCMessageReceiver(Scope *S); 6714 void CodeCompleteObjCSuperMessage(Scope *S, SourceLocation SuperLoc, 6715 IdentifierInfo **SelIdents, 6716 unsigned NumSelIdents, 6717 bool AtArgumentExpression); 6718 void CodeCompleteObjCClassMessage(Scope *S, ParsedType Receiver, 6719 IdentifierInfo **SelIdents, 6720 unsigned NumSelIdents, 6721 bool AtArgumentExpression, 6722 bool IsSuper = false); 6723 void CodeCompleteObjCInstanceMessage(Scope *S, Expr *Receiver, 6724 IdentifierInfo **SelIdents, 6725 unsigned NumSelIdents, 6726 bool AtArgumentExpression, 6727 ObjCInterfaceDecl *Super = 0); 6728 void CodeCompleteObjCForCollection(Scope *S, 6729 DeclGroupPtrTy IterationVar); 6730 void CodeCompleteObjCSelector(Scope *S, 6731 IdentifierInfo **SelIdents, 6732 unsigned NumSelIdents); 6733 void CodeCompleteObjCProtocolReferences(IdentifierLocPair *Protocols, 6734 unsigned NumProtocols); 6735 void CodeCompleteObjCProtocolDecl(Scope *S); 6736 void CodeCompleteObjCInterfaceDecl(Scope *S); 6737 void CodeCompleteObjCSuperclass(Scope *S, 6738 IdentifierInfo *ClassName, 6739 SourceLocation ClassNameLoc); 6740 void CodeCompleteObjCImplementationDecl(Scope *S); 6741 void CodeCompleteObjCInterfaceCategory(Scope *S, 6742 IdentifierInfo *ClassName, 6743 SourceLocation ClassNameLoc); 6744 void CodeCompleteObjCImplementationCategory(Scope *S, 6745 IdentifierInfo *ClassName, 6746 SourceLocation ClassNameLoc); 6747 void CodeCompleteObjCPropertyDefinition(Scope *S); 6748 void CodeCompleteObjCPropertySynthesizeIvar(Scope *S, 6749 IdentifierInfo *PropertyName); 6750 void CodeCompleteObjCMethodDecl(Scope *S, 6751 bool IsInstanceMethod, 6752 ParsedType ReturnType); 6753 void CodeCompleteObjCMethodDeclSelector(Scope *S, 6754 bool IsInstanceMethod, 6755 bool AtParameterName, 6756 ParsedType ReturnType, 6757 IdentifierInfo **SelIdents, 6758 unsigned NumSelIdents); 6759 void CodeCompletePreprocessorDirective(bool InConditional); 6760 void CodeCompleteInPreprocessorConditionalExclusion(Scope *S); 6761 void CodeCompletePreprocessorMacroName(bool IsDefinition); 6762 void CodeCompletePreprocessorExpression(); 6763 void CodeCompletePreprocessorMacroArgument(Scope *S, 6764 IdentifierInfo *Macro, 6765 MacroInfo *MacroInfo, 6766 unsigned Argument); 6767 void CodeCompleteNaturalLanguage(); 6768 void GatherGlobalCodeCompletions(CodeCompletionAllocator &Allocator, 6769 CodeCompletionTUInfo &CCTUInfo, 6770 SmallVectorImpl<CodeCompletionResult> &Results); 6771 //@} 6772 6773 //===--------------------------------------------------------------------===// 6774 // Extra semantic analysis beyond the C type system 6775 6776public: 6777 SourceLocation getLocationOfStringLiteralByte(const StringLiteral *SL, 6778 unsigned ByteNo) const; 6779 6780private: 6781 void CheckArrayAccess(const Expr *BaseExpr, const Expr *IndexExpr, 6782 const ArraySubscriptExpr *ASE=0, 6783 bool AllowOnePastEnd=true, bool IndexNegated=false); 6784 void CheckArrayAccess(const Expr *E); 6785 bool CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall); 6786 bool CheckObjCMethodCall(ObjCMethodDecl *Method, SourceLocation loc, 6787 Expr **Args, unsigned NumArgs); 6788 bool CheckBlockCall(NamedDecl *NDecl, CallExpr *TheCall); 6789 6790 bool CheckObjCString(Expr *Arg); 6791 6792 ExprResult CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); 6793 bool CheckARMBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); 6794 6795 bool SemaBuiltinVAStart(CallExpr *TheCall); 6796 bool SemaBuiltinUnorderedCompare(CallExpr *TheCall); 6797 bool SemaBuiltinFPClassification(CallExpr *TheCall, unsigned NumArgs); 6798 6799public: 6800 // Used by C++ template instantiation. 6801 ExprResult SemaBuiltinShuffleVector(CallExpr *TheCall); 6802 6803private: 6804 bool SemaBuiltinPrefetch(CallExpr *TheCall); 6805 bool SemaBuiltinObjectSize(CallExpr *TheCall); 6806 bool SemaBuiltinLongjmp(CallExpr *TheCall); 6807 ExprResult SemaBuiltinAtomicOverloaded(ExprResult TheCallResult); 6808 ExprResult SemaAtomicOpsOverloaded(ExprResult TheCallResult, 6809 AtomicExpr::AtomicOp Op); 6810 bool SemaBuiltinConstantArg(CallExpr *TheCall, int ArgNum, 6811 llvm::APSInt &Result); 6812 6813 enum FormatStringType { 6814 FST_Scanf, 6815 FST_Printf, 6816 FST_NSString, 6817 FST_Strftime, 6818 FST_Strfmon, 6819 FST_Kprintf, 6820 FST_Unknown 6821 }; 6822 static FormatStringType GetFormatStringType(const FormatAttr *Format); 6823 bool SemaCheckStringLiteral(const Expr *E, Expr **Args, unsigned NumArgs, 6824 bool HasVAListArg, unsigned format_idx, 6825 unsigned firstDataArg, FormatStringType Type, 6826 bool inFunctionCall = true); 6827 6828 void CheckFormatString(const StringLiteral *FExpr, const Expr *OrigFormatExpr, 6829 Expr **Args, unsigned NumArgs, bool HasVAListArg, 6830 unsigned format_idx, unsigned firstDataArg, 6831 FormatStringType Type, bool inFunctionCall); 6832 6833 void CheckFormatArguments(const FormatAttr *Format, CallExpr *TheCall); 6834 void CheckFormatArguments(const FormatAttr *Format, Expr **Args, 6835 unsigned NumArgs, bool IsCXXMember, 6836 SourceLocation Loc, SourceRange Range); 6837 void CheckFormatArguments(Expr **Args, unsigned NumArgs, 6838 bool HasVAListArg, unsigned format_idx, 6839 unsigned firstDataArg, FormatStringType Type, 6840 SourceLocation Loc, SourceRange range); 6841 6842 void CheckNonNullArguments(const NonNullAttr *NonNull, 6843 const Expr * const *ExprArgs, 6844 SourceLocation CallSiteLoc); 6845 6846 void CheckMemaccessArguments(const CallExpr *Call, 6847 unsigned BId, 6848 IdentifierInfo *FnName); 6849 6850 void CheckStrlcpycatArguments(const CallExpr *Call, 6851 IdentifierInfo *FnName); 6852 6853 void CheckStrncatArguments(const CallExpr *Call, 6854 IdentifierInfo *FnName); 6855 6856 void CheckReturnStackAddr(Expr *RetValExp, QualType lhsType, 6857 SourceLocation ReturnLoc); 6858 void CheckFloatComparison(SourceLocation Loc, Expr* LHS, Expr* RHS); 6859 void CheckImplicitConversions(Expr *E, SourceLocation CC = SourceLocation()); 6860 6861 void CheckBitFieldInitialization(SourceLocation InitLoc, FieldDecl *Field, 6862 Expr *Init); 6863 6864 /// \brief The parser's current scope. 6865 /// 6866 /// The parser maintains this state here. 6867 Scope *CurScope; 6868 6869protected: 6870 friend class Parser; 6871 friend class InitializationSequence; 6872 friend class ASTReader; 6873 friend class ASTWriter; 6874 6875public: 6876 /// \brief Retrieve the parser's current scope. 6877 /// 6878 /// This routine must only be used when it is certain that semantic analysis 6879 /// and the parser are in precisely the same context, which is not the case 6880 /// when, e.g., we are performing any kind of template instantiation. 6881 /// Therefore, the only safe places to use this scope are in the parser 6882 /// itself and in routines directly invoked from the parser and *never* from 6883 /// template substitution or instantiation. 6884 Scope *getCurScope() const { return CurScope; } 6885 6886 Decl *getObjCDeclContext() const; 6887 6888 DeclContext *getCurLexicalContext() const { 6889 return OriginalLexicalContext ? OriginalLexicalContext : CurContext; 6890 } 6891 6892 AvailabilityResult getCurContextAvailability() const; 6893}; 6894 6895/// \brief RAII object that enters a new expression evaluation context. 6896class EnterExpressionEvaluationContext { 6897 Sema &Actions; 6898 6899public: 6900 EnterExpressionEvaluationContext(Sema &Actions, 6901 Sema::ExpressionEvaluationContext NewContext, 6902 Decl *LambdaContextDecl = 0, 6903 bool IsDecltype = false) 6904 : Actions(Actions) { 6905 Actions.PushExpressionEvaluationContext(NewContext, LambdaContextDecl, 6906 IsDecltype); 6907 } 6908 6909 ~EnterExpressionEvaluationContext() { 6910 Actions.PopExpressionEvaluationContext(); 6911 } 6912}; 6913 6914} // end namespace clang 6915 6916#endif 6917