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