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