Sema.h revision 23f0267e2d56c0407f12e62df3561ecf75d74e6e
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 ExprResult BuildBlockForLambdaConversion(SourceLocation CurrentLocation, 3659 SourceLocation ConvLocation, 3660 CXXConversionDecl *Conv, 3661 Expr *Src); 3662 3663 // ParseObjCStringLiteral - Parse Objective-C string literals. 3664 ExprResult ParseObjCStringLiteral(SourceLocation *AtLocs, 3665 Expr **Strings, 3666 unsigned NumStrings); 3667 3668 ExprResult BuildObjCEncodeExpression(SourceLocation AtLoc, 3669 TypeSourceInfo *EncodedTypeInfo, 3670 SourceLocation RParenLoc); 3671 ExprResult BuildCXXMemberCallExpr(Expr *Exp, NamedDecl *FoundDecl, 3672 CXXConversionDecl *Method, 3673 bool HadMultipleCandidates); 3674 3675 ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc, 3676 SourceLocation EncodeLoc, 3677 SourceLocation LParenLoc, 3678 ParsedType Ty, 3679 SourceLocation RParenLoc); 3680 3681 // ParseObjCSelectorExpression - Build selector expression for @selector 3682 ExprResult ParseObjCSelectorExpression(Selector Sel, 3683 SourceLocation AtLoc, 3684 SourceLocation SelLoc, 3685 SourceLocation LParenLoc, 3686 SourceLocation RParenLoc); 3687 3688 // ParseObjCProtocolExpression - Build protocol expression for @protocol 3689 ExprResult ParseObjCProtocolExpression(IdentifierInfo * ProtocolName, 3690 SourceLocation AtLoc, 3691 SourceLocation ProtoLoc, 3692 SourceLocation LParenLoc, 3693 SourceLocation RParenLoc); 3694 3695 //===--------------------------------------------------------------------===// 3696 // C++ Declarations 3697 // 3698 Decl *ActOnStartLinkageSpecification(Scope *S, 3699 SourceLocation ExternLoc, 3700 SourceLocation LangLoc, 3701 StringRef Lang, 3702 SourceLocation LBraceLoc); 3703 Decl *ActOnFinishLinkageSpecification(Scope *S, 3704 Decl *LinkageSpec, 3705 SourceLocation RBraceLoc); 3706 3707 3708 //===--------------------------------------------------------------------===// 3709 // C++ Classes 3710 // 3711 bool isCurrentClassName(const IdentifierInfo &II, Scope *S, 3712 const CXXScopeSpec *SS = 0); 3713 3714 bool ActOnAccessSpecifier(AccessSpecifier Access, 3715 SourceLocation ASLoc, 3716 SourceLocation ColonLoc, 3717 AttributeList *Attrs = 0); 3718 3719 Decl *ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS, 3720 Declarator &D, 3721 MultiTemplateParamsArg TemplateParameterLists, 3722 Expr *BitfieldWidth, const VirtSpecifiers &VS, 3723 bool HasDeferredInit); 3724 void ActOnCXXInClassMemberInitializer(Decl *VarDecl, SourceLocation EqualLoc, 3725 Expr *Init); 3726 3727 MemInitResult ActOnMemInitializer(Decl *ConstructorD, 3728 Scope *S, 3729 CXXScopeSpec &SS, 3730 IdentifierInfo *MemberOrBase, 3731 ParsedType TemplateTypeTy, 3732 const DeclSpec &DS, 3733 SourceLocation IdLoc, 3734 SourceLocation LParenLoc, 3735 Expr **Args, unsigned NumArgs, 3736 SourceLocation RParenLoc, 3737 SourceLocation EllipsisLoc); 3738 3739 MemInitResult ActOnMemInitializer(Decl *ConstructorD, 3740 Scope *S, 3741 CXXScopeSpec &SS, 3742 IdentifierInfo *MemberOrBase, 3743 ParsedType TemplateTypeTy, 3744 const DeclSpec &DS, 3745 SourceLocation IdLoc, 3746 Expr *InitList, 3747 SourceLocation EllipsisLoc); 3748 3749 MemInitResult BuildMemInitializer(Decl *ConstructorD, 3750 Scope *S, 3751 CXXScopeSpec &SS, 3752 IdentifierInfo *MemberOrBase, 3753 ParsedType TemplateTypeTy, 3754 const DeclSpec &DS, 3755 SourceLocation IdLoc, 3756 Expr *Init, 3757 SourceLocation EllipsisLoc); 3758 3759 MemInitResult BuildMemberInitializer(ValueDecl *Member, 3760 Expr *Init, 3761 SourceLocation IdLoc); 3762 3763 MemInitResult BuildBaseInitializer(QualType BaseType, 3764 TypeSourceInfo *BaseTInfo, 3765 Expr *Init, 3766 CXXRecordDecl *ClassDecl, 3767 SourceLocation EllipsisLoc); 3768 3769 MemInitResult BuildDelegatingInitializer(TypeSourceInfo *TInfo, 3770 Expr *Init, 3771 CXXRecordDecl *ClassDecl); 3772 3773 bool SetDelegatingInitializer(CXXConstructorDecl *Constructor, 3774 CXXCtorInitializer *Initializer); 3775 3776 bool SetCtorInitializers(CXXConstructorDecl *Constructor, 3777 CXXCtorInitializer **Initializers, 3778 unsigned NumInitializers, bool AnyErrors); 3779 3780 void SetIvarInitializers(ObjCImplementationDecl *ObjCImplementation); 3781 3782 3783 /// MarkBaseAndMemberDestructorsReferenced - Given a record decl, 3784 /// mark all the non-trivial destructors of its members and bases as 3785 /// referenced. 3786 void MarkBaseAndMemberDestructorsReferenced(SourceLocation Loc, 3787 CXXRecordDecl *Record); 3788 3789 /// \brief The list of classes whose vtables have been used within 3790 /// this translation unit, and the source locations at which the 3791 /// first use occurred. 3792 typedef std::pair<CXXRecordDecl*, SourceLocation> VTableUse; 3793 3794 /// \brief The list of vtables that are required but have not yet been 3795 /// materialized. 3796 SmallVector<VTableUse, 16> VTableUses; 3797 3798 /// \brief The set of classes whose vtables have been used within 3799 /// this translation unit, and a bit that will be true if the vtable is 3800 /// required to be emitted (otherwise, it should be emitted only if needed 3801 /// by code generation). 3802 llvm::DenseMap<CXXRecordDecl *, bool> VTablesUsed; 3803 3804 /// \brief Load any externally-stored vtable uses. 3805 void LoadExternalVTableUses(); 3806 3807 typedef LazyVector<CXXRecordDecl *, ExternalSemaSource, 3808 &ExternalSemaSource::ReadDynamicClasses, 2, 2> 3809 DynamicClassesType; 3810 3811 /// \brief A list of all of the dynamic classes in this translation 3812 /// unit. 3813 DynamicClassesType DynamicClasses; 3814 3815 /// \brief Note that the vtable for the given class was used at the 3816 /// given location. 3817 void MarkVTableUsed(SourceLocation Loc, CXXRecordDecl *Class, 3818 bool DefinitionRequired = false); 3819 3820 /// MarkVirtualMembersReferenced - Will mark all members of the given 3821 /// CXXRecordDecl referenced. 3822 void MarkVirtualMembersReferenced(SourceLocation Loc, 3823 const CXXRecordDecl *RD); 3824 3825 /// \brief Define all of the vtables that have been used in this 3826 /// translation unit and reference any virtual members used by those 3827 /// vtables. 3828 /// 3829 /// \returns true if any work was done, false otherwise. 3830 bool DefineUsedVTables(); 3831 3832 void AddImplicitlyDeclaredMembersToClass(CXXRecordDecl *ClassDecl); 3833 3834 void ActOnMemInitializers(Decl *ConstructorDecl, 3835 SourceLocation ColonLoc, 3836 CXXCtorInitializer **MemInits, 3837 unsigned NumMemInits, 3838 bool AnyErrors); 3839 3840 void CheckCompletedCXXClass(CXXRecordDecl *Record); 3841 void ActOnFinishCXXMemberSpecification(Scope* S, SourceLocation RLoc, 3842 Decl *TagDecl, 3843 SourceLocation LBrac, 3844 SourceLocation RBrac, 3845 AttributeList *AttrList); 3846 3847 void ActOnReenterTemplateScope(Scope *S, Decl *Template); 3848 void ActOnReenterDeclaratorTemplateScope(Scope *S, DeclaratorDecl *D); 3849 void ActOnStartDelayedMemberDeclarations(Scope *S, Decl *Record); 3850 void ActOnStartDelayedCXXMethodDeclaration(Scope *S, Decl *Method); 3851 void ActOnDelayedCXXMethodParameter(Scope *S, Decl *Param); 3852 void ActOnFinishDelayedMemberDeclarations(Scope *S, Decl *Record); 3853 void ActOnFinishDelayedCXXMethodDeclaration(Scope *S, Decl *Method); 3854 void ActOnFinishDelayedMemberInitializers(Decl *Record); 3855 void MarkAsLateParsedTemplate(FunctionDecl *FD, bool Flag = true); 3856 bool IsInsideALocalClassWithinATemplateFunction(); 3857 3858 Decl *ActOnStaticAssertDeclaration(SourceLocation StaticAssertLoc, 3859 Expr *AssertExpr, 3860 Expr *AssertMessageExpr, 3861 SourceLocation RParenLoc); 3862 3863 FriendDecl *CheckFriendTypeDecl(SourceLocation Loc, 3864 SourceLocation FriendLoc, 3865 TypeSourceInfo *TSInfo); 3866 Decl *ActOnFriendTypeDecl(Scope *S, const DeclSpec &DS, 3867 MultiTemplateParamsArg TemplateParams); 3868 Decl *ActOnFriendFunctionDecl(Scope *S, Declarator &D, 3869 MultiTemplateParamsArg TemplateParams); 3870 3871 QualType CheckConstructorDeclarator(Declarator &D, QualType R, 3872 StorageClass& SC); 3873 void CheckConstructor(CXXConstructorDecl *Constructor); 3874 QualType CheckDestructorDeclarator(Declarator &D, QualType R, 3875 StorageClass& SC); 3876 bool CheckDestructor(CXXDestructorDecl *Destructor); 3877 void CheckConversionDeclarator(Declarator &D, QualType &R, 3878 StorageClass& SC); 3879 Decl *ActOnConversionDeclarator(CXXConversionDecl *Conversion); 3880 3881 void CheckExplicitlyDefaultedMethods(CXXRecordDecl *Record); 3882 void CheckExplicitlyDefaultedDefaultConstructor(CXXConstructorDecl *Ctor); 3883 void CheckExplicitlyDefaultedCopyConstructor(CXXConstructorDecl *Ctor); 3884 void CheckExplicitlyDefaultedCopyAssignment(CXXMethodDecl *Method); 3885 void CheckExplicitlyDefaultedMoveConstructor(CXXConstructorDecl *Ctor); 3886 void CheckExplicitlyDefaultedMoveAssignment(CXXMethodDecl *Method); 3887 void CheckExplicitlyDefaultedDestructor(CXXDestructorDecl *Dtor); 3888 3889 //===--------------------------------------------------------------------===// 3890 // C++ Derived Classes 3891 // 3892 3893 /// ActOnBaseSpecifier - Parsed a base specifier 3894 CXXBaseSpecifier *CheckBaseSpecifier(CXXRecordDecl *Class, 3895 SourceRange SpecifierRange, 3896 bool Virtual, AccessSpecifier Access, 3897 TypeSourceInfo *TInfo, 3898 SourceLocation EllipsisLoc); 3899 3900 BaseResult ActOnBaseSpecifier(Decl *classdecl, 3901 SourceRange SpecifierRange, 3902 bool Virtual, AccessSpecifier Access, 3903 ParsedType basetype, 3904 SourceLocation BaseLoc, 3905 SourceLocation EllipsisLoc); 3906 3907 bool AttachBaseSpecifiers(CXXRecordDecl *Class, CXXBaseSpecifier **Bases, 3908 unsigned NumBases); 3909 void ActOnBaseSpecifiers(Decl *ClassDecl, CXXBaseSpecifier **Bases, 3910 unsigned NumBases); 3911 3912 bool IsDerivedFrom(QualType Derived, QualType Base); 3913 bool IsDerivedFrom(QualType Derived, QualType Base, CXXBasePaths &Paths); 3914 3915 // FIXME: I don't like this name. 3916 void BuildBasePathArray(const CXXBasePaths &Paths, CXXCastPath &BasePath); 3917 3918 bool BasePathInvolvesVirtualBase(const CXXCastPath &BasePath); 3919 3920 bool CheckDerivedToBaseConversion(QualType Derived, QualType Base, 3921 SourceLocation Loc, SourceRange Range, 3922 CXXCastPath *BasePath = 0, 3923 bool IgnoreAccess = false); 3924 bool CheckDerivedToBaseConversion(QualType Derived, QualType Base, 3925 unsigned InaccessibleBaseID, 3926 unsigned AmbigiousBaseConvID, 3927 SourceLocation Loc, SourceRange Range, 3928 DeclarationName Name, 3929 CXXCastPath *BasePath); 3930 3931 std::string getAmbiguousPathsDisplayString(CXXBasePaths &Paths); 3932 3933 /// CheckOverridingFunctionReturnType - Checks whether the return types are 3934 /// covariant, according to C++ [class.virtual]p5. 3935 bool CheckOverridingFunctionReturnType(const CXXMethodDecl *New, 3936 const CXXMethodDecl *Old); 3937 3938 /// CheckOverridingFunctionExceptionSpec - Checks whether the exception 3939 /// spec is a subset of base spec. 3940 bool CheckOverridingFunctionExceptionSpec(const CXXMethodDecl *New, 3941 const CXXMethodDecl *Old); 3942 3943 bool CheckPureMethod(CXXMethodDecl *Method, SourceRange InitRange); 3944 3945 /// CheckOverrideControl - Check C++0x override control semantics. 3946 void CheckOverrideControl(const Decl *D); 3947 3948 /// CheckForFunctionMarkedFinal - Checks whether a virtual member function 3949 /// overrides a virtual member function marked 'final', according to 3950 /// C++0x [class.virtual]p3. 3951 bool CheckIfOverriddenFunctionIsMarkedFinal(const CXXMethodDecl *New, 3952 const CXXMethodDecl *Old); 3953 3954 3955 //===--------------------------------------------------------------------===// 3956 // C++ Access Control 3957 // 3958 3959 enum AccessResult { 3960 AR_accessible, 3961 AR_inaccessible, 3962 AR_dependent, 3963 AR_delayed 3964 }; 3965 3966 bool SetMemberAccessSpecifier(NamedDecl *MemberDecl, 3967 NamedDecl *PrevMemberDecl, 3968 AccessSpecifier LexicalAS); 3969 3970 AccessResult CheckUnresolvedMemberAccess(UnresolvedMemberExpr *E, 3971 DeclAccessPair FoundDecl); 3972 AccessResult CheckUnresolvedLookupAccess(UnresolvedLookupExpr *E, 3973 DeclAccessPair FoundDecl); 3974 AccessResult CheckAllocationAccess(SourceLocation OperatorLoc, 3975 SourceRange PlacementRange, 3976 CXXRecordDecl *NamingClass, 3977 DeclAccessPair FoundDecl, 3978 bool Diagnose = true); 3979 AccessResult CheckConstructorAccess(SourceLocation Loc, 3980 CXXConstructorDecl *D, 3981 const InitializedEntity &Entity, 3982 AccessSpecifier Access, 3983 bool IsCopyBindingRefToTemp = false); 3984 AccessResult CheckConstructorAccess(SourceLocation Loc, 3985 CXXConstructorDecl *D, 3986 AccessSpecifier Access, 3987 PartialDiagnostic PD); 3988 AccessResult CheckDestructorAccess(SourceLocation Loc, 3989 CXXDestructorDecl *Dtor, 3990 const PartialDiagnostic &PDiag); 3991 AccessResult CheckDirectMemberAccess(SourceLocation Loc, 3992 NamedDecl *D, 3993 const PartialDiagnostic &PDiag); 3994 AccessResult CheckMemberOperatorAccess(SourceLocation Loc, 3995 Expr *ObjectExpr, 3996 Expr *ArgExpr, 3997 DeclAccessPair FoundDecl); 3998 AccessResult CheckAddressOfMemberAccess(Expr *OvlExpr, 3999 DeclAccessPair FoundDecl); 4000 AccessResult CheckBaseClassAccess(SourceLocation AccessLoc, 4001 QualType Base, QualType Derived, 4002 const CXXBasePath &Path, 4003 unsigned DiagID, 4004 bool ForceCheck = false, 4005 bool ForceUnprivileged = false); 4006 void CheckLookupAccess(const LookupResult &R); 4007 bool IsSimplyAccessible(NamedDecl *decl, DeclContext *Ctx); 4008 4009 void HandleDependentAccessCheck(const DependentDiagnostic &DD, 4010 const MultiLevelTemplateArgumentList &TemplateArgs); 4011 void PerformDependentDiagnostics(const DeclContext *Pattern, 4012 const MultiLevelTemplateArgumentList &TemplateArgs); 4013 4014 void HandleDelayedAccessCheck(sema::DelayedDiagnostic &DD, Decl *Ctx); 4015 4016 /// A flag to suppress access checking. 4017 bool SuppressAccessChecking; 4018 4019 /// \brief When true, access checking violations are treated as SFINAE 4020 /// failures rather than hard errors. 4021 bool AccessCheckingSFINAE; 4022 4023 void ActOnStartSuppressingAccessChecks(); 4024 void ActOnStopSuppressingAccessChecks(); 4025 4026 enum AbstractDiagSelID { 4027 AbstractNone = -1, 4028 AbstractReturnType, 4029 AbstractParamType, 4030 AbstractVariableType, 4031 AbstractFieldType, 4032 AbstractArrayType 4033 }; 4034 4035 bool RequireNonAbstractType(SourceLocation Loc, QualType T, 4036 const PartialDiagnostic &PD); 4037 void DiagnoseAbstractType(const CXXRecordDecl *RD); 4038 4039 bool RequireNonAbstractType(SourceLocation Loc, QualType T, unsigned DiagID, 4040 AbstractDiagSelID SelID = AbstractNone); 4041 4042 //===--------------------------------------------------------------------===// 4043 // C++ Overloaded Operators [C++ 13.5] 4044 // 4045 4046 bool CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl); 4047 4048 bool CheckLiteralOperatorDeclaration(FunctionDecl *FnDecl); 4049 4050 //===--------------------------------------------------------------------===// 4051 // C++ Templates [C++ 14] 4052 // 4053 void FilterAcceptableTemplateNames(LookupResult &R); 4054 bool hasAnyAcceptableTemplateNames(LookupResult &R); 4055 4056 void LookupTemplateName(LookupResult &R, Scope *S, CXXScopeSpec &SS, 4057 QualType ObjectType, bool EnteringContext, 4058 bool &MemberOfUnknownSpecialization); 4059 4060 TemplateNameKind isTemplateName(Scope *S, 4061 CXXScopeSpec &SS, 4062 bool hasTemplateKeyword, 4063 UnqualifiedId &Name, 4064 ParsedType ObjectType, 4065 bool EnteringContext, 4066 TemplateTy &Template, 4067 bool &MemberOfUnknownSpecialization); 4068 4069 bool DiagnoseUnknownTemplateName(const IdentifierInfo &II, 4070 SourceLocation IILoc, 4071 Scope *S, 4072 const CXXScopeSpec *SS, 4073 TemplateTy &SuggestedTemplate, 4074 TemplateNameKind &SuggestedKind); 4075 4076 void DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl); 4077 TemplateDecl *AdjustDeclIfTemplate(Decl *&Decl); 4078 4079 Decl *ActOnTypeParameter(Scope *S, bool Typename, bool Ellipsis, 4080 SourceLocation EllipsisLoc, 4081 SourceLocation KeyLoc, 4082 IdentifierInfo *ParamName, 4083 SourceLocation ParamNameLoc, 4084 unsigned Depth, unsigned Position, 4085 SourceLocation EqualLoc, 4086 ParsedType DefaultArg); 4087 4088 QualType CheckNonTypeTemplateParameterType(QualType T, SourceLocation Loc); 4089 Decl *ActOnNonTypeTemplateParameter(Scope *S, Declarator &D, 4090 unsigned Depth, 4091 unsigned Position, 4092 SourceLocation EqualLoc, 4093 Expr *DefaultArg); 4094 Decl *ActOnTemplateTemplateParameter(Scope *S, 4095 SourceLocation TmpLoc, 4096 TemplateParameterList *Params, 4097 SourceLocation EllipsisLoc, 4098 IdentifierInfo *ParamName, 4099 SourceLocation ParamNameLoc, 4100 unsigned Depth, 4101 unsigned Position, 4102 SourceLocation EqualLoc, 4103 ParsedTemplateArgument DefaultArg); 4104 4105 TemplateParameterList * 4106 ActOnTemplateParameterList(unsigned Depth, 4107 SourceLocation ExportLoc, 4108 SourceLocation TemplateLoc, 4109 SourceLocation LAngleLoc, 4110 Decl **Params, unsigned NumParams, 4111 SourceLocation RAngleLoc); 4112 4113 /// \brief The context in which we are checking a template parameter 4114 /// list. 4115 enum TemplateParamListContext { 4116 TPC_ClassTemplate, 4117 TPC_FunctionTemplate, 4118 TPC_ClassTemplateMember, 4119 TPC_FriendFunctionTemplate, 4120 TPC_FriendFunctionTemplateDefinition, 4121 TPC_TypeAliasTemplate 4122 }; 4123 4124 bool CheckTemplateParameterList(TemplateParameterList *NewParams, 4125 TemplateParameterList *OldParams, 4126 TemplateParamListContext TPC); 4127 TemplateParameterList * 4128 MatchTemplateParametersToScopeSpecifier(SourceLocation DeclStartLoc, 4129 SourceLocation DeclLoc, 4130 const CXXScopeSpec &SS, 4131 TemplateParameterList **ParamLists, 4132 unsigned NumParamLists, 4133 bool IsFriend, 4134 bool &IsExplicitSpecialization, 4135 bool &Invalid); 4136 4137 DeclResult CheckClassTemplate(Scope *S, unsigned TagSpec, TagUseKind TUK, 4138 SourceLocation KWLoc, CXXScopeSpec &SS, 4139 IdentifierInfo *Name, SourceLocation NameLoc, 4140 AttributeList *Attr, 4141 TemplateParameterList *TemplateParams, 4142 AccessSpecifier AS, 4143 SourceLocation ModulePrivateLoc, 4144 unsigned NumOuterTemplateParamLists, 4145 TemplateParameterList **OuterTemplateParamLists); 4146 4147 void translateTemplateArguments(const ASTTemplateArgsPtr &In, 4148 TemplateArgumentListInfo &Out); 4149 4150 void NoteAllFoundTemplates(TemplateName Name); 4151 4152 QualType CheckTemplateIdType(TemplateName Template, 4153 SourceLocation TemplateLoc, 4154 TemplateArgumentListInfo &TemplateArgs); 4155 4156 TypeResult 4157 ActOnTemplateIdType(CXXScopeSpec &SS, SourceLocation TemplateKWLoc, 4158 TemplateTy Template, SourceLocation TemplateLoc, 4159 SourceLocation LAngleLoc, 4160 ASTTemplateArgsPtr TemplateArgs, 4161 SourceLocation RAngleLoc, 4162 bool IsCtorOrDtorName = false); 4163 4164 /// \brief Parsed an elaborated-type-specifier that refers to a template-id, 4165 /// such as \c class T::template apply<U>. 4166 /// 4167 /// \param TUK 4168 TypeResult ActOnTagTemplateIdType(TagUseKind TUK, 4169 TypeSpecifierType TagSpec, 4170 SourceLocation TagLoc, 4171 CXXScopeSpec &SS, 4172 SourceLocation TemplateKWLoc, 4173 TemplateTy TemplateD, 4174 SourceLocation TemplateLoc, 4175 SourceLocation LAngleLoc, 4176 ASTTemplateArgsPtr TemplateArgsIn, 4177 SourceLocation RAngleLoc); 4178 4179 4180 ExprResult BuildTemplateIdExpr(const CXXScopeSpec &SS, 4181 SourceLocation TemplateKWLoc, 4182 LookupResult &R, 4183 bool RequiresADL, 4184 const TemplateArgumentListInfo *TemplateArgs); 4185 4186 ExprResult BuildQualifiedTemplateIdExpr(CXXScopeSpec &SS, 4187 SourceLocation TemplateKWLoc, 4188 const DeclarationNameInfo &NameInfo, 4189 const TemplateArgumentListInfo *TemplateArgs); 4190 4191 TemplateNameKind ActOnDependentTemplateName(Scope *S, 4192 CXXScopeSpec &SS, 4193 SourceLocation TemplateKWLoc, 4194 UnqualifiedId &Name, 4195 ParsedType ObjectType, 4196 bool EnteringContext, 4197 TemplateTy &Template); 4198 4199 DeclResult 4200 ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, TagUseKind TUK, 4201 SourceLocation KWLoc, 4202 SourceLocation ModulePrivateLoc, 4203 CXXScopeSpec &SS, 4204 TemplateTy Template, 4205 SourceLocation TemplateNameLoc, 4206 SourceLocation LAngleLoc, 4207 ASTTemplateArgsPtr TemplateArgs, 4208 SourceLocation RAngleLoc, 4209 AttributeList *Attr, 4210 MultiTemplateParamsArg TemplateParameterLists); 4211 4212 Decl *ActOnTemplateDeclarator(Scope *S, 4213 MultiTemplateParamsArg TemplateParameterLists, 4214 Declarator &D); 4215 4216 Decl *ActOnStartOfFunctionTemplateDef(Scope *FnBodyScope, 4217 MultiTemplateParamsArg TemplateParameterLists, 4218 Declarator &D); 4219 4220 bool 4221 CheckSpecializationInstantiationRedecl(SourceLocation NewLoc, 4222 TemplateSpecializationKind NewTSK, 4223 NamedDecl *PrevDecl, 4224 TemplateSpecializationKind PrevTSK, 4225 SourceLocation PrevPtOfInstantiation, 4226 bool &SuppressNew); 4227 4228 bool CheckDependentFunctionTemplateSpecialization(FunctionDecl *FD, 4229 const TemplateArgumentListInfo &ExplicitTemplateArgs, 4230 LookupResult &Previous); 4231 4232 bool CheckFunctionTemplateSpecialization(FunctionDecl *FD, 4233 TemplateArgumentListInfo *ExplicitTemplateArgs, 4234 LookupResult &Previous); 4235 bool CheckMemberSpecialization(NamedDecl *Member, LookupResult &Previous); 4236 4237 DeclResult 4238 ActOnExplicitInstantiation(Scope *S, 4239 SourceLocation ExternLoc, 4240 SourceLocation TemplateLoc, 4241 unsigned TagSpec, 4242 SourceLocation KWLoc, 4243 const CXXScopeSpec &SS, 4244 TemplateTy Template, 4245 SourceLocation TemplateNameLoc, 4246 SourceLocation LAngleLoc, 4247 ASTTemplateArgsPtr TemplateArgs, 4248 SourceLocation RAngleLoc, 4249 AttributeList *Attr); 4250 4251 DeclResult 4252 ActOnExplicitInstantiation(Scope *S, 4253 SourceLocation ExternLoc, 4254 SourceLocation TemplateLoc, 4255 unsigned TagSpec, 4256 SourceLocation KWLoc, 4257 CXXScopeSpec &SS, 4258 IdentifierInfo *Name, 4259 SourceLocation NameLoc, 4260 AttributeList *Attr); 4261 4262 DeclResult ActOnExplicitInstantiation(Scope *S, 4263 SourceLocation ExternLoc, 4264 SourceLocation TemplateLoc, 4265 Declarator &D); 4266 4267 TemplateArgumentLoc 4268 SubstDefaultTemplateArgumentIfAvailable(TemplateDecl *Template, 4269 SourceLocation TemplateLoc, 4270 SourceLocation RAngleLoc, 4271 Decl *Param, 4272 SmallVectorImpl<TemplateArgument> &Converted); 4273 4274 /// \brief Specifies the context in which a particular template 4275 /// argument is being checked. 4276 enum CheckTemplateArgumentKind { 4277 /// \brief The template argument was specified in the code or was 4278 /// instantiated with some deduced template arguments. 4279 CTAK_Specified, 4280 4281 /// \brief The template argument was deduced via template argument 4282 /// deduction. 4283 CTAK_Deduced, 4284 4285 /// \brief The template argument was deduced from an array bound 4286 /// via template argument deduction. 4287 CTAK_DeducedFromArrayBound 4288 }; 4289 4290 bool CheckTemplateArgument(NamedDecl *Param, 4291 const TemplateArgumentLoc &Arg, 4292 NamedDecl *Template, 4293 SourceLocation TemplateLoc, 4294 SourceLocation RAngleLoc, 4295 unsigned ArgumentPackIndex, 4296 SmallVectorImpl<TemplateArgument> &Converted, 4297 CheckTemplateArgumentKind CTAK = CTAK_Specified); 4298 4299 /// \brief Check that the given template arguments can be be provided to 4300 /// the given template, converting the arguments along the way. 4301 /// 4302 /// \param Template The template to which the template arguments are being 4303 /// provided. 4304 /// 4305 /// \param TemplateLoc The location of the template name in the source. 4306 /// 4307 /// \param TemplateArgs The list of template arguments. If the template is 4308 /// a template template parameter, this function may extend the set of 4309 /// template arguments to also include substituted, defaulted template 4310 /// arguments. 4311 /// 4312 /// \param PartialTemplateArgs True if the list of template arguments is 4313 /// intentionally partial, e.g., because we're checking just the initial 4314 /// set of template arguments. 4315 /// 4316 /// \param Converted Will receive the converted, canonicalized template 4317 /// arguments. 4318 /// 4319 /// 4320 /// \param ExpansionIntoFixedList If non-NULL, will be set true to indicate 4321 /// when the template arguments contain a pack expansion that is being 4322 /// expanded into a fixed parameter list. 4323 /// 4324 /// \returns True if an error occurred, false otherwise. 4325 bool CheckTemplateArgumentList(TemplateDecl *Template, 4326 SourceLocation TemplateLoc, 4327 TemplateArgumentListInfo &TemplateArgs, 4328 bool PartialTemplateArgs, 4329 SmallVectorImpl<TemplateArgument> &Converted, 4330 bool *ExpansionIntoFixedList = 0); 4331 4332 bool CheckTemplateTypeArgument(TemplateTypeParmDecl *Param, 4333 const TemplateArgumentLoc &Arg, 4334 SmallVectorImpl<TemplateArgument> &Converted); 4335 4336 bool CheckTemplateArgument(TemplateTypeParmDecl *Param, 4337 TypeSourceInfo *Arg); 4338 bool CheckTemplateArgumentPointerToMember(Expr *Arg, 4339 TemplateArgument &Converted); 4340 ExprResult CheckTemplateArgument(NonTypeTemplateParmDecl *Param, 4341 QualType InstantiatedParamType, Expr *Arg, 4342 TemplateArgument &Converted, 4343 CheckTemplateArgumentKind CTAK = CTAK_Specified); 4344 bool CheckTemplateArgument(TemplateTemplateParmDecl *Param, 4345 const TemplateArgumentLoc &Arg); 4346 4347 ExprResult 4348 BuildExpressionFromDeclTemplateArgument(const TemplateArgument &Arg, 4349 QualType ParamType, 4350 SourceLocation Loc); 4351 ExprResult 4352 BuildExpressionFromIntegralTemplateArgument(const TemplateArgument &Arg, 4353 SourceLocation Loc); 4354 4355 /// \brief Enumeration describing how template parameter lists are compared 4356 /// for equality. 4357 enum TemplateParameterListEqualKind { 4358 /// \brief We are matching the template parameter lists of two templates 4359 /// that might be redeclarations. 4360 /// 4361 /// \code 4362 /// template<typename T> struct X; 4363 /// template<typename T> struct X; 4364 /// \endcode 4365 TPL_TemplateMatch, 4366 4367 /// \brief We are matching the template parameter lists of two template 4368 /// template parameters as part of matching the template parameter lists 4369 /// of two templates that might be redeclarations. 4370 /// 4371 /// \code 4372 /// template<template<int I> class TT> struct X; 4373 /// template<template<int Value> class Other> struct X; 4374 /// \endcode 4375 TPL_TemplateTemplateParmMatch, 4376 4377 /// \brief We are matching the template parameter lists of a template 4378 /// template argument against the template parameter lists of a template 4379 /// template parameter. 4380 /// 4381 /// \code 4382 /// template<template<int Value> class Metafun> struct X; 4383 /// template<int Value> struct integer_c; 4384 /// X<integer_c> xic; 4385 /// \endcode 4386 TPL_TemplateTemplateArgumentMatch 4387 }; 4388 4389 bool TemplateParameterListsAreEqual(TemplateParameterList *New, 4390 TemplateParameterList *Old, 4391 bool Complain, 4392 TemplateParameterListEqualKind Kind, 4393 SourceLocation TemplateArgLoc 4394 = SourceLocation()); 4395 4396 bool CheckTemplateDeclScope(Scope *S, TemplateParameterList *TemplateParams); 4397 4398 /// \brief Called when the parser has parsed a C++ typename 4399 /// specifier, e.g., "typename T::type". 4400 /// 4401 /// \param S The scope in which this typename type occurs. 4402 /// \param TypenameLoc the location of the 'typename' keyword 4403 /// \param SS the nested-name-specifier following the typename (e.g., 'T::'). 4404 /// \param II the identifier we're retrieving (e.g., 'type' in the example). 4405 /// \param IdLoc the location of the identifier. 4406 TypeResult 4407 ActOnTypenameType(Scope *S, SourceLocation TypenameLoc, 4408 const CXXScopeSpec &SS, const IdentifierInfo &II, 4409 SourceLocation IdLoc); 4410 4411 /// \brief Called when the parser has parsed a C++ typename 4412 /// specifier that ends in a template-id, e.g., 4413 /// "typename MetaFun::template apply<T1, T2>". 4414 /// 4415 /// \param S The scope in which this typename type occurs. 4416 /// \param TypenameLoc the location of the 'typename' keyword 4417 /// \param SS the nested-name-specifier following the typename (e.g., 'T::'). 4418 /// \param TemplateLoc the location of the 'template' keyword, if any. 4419 /// \param TemplateName The template name. 4420 /// \param TemplateNameLoc The location of the template name. 4421 /// \param LAngleLoc The location of the opening angle bracket ('<'). 4422 /// \param TemplateArgs The template arguments. 4423 /// \param RAngleLoc The location of the closing angle bracket ('>'). 4424 TypeResult 4425 ActOnTypenameType(Scope *S, SourceLocation TypenameLoc, 4426 const CXXScopeSpec &SS, 4427 SourceLocation TemplateLoc, 4428 TemplateTy Template, 4429 SourceLocation TemplateNameLoc, 4430 SourceLocation LAngleLoc, 4431 ASTTemplateArgsPtr TemplateArgs, 4432 SourceLocation RAngleLoc); 4433 4434 QualType CheckTypenameType(ElaboratedTypeKeyword Keyword, 4435 SourceLocation KeywordLoc, 4436 NestedNameSpecifierLoc QualifierLoc, 4437 const IdentifierInfo &II, 4438 SourceLocation IILoc); 4439 4440 TypeSourceInfo *RebuildTypeInCurrentInstantiation(TypeSourceInfo *T, 4441 SourceLocation Loc, 4442 DeclarationName Name); 4443 bool RebuildNestedNameSpecifierInCurrentInstantiation(CXXScopeSpec &SS); 4444 4445 ExprResult RebuildExprInCurrentInstantiation(Expr *E); 4446 bool RebuildTemplateParamsInCurrentInstantiation( 4447 TemplateParameterList *Params); 4448 4449 std::string 4450 getTemplateArgumentBindingsText(const TemplateParameterList *Params, 4451 const TemplateArgumentList &Args); 4452 4453 std::string 4454 getTemplateArgumentBindingsText(const TemplateParameterList *Params, 4455 const TemplateArgument *Args, 4456 unsigned NumArgs); 4457 4458 //===--------------------------------------------------------------------===// 4459 // C++ Variadic Templates (C++0x [temp.variadic]) 4460 //===--------------------------------------------------------------------===// 4461 4462 /// \brief The context in which an unexpanded parameter pack is 4463 /// being diagnosed. 4464 /// 4465 /// Note that the values of this enumeration line up with the first 4466 /// argument to the \c err_unexpanded_parameter_pack diagnostic. 4467 enum UnexpandedParameterPackContext { 4468 /// \brief An arbitrary expression. 4469 UPPC_Expression = 0, 4470 4471 /// \brief The base type of a class type. 4472 UPPC_BaseType, 4473 4474 /// \brief The type of an arbitrary declaration. 4475 UPPC_DeclarationType, 4476 4477 /// \brief The type of a data member. 4478 UPPC_DataMemberType, 4479 4480 /// \brief The size of a bit-field. 4481 UPPC_BitFieldWidth, 4482 4483 /// \brief The expression in a static assertion. 4484 UPPC_StaticAssertExpression, 4485 4486 /// \brief The fixed underlying type of an enumeration. 4487 UPPC_FixedUnderlyingType, 4488 4489 /// \brief The enumerator value. 4490 UPPC_EnumeratorValue, 4491 4492 /// \brief A using declaration. 4493 UPPC_UsingDeclaration, 4494 4495 /// \brief A friend declaration. 4496 UPPC_FriendDeclaration, 4497 4498 /// \brief A declaration qualifier. 4499 UPPC_DeclarationQualifier, 4500 4501 /// \brief An initializer. 4502 UPPC_Initializer, 4503 4504 /// \brief A default argument. 4505 UPPC_DefaultArgument, 4506 4507 /// \brief The type of a non-type template parameter. 4508 UPPC_NonTypeTemplateParameterType, 4509 4510 /// \brief The type of an exception. 4511 UPPC_ExceptionType, 4512 4513 /// \brief Partial specialization. 4514 UPPC_PartialSpecialization, 4515 4516 /// \brief Microsoft __if_exists. 4517 UPPC_IfExists, 4518 4519 /// \brief Microsoft __if_not_exists. 4520 UPPC_IfNotExists 4521}; 4522 4523 /// \brief Diagnose unexpanded parameter packs. 4524 /// 4525 /// \param Loc The location at which we should emit the diagnostic. 4526 /// 4527 /// \param UPPC The context in which we are diagnosing unexpanded 4528 /// parameter packs. 4529 /// 4530 /// \param Unexpanded the set of unexpanded parameter packs. 4531 void DiagnoseUnexpandedParameterPacks(SourceLocation Loc, 4532 UnexpandedParameterPackContext UPPC, 4533 ArrayRef<UnexpandedParameterPack> Unexpanded); 4534 4535 /// \brief If the given type contains an unexpanded parameter pack, 4536 /// diagnose the error. 4537 /// 4538 /// \param Loc The source location where a diagnostc should be emitted. 4539 /// 4540 /// \param T The type that is being checked for unexpanded parameter 4541 /// packs. 4542 /// 4543 /// \returns true if an error occurred, false otherwise. 4544 bool DiagnoseUnexpandedParameterPack(SourceLocation Loc, TypeSourceInfo *T, 4545 UnexpandedParameterPackContext UPPC); 4546 4547 /// \brief If the given expression contains an unexpanded parameter 4548 /// pack, diagnose the error. 4549 /// 4550 /// \param E The expression that is being checked for unexpanded 4551 /// parameter packs. 4552 /// 4553 /// \returns true if an error occurred, false otherwise. 4554 bool DiagnoseUnexpandedParameterPack(Expr *E, 4555 UnexpandedParameterPackContext UPPC = UPPC_Expression); 4556 4557 /// \brief If the given nested-name-specifier contains an unexpanded 4558 /// parameter pack, diagnose the error. 4559 /// 4560 /// \param SS The nested-name-specifier that is being checked for 4561 /// unexpanded parameter packs. 4562 /// 4563 /// \returns true if an error occurred, false otherwise. 4564 bool DiagnoseUnexpandedParameterPack(const CXXScopeSpec &SS, 4565 UnexpandedParameterPackContext UPPC); 4566 4567 /// \brief If the given name contains an unexpanded parameter pack, 4568 /// diagnose the error. 4569 /// 4570 /// \param NameInfo The name (with source location information) that 4571 /// is being checked for unexpanded parameter packs. 4572 /// 4573 /// \returns true if an error occurred, false otherwise. 4574 bool DiagnoseUnexpandedParameterPack(const DeclarationNameInfo &NameInfo, 4575 UnexpandedParameterPackContext UPPC); 4576 4577 /// \brief If the given template name contains an unexpanded parameter pack, 4578 /// diagnose the error. 4579 /// 4580 /// \param Loc The location of the template name. 4581 /// 4582 /// \param Template The template name that is being checked for unexpanded 4583 /// parameter packs. 4584 /// 4585 /// \returns true if an error occurred, false otherwise. 4586 bool DiagnoseUnexpandedParameterPack(SourceLocation Loc, 4587 TemplateName Template, 4588 UnexpandedParameterPackContext UPPC); 4589 4590 /// \brief If the given template argument contains an unexpanded parameter 4591 /// pack, diagnose the error. 4592 /// 4593 /// \param Arg The template argument that is being checked for unexpanded 4594 /// parameter packs. 4595 /// 4596 /// \returns true if an error occurred, false otherwise. 4597 bool DiagnoseUnexpandedParameterPack(TemplateArgumentLoc Arg, 4598 UnexpandedParameterPackContext UPPC); 4599 4600 /// \brief Collect the set of unexpanded parameter packs within the given 4601 /// template argument. 4602 /// 4603 /// \param Arg The template argument that will be traversed to find 4604 /// unexpanded parameter packs. 4605 void collectUnexpandedParameterPacks(TemplateArgument Arg, 4606 SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); 4607 4608 /// \brief Collect the set of unexpanded parameter packs within the given 4609 /// template argument. 4610 /// 4611 /// \param Arg The template argument that will be traversed to find 4612 /// unexpanded parameter packs. 4613 void collectUnexpandedParameterPacks(TemplateArgumentLoc Arg, 4614 SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); 4615 4616 /// \brief Collect the set of unexpanded parameter packs within the given 4617 /// type. 4618 /// 4619 /// \param T The type that will be traversed to find 4620 /// unexpanded parameter packs. 4621 void collectUnexpandedParameterPacks(QualType T, 4622 SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); 4623 4624 /// \brief Collect the set of unexpanded parameter packs within the given 4625 /// type. 4626 /// 4627 /// \param TL The type that will be traversed to find 4628 /// unexpanded parameter packs. 4629 void collectUnexpandedParameterPacks(TypeLoc TL, 4630 SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); 4631 4632 /// \brief Collect the set of unexpanded parameter packs within the given 4633 /// nested-name-specifier. 4634 /// 4635 /// \param SS The nested-name-specifier that will be traversed to find 4636 /// unexpanded parameter packs. 4637 void collectUnexpandedParameterPacks(CXXScopeSpec &SS, 4638 SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); 4639 4640 /// \brief Collect the set of unexpanded parameter packs within the given 4641 /// name. 4642 /// 4643 /// \param NameInfo The name that will be traversed to find 4644 /// unexpanded parameter packs. 4645 void collectUnexpandedParameterPacks(const DeclarationNameInfo &NameInfo, 4646 SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); 4647 4648 /// \brief Invoked when parsing a template argument followed by an 4649 /// ellipsis, which creates a pack expansion. 4650 /// 4651 /// \param Arg The template argument preceding the ellipsis, which 4652 /// may already be invalid. 4653 /// 4654 /// \param EllipsisLoc The location of the ellipsis. 4655 ParsedTemplateArgument ActOnPackExpansion(const ParsedTemplateArgument &Arg, 4656 SourceLocation EllipsisLoc); 4657 4658 /// \brief Invoked when parsing a type followed by an ellipsis, which 4659 /// creates a pack expansion. 4660 /// 4661 /// \param Type The type preceding the ellipsis, which will become 4662 /// the pattern of the pack expansion. 4663 /// 4664 /// \param EllipsisLoc The location of the ellipsis. 4665 TypeResult ActOnPackExpansion(ParsedType Type, SourceLocation EllipsisLoc); 4666 4667 /// \brief Construct a pack expansion type from the pattern of the pack 4668 /// expansion. 4669 TypeSourceInfo *CheckPackExpansion(TypeSourceInfo *Pattern, 4670 SourceLocation EllipsisLoc, 4671 llvm::Optional<unsigned> NumExpansions); 4672 4673 /// \brief Construct a pack expansion type from the pattern of the pack 4674 /// expansion. 4675 QualType CheckPackExpansion(QualType Pattern, 4676 SourceRange PatternRange, 4677 SourceLocation EllipsisLoc, 4678 llvm::Optional<unsigned> NumExpansions); 4679 4680 /// \brief Invoked when parsing an expression followed by an ellipsis, which 4681 /// creates a pack expansion. 4682 /// 4683 /// \param Pattern The expression preceding the ellipsis, which will become 4684 /// the pattern of the pack expansion. 4685 /// 4686 /// \param EllipsisLoc The location of the ellipsis. 4687 ExprResult ActOnPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc); 4688 4689 /// \brief Invoked when parsing an expression followed by an ellipsis, which 4690 /// creates a pack expansion. 4691 /// 4692 /// \param Pattern The expression preceding the ellipsis, which will become 4693 /// the pattern of the pack expansion. 4694 /// 4695 /// \param EllipsisLoc The location of the ellipsis. 4696 ExprResult CheckPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc, 4697 llvm::Optional<unsigned> NumExpansions); 4698 4699 /// \brief Determine whether we could expand a pack expansion with the 4700 /// given set of parameter packs into separate arguments by repeatedly 4701 /// transforming the pattern. 4702 /// 4703 /// \param EllipsisLoc The location of the ellipsis that identifies the 4704 /// pack expansion. 4705 /// 4706 /// \param PatternRange The source range that covers the entire pattern of 4707 /// the pack expansion. 4708 /// 4709 /// \param Unexpanded The set of unexpanded parameter packs within the 4710 /// pattern. 4711 /// 4712 /// \param NumUnexpanded The number of unexpanded parameter packs in 4713 /// \p Unexpanded. 4714 /// 4715 /// \param ShouldExpand Will be set to \c true if the transformer should 4716 /// expand the corresponding pack expansions into separate arguments. When 4717 /// set, \c NumExpansions must also be set. 4718 /// 4719 /// \param RetainExpansion Whether the caller should add an unexpanded 4720 /// pack expansion after all of the expanded arguments. This is used 4721 /// when extending explicitly-specified template argument packs per 4722 /// C++0x [temp.arg.explicit]p9. 4723 /// 4724 /// \param NumExpansions The number of separate arguments that will be in 4725 /// the expanded form of the corresponding pack expansion. This is both an 4726 /// input and an output parameter, which can be set by the caller if the 4727 /// number of expansions is known a priori (e.g., due to a prior substitution) 4728 /// and will be set by the callee when the number of expansions is known. 4729 /// The callee must set this value when \c ShouldExpand is \c true; it may 4730 /// set this value in other cases. 4731 /// 4732 /// \returns true if an error occurred (e.g., because the parameter packs 4733 /// are to be instantiated with arguments of different lengths), false 4734 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions) 4735 /// must be set. 4736 bool CheckParameterPacksForExpansion(SourceLocation EllipsisLoc, 4737 SourceRange PatternRange, 4738 llvm::ArrayRef<UnexpandedParameterPack> Unexpanded, 4739 const MultiLevelTemplateArgumentList &TemplateArgs, 4740 bool &ShouldExpand, 4741 bool &RetainExpansion, 4742 llvm::Optional<unsigned> &NumExpansions); 4743 4744 /// \brief Determine the number of arguments in the given pack expansion 4745 /// type. 4746 /// 4747 /// This routine already assumes that the pack expansion type can be 4748 /// expanded and that the number of arguments in the expansion is 4749 /// consistent across all of the unexpanded parameter packs in its pattern. 4750 unsigned getNumArgumentsInExpansion(QualType T, 4751 const MultiLevelTemplateArgumentList &TemplateArgs); 4752 4753 /// \brief Determine whether the given declarator contains any unexpanded 4754 /// parameter packs. 4755 /// 4756 /// This routine is used by the parser to disambiguate function declarators 4757 /// with an ellipsis prior to the ')', e.g., 4758 /// 4759 /// \code 4760 /// void f(T...); 4761 /// \endcode 4762 /// 4763 /// To determine whether we have an (unnamed) function parameter pack or 4764 /// a variadic function. 4765 /// 4766 /// \returns true if the declarator contains any unexpanded parameter packs, 4767 /// false otherwise. 4768 bool containsUnexpandedParameterPacks(Declarator &D); 4769 4770 //===--------------------------------------------------------------------===// 4771 // C++ Template Argument Deduction (C++ [temp.deduct]) 4772 //===--------------------------------------------------------------------===// 4773 4774 /// \brief Describes the result of template argument deduction. 4775 /// 4776 /// The TemplateDeductionResult enumeration describes the result of 4777 /// template argument deduction, as returned from 4778 /// DeduceTemplateArguments(). The separate TemplateDeductionInfo 4779 /// structure provides additional information about the results of 4780 /// template argument deduction, e.g., the deduced template argument 4781 /// list (if successful) or the specific template parameters or 4782 /// deduced arguments that were involved in the failure. 4783 enum TemplateDeductionResult { 4784 /// \brief Template argument deduction was successful. 4785 TDK_Success = 0, 4786 /// \brief Template argument deduction exceeded the maximum template 4787 /// instantiation depth (which has already been diagnosed). 4788 TDK_InstantiationDepth, 4789 /// \brief Template argument deduction did not deduce a value 4790 /// for every template parameter. 4791 TDK_Incomplete, 4792 /// \brief Template argument deduction produced inconsistent 4793 /// deduced values for the given template parameter. 4794 TDK_Inconsistent, 4795 /// \brief Template argument deduction failed due to inconsistent 4796 /// cv-qualifiers on a template parameter type that would 4797 /// otherwise be deduced, e.g., we tried to deduce T in "const T" 4798 /// but were given a non-const "X". 4799 TDK_Underqualified, 4800 /// \brief Substitution of the deduced template argument values 4801 /// resulted in an error. 4802 TDK_SubstitutionFailure, 4803 /// \brief Substitution of the deduced template argument values 4804 /// into a non-deduced context produced a type or value that 4805 /// produces a type that does not match the original template 4806 /// arguments provided. 4807 TDK_NonDeducedMismatch, 4808 /// \brief When performing template argument deduction for a function 4809 /// template, there were too many call arguments. 4810 TDK_TooManyArguments, 4811 /// \brief When performing template argument deduction for a function 4812 /// template, there were too few call arguments. 4813 TDK_TooFewArguments, 4814 /// \brief The explicitly-specified template arguments were not valid 4815 /// template arguments for the given template. 4816 TDK_InvalidExplicitArguments, 4817 /// \brief The arguments included an overloaded function name that could 4818 /// not be resolved to a suitable function. 4819 TDK_FailedOverloadResolution 4820 }; 4821 4822 TemplateDeductionResult 4823 DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial, 4824 const TemplateArgumentList &TemplateArgs, 4825 sema::TemplateDeductionInfo &Info); 4826 4827 TemplateDeductionResult 4828 SubstituteExplicitTemplateArguments(FunctionTemplateDecl *FunctionTemplate, 4829 TemplateArgumentListInfo &ExplicitTemplateArgs, 4830 SmallVectorImpl<DeducedTemplateArgument> &Deduced, 4831 SmallVectorImpl<QualType> &ParamTypes, 4832 QualType *FunctionType, 4833 sema::TemplateDeductionInfo &Info); 4834 4835 /// brief A function argument from which we performed template argument 4836 // deduction for a call. 4837 struct OriginalCallArg { 4838 OriginalCallArg(QualType OriginalParamType, 4839 unsigned ArgIdx, 4840 QualType OriginalArgType) 4841 : OriginalParamType(OriginalParamType), ArgIdx(ArgIdx), 4842 OriginalArgType(OriginalArgType) { } 4843 4844 QualType OriginalParamType; 4845 unsigned ArgIdx; 4846 QualType OriginalArgType; 4847 }; 4848 4849 TemplateDeductionResult 4850 FinishTemplateArgumentDeduction(FunctionTemplateDecl *FunctionTemplate, 4851 SmallVectorImpl<DeducedTemplateArgument> &Deduced, 4852 unsigned NumExplicitlySpecified, 4853 FunctionDecl *&Specialization, 4854 sema::TemplateDeductionInfo &Info, 4855 SmallVectorImpl<OriginalCallArg> const *OriginalCallArgs = 0); 4856 4857 TemplateDeductionResult 4858 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, 4859 TemplateArgumentListInfo *ExplicitTemplateArgs, 4860 llvm::ArrayRef<Expr *> Args, 4861 FunctionDecl *&Specialization, 4862 sema::TemplateDeductionInfo &Info); 4863 4864 TemplateDeductionResult 4865 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, 4866 TemplateArgumentListInfo *ExplicitTemplateArgs, 4867 QualType ArgFunctionType, 4868 FunctionDecl *&Specialization, 4869 sema::TemplateDeductionInfo &Info); 4870 4871 TemplateDeductionResult 4872 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, 4873 QualType ToType, 4874 CXXConversionDecl *&Specialization, 4875 sema::TemplateDeductionInfo &Info); 4876 4877 TemplateDeductionResult 4878 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, 4879 TemplateArgumentListInfo *ExplicitTemplateArgs, 4880 FunctionDecl *&Specialization, 4881 sema::TemplateDeductionInfo &Info); 4882 4883 /// \brief Result type of DeduceAutoType. 4884 enum DeduceAutoResult { 4885 DAR_Succeeded, 4886 DAR_Failed, 4887 DAR_FailedAlreadyDiagnosed 4888 }; 4889 4890 DeduceAutoResult DeduceAutoType(TypeSourceInfo *AutoType, Expr *&Initializer, 4891 TypeSourceInfo *&Result); 4892 void DiagnoseAutoDeductionFailure(VarDecl *VDecl, Expr *Init); 4893 4894 FunctionTemplateDecl *getMoreSpecializedTemplate(FunctionTemplateDecl *FT1, 4895 FunctionTemplateDecl *FT2, 4896 SourceLocation Loc, 4897 TemplatePartialOrderingContext TPOC, 4898 unsigned NumCallArguments); 4899 UnresolvedSetIterator getMostSpecialized(UnresolvedSetIterator SBegin, 4900 UnresolvedSetIterator SEnd, 4901 TemplatePartialOrderingContext TPOC, 4902 unsigned NumCallArguments, 4903 SourceLocation Loc, 4904 const PartialDiagnostic &NoneDiag, 4905 const PartialDiagnostic &AmbigDiag, 4906 const PartialDiagnostic &CandidateDiag, 4907 bool Complain = true, 4908 QualType TargetType = QualType()); 4909 4910 ClassTemplatePartialSpecializationDecl * 4911 getMoreSpecializedPartialSpecialization( 4912 ClassTemplatePartialSpecializationDecl *PS1, 4913 ClassTemplatePartialSpecializationDecl *PS2, 4914 SourceLocation Loc); 4915 4916 void MarkUsedTemplateParameters(const TemplateArgumentList &TemplateArgs, 4917 bool OnlyDeduced, 4918 unsigned Depth, 4919 llvm::SmallBitVector &Used); 4920 void MarkDeducedTemplateParameters(FunctionTemplateDecl *FunctionTemplate, 4921 llvm::SmallBitVector &Deduced) { 4922 return MarkDeducedTemplateParameters(Context, FunctionTemplate, Deduced); 4923 } 4924 static void MarkDeducedTemplateParameters(ASTContext &Ctx, 4925 FunctionTemplateDecl *FunctionTemplate, 4926 llvm::SmallBitVector &Deduced); 4927 4928 //===--------------------------------------------------------------------===// 4929 // C++ Template Instantiation 4930 // 4931 4932 MultiLevelTemplateArgumentList getTemplateInstantiationArgs(NamedDecl *D, 4933 const TemplateArgumentList *Innermost = 0, 4934 bool RelativeToPrimary = false, 4935 const FunctionDecl *Pattern = 0); 4936 4937 /// \brief A template instantiation that is currently in progress. 4938 struct ActiveTemplateInstantiation { 4939 /// \brief The kind of template instantiation we are performing 4940 enum InstantiationKind { 4941 /// We are instantiating a template declaration. The entity is 4942 /// the declaration we're instantiating (e.g., a CXXRecordDecl). 4943 TemplateInstantiation, 4944 4945 /// We are instantiating a default argument for a template 4946 /// parameter. The Entity is the template, and 4947 /// TemplateArgs/NumTemplateArguments provides the template 4948 /// arguments as specified. 4949 /// FIXME: Use a TemplateArgumentList 4950 DefaultTemplateArgumentInstantiation, 4951 4952 /// We are instantiating a default argument for a function. 4953 /// The Entity is the ParmVarDecl, and TemplateArgs/NumTemplateArgs 4954 /// provides the template arguments as specified. 4955 DefaultFunctionArgumentInstantiation, 4956 4957 /// We are substituting explicit template arguments provided for 4958 /// a function template. The entity is a FunctionTemplateDecl. 4959 ExplicitTemplateArgumentSubstitution, 4960 4961 /// We are substituting template argument determined as part of 4962 /// template argument deduction for either a class template 4963 /// partial specialization or a function template. The 4964 /// Entity is either a ClassTemplatePartialSpecializationDecl or 4965 /// a FunctionTemplateDecl. 4966 DeducedTemplateArgumentSubstitution, 4967 4968 /// We are substituting prior template arguments into a new 4969 /// template parameter. The template parameter itself is either a 4970 /// NonTypeTemplateParmDecl or a TemplateTemplateParmDecl. 4971 PriorTemplateArgumentSubstitution, 4972 4973 /// We are checking the validity of a default template argument that 4974 /// has been used when naming a template-id. 4975 DefaultTemplateArgumentChecking 4976 } Kind; 4977 4978 /// \brief The point of instantiation within the source code. 4979 SourceLocation PointOfInstantiation; 4980 4981 /// \brief The template (or partial specialization) in which we are 4982 /// performing the instantiation, for substitutions of prior template 4983 /// arguments. 4984 NamedDecl *Template; 4985 4986 /// \brief The entity that is being instantiated. 4987 uintptr_t Entity; 4988 4989 /// \brief The list of template arguments we are substituting, if they 4990 /// are not part of the entity. 4991 const TemplateArgument *TemplateArgs; 4992 4993 /// \brief The number of template arguments in TemplateArgs. 4994 unsigned NumTemplateArgs; 4995 4996 /// \brief The template deduction info object associated with the 4997 /// substitution or checking of explicit or deduced template arguments. 4998 sema::TemplateDeductionInfo *DeductionInfo; 4999 5000 /// \brief The source range that covers the construct that cause 5001 /// the instantiation, e.g., the template-id that causes a class 5002 /// template instantiation. 5003 SourceRange InstantiationRange; 5004 5005 ActiveTemplateInstantiation() 5006 : Kind(TemplateInstantiation), Template(0), Entity(0), TemplateArgs(0), 5007 NumTemplateArgs(0), DeductionInfo(0) {} 5008 5009 /// \brief Determines whether this template is an actual instantiation 5010 /// that should be counted toward the maximum instantiation depth. 5011 bool isInstantiationRecord() const; 5012 5013 friend bool operator==(const ActiveTemplateInstantiation &X, 5014 const ActiveTemplateInstantiation &Y) { 5015 if (X.Kind != Y.Kind) 5016 return false; 5017 5018 if (X.Entity != Y.Entity) 5019 return false; 5020 5021 switch (X.Kind) { 5022 case TemplateInstantiation: 5023 return true; 5024 5025 case PriorTemplateArgumentSubstitution: 5026 case DefaultTemplateArgumentChecking: 5027 if (X.Template != Y.Template) 5028 return false; 5029 5030 // Fall through 5031 5032 case DefaultTemplateArgumentInstantiation: 5033 case ExplicitTemplateArgumentSubstitution: 5034 case DeducedTemplateArgumentSubstitution: 5035 case DefaultFunctionArgumentInstantiation: 5036 return X.TemplateArgs == Y.TemplateArgs; 5037 5038 } 5039 5040 llvm_unreachable("Invalid InstantiationKind!"); 5041 } 5042 5043 friend bool operator!=(const ActiveTemplateInstantiation &X, 5044 const ActiveTemplateInstantiation &Y) { 5045 return !(X == Y); 5046 } 5047 }; 5048 5049 /// \brief List of active template instantiations. 5050 /// 5051 /// This vector is treated as a stack. As one template instantiation 5052 /// requires another template instantiation, additional 5053 /// instantiations are pushed onto the stack up to a 5054 /// user-configurable limit LangOptions::InstantiationDepth. 5055 SmallVector<ActiveTemplateInstantiation, 16> 5056 ActiveTemplateInstantiations; 5057 5058 /// \brief Whether we are in a SFINAE context that is not associated with 5059 /// template instantiation. 5060 /// 5061 /// This is used when setting up a SFINAE trap (\c see SFINAETrap) outside 5062 /// of a template instantiation or template argument deduction. 5063 bool InNonInstantiationSFINAEContext; 5064 5065 /// \brief The number of ActiveTemplateInstantiation entries in 5066 /// \c ActiveTemplateInstantiations that are not actual instantiations and, 5067 /// therefore, should not be counted as part of the instantiation depth. 5068 unsigned NonInstantiationEntries; 5069 5070 /// \brief The last template from which a template instantiation 5071 /// error or warning was produced. 5072 /// 5073 /// This value is used to suppress printing of redundant template 5074 /// instantiation backtraces when there are multiple errors in the 5075 /// same instantiation. FIXME: Does this belong in Sema? It's tough 5076 /// to implement it anywhere else. 5077 ActiveTemplateInstantiation LastTemplateInstantiationErrorContext; 5078 5079 /// \brief The current index into pack expansion arguments that will be 5080 /// used for substitution of parameter packs. 5081 /// 5082 /// The pack expansion index will be -1 to indicate that parameter packs 5083 /// should be instantiated as themselves. Otherwise, the index specifies 5084 /// which argument within the parameter pack will be used for substitution. 5085 int ArgumentPackSubstitutionIndex; 5086 5087 /// \brief RAII object used to change the argument pack substitution index 5088 /// within a \c Sema object. 5089 /// 5090 /// See \c ArgumentPackSubstitutionIndex for more information. 5091 class ArgumentPackSubstitutionIndexRAII { 5092 Sema &Self; 5093 int OldSubstitutionIndex; 5094 5095 public: 5096 ArgumentPackSubstitutionIndexRAII(Sema &Self, int NewSubstitutionIndex) 5097 : Self(Self), OldSubstitutionIndex(Self.ArgumentPackSubstitutionIndex) { 5098 Self.ArgumentPackSubstitutionIndex = NewSubstitutionIndex; 5099 } 5100 5101 ~ArgumentPackSubstitutionIndexRAII() { 5102 Self.ArgumentPackSubstitutionIndex = OldSubstitutionIndex; 5103 } 5104 }; 5105 5106 friend class ArgumentPackSubstitutionRAII; 5107 5108 /// \brief The stack of calls expression undergoing template instantiation. 5109 /// 5110 /// The top of this stack is used by a fixit instantiating unresolved 5111 /// function calls to fix the AST to match the textual change it prints. 5112 SmallVector<CallExpr *, 8> CallsUndergoingInstantiation; 5113 5114 /// \brief For each declaration that involved template argument deduction, the 5115 /// set of diagnostics that were suppressed during that template argument 5116 /// deduction. 5117 /// 5118 /// FIXME: Serialize this structure to the AST file. 5119 llvm::DenseMap<Decl *, SmallVector<PartialDiagnosticAt, 1> > 5120 SuppressedDiagnostics; 5121 5122 /// \brief A stack object to be created when performing template 5123 /// instantiation. 5124 /// 5125 /// Construction of an object of type \c InstantiatingTemplate 5126 /// pushes the current instantiation onto the stack of active 5127 /// instantiations. If the size of this stack exceeds the maximum 5128 /// number of recursive template instantiations, construction 5129 /// produces an error and evaluates true. 5130 /// 5131 /// Destruction of this object will pop the named instantiation off 5132 /// the stack. 5133 struct InstantiatingTemplate { 5134 /// \brief Note that we are instantiating a class template, 5135 /// function template, or a member thereof. 5136 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 5137 Decl *Entity, 5138 SourceRange InstantiationRange = SourceRange()); 5139 5140 /// \brief Note that we are instantiating a default argument in a 5141 /// template-id. 5142 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 5143 TemplateDecl *Template, 5144 const TemplateArgument *TemplateArgs, 5145 unsigned NumTemplateArgs, 5146 SourceRange InstantiationRange = SourceRange()); 5147 5148 /// \brief Note that we are instantiating a default argument in a 5149 /// template-id. 5150 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 5151 FunctionTemplateDecl *FunctionTemplate, 5152 const TemplateArgument *TemplateArgs, 5153 unsigned NumTemplateArgs, 5154 ActiveTemplateInstantiation::InstantiationKind Kind, 5155 sema::TemplateDeductionInfo &DeductionInfo, 5156 SourceRange InstantiationRange = SourceRange()); 5157 5158 /// \brief Note that we are instantiating as part of template 5159 /// argument deduction for a class template partial 5160 /// specialization. 5161 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 5162 ClassTemplatePartialSpecializationDecl *PartialSpec, 5163 const TemplateArgument *TemplateArgs, 5164 unsigned NumTemplateArgs, 5165 sema::TemplateDeductionInfo &DeductionInfo, 5166 SourceRange InstantiationRange = SourceRange()); 5167 5168 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 5169 ParmVarDecl *Param, 5170 const TemplateArgument *TemplateArgs, 5171 unsigned NumTemplateArgs, 5172 SourceRange InstantiationRange = SourceRange()); 5173 5174 /// \brief Note that we are substituting prior template arguments into a 5175 /// non-type or template template parameter. 5176 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 5177 NamedDecl *Template, 5178 NonTypeTemplateParmDecl *Param, 5179 const TemplateArgument *TemplateArgs, 5180 unsigned NumTemplateArgs, 5181 SourceRange InstantiationRange); 5182 5183 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 5184 NamedDecl *Template, 5185 TemplateTemplateParmDecl *Param, 5186 const TemplateArgument *TemplateArgs, 5187 unsigned NumTemplateArgs, 5188 SourceRange InstantiationRange); 5189 5190 /// \brief Note that we are checking the default template argument 5191 /// against the template parameter for a given template-id. 5192 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 5193 TemplateDecl *Template, 5194 NamedDecl *Param, 5195 const TemplateArgument *TemplateArgs, 5196 unsigned NumTemplateArgs, 5197 SourceRange InstantiationRange); 5198 5199 5200 /// \brief Note that we have finished instantiating this template. 5201 void Clear(); 5202 5203 ~InstantiatingTemplate() { Clear(); } 5204 5205 /// \brief Determines whether we have exceeded the maximum 5206 /// recursive template instantiations. 5207 operator bool() const { return Invalid; } 5208 5209 private: 5210 Sema &SemaRef; 5211 bool Invalid; 5212 bool SavedInNonInstantiationSFINAEContext; 5213 bool CheckInstantiationDepth(SourceLocation PointOfInstantiation, 5214 SourceRange InstantiationRange); 5215 5216 InstantiatingTemplate(const InstantiatingTemplate&); // not implemented 5217 5218 InstantiatingTemplate& 5219 operator=(const InstantiatingTemplate&); // not implemented 5220 }; 5221 5222 void PrintInstantiationStack(); 5223 5224 /// \brief Determines whether we are currently in a context where 5225 /// template argument substitution failures are not considered 5226 /// errors. 5227 /// 5228 /// \returns An empty \c llvm::Optional if we're not in a SFINAE context. 5229 /// Otherwise, contains a pointer that, if non-NULL, contains the nearest 5230 /// template-deduction context object, which can be used to capture 5231 /// diagnostics that will be suppressed. 5232 llvm::Optional<sema::TemplateDeductionInfo *> isSFINAEContext() const; 5233 5234 /// \brief RAII class used to determine whether SFINAE has 5235 /// trapped any errors that occur during template argument 5236 /// deduction.` 5237 class SFINAETrap { 5238 Sema &SemaRef; 5239 unsigned PrevSFINAEErrors; 5240 bool PrevInNonInstantiationSFINAEContext; 5241 bool PrevAccessCheckingSFINAE; 5242 5243 public: 5244 explicit SFINAETrap(Sema &SemaRef, bool AccessCheckingSFINAE = false) 5245 : SemaRef(SemaRef), PrevSFINAEErrors(SemaRef.NumSFINAEErrors), 5246 PrevInNonInstantiationSFINAEContext( 5247 SemaRef.InNonInstantiationSFINAEContext), 5248 PrevAccessCheckingSFINAE(SemaRef.AccessCheckingSFINAE) 5249 { 5250 if (!SemaRef.isSFINAEContext()) 5251 SemaRef.InNonInstantiationSFINAEContext = true; 5252 SemaRef.AccessCheckingSFINAE = AccessCheckingSFINAE; 5253 } 5254 5255 ~SFINAETrap() { 5256 SemaRef.NumSFINAEErrors = PrevSFINAEErrors; 5257 SemaRef.InNonInstantiationSFINAEContext 5258 = PrevInNonInstantiationSFINAEContext; 5259 SemaRef.AccessCheckingSFINAE = PrevAccessCheckingSFINAE; 5260 } 5261 5262 /// \brief Determine whether any SFINAE errors have been trapped. 5263 bool hasErrorOccurred() const { 5264 return SemaRef.NumSFINAEErrors > PrevSFINAEErrors; 5265 } 5266 }; 5267 5268 /// \brief The current instantiation scope used to store local 5269 /// variables. 5270 LocalInstantiationScope *CurrentInstantiationScope; 5271 5272 /// \brief The number of typos corrected by CorrectTypo. 5273 unsigned TyposCorrected; 5274 5275 typedef llvm::DenseMap<IdentifierInfo *, TypoCorrection> 5276 UnqualifiedTyposCorrectedMap; 5277 5278 /// \brief A cache containing the results of typo correction for unqualified 5279 /// name lookup. 5280 /// 5281 /// The string is the string that we corrected to (which may be empty, if 5282 /// there was no correction), while the boolean will be true when the 5283 /// string represents a keyword. 5284 UnqualifiedTyposCorrectedMap UnqualifiedTyposCorrected; 5285 5286 /// \brief Worker object for performing CFG-based warnings. 5287 sema::AnalysisBasedWarnings AnalysisWarnings; 5288 5289 /// \brief An entity for which implicit template instantiation is required. 5290 /// 5291 /// The source location associated with the declaration is the first place in 5292 /// the source code where the declaration was "used". It is not necessarily 5293 /// the point of instantiation (which will be either before or after the 5294 /// namespace-scope declaration that triggered this implicit instantiation), 5295 /// However, it is the location that diagnostics should generally refer to, 5296 /// because users will need to know what code triggered the instantiation. 5297 typedef std::pair<ValueDecl *, SourceLocation> PendingImplicitInstantiation; 5298 5299 /// \brief The queue of implicit template instantiations that are required 5300 /// but have not yet been performed. 5301 std::deque<PendingImplicitInstantiation> PendingInstantiations; 5302 5303 /// \brief The queue of implicit template instantiations that are required 5304 /// and must be performed within the current local scope. 5305 /// 5306 /// This queue is only used for member functions of local classes in 5307 /// templates, which must be instantiated in the same scope as their 5308 /// enclosing function, so that they can reference function-local 5309 /// types, static variables, enumerators, etc. 5310 std::deque<PendingImplicitInstantiation> PendingLocalImplicitInstantiations; 5311 5312 void PerformPendingInstantiations(bool LocalOnly = false); 5313 5314 TypeSourceInfo *SubstType(TypeSourceInfo *T, 5315 const MultiLevelTemplateArgumentList &TemplateArgs, 5316 SourceLocation Loc, DeclarationName Entity); 5317 5318 QualType SubstType(QualType T, 5319 const MultiLevelTemplateArgumentList &TemplateArgs, 5320 SourceLocation Loc, DeclarationName Entity); 5321 5322 TypeSourceInfo *SubstType(TypeLoc TL, 5323 const MultiLevelTemplateArgumentList &TemplateArgs, 5324 SourceLocation Loc, DeclarationName Entity); 5325 5326 TypeSourceInfo *SubstFunctionDeclType(TypeSourceInfo *T, 5327 const MultiLevelTemplateArgumentList &TemplateArgs, 5328 SourceLocation Loc, 5329 DeclarationName Entity); 5330 ParmVarDecl *SubstParmVarDecl(ParmVarDecl *D, 5331 const MultiLevelTemplateArgumentList &TemplateArgs, 5332 int indexAdjustment, 5333 llvm::Optional<unsigned> NumExpansions, 5334 bool ExpectParameterPack); 5335 bool SubstParmTypes(SourceLocation Loc, 5336 ParmVarDecl **Params, unsigned NumParams, 5337 const MultiLevelTemplateArgumentList &TemplateArgs, 5338 SmallVectorImpl<QualType> &ParamTypes, 5339 SmallVectorImpl<ParmVarDecl *> *OutParams = 0); 5340 ExprResult SubstExpr(Expr *E, 5341 const MultiLevelTemplateArgumentList &TemplateArgs); 5342 5343 /// \brief Substitute the given template arguments into a list of 5344 /// expressions, expanding pack expansions if required. 5345 /// 5346 /// \param Exprs The list of expressions to substitute into. 5347 /// 5348 /// \param NumExprs The number of expressions in \p Exprs. 5349 /// 5350 /// \param IsCall Whether this is some form of call, in which case 5351 /// default arguments will be dropped. 5352 /// 5353 /// \param TemplateArgs The set of template arguments to substitute. 5354 /// 5355 /// \param Outputs Will receive all of the substituted arguments. 5356 /// 5357 /// \returns true if an error occurred, false otherwise. 5358 bool SubstExprs(Expr **Exprs, unsigned NumExprs, bool IsCall, 5359 const MultiLevelTemplateArgumentList &TemplateArgs, 5360 SmallVectorImpl<Expr *> &Outputs); 5361 5362 StmtResult SubstStmt(Stmt *S, 5363 const MultiLevelTemplateArgumentList &TemplateArgs); 5364 5365 Decl *SubstDecl(Decl *D, DeclContext *Owner, 5366 const MultiLevelTemplateArgumentList &TemplateArgs); 5367 5368 ExprResult SubstInitializer(Expr *E, 5369 const MultiLevelTemplateArgumentList &TemplateArgs, 5370 bool CXXDirectInit); 5371 5372 bool 5373 SubstBaseSpecifiers(CXXRecordDecl *Instantiation, 5374 CXXRecordDecl *Pattern, 5375 const MultiLevelTemplateArgumentList &TemplateArgs); 5376 5377 bool 5378 InstantiateClass(SourceLocation PointOfInstantiation, 5379 CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern, 5380 const MultiLevelTemplateArgumentList &TemplateArgs, 5381 TemplateSpecializationKind TSK, 5382 bool Complain = true); 5383 5384 struct LateInstantiatedAttribute { 5385 const Attr *TmplAttr; 5386 LocalInstantiationScope *Scope; 5387 Decl *NewDecl; 5388 5389 LateInstantiatedAttribute(const Attr *A, LocalInstantiationScope *S, 5390 Decl *D) 5391 : TmplAttr(A), Scope(S), NewDecl(D) 5392 { } 5393 }; 5394 typedef SmallVector<LateInstantiatedAttribute, 16> LateInstantiatedAttrVec; 5395 5396 void InstantiateAttrs(const MultiLevelTemplateArgumentList &TemplateArgs, 5397 const Decl *Pattern, Decl *Inst, 5398 LateInstantiatedAttrVec *LateAttrs = 0, 5399 LocalInstantiationScope *OuterMostScope = 0); 5400 5401 bool 5402 InstantiateClassTemplateSpecialization(SourceLocation PointOfInstantiation, 5403 ClassTemplateSpecializationDecl *ClassTemplateSpec, 5404 TemplateSpecializationKind TSK, 5405 bool Complain = true); 5406 5407 void InstantiateClassMembers(SourceLocation PointOfInstantiation, 5408 CXXRecordDecl *Instantiation, 5409 const MultiLevelTemplateArgumentList &TemplateArgs, 5410 TemplateSpecializationKind TSK); 5411 5412 void InstantiateClassTemplateSpecializationMembers( 5413 SourceLocation PointOfInstantiation, 5414 ClassTemplateSpecializationDecl *ClassTemplateSpec, 5415 TemplateSpecializationKind TSK); 5416 5417 NestedNameSpecifierLoc 5418 SubstNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, 5419 const MultiLevelTemplateArgumentList &TemplateArgs); 5420 5421 DeclarationNameInfo 5422 SubstDeclarationNameInfo(const DeclarationNameInfo &NameInfo, 5423 const MultiLevelTemplateArgumentList &TemplateArgs); 5424 TemplateName 5425 SubstTemplateName(NestedNameSpecifierLoc QualifierLoc, TemplateName Name, 5426 SourceLocation Loc, 5427 const MultiLevelTemplateArgumentList &TemplateArgs); 5428 bool Subst(const TemplateArgumentLoc *Args, unsigned NumArgs, 5429 TemplateArgumentListInfo &Result, 5430 const MultiLevelTemplateArgumentList &TemplateArgs); 5431 5432 void InstantiateFunctionDefinition(SourceLocation PointOfInstantiation, 5433 FunctionDecl *Function, 5434 bool Recursive = false, 5435 bool DefinitionRequired = false); 5436 void InstantiateStaticDataMemberDefinition( 5437 SourceLocation PointOfInstantiation, 5438 VarDecl *Var, 5439 bool Recursive = false, 5440 bool DefinitionRequired = false); 5441 5442 void InstantiateMemInitializers(CXXConstructorDecl *New, 5443 const CXXConstructorDecl *Tmpl, 5444 const MultiLevelTemplateArgumentList &TemplateArgs); 5445 5446 NamedDecl *FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D, 5447 const MultiLevelTemplateArgumentList &TemplateArgs); 5448 DeclContext *FindInstantiatedContext(SourceLocation Loc, DeclContext *DC, 5449 const MultiLevelTemplateArgumentList &TemplateArgs); 5450 5451 // Objective-C declarations. 5452 enum ObjCContainerKind { 5453 OCK_None = -1, 5454 OCK_Interface = 0, 5455 OCK_Protocol, 5456 OCK_Category, 5457 OCK_ClassExtension, 5458 OCK_Implementation, 5459 OCK_CategoryImplementation 5460 }; 5461 ObjCContainerKind getObjCContainerKind() const; 5462 5463 Decl *ActOnStartClassInterface(SourceLocation AtInterfaceLoc, 5464 IdentifierInfo *ClassName, 5465 SourceLocation ClassLoc, 5466 IdentifierInfo *SuperName, 5467 SourceLocation SuperLoc, 5468 Decl * const *ProtoRefs, 5469 unsigned NumProtoRefs, 5470 const SourceLocation *ProtoLocs, 5471 SourceLocation EndProtoLoc, 5472 AttributeList *AttrList); 5473 5474 Decl *ActOnCompatiblityAlias( 5475 SourceLocation AtCompatibilityAliasLoc, 5476 IdentifierInfo *AliasName, SourceLocation AliasLocation, 5477 IdentifierInfo *ClassName, SourceLocation ClassLocation); 5478 5479 bool CheckForwardProtocolDeclarationForCircularDependency( 5480 IdentifierInfo *PName, 5481 SourceLocation &PLoc, SourceLocation PrevLoc, 5482 const ObjCList<ObjCProtocolDecl> &PList); 5483 5484 Decl *ActOnStartProtocolInterface( 5485 SourceLocation AtProtoInterfaceLoc, 5486 IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc, 5487 Decl * const *ProtoRefNames, unsigned NumProtoRefs, 5488 const SourceLocation *ProtoLocs, 5489 SourceLocation EndProtoLoc, 5490 AttributeList *AttrList); 5491 5492 Decl *ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc, 5493 IdentifierInfo *ClassName, 5494 SourceLocation ClassLoc, 5495 IdentifierInfo *CategoryName, 5496 SourceLocation CategoryLoc, 5497 Decl * const *ProtoRefs, 5498 unsigned NumProtoRefs, 5499 const SourceLocation *ProtoLocs, 5500 SourceLocation EndProtoLoc); 5501 5502 Decl *ActOnStartClassImplementation( 5503 SourceLocation AtClassImplLoc, 5504 IdentifierInfo *ClassName, SourceLocation ClassLoc, 5505 IdentifierInfo *SuperClassname, 5506 SourceLocation SuperClassLoc); 5507 5508 Decl *ActOnStartCategoryImplementation(SourceLocation AtCatImplLoc, 5509 IdentifierInfo *ClassName, 5510 SourceLocation ClassLoc, 5511 IdentifierInfo *CatName, 5512 SourceLocation CatLoc); 5513 5514 DeclGroupPtrTy ActOnFinishObjCImplementation(Decl *ObjCImpDecl, 5515 ArrayRef<Decl *> Decls); 5516 5517 DeclGroupPtrTy ActOnForwardClassDeclaration(SourceLocation Loc, 5518 IdentifierInfo **IdentList, 5519 SourceLocation *IdentLocs, 5520 unsigned NumElts); 5521 5522 DeclGroupPtrTy ActOnForwardProtocolDeclaration(SourceLocation AtProtoclLoc, 5523 const IdentifierLocPair *IdentList, 5524 unsigned NumElts, 5525 AttributeList *attrList); 5526 5527 void FindProtocolDeclaration(bool WarnOnDeclarations, 5528 const IdentifierLocPair *ProtocolId, 5529 unsigned NumProtocols, 5530 SmallVectorImpl<Decl *> &Protocols); 5531 5532 /// Ensure attributes are consistent with type. 5533 /// \param [in, out] Attributes The attributes to check; they will 5534 /// be modified to be consistent with \arg PropertyTy. 5535 void CheckObjCPropertyAttributes(Decl *PropertyPtrTy, 5536 SourceLocation Loc, 5537 unsigned &Attributes); 5538 5539 /// Process the specified property declaration and create decls for the 5540 /// setters and getters as needed. 5541 /// \param property The property declaration being processed 5542 /// \param DC The semantic container for the property 5543 /// \param redeclaredProperty Declaration for property if redeclared 5544 /// in class extension. 5545 /// \param lexicalDC Container for redeclaredProperty. 5546 void ProcessPropertyDecl(ObjCPropertyDecl *property, 5547 ObjCContainerDecl *DC, 5548 ObjCPropertyDecl *redeclaredProperty = 0, 5549 ObjCContainerDecl *lexicalDC = 0); 5550 5551 void DiagnosePropertyMismatch(ObjCPropertyDecl *Property, 5552 ObjCPropertyDecl *SuperProperty, 5553 const IdentifierInfo *Name); 5554 void ComparePropertiesInBaseAndSuper(ObjCInterfaceDecl *IDecl); 5555 5556 void CompareMethodParamsInBaseAndSuper(Decl *IDecl, 5557 ObjCMethodDecl *MethodDecl, 5558 bool IsInstance); 5559 5560 void CompareProperties(Decl *CDecl, Decl *MergeProtocols); 5561 5562 void DiagnoseClassExtensionDupMethods(ObjCCategoryDecl *CAT, 5563 ObjCInterfaceDecl *ID); 5564 5565 void MatchOneProtocolPropertiesInClass(Decl *CDecl, 5566 ObjCProtocolDecl *PDecl); 5567 5568 Decl *ActOnAtEnd(Scope *S, SourceRange AtEnd, 5569 Decl **allMethods = 0, unsigned allNum = 0, 5570 Decl **allProperties = 0, unsigned pNum = 0, 5571 DeclGroupPtrTy *allTUVars = 0, unsigned tuvNum = 0); 5572 5573 Decl *ActOnProperty(Scope *S, SourceLocation AtLoc, 5574 SourceLocation LParenLoc, 5575 FieldDeclarator &FD, ObjCDeclSpec &ODS, 5576 Selector GetterSel, Selector SetterSel, 5577 bool *OverridingProperty, 5578 tok::ObjCKeywordKind MethodImplKind, 5579 DeclContext *lexicalDC = 0); 5580 5581 Decl *ActOnPropertyImplDecl(Scope *S, 5582 SourceLocation AtLoc, 5583 SourceLocation PropertyLoc, 5584 bool ImplKind, 5585 IdentifierInfo *PropertyId, 5586 IdentifierInfo *PropertyIvar, 5587 SourceLocation PropertyIvarLoc); 5588 5589 enum ObjCSpecialMethodKind { 5590 OSMK_None, 5591 OSMK_Alloc, 5592 OSMK_New, 5593 OSMK_Copy, 5594 OSMK_RetainingInit, 5595 OSMK_NonRetainingInit 5596 }; 5597 5598 struct ObjCArgInfo { 5599 IdentifierInfo *Name; 5600 SourceLocation NameLoc; 5601 // The Type is null if no type was specified, and the DeclSpec is invalid 5602 // in this case. 5603 ParsedType Type; 5604 ObjCDeclSpec DeclSpec; 5605 5606 /// ArgAttrs - Attribute list for this argument. 5607 AttributeList *ArgAttrs; 5608 }; 5609 5610 Decl *ActOnMethodDeclaration( 5611 Scope *S, 5612 SourceLocation BeginLoc, // location of the + or -. 5613 SourceLocation EndLoc, // location of the ; or {. 5614 tok::TokenKind MethodType, 5615 ObjCDeclSpec &ReturnQT, ParsedType ReturnType, 5616 ArrayRef<SourceLocation> SelectorLocs, Selector Sel, 5617 // optional arguments. The number of types/arguments is obtained 5618 // from the Sel.getNumArgs(). 5619 ObjCArgInfo *ArgInfo, 5620 DeclaratorChunk::ParamInfo *CParamInfo, unsigned CNumArgs, // c-style args 5621 AttributeList *AttrList, tok::ObjCKeywordKind MethodImplKind, 5622 bool isVariadic, bool MethodDefinition); 5623 5624 // Helper method for ActOnClassMethod/ActOnInstanceMethod. 5625 // Will search "local" class/category implementations for a method decl. 5626 // Will also search in class's root looking for instance method. 5627 // Returns 0 if no method is found. 5628 ObjCMethodDecl *LookupPrivateClassMethod(Selector Sel, 5629 ObjCInterfaceDecl *CDecl); 5630 ObjCMethodDecl *LookupPrivateInstanceMethod(Selector Sel, 5631 ObjCInterfaceDecl *ClassDecl); 5632 ObjCMethodDecl *LookupMethodInQualifiedType(Selector Sel, 5633 const ObjCObjectPointerType *OPT, 5634 bool IsInstance); 5635 ObjCMethodDecl *LookupMethodInObjectType(Selector Sel, QualType Ty, 5636 bool IsInstance); 5637 5638 bool inferObjCARCLifetime(ValueDecl *decl); 5639 5640 ExprResult 5641 HandleExprPropertyRefExpr(const ObjCObjectPointerType *OPT, 5642 Expr *BaseExpr, 5643 SourceLocation OpLoc, 5644 DeclarationName MemberName, 5645 SourceLocation MemberLoc, 5646 SourceLocation SuperLoc, QualType SuperType, 5647 bool Super); 5648 5649 ExprResult 5650 ActOnClassPropertyRefExpr(IdentifierInfo &receiverName, 5651 IdentifierInfo &propertyName, 5652 SourceLocation receiverNameLoc, 5653 SourceLocation propertyNameLoc); 5654 5655 ObjCMethodDecl *tryCaptureObjCSelf(SourceLocation Loc); 5656 5657 /// \brief Describes the kind of message expression indicated by a message 5658 /// send that starts with an identifier. 5659 enum ObjCMessageKind { 5660 /// \brief The message is sent to 'super'. 5661 ObjCSuperMessage, 5662 /// \brief The message is an instance message. 5663 ObjCInstanceMessage, 5664 /// \brief The message is a class message, and the identifier is a type 5665 /// name. 5666 ObjCClassMessage 5667 }; 5668 5669 ObjCMessageKind getObjCMessageKind(Scope *S, 5670 IdentifierInfo *Name, 5671 SourceLocation NameLoc, 5672 bool IsSuper, 5673 bool HasTrailingDot, 5674 ParsedType &ReceiverType); 5675 5676 ExprResult ActOnSuperMessage(Scope *S, SourceLocation SuperLoc, 5677 Selector Sel, 5678 SourceLocation LBracLoc, 5679 ArrayRef<SourceLocation> SelectorLocs, 5680 SourceLocation RBracLoc, 5681 MultiExprArg Args); 5682 5683 ExprResult BuildClassMessage(TypeSourceInfo *ReceiverTypeInfo, 5684 QualType ReceiverType, 5685 SourceLocation SuperLoc, 5686 Selector Sel, 5687 ObjCMethodDecl *Method, 5688 SourceLocation LBracLoc, 5689 ArrayRef<SourceLocation> SelectorLocs, 5690 SourceLocation RBracLoc, 5691 MultiExprArg Args, 5692 bool isImplicit = false); 5693 5694 ExprResult BuildClassMessageImplicit(QualType ReceiverType, 5695 bool isSuperReceiver, 5696 SourceLocation Loc, 5697 Selector Sel, 5698 ObjCMethodDecl *Method, 5699 MultiExprArg Args); 5700 5701 ExprResult ActOnClassMessage(Scope *S, 5702 ParsedType Receiver, 5703 Selector Sel, 5704 SourceLocation LBracLoc, 5705 ArrayRef<SourceLocation> SelectorLocs, 5706 SourceLocation RBracLoc, 5707 MultiExprArg Args); 5708 5709 ExprResult BuildInstanceMessage(Expr *Receiver, 5710 QualType ReceiverType, 5711 SourceLocation SuperLoc, 5712 Selector Sel, 5713 ObjCMethodDecl *Method, 5714 SourceLocation LBracLoc, 5715 ArrayRef<SourceLocation> SelectorLocs, 5716 SourceLocation RBracLoc, 5717 MultiExprArg Args, 5718 bool isImplicit = false); 5719 5720 ExprResult BuildInstanceMessageImplicit(Expr *Receiver, 5721 QualType ReceiverType, 5722 SourceLocation Loc, 5723 Selector Sel, 5724 ObjCMethodDecl *Method, 5725 MultiExprArg Args); 5726 5727 ExprResult ActOnInstanceMessage(Scope *S, 5728 Expr *Receiver, 5729 Selector Sel, 5730 SourceLocation LBracLoc, 5731 ArrayRef<SourceLocation> SelectorLocs, 5732 SourceLocation RBracLoc, 5733 MultiExprArg Args); 5734 5735 ExprResult BuildObjCBridgedCast(SourceLocation LParenLoc, 5736 ObjCBridgeCastKind Kind, 5737 SourceLocation BridgeKeywordLoc, 5738 TypeSourceInfo *TSInfo, 5739 Expr *SubExpr); 5740 5741 ExprResult ActOnObjCBridgedCast(Scope *S, 5742 SourceLocation LParenLoc, 5743 ObjCBridgeCastKind Kind, 5744 SourceLocation BridgeKeywordLoc, 5745 ParsedType Type, 5746 SourceLocation RParenLoc, 5747 Expr *SubExpr); 5748 5749 bool checkInitMethod(ObjCMethodDecl *method, QualType receiverTypeIfCall); 5750 5751 /// \brief Check whether the given new method is a valid override of the 5752 /// given overridden method, and set any properties that should be inherited. 5753 void CheckObjCMethodOverride(ObjCMethodDecl *NewMethod, 5754 const ObjCMethodDecl *Overridden, 5755 bool IsImplementation); 5756 5757 /// \brief Check whether the given method overrides any methods in its class, 5758 /// calling \c CheckObjCMethodOverride for each overridden method. 5759 bool CheckObjCMethodOverrides(ObjCMethodDecl *NewMethod, DeclContext *DC); 5760 5761 enum PragmaOptionsAlignKind { 5762 POAK_Native, // #pragma options align=native 5763 POAK_Natural, // #pragma options align=natural 5764 POAK_Packed, // #pragma options align=packed 5765 POAK_Power, // #pragma options align=power 5766 POAK_Mac68k, // #pragma options align=mac68k 5767 POAK_Reset // #pragma options align=reset 5768 }; 5769 5770 /// ActOnPragmaOptionsAlign - Called on well formed #pragma options align. 5771 void ActOnPragmaOptionsAlign(PragmaOptionsAlignKind Kind, 5772 SourceLocation PragmaLoc, 5773 SourceLocation KindLoc); 5774 5775 enum PragmaPackKind { 5776 PPK_Default, // #pragma pack([n]) 5777 PPK_Show, // #pragma pack(show), only supported by MSVC. 5778 PPK_Push, // #pragma pack(push, [identifier], [n]) 5779 PPK_Pop // #pragma pack(pop, [identifier], [n]) 5780 }; 5781 5782 enum PragmaMSStructKind { 5783 PMSST_OFF, // #pragms ms_struct off 5784 PMSST_ON // #pragms ms_struct on 5785 }; 5786 5787 /// ActOnPragmaPack - Called on well formed #pragma pack(...). 5788 void ActOnPragmaPack(PragmaPackKind Kind, 5789 IdentifierInfo *Name, 5790 Expr *Alignment, 5791 SourceLocation PragmaLoc, 5792 SourceLocation LParenLoc, 5793 SourceLocation RParenLoc); 5794 5795 /// ActOnPragmaMSStruct - Called on well formed #pragms ms_struct [on|off]. 5796 void ActOnPragmaMSStruct(PragmaMSStructKind Kind); 5797 5798 /// ActOnPragmaUnused - Called on well-formed '#pragma unused'. 5799 void ActOnPragmaUnused(const Token &Identifier, 5800 Scope *curScope, 5801 SourceLocation PragmaLoc); 5802 5803 /// ActOnPragmaVisibility - Called on well formed #pragma GCC visibility... . 5804 void ActOnPragmaVisibility(const IdentifierInfo* VisType, 5805 SourceLocation PragmaLoc); 5806 5807 NamedDecl *DeclClonePragmaWeak(NamedDecl *ND, IdentifierInfo *II, 5808 SourceLocation Loc); 5809 void DeclApplyPragmaWeak(Scope *S, NamedDecl *ND, WeakInfo &W); 5810 5811 /// ActOnPragmaWeakID - Called on well formed #pragma weak ident. 5812 void ActOnPragmaWeakID(IdentifierInfo* WeakName, 5813 SourceLocation PragmaLoc, 5814 SourceLocation WeakNameLoc); 5815 5816 /// ActOnPragmaRedefineExtname - Called on well formed 5817 /// #pragma redefine_extname oldname newname. 5818 void ActOnPragmaRedefineExtname(IdentifierInfo* WeakName, 5819 IdentifierInfo* AliasName, 5820 SourceLocation PragmaLoc, 5821 SourceLocation WeakNameLoc, 5822 SourceLocation AliasNameLoc); 5823 5824 /// ActOnPragmaWeakAlias - Called on well formed #pragma weak ident = ident. 5825 void ActOnPragmaWeakAlias(IdentifierInfo* WeakName, 5826 IdentifierInfo* AliasName, 5827 SourceLocation PragmaLoc, 5828 SourceLocation WeakNameLoc, 5829 SourceLocation AliasNameLoc); 5830 5831 /// ActOnPragmaFPContract - Called on well formed 5832 /// #pragma {STDC,OPENCL} FP_CONTRACT 5833 void ActOnPragmaFPContract(tok::OnOffSwitch OOS); 5834 5835 /// AddAlignmentAttributesForRecord - Adds any needed alignment attributes to 5836 /// a the record decl, to handle '#pragma pack' and '#pragma options align'. 5837 void AddAlignmentAttributesForRecord(RecordDecl *RD); 5838 5839 /// AddMsStructLayoutForRecord - Adds ms_struct layout attribute to record. 5840 void AddMsStructLayoutForRecord(RecordDecl *RD); 5841 5842 /// FreePackedContext - Deallocate and null out PackContext. 5843 void FreePackedContext(); 5844 5845 /// PushNamespaceVisibilityAttr - Note that we've entered a 5846 /// namespace with a visibility attribute. 5847 void PushNamespaceVisibilityAttr(const VisibilityAttr *Attr, 5848 SourceLocation Loc); 5849 5850 /// AddPushedVisibilityAttribute - If '#pragma GCC visibility' was used, 5851 /// add an appropriate visibility attribute. 5852 void AddPushedVisibilityAttribute(Decl *RD); 5853 5854 /// PopPragmaVisibility - Pop the top element of the visibility stack; used 5855 /// for '#pragma GCC visibility' and visibility attributes on namespaces. 5856 void PopPragmaVisibility(bool IsNamespaceEnd, SourceLocation EndLoc); 5857 5858 /// FreeVisContext - Deallocate and null out VisContext. 5859 void FreeVisContext(); 5860 5861 /// AddCFAuditedAttribute - Check whether we're currently within 5862 /// '#pragma clang arc_cf_code_audited' and, if so, consider adding 5863 /// the appropriate attribute. 5864 void AddCFAuditedAttribute(Decl *D); 5865 5866 /// AddAlignedAttr - Adds an aligned attribute to a particular declaration. 5867 void AddAlignedAttr(SourceRange AttrRange, Decl *D, Expr *E); 5868 void AddAlignedAttr(SourceRange AttrRange, Decl *D, TypeSourceInfo *T); 5869 5870 /// \brief The kind of conversion being performed. 5871 enum CheckedConversionKind { 5872 /// \brief An implicit conversion. 5873 CCK_ImplicitConversion, 5874 /// \brief A C-style cast. 5875 CCK_CStyleCast, 5876 /// \brief A functional-style cast. 5877 CCK_FunctionalCast, 5878 /// \brief A cast other than a C-style cast. 5879 CCK_OtherCast 5880 }; 5881 5882 /// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit 5883 /// cast. If there is already an implicit cast, merge into the existing one. 5884 /// If isLvalue, the result of the cast is an lvalue. 5885 ExprResult ImpCastExprToType(Expr *E, QualType Type, CastKind CK, 5886 ExprValueKind VK = VK_RValue, 5887 const CXXCastPath *BasePath = 0, 5888 CheckedConversionKind CCK 5889 = CCK_ImplicitConversion); 5890 5891 /// ScalarTypeToBooleanCastKind - Returns the cast kind corresponding 5892 /// to the conversion from scalar type ScalarTy to the Boolean type. 5893 static CastKind ScalarTypeToBooleanCastKind(QualType ScalarTy); 5894 5895 /// IgnoredValueConversions - Given that an expression's result is 5896 /// syntactically ignored, perform any conversions that are 5897 /// required. 5898 ExprResult IgnoredValueConversions(Expr *E); 5899 5900 // UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts 5901 // functions and arrays to their respective pointers (C99 6.3.2.1). 5902 ExprResult UsualUnaryConversions(Expr *E); 5903 5904 // DefaultFunctionArrayConversion - converts functions and arrays 5905 // to their respective pointers (C99 6.3.2.1). 5906 ExprResult DefaultFunctionArrayConversion(Expr *E); 5907 5908 // DefaultFunctionArrayLvalueConversion - converts functions and 5909 // arrays to their respective pointers and performs the 5910 // lvalue-to-rvalue conversion. 5911 ExprResult DefaultFunctionArrayLvalueConversion(Expr *E); 5912 5913 // DefaultLvalueConversion - performs lvalue-to-rvalue conversion on 5914 // the operand. This is DefaultFunctionArrayLvalueConversion, 5915 // except that it assumes the operand isn't of function or array 5916 // type. 5917 ExprResult DefaultLvalueConversion(Expr *E); 5918 5919 // DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that 5920 // do not have a prototype. Integer promotions are performed on each 5921 // argument, and arguments that have type float are promoted to double. 5922 ExprResult DefaultArgumentPromotion(Expr *E); 5923 5924 // Used for emitting the right warning by DefaultVariadicArgumentPromotion 5925 enum VariadicCallType { 5926 VariadicFunction, 5927 VariadicBlock, 5928 VariadicMethod, 5929 VariadicConstructor, 5930 VariadicDoesNotApply 5931 }; 5932 5933 /// GatherArgumentsForCall - Collector argument expressions for various 5934 /// form of call prototypes. 5935 bool GatherArgumentsForCall(SourceLocation CallLoc, 5936 FunctionDecl *FDecl, 5937 const FunctionProtoType *Proto, 5938 unsigned FirstProtoArg, 5939 Expr **Args, unsigned NumArgs, 5940 SmallVector<Expr *, 8> &AllArgs, 5941 VariadicCallType CallType = VariadicDoesNotApply, 5942 bool AllowExplicit = false); 5943 5944 // DefaultVariadicArgumentPromotion - Like DefaultArgumentPromotion, but 5945 // will warn if the resulting type is not a POD type. 5946 ExprResult DefaultVariadicArgumentPromotion(Expr *E, VariadicCallType CT, 5947 FunctionDecl *FDecl); 5948 5949 // UsualArithmeticConversions - performs the UsualUnaryConversions on it's 5950 // operands and then handles various conversions that are common to binary 5951 // operators (C99 6.3.1.8). If both operands aren't arithmetic, this 5952 // routine returns the first non-arithmetic type found. The client is 5953 // responsible for emitting appropriate error diagnostics. 5954 QualType UsualArithmeticConversions(ExprResult &LHS, ExprResult &RHS, 5955 bool IsCompAssign = false); 5956 5957 /// AssignConvertType - All of the 'assignment' semantic checks return this 5958 /// enum to indicate whether the assignment was allowed. These checks are 5959 /// done for simple assignments, as well as initialization, return from 5960 /// function, argument passing, etc. The query is phrased in terms of a 5961 /// source and destination type. 5962 enum AssignConvertType { 5963 /// Compatible - the types are compatible according to the standard. 5964 Compatible, 5965 5966 /// PointerToInt - The assignment converts a pointer to an int, which we 5967 /// accept as an extension. 5968 PointerToInt, 5969 5970 /// IntToPointer - The assignment converts an int to a pointer, which we 5971 /// accept as an extension. 5972 IntToPointer, 5973 5974 /// FunctionVoidPointer - The assignment is between a function pointer and 5975 /// void*, which the standard doesn't allow, but we accept as an extension. 5976 FunctionVoidPointer, 5977 5978 /// IncompatiblePointer - The assignment is between two pointers types that 5979 /// are not compatible, but we accept them as an extension. 5980 IncompatiblePointer, 5981 5982 /// IncompatiblePointer - The assignment is between two pointers types which 5983 /// point to integers which have a different sign, but are otherwise 5984 /// identical. This is a subset of the above, but broken out because it's by 5985 /// far the most common case of incompatible pointers. 5986 IncompatiblePointerSign, 5987 5988 /// CompatiblePointerDiscardsQualifiers - The assignment discards 5989 /// c/v/r qualifiers, which we accept as an extension. 5990 CompatiblePointerDiscardsQualifiers, 5991 5992 /// IncompatiblePointerDiscardsQualifiers - The assignment 5993 /// discards qualifiers that we don't permit to be discarded, 5994 /// like address spaces. 5995 IncompatiblePointerDiscardsQualifiers, 5996 5997 /// IncompatibleNestedPointerQualifiers - The assignment is between two 5998 /// nested pointer types, and the qualifiers other than the first two 5999 /// levels differ e.g. char ** -> const char **, but we accept them as an 6000 /// extension. 6001 IncompatibleNestedPointerQualifiers, 6002 6003 /// IncompatibleVectors - The assignment is between two vector types that 6004 /// have the same size, which we accept as an extension. 6005 IncompatibleVectors, 6006 6007 /// IntToBlockPointer - The assignment converts an int to a block 6008 /// pointer. We disallow this. 6009 IntToBlockPointer, 6010 6011 /// IncompatibleBlockPointer - The assignment is between two block 6012 /// pointers types that are not compatible. 6013 IncompatibleBlockPointer, 6014 6015 /// IncompatibleObjCQualifiedId - The assignment is between a qualified 6016 /// id type and something else (that is incompatible with it). For example, 6017 /// "id <XXX>" = "Foo *", where "Foo *" doesn't implement the XXX protocol. 6018 IncompatibleObjCQualifiedId, 6019 6020 /// IncompatibleObjCWeakRef - Assigning a weak-unavailable object to an 6021 /// object with __weak qualifier. 6022 IncompatibleObjCWeakRef, 6023 6024 /// Incompatible - We reject this conversion outright, it is invalid to 6025 /// represent it in the AST. 6026 Incompatible 6027 }; 6028 6029 /// DiagnoseAssignmentResult - Emit a diagnostic, if required, for the 6030 /// assignment conversion type specified by ConvTy. This returns true if the 6031 /// conversion was invalid or false if the conversion was accepted. 6032 bool DiagnoseAssignmentResult(AssignConvertType ConvTy, 6033 SourceLocation Loc, 6034 QualType DstType, QualType SrcType, 6035 Expr *SrcExpr, AssignmentAction Action, 6036 bool *Complained = 0); 6037 6038 /// CheckAssignmentConstraints - Perform type checking for assignment, 6039 /// argument passing, variable initialization, and function return values. 6040 /// C99 6.5.16. 6041 AssignConvertType CheckAssignmentConstraints(SourceLocation Loc, 6042 QualType LHSType, 6043 QualType RHSType); 6044 6045 /// Check assignment constraints and prepare for a conversion of the 6046 /// RHS to the LHS type. 6047 AssignConvertType CheckAssignmentConstraints(QualType LHSType, 6048 ExprResult &RHS, 6049 CastKind &Kind); 6050 6051 // CheckSingleAssignmentConstraints - Currently used by 6052 // CheckAssignmentOperands, and ActOnReturnStmt. Prior to type checking, 6053 // this routine performs the default function/array converions. 6054 AssignConvertType CheckSingleAssignmentConstraints(QualType LHSType, 6055 ExprResult &RHS, 6056 bool Diagnose = true); 6057 6058 // \brief If the lhs type is a transparent union, check whether we 6059 // can initialize the transparent union with the given expression. 6060 AssignConvertType CheckTransparentUnionArgumentConstraints(QualType ArgType, 6061 ExprResult &RHS); 6062 6063 bool IsStringLiteralToNonConstPointerConversion(Expr *From, QualType ToType); 6064 6065 bool CheckExceptionSpecCompatibility(Expr *From, QualType ToType); 6066 6067 ExprResult PerformImplicitConversion(Expr *From, QualType ToType, 6068 AssignmentAction Action, 6069 bool AllowExplicit = false); 6070 ExprResult PerformImplicitConversion(Expr *From, QualType ToType, 6071 AssignmentAction Action, 6072 bool AllowExplicit, 6073 ImplicitConversionSequence& ICS); 6074 ExprResult PerformImplicitConversion(Expr *From, QualType ToType, 6075 const ImplicitConversionSequence& ICS, 6076 AssignmentAction Action, 6077 CheckedConversionKind CCK 6078 = CCK_ImplicitConversion); 6079 ExprResult PerformImplicitConversion(Expr *From, QualType ToType, 6080 const StandardConversionSequence& SCS, 6081 AssignmentAction Action, 6082 CheckedConversionKind CCK); 6083 6084 /// the following "Check" methods will return a valid/converted QualType 6085 /// or a null QualType (indicating an error diagnostic was issued). 6086 6087 /// type checking binary operators (subroutines of CreateBuiltinBinOp). 6088 QualType InvalidOperands(SourceLocation Loc, ExprResult &LHS, 6089 ExprResult &RHS); 6090 QualType CheckPointerToMemberOperands( // C++ 5.5 6091 ExprResult &LHS, ExprResult &RHS, ExprValueKind &VK, 6092 SourceLocation OpLoc, bool isIndirect); 6093 QualType CheckMultiplyDivideOperands( // C99 6.5.5 6094 ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, bool IsCompAssign, 6095 bool IsDivide); 6096 QualType CheckRemainderOperands( // C99 6.5.5 6097 ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, 6098 bool IsCompAssign = false); 6099 QualType CheckAdditionOperands( // C99 6.5.6 6100 ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, 6101 QualType* CompLHSTy = 0); 6102 QualType CheckSubtractionOperands( // C99 6.5.6 6103 ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, 6104 QualType* CompLHSTy = 0); 6105 QualType CheckShiftOperands( // C99 6.5.7 6106 ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, unsigned Opc, 6107 bool IsCompAssign = false); 6108 QualType CheckCompareOperands( // C99 6.5.8/9 6109 ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, unsigned OpaqueOpc, 6110 bool isRelational); 6111 QualType CheckBitwiseOperands( // C99 6.5.[10...12] 6112 ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, 6113 bool IsCompAssign = false); 6114 QualType CheckLogicalOperands( // C99 6.5.[13,14] 6115 ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, unsigned Opc); 6116 // CheckAssignmentOperands is used for both simple and compound assignment. 6117 // For simple assignment, pass both expressions and a null converted type. 6118 // For compound assignment, pass both expressions and the converted type. 6119 QualType CheckAssignmentOperands( // C99 6.5.16.[1,2] 6120 Expr *LHSExpr, ExprResult &RHS, SourceLocation Loc, QualType CompoundType); 6121 6122 ExprResult checkPseudoObjectIncDec(Scope *S, SourceLocation OpLoc, 6123 UnaryOperatorKind Opcode, Expr *Op); 6124 ExprResult checkPseudoObjectAssignment(Scope *S, SourceLocation OpLoc, 6125 BinaryOperatorKind Opcode, 6126 Expr *LHS, Expr *RHS); 6127 ExprResult checkPseudoObjectRValue(Expr *E); 6128 Expr *recreateSyntacticForm(PseudoObjectExpr *E); 6129 6130 QualType CheckConditionalOperands( // C99 6.5.15 6131 ExprResult &Cond, ExprResult &LHS, ExprResult &RHS, 6132 ExprValueKind &VK, ExprObjectKind &OK, SourceLocation QuestionLoc); 6133 QualType CXXCheckConditionalOperands( // C++ 5.16 6134 ExprResult &cond, ExprResult &lhs, ExprResult &rhs, 6135 ExprValueKind &VK, ExprObjectKind &OK, SourceLocation questionLoc); 6136 QualType FindCompositePointerType(SourceLocation Loc, Expr *&E1, Expr *&E2, 6137 bool *NonStandardCompositeType = 0); 6138 QualType FindCompositePointerType(SourceLocation Loc, 6139 ExprResult &E1, ExprResult &E2, 6140 bool *NonStandardCompositeType = 0) { 6141 Expr *E1Tmp = E1.take(), *E2Tmp = E2.take(); 6142 QualType Composite = FindCompositePointerType(Loc, E1Tmp, E2Tmp, 6143 NonStandardCompositeType); 6144 E1 = Owned(E1Tmp); 6145 E2 = Owned(E2Tmp); 6146 return Composite; 6147 } 6148 6149 QualType FindCompositeObjCPointerType(ExprResult &LHS, ExprResult &RHS, 6150 SourceLocation QuestionLoc); 6151 6152 bool DiagnoseConditionalForNull(Expr *LHSExpr, Expr *RHSExpr, 6153 SourceLocation QuestionLoc); 6154 6155 /// type checking for vector binary operators. 6156 QualType CheckVectorOperands(ExprResult &LHS, ExprResult &RHS, 6157 SourceLocation Loc, bool IsCompAssign); 6158 QualType GetSignedVectorType(QualType V); 6159 QualType CheckVectorCompareOperands(ExprResult &LHS, ExprResult &RHS, 6160 SourceLocation Loc, bool isRelational); 6161 QualType CheckVectorLogicalOperands(ExprResult &LHS, ExprResult &RHS, 6162 SourceLocation Loc); 6163 6164 /// type checking declaration initializers (C99 6.7.8) 6165 bool CheckForConstantInitializer(Expr *e, QualType t); 6166 6167 // type checking C++ declaration initializers (C++ [dcl.init]). 6168 6169 /// ReferenceCompareResult - Expresses the result of comparing two 6170 /// types (cv1 T1 and cv2 T2) to determine their compatibility for the 6171 /// purposes of initialization by reference (C++ [dcl.init.ref]p4). 6172 enum ReferenceCompareResult { 6173 /// Ref_Incompatible - The two types are incompatible, so direct 6174 /// reference binding is not possible. 6175 Ref_Incompatible = 0, 6176 /// Ref_Related - The two types are reference-related, which means 6177 /// that their unqualified forms (T1 and T2) are either the same 6178 /// or T1 is a base class of T2. 6179 Ref_Related, 6180 /// Ref_Compatible_With_Added_Qualification - The two types are 6181 /// reference-compatible with added qualification, meaning that 6182 /// they are reference-compatible and the qualifiers on T1 (cv1) 6183 /// are greater than the qualifiers on T2 (cv2). 6184 Ref_Compatible_With_Added_Qualification, 6185 /// Ref_Compatible - The two types are reference-compatible and 6186 /// have equivalent qualifiers (cv1 == cv2). 6187 Ref_Compatible 6188 }; 6189 6190 ReferenceCompareResult CompareReferenceRelationship(SourceLocation Loc, 6191 QualType T1, QualType T2, 6192 bool &DerivedToBase, 6193 bool &ObjCConversion, 6194 bool &ObjCLifetimeConversion); 6195 6196 ExprResult checkUnknownAnyCast(SourceRange TypeRange, QualType CastType, 6197 Expr *CastExpr, CastKind &CastKind, 6198 ExprValueKind &VK, CXXCastPath &Path); 6199 6200 /// \brief Force an expression with unknown-type to an expression of the 6201 /// given type. 6202 ExprResult forceUnknownAnyToType(Expr *E, QualType ToType); 6203 6204 // CheckVectorCast - check type constraints for vectors. 6205 // Since vectors are an extension, there are no C standard reference for this. 6206 // We allow casting between vectors and integer datatypes of the same size. 6207 // returns true if the cast is invalid 6208 bool CheckVectorCast(SourceRange R, QualType VectorTy, QualType Ty, 6209 CastKind &Kind); 6210 6211 // CheckExtVectorCast - check type constraints for extended vectors. 6212 // Since vectors are an extension, there are no C standard reference for this. 6213 // We allow casting between vectors and integer datatypes of the same size, 6214 // or vectors and the element type of that vector. 6215 // returns the cast expr 6216 ExprResult CheckExtVectorCast(SourceRange R, QualType DestTy, Expr *CastExpr, 6217 CastKind &Kind); 6218 6219 ExprResult BuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo, 6220 SourceLocation LParenLoc, 6221 Expr *CastExpr, 6222 SourceLocation RParenLoc); 6223 6224 enum ARCConversionResult { ACR_okay, ACR_unbridged }; 6225 6226 /// \brief Checks for invalid conversions and casts between 6227 /// retainable pointers and other pointer kinds. 6228 ARCConversionResult CheckObjCARCConversion(SourceRange castRange, 6229 QualType castType, Expr *&op, 6230 CheckedConversionKind CCK); 6231 6232 Expr *stripARCUnbridgedCast(Expr *e); 6233 void diagnoseARCUnbridgedCast(Expr *e); 6234 6235 bool CheckObjCARCUnavailableWeakConversion(QualType castType, 6236 QualType ExprType); 6237 6238 /// checkRetainCycles - Check whether an Objective-C message send 6239 /// might create an obvious retain cycle. 6240 void checkRetainCycles(ObjCMessageExpr *msg); 6241 void checkRetainCycles(Expr *receiver, Expr *argument); 6242 6243 /// checkUnsafeAssigns - Check whether +1 expr is being assigned 6244 /// to weak/__unsafe_unretained type. 6245 bool checkUnsafeAssigns(SourceLocation Loc, QualType LHS, Expr *RHS); 6246 6247 /// checkUnsafeExprAssigns - Check whether +1 expr is being assigned 6248 /// to weak/__unsafe_unretained expression. 6249 void checkUnsafeExprAssigns(SourceLocation Loc, Expr *LHS, Expr *RHS); 6250 6251 /// CheckMessageArgumentTypes - Check types in an Obj-C message send. 6252 /// \param Method - May be null. 6253 /// \param [out] ReturnType - The return type of the send. 6254 /// \return true iff there were any incompatible types. 6255 bool CheckMessageArgumentTypes(QualType ReceiverType, 6256 Expr **Args, unsigned NumArgs, Selector Sel, 6257 ObjCMethodDecl *Method, bool isClassMessage, 6258 bool isSuperMessage, 6259 SourceLocation lbrac, SourceLocation rbrac, 6260 QualType &ReturnType, ExprValueKind &VK); 6261 6262 /// \brief Determine the result of a message send expression based on 6263 /// the type of the receiver, the method expected to receive the message, 6264 /// and the form of the message send. 6265 QualType getMessageSendResultType(QualType ReceiverType, 6266 ObjCMethodDecl *Method, 6267 bool isClassMessage, bool isSuperMessage); 6268 6269 /// \brief If the given expression involves a message send to a method 6270 /// with a related result type, emit a note describing what happened. 6271 void EmitRelatedResultTypeNote(const Expr *E); 6272 6273 /// CheckBooleanCondition - Diagnose problems involving the use of 6274 /// the given expression as a boolean condition (e.g. in an if 6275 /// statement). Also performs the standard function and array 6276 /// decays, possibly changing the input variable. 6277 /// 6278 /// \param Loc - A location associated with the condition, e.g. the 6279 /// 'if' keyword. 6280 /// \return true iff there were any errors 6281 ExprResult CheckBooleanCondition(Expr *E, SourceLocation Loc); 6282 6283 ExprResult ActOnBooleanCondition(Scope *S, SourceLocation Loc, 6284 Expr *SubExpr); 6285 6286 /// DiagnoseAssignmentAsCondition - Given that an expression is 6287 /// being used as a boolean condition, warn if it's an assignment. 6288 void DiagnoseAssignmentAsCondition(Expr *E); 6289 6290 /// \brief Redundant parentheses over an equality comparison can indicate 6291 /// that the user intended an assignment used as condition. 6292 void DiagnoseEqualityWithExtraParens(ParenExpr *ParenE); 6293 6294 /// CheckCXXBooleanCondition - Returns true if conversion to bool is invalid. 6295 ExprResult CheckCXXBooleanCondition(Expr *CondExpr); 6296 6297 /// ConvertIntegerToTypeWarnOnOverflow - Convert the specified APInt to have 6298 /// the specified width and sign. If an overflow occurs, detect it and emit 6299 /// the specified diagnostic. 6300 void ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &OldVal, 6301 unsigned NewWidth, bool NewSign, 6302 SourceLocation Loc, unsigned DiagID); 6303 6304 /// Checks that the Objective-C declaration is declared in the global scope. 6305 /// Emits an error and marks the declaration as invalid if it's not declared 6306 /// in the global scope. 6307 bool CheckObjCDeclScope(Decl *D); 6308 6309 /// VerifyIntegerConstantExpression - Verifies that an expression is an ICE, 6310 /// and reports the appropriate diagnostics. Returns false on success. 6311 /// Can optionally return the value of the expression. 6312 ExprResult VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result, 6313 PartialDiagnostic Diag, 6314 bool AllowFold, 6315 PartialDiagnostic FoldDiag); 6316 ExprResult VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result, 6317 PartialDiagnostic Diag, 6318 bool AllowFold = true) { 6319 return VerifyIntegerConstantExpression(E, Result, Diag, AllowFold, 6320 PDiag(0)); 6321 } 6322 ExprResult VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result = 0); 6323 6324 /// VerifyBitField - verifies that a bit field expression is an ICE and has 6325 /// the correct width, and that the field type is valid. 6326 /// Returns false on success. 6327 /// Can optionally return whether the bit-field is of width 0 6328 ExprResult VerifyBitField(SourceLocation FieldLoc, IdentifierInfo *FieldName, 6329 QualType FieldTy, Expr *BitWidth, 6330 bool *ZeroWidth = 0); 6331 6332 enum CUDAFunctionTarget { 6333 CFT_Device, 6334 CFT_Global, 6335 CFT_Host, 6336 CFT_HostDevice 6337 }; 6338 6339 CUDAFunctionTarget IdentifyCUDATarget(const FunctionDecl *D); 6340 6341 bool CheckCUDATarget(CUDAFunctionTarget CallerTarget, 6342 CUDAFunctionTarget CalleeTarget); 6343 6344 bool CheckCUDATarget(const FunctionDecl *Caller, const FunctionDecl *Callee) { 6345 return CheckCUDATarget(IdentifyCUDATarget(Caller), 6346 IdentifyCUDATarget(Callee)); 6347 } 6348 6349 /// \name Code completion 6350 //@{ 6351 /// \brief Describes the context in which code completion occurs. 6352 enum ParserCompletionContext { 6353 /// \brief Code completion occurs at top-level or namespace context. 6354 PCC_Namespace, 6355 /// \brief Code completion occurs within a class, struct, or union. 6356 PCC_Class, 6357 /// \brief Code completion occurs within an Objective-C interface, protocol, 6358 /// or category. 6359 PCC_ObjCInterface, 6360 /// \brief Code completion occurs within an Objective-C implementation or 6361 /// category implementation 6362 PCC_ObjCImplementation, 6363 /// \brief Code completion occurs within the list of instance variables 6364 /// in an Objective-C interface, protocol, category, or implementation. 6365 PCC_ObjCInstanceVariableList, 6366 /// \brief Code completion occurs following one or more template 6367 /// headers. 6368 PCC_Template, 6369 /// \brief Code completion occurs following one or more template 6370 /// headers within a class. 6371 PCC_MemberTemplate, 6372 /// \brief Code completion occurs within an expression. 6373 PCC_Expression, 6374 /// \brief Code completion occurs within a statement, which may 6375 /// also be an expression or a declaration. 6376 PCC_Statement, 6377 /// \brief Code completion occurs at the beginning of the 6378 /// initialization statement (or expression) in a for loop. 6379 PCC_ForInit, 6380 /// \brief Code completion occurs within the condition of an if, 6381 /// while, switch, or for statement. 6382 PCC_Condition, 6383 /// \brief Code completion occurs within the body of a function on a 6384 /// recovery path, where we do not have a specific handle on our position 6385 /// in the grammar. 6386 PCC_RecoveryInFunction, 6387 /// \brief Code completion occurs where only a type is permitted. 6388 PCC_Type, 6389 /// \brief Code completion occurs in a parenthesized expression, which 6390 /// might also be a type cast. 6391 PCC_ParenthesizedExpression, 6392 /// \brief Code completion occurs within a sequence of declaration 6393 /// specifiers within a function, method, or block. 6394 PCC_LocalDeclarationSpecifiers 6395 }; 6396 6397 void CodeCompleteModuleImport(SourceLocation ImportLoc, ModuleIdPath Path); 6398 void CodeCompleteOrdinaryName(Scope *S, 6399 ParserCompletionContext CompletionContext); 6400 void CodeCompleteDeclSpec(Scope *S, DeclSpec &DS, 6401 bool AllowNonIdentifiers, 6402 bool AllowNestedNameSpecifiers); 6403 6404 struct CodeCompleteExpressionData; 6405 void CodeCompleteExpression(Scope *S, 6406 const CodeCompleteExpressionData &Data); 6407 void CodeCompleteMemberReferenceExpr(Scope *S, Expr *Base, 6408 SourceLocation OpLoc, 6409 bool IsArrow); 6410 void CodeCompletePostfixExpression(Scope *S, ExprResult LHS); 6411 void CodeCompleteTag(Scope *S, unsigned TagSpec); 6412 void CodeCompleteTypeQualifiers(DeclSpec &DS); 6413 void CodeCompleteCase(Scope *S); 6414 void CodeCompleteCall(Scope *S, Expr *Fn, llvm::ArrayRef<Expr *> Args); 6415 void CodeCompleteInitializer(Scope *S, Decl *D); 6416 void CodeCompleteReturn(Scope *S); 6417 void CodeCompleteAfterIf(Scope *S); 6418 void CodeCompleteAssignmentRHS(Scope *S, Expr *LHS); 6419 6420 void CodeCompleteQualifiedId(Scope *S, CXXScopeSpec &SS, 6421 bool EnteringContext); 6422 void CodeCompleteUsing(Scope *S); 6423 void CodeCompleteUsingDirective(Scope *S); 6424 void CodeCompleteNamespaceDecl(Scope *S); 6425 void CodeCompleteNamespaceAliasDecl(Scope *S); 6426 void CodeCompleteOperatorName(Scope *S); 6427 void CodeCompleteConstructorInitializer(Decl *Constructor, 6428 CXXCtorInitializer** Initializers, 6429 unsigned NumInitializers); 6430 void CodeCompleteLambdaIntroducer(Scope *S, LambdaIntroducer &Intro, 6431 bool AfterAmpersand); 6432 6433 void CodeCompleteObjCAtDirective(Scope *S); 6434 void CodeCompleteObjCAtVisibility(Scope *S); 6435 void CodeCompleteObjCAtStatement(Scope *S); 6436 void CodeCompleteObjCAtExpression(Scope *S); 6437 void CodeCompleteObjCPropertyFlags(Scope *S, ObjCDeclSpec &ODS); 6438 void CodeCompleteObjCPropertyGetter(Scope *S); 6439 void CodeCompleteObjCPropertySetter(Scope *S); 6440 void CodeCompleteObjCPassingType(Scope *S, ObjCDeclSpec &DS, 6441 bool IsParameter); 6442 void CodeCompleteObjCMessageReceiver(Scope *S); 6443 void CodeCompleteObjCSuperMessage(Scope *S, SourceLocation SuperLoc, 6444 IdentifierInfo **SelIdents, 6445 unsigned NumSelIdents, 6446 bool AtArgumentExpression); 6447 void CodeCompleteObjCClassMessage(Scope *S, ParsedType Receiver, 6448 IdentifierInfo **SelIdents, 6449 unsigned NumSelIdents, 6450 bool AtArgumentExpression, 6451 bool IsSuper = false); 6452 void CodeCompleteObjCInstanceMessage(Scope *S, Expr *Receiver, 6453 IdentifierInfo **SelIdents, 6454 unsigned NumSelIdents, 6455 bool AtArgumentExpression, 6456 ObjCInterfaceDecl *Super = 0); 6457 void CodeCompleteObjCForCollection(Scope *S, 6458 DeclGroupPtrTy IterationVar); 6459 void CodeCompleteObjCSelector(Scope *S, 6460 IdentifierInfo **SelIdents, 6461 unsigned NumSelIdents); 6462 void CodeCompleteObjCProtocolReferences(IdentifierLocPair *Protocols, 6463 unsigned NumProtocols); 6464 void CodeCompleteObjCProtocolDecl(Scope *S); 6465 void CodeCompleteObjCInterfaceDecl(Scope *S); 6466 void CodeCompleteObjCSuperclass(Scope *S, 6467 IdentifierInfo *ClassName, 6468 SourceLocation ClassNameLoc); 6469 void CodeCompleteObjCImplementationDecl(Scope *S); 6470 void CodeCompleteObjCInterfaceCategory(Scope *S, 6471 IdentifierInfo *ClassName, 6472 SourceLocation ClassNameLoc); 6473 void CodeCompleteObjCImplementationCategory(Scope *S, 6474 IdentifierInfo *ClassName, 6475 SourceLocation ClassNameLoc); 6476 void CodeCompleteObjCPropertyDefinition(Scope *S); 6477 void CodeCompleteObjCPropertySynthesizeIvar(Scope *S, 6478 IdentifierInfo *PropertyName); 6479 void CodeCompleteObjCMethodDecl(Scope *S, 6480 bool IsInstanceMethod, 6481 ParsedType ReturnType); 6482 void CodeCompleteObjCMethodDeclSelector(Scope *S, 6483 bool IsInstanceMethod, 6484 bool AtParameterName, 6485 ParsedType ReturnType, 6486 IdentifierInfo **SelIdents, 6487 unsigned NumSelIdents); 6488 void CodeCompletePreprocessorDirective(bool InConditional); 6489 void CodeCompleteInPreprocessorConditionalExclusion(Scope *S); 6490 void CodeCompletePreprocessorMacroName(bool IsDefinition); 6491 void CodeCompletePreprocessorExpression(); 6492 void CodeCompletePreprocessorMacroArgument(Scope *S, 6493 IdentifierInfo *Macro, 6494 MacroInfo *MacroInfo, 6495 unsigned Argument); 6496 void CodeCompleteNaturalLanguage(); 6497 void GatherGlobalCodeCompletions(CodeCompletionAllocator &Allocator, 6498 SmallVectorImpl<CodeCompletionResult> &Results); 6499 //@} 6500 6501 //===--------------------------------------------------------------------===// 6502 // Extra semantic analysis beyond the C type system 6503 6504public: 6505 SourceLocation getLocationOfStringLiteralByte(const StringLiteral *SL, 6506 unsigned ByteNo) const; 6507 6508private: 6509 void CheckArrayAccess(const Expr *BaseExpr, const Expr *IndexExpr, 6510 const ArraySubscriptExpr *ASE=0, 6511 bool AllowOnePastEnd=true, bool IndexNegated=false); 6512 void CheckArrayAccess(const Expr *E); 6513 bool CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall); 6514 bool CheckObjCMethodCall(ObjCMethodDecl *Method, SourceLocation loc, 6515 Expr **Args, unsigned NumArgs); 6516 bool CheckBlockCall(NamedDecl *NDecl, CallExpr *TheCall); 6517 6518 bool CheckObjCString(Expr *Arg); 6519 6520 ExprResult CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); 6521 bool CheckARMBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); 6522 6523 bool SemaBuiltinVAStart(CallExpr *TheCall); 6524 bool SemaBuiltinUnorderedCompare(CallExpr *TheCall); 6525 bool SemaBuiltinFPClassification(CallExpr *TheCall, unsigned NumArgs); 6526 6527public: 6528 // Used by C++ template instantiation. 6529 ExprResult SemaBuiltinShuffleVector(CallExpr *TheCall); 6530 6531private: 6532 bool SemaBuiltinPrefetch(CallExpr *TheCall); 6533 bool SemaBuiltinObjectSize(CallExpr *TheCall); 6534 bool SemaBuiltinLongjmp(CallExpr *TheCall); 6535 ExprResult SemaBuiltinAtomicOverloaded(ExprResult TheCallResult); 6536 ExprResult SemaAtomicOpsOverloaded(ExprResult TheCallResult, 6537 AtomicExpr::AtomicOp Op); 6538 bool SemaBuiltinConstantArg(CallExpr *TheCall, int ArgNum, 6539 llvm::APSInt &Result); 6540 6541 enum FormatStringType { 6542 FST_Scanf, 6543 FST_Printf, 6544 FST_NSString, 6545 FST_Strftime, 6546 FST_Strfmon, 6547 FST_Kprintf, 6548 FST_Unknown 6549 }; 6550 static FormatStringType GetFormatStringType(const FormatAttr *Format); 6551 bool SemaCheckStringLiteral(const Expr *E, Expr **Args, unsigned NumArgs, 6552 bool HasVAListArg, unsigned format_idx, 6553 unsigned firstDataArg, FormatStringType Type, 6554 bool inFunctionCall = true); 6555 6556 void CheckFormatString(const StringLiteral *FExpr, const Expr *OrigFormatExpr, 6557 Expr **Args, unsigned NumArgs, bool HasVAListArg, 6558 unsigned format_idx, unsigned firstDataArg, 6559 FormatStringType Type, bool inFunctionCall); 6560 6561 void CheckFormatArguments(const FormatAttr *Format, CallExpr *TheCall); 6562 void CheckFormatArguments(const FormatAttr *Format, Expr **Args, 6563 unsigned NumArgs, bool IsCXXMember, 6564 SourceLocation Loc, SourceRange Range); 6565 void CheckFormatArguments(Expr **Args, unsigned NumArgs, 6566 bool HasVAListArg, unsigned format_idx, 6567 unsigned firstDataArg, FormatStringType Type, 6568 SourceLocation Loc, SourceRange range); 6569 6570 void CheckNonNullArguments(const NonNullAttr *NonNull, 6571 const Expr * const *ExprArgs, 6572 SourceLocation CallSiteLoc); 6573 6574 void CheckMemaccessArguments(const CallExpr *Call, 6575 unsigned BId, 6576 IdentifierInfo *FnName); 6577 6578 void CheckStrlcpycatArguments(const CallExpr *Call, 6579 IdentifierInfo *FnName); 6580 6581 void CheckStrncatArguments(const CallExpr *Call, 6582 IdentifierInfo *FnName); 6583 6584 void CheckReturnStackAddr(Expr *RetValExp, QualType lhsType, 6585 SourceLocation ReturnLoc); 6586 void CheckFloatComparison(SourceLocation Loc, Expr* LHS, Expr* RHS); 6587 void CheckImplicitConversions(Expr *E, SourceLocation CC = SourceLocation()); 6588 6589 void CheckBitFieldInitialization(SourceLocation InitLoc, FieldDecl *Field, 6590 Expr *Init); 6591 6592 /// \brief The parser's current scope. 6593 /// 6594 /// The parser maintains this state here. 6595 Scope *CurScope; 6596 6597protected: 6598 friend class Parser; 6599 friend class InitializationSequence; 6600 friend class ASTReader; 6601 friend class ASTWriter; 6602 6603public: 6604 /// \brief Retrieve the parser's current scope. 6605 /// 6606 /// This routine must only be used when it is certain that semantic analysis 6607 /// and the parser are in precisely the same context, which is not the case 6608 /// when, e.g., we are performing any kind of template instantiation. 6609 /// Therefore, the only safe places to use this scope are in the parser 6610 /// itself and in routines directly invoked from the parser and *never* from 6611 /// template substitution or instantiation. 6612 Scope *getCurScope() const { return CurScope; } 6613 6614 Decl *getObjCDeclContext() const; 6615 6616 DeclContext *getCurLexicalContext() const { 6617 return OriginalLexicalContext ? OriginalLexicalContext : CurContext; 6618 } 6619 6620 AvailabilityResult getCurContextAvailability() const; 6621}; 6622 6623/// \brief RAII object that enters a new expression evaluation context. 6624class EnterExpressionEvaluationContext { 6625 Sema &Actions; 6626 6627public: 6628 EnterExpressionEvaluationContext(Sema &Actions, 6629 Sema::ExpressionEvaluationContext NewContext, 6630 Decl *LambdaContextDecl = 0, 6631 bool IsDecltype = false) 6632 : Actions(Actions) { 6633 Actions.PushExpressionEvaluationContext(NewContext, LambdaContextDecl, 6634 IsDecltype); 6635 } 6636 6637 ~EnterExpressionEvaluationContext() { 6638 Actions.PopExpressionEvaluationContext(); 6639 } 6640}; 6641 6642} // end namespace clang 6643 6644#endif 6645