Sema.h revision 89ebaed91cca7fd296ec7804e4e9fb68949c1d0e
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, const 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, 1927 const ObjCInterfaceDecl *UnknownObjCClass=0); 1928 1929 void HandleDelayedDeprecationCheck(sema::DelayedDiagnostic &DD, Decl *Ctx); 1930 1931 //===--------------------------------------------------------------------===// 1932 // Expression Parsing Callbacks: SemaExpr.cpp. 1933 1934 bool DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc, 1935 const ObjCInterfaceDecl *UnknownObjCClass=0); 1936 std::string getDeletedOrUnavailableSuffix(const FunctionDecl *FD); 1937 bool DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *PD, 1938 ObjCMethodDecl *Getter, 1939 SourceLocation Loc); 1940 void DiagnoseSentinelCalls(NamedDecl *D, SourceLocation Loc, 1941 Expr **Args, unsigned NumArgs); 1942 1943 void PushExpressionEvaluationContext(ExpressionEvaluationContext NewContext); 1944 1945 void PopExpressionEvaluationContext(); 1946 1947 void MarkDeclarationReferenced(SourceLocation Loc, Decl *D); 1948 void MarkDeclarationsReferencedInType(SourceLocation Loc, QualType T); 1949 void MarkDeclarationsReferencedInExpr(Expr *E); 1950 1951 /// \brief Conditionally issue a diagnostic based on the current 1952 /// evaluation context. 1953 /// 1954 /// \param stmt - If stmt is non-null, delay reporting the diagnostic until 1955 /// the function body is parsed, and then do a basic reachability analysis to 1956 /// determine if the statement is reachable. If it is unreachable, the 1957 /// diagnostic will not be emitted. 1958 bool DiagRuntimeBehavior(SourceLocation Loc, const Stmt *stmt, 1959 const PartialDiagnostic &PD); 1960 1961 // Primary Expressions. 1962 SourceRange getExprRange(Expr *E) const; 1963 1964 ExprResult ActOnIdExpression(Scope *S, CXXScopeSpec &SS, UnqualifiedId &Name, 1965 bool HasTrailingLParen, bool IsAddressOfOperand); 1966 1967 bool DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R, 1968 CorrectTypoContext CTC = CTC_Unknown); 1969 1970 ExprResult LookupInObjCMethod(LookupResult &R, Scope *S, IdentifierInfo *II, 1971 bool AllowBuiltinCreation=false); 1972 1973 ExprResult ActOnDependentIdExpression(const CXXScopeSpec &SS, 1974 const DeclarationNameInfo &NameInfo, 1975 bool isAddressOfOperand, 1976 const TemplateArgumentListInfo *TemplateArgs); 1977 1978 ExprResult BuildDeclRefExpr(ValueDecl *D, QualType Ty, 1979 ExprValueKind VK, 1980 SourceLocation Loc, 1981 const CXXScopeSpec *SS = 0); 1982 ExprResult BuildDeclRefExpr(ValueDecl *D, QualType Ty, 1983 ExprValueKind VK, 1984 const DeclarationNameInfo &NameInfo, 1985 const CXXScopeSpec *SS = 0); 1986 ExprResult 1987 BuildAnonymousStructUnionMemberReference(const CXXScopeSpec &SS, 1988 SourceLocation nameLoc, 1989 IndirectFieldDecl *indirectField, 1990 Expr *baseObjectExpr = 0, 1991 SourceLocation opLoc = SourceLocation()); 1992 ExprResult BuildPossibleImplicitMemberExpr(const CXXScopeSpec &SS, 1993 LookupResult &R, 1994 const TemplateArgumentListInfo *TemplateArgs); 1995 ExprResult BuildImplicitMemberExpr(const CXXScopeSpec &SS, 1996 LookupResult &R, 1997 const TemplateArgumentListInfo *TemplateArgs, 1998 bool IsDefiniteInstance); 1999 bool UseArgumentDependentLookup(const CXXScopeSpec &SS, 2000 const LookupResult &R, 2001 bool HasTrailingLParen); 2002 2003 ExprResult BuildQualifiedDeclarationNameExpr(CXXScopeSpec &SS, 2004 const DeclarationNameInfo &NameInfo); 2005 ExprResult BuildDependentDeclRefExpr(const CXXScopeSpec &SS, 2006 const DeclarationNameInfo &NameInfo, 2007 const TemplateArgumentListInfo *TemplateArgs); 2008 2009 ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS, 2010 LookupResult &R, 2011 bool ADL); 2012 ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS, 2013 const DeclarationNameInfo &NameInfo, 2014 NamedDecl *D); 2015 2016 ExprResult ActOnPredefinedExpr(SourceLocation Loc, tok::TokenKind Kind); 2017 ExprResult ActOnNumericConstant(const Token &); 2018 ExprResult ActOnCharacterConstant(const Token &); 2019 ExprResult ActOnParenExpr(SourceLocation L, SourceLocation R, Expr *Val); 2020 ExprResult ActOnParenOrParenListExpr(SourceLocation L, 2021 SourceLocation R, 2022 MultiExprArg Val, 2023 ParsedType TypeOfCast = ParsedType()); 2024 2025 /// ActOnStringLiteral - The specified tokens were lexed as pasted string 2026 /// fragments (e.g. "foo" "bar" L"baz"). 2027 ExprResult ActOnStringLiteral(const Token *Toks, unsigned NumToks); 2028 2029 ExprResult ActOnGenericSelectionExpr(SourceLocation KeyLoc, 2030 SourceLocation DefaultLoc, 2031 SourceLocation RParenLoc, 2032 Expr *ControllingExpr, 2033 MultiTypeArg Types, 2034 MultiExprArg Exprs); 2035 ExprResult CreateGenericSelectionExpr(SourceLocation KeyLoc, 2036 SourceLocation DefaultLoc, 2037 SourceLocation RParenLoc, 2038 Expr *ControllingExpr, 2039 TypeSourceInfo **Types, 2040 Expr **Exprs, 2041 unsigned NumAssocs); 2042 2043 // Binary/Unary Operators. 'Tok' is the token for the operator. 2044 ExprResult CreateBuiltinUnaryOp(SourceLocation OpLoc, UnaryOperatorKind Opc, 2045 Expr *InputArg); 2046 ExprResult BuildUnaryOp(Scope *S, SourceLocation OpLoc, 2047 UnaryOperatorKind Opc, Expr *input); 2048 ExprResult ActOnUnaryOp(Scope *S, SourceLocation OpLoc, 2049 tok::TokenKind Op, Expr *Input); 2050 2051 ExprResult CreateUnaryExprOrTypeTraitExpr(TypeSourceInfo *T, 2052 SourceLocation OpLoc, 2053 UnaryExprOrTypeTrait ExprKind, 2054 SourceRange R); 2055 ExprResult CreateUnaryExprOrTypeTraitExpr(Expr *E, SourceLocation OpLoc, 2056 UnaryExprOrTypeTrait ExprKind, 2057 SourceRange R); 2058 ExprResult 2059 ActOnUnaryExprOrTypeTraitExpr(SourceLocation OpLoc, 2060 UnaryExprOrTypeTrait ExprKind, 2061 bool isType, void *TyOrEx, 2062 const SourceRange &ArgRange); 2063 2064 ExprResult CheckPlaceholderExpr(Expr *E); 2065 bool CheckVecStepExpr(Expr *E, SourceLocation OpLoc, SourceRange R); 2066 2067 bool CheckUnaryExprOrTypeTraitOperand(QualType type, SourceLocation OpLoc, 2068 SourceRange R, 2069 UnaryExprOrTypeTrait ExprKind); 2070 ExprResult ActOnSizeofParameterPackExpr(Scope *S, 2071 SourceLocation OpLoc, 2072 IdentifierInfo &Name, 2073 SourceLocation NameLoc, 2074 SourceLocation RParenLoc); 2075 ExprResult ActOnPostfixUnaryOp(Scope *S, SourceLocation OpLoc, 2076 tok::TokenKind Kind, Expr *Input); 2077 2078 ExprResult ActOnArraySubscriptExpr(Scope *S, Expr *Base, SourceLocation LLoc, 2079 Expr *Idx, SourceLocation RLoc); 2080 ExprResult CreateBuiltinArraySubscriptExpr(Expr *Base, SourceLocation LLoc, 2081 Expr *Idx, SourceLocation RLoc); 2082 2083 ExprResult BuildMemberReferenceExpr(Expr *Base, QualType BaseType, 2084 SourceLocation OpLoc, bool IsArrow, 2085 CXXScopeSpec &SS, 2086 NamedDecl *FirstQualifierInScope, 2087 const DeclarationNameInfo &NameInfo, 2088 const TemplateArgumentListInfo *TemplateArgs); 2089 2090 ExprResult BuildMemberReferenceExpr(Expr *Base, QualType BaseType, 2091 SourceLocation OpLoc, bool IsArrow, 2092 const CXXScopeSpec &SS, 2093 NamedDecl *FirstQualifierInScope, 2094 LookupResult &R, 2095 const TemplateArgumentListInfo *TemplateArgs, 2096 bool SuppressQualifierCheck = false); 2097 2098 ExprResult LookupMemberExpr(LookupResult &R, ExprResult &Base, 2099 bool &IsArrow, SourceLocation OpLoc, 2100 CXXScopeSpec &SS, 2101 Decl *ObjCImpDecl, 2102 bool HasTemplateArgs); 2103 2104 bool CheckQualifiedMemberReference(Expr *BaseExpr, QualType BaseType, 2105 const CXXScopeSpec &SS, 2106 const LookupResult &R); 2107 2108 ExprResult ActOnDependentMemberExpr(Expr *Base, QualType BaseType, 2109 bool IsArrow, SourceLocation OpLoc, 2110 const CXXScopeSpec &SS, 2111 NamedDecl *FirstQualifierInScope, 2112 const DeclarationNameInfo &NameInfo, 2113 const TemplateArgumentListInfo *TemplateArgs); 2114 2115 ExprResult ActOnMemberAccessExpr(Scope *S, Expr *Base, 2116 SourceLocation OpLoc, 2117 tok::TokenKind OpKind, 2118 CXXScopeSpec &SS, 2119 UnqualifiedId &Member, 2120 Decl *ObjCImpDecl, 2121 bool HasTrailingLParen); 2122 2123 void ActOnDefaultCtorInitializers(Decl *CDtorDecl); 2124 bool ConvertArgumentsForCall(CallExpr *Call, Expr *Fn, 2125 FunctionDecl *FDecl, 2126 const FunctionProtoType *Proto, 2127 Expr **Args, unsigned NumArgs, 2128 SourceLocation RParenLoc); 2129 2130 /// ActOnCallExpr - Handle a call to Fn with the specified array of arguments. 2131 /// This provides the location of the left/right parens and a list of comma 2132 /// locations. 2133 ExprResult ActOnCallExpr(Scope *S, Expr *Fn, SourceLocation LParenLoc, 2134 MultiExprArg Args, SourceLocation RParenLoc, 2135 Expr *ExecConfig = 0); 2136 ExprResult BuildResolvedCallExpr(Expr *Fn, NamedDecl *NDecl, 2137 SourceLocation LParenLoc, 2138 Expr **Args, unsigned NumArgs, 2139 SourceLocation RParenLoc, 2140 Expr *ExecConfig = 0); 2141 2142 ExprResult ActOnCUDAExecConfigExpr(Scope *S, SourceLocation LLLLoc, 2143 MultiExprArg ExecConfig, SourceLocation GGGLoc); 2144 2145 ExprResult ActOnCastExpr(Scope *S, SourceLocation LParenLoc, 2146 ParsedType Ty, SourceLocation RParenLoc, 2147 Expr *Op); 2148 ExprResult BuildCStyleCastExpr(SourceLocation LParenLoc, 2149 TypeSourceInfo *Ty, 2150 SourceLocation RParenLoc, 2151 Expr *Op); 2152 2153 bool TypeIsVectorType(ParsedType Ty) { 2154 return GetTypeFromParser(Ty)->isVectorType(); 2155 } 2156 2157 ExprResult MaybeConvertParenListExprToParenExpr(Scope *S, Expr *ME); 2158 ExprResult ActOnCastOfParenListExpr(Scope *S, SourceLocation LParenLoc, 2159 SourceLocation RParenLoc, Expr *E, 2160 TypeSourceInfo *TInfo); 2161 2162 ExprResult ActOnCompoundLiteral(SourceLocation LParenLoc, 2163 ParsedType Ty, 2164 SourceLocation RParenLoc, 2165 Expr *Op); 2166 2167 ExprResult BuildCompoundLiteralExpr(SourceLocation LParenLoc, 2168 TypeSourceInfo *TInfo, 2169 SourceLocation RParenLoc, 2170 Expr *InitExpr); 2171 2172 ExprResult ActOnInitList(SourceLocation LParenLoc, 2173 MultiExprArg InitList, 2174 SourceLocation RParenLoc); 2175 2176 ExprResult ActOnDesignatedInitializer(Designation &Desig, 2177 SourceLocation Loc, 2178 bool GNUSyntax, 2179 ExprResult Init); 2180 2181 ExprResult ActOnBinOp(Scope *S, SourceLocation TokLoc, 2182 tok::TokenKind Kind, Expr *LHS, Expr *RHS); 2183 ExprResult BuildBinOp(Scope *S, SourceLocation OpLoc, 2184 BinaryOperatorKind Opc, Expr *lhs, Expr *rhs); 2185 ExprResult CreateBuiltinBinOp(SourceLocation TokLoc, 2186 BinaryOperatorKind Opc, Expr *lhs, Expr *rhs); 2187 2188 /// ActOnConditionalOp - Parse a ?: operation. Note that 'LHS' may be null 2189 /// in the case of a the GNU conditional expr extension. 2190 ExprResult ActOnConditionalOp(SourceLocation QuestionLoc, 2191 SourceLocation ColonLoc, 2192 Expr *Cond, Expr *LHS, Expr *RHS); 2193 2194 /// ActOnAddrLabel - Parse the GNU address of label extension: "&&foo". 2195 ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc, 2196 LabelDecl *LD); 2197 2198 ExprResult ActOnStmtExpr(SourceLocation LPLoc, Stmt *SubStmt, 2199 SourceLocation RPLoc); // "({..})" 2200 2201 // __builtin_offsetof(type, identifier(.identifier|[expr])*) 2202 struct OffsetOfComponent { 2203 SourceLocation LocStart, LocEnd; 2204 bool isBrackets; // true if [expr], false if .ident 2205 union { 2206 IdentifierInfo *IdentInfo; 2207 ExprTy *E; 2208 } U; 2209 }; 2210 2211 /// __builtin_offsetof(type, a.b[123][456].c) 2212 ExprResult BuildBuiltinOffsetOf(SourceLocation BuiltinLoc, 2213 TypeSourceInfo *TInfo, 2214 OffsetOfComponent *CompPtr, 2215 unsigned NumComponents, 2216 SourceLocation RParenLoc); 2217 ExprResult ActOnBuiltinOffsetOf(Scope *S, 2218 SourceLocation BuiltinLoc, 2219 SourceLocation TypeLoc, 2220 ParsedType Arg1, 2221 OffsetOfComponent *CompPtr, 2222 unsigned NumComponents, 2223 SourceLocation RParenLoc); 2224 2225 // __builtin_choose_expr(constExpr, expr1, expr2) 2226 ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc, 2227 Expr *cond, Expr *expr1, 2228 Expr *expr2, SourceLocation RPLoc); 2229 2230 // __builtin_va_arg(expr, type) 2231 ExprResult ActOnVAArg(SourceLocation BuiltinLoc, 2232 Expr *expr, ParsedType type, 2233 SourceLocation RPLoc); 2234 ExprResult BuildVAArgExpr(SourceLocation BuiltinLoc, 2235 Expr *expr, TypeSourceInfo *TInfo, 2236 SourceLocation RPLoc); 2237 2238 // __null 2239 ExprResult ActOnGNUNullExpr(SourceLocation TokenLoc); 2240 2241 bool CheckCaseExpression(Expr *expr); 2242 2243 //===------------------------- "Block" Extension ------------------------===// 2244 2245 /// ActOnBlockStart - This callback is invoked when a block literal is 2246 /// started. 2247 void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope); 2248 2249 /// ActOnBlockArguments - This callback allows processing of block arguments. 2250 /// If there are no arguments, this is still invoked. 2251 void ActOnBlockArguments(Declarator &ParamInfo, Scope *CurScope); 2252 2253 /// ActOnBlockError - If there is an error parsing a block, this callback 2254 /// is invoked to pop the information about the block from the action impl. 2255 void ActOnBlockError(SourceLocation CaretLoc, Scope *CurScope); 2256 2257 /// ActOnBlockStmtExpr - This is called when the body of a block statement 2258 /// literal was successfully completed. ^(int x){...} 2259 ExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc, 2260 Stmt *Body, Scope *CurScope); 2261 2262 //===---------------------------- C++ Features --------------------------===// 2263 2264 // Act on C++ namespaces 2265 Decl *ActOnStartNamespaceDef(Scope *S, SourceLocation InlineLoc, 2266 SourceLocation NamespaceLoc, 2267 SourceLocation IdentLoc, 2268 IdentifierInfo *Ident, 2269 SourceLocation LBrace, 2270 AttributeList *AttrList); 2271 void ActOnFinishNamespaceDef(Decl *Dcl, SourceLocation RBrace); 2272 2273 NamespaceDecl *getStdNamespace() const; 2274 NamespaceDecl *getOrCreateStdNamespace(); 2275 2276 CXXRecordDecl *getStdBadAlloc() const; 2277 2278 Decl *ActOnUsingDirective(Scope *CurScope, 2279 SourceLocation UsingLoc, 2280 SourceLocation NamespcLoc, 2281 CXXScopeSpec &SS, 2282 SourceLocation IdentLoc, 2283 IdentifierInfo *NamespcName, 2284 AttributeList *AttrList); 2285 2286 void PushUsingDirective(Scope *S, UsingDirectiveDecl *UDir); 2287 2288 Decl *ActOnNamespaceAliasDef(Scope *CurScope, 2289 SourceLocation NamespaceLoc, 2290 SourceLocation AliasLoc, 2291 IdentifierInfo *Alias, 2292 CXXScopeSpec &SS, 2293 SourceLocation IdentLoc, 2294 IdentifierInfo *Ident); 2295 2296 void HideUsingShadowDecl(Scope *S, UsingShadowDecl *Shadow); 2297 bool CheckUsingShadowDecl(UsingDecl *UD, NamedDecl *Target, 2298 const LookupResult &PreviousDecls); 2299 UsingShadowDecl *BuildUsingShadowDecl(Scope *S, UsingDecl *UD, 2300 NamedDecl *Target); 2301 2302 bool CheckUsingDeclRedeclaration(SourceLocation UsingLoc, 2303 bool isTypeName, 2304 const CXXScopeSpec &SS, 2305 SourceLocation NameLoc, 2306 const LookupResult &Previous); 2307 bool CheckUsingDeclQualifier(SourceLocation UsingLoc, 2308 const CXXScopeSpec &SS, 2309 SourceLocation NameLoc); 2310 2311 NamedDecl *BuildUsingDeclaration(Scope *S, AccessSpecifier AS, 2312 SourceLocation UsingLoc, 2313 CXXScopeSpec &SS, 2314 const DeclarationNameInfo &NameInfo, 2315 AttributeList *AttrList, 2316 bool IsInstantiation, 2317 bool IsTypeName, 2318 SourceLocation TypenameLoc); 2319 2320 bool CheckInheritedConstructorUsingDecl(UsingDecl *UD); 2321 2322 Decl *ActOnUsingDeclaration(Scope *CurScope, 2323 AccessSpecifier AS, 2324 bool HasUsingKeyword, 2325 SourceLocation UsingLoc, 2326 CXXScopeSpec &SS, 2327 UnqualifiedId &Name, 2328 AttributeList *AttrList, 2329 bool IsTypeName, 2330 SourceLocation TypenameLoc); 2331 Decl *ActOnAliasDeclaration(Scope *CurScope, 2332 AccessSpecifier AS, 2333 SourceLocation UsingLoc, 2334 UnqualifiedId &Name, 2335 TypeResult Type); 2336 2337 /// AddCXXDirectInitializerToDecl - This action is called immediately after 2338 /// ActOnDeclarator, when a C++ direct initializer is present. 2339 /// e.g: "int x(1);" 2340 void AddCXXDirectInitializerToDecl(Decl *Dcl, 2341 SourceLocation LParenLoc, 2342 MultiExprArg Exprs, 2343 SourceLocation RParenLoc, 2344 bool TypeMayContainAuto); 2345 2346 /// InitializeVarWithConstructor - Creates an CXXConstructExpr 2347 /// and sets it as the initializer for the the passed in VarDecl. 2348 bool InitializeVarWithConstructor(VarDecl *VD, 2349 CXXConstructorDecl *Constructor, 2350 MultiExprArg Exprs); 2351 2352 /// BuildCXXConstructExpr - Creates a complete call to a constructor, 2353 /// including handling of its default argument expressions. 2354 /// 2355 /// \param ConstructKind - a CXXConstructExpr::ConstructionKind 2356 ExprResult 2357 BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType, 2358 CXXConstructorDecl *Constructor, MultiExprArg Exprs, 2359 bool RequiresZeroInit, unsigned ConstructKind, 2360 SourceRange ParenRange); 2361 2362 // FIXME: Can re remove this and have the above BuildCXXConstructExpr check if 2363 // the constructor can be elidable? 2364 ExprResult 2365 BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType, 2366 CXXConstructorDecl *Constructor, bool Elidable, 2367 MultiExprArg Exprs, bool RequiresZeroInit, 2368 unsigned ConstructKind, 2369 SourceRange ParenRange); 2370 2371 /// BuildCXXDefaultArgExpr - Creates a CXXDefaultArgExpr, instantiating 2372 /// the default expr if needed. 2373 ExprResult BuildCXXDefaultArgExpr(SourceLocation CallLoc, 2374 FunctionDecl *FD, 2375 ParmVarDecl *Param); 2376 2377 /// FinalizeVarWithDestructor - Prepare for calling destructor on the 2378 /// constructed variable. 2379 void FinalizeVarWithDestructor(VarDecl *VD, const RecordType *DeclInitType); 2380 2381 /// \brief Declare the implicit default constructor for the given class. 2382 /// 2383 /// \param ClassDecl The class declaration into which the implicit 2384 /// default constructor will be added. 2385 /// 2386 /// \returns The implicitly-declared default constructor. 2387 CXXConstructorDecl *DeclareImplicitDefaultConstructor( 2388 CXXRecordDecl *ClassDecl); 2389 2390 /// DefineImplicitDefaultConstructor - Checks for feasibility of 2391 /// defining this constructor as the default constructor. 2392 void DefineImplicitDefaultConstructor(SourceLocation CurrentLocation, 2393 CXXConstructorDecl *Constructor); 2394 2395 /// \brief Declare the implicit destructor for the given class. 2396 /// 2397 /// \param ClassDecl The class declaration into which the implicit 2398 /// destructor will be added. 2399 /// 2400 /// \returns The implicitly-declared destructor. 2401 CXXDestructorDecl *DeclareImplicitDestructor(CXXRecordDecl *ClassDecl); 2402 2403 /// DefineImplicitDestructor - Checks for feasibility of 2404 /// defining this destructor as the default destructor. 2405 void DefineImplicitDestructor(SourceLocation CurrentLocation, 2406 CXXDestructorDecl *Destructor); 2407 2408 /// \brief Declare all inherited constructors for the given class. 2409 /// 2410 /// \param ClassDecl The class declaration into which the inherited 2411 /// constructors will be added. 2412 void DeclareInheritedConstructors(CXXRecordDecl *ClassDecl); 2413 2414 /// \brief Declare the implicit copy constructor for the given class. 2415 /// 2416 /// \param S The scope of the class, which may be NULL if this is a 2417 /// template instantiation. 2418 /// 2419 /// \param ClassDecl The class declaration into which the implicit 2420 /// copy constructor will be added. 2421 /// 2422 /// \returns The implicitly-declared copy constructor. 2423 CXXConstructorDecl *DeclareImplicitCopyConstructor(CXXRecordDecl *ClassDecl); 2424 2425 /// DefineImplicitCopyConstructor - Checks for feasibility of 2426 /// defining this constructor as the copy constructor. 2427 void DefineImplicitCopyConstructor(SourceLocation CurrentLocation, 2428 CXXConstructorDecl *Constructor, 2429 unsigned TypeQuals); 2430 2431 /// \brief Declare the implicit copy assignment operator for the given class. 2432 /// 2433 /// \param S The scope of the class, which may be NULL if this is a 2434 /// template instantiation. 2435 /// 2436 /// \param ClassDecl The class declaration into which the implicit 2437 /// copy-assignment operator will be added. 2438 /// 2439 /// \returns The implicitly-declared copy assignment operator. 2440 CXXMethodDecl *DeclareImplicitCopyAssignment(CXXRecordDecl *ClassDecl); 2441 2442 /// \brief Defined an implicitly-declared copy assignment operator. 2443 void DefineImplicitCopyAssignment(SourceLocation CurrentLocation, 2444 CXXMethodDecl *MethodDecl); 2445 2446 /// \brief Force the declaration of any implicitly-declared members of this 2447 /// class. 2448 void ForceDeclarationOfImplicitMembers(CXXRecordDecl *Class); 2449 2450 /// MaybeBindToTemporary - If the passed in expression has a record type with 2451 /// a non-trivial destructor, this will return CXXBindTemporaryExpr. Otherwise 2452 /// it simply returns the passed in expression. 2453 ExprResult MaybeBindToTemporary(Expr *E); 2454 2455 bool CompleteConstructorCall(CXXConstructorDecl *Constructor, 2456 MultiExprArg ArgsPtr, 2457 SourceLocation Loc, 2458 ASTOwningVector<Expr*> &ConvertedArgs); 2459 2460 ParsedType getDestructorName(SourceLocation TildeLoc, 2461 IdentifierInfo &II, SourceLocation NameLoc, 2462 Scope *S, CXXScopeSpec &SS, 2463 ParsedType ObjectType, 2464 bool EnteringContext); 2465 2466 /// ActOnCXXNamedCast - Parse {dynamic,static,reinterpret,const}_cast's. 2467 ExprResult ActOnCXXNamedCast(SourceLocation OpLoc, 2468 tok::TokenKind Kind, 2469 SourceLocation LAngleBracketLoc, 2470 ParsedType Ty, 2471 SourceLocation RAngleBracketLoc, 2472 SourceLocation LParenLoc, 2473 Expr *E, 2474 SourceLocation RParenLoc); 2475 2476 ExprResult BuildCXXNamedCast(SourceLocation OpLoc, 2477 tok::TokenKind Kind, 2478 TypeSourceInfo *Ty, 2479 Expr *E, 2480 SourceRange AngleBrackets, 2481 SourceRange Parens); 2482 2483 ExprResult BuildCXXTypeId(QualType TypeInfoType, 2484 SourceLocation TypeidLoc, 2485 TypeSourceInfo *Operand, 2486 SourceLocation RParenLoc); 2487 ExprResult BuildCXXTypeId(QualType TypeInfoType, 2488 SourceLocation TypeidLoc, 2489 Expr *Operand, 2490 SourceLocation RParenLoc); 2491 2492 /// ActOnCXXTypeid - Parse typeid( something ). 2493 ExprResult ActOnCXXTypeid(SourceLocation OpLoc, 2494 SourceLocation LParenLoc, bool isType, 2495 void *TyOrExpr, 2496 SourceLocation RParenLoc); 2497 2498 ExprResult BuildCXXUuidof(QualType TypeInfoType, 2499 SourceLocation TypeidLoc, 2500 TypeSourceInfo *Operand, 2501 SourceLocation RParenLoc); 2502 ExprResult BuildCXXUuidof(QualType TypeInfoType, 2503 SourceLocation TypeidLoc, 2504 Expr *Operand, 2505 SourceLocation RParenLoc); 2506 2507 /// ActOnCXXUuidof - Parse __uuidof( something ). 2508 ExprResult ActOnCXXUuidof(SourceLocation OpLoc, 2509 SourceLocation LParenLoc, bool isType, 2510 void *TyOrExpr, 2511 SourceLocation RParenLoc); 2512 2513 2514 //// ActOnCXXThis - Parse 'this' pointer. 2515 ExprResult ActOnCXXThis(SourceLocation loc); 2516 2517 /// tryCaptureCXXThis - Try to capture a 'this' pointer. Returns a 2518 /// pointer to an instance method whose 'this' pointer is 2519 /// capturable, or null if this is not possible. 2520 CXXMethodDecl *tryCaptureCXXThis(); 2521 2522 /// ActOnCXXBoolLiteral - Parse {true,false} literals. 2523 ExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind); 2524 2525 /// ActOnCXXNullPtrLiteral - Parse 'nullptr'. 2526 ExprResult ActOnCXXNullPtrLiteral(SourceLocation Loc); 2527 2528 //// ActOnCXXThrow - Parse throw expressions. 2529 ExprResult ActOnCXXThrow(SourceLocation OpLoc, Expr *expr); 2530 ExprResult CheckCXXThrowOperand(SourceLocation ThrowLoc, Expr *E); 2531 2532 /// ActOnCXXTypeConstructExpr - Parse construction of a specified type. 2533 /// Can be interpreted either as function-style casting ("int(x)") 2534 /// or class type construction ("ClassType(x,y,z)") 2535 /// or creation of a value-initialized type ("int()"). 2536 ExprResult ActOnCXXTypeConstructExpr(ParsedType TypeRep, 2537 SourceLocation LParenLoc, 2538 MultiExprArg Exprs, 2539 SourceLocation RParenLoc); 2540 2541 ExprResult BuildCXXTypeConstructExpr(TypeSourceInfo *Type, 2542 SourceLocation LParenLoc, 2543 MultiExprArg Exprs, 2544 SourceLocation RParenLoc); 2545 2546 /// ActOnCXXNew - Parsed a C++ 'new' expression. 2547 ExprResult ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal, 2548 SourceLocation PlacementLParen, 2549 MultiExprArg PlacementArgs, 2550 SourceLocation PlacementRParen, 2551 SourceRange TypeIdParens, Declarator &D, 2552 SourceLocation ConstructorLParen, 2553 MultiExprArg ConstructorArgs, 2554 SourceLocation ConstructorRParen); 2555 ExprResult BuildCXXNew(SourceLocation StartLoc, bool UseGlobal, 2556 SourceLocation PlacementLParen, 2557 MultiExprArg PlacementArgs, 2558 SourceLocation PlacementRParen, 2559 SourceRange TypeIdParens, 2560 QualType AllocType, 2561 TypeSourceInfo *AllocTypeInfo, 2562 Expr *ArraySize, 2563 SourceLocation ConstructorLParen, 2564 MultiExprArg ConstructorArgs, 2565 SourceLocation ConstructorRParen, 2566 bool TypeMayContainAuto = true); 2567 2568 bool CheckAllocatedType(QualType AllocType, SourceLocation Loc, 2569 SourceRange R); 2570 bool FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range, 2571 bool UseGlobal, QualType AllocType, bool IsArray, 2572 Expr **PlaceArgs, unsigned NumPlaceArgs, 2573 FunctionDecl *&OperatorNew, 2574 FunctionDecl *&OperatorDelete); 2575 bool FindAllocationOverload(SourceLocation StartLoc, SourceRange Range, 2576 DeclarationName Name, Expr** Args, 2577 unsigned NumArgs, DeclContext *Ctx, 2578 bool AllowMissing, FunctionDecl *&Operator); 2579 void DeclareGlobalNewDelete(); 2580 void DeclareGlobalAllocationFunction(DeclarationName Name, QualType Return, 2581 QualType Argument, 2582 bool addMallocAttr = false); 2583 2584 bool FindDeallocationFunction(SourceLocation StartLoc, CXXRecordDecl *RD, 2585 DeclarationName Name, FunctionDecl* &Operator); 2586 2587 /// ActOnCXXDelete - Parsed a C++ 'delete' expression 2588 ExprResult ActOnCXXDelete(SourceLocation StartLoc, 2589 bool UseGlobal, bool ArrayForm, 2590 Expr *Operand); 2591 2592 DeclResult ActOnCXXConditionDeclaration(Scope *S, Declarator &D); 2593 ExprResult CheckConditionVariable(VarDecl *ConditionVar, 2594 SourceLocation StmtLoc, 2595 bool ConvertToBoolean); 2596 2597 ExprResult ActOnNoexceptExpr(SourceLocation KeyLoc, SourceLocation LParen, 2598 Expr *Operand, SourceLocation RParen); 2599 ExprResult BuildCXXNoexceptExpr(SourceLocation KeyLoc, Expr *Operand, 2600 SourceLocation RParen); 2601 2602 /// ActOnUnaryTypeTrait - Parsed one of the unary type trait support 2603 /// pseudo-functions. 2604 ExprResult ActOnUnaryTypeTrait(UnaryTypeTrait OTT, 2605 SourceLocation KWLoc, 2606 ParsedType Ty, 2607 SourceLocation RParen); 2608 2609 ExprResult BuildUnaryTypeTrait(UnaryTypeTrait OTT, 2610 SourceLocation KWLoc, 2611 TypeSourceInfo *T, 2612 SourceLocation RParen); 2613 2614 /// ActOnBinaryTypeTrait - Parsed one of the bianry type trait support 2615 /// pseudo-functions. 2616 ExprResult ActOnBinaryTypeTrait(BinaryTypeTrait OTT, 2617 SourceLocation KWLoc, 2618 ParsedType LhsTy, 2619 ParsedType RhsTy, 2620 SourceLocation RParen); 2621 2622 ExprResult BuildBinaryTypeTrait(BinaryTypeTrait BTT, 2623 SourceLocation KWLoc, 2624 TypeSourceInfo *LhsT, 2625 TypeSourceInfo *RhsT, 2626 SourceLocation RParen); 2627 2628 ExprResult ActOnStartCXXMemberReference(Scope *S, 2629 Expr *Base, 2630 SourceLocation OpLoc, 2631 tok::TokenKind OpKind, 2632 ParsedType &ObjectType, 2633 bool &MayBePseudoDestructor); 2634 2635 ExprResult DiagnoseDtorReference(SourceLocation NameLoc, Expr *MemExpr); 2636 2637 ExprResult BuildPseudoDestructorExpr(Expr *Base, 2638 SourceLocation OpLoc, 2639 tok::TokenKind OpKind, 2640 const CXXScopeSpec &SS, 2641 TypeSourceInfo *ScopeType, 2642 SourceLocation CCLoc, 2643 SourceLocation TildeLoc, 2644 PseudoDestructorTypeStorage DestroyedType, 2645 bool HasTrailingLParen); 2646 2647 ExprResult ActOnPseudoDestructorExpr(Scope *S, Expr *Base, 2648 SourceLocation OpLoc, 2649 tok::TokenKind OpKind, 2650 CXXScopeSpec &SS, 2651 UnqualifiedId &FirstTypeName, 2652 SourceLocation CCLoc, 2653 SourceLocation TildeLoc, 2654 UnqualifiedId &SecondTypeName, 2655 bool HasTrailingLParen); 2656 2657 /// MaybeCreateExprWithCleanups - If the current full-expression 2658 /// requires any cleanups, surround it with a ExprWithCleanups node. 2659 /// Otherwise, just returns the passed-in expression. 2660 Expr *MaybeCreateExprWithCleanups(Expr *SubExpr); 2661 Stmt *MaybeCreateStmtWithCleanups(Stmt *SubStmt); 2662 ExprResult MaybeCreateExprWithCleanups(ExprResult SubExpr); 2663 2664 ExprResult ActOnFinishFullExpr(Expr *Expr); 2665 StmtResult ActOnFinishFullStmt(Stmt *Stmt); 2666 2667 // Marks SS invalid if it represents an incomplete type. 2668 bool RequireCompleteDeclContext(CXXScopeSpec &SS, DeclContext *DC); 2669 2670 DeclContext *computeDeclContext(QualType T); 2671 DeclContext *computeDeclContext(const CXXScopeSpec &SS, 2672 bool EnteringContext = false); 2673 bool isDependentScopeSpecifier(const CXXScopeSpec &SS); 2674 CXXRecordDecl *getCurrentInstantiationOf(NestedNameSpecifier *NNS); 2675 bool isUnknownSpecialization(const CXXScopeSpec &SS); 2676 2677 /// \brief The parser has parsed a global nested-name-specifier '::'. 2678 /// 2679 /// \param S The scope in which this nested-name-specifier occurs. 2680 /// 2681 /// \param CCLoc The location of the '::'. 2682 /// 2683 /// \param SS The nested-name-specifier, which will be updated in-place 2684 /// to reflect the parsed nested-name-specifier. 2685 /// 2686 /// \returns true if an error occurred, false otherwise. 2687 bool ActOnCXXGlobalScopeSpecifier(Scope *S, SourceLocation CCLoc, 2688 CXXScopeSpec &SS); 2689 2690 bool isAcceptableNestedNameSpecifier(NamedDecl *SD); 2691 NamedDecl *FindFirstQualifierInScope(Scope *S, NestedNameSpecifier *NNS); 2692 2693 bool isNonTypeNestedNameSpecifier(Scope *S, CXXScopeSpec &SS, 2694 SourceLocation IdLoc, 2695 IdentifierInfo &II, 2696 ParsedType ObjectType); 2697 2698 bool BuildCXXNestedNameSpecifier(Scope *S, 2699 IdentifierInfo &Identifier, 2700 SourceLocation IdentifierLoc, 2701 SourceLocation CCLoc, 2702 QualType ObjectType, 2703 bool EnteringContext, 2704 CXXScopeSpec &SS, 2705 NamedDecl *ScopeLookupResult, 2706 bool ErrorRecoveryLookup); 2707 2708 /// \brief The parser has parsed a nested-name-specifier 'identifier::'. 2709 /// 2710 /// \param S The scope in which this nested-name-specifier occurs. 2711 /// 2712 /// \param Identifier The identifier preceding the '::'. 2713 /// 2714 /// \param IdentifierLoc The location of the identifier. 2715 /// 2716 /// \param CCLoc The location of the '::'. 2717 /// 2718 /// \param ObjectType The type of the object, if we're parsing 2719 /// nested-name-specifier in a member access expression. 2720 /// 2721 /// \param EnteringContext Whether we're entering the context nominated by 2722 /// this nested-name-specifier. 2723 /// 2724 /// \param SS The nested-name-specifier, which is both an input 2725 /// parameter (the nested-name-specifier before this type) and an 2726 /// output parameter (containing the full nested-name-specifier, 2727 /// including this new type). 2728 /// 2729 /// \returns true if an error occurred, false otherwise. 2730 bool ActOnCXXNestedNameSpecifier(Scope *S, 2731 IdentifierInfo &Identifier, 2732 SourceLocation IdentifierLoc, 2733 SourceLocation CCLoc, 2734 ParsedType ObjectType, 2735 bool EnteringContext, 2736 CXXScopeSpec &SS); 2737 2738 bool IsInvalidUnlessNestedName(Scope *S, CXXScopeSpec &SS, 2739 IdentifierInfo &Identifier, 2740 SourceLocation IdentifierLoc, 2741 SourceLocation ColonLoc, 2742 ParsedType ObjectType, 2743 bool EnteringContext); 2744 2745 /// \brief The parser has parsed a nested-name-specifier 2746 /// 'template[opt] template-name < template-args >::'. 2747 /// 2748 /// \param S The scope in which this nested-name-specifier occurs. 2749 /// 2750 /// \param TemplateLoc The location of the 'template' keyword, if any. 2751 /// 2752 /// \param SS The nested-name-specifier, which is both an input 2753 /// parameter (the nested-name-specifier before this type) and an 2754 /// output parameter (containing the full nested-name-specifier, 2755 /// including this new type). 2756 /// 2757 /// \param TemplateLoc the location of the 'template' keyword, if any. 2758 /// \param TemplateName The template name. 2759 /// \param TemplateNameLoc The location of the template name. 2760 /// \param LAngleLoc The location of the opening angle bracket ('<'). 2761 /// \param TemplateArgs The template arguments. 2762 /// \param RAngleLoc The location of the closing angle bracket ('>'). 2763 /// \param CCLoc The location of the '::'. 2764 2765 /// \param EnteringContext Whether we're entering the context of the 2766 /// nested-name-specifier. 2767 /// 2768 /// 2769 /// \returns true if an error occurred, false otherwise. 2770 bool ActOnCXXNestedNameSpecifier(Scope *S, 2771 SourceLocation TemplateLoc, 2772 CXXScopeSpec &SS, 2773 TemplateTy Template, 2774 SourceLocation TemplateNameLoc, 2775 SourceLocation LAngleLoc, 2776 ASTTemplateArgsPtr TemplateArgs, 2777 SourceLocation RAngleLoc, 2778 SourceLocation CCLoc, 2779 bool EnteringContext); 2780 2781 /// \brief Given a C++ nested-name-specifier, produce an annotation value 2782 /// that the parser can use later to reconstruct the given 2783 /// nested-name-specifier. 2784 /// 2785 /// \param SS A nested-name-specifier. 2786 /// 2787 /// \returns A pointer containing all of the information in the 2788 /// nested-name-specifier \p SS. 2789 void *SaveNestedNameSpecifierAnnotation(CXXScopeSpec &SS); 2790 2791 /// \brief Given an annotation pointer for a nested-name-specifier, restore 2792 /// the nested-name-specifier structure. 2793 /// 2794 /// \param Annotation The annotation pointer, produced by 2795 /// \c SaveNestedNameSpecifierAnnotation(). 2796 /// 2797 /// \param AnnotationRange The source range corresponding to the annotation. 2798 /// 2799 /// \param SS The nested-name-specifier that will be updated with the contents 2800 /// of the annotation pointer. 2801 void RestoreNestedNameSpecifierAnnotation(void *Annotation, 2802 SourceRange AnnotationRange, 2803 CXXScopeSpec &SS); 2804 2805 bool ShouldEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS); 2806 2807 /// ActOnCXXEnterDeclaratorScope - Called when a C++ scope specifier (global 2808 /// scope or nested-name-specifier) is parsed, part of a declarator-id. 2809 /// After this method is called, according to [C++ 3.4.3p3], names should be 2810 /// looked up in the declarator-id's scope, until the declarator is parsed and 2811 /// ActOnCXXExitDeclaratorScope is called. 2812 /// The 'SS' should be a non-empty valid CXXScopeSpec. 2813 bool ActOnCXXEnterDeclaratorScope(Scope *S, CXXScopeSpec &SS); 2814 2815 /// ActOnCXXExitDeclaratorScope - Called when a declarator that previously 2816 /// invoked ActOnCXXEnterDeclaratorScope(), is finished. 'SS' is the same 2817 /// CXXScopeSpec that was passed to ActOnCXXEnterDeclaratorScope as well. 2818 /// Used to indicate that names should revert to being looked up in the 2819 /// defining scope. 2820 void ActOnCXXExitDeclaratorScope(Scope *S, const CXXScopeSpec &SS); 2821 2822 /// ActOnCXXEnterDeclInitializer - Invoked when we are about to parse an 2823 /// initializer for the declaration 'Dcl'. 2824 /// After this method is called, according to [C++ 3.4.1p13], if 'Dcl' is a 2825 /// static data member of class X, names should be looked up in the scope of 2826 /// class X. 2827 void ActOnCXXEnterDeclInitializer(Scope *S, Decl *Dcl); 2828 2829 /// ActOnCXXExitDeclInitializer - Invoked after we are finished parsing an 2830 /// initializer for the declaration 'Dcl'. 2831 void ActOnCXXExitDeclInitializer(Scope *S, Decl *Dcl); 2832 2833 // ParseObjCStringLiteral - Parse Objective-C string literals. 2834 ExprResult ParseObjCStringLiteral(SourceLocation *AtLocs, 2835 Expr **Strings, 2836 unsigned NumStrings); 2837 2838 Expr *BuildObjCEncodeExpression(SourceLocation AtLoc, 2839 TypeSourceInfo *EncodedTypeInfo, 2840 SourceLocation RParenLoc); 2841 ExprResult BuildCXXMemberCallExpr(Expr *Exp, NamedDecl *FoundDecl, 2842 CXXMethodDecl *Method); 2843 2844 ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc, 2845 SourceLocation EncodeLoc, 2846 SourceLocation LParenLoc, 2847 ParsedType Ty, 2848 SourceLocation RParenLoc); 2849 2850 // ParseObjCSelectorExpression - Build selector expression for @selector 2851 ExprResult ParseObjCSelectorExpression(Selector Sel, 2852 SourceLocation AtLoc, 2853 SourceLocation SelLoc, 2854 SourceLocation LParenLoc, 2855 SourceLocation RParenLoc); 2856 2857 // ParseObjCProtocolExpression - Build protocol expression for @protocol 2858 ExprResult ParseObjCProtocolExpression(IdentifierInfo * ProtocolName, 2859 SourceLocation AtLoc, 2860 SourceLocation ProtoLoc, 2861 SourceLocation LParenLoc, 2862 SourceLocation RParenLoc); 2863 2864 //===--------------------------------------------------------------------===// 2865 // C++ Declarations 2866 // 2867 Decl *ActOnStartLinkageSpecification(Scope *S, 2868 SourceLocation ExternLoc, 2869 SourceLocation LangLoc, 2870 llvm::StringRef Lang, 2871 SourceLocation LBraceLoc); 2872 Decl *ActOnFinishLinkageSpecification(Scope *S, 2873 Decl *LinkageSpec, 2874 SourceLocation RBraceLoc); 2875 2876 2877 //===--------------------------------------------------------------------===// 2878 // C++ Classes 2879 // 2880 bool isCurrentClassName(const IdentifierInfo &II, Scope *S, 2881 const CXXScopeSpec *SS = 0); 2882 2883 Decl *ActOnAccessSpecifier(AccessSpecifier Access, 2884 SourceLocation ASLoc, 2885 SourceLocation ColonLoc); 2886 2887 Decl *ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS, 2888 Declarator &D, 2889 MultiTemplateParamsArg TemplateParameterLists, 2890 Expr *BitfieldWidth, const VirtSpecifiers &VS, 2891 Expr *Init, bool IsDefinition, 2892 bool Deleted = false); 2893 2894 MemInitResult ActOnMemInitializer(Decl *ConstructorD, 2895 Scope *S, 2896 CXXScopeSpec &SS, 2897 IdentifierInfo *MemberOrBase, 2898 ParsedType TemplateTypeTy, 2899 SourceLocation IdLoc, 2900 SourceLocation LParenLoc, 2901 Expr **Args, unsigned NumArgs, 2902 SourceLocation RParenLoc, 2903 SourceLocation EllipsisLoc); 2904 2905 MemInitResult BuildMemberInitializer(ValueDecl *Member, Expr **Args, 2906 unsigned NumArgs, SourceLocation IdLoc, 2907 SourceLocation LParenLoc, 2908 SourceLocation RParenLoc); 2909 2910 MemInitResult BuildBaseInitializer(QualType BaseType, 2911 TypeSourceInfo *BaseTInfo, 2912 Expr **Args, unsigned NumArgs, 2913 SourceLocation LParenLoc, 2914 SourceLocation RParenLoc, 2915 CXXRecordDecl *ClassDecl, 2916 SourceLocation EllipsisLoc); 2917 2918 MemInitResult BuildDelegatingInitializer(TypeSourceInfo *TInfo, 2919 Expr **Args, unsigned NumArgs, 2920 SourceLocation BaseLoc, 2921 SourceLocation RParenLoc, 2922 SourceLocation LParenLoc, 2923 CXXRecordDecl *ClassDecl); 2924 2925 bool SetCtorInitializers(CXXConstructorDecl *Constructor, 2926 CXXCtorInitializer **Initializers, 2927 unsigned NumInitializers, bool AnyErrors); 2928 2929 void SetIvarInitializers(ObjCImplementationDecl *ObjCImplementation); 2930 2931 2932 /// MarkBaseAndMemberDestructorsReferenced - Given a record decl, 2933 /// mark all the non-trivial destructors of its members and bases as 2934 /// referenced. 2935 void MarkBaseAndMemberDestructorsReferenced(SourceLocation Loc, 2936 CXXRecordDecl *Record); 2937 2938 /// \brief The list of classes whose vtables have been used within 2939 /// this translation unit, and the source locations at which the 2940 /// first use occurred. 2941 typedef std::pair<CXXRecordDecl*, SourceLocation> VTableUse; 2942 2943 /// \brief The list of vtables that are required but have not yet been 2944 /// materialized. 2945 llvm::SmallVector<VTableUse, 16> VTableUses; 2946 2947 /// \brief The set of classes whose vtables have been used within 2948 /// this translation unit, and a bit that will be true if the vtable is 2949 /// required to be emitted (otherwise, it should be emitted only if needed 2950 /// by code generation). 2951 llvm::DenseMap<CXXRecordDecl *, bool> VTablesUsed; 2952 2953 /// \brief A list of all of the dynamic classes in this translation 2954 /// unit. 2955 llvm::SmallVector<CXXRecordDecl *, 16> DynamicClasses; 2956 2957 /// \brief Note that the vtable for the given class was used at the 2958 /// given location. 2959 void MarkVTableUsed(SourceLocation Loc, CXXRecordDecl *Class, 2960 bool DefinitionRequired = false); 2961 2962 /// MarkVirtualMembersReferenced - Will mark all members of the given 2963 /// CXXRecordDecl referenced. 2964 void MarkVirtualMembersReferenced(SourceLocation Loc, 2965 const CXXRecordDecl *RD); 2966 2967 /// \brief Define all of the vtables that have been used in this 2968 /// translation unit and reference any virtual members used by those 2969 /// vtables. 2970 /// 2971 /// \returns true if any work was done, false otherwise. 2972 bool DefineUsedVTables(); 2973 2974 void AddImplicitlyDeclaredMembersToClass(CXXRecordDecl *ClassDecl); 2975 2976 void ActOnMemInitializers(Decl *ConstructorDecl, 2977 SourceLocation ColonLoc, 2978 MemInitTy **MemInits, unsigned NumMemInits, 2979 bool AnyErrors); 2980 2981 void CheckCompletedCXXClass(CXXRecordDecl *Record); 2982 void ActOnFinishCXXMemberSpecification(Scope* S, SourceLocation RLoc, 2983 Decl *TagDecl, 2984 SourceLocation LBrac, 2985 SourceLocation RBrac, 2986 AttributeList *AttrList); 2987 2988 void ActOnReenterTemplateScope(Scope *S, Decl *Template); 2989 void ActOnReenterDeclaratorTemplateScope(Scope *S, DeclaratorDecl *D); 2990 void ActOnStartDelayedMemberDeclarations(Scope *S, Decl *Record); 2991 void ActOnStartDelayedCXXMethodDeclaration(Scope *S, Decl *Method); 2992 void ActOnDelayedCXXMethodParameter(Scope *S, Decl *Param); 2993 void ActOnFinishDelayedCXXMethodDeclaration(Scope *S, Decl *Method); 2994 void ActOnFinishDelayedMemberDeclarations(Scope *S, Decl *Record); 2995 void MarkAsLateParsedTemplate(FunctionDecl *FD, bool Flag = true); 2996 bool IsInsideALocalClassWithinATemplateFunction(); 2997 2998 Decl *ActOnStaticAssertDeclaration(SourceLocation StaticAssertLoc, 2999 Expr *AssertExpr, 3000 Expr *AssertMessageExpr, 3001 SourceLocation RParenLoc); 3002 3003 FriendDecl *CheckFriendTypeDecl(SourceLocation FriendLoc, 3004 TypeSourceInfo *TSInfo); 3005 Decl *ActOnFriendTypeDecl(Scope *S, const DeclSpec &DS, 3006 MultiTemplateParamsArg TemplateParams); 3007 Decl *ActOnFriendFunctionDecl(Scope *S, Declarator &D, bool IsDefinition, 3008 MultiTemplateParamsArg TemplateParams); 3009 3010 QualType CheckConstructorDeclarator(Declarator &D, QualType R, 3011 StorageClass& SC); 3012 void CheckConstructor(CXXConstructorDecl *Constructor); 3013 QualType CheckDestructorDeclarator(Declarator &D, QualType R, 3014 StorageClass& SC); 3015 bool CheckDestructor(CXXDestructorDecl *Destructor); 3016 void CheckConversionDeclarator(Declarator &D, QualType &R, 3017 StorageClass& SC); 3018 Decl *ActOnConversionDeclarator(CXXConversionDecl *Conversion); 3019 3020 //===--------------------------------------------------------------------===// 3021 // C++ Derived Classes 3022 // 3023 3024 /// ActOnBaseSpecifier - Parsed a base specifier 3025 CXXBaseSpecifier *CheckBaseSpecifier(CXXRecordDecl *Class, 3026 SourceRange SpecifierRange, 3027 bool Virtual, AccessSpecifier Access, 3028 TypeSourceInfo *TInfo, 3029 SourceLocation EllipsisLoc); 3030 3031 BaseResult ActOnBaseSpecifier(Decl *classdecl, 3032 SourceRange SpecifierRange, 3033 bool Virtual, AccessSpecifier Access, 3034 ParsedType basetype, 3035 SourceLocation BaseLoc, 3036 SourceLocation EllipsisLoc); 3037 3038 bool AttachBaseSpecifiers(CXXRecordDecl *Class, CXXBaseSpecifier **Bases, 3039 unsigned NumBases); 3040 void ActOnBaseSpecifiers(Decl *ClassDecl, BaseTy **Bases, unsigned NumBases); 3041 3042 bool IsDerivedFrom(QualType Derived, QualType Base); 3043 bool IsDerivedFrom(QualType Derived, QualType Base, CXXBasePaths &Paths); 3044 3045 // FIXME: I don't like this name. 3046 void BuildBasePathArray(const CXXBasePaths &Paths, CXXCastPath &BasePath); 3047 3048 bool BasePathInvolvesVirtualBase(const CXXCastPath &BasePath); 3049 3050 bool CheckDerivedToBaseConversion(QualType Derived, QualType Base, 3051 SourceLocation Loc, SourceRange Range, 3052 CXXCastPath *BasePath = 0, 3053 bool IgnoreAccess = false); 3054 bool CheckDerivedToBaseConversion(QualType Derived, QualType Base, 3055 unsigned InaccessibleBaseID, 3056 unsigned AmbigiousBaseConvID, 3057 SourceLocation Loc, SourceRange Range, 3058 DeclarationName Name, 3059 CXXCastPath *BasePath); 3060 3061 std::string getAmbiguousPathsDisplayString(CXXBasePaths &Paths); 3062 3063 /// CheckOverridingFunctionReturnType - Checks whether the return types are 3064 /// covariant, according to C++ [class.virtual]p5. 3065 bool CheckOverridingFunctionReturnType(const CXXMethodDecl *New, 3066 const CXXMethodDecl *Old); 3067 3068 /// CheckOverridingFunctionExceptionSpec - Checks whether the exception 3069 /// spec is a subset of base spec. 3070 bool CheckOverridingFunctionExceptionSpec(const CXXMethodDecl *New, 3071 const CXXMethodDecl *Old); 3072 3073 bool CheckPureMethod(CXXMethodDecl *Method, SourceRange InitRange); 3074 3075 /// CheckOverrideControl - Check C++0x override control semantics. 3076 void CheckOverrideControl(const Decl *D); 3077 3078 /// CheckForFunctionMarkedFinal - Checks whether a virtual member function 3079 /// overrides a virtual member function marked 'final', according to 3080 /// C++0x [class.virtual]p3. 3081 bool CheckIfOverriddenFunctionIsMarkedFinal(const CXXMethodDecl *New, 3082 const CXXMethodDecl *Old); 3083 3084 3085 //===--------------------------------------------------------------------===// 3086 // C++ Access Control 3087 // 3088 3089 enum AccessResult { 3090 AR_accessible, 3091 AR_inaccessible, 3092 AR_dependent, 3093 AR_delayed 3094 }; 3095 3096 bool SetMemberAccessSpecifier(NamedDecl *MemberDecl, 3097 NamedDecl *PrevMemberDecl, 3098 AccessSpecifier LexicalAS); 3099 3100 AccessResult CheckUnresolvedMemberAccess(UnresolvedMemberExpr *E, 3101 DeclAccessPair FoundDecl); 3102 AccessResult CheckUnresolvedLookupAccess(UnresolvedLookupExpr *E, 3103 DeclAccessPair FoundDecl); 3104 AccessResult CheckAllocationAccess(SourceLocation OperatorLoc, 3105 SourceRange PlacementRange, 3106 CXXRecordDecl *NamingClass, 3107 DeclAccessPair FoundDecl); 3108 AccessResult CheckConstructorAccess(SourceLocation Loc, 3109 CXXConstructorDecl *D, 3110 const InitializedEntity &Entity, 3111 AccessSpecifier Access, 3112 bool IsCopyBindingRefToTemp = false); 3113 AccessResult CheckDestructorAccess(SourceLocation Loc, 3114 CXXDestructorDecl *Dtor, 3115 const PartialDiagnostic &PDiag); 3116 AccessResult CheckDirectMemberAccess(SourceLocation Loc, 3117 NamedDecl *D, 3118 const PartialDiagnostic &PDiag); 3119 AccessResult CheckMemberOperatorAccess(SourceLocation Loc, 3120 Expr *ObjectExpr, 3121 Expr *ArgExpr, 3122 DeclAccessPair FoundDecl); 3123 AccessResult CheckAddressOfMemberAccess(Expr *OvlExpr, 3124 DeclAccessPair FoundDecl); 3125 AccessResult CheckBaseClassAccess(SourceLocation AccessLoc, 3126 QualType Base, QualType Derived, 3127 const CXXBasePath &Path, 3128 unsigned DiagID, 3129 bool ForceCheck = false, 3130 bool ForceUnprivileged = false); 3131 void CheckLookupAccess(const LookupResult &R); 3132 3133 void HandleDependentAccessCheck(const DependentDiagnostic &DD, 3134 const MultiLevelTemplateArgumentList &TemplateArgs); 3135 void PerformDependentDiagnostics(const DeclContext *Pattern, 3136 const MultiLevelTemplateArgumentList &TemplateArgs); 3137 3138 void HandleDelayedAccessCheck(sema::DelayedDiagnostic &DD, Decl *Ctx); 3139 3140 /// A flag to suppress access checking. 3141 bool SuppressAccessChecking; 3142 3143 /// \brief When true, access checking violations are treated as SFINAE 3144 /// failures rather than hard errors. 3145 bool AccessCheckingSFINAE; 3146 3147 void ActOnStartSuppressingAccessChecks(); 3148 void ActOnStopSuppressingAccessChecks(); 3149 3150 enum AbstractDiagSelID { 3151 AbstractNone = -1, 3152 AbstractReturnType, 3153 AbstractParamType, 3154 AbstractVariableType, 3155 AbstractFieldType, 3156 AbstractArrayType 3157 }; 3158 3159 bool RequireNonAbstractType(SourceLocation Loc, QualType T, 3160 const PartialDiagnostic &PD); 3161 void DiagnoseAbstractType(const CXXRecordDecl *RD); 3162 3163 bool RequireNonAbstractType(SourceLocation Loc, QualType T, unsigned DiagID, 3164 AbstractDiagSelID SelID = AbstractNone); 3165 3166 //===--------------------------------------------------------------------===// 3167 // C++ Overloaded Operators [C++ 13.5] 3168 // 3169 3170 bool CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl); 3171 3172 bool CheckLiteralOperatorDeclaration(FunctionDecl *FnDecl); 3173 3174 //===--------------------------------------------------------------------===// 3175 // C++ Templates [C++ 14] 3176 // 3177 void LookupTemplateName(LookupResult &R, Scope *S, CXXScopeSpec &SS, 3178 QualType ObjectType, bool EnteringContext, 3179 bool &MemberOfUnknownSpecialization); 3180 3181 TemplateNameKind isTemplateName(Scope *S, 3182 CXXScopeSpec &SS, 3183 bool hasTemplateKeyword, 3184 UnqualifiedId &Name, 3185 ParsedType ObjectType, 3186 bool EnteringContext, 3187 TemplateTy &Template, 3188 bool &MemberOfUnknownSpecialization); 3189 3190 bool DiagnoseUnknownTemplateName(const IdentifierInfo &II, 3191 SourceLocation IILoc, 3192 Scope *S, 3193 const CXXScopeSpec *SS, 3194 TemplateTy &SuggestedTemplate, 3195 TemplateNameKind &SuggestedKind); 3196 3197 bool DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl); 3198 TemplateDecl *AdjustDeclIfTemplate(Decl *&Decl); 3199 3200 Decl *ActOnTypeParameter(Scope *S, bool Typename, bool Ellipsis, 3201 SourceLocation EllipsisLoc, 3202 SourceLocation KeyLoc, 3203 IdentifierInfo *ParamName, 3204 SourceLocation ParamNameLoc, 3205 unsigned Depth, unsigned Position, 3206 SourceLocation EqualLoc, 3207 ParsedType DefaultArg); 3208 3209 QualType CheckNonTypeTemplateParameterType(QualType T, SourceLocation Loc); 3210 Decl *ActOnNonTypeTemplateParameter(Scope *S, Declarator &D, 3211 unsigned Depth, 3212 unsigned Position, 3213 SourceLocation EqualLoc, 3214 Expr *DefaultArg); 3215 Decl *ActOnTemplateTemplateParameter(Scope *S, 3216 SourceLocation TmpLoc, 3217 TemplateParamsTy *Params, 3218 SourceLocation EllipsisLoc, 3219 IdentifierInfo *ParamName, 3220 SourceLocation ParamNameLoc, 3221 unsigned Depth, 3222 unsigned Position, 3223 SourceLocation EqualLoc, 3224 ParsedTemplateArgument DefaultArg); 3225 3226 TemplateParamsTy * 3227 ActOnTemplateParameterList(unsigned Depth, 3228 SourceLocation ExportLoc, 3229 SourceLocation TemplateLoc, 3230 SourceLocation LAngleLoc, 3231 Decl **Params, unsigned NumParams, 3232 SourceLocation RAngleLoc); 3233 3234 /// \brief The context in which we are checking a template parameter 3235 /// list. 3236 enum TemplateParamListContext { 3237 TPC_ClassTemplate, 3238 TPC_FunctionTemplate, 3239 TPC_ClassTemplateMember, 3240 TPC_FriendFunctionTemplate, 3241 TPC_FriendFunctionTemplateDefinition 3242 }; 3243 3244 bool CheckTemplateParameterList(TemplateParameterList *NewParams, 3245 TemplateParameterList *OldParams, 3246 TemplateParamListContext TPC); 3247 TemplateParameterList * 3248 MatchTemplateParametersToScopeSpecifier(SourceLocation DeclStartLoc, 3249 const CXXScopeSpec &SS, 3250 TemplateParameterList **ParamLists, 3251 unsigned NumParamLists, 3252 bool IsFriend, 3253 bool &IsExplicitSpecialization, 3254 bool &Invalid); 3255 3256 DeclResult CheckClassTemplate(Scope *S, unsigned TagSpec, TagUseKind TUK, 3257 SourceLocation KWLoc, CXXScopeSpec &SS, 3258 IdentifierInfo *Name, SourceLocation NameLoc, 3259 AttributeList *Attr, 3260 TemplateParameterList *TemplateParams, 3261 AccessSpecifier AS, 3262 unsigned NumOuterTemplateParamLists, 3263 TemplateParameterList **OuterTemplateParamLists); 3264 3265 void translateTemplateArguments(const ASTTemplateArgsPtr &In, 3266 TemplateArgumentListInfo &Out); 3267 3268 void NoteAllFoundTemplates(TemplateName Name); 3269 3270 QualType CheckTemplateIdType(TemplateName Template, 3271 SourceLocation TemplateLoc, 3272 TemplateArgumentListInfo &TemplateArgs); 3273 3274 TypeResult 3275 ActOnTemplateIdType(CXXScopeSpec &SS, 3276 TemplateTy Template, SourceLocation TemplateLoc, 3277 SourceLocation LAngleLoc, 3278 ASTTemplateArgsPtr TemplateArgs, 3279 SourceLocation RAngleLoc); 3280 3281 /// \brief Parsed an elaborated-type-specifier that refers to a template-id, 3282 /// such as \c class T::template apply<U>. 3283 /// 3284 /// \param TUK 3285 TypeResult ActOnTagTemplateIdType(TagUseKind TUK, 3286 TypeSpecifierType TagSpec, 3287 SourceLocation TagLoc, 3288 CXXScopeSpec &SS, 3289 TemplateTy TemplateD, 3290 SourceLocation TemplateLoc, 3291 SourceLocation LAngleLoc, 3292 ASTTemplateArgsPtr TemplateArgsIn, 3293 SourceLocation RAngleLoc); 3294 3295 3296 ExprResult BuildTemplateIdExpr(const CXXScopeSpec &SS, 3297 LookupResult &R, 3298 bool RequiresADL, 3299 const TemplateArgumentListInfo &TemplateArgs); 3300 ExprResult BuildQualifiedTemplateIdExpr(CXXScopeSpec &SS, 3301 const DeclarationNameInfo &NameInfo, 3302 const TemplateArgumentListInfo &TemplateArgs); 3303 3304 TemplateNameKind ActOnDependentTemplateName(Scope *S, 3305 SourceLocation TemplateKWLoc, 3306 CXXScopeSpec &SS, 3307 UnqualifiedId &Name, 3308 ParsedType ObjectType, 3309 bool EnteringContext, 3310 TemplateTy &Template); 3311 3312 DeclResult 3313 ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, TagUseKind TUK, 3314 SourceLocation KWLoc, 3315 CXXScopeSpec &SS, 3316 TemplateTy Template, 3317 SourceLocation TemplateNameLoc, 3318 SourceLocation LAngleLoc, 3319 ASTTemplateArgsPtr TemplateArgs, 3320 SourceLocation RAngleLoc, 3321 AttributeList *Attr, 3322 MultiTemplateParamsArg TemplateParameterLists); 3323 3324 Decl *ActOnTemplateDeclarator(Scope *S, 3325 MultiTemplateParamsArg TemplateParameterLists, 3326 Declarator &D); 3327 3328 Decl *ActOnStartOfFunctionTemplateDef(Scope *FnBodyScope, 3329 MultiTemplateParamsArg TemplateParameterLists, 3330 Declarator &D); 3331 3332 bool 3333 CheckSpecializationInstantiationRedecl(SourceLocation NewLoc, 3334 TemplateSpecializationKind NewTSK, 3335 NamedDecl *PrevDecl, 3336 TemplateSpecializationKind PrevTSK, 3337 SourceLocation PrevPtOfInstantiation, 3338 bool &SuppressNew); 3339 3340 bool CheckDependentFunctionTemplateSpecialization(FunctionDecl *FD, 3341 const TemplateArgumentListInfo &ExplicitTemplateArgs, 3342 LookupResult &Previous); 3343 3344 bool CheckFunctionTemplateSpecialization(FunctionDecl *FD, 3345 TemplateArgumentListInfo *ExplicitTemplateArgs, 3346 LookupResult &Previous); 3347 bool CheckMemberSpecialization(NamedDecl *Member, LookupResult &Previous); 3348 3349 DeclResult 3350 ActOnExplicitInstantiation(Scope *S, 3351 SourceLocation ExternLoc, 3352 SourceLocation TemplateLoc, 3353 unsigned TagSpec, 3354 SourceLocation KWLoc, 3355 const CXXScopeSpec &SS, 3356 TemplateTy Template, 3357 SourceLocation TemplateNameLoc, 3358 SourceLocation LAngleLoc, 3359 ASTTemplateArgsPtr TemplateArgs, 3360 SourceLocation RAngleLoc, 3361 AttributeList *Attr); 3362 3363 DeclResult 3364 ActOnExplicitInstantiation(Scope *S, 3365 SourceLocation ExternLoc, 3366 SourceLocation TemplateLoc, 3367 unsigned TagSpec, 3368 SourceLocation KWLoc, 3369 CXXScopeSpec &SS, 3370 IdentifierInfo *Name, 3371 SourceLocation NameLoc, 3372 AttributeList *Attr); 3373 3374 DeclResult ActOnExplicitInstantiation(Scope *S, 3375 SourceLocation ExternLoc, 3376 SourceLocation TemplateLoc, 3377 Declarator &D); 3378 3379 TemplateArgumentLoc 3380 SubstDefaultTemplateArgumentIfAvailable(TemplateDecl *Template, 3381 SourceLocation TemplateLoc, 3382 SourceLocation RAngleLoc, 3383 Decl *Param, 3384 llvm::SmallVectorImpl<TemplateArgument> &Converted); 3385 3386 /// \brief Specifies the context in which a particular template 3387 /// argument is being checked. 3388 enum CheckTemplateArgumentKind { 3389 /// \brief The template argument was specified in the code or was 3390 /// instantiated with some deduced template arguments. 3391 CTAK_Specified, 3392 3393 /// \brief The template argument was deduced via template argument 3394 /// deduction. 3395 CTAK_Deduced, 3396 3397 /// \brief The template argument was deduced from an array bound 3398 /// via template argument deduction. 3399 CTAK_DeducedFromArrayBound 3400 }; 3401 3402 bool CheckTemplateArgument(NamedDecl *Param, 3403 const TemplateArgumentLoc &Arg, 3404 NamedDecl *Template, 3405 SourceLocation TemplateLoc, 3406 SourceLocation RAngleLoc, 3407 unsigned ArgumentPackIndex, 3408 llvm::SmallVectorImpl<TemplateArgument> &Converted, 3409 CheckTemplateArgumentKind CTAK = CTAK_Specified); 3410 3411 /// \brief Check that the given template arguments can be be provided to 3412 /// the given template, converting the arguments along the way. 3413 /// 3414 /// \param Template The template to which the template arguments are being 3415 /// provided. 3416 /// 3417 /// \param TemplateLoc The location of the template name in the source. 3418 /// 3419 /// \param TemplateArgs The list of template arguments. If the template is 3420 /// a template template parameter, this function may extend the set of 3421 /// template arguments to also include substituted, defaulted template 3422 /// arguments. 3423 /// 3424 /// \param PartialTemplateArgs True if the list of template arguments is 3425 /// intentionally partial, e.g., because we're checking just the initial 3426 /// set of template arguments. 3427 /// 3428 /// \param Converted Will receive the converted, canonicalized template 3429 /// arguments. 3430 /// 3431 /// \returns True if an error occurred, false otherwise. 3432 bool CheckTemplateArgumentList(TemplateDecl *Template, 3433 SourceLocation TemplateLoc, 3434 TemplateArgumentListInfo &TemplateArgs, 3435 bool PartialTemplateArgs, 3436 llvm::SmallVectorImpl<TemplateArgument> &Converted); 3437 3438 bool CheckTemplateTypeArgument(TemplateTypeParmDecl *Param, 3439 const TemplateArgumentLoc &Arg, 3440 llvm::SmallVectorImpl<TemplateArgument> &Converted); 3441 3442 bool CheckTemplateArgument(TemplateTypeParmDecl *Param, 3443 TypeSourceInfo *Arg); 3444 bool CheckTemplateArgumentPointerToMember(Expr *Arg, 3445 TemplateArgument &Converted); 3446 ExprResult CheckTemplateArgument(NonTypeTemplateParmDecl *Param, 3447 QualType InstantiatedParamType, Expr *Arg, 3448 TemplateArgument &Converted, 3449 CheckTemplateArgumentKind CTAK = CTAK_Specified); 3450 bool CheckTemplateArgument(TemplateTemplateParmDecl *Param, 3451 const TemplateArgumentLoc &Arg); 3452 3453 ExprResult 3454 BuildExpressionFromDeclTemplateArgument(const TemplateArgument &Arg, 3455 QualType ParamType, 3456 SourceLocation Loc); 3457 ExprResult 3458 BuildExpressionFromIntegralTemplateArgument(const TemplateArgument &Arg, 3459 SourceLocation Loc); 3460 3461 /// \brief Enumeration describing how template parameter lists are compared 3462 /// for equality. 3463 enum TemplateParameterListEqualKind { 3464 /// \brief We are matching the template parameter lists of two templates 3465 /// that might be redeclarations. 3466 /// 3467 /// \code 3468 /// template<typename T> struct X; 3469 /// template<typename T> struct X; 3470 /// \endcode 3471 TPL_TemplateMatch, 3472 3473 /// \brief We are matching the template parameter lists of two template 3474 /// template parameters as part of matching the template parameter lists 3475 /// of two templates that might be redeclarations. 3476 /// 3477 /// \code 3478 /// template<template<int I> class TT> struct X; 3479 /// template<template<int Value> class Other> struct X; 3480 /// \endcode 3481 TPL_TemplateTemplateParmMatch, 3482 3483 /// \brief We are matching the template parameter lists of a template 3484 /// template argument against the template parameter lists of a template 3485 /// template parameter. 3486 /// 3487 /// \code 3488 /// template<template<int Value> class Metafun> struct X; 3489 /// template<int Value> struct integer_c; 3490 /// X<integer_c> xic; 3491 /// \endcode 3492 TPL_TemplateTemplateArgumentMatch 3493 }; 3494 3495 bool TemplateParameterListsAreEqual(TemplateParameterList *New, 3496 TemplateParameterList *Old, 3497 bool Complain, 3498 TemplateParameterListEqualKind Kind, 3499 SourceLocation TemplateArgLoc 3500 = SourceLocation()); 3501 3502 bool CheckTemplateDeclScope(Scope *S, TemplateParameterList *TemplateParams); 3503 3504 /// \brief Called when the parser has parsed a C++ typename 3505 /// specifier, e.g., "typename T::type". 3506 /// 3507 /// \param S The scope in which this typename type occurs. 3508 /// \param TypenameLoc the location of the 'typename' keyword 3509 /// \param SS the nested-name-specifier following the typename (e.g., 'T::'). 3510 /// \param II the identifier we're retrieving (e.g., 'type' in the example). 3511 /// \param IdLoc the location of the identifier. 3512 TypeResult 3513 ActOnTypenameType(Scope *S, SourceLocation TypenameLoc, 3514 const CXXScopeSpec &SS, const IdentifierInfo &II, 3515 SourceLocation IdLoc); 3516 3517 /// \brief Called when the parser has parsed a C++ typename 3518 /// specifier that ends in a template-id, e.g., 3519 /// "typename MetaFun::template apply<T1, T2>". 3520 /// 3521 /// \param S The scope in which this typename type occurs. 3522 /// \param TypenameLoc the location of the 'typename' keyword 3523 /// \param SS the nested-name-specifier following the typename (e.g., 'T::'). 3524 /// \param TemplateLoc the location of the 'template' keyword, if any. 3525 /// \param TemplateName The template name. 3526 /// \param TemplateNameLoc The location of the template name. 3527 /// \param LAngleLoc The location of the opening angle bracket ('<'). 3528 /// \param TemplateArgs The template arguments. 3529 /// \param RAngleLoc The location of the closing angle bracket ('>'). 3530 TypeResult 3531 ActOnTypenameType(Scope *S, SourceLocation TypenameLoc, 3532 const CXXScopeSpec &SS, 3533 SourceLocation TemplateLoc, 3534 TemplateTy Template, 3535 SourceLocation TemplateNameLoc, 3536 SourceLocation LAngleLoc, 3537 ASTTemplateArgsPtr TemplateArgs, 3538 SourceLocation RAngleLoc); 3539 3540 QualType CheckTypenameType(ElaboratedTypeKeyword Keyword, 3541 SourceLocation KeywordLoc, 3542 NestedNameSpecifierLoc QualifierLoc, 3543 const IdentifierInfo &II, 3544 SourceLocation IILoc); 3545 3546 TypeSourceInfo *RebuildTypeInCurrentInstantiation(TypeSourceInfo *T, 3547 SourceLocation Loc, 3548 DeclarationName Name); 3549 bool RebuildNestedNameSpecifierInCurrentInstantiation(CXXScopeSpec &SS); 3550 3551 ExprResult RebuildExprInCurrentInstantiation(Expr *E); 3552 3553 std::string 3554 getTemplateArgumentBindingsText(const TemplateParameterList *Params, 3555 const TemplateArgumentList &Args); 3556 3557 std::string 3558 getTemplateArgumentBindingsText(const TemplateParameterList *Params, 3559 const TemplateArgument *Args, 3560 unsigned NumArgs); 3561 3562 //===--------------------------------------------------------------------===// 3563 // C++ Variadic Templates (C++0x [temp.variadic]) 3564 //===--------------------------------------------------------------------===// 3565 3566 /// \brief The context in which an unexpanded parameter pack is 3567 /// being diagnosed. 3568 /// 3569 /// Note that the values of this enumeration line up with the first 3570 /// argument to the \c err_unexpanded_parameter_pack diagnostic. 3571 enum UnexpandedParameterPackContext { 3572 /// \brief An arbitrary expression. 3573 UPPC_Expression = 0, 3574 3575 /// \brief The base type of a class type. 3576 UPPC_BaseType, 3577 3578 /// \brief The type of an arbitrary declaration. 3579 UPPC_DeclarationType, 3580 3581 /// \brief The type of a data member. 3582 UPPC_DataMemberType, 3583 3584 /// \brief The size of a bit-field. 3585 UPPC_BitFieldWidth, 3586 3587 /// \brief The expression in a static assertion. 3588 UPPC_StaticAssertExpression, 3589 3590 /// \brief The fixed underlying type of an enumeration. 3591 UPPC_FixedUnderlyingType, 3592 3593 /// \brief The enumerator value. 3594 UPPC_EnumeratorValue, 3595 3596 /// \brief A using declaration. 3597 UPPC_UsingDeclaration, 3598 3599 /// \brief A friend declaration. 3600 UPPC_FriendDeclaration, 3601 3602 /// \brief A declaration qualifier. 3603 UPPC_DeclarationQualifier, 3604 3605 /// \brief An initializer. 3606 UPPC_Initializer, 3607 3608 /// \brief A default argument. 3609 UPPC_DefaultArgument, 3610 3611 /// \brief The type of a non-type template parameter. 3612 UPPC_NonTypeTemplateParameterType, 3613 3614 /// \brief The type of an exception. 3615 UPPC_ExceptionType, 3616 3617 /// \brief Partial specialization. 3618 UPPC_PartialSpecialization 3619 }; 3620 3621 /// \brief If the given type contains an unexpanded parameter pack, 3622 /// diagnose the error. 3623 /// 3624 /// \param Loc The source location where a diagnostc should be emitted. 3625 /// 3626 /// \param T The type that is being checked for unexpanded parameter 3627 /// packs. 3628 /// 3629 /// \returns true if an error occurred, false otherwise. 3630 bool DiagnoseUnexpandedParameterPack(SourceLocation Loc, TypeSourceInfo *T, 3631 UnexpandedParameterPackContext UPPC); 3632 3633 /// \brief If the given expression contains an unexpanded parameter 3634 /// pack, diagnose the error. 3635 /// 3636 /// \param E The expression that is being checked for unexpanded 3637 /// parameter packs. 3638 /// 3639 /// \returns true if an error occurred, false otherwise. 3640 bool DiagnoseUnexpandedParameterPack(Expr *E, 3641 UnexpandedParameterPackContext UPPC = UPPC_Expression); 3642 3643 /// \brief If the given nested-name-specifier contains an unexpanded 3644 /// parameter pack, diagnose the error. 3645 /// 3646 /// \param SS The nested-name-specifier that is being checked for 3647 /// unexpanded parameter packs. 3648 /// 3649 /// \returns true if an error occurred, false otherwise. 3650 bool DiagnoseUnexpandedParameterPack(const CXXScopeSpec &SS, 3651 UnexpandedParameterPackContext UPPC); 3652 3653 /// \brief If the given name contains an unexpanded parameter pack, 3654 /// diagnose the error. 3655 /// 3656 /// \param NameInfo The name (with source location information) that 3657 /// is being checked for unexpanded parameter packs. 3658 /// 3659 /// \returns true if an error occurred, false otherwise. 3660 bool DiagnoseUnexpandedParameterPack(const DeclarationNameInfo &NameInfo, 3661 UnexpandedParameterPackContext UPPC); 3662 3663 /// \brief If the given template name contains an unexpanded parameter pack, 3664 /// diagnose the error. 3665 /// 3666 /// \param Loc The location of the template name. 3667 /// 3668 /// \param Template The template name that is being checked for unexpanded 3669 /// parameter packs. 3670 /// 3671 /// \returns true if an error occurred, false otherwise. 3672 bool DiagnoseUnexpandedParameterPack(SourceLocation Loc, 3673 TemplateName Template, 3674 UnexpandedParameterPackContext UPPC); 3675 3676 /// \brief If the given template argument contains an unexpanded parameter 3677 /// pack, diagnose the error. 3678 /// 3679 /// \param Arg The template argument that is being checked for unexpanded 3680 /// parameter packs. 3681 /// 3682 /// \returns true if an error occurred, false otherwise. 3683 bool DiagnoseUnexpandedParameterPack(TemplateArgumentLoc Arg, 3684 UnexpandedParameterPackContext UPPC); 3685 3686 /// \brief Collect the set of unexpanded parameter packs within the given 3687 /// template argument. 3688 /// 3689 /// \param Arg The template argument that will be traversed to find 3690 /// unexpanded parameter packs. 3691 void collectUnexpandedParameterPacks(TemplateArgument Arg, 3692 llvm::SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); 3693 3694 /// \brief Collect the set of unexpanded parameter packs within the given 3695 /// template argument. 3696 /// 3697 /// \param Arg The template argument that will be traversed to find 3698 /// unexpanded parameter packs. 3699 void collectUnexpandedParameterPacks(TemplateArgumentLoc Arg, 3700 llvm::SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); 3701 3702 /// \brief Collect the set of unexpanded parameter packs within the given 3703 /// type. 3704 /// 3705 /// \param T The type that will be traversed to find 3706 /// unexpanded parameter packs. 3707 void collectUnexpandedParameterPacks(QualType T, 3708 llvm::SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); 3709 3710 /// \brief Collect the set of unexpanded parameter packs within the given 3711 /// type. 3712 /// 3713 /// \param TL The type that will be traversed to find 3714 /// unexpanded parameter packs. 3715 void collectUnexpandedParameterPacks(TypeLoc TL, 3716 llvm::SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); 3717 3718 /// \brief Invoked when parsing a template argument followed by an 3719 /// ellipsis, which creates a pack expansion. 3720 /// 3721 /// \param Arg The template argument preceding the ellipsis, which 3722 /// may already be invalid. 3723 /// 3724 /// \param EllipsisLoc The location of the ellipsis. 3725 ParsedTemplateArgument ActOnPackExpansion(const ParsedTemplateArgument &Arg, 3726 SourceLocation EllipsisLoc); 3727 3728 /// \brief Invoked when parsing a type followed by an ellipsis, which 3729 /// creates a pack expansion. 3730 /// 3731 /// \param Type The type preceding the ellipsis, which will become 3732 /// the pattern of the pack expansion. 3733 /// 3734 /// \param EllipsisLoc The location of the ellipsis. 3735 TypeResult ActOnPackExpansion(ParsedType Type, SourceLocation EllipsisLoc); 3736 3737 /// \brief Construct a pack expansion type from the pattern of the pack 3738 /// expansion. 3739 TypeSourceInfo *CheckPackExpansion(TypeSourceInfo *Pattern, 3740 SourceLocation EllipsisLoc, 3741 llvm::Optional<unsigned> NumExpansions); 3742 3743 /// \brief Construct a pack expansion type from the pattern of the pack 3744 /// expansion. 3745 QualType CheckPackExpansion(QualType Pattern, 3746 SourceRange PatternRange, 3747 SourceLocation EllipsisLoc, 3748 llvm::Optional<unsigned> NumExpansions); 3749 3750 /// \brief Invoked when parsing an expression followed by an ellipsis, which 3751 /// creates a pack expansion. 3752 /// 3753 /// \param Pattern The expression preceding the ellipsis, which will become 3754 /// the pattern of the pack expansion. 3755 /// 3756 /// \param EllipsisLoc The location of the ellipsis. 3757 ExprResult ActOnPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc); 3758 3759 /// \brief Invoked when parsing an expression followed by an ellipsis, which 3760 /// creates a pack expansion. 3761 /// 3762 /// \param Pattern The expression preceding the ellipsis, which will become 3763 /// the pattern of the pack expansion. 3764 /// 3765 /// \param EllipsisLoc The location of the ellipsis. 3766 ExprResult CheckPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc, 3767 llvm::Optional<unsigned> NumExpansions); 3768 3769 /// \brief Determine whether we could expand a pack expansion with the 3770 /// given set of parameter packs into separate arguments by repeatedly 3771 /// transforming the pattern. 3772 /// 3773 /// \param EllipsisLoc The location of the ellipsis that identifies the 3774 /// pack expansion. 3775 /// 3776 /// \param PatternRange The source range that covers the entire pattern of 3777 /// the pack expansion. 3778 /// 3779 /// \param Unexpanded The set of unexpanded parameter packs within the 3780 /// pattern. 3781 /// 3782 /// \param NumUnexpanded The number of unexpanded parameter packs in 3783 /// \p Unexpanded. 3784 /// 3785 /// \param ShouldExpand Will be set to \c true if the transformer should 3786 /// expand the corresponding pack expansions into separate arguments. When 3787 /// set, \c NumExpansions must also be set. 3788 /// 3789 /// \param RetainExpansion Whether the caller should add an unexpanded 3790 /// pack expansion after all of the expanded arguments. This is used 3791 /// when extending explicitly-specified template argument packs per 3792 /// C++0x [temp.arg.explicit]p9. 3793 /// 3794 /// \param NumExpansions The number of separate arguments that will be in 3795 /// the expanded form of the corresponding pack expansion. This is both an 3796 /// input and an output parameter, which can be set by the caller if the 3797 /// number of expansions is known a priori (e.g., due to a prior substitution) 3798 /// and will be set by the callee when the number of expansions is known. 3799 /// The callee must set this value when \c ShouldExpand is \c true; it may 3800 /// set this value in other cases. 3801 /// 3802 /// \returns true if an error occurred (e.g., because the parameter packs 3803 /// are to be instantiated with arguments of different lengths), false 3804 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions) 3805 /// must be set. 3806 bool CheckParameterPacksForExpansion(SourceLocation EllipsisLoc, 3807 SourceRange PatternRange, 3808 const UnexpandedParameterPack *Unexpanded, 3809 unsigned NumUnexpanded, 3810 const MultiLevelTemplateArgumentList &TemplateArgs, 3811 bool &ShouldExpand, 3812 bool &RetainExpansion, 3813 llvm::Optional<unsigned> &NumExpansions); 3814 3815 /// \brief Determine the number of arguments in the given pack expansion 3816 /// type. 3817 /// 3818 /// This routine already assumes that the pack expansion type can be 3819 /// expanded and that the number of arguments in the expansion is 3820 /// consistent across all of the unexpanded parameter packs in its pattern. 3821 unsigned getNumArgumentsInExpansion(QualType T, 3822 const MultiLevelTemplateArgumentList &TemplateArgs); 3823 3824 /// \brief Determine whether the given declarator contains any unexpanded 3825 /// parameter packs. 3826 /// 3827 /// This routine is used by the parser to disambiguate function declarators 3828 /// with an ellipsis prior to the ')', e.g., 3829 /// 3830 /// \code 3831 /// void f(T...); 3832 /// \endcode 3833 /// 3834 /// To determine whether we have an (unnamed) function parameter pack or 3835 /// a variadic function. 3836 /// 3837 /// \returns true if the declarator contains any unexpanded parameter packs, 3838 /// false otherwise. 3839 bool containsUnexpandedParameterPacks(Declarator &D); 3840 3841 //===--------------------------------------------------------------------===// 3842 // C++ Template Argument Deduction (C++ [temp.deduct]) 3843 //===--------------------------------------------------------------------===// 3844 3845 /// \brief Describes the result of template argument deduction. 3846 /// 3847 /// The TemplateDeductionResult enumeration describes the result of 3848 /// template argument deduction, as returned from 3849 /// DeduceTemplateArguments(). The separate TemplateDeductionInfo 3850 /// structure provides additional information about the results of 3851 /// template argument deduction, e.g., the deduced template argument 3852 /// list (if successful) or the specific template parameters or 3853 /// deduced arguments that were involved in the failure. 3854 enum TemplateDeductionResult { 3855 /// \brief Template argument deduction was successful. 3856 TDK_Success = 0, 3857 /// \brief Template argument deduction exceeded the maximum template 3858 /// instantiation depth (which has already been diagnosed). 3859 TDK_InstantiationDepth, 3860 /// \brief Template argument deduction did not deduce a value 3861 /// for every template parameter. 3862 TDK_Incomplete, 3863 /// \brief Template argument deduction produced inconsistent 3864 /// deduced values for the given template parameter. 3865 TDK_Inconsistent, 3866 /// \brief Template argument deduction failed due to inconsistent 3867 /// cv-qualifiers on a template parameter type that would 3868 /// otherwise be deduced, e.g., we tried to deduce T in "const T" 3869 /// but were given a non-const "X". 3870 TDK_Underqualified, 3871 /// \brief Substitution of the deduced template argument values 3872 /// resulted in an error. 3873 TDK_SubstitutionFailure, 3874 /// \brief Substitution of the deduced template argument values 3875 /// into a non-deduced context produced a type or value that 3876 /// produces a type that does not match the original template 3877 /// arguments provided. 3878 TDK_NonDeducedMismatch, 3879 /// \brief When performing template argument deduction for a function 3880 /// template, there were too many call arguments. 3881 TDK_TooManyArguments, 3882 /// \brief When performing template argument deduction for a function 3883 /// template, there were too few call arguments. 3884 TDK_TooFewArguments, 3885 /// \brief The explicitly-specified template arguments were not valid 3886 /// template arguments for the given template. 3887 TDK_InvalidExplicitArguments, 3888 /// \brief The arguments included an overloaded function name that could 3889 /// not be resolved to a suitable function. 3890 TDK_FailedOverloadResolution 3891 }; 3892 3893 TemplateDeductionResult 3894 DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial, 3895 const TemplateArgumentList &TemplateArgs, 3896 sema::TemplateDeductionInfo &Info); 3897 3898 TemplateDeductionResult 3899 SubstituteExplicitTemplateArguments(FunctionTemplateDecl *FunctionTemplate, 3900 TemplateArgumentListInfo &ExplicitTemplateArgs, 3901 llvm::SmallVectorImpl<DeducedTemplateArgument> &Deduced, 3902 llvm::SmallVectorImpl<QualType> &ParamTypes, 3903 QualType *FunctionType, 3904 sema::TemplateDeductionInfo &Info); 3905 3906 TemplateDeductionResult 3907 FinishTemplateArgumentDeduction(FunctionTemplateDecl *FunctionTemplate, 3908 llvm::SmallVectorImpl<DeducedTemplateArgument> &Deduced, 3909 unsigned NumExplicitlySpecified, 3910 FunctionDecl *&Specialization, 3911 sema::TemplateDeductionInfo &Info); 3912 3913 TemplateDeductionResult 3914 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, 3915 TemplateArgumentListInfo *ExplicitTemplateArgs, 3916 Expr **Args, unsigned NumArgs, 3917 FunctionDecl *&Specialization, 3918 sema::TemplateDeductionInfo &Info); 3919 3920 TemplateDeductionResult 3921 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, 3922 TemplateArgumentListInfo *ExplicitTemplateArgs, 3923 QualType ArgFunctionType, 3924 FunctionDecl *&Specialization, 3925 sema::TemplateDeductionInfo &Info); 3926 3927 TemplateDeductionResult 3928 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, 3929 QualType ToType, 3930 CXXConversionDecl *&Specialization, 3931 sema::TemplateDeductionInfo &Info); 3932 3933 TemplateDeductionResult 3934 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, 3935 TemplateArgumentListInfo *ExplicitTemplateArgs, 3936 FunctionDecl *&Specialization, 3937 sema::TemplateDeductionInfo &Info); 3938 3939 bool DeduceAutoType(TypeSourceInfo *AutoType, Expr *Initializer, 3940 TypeSourceInfo *&Result); 3941 3942 FunctionTemplateDecl *getMoreSpecializedTemplate(FunctionTemplateDecl *FT1, 3943 FunctionTemplateDecl *FT2, 3944 SourceLocation Loc, 3945 TemplatePartialOrderingContext TPOC, 3946 unsigned NumCallArguments); 3947 UnresolvedSetIterator getMostSpecialized(UnresolvedSetIterator SBegin, 3948 UnresolvedSetIterator SEnd, 3949 TemplatePartialOrderingContext TPOC, 3950 unsigned NumCallArguments, 3951 SourceLocation Loc, 3952 const PartialDiagnostic &NoneDiag, 3953 const PartialDiagnostic &AmbigDiag, 3954 const PartialDiagnostic &CandidateDiag, 3955 bool Complain = true); 3956 3957 ClassTemplatePartialSpecializationDecl * 3958 getMoreSpecializedPartialSpecialization( 3959 ClassTemplatePartialSpecializationDecl *PS1, 3960 ClassTemplatePartialSpecializationDecl *PS2, 3961 SourceLocation Loc); 3962 3963 void MarkUsedTemplateParameters(const TemplateArgumentList &TemplateArgs, 3964 bool OnlyDeduced, 3965 unsigned Depth, 3966 llvm::SmallVectorImpl<bool> &Used); 3967 void MarkDeducedTemplateParameters(FunctionTemplateDecl *FunctionTemplate, 3968 llvm::SmallVectorImpl<bool> &Deduced); 3969 3970 //===--------------------------------------------------------------------===// 3971 // C++ Template Instantiation 3972 // 3973 3974 MultiLevelTemplateArgumentList getTemplateInstantiationArgs(NamedDecl *D, 3975 const TemplateArgumentList *Innermost = 0, 3976 bool RelativeToPrimary = false, 3977 const FunctionDecl *Pattern = 0); 3978 3979 /// \brief A template instantiation that is currently in progress. 3980 struct ActiveTemplateInstantiation { 3981 /// \brief The kind of template instantiation we are performing 3982 enum InstantiationKind { 3983 /// We are instantiating a template declaration. The entity is 3984 /// the declaration we're instantiating (e.g., a CXXRecordDecl). 3985 TemplateInstantiation, 3986 3987 /// We are instantiating a default argument for a template 3988 /// parameter. The Entity is the template, and 3989 /// TemplateArgs/NumTemplateArguments provides the template 3990 /// arguments as specified. 3991 /// FIXME: Use a TemplateArgumentList 3992 DefaultTemplateArgumentInstantiation, 3993 3994 /// We are instantiating a default argument for a function. 3995 /// The Entity is the ParmVarDecl, and TemplateArgs/NumTemplateArgs 3996 /// provides the template arguments as specified. 3997 DefaultFunctionArgumentInstantiation, 3998 3999 /// We are substituting explicit template arguments provided for 4000 /// a function template. The entity is a FunctionTemplateDecl. 4001 ExplicitTemplateArgumentSubstitution, 4002 4003 /// We are substituting template argument determined as part of 4004 /// template argument deduction for either a class template 4005 /// partial specialization or a function template. The 4006 /// Entity is either a ClassTemplatePartialSpecializationDecl or 4007 /// a FunctionTemplateDecl. 4008 DeducedTemplateArgumentSubstitution, 4009 4010 /// We are substituting prior template arguments into a new 4011 /// template parameter. The template parameter itself is either a 4012 /// NonTypeTemplateParmDecl or a TemplateTemplateParmDecl. 4013 PriorTemplateArgumentSubstitution, 4014 4015 /// We are checking the validity of a default template argument that 4016 /// has been used when naming a template-id. 4017 DefaultTemplateArgumentChecking 4018 } Kind; 4019 4020 /// \brief The point of instantiation within the source code. 4021 SourceLocation PointOfInstantiation; 4022 4023 /// \brief The template (or partial specialization) in which we are 4024 /// performing the instantiation, for substitutions of prior template 4025 /// arguments. 4026 NamedDecl *Template; 4027 4028 /// \brief The entity that is being instantiated. 4029 uintptr_t Entity; 4030 4031 /// \brief The list of template arguments we are substituting, if they 4032 /// are not part of the entity. 4033 const TemplateArgument *TemplateArgs; 4034 4035 /// \brief The number of template arguments in TemplateArgs. 4036 unsigned NumTemplateArgs; 4037 4038 /// \brief The template deduction info object associated with the 4039 /// substitution or checking of explicit or deduced template arguments. 4040 sema::TemplateDeductionInfo *DeductionInfo; 4041 4042 /// \brief The source range that covers the construct that cause 4043 /// the instantiation, e.g., the template-id that causes a class 4044 /// template instantiation. 4045 SourceRange InstantiationRange; 4046 4047 ActiveTemplateInstantiation() 4048 : Kind(TemplateInstantiation), Template(0), Entity(0), TemplateArgs(0), 4049 NumTemplateArgs(0), DeductionInfo(0) {} 4050 4051 /// \brief Determines whether this template is an actual instantiation 4052 /// that should be counted toward the maximum instantiation depth. 4053 bool isInstantiationRecord() const; 4054 4055 friend bool operator==(const ActiveTemplateInstantiation &X, 4056 const ActiveTemplateInstantiation &Y) { 4057 if (X.Kind != Y.Kind) 4058 return false; 4059 4060 if (X.Entity != Y.Entity) 4061 return false; 4062 4063 switch (X.Kind) { 4064 case TemplateInstantiation: 4065 return true; 4066 4067 case PriorTemplateArgumentSubstitution: 4068 case DefaultTemplateArgumentChecking: 4069 if (X.Template != Y.Template) 4070 return false; 4071 4072 // Fall through 4073 4074 case DefaultTemplateArgumentInstantiation: 4075 case ExplicitTemplateArgumentSubstitution: 4076 case DeducedTemplateArgumentSubstitution: 4077 case DefaultFunctionArgumentInstantiation: 4078 return X.TemplateArgs == Y.TemplateArgs; 4079 4080 } 4081 4082 return true; 4083 } 4084 4085 friend bool operator!=(const ActiveTemplateInstantiation &X, 4086 const ActiveTemplateInstantiation &Y) { 4087 return !(X == Y); 4088 } 4089 }; 4090 4091 /// \brief List of active template instantiations. 4092 /// 4093 /// This vector is treated as a stack. As one template instantiation 4094 /// requires another template instantiation, additional 4095 /// instantiations are pushed onto the stack up to a 4096 /// user-configurable limit LangOptions::InstantiationDepth. 4097 llvm::SmallVector<ActiveTemplateInstantiation, 16> 4098 ActiveTemplateInstantiations; 4099 4100 /// \brief Whether we are in a SFINAE context that is not associated with 4101 /// template instantiation. 4102 /// 4103 /// This is used when setting up a SFINAE trap (\c see SFINAETrap) outside 4104 /// of a template instantiation or template argument deduction. 4105 bool InNonInstantiationSFINAEContext; 4106 4107 /// \brief The number of ActiveTemplateInstantiation entries in 4108 /// \c ActiveTemplateInstantiations that are not actual instantiations and, 4109 /// therefore, should not be counted as part of the instantiation depth. 4110 unsigned NonInstantiationEntries; 4111 4112 /// \brief The last template from which a template instantiation 4113 /// error or warning was produced. 4114 /// 4115 /// This value is used to suppress printing of redundant template 4116 /// instantiation backtraces when there are multiple errors in the 4117 /// same instantiation. FIXME: Does this belong in Sema? It's tough 4118 /// to implement it anywhere else. 4119 ActiveTemplateInstantiation LastTemplateInstantiationErrorContext; 4120 4121 /// \brief The current index into pack expansion arguments that will be 4122 /// used for substitution of parameter packs. 4123 /// 4124 /// The pack expansion index will be -1 to indicate that parameter packs 4125 /// should be instantiated as themselves. Otherwise, the index specifies 4126 /// which argument within the parameter pack will be used for substitution. 4127 int ArgumentPackSubstitutionIndex; 4128 4129 /// \brief RAII object used to change the argument pack substitution index 4130 /// within a \c Sema object. 4131 /// 4132 /// See \c ArgumentPackSubstitutionIndex for more information. 4133 class ArgumentPackSubstitutionIndexRAII { 4134 Sema &Self; 4135 int OldSubstitutionIndex; 4136 4137 public: 4138 ArgumentPackSubstitutionIndexRAII(Sema &Self, int NewSubstitutionIndex) 4139 : Self(Self), OldSubstitutionIndex(Self.ArgumentPackSubstitutionIndex) { 4140 Self.ArgumentPackSubstitutionIndex = NewSubstitutionIndex; 4141 } 4142 4143 ~ArgumentPackSubstitutionIndexRAII() { 4144 Self.ArgumentPackSubstitutionIndex = OldSubstitutionIndex; 4145 } 4146 }; 4147 4148 friend class ArgumentPackSubstitutionRAII; 4149 4150 /// \brief The stack of calls expression undergoing template instantiation. 4151 /// 4152 /// The top of this stack is used by a fixit instantiating unresolved 4153 /// function calls to fix the AST to match the textual change it prints. 4154 llvm::SmallVector<CallExpr *, 8> CallsUndergoingInstantiation; 4155 4156 /// \brief For each declaration that involved template argument deduction, the 4157 /// set of diagnostics that were suppressed during that template argument 4158 /// deduction. 4159 /// 4160 /// FIXME: Serialize this structure to the AST file. 4161 llvm::DenseMap<Decl *, llvm::SmallVector<PartialDiagnosticAt, 1> > 4162 SuppressedDiagnostics; 4163 4164 /// \brief A stack object to be created when performing template 4165 /// instantiation. 4166 /// 4167 /// Construction of an object of type \c InstantiatingTemplate 4168 /// pushes the current instantiation onto the stack of active 4169 /// instantiations. If the size of this stack exceeds the maximum 4170 /// number of recursive template instantiations, construction 4171 /// produces an error and evaluates true. 4172 /// 4173 /// Destruction of this object will pop the named instantiation off 4174 /// the stack. 4175 struct InstantiatingTemplate { 4176 /// \brief Note that we are instantiating a class template, 4177 /// function template, or a member thereof. 4178 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 4179 Decl *Entity, 4180 SourceRange InstantiationRange = SourceRange()); 4181 4182 /// \brief Note that we are instantiating a default argument in a 4183 /// template-id. 4184 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 4185 TemplateDecl *Template, 4186 const TemplateArgument *TemplateArgs, 4187 unsigned NumTemplateArgs, 4188 SourceRange InstantiationRange = SourceRange()); 4189 4190 /// \brief Note that we are instantiating a default argument in a 4191 /// template-id. 4192 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 4193 FunctionTemplateDecl *FunctionTemplate, 4194 const TemplateArgument *TemplateArgs, 4195 unsigned NumTemplateArgs, 4196 ActiveTemplateInstantiation::InstantiationKind Kind, 4197 sema::TemplateDeductionInfo &DeductionInfo, 4198 SourceRange InstantiationRange = SourceRange()); 4199 4200 /// \brief Note that we are instantiating as part of template 4201 /// argument deduction for a class template partial 4202 /// specialization. 4203 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 4204 ClassTemplatePartialSpecializationDecl *PartialSpec, 4205 const TemplateArgument *TemplateArgs, 4206 unsigned NumTemplateArgs, 4207 sema::TemplateDeductionInfo &DeductionInfo, 4208 SourceRange InstantiationRange = SourceRange()); 4209 4210 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 4211 ParmVarDecl *Param, 4212 const TemplateArgument *TemplateArgs, 4213 unsigned NumTemplateArgs, 4214 SourceRange InstantiationRange = SourceRange()); 4215 4216 /// \brief Note that we are substituting prior template arguments into a 4217 /// non-type or template template parameter. 4218 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 4219 NamedDecl *Template, 4220 NonTypeTemplateParmDecl *Param, 4221 const TemplateArgument *TemplateArgs, 4222 unsigned NumTemplateArgs, 4223 SourceRange InstantiationRange); 4224 4225 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 4226 NamedDecl *Template, 4227 TemplateTemplateParmDecl *Param, 4228 const TemplateArgument *TemplateArgs, 4229 unsigned NumTemplateArgs, 4230 SourceRange InstantiationRange); 4231 4232 /// \brief Note that we are checking the default template argument 4233 /// against the template parameter for a given template-id. 4234 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 4235 TemplateDecl *Template, 4236 NamedDecl *Param, 4237 const TemplateArgument *TemplateArgs, 4238 unsigned NumTemplateArgs, 4239 SourceRange InstantiationRange); 4240 4241 4242 /// \brief Note that we have finished instantiating this template. 4243 void Clear(); 4244 4245 ~InstantiatingTemplate() { Clear(); } 4246 4247 /// \brief Determines whether we have exceeded the maximum 4248 /// recursive template instantiations. 4249 operator bool() const { return Invalid; } 4250 4251 private: 4252 Sema &SemaRef; 4253 bool Invalid; 4254 bool SavedInNonInstantiationSFINAEContext; 4255 bool CheckInstantiationDepth(SourceLocation PointOfInstantiation, 4256 SourceRange InstantiationRange); 4257 4258 InstantiatingTemplate(const InstantiatingTemplate&); // not implemented 4259 4260 InstantiatingTemplate& 4261 operator=(const InstantiatingTemplate&); // not implemented 4262 }; 4263 4264 void PrintInstantiationStack(); 4265 4266 /// \brief Determines whether we are currently in a context where 4267 /// template argument substitution failures are not considered 4268 /// errors. 4269 /// 4270 /// \returns An empty \c llvm::Optional if we're not in a SFINAE context. 4271 /// Otherwise, contains a pointer that, if non-NULL, contains the nearest 4272 /// template-deduction context object, which can be used to capture 4273 /// diagnostics that will be suppressed. 4274 llvm::Optional<sema::TemplateDeductionInfo *> isSFINAEContext() const; 4275 4276 /// \brief RAII class used to determine whether SFINAE has 4277 /// trapped any errors that occur during template argument 4278 /// deduction.` 4279 class SFINAETrap { 4280 Sema &SemaRef; 4281 unsigned PrevSFINAEErrors; 4282 bool PrevInNonInstantiationSFINAEContext; 4283 bool PrevAccessCheckingSFINAE; 4284 4285 public: 4286 explicit SFINAETrap(Sema &SemaRef, bool AccessCheckingSFINAE = false) 4287 : SemaRef(SemaRef), PrevSFINAEErrors(SemaRef.NumSFINAEErrors), 4288 PrevInNonInstantiationSFINAEContext( 4289 SemaRef.InNonInstantiationSFINAEContext), 4290 PrevAccessCheckingSFINAE(SemaRef.AccessCheckingSFINAE) 4291 { 4292 if (!SemaRef.isSFINAEContext()) 4293 SemaRef.InNonInstantiationSFINAEContext = true; 4294 SemaRef.AccessCheckingSFINAE = AccessCheckingSFINAE; 4295 } 4296 4297 ~SFINAETrap() { 4298 SemaRef.NumSFINAEErrors = PrevSFINAEErrors; 4299 SemaRef.InNonInstantiationSFINAEContext 4300 = PrevInNonInstantiationSFINAEContext; 4301 SemaRef.AccessCheckingSFINAE = PrevAccessCheckingSFINAE; 4302 } 4303 4304 /// \brief Determine whether any SFINAE errors have been trapped. 4305 bool hasErrorOccurred() const { 4306 return SemaRef.NumSFINAEErrors > PrevSFINAEErrors; 4307 } 4308 }; 4309 4310 /// \brief The current instantiation scope used to store local 4311 /// variables. 4312 LocalInstantiationScope *CurrentInstantiationScope; 4313 4314 /// \brief The number of typos corrected by CorrectTypo. 4315 unsigned TyposCorrected; 4316 4317 typedef llvm::DenseMap<IdentifierInfo *, std::pair<llvm::StringRef, bool> > 4318 UnqualifiedTyposCorrectedMap; 4319 4320 /// \brief A cache containing the results of typo correction for unqualified 4321 /// name lookup. 4322 /// 4323 /// The string is the string that we corrected to (which may be empty, if 4324 /// there was no correction), while the boolean will be true when the 4325 /// string represents a keyword. 4326 UnqualifiedTyposCorrectedMap UnqualifiedTyposCorrected; 4327 4328 /// \brief Worker object for performing CFG-based warnings. 4329 sema::AnalysisBasedWarnings AnalysisWarnings; 4330 4331 /// \brief An entity for which implicit template instantiation is required. 4332 /// 4333 /// The source location associated with the declaration is the first place in 4334 /// the source code where the declaration was "used". It is not necessarily 4335 /// the point of instantiation (which will be either before or after the 4336 /// namespace-scope declaration that triggered this implicit instantiation), 4337 /// However, it is the location that diagnostics should generally refer to, 4338 /// because users will need to know what code triggered the instantiation. 4339 typedef std::pair<ValueDecl *, SourceLocation> PendingImplicitInstantiation; 4340 4341 /// \brief The queue of implicit template instantiations that are required 4342 /// but have not yet been performed. 4343 std::deque<PendingImplicitInstantiation> PendingInstantiations; 4344 4345 /// \brief The queue of implicit template instantiations that are required 4346 /// and must be performed within the current local scope. 4347 /// 4348 /// This queue is only used for member functions of local classes in 4349 /// templates, which must be instantiated in the same scope as their 4350 /// enclosing function, so that they can reference function-local 4351 /// types, static variables, enumerators, etc. 4352 std::deque<PendingImplicitInstantiation> PendingLocalImplicitInstantiations; 4353 4354 bool PerformPendingInstantiations(bool LocalOnly = false); 4355 4356 TypeSourceInfo *SubstType(TypeSourceInfo *T, 4357 const MultiLevelTemplateArgumentList &TemplateArgs, 4358 SourceLocation Loc, DeclarationName Entity); 4359 4360 QualType SubstType(QualType T, 4361 const MultiLevelTemplateArgumentList &TemplateArgs, 4362 SourceLocation Loc, DeclarationName Entity); 4363 4364 TypeSourceInfo *SubstType(TypeLoc TL, 4365 const MultiLevelTemplateArgumentList &TemplateArgs, 4366 SourceLocation Loc, DeclarationName Entity); 4367 4368 TypeSourceInfo *SubstFunctionDeclType(TypeSourceInfo *T, 4369 const MultiLevelTemplateArgumentList &TemplateArgs, 4370 SourceLocation Loc, 4371 DeclarationName Entity); 4372 ParmVarDecl *SubstParmVarDecl(ParmVarDecl *D, 4373 const MultiLevelTemplateArgumentList &TemplateArgs, 4374 llvm::Optional<unsigned> NumExpansions); 4375 bool SubstParmTypes(SourceLocation Loc, 4376 ParmVarDecl **Params, unsigned NumParams, 4377 const MultiLevelTemplateArgumentList &TemplateArgs, 4378 llvm::SmallVectorImpl<QualType> &ParamTypes, 4379 llvm::SmallVectorImpl<ParmVarDecl *> *OutParams = 0); 4380 ExprResult SubstExpr(Expr *E, 4381 const MultiLevelTemplateArgumentList &TemplateArgs); 4382 4383 /// \brief Substitute the given template arguments into a list of 4384 /// expressions, expanding pack expansions if required. 4385 /// 4386 /// \param Exprs The list of expressions to substitute into. 4387 /// 4388 /// \param NumExprs The number of expressions in \p Exprs. 4389 /// 4390 /// \param IsCall Whether this is some form of call, in which case 4391 /// default arguments will be dropped. 4392 /// 4393 /// \param TemplateArgs The set of template arguments to substitute. 4394 /// 4395 /// \param Outputs Will receive all of the substituted arguments. 4396 /// 4397 /// \returns true if an error occurred, false otherwise. 4398 bool SubstExprs(Expr **Exprs, unsigned NumExprs, bool IsCall, 4399 const MultiLevelTemplateArgumentList &TemplateArgs, 4400 llvm::SmallVectorImpl<Expr *> &Outputs); 4401 4402 StmtResult SubstStmt(Stmt *S, 4403 const MultiLevelTemplateArgumentList &TemplateArgs); 4404 4405 Decl *SubstDecl(Decl *D, DeclContext *Owner, 4406 const MultiLevelTemplateArgumentList &TemplateArgs); 4407 4408 bool 4409 SubstBaseSpecifiers(CXXRecordDecl *Instantiation, 4410 CXXRecordDecl *Pattern, 4411 const MultiLevelTemplateArgumentList &TemplateArgs); 4412 4413 bool 4414 InstantiateClass(SourceLocation PointOfInstantiation, 4415 CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern, 4416 const MultiLevelTemplateArgumentList &TemplateArgs, 4417 TemplateSpecializationKind TSK, 4418 bool Complain = true); 4419 4420 void InstantiateAttrs(const MultiLevelTemplateArgumentList &TemplateArgs, 4421 Decl *Pattern, Decl *Inst); 4422 4423 bool 4424 InstantiateClassTemplateSpecialization(SourceLocation PointOfInstantiation, 4425 ClassTemplateSpecializationDecl *ClassTemplateSpec, 4426 TemplateSpecializationKind TSK, 4427 bool Complain = true); 4428 4429 void InstantiateClassMembers(SourceLocation PointOfInstantiation, 4430 CXXRecordDecl *Instantiation, 4431 const MultiLevelTemplateArgumentList &TemplateArgs, 4432 TemplateSpecializationKind TSK); 4433 4434 void InstantiateClassTemplateSpecializationMembers( 4435 SourceLocation PointOfInstantiation, 4436 ClassTemplateSpecializationDecl *ClassTemplateSpec, 4437 TemplateSpecializationKind TSK); 4438 4439 NestedNameSpecifierLoc 4440 SubstNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, 4441 const MultiLevelTemplateArgumentList &TemplateArgs); 4442 4443 DeclarationNameInfo 4444 SubstDeclarationNameInfo(const DeclarationNameInfo &NameInfo, 4445 const MultiLevelTemplateArgumentList &TemplateArgs); 4446 TemplateName 4447 SubstTemplateName(NestedNameSpecifierLoc QualifierLoc, TemplateName Name, 4448 SourceLocation Loc, 4449 const MultiLevelTemplateArgumentList &TemplateArgs); 4450 bool Subst(const TemplateArgumentLoc *Args, unsigned NumArgs, 4451 TemplateArgumentListInfo &Result, 4452 const MultiLevelTemplateArgumentList &TemplateArgs); 4453 4454 void InstantiateFunctionDefinition(SourceLocation PointOfInstantiation, 4455 FunctionDecl *Function, 4456 bool Recursive = false, 4457 bool DefinitionRequired = false); 4458 void InstantiateStaticDataMemberDefinition( 4459 SourceLocation PointOfInstantiation, 4460 VarDecl *Var, 4461 bool Recursive = false, 4462 bool DefinitionRequired = false); 4463 4464 void InstantiateMemInitializers(CXXConstructorDecl *New, 4465 const CXXConstructorDecl *Tmpl, 4466 const MultiLevelTemplateArgumentList &TemplateArgs); 4467 4468 NamedDecl *FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D, 4469 const MultiLevelTemplateArgumentList &TemplateArgs); 4470 DeclContext *FindInstantiatedContext(SourceLocation Loc, DeclContext *DC, 4471 const MultiLevelTemplateArgumentList &TemplateArgs); 4472 4473 // Objective-C declarations. 4474 Decl *ActOnStartClassInterface(SourceLocation AtInterfaceLoc, 4475 IdentifierInfo *ClassName, 4476 SourceLocation ClassLoc, 4477 IdentifierInfo *SuperName, 4478 SourceLocation SuperLoc, 4479 Decl * const *ProtoRefs, 4480 unsigned NumProtoRefs, 4481 const SourceLocation *ProtoLocs, 4482 SourceLocation EndProtoLoc, 4483 AttributeList *AttrList); 4484 4485 Decl *ActOnCompatiblityAlias( 4486 SourceLocation AtCompatibilityAliasLoc, 4487 IdentifierInfo *AliasName, SourceLocation AliasLocation, 4488 IdentifierInfo *ClassName, SourceLocation ClassLocation); 4489 4490 void CheckForwardProtocolDeclarationForCircularDependency( 4491 IdentifierInfo *PName, 4492 SourceLocation &PLoc, SourceLocation PrevLoc, 4493 const ObjCList<ObjCProtocolDecl> &PList); 4494 4495 Decl *ActOnStartProtocolInterface( 4496 SourceLocation AtProtoInterfaceLoc, 4497 IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc, 4498 Decl * const *ProtoRefNames, unsigned NumProtoRefs, 4499 const SourceLocation *ProtoLocs, 4500 SourceLocation EndProtoLoc, 4501 AttributeList *AttrList); 4502 4503 Decl *ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc, 4504 IdentifierInfo *ClassName, 4505 SourceLocation ClassLoc, 4506 IdentifierInfo *CategoryName, 4507 SourceLocation CategoryLoc, 4508 Decl * const *ProtoRefs, 4509 unsigned NumProtoRefs, 4510 const SourceLocation *ProtoLocs, 4511 SourceLocation EndProtoLoc); 4512 4513 Decl *ActOnStartClassImplementation( 4514 SourceLocation AtClassImplLoc, 4515 IdentifierInfo *ClassName, SourceLocation ClassLoc, 4516 IdentifierInfo *SuperClassname, 4517 SourceLocation SuperClassLoc); 4518 4519 Decl *ActOnStartCategoryImplementation(SourceLocation AtCatImplLoc, 4520 IdentifierInfo *ClassName, 4521 SourceLocation ClassLoc, 4522 IdentifierInfo *CatName, 4523 SourceLocation CatLoc); 4524 4525 Decl *ActOnForwardClassDeclaration(SourceLocation Loc, 4526 IdentifierInfo **IdentList, 4527 SourceLocation *IdentLocs, 4528 unsigned NumElts); 4529 4530 Decl *ActOnForwardProtocolDeclaration(SourceLocation AtProtoclLoc, 4531 const IdentifierLocPair *IdentList, 4532 unsigned NumElts, 4533 AttributeList *attrList); 4534 4535 void FindProtocolDeclaration(bool WarnOnDeclarations, 4536 const IdentifierLocPair *ProtocolId, 4537 unsigned NumProtocols, 4538 llvm::SmallVectorImpl<Decl *> &Protocols); 4539 4540 /// Ensure attributes are consistent with type. 4541 /// \param [in, out] Attributes The attributes to check; they will 4542 /// be modified to be consistent with \arg PropertyTy. 4543 void CheckObjCPropertyAttributes(Decl *PropertyPtrTy, 4544 SourceLocation Loc, 4545 unsigned &Attributes); 4546 4547 /// Process the specified property declaration and create decls for the 4548 /// setters and getters as needed. 4549 /// \param property The property declaration being processed 4550 /// \param DC The semantic container for the property 4551 /// \param redeclaredProperty Declaration for property if redeclared 4552 /// in class extension. 4553 /// \param lexicalDC Container for redeclaredProperty. 4554 void ProcessPropertyDecl(ObjCPropertyDecl *property, 4555 ObjCContainerDecl *DC, 4556 ObjCPropertyDecl *redeclaredProperty = 0, 4557 ObjCContainerDecl *lexicalDC = 0); 4558 4559 void DiagnosePropertyMismatch(ObjCPropertyDecl *Property, 4560 ObjCPropertyDecl *SuperProperty, 4561 const IdentifierInfo *Name); 4562 void ComparePropertiesInBaseAndSuper(ObjCInterfaceDecl *IDecl); 4563 4564 void CompareMethodParamsInBaseAndSuper(Decl *IDecl, 4565 ObjCMethodDecl *MethodDecl, 4566 bool IsInstance); 4567 4568 void CompareProperties(Decl *CDecl, Decl *MergeProtocols); 4569 4570 void DiagnoseClassExtensionDupMethods(ObjCCategoryDecl *CAT, 4571 ObjCInterfaceDecl *ID); 4572 4573 void MatchOneProtocolPropertiesInClass(Decl *CDecl, 4574 ObjCProtocolDecl *PDecl); 4575 4576 void ActOnAtEnd(Scope *S, SourceRange AtEnd, Decl *classDecl, 4577 Decl **allMethods = 0, unsigned allNum = 0, 4578 Decl **allProperties = 0, unsigned pNum = 0, 4579 DeclGroupPtrTy *allTUVars = 0, unsigned tuvNum = 0); 4580 4581 Decl *ActOnProperty(Scope *S, SourceLocation AtLoc, 4582 FieldDeclarator &FD, ObjCDeclSpec &ODS, 4583 Selector GetterSel, Selector SetterSel, 4584 Decl *ClassCategory, 4585 bool *OverridingProperty, 4586 tok::ObjCKeywordKind MethodImplKind, 4587 DeclContext *lexicalDC = 0); 4588 4589 Decl *ActOnPropertyImplDecl(Scope *S, 4590 SourceLocation AtLoc, 4591 SourceLocation PropertyLoc, 4592 bool ImplKind,Decl *ClassImplDecl, 4593 IdentifierInfo *PropertyId, 4594 IdentifierInfo *PropertyIvar, 4595 SourceLocation PropertyIvarLoc); 4596 4597 struct ObjCArgInfo { 4598 IdentifierInfo *Name; 4599 SourceLocation NameLoc; 4600 // The Type is null if no type was specified, and the DeclSpec is invalid 4601 // in this case. 4602 ParsedType Type; 4603 ObjCDeclSpec DeclSpec; 4604 4605 /// ArgAttrs - Attribute list for this argument. 4606 AttributeList *ArgAttrs; 4607 }; 4608 4609 Decl *ActOnMethodDeclaration( 4610 Scope *S, 4611 SourceLocation BeginLoc, // location of the + or -. 4612 SourceLocation EndLoc, // location of the ; or {. 4613 tok::TokenKind MethodType, 4614 Decl *ClassDecl, ObjCDeclSpec &ReturnQT, ParsedType ReturnType, 4615 Selector Sel, 4616 // optional arguments. The number of types/arguments is obtained 4617 // from the Sel.getNumArgs(). 4618 ObjCArgInfo *ArgInfo, 4619 DeclaratorChunk::ParamInfo *CParamInfo, unsigned CNumArgs, // c-style args 4620 AttributeList *AttrList, tok::ObjCKeywordKind MethodImplKind, 4621 bool isVariadic, bool MethodDefinition); 4622 4623 // Helper method for ActOnClassMethod/ActOnInstanceMethod. 4624 // Will search "local" class/category implementations for a method decl. 4625 // Will also search in class's root looking for instance method. 4626 // Returns 0 if no method is found. 4627 ObjCMethodDecl *LookupPrivateClassMethod(Selector Sel, 4628 ObjCInterfaceDecl *CDecl); 4629 ObjCMethodDecl *LookupPrivateInstanceMethod(Selector Sel, 4630 ObjCInterfaceDecl *ClassDecl); 4631 ObjCMethodDecl *LookupMethodInQualifiedType(Selector Sel, 4632 const ObjCObjectPointerType *OPT, 4633 bool IsInstance); 4634 4635 ExprResult 4636 HandleExprPropertyRefExpr(const ObjCObjectPointerType *OPT, 4637 Expr *BaseExpr, 4638 DeclarationName MemberName, 4639 SourceLocation MemberLoc, 4640 SourceLocation SuperLoc, QualType SuperType, 4641 bool Super); 4642 4643 ExprResult 4644 ActOnClassPropertyRefExpr(IdentifierInfo &receiverName, 4645 IdentifierInfo &propertyName, 4646 SourceLocation receiverNameLoc, 4647 SourceLocation propertyNameLoc); 4648 4649 ObjCMethodDecl *tryCaptureObjCSelf(); 4650 4651 /// \brief Describes the kind of message expression indicated by a message 4652 /// send that starts with an identifier. 4653 enum ObjCMessageKind { 4654 /// \brief The message is sent to 'super'. 4655 ObjCSuperMessage, 4656 /// \brief The message is an instance message. 4657 ObjCInstanceMessage, 4658 /// \brief The message is a class message, and the identifier is a type 4659 /// name. 4660 ObjCClassMessage 4661 }; 4662 4663 ObjCMessageKind getObjCMessageKind(Scope *S, 4664 IdentifierInfo *Name, 4665 SourceLocation NameLoc, 4666 bool IsSuper, 4667 bool HasTrailingDot, 4668 ParsedType &ReceiverType); 4669 4670 ExprResult ActOnSuperMessage(Scope *S, SourceLocation SuperLoc, 4671 Selector Sel, 4672 SourceLocation LBracLoc, 4673 SourceLocation SelectorLoc, 4674 SourceLocation RBracLoc, 4675 MultiExprArg Args); 4676 4677 ExprResult BuildClassMessage(TypeSourceInfo *ReceiverTypeInfo, 4678 QualType ReceiverType, 4679 SourceLocation SuperLoc, 4680 Selector Sel, 4681 ObjCMethodDecl *Method, 4682 SourceLocation LBracLoc, 4683 SourceLocation SelectorLoc, 4684 SourceLocation RBracLoc, 4685 MultiExprArg Args); 4686 4687 ExprResult ActOnClassMessage(Scope *S, 4688 ParsedType Receiver, 4689 Selector Sel, 4690 SourceLocation LBracLoc, 4691 SourceLocation SelectorLoc, 4692 SourceLocation RBracLoc, 4693 MultiExprArg Args); 4694 4695 ExprResult BuildInstanceMessage(Expr *Receiver, 4696 QualType ReceiverType, 4697 SourceLocation SuperLoc, 4698 Selector Sel, 4699 ObjCMethodDecl *Method, 4700 SourceLocation LBracLoc, 4701 SourceLocation SelectorLoc, 4702 SourceLocation RBracLoc, 4703 MultiExprArg Args); 4704 4705 ExprResult ActOnInstanceMessage(Scope *S, 4706 Expr *Receiver, 4707 Selector Sel, 4708 SourceLocation LBracLoc, 4709 SourceLocation SelectorLoc, 4710 SourceLocation RBracLoc, 4711 MultiExprArg Args); 4712 4713 4714 enum PragmaOptionsAlignKind { 4715 POAK_Native, // #pragma options align=native 4716 POAK_Natural, // #pragma options align=natural 4717 POAK_Packed, // #pragma options align=packed 4718 POAK_Power, // #pragma options align=power 4719 POAK_Mac68k, // #pragma options align=mac68k 4720 POAK_Reset // #pragma options align=reset 4721 }; 4722 4723 /// ActOnPragmaOptionsAlign - Called on well formed #pragma options align. 4724 void ActOnPragmaOptionsAlign(PragmaOptionsAlignKind Kind, 4725 SourceLocation PragmaLoc, 4726 SourceLocation KindLoc); 4727 4728 enum PragmaPackKind { 4729 PPK_Default, // #pragma pack([n]) 4730 PPK_Show, // #pragma pack(show), only supported by MSVC. 4731 PPK_Push, // #pragma pack(push, [identifier], [n]) 4732 PPK_Pop // #pragma pack(pop, [identifier], [n]) 4733 }; 4734 4735 /// ActOnPragmaPack - Called on well formed #pragma pack(...). 4736 void ActOnPragmaPack(PragmaPackKind Kind, 4737 IdentifierInfo *Name, 4738 Expr *Alignment, 4739 SourceLocation PragmaLoc, 4740 SourceLocation LParenLoc, 4741 SourceLocation RParenLoc); 4742 4743 /// ActOnPragmaUnused - Called on well-formed '#pragma unused'. 4744 void ActOnPragmaUnused(const Token &Identifier, 4745 Scope *curScope, 4746 SourceLocation PragmaLoc); 4747 4748 /// ActOnPragmaVisibility - Called on well formed #pragma GCC visibility... . 4749 void ActOnPragmaVisibility(bool IsPush, const IdentifierInfo* VisType, 4750 SourceLocation PragmaLoc); 4751 4752 NamedDecl *DeclClonePragmaWeak(NamedDecl *ND, IdentifierInfo *II); 4753 void DeclApplyPragmaWeak(Scope *S, NamedDecl *ND, WeakInfo &W); 4754 4755 /// ActOnPragmaWeakID - Called on well formed #pragma weak ident. 4756 void ActOnPragmaWeakID(IdentifierInfo* WeakName, 4757 SourceLocation PragmaLoc, 4758 SourceLocation WeakNameLoc); 4759 4760 /// ActOnPragmaWeakAlias - Called on well formed #pragma weak ident = ident. 4761 void ActOnPragmaWeakAlias(IdentifierInfo* WeakName, 4762 IdentifierInfo* AliasName, 4763 SourceLocation PragmaLoc, 4764 SourceLocation WeakNameLoc, 4765 SourceLocation AliasNameLoc); 4766 4767 /// ActOnPragmaFPContract - Called on well formed 4768 /// #pragma {STDC,OPENCL} FP_CONTRACT 4769 void ActOnPragmaFPContract(tok::OnOffSwitch OOS); 4770 4771 /// AddAlignmentAttributesForRecord - Adds any needed alignment attributes to 4772 /// a the record decl, to handle '#pragma pack' and '#pragma options align'. 4773 void AddAlignmentAttributesForRecord(RecordDecl *RD); 4774 4775 /// FreePackedContext - Deallocate and null out PackContext. 4776 void FreePackedContext(); 4777 4778 /// PushNamespaceVisibilityAttr - Note that we've entered a 4779 /// namespace with a visibility attribute. 4780 void PushNamespaceVisibilityAttr(const VisibilityAttr *Attr); 4781 4782 /// AddPushedVisibilityAttribute - If '#pragma GCC visibility' was used, 4783 /// add an appropriate visibility attribute. 4784 void AddPushedVisibilityAttribute(Decl *RD); 4785 4786 /// PopPragmaVisibility - Pop the top element of the visibility stack; used 4787 /// for '#pragma GCC visibility' and visibility attributes on namespaces. 4788 void PopPragmaVisibility(); 4789 4790 /// FreeVisContext - Deallocate and null out VisContext. 4791 void FreeVisContext(); 4792 4793 /// AddAlignedAttr - Adds an aligned attribute to a particular declaration. 4794 void AddAlignedAttr(SourceLocation AttrLoc, Decl *D, Expr *E); 4795 void AddAlignedAttr(SourceLocation AttrLoc, Decl *D, TypeSourceInfo *T); 4796 4797 /// CastCategory - Get the correct forwarded implicit cast result category 4798 /// from the inner expression. 4799 ExprValueKind CastCategory(Expr *E); 4800 4801 /// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit 4802 /// cast. If there is already an implicit cast, merge into the existing one. 4803 /// If isLvalue, the result of the cast is an lvalue. 4804 ExprResult ImpCastExprToType(Expr *E, QualType Type, CastKind CK, 4805 ExprValueKind VK = VK_RValue, 4806 const CXXCastPath *BasePath = 0); 4807 4808 /// ScalarTypeToBooleanCastKind - Returns the cast kind corresponding 4809 /// to the conversion from scalar type ScalarTy to the Boolean type. 4810 static CastKind ScalarTypeToBooleanCastKind(QualType ScalarTy); 4811 4812 /// IgnoredValueConversions - Given that an expression's result is 4813 /// syntactically ignored, perform any conversions that are 4814 /// required. 4815 ExprResult IgnoredValueConversions(Expr *E); 4816 4817 // UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts 4818 // functions and arrays to their respective pointers (C99 6.3.2.1). 4819 ExprResult UsualUnaryConversions(Expr *E); 4820 4821 // DefaultFunctionArrayConversion - converts functions and arrays 4822 // to their respective pointers (C99 6.3.2.1). 4823 ExprResult DefaultFunctionArrayConversion(Expr *E); 4824 4825 // DefaultFunctionArrayLvalueConversion - converts functions and 4826 // arrays to their respective pointers and performs the 4827 // lvalue-to-rvalue conversion. 4828 ExprResult DefaultFunctionArrayLvalueConversion(Expr *E); 4829 4830 // DefaultLvalueConversion - performs lvalue-to-rvalue conversion on 4831 // the operand. This is DefaultFunctionArrayLvalueConversion, 4832 // except that it assumes the operand isn't of function or array 4833 // type. 4834 ExprResult DefaultLvalueConversion(Expr *E); 4835 4836 // DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that 4837 // do not have a prototype. Integer promotions are performed on each 4838 // argument, and arguments that have type float are promoted to double. 4839 ExprResult DefaultArgumentPromotion(Expr *E); 4840 4841 // Used for emitting the right warning by DefaultVariadicArgumentPromotion 4842 enum VariadicCallType { 4843 VariadicFunction, 4844 VariadicBlock, 4845 VariadicMethod, 4846 VariadicConstructor, 4847 VariadicDoesNotApply 4848 }; 4849 4850 /// GatherArgumentsForCall - Collector argument expressions for various 4851 /// form of call prototypes. 4852 bool GatherArgumentsForCall(SourceLocation CallLoc, 4853 FunctionDecl *FDecl, 4854 const FunctionProtoType *Proto, 4855 unsigned FirstProtoArg, 4856 Expr **Args, unsigned NumArgs, 4857 llvm::SmallVector<Expr *, 8> &AllArgs, 4858 VariadicCallType CallType = VariadicDoesNotApply); 4859 4860 // DefaultVariadicArgumentPromotion - Like DefaultArgumentPromotion, but 4861 // will warn if the resulting type is not a POD type. 4862 ExprResult DefaultVariadicArgumentPromotion(Expr *E, VariadicCallType CT, 4863 FunctionDecl *FDecl); 4864 4865 // UsualArithmeticConversions - performs the UsualUnaryConversions on it's 4866 // operands and then handles various conversions that are common to binary 4867 // operators (C99 6.3.1.8). If both operands aren't arithmetic, this 4868 // routine returns the first non-arithmetic type found. The client is 4869 // responsible for emitting appropriate error diagnostics. 4870 QualType UsualArithmeticConversions(ExprResult &lExpr, ExprResult &rExpr, 4871 bool isCompAssign = false); 4872 4873 /// AssignConvertType - All of the 'assignment' semantic checks return this 4874 /// enum to indicate whether the assignment was allowed. These checks are 4875 /// done for simple assignments, as well as initialization, return from 4876 /// function, argument passing, etc. The query is phrased in terms of a 4877 /// source and destination type. 4878 enum AssignConvertType { 4879 /// Compatible - the types are compatible according to the standard. 4880 Compatible, 4881 4882 /// PointerToInt - The assignment converts a pointer to an int, which we 4883 /// accept as an extension. 4884 PointerToInt, 4885 4886 /// IntToPointer - The assignment converts an int to a pointer, which we 4887 /// accept as an extension. 4888 IntToPointer, 4889 4890 /// FunctionVoidPointer - The assignment is between a function pointer and 4891 /// void*, which the standard doesn't allow, but we accept as an extension. 4892 FunctionVoidPointer, 4893 4894 /// IncompatiblePointer - The assignment is between two pointers types that 4895 /// are not compatible, but we accept them as an extension. 4896 IncompatiblePointer, 4897 4898 /// IncompatiblePointer - The assignment is between two pointers types which 4899 /// point to integers which have a different sign, but are otherwise identical. 4900 /// This is a subset of the above, but broken out because it's by far the most 4901 /// common case of incompatible pointers. 4902 IncompatiblePointerSign, 4903 4904 /// CompatiblePointerDiscardsQualifiers - The assignment discards 4905 /// c/v/r qualifiers, which we accept as an extension. 4906 CompatiblePointerDiscardsQualifiers, 4907 4908 /// IncompatiblePointerDiscardsQualifiers - The assignment 4909 /// discards qualifiers that we don't permit to be discarded, 4910 /// like address spaces. 4911 IncompatiblePointerDiscardsQualifiers, 4912 4913 /// IncompatibleNestedPointerQualifiers - The assignment is between two 4914 /// nested pointer types, and the qualifiers other than the first two 4915 /// levels differ e.g. char ** -> const char **, but we accept them as an 4916 /// extension. 4917 IncompatibleNestedPointerQualifiers, 4918 4919 /// IncompatibleVectors - The assignment is between two vector types that 4920 /// have the same size, which we accept as an extension. 4921 IncompatibleVectors, 4922 4923 /// IntToBlockPointer - The assignment converts an int to a block 4924 /// pointer. We disallow this. 4925 IntToBlockPointer, 4926 4927 /// IncompatibleBlockPointer - The assignment is between two block 4928 /// pointers types that are not compatible. 4929 IncompatibleBlockPointer, 4930 4931 /// IncompatibleObjCQualifiedId - The assignment is between a qualified 4932 /// id type and something else (that is incompatible with it). For example, 4933 /// "id <XXX>" = "Foo *", where "Foo *" doesn't implement the XXX protocol. 4934 IncompatibleObjCQualifiedId, 4935 4936 /// Incompatible - We reject this conversion outright, it is invalid to 4937 /// represent it in the AST. 4938 Incompatible 4939 }; 4940 4941 /// DiagnoseAssignmentResult - Emit a diagnostic, if required, for the 4942 /// assignment conversion type specified by ConvTy. This returns true if the 4943 /// conversion was invalid or false if the conversion was accepted. 4944 bool DiagnoseAssignmentResult(AssignConvertType ConvTy, 4945 SourceLocation Loc, 4946 QualType DstType, QualType SrcType, 4947 Expr *SrcExpr, AssignmentAction Action, 4948 bool *Complained = 0); 4949 4950 /// CheckAssignmentConstraints - Perform type checking for assignment, 4951 /// argument passing, variable initialization, and function return values. 4952 /// C99 6.5.16. 4953 AssignConvertType CheckAssignmentConstraints(SourceLocation Loc, 4954 QualType lhs, QualType rhs); 4955 4956 /// Check assignment constraints and prepare for a conversion of the 4957 /// RHS to the LHS type. 4958 AssignConvertType CheckAssignmentConstraints(QualType lhs, ExprResult &rhs, 4959 CastKind &Kind); 4960 4961 // CheckSingleAssignmentConstraints - Currently used by 4962 // CheckAssignmentOperands, and ActOnReturnStmt. Prior to type checking, 4963 // this routine performs the default function/array converions. 4964 AssignConvertType CheckSingleAssignmentConstraints(QualType lhs, 4965 ExprResult &rExprRes); 4966 4967 // \brief If the lhs type is a transparent union, check whether we 4968 // can initialize the transparent union with the given expression. 4969 AssignConvertType CheckTransparentUnionArgumentConstraints(QualType lhs, 4970 ExprResult &rExpr); 4971 4972 bool IsStringLiteralToNonConstPointerConversion(Expr *From, QualType ToType); 4973 4974 bool CheckExceptionSpecCompatibility(Expr *From, QualType ToType); 4975 4976 ExprResult PerformImplicitConversion(Expr *From, QualType ToType, 4977 AssignmentAction Action, 4978 bool AllowExplicit = false); 4979 ExprResult PerformImplicitConversion(Expr *From, QualType ToType, 4980 AssignmentAction Action, 4981 bool AllowExplicit, 4982 ImplicitConversionSequence& ICS); 4983 ExprResult PerformImplicitConversion(Expr *From, QualType ToType, 4984 const ImplicitConversionSequence& ICS, 4985 AssignmentAction Action, 4986 bool CStyle = false); 4987 ExprResult PerformImplicitConversion(Expr *From, QualType ToType, 4988 const StandardConversionSequence& SCS, 4989 AssignmentAction Action, 4990 bool CStyle); 4991 4992 /// the following "Check" methods will return a valid/converted QualType 4993 /// or a null QualType (indicating an error diagnostic was issued). 4994 4995 /// type checking binary operators (subroutines of CreateBuiltinBinOp). 4996 QualType InvalidOperands(SourceLocation l, ExprResult &lex, ExprResult &rex); 4997 QualType CheckPointerToMemberOperands( // C++ 5.5 4998 ExprResult &lex, ExprResult &rex, ExprValueKind &VK, 4999 SourceLocation OpLoc, bool isIndirect); 5000 QualType CheckMultiplyDivideOperands( // C99 6.5.5 5001 ExprResult &lex, ExprResult &rex, SourceLocation OpLoc, bool isCompAssign, 5002 bool isDivide); 5003 QualType CheckRemainderOperands( // C99 6.5.5 5004 ExprResult &lex, ExprResult &rex, SourceLocation OpLoc, bool isCompAssign = false); 5005 QualType CheckAdditionOperands( // C99 6.5.6 5006 ExprResult &lex, ExprResult &rex, SourceLocation OpLoc, QualType* CompLHSTy = 0); 5007 QualType CheckSubtractionOperands( // C99 6.5.6 5008 ExprResult &lex, ExprResult &rex, SourceLocation OpLoc, QualType* CompLHSTy = 0); 5009 QualType CheckShiftOperands( // C99 6.5.7 5010 ExprResult &lex, ExprResult &rex, SourceLocation OpLoc, unsigned Opc, 5011 bool isCompAssign = false); 5012 QualType CheckCompareOperands( // C99 6.5.8/9 5013 ExprResult &lex, ExprResult &rex, SourceLocation OpLoc, unsigned Opc, 5014 bool isRelational); 5015 QualType CheckBitwiseOperands( // C99 6.5.[10...12] 5016 ExprResult &lex, ExprResult &rex, SourceLocation OpLoc, bool isCompAssign = false); 5017 QualType CheckLogicalOperands( // C99 6.5.[13,14] 5018 ExprResult &lex, ExprResult &rex, SourceLocation OpLoc, unsigned Opc); 5019 // CheckAssignmentOperands is used for both simple and compound assignment. 5020 // For simple assignment, pass both expressions and a null converted type. 5021 // For compound assignment, pass both expressions and the converted type. 5022 QualType CheckAssignmentOperands( // C99 6.5.16.[1,2] 5023 Expr *lex, ExprResult &rex, SourceLocation OpLoc, QualType convertedType); 5024 5025 void ConvertPropertyForLValue(ExprResult &LHS, ExprResult &RHS, QualType& LHSTy); 5026 ExprResult ConvertPropertyForRValue(Expr *E); 5027 5028 QualType CheckConditionalOperands( // C99 6.5.15 5029 ExprResult &cond, ExprResult &lhs, ExprResult &rhs, 5030 ExprValueKind &VK, ExprObjectKind &OK, SourceLocation questionLoc); 5031 QualType CXXCheckConditionalOperands( // C++ 5.16 5032 ExprResult &cond, ExprResult &lhs, ExprResult &rhs, 5033 ExprValueKind &VK, ExprObjectKind &OK, SourceLocation questionLoc); 5034 QualType FindCompositePointerType(SourceLocation Loc, Expr *&E1, Expr *&E2, 5035 bool *NonStandardCompositeType = 0); 5036 QualType FindCompositePointerType(SourceLocation Loc, ExprResult &E1, ExprResult &E2, 5037 bool *NonStandardCompositeType = 0) { 5038 Expr *E1Tmp = E1.take(), *E2Tmp = E2.take(); 5039 QualType Composite = FindCompositePointerType(Loc, E1Tmp, E2Tmp, NonStandardCompositeType); 5040 E1 = Owned(E1Tmp); 5041 E2 = Owned(E2Tmp); 5042 return Composite; 5043 } 5044 5045 QualType FindCompositeObjCPointerType(ExprResult &LHS, ExprResult &RHS, 5046 SourceLocation questionLoc); 5047 5048 bool DiagnoseConditionalForNull(Expr *LHS, Expr *RHS, 5049 SourceLocation QuestionLoc); 5050 5051 /// type checking for vector binary operators. 5052 QualType CheckVectorOperands(SourceLocation l, ExprResult &lex, ExprResult &rex); 5053 QualType CheckVectorCompareOperands(ExprResult &lex, ExprResult &rx, 5054 SourceLocation l, bool isRel); 5055 5056 /// type checking declaration initializers (C99 6.7.8) 5057 bool CheckInitList(const InitializedEntity &Entity, 5058 InitListExpr *&InitList, QualType &DeclType); 5059 bool CheckForConstantInitializer(Expr *e, QualType t); 5060 5061 // type checking C++ declaration initializers (C++ [dcl.init]). 5062 5063 /// ReferenceCompareResult - Expresses the result of comparing two 5064 /// types (cv1 T1 and cv2 T2) to determine their compatibility for the 5065 /// purposes of initialization by reference (C++ [dcl.init.ref]p4). 5066 enum ReferenceCompareResult { 5067 /// Ref_Incompatible - The two types are incompatible, so direct 5068 /// reference binding is not possible. 5069 Ref_Incompatible = 0, 5070 /// Ref_Related - The two types are reference-related, which means 5071 /// that their unqualified forms (T1 and T2) are either the same 5072 /// or T1 is a base class of T2. 5073 Ref_Related, 5074 /// Ref_Compatible_With_Added_Qualification - The two types are 5075 /// reference-compatible with added qualification, meaning that 5076 /// they are reference-compatible and the qualifiers on T1 (cv1) 5077 /// are greater than the qualifiers on T2 (cv2). 5078 Ref_Compatible_With_Added_Qualification, 5079 /// Ref_Compatible - The two types are reference-compatible and 5080 /// have equivalent qualifiers (cv1 == cv2). 5081 Ref_Compatible 5082 }; 5083 5084 ReferenceCompareResult CompareReferenceRelationship(SourceLocation Loc, 5085 QualType T1, QualType T2, 5086 bool &DerivedToBase, 5087 bool &ObjCConversion); 5088 5089 /// CheckCastTypes - Check type constraints for casting between types under 5090 /// C semantics, or forward to CXXCheckCStyleCast in C++. 5091 ExprResult CheckCastTypes(SourceRange TyRange, QualType CastTy, Expr *CastExpr, 5092 CastKind &Kind, ExprValueKind &VK, CXXCastPath &BasePath, 5093 bool FunctionalStyle = false); 5094 5095 ExprResult checkUnknownAnyCast(SourceRange TyRange, QualType castType, 5096 Expr *castExpr, CastKind &castKind, 5097 ExprValueKind &valueKind, CXXCastPath &BasePath); 5098 5099 // CheckVectorCast - check type constraints for vectors. 5100 // Since vectors are an extension, there are no C standard reference for this. 5101 // We allow casting between vectors and integer datatypes of the same size. 5102 // returns true if the cast is invalid 5103 bool CheckVectorCast(SourceRange R, QualType VectorTy, QualType Ty, 5104 CastKind &Kind); 5105 5106 // CheckExtVectorCast - check type constraints for extended vectors. 5107 // Since vectors are an extension, there are no C standard reference for this. 5108 // We allow casting between vectors and integer datatypes of the same size, 5109 // or vectors and the element type of that vector. 5110 // returns the cast expr 5111 ExprResult CheckExtVectorCast(SourceRange R, QualType VectorTy, Expr *CastExpr, 5112 CastKind &Kind); 5113 5114 /// CXXCheckCStyleCast - Check constraints of a C-style or function-style 5115 /// cast under C++ semantics. 5116 ExprResult CXXCheckCStyleCast(SourceRange R, QualType CastTy, ExprValueKind &VK, 5117 Expr *CastExpr, CastKind &Kind, 5118 CXXCastPath &BasePath, bool FunctionalStyle); 5119 5120 /// CheckMessageArgumentTypes - Check types in an Obj-C message send. 5121 /// \param Method - May be null. 5122 /// \param [out] ReturnType - The return type of the send. 5123 /// \return true iff there were any incompatible types. 5124 bool CheckMessageArgumentTypes(Expr **Args, unsigned NumArgs, Selector Sel, 5125 ObjCMethodDecl *Method, bool isClassMessage, 5126 SourceLocation lbrac, SourceLocation rbrac, 5127 QualType &ReturnType, ExprValueKind &VK); 5128 5129 /// CheckBooleanCondition - Diagnose problems involving the use of 5130 /// the given expression as a boolean condition (e.g. in an if 5131 /// statement). Also performs the standard function and array 5132 /// decays, possibly changing the input variable. 5133 /// 5134 /// \param Loc - A location associated with the condition, e.g. the 5135 /// 'if' keyword. 5136 /// \return true iff there were any errors 5137 ExprResult CheckBooleanCondition(Expr *CondExpr, SourceLocation Loc); 5138 5139 ExprResult ActOnBooleanCondition(Scope *S, SourceLocation Loc, 5140 Expr *SubExpr); 5141 5142 /// DiagnoseAssignmentAsCondition - Given that an expression is 5143 /// being used as a boolean condition, warn if it's an assignment. 5144 void DiagnoseAssignmentAsCondition(Expr *E); 5145 5146 /// \brief Redundant parentheses over an equality comparison can indicate 5147 /// that the user intended an assignment used as condition. 5148 void DiagnoseEqualityWithExtraParens(ParenExpr *parenE); 5149 5150 /// CheckCXXBooleanCondition - Returns true if conversion to bool is invalid. 5151 ExprResult CheckCXXBooleanCondition(Expr *CondExpr); 5152 5153 /// ConvertIntegerToTypeWarnOnOverflow - Convert the specified APInt to have 5154 /// the specified width and sign. If an overflow occurs, detect it and emit 5155 /// the specified diagnostic. 5156 void ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &OldVal, 5157 unsigned NewWidth, bool NewSign, 5158 SourceLocation Loc, unsigned DiagID); 5159 5160 /// Checks that the Objective-C declaration is declared in the global scope. 5161 /// Emits an error and marks the declaration as invalid if it's not declared 5162 /// in the global scope. 5163 bool CheckObjCDeclScope(Decl *D); 5164 5165 /// VerifyIntegerConstantExpression - verifies that an expression is an ICE, 5166 /// and reports the appropriate diagnostics. Returns false on success. 5167 /// Can optionally return the value of the expression. 5168 bool VerifyIntegerConstantExpression(const Expr *E, llvm::APSInt *Result = 0); 5169 5170 /// VerifyBitField - verifies that a bit field expression is an ICE and has 5171 /// the correct width, and that the field type is valid. 5172 /// Returns false on success. 5173 /// Can optionally return whether the bit-field is of width 0 5174 bool VerifyBitField(SourceLocation FieldLoc, IdentifierInfo *FieldName, 5175 QualType FieldTy, const Expr *BitWidth, 5176 bool *ZeroWidth = 0); 5177 5178 /// \name Code completion 5179 //@{ 5180 /// \brief Describes the context in which code completion occurs. 5181 enum ParserCompletionContext { 5182 /// \brief Code completion occurs at top-level or namespace context. 5183 PCC_Namespace, 5184 /// \brief Code completion occurs within a class, struct, or union. 5185 PCC_Class, 5186 /// \brief Code completion occurs within an Objective-C interface, protocol, 5187 /// or category. 5188 PCC_ObjCInterface, 5189 /// \brief Code completion occurs within an Objective-C implementation or 5190 /// category implementation 5191 PCC_ObjCImplementation, 5192 /// \brief Code completion occurs within the list of instance variables 5193 /// in an Objective-C interface, protocol, category, or implementation. 5194 PCC_ObjCInstanceVariableList, 5195 /// \brief Code completion occurs following one or more template 5196 /// headers. 5197 PCC_Template, 5198 /// \brief Code completion occurs following one or more template 5199 /// headers within a class. 5200 PCC_MemberTemplate, 5201 /// \brief Code completion occurs within an expression. 5202 PCC_Expression, 5203 /// \brief Code completion occurs within a statement, which may 5204 /// also be an expression or a declaration. 5205 PCC_Statement, 5206 /// \brief Code completion occurs at the beginning of the 5207 /// initialization statement (or expression) in a for loop. 5208 PCC_ForInit, 5209 /// \brief Code completion occurs within the condition of an if, 5210 /// while, switch, or for statement. 5211 PCC_Condition, 5212 /// \brief Code completion occurs within the body of a function on a 5213 /// recovery path, where we do not have a specific handle on our position 5214 /// in the grammar. 5215 PCC_RecoveryInFunction, 5216 /// \brief Code completion occurs where only a type is permitted. 5217 PCC_Type, 5218 /// \brief Code completion occurs in a parenthesized expression, which 5219 /// might also be a type cast. 5220 PCC_ParenthesizedExpression, 5221 /// \brief Code completion occurs within a sequence of declaration 5222 /// specifiers within a function, method, or block. 5223 PCC_LocalDeclarationSpecifiers 5224 }; 5225 5226 void CodeCompleteOrdinaryName(Scope *S, 5227 ParserCompletionContext CompletionContext); 5228 void CodeCompleteDeclSpec(Scope *S, DeclSpec &DS, 5229 bool AllowNonIdentifiers, 5230 bool AllowNestedNameSpecifiers); 5231 5232 struct CodeCompleteExpressionData; 5233 void CodeCompleteExpression(Scope *S, 5234 const CodeCompleteExpressionData &Data); 5235 void CodeCompleteMemberReferenceExpr(Scope *S, Expr *Base, 5236 SourceLocation OpLoc, 5237 bool IsArrow); 5238 void CodeCompletePostfixExpression(Scope *S, ExprResult LHS); 5239 void CodeCompleteTag(Scope *S, unsigned TagSpec); 5240 void CodeCompleteTypeQualifiers(DeclSpec &DS); 5241 void CodeCompleteCase(Scope *S); 5242 void CodeCompleteCall(Scope *S, Expr *Fn, Expr **Args, unsigned NumArgs); 5243 void CodeCompleteInitializer(Scope *S, Decl *D); 5244 void CodeCompleteReturn(Scope *S); 5245 void CodeCompleteAssignmentRHS(Scope *S, Expr *LHS); 5246 5247 void CodeCompleteQualifiedId(Scope *S, CXXScopeSpec &SS, 5248 bool EnteringContext); 5249 void CodeCompleteUsing(Scope *S); 5250 void CodeCompleteUsingDirective(Scope *S); 5251 void CodeCompleteNamespaceDecl(Scope *S); 5252 void CodeCompleteNamespaceAliasDecl(Scope *S); 5253 void CodeCompleteOperatorName(Scope *S); 5254 void CodeCompleteConstructorInitializer(Decl *Constructor, 5255 CXXCtorInitializer** Initializers, 5256 unsigned NumInitializers); 5257 5258 void CodeCompleteObjCAtDirective(Scope *S, Decl *ObjCImpDecl, 5259 bool InInterface); 5260 void CodeCompleteObjCAtVisibility(Scope *S); 5261 void CodeCompleteObjCAtStatement(Scope *S); 5262 void CodeCompleteObjCAtExpression(Scope *S); 5263 void CodeCompleteObjCPropertyFlags(Scope *S, ObjCDeclSpec &ODS); 5264 void CodeCompleteObjCPropertyGetter(Scope *S, Decl *ClassDecl); 5265 void CodeCompleteObjCPropertySetter(Scope *S, Decl *ClassDecl); 5266 void CodeCompleteObjCPassingType(Scope *S, ObjCDeclSpec &DS, 5267 bool IsParameter); 5268 void CodeCompleteObjCMessageReceiver(Scope *S); 5269 void CodeCompleteObjCSuperMessage(Scope *S, SourceLocation SuperLoc, 5270 IdentifierInfo **SelIdents, 5271 unsigned NumSelIdents, 5272 bool AtArgumentExpression); 5273 void CodeCompleteObjCClassMessage(Scope *S, ParsedType Receiver, 5274 IdentifierInfo **SelIdents, 5275 unsigned NumSelIdents, 5276 bool AtArgumentExpression, 5277 bool IsSuper = false); 5278 void CodeCompleteObjCInstanceMessage(Scope *S, ExprTy *Receiver, 5279 IdentifierInfo **SelIdents, 5280 unsigned NumSelIdents, 5281 bool AtArgumentExpression, 5282 ObjCInterfaceDecl *Super = 0); 5283 void CodeCompleteObjCForCollection(Scope *S, 5284 DeclGroupPtrTy IterationVar); 5285 void CodeCompleteObjCSelector(Scope *S, 5286 IdentifierInfo **SelIdents, 5287 unsigned NumSelIdents); 5288 void CodeCompleteObjCProtocolReferences(IdentifierLocPair *Protocols, 5289 unsigned NumProtocols); 5290 void CodeCompleteObjCProtocolDecl(Scope *S); 5291 void CodeCompleteObjCInterfaceDecl(Scope *S); 5292 void CodeCompleteObjCSuperclass(Scope *S, 5293 IdentifierInfo *ClassName, 5294 SourceLocation ClassNameLoc); 5295 void CodeCompleteObjCImplementationDecl(Scope *S); 5296 void CodeCompleteObjCInterfaceCategory(Scope *S, 5297 IdentifierInfo *ClassName, 5298 SourceLocation ClassNameLoc); 5299 void CodeCompleteObjCImplementationCategory(Scope *S, 5300 IdentifierInfo *ClassName, 5301 SourceLocation ClassNameLoc); 5302 void CodeCompleteObjCPropertyDefinition(Scope *S, Decl *ObjCImpDecl); 5303 void CodeCompleteObjCPropertySynthesizeIvar(Scope *S, 5304 IdentifierInfo *PropertyName, 5305 Decl *ObjCImpDecl); 5306 void CodeCompleteObjCMethodDecl(Scope *S, 5307 bool IsInstanceMethod, 5308 ParsedType ReturnType, 5309 Decl *IDecl); 5310 void CodeCompleteObjCMethodDeclSelector(Scope *S, 5311 bool IsInstanceMethod, 5312 bool AtParameterName, 5313 ParsedType ReturnType, 5314 IdentifierInfo **SelIdents, 5315 unsigned NumSelIdents); 5316 void CodeCompletePreprocessorDirective(bool InConditional); 5317 void CodeCompleteInPreprocessorConditionalExclusion(Scope *S); 5318 void CodeCompletePreprocessorMacroName(bool IsDefinition); 5319 void CodeCompletePreprocessorExpression(); 5320 void CodeCompletePreprocessorMacroArgument(Scope *S, 5321 IdentifierInfo *Macro, 5322 MacroInfo *MacroInfo, 5323 unsigned Argument); 5324 void CodeCompleteNaturalLanguage(); 5325 void GatherGlobalCodeCompletions(CodeCompletionAllocator &Allocator, 5326 llvm::SmallVectorImpl<CodeCompletionResult> &Results); 5327 //@} 5328 5329 void PrintStats() const {} 5330 5331 //===--------------------------------------------------------------------===// 5332 // Extra semantic analysis beyond the C type system 5333 5334public: 5335 SourceLocation getLocationOfStringLiteralByte(const StringLiteral *SL, 5336 unsigned ByteNo) const; 5337 5338private: 5339 void CheckArrayAccess(const Expr *E); 5340 bool CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall); 5341 bool CheckBlockCall(NamedDecl *NDecl, CallExpr *TheCall); 5342 5343 bool CheckablePrintfAttr(const FormatAttr *Format, CallExpr *TheCall); 5344 bool CheckObjCString(Expr *Arg); 5345 5346 ExprResult CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); 5347 bool CheckARMBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); 5348 5349 bool SemaBuiltinVAStart(CallExpr *TheCall); 5350 bool SemaBuiltinUnorderedCompare(CallExpr *TheCall); 5351 bool SemaBuiltinFPClassification(CallExpr *TheCall, unsigned NumArgs); 5352 5353public: 5354 // Used by C++ template instantiation. 5355 ExprResult SemaBuiltinShuffleVector(CallExpr *TheCall); 5356 5357private: 5358 bool SemaBuiltinPrefetch(CallExpr *TheCall); 5359 bool SemaBuiltinObjectSize(CallExpr *TheCall); 5360 bool SemaBuiltinLongjmp(CallExpr *TheCall); 5361 ExprResult SemaBuiltinAtomicOverloaded(ExprResult TheCallResult); 5362 bool SemaBuiltinConstantArg(CallExpr *TheCall, int ArgNum, 5363 llvm::APSInt &Result); 5364 5365 bool SemaCheckStringLiteral(const Expr *E, const CallExpr *TheCall, 5366 bool HasVAListArg, unsigned format_idx, 5367 unsigned firstDataArg, bool isPrintf); 5368 5369 void CheckFormatString(const StringLiteral *FExpr, const Expr *OrigFormatExpr, 5370 const CallExpr *TheCall, bool HasVAListArg, 5371 unsigned format_idx, unsigned firstDataArg, 5372 bool isPrintf); 5373 5374 void CheckNonNullArguments(const NonNullAttr *NonNull, 5375 const Expr * const *ExprArgs, 5376 SourceLocation CallSiteLoc); 5377 5378 void CheckPrintfScanfArguments(const CallExpr *TheCall, bool HasVAListArg, 5379 unsigned format_idx, unsigned firstDataArg, 5380 bool isPrintf); 5381 5382 void CheckReturnStackAddr(Expr *RetValExp, QualType lhsType, 5383 SourceLocation ReturnLoc); 5384 void CheckFloatComparison(SourceLocation loc, Expr* lex, Expr* rex); 5385 void CheckImplicitConversions(Expr *E, SourceLocation CC = SourceLocation()); 5386 5387 void CheckBitFieldInitialization(SourceLocation InitLoc, FieldDecl *Field, 5388 Expr *Init); 5389 5390 /// \brief The parser's current scope. 5391 /// 5392 /// The parser maintains this state here. 5393 Scope *CurScope; 5394 5395protected: 5396 friend class Parser; 5397 friend class InitializationSequence; 5398 5399 /// \brief Retrieve the parser's current scope. 5400 Scope *getCurScope() const { return CurScope; } 5401}; 5402 5403/// \brief RAII object that enters a new expression evaluation context. 5404class EnterExpressionEvaluationContext { 5405 Sema &Actions; 5406 5407public: 5408 EnterExpressionEvaluationContext(Sema &Actions, 5409 Sema::ExpressionEvaluationContext NewContext) 5410 : Actions(Actions) { 5411 Actions.PushExpressionEvaluationContext(NewContext); 5412 } 5413 5414 ~EnterExpressionEvaluationContext() { 5415 Actions.PopExpressionEvaluationContext(); 5416 } 5417}; 5418 5419} // end namespace clang 5420 5421#endif 5422