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