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