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