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