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