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