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