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