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