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