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