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