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