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