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