1 //===--- Sema.h - Semantic Analysis & AST Building --------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This file defines the Sema class, which performs semantic analysis and 11 // builds ASTs. 12 // 13 //===----------------------------------------------------------------------===// 14 15 #ifndef LLVM_CLANG_SEMA_SEMA_H 16 #define LLVM_CLANG_SEMA_SEMA_H 17 18 #include "clang/Sema/Ownership.h" 19 #include "clang/Sema/AnalysisBasedWarnings.h" 20 #include "clang/Sema/IdentifierResolver.h" 21 #include "clang/Sema/ObjCMethodList.h" 22 #include "clang/Sema/DeclSpec.h" 23 #include "clang/Sema/ExternalSemaSource.h" 24 #include "clang/Sema/LocInfoType.h" 25 #include "clang/Sema/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 45 namespace llvm { 46 class APSInt; 47 template <typename ValueT> struct DenseMapInfo; 48 template <typename ValueT, typename ValueInfoT> class DenseSet; 49 class SmallBitVector; 50 } 51 52 namespace 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 167 namespace 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. 180 typedef std::pair<llvm::PointerUnion<const TemplateTypeParmType*, NamedDecl*>, 181 SourceLocation> UnexpandedParameterPack; 182 183 /// Sema - This implements semantic analysis and AST building for C. 184 class Sema { 185 Sema(const Sema&); // DO NOT IMPLEMENT 186 void operator=(const Sema&); // DO NOT IMPLEMENT 187 mutable const TargetAttributesSema* TheTargetAttributesSema; 188 public: 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 bit of the 669 /// integer is used to determine whether we have a parameter qualification 670 /// match, the second-lowest is whether we had success in resolving the 671 /// overload to a unique non-deleted function. 672 /// 673 /// The ConstParamMatch bit represents whether, when looking up a copy 674 /// constructor or assignment operator, we found a potential copy 675 /// constructor/assignment operator whose first parameter is const-qualified. 676 /// This is used for determining parameter types of other objects and is 677 /// utterly meaningless on other types of special members. 678 class SpecialMemberOverloadResult : public llvm::FastFoldingSetNode { 679 public: 680 enum Kind { 681 NoMemberOrDeleted, 682 Ambiguous, 683 SuccessNonConst, 684 SuccessConst 685 }; 686 687 private: 688 llvm::PointerIntPair<CXXMethodDecl*, 2> Pair; 689 690 public: 691 SpecialMemberOverloadResult(const llvm::FoldingSetNodeID &ID) 692 : FastFoldingSetNode(ID) 693 {} 694 695 CXXMethodDecl *getMethod() const { return Pair.getPointer(); } 696 void setMethod(CXXMethodDecl *MD) { Pair.setPointer(MD); } 697 698 Kind getKind() const { return static_cast<Kind>(Pair.getInt()); } 699 void setKind(Kind K) { Pair.setInt(K); } 700 701 bool hasSuccess() const { return getKind() >= SuccessNonConst; } 702 bool hasConstParamMatch() const { return getKind() == SuccessConst; } 703 }; 704 705 /// \brief A cache of special member function overload resolution results 706 /// for C++ records. 707 llvm::FoldingSet<SpecialMemberOverloadResult> SpecialMemberCache; 708 709 /// \brief The kind of translation unit we are processing. 710 /// 711 /// When we're processing a complete translation unit, Sema will perform 712 /// end-of-translation-unit semantic tasks (such as creating 713 /// initializers for tentative definitions in C) once parsing has 714 /// completed. Modules and precompiled headers perform different kinds of 715 /// checks. 716 TranslationUnitKind TUKind; 717 718 llvm::BumpPtrAllocator BumpAlloc; 719 720 /// \brief The number of SFINAE diagnostics that have been trapped. 721 unsigned NumSFINAEErrors; 722 723 typedef llvm::DenseMap<ParmVarDecl *, SmallVector<ParmVarDecl *, 1> > 724 UnparsedDefaultArgInstantiationsMap; 725 726 /// \brief A mapping from parameters with unparsed default arguments to the 727 /// set of instantiations of each parameter. 728 /// 729 /// This mapping is a temporary data structure used when parsing 730 /// nested class templates or nested classes of class templates, 731 /// where we might end up instantiating an inner class before the 732 /// default arguments of its methods have been parsed. 733 UnparsedDefaultArgInstantiationsMap UnparsedDefaultArgInstantiations; 734 735 // Contains the locations of the beginning of unparsed default 736 // argument locations. 737 llvm::DenseMap<ParmVarDecl *,SourceLocation> UnparsedDefaultArgLocs; 738 739 /// UndefinedInternals - all the used, undefined objects with 740 /// internal linkage in this translation unit. 741 llvm::DenseMap<NamedDecl*, SourceLocation> UndefinedInternals; 742 743 typedef std::pair<ObjCMethodList, ObjCMethodList> GlobalMethods; 744 typedef llvm::DenseMap<Selector, GlobalMethods> GlobalMethodPool; 745 746 /// Method Pool - allows efficient lookup when typechecking messages to "id". 747 /// We need to maintain a list, since selectors can have differing signatures 748 /// across classes. In Cocoa, this happens to be extremely uncommon (only 1% 749 /// of selectors are "overloaded"). 750 GlobalMethodPool MethodPool; 751 752 /// Method selectors used in a @selector expression. Used for implementation 753 /// of -Wselector. 754 llvm::DenseMap<Selector, SourceLocation> ReferencedSelectors; 755 756 void ReadMethodPool(Selector Sel); 757 758 /// Private Helper predicate to check for 'self'. 759 bool isSelfExpr(Expr *RExpr); 760 761 /// \brief Cause the active diagnostic on the DiagosticsEngine to be 762 /// emitted. This is closely coupled to the SemaDiagnosticBuilder class and 763 /// should not be used elsewhere. 764 void EmitCurrentDiagnostic(unsigned DiagID); 765 766 public: 767 Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer, 768 TranslationUnitKind TUKind = TU_Complete, 769 CodeCompleteConsumer *CompletionConsumer = 0); 770 ~Sema(); 771 772 /// \brief Perform initialization that occurs after the parser has been 773 /// initialized but before it parses anything. 774 void Initialize(); 775 776 const LangOptions &getLangOpts() const { return LangOpts; } 777 OpenCLOptions &getOpenCLOptions() { return OpenCLFeatures; } 778 FPOptions &getFPOptions() { return FPFeatures; } 779 780 DiagnosticsEngine &getDiagnostics() const { return Diags; } 781 SourceManager &getSourceManager() const { return SourceMgr; } 782 const TargetAttributesSema &getTargetAttributesSema() const; 783 Preprocessor &getPreprocessor() const { return PP; } 784 ASTContext &getASTContext() const { return Context; } 785 ASTConsumer &getASTConsumer() const { return Consumer; } 786 ASTMutationListener *getASTMutationListener() const; 787 788 void PrintStats() const; 789 790 /// \brief Helper class that creates diagnostics with optional 791 /// template instantiation stacks. 792 /// 793 /// This class provides a wrapper around the basic DiagnosticBuilder 794 /// class that emits diagnostics. SemaDiagnosticBuilder is 795 /// responsible for emitting the diagnostic (as DiagnosticBuilder 796 /// does) and, if the diagnostic comes from inside a template 797 /// instantiation, printing the template instantiation stack as 798 /// well. 799 class SemaDiagnosticBuilder : public DiagnosticBuilder { 800 Sema &SemaRef; 801 unsigned DiagID; 802 803 public: 804 SemaDiagnosticBuilder(DiagnosticBuilder &DB, Sema &SemaRef, unsigned DiagID) 805 : DiagnosticBuilder(DB), SemaRef(SemaRef), DiagID(DiagID) { } 806 807 ~SemaDiagnosticBuilder() { 808 // If we aren't active, there is nothing to do. 809 if (!isActive()) return; 810 811 // Otherwise, we need to emit the diagnostic. First flush the underlying 812 // DiagnosticBuilder data, and clear the diagnostic builder itself so it 813 // won't emit the diagnostic in its own destructor. 814 // 815 // This seems wasteful, in that as written the DiagnosticBuilder dtor will 816 // do its own needless checks to see if the diagnostic needs to be 817 // emitted. However, because we take care to ensure that the builder 818 // objects never escape, a sufficiently smart compiler will be able to 819 // eliminate that code. 820 FlushCounts(); 821 Clear(); 822 823 // Dispatch to Sema to emit the diagnostic. 824 SemaRef.EmitCurrentDiagnostic(DiagID); 825 } 826 }; 827 828 /// \brief Emit a diagnostic. 829 SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) { 830 DiagnosticBuilder DB = Diags.Report(Loc, DiagID); 831 return SemaDiagnosticBuilder(DB, *this, DiagID); 832 } 833 834 /// \brief Emit a partial diagnostic. 835 SemaDiagnosticBuilder Diag(SourceLocation Loc, const PartialDiagnostic& PD); 836 837 /// \brief Build a partial diagnostic. 838 PartialDiagnostic PDiag(unsigned DiagID = 0); // in SemaInternal.h 839 840 bool findMacroSpelling(SourceLocation &loc, StringRef name); 841 842 /// \brief Get a string to suggest for zero-initialization of a type. 843 const char *getFixItZeroInitializerForType(QualType T) const; 844 845 ExprResult Owned(Expr* E) { return E; } 846 ExprResult Owned(ExprResult R) { return R; } 847 StmtResult Owned(Stmt* S) { return S; } 848 849 void ActOnEndOfTranslationUnit(); 850 851 void CheckDelegatingCtorCycles(); 852 853 Scope *getScopeForContext(DeclContext *Ctx); 854 855 void PushFunctionScope(); 856 void PushBlockScope(Scope *BlockScope, BlockDecl *Block); 857 void PushLambdaScope(CXXRecordDecl *Lambda, CXXMethodDecl *CallOperator); 858 void PopFunctionScopeInfo(const sema::AnalysisBasedWarnings::Policy *WP =0, 859 const Decl *D = 0, const BlockExpr *blkExpr = 0); 860 861 sema::FunctionScopeInfo *getCurFunction() const { 862 return FunctionScopes.back(); 863 } 864 865 void PushCompoundScope(); 866 void PopCompoundScope(); 867 868 sema::CompoundScopeInfo &getCurCompoundScope() const; 869 870 bool hasAnyUnrecoverableErrorsInThisFunction() const; 871 872 /// \brief Retrieve the current block, if any. 873 sema::BlockScopeInfo *getCurBlock(); 874 875 /// \brief Retrieve the current lambda expression, if any. 876 sema::LambdaScopeInfo *getCurLambda(); 877 878 /// WeakTopLevelDeclDecls - access to #pragma weak-generated Decls 879 SmallVector<Decl*,2> &WeakTopLevelDecls() { return WeakTopLevelDecl; } 880 881 //===--------------------------------------------------------------------===// 882 // Type Analysis / Processing: SemaType.cpp. 883 // 884 885 QualType BuildQualifiedType(QualType T, SourceLocation Loc, Qualifiers Qs); 886 QualType BuildQualifiedType(QualType T, SourceLocation Loc, unsigned CVR) { 887 return BuildQualifiedType(T, Loc, Qualifiers::fromCVRMask(CVR)); 888 } 889 QualType BuildPointerType(QualType T, 890 SourceLocation Loc, DeclarationName Entity); 891 QualType BuildReferenceType(QualType T, bool LValueRef, 892 SourceLocation Loc, DeclarationName Entity); 893 QualType BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM, 894 Expr *ArraySize, unsigned Quals, 895 SourceRange Brackets, DeclarationName Entity); 896 QualType BuildExtVectorType(QualType T, Expr *ArraySize, 897 SourceLocation AttrLoc); 898 QualType BuildFunctionType(QualType T, 899 QualType *ParamTypes, unsigned NumParamTypes, 900 bool Variadic, bool HasTrailingReturn, 901 unsigned Quals, RefQualifierKind RefQualifier, 902 SourceLocation Loc, DeclarationName Entity, 903 FunctionType::ExtInfo Info); 904 QualType BuildMemberPointerType(QualType T, QualType Class, 905 SourceLocation Loc, 906 DeclarationName Entity); 907 QualType BuildBlockPointerType(QualType T, 908 SourceLocation Loc, DeclarationName Entity); 909 QualType BuildParenType(QualType T); 910 QualType BuildAtomicType(QualType T, SourceLocation Loc); 911 912 TypeSourceInfo *GetTypeForDeclarator(Declarator &D, Scope *S); 913 TypeSourceInfo *GetTypeForDeclaratorCast(Declarator &D, QualType FromTy); 914 TypeSourceInfo *GetTypeSourceInfoForDeclarator(Declarator &D, QualType T, 915 TypeSourceInfo *ReturnTypeInfo); 916 917 /// \brief Package the given type and TSI into a ParsedType. 918 ParsedType CreateParsedType(QualType T, TypeSourceInfo *TInfo); 919 DeclarationNameInfo GetNameForDeclarator(Declarator &D); 920 DeclarationNameInfo GetNameFromUnqualifiedId(const UnqualifiedId &Name); 921 static QualType GetTypeFromParser(ParsedType Ty, TypeSourceInfo **TInfo = 0); 922 CanThrowResult canThrow(const Expr *E); 923 const FunctionProtoType *ResolveExceptionSpec(SourceLocation Loc, 924 const FunctionProtoType *FPT); 925 bool CheckSpecifiedExceptionType(QualType T, const SourceRange &Range); 926 bool CheckDistantExceptionSpec(QualType T); 927 bool CheckEquivalentExceptionSpec(FunctionDecl *Old, FunctionDecl *New); 928 bool CheckEquivalentExceptionSpec( 929 const FunctionProtoType *Old, SourceLocation OldLoc, 930 const FunctionProtoType *New, SourceLocation NewLoc); 931 bool CheckEquivalentExceptionSpec( 932 const PartialDiagnostic &DiagID, const PartialDiagnostic & NoteID, 933 const FunctionProtoType *Old, SourceLocation OldLoc, 934 const FunctionProtoType *New, SourceLocation NewLoc, 935 bool *MissingExceptionSpecification = 0, 936 bool *MissingEmptyExceptionSpecification = 0, 937 bool AllowNoexceptAllMatchWithNoSpec = false, 938 bool IsOperatorNew = false); 939 bool CheckExceptionSpecSubset( 940 const PartialDiagnostic &DiagID, const PartialDiagnostic & NoteID, 941 const FunctionProtoType *Superset, SourceLocation SuperLoc, 942 const FunctionProtoType *Subset, SourceLocation SubLoc); 943 bool CheckParamExceptionSpec(const PartialDiagnostic & NoteID, 944 const FunctionProtoType *Target, SourceLocation TargetLoc, 945 const FunctionProtoType *Source, SourceLocation SourceLoc); 946 947 TypeResult ActOnTypeName(Scope *S, Declarator &D); 948 949 /// \brief The parser has parsed the context-sensitive type 'instancetype' 950 /// in an Objective-C message declaration. Return the appropriate type. 951 ParsedType ActOnObjCInstanceType(SourceLocation Loc); 952 953 bool RequireCompleteType(SourceLocation Loc, QualType T, 954 const PartialDiagnostic &PD, 955 std::pair<SourceLocation, PartialDiagnostic> Note); 956 bool RequireCompleteType(SourceLocation Loc, QualType T, 957 const PartialDiagnostic &PD); 958 bool RequireCompleteType(SourceLocation Loc, QualType T, 959 unsigned DiagID); 960 bool RequireCompleteExprType(Expr *E, const PartialDiagnostic &PD, 961 std::pair<SourceLocation, 962 PartialDiagnostic> Note); 963 964 bool RequireLiteralType(SourceLocation Loc, QualType T, 965 const PartialDiagnostic &PD); 966 967 QualType getElaboratedType(ElaboratedTypeKeyword Keyword, 968 const CXXScopeSpec &SS, QualType T); 969 970 QualType BuildTypeofExprType(Expr *E, SourceLocation Loc); 971 QualType BuildDecltypeType(Expr *E, SourceLocation Loc); 972 QualType BuildUnaryTransformType(QualType BaseType, 973 UnaryTransformType::UTTKind UKind, 974 SourceLocation Loc); 975 976 //===--------------------------------------------------------------------===// 977 // Symbol table / Decl tracking callbacks: SemaDecl.cpp. 978 // 979 980 /// List of decls defined in a function prototype. This contains EnumConstants 981 /// that incorrectly end up in translation unit scope because there is no 982 /// function to pin them on. ActOnFunctionDeclarator reads this list and patches 983 /// them into the FunctionDecl. 984 std::vector<NamedDecl*> DeclsInPrototypeScope; 985 /// Nonzero if we are currently parsing a function declarator. This is a counter 986 /// as opposed to a boolean so we can deal with nested function declarators 987 /// such as: 988 /// void f(void (*g)(), ...) 989 unsigned InFunctionDeclarator; 990 991 DeclGroupPtrTy ConvertDeclToDeclGroup(Decl *Ptr, Decl *OwnedType = 0); 992 993 void DiagnoseUseOfUnimplementedSelectors(); 994 995 ParsedType getTypeName(IdentifierInfo &II, SourceLocation NameLoc, 996 Scope *S, CXXScopeSpec *SS = 0, 997 bool isClassName = false, 998 bool HasTrailingDot = false, 999 ParsedType ObjectType = ParsedType(), 1000 bool IsCtorOrDtorName = false, 1001 bool WantNontrivialTypeSourceInfo = false, 1002 IdentifierInfo **CorrectedII = 0); 1003 TypeSpecifierType isTagName(IdentifierInfo &II, Scope *S); 1004 bool isMicrosoftMissingTypename(const CXXScopeSpec *SS, Scope *S); 1005 bool DiagnoseUnknownTypeName(const IdentifierInfo &II, 1006 SourceLocation IILoc, 1007 Scope *S, 1008 CXXScopeSpec *SS, 1009 ParsedType &SuggestedType); 1010 1011 /// \brief Describes the result of the name lookup and resolution performed 1012 /// by \c ClassifyName(). 1013 enum NameClassificationKind { 1014 NC_Unknown, 1015 NC_Error, 1016 NC_Keyword, 1017 NC_Type, 1018 NC_Expression, 1019 NC_NestedNameSpecifier, 1020 NC_TypeTemplate, 1021 NC_FunctionTemplate 1022 }; 1023 1024 class NameClassification { 1025 NameClassificationKind Kind; 1026 ExprResult Expr; 1027 TemplateName Template; 1028 ParsedType Type; 1029 const IdentifierInfo *Keyword; 1030 1031 explicit NameClassification(NameClassificationKind Kind) : Kind(Kind) {} 1032 1033 public: 1034 NameClassification(ExprResult Expr) : Kind(NC_Expression), Expr(Expr) {} 1035 1036 NameClassification(ParsedType Type) : Kind(NC_Type), Type(Type) {} 1037 1038 NameClassification(const IdentifierInfo *Keyword) 1039 : Kind(NC_Keyword), Keyword(Keyword) { } 1040 1041 static NameClassification Error() { 1042 return NameClassification(NC_Error); 1043 } 1044 1045 static NameClassification Unknown() { 1046 return NameClassification(NC_Unknown); 1047 } 1048 1049 static NameClassification NestedNameSpecifier() { 1050 return NameClassification(NC_NestedNameSpecifier); 1051 } 1052 1053 static NameClassification TypeTemplate(TemplateName Name) { 1054 NameClassification Result(NC_TypeTemplate); 1055 Result.Template = Name; 1056 return Result; 1057 } 1058 1059 static NameClassification FunctionTemplate(TemplateName Name) { 1060 NameClassification Result(NC_FunctionTemplate); 1061 Result.Template = Name; 1062 return Result; 1063 } 1064 1065 NameClassificationKind getKind() const { return Kind; } 1066 1067 ParsedType getType() const { 1068 assert(Kind == NC_Type); 1069 return Type; 1070 } 1071 1072 ExprResult getExpression() const { 1073 assert(Kind == NC_Expression); 1074 return Expr; 1075 } 1076 1077 TemplateName getTemplateName() const { 1078 assert(Kind == NC_TypeTemplate || Kind == NC_FunctionTemplate); 1079 return Template; 1080 } 1081 1082 TemplateNameKind getTemplateNameKind() const { 1083 assert(Kind == NC_TypeTemplate || Kind == NC_FunctionTemplate); 1084 return Kind == NC_TypeTemplate? TNK_Type_template : TNK_Function_template; 1085 } 1086 }; 1087 1088 /// \brief Perform name lookup on the given name, classifying it based on 1089 /// the results of name lookup and the following token. 1090 /// 1091 /// This routine is used by the parser to resolve identifiers and help direct 1092 /// parsing. When the identifier cannot be found, this routine will attempt 1093 /// to correct the typo and classify based on the resulting name. 1094 /// 1095 /// \param S The scope in which we're performing name lookup. 1096 /// 1097 /// \param SS The nested-name-specifier that precedes the name. 1098 /// 1099 /// \param Name The identifier. If typo correction finds an alternative name, 1100 /// this pointer parameter will be updated accordingly. 1101 /// 1102 /// \param NameLoc The location of the identifier. 1103 /// 1104 /// \param NextToken The token following the identifier. Used to help 1105 /// disambiguate the name. 1106 NameClassification ClassifyName(Scope *S, 1107 CXXScopeSpec &SS, 1108 IdentifierInfo *&Name, 1109 SourceLocation NameLoc, 1110 const Token &NextToken); 1111 1112 Decl *ActOnDeclarator(Scope *S, Declarator &D); 1113 1114 Decl *HandleDeclarator(Scope *S, Declarator &D, 1115 MultiTemplateParamsArg TemplateParameterLists); 1116 void RegisterLocallyScopedExternCDecl(NamedDecl *ND, 1117 const LookupResult &Previous, 1118 Scope *S); 1119 bool DiagnoseClassNameShadow(DeclContext *DC, DeclarationNameInfo Info); 1120 bool diagnoseQualifiedDeclaration(CXXScopeSpec &SS, DeclContext *DC, 1121 DeclarationName Name, 1122 SourceLocation Loc); 1123 void DiagnoseFunctionSpecifiers(Declarator& D); 1124 void CheckShadow(Scope *S, VarDecl *D, const LookupResult& R); 1125 void CheckShadow(Scope *S, VarDecl *D); 1126 void CheckCastAlign(Expr *Op, QualType T, SourceRange TRange); 1127 void CheckTypedefForVariablyModifiedType(Scope *S, TypedefNameDecl *D); 1128 NamedDecl* ActOnTypedefDeclarator(Scope* S, Declarator& D, DeclContext* DC, 1129 TypeSourceInfo *TInfo, 1130 LookupResult &Previous); 1131 NamedDecl* ActOnTypedefNameDecl(Scope* S, DeclContext* DC, TypedefNameDecl *D, 1132 LookupResult &Previous, bool &Redeclaration); 1133 NamedDecl* ActOnVariableDeclarator(Scope* S, Declarator& D, DeclContext* DC, 1134 TypeSourceInfo *TInfo, 1135 LookupResult &Previous, 1136 MultiTemplateParamsArg TemplateParamLists); 1137 // Returns true if the variable declaration is a redeclaration 1138 bool CheckVariableDeclaration(VarDecl *NewVD, LookupResult &Previous); 1139 void CheckCompleteVariableDeclaration(VarDecl *var); 1140 void ActOnStartFunctionDeclarator(); 1141 void ActOnEndFunctionDeclarator(); 1142 NamedDecl* ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC, 1143 TypeSourceInfo *TInfo, 1144 LookupResult &Previous, 1145 MultiTemplateParamsArg TemplateParamLists, 1146 bool &AddToScope); 1147 bool AddOverriddenMethods(CXXRecordDecl *DC, CXXMethodDecl *MD); 1148 1149 bool CheckConstexprFunctionDecl(const FunctionDecl *FD); 1150 bool CheckConstexprFunctionBody(const FunctionDecl *FD, Stmt *Body); 1151 1152 void DiagnoseHiddenVirtualMethods(CXXRecordDecl *DC, CXXMethodDecl *MD); 1153 // Returns true if the function declaration is a redeclaration 1154 bool CheckFunctionDeclaration(Scope *S, 1155 FunctionDecl *NewFD, LookupResult &Previous, 1156 bool IsExplicitSpecialization); 1157 void CheckMain(FunctionDecl *FD, const DeclSpec &D); 1158 Decl *ActOnParamDeclarator(Scope *S, Declarator &D); 1159 ParmVarDecl *BuildParmVarDeclForTypedef(DeclContext *DC, 1160 SourceLocation Loc, 1161 QualType T); 1162 ParmVarDecl *CheckParameter(DeclContext *DC, SourceLocation StartLoc, 1163 SourceLocation NameLoc, IdentifierInfo *Name, 1164 QualType T, TypeSourceInfo *TSInfo, 1165 StorageClass SC, StorageClass SCAsWritten); 1166 void ActOnParamDefaultArgument(Decl *param, 1167 SourceLocation EqualLoc, 1168 Expr *defarg); 1169 void ActOnParamUnparsedDefaultArgument(Decl *param, 1170 SourceLocation EqualLoc, 1171 SourceLocation ArgLoc); 1172 void ActOnParamDefaultArgumentError(Decl *param); 1173 bool SetParamDefaultArgument(ParmVarDecl *Param, Expr *DefaultArg, 1174 SourceLocation EqualLoc); 1175 1176 void CheckSelfReference(Decl *OrigDecl, Expr *E); 1177 void AddInitializerToDecl(Decl *dcl, Expr *init, bool DirectInit, 1178 bool TypeMayContainAuto); 1179 void ActOnUninitializedDecl(Decl *dcl, bool TypeMayContainAuto); 1180 void ActOnInitializerError(Decl *Dcl); 1181 void ActOnCXXForRangeDecl(Decl *D); 1182 void SetDeclDeleted(Decl *dcl, SourceLocation DelLoc); 1183 void SetDeclDefaulted(Decl *dcl, SourceLocation DefaultLoc); 1184 void FinalizeDeclaration(Decl *D); 1185 DeclGroupPtrTy FinalizeDeclaratorGroup(Scope *S, const DeclSpec &DS, 1186 Decl **Group, 1187 unsigned NumDecls); 1188 DeclGroupPtrTy BuildDeclaratorGroup(Decl **Group, unsigned NumDecls, 1189 bool TypeMayContainAuto = true); 1190 void ActOnFinishKNRParamDeclarations(Scope *S, Declarator &D, 1191 SourceLocation LocAfterDecls); 1192 void CheckForFunctionRedefinition(FunctionDecl *FD); 1193 Decl *ActOnStartOfFunctionDef(Scope *S, Declarator &D); 1194 Decl *ActOnStartOfFunctionDef(Scope *S, Decl *D); 1195 void ActOnStartOfObjCMethodDef(Scope *S, Decl *D); 1196 1197 void computeNRVO(Stmt *Body, sema::FunctionScopeInfo *Scope); 1198 Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body); 1199 Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body, bool IsInstantiation); 1200 1201 /// ActOnFinishDelayedAttribute - Invoked when we have finished parsing an 1202 /// attribute for which parsing is delayed. 1203 void ActOnFinishDelayedAttribute(Scope *S, Decl *D, ParsedAttributes &Attrs); 1204 1205 /// \brief Diagnose any unused parameters in the given sequence of 1206 /// ParmVarDecl pointers. 1207 void DiagnoseUnusedParameters(ParmVarDecl * const *Begin, 1208 ParmVarDecl * const *End); 1209 1210 /// \brief Diagnose whether the size of parameters or return value of a 1211 /// function or obj-c method definition is pass-by-value and larger than a 1212 /// specified threshold. 1213 void DiagnoseSizeOfParametersAndReturnValue(ParmVarDecl * const *Begin, 1214 ParmVarDecl * const *End, 1215 QualType ReturnTy, 1216 NamedDecl *D); 1217 1218 void DiagnoseInvalidJumps(Stmt *Body); 1219 Decl *ActOnFileScopeAsmDecl(Expr *expr, 1220 SourceLocation AsmLoc, 1221 SourceLocation RParenLoc); 1222 1223 /// \brief The parser has processed a module import declaration. 1224 /// 1225 /// \param AtLoc The location of the '@' symbol, if any. 1226 /// 1227 /// \param ImportLoc The location of the 'import' keyword. 1228 /// 1229 /// \param Path The module access path. 1230 DeclResult ActOnModuleImport(SourceLocation AtLoc, SourceLocation ImportLoc, 1231 ModuleIdPath Path); 1232 1233 /// \brief Retrieve a suitable printing policy. 1234 PrintingPolicy getPrintingPolicy() const { 1235 return getPrintingPolicy(Context, PP); 1236 } 1237 1238 /// \brief Retrieve a suitable printing policy. 1239 static PrintingPolicy getPrintingPolicy(const ASTContext &Ctx, 1240 const Preprocessor &PP); 1241 1242 /// Scope actions. 1243 void ActOnPopScope(SourceLocation Loc, Scope *S); 1244 void ActOnTranslationUnitScope(Scope *S); 1245 1246 Decl *ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS, 1247 DeclSpec &DS); 1248 Decl *ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS, 1249 DeclSpec &DS, 1250 MultiTemplateParamsArg TemplateParams); 1251 1252 Decl *BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS, 1253 AccessSpecifier AS, 1254 RecordDecl *Record); 1255 1256 Decl *BuildMicrosoftCAnonymousStruct(Scope *S, DeclSpec &DS, 1257 RecordDecl *Record); 1258 1259 bool isAcceptableTagRedeclaration(const TagDecl *Previous, 1260 TagTypeKind NewTag, bool isDefinition, 1261 SourceLocation NewTagLoc, 1262 const IdentifierInfo &Name); 1263 1264 enum TagUseKind { 1265 TUK_Reference, // Reference to a tag: 'struct foo *X;' 1266 TUK_Declaration, // Fwd decl of a tag: 'struct foo;' 1267 TUK_Definition, // Definition of a tag: 'struct foo { int X; } Y;' 1268 TUK_Friend // Friend declaration: 'friend struct foo;' 1269 }; 1270 1271 Decl *ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, 1272 SourceLocation KWLoc, CXXScopeSpec &SS, 1273 IdentifierInfo *Name, SourceLocation NameLoc, 1274 AttributeList *Attr, AccessSpecifier AS, 1275 SourceLocation ModulePrivateLoc, 1276 MultiTemplateParamsArg TemplateParameterLists, 1277 bool &OwnedDecl, bool &IsDependent, 1278 SourceLocation ScopedEnumKWLoc, 1279 bool ScopedEnumUsesClassTag, TypeResult UnderlyingType); 1280 1281 Decl *ActOnTemplatedFriendTag(Scope *S, SourceLocation FriendLoc, 1282 unsigned TagSpec, SourceLocation TagLoc, 1283 CXXScopeSpec &SS, 1284 IdentifierInfo *Name, SourceLocation NameLoc, 1285 AttributeList *Attr, 1286 MultiTemplateParamsArg TempParamLists); 1287 1288 TypeResult ActOnDependentTag(Scope *S, 1289 unsigned TagSpec, 1290 TagUseKind TUK, 1291 const CXXScopeSpec &SS, 1292 IdentifierInfo *Name, 1293 SourceLocation TagLoc, 1294 SourceLocation NameLoc); 1295 1296 void ActOnDefs(Scope *S, Decl *TagD, SourceLocation DeclStart, 1297 IdentifierInfo *ClassName, 1298 SmallVectorImpl<Decl *> &Decls); 1299 Decl *ActOnField(Scope *S, Decl *TagD, SourceLocation DeclStart, 1300 Declarator &D, Expr *BitfieldWidth); 1301 1302 FieldDecl *HandleField(Scope *S, RecordDecl *TagD, SourceLocation DeclStart, 1303 Declarator &D, Expr *BitfieldWidth, bool HasInit, 1304 AccessSpecifier AS); 1305 1306 FieldDecl *CheckFieldDecl(DeclarationName Name, QualType T, 1307 TypeSourceInfo *TInfo, 1308 RecordDecl *Record, SourceLocation Loc, 1309 bool Mutable, Expr *BitfieldWidth, bool HasInit, 1310 SourceLocation TSSL, 1311 AccessSpecifier AS, NamedDecl *PrevDecl, 1312 Declarator *D = 0); 1313 1314 enum CXXSpecialMember { 1315 CXXDefaultConstructor, 1316 CXXCopyConstructor, 1317 CXXMoveConstructor, 1318 CXXCopyAssignment, 1319 CXXMoveAssignment, 1320 CXXDestructor, 1321 CXXInvalid 1322 }; 1323 bool CheckNontrivialField(FieldDecl *FD); 1324 void DiagnoseNontrivial(const RecordType* Record, CXXSpecialMember mem); 1325 CXXSpecialMember getSpecialMember(const CXXMethodDecl *MD); 1326 void ActOnLastBitfield(SourceLocation DeclStart, 1327 SmallVectorImpl<Decl *> &AllIvarDecls); 1328 Decl *ActOnIvar(Scope *S, SourceLocation DeclStart, 1329 Declarator &D, Expr *BitfieldWidth, 1330 tok::ObjCKeywordKind visibility); 1331 1332 // This is used for both record definitions and ObjC interface declarations. 1333 void ActOnFields(Scope* S, SourceLocation RecLoc, Decl *TagDecl, 1334 llvm::ArrayRef<Decl *> Fields, 1335 SourceLocation LBrac, SourceLocation RBrac, 1336 AttributeList *AttrList); 1337 1338 /// ActOnTagStartDefinition - Invoked when we have entered the 1339 /// scope of a tag's definition (e.g., for an enumeration, class, 1340 /// struct, or union). 1341 void ActOnTagStartDefinition(Scope *S, Decl *TagDecl); 1342 1343 Decl *ActOnObjCContainerStartDefinition(Decl *IDecl); 1344 1345 /// ActOnStartCXXMemberDeclarations - Invoked when we have parsed a 1346 /// C++ record definition's base-specifiers clause and are starting its 1347 /// member declarations. 1348 void ActOnStartCXXMemberDeclarations(Scope *S, Decl *TagDecl, 1349 SourceLocation FinalLoc, 1350 SourceLocation LBraceLoc); 1351 1352 /// ActOnTagFinishDefinition - Invoked once we have finished parsing 1353 /// the definition of a tag (enumeration, class, struct, or union). 1354 void ActOnTagFinishDefinition(Scope *S, Decl *TagDecl, 1355 SourceLocation RBraceLoc); 1356 1357 void ActOnObjCContainerFinishDefinition(); 1358 1359 /// \brief Invoked when we must temporarily exit the objective-c container 1360 /// scope for parsing/looking-up C constructs. 1361 /// 1362 /// Must be followed by a call to \see ActOnObjCReenterContainerContext 1363 void ActOnObjCTemporaryExitContainerContext(DeclContext *DC); 1364 void ActOnObjCReenterContainerContext(DeclContext *DC); 1365 1366 /// ActOnTagDefinitionError - Invoked when there was an unrecoverable 1367 /// error parsing the definition of a tag. 1368 void ActOnTagDefinitionError(Scope *S, Decl *TagDecl); 1369 1370 EnumConstantDecl *CheckEnumConstant(EnumDecl *Enum, 1371 EnumConstantDecl *LastEnumConst, 1372 SourceLocation IdLoc, 1373 IdentifierInfo *Id, 1374 Expr *val); 1375 bool CheckEnumUnderlyingType(TypeSourceInfo *TI); 1376 bool CheckEnumRedeclaration(SourceLocation EnumLoc, bool IsScoped, 1377 QualType EnumUnderlyingTy, const EnumDecl *Prev); 1378 1379 Decl *ActOnEnumConstant(Scope *S, Decl *EnumDecl, Decl *LastEnumConstant, 1380 SourceLocation IdLoc, IdentifierInfo *Id, 1381 AttributeList *Attrs, 1382 SourceLocation EqualLoc, Expr *Val); 1383 void ActOnEnumBody(SourceLocation EnumLoc, SourceLocation LBraceLoc, 1384 SourceLocation RBraceLoc, Decl *EnumDecl, 1385 Decl **Elements, unsigned NumElements, 1386 Scope *S, AttributeList *Attr); 1387 1388 DeclContext *getContainingDC(DeclContext *DC); 1389 1390 /// Set the current declaration context until it gets popped. 1391 void PushDeclContext(Scope *S, DeclContext *DC); 1392 void PopDeclContext(); 1393 1394 /// EnterDeclaratorContext - Used when we must lookup names in the context 1395 /// of a declarator's nested name specifier. 1396 void EnterDeclaratorContext(Scope *S, DeclContext *DC); 1397 void ExitDeclaratorContext(Scope *S); 1398 1399 /// Push the parameters of D, which must be a function, into scope. 1400 void ActOnReenterFunctionContext(Scope* S, Decl* D); 1401 void ActOnExitFunctionContext(); 1402 1403 DeclContext *getFunctionLevelDeclContext(); 1404 1405 /// getCurFunctionDecl - If inside of a function body, this returns a pointer 1406 /// to the function decl for the function being parsed. If we're currently 1407 /// in a 'block', this returns the containing context. 1408 FunctionDecl *getCurFunctionDecl(); 1409 1410 /// getCurMethodDecl - If inside of a method body, this returns a pointer to 1411 /// the method decl for the method being parsed. If we're currently 1412 /// in a 'block', this returns the containing context. 1413 ObjCMethodDecl *getCurMethodDecl(); 1414 1415 /// getCurFunctionOrMethodDecl - Return the Decl for the current ObjC method 1416 /// or C function we're in, otherwise return null. If we're currently 1417 /// in a 'block', this returns the containing context. 1418 NamedDecl *getCurFunctionOrMethodDecl(); 1419 1420 /// Add this decl to the scope shadowed decl chains. 1421 void PushOnScopeChains(NamedDecl *D, Scope *S, bool AddToContext = true); 1422 1423 /// \brief Make the given externally-produced declaration visible at the 1424 /// top level scope. 1425 /// 1426 /// \param D The externally-produced declaration to push. 1427 /// 1428 /// \param Name The name of the externally-produced declaration. 1429 void pushExternalDeclIntoScope(NamedDecl *D, DeclarationName Name); 1430 1431 /// isDeclInScope - If 'Ctx' is a function/method, isDeclInScope returns true 1432 /// if 'D' is in Scope 'S', otherwise 'S' is ignored and isDeclInScope returns 1433 /// true if 'D' belongs to the given declaration context. 1434 /// 1435 /// \param ExplicitInstantiationOrSpecialization When true, we are checking 1436 /// whether the declaration is in scope for the purposes of explicit template 1437 /// instantiation or specialization. The default is false. 1438 bool isDeclInScope(NamedDecl *&D, DeclContext *Ctx, Scope *S = 0, 1439 bool ExplicitInstantiationOrSpecialization = false); 1440 1441 /// Finds the scope corresponding to the given decl context, if it 1442 /// happens to be an enclosing scope. Otherwise return NULL. 1443 static Scope *getScopeForDeclContext(Scope *S, DeclContext *DC); 1444 1445 /// Subroutines of ActOnDeclarator(). 1446 TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, QualType T, 1447 TypeSourceInfo *TInfo); 1448 bool isIncompatibleTypedef(TypeDecl *Old, TypedefNameDecl *New); 1449 void mergeDeclAttributes(Decl *New, Decl *Old, bool MergeDeprecation = true); 1450 void MergeTypedefNameDecl(TypedefNameDecl *New, LookupResult &OldDecls); 1451 bool MergeFunctionDecl(FunctionDecl *New, Decl *Old, Scope *S); 1452 bool MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old, 1453 Scope *S); 1454 void mergeObjCMethodDecls(ObjCMethodDecl *New, ObjCMethodDecl *Old); 1455 void MergeVarDecl(VarDecl *New, LookupResult &OldDecls); 1456 void MergeVarDeclTypes(VarDecl *New, VarDecl *Old); 1457 void MergeVarDeclExceptionSpecs(VarDecl *New, VarDecl *Old); 1458 bool MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old, Scope *S); 1459 1460 // AssignmentAction - This is used by all the assignment diagnostic functions 1461 // to represent what is actually causing the operation 1462 enum AssignmentAction { 1463 AA_Assigning, 1464 AA_Passing, 1465 AA_Returning, 1466 AA_Converting, 1467 AA_Initializing, 1468 AA_Sending, 1469 AA_Casting 1470 }; 1471 1472 /// C++ Overloading. 1473 enum OverloadKind { 1474 /// This is a legitimate overload: the existing declarations are 1475 /// functions or function templates with different signatures. 1476 Ovl_Overload, 1477 1478 /// This is not an overload because the signature exactly matches 1479 /// an existing declaration. 1480 Ovl_Match, 1481 1482 /// This is not an overload because the lookup results contain a 1483 /// non-function. 1484 Ovl_NonFunction 1485 }; 1486 OverloadKind CheckOverload(Scope *S, 1487 FunctionDecl *New, 1488 const LookupResult &OldDecls, 1489 NamedDecl *&OldDecl, 1490 bool IsForUsingDecl); 1491 bool IsOverload(FunctionDecl *New, FunctionDecl *Old, bool IsForUsingDecl); 1492 1493 /// \brief Checks availability of the function depending on the current 1494 /// function context.Inside an unavailable function,unavailability is ignored. 1495 /// 1496 /// \returns true if \arg FD is unavailable and current context is inside 1497 /// an available function, false otherwise. 1498 bool isFunctionConsideredUnavailable(FunctionDecl *FD); 1499 1500 ImplicitConversionSequence 1501 TryImplicitConversion(Expr *From, QualType ToType, 1502 bool SuppressUserConversions, 1503 bool AllowExplicit, 1504 bool InOverloadResolution, 1505 bool CStyle, 1506 bool AllowObjCWritebackConversion); 1507 1508 bool IsIntegralPromotion(Expr *From, QualType FromType, QualType ToType); 1509 bool IsFloatingPointPromotion(QualType FromType, QualType ToType); 1510 bool IsComplexPromotion(QualType FromType, QualType ToType); 1511 bool IsPointerConversion(Expr *From, QualType FromType, QualType ToType, 1512 bool InOverloadResolution, 1513 QualType& ConvertedType, bool &IncompatibleObjC); 1514 bool isObjCPointerConversion(QualType FromType, QualType ToType, 1515 QualType& ConvertedType, bool &IncompatibleObjC); 1516 bool isObjCWritebackConversion(QualType FromType, QualType ToType, 1517 QualType &ConvertedType); 1518 bool IsBlockPointerConversion(QualType FromType, QualType ToType, 1519 QualType& ConvertedType); 1520 bool FunctionArgTypesAreEqual(const FunctionProtoType *OldType, 1521 const FunctionProtoType *NewType, 1522 unsigned *ArgPos = 0); 1523 void HandleFunctionTypeMismatch(PartialDiagnostic &PDiag, 1524 QualType FromType, QualType ToType); 1525 1526 CastKind PrepareCastToObjCObjectPointer(ExprResult &E); 1527 bool CheckPointerConversion(Expr *From, QualType ToType, 1528 CastKind &Kind, 1529 CXXCastPath& BasePath, 1530 bool IgnoreBaseAccess); 1531 bool IsMemberPointerConversion(Expr *From, QualType FromType, QualType ToType, 1532 bool InOverloadResolution, 1533 QualType &ConvertedType); 1534 bool CheckMemberPointerConversion(Expr *From, QualType ToType, 1535 CastKind &Kind, 1536 CXXCastPath &BasePath, 1537 bool IgnoreBaseAccess); 1538 bool IsQualificationConversion(QualType FromType, QualType ToType, 1539 bool CStyle, bool &ObjCLifetimeConversion); 1540 bool IsNoReturnConversion(QualType FromType, QualType ToType, 1541 QualType &ResultTy); 1542 bool DiagnoseMultipleUserDefinedConversion(Expr *From, QualType ToType); 1543 1544 1545 ExprResult PerformMoveOrCopyInitialization(const InitializedEntity &Entity, 1546 const VarDecl *NRVOCandidate, 1547 QualType ResultType, 1548 Expr *Value, 1549 bool AllowNRVO = true); 1550 1551 bool CanPerformCopyInitialization(const InitializedEntity &Entity, 1552 ExprResult Init); 1553 ExprResult PerformCopyInitialization(const InitializedEntity &Entity, 1554 SourceLocation EqualLoc, 1555 ExprResult Init, 1556 bool TopLevelOfInitList = false, 1557 bool AllowExplicit = false); 1558 ExprResult PerformObjectArgumentInitialization(Expr *From, 1559 NestedNameSpecifier *Qualifier, 1560 NamedDecl *FoundDecl, 1561 CXXMethodDecl *Method); 1562 1563 ExprResult PerformContextuallyConvertToBool(Expr *From); 1564 ExprResult PerformContextuallyConvertToObjCPointer(Expr *From); 1565 1566 /// Contexts in which a converted constant expression is required. 1567 enum CCEKind { 1568 CCEK_CaseValue, ///< Expression in a case label. 1569 CCEK_Enumerator, ///< Enumerator value with fixed underlying type. 1570 CCEK_TemplateArg ///< Value of a non-type template parameter. 1571 }; 1572 ExprResult CheckConvertedConstantExpression(Expr *From, QualType T, 1573 llvm::APSInt &Value, CCEKind CCE); 1574 1575 ExprResult 1576 ConvertToIntegralOrEnumerationType(SourceLocation Loc, Expr *FromE, 1577 const PartialDiagnostic &NotIntDiag, 1578 const PartialDiagnostic &IncompleteDiag, 1579 const PartialDiagnostic &ExplicitConvDiag, 1580 const PartialDiagnostic &ExplicitConvNote, 1581 const PartialDiagnostic &AmbigDiag, 1582 const PartialDiagnostic &AmbigNote, 1583 const PartialDiagnostic &ConvDiag, 1584 bool AllowScopedEnumerations); 1585 enum ObjCSubscriptKind { 1586 OS_Array, 1587 OS_Dictionary, 1588 OS_Error 1589 }; 1590 ObjCSubscriptKind CheckSubscriptingKind(Expr *FromE); 1591 1592 ExprResult PerformObjectMemberConversion(Expr *From, 1593 NestedNameSpecifier *Qualifier, 1594 NamedDecl *FoundDecl, 1595 NamedDecl *Member); 1596 1597 // Members have to be NamespaceDecl* or TranslationUnitDecl*. 1598 // TODO: make this is a typesafe union. 1599 typedef llvm::SmallPtrSet<DeclContext *, 16> AssociatedNamespaceSet; 1600 typedef llvm::SmallPtrSet<CXXRecordDecl *, 16> AssociatedClassSet; 1601 1602 void AddOverloadCandidate(FunctionDecl *Function, 1603 DeclAccessPair FoundDecl, 1604 llvm::ArrayRef<Expr *> Args, 1605 OverloadCandidateSet& CandidateSet, 1606 bool SuppressUserConversions = false, 1607 bool PartialOverloading = false, 1608 bool AllowExplicit = false); 1609 void AddFunctionCandidates(const UnresolvedSetImpl &Functions, 1610 llvm::ArrayRef<Expr *> Args, 1611 OverloadCandidateSet& CandidateSet, 1612 bool SuppressUserConversions = false, 1613 TemplateArgumentListInfo *ExplicitTemplateArgs = 0); 1614 void AddMethodCandidate(DeclAccessPair FoundDecl, 1615 QualType ObjectType, 1616 Expr::Classification ObjectClassification, 1617 Expr **Args, unsigned NumArgs, 1618 OverloadCandidateSet& CandidateSet, 1619 bool SuppressUserConversion = false); 1620 void AddMethodCandidate(CXXMethodDecl *Method, 1621 DeclAccessPair FoundDecl, 1622 CXXRecordDecl *ActingContext, QualType ObjectType, 1623 Expr::Classification ObjectClassification, 1624 llvm::ArrayRef<Expr *> Args, 1625 OverloadCandidateSet& CandidateSet, 1626 bool SuppressUserConversions = false); 1627 void AddMethodTemplateCandidate(FunctionTemplateDecl *MethodTmpl, 1628 DeclAccessPair FoundDecl, 1629 CXXRecordDecl *ActingContext, 1630 TemplateArgumentListInfo *ExplicitTemplateArgs, 1631 QualType ObjectType, 1632 Expr::Classification ObjectClassification, 1633 llvm::ArrayRef<Expr *> Args, 1634 OverloadCandidateSet& CandidateSet, 1635 bool SuppressUserConversions = false); 1636 void AddTemplateOverloadCandidate(FunctionTemplateDecl *FunctionTemplate, 1637 DeclAccessPair FoundDecl, 1638 TemplateArgumentListInfo *ExplicitTemplateArgs, 1639 llvm::ArrayRef<Expr *> Args, 1640 OverloadCandidateSet& CandidateSet, 1641 bool SuppressUserConversions = false); 1642 void AddConversionCandidate(CXXConversionDecl *Conversion, 1643 DeclAccessPair FoundDecl, 1644 CXXRecordDecl *ActingContext, 1645 Expr *From, QualType ToType, 1646 OverloadCandidateSet& CandidateSet); 1647 void AddTemplateConversionCandidate(FunctionTemplateDecl *FunctionTemplate, 1648 DeclAccessPair FoundDecl, 1649 CXXRecordDecl *ActingContext, 1650 Expr *From, QualType ToType, 1651 OverloadCandidateSet &CandidateSet); 1652 void AddSurrogateCandidate(CXXConversionDecl *Conversion, 1653 DeclAccessPair FoundDecl, 1654 CXXRecordDecl *ActingContext, 1655 const FunctionProtoType *Proto, 1656 Expr *Object, llvm::ArrayRef<Expr*> Args, 1657 OverloadCandidateSet& CandidateSet); 1658 void AddMemberOperatorCandidates(OverloadedOperatorKind Op, 1659 SourceLocation OpLoc, 1660 Expr **Args, unsigned NumArgs, 1661 OverloadCandidateSet& CandidateSet, 1662 SourceRange OpRange = SourceRange()); 1663 void AddBuiltinCandidate(QualType ResultTy, QualType *ParamTys, 1664 Expr **Args, unsigned NumArgs, 1665 OverloadCandidateSet& CandidateSet, 1666 bool IsAssignmentOperator = false, 1667 unsigned NumContextualBoolArguments = 0); 1668 void AddBuiltinOperatorCandidates(OverloadedOperatorKind Op, 1669 SourceLocation OpLoc, 1670 Expr **Args, unsigned NumArgs, 1671 OverloadCandidateSet& CandidateSet); 1672 void AddArgumentDependentLookupCandidates(DeclarationName Name, 1673 bool Operator, SourceLocation Loc, 1674 llvm::ArrayRef<Expr *> Args, 1675 TemplateArgumentListInfo *ExplicitTemplateArgs, 1676 OverloadCandidateSet& CandidateSet, 1677 bool PartialOverloading = false, 1678 bool StdNamespaceIsAssociated = false); 1679 1680 // Emit as a 'note' the specific overload candidate 1681 void NoteOverloadCandidate(FunctionDecl *Fn, QualType DestType = QualType()); 1682 1683 // Emit as a series of 'note's all template and non-templates 1684 // identified by the expression Expr 1685 void NoteAllOverloadCandidates(Expr* E, QualType DestType = QualType()); 1686 1687 // [PossiblyAFunctionType] --> [Return] 1688 // NonFunctionType --> NonFunctionType 1689 // R (A) --> R(A) 1690 // R (*)(A) --> R (A) 1691 // R (&)(A) --> R (A) 1692 // R (S::*)(A) --> R (A) 1693 QualType ExtractUnqualifiedFunctionType(QualType PossiblyAFunctionType); 1694 1695 FunctionDecl * 1696 ResolveAddressOfOverloadedFunction(Expr *AddressOfExpr, 1697 QualType TargetType, 1698 bool Complain, 1699 DeclAccessPair &Found, 1700 bool *pHadMultipleCandidates = 0); 1701 1702 FunctionDecl *ResolveSingleFunctionTemplateSpecialization(OverloadExpr *ovl, 1703 bool Complain = false, 1704 DeclAccessPair* Found = 0); 1705 1706 bool ResolveAndFixSingleFunctionTemplateSpecialization( 1707 ExprResult &SrcExpr, 1708 bool DoFunctionPointerConverion = false, 1709 bool Complain = false, 1710 const SourceRange& OpRangeForComplaining = SourceRange(), 1711 QualType DestTypeForComplaining = QualType(), 1712 unsigned DiagIDForComplaining = 0); 1713 1714 1715 Expr *FixOverloadedFunctionReference(Expr *E, 1716 DeclAccessPair FoundDecl, 1717 FunctionDecl *Fn); 1718 ExprResult FixOverloadedFunctionReference(ExprResult, 1719 DeclAccessPair FoundDecl, 1720 FunctionDecl *Fn); 1721 1722 void AddOverloadedCallCandidates(UnresolvedLookupExpr *ULE, 1723 llvm::ArrayRef<Expr *> Args, 1724 OverloadCandidateSet &CandidateSet, 1725 bool PartialOverloading = false); 1726 1727 ExprResult BuildOverloadedCallExpr(Scope *S, Expr *Fn, 1728 UnresolvedLookupExpr *ULE, 1729 SourceLocation LParenLoc, 1730 Expr **Args, unsigned NumArgs, 1731 SourceLocation RParenLoc, 1732 Expr *ExecConfig, 1733 bool AllowTypoCorrection=true); 1734 1735 ExprResult CreateOverloadedUnaryOp(SourceLocation OpLoc, 1736 unsigned Opc, 1737 const UnresolvedSetImpl &Fns, 1738 Expr *input); 1739 1740 ExprResult CreateOverloadedBinOp(SourceLocation OpLoc, 1741 unsigned Opc, 1742 const UnresolvedSetImpl &Fns, 1743 Expr *LHS, Expr *RHS); 1744 1745 ExprResult CreateOverloadedArraySubscriptExpr(SourceLocation LLoc, 1746 SourceLocation RLoc, 1747 Expr *Base,Expr *Idx); 1748 1749 ExprResult 1750 BuildCallToMemberFunction(Scope *S, Expr *MemExpr, 1751 SourceLocation LParenLoc, Expr **Args, 1752 unsigned NumArgs, SourceLocation RParenLoc); 1753 ExprResult 1754 BuildCallToObjectOfClassType(Scope *S, Expr *Object, SourceLocation LParenLoc, 1755 Expr **Args, unsigned NumArgs, 1756 SourceLocation RParenLoc); 1757 1758 ExprResult BuildOverloadedArrowExpr(Scope *S, Expr *Base, 1759 SourceLocation OpLoc); 1760 1761 /// CheckCallReturnType - Checks that a call expression's return type is 1762 /// complete. Returns true on failure. The location passed in is the location 1763 /// that best represents the call. 1764 bool CheckCallReturnType(QualType ReturnType, SourceLocation Loc, 1765 CallExpr *CE, FunctionDecl *FD); 1766 1767 /// Helpers for dealing with blocks and functions. 1768 bool CheckParmsForFunctionDef(ParmVarDecl **Param, ParmVarDecl **ParamEnd, 1769 bool CheckParameterNames); 1770 void CheckCXXDefaultArguments(FunctionDecl *FD); 1771 void CheckExtraCXXDefaultArguments(Declarator &D); 1772 Scope *getNonFieldDeclScope(Scope *S); 1773 1774 /// \name Name lookup 1775 /// 1776 /// These routines provide name lookup that is used during semantic 1777 /// analysis to resolve the various kinds of names (identifiers, 1778 /// overloaded operator names, constructor names, etc.) into zero or 1779 /// more declarations within a particular scope. The major entry 1780 /// points are LookupName, which performs unqualified name lookup, 1781 /// and LookupQualifiedName, which performs qualified name lookup. 1782 /// 1783 /// All name lookup is performed based on some specific criteria, 1784 /// which specify what names will be visible to name lookup and how 1785 /// far name lookup should work. These criteria are important both 1786 /// for capturing language semantics (certain lookups will ignore 1787 /// certain names, for example) and for performance, since name 1788 /// lookup is often a bottleneck in the compilation of C++. Name 1789 /// lookup criteria is specified via the LookupCriteria enumeration. 1790 /// 1791 /// The results of name lookup can vary based on the kind of name 1792 /// lookup performed, the current language, and the translation 1793 /// unit. In C, for example, name lookup will either return nothing 1794 /// (no entity found) or a single declaration. In C++, name lookup 1795 /// can additionally refer to a set of overloaded functions or 1796 /// result in an ambiguity. All of the possible results of name 1797 /// lookup are captured by the LookupResult class, which provides 1798 /// the ability to distinguish among them. 1799 //@{ 1800 1801 /// @brief Describes the kind of name lookup to perform. 1802 enum LookupNameKind { 1803 /// Ordinary name lookup, which finds ordinary names (functions, 1804 /// variables, typedefs, etc.) in C and most kinds of names 1805 /// (functions, variables, members, types, etc.) in C++. 1806 LookupOrdinaryName = 0, 1807 /// Tag name lookup, which finds the names of enums, classes, 1808 /// structs, and unions. 1809 LookupTagName, 1810 /// Label name lookup. 1811 LookupLabel, 1812 /// Member name lookup, which finds the names of 1813 /// class/struct/union members. 1814 LookupMemberName, 1815 /// Look up of an operator name (e.g., operator+) for use with 1816 /// operator overloading. This lookup is similar to ordinary name 1817 /// lookup, but will ignore any declarations that are class members. 1818 LookupOperatorName, 1819 /// Look up of a name that precedes the '::' scope resolution 1820 /// operator in C++. This lookup completely ignores operator, object, 1821 /// function, and enumerator names (C++ [basic.lookup.qual]p1). 1822 LookupNestedNameSpecifierName, 1823 /// Look up a namespace name within a C++ using directive or 1824 /// namespace alias definition, ignoring non-namespace names (C++ 1825 /// [basic.lookup.udir]p1). 1826 LookupNamespaceName, 1827 /// Look up all declarations in a scope with the given name, 1828 /// including resolved using declarations. This is appropriate 1829 /// for checking redeclarations for a using declaration. 1830 LookupUsingDeclName, 1831 /// Look up an ordinary name that is going to be redeclared as a 1832 /// name with linkage. This lookup ignores any declarations that 1833 /// are outside of the current scope unless they have linkage. See 1834 /// C99 6.2.2p4-5 and C++ [basic.link]p6. 1835 LookupRedeclarationWithLinkage, 1836 /// Look up the name of an Objective-C protocol. 1837 LookupObjCProtocolName, 1838 /// Look up implicit 'self' parameter of an objective-c method. 1839 LookupObjCImplicitSelfParam, 1840 /// \brief Look up any declaration with any name. 1841 LookupAnyName 1842 }; 1843 1844 /// \brief Specifies whether (or how) name lookup is being performed for a 1845 /// redeclaration (vs. a reference). 1846 enum RedeclarationKind { 1847 /// \brief The lookup is a reference to this name that is not for the 1848 /// purpose of redeclaring the name. 1849 NotForRedeclaration = 0, 1850 /// \brief The lookup results will be used for redeclaration of a name, 1851 /// if an entity by that name already exists. 1852 ForRedeclaration 1853 }; 1854 1855 /// \brief The possible outcomes of name lookup for a literal operator. 1856 enum LiteralOperatorLookupResult { 1857 /// \brief The lookup resulted in an error. 1858 LOLR_Error, 1859 /// \brief The lookup found a single 'cooked' literal operator, which 1860 /// expects a normal literal to be built and passed to it. 1861 LOLR_Cooked, 1862 /// \brief The lookup found a single 'raw' literal operator, which expects 1863 /// a string literal containing the spelling of the literal token. 1864 LOLR_Raw, 1865 /// \brief The lookup found an overload set of literal operator templates, 1866 /// which expect the characters of the spelling of the literal token to be 1867 /// passed as a non-type template argument pack. 1868 LOLR_Template 1869 }; 1870 1871 SpecialMemberOverloadResult *LookupSpecialMember(CXXRecordDecl *D, 1872 CXXSpecialMember SM, 1873 bool ConstArg, 1874 bool VolatileArg, 1875 bool RValueThis, 1876 bool ConstThis, 1877 bool VolatileThis); 1878 1879 private: 1880 bool CppLookupName(LookupResult &R, Scope *S); 1881 1882 // \brief The set of known/encountered (unique, canonicalized) NamespaceDecls. 1883 // 1884 // The boolean value will be true to indicate that the namespace was loaded 1885 // from an AST/PCH file, or false otherwise. 1886 llvm::DenseMap<NamespaceDecl*, bool> KnownNamespaces; 1887 1888 /// \brief Whether we have already loaded known namespaces from an extenal 1889 /// source. 1890 bool LoadedExternalKnownNamespaces; 1891 1892 public: 1893 /// \brief Look up a name, looking for a single declaration. Return 1894 /// null if the results were absent, ambiguous, or overloaded. 1895 /// 1896 /// It is preferable to use the elaborated form and explicitly handle 1897 /// ambiguity and overloaded. 1898 NamedDecl *LookupSingleName(Scope *S, DeclarationName Name, 1899 SourceLocation Loc, 1900 LookupNameKind NameKind, 1901 RedeclarationKind Redecl 1902 = NotForRedeclaration); 1903 bool LookupName(LookupResult &R, Scope *S, 1904 bool AllowBuiltinCreation = false); 1905 bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx, 1906 bool InUnqualifiedLookup = false); 1907 bool LookupParsedName(LookupResult &R, Scope *S, CXXScopeSpec *SS, 1908 bool AllowBuiltinCreation = false, 1909 bool EnteringContext = false); 1910 ObjCProtocolDecl *LookupProtocol(IdentifierInfo *II, SourceLocation IdLoc, 1911 RedeclarationKind Redecl 1912 = NotForRedeclaration); 1913 1914 void LookupOverloadedOperatorName(OverloadedOperatorKind Op, Scope *S, 1915 QualType T1, QualType T2, 1916 UnresolvedSetImpl &Functions); 1917 1918 LabelDecl *LookupOrCreateLabel(IdentifierInfo *II, SourceLocation IdentLoc, 1919 SourceLocation GnuLabelLoc = SourceLocation()); 1920 1921 DeclContextLookupResult LookupConstructors(CXXRecordDecl *Class); 1922 CXXConstructorDecl *LookupDefaultConstructor(CXXRecordDecl *Class); 1923 CXXConstructorDecl *LookupCopyingConstructor(CXXRecordDecl *Class, 1924 unsigned Quals, 1925 bool *ConstParam = 0); 1926 CXXMethodDecl *LookupCopyingAssignment(CXXRecordDecl *Class, unsigned Quals, 1927 bool RValueThis, unsigned ThisQuals, 1928 bool *ConstParam = 0); 1929 CXXConstructorDecl *LookupMovingConstructor(CXXRecordDecl *Class); 1930 CXXMethodDecl *LookupMovingAssignment(CXXRecordDecl *Class, bool RValueThis, 1931 unsigned ThisQuals); 1932 CXXDestructorDecl *LookupDestructor(CXXRecordDecl *Class); 1933 1934 LiteralOperatorLookupResult LookupLiteralOperator(Scope *S, LookupResult &R, 1935 ArrayRef<QualType> ArgTys, 1936 bool AllowRawAndTemplate); 1937 1938 void ArgumentDependentLookup(DeclarationName Name, bool Operator, 1939 SourceLocation Loc, 1940 llvm::ArrayRef<Expr *> Args, 1941 ADLResult &Functions, 1942 bool StdNamespaceIsAssociated = false); 1943 1944 void LookupVisibleDecls(Scope *S, LookupNameKind Kind, 1945 VisibleDeclConsumer &Consumer, 1946 bool IncludeGlobalScope = true); 1947 void LookupVisibleDecls(DeclContext *Ctx, LookupNameKind Kind, 1948 VisibleDeclConsumer &Consumer, 1949 bool IncludeGlobalScope = true); 1950 1951 TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo, 1952 Sema::LookupNameKind LookupKind, 1953 Scope *S, CXXScopeSpec *SS, 1954 CorrectionCandidateCallback &CCC, 1955 DeclContext *MemberContext = 0, 1956 bool EnteringContext = false, 1957 const ObjCObjectPointerType *OPT = 0); 1958 1959 void FindAssociatedClassesAndNamespaces(llvm::ArrayRef<Expr *> Args, 1960 AssociatedNamespaceSet &AssociatedNamespaces, 1961 AssociatedClassSet &AssociatedClasses); 1962 1963 void FilterLookupForScope(LookupResult &R, DeclContext *Ctx, Scope *S, 1964 bool ConsiderLinkage, 1965 bool ExplicitInstantiationOrSpecialization); 1966 1967 bool DiagnoseAmbiguousLookup(LookupResult &Result); 1968 //@} 1969 1970 ObjCInterfaceDecl *getObjCInterfaceDecl(IdentifierInfo *&Id, 1971 SourceLocation IdLoc, 1972 bool TypoCorrection = false); 1973 NamedDecl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID, 1974 Scope *S, bool ForRedeclaration, 1975 SourceLocation Loc); 1976 NamedDecl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II, 1977 Scope *S); 1978 void AddKnownFunctionAttributes(FunctionDecl *FD); 1979 1980 // More parsing and symbol table subroutines. 1981 1982 // Decl attributes - this routine is the top level dispatcher. 1983 void ProcessDeclAttributes(Scope *S, Decl *D, const Declarator &PD, 1984 bool NonInheritable = true, bool Inheritable = true); 1985 void ProcessDeclAttributeList(Scope *S, Decl *D, const AttributeList *AL, 1986 bool NonInheritable = true, bool Inheritable = true); 1987 bool ProcessAccessDeclAttributeList(AccessSpecDecl *ASDecl, 1988 const AttributeList *AttrList); 1989 1990 void checkUnusedDeclAttributes(Declarator &D); 1991 1992 bool CheckRegparmAttr(const AttributeList &attr, unsigned &value); 1993 bool CheckCallingConvAttr(const AttributeList &attr, CallingConv &CC); 1994 bool CheckNoReturnAttr(const AttributeList &attr); 1995 1996 /// \brief Stmt attributes - this routine is the top level dispatcher. 1997 StmtResult ProcessStmtAttributes(Stmt *Stmt, AttributeList *Attrs, 1998 SourceRange Range); 1999 2000 void WarnUndefinedMethod(SourceLocation ImpLoc, ObjCMethodDecl *method, 2001 bool &IncompleteImpl, unsigned DiagID); 2002 void WarnConflictingTypedMethods(ObjCMethodDecl *Method, 2003 ObjCMethodDecl *MethodDecl, 2004 bool IsProtocolMethodDecl); 2005 2006 void CheckConflictingOverridingMethod(ObjCMethodDecl *Method, 2007 ObjCMethodDecl *Overridden, 2008 bool IsProtocolMethodDecl); 2009 2010 /// WarnExactTypedMethods - This routine issues a warning if method 2011 /// implementation declaration matches exactly that of its declaration. 2012 void WarnExactTypedMethods(ObjCMethodDecl *Method, 2013 ObjCMethodDecl *MethodDecl, 2014 bool IsProtocolMethodDecl); 2015 2016 bool isPropertyReadonly(ObjCPropertyDecl *PropertyDecl, 2017 ObjCInterfaceDecl *IDecl); 2018 2019 typedef llvm::DenseSet<Selector, llvm::DenseMapInfo<Selector> > SelectorSet; 2020 typedef llvm::DenseMap<Selector, ObjCMethodDecl*> ProtocolsMethodsMap; 2021 2022 /// CheckProtocolMethodDefs - This routine checks unimplemented 2023 /// methods declared in protocol, and those referenced by it. 2024 /// \param IDecl - Used for checking for methods which may have been 2025 /// inherited. 2026 void CheckProtocolMethodDefs(SourceLocation ImpLoc, 2027 ObjCProtocolDecl *PDecl, 2028 bool& IncompleteImpl, 2029 const SelectorSet &InsMap, 2030 const SelectorSet &ClsMap, 2031 ObjCContainerDecl *CDecl); 2032 2033 /// CheckImplementationIvars - This routine checks if the instance variables 2034 /// listed in the implelementation match those listed in the interface. 2035 void CheckImplementationIvars(ObjCImplementationDecl *ImpDecl, 2036 ObjCIvarDecl **Fields, unsigned nIvars, 2037 SourceLocation Loc); 2038 2039 /// ImplMethodsVsClassMethods - This is main routine to warn if any method 2040 /// remains unimplemented in the class or category @implementation. 2041 void ImplMethodsVsClassMethods(Scope *S, ObjCImplDecl* IMPDecl, 2042 ObjCContainerDecl* IDecl, 2043 bool IncompleteImpl = false); 2044 2045 /// DiagnoseUnimplementedProperties - This routine warns on those properties 2046 /// which must be implemented by this implementation. 2047 void DiagnoseUnimplementedProperties(Scope *S, ObjCImplDecl* IMPDecl, 2048 ObjCContainerDecl *CDecl, 2049 const SelectorSet &InsMap); 2050 2051 /// DefaultSynthesizeProperties - This routine default synthesizes all 2052 /// properties which must be synthesized in class's @implementation. 2053 void DefaultSynthesizeProperties (Scope *S, ObjCImplDecl* IMPDecl, 2054 ObjCInterfaceDecl *IDecl); 2055 void DefaultSynthesizeProperties(Scope *S, Decl *D); 2056 2057 /// CollectImmediateProperties - This routine collects all properties in 2058 /// the class and its conforming protocols; but not those it its super class. 2059 void CollectImmediateProperties(ObjCContainerDecl *CDecl, 2060 llvm::DenseMap<IdentifierInfo *, ObjCPropertyDecl*>& PropMap, 2061 llvm::DenseMap<IdentifierInfo *, ObjCPropertyDecl*>& SuperPropMap); 2062 2063 2064 /// LookupPropertyDecl - Looks up a property in the current class and all 2065 /// its protocols. 2066 ObjCPropertyDecl *LookupPropertyDecl(const ObjCContainerDecl *CDecl, 2067 IdentifierInfo *II); 2068 2069 /// Called by ActOnProperty to handle @property declarations in 2070 //// class extensions. 2071 Decl *HandlePropertyInClassExtension(Scope *S, 2072 SourceLocation AtLoc, 2073 SourceLocation LParenLoc, 2074 FieldDeclarator &FD, 2075 Selector GetterSel, 2076 Selector SetterSel, 2077 const bool isAssign, 2078 const bool isReadWrite, 2079 const unsigned Attributes, 2080 const unsigned AttributesAsWritten, 2081 bool *isOverridingProperty, 2082 TypeSourceInfo *T, 2083 tok::ObjCKeywordKind MethodImplKind); 2084 2085 /// Called by ActOnProperty and HandlePropertyInClassExtension to 2086 /// handle creating the ObjcPropertyDecl for a category or @interface. 2087 ObjCPropertyDecl *CreatePropertyDecl(Scope *S, 2088 ObjCContainerDecl *CDecl, 2089 SourceLocation AtLoc, 2090 SourceLocation LParenLoc, 2091 FieldDeclarator &FD, 2092 Selector GetterSel, 2093 Selector SetterSel, 2094 const bool isAssign, 2095 const bool isReadWrite, 2096 const unsigned Attributes, 2097 const unsigned AttributesAsWritten, 2098 TypeSourceInfo *T, 2099 tok::ObjCKeywordKind MethodImplKind, 2100 DeclContext *lexicalDC = 0); 2101 2102 /// AtomicPropertySetterGetterRules - This routine enforces the rule (via 2103 /// warning) when atomic property has one but not the other user-declared 2104 /// setter or getter. 2105 void AtomicPropertySetterGetterRules(ObjCImplDecl* IMPDecl, 2106 ObjCContainerDecl* IDecl); 2107 2108 void DiagnoseOwningPropertyGetterSynthesis(const ObjCImplementationDecl *D); 2109 2110 void DiagnoseDuplicateIvars(ObjCInterfaceDecl *ID, ObjCInterfaceDecl *SID); 2111 2112 enum MethodMatchStrategy { 2113 MMS_loose, 2114 MMS_strict 2115 }; 2116 2117 /// MatchTwoMethodDeclarations - Checks if two methods' type match and returns 2118 /// true, or false, accordingly. 2119 bool MatchTwoMethodDeclarations(const ObjCMethodDecl *Method, 2120 const ObjCMethodDecl *PrevMethod, 2121 MethodMatchStrategy strategy = MMS_strict); 2122 2123 /// MatchAllMethodDeclarations - Check methods declaraed in interface or 2124 /// or protocol against those declared in their implementations. 2125 void MatchAllMethodDeclarations(const SelectorSet &InsMap, 2126 const SelectorSet &ClsMap, 2127 SelectorSet &InsMapSeen, 2128 SelectorSet &ClsMapSeen, 2129 ObjCImplDecl* IMPDecl, 2130 ObjCContainerDecl* IDecl, 2131 bool &IncompleteImpl, 2132 bool ImmediateClass, 2133 bool WarnCategoryMethodImpl=false); 2134 2135 /// CheckCategoryVsClassMethodMatches - Checks that methods implemented in 2136 /// category matches with those implemented in its primary class and 2137 /// warns each time an exact match is found. 2138 void CheckCategoryVsClassMethodMatches(ObjCCategoryImplDecl *CatIMP); 2139 2140 /// \brief Add the given method to the list of globally-known methods. 2141 void addMethodToGlobalList(ObjCMethodList *List, ObjCMethodDecl *Method); 2142 2143 private: 2144 /// AddMethodToGlobalPool - Add an instance or factory method to the global 2145 /// pool. See descriptoin of AddInstanceMethodToGlobalPool. 2146 void AddMethodToGlobalPool(ObjCMethodDecl *Method, bool impl, bool instance); 2147 2148 /// LookupMethodInGlobalPool - Returns the instance or factory method and 2149 /// optionally warns if there are multiple signatures. 2150 ObjCMethodDecl *LookupMethodInGlobalPool(Selector Sel, SourceRange R, 2151 bool receiverIdOrClass, 2152 bool warn, bool instance); 2153 2154 public: 2155 /// AddInstanceMethodToGlobalPool - All instance methods in a translation 2156 /// unit are added to a global pool. This allows us to efficiently associate 2157 /// a selector with a method declaraation for purposes of typechecking 2158 /// messages sent to "id" (where the class of the object is unknown). 2159 void AddInstanceMethodToGlobalPool(ObjCMethodDecl *Method, bool impl=false) { 2160 AddMethodToGlobalPool(Method, impl, /*instance*/true); 2161 } 2162 2163 /// AddFactoryMethodToGlobalPool - Same as above, but for factory methods. 2164 void AddFactoryMethodToGlobalPool(ObjCMethodDecl *Method, bool impl=false) { 2165 AddMethodToGlobalPool(Method, impl, /*instance*/false); 2166 } 2167 2168 /// AddAnyMethodToGlobalPool - Add any method, instance or factory to global 2169 /// pool. 2170 void AddAnyMethodToGlobalPool(Decl *D); 2171 2172 /// LookupInstanceMethodInGlobalPool - Returns the method and warns if 2173 /// there are multiple signatures. 2174 ObjCMethodDecl *LookupInstanceMethodInGlobalPool(Selector Sel, SourceRange R, 2175 bool receiverIdOrClass=false, 2176 bool warn=true) { 2177 return LookupMethodInGlobalPool(Sel, R, receiverIdOrClass, 2178 warn, /*instance*/true); 2179 } 2180 2181 /// LookupFactoryMethodInGlobalPool - Returns the method and warns if 2182 /// there are multiple signatures. 2183 ObjCMethodDecl *LookupFactoryMethodInGlobalPool(Selector Sel, SourceRange R, 2184 bool receiverIdOrClass=false, 2185 bool warn=true) { 2186 return LookupMethodInGlobalPool(Sel, R, receiverIdOrClass, 2187 warn, /*instance*/false); 2188 } 2189 2190 /// LookupImplementedMethodInGlobalPool - Returns the method which has an 2191 /// implementation. 2192 ObjCMethodDecl *LookupImplementedMethodInGlobalPool(Selector Sel); 2193 2194 /// CollectIvarsToConstructOrDestruct - Collect those ivars which require 2195 /// initialization. 2196 void CollectIvarsToConstructOrDestruct(ObjCInterfaceDecl *OI, 2197 SmallVectorImpl<ObjCIvarDecl*> &Ivars); 2198 2199 //===--------------------------------------------------------------------===// 2200 // Statement Parsing Callbacks: SemaStmt.cpp. 2201 public: 2202 class FullExprArg { 2203 public: 2204 FullExprArg(Sema &actions) : E(0) { } 2205 2206 // FIXME: The const_cast here is ugly. RValue references would make this 2207 // much nicer (or we could duplicate a bunch of the move semantics 2208 // emulation code from Ownership.h). 2209 FullExprArg(const FullExprArg& Other) : E(Other.E) {} 2210 2211 ExprResult release() { 2212 return move(E); 2213 } 2214 2215 Expr *get() const { return E; } 2216 2217 Expr *operator->() { 2218 return E; 2219 } 2220 2221 private: 2222 // FIXME: No need to make the entire Sema class a friend when it's just 2223 // Sema::MakeFullExpr that needs access to the constructor below. 2224 friend class Sema; 2225 2226 explicit FullExprArg(Expr *expr) : E(expr) {} 2227 2228 Expr *E; 2229 }; 2230 2231 FullExprArg MakeFullExpr(Expr *Arg) { 2232 return FullExprArg(ActOnFinishFullExpr(Arg).release()); 2233 } 2234 2235 StmtResult ActOnExprStmt(FullExprArg Expr); 2236 2237 StmtResult ActOnNullStmt(SourceLocation SemiLoc, 2238 bool HasLeadingEmptyMacro = false); 2239 2240 void ActOnStartOfCompoundStmt(); 2241 void ActOnFinishOfCompoundStmt(); 2242 StmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R, 2243 MultiStmtArg Elts, 2244 bool isStmtExpr); 2245 2246 /// \brief A RAII object to enter scope of a compound statement. 2247 class CompoundScopeRAII { 2248 public: 2249 CompoundScopeRAII(Sema &S): S(S) { 2250 S.ActOnStartOfCompoundStmt(); 2251 } 2252 2253 ~CompoundScopeRAII() { 2254 S.ActOnFinishOfCompoundStmt(); 2255 } 2256 2257 private: 2258 Sema &S; 2259 }; 2260 2261 StmtResult ActOnDeclStmt(DeclGroupPtrTy Decl, 2262 SourceLocation StartLoc, 2263 SourceLocation EndLoc); 2264 void ActOnForEachDeclStmt(DeclGroupPtrTy Decl); 2265 StmtResult ActOnForEachLValueExpr(Expr *E); 2266 StmtResult ActOnCaseStmt(SourceLocation CaseLoc, Expr *LHSVal, 2267 SourceLocation DotDotDotLoc, Expr *RHSVal, 2268 SourceLocation ColonLoc); 2269 void ActOnCaseStmtBody(Stmt *CaseStmt, Stmt *SubStmt); 2270 2271 StmtResult ActOnDefaultStmt(SourceLocation DefaultLoc, 2272 SourceLocation ColonLoc, 2273 Stmt *SubStmt, Scope *CurScope); 2274 StmtResult ActOnLabelStmt(SourceLocation IdentLoc, LabelDecl *TheDecl, 2275 SourceLocation ColonLoc, Stmt *SubStmt); 2276 2277 StmtResult ActOnAttributedStmt(SourceLocation AttrLoc, const AttrVec &Attrs, 2278 Stmt *SubStmt); 2279 2280 StmtResult ActOnIfStmt(SourceLocation IfLoc, 2281 FullExprArg CondVal, Decl *CondVar, 2282 Stmt *ThenVal, 2283 SourceLocation ElseLoc, Stmt *ElseVal); 2284 StmtResult ActOnStartOfSwitchStmt(SourceLocation SwitchLoc, 2285 Expr *Cond, 2286 Decl *CondVar); 2287 StmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc, 2288 Stmt *Switch, Stmt *Body); 2289 StmtResult ActOnWhileStmt(SourceLocation WhileLoc, 2290 FullExprArg Cond, 2291 Decl *CondVar, Stmt *Body); 2292 StmtResult ActOnDoStmt(SourceLocation DoLoc, Stmt *Body, 2293 SourceLocation WhileLoc, 2294 SourceLocation CondLParen, Expr *Cond, 2295 SourceLocation CondRParen); 2296 2297 StmtResult ActOnForStmt(SourceLocation ForLoc, 2298 SourceLocation LParenLoc, 2299 Stmt *First, FullExprArg Second, 2300 Decl *SecondVar, 2301 FullExprArg Third, 2302 SourceLocation RParenLoc, 2303 Stmt *Body); 2304 ExprResult ActOnObjCForCollectionOperand(SourceLocation forLoc, 2305 Expr *collection); 2306 StmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc, 2307 SourceLocation LParenLoc, 2308 Stmt *First, Expr *Second, 2309 SourceLocation RParenLoc, Stmt *Body); 2310 StmtResult ActOnCXXForRangeStmt(SourceLocation ForLoc, 2311 SourceLocation LParenLoc, Stmt *LoopVar, 2312 SourceLocation ColonLoc, Expr *Collection, 2313 SourceLocation RParenLoc); 2314 StmtResult BuildCXXForRangeStmt(SourceLocation ForLoc, 2315 SourceLocation ColonLoc, 2316 Stmt *RangeDecl, Stmt *BeginEndDecl, 2317 Expr *Cond, Expr *Inc, 2318 Stmt *LoopVarDecl, 2319 SourceLocation RParenLoc); 2320 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body); 2321 2322 StmtResult ActOnGotoStmt(SourceLocation GotoLoc, 2323 SourceLocation LabelLoc, 2324 LabelDecl *TheDecl); 2325 StmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc, 2326 SourceLocation StarLoc, 2327 Expr *DestExp); 2328 StmtResult ActOnContinueStmt(SourceLocation ContinueLoc, Scope *CurScope); 2329 StmtResult ActOnBreakStmt(SourceLocation GotoLoc, Scope *CurScope); 2330 2331 const VarDecl *getCopyElisionCandidate(QualType ReturnType, Expr *E, 2332 bool AllowFunctionParameters); 2333 2334 StmtResult ActOnReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp); 2335 StmtResult ActOnCapScopeReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp); 2336 2337 StmtResult ActOnAsmStmt(SourceLocation AsmLoc, 2338 bool IsSimple, bool IsVolatile, 2339 unsigned NumOutputs, unsigned NumInputs, 2340 IdentifierInfo **Names, 2341 MultiExprArg Constraints, 2342 MultiExprArg Exprs, 2343 Expr *AsmString, 2344 MultiExprArg Clobbers, 2345 SourceLocation RParenLoc, 2346 bool MSAsm = false); 2347 2348 2349 VarDecl *BuildObjCExceptionDecl(TypeSourceInfo *TInfo, QualType ExceptionType, 2350 SourceLocation StartLoc, 2351 SourceLocation IdLoc, IdentifierInfo *Id, 2352 bool Invalid = false); 2353 2354 Decl *ActOnObjCExceptionDecl(Scope *S, Declarator &D); 2355 2356 StmtResult ActOnObjCAtCatchStmt(SourceLocation AtLoc, SourceLocation RParen, 2357 Decl *Parm, Stmt *Body); 2358 2359 StmtResult ActOnObjCAtFinallyStmt(SourceLocation AtLoc, Stmt *Body); 2360 2361 StmtResult ActOnObjCAtTryStmt(SourceLocation AtLoc, Stmt *Try, 2362 MultiStmtArg Catch, Stmt *Finally); 2363 2364 StmtResult BuildObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw); 2365 StmtResult ActOnObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw, 2366 Scope *CurScope); 2367 ExprResult ActOnObjCAtSynchronizedOperand(SourceLocation atLoc, 2368 Expr *operand); 2369 StmtResult ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc, 2370 Expr *SynchExpr, 2371 Stmt *SynchBody); 2372 2373 StmtResult ActOnObjCAutoreleasePoolStmt(SourceLocation AtLoc, Stmt *Body); 2374 2375 VarDecl *BuildExceptionDeclaration(Scope *S, TypeSourceInfo *TInfo, 2376 SourceLocation StartLoc, 2377 SourceLocation IdLoc, 2378 IdentifierInfo *Id); 2379 2380 Decl *ActOnExceptionDeclarator(Scope *S, Declarator &D); 2381 2382 StmtResult ActOnCXXCatchBlock(SourceLocation CatchLoc, 2383 Decl *ExDecl, Stmt *HandlerBlock); 2384 StmtResult ActOnCXXTryBlock(SourceLocation TryLoc, Stmt *TryBlock, 2385 MultiStmtArg Handlers); 2386 2387 StmtResult ActOnSEHTryBlock(bool IsCXXTry, // try (true) or __try (false) ? 2388 SourceLocation TryLoc, 2389 Stmt *TryBlock, 2390 Stmt *Handler); 2391 2392 StmtResult ActOnSEHExceptBlock(SourceLocation Loc, 2393 Expr *FilterExpr, 2394 Stmt *Block); 2395 2396 StmtResult ActOnSEHFinallyBlock(SourceLocation Loc, 2397 Stmt *Block); 2398 2399 void DiagnoseReturnInConstructorExceptionHandler(CXXTryStmt *TryBlock); 2400 2401 bool ShouldWarnIfUnusedFileScopedDecl(const DeclaratorDecl *D) const; 2402 2403 /// \brief If it's a file scoped decl that must warn if not used, keep track 2404 /// of it. 2405 void MarkUnusedFileScopedDecl(const DeclaratorDecl *D); 2406 2407 /// DiagnoseUnusedExprResult - If the statement passed in is an expression 2408 /// whose result is unused, warn. 2409 void DiagnoseUnusedExprResult(const Stmt *S); 2410 void DiagnoseUnusedDecl(const NamedDecl *ND); 2411 2412 /// Emit \p DiagID if statement located on \p StmtLoc has a suspicious null 2413 /// statement as a \p Body, and it is located on the same line. 2414 /// 2415 /// This helps prevent bugs due to typos, such as: 2416 /// if (condition); 2417 /// do_stuff(); 2418 void DiagnoseEmptyStmtBody(SourceLocation StmtLoc, 2419 const Stmt *Body, 2420 unsigned DiagID); 2421 2422 /// Warn if a for/while loop statement \p S, which is followed by 2423 /// \p PossibleBody, has a suspicious null statement as a body. 2424 void DiagnoseEmptyLoopBody(const Stmt *S, 2425 const Stmt *PossibleBody); 2426 2427 ParsingDeclState PushParsingDeclaration() { 2428 return DelayedDiagnostics.pushParsingDecl(); 2429 } 2430 void PopParsingDeclaration(ParsingDeclState state, Decl *decl) { 2431 DelayedDiagnostics::popParsingDecl(*this, state, decl); 2432 } 2433 2434 typedef ProcessingContextState ParsingClassState; 2435 ParsingClassState PushParsingClass() { 2436 return DelayedDiagnostics.pushContext(); 2437 } 2438 void PopParsingClass(ParsingClassState state) { 2439 DelayedDiagnostics.popContext(state); 2440 } 2441 2442 void EmitDeprecationWarning(NamedDecl *D, StringRef Message, 2443 SourceLocation Loc, 2444 const ObjCInterfaceDecl *UnknownObjCClass=0); 2445 2446 void HandleDelayedDeprecationCheck(sema::DelayedDiagnostic &DD, Decl *Ctx); 2447 2448 bool makeUnavailableInSystemHeader(SourceLocation loc, 2449 StringRef message); 2450 2451 //===--------------------------------------------------------------------===// 2452 // Expression Parsing Callbacks: SemaExpr.cpp. 2453 2454 bool CanUseDecl(NamedDecl *D); 2455 bool DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc, 2456 const ObjCInterfaceDecl *UnknownObjCClass=0); 2457 void NoteDeletedFunction(FunctionDecl *FD); 2458 std::string getDeletedOrUnavailableSuffix(const FunctionDecl *FD); 2459 bool DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *PD, 2460 ObjCMethodDecl *Getter, 2461 SourceLocation Loc); 2462 void DiagnoseSentinelCalls(NamedDecl *D, SourceLocation Loc, 2463 Expr **Args, unsigned NumArgs); 2464 2465 void PushExpressionEvaluationContext(ExpressionEvaluationContext NewContext, 2466 Decl *LambdaContextDecl = 0, 2467 bool IsDecltype = false); 2468 2469 void PopExpressionEvaluationContext(); 2470 2471 void DiscardCleanupsInEvaluationContext(); 2472 2473 ExprResult TranformToPotentiallyEvaluated(Expr *E); 2474 ExprResult HandleExprEvaluationContextForTypeof(Expr *E); 2475 2476 ExprResult ActOnConstantExpression(ExprResult Res); 2477 2478 // Functions for marking a declaration referenced. These functions also 2479 // contain the relevant logic for marking if a reference to a function or 2480 // variable is an odr-use (in the C++11 sense). There are separate variants 2481 // for expressions referring to a decl; these exist because odr-use marking 2482 // needs to be delayed for some constant variables when we build one of the 2483 // named expressions. 2484 void MarkAnyDeclReferenced(SourceLocation Loc, Decl *D); 2485 void MarkFunctionReferenced(SourceLocation Loc, FunctionDecl *Func); 2486 void MarkVariableReferenced(SourceLocation Loc, VarDecl *Var); 2487 void MarkDeclRefReferenced(DeclRefExpr *E); 2488 void MarkMemberReferenced(MemberExpr *E); 2489 2490 void UpdateMarkingForLValueToRValue(Expr *E); 2491 void CleanupVarDeclMarking(); 2492 2493 enum TryCaptureKind { 2494 TryCapture_Implicit, TryCapture_ExplicitByVal, TryCapture_ExplicitByRef 2495 }; 2496 2497 /// \brief Try to capture the given variable. 2498 /// 2499 /// \param Var The variable to capture. 2500 /// 2501 /// \param Loc The location at which the capture occurs. 2502 /// 2503 /// \param Kind The kind of capture, which may be implicit (for either a 2504 /// block or a lambda), or explicit by-value or by-reference (for a lambda). 2505 /// 2506 /// \param EllipsisLoc The location of the ellipsis, if one is provided in 2507 /// an explicit lambda capture. 2508 /// 2509 /// \param BuildAndDiagnose Whether we are actually supposed to add the 2510 /// captures or diagnose errors. If false, this routine merely check whether 2511 /// the capture can occur without performing the capture itself or complaining 2512 /// if the variable cannot be captured. 2513 /// 2514 /// \param CaptureType Will be set to the type of the field used to capture 2515 /// this variable in the innermost block or lambda. Only valid when the 2516 /// variable can be captured. 2517 /// 2518 /// \param DeclRefType Will be set to the type of a refernce to the capture 2519 /// from within the current scope. Only valid when the variable can be 2520 /// captured. 2521 /// 2522 /// \returns true if an error occurred (i.e., the variable cannot be 2523 /// captured) and false if the capture succeeded. 2524 bool tryCaptureVariable(VarDecl *Var, SourceLocation Loc, TryCaptureKind Kind, 2525 SourceLocation EllipsisLoc, bool BuildAndDiagnose, 2526 QualType &CaptureType, 2527 QualType &DeclRefType); 2528 2529 /// \brief Try to capture the given variable. 2530 bool tryCaptureVariable(VarDecl *Var, SourceLocation Loc, 2531 TryCaptureKind Kind = TryCapture_Implicit, 2532 SourceLocation EllipsisLoc = SourceLocation()); 2533 2534 /// \brief Given a variable, determine the type that a reference to that 2535 /// variable will have in the given scope. 2536 QualType getCapturedDeclRefType(VarDecl *Var, SourceLocation Loc); 2537 2538 void MarkDeclarationsReferencedInType(SourceLocation Loc, QualType T); 2539 void MarkDeclarationsReferencedInExpr(Expr *E, 2540 bool SkipLocalVariables = false); 2541 2542 /// \brief Try to recover by turning the given expression into a 2543 /// call. Returns true if recovery was attempted or an error was 2544 /// emitted; this may also leave the ExprResult invalid. 2545 bool tryToRecoverWithCall(ExprResult &E, const PartialDiagnostic &PD, 2546 bool ForceComplain = false, 2547 bool (*IsPlausibleResult)(QualType) = 0); 2548 2549 /// \brief Figure out if an expression could be turned into a call. 2550 bool isExprCallable(const Expr &E, QualType &ZeroArgCallReturnTy, 2551 UnresolvedSetImpl &NonTemplateOverloads); 2552 2553 /// \brief Conditionally issue a diagnostic based on the current 2554 /// evaluation context. 2555 /// 2556 /// \param stmt - If stmt is non-null, delay reporting the diagnostic until 2557 /// the function body is parsed, and then do a basic reachability analysis to 2558 /// determine if the statement is reachable. If it is unreachable, the 2559 /// diagnostic will not be emitted. 2560 bool DiagRuntimeBehavior(SourceLocation Loc, const Stmt *Statement, 2561 const PartialDiagnostic &PD); 2562 2563 // Primary Expressions. 2564 SourceRange getExprRange(Expr *E) const; 2565 2566 ExprResult ActOnIdExpression(Scope *S, CXXScopeSpec &SS, 2567 SourceLocation TemplateKWLoc, 2568 UnqualifiedId &Id, 2569 bool HasTrailingLParen, bool IsAddressOfOperand, 2570 CorrectionCandidateCallback *CCC = 0); 2571 2572 void DecomposeUnqualifiedId(const UnqualifiedId &Id, 2573 TemplateArgumentListInfo &Buffer, 2574 DeclarationNameInfo &NameInfo, 2575 const TemplateArgumentListInfo *&TemplateArgs); 2576 2577 bool DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R, 2578 CorrectionCandidateCallback &CCC, 2579 TemplateArgumentListInfo *ExplicitTemplateArgs = 0, 2580 llvm::ArrayRef<Expr *> Args = llvm::ArrayRef<Expr *>()); 2581 2582 ExprResult LookupInObjCMethod(LookupResult &LookUp, Scope *S, 2583 IdentifierInfo *II, 2584 bool AllowBuiltinCreation=false); 2585 2586 ExprResult ActOnDependentIdExpression(const CXXScopeSpec &SS, 2587 SourceLocation TemplateKWLoc, 2588 const DeclarationNameInfo &NameInfo, 2589 bool isAddressOfOperand, 2590 const TemplateArgumentListInfo *TemplateArgs); 2591 2592 ExprResult BuildDeclRefExpr(ValueDecl *D, QualType Ty, 2593 ExprValueKind VK, 2594 SourceLocation Loc, 2595 const CXXScopeSpec *SS = 0); 2596 ExprResult BuildDeclRefExpr(ValueDecl *D, QualType Ty, 2597 ExprValueKind VK, 2598 const DeclarationNameInfo &NameInfo, 2599 const CXXScopeSpec *SS = 0); 2600 ExprResult 2601 BuildAnonymousStructUnionMemberReference(const CXXScopeSpec &SS, 2602 SourceLocation nameLoc, 2603 IndirectFieldDecl *indirectField, 2604 Expr *baseObjectExpr = 0, 2605 SourceLocation opLoc = SourceLocation()); 2606 ExprResult BuildPossibleImplicitMemberExpr(const CXXScopeSpec &SS, 2607 SourceLocation TemplateKWLoc, 2608 LookupResult &R, 2609 const TemplateArgumentListInfo *TemplateArgs); 2610 ExprResult BuildImplicitMemberExpr(const CXXScopeSpec &SS, 2611 SourceLocation TemplateKWLoc, 2612 LookupResult &R, 2613 const TemplateArgumentListInfo *TemplateArgs, 2614 bool IsDefiniteInstance); 2615 bool UseArgumentDependentLookup(const CXXScopeSpec &SS, 2616 const LookupResult &R, 2617 bool HasTrailingLParen); 2618 2619 ExprResult BuildQualifiedDeclarationNameExpr(CXXScopeSpec &SS, 2620 const DeclarationNameInfo &NameInfo); 2621 ExprResult BuildDependentDeclRefExpr(const CXXScopeSpec &SS, 2622 SourceLocation TemplateKWLoc, 2623 const DeclarationNameInfo &NameInfo, 2624 const TemplateArgumentListInfo *TemplateArgs); 2625 2626 ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS, 2627 LookupResult &R, 2628 bool NeedsADL); 2629 ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS, 2630 const DeclarationNameInfo &NameInfo, 2631 NamedDecl *D); 2632 2633 ExprResult BuildLiteralOperatorCall(LookupResult &R, 2634 DeclarationNameInfo &SuffixInfo, 2635 ArrayRef<Expr*> Args, 2636 SourceLocation LitEndLoc, 2637 TemplateArgumentListInfo *ExplicitTemplateArgs = 0); 2638 2639 ExprResult ActOnPredefinedExpr(SourceLocation Loc, tok::TokenKind Kind); 2640 ExprResult ActOnIntegerConstant(SourceLocation Loc, uint64_t Val); 2641 ExprResult ActOnNumericConstant(const Token &Tok, Scope *UDLScope = 0); 2642 ExprResult ActOnCharacterConstant(const Token &Tok, Scope *UDLScope = 0); 2643 ExprResult ActOnParenExpr(SourceLocation L, SourceLocation R, Expr *E); 2644 ExprResult ActOnParenListExpr(SourceLocation L, 2645 SourceLocation R, 2646 MultiExprArg Val); 2647 2648 /// ActOnStringLiteral - The specified tokens were lexed as pasted string 2649 /// fragments (e.g. "foo" "bar" L"baz"). 2650 ExprResult ActOnStringLiteral(const Token *StringToks, unsigned NumStringToks, 2651 Scope *UDLScope = 0); 2652 2653 ExprResult ActOnGenericSelectionExpr(SourceLocation KeyLoc, 2654 SourceLocation DefaultLoc, 2655 SourceLocation RParenLoc, 2656 Expr *ControllingExpr, 2657 MultiTypeArg ArgTypes, 2658 MultiExprArg ArgExprs); 2659 ExprResult CreateGenericSelectionExpr(SourceLocation KeyLoc, 2660 SourceLocation DefaultLoc, 2661 SourceLocation RParenLoc, 2662 Expr *ControllingExpr, 2663 TypeSourceInfo **Types, 2664 Expr **Exprs, 2665 unsigned NumAssocs); 2666 2667 // Binary/Unary Operators. 'Tok' is the token for the operator. 2668 ExprResult CreateBuiltinUnaryOp(SourceLocation OpLoc, UnaryOperatorKind Opc, 2669 Expr *InputExpr); 2670 ExprResult BuildUnaryOp(Scope *S, SourceLocation OpLoc, 2671 UnaryOperatorKind Opc, Expr *Input); 2672 ExprResult ActOnUnaryOp(Scope *S, SourceLocation OpLoc, 2673 tok::TokenKind Op, Expr *Input); 2674 2675 ExprResult CreateUnaryExprOrTypeTraitExpr(TypeSourceInfo *TInfo, 2676 SourceLocation OpLoc, 2677 UnaryExprOrTypeTrait ExprKind, 2678 SourceRange R); 2679 ExprResult CreateUnaryExprOrTypeTraitExpr(Expr *E, SourceLocation OpLoc, 2680 UnaryExprOrTypeTrait ExprKind); 2681 ExprResult 2682 ActOnUnaryExprOrTypeTraitExpr(SourceLocation OpLoc, 2683 UnaryExprOrTypeTrait ExprKind, 2684 bool IsType, void *TyOrEx, 2685 const SourceRange &ArgRange); 2686 2687 ExprResult CheckPlaceholderExpr(Expr *E); 2688 bool CheckVecStepExpr(Expr *E); 2689 2690 bool CheckUnaryExprOrTypeTraitOperand(Expr *E, UnaryExprOrTypeTrait ExprKind); 2691 bool CheckUnaryExprOrTypeTraitOperand(QualType ExprType, SourceLocation OpLoc, 2692 SourceRange ExprRange, 2693 UnaryExprOrTypeTrait ExprKind); 2694 ExprResult ActOnSizeofParameterPackExpr(Scope *S, 2695 SourceLocation OpLoc, 2696 IdentifierInfo &Name, 2697 SourceLocation NameLoc, 2698 SourceLocation RParenLoc); 2699 ExprResult ActOnPostfixUnaryOp(Scope *S, SourceLocation OpLoc, 2700 tok::TokenKind Kind, Expr *Input); 2701 2702 ExprResult ActOnArraySubscriptExpr(Scope *S, Expr *Base, SourceLocation LLoc, 2703 Expr *Idx, SourceLocation RLoc); 2704 ExprResult CreateBuiltinArraySubscriptExpr(Expr *Base, SourceLocation LLoc, 2705 Expr *Idx, SourceLocation RLoc); 2706 2707 ExprResult BuildMemberReferenceExpr(Expr *Base, QualType BaseType, 2708 SourceLocation OpLoc, bool IsArrow, 2709 CXXScopeSpec &SS, 2710 SourceLocation TemplateKWLoc, 2711 NamedDecl *FirstQualifierInScope, 2712 const DeclarationNameInfo &NameInfo, 2713 const TemplateArgumentListInfo *TemplateArgs); 2714 2715 ExprResult BuildMemberReferenceExpr(Expr *Base, QualType BaseType, 2716 SourceLocation OpLoc, bool IsArrow, 2717 const CXXScopeSpec &SS, 2718 SourceLocation TemplateKWLoc, 2719 NamedDecl *FirstQualifierInScope, 2720 LookupResult &R, 2721 const TemplateArgumentListInfo *TemplateArgs, 2722 bool SuppressQualifierCheck = false); 2723 2724 ExprResult PerformMemberExprBaseConversion(Expr *Base, bool IsArrow); 2725 ExprResult LookupMemberExpr(LookupResult &R, ExprResult &Base, 2726 bool &IsArrow, SourceLocation OpLoc, 2727 CXXScopeSpec &SS, 2728 Decl *ObjCImpDecl, 2729 bool HasTemplateArgs); 2730 2731 bool CheckQualifiedMemberReference(Expr *BaseExpr, QualType BaseType, 2732 const CXXScopeSpec &SS, 2733 const LookupResult &R); 2734 2735 ExprResult ActOnDependentMemberExpr(Expr *Base, QualType BaseType, 2736 bool IsArrow, SourceLocation OpLoc, 2737 const CXXScopeSpec &SS, 2738 SourceLocation TemplateKWLoc, 2739 NamedDecl *FirstQualifierInScope, 2740 const DeclarationNameInfo &NameInfo, 2741 const TemplateArgumentListInfo *TemplateArgs); 2742 2743 ExprResult ActOnMemberAccessExpr(Scope *S, Expr *Base, 2744 SourceLocation OpLoc, 2745 tok::TokenKind OpKind, 2746 CXXScopeSpec &SS, 2747 SourceLocation TemplateKWLoc, 2748 UnqualifiedId &Member, 2749 Decl *ObjCImpDecl, 2750 bool HasTrailingLParen); 2751 2752 void ActOnDefaultCtorInitializers(Decl *CDtorDecl); 2753 bool ConvertArgumentsForCall(CallExpr *Call, Expr *Fn, 2754 FunctionDecl *FDecl, 2755 const FunctionProtoType *Proto, 2756 Expr **Args, unsigned NumArgs, 2757 SourceLocation RParenLoc, 2758 bool ExecConfig = false); 2759 void CheckStaticArrayArgument(SourceLocation CallLoc, 2760 ParmVarDecl *Param, 2761 const Expr *ArgExpr); 2762 2763 /// ActOnCallExpr - Handle a call to Fn with the specified array of arguments. 2764 /// This provides the location of the left/right parens and a list of comma 2765 /// locations. 2766 ExprResult ActOnCallExpr(Scope *S, Expr *Fn, SourceLocation LParenLoc, 2767 MultiExprArg ArgExprs, SourceLocation RParenLoc, 2768 Expr *ExecConfig = 0, bool IsExecConfig = false); 2769 ExprResult BuildResolvedCallExpr(Expr *Fn, NamedDecl *NDecl, 2770 SourceLocation LParenLoc, 2771 Expr **Args, unsigned NumArgs, 2772 SourceLocation RParenLoc, 2773 Expr *Config = 0, 2774 bool IsExecConfig = false); 2775 2776 ExprResult ActOnCUDAExecConfigExpr(Scope *S, SourceLocation LLLLoc, 2777 MultiExprArg ExecConfig, 2778 SourceLocation GGGLoc); 2779 2780 ExprResult ActOnCastExpr(Scope *S, SourceLocation LParenLoc, 2781 Declarator &D, ParsedType &Ty, 2782 SourceLocation RParenLoc, Expr *CastExpr); 2783 ExprResult BuildCStyleCastExpr(SourceLocation LParenLoc, 2784 TypeSourceInfo *Ty, 2785 SourceLocation RParenLoc, 2786 Expr *Op); 2787 CastKind PrepareScalarCast(ExprResult &src, QualType destType); 2788 2789 /// \brief Build an altivec or OpenCL literal. 2790 ExprResult BuildVectorLiteral(SourceLocation LParenLoc, 2791 SourceLocation RParenLoc, Expr *E, 2792 TypeSourceInfo *TInfo); 2793 2794 ExprResult MaybeConvertParenListExprToParenExpr(Scope *S, Expr *ME); 2795 2796 ExprResult ActOnCompoundLiteral(SourceLocation LParenLoc, 2797 ParsedType Ty, 2798 SourceLocation RParenLoc, 2799 Expr *InitExpr); 2800 2801 ExprResult BuildCompoundLiteralExpr(SourceLocation LParenLoc, 2802 TypeSourceInfo *TInfo, 2803 SourceLocation RParenLoc, 2804 Expr *LiteralExpr); 2805 2806 ExprResult ActOnInitList(SourceLocation LBraceLoc, 2807 MultiExprArg InitArgList, 2808 SourceLocation RBraceLoc); 2809 2810 ExprResult ActOnDesignatedInitializer(Designation &Desig, 2811 SourceLocation Loc, 2812 bool GNUSyntax, 2813 ExprResult Init); 2814 2815 ExprResult ActOnBinOp(Scope *S, SourceLocation TokLoc, 2816 tok::TokenKind Kind, Expr *LHSExpr, Expr *RHSExpr); 2817 ExprResult BuildBinOp(Scope *S, SourceLocation OpLoc, 2818 BinaryOperatorKind Opc, Expr *LHSExpr, Expr *RHSExpr); 2819 ExprResult CreateBuiltinBinOp(SourceLocation OpLoc, BinaryOperatorKind Opc, 2820 Expr *LHSExpr, Expr *RHSExpr); 2821 2822 /// ActOnConditionalOp - Parse a ?: operation. Note that 'LHS' may be null 2823 /// in the case of a the GNU conditional expr extension. 2824 ExprResult ActOnConditionalOp(SourceLocation QuestionLoc, 2825 SourceLocation ColonLoc, 2826 Expr *CondExpr, Expr *LHSExpr, Expr *RHSExpr); 2827 2828 /// ActOnAddrLabel - Parse the GNU address of label extension: "&&foo". 2829 ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc, 2830 LabelDecl *TheDecl); 2831 2832 void ActOnStartStmtExpr(); 2833 ExprResult ActOnStmtExpr(SourceLocation LPLoc, Stmt *SubStmt, 2834 SourceLocation RPLoc); // "({..})" 2835 void ActOnStmtExprError(); 2836 2837 // __builtin_offsetof(type, identifier(.identifier|[expr])*) 2838 struct OffsetOfComponent { 2839 SourceLocation LocStart, LocEnd; 2840 bool isBrackets; // true if [expr], false if .ident 2841 union { 2842 IdentifierInfo *IdentInfo; 2843 Expr *E; 2844 } U; 2845 }; 2846 2847 /// __builtin_offsetof(type, a.b[123][456].c) 2848 ExprResult BuildBuiltinOffsetOf(SourceLocation BuiltinLoc, 2849 TypeSourceInfo *TInfo, 2850 OffsetOfComponent *CompPtr, 2851 unsigned NumComponents, 2852 SourceLocation RParenLoc); 2853 ExprResult ActOnBuiltinOffsetOf(Scope *S, 2854 SourceLocation BuiltinLoc, 2855 SourceLocation TypeLoc, 2856 ParsedType ParsedArgTy, 2857 OffsetOfComponent *CompPtr, 2858 unsigned NumComponents, 2859 SourceLocation RParenLoc); 2860 2861 // __builtin_choose_expr(constExpr, expr1, expr2) 2862 ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc, 2863 Expr *CondExpr, Expr *LHSExpr, 2864 Expr *RHSExpr, SourceLocation RPLoc); 2865 2866 // __builtin_va_arg(expr, type) 2867 ExprResult ActOnVAArg(SourceLocation BuiltinLoc, Expr *E, ParsedType Ty, 2868 SourceLocation RPLoc); 2869 ExprResult BuildVAArgExpr(SourceLocation BuiltinLoc, Expr *E, 2870 TypeSourceInfo *TInfo, SourceLocation RPLoc); 2871 2872 // __null 2873 ExprResult ActOnGNUNullExpr(SourceLocation TokenLoc); 2874 2875 bool CheckCaseExpression(Expr *E); 2876 2877 /// \brief Describes the result of an "if-exists" condition check. 2878 enum IfExistsResult { 2879 /// \brief The symbol exists. 2880 IER_Exists, 2881 2882 /// \brief The symbol does not exist. 2883 IER_DoesNotExist, 2884 2885 /// \brief The name is a dependent name, so the results will differ 2886 /// from one instantiation to the next. 2887 IER_Dependent, 2888 2889 /// \brief An error occurred. 2890 IER_Error 2891 }; 2892 2893 IfExistsResult 2894 CheckMicrosoftIfExistsSymbol(Scope *S, CXXScopeSpec &SS, 2895 const DeclarationNameInfo &TargetNameInfo); 2896 2897 IfExistsResult 2898 CheckMicrosoftIfExistsSymbol(Scope *S, SourceLocation KeywordLoc, 2899 bool IsIfExists, CXXScopeSpec &SS, 2900 UnqualifiedId &Name); 2901 2902 StmtResult BuildMSDependentExistsStmt(SourceLocation KeywordLoc, 2903 bool IsIfExists, 2904 NestedNameSpecifierLoc QualifierLoc, 2905 DeclarationNameInfo NameInfo, 2906 Stmt *Nested); 2907 StmtResult ActOnMSDependentExistsStmt(SourceLocation KeywordLoc, 2908 bool IsIfExists, 2909 CXXScopeSpec &SS, UnqualifiedId &Name, 2910 Stmt *Nested); 2911 2912 //===------------------------- "Block" Extension ------------------------===// 2913 2914 /// ActOnBlockStart - This callback is invoked when a block literal is 2915 /// started. 2916 void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope); 2917 2918 /// ActOnBlockArguments - This callback allows processing of block arguments. 2919 /// If there are no arguments, this is still invoked. 2920 void ActOnBlockArguments(Declarator &ParamInfo, Scope *CurScope); 2921 2922 /// ActOnBlockError - If there is an error parsing a block, this callback 2923 /// is invoked to pop the information about the block from the action impl. 2924 void ActOnBlockError(SourceLocation CaretLoc, Scope *CurScope); 2925 2926 /// ActOnBlockStmtExpr - This is called when the body of a block statement 2927 /// literal was successfully completed. ^(int x){...} 2928 ExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc, Stmt *Body, 2929 Scope *CurScope); 2930 2931 //===---------------------------- OpenCL Features -----------------------===// 2932 2933 /// __builtin_astype(...) 2934 ExprResult ActOnAsTypeExpr(Expr *E, ParsedType ParsedDestTy, 2935 SourceLocation BuiltinLoc, 2936 SourceLocation RParenLoc); 2937 2938 //===---------------------------- C++ Features --------------------------===// 2939 2940 // Act on C++ namespaces 2941 Decl *ActOnStartNamespaceDef(Scope *S, SourceLocation InlineLoc, 2942 SourceLocation NamespaceLoc, 2943 SourceLocation IdentLoc, 2944 IdentifierInfo *Ident, 2945 SourceLocation LBrace, 2946 AttributeList *AttrList); 2947 void ActOnFinishNamespaceDef(Decl *Dcl, SourceLocation RBrace); 2948 2949 NamespaceDecl *getStdNamespace() const; 2950 NamespaceDecl *getOrCreateStdNamespace(); 2951 2952 CXXRecordDecl *getStdBadAlloc() const; 2953 2954 /// \brief Tests whether Ty is an instance of std::initializer_list and, if 2955 /// it is and Element is not NULL, assigns the element type to Element. 2956 bool isStdInitializerList(QualType Ty, QualType *Element); 2957 2958 /// \brief Looks for the std::initializer_list template and instantiates it 2959 /// with Element, or emits an error if it's not found. 2960 /// 2961 /// \returns The instantiated template, or null on error. 2962 QualType BuildStdInitializerList(QualType Element, SourceLocation Loc); 2963 2964 /// \brief Determine whether Ctor is an initializer-list constructor, as 2965 /// defined in [dcl.init.list]p2. 2966 bool isInitListConstructor(const CXXConstructorDecl *Ctor); 2967 2968 Decl *ActOnUsingDirective(Scope *CurScope, 2969 SourceLocation UsingLoc, 2970 SourceLocation NamespcLoc, 2971 CXXScopeSpec &SS, 2972 SourceLocation IdentLoc, 2973 IdentifierInfo *NamespcName, 2974 AttributeList *AttrList); 2975 2976 void PushUsingDirective(Scope *S, UsingDirectiveDecl *UDir); 2977 2978 Decl *ActOnNamespaceAliasDef(Scope *CurScope, 2979 SourceLocation NamespaceLoc, 2980 SourceLocation AliasLoc, 2981 IdentifierInfo *Alias, 2982 CXXScopeSpec &SS, 2983 SourceLocation IdentLoc, 2984 IdentifierInfo *Ident); 2985 2986 void HideUsingShadowDecl(Scope *S, UsingShadowDecl *Shadow); 2987 bool CheckUsingShadowDecl(UsingDecl *UD, NamedDecl *Target, 2988 const LookupResult &PreviousDecls); 2989 UsingShadowDecl *BuildUsingShadowDecl(Scope *S, UsingDecl *UD, 2990 NamedDecl *Target); 2991 2992 bool CheckUsingDeclRedeclaration(SourceLocation UsingLoc, 2993 bool isTypeName, 2994 const CXXScopeSpec &SS, 2995 SourceLocation NameLoc, 2996 const LookupResult &Previous); 2997 bool CheckUsingDeclQualifier(SourceLocation UsingLoc, 2998 const CXXScopeSpec &SS, 2999 SourceLocation NameLoc); 3000 3001 NamedDecl *BuildUsingDeclaration(Scope *S, AccessSpecifier AS, 3002 SourceLocation UsingLoc, 3003 CXXScopeSpec &SS, 3004 const DeclarationNameInfo &NameInfo, 3005 AttributeList *AttrList, 3006 bool IsInstantiation, 3007 bool IsTypeName, 3008 SourceLocation TypenameLoc); 3009 3010 bool CheckInheritingConstructorUsingDecl(UsingDecl *UD); 3011 3012 Decl *ActOnUsingDeclaration(Scope *CurScope, 3013 AccessSpecifier AS, 3014 bool HasUsingKeyword, 3015 SourceLocation UsingLoc, 3016 CXXScopeSpec &SS, 3017 UnqualifiedId &Name, 3018 AttributeList *AttrList, 3019 bool IsTypeName, 3020 SourceLocation TypenameLoc); 3021 Decl *ActOnAliasDeclaration(Scope *CurScope, 3022 AccessSpecifier AS, 3023 MultiTemplateParamsArg TemplateParams, 3024 SourceLocation UsingLoc, 3025 UnqualifiedId &Name, 3026 TypeResult Type); 3027 3028 /// InitializeVarWithConstructor - Creates an CXXConstructExpr 3029 /// and sets it as the initializer for the the passed in VarDecl. 3030 bool InitializeVarWithConstructor(VarDecl *VD, 3031 CXXConstructorDecl *Constructor, 3032 MultiExprArg Exprs, 3033 bool HadMultipleCandidates); 3034 3035 /// BuildCXXConstructExpr - Creates a complete call to a constructor, 3036 /// including handling of its default argument expressions. 3037 /// 3038 /// \param ConstructKind - a CXXConstructExpr::ConstructionKind 3039 ExprResult 3040 BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType, 3041 CXXConstructorDecl *Constructor, MultiExprArg Exprs, 3042 bool HadMultipleCandidates, bool RequiresZeroInit, 3043 unsigned ConstructKind, SourceRange ParenRange); 3044 3045 // FIXME: Can re remove this and have the above BuildCXXConstructExpr check if 3046 // the constructor can be elidable? 3047 ExprResult 3048 BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType, 3049 CXXConstructorDecl *Constructor, bool Elidable, 3050 MultiExprArg Exprs, bool HadMultipleCandidates, 3051 bool RequiresZeroInit, unsigned ConstructKind, 3052 SourceRange ParenRange); 3053 3054 /// BuildCXXDefaultArgExpr - Creates a CXXDefaultArgExpr, instantiating 3055 /// the default expr if needed. 3056 ExprResult BuildCXXDefaultArgExpr(SourceLocation CallLoc, 3057 FunctionDecl *FD, 3058 ParmVarDecl *Param); 3059 3060 /// FinalizeVarWithDestructor - Prepare for calling destructor on the 3061 /// constructed variable. 3062 void FinalizeVarWithDestructor(VarDecl *VD, const RecordType *DeclInitType); 3063 3064 /// \brief Helper class that collects exception specifications for 3065 /// implicitly-declared special member functions. 3066 class ImplicitExceptionSpecification { 3067 // Pointer to allow copying 3068 Sema *Self; 3069 // We order exception specifications thus: 3070 // noexcept is the most restrictive, but is only used in C++0x. 3071 // throw() comes next. 3072 // Then a throw(collected exceptions) 3073 // Finally no specification. 3074 // throw(...) is used instead if any called function uses it. 3075 // 3076 // If this exception specification cannot be known yet (for instance, 3077 // because this is the exception specification for a defaulted default 3078 // constructor and we haven't finished parsing the deferred parts of the 3079 // class yet), the C++0x standard does not specify how to behave. We 3080 // record this as an 'unknown' exception specification, which overrules 3081 // any other specification (even 'none', to keep this rule simple). 3082 ExceptionSpecificationType ComputedEST; 3083 llvm::SmallPtrSet<CanQualType, 4> ExceptionsSeen; 3084 SmallVector<QualType, 4> Exceptions; 3085 3086 void ClearExceptions() { 3087 ExceptionsSeen.clear(); 3088 Exceptions.clear(); 3089 } 3090 3091 public: 3092 explicit ImplicitExceptionSpecification(Sema &Self) 3093 : Self(&Self), ComputedEST(EST_BasicNoexcept) { 3094 if (!Self.Context.getLangOpts().CPlusPlus0x) 3095 ComputedEST = EST_DynamicNone; 3096 } 3097 3098 /// \brief Get the computed exception specification type. 3099 ExceptionSpecificationType getExceptionSpecType() const { 3100 assert(ComputedEST != EST_ComputedNoexcept && 3101 "noexcept(expr) should not be a possible result"); 3102 return ComputedEST; 3103 } 3104 3105 /// \brief The number of exceptions in the exception specification. 3106 unsigned size() const { return Exceptions.size(); } 3107 3108 /// \brief The set of exceptions in the exception specification. 3109 const QualType *data() const { return Exceptions.data(); } 3110 3111 /// \brief Integrate another called method into the collected data. 3112 void CalledDecl(SourceLocation CallLoc, CXXMethodDecl *Method); 3113 3114 /// \brief Integrate an invoked expression into the collected data. 3115 void CalledExpr(Expr *E); 3116 3117 /// \brief Specify that the exception specification can't be detemined yet. 3118 void SetDelayed() { 3119 ClearExceptions(); 3120 ComputedEST = EST_Delayed; 3121 } 3122 3123 FunctionProtoType::ExtProtoInfo getEPI() const { 3124 FunctionProtoType::ExtProtoInfo EPI; 3125 EPI.ExceptionSpecType = getExceptionSpecType(); 3126 EPI.NumExceptions = size(); 3127 EPI.Exceptions = data(); 3128 return EPI; 3129 } 3130 }; 3131 3132 /// \brief Determine what sort of exception specification a defaulted 3133 /// copy constructor of a class will have. 3134 ImplicitExceptionSpecification 3135 ComputeDefaultedDefaultCtorExceptionSpec(CXXRecordDecl *ClassDecl); 3136 3137 /// \brief Determine what sort of exception specification a defaulted 3138 /// default constructor of a class will have, and whether the parameter 3139 /// will be const. 3140 std::pair<ImplicitExceptionSpecification, bool> 3141 ComputeDefaultedCopyCtorExceptionSpecAndConst(CXXRecordDecl *ClassDecl); 3142 3143 /// \brief Determine what sort of exception specification a defautled 3144 /// copy assignment operator of a class will have, and whether the 3145 /// parameter will be const. 3146 std::pair<ImplicitExceptionSpecification, bool> 3147 ComputeDefaultedCopyAssignmentExceptionSpecAndConst(CXXRecordDecl *ClassDecl); 3148 3149 /// \brief Determine what sort of exception specification a defaulted move 3150 /// constructor of a class will have. 3151 ImplicitExceptionSpecification 3152 ComputeDefaultedMoveCtorExceptionSpec(CXXRecordDecl *ClassDecl); 3153 3154 /// \brief Determine what sort of exception specification a defaulted move 3155 /// assignment operator of a class will have. 3156 ImplicitExceptionSpecification 3157 ComputeDefaultedMoveAssignmentExceptionSpec(CXXRecordDecl *ClassDecl); 3158 3159 /// \brief Determine what sort of exception specification a defaulted 3160 /// destructor of a class will have. 3161 ImplicitExceptionSpecification 3162 ComputeDefaultedDtorExceptionSpec(CXXRecordDecl *ClassDecl); 3163 3164 /// \brief Check the given exception-specification and update the 3165 /// extended prototype information with the results. 3166 void checkExceptionSpecification(ExceptionSpecificationType EST, 3167 ArrayRef<ParsedType> DynamicExceptions, 3168 ArrayRef<SourceRange> DynamicExceptionRanges, 3169 Expr *NoexceptExpr, 3170 llvm::SmallVectorImpl<QualType> &Exceptions, 3171 FunctionProtoType::ExtProtoInfo &EPI); 3172 3173 /// \brief Add an exception-specification to the given member function 3174 /// (or member function template). The exception-specification was parsed 3175 /// after the method itself was declared. 3176 void actOnDelayedExceptionSpecification(Decl *Method, 3177 ExceptionSpecificationType EST, 3178 SourceRange SpecificationRange, 3179 ArrayRef<ParsedType> DynamicExceptions, 3180 ArrayRef<SourceRange> DynamicExceptionRanges, 3181 Expr *NoexceptExpr); 3182 3183 /// \brief Determine if a special member function should have a deleted 3184 /// definition when it is defaulted. 3185 bool ShouldDeleteSpecialMember(CXXMethodDecl *MD, CXXSpecialMember CSM, 3186 bool Diagnose = false); 3187 3188 /// \brief Declare the implicit default constructor for the given class. 3189 /// 3190 /// \param ClassDecl The class declaration into which the implicit 3191 /// default constructor will be added. 3192 /// 3193 /// \returns The implicitly-declared default constructor. 3194 CXXConstructorDecl *DeclareImplicitDefaultConstructor( 3195 CXXRecordDecl *ClassDecl); 3196 3197 /// DefineImplicitDefaultConstructor - Checks for feasibility of 3198 /// defining this constructor as the default constructor. 3199 void DefineImplicitDefaultConstructor(SourceLocation CurrentLocation, 3200 CXXConstructorDecl *Constructor); 3201 3202 /// \brief Declare the implicit destructor for the given class. 3203 /// 3204 /// \param ClassDecl The class declaration into which the implicit 3205 /// destructor will be added. 3206 /// 3207 /// \returns The implicitly-declared destructor. 3208 CXXDestructorDecl *DeclareImplicitDestructor(CXXRecordDecl *ClassDecl); 3209 3210 /// DefineImplicitDestructor - Checks for feasibility of 3211 /// defining this destructor as the default destructor. 3212 void DefineImplicitDestructor(SourceLocation CurrentLocation, 3213 CXXDestructorDecl *Destructor); 3214 3215 /// \brief Build an exception spec for destructors that don't have one. 3216 /// 3217 /// C++11 says that user-defined destructors with no exception spec get one 3218 /// that looks as if the destructor was implicitly declared. 3219 void AdjustDestructorExceptionSpec(CXXRecordDecl *ClassDecl, 3220 CXXDestructorDecl *Destructor); 3221 3222 /// \brief Declare all inherited constructors for the given class. 3223 /// 3224 /// \param ClassDecl The class declaration into which the inherited 3225 /// constructors will be added. 3226 void DeclareInheritedConstructors(CXXRecordDecl *ClassDecl); 3227 3228 /// \brief Declare the implicit copy constructor for the given class. 3229 /// 3230 /// \param ClassDecl The class declaration into which the implicit 3231 /// copy constructor will be added. 3232 /// 3233 /// \returns The implicitly-declared copy constructor. 3234 CXXConstructorDecl *DeclareImplicitCopyConstructor(CXXRecordDecl *ClassDecl); 3235 3236 /// DefineImplicitCopyConstructor - Checks for feasibility of 3237 /// defining this constructor as the copy constructor. 3238 void DefineImplicitCopyConstructor(SourceLocation CurrentLocation, 3239 CXXConstructorDecl *Constructor); 3240 3241 /// \brief Declare the implicit move constructor for the given class. 3242 /// 3243 /// \param ClassDecl The Class declaration into which the implicit 3244 /// move constructor will be added. 3245 /// 3246 /// \returns The implicitly-declared move constructor, or NULL if it wasn't 3247 /// declared. 3248 CXXConstructorDecl *DeclareImplicitMoveConstructor(CXXRecordDecl *ClassDecl); 3249 3250 /// DefineImplicitMoveConstructor - Checks for feasibility of 3251 /// defining this constructor as the move constructor. 3252 void DefineImplicitMoveConstructor(SourceLocation CurrentLocation, 3253 CXXConstructorDecl *Constructor); 3254 3255 /// \brief Declare the implicit copy assignment operator for the given class. 3256 /// 3257 /// \param ClassDecl The class declaration into which the implicit 3258 /// copy assignment operator will be added. 3259 /// 3260 /// \returns The implicitly-declared copy assignment operator. 3261 CXXMethodDecl *DeclareImplicitCopyAssignment(CXXRecordDecl *ClassDecl); 3262 3263 /// \brief Defines an implicitly-declared copy assignment operator. 3264 void DefineImplicitCopyAssignment(SourceLocation CurrentLocation, 3265 CXXMethodDecl *MethodDecl); 3266 3267 /// \brief Declare the implicit move assignment operator for the given class. 3268 /// 3269 /// \param ClassDecl The Class declaration into which the implicit 3270 /// move assignment operator will be added. 3271 /// 3272 /// \returns The implicitly-declared move assignment operator, or NULL if it 3273 /// wasn't declared. 3274 CXXMethodDecl *DeclareImplicitMoveAssignment(CXXRecordDecl *ClassDecl); 3275 3276 /// \brief Defines an implicitly-declared move assignment operator. 3277 void DefineImplicitMoveAssignment(SourceLocation CurrentLocation, 3278 CXXMethodDecl *MethodDecl); 3279 3280 /// \brief Force the declaration of any implicitly-declared members of this 3281 /// class. 3282 void ForceDeclarationOfImplicitMembers(CXXRecordDecl *Class); 3283 3284 /// \brief Determine whether the given function is an implicitly-deleted 3285 /// special member function. 3286 bool isImplicitlyDeleted(FunctionDecl *FD); 3287 3288 /// \brief Check whether 'this' shows up in the type of a static member 3289 /// function after the (naturally empty) cv-qualifier-seq would be. 3290 /// 3291 /// \returns true if an error occurred. 3292 bool checkThisInStaticMemberFunctionType(CXXMethodDecl *Method); 3293 3294 /// \brief Whether this' shows up in the exception specification of a static 3295 /// member function. 3296 bool checkThisInStaticMemberFunctionExceptionSpec(CXXMethodDecl *Method); 3297 3298 /// \brief Check whether 'this' shows up in the attributes of the given 3299 /// static member function. 3300 /// 3301 /// \returns true if an error occurred. 3302 bool checkThisInStaticMemberFunctionAttributes(CXXMethodDecl *Method); 3303 3304 /// MaybeBindToTemporary - If the passed in expression has a record type with 3305 /// a non-trivial destructor, this will return CXXBindTemporaryExpr. Otherwise 3306 /// it simply returns the passed in expression. 3307 ExprResult MaybeBindToTemporary(Expr *E); 3308 3309 bool CompleteConstructorCall(CXXConstructorDecl *Constructor, 3310 MultiExprArg ArgsPtr, 3311 SourceLocation Loc, 3312 ASTOwningVector<Expr*> &ConvertedArgs, 3313 bool AllowExplicit = false); 3314 3315 ParsedType getDestructorName(SourceLocation TildeLoc, 3316 IdentifierInfo &II, SourceLocation NameLoc, 3317 Scope *S, CXXScopeSpec &SS, 3318 ParsedType ObjectType, 3319 bool EnteringContext); 3320 3321 ParsedType getDestructorType(const DeclSpec& DS, ParsedType ObjectType); 3322 3323 // Checks that reinterpret casts don't have undefined behavior. 3324 void CheckCompatibleReinterpretCast(QualType SrcType, QualType DestType, 3325 bool IsDereference, SourceRange Range); 3326 3327 /// ActOnCXXNamedCast - Parse {dynamic,static,reinterpret,const}_cast's. 3328 ExprResult ActOnCXXNamedCast(SourceLocation OpLoc, 3329 tok::TokenKind Kind, 3330 SourceLocation LAngleBracketLoc, 3331 Declarator &D, 3332 SourceLocation RAngleBracketLoc, 3333 SourceLocation LParenLoc, 3334 Expr *E, 3335 SourceLocation RParenLoc); 3336 3337 ExprResult BuildCXXNamedCast(SourceLocation OpLoc, 3338 tok::TokenKind Kind, 3339 TypeSourceInfo *Ty, 3340 Expr *E, 3341 SourceRange AngleBrackets, 3342 SourceRange Parens); 3343 3344 ExprResult BuildCXXTypeId(QualType TypeInfoType, 3345 SourceLocation TypeidLoc, 3346 TypeSourceInfo *Operand, 3347 SourceLocation RParenLoc); 3348 ExprResult BuildCXXTypeId(QualType TypeInfoType, 3349 SourceLocation TypeidLoc, 3350 Expr *Operand, 3351 SourceLocation RParenLoc); 3352 3353 /// ActOnCXXTypeid - Parse typeid( something ). 3354 ExprResult ActOnCXXTypeid(SourceLocation OpLoc, 3355 SourceLocation LParenLoc, bool isType, 3356 void *TyOrExpr, 3357 SourceLocation RParenLoc); 3358 3359 ExprResult BuildCXXUuidof(QualType TypeInfoType, 3360 SourceLocation TypeidLoc, 3361 TypeSourceInfo *Operand, 3362 SourceLocation RParenLoc); 3363 ExprResult BuildCXXUuidof(QualType TypeInfoType, 3364 SourceLocation TypeidLoc, 3365 Expr *Operand, 3366 SourceLocation RParenLoc); 3367 3368 /// ActOnCXXUuidof - Parse __uuidof( something ). 3369 ExprResult ActOnCXXUuidof(SourceLocation OpLoc, 3370 SourceLocation LParenLoc, bool isType, 3371 void *TyOrExpr, 3372 SourceLocation RParenLoc); 3373 3374 3375 //// ActOnCXXThis - Parse 'this' pointer. 3376 ExprResult ActOnCXXThis(SourceLocation loc); 3377 3378 /// \brief Try to retrieve the type of the 'this' pointer. 3379 /// 3380 /// \param Capture If true, capture 'this' in this context. 3381 /// 3382 /// \returns The type of 'this', if possible. Otherwise, returns a NULL type. 3383 QualType getCurrentThisType(); 3384 3385 /// \brief When non-NULL, the C++ 'this' expression is allowed despite the 3386 /// current context not being a non-static member function. In such cases, 3387 /// this provides the type used for 'this'. 3388 QualType CXXThisTypeOverride; 3389 3390 /// \brief RAII object used to temporarily allow the C++ 'this' expression 3391 /// to be used, with the given qualifiers on the current class type. 3392 class CXXThisScopeRAII { 3393 Sema &S; 3394 QualType OldCXXThisTypeOverride; 3395 bool Enabled; 3396 3397 public: 3398 /// \brief Introduce a new scope where 'this' may be allowed (when enabled), 3399 /// using the given declaration (which is either a class template or a 3400 /// class) along with the given qualifiers. 3401 /// along with the qualifiers placed on '*this'. 3402 CXXThisScopeRAII(Sema &S, Decl *ContextDecl, unsigned CXXThisTypeQuals, 3403 bool Enabled = true); 3404 3405 ~CXXThisScopeRAII(); 3406 }; 3407 3408 /// \brief Make sure the value of 'this' is actually available in the current 3409 /// context, if it is a potentially evaluated context. 3410 /// 3411 /// \param Loc The location at which the capture of 'this' occurs. 3412 /// 3413 /// \param Explicit Whether 'this' is explicitly captured in a lambda 3414 /// capture list. 3415 void CheckCXXThisCapture(SourceLocation Loc, bool Explicit = false); 3416 3417 /// \brief Determine whether the given type is the type of *this that is used 3418 /// outside of the body of a member function for a type that is currently 3419 /// being defined. 3420 bool isThisOutsideMemberFunctionBody(QualType BaseType); 3421 3422 /// ActOnCXXBoolLiteral - Parse {true,false} literals. 3423 ExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind); 3424 3425 3426 /// ActOnObjCBoolLiteral - Parse {__objc_yes,__objc_no} literals. 3427 ExprResult ActOnObjCBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind); 3428 3429 /// ActOnCXXNullPtrLiteral - Parse 'nullptr'. 3430 ExprResult ActOnCXXNullPtrLiteral(SourceLocation Loc); 3431 3432 //// ActOnCXXThrow - Parse throw expressions. 3433 ExprResult ActOnCXXThrow(Scope *S, SourceLocation OpLoc, Expr *expr); 3434 ExprResult BuildCXXThrow(SourceLocation OpLoc, Expr *Ex, 3435 bool IsThrownVarInScope); 3436 ExprResult CheckCXXThrowOperand(SourceLocation ThrowLoc, Expr *E, 3437 bool IsThrownVarInScope); 3438 3439 /// ActOnCXXTypeConstructExpr - Parse construction of a specified type. 3440 /// Can be interpreted either as function-style casting ("int(x)") 3441 /// or class type construction ("ClassType(x,y,z)") 3442 /// or creation of a value-initialized type ("int()"). 3443 ExprResult ActOnCXXTypeConstructExpr(ParsedType TypeRep, 3444 SourceLocation LParenLoc, 3445 MultiExprArg Exprs, 3446 SourceLocation RParenLoc); 3447 3448 ExprResult BuildCXXTypeConstructExpr(TypeSourceInfo *Type, 3449 SourceLocation LParenLoc, 3450 MultiExprArg Exprs, 3451 SourceLocation RParenLoc); 3452 3453 /// ActOnCXXNew - Parsed a C++ 'new' expression. 3454 ExprResult ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal, 3455 SourceLocation PlacementLParen, 3456 MultiExprArg PlacementArgs, 3457 SourceLocation PlacementRParen, 3458 SourceRange TypeIdParens, Declarator &D, 3459 Expr *Initializer); 3460 ExprResult BuildCXXNew(SourceLocation StartLoc, bool UseGlobal, 3461 SourceLocation PlacementLParen, 3462 MultiExprArg PlacementArgs, 3463 SourceLocation PlacementRParen, 3464 SourceRange TypeIdParens, 3465 QualType AllocType, 3466 TypeSourceInfo *AllocTypeInfo, 3467 Expr *ArraySize, 3468 SourceRange DirectInitRange, 3469 Expr *Initializer, 3470 bool TypeMayContainAuto = true); 3471 3472 bool CheckAllocatedType(QualType AllocType, SourceLocation Loc, 3473 SourceRange R); 3474 bool FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range, 3475 bool UseGlobal, QualType AllocType, bool IsArray, 3476 Expr **PlaceArgs, unsigned NumPlaceArgs, 3477 FunctionDecl *&OperatorNew, 3478 FunctionDecl *&OperatorDelete); 3479 bool FindAllocationOverload(SourceLocation StartLoc, SourceRange Range, 3480 DeclarationName Name, Expr** Args, 3481 unsigned NumArgs, DeclContext *Ctx, 3482 bool AllowMissing, FunctionDecl *&Operator, 3483 bool Diagnose = true); 3484 void DeclareGlobalNewDelete(); 3485 void DeclareGlobalAllocationFunction(DeclarationName Name, QualType Return, 3486 QualType Argument, 3487 bool addMallocAttr = false); 3488 3489 bool FindDeallocationFunction(SourceLocation StartLoc, CXXRecordDecl *RD, 3490 DeclarationName Name, FunctionDecl* &Operator, 3491 bool Diagnose = true); 3492 3493 /// ActOnCXXDelete - Parsed a C++ 'delete' expression 3494 ExprResult ActOnCXXDelete(SourceLocation StartLoc, 3495 bool UseGlobal, bool ArrayForm, 3496 Expr *Operand); 3497 3498 DeclResult ActOnCXXConditionDeclaration(Scope *S, Declarator &D); 3499 ExprResult CheckConditionVariable(VarDecl *ConditionVar, 3500 SourceLocation StmtLoc, 3501 bool ConvertToBoolean); 3502 3503 ExprResult ActOnNoexceptExpr(SourceLocation KeyLoc, SourceLocation LParen, 3504 Expr *Operand, SourceLocation RParen); 3505 ExprResult BuildCXXNoexceptExpr(SourceLocation KeyLoc, Expr *Operand, 3506 SourceLocation RParen); 3507 3508 /// ActOnUnaryTypeTrait - Parsed one of the unary type trait support 3509 /// pseudo-functions. 3510 ExprResult ActOnUnaryTypeTrait(UnaryTypeTrait OTT, 3511 SourceLocation KWLoc, 3512 ParsedType Ty, 3513 SourceLocation RParen); 3514 3515 ExprResult BuildUnaryTypeTrait(UnaryTypeTrait OTT, 3516 SourceLocation KWLoc, 3517 TypeSourceInfo *T, 3518 SourceLocation RParen); 3519 3520 /// ActOnBinaryTypeTrait - Parsed one of the bianry type trait support 3521 /// pseudo-functions. 3522 ExprResult ActOnBinaryTypeTrait(BinaryTypeTrait OTT, 3523 SourceLocation KWLoc, 3524 ParsedType LhsTy, 3525 ParsedType RhsTy, 3526 SourceLocation RParen); 3527 3528 ExprResult BuildBinaryTypeTrait(BinaryTypeTrait BTT, 3529 SourceLocation KWLoc, 3530 TypeSourceInfo *LhsT, 3531 TypeSourceInfo *RhsT, 3532 SourceLocation RParen); 3533 3534 /// \brief Parsed one of the type trait support pseudo-functions. 3535 ExprResult ActOnTypeTrait(TypeTrait Kind, SourceLocation KWLoc, 3536 ArrayRef<ParsedType> Args, 3537 SourceLocation RParenLoc); 3538 ExprResult BuildTypeTrait(TypeTrait Kind, SourceLocation KWLoc, 3539 ArrayRef<TypeSourceInfo *> Args, 3540 SourceLocation RParenLoc); 3541 3542 /// ActOnArrayTypeTrait - Parsed one of the bianry type trait support 3543 /// pseudo-functions. 3544 ExprResult ActOnArrayTypeTrait(ArrayTypeTrait ATT, 3545 SourceLocation KWLoc, 3546 ParsedType LhsTy, 3547 Expr *DimExpr, 3548 SourceLocation RParen); 3549 3550 ExprResult BuildArrayTypeTrait(ArrayTypeTrait ATT, 3551 SourceLocation KWLoc, 3552 TypeSourceInfo *TSInfo, 3553 Expr *DimExpr, 3554 SourceLocation RParen); 3555 3556 /// ActOnExpressionTrait - Parsed one of the unary type trait support 3557 /// pseudo-functions. 3558 ExprResult ActOnExpressionTrait(ExpressionTrait OET, 3559 SourceLocation KWLoc, 3560 Expr *Queried, 3561 SourceLocation RParen); 3562 3563 ExprResult BuildExpressionTrait(ExpressionTrait OET, 3564 SourceLocation KWLoc, 3565 Expr *Queried, 3566 SourceLocation RParen); 3567 3568 ExprResult ActOnStartCXXMemberReference(Scope *S, 3569 Expr *Base, 3570 SourceLocation OpLoc, 3571 tok::TokenKind OpKind, 3572 ParsedType &ObjectType, 3573 bool &MayBePseudoDestructor); 3574 3575 ExprResult DiagnoseDtorReference(SourceLocation NameLoc, Expr *MemExpr); 3576 3577 ExprResult BuildPseudoDestructorExpr(Expr *Base, 3578 SourceLocation OpLoc, 3579 tok::TokenKind OpKind, 3580 const CXXScopeSpec &SS, 3581 TypeSourceInfo *ScopeType, 3582 SourceLocation CCLoc, 3583 SourceLocation TildeLoc, 3584 PseudoDestructorTypeStorage DestroyedType, 3585 bool HasTrailingLParen); 3586 3587 ExprResult ActOnPseudoDestructorExpr(Scope *S, Expr *Base, 3588 SourceLocation OpLoc, 3589 tok::TokenKind OpKind, 3590 CXXScopeSpec &SS, 3591 UnqualifiedId &FirstTypeName, 3592 SourceLocation CCLoc, 3593 SourceLocation TildeLoc, 3594 UnqualifiedId &SecondTypeName, 3595 bool HasTrailingLParen); 3596 3597 ExprResult ActOnPseudoDestructorExpr(Scope *S, Expr *Base, 3598 SourceLocation OpLoc, 3599 tok::TokenKind OpKind, 3600 SourceLocation TildeLoc, 3601 const DeclSpec& DS, 3602 bool HasTrailingLParen); 3603 3604 /// MaybeCreateExprWithCleanups - If the current full-expression 3605 /// requires any cleanups, surround it with a ExprWithCleanups node. 3606 /// Otherwise, just returns the passed-in expression. 3607 Expr *MaybeCreateExprWithCleanups(Expr *SubExpr); 3608 Stmt *MaybeCreateStmtWithCleanups(Stmt *SubStmt); 3609 ExprResult MaybeCreateExprWithCleanups(ExprResult SubExpr); 3610 3611 ExprResult ActOnFinishFullExpr(Expr *Expr); 3612 StmtResult ActOnFinishFullStmt(Stmt *Stmt); 3613 3614 // Marks SS invalid if it represents an incomplete type. 3615 bool RequireCompleteDeclContext(CXXScopeSpec &SS, DeclContext *DC); 3616 3617 DeclContext *computeDeclContext(QualType T); 3618 DeclContext *computeDeclContext(const CXXScopeSpec &SS, 3619 bool EnteringContext = false); 3620 bool isDependentScopeSpecifier(const CXXScopeSpec &SS); 3621 CXXRecordDecl *getCurrentInstantiationOf(NestedNameSpecifier *NNS); 3622 bool isUnknownSpecialization(const CXXScopeSpec &SS); 3623 3624 /// \brief The parser has parsed a global nested-name-specifier '::'. 3625 /// 3626 /// \param S The scope in which this nested-name-specifier occurs. 3627 /// 3628 /// \param CCLoc The location of the '::'. 3629 /// 3630 /// \param SS The nested-name-specifier, which will be updated in-place 3631 /// to reflect the parsed nested-name-specifier. 3632 /// 3633 /// \returns true if an error occurred, false otherwise. 3634 bool ActOnCXXGlobalScopeSpecifier(Scope *S, SourceLocation CCLoc, 3635 CXXScopeSpec &SS); 3636 3637 bool isAcceptableNestedNameSpecifier(NamedDecl *SD); 3638 NamedDecl *FindFirstQualifierInScope(Scope *S, NestedNameSpecifier *NNS); 3639 3640 bool isNonTypeNestedNameSpecifier(Scope *S, CXXScopeSpec &SS, 3641 SourceLocation IdLoc, 3642 IdentifierInfo &II, 3643 ParsedType ObjectType); 3644 3645 bool BuildCXXNestedNameSpecifier(Scope *S, 3646 IdentifierInfo &Identifier, 3647 SourceLocation IdentifierLoc, 3648 SourceLocation CCLoc, 3649 QualType ObjectType, 3650 bool EnteringContext, 3651 CXXScopeSpec &SS, 3652 NamedDecl *ScopeLookupResult, 3653 bool ErrorRecoveryLookup); 3654 3655 /// \brief The parser has parsed a nested-name-specifier 'identifier::'. 3656 /// 3657 /// \param S The scope in which this nested-name-specifier occurs. 3658 /// 3659 /// \param Identifier The identifier preceding the '::'. 3660 /// 3661 /// \param IdentifierLoc The location of the identifier. 3662 /// 3663 /// \param CCLoc The location of the '::'. 3664 /// 3665 /// \param ObjectType The type of the object, if we're parsing 3666 /// nested-name-specifier in a member access expression. 3667 /// 3668 /// \param EnteringContext Whether we're entering the context nominated by 3669 /// this nested-name-specifier. 3670 /// 3671 /// \param SS The nested-name-specifier, which is both an input 3672 /// parameter (the nested-name-specifier before this type) and an 3673 /// output parameter (containing the full nested-name-specifier, 3674 /// including this new type). 3675 /// 3676 /// \returns true if an error occurred, false otherwise. 3677 bool ActOnCXXNestedNameSpecifier(Scope *S, 3678 IdentifierInfo &Identifier, 3679 SourceLocation IdentifierLoc, 3680 SourceLocation CCLoc, 3681 ParsedType ObjectType, 3682 bool EnteringContext, 3683 CXXScopeSpec &SS); 3684 3685 ExprResult ActOnDecltypeExpression(Expr *E); 3686 3687 bool ActOnCXXNestedNameSpecifierDecltype(CXXScopeSpec &SS, 3688 const DeclSpec &DS, 3689 SourceLocation ColonColonLoc); 3690 3691 bool IsInvalidUnlessNestedName(Scope *S, CXXScopeSpec &SS, 3692 IdentifierInfo &Identifier, 3693 SourceLocation IdentifierLoc, 3694 SourceLocation ColonLoc, 3695 ParsedType ObjectType, 3696 bool EnteringContext); 3697 3698 /// \brief The parser has parsed a nested-name-specifier 3699 /// 'template[opt] template-name < template-args >::'. 3700 /// 3701 /// \param S The scope in which this nested-name-specifier occurs. 3702 /// 3703 /// \param SS The nested-name-specifier, which is both an input 3704 /// parameter (the nested-name-specifier before this type) and an 3705 /// output parameter (containing the full nested-name-specifier, 3706 /// including this new type). 3707 /// 3708 /// \param TemplateKWLoc the location of the 'template' keyword, if any. 3709 /// \param TemplateName The template name. 3710 /// \param TemplateNameLoc The location of the template name. 3711 /// \param LAngleLoc The location of the opening angle bracket ('<'). 3712 /// \param TemplateArgs The template arguments. 3713 /// \param RAngleLoc The location of the closing angle bracket ('>'). 3714 /// \param CCLoc The location of the '::'. 3715 /// 3716 /// \param EnteringContext Whether we're entering the context of the 3717 /// nested-name-specifier. 3718 /// 3719 /// 3720 /// \returns true if an error occurred, false otherwise. 3721 bool ActOnCXXNestedNameSpecifier(Scope *S, 3722 CXXScopeSpec &SS, 3723 SourceLocation TemplateKWLoc, 3724 TemplateTy Template, 3725 SourceLocation TemplateNameLoc, 3726 SourceLocation LAngleLoc, 3727 ASTTemplateArgsPtr TemplateArgs, 3728 SourceLocation RAngleLoc, 3729 SourceLocation CCLoc, 3730 bool EnteringContext); 3731 3732 /// \brief Given a C++ nested-name-specifier, produce an annotation value 3733 /// that the parser can use later to reconstruct the given 3734 /// nested-name-specifier. 3735 /// 3736 /// \param SS A nested-name-specifier. 3737 /// 3738 /// \returns A pointer containing all of the information in the 3739 /// nested-name-specifier \p SS. 3740 void *SaveNestedNameSpecifierAnnotation(CXXScopeSpec &SS); 3741 3742 /// \brief Given an annotation pointer for a nested-name-specifier, restore 3743 /// the nested-name-specifier structure. 3744 /// 3745 /// \param Annotation The annotation pointer, produced by 3746 /// \c SaveNestedNameSpecifierAnnotation(). 3747 /// 3748 /// \param AnnotationRange The source range corresponding to the annotation. 3749 /// 3750 /// \param SS The nested-name-specifier that will be updated with the contents 3751 /// of the annotation pointer. 3752 void RestoreNestedNameSpecifierAnnotation(void *Annotation, 3753 SourceRange AnnotationRange, 3754 CXXScopeSpec &SS); 3755 3756 bool ShouldEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS); 3757 3758 /// ActOnCXXEnterDeclaratorScope - Called when a C++ scope specifier (global 3759 /// scope or nested-name-specifier) is parsed, part of a declarator-id. 3760 /// After this method is called, according to [C++ 3.4.3p3], names should be 3761 /// looked up in the declarator-id's scope, until the declarator is parsed and 3762 /// ActOnCXXExitDeclaratorScope is called. 3763 /// The 'SS' should be a non-empty valid CXXScopeSpec. 3764 bool ActOnCXXEnterDeclaratorScope(Scope *S, CXXScopeSpec &SS); 3765 3766 /// ActOnCXXExitDeclaratorScope - Called when a declarator that previously 3767 /// invoked ActOnCXXEnterDeclaratorScope(), is finished. 'SS' is the same 3768 /// CXXScopeSpec that was passed to ActOnCXXEnterDeclaratorScope as well. 3769 /// Used to indicate that names should revert to being looked up in the 3770 /// defining scope. 3771 void ActOnCXXExitDeclaratorScope(Scope *S, const CXXScopeSpec &SS); 3772 3773 /// ActOnCXXEnterDeclInitializer - Invoked when we are about to parse an 3774 /// initializer for the declaration 'Dcl'. 3775 /// After this method is called, according to [C++ 3.4.1p13], if 'Dcl' is a 3776 /// static data member of class X, names should be looked up in the scope of 3777 /// class X. 3778 void ActOnCXXEnterDeclInitializer(Scope *S, Decl *Dcl); 3779 3780 /// ActOnCXXExitDeclInitializer - Invoked after we are finished parsing an 3781 /// initializer for the declaration 'Dcl'. 3782 void ActOnCXXExitDeclInitializer(Scope *S, Decl *Dcl);