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