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