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