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