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