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