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