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