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