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