Sema.h revision 96b69a7305e20c98f1a3e2e7cd52e2d6c5d53835
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 if a defaulted default constructor ought to be 2586 /// deleted. 2587 bool ShouldDeleteDefaultConstructor(CXXConstructorDecl *RD); 2588 2589 /// \brief Declare the implicit default constructor for the given class. 2590 /// 2591 /// \param ClassDecl The class declaration into which the implicit 2592 /// default constructor will be added. 2593 /// 2594 /// \returns The implicitly-declared default constructor. 2595 CXXConstructorDecl *DeclareImplicitDefaultConstructor( 2596 CXXRecordDecl *ClassDecl); 2597 2598 /// DefineImplicitDefaultConstructor - Checks for feasibility of 2599 /// defining this constructor as the default constructor. 2600 void DefineImplicitDefaultConstructor(SourceLocation CurrentLocation, 2601 CXXConstructorDecl *Constructor); 2602 2603 /// \brief Declare the implicit destructor for the given class. 2604 /// 2605 /// \param ClassDecl The class declaration into which the implicit 2606 /// destructor will be added. 2607 /// 2608 /// \returns The implicitly-declared destructor. 2609 CXXDestructorDecl *DeclareImplicitDestructor(CXXRecordDecl *ClassDecl); 2610 2611 /// DefineImplicitDestructor - Checks for feasibility of 2612 /// defining this destructor as the default destructor. 2613 void DefineImplicitDestructor(SourceLocation CurrentLocation, 2614 CXXDestructorDecl *Destructor); 2615 2616 /// \brief Declare all inherited constructors for the given class. 2617 /// 2618 /// \param ClassDecl The class declaration into which the inherited 2619 /// constructors will be added. 2620 void DeclareInheritedConstructors(CXXRecordDecl *ClassDecl); 2621 2622 /// \brief Declare the implicit copy constructor for the given class. 2623 /// 2624 /// \param S The scope of the class, which may be NULL if this is a 2625 /// template instantiation. 2626 /// 2627 /// \param ClassDecl The class declaration into which the implicit 2628 /// copy constructor will be added. 2629 /// 2630 /// \returns The implicitly-declared copy constructor. 2631 CXXConstructorDecl *DeclareImplicitCopyConstructor(CXXRecordDecl *ClassDecl); 2632 2633 /// DefineImplicitCopyConstructor - Checks for feasibility of 2634 /// defining this constructor as the copy constructor. 2635 void DefineImplicitCopyConstructor(SourceLocation CurrentLocation, 2636 CXXConstructorDecl *Constructor, 2637 unsigned TypeQuals); 2638 2639 /// \brief Declare the implicit copy assignment operator for the given class. 2640 /// 2641 /// \param S The scope of the class, which may be NULL if this is a 2642 /// template instantiation. 2643 /// 2644 /// \param ClassDecl The class declaration into which the implicit 2645 /// copy-assignment operator will be added. 2646 /// 2647 /// \returns The implicitly-declared copy assignment operator. 2648 CXXMethodDecl *DeclareImplicitCopyAssignment(CXXRecordDecl *ClassDecl); 2649 2650 /// \brief Defined an implicitly-declared copy assignment operator. 2651 void DefineImplicitCopyAssignment(SourceLocation CurrentLocation, 2652 CXXMethodDecl *MethodDecl); 2653 2654 /// \brief Force the declaration of any implicitly-declared members of this 2655 /// class. 2656 void ForceDeclarationOfImplicitMembers(CXXRecordDecl *Class); 2657 2658 /// MaybeBindToTemporary - If the passed in expression has a record type with 2659 /// a non-trivial destructor, this will return CXXBindTemporaryExpr. Otherwise 2660 /// it simply returns the passed in expression. 2661 ExprResult MaybeBindToTemporary(Expr *E); 2662 2663 bool CompleteConstructorCall(CXXConstructorDecl *Constructor, 2664 MultiExprArg ArgsPtr, 2665 SourceLocation Loc, 2666 ASTOwningVector<Expr*> &ConvertedArgs); 2667 2668 ParsedType getDestructorName(SourceLocation TildeLoc, 2669 IdentifierInfo &II, SourceLocation NameLoc, 2670 Scope *S, CXXScopeSpec &SS, 2671 ParsedType ObjectType, 2672 bool EnteringContext); 2673 2674 // Checks that reinterpret casts don't have undefined behavior. 2675 void CheckCompatibleReinterpretCast(QualType SrcType, QualType DestType, 2676 bool IsDereference, SourceRange Range); 2677 2678 /// ActOnCXXNamedCast - Parse {dynamic,static,reinterpret,const}_cast's. 2679 ExprResult ActOnCXXNamedCast(SourceLocation OpLoc, 2680 tok::TokenKind Kind, 2681 SourceLocation LAngleBracketLoc, 2682 ParsedType Ty, 2683 SourceLocation RAngleBracketLoc, 2684 SourceLocation LParenLoc, 2685 Expr *E, 2686 SourceLocation RParenLoc); 2687 2688 ExprResult BuildCXXNamedCast(SourceLocation OpLoc, 2689 tok::TokenKind Kind, 2690 TypeSourceInfo *Ty, 2691 Expr *E, 2692 SourceRange AngleBrackets, 2693 SourceRange Parens); 2694 2695 ExprResult BuildCXXTypeId(QualType TypeInfoType, 2696 SourceLocation TypeidLoc, 2697 TypeSourceInfo *Operand, 2698 SourceLocation RParenLoc); 2699 ExprResult BuildCXXTypeId(QualType TypeInfoType, 2700 SourceLocation TypeidLoc, 2701 Expr *Operand, 2702 SourceLocation RParenLoc); 2703 2704 /// ActOnCXXTypeid - Parse typeid( something ). 2705 ExprResult ActOnCXXTypeid(SourceLocation OpLoc, 2706 SourceLocation LParenLoc, bool isType, 2707 void *TyOrExpr, 2708 SourceLocation RParenLoc); 2709 2710 ExprResult BuildCXXUuidof(QualType TypeInfoType, 2711 SourceLocation TypeidLoc, 2712 TypeSourceInfo *Operand, 2713 SourceLocation RParenLoc); 2714 ExprResult BuildCXXUuidof(QualType TypeInfoType, 2715 SourceLocation TypeidLoc, 2716 Expr *Operand, 2717 SourceLocation RParenLoc); 2718 2719 /// ActOnCXXUuidof - Parse __uuidof( something ). 2720 ExprResult ActOnCXXUuidof(SourceLocation OpLoc, 2721 SourceLocation LParenLoc, bool isType, 2722 void *TyOrExpr, 2723 SourceLocation RParenLoc); 2724 2725 2726 //// ActOnCXXThis - Parse 'this' pointer. 2727 ExprResult ActOnCXXThis(SourceLocation loc); 2728 2729 /// tryCaptureCXXThis - Try to capture a 'this' pointer. Returns a 2730 /// pointer to an instance method whose 'this' pointer is 2731 /// capturable, or null if this is not possible. 2732 CXXMethodDecl *tryCaptureCXXThis(); 2733 2734 /// ActOnCXXBoolLiteral - Parse {true,false} literals. 2735 ExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind); 2736 2737 /// ActOnCXXNullPtrLiteral - Parse 'nullptr'. 2738 ExprResult ActOnCXXNullPtrLiteral(SourceLocation Loc); 2739 2740 //// ActOnCXXThrow - Parse throw expressions. 2741 ExprResult ActOnCXXThrow(SourceLocation OpLoc, Expr *expr); 2742 ExprResult CheckCXXThrowOperand(SourceLocation ThrowLoc, Expr *E); 2743 2744 /// ActOnCXXTypeConstructExpr - Parse construction of a specified type. 2745 /// Can be interpreted either as function-style casting ("int(x)") 2746 /// or class type construction ("ClassType(x,y,z)") 2747 /// or creation of a value-initialized type ("int()"). 2748 ExprResult ActOnCXXTypeConstructExpr(ParsedType TypeRep, 2749 SourceLocation LParenLoc, 2750 MultiExprArg Exprs, 2751 SourceLocation RParenLoc); 2752 2753 ExprResult BuildCXXTypeConstructExpr(TypeSourceInfo *Type, 2754 SourceLocation LParenLoc, 2755 MultiExprArg Exprs, 2756 SourceLocation RParenLoc); 2757 2758 /// ActOnCXXNew - Parsed a C++ 'new' expression. 2759 ExprResult ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal, 2760 SourceLocation PlacementLParen, 2761 MultiExprArg PlacementArgs, 2762 SourceLocation PlacementRParen, 2763 SourceRange TypeIdParens, Declarator &D, 2764 SourceLocation ConstructorLParen, 2765 MultiExprArg ConstructorArgs, 2766 SourceLocation ConstructorRParen); 2767 ExprResult BuildCXXNew(SourceLocation StartLoc, bool UseGlobal, 2768 SourceLocation PlacementLParen, 2769 MultiExprArg PlacementArgs, 2770 SourceLocation PlacementRParen, 2771 SourceRange TypeIdParens, 2772 QualType AllocType, 2773 TypeSourceInfo *AllocTypeInfo, 2774 Expr *ArraySize, 2775 SourceLocation ConstructorLParen, 2776 MultiExprArg ConstructorArgs, 2777 SourceLocation ConstructorRParen, 2778 bool TypeMayContainAuto = true); 2779 2780 bool CheckAllocatedType(QualType AllocType, SourceLocation Loc, 2781 SourceRange R); 2782 bool FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range, 2783 bool UseGlobal, QualType AllocType, bool IsArray, 2784 Expr **PlaceArgs, unsigned NumPlaceArgs, 2785 FunctionDecl *&OperatorNew, 2786 FunctionDecl *&OperatorDelete); 2787 bool FindAllocationOverload(SourceLocation StartLoc, SourceRange Range, 2788 DeclarationName Name, Expr** Args, 2789 unsigned NumArgs, DeclContext *Ctx, 2790 bool AllowMissing, FunctionDecl *&Operator); 2791 void DeclareGlobalNewDelete(); 2792 void DeclareGlobalAllocationFunction(DeclarationName Name, QualType Return, 2793 QualType Argument, 2794 bool addMallocAttr = false); 2795 2796 bool FindDeallocationFunction(SourceLocation StartLoc, CXXRecordDecl *RD, 2797 DeclarationName Name, FunctionDecl* &Operator); 2798 2799 /// ActOnCXXDelete - Parsed a C++ 'delete' expression 2800 ExprResult ActOnCXXDelete(SourceLocation StartLoc, 2801 bool UseGlobal, bool ArrayForm, 2802 Expr *Operand); 2803 2804 DeclResult ActOnCXXConditionDeclaration(Scope *S, Declarator &D); 2805 ExprResult CheckConditionVariable(VarDecl *ConditionVar, 2806 SourceLocation StmtLoc, 2807 bool ConvertToBoolean); 2808 2809 ExprResult ActOnNoexceptExpr(SourceLocation KeyLoc, SourceLocation LParen, 2810 Expr *Operand, SourceLocation RParen); 2811 ExprResult BuildCXXNoexceptExpr(SourceLocation KeyLoc, Expr *Operand, 2812 SourceLocation RParen); 2813 2814 /// ActOnUnaryTypeTrait - Parsed one of the unary type trait support 2815 /// pseudo-functions. 2816 ExprResult ActOnUnaryTypeTrait(UnaryTypeTrait OTT, 2817 SourceLocation KWLoc, 2818 ParsedType Ty, 2819 SourceLocation RParen); 2820 2821 ExprResult BuildUnaryTypeTrait(UnaryTypeTrait OTT, 2822 SourceLocation KWLoc, 2823 TypeSourceInfo *T, 2824 SourceLocation RParen); 2825 2826 /// ActOnBinaryTypeTrait - Parsed one of the bianry type trait support 2827 /// pseudo-functions. 2828 ExprResult ActOnBinaryTypeTrait(BinaryTypeTrait OTT, 2829 SourceLocation KWLoc, 2830 ParsedType LhsTy, 2831 ParsedType RhsTy, 2832 SourceLocation RParen); 2833 2834 ExprResult BuildBinaryTypeTrait(BinaryTypeTrait BTT, 2835 SourceLocation KWLoc, 2836 TypeSourceInfo *LhsT, 2837 TypeSourceInfo *RhsT, 2838 SourceLocation RParen); 2839 2840 /// ActOnArrayTypeTrait - Parsed one of the bianry type trait support 2841 /// pseudo-functions. 2842 ExprResult ActOnArrayTypeTrait(ArrayTypeTrait ATT, 2843 SourceLocation KWLoc, 2844 ParsedType LhsTy, 2845 Expr *DimExpr, 2846 SourceLocation RParen); 2847 2848 ExprResult BuildArrayTypeTrait(ArrayTypeTrait ATT, 2849 SourceLocation KWLoc, 2850 TypeSourceInfo *TSInfo, 2851 Expr *DimExpr, 2852 SourceLocation RParen); 2853 2854 /// ActOnExpressionTrait - Parsed one of the unary type trait support 2855 /// pseudo-functions. 2856 ExprResult ActOnExpressionTrait(ExpressionTrait OET, 2857 SourceLocation KWLoc, 2858 Expr *Queried, 2859 SourceLocation RParen); 2860 2861 ExprResult BuildExpressionTrait(ExpressionTrait OET, 2862 SourceLocation KWLoc, 2863 Expr *Queried, 2864 SourceLocation RParen); 2865 2866 ExprResult ActOnStartCXXMemberReference(Scope *S, 2867 Expr *Base, 2868 SourceLocation OpLoc, 2869 tok::TokenKind OpKind, 2870 ParsedType &ObjectType, 2871 bool &MayBePseudoDestructor); 2872 2873 ExprResult DiagnoseDtorReference(SourceLocation NameLoc, Expr *MemExpr); 2874 2875 ExprResult BuildPseudoDestructorExpr(Expr *Base, 2876 SourceLocation OpLoc, 2877 tok::TokenKind OpKind, 2878 const CXXScopeSpec &SS, 2879 TypeSourceInfo *ScopeType, 2880 SourceLocation CCLoc, 2881 SourceLocation TildeLoc, 2882 PseudoDestructorTypeStorage DestroyedType, 2883 bool HasTrailingLParen); 2884 2885 ExprResult ActOnPseudoDestructorExpr(Scope *S, Expr *Base, 2886 SourceLocation OpLoc, 2887 tok::TokenKind OpKind, 2888 CXXScopeSpec &SS, 2889 UnqualifiedId &FirstTypeName, 2890 SourceLocation CCLoc, 2891 SourceLocation TildeLoc, 2892 UnqualifiedId &SecondTypeName, 2893 bool HasTrailingLParen); 2894 2895 /// MaybeCreateExprWithCleanups - If the current full-expression 2896 /// requires any cleanups, surround it with a ExprWithCleanups node. 2897 /// Otherwise, just returns the passed-in expression. 2898 Expr *MaybeCreateExprWithCleanups(Expr *SubExpr); 2899 Stmt *MaybeCreateStmtWithCleanups(Stmt *SubStmt); 2900 ExprResult MaybeCreateExprWithCleanups(ExprResult SubExpr); 2901 2902 ExprResult ActOnFinishFullExpr(Expr *Expr); 2903 StmtResult ActOnFinishFullStmt(Stmt *Stmt); 2904 2905 // Marks SS invalid if it represents an incomplete type. 2906 bool RequireCompleteDeclContext(CXXScopeSpec &SS, DeclContext *DC); 2907 2908 DeclContext *computeDeclContext(QualType T); 2909 DeclContext *computeDeclContext(const CXXScopeSpec &SS, 2910 bool EnteringContext = false); 2911 bool isDependentScopeSpecifier(const CXXScopeSpec &SS); 2912 CXXRecordDecl *getCurrentInstantiationOf(NestedNameSpecifier *NNS); 2913 bool isUnknownSpecialization(const CXXScopeSpec &SS); 2914 2915 /// \brief The parser has parsed a global nested-name-specifier '::'. 2916 /// 2917 /// \param S The scope in which this nested-name-specifier occurs. 2918 /// 2919 /// \param CCLoc The location of the '::'. 2920 /// 2921 /// \param SS The nested-name-specifier, which will be updated in-place 2922 /// to reflect the parsed nested-name-specifier. 2923 /// 2924 /// \returns true if an error occurred, false otherwise. 2925 bool ActOnCXXGlobalScopeSpecifier(Scope *S, SourceLocation CCLoc, 2926 CXXScopeSpec &SS); 2927 2928 bool isAcceptableNestedNameSpecifier(NamedDecl *SD); 2929 NamedDecl *FindFirstQualifierInScope(Scope *S, NestedNameSpecifier *NNS); 2930 2931 bool isNonTypeNestedNameSpecifier(Scope *S, CXXScopeSpec &SS, 2932 SourceLocation IdLoc, 2933 IdentifierInfo &II, 2934 ParsedType ObjectType); 2935 2936 bool BuildCXXNestedNameSpecifier(Scope *S, 2937 IdentifierInfo &Identifier, 2938 SourceLocation IdentifierLoc, 2939 SourceLocation CCLoc, 2940 QualType ObjectType, 2941 bool EnteringContext, 2942 CXXScopeSpec &SS, 2943 NamedDecl *ScopeLookupResult, 2944 bool ErrorRecoveryLookup); 2945 2946 /// \brief The parser has parsed a nested-name-specifier 'identifier::'. 2947 /// 2948 /// \param S The scope in which this nested-name-specifier occurs. 2949 /// 2950 /// \param Identifier The identifier preceding the '::'. 2951 /// 2952 /// \param IdentifierLoc The location of the identifier. 2953 /// 2954 /// \param CCLoc The location of the '::'. 2955 /// 2956 /// \param ObjectType The type of the object, if we're parsing 2957 /// nested-name-specifier in a member access expression. 2958 /// 2959 /// \param EnteringContext Whether we're entering the context nominated by 2960 /// this nested-name-specifier. 2961 /// 2962 /// \param SS The nested-name-specifier, which is both an input 2963 /// parameter (the nested-name-specifier before this type) and an 2964 /// output parameter (containing the full nested-name-specifier, 2965 /// including this new type). 2966 /// 2967 /// \returns true if an error occurred, false otherwise. 2968 bool ActOnCXXNestedNameSpecifier(Scope *S, 2969 IdentifierInfo &Identifier, 2970 SourceLocation IdentifierLoc, 2971 SourceLocation CCLoc, 2972 ParsedType ObjectType, 2973 bool EnteringContext, 2974 CXXScopeSpec &SS); 2975 2976 bool IsInvalidUnlessNestedName(Scope *S, CXXScopeSpec &SS, 2977 IdentifierInfo &Identifier, 2978 SourceLocation IdentifierLoc, 2979 SourceLocation ColonLoc, 2980 ParsedType ObjectType, 2981 bool EnteringContext); 2982 2983 /// \brief The parser has parsed a nested-name-specifier 2984 /// 'template[opt] template-name < template-args >::'. 2985 /// 2986 /// \param S The scope in which this nested-name-specifier occurs. 2987 /// 2988 /// \param TemplateLoc The location of the 'template' keyword, if any. 2989 /// 2990 /// \param SS The nested-name-specifier, which is both an input 2991 /// parameter (the nested-name-specifier before this type) and an 2992 /// output parameter (containing the full nested-name-specifier, 2993 /// including this new type). 2994 /// 2995 /// \param TemplateLoc the location of the 'template' keyword, if any. 2996 /// \param TemplateName The template name. 2997 /// \param TemplateNameLoc The location of the template name. 2998 /// \param LAngleLoc The location of the opening angle bracket ('<'). 2999 /// \param TemplateArgs The template arguments. 3000 /// \param RAngleLoc The location of the closing angle bracket ('>'). 3001 /// \param CCLoc The location of the '::'. 3002 3003 /// \param EnteringContext Whether we're entering the context of the 3004 /// nested-name-specifier. 3005 /// 3006 /// 3007 /// \returns true if an error occurred, false otherwise. 3008 bool ActOnCXXNestedNameSpecifier(Scope *S, 3009 SourceLocation TemplateLoc, 3010 CXXScopeSpec &SS, 3011 TemplateTy Template, 3012 SourceLocation TemplateNameLoc, 3013 SourceLocation LAngleLoc, 3014 ASTTemplateArgsPtr TemplateArgs, 3015 SourceLocation RAngleLoc, 3016 SourceLocation CCLoc, 3017 bool EnteringContext); 3018 3019 /// \brief Given a C++ nested-name-specifier, produce an annotation value 3020 /// that the parser can use later to reconstruct the given 3021 /// nested-name-specifier. 3022 /// 3023 /// \param SS A nested-name-specifier. 3024 /// 3025 /// \returns A pointer containing all of the information in the 3026 /// nested-name-specifier \p SS. 3027 void *SaveNestedNameSpecifierAnnotation(CXXScopeSpec &SS); 3028 3029 /// \brief Given an annotation pointer for a nested-name-specifier, restore 3030 /// the nested-name-specifier structure. 3031 /// 3032 /// \param Annotation The annotation pointer, produced by 3033 /// \c SaveNestedNameSpecifierAnnotation(). 3034 /// 3035 /// \param AnnotationRange The source range corresponding to the annotation. 3036 /// 3037 /// \param SS The nested-name-specifier that will be updated with the contents 3038 /// of the annotation pointer. 3039 void RestoreNestedNameSpecifierAnnotation(void *Annotation, 3040 SourceRange AnnotationRange, 3041 CXXScopeSpec &SS); 3042 3043 bool ShouldEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS); 3044 3045 /// ActOnCXXEnterDeclaratorScope - Called when a C++ scope specifier (global 3046 /// scope or nested-name-specifier) is parsed, part of a declarator-id. 3047 /// After this method is called, according to [C++ 3.4.3p3], names should be 3048 /// looked up in the declarator-id's scope, until the declarator is parsed and 3049 /// ActOnCXXExitDeclaratorScope is called. 3050 /// The 'SS' should be a non-empty valid CXXScopeSpec. 3051 bool ActOnCXXEnterDeclaratorScope(Scope *S, CXXScopeSpec &SS); 3052 3053 /// ActOnCXXExitDeclaratorScope - Called when a declarator that previously 3054 /// invoked ActOnCXXEnterDeclaratorScope(), is finished. 'SS' is the same 3055 /// CXXScopeSpec that was passed to ActOnCXXEnterDeclaratorScope as well. 3056 /// Used to indicate that names should revert to being looked up in the 3057 /// defining scope. 3058 void ActOnCXXExitDeclaratorScope(Scope *S, const CXXScopeSpec &SS); 3059 3060 /// ActOnCXXEnterDeclInitializer - Invoked when we are about to parse an 3061 /// initializer for the declaration 'Dcl'. 3062 /// After this method is called, according to [C++ 3.4.1p13], if 'Dcl' is a 3063 /// static data member of class X, names should be looked up in the scope of 3064 /// class X. 3065 void ActOnCXXEnterDeclInitializer(Scope *S, Decl *Dcl); 3066 3067 /// ActOnCXXExitDeclInitializer - Invoked after we are finished parsing an 3068 /// initializer for the declaration 'Dcl'. 3069 void ActOnCXXExitDeclInitializer(Scope *S, Decl *Dcl); 3070 3071 // ParseObjCStringLiteral - Parse Objective-C string literals. 3072 ExprResult ParseObjCStringLiteral(SourceLocation *AtLocs, 3073 Expr **Strings, 3074 unsigned NumStrings); 3075 3076 Expr *BuildObjCEncodeExpression(SourceLocation AtLoc, 3077 TypeSourceInfo *EncodedTypeInfo, 3078 SourceLocation RParenLoc); 3079 ExprResult BuildCXXMemberCallExpr(Expr *Exp, NamedDecl *FoundDecl, 3080 CXXMethodDecl *Method); 3081 3082 ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc, 3083 SourceLocation EncodeLoc, 3084 SourceLocation LParenLoc, 3085 ParsedType Ty, 3086 SourceLocation RParenLoc); 3087 3088 // ParseObjCSelectorExpression - Build selector expression for @selector 3089 ExprResult ParseObjCSelectorExpression(Selector Sel, 3090 SourceLocation AtLoc, 3091 SourceLocation SelLoc, 3092 SourceLocation LParenLoc, 3093 SourceLocation RParenLoc); 3094 3095 // ParseObjCProtocolExpression - Build protocol expression for @protocol 3096 ExprResult ParseObjCProtocolExpression(IdentifierInfo * ProtocolName, 3097 SourceLocation AtLoc, 3098 SourceLocation ProtoLoc, 3099 SourceLocation LParenLoc, 3100 SourceLocation RParenLoc); 3101 3102 //===--------------------------------------------------------------------===// 3103 // C++ Declarations 3104 // 3105 Decl *ActOnStartLinkageSpecification(Scope *S, 3106 SourceLocation ExternLoc, 3107 SourceLocation LangLoc, 3108 llvm::StringRef Lang, 3109 SourceLocation LBraceLoc); 3110 Decl *ActOnFinishLinkageSpecification(Scope *S, 3111 Decl *LinkageSpec, 3112 SourceLocation RBraceLoc); 3113 3114 3115 //===--------------------------------------------------------------------===// 3116 // C++ Classes 3117 // 3118 bool isCurrentClassName(const IdentifierInfo &II, Scope *S, 3119 const CXXScopeSpec *SS = 0); 3120 3121 Decl *ActOnAccessSpecifier(AccessSpecifier Access, 3122 SourceLocation ASLoc, 3123 SourceLocation ColonLoc); 3124 3125 Decl *ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS, 3126 Declarator &D, 3127 MultiTemplateParamsArg TemplateParameterLists, 3128 Expr *BitfieldWidth, const VirtSpecifiers &VS, 3129 Expr *Init, bool IsDefinition); 3130 3131 MemInitResult ActOnMemInitializer(Decl *ConstructorD, 3132 Scope *S, 3133 CXXScopeSpec &SS, 3134 IdentifierInfo *MemberOrBase, 3135 ParsedType TemplateTypeTy, 3136 SourceLocation IdLoc, 3137 SourceLocation LParenLoc, 3138 Expr **Args, unsigned NumArgs, 3139 SourceLocation RParenLoc, 3140 SourceLocation EllipsisLoc); 3141 3142 MemInitResult BuildMemberInitializer(ValueDecl *Member, Expr **Args, 3143 unsigned NumArgs, SourceLocation IdLoc, 3144 SourceLocation LParenLoc, 3145 SourceLocation RParenLoc); 3146 3147 MemInitResult BuildBaseInitializer(QualType BaseType, 3148 TypeSourceInfo *BaseTInfo, 3149 Expr **Args, unsigned NumArgs, 3150 SourceLocation LParenLoc, 3151 SourceLocation RParenLoc, 3152 CXXRecordDecl *ClassDecl, 3153 SourceLocation EllipsisLoc); 3154 3155 MemInitResult BuildDelegatingInitializer(TypeSourceInfo *TInfo, 3156 Expr **Args, unsigned NumArgs, 3157 SourceLocation BaseLoc, 3158 SourceLocation RParenLoc, 3159 SourceLocation LParenLoc, 3160 CXXRecordDecl *ClassDecl); 3161 3162 bool SetDelegatingInitializer(CXXConstructorDecl *Constructor, 3163 CXXCtorInitializer *Initializer); 3164 3165 bool SetCtorInitializers(CXXConstructorDecl *Constructor, 3166 CXXCtorInitializer **Initializers, 3167 unsigned NumInitializers, bool AnyErrors); 3168 3169 void SetIvarInitializers(ObjCImplementationDecl *ObjCImplementation); 3170 3171 3172 /// MarkBaseAndMemberDestructorsReferenced - Given a record decl, 3173 /// mark all the non-trivial destructors of its members and bases as 3174 /// referenced. 3175 void MarkBaseAndMemberDestructorsReferenced(SourceLocation Loc, 3176 CXXRecordDecl *Record); 3177 3178 /// \brief The list of classes whose vtables have been used within 3179 /// this translation unit, and the source locations at which the 3180 /// first use occurred. 3181 typedef std::pair<CXXRecordDecl*, SourceLocation> VTableUse; 3182 3183 /// \brief The list of vtables that are required but have not yet been 3184 /// materialized. 3185 llvm::SmallVector<VTableUse, 16> VTableUses; 3186 3187 /// \brief The set of classes whose vtables have been used within 3188 /// this translation unit, and a bit that will be true if the vtable is 3189 /// required to be emitted (otherwise, it should be emitted only if needed 3190 /// by code generation). 3191 llvm::DenseMap<CXXRecordDecl *, bool> VTablesUsed; 3192 3193 /// \brief A list of all of the dynamic classes in this translation 3194 /// unit. 3195 llvm::SmallVector<CXXRecordDecl *, 16> DynamicClasses; 3196 3197 /// \brief Note that the vtable for the given class was used at the 3198 /// given location. 3199 void MarkVTableUsed(SourceLocation Loc, CXXRecordDecl *Class, 3200 bool DefinitionRequired = false); 3201 3202 /// MarkVirtualMembersReferenced - Will mark all members of the given 3203 /// CXXRecordDecl referenced. 3204 void MarkVirtualMembersReferenced(SourceLocation Loc, 3205 const CXXRecordDecl *RD); 3206 3207 /// \brief Define all of the vtables that have been used in this 3208 /// translation unit and reference any virtual members used by those 3209 /// vtables. 3210 /// 3211 /// \returns true if any work was done, false otherwise. 3212 bool DefineUsedVTables(); 3213 3214 void AddImplicitlyDeclaredMembersToClass(CXXRecordDecl *ClassDecl); 3215 3216 void ActOnMemInitializers(Decl *ConstructorDecl, 3217 SourceLocation ColonLoc, 3218 MemInitTy **MemInits, unsigned NumMemInits, 3219 bool AnyErrors); 3220 3221 void CheckCompletedCXXClass(CXXRecordDecl *Record); 3222 void ActOnFinishCXXMemberSpecification(Scope* S, SourceLocation RLoc, 3223 Decl *TagDecl, 3224 SourceLocation LBrac, 3225 SourceLocation RBrac, 3226 AttributeList *AttrList); 3227 3228 void ActOnReenterTemplateScope(Scope *S, Decl *Template); 3229 void ActOnReenterDeclaratorTemplateScope(Scope *S, DeclaratorDecl *D); 3230 void ActOnStartDelayedMemberDeclarations(Scope *S, Decl *Record); 3231 void ActOnStartDelayedCXXMethodDeclaration(Scope *S, Decl *Method); 3232 void ActOnDelayedCXXMethodParameter(Scope *S, Decl *Param); 3233 void ActOnFinishDelayedCXXMethodDeclaration(Scope *S, Decl *Method); 3234 void ActOnFinishDelayedMemberDeclarations(Scope *S, Decl *Record); 3235 void MarkAsLateParsedTemplate(FunctionDecl *FD, bool Flag = true); 3236 bool IsInsideALocalClassWithinATemplateFunction(); 3237 3238 Decl *ActOnStaticAssertDeclaration(SourceLocation StaticAssertLoc, 3239 Expr *AssertExpr, 3240 Expr *AssertMessageExpr, 3241 SourceLocation RParenLoc); 3242 3243 FriendDecl *CheckFriendTypeDecl(SourceLocation FriendLoc, 3244 TypeSourceInfo *TSInfo); 3245 Decl *ActOnFriendTypeDecl(Scope *S, const DeclSpec &DS, 3246 MultiTemplateParamsArg TemplateParams); 3247 Decl *ActOnFriendFunctionDecl(Scope *S, Declarator &D, bool IsDefinition, 3248 MultiTemplateParamsArg TemplateParams); 3249 3250 QualType CheckConstructorDeclarator(Declarator &D, QualType R, 3251 StorageClass& SC); 3252 void CheckConstructor(CXXConstructorDecl *Constructor); 3253 QualType CheckDestructorDeclarator(Declarator &D, QualType R, 3254 StorageClass& SC); 3255 bool CheckDestructor(CXXDestructorDecl *Destructor); 3256 void CheckConversionDeclarator(Declarator &D, QualType &R, 3257 StorageClass& SC); 3258 Decl *ActOnConversionDeclarator(CXXConversionDecl *Conversion); 3259 3260 void CheckExplicitlyDefaultedMethods(CXXRecordDecl *Record); 3261 void CheckExplicitlyDefaultedDefaultConstructor(CXXConstructorDecl *Ctor); 3262 3263 //===--------------------------------------------------------------------===// 3264 // C++ Derived Classes 3265 // 3266 3267 /// ActOnBaseSpecifier - Parsed a base specifier 3268 CXXBaseSpecifier *CheckBaseSpecifier(CXXRecordDecl *Class, 3269 SourceRange SpecifierRange, 3270 bool Virtual, AccessSpecifier Access, 3271 TypeSourceInfo *TInfo, 3272 SourceLocation EllipsisLoc); 3273 3274 BaseResult ActOnBaseSpecifier(Decl *classdecl, 3275 SourceRange SpecifierRange, 3276 bool Virtual, AccessSpecifier Access, 3277 ParsedType basetype, 3278 SourceLocation BaseLoc, 3279 SourceLocation EllipsisLoc); 3280 3281 bool AttachBaseSpecifiers(CXXRecordDecl *Class, CXXBaseSpecifier **Bases, 3282 unsigned NumBases); 3283 void ActOnBaseSpecifiers(Decl *ClassDecl, BaseTy **Bases, unsigned NumBases); 3284 3285 bool IsDerivedFrom(QualType Derived, QualType Base); 3286 bool IsDerivedFrom(QualType Derived, QualType Base, CXXBasePaths &Paths); 3287 3288 // FIXME: I don't like this name. 3289 void BuildBasePathArray(const CXXBasePaths &Paths, CXXCastPath &BasePath); 3290 3291 bool BasePathInvolvesVirtualBase(const CXXCastPath &BasePath); 3292 3293 bool CheckDerivedToBaseConversion(QualType Derived, QualType Base, 3294 SourceLocation Loc, SourceRange Range, 3295 CXXCastPath *BasePath = 0, 3296 bool IgnoreAccess = false); 3297 bool CheckDerivedToBaseConversion(QualType Derived, QualType Base, 3298 unsigned InaccessibleBaseID, 3299 unsigned AmbigiousBaseConvID, 3300 SourceLocation Loc, SourceRange Range, 3301 DeclarationName Name, 3302 CXXCastPath *BasePath); 3303 3304 std::string getAmbiguousPathsDisplayString(CXXBasePaths &Paths); 3305 3306 /// CheckOverridingFunctionReturnType - Checks whether the return types are 3307 /// covariant, according to C++ [class.virtual]p5. 3308 bool CheckOverridingFunctionReturnType(const CXXMethodDecl *New, 3309 const CXXMethodDecl *Old); 3310 3311 /// CheckOverridingFunctionExceptionSpec - Checks whether the exception 3312 /// spec is a subset of base spec. 3313 bool CheckOverridingFunctionExceptionSpec(const CXXMethodDecl *New, 3314 const CXXMethodDecl *Old); 3315 3316 bool CheckPureMethod(CXXMethodDecl *Method, SourceRange InitRange); 3317 3318 /// CheckOverrideControl - Check C++0x override control semantics. 3319 void CheckOverrideControl(const Decl *D); 3320 3321 /// CheckForFunctionMarkedFinal - Checks whether a virtual member function 3322 /// overrides a virtual member function marked 'final', according to 3323 /// C++0x [class.virtual]p3. 3324 bool CheckIfOverriddenFunctionIsMarkedFinal(const CXXMethodDecl *New, 3325 const CXXMethodDecl *Old); 3326 3327 3328 //===--------------------------------------------------------------------===// 3329 // C++ Access Control 3330 // 3331 3332 enum AccessResult { 3333 AR_accessible, 3334 AR_inaccessible, 3335 AR_dependent, 3336 AR_delayed 3337 }; 3338 3339 bool SetMemberAccessSpecifier(NamedDecl *MemberDecl, 3340 NamedDecl *PrevMemberDecl, 3341 AccessSpecifier LexicalAS); 3342 3343 AccessResult CheckUnresolvedMemberAccess(UnresolvedMemberExpr *E, 3344 DeclAccessPair FoundDecl); 3345 AccessResult CheckUnresolvedLookupAccess(UnresolvedLookupExpr *E, 3346 DeclAccessPair FoundDecl); 3347 AccessResult CheckAllocationAccess(SourceLocation OperatorLoc, 3348 SourceRange PlacementRange, 3349 CXXRecordDecl *NamingClass, 3350 DeclAccessPair FoundDecl); 3351 AccessResult CheckConstructorAccess(SourceLocation Loc, 3352 CXXConstructorDecl *D, 3353 const InitializedEntity &Entity, 3354 AccessSpecifier Access, 3355 bool IsCopyBindingRefToTemp = false); 3356 AccessResult CheckDestructorAccess(SourceLocation Loc, 3357 CXXDestructorDecl *Dtor, 3358 const PartialDiagnostic &PDiag); 3359 AccessResult CheckDirectMemberAccess(SourceLocation Loc, 3360 NamedDecl *D, 3361 const PartialDiagnostic &PDiag); 3362 AccessResult CheckMemberOperatorAccess(SourceLocation Loc, 3363 Expr *ObjectExpr, 3364 Expr *ArgExpr, 3365 DeclAccessPair FoundDecl); 3366 AccessResult CheckAddressOfMemberAccess(Expr *OvlExpr, 3367 DeclAccessPair FoundDecl); 3368 AccessResult CheckBaseClassAccess(SourceLocation AccessLoc, 3369 QualType Base, QualType Derived, 3370 const CXXBasePath &Path, 3371 unsigned DiagID, 3372 bool ForceCheck = false, 3373 bool ForceUnprivileged = false); 3374 void CheckLookupAccess(const LookupResult &R); 3375 3376 void HandleDependentAccessCheck(const DependentDiagnostic &DD, 3377 const MultiLevelTemplateArgumentList &TemplateArgs); 3378 void PerformDependentDiagnostics(const DeclContext *Pattern, 3379 const MultiLevelTemplateArgumentList &TemplateArgs); 3380 3381 void HandleDelayedAccessCheck(sema::DelayedDiagnostic &DD, Decl *Ctx); 3382 3383 /// A flag to suppress access checking. 3384 bool SuppressAccessChecking; 3385 3386 /// \brief When true, access checking violations are treated as SFINAE 3387 /// failures rather than hard errors. 3388 bool AccessCheckingSFINAE; 3389 3390 void ActOnStartSuppressingAccessChecks(); 3391 void ActOnStopSuppressingAccessChecks(); 3392 3393 enum AbstractDiagSelID { 3394 AbstractNone = -1, 3395 AbstractReturnType, 3396 AbstractParamType, 3397 AbstractVariableType, 3398 AbstractFieldType, 3399 AbstractArrayType 3400 }; 3401 3402 bool RequireNonAbstractType(SourceLocation Loc, QualType T, 3403 const PartialDiagnostic &PD); 3404 void DiagnoseAbstractType(const CXXRecordDecl *RD); 3405 3406 bool RequireNonAbstractType(SourceLocation Loc, QualType T, unsigned DiagID, 3407 AbstractDiagSelID SelID = AbstractNone); 3408 3409 //===--------------------------------------------------------------------===// 3410 // C++ Overloaded Operators [C++ 13.5] 3411 // 3412 3413 bool CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl); 3414 3415 bool CheckLiteralOperatorDeclaration(FunctionDecl *FnDecl); 3416 3417 //===--------------------------------------------------------------------===// 3418 // C++ Templates [C++ 14] 3419 // 3420 void FilterAcceptableTemplateNames(LookupResult &R); 3421 bool hasAnyAcceptableTemplateNames(LookupResult &R); 3422 3423 void LookupTemplateName(LookupResult &R, Scope *S, CXXScopeSpec &SS, 3424 QualType ObjectType, bool EnteringContext, 3425 bool &MemberOfUnknownSpecialization); 3426 3427 TemplateNameKind isTemplateName(Scope *S, 3428 CXXScopeSpec &SS, 3429 bool hasTemplateKeyword, 3430 UnqualifiedId &Name, 3431 ParsedType ObjectType, 3432 bool EnteringContext, 3433 TemplateTy &Template, 3434 bool &MemberOfUnknownSpecialization); 3435 3436 bool DiagnoseUnknownTemplateName(const IdentifierInfo &II, 3437 SourceLocation IILoc, 3438 Scope *S, 3439 const CXXScopeSpec *SS, 3440 TemplateTy &SuggestedTemplate, 3441 TemplateNameKind &SuggestedKind); 3442 3443 bool DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl); 3444 TemplateDecl *AdjustDeclIfTemplate(Decl *&Decl); 3445 3446 Decl *ActOnTypeParameter(Scope *S, bool Typename, bool Ellipsis, 3447 SourceLocation EllipsisLoc, 3448 SourceLocation KeyLoc, 3449 IdentifierInfo *ParamName, 3450 SourceLocation ParamNameLoc, 3451 unsigned Depth, unsigned Position, 3452 SourceLocation EqualLoc, 3453 ParsedType DefaultArg); 3454 3455 QualType CheckNonTypeTemplateParameterType(QualType T, SourceLocation Loc); 3456 Decl *ActOnNonTypeTemplateParameter(Scope *S, Declarator &D, 3457 unsigned Depth, 3458 unsigned Position, 3459 SourceLocation EqualLoc, 3460 Expr *DefaultArg); 3461 Decl *ActOnTemplateTemplateParameter(Scope *S, 3462 SourceLocation TmpLoc, 3463 TemplateParamsTy *Params, 3464 SourceLocation EllipsisLoc, 3465 IdentifierInfo *ParamName, 3466 SourceLocation ParamNameLoc, 3467 unsigned Depth, 3468 unsigned Position, 3469 SourceLocation EqualLoc, 3470 ParsedTemplateArgument DefaultArg); 3471 3472 TemplateParamsTy * 3473 ActOnTemplateParameterList(unsigned Depth, 3474 SourceLocation ExportLoc, 3475 SourceLocation TemplateLoc, 3476 SourceLocation LAngleLoc, 3477 Decl **Params, unsigned NumParams, 3478 SourceLocation RAngleLoc); 3479 3480 /// \brief The context in which we are checking a template parameter 3481 /// list. 3482 enum TemplateParamListContext { 3483 TPC_ClassTemplate, 3484 TPC_FunctionTemplate, 3485 TPC_ClassTemplateMember, 3486 TPC_FriendFunctionTemplate, 3487 TPC_FriendFunctionTemplateDefinition, 3488 TPC_TypeAliasTemplate 3489 }; 3490 3491 bool CheckTemplateParameterList(TemplateParameterList *NewParams, 3492 TemplateParameterList *OldParams, 3493 TemplateParamListContext TPC); 3494 TemplateParameterList * 3495 MatchTemplateParametersToScopeSpecifier(SourceLocation DeclStartLoc, 3496 SourceLocation DeclLoc, 3497 const CXXScopeSpec &SS, 3498 TemplateParameterList **ParamLists, 3499 unsigned NumParamLists, 3500 bool IsFriend, 3501 bool &IsExplicitSpecialization, 3502 bool &Invalid); 3503 3504 DeclResult CheckClassTemplate(Scope *S, unsigned TagSpec, TagUseKind TUK, 3505 SourceLocation KWLoc, CXXScopeSpec &SS, 3506 IdentifierInfo *Name, SourceLocation NameLoc, 3507 AttributeList *Attr, 3508 TemplateParameterList *TemplateParams, 3509 AccessSpecifier AS, 3510 unsigned NumOuterTemplateParamLists, 3511 TemplateParameterList **OuterTemplateParamLists); 3512 3513 void translateTemplateArguments(const ASTTemplateArgsPtr &In, 3514 TemplateArgumentListInfo &Out); 3515 3516 void NoteAllFoundTemplates(TemplateName Name); 3517 3518 QualType CheckTemplateIdType(TemplateName Template, 3519 SourceLocation TemplateLoc, 3520 TemplateArgumentListInfo &TemplateArgs); 3521 3522 TypeResult 3523 ActOnTemplateIdType(CXXScopeSpec &SS, 3524 TemplateTy Template, SourceLocation TemplateLoc, 3525 SourceLocation LAngleLoc, 3526 ASTTemplateArgsPtr TemplateArgs, 3527 SourceLocation RAngleLoc); 3528 3529 /// \brief Parsed an elaborated-type-specifier that refers to a template-id, 3530 /// such as \c class T::template apply<U>. 3531 /// 3532 /// \param TUK 3533 TypeResult ActOnTagTemplateIdType(TagUseKind TUK, 3534 TypeSpecifierType TagSpec, 3535 SourceLocation TagLoc, 3536 CXXScopeSpec &SS, 3537 TemplateTy TemplateD, 3538 SourceLocation TemplateLoc, 3539 SourceLocation LAngleLoc, 3540 ASTTemplateArgsPtr TemplateArgsIn, 3541 SourceLocation RAngleLoc); 3542 3543 3544 ExprResult BuildTemplateIdExpr(const CXXScopeSpec &SS, 3545 LookupResult &R, 3546 bool RequiresADL, 3547 const TemplateArgumentListInfo &TemplateArgs); 3548 ExprResult BuildQualifiedTemplateIdExpr(CXXScopeSpec &SS, 3549 const DeclarationNameInfo &NameInfo, 3550 const TemplateArgumentListInfo &TemplateArgs); 3551 3552 TemplateNameKind ActOnDependentTemplateName(Scope *S, 3553 SourceLocation TemplateKWLoc, 3554 CXXScopeSpec &SS, 3555 UnqualifiedId &Name, 3556 ParsedType ObjectType, 3557 bool EnteringContext, 3558 TemplateTy &Template); 3559 3560 DeclResult 3561 ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, TagUseKind TUK, 3562 SourceLocation KWLoc, 3563 CXXScopeSpec &SS, 3564 TemplateTy Template, 3565 SourceLocation TemplateNameLoc, 3566 SourceLocation LAngleLoc, 3567 ASTTemplateArgsPtr TemplateArgs, 3568 SourceLocation RAngleLoc, 3569 AttributeList *Attr, 3570 MultiTemplateParamsArg TemplateParameterLists); 3571 3572 Decl *ActOnTemplateDeclarator(Scope *S, 3573 MultiTemplateParamsArg TemplateParameterLists, 3574 Declarator &D); 3575 3576 Decl *ActOnStartOfFunctionTemplateDef(Scope *FnBodyScope, 3577 MultiTemplateParamsArg TemplateParameterLists, 3578 Declarator &D); 3579 3580 bool 3581 CheckSpecializationInstantiationRedecl(SourceLocation NewLoc, 3582 TemplateSpecializationKind NewTSK, 3583 NamedDecl *PrevDecl, 3584 TemplateSpecializationKind PrevTSK, 3585 SourceLocation PrevPtOfInstantiation, 3586 bool &SuppressNew); 3587 3588 bool CheckDependentFunctionTemplateSpecialization(FunctionDecl *FD, 3589 const TemplateArgumentListInfo &ExplicitTemplateArgs, 3590 LookupResult &Previous); 3591 3592 bool CheckFunctionTemplateSpecialization(FunctionDecl *FD, 3593 TemplateArgumentListInfo *ExplicitTemplateArgs, 3594 LookupResult &Previous); 3595 bool CheckMemberSpecialization(NamedDecl *Member, LookupResult &Previous); 3596 3597 DeclResult 3598 ActOnExplicitInstantiation(Scope *S, 3599 SourceLocation ExternLoc, 3600 SourceLocation TemplateLoc, 3601 unsigned TagSpec, 3602 SourceLocation KWLoc, 3603 const CXXScopeSpec &SS, 3604 TemplateTy Template, 3605 SourceLocation TemplateNameLoc, 3606 SourceLocation LAngleLoc, 3607 ASTTemplateArgsPtr TemplateArgs, 3608 SourceLocation RAngleLoc, 3609 AttributeList *Attr); 3610 3611 DeclResult 3612 ActOnExplicitInstantiation(Scope *S, 3613 SourceLocation ExternLoc, 3614 SourceLocation TemplateLoc, 3615 unsigned TagSpec, 3616 SourceLocation KWLoc, 3617 CXXScopeSpec &SS, 3618 IdentifierInfo *Name, 3619 SourceLocation NameLoc, 3620 AttributeList *Attr); 3621 3622 DeclResult ActOnExplicitInstantiation(Scope *S, 3623 SourceLocation ExternLoc, 3624 SourceLocation TemplateLoc, 3625 Declarator &D); 3626 3627 TemplateArgumentLoc 3628 SubstDefaultTemplateArgumentIfAvailable(TemplateDecl *Template, 3629 SourceLocation TemplateLoc, 3630 SourceLocation RAngleLoc, 3631 Decl *Param, 3632 llvm::SmallVectorImpl<TemplateArgument> &Converted); 3633 3634 /// \brief Specifies the context in which a particular template 3635 /// argument is being checked. 3636 enum CheckTemplateArgumentKind { 3637 /// \brief The template argument was specified in the code or was 3638 /// instantiated with some deduced template arguments. 3639 CTAK_Specified, 3640 3641 /// \brief The template argument was deduced via template argument 3642 /// deduction. 3643 CTAK_Deduced, 3644 3645 /// \brief The template argument was deduced from an array bound 3646 /// via template argument deduction. 3647 CTAK_DeducedFromArrayBound 3648 }; 3649 3650 bool CheckTemplateArgument(NamedDecl *Param, 3651 const TemplateArgumentLoc &Arg, 3652 NamedDecl *Template, 3653 SourceLocation TemplateLoc, 3654 SourceLocation RAngleLoc, 3655 unsigned ArgumentPackIndex, 3656 llvm::SmallVectorImpl<TemplateArgument> &Converted, 3657 CheckTemplateArgumentKind CTAK = CTAK_Specified); 3658 3659 /// \brief Check that the given template arguments can be be provided to 3660 /// the given template, converting the arguments along the way. 3661 /// 3662 /// \param Template The template to which the template arguments are being 3663 /// provided. 3664 /// 3665 /// \param TemplateLoc The location of the template name in the source. 3666 /// 3667 /// \param TemplateArgs The list of template arguments. If the template is 3668 /// a template template parameter, this function may extend the set of 3669 /// template arguments to also include substituted, defaulted template 3670 /// arguments. 3671 /// 3672 /// \param PartialTemplateArgs True if the list of template arguments is 3673 /// intentionally partial, e.g., because we're checking just the initial 3674 /// set of template arguments. 3675 /// 3676 /// \param Converted Will receive the converted, canonicalized template 3677 /// arguments. 3678 /// 3679 /// \returns True if an error occurred, false otherwise. 3680 bool CheckTemplateArgumentList(TemplateDecl *Template, 3681 SourceLocation TemplateLoc, 3682 TemplateArgumentListInfo &TemplateArgs, 3683 bool PartialTemplateArgs, 3684 llvm::SmallVectorImpl<TemplateArgument> &Converted); 3685 3686 bool CheckTemplateTypeArgument(TemplateTypeParmDecl *Param, 3687 const TemplateArgumentLoc &Arg, 3688 llvm::SmallVectorImpl<TemplateArgument> &Converted); 3689 3690 bool CheckTemplateArgument(TemplateTypeParmDecl *Param, 3691 TypeSourceInfo *Arg); 3692 bool CheckTemplateArgumentPointerToMember(Expr *Arg, 3693 TemplateArgument &Converted); 3694 ExprResult CheckTemplateArgument(NonTypeTemplateParmDecl *Param, 3695 QualType InstantiatedParamType, Expr *Arg, 3696 TemplateArgument &Converted, 3697 CheckTemplateArgumentKind CTAK = CTAK_Specified); 3698 bool CheckTemplateArgument(TemplateTemplateParmDecl *Param, 3699 const TemplateArgumentLoc &Arg); 3700 3701 ExprResult 3702 BuildExpressionFromDeclTemplateArgument(const TemplateArgument &Arg, 3703 QualType ParamType, 3704 SourceLocation Loc); 3705 ExprResult 3706 BuildExpressionFromIntegralTemplateArgument(const TemplateArgument &Arg, 3707 SourceLocation Loc); 3708 3709 /// \brief Enumeration describing how template parameter lists are compared 3710 /// for equality. 3711 enum TemplateParameterListEqualKind { 3712 /// \brief We are matching the template parameter lists of two templates 3713 /// that might be redeclarations. 3714 /// 3715 /// \code 3716 /// template<typename T> struct X; 3717 /// template<typename T> struct X; 3718 /// \endcode 3719 TPL_TemplateMatch, 3720 3721 /// \brief We are matching the template parameter lists of two template 3722 /// template parameters as part of matching the template parameter lists 3723 /// of two templates that might be redeclarations. 3724 /// 3725 /// \code 3726 /// template<template<int I> class TT> struct X; 3727 /// template<template<int Value> class Other> struct X; 3728 /// \endcode 3729 TPL_TemplateTemplateParmMatch, 3730 3731 /// \brief We are matching the template parameter lists of a template 3732 /// template argument against the template parameter lists of a template 3733 /// template parameter. 3734 /// 3735 /// \code 3736 /// template<template<int Value> class Metafun> struct X; 3737 /// template<int Value> struct integer_c; 3738 /// X<integer_c> xic; 3739 /// \endcode 3740 TPL_TemplateTemplateArgumentMatch 3741 }; 3742 3743 bool TemplateParameterListsAreEqual(TemplateParameterList *New, 3744 TemplateParameterList *Old, 3745 bool Complain, 3746 TemplateParameterListEqualKind Kind, 3747 SourceLocation TemplateArgLoc 3748 = SourceLocation()); 3749 3750 bool CheckTemplateDeclScope(Scope *S, TemplateParameterList *TemplateParams); 3751 3752 /// \brief Called when the parser has parsed a C++ typename 3753 /// specifier, e.g., "typename T::type". 3754 /// 3755 /// \param S The scope in which this typename type occurs. 3756 /// \param TypenameLoc the location of the 'typename' keyword 3757 /// \param SS the nested-name-specifier following the typename (e.g., 'T::'). 3758 /// \param II the identifier we're retrieving (e.g., 'type' in the example). 3759 /// \param IdLoc the location of the identifier. 3760 TypeResult 3761 ActOnTypenameType(Scope *S, SourceLocation TypenameLoc, 3762 const CXXScopeSpec &SS, const IdentifierInfo &II, 3763 SourceLocation IdLoc); 3764 3765 /// \brief Called when the parser has parsed a C++ typename 3766 /// specifier that ends in a template-id, e.g., 3767 /// "typename MetaFun::template apply<T1, T2>". 3768 /// 3769 /// \param S The scope in which this typename type occurs. 3770 /// \param TypenameLoc the location of the 'typename' keyword 3771 /// \param SS the nested-name-specifier following the typename (e.g., 'T::'). 3772 /// \param TemplateLoc the location of the 'template' keyword, if any. 3773 /// \param TemplateName The template name. 3774 /// \param TemplateNameLoc The location of the template name. 3775 /// \param LAngleLoc The location of the opening angle bracket ('<'). 3776 /// \param TemplateArgs The template arguments. 3777 /// \param RAngleLoc The location of the closing angle bracket ('>'). 3778 TypeResult 3779 ActOnTypenameType(Scope *S, SourceLocation TypenameLoc, 3780 const CXXScopeSpec &SS, 3781 SourceLocation TemplateLoc, 3782 TemplateTy Template, 3783 SourceLocation TemplateNameLoc, 3784 SourceLocation LAngleLoc, 3785 ASTTemplateArgsPtr TemplateArgs, 3786 SourceLocation RAngleLoc); 3787 3788 QualType CheckTypenameType(ElaboratedTypeKeyword Keyword, 3789 SourceLocation KeywordLoc, 3790 NestedNameSpecifierLoc QualifierLoc, 3791 const IdentifierInfo &II, 3792 SourceLocation IILoc); 3793 3794 TypeSourceInfo *RebuildTypeInCurrentInstantiation(TypeSourceInfo *T, 3795 SourceLocation Loc, 3796 DeclarationName Name); 3797 bool RebuildNestedNameSpecifierInCurrentInstantiation(CXXScopeSpec &SS); 3798 3799 ExprResult RebuildExprInCurrentInstantiation(Expr *E); 3800 3801 std::string 3802 getTemplateArgumentBindingsText(const TemplateParameterList *Params, 3803 const TemplateArgumentList &Args); 3804 3805 std::string 3806 getTemplateArgumentBindingsText(const TemplateParameterList *Params, 3807 const TemplateArgument *Args, 3808 unsigned NumArgs); 3809 3810 //===--------------------------------------------------------------------===// 3811 // C++ Variadic Templates (C++0x [temp.variadic]) 3812 //===--------------------------------------------------------------------===// 3813 3814 /// \brief The context in which an unexpanded parameter pack is 3815 /// being diagnosed. 3816 /// 3817 /// Note that the values of this enumeration line up with the first 3818 /// argument to the \c err_unexpanded_parameter_pack diagnostic. 3819 enum UnexpandedParameterPackContext { 3820 /// \brief An arbitrary expression. 3821 UPPC_Expression = 0, 3822 3823 /// \brief The base type of a class type. 3824 UPPC_BaseType, 3825 3826 /// \brief The type of an arbitrary declaration. 3827 UPPC_DeclarationType, 3828 3829 /// \brief The type of a data member. 3830 UPPC_DataMemberType, 3831 3832 /// \brief The size of a bit-field. 3833 UPPC_BitFieldWidth, 3834 3835 /// \brief The expression in a static assertion. 3836 UPPC_StaticAssertExpression, 3837 3838 /// \brief The fixed underlying type of an enumeration. 3839 UPPC_FixedUnderlyingType, 3840 3841 /// \brief The enumerator value. 3842 UPPC_EnumeratorValue, 3843 3844 /// \brief A using declaration. 3845 UPPC_UsingDeclaration, 3846 3847 /// \brief A friend declaration. 3848 UPPC_FriendDeclaration, 3849 3850 /// \brief A declaration qualifier. 3851 UPPC_DeclarationQualifier, 3852 3853 /// \brief An initializer. 3854 UPPC_Initializer, 3855 3856 /// \brief A default argument. 3857 UPPC_DefaultArgument, 3858 3859 /// \brief The type of a non-type template parameter. 3860 UPPC_NonTypeTemplateParameterType, 3861 3862 /// \brief The type of an exception. 3863 UPPC_ExceptionType, 3864 3865 /// \brief Partial specialization. 3866 UPPC_PartialSpecialization 3867 }; 3868 3869 /// \brief If the given type contains an unexpanded parameter pack, 3870 /// diagnose the error. 3871 /// 3872 /// \param Loc The source location where a diagnostc should be emitted. 3873 /// 3874 /// \param T The type that is being checked for unexpanded parameter 3875 /// packs. 3876 /// 3877 /// \returns true if an error occurred, false otherwise. 3878 bool DiagnoseUnexpandedParameterPack(SourceLocation Loc, TypeSourceInfo *T, 3879 UnexpandedParameterPackContext UPPC); 3880 3881 /// \brief If the given expression contains an unexpanded parameter 3882 /// pack, diagnose the error. 3883 /// 3884 /// \param E The expression that is being checked for unexpanded 3885 /// parameter packs. 3886 /// 3887 /// \returns true if an error occurred, false otherwise. 3888 bool DiagnoseUnexpandedParameterPack(Expr *E, 3889 UnexpandedParameterPackContext UPPC = UPPC_Expression); 3890 3891 /// \brief If the given nested-name-specifier contains an unexpanded 3892 /// parameter pack, diagnose the error. 3893 /// 3894 /// \param SS The nested-name-specifier that is being checked for 3895 /// unexpanded parameter packs. 3896 /// 3897 /// \returns true if an error occurred, false otherwise. 3898 bool DiagnoseUnexpandedParameterPack(const CXXScopeSpec &SS, 3899 UnexpandedParameterPackContext UPPC); 3900 3901 /// \brief If the given name contains an unexpanded parameter pack, 3902 /// diagnose the error. 3903 /// 3904 /// \param NameInfo The name (with source location information) that 3905 /// is being checked for unexpanded parameter packs. 3906 /// 3907 /// \returns true if an error occurred, false otherwise. 3908 bool DiagnoseUnexpandedParameterPack(const DeclarationNameInfo &NameInfo, 3909 UnexpandedParameterPackContext UPPC); 3910 3911 /// \brief If the given template name contains an unexpanded parameter pack, 3912 /// diagnose the error. 3913 /// 3914 /// \param Loc The location of the template name. 3915 /// 3916 /// \param Template The template name that is being checked for unexpanded 3917 /// parameter packs. 3918 /// 3919 /// \returns true if an error occurred, false otherwise. 3920 bool DiagnoseUnexpandedParameterPack(SourceLocation Loc, 3921 TemplateName Template, 3922 UnexpandedParameterPackContext UPPC); 3923 3924 /// \brief If the given template argument contains an unexpanded parameter 3925 /// pack, diagnose the error. 3926 /// 3927 /// \param Arg The template argument that is being checked for unexpanded 3928 /// parameter packs. 3929 /// 3930 /// \returns true if an error occurred, false otherwise. 3931 bool DiagnoseUnexpandedParameterPack(TemplateArgumentLoc Arg, 3932 UnexpandedParameterPackContext UPPC); 3933 3934 /// \brief Collect the set of unexpanded parameter packs within the given 3935 /// template argument. 3936 /// 3937 /// \param Arg The template argument that will be traversed to find 3938 /// unexpanded parameter packs. 3939 void collectUnexpandedParameterPacks(TemplateArgument Arg, 3940 llvm::SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); 3941 3942 /// \brief Collect the set of unexpanded parameter packs within the given 3943 /// template argument. 3944 /// 3945 /// \param Arg The template argument that will be traversed to find 3946 /// unexpanded parameter packs. 3947 void collectUnexpandedParameterPacks(TemplateArgumentLoc Arg, 3948 llvm::SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); 3949 3950 /// \brief Collect the set of unexpanded parameter packs within the given 3951 /// type. 3952 /// 3953 /// \param T The type that will be traversed to find 3954 /// unexpanded parameter packs. 3955 void collectUnexpandedParameterPacks(QualType T, 3956 llvm::SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); 3957 3958 /// \brief Collect the set of unexpanded parameter packs within the given 3959 /// type. 3960 /// 3961 /// \param TL The type that will be traversed to find 3962 /// unexpanded parameter packs. 3963 void collectUnexpandedParameterPacks(TypeLoc TL, 3964 llvm::SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); 3965 3966 /// \brief Invoked when parsing a template argument followed by an 3967 /// ellipsis, which creates a pack expansion. 3968 /// 3969 /// \param Arg The template argument preceding the ellipsis, which 3970 /// may already be invalid. 3971 /// 3972 /// \param EllipsisLoc The location of the ellipsis. 3973 ParsedTemplateArgument ActOnPackExpansion(const ParsedTemplateArgument &Arg, 3974 SourceLocation EllipsisLoc); 3975 3976 /// \brief Invoked when parsing a type followed by an ellipsis, which 3977 /// creates a pack expansion. 3978 /// 3979 /// \param Type The type preceding the ellipsis, which will become 3980 /// the pattern of the pack expansion. 3981 /// 3982 /// \param EllipsisLoc The location of the ellipsis. 3983 TypeResult ActOnPackExpansion(ParsedType Type, SourceLocation EllipsisLoc); 3984 3985 /// \brief Construct a pack expansion type from the pattern of the pack 3986 /// expansion. 3987 TypeSourceInfo *CheckPackExpansion(TypeSourceInfo *Pattern, 3988 SourceLocation EllipsisLoc, 3989 llvm::Optional<unsigned> NumExpansions); 3990 3991 /// \brief Construct a pack expansion type from the pattern of the pack 3992 /// expansion. 3993 QualType CheckPackExpansion(QualType Pattern, 3994 SourceRange PatternRange, 3995 SourceLocation EllipsisLoc, 3996 llvm::Optional<unsigned> NumExpansions); 3997 3998 /// \brief Invoked when parsing an expression followed by an ellipsis, which 3999 /// creates a pack expansion. 4000 /// 4001 /// \param Pattern The expression preceding the ellipsis, which will become 4002 /// the pattern of the pack expansion. 4003 /// 4004 /// \param EllipsisLoc The location of the ellipsis. 4005 ExprResult ActOnPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc); 4006 4007 /// \brief Invoked when parsing an expression followed by an ellipsis, which 4008 /// creates a pack expansion. 4009 /// 4010 /// \param Pattern The expression preceding the ellipsis, which will become 4011 /// the pattern of the pack expansion. 4012 /// 4013 /// \param EllipsisLoc The location of the ellipsis. 4014 ExprResult CheckPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc, 4015 llvm::Optional<unsigned> NumExpansions); 4016 4017 /// \brief Determine whether we could expand a pack expansion with the 4018 /// given set of parameter packs into separate arguments by repeatedly 4019 /// transforming the pattern. 4020 /// 4021 /// \param EllipsisLoc The location of the ellipsis that identifies the 4022 /// pack expansion. 4023 /// 4024 /// \param PatternRange The source range that covers the entire pattern of 4025 /// the pack expansion. 4026 /// 4027 /// \param Unexpanded The set of unexpanded parameter packs within the 4028 /// pattern. 4029 /// 4030 /// \param NumUnexpanded The number of unexpanded parameter packs in 4031 /// \p Unexpanded. 4032 /// 4033 /// \param ShouldExpand Will be set to \c true if the transformer should 4034 /// expand the corresponding pack expansions into separate arguments. When 4035 /// set, \c NumExpansions must also be set. 4036 /// 4037 /// \param RetainExpansion Whether the caller should add an unexpanded 4038 /// pack expansion after all of the expanded arguments. This is used 4039 /// when extending explicitly-specified template argument packs per 4040 /// C++0x [temp.arg.explicit]p9. 4041 /// 4042 /// \param NumExpansions The number of separate arguments that will be in 4043 /// the expanded form of the corresponding pack expansion. This is both an 4044 /// input and an output parameter, which can be set by the caller if the 4045 /// number of expansions is known a priori (e.g., due to a prior substitution) 4046 /// and will be set by the callee when the number of expansions is known. 4047 /// The callee must set this value when \c ShouldExpand is \c true; it may 4048 /// set this value in other cases. 4049 /// 4050 /// \returns true if an error occurred (e.g., because the parameter packs 4051 /// are to be instantiated with arguments of different lengths), false 4052 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions) 4053 /// must be set. 4054 bool CheckParameterPacksForExpansion(SourceLocation EllipsisLoc, 4055 SourceRange PatternRange, 4056 const UnexpandedParameterPack *Unexpanded, 4057 unsigned NumUnexpanded, 4058 const MultiLevelTemplateArgumentList &TemplateArgs, 4059 bool &ShouldExpand, 4060 bool &RetainExpansion, 4061 llvm::Optional<unsigned> &NumExpansions); 4062 4063 /// \brief Determine the number of arguments in the given pack expansion 4064 /// type. 4065 /// 4066 /// This routine already assumes that the pack expansion type can be 4067 /// expanded and that the number of arguments in the expansion is 4068 /// consistent across all of the unexpanded parameter packs in its pattern. 4069 unsigned getNumArgumentsInExpansion(QualType T, 4070 const MultiLevelTemplateArgumentList &TemplateArgs); 4071 4072 /// \brief Determine whether the given declarator contains any unexpanded 4073 /// parameter packs. 4074 /// 4075 /// This routine is used by the parser to disambiguate function declarators 4076 /// with an ellipsis prior to the ')', e.g., 4077 /// 4078 /// \code 4079 /// void f(T...); 4080 /// \endcode 4081 /// 4082 /// To determine whether we have an (unnamed) function parameter pack or 4083 /// a variadic function. 4084 /// 4085 /// \returns true if the declarator contains any unexpanded parameter packs, 4086 /// false otherwise. 4087 bool containsUnexpandedParameterPacks(Declarator &D); 4088 4089 //===--------------------------------------------------------------------===// 4090 // C++ Template Argument Deduction (C++ [temp.deduct]) 4091 //===--------------------------------------------------------------------===// 4092 4093 /// \brief Describes the result of template argument deduction. 4094 /// 4095 /// The TemplateDeductionResult enumeration describes the result of 4096 /// template argument deduction, as returned from 4097 /// DeduceTemplateArguments(). The separate TemplateDeductionInfo 4098 /// structure provides additional information about the results of 4099 /// template argument deduction, e.g., the deduced template argument 4100 /// list (if successful) or the specific template parameters or 4101 /// deduced arguments that were involved in the failure. 4102 enum TemplateDeductionResult { 4103 /// \brief Template argument deduction was successful. 4104 TDK_Success = 0, 4105 /// \brief Template argument deduction exceeded the maximum template 4106 /// instantiation depth (which has already been diagnosed). 4107 TDK_InstantiationDepth, 4108 /// \brief Template argument deduction did not deduce a value 4109 /// for every template parameter. 4110 TDK_Incomplete, 4111 /// \brief Template argument deduction produced inconsistent 4112 /// deduced values for the given template parameter. 4113 TDK_Inconsistent, 4114 /// \brief Template argument deduction failed due to inconsistent 4115 /// cv-qualifiers on a template parameter type that would 4116 /// otherwise be deduced, e.g., we tried to deduce T in "const T" 4117 /// but were given a non-const "X". 4118 TDK_Underqualified, 4119 /// \brief Substitution of the deduced template argument values 4120 /// resulted in an error. 4121 TDK_SubstitutionFailure, 4122 /// \brief Substitution of the deduced template argument values 4123 /// into a non-deduced context produced a type or value that 4124 /// produces a type that does not match the original template 4125 /// arguments provided. 4126 TDK_NonDeducedMismatch, 4127 /// \brief When performing template argument deduction for a function 4128 /// template, there were too many call arguments. 4129 TDK_TooManyArguments, 4130 /// \brief When performing template argument deduction for a function 4131 /// template, there were too few call arguments. 4132 TDK_TooFewArguments, 4133 /// \brief The explicitly-specified template arguments were not valid 4134 /// template arguments for the given template. 4135 TDK_InvalidExplicitArguments, 4136 /// \brief The arguments included an overloaded function name that could 4137 /// not be resolved to a suitable function. 4138 TDK_FailedOverloadResolution 4139 }; 4140 4141 TemplateDeductionResult 4142 DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial, 4143 const TemplateArgumentList &TemplateArgs, 4144 sema::TemplateDeductionInfo &Info); 4145 4146 TemplateDeductionResult 4147 SubstituteExplicitTemplateArguments(FunctionTemplateDecl *FunctionTemplate, 4148 TemplateArgumentListInfo &ExplicitTemplateArgs, 4149 llvm::SmallVectorImpl<DeducedTemplateArgument> &Deduced, 4150 llvm::SmallVectorImpl<QualType> &ParamTypes, 4151 QualType *FunctionType, 4152 sema::TemplateDeductionInfo &Info); 4153 4154 TemplateDeductionResult 4155 FinishTemplateArgumentDeduction(FunctionTemplateDecl *FunctionTemplate, 4156 llvm::SmallVectorImpl<DeducedTemplateArgument> &Deduced, 4157 unsigned NumExplicitlySpecified, 4158 FunctionDecl *&Specialization, 4159 sema::TemplateDeductionInfo &Info); 4160 4161 TemplateDeductionResult 4162 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, 4163 TemplateArgumentListInfo *ExplicitTemplateArgs, 4164 Expr **Args, unsigned NumArgs, 4165 FunctionDecl *&Specialization, 4166 sema::TemplateDeductionInfo &Info); 4167 4168 TemplateDeductionResult 4169 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, 4170 TemplateArgumentListInfo *ExplicitTemplateArgs, 4171 QualType ArgFunctionType, 4172 FunctionDecl *&Specialization, 4173 sema::TemplateDeductionInfo &Info); 4174 4175 TemplateDeductionResult 4176 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, 4177 QualType ToType, 4178 CXXConversionDecl *&Specialization, 4179 sema::TemplateDeductionInfo &Info); 4180 4181 TemplateDeductionResult 4182 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, 4183 TemplateArgumentListInfo *ExplicitTemplateArgs, 4184 FunctionDecl *&Specialization, 4185 sema::TemplateDeductionInfo &Info); 4186 4187 bool DeduceAutoType(TypeSourceInfo *AutoType, Expr *Initializer, 4188 TypeSourceInfo *&Result); 4189 4190 FunctionTemplateDecl *getMoreSpecializedTemplate(FunctionTemplateDecl *FT1, 4191 FunctionTemplateDecl *FT2, 4192 SourceLocation Loc, 4193 TemplatePartialOrderingContext TPOC, 4194 unsigned NumCallArguments); 4195 UnresolvedSetIterator getMostSpecialized(UnresolvedSetIterator SBegin, 4196 UnresolvedSetIterator SEnd, 4197 TemplatePartialOrderingContext TPOC, 4198 unsigned NumCallArguments, 4199 SourceLocation Loc, 4200 const PartialDiagnostic &NoneDiag, 4201 const PartialDiagnostic &AmbigDiag, 4202 const PartialDiagnostic &CandidateDiag, 4203 bool Complain = true); 4204 4205 ClassTemplatePartialSpecializationDecl * 4206 getMoreSpecializedPartialSpecialization( 4207 ClassTemplatePartialSpecializationDecl *PS1, 4208 ClassTemplatePartialSpecializationDecl *PS2, 4209 SourceLocation Loc); 4210 4211 void MarkUsedTemplateParameters(const TemplateArgumentList &TemplateArgs, 4212 bool OnlyDeduced, 4213 unsigned Depth, 4214 llvm::SmallVectorImpl<bool> &Used); 4215 void MarkDeducedTemplateParameters(FunctionTemplateDecl *FunctionTemplate, 4216 llvm::SmallVectorImpl<bool> &Deduced); 4217 4218 //===--------------------------------------------------------------------===// 4219 // C++ Template Instantiation 4220 // 4221 4222 MultiLevelTemplateArgumentList getTemplateInstantiationArgs(NamedDecl *D, 4223 const TemplateArgumentList *Innermost = 0, 4224 bool RelativeToPrimary = false, 4225 const FunctionDecl *Pattern = 0); 4226 4227 /// \brief A template instantiation that is currently in progress. 4228 struct ActiveTemplateInstantiation { 4229 /// \brief The kind of template instantiation we are performing 4230 enum InstantiationKind { 4231 /// We are instantiating a template declaration. The entity is 4232 /// the declaration we're instantiating (e.g., a CXXRecordDecl). 4233 TemplateInstantiation, 4234 4235 /// We are instantiating a default argument for a template 4236 /// parameter. The Entity is the template, and 4237 /// TemplateArgs/NumTemplateArguments provides the template 4238 /// arguments as specified. 4239 /// FIXME: Use a TemplateArgumentList 4240 DefaultTemplateArgumentInstantiation, 4241 4242 /// We are instantiating a default argument for a function. 4243 /// The Entity is the ParmVarDecl, and TemplateArgs/NumTemplateArgs 4244 /// provides the template arguments as specified. 4245 DefaultFunctionArgumentInstantiation, 4246 4247 /// We are substituting explicit template arguments provided for 4248 /// a function template. The entity is a FunctionTemplateDecl. 4249 ExplicitTemplateArgumentSubstitution, 4250 4251 /// We are substituting template argument determined as part of 4252 /// template argument deduction for either a class template 4253 /// partial specialization or a function template. The 4254 /// Entity is either a ClassTemplatePartialSpecializationDecl or 4255 /// a FunctionTemplateDecl. 4256 DeducedTemplateArgumentSubstitution, 4257 4258 /// We are substituting prior template arguments into a new 4259 /// template parameter. The template parameter itself is either a 4260 /// NonTypeTemplateParmDecl or a TemplateTemplateParmDecl. 4261 PriorTemplateArgumentSubstitution, 4262 4263 /// We are checking the validity of a default template argument that 4264 /// has been used when naming a template-id. 4265 DefaultTemplateArgumentChecking 4266 } Kind; 4267 4268 /// \brief The point of instantiation within the source code. 4269 SourceLocation PointOfInstantiation; 4270 4271 /// \brief The template (or partial specialization) in which we are 4272 /// performing the instantiation, for substitutions of prior template 4273 /// arguments. 4274 NamedDecl *Template; 4275 4276 /// \brief The entity that is being instantiated. 4277 uintptr_t Entity; 4278 4279 /// \brief The list of template arguments we are substituting, if they 4280 /// are not part of the entity. 4281 const TemplateArgument *TemplateArgs; 4282 4283 /// \brief The number of template arguments in TemplateArgs. 4284 unsigned NumTemplateArgs; 4285 4286 /// \brief The template deduction info object associated with the 4287 /// substitution or checking of explicit or deduced template arguments. 4288 sema::TemplateDeductionInfo *DeductionInfo; 4289 4290 /// \brief The source range that covers the construct that cause 4291 /// the instantiation, e.g., the template-id that causes a class 4292 /// template instantiation. 4293 SourceRange InstantiationRange; 4294 4295 ActiveTemplateInstantiation() 4296 : Kind(TemplateInstantiation), Template(0), Entity(0), TemplateArgs(0), 4297 NumTemplateArgs(0), DeductionInfo(0) {} 4298 4299 /// \brief Determines whether this template is an actual instantiation 4300 /// that should be counted toward the maximum instantiation depth. 4301 bool isInstantiationRecord() const; 4302 4303 friend bool operator==(const ActiveTemplateInstantiation &X, 4304 const ActiveTemplateInstantiation &Y) { 4305 if (X.Kind != Y.Kind) 4306 return false; 4307 4308 if (X.Entity != Y.Entity) 4309 return false; 4310 4311 switch (X.Kind) { 4312 case TemplateInstantiation: 4313 return true; 4314 4315 case PriorTemplateArgumentSubstitution: 4316 case DefaultTemplateArgumentChecking: 4317 if (X.Template != Y.Template) 4318 return false; 4319 4320 // Fall through 4321 4322 case DefaultTemplateArgumentInstantiation: 4323 case ExplicitTemplateArgumentSubstitution: 4324 case DeducedTemplateArgumentSubstitution: 4325 case DefaultFunctionArgumentInstantiation: 4326 return X.TemplateArgs == Y.TemplateArgs; 4327 4328 } 4329 4330 return true; 4331 } 4332 4333 friend bool operator!=(const ActiveTemplateInstantiation &X, 4334 const ActiveTemplateInstantiation &Y) { 4335 return !(X == Y); 4336 } 4337 }; 4338 4339 /// \brief List of active template instantiations. 4340 /// 4341 /// This vector is treated as a stack. As one template instantiation 4342 /// requires another template instantiation, additional 4343 /// instantiations are pushed onto the stack up to a 4344 /// user-configurable limit LangOptions::InstantiationDepth. 4345 llvm::SmallVector<ActiveTemplateInstantiation, 16> 4346 ActiveTemplateInstantiations; 4347 4348 /// \brief Whether we are in a SFINAE context that is not associated with 4349 /// template instantiation. 4350 /// 4351 /// This is used when setting up a SFINAE trap (\c see SFINAETrap) outside 4352 /// of a template instantiation or template argument deduction. 4353 bool InNonInstantiationSFINAEContext; 4354 4355 /// \brief The number of ActiveTemplateInstantiation entries in 4356 /// \c ActiveTemplateInstantiations that are not actual instantiations and, 4357 /// therefore, should not be counted as part of the instantiation depth. 4358 unsigned NonInstantiationEntries; 4359 4360 /// \brief The last template from which a template instantiation 4361 /// error or warning was produced. 4362 /// 4363 /// This value is used to suppress printing of redundant template 4364 /// instantiation backtraces when there are multiple errors in the 4365 /// same instantiation. FIXME: Does this belong in Sema? It's tough 4366 /// to implement it anywhere else. 4367 ActiveTemplateInstantiation LastTemplateInstantiationErrorContext; 4368 4369 /// \brief The current index into pack expansion arguments that will be 4370 /// used for substitution of parameter packs. 4371 /// 4372 /// The pack expansion index will be -1 to indicate that parameter packs 4373 /// should be instantiated as themselves. Otherwise, the index specifies 4374 /// which argument within the parameter pack will be used for substitution. 4375 int ArgumentPackSubstitutionIndex; 4376 4377 /// \brief RAII object used to change the argument pack substitution index 4378 /// within a \c Sema object. 4379 /// 4380 /// See \c ArgumentPackSubstitutionIndex for more information. 4381 class ArgumentPackSubstitutionIndexRAII { 4382 Sema &Self; 4383 int OldSubstitutionIndex; 4384 4385 public: 4386 ArgumentPackSubstitutionIndexRAII(Sema &Self, int NewSubstitutionIndex) 4387 : Self(Self), OldSubstitutionIndex(Self.ArgumentPackSubstitutionIndex) { 4388 Self.ArgumentPackSubstitutionIndex = NewSubstitutionIndex; 4389 } 4390 4391 ~ArgumentPackSubstitutionIndexRAII() { 4392 Self.ArgumentPackSubstitutionIndex = OldSubstitutionIndex; 4393 } 4394 }; 4395 4396 friend class ArgumentPackSubstitutionRAII; 4397 4398 /// \brief The stack of calls expression undergoing template instantiation. 4399 /// 4400 /// The top of this stack is used by a fixit instantiating unresolved 4401 /// function calls to fix the AST to match the textual change it prints. 4402 llvm::SmallVector<CallExpr *, 8> CallsUndergoingInstantiation; 4403 4404 /// \brief For each declaration that involved template argument deduction, the 4405 /// set of diagnostics that were suppressed during that template argument 4406 /// deduction. 4407 /// 4408 /// FIXME: Serialize this structure to the AST file. 4409 llvm::DenseMap<Decl *, llvm::SmallVector<PartialDiagnosticAt, 1> > 4410 SuppressedDiagnostics; 4411 4412 /// \brief A stack object to be created when performing template 4413 /// instantiation. 4414 /// 4415 /// Construction of an object of type \c InstantiatingTemplate 4416 /// pushes the current instantiation onto the stack of active 4417 /// instantiations. If the size of this stack exceeds the maximum 4418 /// number of recursive template instantiations, construction 4419 /// produces an error and evaluates true. 4420 /// 4421 /// Destruction of this object will pop the named instantiation off 4422 /// the stack. 4423 struct InstantiatingTemplate { 4424 /// \brief Note that we are instantiating a class template, 4425 /// function template, or a member thereof. 4426 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 4427 Decl *Entity, 4428 SourceRange InstantiationRange = SourceRange()); 4429 4430 /// \brief Note that we are instantiating a default argument in a 4431 /// template-id. 4432 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 4433 TemplateDecl *Template, 4434 const TemplateArgument *TemplateArgs, 4435 unsigned NumTemplateArgs, 4436 SourceRange InstantiationRange = SourceRange()); 4437 4438 /// \brief Note that we are instantiating a default argument in a 4439 /// template-id. 4440 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 4441 FunctionTemplateDecl *FunctionTemplate, 4442 const TemplateArgument *TemplateArgs, 4443 unsigned NumTemplateArgs, 4444 ActiveTemplateInstantiation::InstantiationKind Kind, 4445 sema::TemplateDeductionInfo &DeductionInfo, 4446 SourceRange InstantiationRange = SourceRange()); 4447 4448 /// \brief Note that we are instantiating as part of template 4449 /// argument deduction for a class template partial 4450 /// specialization. 4451 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 4452 ClassTemplatePartialSpecializationDecl *PartialSpec, 4453 const TemplateArgument *TemplateArgs, 4454 unsigned NumTemplateArgs, 4455 sema::TemplateDeductionInfo &DeductionInfo, 4456 SourceRange InstantiationRange = SourceRange()); 4457 4458 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 4459 ParmVarDecl *Param, 4460 const TemplateArgument *TemplateArgs, 4461 unsigned NumTemplateArgs, 4462 SourceRange InstantiationRange = SourceRange()); 4463 4464 /// \brief Note that we are substituting prior template arguments into a 4465 /// non-type or template template parameter. 4466 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 4467 NamedDecl *Template, 4468 NonTypeTemplateParmDecl *Param, 4469 const TemplateArgument *TemplateArgs, 4470 unsigned NumTemplateArgs, 4471 SourceRange InstantiationRange); 4472 4473 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 4474 NamedDecl *Template, 4475 TemplateTemplateParmDecl *Param, 4476 const TemplateArgument *TemplateArgs, 4477 unsigned NumTemplateArgs, 4478 SourceRange InstantiationRange); 4479 4480 /// \brief Note that we are checking the default template argument 4481 /// against the template parameter for a given template-id. 4482 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 4483 TemplateDecl *Template, 4484 NamedDecl *Param, 4485 const TemplateArgument *TemplateArgs, 4486 unsigned NumTemplateArgs, 4487 SourceRange InstantiationRange); 4488 4489 4490 /// \brief Note that we have finished instantiating this template. 4491 void Clear(); 4492 4493 ~InstantiatingTemplate() { Clear(); } 4494 4495 /// \brief Determines whether we have exceeded the maximum 4496 /// recursive template instantiations. 4497 operator bool() const { return Invalid; } 4498 4499 private: 4500 Sema &SemaRef; 4501 bool Invalid; 4502 bool SavedInNonInstantiationSFINAEContext; 4503 bool CheckInstantiationDepth(SourceLocation PointOfInstantiation, 4504 SourceRange InstantiationRange); 4505 4506 InstantiatingTemplate(const InstantiatingTemplate&); // not implemented 4507 4508 InstantiatingTemplate& 4509 operator=(const InstantiatingTemplate&); // not implemented 4510 }; 4511 4512 void PrintInstantiationStack(); 4513 4514 /// \brief Determines whether we are currently in a context where 4515 /// template argument substitution failures are not considered 4516 /// errors. 4517 /// 4518 /// \returns An empty \c llvm::Optional if we're not in a SFINAE context. 4519 /// Otherwise, contains a pointer that, if non-NULL, contains the nearest 4520 /// template-deduction context object, which can be used to capture 4521 /// diagnostics that will be suppressed. 4522 llvm::Optional<sema::TemplateDeductionInfo *> isSFINAEContext() const; 4523 4524 /// \brief RAII class used to determine whether SFINAE has 4525 /// trapped any errors that occur during template argument 4526 /// deduction.` 4527 class SFINAETrap { 4528 Sema &SemaRef; 4529 unsigned PrevSFINAEErrors; 4530 bool PrevInNonInstantiationSFINAEContext; 4531 bool PrevAccessCheckingSFINAE; 4532 4533 public: 4534 explicit SFINAETrap(Sema &SemaRef, bool AccessCheckingSFINAE = false) 4535 : SemaRef(SemaRef), PrevSFINAEErrors(SemaRef.NumSFINAEErrors), 4536 PrevInNonInstantiationSFINAEContext( 4537 SemaRef.InNonInstantiationSFINAEContext), 4538 PrevAccessCheckingSFINAE(SemaRef.AccessCheckingSFINAE) 4539 { 4540 if (!SemaRef.isSFINAEContext()) 4541 SemaRef.InNonInstantiationSFINAEContext = true; 4542 SemaRef.AccessCheckingSFINAE = AccessCheckingSFINAE; 4543 } 4544 4545 ~SFINAETrap() { 4546 SemaRef.NumSFINAEErrors = PrevSFINAEErrors; 4547 SemaRef.InNonInstantiationSFINAEContext 4548 = PrevInNonInstantiationSFINAEContext; 4549 SemaRef.AccessCheckingSFINAE = PrevAccessCheckingSFINAE; 4550 } 4551 4552 /// \brief Determine whether any SFINAE errors have been trapped. 4553 bool hasErrorOccurred() const { 4554 return SemaRef.NumSFINAEErrors > PrevSFINAEErrors; 4555 } 4556 }; 4557 4558 /// \brief The current instantiation scope used to store local 4559 /// variables. 4560 LocalInstantiationScope *CurrentInstantiationScope; 4561 4562 /// \brief The number of typos corrected by CorrectTypo. 4563 unsigned TyposCorrected; 4564 4565 typedef llvm::DenseMap<IdentifierInfo *, std::pair<llvm::StringRef, bool> > 4566 UnqualifiedTyposCorrectedMap; 4567 4568 /// \brief A cache containing the results of typo correction for unqualified 4569 /// name lookup. 4570 /// 4571 /// The string is the string that we corrected to (which may be empty, if 4572 /// there was no correction), while the boolean will be true when the 4573 /// string represents a keyword. 4574 UnqualifiedTyposCorrectedMap UnqualifiedTyposCorrected; 4575 4576 /// \brief Worker object for performing CFG-based warnings. 4577 sema::AnalysisBasedWarnings AnalysisWarnings; 4578 4579 /// \brief An entity for which implicit template instantiation is required. 4580 /// 4581 /// The source location associated with the declaration is the first place in 4582 /// the source code where the declaration was "used". It is not necessarily 4583 /// the point of instantiation (which will be either before or after the 4584 /// namespace-scope declaration that triggered this implicit instantiation), 4585 /// However, it is the location that diagnostics should generally refer to, 4586 /// because users will need to know what code triggered the instantiation. 4587 typedef std::pair<ValueDecl *, SourceLocation> PendingImplicitInstantiation; 4588 4589 /// \brief The queue of implicit template instantiations that are required 4590 /// but have not yet been performed. 4591 std::deque<PendingImplicitInstantiation> PendingInstantiations; 4592 4593 /// \brief The queue of implicit template instantiations that are required 4594 /// and must be performed within the current local scope. 4595 /// 4596 /// This queue is only used for member functions of local classes in 4597 /// templates, which must be instantiated in the same scope as their 4598 /// enclosing function, so that they can reference function-local 4599 /// types, static variables, enumerators, etc. 4600 std::deque<PendingImplicitInstantiation> PendingLocalImplicitInstantiations; 4601 4602 bool PerformPendingInstantiations(bool LocalOnly = false); 4603 4604 TypeSourceInfo *SubstType(TypeSourceInfo *T, 4605 const MultiLevelTemplateArgumentList &TemplateArgs, 4606 SourceLocation Loc, DeclarationName Entity); 4607 4608 QualType SubstType(QualType T, 4609 const MultiLevelTemplateArgumentList &TemplateArgs, 4610 SourceLocation Loc, DeclarationName Entity); 4611 4612 TypeSourceInfo *SubstType(TypeLoc TL, 4613 const MultiLevelTemplateArgumentList &TemplateArgs, 4614 SourceLocation Loc, DeclarationName Entity); 4615 4616 TypeSourceInfo *SubstFunctionDeclType(TypeSourceInfo *T, 4617 const MultiLevelTemplateArgumentList &TemplateArgs, 4618 SourceLocation Loc, 4619 DeclarationName Entity); 4620 ParmVarDecl *SubstParmVarDecl(ParmVarDecl *D, 4621 const MultiLevelTemplateArgumentList &TemplateArgs, 4622 int indexAdjustment, 4623 llvm::Optional<unsigned> NumExpansions); 4624 bool SubstParmTypes(SourceLocation Loc, 4625 ParmVarDecl **Params, unsigned NumParams, 4626 const MultiLevelTemplateArgumentList &TemplateArgs, 4627 llvm::SmallVectorImpl<QualType> &ParamTypes, 4628 llvm::SmallVectorImpl<ParmVarDecl *> *OutParams = 0); 4629 ExprResult SubstExpr(Expr *E, 4630 const MultiLevelTemplateArgumentList &TemplateArgs); 4631 4632 /// \brief Substitute the given template arguments into a list of 4633 /// expressions, expanding pack expansions if required. 4634 /// 4635 /// \param Exprs The list of expressions to substitute into. 4636 /// 4637 /// \param NumExprs The number of expressions in \p Exprs. 4638 /// 4639 /// \param IsCall Whether this is some form of call, in which case 4640 /// default arguments will be dropped. 4641 /// 4642 /// \param TemplateArgs The set of template arguments to substitute. 4643 /// 4644 /// \param Outputs Will receive all of the substituted arguments. 4645 /// 4646 /// \returns true if an error occurred, false otherwise. 4647 bool SubstExprs(Expr **Exprs, unsigned NumExprs, bool IsCall, 4648 const MultiLevelTemplateArgumentList &TemplateArgs, 4649 llvm::SmallVectorImpl<Expr *> &Outputs); 4650 4651 StmtResult SubstStmt(Stmt *S, 4652 const MultiLevelTemplateArgumentList &TemplateArgs); 4653 4654 Decl *SubstDecl(Decl *D, DeclContext *Owner, 4655 const MultiLevelTemplateArgumentList &TemplateArgs); 4656 4657 bool 4658 SubstBaseSpecifiers(CXXRecordDecl *Instantiation, 4659 CXXRecordDecl *Pattern, 4660 const MultiLevelTemplateArgumentList &TemplateArgs); 4661 4662 bool 4663 InstantiateClass(SourceLocation PointOfInstantiation, 4664 CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern, 4665 const MultiLevelTemplateArgumentList &TemplateArgs, 4666 TemplateSpecializationKind TSK, 4667 bool Complain = true); 4668 4669 void InstantiateAttrs(const MultiLevelTemplateArgumentList &TemplateArgs, 4670 Decl *Pattern, Decl *Inst); 4671 4672 bool 4673 InstantiateClassTemplateSpecialization(SourceLocation PointOfInstantiation, 4674 ClassTemplateSpecializationDecl *ClassTemplateSpec, 4675 TemplateSpecializationKind TSK, 4676 bool Complain = true); 4677 4678 void InstantiateClassMembers(SourceLocation PointOfInstantiation, 4679 CXXRecordDecl *Instantiation, 4680 const MultiLevelTemplateArgumentList &TemplateArgs, 4681 TemplateSpecializationKind TSK); 4682 4683 void InstantiateClassTemplateSpecializationMembers( 4684 SourceLocation PointOfInstantiation, 4685 ClassTemplateSpecializationDecl *ClassTemplateSpec, 4686 TemplateSpecializationKind TSK); 4687 4688 NestedNameSpecifierLoc 4689 SubstNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, 4690 const MultiLevelTemplateArgumentList &TemplateArgs); 4691 4692 DeclarationNameInfo 4693 SubstDeclarationNameInfo(const DeclarationNameInfo &NameInfo, 4694 const MultiLevelTemplateArgumentList &TemplateArgs); 4695 TemplateName 4696 SubstTemplateName(NestedNameSpecifierLoc QualifierLoc, TemplateName Name, 4697 SourceLocation Loc, 4698 const MultiLevelTemplateArgumentList &TemplateArgs); 4699 bool Subst(const TemplateArgumentLoc *Args, unsigned NumArgs, 4700 TemplateArgumentListInfo &Result, 4701 const MultiLevelTemplateArgumentList &TemplateArgs); 4702 4703 void InstantiateFunctionDefinition(SourceLocation PointOfInstantiation, 4704 FunctionDecl *Function, 4705 bool Recursive = false, 4706 bool DefinitionRequired = false); 4707 void InstantiateStaticDataMemberDefinition( 4708 SourceLocation PointOfInstantiation, 4709 VarDecl *Var, 4710 bool Recursive = false, 4711 bool DefinitionRequired = false); 4712 4713 void InstantiateMemInitializers(CXXConstructorDecl *New, 4714 const CXXConstructorDecl *Tmpl, 4715 const MultiLevelTemplateArgumentList &TemplateArgs); 4716 4717 NamedDecl *FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D, 4718 const MultiLevelTemplateArgumentList &TemplateArgs); 4719 DeclContext *FindInstantiatedContext(SourceLocation Loc, DeclContext *DC, 4720 const MultiLevelTemplateArgumentList &TemplateArgs); 4721 4722 // Objective-C declarations. 4723 Decl *ActOnStartClassInterface(SourceLocation AtInterfaceLoc, 4724 IdentifierInfo *ClassName, 4725 SourceLocation ClassLoc, 4726 IdentifierInfo *SuperName, 4727 SourceLocation SuperLoc, 4728 Decl * const *ProtoRefs, 4729 unsigned NumProtoRefs, 4730 const SourceLocation *ProtoLocs, 4731 SourceLocation EndProtoLoc, 4732 AttributeList *AttrList); 4733 4734 Decl *ActOnCompatiblityAlias( 4735 SourceLocation AtCompatibilityAliasLoc, 4736 IdentifierInfo *AliasName, SourceLocation AliasLocation, 4737 IdentifierInfo *ClassName, SourceLocation ClassLocation); 4738 4739 void CheckForwardProtocolDeclarationForCircularDependency( 4740 IdentifierInfo *PName, 4741 SourceLocation &PLoc, SourceLocation PrevLoc, 4742 const ObjCList<ObjCProtocolDecl> &PList, 4743 bool &err); 4744 4745 Decl *ActOnStartProtocolInterface( 4746 SourceLocation AtProtoInterfaceLoc, 4747 IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc, 4748 Decl * const *ProtoRefNames, unsigned NumProtoRefs, 4749 const SourceLocation *ProtoLocs, 4750 SourceLocation EndProtoLoc, 4751 AttributeList *AttrList); 4752 4753 Decl *ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc, 4754 IdentifierInfo *ClassName, 4755 SourceLocation ClassLoc, 4756 IdentifierInfo *CategoryName, 4757 SourceLocation CategoryLoc, 4758 Decl * const *ProtoRefs, 4759 unsigned NumProtoRefs, 4760 const SourceLocation *ProtoLocs, 4761 SourceLocation EndProtoLoc); 4762 4763 Decl *ActOnStartClassImplementation( 4764 SourceLocation AtClassImplLoc, 4765 IdentifierInfo *ClassName, SourceLocation ClassLoc, 4766 IdentifierInfo *SuperClassname, 4767 SourceLocation SuperClassLoc); 4768 4769 Decl *ActOnStartCategoryImplementation(SourceLocation AtCatImplLoc, 4770 IdentifierInfo *ClassName, 4771 SourceLocation ClassLoc, 4772 IdentifierInfo *CatName, 4773 SourceLocation CatLoc); 4774 4775 Decl *ActOnForwardClassDeclaration(SourceLocation Loc, 4776 IdentifierInfo **IdentList, 4777 SourceLocation *IdentLocs, 4778 unsigned NumElts); 4779 4780 Decl *ActOnForwardProtocolDeclaration(SourceLocation AtProtoclLoc, 4781 const IdentifierLocPair *IdentList, 4782 unsigned NumElts, 4783 AttributeList *attrList); 4784 4785 void FindProtocolDeclaration(bool WarnOnDeclarations, 4786 const IdentifierLocPair *ProtocolId, 4787 unsigned NumProtocols, 4788 llvm::SmallVectorImpl<Decl *> &Protocols); 4789 4790 /// Ensure attributes are consistent with type. 4791 /// \param [in, out] Attributes The attributes to check; they will 4792 /// be modified to be consistent with \arg PropertyTy. 4793 void CheckObjCPropertyAttributes(Decl *PropertyPtrTy, 4794 SourceLocation Loc, 4795 unsigned &Attributes); 4796 4797 /// Process the specified property declaration and create decls for the 4798 /// setters and getters as needed. 4799 /// \param property The property declaration being processed 4800 /// \param DC The semantic container for the property 4801 /// \param redeclaredProperty Declaration for property if redeclared 4802 /// in class extension. 4803 /// \param lexicalDC Container for redeclaredProperty. 4804 void ProcessPropertyDecl(ObjCPropertyDecl *property, 4805 ObjCContainerDecl *DC, 4806 ObjCPropertyDecl *redeclaredProperty = 0, 4807 ObjCContainerDecl *lexicalDC = 0); 4808 4809 void DiagnosePropertyMismatch(ObjCPropertyDecl *Property, 4810 ObjCPropertyDecl *SuperProperty, 4811 const IdentifierInfo *Name); 4812 void ComparePropertiesInBaseAndSuper(ObjCInterfaceDecl *IDecl); 4813 4814 void CompareMethodParamsInBaseAndSuper(Decl *IDecl, 4815 ObjCMethodDecl *MethodDecl, 4816 bool IsInstance); 4817 4818 void CompareProperties(Decl *CDecl, Decl *MergeProtocols); 4819 4820 void DiagnoseClassExtensionDupMethods(ObjCCategoryDecl *CAT, 4821 ObjCInterfaceDecl *ID); 4822 4823 void MatchOneProtocolPropertiesInClass(Decl *CDecl, 4824 ObjCProtocolDecl *PDecl); 4825 4826 void ActOnAtEnd(Scope *S, SourceRange AtEnd, Decl *classDecl, 4827 Decl **allMethods = 0, unsigned allNum = 0, 4828 Decl **allProperties = 0, unsigned pNum = 0, 4829 DeclGroupPtrTy *allTUVars = 0, unsigned tuvNum = 0); 4830 4831 Decl *ActOnProperty(Scope *S, SourceLocation AtLoc, 4832 FieldDeclarator &FD, ObjCDeclSpec &ODS, 4833 Selector GetterSel, Selector SetterSel, 4834 Decl *ClassCategory, 4835 bool *OverridingProperty, 4836 tok::ObjCKeywordKind MethodImplKind, 4837 DeclContext *lexicalDC = 0); 4838 4839 Decl *ActOnPropertyImplDecl(Scope *S, 4840 SourceLocation AtLoc, 4841 SourceLocation PropertyLoc, 4842 bool ImplKind,Decl *ClassImplDecl, 4843 IdentifierInfo *PropertyId, 4844 IdentifierInfo *PropertyIvar, 4845 SourceLocation PropertyIvarLoc); 4846 4847 struct ObjCArgInfo { 4848 IdentifierInfo *Name; 4849 SourceLocation NameLoc; 4850 // The Type is null if no type was specified, and the DeclSpec is invalid 4851 // in this case. 4852 ParsedType Type; 4853 ObjCDeclSpec DeclSpec; 4854 4855 /// ArgAttrs - Attribute list for this argument. 4856 AttributeList *ArgAttrs; 4857 }; 4858 4859 Decl *ActOnMethodDeclaration( 4860 Scope *S, 4861 SourceLocation BeginLoc, // location of the + or -. 4862 SourceLocation EndLoc, // location of the ; or {. 4863 tok::TokenKind MethodType, 4864 Decl *ClassDecl, ObjCDeclSpec &ReturnQT, ParsedType ReturnType, 4865 Selector Sel, 4866 // optional arguments. The number of types/arguments is obtained 4867 // from the Sel.getNumArgs(). 4868 ObjCArgInfo *ArgInfo, 4869 DeclaratorChunk::ParamInfo *CParamInfo, unsigned CNumArgs, // c-style args 4870 AttributeList *AttrList, tok::ObjCKeywordKind MethodImplKind, 4871 bool isVariadic, bool MethodDefinition); 4872 4873 // Helper method for ActOnClassMethod/ActOnInstanceMethod. 4874 // Will search "local" class/category implementations for a method decl. 4875 // Will also search in class's root looking for instance method. 4876 // Returns 0 if no method is found. 4877 ObjCMethodDecl *LookupPrivateClassMethod(Selector Sel, 4878 ObjCInterfaceDecl *CDecl); 4879 ObjCMethodDecl *LookupPrivateInstanceMethod(Selector Sel, 4880 ObjCInterfaceDecl *ClassDecl); 4881 ObjCMethodDecl *LookupMethodInQualifiedType(Selector Sel, 4882 const ObjCObjectPointerType *OPT, 4883 bool IsInstance); 4884 4885 ExprResult 4886 HandleExprPropertyRefExpr(const ObjCObjectPointerType *OPT, 4887 Expr *BaseExpr, 4888 DeclarationName MemberName, 4889 SourceLocation MemberLoc, 4890 SourceLocation SuperLoc, QualType SuperType, 4891 bool Super); 4892 4893 ExprResult 4894 ActOnClassPropertyRefExpr(IdentifierInfo &receiverName, 4895 IdentifierInfo &propertyName, 4896 SourceLocation receiverNameLoc, 4897 SourceLocation propertyNameLoc); 4898 4899 ObjCMethodDecl *tryCaptureObjCSelf(); 4900 4901 /// \brief Describes the kind of message expression indicated by a message 4902 /// send that starts with an identifier. 4903 enum ObjCMessageKind { 4904 /// \brief The message is sent to 'super'. 4905 ObjCSuperMessage, 4906 /// \brief The message is an instance message. 4907 ObjCInstanceMessage, 4908 /// \brief The message is a class message, and the identifier is a type 4909 /// name. 4910 ObjCClassMessage 4911 }; 4912 4913 ObjCMessageKind getObjCMessageKind(Scope *S, 4914 IdentifierInfo *Name, 4915 SourceLocation NameLoc, 4916 bool IsSuper, 4917 bool HasTrailingDot, 4918 ParsedType &ReceiverType); 4919 4920 ExprResult ActOnSuperMessage(Scope *S, SourceLocation SuperLoc, 4921 Selector Sel, 4922 SourceLocation LBracLoc, 4923 SourceLocation SelectorLoc, 4924 SourceLocation RBracLoc, 4925 MultiExprArg Args); 4926 4927 ExprResult BuildClassMessage(TypeSourceInfo *ReceiverTypeInfo, 4928 QualType ReceiverType, 4929 SourceLocation SuperLoc, 4930 Selector Sel, 4931 ObjCMethodDecl *Method, 4932 SourceLocation LBracLoc, 4933 SourceLocation SelectorLoc, 4934 SourceLocation RBracLoc, 4935 MultiExprArg Args); 4936 4937 ExprResult ActOnClassMessage(Scope *S, 4938 ParsedType Receiver, 4939 Selector Sel, 4940 SourceLocation LBracLoc, 4941 SourceLocation SelectorLoc, 4942 SourceLocation RBracLoc, 4943 MultiExprArg Args); 4944 4945 ExprResult BuildInstanceMessage(Expr *Receiver, 4946 QualType ReceiverType, 4947 SourceLocation SuperLoc, 4948 Selector Sel, 4949 ObjCMethodDecl *Method, 4950 SourceLocation LBracLoc, 4951 SourceLocation SelectorLoc, 4952 SourceLocation RBracLoc, 4953 MultiExprArg Args); 4954 4955 ExprResult ActOnInstanceMessage(Scope *S, 4956 Expr *Receiver, 4957 Selector Sel, 4958 SourceLocation LBracLoc, 4959 SourceLocation SelectorLoc, 4960 SourceLocation RBracLoc, 4961 MultiExprArg Args); 4962 4963 4964 enum PragmaOptionsAlignKind { 4965 POAK_Native, // #pragma options align=native 4966 POAK_Natural, // #pragma options align=natural 4967 POAK_Packed, // #pragma options align=packed 4968 POAK_Power, // #pragma options align=power 4969 POAK_Mac68k, // #pragma options align=mac68k 4970 POAK_Reset // #pragma options align=reset 4971 }; 4972 4973 /// ActOnPragmaOptionsAlign - Called on well formed #pragma options align. 4974 void ActOnPragmaOptionsAlign(PragmaOptionsAlignKind Kind, 4975 SourceLocation PragmaLoc, 4976 SourceLocation KindLoc); 4977 4978 enum PragmaPackKind { 4979 PPK_Default, // #pragma pack([n]) 4980 PPK_Show, // #pragma pack(show), only supported by MSVC. 4981 PPK_Push, // #pragma pack(push, [identifier], [n]) 4982 PPK_Pop // #pragma pack(pop, [identifier], [n]) 4983 }; 4984 4985 enum PragmaMSStructKind { 4986 PMSST_OFF, // #pragms ms_struct off 4987 PMSST_ON // #pragms ms_struct on 4988 }; 4989 4990 /// ActOnPragmaPack - Called on well formed #pragma pack(...). 4991 void ActOnPragmaPack(PragmaPackKind Kind, 4992 IdentifierInfo *Name, 4993 Expr *Alignment, 4994 SourceLocation PragmaLoc, 4995 SourceLocation LParenLoc, 4996 SourceLocation RParenLoc); 4997 4998 /// ActOnPragmaMSStruct - Called on well formed #pragms ms_struct [on|off]. 4999 void ActOnPragmaMSStruct(PragmaMSStructKind Kind); 5000 5001 /// ActOnPragmaUnused - Called on well-formed '#pragma unused'. 5002 void ActOnPragmaUnused(const Token &Identifier, 5003 Scope *curScope, 5004 SourceLocation PragmaLoc); 5005 5006 /// ActOnPragmaVisibility - Called on well formed #pragma GCC visibility... . 5007 void ActOnPragmaVisibility(bool IsPush, const IdentifierInfo* VisType, 5008 SourceLocation PragmaLoc); 5009 5010 NamedDecl *DeclClonePragmaWeak(NamedDecl *ND, IdentifierInfo *II); 5011 void DeclApplyPragmaWeak(Scope *S, NamedDecl *ND, WeakInfo &W); 5012 5013 /// ActOnPragmaWeakID - Called on well formed #pragma weak ident. 5014 void ActOnPragmaWeakID(IdentifierInfo* WeakName, 5015 SourceLocation PragmaLoc, 5016 SourceLocation WeakNameLoc); 5017 5018 /// ActOnPragmaWeakAlias - Called on well formed #pragma weak ident = ident. 5019 void ActOnPragmaWeakAlias(IdentifierInfo* WeakName, 5020 IdentifierInfo* AliasName, 5021 SourceLocation PragmaLoc, 5022 SourceLocation WeakNameLoc, 5023 SourceLocation AliasNameLoc); 5024 5025 /// ActOnPragmaFPContract - Called on well formed 5026 /// #pragma {STDC,OPENCL} FP_CONTRACT 5027 void ActOnPragmaFPContract(tok::OnOffSwitch OOS); 5028 5029 /// AddAlignmentAttributesForRecord - Adds any needed alignment attributes to 5030 /// a the record decl, to handle '#pragma pack' and '#pragma options align'. 5031 void AddAlignmentAttributesForRecord(RecordDecl *RD); 5032 5033 /// AddMsStructLayoutForRecord - Adds ms_struct layout attribute to record. 5034 void AddMsStructLayoutForRecord(RecordDecl *RD); 5035 5036 /// FreePackedContext - Deallocate and null out PackContext. 5037 void FreePackedContext(); 5038 5039 /// PushNamespaceVisibilityAttr - Note that we've entered a 5040 /// namespace with a visibility attribute. 5041 void PushNamespaceVisibilityAttr(const VisibilityAttr *Attr); 5042 5043 /// AddPushedVisibilityAttribute - If '#pragma GCC visibility' was used, 5044 /// add an appropriate visibility attribute. 5045 void AddPushedVisibilityAttribute(Decl *RD); 5046 5047 /// PopPragmaVisibility - Pop the top element of the visibility stack; used 5048 /// for '#pragma GCC visibility' and visibility attributes on namespaces. 5049 void PopPragmaVisibility(); 5050 5051 /// FreeVisContext - Deallocate and null out VisContext. 5052 void FreeVisContext(); 5053 5054 /// AddAlignedAttr - Adds an aligned attribute to a particular declaration. 5055 void AddAlignedAttr(SourceLocation AttrLoc, Decl *D, Expr *E); 5056 void AddAlignedAttr(SourceLocation AttrLoc, Decl *D, TypeSourceInfo *T); 5057 5058 /// CastCategory - Get the correct forwarded implicit cast result category 5059 /// from the inner expression. 5060 ExprValueKind CastCategory(Expr *E); 5061 5062 /// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit 5063 /// cast. If there is already an implicit cast, merge into the existing one. 5064 /// If isLvalue, the result of the cast is an lvalue. 5065 ExprResult ImpCastExprToType(Expr *E, QualType Type, CastKind CK, 5066 ExprValueKind VK = VK_RValue, 5067 const CXXCastPath *BasePath = 0); 5068 5069 /// ScalarTypeToBooleanCastKind - Returns the cast kind corresponding 5070 /// to the conversion from scalar type ScalarTy to the Boolean type. 5071 static CastKind ScalarTypeToBooleanCastKind(QualType ScalarTy); 5072 5073 /// IgnoredValueConversions - Given that an expression's result is 5074 /// syntactically ignored, perform any conversions that are 5075 /// required. 5076 ExprResult IgnoredValueConversions(Expr *E); 5077 5078 // UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts 5079 // functions and arrays to their respective pointers (C99 6.3.2.1). 5080 ExprResult UsualUnaryConversions(Expr *E); 5081 5082 // DefaultFunctionArrayConversion - converts functions and arrays 5083 // to their respective pointers (C99 6.3.2.1). 5084 ExprResult DefaultFunctionArrayConversion(Expr *E); 5085 5086 // DefaultFunctionArrayLvalueConversion - converts functions and 5087 // arrays to their respective pointers and performs the 5088 // lvalue-to-rvalue conversion. 5089 ExprResult DefaultFunctionArrayLvalueConversion(Expr *E); 5090 5091 // DefaultLvalueConversion - performs lvalue-to-rvalue conversion on 5092 // the operand. This is DefaultFunctionArrayLvalueConversion, 5093 // except that it assumes the operand isn't of function or array 5094 // type. 5095 ExprResult DefaultLvalueConversion(Expr *E); 5096 5097 // DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that 5098 // do not have a prototype. Integer promotions are performed on each 5099 // argument, and arguments that have type float are promoted to double. 5100 ExprResult DefaultArgumentPromotion(Expr *E); 5101 5102 // Used for emitting the right warning by DefaultVariadicArgumentPromotion 5103 enum VariadicCallType { 5104 VariadicFunction, 5105 VariadicBlock, 5106 VariadicMethod, 5107 VariadicConstructor, 5108 VariadicDoesNotApply 5109 }; 5110 5111 /// GatherArgumentsForCall - Collector argument expressions for various 5112 /// form of call prototypes. 5113 bool GatherArgumentsForCall(SourceLocation CallLoc, 5114 FunctionDecl *FDecl, 5115 const FunctionProtoType *Proto, 5116 unsigned FirstProtoArg, 5117 Expr **Args, unsigned NumArgs, 5118 llvm::SmallVector<Expr *, 8> &AllArgs, 5119 VariadicCallType CallType = VariadicDoesNotApply); 5120 5121 // DefaultVariadicArgumentPromotion - Like DefaultArgumentPromotion, but 5122 // will warn if the resulting type is not a POD type. 5123 ExprResult DefaultVariadicArgumentPromotion(Expr *E, VariadicCallType CT, 5124 FunctionDecl *FDecl); 5125 5126 // UsualArithmeticConversions - performs the UsualUnaryConversions on it's 5127 // operands and then handles various conversions that are common to binary 5128 // operators (C99 6.3.1.8). If both operands aren't arithmetic, this 5129 // routine returns the first non-arithmetic type found. The client is 5130 // responsible for emitting appropriate error diagnostics. 5131 QualType UsualArithmeticConversions(ExprResult &lExpr, ExprResult &rExpr, 5132 bool isCompAssign = false); 5133 5134 /// AssignConvertType - All of the 'assignment' semantic checks return this 5135 /// enum to indicate whether the assignment was allowed. These checks are 5136 /// done for simple assignments, as well as initialization, return from 5137 /// function, argument passing, etc. The query is phrased in terms of a 5138 /// source and destination type. 5139 enum AssignConvertType { 5140 /// Compatible - the types are compatible according to the standard. 5141 Compatible, 5142 5143 /// PointerToInt - The assignment converts a pointer to an int, which we 5144 /// accept as an extension. 5145 PointerToInt, 5146 5147 /// IntToPointer - The assignment converts an int to a pointer, which we 5148 /// accept as an extension. 5149 IntToPointer, 5150 5151 /// FunctionVoidPointer - The assignment is between a function pointer and 5152 /// void*, which the standard doesn't allow, but we accept as an extension. 5153 FunctionVoidPointer, 5154 5155 /// IncompatiblePointer - The assignment is between two pointers types that 5156 /// are not compatible, but we accept them as an extension. 5157 IncompatiblePointer, 5158 5159 /// IncompatiblePointer - The assignment is between two pointers types which 5160 /// point to integers which have a different sign, but are otherwise identical. 5161 /// This is a subset of the above, but broken out because it's by far the most 5162 /// common case of incompatible pointers. 5163 IncompatiblePointerSign, 5164 5165 /// CompatiblePointerDiscardsQualifiers - The assignment discards 5166 /// c/v/r qualifiers, which we accept as an extension. 5167 CompatiblePointerDiscardsQualifiers, 5168 5169 /// IncompatiblePointerDiscardsQualifiers - The assignment 5170 /// discards qualifiers that we don't permit to be discarded, 5171 /// like address spaces. 5172 IncompatiblePointerDiscardsQualifiers, 5173 5174 /// IncompatibleNestedPointerQualifiers - The assignment is between two 5175 /// nested pointer types, and the qualifiers other than the first two 5176 /// levels differ e.g. char ** -> const char **, but we accept them as an 5177 /// extension. 5178 IncompatibleNestedPointerQualifiers, 5179 5180 /// IncompatibleVectors - The assignment is between two vector types that 5181 /// have the same size, which we accept as an extension. 5182 IncompatibleVectors, 5183 5184 /// IntToBlockPointer - The assignment converts an int to a block 5185 /// pointer. We disallow this. 5186 IntToBlockPointer, 5187 5188 /// IncompatibleBlockPointer - The assignment is between two block 5189 /// pointers types that are not compatible. 5190 IncompatibleBlockPointer, 5191 5192 /// IncompatibleObjCQualifiedId - The assignment is between a qualified 5193 /// id type and something else (that is incompatible with it). For example, 5194 /// "id <XXX>" = "Foo *", where "Foo *" doesn't implement the XXX protocol. 5195 IncompatibleObjCQualifiedId, 5196 5197 /// Incompatible - We reject this conversion outright, it is invalid to 5198 /// represent it in the AST. 5199 Incompatible 5200 }; 5201 5202 /// DiagnoseAssignmentResult - Emit a diagnostic, if required, for the 5203 /// assignment conversion type specified by ConvTy. This returns true if the 5204 /// conversion was invalid or false if the conversion was accepted. 5205 bool DiagnoseAssignmentResult(AssignConvertType ConvTy, 5206 SourceLocation Loc, 5207 QualType DstType, QualType SrcType, 5208 Expr *SrcExpr, AssignmentAction Action, 5209 bool *Complained = 0); 5210 5211 /// CheckAssignmentConstraints - Perform type checking for assignment, 5212 /// argument passing, variable initialization, and function return values. 5213 /// C99 6.5.16. 5214 AssignConvertType CheckAssignmentConstraints(SourceLocation Loc, 5215 QualType lhs, QualType rhs); 5216 5217 /// Check assignment constraints and prepare for a conversion of the 5218 /// RHS to the LHS type. 5219 AssignConvertType CheckAssignmentConstraints(QualType lhs, ExprResult &rhs, 5220 CastKind &Kind); 5221 5222 // CheckSingleAssignmentConstraints - Currently used by 5223 // CheckAssignmentOperands, and ActOnReturnStmt. Prior to type checking, 5224 // this routine performs the default function/array converions. 5225 AssignConvertType CheckSingleAssignmentConstraints(QualType lhs, 5226 ExprResult &rExprRes); 5227 5228 // \brief If the lhs type is a transparent union, check whether we 5229 // can initialize the transparent union with the given expression. 5230 AssignConvertType CheckTransparentUnionArgumentConstraints(QualType lhs, 5231 ExprResult &rExpr); 5232 5233 bool IsStringLiteralToNonConstPointerConversion(Expr *From, QualType ToType); 5234 5235 bool CheckExceptionSpecCompatibility(Expr *From, QualType ToType); 5236 5237 ExprResult PerformImplicitConversion(Expr *From, QualType ToType, 5238 AssignmentAction Action, 5239 bool AllowExplicit = false); 5240 ExprResult PerformImplicitConversion(Expr *From, QualType ToType, 5241 AssignmentAction Action, 5242 bool AllowExplicit, 5243 ImplicitConversionSequence& ICS); 5244 ExprResult PerformImplicitConversion(Expr *From, QualType ToType, 5245 const ImplicitConversionSequence& ICS, 5246 AssignmentAction Action, 5247 bool CStyle = false); 5248 ExprResult PerformImplicitConversion(Expr *From, QualType ToType, 5249 const StandardConversionSequence& SCS, 5250 AssignmentAction Action, 5251 bool CStyle); 5252 5253 /// the following "Check" methods will return a valid/converted QualType 5254 /// or a null QualType (indicating an error diagnostic was issued). 5255 5256 /// type checking binary operators (subroutines of CreateBuiltinBinOp). 5257 QualType InvalidOperands(SourceLocation l, ExprResult &lex, ExprResult &rex); 5258 QualType CheckPointerToMemberOperands( // C++ 5.5 5259 ExprResult &lex, ExprResult &rex, ExprValueKind &VK, 5260 SourceLocation OpLoc, bool isIndirect); 5261 QualType CheckMultiplyDivideOperands( // C99 6.5.5 5262 ExprResult &lex, ExprResult &rex, SourceLocation OpLoc, bool isCompAssign, 5263 bool isDivide); 5264 QualType CheckRemainderOperands( // C99 6.5.5 5265 ExprResult &lex, ExprResult &rex, SourceLocation OpLoc, bool isCompAssign = false); 5266 QualType CheckAdditionOperands( // C99 6.5.6 5267 ExprResult &lex, ExprResult &rex, SourceLocation OpLoc, QualType* CompLHSTy = 0); 5268 QualType CheckSubtractionOperands( // C99 6.5.6 5269 ExprResult &lex, ExprResult &rex, SourceLocation OpLoc, QualType* CompLHSTy = 0); 5270 QualType CheckShiftOperands( // C99 6.5.7 5271 ExprResult &lex, ExprResult &rex, SourceLocation OpLoc, unsigned Opc, 5272 bool isCompAssign = false); 5273 QualType CheckCompareOperands( // C99 6.5.8/9 5274 ExprResult &lex, ExprResult &rex, SourceLocation OpLoc, unsigned Opc, 5275 bool isRelational); 5276 QualType CheckBitwiseOperands( // C99 6.5.[10...12] 5277 ExprResult &lex, ExprResult &rex, SourceLocation OpLoc, bool isCompAssign = false); 5278 QualType CheckLogicalOperands( // C99 6.5.[13,14] 5279 ExprResult &lex, ExprResult &rex, SourceLocation OpLoc, unsigned Opc); 5280 // CheckAssignmentOperands is used for both simple and compound assignment. 5281 // For simple assignment, pass both expressions and a null converted type. 5282 // For compound assignment, pass both expressions and the converted type. 5283 QualType CheckAssignmentOperands( // C99 6.5.16.[1,2] 5284 Expr *lex, ExprResult &rex, SourceLocation OpLoc, QualType convertedType); 5285 5286 void ConvertPropertyForLValue(ExprResult &LHS, ExprResult &RHS, QualType& LHSTy); 5287 ExprResult ConvertPropertyForRValue(Expr *E); 5288 5289 QualType CheckConditionalOperands( // C99 6.5.15 5290 ExprResult &cond, ExprResult &lhs, ExprResult &rhs, 5291 ExprValueKind &VK, ExprObjectKind &OK, SourceLocation questionLoc); 5292 QualType CXXCheckConditionalOperands( // C++ 5.16 5293 ExprResult &cond, ExprResult &lhs, ExprResult &rhs, 5294 ExprValueKind &VK, ExprObjectKind &OK, SourceLocation questionLoc); 5295 QualType FindCompositePointerType(SourceLocation Loc, Expr *&E1, Expr *&E2, 5296 bool *NonStandardCompositeType = 0); 5297 QualType FindCompositePointerType(SourceLocation Loc, ExprResult &E1, ExprResult &E2, 5298 bool *NonStandardCompositeType = 0) { 5299 Expr *E1Tmp = E1.take(), *E2Tmp = E2.take(); 5300 QualType Composite = FindCompositePointerType(Loc, E1Tmp, E2Tmp, NonStandardCompositeType); 5301 E1 = Owned(E1Tmp); 5302 E2 = Owned(E2Tmp); 5303 return Composite; 5304 } 5305 5306 QualType FindCompositeObjCPointerType(ExprResult &LHS, ExprResult &RHS, 5307 SourceLocation questionLoc); 5308 5309 bool DiagnoseConditionalForNull(Expr *LHS, Expr *RHS, 5310 SourceLocation QuestionLoc); 5311 5312 /// type checking for vector binary operators. 5313 QualType CheckVectorOperands(SourceLocation l, ExprResult &lex, ExprResult &rex); 5314 QualType CheckVectorCompareOperands(ExprResult &lex, ExprResult &rx, 5315 SourceLocation l, bool isRel); 5316 5317 /// type checking declaration initializers (C99 6.7.8) 5318 bool CheckInitList(const InitializedEntity &Entity, 5319 InitListExpr *&InitList, QualType &DeclType); 5320 bool CheckForConstantInitializer(Expr *e, QualType t); 5321 5322 // type checking C++ declaration initializers (C++ [dcl.init]). 5323 5324 /// ReferenceCompareResult - Expresses the result of comparing two 5325 /// types (cv1 T1 and cv2 T2) to determine their compatibility for the 5326 /// purposes of initialization by reference (C++ [dcl.init.ref]p4). 5327 enum ReferenceCompareResult { 5328 /// Ref_Incompatible - The two types are incompatible, so direct 5329 /// reference binding is not possible. 5330 Ref_Incompatible = 0, 5331 /// Ref_Related - The two types are reference-related, which means 5332 /// that their unqualified forms (T1 and T2) are either the same 5333 /// or T1 is a base class of T2. 5334 Ref_Related, 5335 /// Ref_Compatible_With_Added_Qualification - The two types are 5336 /// reference-compatible with added qualification, meaning that 5337 /// they are reference-compatible and the qualifiers on T1 (cv1) 5338 /// are greater than the qualifiers on T2 (cv2). 5339 Ref_Compatible_With_Added_Qualification, 5340 /// Ref_Compatible - The two types are reference-compatible and 5341 /// have equivalent qualifiers (cv1 == cv2). 5342 Ref_Compatible 5343 }; 5344 5345 ReferenceCompareResult CompareReferenceRelationship(SourceLocation Loc, 5346 QualType T1, QualType T2, 5347 bool &DerivedToBase, 5348 bool &ObjCConversion); 5349 5350 /// CheckCastTypes - Check type constraints for casting between types under 5351 /// C semantics, or forward to CXXCheckCStyleCast in C++. 5352 ExprResult CheckCastTypes(SourceRange TyRange, QualType CastTy, Expr *CastExpr, 5353 CastKind &Kind, ExprValueKind &VK, CXXCastPath &BasePath, 5354 bool FunctionalStyle = false); 5355 5356 ExprResult checkUnknownAnyCast(SourceRange TyRange, QualType castType, 5357 Expr *castExpr, CastKind &castKind, 5358 ExprValueKind &valueKind, CXXCastPath &BasePath); 5359 5360 // CheckVectorCast - check type constraints for vectors. 5361 // Since vectors are an extension, there are no C standard reference for this. 5362 // We allow casting between vectors and integer datatypes of the same size. 5363 // returns true if the cast is invalid 5364 bool CheckVectorCast(SourceRange R, QualType VectorTy, QualType Ty, 5365 CastKind &Kind); 5366 5367 // CheckExtVectorCast - check type constraints for extended vectors. 5368 // Since vectors are an extension, there are no C standard reference for this. 5369 // We allow casting between vectors and integer datatypes of the same size, 5370 // or vectors and the element type of that vector. 5371 // returns the cast expr 5372 ExprResult CheckExtVectorCast(SourceRange R, QualType VectorTy, Expr *CastExpr, 5373 CastKind &Kind); 5374 5375 /// CXXCheckCStyleCast - Check constraints of a C-style or function-style 5376 /// cast under C++ semantics. 5377 ExprResult CXXCheckCStyleCast(SourceRange R, QualType CastTy, ExprValueKind &VK, 5378 Expr *CastExpr, CastKind &Kind, 5379 CXXCastPath &BasePath, bool FunctionalStyle); 5380 5381 /// CheckMessageArgumentTypes - Check types in an Obj-C message send. 5382 /// \param Method - May be null. 5383 /// \param [out] ReturnType - The return type of the send. 5384 /// \return true iff there were any incompatible types. 5385 bool CheckMessageArgumentTypes(Expr **Args, unsigned NumArgs, Selector Sel, 5386 ObjCMethodDecl *Method, bool isClassMessage, 5387 SourceLocation lbrac, SourceLocation rbrac, 5388 QualType &ReturnType, ExprValueKind &VK); 5389 5390 /// CheckBooleanCondition - Diagnose problems involving the use of 5391 /// the given expression as a boolean condition (e.g. in an if 5392 /// statement). Also performs the standard function and array 5393 /// decays, possibly changing the input variable. 5394 /// 5395 /// \param Loc - A location associated with the condition, e.g. the 5396 /// 'if' keyword. 5397 /// \return true iff there were any errors 5398 ExprResult CheckBooleanCondition(Expr *CondExpr, SourceLocation Loc); 5399 5400 ExprResult ActOnBooleanCondition(Scope *S, SourceLocation Loc, 5401 Expr *SubExpr); 5402 5403 /// DiagnoseAssignmentAsCondition - Given that an expression is 5404 /// being used as a boolean condition, warn if it's an assignment. 5405 void DiagnoseAssignmentAsCondition(Expr *E); 5406 5407 /// \brief Redundant parentheses over an equality comparison can indicate 5408 /// that the user intended an assignment used as condition. 5409 void DiagnoseEqualityWithExtraParens(ParenExpr *parenE); 5410 5411 /// CheckCXXBooleanCondition - Returns true if conversion to bool is invalid. 5412 ExprResult CheckCXXBooleanCondition(Expr *CondExpr); 5413 5414 /// ConvertIntegerToTypeWarnOnOverflow - Convert the specified APInt to have 5415 /// the specified width and sign. If an overflow occurs, detect it and emit 5416 /// the specified diagnostic. 5417 void ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &OldVal, 5418 unsigned NewWidth, bool NewSign, 5419 SourceLocation Loc, unsigned DiagID); 5420 5421 /// Checks that the Objective-C declaration is declared in the global scope. 5422 /// Emits an error and marks the declaration as invalid if it's not declared 5423 /// in the global scope. 5424 bool CheckObjCDeclScope(Decl *D); 5425 5426 /// VerifyIntegerConstantExpression - verifies that an expression is an ICE, 5427 /// and reports the appropriate diagnostics. Returns false on success. 5428 /// Can optionally return the value of the expression. 5429 bool VerifyIntegerConstantExpression(const Expr *E, llvm::APSInt *Result = 0); 5430 5431 /// VerifyBitField - verifies that a bit field expression is an ICE and has 5432 /// the correct width, and that the field type is valid. 5433 /// Returns false on success. 5434 /// Can optionally return whether the bit-field is of width 0 5435 bool VerifyBitField(SourceLocation FieldLoc, IdentifierInfo *FieldName, 5436 QualType FieldTy, const Expr *BitWidth, 5437 bool *ZeroWidth = 0); 5438 5439 /// \name Code completion 5440 //@{ 5441 /// \brief Describes the context in which code completion occurs. 5442 enum ParserCompletionContext { 5443 /// \brief Code completion occurs at top-level or namespace context. 5444 PCC_Namespace, 5445 /// \brief Code completion occurs within a class, struct, or union. 5446 PCC_Class, 5447 /// \brief Code completion occurs within an Objective-C interface, protocol, 5448 /// or category. 5449 PCC_ObjCInterface, 5450 /// \brief Code completion occurs within an Objective-C implementation or 5451 /// category implementation 5452 PCC_ObjCImplementation, 5453 /// \brief Code completion occurs within the list of instance variables 5454 /// in an Objective-C interface, protocol, category, or implementation. 5455 PCC_ObjCInstanceVariableList, 5456 /// \brief Code completion occurs following one or more template 5457 /// headers. 5458 PCC_Template, 5459 /// \brief Code completion occurs following one or more template 5460 /// headers within a class. 5461 PCC_MemberTemplate, 5462 /// \brief Code completion occurs within an expression. 5463 PCC_Expression, 5464 /// \brief Code completion occurs within a statement, which may 5465 /// also be an expression or a declaration. 5466 PCC_Statement, 5467 /// \brief Code completion occurs at the beginning of the 5468 /// initialization statement (or expression) in a for loop. 5469 PCC_ForInit, 5470 /// \brief Code completion occurs within the condition of an if, 5471 /// while, switch, or for statement. 5472 PCC_Condition, 5473 /// \brief Code completion occurs within the body of a function on a 5474 /// recovery path, where we do not have a specific handle on our position 5475 /// in the grammar. 5476 PCC_RecoveryInFunction, 5477 /// \brief Code completion occurs where only a type is permitted. 5478 PCC_Type, 5479 /// \brief Code completion occurs in a parenthesized expression, which 5480 /// might also be a type cast. 5481 PCC_ParenthesizedExpression, 5482 /// \brief Code completion occurs within a sequence of declaration 5483 /// specifiers within a function, method, or block. 5484 PCC_LocalDeclarationSpecifiers 5485 }; 5486 5487 void CodeCompleteOrdinaryName(Scope *S, 5488 ParserCompletionContext CompletionContext); 5489 void CodeCompleteDeclSpec(Scope *S, DeclSpec &DS, 5490 bool AllowNonIdentifiers, 5491 bool AllowNestedNameSpecifiers); 5492 5493 struct CodeCompleteExpressionData; 5494 void CodeCompleteExpression(Scope *S, 5495 const CodeCompleteExpressionData &Data); 5496 void CodeCompleteMemberReferenceExpr(Scope *S, Expr *Base, 5497 SourceLocation OpLoc, 5498 bool IsArrow); 5499 void CodeCompletePostfixExpression(Scope *S, ExprResult LHS); 5500 void CodeCompleteTag(Scope *S, unsigned TagSpec); 5501 void CodeCompleteTypeQualifiers(DeclSpec &DS); 5502 void CodeCompleteCase(Scope *S); 5503 void CodeCompleteCall(Scope *S, Expr *Fn, Expr **Args, unsigned NumArgs); 5504 void CodeCompleteInitializer(Scope *S, Decl *D); 5505 void CodeCompleteReturn(Scope *S); 5506 void CodeCompleteAssignmentRHS(Scope *S, Expr *LHS); 5507 5508 void CodeCompleteQualifiedId(Scope *S, CXXScopeSpec &SS, 5509 bool EnteringContext); 5510 void CodeCompleteUsing(Scope *S); 5511 void CodeCompleteUsingDirective(Scope *S); 5512 void CodeCompleteNamespaceDecl(Scope *S); 5513 void CodeCompleteNamespaceAliasDecl(Scope *S); 5514 void CodeCompleteOperatorName(Scope *S); 5515 void CodeCompleteConstructorInitializer(Decl *Constructor, 5516 CXXCtorInitializer** Initializers, 5517 unsigned NumInitializers); 5518 5519 void CodeCompleteObjCAtDirective(Scope *S, Decl *ObjCImpDecl, 5520 bool InInterface); 5521 void CodeCompleteObjCAtVisibility(Scope *S); 5522 void CodeCompleteObjCAtStatement(Scope *S); 5523 void CodeCompleteObjCAtExpression(Scope *S); 5524 void CodeCompleteObjCPropertyFlags(Scope *S, ObjCDeclSpec &ODS); 5525 void CodeCompleteObjCPropertyGetter(Scope *S, Decl *ClassDecl); 5526 void CodeCompleteObjCPropertySetter(Scope *S, Decl *ClassDecl); 5527 void CodeCompleteObjCPassingType(Scope *S, ObjCDeclSpec &DS, 5528 bool IsParameter); 5529 void CodeCompleteObjCMessageReceiver(Scope *S); 5530 void CodeCompleteObjCSuperMessage(Scope *S, SourceLocation SuperLoc, 5531 IdentifierInfo **SelIdents, 5532 unsigned NumSelIdents, 5533 bool AtArgumentExpression); 5534 void CodeCompleteObjCClassMessage(Scope *S, ParsedType Receiver, 5535 IdentifierInfo **SelIdents, 5536 unsigned NumSelIdents, 5537 bool AtArgumentExpression, 5538 bool IsSuper = false); 5539 void CodeCompleteObjCInstanceMessage(Scope *S, ExprTy *Receiver, 5540 IdentifierInfo **SelIdents, 5541 unsigned NumSelIdents, 5542 bool AtArgumentExpression, 5543 ObjCInterfaceDecl *Super = 0); 5544 void CodeCompleteObjCForCollection(Scope *S, 5545 DeclGroupPtrTy IterationVar); 5546 void CodeCompleteObjCSelector(Scope *S, 5547 IdentifierInfo **SelIdents, 5548 unsigned NumSelIdents); 5549 void CodeCompleteObjCProtocolReferences(IdentifierLocPair *Protocols, 5550 unsigned NumProtocols); 5551 void CodeCompleteObjCProtocolDecl(Scope *S); 5552 void CodeCompleteObjCInterfaceDecl(Scope *S); 5553 void CodeCompleteObjCSuperclass(Scope *S, 5554 IdentifierInfo *ClassName, 5555 SourceLocation ClassNameLoc); 5556 void CodeCompleteObjCImplementationDecl(Scope *S); 5557 void CodeCompleteObjCInterfaceCategory(Scope *S, 5558 IdentifierInfo *ClassName, 5559 SourceLocation ClassNameLoc); 5560 void CodeCompleteObjCImplementationCategory(Scope *S, 5561 IdentifierInfo *ClassName, 5562 SourceLocation ClassNameLoc); 5563 void CodeCompleteObjCPropertyDefinition(Scope *S, Decl *ObjCImpDecl); 5564 void CodeCompleteObjCPropertySynthesizeIvar(Scope *S, 5565 IdentifierInfo *PropertyName, 5566 Decl *ObjCImpDecl); 5567 void CodeCompleteObjCMethodDecl(Scope *S, 5568 bool IsInstanceMethod, 5569 ParsedType ReturnType, 5570 Decl *IDecl); 5571 void CodeCompleteObjCMethodDeclSelector(Scope *S, 5572 bool IsInstanceMethod, 5573 bool AtParameterName, 5574 ParsedType ReturnType, 5575 IdentifierInfo **SelIdents, 5576 unsigned NumSelIdents); 5577 void CodeCompletePreprocessorDirective(bool InConditional); 5578 void CodeCompleteInPreprocessorConditionalExclusion(Scope *S); 5579 void CodeCompletePreprocessorMacroName(bool IsDefinition); 5580 void CodeCompletePreprocessorExpression(); 5581 void CodeCompletePreprocessorMacroArgument(Scope *S, 5582 IdentifierInfo *Macro, 5583 MacroInfo *MacroInfo, 5584 unsigned Argument); 5585 void CodeCompleteNaturalLanguage(); 5586 void GatherGlobalCodeCompletions(CodeCompletionAllocator &Allocator, 5587 llvm::SmallVectorImpl<CodeCompletionResult> &Results); 5588 //@} 5589 5590 void PrintStats() const {} 5591 5592 //===--------------------------------------------------------------------===// 5593 // Extra semantic analysis beyond the C type system 5594 5595public: 5596 SourceLocation getLocationOfStringLiteralByte(const StringLiteral *SL, 5597 unsigned ByteNo) const; 5598 5599private: 5600 void CheckArrayAccess(const Expr *E); 5601 bool CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall); 5602 bool CheckBlockCall(NamedDecl *NDecl, CallExpr *TheCall); 5603 5604 bool CheckablePrintfAttr(const FormatAttr *Format, CallExpr *TheCall); 5605 bool CheckObjCString(Expr *Arg); 5606 5607 ExprResult CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); 5608 bool CheckARMBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); 5609 5610 bool SemaBuiltinVAStart(CallExpr *TheCall); 5611 bool SemaBuiltinUnorderedCompare(CallExpr *TheCall); 5612 bool SemaBuiltinFPClassification(CallExpr *TheCall, unsigned NumArgs); 5613 5614public: 5615 // Used by C++ template instantiation. 5616 ExprResult SemaBuiltinShuffleVector(CallExpr *TheCall); 5617 5618private: 5619 bool SemaBuiltinPrefetch(CallExpr *TheCall); 5620 bool SemaBuiltinObjectSize(CallExpr *TheCall); 5621 bool SemaBuiltinLongjmp(CallExpr *TheCall); 5622 ExprResult SemaBuiltinAtomicOverloaded(ExprResult TheCallResult); 5623 bool SemaBuiltinConstantArg(CallExpr *TheCall, int ArgNum, 5624 llvm::APSInt &Result); 5625 5626 bool SemaCheckStringLiteral(const Expr *E, const CallExpr *TheCall, 5627 bool HasVAListArg, unsigned format_idx, 5628 unsigned firstDataArg, bool isPrintf); 5629 5630 void CheckFormatString(const StringLiteral *FExpr, const Expr *OrigFormatExpr, 5631 const CallExpr *TheCall, bool HasVAListArg, 5632 unsigned format_idx, unsigned firstDataArg, 5633 bool isPrintf); 5634 5635 void CheckNonNullArguments(const NonNullAttr *NonNull, 5636 const Expr * const *ExprArgs, 5637 SourceLocation CallSiteLoc); 5638 5639 void CheckPrintfScanfArguments(const CallExpr *TheCall, bool HasVAListArg, 5640 unsigned format_idx, unsigned firstDataArg, 5641 bool isPrintf); 5642 5643 void CheckMemsetcpymoveArguments(const CallExpr *Call, 5644 const IdentifierInfo *FnName); 5645 5646 void CheckReturnStackAddr(Expr *RetValExp, QualType lhsType, 5647 SourceLocation ReturnLoc); 5648 void CheckFloatComparison(SourceLocation loc, Expr* lex, Expr* rex); 5649 void CheckImplicitConversions(Expr *E, SourceLocation CC = SourceLocation()); 5650 5651 void CheckBitFieldInitialization(SourceLocation InitLoc, FieldDecl *Field, 5652 Expr *Init); 5653 5654 /// \brief The parser's current scope. 5655 /// 5656 /// The parser maintains this state here. 5657 Scope *CurScope; 5658 5659protected: 5660 friend class Parser; 5661 friend class InitializationSequence; 5662 5663 /// \brief Retrieve the parser's current scope. 5664 Scope *getCurScope() const { return CurScope; } 5665}; 5666 5667/// \brief RAII object that enters a new expression evaluation context. 5668class EnterExpressionEvaluationContext { 5669 Sema &Actions; 5670 5671public: 5672 EnterExpressionEvaluationContext(Sema &Actions, 5673 Sema::ExpressionEvaluationContext NewContext) 5674 : Actions(Actions) { 5675 Actions.PushExpressionEvaluationContext(NewContext); 5676 } 5677 5678 ~EnterExpressionEvaluationContext() { 5679 Actions.PopExpressionEvaluationContext(); 5680 } 5681}; 5682 5683} // end namespace clang 5684 5685#endif 5686