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