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