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