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