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