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