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