Sema.h revision dfe6543e12eca5c79421378b7fa6b3e8fc403e63
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 /// \brief Load any externally-stored vtable uses. 3369 void LoadExternalVTableUses(); 3370 3371 typedef LazyVector<CXXRecordDecl *, ExternalSemaSource, 3372 &ExternalSemaSource::ReadDynamicClasses, 2, 2> 3373 DynamicClassesType; 3374 3375 /// \brief A list of all of the dynamic classes in this translation 3376 /// unit. 3377 DynamicClassesType DynamicClasses; 3378 3379 /// \brief Note that the vtable for the given class was used at the 3380 /// given location. 3381 void MarkVTableUsed(SourceLocation Loc, CXXRecordDecl *Class, 3382 bool DefinitionRequired = false); 3383 3384 /// MarkVirtualMembersReferenced - Will mark all members of the given 3385 /// CXXRecordDecl referenced. 3386 void MarkVirtualMembersReferenced(SourceLocation Loc, 3387 const CXXRecordDecl *RD); 3388 3389 /// \brief Define all of the vtables that have been used in this 3390 /// translation unit and reference any virtual members used by those 3391 /// vtables. 3392 /// 3393 /// \returns true if any work was done, false otherwise. 3394 bool DefineUsedVTables(); 3395 3396 void AddImplicitlyDeclaredMembersToClass(CXXRecordDecl *ClassDecl); 3397 3398 void ActOnMemInitializers(Decl *ConstructorDecl, 3399 SourceLocation ColonLoc, 3400 MemInitTy **MemInits, unsigned NumMemInits, 3401 bool AnyErrors); 3402 3403 void CheckCompletedCXXClass(CXXRecordDecl *Record); 3404 void ActOnFinishCXXMemberSpecification(Scope* S, SourceLocation RLoc, 3405 Decl *TagDecl, 3406 SourceLocation LBrac, 3407 SourceLocation RBrac, 3408 AttributeList *AttrList); 3409 3410 void ActOnReenterTemplateScope(Scope *S, Decl *Template); 3411 void ActOnReenterDeclaratorTemplateScope(Scope *S, DeclaratorDecl *D); 3412 void ActOnStartDelayedMemberDeclarations(Scope *S, Decl *Record); 3413 void ActOnStartDelayedCXXMethodDeclaration(Scope *S, Decl *Method); 3414 void ActOnDelayedCXXMethodParameter(Scope *S, Decl *Param); 3415 void ActOnFinishDelayedMemberDeclarations(Scope *S, Decl *Record); 3416 void ActOnFinishDelayedCXXMethodDeclaration(Scope *S, Decl *Method); 3417 void ActOnFinishDelayedMemberInitializers(Decl *Record); 3418 void MarkAsLateParsedTemplate(FunctionDecl *FD, bool Flag = true); 3419 bool IsInsideALocalClassWithinATemplateFunction(); 3420 3421 Decl *ActOnStaticAssertDeclaration(SourceLocation StaticAssertLoc, 3422 Expr *AssertExpr, 3423 Expr *AssertMessageExpr, 3424 SourceLocation RParenLoc); 3425 3426 FriendDecl *CheckFriendTypeDecl(SourceLocation FriendLoc, 3427 TypeSourceInfo *TSInfo); 3428 Decl *ActOnFriendTypeDecl(Scope *S, const DeclSpec &DS, 3429 MultiTemplateParamsArg TemplateParams); 3430 Decl *ActOnFriendFunctionDecl(Scope *S, Declarator &D, bool IsDefinition, 3431 MultiTemplateParamsArg TemplateParams); 3432 3433 QualType CheckConstructorDeclarator(Declarator &D, QualType R, 3434 StorageClass& SC); 3435 void CheckConstructor(CXXConstructorDecl *Constructor); 3436 QualType CheckDestructorDeclarator(Declarator &D, QualType R, 3437 StorageClass& SC); 3438 bool CheckDestructor(CXXDestructorDecl *Destructor); 3439 void CheckConversionDeclarator(Declarator &D, QualType &R, 3440 StorageClass& SC); 3441 Decl *ActOnConversionDeclarator(CXXConversionDecl *Conversion); 3442 3443 void CheckExplicitlyDefaultedMethods(CXXRecordDecl *Record); 3444 void CheckExplicitlyDefaultedDefaultConstructor(CXXConstructorDecl *Ctor); 3445 void CheckExplicitlyDefaultedCopyConstructor(CXXConstructorDecl *Ctor); 3446 void CheckExplicitlyDefaultedCopyAssignment(CXXMethodDecl *Method); 3447 void CheckExplicitlyDefaultedDestructor(CXXDestructorDecl *Dtor); 3448 3449 //===--------------------------------------------------------------------===// 3450 // C++ Derived Classes 3451 // 3452 3453 /// ActOnBaseSpecifier - Parsed a base specifier 3454 CXXBaseSpecifier *CheckBaseSpecifier(CXXRecordDecl *Class, 3455 SourceRange SpecifierRange, 3456 bool Virtual, AccessSpecifier Access, 3457 TypeSourceInfo *TInfo, 3458 SourceLocation EllipsisLoc); 3459 3460 BaseResult ActOnBaseSpecifier(Decl *classdecl, 3461 SourceRange SpecifierRange, 3462 bool Virtual, AccessSpecifier Access, 3463 ParsedType basetype, 3464 SourceLocation BaseLoc, 3465 SourceLocation EllipsisLoc); 3466 3467 bool AttachBaseSpecifiers(CXXRecordDecl *Class, CXXBaseSpecifier **Bases, 3468 unsigned NumBases); 3469 void ActOnBaseSpecifiers(Decl *ClassDecl, BaseTy **Bases, unsigned NumBases); 3470 3471 bool IsDerivedFrom(QualType Derived, QualType Base); 3472 bool IsDerivedFrom(QualType Derived, QualType Base, CXXBasePaths &Paths); 3473 3474 // FIXME: I don't like this name. 3475 void BuildBasePathArray(const CXXBasePaths &Paths, CXXCastPath &BasePath); 3476 3477 bool BasePathInvolvesVirtualBase(const CXXCastPath &BasePath); 3478 3479 bool CheckDerivedToBaseConversion(QualType Derived, QualType Base, 3480 SourceLocation Loc, SourceRange Range, 3481 CXXCastPath *BasePath = 0, 3482 bool IgnoreAccess = false); 3483 bool CheckDerivedToBaseConversion(QualType Derived, QualType Base, 3484 unsigned InaccessibleBaseID, 3485 unsigned AmbigiousBaseConvID, 3486 SourceLocation Loc, SourceRange Range, 3487 DeclarationName Name, 3488 CXXCastPath *BasePath); 3489 3490 std::string getAmbiguousPathsDisplayString(CXXBasePaths &Paths); 3491 3492 /// CheckOverridingFunctionReturnType - Checks whether the return types are 3493 /// covariant, according to C++ [class.virtual]p5. 3494 bool CheckOverridingFunctionReturnType(const CXXMethodDecl *New, 3495 const CXXMethodDecl *Old); 3496 3497 /// CheckOverridingFunctionExceptionSpec - Checks whether the exception 3498 /// spec is a subset of base spec. 3499 bool CheckOverridingFunctionExceptionSpec(const CXXMethodDecl *New, 3500 const CXXMethodDecl *Old); 3501 3502 bool CheckPureMethod(CXXMethodDecl *Method, SourceRange InitRange); 3503 3504 /// CheckOverrideControl - Check C++0x override control semantics. 3505 void CheckOverrideControl(const Decl *D); 3506 3507 /// CheckForFunctionMarkedFinal - Checks whether a virtual member function 3508 /// overrides a virtual member function marked 'final', according to 3509 /// C++0x [class.virtual]p3. 3510 bool CheckIfOverriddenFunctionIsMarkedFinal(const CXXMethodDecl *New, 3511 const CXXMethodDecl *Old); 3512 3513 3514 //===--------------------------------------------------------------------===// 3515 // C++ Access Control 3516 // 3517 3518 enum AccessResult { 3519 AR_accessible, 3520 AR_inaccessible, 3521 AR_dependent, 3522 AR_delayed 3523 }; 3524 3525 bool SetMemberAccessSpecifier(NamedDecl *MemberDecl, 3526 NamedDecl *PrevMemberDecl, 3527 AccessSpecifier LexicalAS); 3528 3529 AccessResult CheckUnresolvedMemberAccess(UnresolvedMemberExpr *E, 3530 DeclAccessPair FoundDecl); 3531 AccessResult CheckUnresolvedLookupAccess(UnresolvedLookupExpr *E, 3532 DeclAccessPair FoundDecl); 3533 AccessResult CheckAllocationAccess(SourceLocation OperatorLoc, 3534 SourceRange PlacementRange, 3535 CXXRecordDecl *NamingClass, 3536 DeclAccessPair FoundDecl, 3537 bool Diagnose = true); 3538 AccessResult CheckConstructorAccess(SourceLocation Loc, 3539 CXXConstructorDecl *D, 3540 const InitializedEntity &Entity, 3541 AccessSpecifier Access, 3542 bool IsCopyBindingRefToTemp = false); 3543 AccessResult CheckConstructorAccess(SourceLocation Loc, 3544 CXXConstructorDecl *D, 3545 AccessSpecifier Access, 3546 PartialDiagnostic PD); 3547 AccessResult CheckDestructorAccess(SourceLocation Loc, 3548 CXXDestructorDecl *Dtor, 3549 const PartialDiagnostic &PDiag); 3550 AccessResult CheckDirectMemberAccess(SourceLocation Loc, 3551 NamedDecl *D, 3552 const PartialDiagnostic &PDiag); 3553 AccessResult CheckMemberOperatorAccess(SourceLocation Loc, 3554 Expr *ObjectExpr, 3555 Expr *ArgExpr, 3556 DeclAccessPair FoundDecl); 3557 AccessResult CheckAddressOfMemberAccess(Expr *OvlExpr, 3558 DeclAccessPair FoundDecl); 3559 AccessResult CheckBaseClassAccess(SourceLocation AccessLoc, 3560 QualType Base, QualType Derived, 3561 const CXXBasePath &Path, 3562 unsigned DiagID, 3563 bool ForceCheck = false, 3564 bool ForceUnprivileged = false); 3565 void CheckLookupAccess(const LookupResult &R); 3566 3567 void HandleDependentAccessCheck(const DependentDiagnostic &DD, 3568 const MultiLevelTemplateArgumentList &TemplateArgs); 3569 void PerformDependentDiagnostics(const DeclContext *Pattern, 3570 const MultiLevelTemplateArgumentList &TemplateArgs); 3571 3572 void HandleDelayedAccessCheck(sema::DelayedDiagnostic &DD, Decl *Ctx); 3573 3574 /// A flag to suppress access checking. 3575 bool SuppressAccessChecking; 3576 3577 /// \brief When true, access checking violations are treated as SFINAE 3578 /// failures rather than hard errors. 3579 bool AccessCheckingSFINAE; 3580 3581 void ActOnStartSuppressingAccessChecks(); 3582 void ActOnStopSuppressingAccessChecks(); 3583 3584 enum AbstractDiagSelID { 3585 AbstractNone = -1, 3586 AbstractReturnType, 3587 AbstractParamType, 3588 AbstractVariableType, 3589 AbstractFieldType, 3590 AbstractArrayType 3591 }; 3592 3593 bool RequireNonAbstractType(SourceLocation Loc, QualType T, 3594 const PartialDiagnostic &PD); 3595 void DiagnoseAbstractType(const CXXRecordDecl *RD); 3596 3597 bool RequireNonAbstractType(SourceLocation Loc, QualType T, unsigned DiagID, 3598 AbstractDiagSelID SelID = AbstractNone); 3599 3600 //===--------------------------------------------------------------------===// 3601 // C++ Overloaded Operators [C++ 13.5] 3602 // 3603 3604 bool CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl); 3605 3606 bool CheckLiteralOperatorDeclaration(FunctionDecl *FnDecl); 3607 3608 //===--------------------------------------------------------------------===// 3609 // C++ Templates [C++ 14] 3610 // 3611 void FilterAcceptableTemplateNames(LookupResult &R); 3612 bool hasAnyAcceptableTemplateNames(LookupResult &R); 3613 3614 void LookupTemplateName(LookupResult &R, Scope *S, CXXScopeSpec &SS, 3615 QualType ObjectType, bool EnteringContext, 3616 bool &MemberOfUnknownSpecialization); 3617 3618 TemplateNameKind isTemplateName(Scope *S, 3619 CXXScopeSpec &SS, 3620 bool hasTemplateKeyword, 3621 UnqualifiedId &Name, 3622 ParsedType ObjectType, 3623 bool EnteringContext, 3624 TemplateTy &Template, 3625 bool &MemberOfUnknownSpecialization); 3626 3627 bool DiagnoseUnknownTemplateName(const IdentifierInfo &II, 3628 SourceLocation IILoc, 3629 Scope *S, 3630 const CXXScopeSpec *SS, 3631 TemplateTy &SuggestedTemplate, 3632 TemplateNameKind &SuggestedKind); 3633 3634 bool DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl); 3635 TemplateDecl *AdjustDeclIfTemplate(Decl *&Decl); 3636 3637 Decl *ActOnTypeParameter(Scope *S, bool Typename, bool Ellipsis, 3638 SourceLocation EllipsisLoc, 3639 SourceLocation KeyLoc, 3640 IdentifierInfo *ParamName, 3641 SourceLocation ParamNameLoc, 3642 unsigned Depth, unsigned Position, 3643 SourceLocation EqualLoc, 3644 ParsedType DefaultArg); 3645 3646 QualType CheckNonTypeTemplateParameterType(QualType T, SourceLocation Loc); 3647 Decl *ActOnNonTypeTemplateParameter(Scope *S, Declarator &D, 3648 unsigned Depth, 3649 unsigned Position, 3650 SourceLocation EqualLoc, 3651 Expr *DefaultArg); 3652 Decl *ActOnTemplateTemplateParameter(Scope *S, 3653 SourceLocation TmpLoc, 3654 TemplateParamsTy *Params, 3655 SourceLocation EllipsisLoc, 3656 IdentifierInfo *ParamName, 3657 SourceLocation ParamNameLoc, 3658 unsigned Depth, 3659 unsigned Position, 3660 SourceLocation EqualLoc, 3661 ParsedTemplateArgument DefaultArg); 3662 3663 TemplateParamsTy * 3664 ActOnTemplateParameterList(unsigned Depth, 3665 SourceLocation ExportLoc, 3666 SourceLocation TemplateLoc, 3667 SourceLocation LAngleLoc, 3668 Decl **Params, unsigned NumParams, 3669 SourceLocation RAngleLoc); 3670 3671 /// \brief The context in which we are checking a template parameter 3672 /// list. 3673 enum TemplateParamListContext { 3674 TPC_ClassTemplate, 3675 TPC_FunctionTemplate, 3676 TPC_ClassTemplateMember, 3677 TPC_FriendFunctionTemplate, 3678 TPC_FriendFunctionTemplateDefinition, 3679 TPC_TypeAliasTemplate 3680 }; 3681 3682 bool CheckTemplateParameterList(TemplateParameterList *NewParams, 3683 TemplateParameterList *OldParams, 3684 TemplateParamListContext TPC); 3685 TemplateParameterList * 3686 MatchTemplateParametersToScopeSpecifier(SourceLocation DeclStartLoc, 3687 SourceLocation DeclLoc, 3688 const CXXScopeSpec &SS, 3689 TemplateParameterList **ParamLists, 3690 unsigned NumParamLists, 3691 bool IsFriend, 3692 bool &IsExplicitSpecialization, 3693 bool &Invalid); 3694 3695 DeclResult CheckClassTemplate(Scope *S, unsigned TagSpec, TagUseKind TUK, 3696 SourceLocation KWLoc, CXXScopeSpec &SS, 3697 IdentifierInfo *Name, SourceLocation NameLoc, 3698 AttributeList *Attr, 3699 TemplateParameterList *TemplateParams, 3700 AccessSpecifier AS, 3701 unsigned NumOuterTemplateParamLists, 3702 TemplateParameterList **OuterTemplateParamLists); 3703 3704 void translateTemplateArguments(const ASTTemplateArgsPtr &In, 3705 TemplateArgumentListInfo &Out); 3706 3707 void NoteAllFoundTemplates(TemplateName Name); 3708 3709 QualType CheckTemplateIdType(TemplateName Template, 3710 SourceLocation TemplateLoc, 3711 TemplateArgumentListInfo &TemplateArgs); 3712 3713 TypeResult 3714 ActOnTemplateIdType(CXXScopeSpec &SS, 3715 TemplateTy Template, SourceLocation TemplateLoc, 3716 SourceLocation LAngleLoc, 3717 ASTTemplateArgsPtr TemplateArgs, 3718 SourceLocation RAngleLoc); 3719 3720 /// \brief Parsed an elaborated-type-specifier that refers to a template-id, 3721 /// such as \c class T::template apply<U>. 3722 /// 3723 /// \param TUK 3724 TypeResult ActOnTagTemplateIdType(TagUseKind TUK, 3725 TypeSpecifierType TagSpec, 3726 SourceLocation TagLoc, 3727 CXXScopeSpec &SS, 3728 TemplateTy TemplateD, 3729 SourceLocation TemplateLoc, 3730 SourceLocation LAngleLoc, 3731 ASTTemplateArgsPtr TemplateArgsIn, 3732 SourceLocation RAngleLoc); 3733 3734 3735 ExprResult BuildTemplateIdExpr(const CXXScopeSpec &SS, 3736 LookupResult &R, 3737 bool RequiresADL, 3738 const TemplateArgumentListInfo &TemplateArgs); 3739 ExprResult BuildQualifiedTemplateIdExpr(CXXScopeSpec &SS, 3740 const DeclarationNameInfo &NameInfo, 3741 const TemplateArgumentListInfo &TemplateArgs); 3742 3743 TemplateNameKind ActOnDependentTemplateName(Scope *S, 3744 SourceLocation TemplateKWLoc, 3745 CXXScopeSpec &SS, 3746 UnqualifiedId &Name, 3747 ParsedType ObjectType, 3748 bool EnteringContext, 3749 TemplateTy &Template); 3750 3751 DeclResult 3752 ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, TagUseKind TUK, 3753 SourceLocation KWLoc, 3754 CXXScopeSpec &SS, 3755 TemplateTy Template, 3756 SourceLocation TemplateNameLoc, 3757 SourceLocation LAngleLoc, 3758 ASTTemplateArgsPtr TemplateArgs, 3759 SourceLocation RAngleLoc, 3760 AttributeList *Attr, 3761 MultiTemplateParamsArg TemplateParameterLists); 3762 3763 Decl *ActOnTemplateDeclarator(Scope *S, 3764 MultiTemplateParamsArg TemplateParameterLists, 3765 Declarator &D); 3766 3767 Decl *ActOnStartOfFunctionTemplateDef(Scope *FnBodyScope, 3768 MultiTemplateParamsArg TemplateParameterLists, 3769 Declarator &D); 3770 3771 bool 3772 CheckSpecializationInstantiationRedecl(SourceLocation NewLoc, 3773 TemplateSpecializationKind NewTSK, 3774 NamedDecl *PrevDecl, 3775 TemplateSpecializationKind PrevTSK, 3776 SourceLocation PrevPtOfInstantiation, 3777 bool &SuppressNew); 3778 3779 bool CheckDependentFunctionTemplateSpecialization(FunctionDecl *FD, 3780 const TemplateArgumentListInfo &ExplicitTemplateArgs, 3781 LookupResult &Previous); 3782 3783 bool CheckFunctionTemplateSpecialization(FunctionDecl *FD, 3784 TemplateArgumentListInfo *ExplicitTemplateArgs, 3785 LookupResult &Previous); 3786 bool CheckMemberSpecialization(NamedDecl *Member, LookupResult &Previous); 3787 3788 DeclResult 3789 ActOnExplicitInstantiation(Scope *S, 3790 SourceLocation ExternLoc, 3791 SourceLocation TemplateLoc, 3792 unsigned TagSpec, 3793 SourceLocation KWLoc, 3794 const CXXScopeSpec &SS, 3795 TemplateTy Template, 3796 SourceLocation TemplateNameLoc, 3797 SourceLocation LAngleLoc, 3798 ASTTemplateArgsPtr TemplateArgs, 3799 SourceLocation RAngleLoc, 3800 AttributeList *Attr); 3801 3802 DeclResult 3803 ActOnExplicitInstantiation(Scope *S, 3804 SourceLocation ExternLoc, 3805 SourceLocation TemplateLoc, 3806 unsigned TagSpec, 3807 SourceLocation KWLoc, 3808 CXXScopeSpec &SS, 3809 IdentifierInfo *Name, 3810 SourceLocation NameLoc, 3811 AttributeList *Attr); 3812 3813 DeclResult ActOnExplicitInstantiation(Scope *S, 3814 SourceLocation ExternLoc, 3815 SourceLocation TemplateLoc, 3816 Declarator &D); 3817 3818 TemplateArgumentLoc 3819 SubstDefaultTemplateArgumentIfAvailable(TemplateDecl *Template, 3820 SourceLocation TemplateLoc, 3821 SourceLocation RAngleLoc, 3822 Decl *Param, 3823 SmallVectorImpl<TemplateArgument> &Converted); 3824 3825 /// \brief Specifies the context in which a particular template 3826 /// argument is being checked. 3827 enum CheckTemplateArgumentKind { 3828 /// \brief The template argument was specified in the code or was 3829 /// instantiated with some deduced template arguments. 3830 CTAK_Specified, 3831 3832 /// \brief The template argument was deduced via template argument 3833 /// deduction. 3834 CTAK_Deduced, 3835 3836 /// \brief The template argument was deduced from an array bound 3837 /// via template argument deduction. 3838 CTAK_DeducedFromArrayBound 3839 }; 3840 3841 bool CheckTemplateArgument(NamedDecl *Param, 3842 const TemplateArgumentLoc &Arg, 3843 NamedDecl *Template, 3844 SourceLocation TemplateLoc, 3845 SourceLocation RAngleLoc, 3846 unsigned ArgumentPackIndex, 3847 SmallVectorImpl<TemplateArgument> &Converted, 3848 CheckTemplateArgumentKind CTAK = CTAK_Specified); 3849 3850 /// \brief Check that the given template arguments can be be provided to 3851 /// the given template, converting the arguments along the way. 3852 /// 3853 /// \param Template The template to which the template arguments are being 3854 /// provided. 3855 /// 3856 /// \param TemplateLoc The location of the template name in the source. 3857 /// 3858 /// \param TemplateArgs The list of template arguments. If the template is 3859 /// a template template parameter, this function may extend the set of 3860 /// template arguments to also include substituted, defaulted template 3861 /// arguments. 3862 /// 3863 /// \param PartialTemplateArgs True if the list of template arguments is 3864 /// intentionally partial, e.g., because we're checking just the initial 3865 /// set of template arguments. 3866 /// 3867 /// \param Converted Will receive the converted, canonicalized template 3868 /// arguments. 3869 /// 3870 /// \returns True if an error occurred, false otherwise. 3871 bool CheckTemplateArgumentList(TemplateDecl *Template, 3872 SourceLocation TemplateLoc, 3873 TemplateArgumentListInfo &TemplateArgs, 3874 bool PartialTemplateArgs, 3875 SmallVectorImpl<TemplateArgument> &Converted); 3876 3877 bool CheckTemplateTypeArgument(TemplateTypeParmDecl *Param, 3878 const TemplateArgumentLoc &Arg, 3879 SmallVectorImpl<TemplateArgument> &Converted); 3880 3881 bool CheckTemplateArgument(TemplateTypeParmDecl *Param, 3882 TypeSourceInfo *Arg); 3883 bool CheckTemplateArgumentPointerToMember(Expr *Arg, 3884 TemplateArgument &Converted); 3885 ExprResult CheckTemplateArgument(NonTypeTemplateParmDecl *Param, 3886 QualType InstantiatedParamType, Expr *Arg, 3887 TemplateArgument &Converted, 3888 CheckTemplateArgumentKind CTAK = CTAK_Specified); 3889 bool CheckTemplateArgument(TemplateTemplateParmDecl *Param, 3890 const TemplateArgumentLoc &Arg); 3891 3892 ExprResult 3893 BuildExpressionFromDeclTemplateArgument(const TemplateArgument &Arg, 3894 QualType ParamType, 3895 SourceLocation Loc); 3896 ExprResult 3897 BuildExpressionFromIntegralTemplateArgument(const TemplateArgument &Arg, 3898 SourceLocation Loc); 3899 3900 /// \brief Enumeration describing how template parameter lists are compared 3901 /// for equality. 3902 enum TemplateParameterListEqualKind { 3903 /// \brief We are matching the template parameter lists of two templates 3904 /// that might be redeclarations. 3905 /// 3906 /// \code 3907 /// template<typename T> struct X; 3908 /// template<typename T> struct X; 3909 /// \endcode 3910 TPL_TemplateMatch, 3911 3912 /// \brief We are matching the template parameter lists of two template 3913 /// template parameters as part of matching the template parameter lists 3914 /// of two templates that might be redeclarations. 3915 /// 3916 /// \code 3917 /// template<template<int I> class TT> struct X; 3918 /// template<template<int Value> class Other> struct X; 3919 /// \endcode 3920 TPL_TemplateTemplateParmMatch, 3921 3922 /// \brief We are matching the template parameter lists of a template 3923 /// template argument against the template parameter lists of a template 3924 /// template parameter. 3925 /// 3926 /// \code 3927 /// template<template<int Value> class Metafun> struct X; 3928 /// template<int Value> struct integer_c; 3929 /// X<integer_c> xic; 3930 /// \endcode 3931 TPL_TemplateTemplateArgumentMatch 3932 }; 3933 3934 bool TemplateParameterListsAreEqual(TemplateParameterList *New, 3935 TemplateParameterList *Old, 3936 bool Complain, 3937 TemplateParameterListEqualKind Kind, 3938 SourceLocation TemplateArgLoc 3939 = SourceLocation()); 3940 3941 bool CheckTemplateDeclScope(Scope *S, TemplateParameterList *TemplateParams); 3942 3943 /// \brief Called when the parser has parsed a C++ typename 3944 /// specifier, e.g., "typename T::type". 3945 /// 3946 /// \param S The scope in which this typename type occurs. 3947 /// \param TypenameLoc the location of the 'typename' keyword 3948 /// \param SS the nested-name-specifier following the typename (e.g., 'T::'). 3949 /// \param II the identifier we're retrieving (e.g., 'type' in the example). 3950 /// \param IdLoc the location of the identifier. 3951 TypeResult 3952 ActOnTypenameType(Scope *S, SourceLocation TypenameLoc, 3953 const CXXScopeSpec &SS, const IdentifierInfo &II, 3954 SourceLocation IdLoc); 3955 3956 /// \brief Called when the parser has parsed a C++ typename 3957 /// specifier that ends in a template-id, e.g., 3958 /// "typename MetaFun::template apply<T1, T2>". 3959 /// 3960 /// \param S The scope in which this typename type occurs. 3961 /// \param TypenameLoc the location of the 'typename' keyword 3962 /// \param SS the nested-name-specifier following the typename (e.g., 'T::'). 3963 /// \param TemplateLoc the location of the 'template' keyword, if any. 3964 /// \param TemplateName The template name. 3965 /// \param TemplateNameLoc The location of the template name. 3966 /// \param LAngleLoc The location of the opening angle bracket ('<'). 3967 /// \param TemplateArgs The template arguments. 3968 /// \param RAngleLoc The location of the closing angle bracket ('>'). 3969 TypeResult 3970 ActOnTypenameType(Scope *S, SourceLocation TypenameLoc, 3971 const CXXScopeSpec &SS, 3972 SourceLocation TemplateLoc, 3973 TemplateTy Template, 3974 SourceLocation TemplateNameLoc, 3975 SourceLocation LAngleLoc, 3976 ASTTemplateArgsPtr TemplateArgs, 3977 SourceLocation RAngleLoc); 3978 3979 QualType CheckTypenameType(ElaboratedTypeKeyword Keyword, 3980 SourceLocation KeywordLoc, 3981 NestedNameSpecifierLoc QualifierLoc, 3982 const IdentifierInfo &II, 3983 SourceLocation IILoc); 3984 3985 TypeSourceInfo *RebuildTypeInCurrentInstantiation(TypeSourceInfo *T, 3986 SourceLocation Loc, 3987 DeclarationName Name); 3988 bool RebuildNestedNameSpecifierInCurrentInstantiation(CXXScopeSpec &SS); 3989 3990 ExprResult RebuildExprInCurrentInstantiation(Expr *E); 3991 3992 std::string 3993 getTemplateArgumentBindingsText(const TemplateParameterList *Params, 3994 const TemplateArgumentList &Args); 3995 3996 std::string 3997 getTemplateArgumentBindingsText(const TemplateParameterList *Params, 3998 const TemplateArgument *Args, 3999 unsigned NumArgs); 4000 4001 //===--------------------------------------------------------------------===// 4002 // C++ Variadic Templates (C++0x [temp.variadic]) 4003 //===--------------------------------------------------------------------===// 4004 4005 /// \brief The context in which an unexpanded parameter pack is 4006 /// being diagnosed. 4007 /// 4008 /// Note that the values of this enumeration line up with the first 4009 /// argument to the \c err_unexpanded_parameter_pack diagnostic. 4010 enum UnexpandedParameterPackContext { 4011 /// \brief An arbitrary expression. 4012 UPPC_Expression = 0, 4013 4014 /// \brief The base type of a class type. 4015 UPPC_BaseType, 4016 4017 /// \brief The type of an arbitrary declaration. 4018 UPPC_DeclarationType, 4019 4020 /// \brief The type of a data member. 4021 UPPC_DataMemberType, 4022 4023 /// \brief The size of a bit-field. 4024 UPPC_BitFieldWidth, 4025 4026 /// \brief The expression in a static assertion. 4027 UPPC_StaticAssertExpression, 4028 4029 /// \brief The fixed underlying type of an enumeration. 4030 UPPC_FixedUnderlyingType, 4031 4032 /// \brief The enumerator value. 4033 UPPC_EnumeratorValue, 4034 4035 /// \brief A using declaration. 4036 UPPC_UsingDeclaration, 4037 4038 /// \brief A friend declaration. 4039 UPPC_FriendDeclaration, 4040 4041 /// \brief A declaration qualifier. 4042 UPPC_DeclarationQualifier, 4043 4044 /// \brief An initializer. 4045 UPPC_Initializer, 4046 4047 /// \brief A default argument. 4048 UPPC_DefaultArgument, 4049 4050 /// \brief The type of a non-type template parameter. 4051 UPPC_NonTypeTemplateParameterType, 4052 4053 /// \brief The type of an exception. 4054 UPPC_ExceptionType, 4055 4056 /// \brief Partial specialization. 4057 UPPC_PartialSpecialization 4058 }; 4059 4060 /// \brief If the given type contains an unexpanded parameter pack, 4061 /// diagnose the error. 4062 /// 4063 /// \param Loc The source location where a diagnostc should be emitted. 4064 /// 4065 /// \param T The type that is being checked for unexpanded parameter 4066 /// packs. 4067 /// 4068 /// \returns true if an error occurred, false otherwise. 4069 bool DiagnoseUnexpandedParameterPack(SourceLocation Loc, TypeSourceInfo *T, 4070 UnexpandedParameterPackContext UPPC); 4071 4072 /// \brief If the given expression contains an unexpanded parameter 4073 /// pack, diagnose the error. 4074 /// 4075 /// \param E The expression that is being checked for unexpanded 4076 /// parameter packs. 4077 /// 4078 /// \returns true if an error occurred, false otherwise. 4079 bool DiagnoseUnexpandedParameterPack(Expr *E, 4080 UnexpandedParameterPackContext UPPC = UPPC_Expression); 4081 4082 /// \brief If the given nested-name-specifier contains an unexpanded 4083 /// parameter pack, diagnose the error. 4084 /// 4085 /// \param SS The nested-name-specifier that is being checked for 4086 /// unexpanded parameter packs. 4087 /// 4088 /// \returns true if an error occurred, false otherwise. 4089 bool DiagnoseUnexpandedParameterPack(const CXXScopeSpec &SS, 4090 UnexpandedParameterPackContext UPPC); 4091 4092 /// \brief If the given name contains an unexpanded parameter pack, 4093 /// diagnose the error. 4094 /// 4095 /// \param NameInfo The name (with source location information) that 4096 /// is being checked for unexpanded parameter packs. 4097 /// 4098 /// \returns true if an error occurred, false otherwise. 4099 bool DiagnoseUnexpandedParameterPack(const DeclarationNameInfo &NameInfo, 4100 UnexpandedParameterPackContext UPPC); 4101 4102 /// \brief If the given template name contains an unexpanded parameter pack, 4103 /// diagnose the error. 4104 /// 4105 /// \param Loc The location of the template name. 4106 /// 4107 /// \param Template The template name that is being checked for unexpanded 4108 /// parameter packs. 4109 /// 4110 /// \returns true if an error occurred, false otherwise. 4111 bool DiagnoseUnexpandedParameterPack(SourceLocation Loc, 4112 TemplateName Template, 4113 UnexpandedParameterPackContext UPPC); 4114 4115 /// \brief If the given template argument contains an unexpanded parameter 4116 /// pack, diagnose the error. 4117 /// 4118 /// \param Arg The template argument that is being checked for unexpanded 4119 /// parameter packs. 4120 /// 4121 /// \returns true if an error occurred, false otherwise. 4122 bool DiagnoseUnexpandedParameterPack(TemplateArgumentLoc Arg, 4123 UnexpandedParameterPackContext UPPC); 4124 4125 /// \brief Collect the set of unexpanded parameter packs within the given 4126 /// template argument. 4127 /// 4128 /// \param Arg The template argument that will be traversed to find 4129 /// unexpanded parameter packs. 4130 void collectUnexpandedParameterPacks(TemplateArgument Arg, 4131 SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); 4132 4133 /// \brief Collect the set of unexpanded parameter packs within the given 4134 /// template argument. 4135 /// 4136 /// \param Arg The template argument that will be traversed to find 4137 /// unexpanded parameter packs. 4138 void collectUnexpandedParameterPacks(TemplateArgumentLoc Arg, 4139 SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); 4140 4141 /// \brief Collect the set of unexpanded parameter packs within the given 4142 /// type. 4143 /// 4144 /// \param T The type that will be traversed to find 4145 /// unexpanded parameter packs. 4146 void collectUnexpandedParameterPacks(QualType T, 4147 SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); 4148 4149 /// \brief Collect the set of unexpanded parameter packs within the given 4150 /// type. 4151 /// 4152 /// \param TL The type that will be traversed to find 4153 /// unexpanded parameter packs. 4154 void collectUnexpandedParameterPacks(TypeLoc TL, 4155 SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); 4156 4157 /// \brief Invoked when parsing a template argument followed by an 4158 /// ellipsis, which creates a pack expansion. 4159 /// 4160 /// \param Arg The template argument preceding the ellipsis, which 4161 /// may already be invalid. 4162 /// 4163 /// \param EllipsisLoc The location of the ellipsis. 4164 ParsedTemplateArgument ActOnPackExpansion(const ParsedTemplateArgument &Arg, 4165 SourceLocation EllipsisLoc); 4166 4167 /// \brief Invoked when parsing a type followed by an ellipsis, which 4168 /// creates a pack expansion. 4169 /// 4170 /// \param Type The type preceding the ellipsis, which will become 4171 /// the pattern of the pack expansion. 4172 /// 4173 /// \param EllipsisLoc The location of the ellipsis. 4174 TypeResult ActOnPackExpansion(ParsedType Type, SourceLocation EllipsisLoc); 4175 4176 /// \brief Construct a pack expansion type from the pattern of the pack 4177 /// expansion. 4178 TypeSourceInfo *CheckPackExpansion(TypeSourceInfo *Pattern, 4179 SourceLocation EllipsisLoc, 4180 llvm::Optional<unsigned> NumExpansions); 4181 4182 /// \brief Construct a pack expansion type from the pattern of the pack 4183 /// expansion. 4184 QualType CheckPackExpansion(QualType Pattern, 4185 SourceRange PatternRange, 4186 SourceLocation EllipsisLoc, 4187 llvm::Optional<unsigned> NumExpansions); 4188 4189 /// \brief Invoked when parsing an expression followed by an ellipsis, which 4190 /// creates a pack expansion. 4191 /// 4192 /// \param Pattern The expression preceding the ellipsis, which will become 4193 /// the pattern of the pack expansion. 4194 /// 4195 /// \param EllipsisLoc The location of the ellipsis. 4196 ExprResult ActOnPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc); 4197 4198 /// \brief Invoked when parsing an expression followed by an ellipsis, which 4199 /// creates a pack expansion. 4200 /// 4201 /// \param Pattern The expression preceding the ellipsis, which will become 4202 /// the pattern of the pack expansion. 4203 /// 4204 /// \param EllipsisLoc The location of the ellipsis. 4205 ExprResult CheckPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc, 4206 llvm::Optional<unsigned> NumExpansions); 4207 4208 /// \brief Determine whether we could expand a pack expansion with the 4209 /// given set of parameter packs into separate arguments by repeatedly 4210 /// transforming the pattern. 4211 /// 4212 /// \param EllipsisLoc The location of the ellipsis that identifies the 4213 /// pack expansion. 4214 /// 4215 /// \param PatternRange The source range that covers the entire pattern of 4216 /// the pack expansion. 4217 /// 4218 /// \param Unexpanded The set of unexpanded parameter packs within the 4219 /// pattern. 4220 /// 4221 /// \param NumUnexpanded The number of unexpanded parameter packs in 4222 /// \p Unexpanded. 4223 /// 4224 /// \param ShouldExpand Will be set to \c true if the transformer should 4225 /// expand the corresponding pack expansions into separate arguments. When 4226 /// set, \c NumExpansions must also be set. 4227 /// 4228 /// \param RetainExpansion Whether the caller should add an unexpanded 4229 /// pack expansion after all of the expanded arguments. This is used 4230 /// when extending explicitly-specified template argument packs per 4231 /// C++0x [temp.arg.explicit]p9. 4232 /// 4233 /// \param NumExpansions The number of separate arguments that will be in 4234 /// the expanded form of the corresponding pack expansion. This is both an 4235 /// input and an output parameter, which can be set by the caller if the 4236 /// number of expansions is known a priori (e.g., due to a prior substitution) 4237 /// and will be set by the callee when the number of expansions is known. 4238 /// The callee must set this value when \c ShouldExpand is \c true; it may 4239 /// set this value in other cases. 4240 /// 4241 /// \returns true if an error occurred (e.g., because the parameter packs 4242 /// are to be instantiated with arguments of different lengths), false 4243 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions) 4244 /// must be set. 4245 bool CheckParameterPacksForExpansion(SourceLocation EllipsisLoc, 4246 SourceRange PatternRange, 4247 const UnexpandedParameterPack *Unexpanded, 4248 unsigned NumUnexpanded, 4249 const MultiLevelTemplateArgumentList &TemplateArgs, 4250 bool &ShouldExpand, 4251 bool &RetainExpansion, 4252 llvm::Optional<unsigned> &NumExpansions); 4253 4254 /// \brief Determine the number of arguments in the given pack expansion 4255 /// type. 4256 /// 4257 /// This routine already assumes that the pack expansion type can be 4258 /// expanded and that the number of arguments in the expansion is 4259 /// consistent across all of the unexpanded parameter packs in its pattern. 4260 unsigned getNumArgumentsInExpansion(QualType T, 4261 const MultiLevelTemplateArgumentList &TemplateArgs); 4262 4263 /// \brief Determine whether the given declarator contains any unexpanded 4264 /// parameter packs. 4265 /// 4266 /// This routine is used by the parser to disambiguate function declarators 4267 /// with an ellipsis prior to the ')', e.g., 4268 /// 4269 /// \code 4270 /// void f(T...); 4271 /// \endcode 4272 /// 4273 /// To determine whether we have an (unnamed) function parameter pack or 4274 /// a variadic function. 4275 /// 4276 /// \returns true if the declarator contains any unexpanded parameter packs, 4277 /// false otherwise. 4278 bool containsUnexpandedParameterPacks(Declarator &D); 4279 4280 //===--------------------------------------------------------------------===// 4281 // C++ Template Argument Deduction (C++ [temp.deduct]) 4282 //===--------------------------------------------------------------------===// 4283 4284 /// \brief Describes the result of template argument deduction. 4285 /// 4286 /// The TemplateDeductionResult enumeration describes the result of 4287 /// template argument deduction, as returned from 4288 /// DeduceTemplateArguments(). The separate TemplateDeductionInfo 4289 /// structure provides additional information about the results of 4290 /// template argument deduction, e.g., the deduced template argument 4291 /// list (if successful) or the specific template parameters or 4292 /// deduced arguments that were involved in the failure. 4293 enum TemplateDeductionResult { 4294 /// \brief Template argument deduction was successful. 4295 TDK_Success = 0, 4296 /// \brief Template argument deduction exceeded the maximum template 4297 /// instantiation depth (which has already been diagnosed). 4298 TDK_InstantiationDepth, 4299 /// \brief Template argument deduction did not deduce a value 4300 /// for every template parameter. 4301 TDK_Incomplete, 4302 /// \brief Template argument deduction produced inconsistent 4303 /// deduced values for the given template parameter. 4304 TDK_Inconsistent, 4305 /// \brief Template argument deduction failed due to inconsistent 4306 /// cv-qualifiers on a template parameter type that would 4307 /// otherwise be deduced, e.g., we tried to deduce T in "const T" 4308 /// but were given a non-const "X". 4309 TDK_Underqualified, 4310 /// \brief Substitution of the deduced template argument values 4311 /// resulted in an error. 4312 TDK_SubstitutionFailure, 4313 /// \brief Substitution of the deduced template argument values 4314 /// into a non-deduced context produced a type or value that 4315 /// produces a type that does not match the original template 4316 /// arguments provided. 4317 TDK_NonDeducedMismatch, 4318 /// \brief When performing template argument deduction for a function 4319 /// template, there were too many call arguments. 4320 TDK_TooManyArguments, 4321 /// \brief When performing template argument deduction for a function 4322 /// template, there were too few call arguments. 4323 TDK_TooFewArguments, 4324 /// \brief The explicitly-specified template arguments were not valid 4325 /// template arguments for the given template. 4326 TDK_InvalidExplicitArguments, 4327 /// \brief The arguments included an overloaded function name that could 4328 /// not be resolved to a suitable function. 4329 TDK_FailedOverloadResolution 4330 }; 4331 4332 TemplateDeductionResult 4333 DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial, 4334 const TemplateArgumentList &TemplateArgs, 4335 sema::TemplateDeductionInfo &Info); 4336 4337 TemplateDeductionResult 4338 SubstituteExplicitTemplateArguments(FunctionTemplateDecl *FunctionTemplate, 4339 TemplateArgumentListInfo &ExplicitTemplateArgs, 4340 SmallVectorImpl<DeducedTemplateArgument> &Deduced, 4341 SmallVectorImpl<QualType> &ParamTypes, 4342 QualType *FunctionType, 4343 sema::TemplateDeductionInfo &Info); 4344 4345 /// brief A function argument from which we performed template argument 4346 // deduction for a call. 4347 struct OriginalCallArg { 4348 OriginalCallArg(QualType OriginalParamType, 4349 unsigned ArgIdx, 4350 QualType OriginalArgType) 4351 : OriginalParamType(OriginalParamType), ArgIdx(ArgIdx), 4352 OriginalArgType(OriginalArgType) { } 4353 4354 QualType OriginalParamType; 4355 unsigned ArgIdx; 4356 QualType OriginalArgType; 4357 }; 4358 4359 TemplateDeductionResult 4360 FinishTemplateArgumentDeduction(FunctionTemplateDecl *FunctionTemplate, 4361 SmallVectorImpl<DeducedTemplateArgument> &Deduced, 4362 unsigned NumExplicitlySpecified, 4363 FunctionDecl *&Specialization, 4364 sema::TemplateDeductionInfo &Info, 4365 SmallVectorImpl<OriginalCallArg> const *OriginalCallArgs = 0); 4366 4367 TemplateDeductionResult 4368 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, 4369 TemplateArgumentListInfo *ExplicitTemplateArgs, 4370 Expr **Args, unsigned NumArgs, 4371 FunctionDecl *&Specialization, 4372 sema::TemplateDeductionInfo &Info); 4373 4374 TemplateDeductionResult 4375 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, 4376 TemplateArgumentListInfo *ExplicitTemplateArgs, 4377 QualType ArgFunctionType, 4378 FunctionDecl *&Specialization, 4379 sema::TemplateDeductionInfo &Info); 4380 4381 TemplateDeductionResult 4382 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, 4383 QualType ToType, 4384 CXXConversionDecl *&Specialization, 4385 sema::TemplateDeductionInfo &Info); 4386 4387 TemplateDeductionResult 4388 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, 4389 TemplateArgumentListInfo *ExplicitTemplateArgs, 4390 FunctionDecl *&Specialization, 4391 sema::TemplateDeductionInfo &Info); 4392 4393 bool DeduceAutoType(TypeSourceInfo *AutoType, Expr *Initializer, 4394 TypeSourceInfo *&Result); 4395 4396 FunctionTemplateDecl *getMoreSpecializedTemplate(FunctionTemplateDecl *FT1, 4397 FunctionTemplateDecl *FT2, 4398 SourceLocation Loc, 4399 TemplatePartialOrderingContext TPOC, 4400 unsigned NumCallArguments); 4401 UnresolvedSetIterator getMostSpecialized(UnresolvedSetIterator SBegin, 4402 UnresolvedSetIterator SEnd, 4403 TemplatePartialOrderingContext TPOC, 4404 unsigned NumCallArguments, 4405 SourceLocation Loc, 4406 const PartialDiagnostic &NoneDiag, 4407 const PartialDiagnostic &AmbigDiag, 4408 const PartialDiagnostic &CandidateDiag, 4409 bool Complain = true); 4410 4411 ClassTemplatePartialSpecializationDecl * 4412 getMoreSpecializedPartialSpecialization( 4413 ClassTemplatePartialSpecializationDecl *PS1, 4414 ClassTemplatePartialSpecializationDecl *PS2, 4415 SourceLocation Loc); 4416 4417 void MarkUsedTemplateParameters(const TemplateArgumentList &TemplateArgs, 4418 bool OnlyDeduced, 4419 unsigned Depth, 4420 SmallVectorImpl<bool> &Used); 4421 void MarkDeducedTemplateParameters(FunctionTemplateDecl *FunctionTemplate, 4422 SmallVectorImpl<bool> &Deduced); 4423 4424 //===--------------------------------------------------------------------===// 4425 // C++ Template Instantiation 4426 // 4427 4428 MultiLevelTemplateArgumentList getTemplateInstantiationArgs(NamedDecl *D, 4429 const TemplateArgumentList *Innermost = 0, 4430 bool RelativeToPrimary = false, 4431 const FunctionDecl *Pattern = 0); 4432 4433 /// \brief A template instantiation that is currently in progress. 4434 struct ActiveTemplateInstantiation { 4435 /// \brief The kind of template instantiation we are performing 4436 enum InstantiationKind { 4437 /// We are instantiating a template declaration. The entity is 4438 /// the declaration we're instantiating (e.g., a CXXRecordDecl). 4439 TemplateInstantiation, 4440 4441 /// We are instantiating a default argument for a template 4442 /// parameter. The Entity is the template, and 4443 /// TemplateArgs/NumTemplateArguments provides the template 4444 /// arguments as specified. 4445 /// FIXME: Use a TemplateArgumentList 4446 DefaultTemplateArgumentInstantiation, 4447 4448 /// We are instantiating a default argument for a function. 4449 /// The Entity is the ParmVarDecl, and TemplateArgs/NumTemplateArgs 4450 /// provides the template arguments as specified. 4451 DefaultFunctionArgumentInstantiation, 4452 4453 /// We are substituting explicit template arguments provided for 4454 /// a function template. The entity is a FunctionTemplateDecl. 4455 ExplicitTemplateArgumentSubstitution, 4456 4457 /// We are substituting template argument determined as part of 4458 /// template argument deduction for either a class template 4459 /// partial specialization or a function template. The 4460 /// Entity is either a ClassTemplatePartialSpecializationDecl or 4461 /// a FunctionTemplateDecl. 4462 DeducedTemplateArgumentSubstitution, 4463 4464 /// We are substituting prior template arguments into a new 4465 /// template parameter. The template parameter itself is either a 4466 /// NonTypeTemplateParmDecl or a TemplateTemplateParmDecl. 4467 PriorTemplateArgumentSubstitution, 4468 4469 /// We are checking the validity of a default template argument that 4470 /// has been used when naming a template-id. 4471 DefaultTemplateArgumentChecking 4472 } Kind; 4473 4474 /// \brief The point of instantiation within the source code. 4475 SourceLocation PointOfInstantiation; 4476 4477 /// \brief The template (or partial specialization) in which we are 4478 /// performing the instantiation, for substitutions of prior template 4479 /// arguments. 4480 NamedDecl *Template; 4481 4482 /// \brief The entity that is being instantiated. 4483 uintptr_t Entity; 4484 4485 /// \brief The list of template arguments we are substituting, if they 4486 /// are not part of the entity. 4487 const TemplateArgument *TemplateArgs; 4488 4489 /// \brief The number of template arguments in TemplateArgs. 4490 unsigned NumTemplateArgs; 4491 4492 /// \brief The template deduction info object associated with the 4493 /// substitution or checking of explicit or deduced template arguments. 4494 sema::TemplateDeductionInfo *DeductionInfo; 4495 4496 /// \brief The source range that covers the construct that cause 4497 /// the instantiation, e.g., the template-id that causes a class 4498 /// template instantiation. 4499 SourceRange InstantiationRange; 4500 4501 ActiveTemplateInstantiation() 4502 : Kind(TemplateInstantiation), Template(0), Entity(0), TemplateArgs(0), 4503 NumTemplateArgs(0), DeductionInfo(0) {} 4504 4505 /// \brief Determines whether this template is an actual instantiation 4506 /// that should be counted toward the maximum instantiation depth. 4507 bool isInstantiationRecord() const; 4508 4509 friend bool operator==(const ActiveTemplateInstantiation &X, 4510 const ActiveTemplateInstantiation &Y) { 4511 if (X.Kind != Y.Kind) 4512 return false; 4513 4514 if (X.Entity != Y.Entity) 4515 return false; 4516 4517 switch (X.Kind) { 4518 case TemplateInstantiation: 4519 return true; 4520 4521 case PriorTemplateArgumentSubstitution: 4522 case DefaultTemplateArgumentChecking: 4523 if (X.Template != Y.Template) 4524 return false; 4525 4526 // Fall through 4527 4528 case DefaultTemplateArgumentInstantiation: 4529 case ExplicitTemplateArgumentSubstitution: 4530 case DeducedTemplateArgumentSubstitution: 4531 case DefaultFunctionArgumentInstantiation: 4532 return X.TemplateArgs == Y.TemplateArgs; 4533 4534 } 4535 4536 return true; 4537 } 4538 4539 friend bool operator!=(const ActiveTemplateInstantiation &X, 4540 const ActiveTemplateInstantiation &Y) { 4541 return !(X == Y); 4542 } 4543 }; 4544 4545 /// \brief List of active template instantiations. 4546 /// 4547 /// This vector is treated as a stack. As one template instantiation 4548 /// requires another template instantiation, additional 4549 /// instantiations are pushed onto the stack up to a 4550 /// user-configurable limit LangOptions::InstantiationDepth. 4551 SmallVector<ActiveTemplateInstantiation, 16> 4552 ActiveTemplateInstantiations; 4553 4554 /// \brief Whether we are in a SFINAE context that is not associated with 4555 /// template instantiation. 4556 /// 4557 /// This is used when setting up a SFINAE trap (\c see SFINAETrap) outside 4558 /// of a template instantiation or template argument deduction. 4559 bool InNonInstantiationSFINAEContext; 4560 4561 /// \brief The number of ActiveTemplateInstantiation entries in 4562 /// \c ActiveTemplateInstantiations that are not actual instantiations and, 4563 /// therefore, should not be counted as part of the instantiation depth. 4564 unsigned NonInstantiationEntries; 4565 4566 /// \brief The last template from which a template instantiation 4567 /// error or warning was produced. 4568 /// 4569 /// This value is used to suppress printing of redundant template 4570 /// instantiation backtraces when there are multiple errors in the 4571 /// same instantiation. FIXME: Does this belong in Sema? It's tough 4572 /// to implement it anywhere else. 4573 ActiveTemplateInstantiation LastTemplateInstantiationErrorContext; 4574 4575 /// \brief The current index into pack expansion arguments that will be 4576 /// used for substitution of parameter packs. 4577 /// 4578 /// The pack expansion index will be -1 to indicate that parameter packs 4579 /// should be instantiated as themselves. Otherwise, the index specifies 4580 /// which argument within the parameter pack will be used for substitution. 4581 int ArgumentPackSubstitutionIndex; 4582 4583 /// \brief RAII object used to change the argument pack substitution index 4584 /// within a \c Sema object. 4585 /// 4586 /// See \c ArgumentPackSubstitutionIndex for more information. 4587 class ArgumentPackSubstitutionIndexRAII { 4588 Sema &Self; 4589 int OldSubstitutionIndex; 4590 4591 public: 4592 ArgumentPackSubstitutionIndexRAII(Sema &Self, int NewSubstitutionIndex) 4593 : Self(Self), OldSubstitutionIndex(Self.ArgumentPackSubstitutionIndex) { 4594 Self.ArgumentPackSubstitutionIndex = NewSubstitutionIndex; 4595 } 4596 4597 ~ArgumentPackSubstitutionIndexRAII() { 4598 Self.ArgumentPackSubstitutionIndex = OldSubstitutionIndex; 4599 } 4600 }; 4601 4602 friend class ArgumentPackSubstitutionRAII; 4603 4604 /// \brief The stack of calls expression undergoing template instantiation. 4605 /// 4606 /// The top of this stack is used by a fixit instantiating unresolved 4607 /// function calls to fix the AST to match the textual change it prints. 4608 SmallVector<CallExpr *, 8> CallsUndergoingInstantiation; 4609 4610 /// \brief For each declaration that involved template argument deduction, the 4611 /// set of diagnostics that were suppressed during that template argument 4612 /// deduction. 4613 /// 4614 /// FIXME: Serialize this structure to the AST file. 4615 llvm::DenseMap<Decl *, SmallVector<PartialDiagnosticAt, 1> > 4616 SuppressedDiagnostics; 4617 4618 /// \brief A stack object to be created when performing template 4619 /// instantiation. 4620 /// 4621 /// Construction of an object of type \c InstantiatingTemplate 4622 /// pushes the current instantiation onto the stack of active 4623 /// instantiations. If the size of this stack exceeds the maximum 4624 /// number of recursive template instantiations, construction 4625 /// produces an error and evaluates true. 4626 /// 4627 /// Destruction of this object will pop the named instantiation off 4628 /// the stack. 4629 struct InstantiatingTemplate { 4630 /// \brief Note that we are instantiating a class template, 4631 /// function template, or a member thereof. 4632 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 4633 Decl *Entity, 4634 SourceRange InstantiationRange = SourceRange()); 4635 4636 /// \brief Note that we are instantiating a default argument in a 4637 /// template-id. 4638 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 4639 TemplateDecl *Template, 4640 const TemplateArgument *TemplateArgs, 4641 unsigned NumTemplateArgs, 4642 SourceRange InstantiationRange = SourceRange()); 4643 4644 /// \brief Note that we are instantiating a default argument in a 4645 /// template-id. 4646 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 4647 FunctionTemplateDecl *FunctionTemplate, 4648 const TemplateArgument *TemplateArgs, 4649 unsigned NumTemplateArgs, 4650 ActiveTemplateInstantiation::InstantiationKind Kind, 4651 sema::TemplateDeductionInfo &DeductionInfo, 4652 SourceRange InstantiationRange = SourceRange()); 4653 4654 /// \brief Note that we are instantiating as part of template 4655 /// argument deduction for a class template partial 4656 /// specialization. 4657 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 4658 ClassTemplatePartialSpecializationDecl *PartialSpec, 4659 const TemplateArgument *TemplateArgs, 4660 unsigned NumTemplateArgs, 4661 sema::TemplateDeductionInfo &DeductionInfo, 4662 SourceRange InstantiationRange = SourceRange()); 4663 4664 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 4665 ParmVarDecl *Param, 4666 const TemplateArgument *TemplateArgs, 4667 unsigned NumTemplateArgs, 4668 SourceRange InstantiationRange = SourceRange()); 4669 4670 /// \brief Note that we are substituting prior template arguments into a 4671 /// non-type or template template parameter. 4672 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 4673 NamedDecl *Template, 4674 NonTypeTemplateParmDecl *Param, 4675 const TemplateArgument *TemplateArgs, 4676 unsigned NumTemplateArgs, 4677 SourceRange InstantiationRange); 4678 4679 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 4680 NamedDecl *Template, 4681 TemplateTemplateParmDecl *Param, 4682 const TemplateArgument *TemplateArgs, 4683 unsigned NumTemplateArgs, 4684 SourceRange InstantiationRange); 4685 4686 /// \brief Note that we are checking the default template argument 4687 /// against the template parameter for a given template-id. 4688 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 4689 TemplateDecl *Template, 4690 NamedDecl *Param, 4691 const TemplateArgument *TemplateArgs, 4692 unsigned NumTemplateArgs, 4693 SourceRange InstantiationRange); 4694 4695 4696 /// \brief Note that we have finished instantiating this template. 4697 void Clear(); 4698 4699 ~InstantiatingTemplate() { Clear(); } 4700 4701 /// \brief Determines whether we have exceeded the maximum 4702 /// recursive template instantiations. 4703 operator bool() const { return Invalid; } 4704 4705 private: 4706 Sema &SemaRef; 4707 bool Invalid; 4708 bool SavedInNonInstantiationSFINAEContext; 4709 bool CheckInstantiationDepth(SourceLocation PointOfInstantiation, 4710 SourceRange InstantiationRange); 4711 4712 InstantiatingTemplate(const InstantiatingTemplate&); // not implemented 4713 4714 InstantiatingTemplate& 4715 operator=(const InstantiatingTemplate&); // not implemented 4716 }; 4717 4718 void PrintInstantiationStack(); 4719 4720 /// \brief Determines whether we are currently in a context where 4721 /// template argument substitution failures are not considered 4722 /// errors. 4723 /// 4724 /// \returns An empty \c llvm::Optional if we're not in a SFINAE context. 4725 /// Otherwise, contains a pointer that, if non-NULL, contains the nearest 4726 /// template-deduction context object, which can be used to capture 4727 /// diagnostics that will be suppressed. 4728 llvm::Optional<sema::TemplateDeductionInfo *> isSFINAEContext() const; 4729 4730 /// \brief RAII class used to determine whether SFINAE has 4731 /// trapped any errors that occur during template argument 4732 /// deduction.` 4733 class SFINAETrap { 4734 Sema &SemaRef; 4735 unsigned PrevSFINAEErrors; 4736 bool PrevInNonInstantiationSFINAEContext; 4737 bool PrevAccessCheckingSFINAE; 4738 4739 public: 4740 explicit SFINAETrap(Sema &SemaRef, bool AccessCheckingSFINAE = false) 4741 : SemaRef(SemaRef), PrevSFINAEErrors(SemaRef.NumSFINAEErrors), 4742 PrevInNonInstantiationSFINAEContext( 4743 SemaRef.InNonInstantiationSFINAEContext), 4744 PrevAccessCheckingSFINAE(SemaRef.AccessCheckingSFINAE) 4745 { 4746 if (!SemaRef.isSFINAEContext()) 4747 SemaRef.InNonInstantiationSFINAEContext = true; 4748 SemaRef.AccessCheckingSFINAE = AccessCheckingSFINAE; 4749 } 4750 4751 ~SFINAETrap() { 4752 SemaRef.NumSFINAEErrors = PrevSFINAEErrors; 4753 SemaRef.InNonInstantiationSFINAEContext 4754 = PrevInNonInstantiationSFINAEContext; 4755 SemaRef.AccessCheckingSFINAE = PrevAccessCheckingSFINAE; 4756 } 4757 4758 /// \brief Determine whether any SFINAE errors have been trapped. 4759 bool hasErrorOccurred() const { 4760 return SemaRef.NumSFINAEErrors > PrevSFINAEErrors; 4761 } 4762 }; 4763 4764 /// \brief The current instantiation scope used to store local 4765 /// variables. 4766 LocalInstantiationScope *CurrentInstantiationScope; 4767 4768 /// \brief The number of typos corrected by CorrectTypo. 4769 unsigned TyposCorrected; 4770 4771 typedef llvm::DenseMap<IdentifierInfo *, TypoCorrection> 4772 UnqualifiedTyposCorrectedMap; 4773 4774 /// \brief A cache containing the results of typo correction for unqualified 4775 /// name lookup. 4776 /// 4777 /// The string is the string that we corrected to (which may be empty, if 4778 /// there was no correction), while the boolean will be true when the 4779 /// string represents a keyword. 4780 UnqualifiedTyposCorrectedMap UnqualifiedTyposCorrected; 4781 4782 /// \brief Worker object for performing CFG-based warnings. 4783 sema::AnalysisBasedWarnings AnalysisWarnings; 4784 4785 /// \brief An entity for which implicit template instantiation is required. 4786 /// 4787 /// The source location associated with the declaration is the first place in 4788 /// the source code where the declaration was "used". It is not necessarily 4789 /// the point of instantiation (which will be either before or after the 4790 /// namespace-scope declaration that triggered this implicit instantiation), 4791 /// However, it is the location that diagnostics should generally refer to, 4792 /// because users will need to know what code triggered the instantiation. 4793 typedef std::pair<ValueDecl *, SourceLocation> PendingImplicitInstantiation; 4794 4795 /// \brief The queue of implicit template instantiations that are required 4796 /// but have not yet been performed. 4797 std::deque<PendingImplicitInstantiation> PendingInstantiations; 4798 4799 /// \brief The queue of implicit template instantiations that are required 4800 /// and must be performed within the current local scope. 4801 /// 4802 /// This queue is only used for member functions of local classes in 4803 /// templates, which must be instantiated in the same scope as their 4804 /// enclosing function, so that they can reference function-local 4805 /// types, static variables, enumerators, etc. 4806 std::deque<PendingImplicitInstantiation> PendingLocalImplicitInstantiations; 4807 4808 void PerformPendingInstantiations(bool LocalOnly = false); 4809 4810 TypeSourceInfo *SubstType(TypeSourceInfo *T, 4811 const MultiLevelTemplateArgumentList &TemplateArgs, 4812 SourceLocation Loc, DeclarationName Entity); 4813 4814 QualType SubstType(QualType T, 4815 const MultiLevelTemplateArgumentList &TemplateArgs, 4816 SourceLocation Loc, DeclarationName Entity); 4817 4818 TypeSourceInfo *SubstType(TypeLoc TL, 4819 const MultiLevelTemplateArgumentList &TemplateArgs, 4820 SourceLocation Loc, DeclarationName Entity); 4821 4822 TypeSourceInfo *SubstFunctionDeclType(TypeSourceInfo *T, 4823 const MultiLevelTemplateArgumentList &TemplateArgs, 4824 SourceLocation Loc, 4825 DeclarationName Entity); 4826 ParmVarDecl *SubstParmVarDecl(ParmVarDecl *D, 4827 const MultiLevelTemplateArgumentList &TemplateArgs, 4828 int indexAdjustment, 4829 llvm::Optional<unsigned> NumExpansions); 4830 bool SubstParmTypes(SourceLocation Loc, 4831 ParmVarDecl **Params, unsigned NumParams, 4832 const MultiLevelTemplateArgumentList &TemplateArgs, 4833 SmallVectorImpl<QualType> &ParamTypes, 4834 SmallVectorImpl<ParmVarDecl *> *OutParams = 0); 4835 ExprResult SubstExpr(Expr *E, 4836 const MultiLevelTemplateArgumentList &TemplateArgs); 4837 4838 /// \brief Substitute the given template arguments into a list of 4839 /// expressions, expanding pack expansions if required. 4840 /// 4841 /// \param Exprs The list of expressions to substitute into. 4842 /// 4843 /// \param NumExprs The number of expressions in \p Exprs. 4844 /// 4845 /// \param IsCall Whether this is some form of call, in which case 4846 /// default arguments will be dropped. 4847 /// 4848 /// \param TemplateArgs The set of template arguments to substitute. 4849 /// 4850 /// \param Outputs Will receive all of the substituted arguments. 4851 /// 4852 /// \returns true if an error occurred, false otherwise. 4853 bool SubstExprs(Expr **Exprs, unsigned NumExprs, bool IsCall, 4854 const MultiLevelTemplateArgumentList &TemplateArgs, 4855 SmallVectorImpl<Expr *> &Outputs); 4856 4857 StmtResult SubstStmt(Stmt *S, 4858 const MultiLevelTemplateArgumentList &TemplateArgs); 4859 4860 Decl *SubstDecl(Decl *D, DeclContext *Owner, 4861 const MultiLevelTemplateArgumentList &TemplateArgs); 4862 4863 bool 4864 SubstBaseSpecifiers(CXXRecordDecl *Instantiation, 4865 CXXRecordDecl *Pattern, 4866 const MultiLevelTemplateArgumentList &TemplateArgs); 4867 4868 bool 4869 InstantiateClass(SourceLocation PointOfInstantiation, 4870 CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern, 4871 const MultiLevelTemplateArgumentList &TemplateArgs, 4872 TemplateSpecializationKind TSK, 4873 bool Complain = true); 4874 4875 void InstantiateAttrs(const MultiLevelTemplateArgumentList &TemplateArgs, 4876 const Decl *Pattern, Decl *Inst); 4877 4878 bool 4879 InstantiateClassTemplateSpecialization(SourceLocation PointOfInstantiation, 4880 ClassTemplateSpecializationDecl *ClassTemplateSpec, 4881 TemplateSpecializationKind TSK, 4882 bool Complain = true); 4883 4884 void InstantiateClassMembers(SourceLocation PointOfInstantiation, 4885 CXXRecordDecl *Instantiation, 4886 const MultiLevelTemplateArgumentList &TemplateArgs, 4887 TemplateSpecializationKind TSK); 4888 4889 void InstantiateClassTemplateSpecializationMembers( 4890 SourceLocation PointOfInstantiation, 4891 ClassTemplateSpecializationDecl *ClassTemplateSpec, 4892 TemplateSpecializationKind TSK); 4893 4894 NestedNameSpecifierLoc 4895 SubstNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, 4896 const MultiLevelTemplateArgumentList &TemplateArgs); 4897 4898 DeclarationNameInfo 4899 SubstDeclarationNameInfo(const DeclarationNameInfo &NameInfo, 4900 const MultiLevelTemplateArgumentList &TemplateArgs); 4901 TemplateName 4902 SubstTemplateName(NestedNameSpecifierLoc QualifierLoc, TemplateName Name, 4903 SourceLocation Loc, 4904 const MultiLevelTemplateArgumentList &TemplateArgs); 4905 bool Subst(const TemplateArgumentLoc *Args, unsigned NumArgs, 4906 TemplateArgumentListInfo &Result, 4907 const MultiLevelTemplateArgumentList &TemplateArgs); 4908 4909 void InstantiateFunctionDefinition(SourceLocation PointOfInstantiation, 4910 FunctionDecl *Function, 4911 bool Recursive = false, 4912 bool DefinitionRequired = false); 4913 void InstantiateStaticDataMemberDefinition( 4914 SourceLocation PointOfInstantiation, 4915 VarDecl *Var, 4916 bool Recursive = false, 4917 bool DefinitionRequired = false); 4918 4919 void InstantiateMemInitializers(CXXConstructorDecl *New, 4920 const CXXConstructorDecl *Tmpl, 4921 const MultiLevelTemplateArgumentList &TemplateArgs); 4922 bool InstantiateInitializer(Expr *Init, 4923 const MultiLevelTemplateArgumentList &TemplateArgs, 4924 SourceLocation &LParenLoc, 4925 ASTOwningVector<Expr*> &NewArgs, 4926 SourceLocation &RParenLoc); 4927 4928 NamedDecl *FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D, 4929 const MultiLevelTemplateArgumentList &TemplateArgs); 4930 DeclContext *FindInstantiatedContext(SourceLocation Loc, DeclContext *DC, 4931 const MultiLevelTemplateArgumentList &TemplateArgs); 4932 4933 // Objective-C declarations. 4934 Decl *ActOnStartClassInterface(SourceLocation AtInterfaceLoc, 4935 IdentifierInfo *ClassName, 4936 SourceLocation ClassLoc, 4937 IdentifierInfo *SuperName, 4938 SourceLocation SuperLoc, 4939 Decl * const *ProtoRefs, 4940 unsigned NumProtoRefs, 4941 const SourceLocation *ProtoLocs, 4942 SourceLocation EndProtoLoc, 4943 AttributeList *AttrList); 4944 4945 Decl *ActOnCompatiblityAlias( 4946 SourceLocation AtCompatibilityAliasLoc, 4947 IdentifierInfo *AliasName, SourceLocation AliasLocation, 4948 IdentifierInfo *ClassName, SourceLocation ClassLocation); 4949 4950 bool CheckForwardProtocolDeclarationForCircularDependency( 4951 IdentifierInfo *PName, 4952 SourceLocation &PLoc, SourceLocation PrevLoc, 4953 const ObjCList<ObjCProtocolDecl> &PList); 4954 4955 Decl *ActOnStartProtocolInterface( 4956 SourceLocation AtProtoInterfaceLoc, 4957 IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc, 4958 Decl * const *ProtoRefNames, unsigned NumProtoRefs, 4959 const SourceLocation *ProtoLocs, 4960 SourceLocation EndProtoLoc, 4961 AttributeList *AttrList); 4962 4963 Decl *ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc, 4964 IdentifierInfo *ClassName, 4965 SourceLocation ClassLoc, 4966 IdentifierInfo *CategoryName, 4967 SourceLocation CategoryLoc, 4968 Decl * const *ProtoRefs, 4969 unsigned NumProtoRefs, 4970 const SourceLocation *ProtoLocs, 4971 SourceLocation EndProtoLoc); 4972 4973 Decl *ActOnStartClassImplementation( 4974 SourceLocation AtClassImplLoc, 4975 IdentifierInfo *ClassName, SourceLocation ClassLoc, 4976 IdentifierInfo *SuperClassname, 4977 SourceLocation SuperClassLoc); 4978 4979 Decl *ActOnStartCategoryImplementation(SourceLocation AtCatImplLoc, 4980 IdentifierInfo *ClassName, 4981 SourceLocation ClassLoc, 4982 IdentifierInfo *CatName, 4983 SourceLocation CatLoc); 4984 4985 Decl *ActOnForwardClassDeclaration(SourceLocation Loc, 4986 IdentifierInfo **IdentList, 4987 SourceLocation *IdentLocs, 4988 unsigned NumElts); 4989 4990 Decl *ActOnForwardProtocolDeclaration(SourceLocation AtProtoclLoc, 4991 const IdentifierLocPair *IdentList, 4992 unsigned NumElts, 4993 AttributeList *attrList); 4994 4995 void FindProtocolDeclaration(bool WarnOnDeclarations, 4996 const IdentifierLocPair *ProtocolId, 4997 unsigned NumProtocols, 4998 SmallVectorImpl<Decl *> &Protocols); 4999 5000 /// Ensure attributes are consistent with type. 5001 /// \param [in, out] Attributes The attributes to check; they will 5002 /// be modified to be consistent with \arg PropertyTy. 5003 void CheckObjCPropertyAttributes(Decl *PropertyPtrTy, 5004 SourceLocation Loc, 5005 unsigned &Attributes); 5006 5007 /// Process the specified property declaration and create decls for the 5008 /// setters and getters as needed. 5009 /// \param property The property declaration being processed 5010 /// \param DC The semantic container for the property 5011 /// \param redeclaredProperty Declaration for property if redeclared 5012 /// in class extension. 5013 /// \param lexicalDC Container for redeclaredProperty. 5014 void ProcessPropertyDecl(ObjCPropertyDecl *property, 5015 ObjCContainerDecl *DC, 5016 ObjCPropertyDecl *redeclaredProperty = 0, 5017 ObjCContainerDecl *lexicalDC = 0); 5018 5019 void DiagnosePropertyMismatch(ObjCPropertyDecl *Property, 5020 ObjCPropertyDecl *SuperProperty, 5021 const IdentifierInfo *Name); 5022 void ComparePropertiesInBaseAndSuper(ObjCInterfaceDecl *IDecl); 5023 5024 void CompareMethodParamsInBaseAndSuper(Decl *IDecl, 5025 ObjCMethodDecl *MethodDecl, 5026 bool IsInstance); 5027 5028 void CompareProperties(Decl *CDecl, Decl *MergeProtocols); 5029 5030 void DiagnoseClassExtensionDupMethods(ObjCCategoryDecl *CAT, 5031 ObjCInterfaceDecl *ID); 5032 5033 void MatchOneProtocolPropertiesInClass(Decl *CDecl, 5034 ObjCProtocolDecl *PDecl); 5035 5036 void ActOnAtEnd(Scope *S, SourceRange AtEnd, Decl *classDecl, 5037 Decl **allMethods = 0, unsigned allNum = 0, 5038 Decl **allProperties = 0, unsigned pNum = 0, 5039 DeclGroupPtrTy *allTUVars = 0, unsigned tuvNum = 0); 5040 5041 Decl *ActOnProperty(Scope *S, SourceLocation AtLoc, 5042 FieldDeclarator &FD, ObjCDeclSpec &ODS, 5043 Selector GetterSel, Selector SetterSel, 5044 Decl *ClassCategory, 5045 bool *OverridingProperty, 5046 tok::ObjCKeywordKind MethodImplKind, 5047 DeclContext *lexicalDC = 0); 5048 5049 Decl *ActOnPropertyImplDecl(Scope *S, 5050 SourceLocation AtLoc, 5051 SourceLocation PropertyLoc, 5052 bool ImplKind,Decl *ClassImplDecl, 5053 IdentifierInfo *PropertyId, 5054 IdentifierInfo *PropertyIvar, 5055 SourceLocation PropertyIvarLoc); 5056 5057 enum ObjCSpecialMethodKind { 5058 OSMK_None, 5059 OSMK_Alloc, 5060 OSMK_New, 5061 OSMK_Copy, 5062 OSMK_RetainingInit, 5063 OSMK_NonRetainingInit 5064 }; 5065 5066 struct ObjCArgInfo { 5067 IdentifierInfo *Name; 5068 SourceLocation NameLoc; 5069 // The Type is null if no type was specified, and the DeclSpec is invalid 5070 // in this case. 5071 ParsedType Type; 5072 ObjCDeclSpec DeclSpec; 5073 5074 /// ArgAttrs - Attribute list for this argument. 5075 AttributeList *ArgAttrs; 5076 }; 5077 5078 Decl *ActOnMethodDeclaration( 5079 Scope *S, 5080 SourceLocation BeginLoc, // location of the + or -. 5081 SourceLocation EndLoc, // location of the ; or {. 5082 tok::TokenKind MethodType, 5083 Decl *ClassDecl, ObjCDeclSpec &ReturnQT, ParsedType ReturnType, 5084 SourceLocation SelectorStartLoc, Selector Sel, 5085 // optional arguments. The number of types/arguments is obtained 5086 // from the Sel.getNumArgs(). 5087 ObjCArgInfo *ArgInfo, 5088 DeclaratorChunk::ParamInfo *CParamInfo, unsigned CNumArgs, // c-style args 5089 AttributeList *AttrList, tok::ObjCKeywordKind MethodImplKind, 5090 bool isVariadic, bool MethodDefinition); 5091 5092 // Helper method for ActOnClassMethod/ActOnInstanceMethod. 5093 // Will search "local" class/category implementations for a method decl. 5094 // Will also search in class's root looking for instance method. 5095 // Returns 0 if no method is found. 5096 ObjCMethodDecl *LookupPrivateClassMethod(Selector Sel, 5097 ObjCInterfaceDecl *CDecl); 5098 ObjCMethodDecl *LookupPrivateInstanceMethod(Selector Sel, 5099 ObjCInterfaceDecl *ClassDecl); 5100 ObjCMethodDecl *LookupMethodInQualifiedType(Selector Sel, 5101 const ObjCObjectPointerType *OPT, 5102 bool IsInstance); 5103 5104 bool inferObjCARCLifetime(ValueDecl *decl); 5105 5106 ExprResult 5107 HandleExprPropertyRefExpr(const ObjCObjectPointerType *OPT, 5108 Expr *BaseExpr, 5109 SourceLocation OpLoc, 5110 DeclarationName MemberName, 5111 SourceLocation MemberLoc, 5112 SourceLocation SuperLoc, QualType SuperType, 5113 bool Super); 5114 5115 ExprResult 5116 ActOnClassPropertyRefExpr(IdentifierInfo &receiverName, 5117 IdentifierInfo &propertyName, 5118 SourceLocation receiverNameLoc, 5119 SourceLocation propertyNameLoc); 5120 5121 ObjCMethodDecl *tryCaptureObjCSelf(); 5122 5123 /// \brief Describes the kind of message expression indicated by a message 5124 /// send that starts with an identifier. 5125 enum ObjCMessageKind { 5126 /// \brief The message is sent to 'super'. 5127 ObjCSuperMessage, 5128 /// \brief The message is an instance message. 5129 ObjCInstanceMessage, 5130 /// \brief The message is a class message, and the identifier is a type 5131 /// name. 5132 ObjCClassMessage 5133 }; 5134 5135 ObjCMessageKind getObjCMessageKind(Scope *S, 5136 IdentifierInfo *Name, 5137 SourceLocation NameLoc, 5138 bool IsSuper, 5139 bool HasTrailingDot, 5140 ParsedType &ReceiverType); 5141 5142 ExprResult ActOnSuperMessage(Scope *S, SourceLocation SuperLoc, 5143 Selector Sel, 5144 SourceLocation LBracLoc, 5145 SourceLocation SelectorLoc, 5146 SourceLocation RBracLoc, 5147 MultiExprArg Args); 5148 5149 ExprResult BuildClassMessage(TypeSourceInfo *ReceiverTypeInfo, 5150 QualType ReceiverType, 5151 SourceLocation SuperLoc, 5152 Selector Sel, 5153 ObjCMethodDecl *Method, 5154 SourceLocation LBracLoc, 5155 SourceLocation SelectorLoc, 5156 SourceLocation RBracLoc, 5157 MultiExprArg Args); 5158 5159 ExprResult ActOnClassMessage(Scope *S, 5160 ParsedType Receiver, 5161 Selector Sel, 5162 SourceLocation LBracLoc, 5163 SourceLocation SelectorLoc, 5164 SourceLocation RBracLoc, 5165 MultiExprArg Args); 5166 5167 ExprResult BuildInstanceMessage(Expr *Receiver, 5168 QualType ReceiverType, 5169 SourceLocation SuperLoc, 5170 Selector Sel, 5171 ObjCMethodDecl *Method, 5172 SourceLocation LBracLoc, 5173 SourceLocation SelectorLoc, 5174 SourceLocation RBracLoc, 5175 MultiExprArg Args); 5176 5177 ExprResult ActOnInstanceMessage(Scope *S, 5178 Expr *Receiver, 5179 Selector Sel, 5180 SourceLocation LBracLoc, 5181 SourceLocation SelectorLoc, 5182 SourceLocation RBracLoc, 5183 MultiExprArg Args); 5184 5185 ExprResult BuildObjCBridgedCast(SourceLocation LParenLoc, 5186 ObjCBridgeCastKind Kind, 5187 SourceLocation BridgeKeywordLoc, 5188 TypeSourceInfo *TSInfo, 5189 Expr *SubExpr); 5190 5191 ExprResult ActOnObjCBridgedCast(Scope *S, 5192 SourceLocation LParenLoc, 5193 ObjCBridgeCastKind Kind, 5194 SourceLocation BridgeKeywordLoc, 5195 ParsedType Type, 5196 SourceLocation RParenLoc, 5197 Expr *SubExpr); 5198 5199 bool checkInitMethod(ObjCMethodDecl *method, QualType receiverTypeIfCall); 5200 5201 /// \brief Check whether the given new method is a valid override of the 5202 /// given overridden method, and set any properties that should be inherited. 5203 /// 5204 /// \returns True if an error occurred. 5205 bool CheckObjCMethodOverride(ObjCMethodDecl *NewMethod, 5206 const ObjCMethodDecl *Overridden, 5207 bool IsImplementation); 5208 5209 /// \brief Check whether the given method overrides any methods in its class, 5210 /// calling \c CheckObjCMethodOverride for each overridden method. 5211 bool CheckObjCMethodOverrides(ObjCMethodDecl *NewMethod, DeclContext *DC); 5212 5213 enum PragmaOptionsAlignKind { 5214 POAK_Native, // #pragma options align=native 5215 POAK_Natural, // #pragma options align=natural 5216 POAK_Packed, // #pragma options align=packed 5217 POAK_Power, // #pragma options align=power 5218 POAK_Mac68k, // #pragma options align=mac68k 5219 POAK_Reset // #pragma options align=reset 5220 }; 5221 5222 /// ActOnPragmaOptionsAlign - Called on well formed #pragma options align. 5223 void ActOnPragmaOptionsAlign(PragmaOptionsAlignKind Kind, 5224 SourceLocation PragmaLoc, 5225 SourceLocation KindLoc); 5226 5227 enum PragmaPackKind { 5228 PPK_Default, // #pragma pack([n]) 5229 PPK_Show, // #pragma pack(show), only supported by MSVC. 5230 PPK_Push, // #pragma pack(push, [identifier], [n]) 5231 PPK_Pop // #pragma pack(pop, [identifier], [n]) 5232 }; 5233 5234 enum PragmaMSStructKind { 5235 PMSST_OFF, // #pragms ms_struct off 5236 PMSST_ON // #pragms ms_struct on 5237 }; 5238 5239 /// ActOnPragmaPack - Called on well formed #pragma pack(...). 5240 void ActOnPragmaPack(PragmaPackKind Kind, 5241 IdentifierInfo *Name, 5242 Expr *Alignment, 5243 SourceLocation PragmaLoc, 5244 SourceLocation LParenLoc, 5245 SourceLocation RParenLoc); 5246 5247 /// ActOnPragmaMSStruct - Called on well formed #pragms ms_struct [on|off]. 5248 void ActOnPragmaMSStruct(PragmaMSStructKind Kind); 5249 5250 /// ActOnPragmaUnused - Called on well-formed '#pragma unused'. 5251 void ActOnPragmaUnused(const Token &Identifier, 5252 Scope *curScope, 5253 SourceLocation PragmaLoc); 5254 5255 /// ActOnPragmaVisibility - Called on well formed #pragma GCC visibility... . 5256 void ActOnPragmaVisibility(bool IsPush, const IdentifierInfo* VisType, 5257 SourceLocation PragmaLoc); 5258 5259 NamedDecl *DeclClonePragmaWeak(NamedDecl *ND, IdentifierInfo *II); 5260 void DeclApplyPragmaWeak(Scope *S, NamedDecl *ND, WeakInfo &W); 5261 5262 /// ActOnPragmaWeakID - Called on well formed #pragma weak ident. 5263 void ActOnPragmaWeakID(IdentifierInfo* WeakName, 5264 SourceLocation PragmaLoc, 5265 SourceLocation WeakNameLoc); 5266 5267 /// ActOnPragmaWeakAlias - Called on well formed #pragma weak ident = ident. 5268 void ActOnPragmaWeakAlias(IdentifierInfo* WeakName, 5269 IdentifierInfo* AliasName, 5270 SourceLocation PragmaLoc, 5271 SourceLocation WeakNameLoc, 5272 SourceLocation AliasNameLoc); 5273 5274 /// ActOnPragmaFPContract - Called on well formed 5275 /// #pragma {STDC,OPENCL} FP_CONTRACT 5276 void ActOnPragmaFPContract(tok::OnOffSwitch OOS); 5277 5278 /// AddAlignmentAttributesForRecord - Adds any needed alignment attributes to 5279 /// a the record decl, to handle '#pragma pack' and '#pragma options align'. 5280 void AddAlignmentAttributesForRecord(RecordDecl *RD); 5281 5282 /// AddMsStructLayoutForRecord - Adds ms_struct layout attribute to record. 5283 void AddMsStructLayoutForRecord(RecordDecl *RD); 5284 5285 /// FreePackedContext - Deallocate and null out PackContext. 5286 void FreePackedContext(); 5287 5288 /// PushNamespaceVisibilityAttr - Note that we've entered a 5289 /// namespace with a visibility attribute. 5290 void PushNamespaceVisibilityAttr(const VisibilityAttr *Attr); 5291 5292 /// AddPushedVisibilityAttribute - If '#pragma GCC visibility' was used, 5293 /// add an appropriate visibility attribute. 5294 void AddPushedVisibilityAttribute(Decl *RD); 5295 5296 /// PopPragmaVisibility - Pop the top element of the visibility stack; used 5297 /// for '#pragma GCC visibility' and visibility attributes on namespaces. 5298 void PopPragmaVisibility(); 5299 5300 /// FreeVisContext - Deallocate and null out VisContext. 5301 void FreeVisContext(); 5302 5303 /// AddAlignedAttr - Adds an aligned attribute to a particular declaration. 5304 void AddAlignedAttr(SourceLocation AttrLoc, Decl *D, Expr *E); 5305 void AddAlignedAttr(SourceLocation AttrLoc, Decl *D, TypeSourceInfo *T); 5306 5307 /// CastCategory - Get the correct forwarded implicit cast result category 5308 /// from the inner expression. 5309 ExprValueKind CastCategory(Expr *E); 5310 5311 /// \brief The kind of conversion being performed. 5312 enum CheckedConversionKind { 5313 /// \brief An implicit conversion. 5314 CCK_ImplicitConversion, 5315 /// \brief A C-style cast. 5316 CCK_CStyleCast, 5317 /// \brief A functional-style cast. 5318 CCK_FunctionalCast, 5319 /// \brief A cast other than a C-style cast. 5320 CCK_OtherCast 5321 }; 5322 5323 /// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit 5324 /// cast. If there is already an implicit cast, merge into the existing one. 5325 /// If isLvalue, the result of the cast is an lvalue. 5326 ExprResult ImpCastExprToType(Expr *E, QualType Type, CastKind CK, 5327 ExprValueKind VK = VK_RValue, 5328 const CXXCastPath *BasePath = 0, 5329 CheckedConversionKind CCK 5330 = CCK_ImplicitConversion); 5331 5332 /// ScalarTypeToBooleanCastKind - Returns the cast kind corresponding 5333 /// to the conversion from scalar type ScalarTy to the Boolean type. 5334 static CastKind ScalarTypeToBooleanCastKind(QualType ScalarTy); 5335 5336 /// IgnoredValueConversions - Given that an expression's result is 5337 /// syntactically ignored, perform any conversions that are 5338 /// required. 5339 ExprResult IgnoredValueConversions(Expr *E); 5340 5341 // UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts 5342 // functions and arrays to their respective pointers (C99 6.3.2.1). 5343 ExprResult UsualUnaryConversions(Expr *E); 5344 5345 // DefaultFunctionArrayConversion - converts functions and arrays 5346 // to their respective pointers (C99 6.3.2.1). 5347 ExprResult DefaultFunctionArrayConversion(Expr *E); 5348 5349 // DefaultFunctionArrayLvalueConversion - converts functions and 5350 // arrays to their respective pointers and performs the 5351 // lvalue-to-rvalue conversion. 5352 ExprResult DefaultFunctionArrayLvalueConversion(Expr *E); 5353 5354 // DefaultLvalueConversion - performs lvalue-to-rvalue conversion on 5355 // the operand. This is DefaultFunctionArrayLvalueConversion, 5356 // except that it assumes the operand isn't of function or array 5357 // type. 5358 ExprResult DefaultLvalueConversion(Expr *E); 5359 5360 // DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that 5361 // do not have a prototype. Integer promotions are performed on each 5362 // argument, and arguments that have type float are promoted to double. 5363 ExprResult DefaultArgumentPromotion(Expr *E); 5364 5365 // Used for emitting the right warning by DefaultVariadicArgumentPromotion 5366 enum VariadicCallType { 5367 VariadicFunction, 5368 VariadicBlock, 5369 VariadicMethod, 5370 VariadicConstructor, 5371 VariadicDoesNotApply 5372 }; 5373 5374 /// GatherArgumentsForCall - Collector argument expressions for various 5375 /// form of call prototypes. 5376 bool GatherArgumentsForCall(SourceLocation CallLoc, 5377 FunctionDecl *FDecl, 5378 const FunctionProtoType *Proto, 5379 unsigned FirstProtoArg, 5380 Expr **Args, unsigned NumArgs, 5381 SmallVector<Expr *, 8> &AllArgs, 5382 VariadicCallType CallType = VariadicDoesNotApply); 5383 5384 // DefaultVariadicArgumentPromotion - Like DefaultArgumentPromotion, but 5385 // will warn if the resulting type is not a POD type. 5386 ExprResult DefaultVariadicArgumentPromotion(Expr *E, VariadicCallType CT, 5387 FunctionDecl *FDecl); 5388 5389 // UsualArithmeticConversions - performs the UsualUnaryConversions on it's 5390 // operands and then handles various conversions that are common to binary 5391 // operators (C99 6.3.1.8). If both operands aren't arithmetic, this 5392 // routine returns the first non-arithmetic type found. The client is 5393 // responsible for emitting appropriate error diagnostics. 5394 QualType UsualArithmeticConversions(ExprResult &lExpr, ExprResult &rExpr, 5395 bool isCompAssign = false); 5396 5397 /// AssignConvertType - All of the 'assignment' semantic checks return this 5398 /// enum to indicate whether the assignment was allowed. These checks are 5399 /// done for simple assignments, as well as initialization, return from 5400 /// function, argument passing, etc. The query is phrased in terms of a 5401 /// source and destination type. 5402 enum AssignConvertType { 5403 /// Compatible - the types are compatible according to the standard. 5404 Compatible, 5405 5406 /// PointerToInt - The assignment converts a pointer to an int, which we 5407 /// accept as an extension. 5408 PointerToInt, 5409 5410 /// IntToPointer - The assignment converts an int to a pointer, which we 5411 /// accept as an extension. 5412 IntToPointer, 5413 5414 /// FunctionVoidPointer - The assignment is between a function pointer and 5415 /// void*, which the standard doesn't allow, but we accept as an extension. 5416 FunctionVoidPointer, 5417 5418 /// IncompatiblePointer - The assignment is between two pointers types that 5419 /// are not compatible, but we accept them as an extension. 5420 IncompatiblePointer, 5421 5422 /// IncompatiblePointer - The assignment is between two pointers types which 5423 /// point to integers which have a different sign, but are otherwise identical. 5424 /// This is a subset of the above, but broken out because it's by far the most 5425 /// common case of incompatible pointers. 5426 IncompatiblePointerSign, 5427 5428 /// CompatiblePointerDiscardsQualifiers - The assignment discards 5429 /// c/v/r qualifiers, which we accept as an extension. 5430 CompatiblePointerDiscardsQualifiers, 5431 5432 /// IncompatiblePointerDiscardsQualifiers - The assignment 5433 /// discards qualifiers that we don't permit to be discarded, 5434 /// like address spaces. 5435 IncompatiblePointerDiscardsQualifiers, 5436 5437 /// IncompatibleNestedPointerQualifiers - The assignment is between two 5438 /// nested pointer types, and the qualifiers other than the first two 5439 /// levels differ e.g. char ** -> const char **, but we accept them as an 5440 /// extension. 5441 IncompatibleNestedPointerQualifiers, 5442 5443 /// IncompatibleVectors - The assignment is between two vector types that 5444 /// have the same size, which we accept as an extension. 5445 IncompatibleVectors, 5446 5447 /// IntToBlockPointer - The assignment converts an int to a block 5448 /// pointer. We disallow this. 5449 IntToBlockPointer, 5450 5451 /// IncompatibleBlockPointer - The assignment is between two block 5452 /// pointers types that are not compatible. 5453 IncompatibleBlockPointer, 5454 5455 /// IncompatibleObjCQualifiedId - The assignment is between a qualified 5456 /// id type and something else (that is incompatible with it). For example, 5457 /// "id <XXX>" = "Foo *", where "Foo *" doesn't implement the XXX protocol. 5458 IncompatibleObjCQualifiedId, 5459 5460 /// IncompatibleObjCWeakRef - Assigning a weak-unavailable object to an 5461 /// object with __weak qualifier. 5462 IncompatibleObjCWeakRef, 5463 5464 /// Incompatible - We reject this conversion outright, it is invalid to 5465 /// represent it in the AST. 5466 Incompatible 5467 }; 5468 5469 /// DiagnoseAssignmentResult - Emit a diagnostic, if required, for the 5470 /// assignment conversion type specified by ConvTy. This returns true if the 5471 /// conversion was invalid or false if the conversion was accepted. 5472 bool DiagnoseAssignmentResult(AssignConvertType ConvTy, 5473 SourceLocation Loc, 5474 QualType DstType, QualType SrcType, 5475 Expr *SrcExpr, AssignmentAction Action, 5476 bool *Complained = 0); 5477 5478 /// CheckAssignmentConstraints - Perform type checking for assignment, 5479 /// argument passing, variable initialization, and function return values. 5480 /// C99 6.5.16. 5481 AssignConvertType CheckAssignmentConstraints(SourceLocation Loc, 5482 QualType lhs, QualType rhs); 5483 5484 /// Check assignment constraints and prepare for a conversion of the 5485 /// RHS to the LHS type. 5486 AssignConvertType CheckAssignmentConstraints(QualType lhs, ExprResult &rhs, 5487 CastKind &Kind); 5488 5489 // CheckSingleAssignmentConstraints - Currently used by 5490 // CheckAssignmentOperands, and ActOnReturnStmt. Prior to type checking, 5491 // this routine performs the default function/array converions. 5492 AssignConvertType CheckSingleAssignmentConstraints(QualType lhs, 5493 ExprResult &rExprRes); 5494 5495 // \brief If the lhs type is a transparent union, check whether we 5496 // can initialize the transparent union with the given expression. 5497 AssignConvertType CheckTransparentUnionArgumentConstraints(QualType lhs, 5498 ExprResult &rExpr); 5499 5500 bool IsStringLiteralToNonConstPointerConversion(Expr *From, QualType ToType); 5501 5502 bool CheckExceptionSpecCompatibility(Expr *From, QualType ToType); 5503 5504 ExprResult PerformImplicitConversion(Expr *From, QualType ToType, 5505 AssignmentAction Action, 5506 bool AllowExplicit = false); 5507 ExprResult PerformImplicitConversion(Expr *From, QualType ToType, 5508 AssignmentAction Action, 5509 bool AllowExplicit, 5510 ImplicitConversionSequence& ICS); 5511 ExprResult PerformImplicitConversion(Expr *From, QualType ToType, 5512 const ImplicitConversionSequence& ICS, 5513 AssignmentAction Action, 5514 CheckedConversionKind CCK 5515 = CCK_ImplicitConversion); 5516 ExprResult PerformImplicitConversion(Expr *From, QualType ToType, 5517 const StandardConversionSequence& SCS, 5518 AssignmentAction Action, 5519 CheckedConversionKind CCK); 5520 5521 /// the following "Check" methods will return a valid/converted QualType 5522 /// or a null QualType (indicating an error diagnostic was issued). 5523 5524 /// type checking binary operators (subroutines of CreateBuiltinBinOp). 5525 QualType InvalidOperands(SourceLocation l, ExprResult &lex, ExprResult &rex); 5526 QualType CheckPointerToMemberOperands( // C++ 5.5 5527 ExprResult &lex, ExprResult &rex, ExprValueKind &VK, 5528 SourceLocation OpLoc, bool isIndirect); 5529 QualType CheckMultiplyDivideOperands( // C99 6.5.5 5530 ExprResult &lex, ExprResult &rex, SourceLocation OpLoc, bool isCompAssign, 5531 bool isDivide); 5532 QualType CheckRemainderOperands( // C99 6.5.5 5533 ExprResult &lex, ExprResult &rex, SourceLocation OpLoc, bool isCompAssign = false); 5534 QualType CheckAdditionOperands( // C99 6.5.6 5535 ExprResult &lex, ExprResult &rex, SourceLocation OpLoc, QualType* CompLHSTy = 0); 5536 QualType CheckSubtractionOperands( // C99 6.5.6 5537 ExprResult &lex, ExprResult &rex, SourceLocation OpLoc, QualType* CompLHSTy = 0); 5538 QualType CheckShiftOperands( // C99 6.5.7 5539 ExprResult &lex, ExprResult &rex, SourceLocation OpLoc, unsigned Opc, 5540 bool isCompAssign = false); 5541 QualType CheckCompareOperands( // C99 6.5.8/9 5542 ExprResult &lex, ExprResult &rex, SourceLocation OpLoc, unsigned Opc, 5543 bool isRelational); 5544 QualType CheckBitwiseOperands( // C99 6.5.[10...12] 5545 ExprResult &lex, ExprResult &rex, SourceLocation OpLoc, bool isCompAssign = false); 5546 QualType CheckLogicalOperands( // C99 6.5.[13,14] 5547 ExprResult &lex, ExprResult &rex, SourceLocation OpLoc, unsigned Opc); 5548 // CheckAssignmentOperands is used for both simple and compound assignment. 5549 // For simple assignment, pass both expressions and a null converted type. 5550 // For compound assignment, pass both expressions and the converted type. 5551 QualType CheckAssignmentOperands( // C99 6.5.16.[1,2] 5552 Expr *lex, ExprResult &rex, SourceLocation OpLoc, QualType convertedType); 5553 5554 void ConvertPropertyForLValue(ExprResult &LHS, ExprResult &RHS, QualType& LHSTy); 5555 ExprResult ConvertPropertyForRValue(Expr *E); 5556 5557 QualType CheckConditionalOperands( // C99 6.5.15 5558 ExprResult &cond, ExprResult &lhs, ExprResult &rhs, 5559 ExprValueKind &VK, ExprObjectKind &OK, SourceLocation questionLoc); 5560 QualType CXXCheckConditionalOperands( // C++ 5.16 5561 ExprResult &cond, ExprResult &lhs, ExprResult &rhs, 5562 ExprValueKind &VK, ExprObjectKind &OK, SourceLocation questionLoc); 5563 QualType FindCompositePointerType(SourceLocation Loc, Expr *&E1, Expr *&E2, 5564 bool *NonStandardCompositeType = 0); 5565 QualType FindCompositePointerType(SourceLocation Loc, ExprResult &E1, ExprResult &E2, 5566 bool *NonStandardCompositeType = 0) { 5567 Expr *E1Tmp = E1.take(), *E2Tmp = E2.take(); 5568 QualType Composite = FindCompositePointerType(Loc, E1Tmp, E2Tmp, NonStandardCompositeType); 5569 E1 = Owned(E1Tmp); 5570 E2 = Owned(E2Tmp); 5571 return Composite; 5572 } 5573 5574 QualType FindCompositeObjCPointerType(ExprResult &LHS, ExprResult &RHS, 5575 SourceLocation questionLoc); 5576 5577 bool DiagnoseConditionalForNull(Expr *LHS, Expr *RHS, 5578 SourceLocation QuestionLoc); 5579 5580 /// type checking for vector binary operators. 5581 QualType CheckVectorOperands(ExprResult &lex, ExprResult &rex, 5582 SourceLocation Loc, bool isCompAssign); 5583 QualType CheckVectorCompareOperands(ExprResult &lex, ExprResult &rx, 5584 SourceLocation l, bool isRel); 5585 5586 /// type checking declaration initializers (C99 6.7.8) 5587 bool CheckInitList(const InitializedEntity &Entity, 5588 InitListExpr *&InitList, QualType &DeclType); 5589 bool CheckForConstantInitializer(Expr *e, QualType t); 5590 5591 // type checking C++ declaration initializers (C++ [dcl.init]). 5592 5593 /// ReferenceCompareResult - Expresses the result of comparing two 5594 /// types (cv1 T1 and cv2 T2) to determine their compatibility for the 5595 /// purposes of initialization by reference (C++ [dcl.init.ref]p4). 5596 enum ReferenceCompareResult { 5597 /// Ref_Incompatible - The two types are incompatible, so direct 5598 /// reference binding is not possible. 5599 Ref_Incompatible = 0, 5600 /// Ref_Related - The two types are reference-related, which means 5601 /// that their unqualified forms (T1 and T2) are either the same 5602 /// or T1 is a base class of T2. 5603 Ref_Related, 5604 /// Ref_Compatible_With_Added_Qualification - The two types are 5605 /// reference-compatible with added qualification, meaning that 5606 /// they are reference-compatible and the qualifiers on T1 (cv1) 5607 /// are greater than the qualifiers on T2 (cv2). 5608 Ref_Compatible_With_Added_Qualification, 5609 /// Ref_Compatible - The two types are reference-compatible and 5610 /// have equivalent qualifiers (cv1 == cv2). 5611 Ref_Compatible 5612 }; 5613 5614 ReferenceCompareResult CompareReferenceRelationship(SourceLocation Loc, 5615 QualType T1, QualType T2, 5616 bool &DerivedToBase, 5617 bool &ObjCConversion, 5618 bool &ObjCLifetimeConversion); 5619 5620 /// CheckCastTypes - Check type constraints for casting between types under 5621 /// C semantics, or forward to CXXCheckCStyleCast in C++. 5622 ExprResult CheckCastTypes(SourceLocation CastStartLoc, SourceRange TyRange, 5623 QualType CastTy, Expr *CastExpr, CastKind &Kind, 5624 ExprValueKind &VK, CXXCastPath &BasePath, 5625 bool FunctionalStyle = false); 5626 5627 ExprResult checkUnknownAnyCast(SourceRange TyRange, QualType castType, 5628 Expr *castExpr, CastKind &castKind, 5629 ExprValueKind &valueKind, CXXCastPath &BasePath); 5630 5631 // CheckVectorCast - check type constraints for vectors. 5632 // Since vectors are an extension, there are no C standard reference for this. 5633 // We allow casting between vectors and integer datatypes of the same size. 5634 // returns true if the cast is invalid 5635 bool CheckVectorCast(SourceRange R, QualType VectorTy, QualType Ty, 5636 CastKind &Kind); 5637 5638 // CheckExtVectorCast - check type constraints for extended vectors. 5639 // Since vectors are an extension, there are no C standard reference for this. 5640 // We allow casting between vectors and integer datatypes of the same size, 5641 // or vectors and the element type of that vector. 5642 // returns the cast expr 5643 ExprResult CheckExtVectorCast(SourceRange R, QualType VectorTy, Expr *CastExpr, 5644 CastKind &Kind); 5645 5646 /// CXXCheckCStyleCast - Check constraints of a C-style or function-style 5647 /// cast under C++ semantics. 5648 ExprResult CXXCheckCStyleCast(SourceRange R, QualType CastTy, ExprValueKind &VK, 5649 Expr *CastExpr, CastKind &Kind, 5650 CXXCastPath &BasePath, bool FunctionalStyle); 5651 5652 /// \brief Checks for valid expressions which can be cast to an ObjC 5653 /// pointer without needing a bridge cast. 5654 bool ValidObjCARCNoBridgeCastExpr(Expr *&Exp, QualType castType); 5655 5656 /// \brief Checks for invalid conversions and casts between 5657 /// retainable pointers and other pointer kinds. 5658 void CheckObjCARCConversion(SourceRange castRange, QualType castType, 5659 Expr *&op, CheckedConversionKind CCK); 5660 5661 bool CheckObjCARCUnavailableWeakConversion(QualType castType, 5662 QualType ExprType); 5663 5664 /// checkRetainCycles - Check whether an Objective-C message send 5665 /// might create an obvious retain cycle. 5666 void checkRetainCycles(ObjCMessageExpr *msg); 5667 void checkRetainCycles(Expr *receiver, Expr *argument); 5668 5669 /// checkUnsafeAssigns - Check whether +1 expr is being assigned 5670 /// to weak/__unsafe_unretained type. 5671 bool checkUnsafeAssigns(SourceLocation Loc, QualType LHS, Expr *RHS); 5672 5673 /// checkUnsafeExprAssigns - Check whether +1 expr is being assigned 5674 /// to weak/__unsafe_unretained expression. 5675 void checkUnsafeExprAssigns(SourceLocation Loc, Expr *LHS, Expr *RHS); 5676 5677 /// CheckMessageArgumentTypes - Check types in an Obj-C message send. 5678 /// \param Method - May be null. 5679 /// \param [out] ReturnType - The return type of the send. 5680 /// \return true iff there were any incompatible types. 5681 bool CheckMessageArgumentTypes(QualType ReceiverType, 5682 Expr **Args, unsigned NumArgs, Selector Sel, 5683 ObjCMethodDecl *Method, bool isClassMessage, 5684 bool isSuperMessage, 5685 SourceLocation lbrac, SourceLocation rbrac, 5686 QualType &ReturnType, ExprValueKind &VK); 5687 5688 /// \brief Determine the result of a message send expression based on 5689 /// the type of the receiver, the method expected to receive the message, 5690 /// and the form of the message send. 5691 QualType getMessageSendResultType(QualType ReceiverType, 5692 ObjCMethodDecl *Method, 5693 bool isClassMessage, bool isSuperMessage); 5694 5695 /// \brief If the given expression involves a message send to a method 5696 /// with a related result type, emit a note describing what happened. 5697 void EmitRelatedResultTypeNote(const Expr *E); 5698 5699 /// CheckBooleanCondition - Diagnose problems involving the use of 5700 /// the given expression as a boolean condition (e.g. in an if 5701 /// statement). Also performs the standard function and array 5702 /// decays, possibly changing the input variable. 5703 /// 5704 /// \param Loc - A location associated with the condition, e.g. the 5705 /// 'if' keyword. 5706 /// \return true iff there were any errors 5707 ExprResult CheckBooleanCondition(Expr *CondExpr, SourceLocation Loc); 5708 5709 ExprResult ActOnBooleanCondition(Scope *S, SourceLocation Loc, 5710 Expr *SubExpr); 5711 5712 /// DiagnoseAssignmentAsCondition - Given that an expression is 5713 /// being used as a boolean condition, warn if it's an assignment. 5714 void DiagnoseAssignmentAsCondition(Expr *E); 5715 5716 /// \brief Redundant parentheses over an equality comparison can indicate 5717 /// that the user intended an assignment used as condition. 5718 void DiagnoseEqualityWithExtraParens(ParenExpr *parenE); 5719 5720 /// CheckCXXBooleanCondition - Returns true if conversion to bool is invalid. 5721 ExprResult CheckCXXBooleanCondition(Expr *CondExpr); 5722 5723 /// ConvertIntegerToTypeWarnOnOverflow - Convert the specified APInt to have 5724 /// the specified width and sign. If an overflow occurs, detect it and emit 5725 /// the specified diagnostic. 5726 void ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &OldVal, 5727 unsigned NewWidth, bool NewSign, 5728 SourceLocation Loc, unsigned DiagID); 5729 5730 /// Checks that the Objective-C declaration is declared in the global scope. 5731 /// Emits an error and marks the declaration as invalid if it's not declared 5732 /// in the global scope. 5733 bool CheckObjCDeclScope(Decl *D); 5734 5735 /// VerifyIntegerConstantExpression - verifies that an expression is an ICE, 5736 /// and reports the appropriate diagnostics. Returns false on success. 5737 /// Can optionally return the value of the expression. 5738 bool VerifyIntegerConstantExpression(const Expr *E, llvm::APSInt *Result = 0); 5739 5740 /// VerifyBitField - verifies that a bit field expression is an ICE and has 5741 /// the correct width, and that the field type is valid. 5742 /// Returns false on success. 5743 /// Can optionally return whether the bit-field is of width 0 5744 bool VerifyBitField(SourceLocation FieldLoc, IdentifierInfo *FieldName, 5745 QualType FieldTy, const Expr *BitWidth, 5746 bool *ZeroWidth = 0); 5747 5748 /// \name Code completion 5749 //@{ 5750 /// \brief Describes the context in which code completion occurs. 5751 enum ParserCompletionContext { 5752 /// \brief Code completion occurs at top-level or namespace context. 5753 PCC_Namespace, 5754 /// \brief Code completion occurs within a class, struct, or union. 5755 PCC_Class, 5756 /// \brief Code completion occurs within an Objective-C interface, protocol, 5757 /// or category. 5758 PCC_ObjCInterface, 5759 /// \brief Code completion occurs within an Objective-C implementation or 5760 /// category implementation 5761 PCC_ObjCImplementation, 5762 /// \brief Code completion occurs within the list of instance variables 5763 /// in an Objective-C interface, protocol, category, or implementation. 5764 PCC_ObjCInstanceVariableList, 5765 /// \brief Code completion occurs following one or more template 5766 /// headers. 5767 PCC_Template, 5768 /// \brief Code completion occurs following one or more template 5769 /// headers within a class. 5770 PCC_MemberTemplate, 5771 /// \brief Code completion occurs within an expression. 5772 PCC_Expression, 5773 /// \brief Code completion occurs within a statement, which may 5774 /// also be an expression or a declaration. 5775 PCC_Statement, 5776 /// \brief Code completion occurs at the beginning of the 5777 /// initialization statement (or expression) in a for loop. 5778 PCC_ForInit, 5779 /// \brief Code completion occurs within the condition of an if, 5780 /// while, switch, or for statement. 5781 PCC_Condition, 5782 /// \brief Code completion occurs within the body of a function on a 5783 /// recovery path, where we do not have a specific handle on our position 5784 /// in the grammar. 5785 PCC_RecoveryInFunction, 5786 /// \brief Code completion occurs where only a type is permitted. 5787 PCC_Type, 5788 /// \brief Code completion occurs in a parenthesized expression, which 5789 /// might also be a type cast. 5790 PCC_ParenthesizedExpression, 5791 /// \brief Code completion occurs within a sequence of declaration 5792 /// specifiers within a function, method, or block. 5793 PCC_LocalDeclarationSpecifiers 5794 }; 5795 5796 void CodeCompleteOrdinaryName(Scope *S, 5797 ParserCompletionContext CompletionContext); 5798 void CodeCompleteDeclSpec(Scope *S, DeclSpec &DS, 5799 bool AllowNonIdentifiers, 5800 bool AllowNestedNameSpecifiers); 5801 5802 struct CodeCompleteExpressionData; 5803 void CodeCompleteExpression(Scope *S, 5804 const CodeCompleteExpressionData &Data); 5805 void CodeCompleteMemberReferenceExpr(Scope *S, Expr *Base, 5806 SourceLocation OpLoc, 5807 bool IsArrow); 5808 void CodeCompletePostfixExpression(Scope *S, ExprResult LHS); 5809 void CodeCompleteTag(Scope *S, unsigned TagSpec); 5810 void CodeCompleteTypeQualifiers(DeclSpec &DS); 5811 void CodeCompleteCase(Scope *S); 5812 void CodeCompleteCall(Scope *S, Expr *Fn, Expr **Args, unsigned NumArgs); 5813 void CodeCompleteInitializer(Scope *S, Decl *D); 5814 void CodeCompleteReturn(Scope *S); 5815 void CodeCompleteAssignmentRHS(Scope *S, Expr *LHS); 5816 5817 void CodeCompleteQualifiedId(Scope *S, CXXScopeSpec &SS, 5818 bool EnteringContext); 5819 void CodeCompleteUsing(Scope *S); 5820 void CodeCompleteUsingDirective(Scope *S); 5821 void CodeCompleteNamespaceDecl(Scope *S); 5822 void CodeCompleteNamespaceAliasDecl(Scope *S); 5823 void CodeCompleteOperatorName(Scope *S); 5824 void CodeCompleteConstructorInitializer(Decl *Constructor, 5825 CXXCtorInitializer** Initializers, 5826 unsigned NumInitializers); 5827 5828 void CodeCompleteObjCAtDirective(Scope *S, Decl *ObjCImpDecl, 5829 bool InInterface); 5830 void CodeCompleteObjCAtVisibility(Scope *S); 5831 void CodeCompleteObjCAtStatement(Scope *S); 5832 void CodeCompleteObjCAtExpression(Scope *S); 5833 void CodeCompleteObjCPropertyFlags(Scope *S, ObjCDeclSpec &ODS); 5834 void CodeCompleteObjCPropertyGetter(Scope *S, Decl *ClassDecl); 5835 void CodeCompleteObjCPropertySetter(Scope *S, Decl *ClassDecl); 5836 void CodeCompleteObjCPassingType(Scope *S, ObjCDeclSpec &DS, 5837 bool IsParameter); 5838 void CodeCompleteObjCMessageReceiver(Scope *S); 5839 void CodeCompleteObjCSuperMessage(Scope *S, SourceLocation SuperLoc, 5840 IdentifierInfo **SelIdents, 5841 unsigned NumSelIdents, 5842 bool AtArgumentExpression); 5843 void CodeCompleteObjCClassMessage(Scope *S, ParsedType Receiver, 5844 IdentifierInfo **SelIdents, 5845 unsigned NumSelIdents, 5846 bool AtArgumentExpression, 5847 bool IsSuper = false); 5848 void CodeCompleteObjCInstanceMessage(Scope *S, ExprTy *Receiver, 5849 IdentifierInfo **SelIdents, 5850 unsigned NumSelIdents, 5851 bool AtArgumentExpression, 5852 ObjCInterfaceDecl *Super = 0); 5853 void CodeCompleteObjCForCollection(Scope *S, 5854 DeclGroupPtrTy IterationVar); 5855 void CodeCompleteObjCSelector(Scope *S, 5856 IdentifierInfo **SelIdents, 5857 unsigned NumSelIdents); 5858 void CodeCompleteObjCProtocolReferences(IdentifierLocPair *Protocols, 5859 unsigned NumProtocols); 5860 void CodeCompleteObjCProtocolDecl(Scope *S); 5861 void CodeCompleteObjCInterfaceDecl(Scope *S); 5862 void CodeCompleteObjCSuperclass(Scope *S, 5863 IdentifierInfo *ClassName, 5864 SourceLocation ClassNameLoc); 5865 void CodeCompleteObjCImplementationDecl(Scope *S); 5866 void CodeCompleteObjCInterfaceCategory(Scope *S, 5867 IdentifierInfo *ClassName, 5868 SourceLocation ClassNameLoc); 5869 void CodeCompleteObjCImplementationCategory(Scope *S, 5870 IdentifierInfo *ClassName, 5871 SourceLocation ClassNameLoc); 5872 void CodeCompleteObjCPropertyDefinition(Scope *S, Decl *ObjCImpDecl); 5873 void CodeCompleteObjCPropertySynthesizeIvar(Scope *S, 5874 IdentifierInfo *PropertyName, 5875 Decl *ObjCImpDecl); 5876 void CodeCompleteObjCMethodDecl(Scope *S, 5877 bool IsInstanceMethod, 5878 ParsedType ReturnType, 5879 Decl *IDecl); 5880 void CodeCompleteObjCMethodDeclSelector(Scope *S, 5881 bool IsInstanceMethod, 5882 bool AtParameterName, 5883 ParsedType ReturnType, 5884 IdentifierInfo **SelIdents, 5885 unsigned NumSelIdents); 5886 void CodeCompletePreprocessorDirective(bool InConditional); 5887 void CodeCompleteInPreprocessorConditionalExclusion(Scope *S); 5888 void CodeCompletePreprocessorMacroName(bool IsDefinition); 5889 void CodeCompletePreprocessorExpression(); 5890 void CodeCompletePreprocessorMacroArgument(Scope *S, 5891 IdentifierInfo *Macro, 5892 MacroInfo *MacroInfo, 5893 unsigned Argument); 5894 void CodeCompleteNaturalLanguage(); 5895 void GatherGlobalCodeCompletions(CodeCompletionAllocator &Allocator, 5896 SmallVectorImpl<CodeCompletionResult> &Results); 5897 //@} 5898 5899 //===--------------------------------------------------------------------===// 5900 // Extra semantic analysis beyond the C type system 5901 5902public: 5903 SourceLocation getLocationOfStringLiteralByte(const StringLiteral *SL, 5904 unsigned ByteNo) const; 5905 5906private: 5907 void CheckArrayAccess(const Expr *E); 5908 bool CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall); 5909 bool CheckBlockCall(NamedDecl *NDecl, CallExpr *TheCall); 5910 5911 bool CheckablePrintfAttr(const FormatAttr *Format, CallExpr *TheCall); 5912 bool CheckObjCString(Expr *Arg); 5913 5914 ExprResult CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); 5915 bool CheckARMBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); 5916 5917 bool SemaBuiltinVAStart(CallExpr *TheCall); 5918 bool SemaBuiltinUnorderedCompare(CallExpr *TheCall); 5919 bool SemaBuiltinFPClassification(CallExpr *TheCall, unsigned NumArgs); 5920 5921public: 5922 // Used by C++ template instantiation. 5923 ExprResult SemaBuiltinShuffleVector(CallExpr *TheCall); 5924 5925private: 5926 bool SemaBuiltinPrefetch(CallExpr *TheCall); 5927 bool SemaBuiltinObjectSize(CallExpr *TheCall); 5928 bool SemaBuiltinLongjmp(CallExpr *TheCall); 5929 ExprResult SemaBuiltinAtomicOverloaded(ExprResult TheCallResult); 5930 bool SemaBuiltinConstantArg(CallExpr *TheCall, int ArgNum, 5931 llvm::APSInt &Result); 5932 5933 bool SemaCheckStringLiteral(const Expr *E, const CallExpr *TheCall, 5934 bool HasVAListArg, unsigned format_idx, 5935 unsigned firstDataArg, bool isPrintf); 5936 5937 void CheckFormatString(const StringLiteral *FExpr, const Expr *OrigFormatExpr, 5938 const CallExpr *TheCall, bool HasVAListArg, 5939 unsigned format_idx, unsigned firstDataArg, 5940 bool isPrintf); 5941 5942 void CheckNonNullArguments(const NonNullAttr *NonNull, 5943 const Expr * const *ExprArgs, 5944 SourceLocation CallSiteLoc); 5945 5946 void CheckPrintfScanfArguments(const CallExpr *TheCall, bool HasVAListArg, 5947 unsigned format_idx, unsigned firstDataArg, 5948 bool isPrintf); 5949 5950 /// \brief Enumeration used to describe which of the memory setting or copying 5951 /// functions is being checked by \c CheckMemsetcpymoveArguments(). 5952 enum CheckedMemoryFunction { 5953 CMF_Memset, 5954 CMF_Memcpy, 5955 CMF_Memmove 5956 }; 5957 5958 void CheckMemsetcpymoveArguments(const CallExpr *Call, 5959 CheckedMemoryFunction CMF, 5960 IdentifierInfo *FnName); 5961 5962 void CheckReturnStackAddr(Expr *RetValExp, QualType lhsType, 5963 SourceLocation ReturnLoc); 5964 void CheckFloatComparison(SourceLocation loc, Expr* lex, Expr* rex); 5965 void CheckImplicitConversions(Expr *E, SourceLocation CC = SourceLocation()); 5966 5967 void CheckBitFieldInitialization(SourceLocation InitLoc, FieldDecl *Field, 5968 Expr *Init); 5969 5970 /// \brief The parser's current scope. 5971 /// 5972 /// The parser maintains this state here. 5973 Scope *CurScope; 5974 5975protected: 5976 friend class Parser; 5977 friend class InitializationSequence; 5978 friend class ASTReader; 5979 friend class ASTWriter; 5980 5981public: 5982 /// \brief Retrieve the parser's current scope. 5983 /// 5984 /// This routine must only be used when it is certain that semantic analysis 5985 /// and the parser are in precisely the same context, which is not the case 5986 /// when, e.g., we are performing any kind of template instantiation. 5987 /// Therefore, the only safe places to use this scope are in the parser 5988 /// itself and in routines directly invoked from the parser and *never* from 5989 /// template substitution or instantiation. 5990 Scope *getCurScope() const { return CurScope; } 5991}; 5992 5993/// \brief RAII object that enters a new expression evaluation context. 5994class EnterExpressionEvaluationContext { 5995 Sema &Actions; 5996 5997public: 5998 EnterExpressionEvaluationContext(Sema &Actions, 5999 Sema::ExpressionEvaluationContext NewContext) 6000 : Actions(Actions) { 6001 Actions.PushExpressionEvaluationContext(NewContext); 6002 } 6003 6004 ~EnterExpressionEvaluationContext() { 6005 Actions.PopExpressionEvaluationContext(); 6006 } 6007}; 6008 6009} // end namespace clang 6010 6011#endif 6012