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