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