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