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