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