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