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