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