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