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