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