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