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