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