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