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