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