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