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