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