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