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