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