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