Sema.h revision c4e1a6815235ade1a4affe3511ca5ce2dcc64467
1//===--- Sema.h - Semantic Analysis & AST Building --------------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This file defines the Sema class, which performs semantic analysis and 11// builds ASTs. 12// 13//===----------------------------------------------------------------------===// 14 15#ifndef LLVM_CLANG_SEMA_SEMA_H 16#define LLVM_CLANG_SEMA_SEMA_H 17 18#include "clang/Sema/Ownership.h" 19#include "clang/Sema/AnalysisBasedWarnings.h" 20#include "clang/Sema/IdentifierResolver.h" 21#include "clang/Sema/ObjCMethodList.h" 22#include "clang/Sema/DeclSpec.h" 23#include "clang/AST/OperationKinds.h" 24#include "clang/AST/DeclarationName.h" 25#include "clang/AST/ExternalASTSource.h" 26#include "clang/Basic/Specifiers.h" 27#include "clang/Basic/TemplateKinds.h" 28#include "clang/Basic/TypeTraits.h" 29#include "llvm/ADT/OwningPtr.h" 30#include "llvm/ADT/SmallPtrSet.h" 31#include "llvm/ADT/SmallVector.h" 32#include <deque> 33#include <string> 34 35namespace llvm { 36 class APSInt; 37 template <typename ValueT> struct DenseMapInfo; 38 template <typename ValueT, typename ValueInfoT> class DenseSet; 39} 40 41namespace clang { 42 class ADLResult; 43 class ASTConsumer; 44 class ASTContext; 45 class ArrayType; 46 class AttributeList; 47 class BlockDecl; 48 class CXXBasePath; 49 class CXXBasePaths; 50 typedef llvm::SmallVector<CXXBaseSpecifier*, 4> CXXCastPath; 51 class CXXConstructorDecl; 52 class CXXConversionDecl; 53 class CXXDestructorDecl; 54 class CXXFieldCollector; 55 class CXXMemberCallExpr; 56 class CXXMethodDecl; 57 class CXXScopeSpec; 58 class CXXTemporary; 59 class CXXTryStmt; 60 class CallExpr; 61 class ClassTemplateDecl; 62 class ClassTemplatePartialSpecializationDecl; 63 class ClassTemplateSpecializationDecl; 64 class CodeCompleteConsumer; 65 class CodeCompletionResult; 66 class Decl; 67 class DeclAccessPair; 68 class DeclContext; 69 class DeclRefExpr; 70 class DeclaratorDecl; 71 class DeducedTemplateArgument; 72 class DependentDiagnostic; 73 class DesignatedInitExpr; 74 class Designation; 75 class EnumConstantDecl; 76 class Expr; 77 class ExtVectorType; 78 class ExternalSemaSource; 79 class FormatAttr; 80 class FriendDecl; 81 class FullExpr; 82 class FunctionDecl; 83 class FunctionProtoType; 84 class FunctionTemplateDecl; 85 class ImplicitConversionSequence; 86 class InitListExpr; 87 class InitializationKind; 88 class InitializationSequence; 89 class InitializedEntity; 90 class IntegerLiteral; 91 class LabelStmt; 92 class LangOptions; 93 class LocalInstantiationScope; 94 class LookupResult; 95 class MacroInfo; 96 class MultiLevelTemplateArgumentList; 97 class NamedDecl; 98 class NonNullAttr; 99 class ObjCCategoryDecl; 100 class ObjCCategoryImplDecl; 101 class ObjCCompatibleAliasDecl; 102 class ObjCContainerDecl; 103 class ObjCImplDecl; 104 class ObjCImplementationDecl; 105 class ObjCInterfaceDecl; 106 class ObjCIvarDecl; 107 template <class T> class ObjCList; 108 class ObjCMethodDecl; 109 class ObjCPropertyDecl; 110 class ObjCProtocolDecl; 111 class OverloadCandidateSet; 112 class ParenListExpr; 113 class ParmVarDecl; 114 class Preprocessor; 115 class PseudoDestructorTypeStorage; 116 class QualType; 117 class StandardConversionSequence; 118 class Stmt; 119 class StringLiteral; 120 class SwitchStmt; 121 class TargetAttributesSema; 122 class TemplateArgument; 123 class TemplateArgumentList; 124 class TemplateArgumentListBuilder; 125 class TemplateArgumentLoc; 126 class TemplateDecl; 127 class TemplateParameterList; 128 class TemplatePartialOrderingContext; 129 class TemplateTemplateParmDecl; 130 class Token; 131 class TypedefDecl; 132 class UnqualifiedId; 133 class UnresolvedLookupExpr; 134 class UnresolvedMemberExpr; 135 class UnresolvedSetImpl; 136 class UnresolvedSetIterator; 137 class UsingDecl; 138 class UsingShadowDecl; 139 class ValueDecl; 140 class VarDecl; 141 class VisibilityAttr; 142 class VisibleDeclConsumer; 143 144namespace sema { 145 class AccessedEntity; 146 class BlockScopeInfo; 147 class DelayedDiagnostic; 148 class FunctionScopeInfo; 149 class TemplateDeductionInfo; 150} 151 152/// \brief Holds a QualType and a TypeSourceInfo* that came out of a declarator 153/// parsing. 154/// 155/// LocInfoType is a "transient" type, only needed for passing to/from Parser 156/// and Sema, when we want to preserve type source info for a parsed type. 157/// It will not participate in the type system semantics in any way. 158class LocInfoType : public Type { 159 enum { 160 // The last number that can fit in Type's TC. 161 // Avoids conflict with an existing Type class. 162 LocInfo = Type::TypeLast + 1 163 }; 164 165 TypeSourceInfo *DeclInfo; 166 167 LocInfoType(QualType ty, TypeSourceInfo *TInfo) 168 : Type((TypeClass)LocInfo, ty, ty->isDependentType()), DeclInfo(TInfo) { 169 assert(getTypeClass() == (TypeClass)LocInfo && "LocInfo didn't fit in TC?"); 170 } 171 friend class Sema; 172 173public: 174 QualType getType() const { return getCanonicalTypeInternal(); } 175 TypeSourceInfo *getTypeSourceInfo() const { return DeclInfo; } 176 177 void getAsStringInternal(std::string &Str, 178 const PrintingPolicy &Policy) const; 179 180 static bool classof(const Type *T) { 181 return T->getTypeClass() == (TypeClass)LocInfo; 182 } 183 static bool classof(const LocInfoType *) { return true; } 184}; 185 186/// Sema - This implements semantic analysis and AST building for C. 187class Sema { 188 Sema(const Sema&); // DO NOT IMPLEMENT 189 void operator=(const Sema&); // DO NOT IMPLEMENT 190 mutable const TargetAttributesSema* TheTargetAttributesSema; 191public: 192 typedef OpaquePtr<DeclGroupRef> DeclGroupPtrTy; 193 typedef OpaquePtr<TemplateName> TemplateTy; 194 typedef OpaquePtr<QualType> TypeTy; 195 typedef Attr AttrTy; 196 typedef CXXBaseSpecifier BaseTy; 197 typedef CXXBaseOrMemberInitializer MemInitTy; 198 typedef Expr ExprTy; 199 typedef Stmt StmtTy; 200 typedef TemplateParameterList TemplateParamsTy; 201 typedef NestedNameSpecifier CXXScopeTy; 202 203 const LangOptions &LangOpts; 204 Preprocessor &PP; 205 ASTContext &Context; 206 ASTConsumer &Consumer; 207 Diagnostic &Diags; 208 SourceManager &SourceMgr; 209 210 /// \brief Source of additional semantic information. 211 ExternalSemaSource *ExternalSource; 212 213 /// \brief Code-completion consumer. 214 CodeCompleteConsumer *CodeCompleter; 215 216 /// CurContext - This is the current declaration context of parsing. 217 DeclContext *CurContext; 218 219 /// VAListTagName - The declaration name corresponding to __va_list_tag. 220 /// This is used as part of a hack to omit that class from ADL results. 221 DeclarationName VAListTagName; 222 223 /// A RAII object to temporarily push a declaration context. 224 class ContextRAII { 225 private: 226 Sema &S; 227 DeclContext *SavedContext; 228 229 public: 230 ContextRAII(Sema &S, DeclContext *ContextToPush) 231 : S(S), SavedContext(S.CurContext) { 232 assert(ContextToPush && "pushing null context"); 233 S.CurContext = ContextToPush; 234 } 235 236 void pop() { 237 if (!SavedContext) return; 238 S.CurContext = SavedContext; 239 SavedContext = 0; 240 } 241 242 ~ContextRAII() { 243 pop(); 244 } 245 }; 246 247 /// PackContext - Manages the stack for #pragma pack. An alignment 248 /// of 0 indicates default alignment. 249 void *PackContext; // Really a "PragmaPackStack*" 250 251 /// VisContext - Manages the stack for #pragma GCC visibility. 252 void *VisContext; // Really a "PragmaVisStack*" 253 254 /// \brief Stack containing information about each of the nested 255 /// function, block, and method scopes that are currently active. 256 /// 257 /// This array is never empty. Clients should ignore the first 258 /// element, which is used to cache a single FunctionScopeInfo 259 /// that's used to parse every top-level function. 260 llvm::SmallVector<sema::FunctionScopeInfo *, 4> FunctionScopes; 261 262 /// ExprTemporaries - This is the stack of temporaries that are created by 263 /// the current full expression. 264 llvm::SmallVector<CXXTemporary*, 8> ExprTemporaries; 265 266 /// ExtVectorDecls - This is a list all the extended vector types. This allows 267 /// us to associate a raw vector type with one of the ext_vector type names. 268 /// This is only necessary for issuing pretty diagnostics. 269 llvm::SmallVector<TypedefDecl*, 24> ExtVectorDecls; 270 271 /// FieldCollector - Collects CXXFieldDecls during parsing of C++ classes. 272 llvm::OwningPtr<CXXFieldCollector> FieldCollector; 273 274 typedef llvm::SmallPtrSet<const CXXRecordDecl*, 8> RecordDeclSetTy; 275 276 /// PureVirtualClassDiagSet - a set of class declarations which we have 277 /// emitted a list of pure virtual functions. Used to prevent emitting the 278 /// same list more than once. 279 llvm::OwningPtr<RecordDeclSetTy> PureVirtualClassDiagSet; 280 281 /// \brief A mapping from external names to the most recent 282 /// locally-scoped external declaration with that name. 283 /// 284 /// This map contains external declarations introduced in local 285 /// scoped, e.g., 286 /// 287 /// \code 288 /// void f() { 289 /// void foo(int, int); 290 /// } 291 /// \endcode 292 /// 293 /// Here, the name "foo" will be associated with the declaration on 294 /// "foo" within f. This name is not visible outside of 295 /// "f". However, we still find it in two cases: 296 /// 297 /// - If we are declaring another external with the name "foo", we 298 /// can find "foo" as a previous declaration, so that the types 299 /// of this external declaration can be checked for 300 /// compatibility. 301 /// 302 /// - If we would implicitly declare "foo" (e.g., due to a call to 303 /// "foo" in C when no prototype or definition is visible), then 304 /// we find this declaration of "foo" and complain that it is 305 /// not visible. 306 llvm::DenseMap<DeclarationName, NamedDecl *> LocallyScopedExternalDecls; 307 308 /// \brief All the tentative definitions encountered in the TU. 309 llvm::SmallVector<VarDecl *, 2> TentativeDefinitions; 310 311 /// \brief The set of file scoped decls seen so far that have not been used 312 /// and must warn if not used. Only contains the first declaration. 313 llvm::SmallVector<const DeclaratorDecl*, 4> UnusedFileScopedDecls; 314 315 /// \brief The stack of diagnostics that were delayed due to being 316 /// produced during the parsing of a declaration. 317 llvm::SmallVector<sema::DelayedDiagnostic, 0> DelayedDiagnostics; 318 319 /// \brief The depth of the current ParsingDeclaration stack. 320 /// If nonzero, we are currently parsing a declaration (and 321 /// hence should delay deprecation warnings). 322 unsigned ParsingDeclDepth; 323 324 /// WeakUndeclaredIdentifiers - Identifiers contained in 325 /// #pragma weak before declared. rare. may alias another 326 /// identifier, declared or undeclared 327 class WeakInfo { 328 IdentifierInfo *alias; // alias (optional) 329 SourceLocation loc; // for diagnostics 330 bool used; // identifier later declared? 331 public: 332 WeakInfo() 333 : alias(0), loc(SourceLocation()), used(false) {} 334 WeakInfo(IdentifierInfo *Alias, SourceLocation Loc) 335 : alias(Alias), loc(Loc), used(false) {} 336 inline IdentifierInfo * getAlias() const { return alias; } 337 inline SourceLocation getLocation() const { return loc; } 338 void setUsed(bool Used=true) { used = Used; } 339 inline bool getUsed() { return used; } 340 bool operator==(WeakInfo RHS) const { 341 return alias == RHS.getAlias() && loc == RHS.getLocation(); 342 } 343 bool operator!=(WeakInfo RHS) const { return !(*this == RHS); } 344 }; 345 llvm::DenseMap<IdentifierInfo*,WeakInfo> WeakUndeclaredIdentifiers; 346 347 /// WeakTopLevelDecl - Translation-unit scoped declarations generated by 348 /// #pragma weak during processing of other Decls. 349 /// I couldn't figure out a clean way to generate these in-line, so 350 /// we store them here and handle separately -- which is a hack. 351 /// It would be best to refactor this. 352 llvm::SmallVector<Decl*,2> WeakTopLevelDecl; 353 354 IdentifierResolver IdResolver; 355 356 /// Translation Unit Scope - useful to Objective-C actions that need 357 /// to lookup file scope declarations in the "ordinary" C decl namespace. 358 /// For example, user-defined classes, built-in "id" type, etc. 359 Scope *TUScope; 360 361 /// \brief The C++ "std" namespace, where the standard library resides. 362 LazyDeclPtr StdNamespace; 363 364 /// \brief The C++ "std::bad_alloc" class, which is defined by the C++ 365 /// standard library. 366 LazyDeclPtr StdBadAlloc; 367 368 /// \brief The C++ "type_info" declaration, which is defined in <typeinfo>. 369 RecordDecl *CXXTypeInfoDecl; 370 371 /// \brief The MSVC "_GUID" struct, which is defined in MSVC header files. 372 RecordDecl *MSVCGuidDecl; 373 374 /// A flag to remember whether the implicit forms of operator new and delete 375 /// have been declared. 376 bool GlobalNewDeleteDeclared; 377 378 /// \brief The set of declarations that have been referenced within 379 /// a potentially evaluated expression. 380 typedef llvm::SmallVector<std::pair<SourceLocation, Decl *>, 10> 381 PotentiallyReferencedDecls; 382 383 /// \brief A set of diagnostics that may be emitted. 384 typedef llvm::SmallVector<std::pair<SourceLocation, PartialDiagnostic>, 10> 385 PotentiallyEmittedDiagnostics; 386 387 /// \brief Describes how the expressions currently being parsed are 388 /// evaluated at run-time, if at all. 389 enum ExpressionEvaluationContext { 390 /// \brief The current expression and its subexpressions occur within an 391 /// unevaluated operand (C++0x [expr]p8), such as a constant expression 392 /// or the subexpression of \c sizeof, where the type or the value of the 393 /// expression may be significant but no code will be generated to evaluate 394 /// the value of the expression at run time. 395 Unevaluated, 396 397 /// \brief The current expression is potentially evaluated at run time, 398 /// which means that code may be generated to evaluate the value of the 399 /// expression at run time. 400 PotentiallyEvaluated, 401 402 /// \brief The current expression may be potentially evaluated or it may 403 /// be unevaluated, but it is impossible to tell from the lexical context. 404 /// This evaluation context is used primary for the operand of the C++ 405 /// \c typeid expression, whose argument is potentially evaluated only when 406 /// it is an lvalue of polymorphic class type (C++ [basic.def.odr]p2). 407 PotentiallyPotentiallyEvaluated, 408 409 /// \brief The current expression is potentially evaluated, but any 410 /// declarations referenced inside that expression are only used if 411 /// in fact the current expression is used. 412 /// 413 /// This value is used when parsing default function arguments, for which 414 /// we would like to provide diagnostics (e.g., passing non-POD arguments 415 /// through varargs) but do not want to mark declarations as "referenced" 416 /// until the default argument is used. 417 PotentiallyEvaluatedIfUsed 418 }; 419 420 /// \brief Data structure used to record current or nested 421 /// expression evaluation contexts. 422 struct ExpressionEvaluationContextRecord { 423 /// \brief The expression evaluation context. 424 ExpressionEvaluationContext Context; 425 426 /// \brief The number of temporaries that were active when we 427 /// entered this expression evaluation context. 428 unsigned NumTemporaries; 429 430 /// \brief The set of declarations referenced within a 431 /// potentially potentially-evaluated context. 432 /// 433 /// When leaving a potentially potentially-evaluated context, each 434 /// of these elements will be as referenced if the corresponding 435 /// potentially potentially evaluated expression is potentially 436 /// evaluated. 437 PotentiallyReferencedDecls *PotentiallyReferenced; 438 439 /// \brief The set of diagnostics to emit should this potentially 440 /// potentially-evaluated context become evaluated. 441 PotentiallyEmittedDiagnostics *PotentiallyDiagnosed; 442 443 ExpressionEvaluationContextRecord(ExpressionEvaluationContext Context, 444 unsigned NumTemporaries) 445 : Context(Context), NumTemporaries(NumTemporaries), 446 PotentiallyReferenced(0), PotentiallyDiagnosed(0) { } 447 448 void addReferencedDecl(SourceLocation Loc, Decl *Decl) { 449 if (!PotentiallyReferenced) 450 PotentiallyReferenced = new PotentiallyReferencedDecls; 451 PotentiallyReferenced->push_back(std::make_pair(Loc, Decl)); 452 } 453 454 void addDiagnostic(SourceLocation Loc, const PartialDiagnostic &PD) { 455 if (!PotentiallyDiagnosed) 456 PotentiallyDiagnosed = new PotentiallyEmittedDiagnostics; 457 PotentiallyDiagnosed->push_back(std::make_pair(Loc, PD)); 458 } 459 460 void Destroy() { 461 delete PotentiallyReferenced; 462 delete PotentiallyDiagnosed; 463 PotentiallyReferenced = 0; 464 PotentiallyDiagnosed = 0; 465 } 466 }; 467 468 /// A stack of expression evaluation contexts. 469 llvm::SmallVector<ExpressionEvaluationContextRecord, 8> ExprEvalContexts; 470 471 /// \brief Whether the code handled by Sema should be considered a 472 /// complete translation unit or not. 473 /// 474 /// When true (which is generally the case), Sema will perform 475 /// end-of-translation-unit semantic tasks (such as creating 476 /// initializers for tentative definitions in C) once parsing has 477 /// completed. This flag will be false when building PCH files, 478 /// since a PCH file is by definition not a complete translation 479 /// unit. 480 bool CompleteTranslationUnit; 481 482 llvm::BumpPtrAllocator BumpAlloc; 483 484 /// \brief The number of SFINAE diagnostics that have been trapped. 485 unsigned NumSFINAEErrors; 486 487 typedef std::pair<ObjCMethodList, ObjCMethodList> GlobalMethods; 488 typedef llvm::DenseMap<Selector, GlobalMethods> GlobalMethodPool; 489 490 /// Method Pool - allows efficient lookup when typechecking messages to "id". 491 /// We need to maintain a list, since selectors can have differing signatures 492 /// across classes. In Cocoa, this happens to be extremely uncommon (only 1% 493 /// of selectors are "overloaded"). 494 GlobalMethodPool MethodPool; 495 496 /// Method selectors used in a @selector expression. Used for implementation 497 /// of -Wselector. 498 llvm::DenseMap<Selector, SourceLocation> ReferencedSelectors; 499 500 501 GlobalMethodPool::iterator ReadMethodPool(Selector Sel); 502 503 /// Private Helper predicate to check for 'self'. 504 bool isSelfExpr(Expr *RExpr); 505public: 506 Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer, 507 bool CompleteTranslationUnit = true, 508 CodeCompleteConsumer *CompletionConsumer = 0); 509 ~Sema(); 510 511 /// \brief Perform initialization that occurs after the parser has been 512 /// initialized but before it parses anything. 513 void Initialize(); 514 515 const LangOptions &getLangOptions() const { return LangOpts; } 516 Diagnostic &getDiagnostics() const { return Diags; } 517 SourceManager &getSourceManager() const { return SourceMgr; } 518 const TargetAttributesSema &getTargetAttributesSema() const; 519 Preprocessor &getPreprocessor() const { return PP; } 520 ASTContext &getASTContext() const { return Context; } 521 ASTConsumer &getASTConsumer() const { return Consumer; } 522 523 /// \brief Helper class that creates diagnostics with optional 524 /// template instantiation stacks. 525 /// 526 /// This class provides a wrapper around the basic DiagnosticBuilder 527 /// class that emits diagnostics. SemaDiagnosticBuilder is 528 /// responsible for emitting the diagnostic (as DiagnosticBuilder 529 /// does) and, if the diagnostic comes from inside a template 530 /// instantiation, printing the template instantiation stack as 531 /// well. 532 class SemaDiagnosticBuilder : public DiagnosticBuilder { 533 Sema &SemaRef; 534 unsigned DiagID; 535 536 public: 537 SemaDiagnosticBuilder(DiagnosticBuilder &DB, Sema &SemaRef, unsigned DiagID) 538 : DiagnosticBuilder(DB), SemaRef(SemaRef), DiagID(DiagID) { } 539 540 explicit SemaDiagnosticBuilder(Sema &SemaRef) 541 : DiagnosticBuilder(DiagnosticBuilder::Suppress), SemaRef(SemaRef) { } 542 543 ~SemaDiagnosticBuilder(); 544 }; 545 546 /// \brief Emit a diagnostic. 547 SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID); 548 549 /// \brief Emit a partial diagnostic. 550 SemaDiagnosticBuilder Diag(SourceLocation Loc, const PartialDiagnostic& PD); 551 552 /// \brief Build a partial diagnostic. 553 PartialDiagnostic PDiag(unsigned DiagID = 0); // in SemaInternal.h 554 555 ExprResult Owned(Expr* E) { return E; } 556 ExprResult Owned(ExprResult R) { return R; } 557 StmtResult Owned(Stmt* S) { return S; } 558 559 void ActOnEndOfTranslationUnit(); 560 561 Scope *getScopeForContext(DeclContext *Ctx); 562 563 void PushFunctionScope(); 564 void PushBlockScope(Scope *BlockScope, BlockDecl *Block); 565 void PopFunctionOrBlockScope(); 566 567 sema::FunctionScopeInfo *getCurFunction() const { 568 return FunctionScopes.back(); 569 } 570 571 bool hasAnyErrorsInThisFunction() const; 572 573 /// \brief Retrieve the current block, if any. 574 sema::BlockScopeInfo *getCurBlock(); 575 576 /// WeakTopLevelDeclDecls - access to #pragma weak-generated Decls 577 llvm::SmallVector<Decl*,2> &WeakTopLevelDecls() { return WeakTopLevelDecl; } 578 579 //===--------------------------------------------------------------------===// 580 // Type Analysis / Processing: SemaType.cpp. 581 // 582 583 QualType adjustParameterType(QualType T); 584 QualType BuildQualifiedType(QualType T, SourceLocation Loc, Qualifiers Qs); 585 QualType BuildQualifiedType(QualType T, SourceLocation Loc, unsigned CVR) { 586 return BuildQualifiedType(T, Loc, Qualifiers::fromCVRMask(CVR)); 587 } 588 QualType BuildPointerType(QualType T, 589 SourceLocation Loc, DeclarationName Entity); 590 QualType BuildReferenceType(QualType T, bool LValueRef, 591 SourceLocation Loc, DeclarationName Entity); 592 QualType BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM, 593 Expr *ArraySize, unsigned Quals, 594 SourceRange Brackets, DeclarationName Entity); 595 QualType BuildExtVectorType(QualType T, Expr *ArraySize, 596 SourceLocation AttrLoc); 597 QualType BuildFunctionType(QualType T, 598 QualType *ParamTypes, unsigned NumParamTypes, 599 bool Variadic, unsigned Quals, 600 SourceLocation Loc, DeclarationName Entity, 601 const FunctionType::ExtInfo &Info); 602 QualType BuildMemberPointerType(QualType T, QualType Class, 603 SourceLocation Loc, 604 DeclarationName Entity); 605 QualType BuildBlockPointerType(QualType T, 606 SourceLocation Loc, DeclarationName Entity); 607 TypeSourceInfo *GetTypeForDeclarator(Declarator &D, Scope *S, 608 TagDecl **OwnedDecl = 0); 609 TypeSourceInfo *GetTypeSourceInfoForDeclarator(Declarator &D, QualType T, 610 TypeSourceInfo *ReturnTypeInfo); 611 /// \brief Package the given type and TSI into a ParsedType. 612 ParsedType CreateParsedType(QualType T, TypeSourceInfo *TInfo); 613 DeclarationNameInfo GetNameForDeclarator(Declarator &D); 614 DeclarationNameInfo GetNameFromUnqualifiedId(const UnqualifiedId &Name); 615 static QualType GetTypeFromParser(ParsedType Ty, TypeSourceInfo **TInfo = 0); 616 bool CheckSpecifiedExceptionType(QualType T, const SourceRange &Range); 617 bool CheckDistantExceptionSpec(QualType T); 618 bool CheckEquivalentExceptionSpec(FunctionDecl *Old, FunctionDecl *New); 619 bool CheckEquivalentExceptionSpec( 620 const FunctionProtoType *Old, SourceLocation OldLoc, 621 const FunctionProtoType *New, SourceLocation NewLoc); 622 bool CheckEquivalentExceptionSpec( 623 const PartialDiagnostic &DiagID, const PartialDiagnostic & NoteID, 624 const FunctionProtoType *Old, SourceLocation OldLoc, 625 const FunctionProtoType *New, SourceLocation NewLoc, 626 bool *MissingExceptionSpecification = 0, 627 bool *MissingEmptyExceptionSpecification = 0); 628 bool CheckExceptionSpecSubset( 629 const PartialDiagnostic &DiagID, const PartialDiagnostic & NoteID, 630 const FunctionProtoType *Superset, SourceLocation SuperLoc, 631 const FunctionProtoType *Subset, SourceLocation SubLoc); 632 bool CheckParamExceptionSpec(const PartialDiagnostic & NoteID, 633 const FunctionProtoType *Target, SourceLocation TargetLoc, 634 const FunctionProtoType *Source, SourceLocation SourceLoc); 635 636 TypeResult ActOnTypeName(Scope *S, Declarator &D); 637 638 bool RequireCompleteType(SourceLocation Loc, QualType T, 639 const PartialDiagnostic &PD, 640 std::pair<SourceLocation, PartialDiagnostic> Note); 641 bool RequireCompleteType(SourceLocation Loc, QualType T, 642 const PartialDiagnostic &PD); 643 bool RequireCompleteType(SourceLocation Loc, QualType T, 644 unsigned DiagID); 645 646 QualType getElaboratedType(ElaboratedTypeKeyword Keyword, 647 const CXXScopeSpec &SS, QualType T); 648 649 QualType BuildTypeofExprType(Expr *E); 650 QualType BuildDecltypeType(Expr *E); 651 652 //===--------------------------------------------------------------------===// 653 // Symbol table / Decl tracking callbacks: SemaDecl.cpp. 654 // 655 656 DeclGroupPtrTy ConvertDeclToDeclGroup(Decl *Ptr); 657 658 void DiagnoseUseOfUnimplementedSelectors(); 659 660 ParsedType getTypeName(IdentifierInfo &II, SourceLocation NameLoc, 661 Scope *S, CXXScopeSpec *SS = 0, 662 bool isClassName = false, 663 ParsedType ObjectType = ParsedType()); 664 TypeSpecifierType isTagName(IdentifierInfo &II, Scope *S); 665 bool DiagnoseUnknownTypeName(const IdentifierInfo &II, 666 SourceLocation IILoc, 667 Scope *S, 668 CXXScopeSpec *SS, 669 ParsedType &SuggestedType); 670 671 Decl *ActOnDeclarator(Scope *S, Declarator &D); 672 673 Decl *HandleDeclarator(Scope *S, Declarator &D, 674 MultiTemplateParamsArg TemplateParameterLists, 675 bool IsFunctionDefinition); 676 void RegisterLocallyScopedExternCDecl(NamedDecl *ND, 677 const LookupResult &Previous, 678 Scope *S); 679 void DiagnoseFunctionSpecifiers(Declarator& D); 680 void CheckShadow(Scope *S, VarDecl *D, const LookupResult& R); 681 void CheckShadow(Scope *S, VarDecl *D); 682 void CheckCastAlign(Expr *Op, QualType T, SourceRange TRange); 683 NamedDecl* ActOnTypedefDeclarator(Scope* S, Declarator& D, DeclContext* DC, 684 QualType R, TypeSourceInfo *TInfo, 685 LookupResult &Previous, bool &Redeclaration); 686 NamedDecl* ActOnVariableDeclarator(Scope* S, Declarator& D, DeclContext* DC, 687 QualType R, TypeSourceInfo *TInfo, 688 LookupResult &Previous, 689 MultiTemplateParamsArg TemplateParamLists, 690 bool &Redeclaration); 691 void CheckVariableDeclaration(VarDecl *NewVD, LookupResult &Previous, 692 bool &Redeclaration); 693 NamedDecl* ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC, 694 QualType R, TypeSourceInfo *TInfo, 695 LookupResult &Previous, 696 MultiTemplateParamsArg TemplateParamLists, 697 bool IsFunctionDefinition, 698 bool &Redeclaration); 699 void AddOverriddenMethods(CXXRecordDecl *DC, CXXMethodDecl *MD); 700 void CheckFunctionDeclaration(Scope *S, 701 FunctionDecl *NewFD, LookupResult &Previous, 702 bool IsExplicitSpecialization, 703 bool &Redeclaration, 704 bool &OverloadableAttrRequired); 705 void CheckMain(FunctionDecl *FD); 706 Decl *ActOnParamDeclarator(Scope *S, Declarator &D); 707 ParmVarDecl *BuildParmVarDeclForTypedef(DeclContext *DC, 708 SourceLocation Loc, 709 QualType T); 710 ParmVarDecl *CheckParameter(DeclContext *DC, 711 TypeSourceInfo *TSInfo, QualType T, 712 IdentifierInfo *Name, 713 SourceLocation NameLoc, 714 StorageClass SC, 715 StorageClass SCAsWritten); 716 void ActOnParamDefaultArgument(Decl *param, 717 SourceLocation EqualLoc, 718 Expr *defarg); 719 void ActOnParamUnparsedDefaultArgument(Decl *param, 720 SourceLocation EqualLoc, 721 SourceLocation ArgLoc); 722 void ActOnParamDefaultArgumentError(Decl *param); 723 bool SetParamDefaultArgument(ParmVarDecl *Param, Expr *DefaultArg, 724 SourceLocation EqualLoc); 725 726 727 // Contains the locations of the beginning of unparsed default 728 // argument locations. 729 llvm::DenseMap<ParmVarDecl *,SourceLocation> UnparsedDefaultArgLocs; 730 731 void AddInitializerToDecl(Decl *dcl, Expr *init); 732 void AddInitializerToDecl(Decl *dcl, Expr *init, bool DirectInit); 733 void ActOnUninitializedDecl(Decl *dcl, bool TypeContainsUndeducedAuto); 734 void ActOnInitializerError(Decl *Dcl); 735 void SetDeclDeleted(Decl *dcl, SourceLocation DelLoc); 736 DeclGroupPtrTy FinalizeDeclaratorGroup(Scope *S, const DeclSpec &DS, 737 Decl **Group, 738 unsigned NumDecls); 739 void ActOnFinishKNRParamDeclarations(Scope *S, Declarator &D, 740 SourceLocation LocAfterDecls); 741 Decl *ActOnStartOfFunctionDef(Scope *S, Declarator &D); 742 Decl *ActOnStartOfFunctionDef(Scope *S, Decl *D); 743 void ActOnStartOfObjCMethodDef(Scope *S, Decl *D); 744 745 Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body); 746 Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body, bool IsInstantiation); 747 748 /// \brief Diagnose any unused parameters in the given sequence of 749 /// ParmVarDecl pointers. 750 void DiagnoseUnusedParameters(ParmVarDecl * const *Begin, 751 ParmVarDecl * const *End); 752 753 void DiagnoseInvalidJumps(Stmt *Body); 754 Decl *ActOnFileScopeAsmDecl(SourceLocation Loc, Expr *expr); 755 756 /// Scope actions. 757 void ActOnPopScope(SourceLocation Loc, Scope *S); 758 void ActOnTranslationUnitScope(Scope *S); 759 760 /// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with 761 /// no declarator (e.g. "struct foo;") is parsed. 762 Decl *ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS, 763 DeclSpec &DS); 764 765 Decl *BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS, 766 AccessSpecifier AS, 767 RecordDecl *Record); 768 769 bool isAcceptableTagRedeclaration(const TagDecl *Previous, 770 TagTypeKind NewTag, 771 SourceLocation NewTagLoc, 772 const IdentifierInfo &Name); 773 774 enum TagUseKind { 775 TUK_Reference, // Reference to a tag: 'struct foo *X;' 776 TUK_Declaration, // Fwd decl of a tag: 'struct foo;' 777 TUK_Definition, // Definition of a tag: 'struct foo { int X; } Y;' 778 TUK_Friend // Friend declaration: 'friend struct foo;' 779 }; 780 781 Decl *ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, 782 SourceLocation KWLoc, CXXScopeSpec &SS, 783 IdentifierInfo *Name, SourceLocation NameLoc, 784 AttributeList *Attr, AccessSpecifier AS, 785 MultiTemplateParamsArg TemplateParameterLists, 786 bool &OwnedDecl, bool &IsDependent); 787 788 TypeResult ActOnDependentTag(Scope *S, 789 unsigned TagSpec, 790 TagUseKind TUK, 791 const CXXScopeSpec &SS, 792 IdentifierInfo *Name, 793 SourceLocation TagLoc, 794 SourceLocation NameLoc); 795 796 void ActOnDefs(Scope *S, Decl *TagD, SourceLocation DeclStart, 797 IdentifierInfo *ClassName, 798 llvm::SmallVectorImpl<Decl *> &Decls); 799 Decl *ActOnField(Scope *S, Decl *TagD, SourceLocation DeclStart, 800 Declarator &D, Expr *BitfieldWidth); 801 802 FieldDecl *HandleField(Scope *S, RecordDecl *TagD, SourceLocation DeclStart, 803 Declarator &D, Expr *BitfieldWidth, 804 AccessSpecifier AS); 805 806 FieldDecl *CheckFieldDecl(DeclarationName Name, QualType T, 807 TypeSourceInfo *TInfo, 808 RecordDecl *Record, SourceLocation Loc, 809 bool Mutable, Expr *BitfieldWidth, 810 SourceLocation TSSL, 811 AccessSpecifier AS, NamedDecl *PrevDecl, 812 Declarator *D = 0); 813 814 enum CXXSpecialMember { 815 CXXInvalid = -1, 816 CXXConstructor = 0, 817 CXXCopyConstructor = 1, 818 CXXCopyAssignment = 2, 819 CXXDestructor = 3 820 }; 821 bool CheckNontrivialField(FieldDecl *FD); 822 void DiagnoseNontrivial(const RecordType* Record, CXXSpecialMember mem); 823 CXXSpecialMember getSpecialMember(const CXXMethodDecl *MD); 824 void ActOnLastBitfield(SourceLocation DeclStart, Decl *IntfDecl, 825 llvm::SmallVectorImpl<Decl *> &AllIvarDecls); 826 Decl *ActOnIvar(Scope *S, SourceLocation DeclStart, Decl *IntfDecl, 827 Declarator &D, Expr *BitfieldWidth, 828 tok::ObjCKeywordKind visibility); 829 830 // This is used for both record definitions and ObjC interface declarations. 831 void ActOnFields(Scope* S, SourceLocation RecLoc, Decl *TagDecl, 832 Decl **Fields, unsigned NumFields, 833 SourceLocation LBrac, SourceLocation RBrac, 834 AttributeList *AttrList); 835 836 /// ActOnTagStartDefinition - Invoked when we have entered the 837 /// scope of a tag's definition (e.g., for an enumeration, class, 838 /// struct, or union). 839 void ActOnTagStartDefinition(Scope *S, Decl *TagDecl); 840 841 /// ActOnStartCXXMemberDeclarations - Invoked when we have parsed a 842 /// C++ record definition's base-specifiers clause and are starting its 843 /// member declarations. 844 void ActOnStartCXXMemberDeclarations(Scope *S, Decl *TagDecl, 845 SourceLocation LBraceLoc); 846 847 /// ActOnTagFinishDefinition - Invoked once we have finished parsing 848 /// the definition of a tag (enumeration, class, struct, or union). 849 void ActOnTagFinishDefinition(Scope *S, Decl *TagDecl, 850 SourceLocation RBraceLoc); 851 852 /// ActOnTagDefinitionError - Invoked when there was an unrecoverable 853 /// error parsing the definition of a tag. 854 void ActOnTagDefinitionError(Scope *S, Decl *TagDecl); 855 856 EnumConstantDecl *CheckEnumConstant(EnumDecl *Enum, 857 EnumConstantDecl *LastEnumConst, 858 SourceLocation IdLoc, 859 IdentifierInfo *Id, 860 Expr *val); 861 862 Decl *ActOnEnumConstant(Scope *S, Decl *EnumDecl, Decl *LastEnumConstant, 863 SourceLocation IdLoc, IdentifierInfo *Id, 864 SourceLocation EqualLoc, Expr *Val); 865 void ActOnEnumBody(SourceLocation EnumLoc, SourceLocation LBraceLoc, 866 SourceLocation RBraceLoc, Decl *EnumDecl, 867 Decl **Elements, unsigned NumElements, 868 Scope *S, AttributeList *Attr); 869 870 DeclContext *getContainingDC(DeclContext *DC); 871 872 /// Set the current declaration context until it gets popped. 873 void PushDeclContext(Scope *S, DeclContext *DC); 874 void PopDeclContext(); 875 876 /// EnterDeclaratorContext - Used when we must lookup names in the context 877 /// of a declarator's nested name specifier. 878 void EnterDeclaratorContext(Scope *S, DeclContext *DC); 879 void ExitDeclaratorContext(Scope *S); 880 881 DeclContext *getFunctionLevelDeclContext(); 882 883 /// getCurFunctionDecl - If inside of a function body, this returns a pointer 884 /// to the function decl for the function being parsed. If we're currently 885 /// in a 'block', this returns the containing context. 886 FunctionDecl *getCurFunctionDecl(); 887 888 /// getCurMethodDecl - If inside of a method body, this returns a pointer to 889 /// the method decl for the method being parsed. If we're currently 890 /// in a 'block', this returns the containing context. 891 ObjCMethodDecl *getCurMethodDecl(); 892 893 /// getCurFunctionOrMethodDecl - Return the Decl for the current ObjC method 894 /// or C function we're in, otherwise return null. If we're currently 895 /// in a 'block', this returns the containing context. 896 NamedDecl *getCurFunctionOrMethodDecl(); 897 898 /// Add this decl to the scope shadowed decl chains. 899 void PushOnScopeChains(NamedDecl *D, Scope *S, bool AddToContext = true); 900 901 /// isDeclInScope - If 'Ctx' is a function/method, isDeclInScope returns true 902 /// if 'D' is in Scope 'S', otherwise 'S' is ignored and isDeclInScope returns 903 /// true if 'D' belongs to the given declaration context. 904 bool isDeclInScope(NamedDecl *&D, DeclContext *Ctx, Scope *S = 0); 905 906 /// Finds the scope corresponding to the given decl context, if it 907 /// happens to be an enclosing scope. Otherwise return NULL. 908 static Scope *getScopeForDeclContext(Scope *S, DeclContext *DC); 909 910 /// Subroutines of ActOnDeclarator(). 911 TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, QualType T, 912 TypeSourceInfo *TInfo); 913 void MergeTypeDefDecl(TypedefDecl *New, LookupResult &OldDecls); 914 bool MergeFunctionDecl(FunctionDecl *New, Decl *Old); 915 bool MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old); 916 void MergeVarDecl(VarDecl *New, LookupResult &OldDecls); 917 bool MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old); 918 919 // AssignmentAction - This is used by all the assignment diagnostic functions 920 // to represent what is actually causing the operation 921 enum AssignmentAction { 922 AA_Assigning, 923 AA_Passing, 924 AA_Returning, 925 AA_Converting, 926 AA_Initializing, 927 AA_Sending, 928 AA_Casting 929 }; 930 931 /// C++ Overloading. 932 enum OverloadKind { 933 /// This is a legitimate overload: the existing declarations are 934 /// functions or function templates with different signatures. 935 Ovl_Overload, 936 937 /// This is not an overload because the signature exactly matches 938 /// an existing declaration. 939 Ovl_Match, 940 941 /// This is not an overload because the lookup results contain a 942 /// non-function. 943 Ovl_NonFunction 944 }; 945 OverloadKind CheckOverload(Scope *S, 946 FunctionDecl *New, 947 const LookupResult &OldDecls, 948 NamedDecl *&OldDecl, 949 bool IsForUsingDecl); 950 bool IsOverload(FunctionDecl *New, FunctionDecl *Old, bool IsForUsingDecl); 951 952 bool TryImplicitConversion(InitializationSequence &Sequence, 953 const InitializedEntity &Entity, 954 Expr *From, 955 bool SuppressUserConversions, 956 bool AllowExplicit, 957 bool InOverloadResolution); 958 959 bool IsIntegralPromotion(Expr *From, QualType FromType, QualType ToType); 960 bool IsFloatingPointPromotion(QualType FromType, QualType ToType); 961 bool IsComplexPromotion(QualType FromType, QualType ToType); 962 bool IsPointerConversion(Expr *From, QualType FromType, QualType ToType, 963 bool InOverloadResolution, 964 QualType& ConvertedType, bool &IncompatibleObjC); 965 bool isObjCPointerConversion(QualType FromType, QualType ToType, 966 QualType& ConvertedType, bool &IncompatibleObjC); 967 bool FunctionArgTypesAreEqual (FunctionProtoType* OldType, 968 FunctionProtoType* NewType); 969 970 bool CheckPointerConversion(Expr *From, QualType ToType, 971 CastKind &Kind, 972 CXXCastPath& BasePath, 973 bool IgnoreBaseAccess); 974 bool IsMemberPointerConversion(Expr *From, QualType FromType, QualType ToType, 975 bool InOverloadResolution, 976 QualType &ConvertedType); 977 bool CheckMemberPointerConversion(Expr *From, QualType ToType, 978 CastKind &Kind, 979 CXXCastPath &BasePath, 980 bool IgnoreBaseAccess); 981 bool IsQualificationConversion(QualType FromType, QualType ToType); 982 bool DiagnoseMultipleUserDefinedConversion(Expr *From, QualType ToType); 983 984 985 ExprResult PerformCopyInitialization(const InitializedEntity &Entity, 986 SourceLocation EqualLoc, 987 ExprResult Init); 988 bool PerformObjectArgumentInitialization(Expr *&From, 989 NestedNameSpecifier *Qualifier, 990 NamedDecl *FoundDecl, 991 CXXMethodDecl *Method); 992 993 bool PerformContextuallyConvertToBool(Expr *&From); 994 bool PerformContextuallyConvertToObjCId(Expr *&From); 995 996 ExprResult 997 ConvertToIntegralOrEnumerationType(SourceLocation Loc, Expr *FromE, 998 const PartialDiagnostic &NotIntDiag, 999 const PartialDiagnostic &IncompleteDiag, 1000 const PartialDiagnostic &ExplicitConvDiag, 1001 const PartialDiagnostic &ExplicitConvNote, 1002 const PartialDiagnostic &AmbigDiag, 1003 const PartialDiagnostic &AmbigNote, 1004 const PartialDiagnostic &ConvDiag); 1005 1006 bool PerformObjectMemberConversion(Expr *&From, 1007 NestedNameSpecifier *Qualifier, 1008 NamedDecl *FoundDecl, 1009 NamedDecl *Member); 1010 1011 // Members have to be NamespaceDecl* or TranslationUnitDecl*. 1012 // TODO: make this is a typesafe union. 1013 typedef llvm::SmallPtrSet<DeclContext *, 16> AssociatedNamespaceSet; 1014 typedef llvm::SmallPtrSet<CXXRecordDecl *, 16> AssociatedClassSet; 1015 1016 void AddOverloadCandidate(NamedDecl *Function, 1017 DeclAccessPair FoundDecl, 1018 Expr **Args, unsigned NumArgs, 1019 OverloadCandidateSet &CandidateSet); 1020 1021 void AddOverloadCandidate(FunctionDecl *Function, 1022 DeclAccessPair FoundDecl, 1023 Expr **Args, unsigned NumArgs, 1024 OverloadCandidateSet& CandidateSet, 1025 bool SuppressUserConversions = false, 1026 bool PartialOverloading = false); 1027 void AddFunctionCandidates(const UnresolvedSetImpl &Functions, 1028 Expr **Args, unsigned NumArgs, 1029 OverloadCandidateSet& CandidateSet, 1030 bool SuppressUserConversions = false); 1031 void AddMethodCandidate(DeclAccessPair FoundDecl, 1032 QualType ObjectType, 1033 Expr **Args, unsigned NumArgs, 1034 OverloadCandidateSet& CandidateSet, 1035 bool SuppressUserConversion = false); 1036 void AddMethodCandidate(CXXMethodDecl *Method, 1037 DeclAccessPair FoundDecl, 1038 CXXRecordDecl *ActingContext, QualType ObjectType, 1039 Expr **Args, unsigned NumArgs, 1040 OverloadCandidateSet& CandidateSet, 1041 bool SuppressUserConversions = false); 1042 void AddMethodTemplateCandidate(FunctionTemplateDecl *MethodTmpl, 1043 DeclAccessPair FoundDecl, 1044 CXXRecordDecl *ActingContext, 1045 const TemplateArgumentListInfo *ExplicitTemplateArgs, 1046 QualType ObjectType, 1047 Expr **Args, unsigned NumArgs, 1048 OverloadCandidateSet& CandidateSet, 1049 bool SuppressUserConversions = false); 1050 void AddTemplateOverloadCandidate(FunctionTemplateDecl *FunctionTemplate, 1051 DeclAccessPair FoundDecl, 1052 const TemplateArgumentListInfo *ExplicitTemplateArgs, 1053 Expr **Args, unsigned NumArgs, 1054 OverloadCandidateSet& CandidateSet, 1055 bool SuppressUserConversions = false); 1056 void AddConversionCandidate(CXXConversionDecl *Conversion, 1057 DeclAccessPair FoundDecl, 1058 CXXRecordDecl *ActingContext, 1059 Expr *From, QualType ToType, 1060 OverloadCandidateSet& CandidateSet); 1061 void AddTemplateConversionCandidate(FunctionTemplateDecl *FunctionTemplate, 1062 DeclAccessPair FoundDecl, 1063 CXXRecordDecl *ActingContext, 1064 Expr *From, QualType ToType, 1065 OverloadCandidateSet &CandidateSet); 1066 void AddSurrogateCandidate(CXXConversionDecl *Conversion, 1067 DeclAccessPair FoundDecl, 1068 CXXRecordDecl *ActingContext, 1069 const FunctionProtoType *Proto, 1070 QualType ObjectTy, Expr **Args, unsigned NumArgs, 1071 OverloadCandidateSet& CandidateSet); 1072 void AddMemberOperatorCandidates(OverloadedOperatorKind Op, 1073 SourceLocation OpLoc, 1074 Expr **Args, unsigned NumArgs, 1075 OverloadCandidateSet& CandidateSet, 1076 SourceRange OpRange = SourceRange()); 1077 void AddBuiltinCandidate(QualType ResultTy, QualType *ParamTys, 1078 Expr **Args, unsigned NumArgs, 1079 OverloadCandidateSet& CandidateSet, 1080 bool IsAssignmentOperator = false, 1081 unsigned NumContextualBoolArguments = 0); 1082 void AddBuiltinOperatorCandidates(OverloadedOperatorKind Op, 1083 SourceLocation OpLoc, 1084 Expr **Args, unsigned NumArgs, 1085 OverloadCandidateSet& CandidateSet); 1086 void AddArgumentDependentLookupCandidates(DeclarationName Name, 1087 bool Operator, 1088 Expr **Args, unsigned NumArgs, 1089 const TemplateArgumentListInfo *ExplicitTemplateArgs, 1090 OverloadCandidateSet& CandidateSet, 1091 bool PartialOverloading = false); 1092 1093 void NoteOverloadCandidate(FunctionDecl *Fn); 1094 1095 FunctionDecl *ResolveAddressOfOverloadedFunction(Expr *From, QualType ToType, 1096 bool Complain, 1097 DeclAccessPair &Found); 1098 FunctionDecl *ResolveSingleFunctionTemplateSpecialization(Expr *From); 1099 1100 Expr *FixOverloadedFunctionReference(Expr *E, 1101 DeclAccessPair FoundDecl, 1102 FunctionDecl *Fn); 1103 ExprResult FixOverloadedFunctionReference(ExprResult, 1104 DeclAccessPair FoundDecl, 1105 FunctionDecl *Fn); 1106 1107 void AddOverloadedCallCandidates(UnresolvedLookupExpr *ULE, 1108 Expr **Args, unsigned NumArgs, 1109 OverloadCandidateSet &CandidateSet, 1110 bool PartialOverloading = false); 1111 1112 ExprResult BuildOverloadedCallExpr(Scope *S, Expr *Fn, 1113 UnresolvedLookupExpr *ULE, 1114 SourceLocation LParenLoc, 1115 Expr **Args, unsigned NumArgs, 1116 SourceLocation RParenLoc); 1117 1118 ExprResult CreateOverloadedUnaryOp(SourceLocation OpLoc, 1119 unsigned Opc, 1120 const UnresolvedSetImpl &Fns, 1121 Expr *input); 1122 1123 ExprResult CreateOverloadedBinOp(SourceLocation OpLoc, 1124 unsigned Opc, 1125 const UnresolvedSetImpl &Fns, 1126 Expr *LHS, Expr *RHS); 1127 1128 ExprResult CreateOverloadedArraySubscriptExpr(SourceLocation LLoc, 1129 SourceLocation RLoc, 1130 Expr *Base,Expr *Idx); 1131 1132 ExprResult 1133 BuildCallToMemberFunction(Scope *S, Expr *MemExpr, 1134 SourceLocation LParenLoc, Expr **Args, 1135 unsigned NumArgs, SourceLocation RParenLoc); 1136 ExprResult 1137 BuildCallToObjectOfClassType(Scope *S, Expr *Object, SourceLocation LParenLoc, 1138 Expr **Args, unsigned NumArgs, 1139 SourceLocation RParenLoc); 1140 1141 ExprResult BuildOverloadedArrowExpr(Scope *S, Expr *Base, 1142 SourceLocation OpLoc); 1143 1144 /// CheckCallReturnType - Checks that a call expression's return type is 1145 /// complete. Returns true on failure. The location passed in is the location 1146 /// that best represents the call. 1147 bool CheckCallReturnType(QualType ReturnType, SourceLocation Loc, 1148 CallExpr *CE, FunctionDecl *FD); 1149 1150 /// Helpers for dealing with blocks and functions. 1151 bool CheckParmsForFunctionDef(FunctionDecl *FD); 1152 void CheckCXXDefaultArguments(FunctionDecl *FD); 1153 void CheckExtraCXXDefaultArguments(Declarator &D); 1154 Scope *getNonFieldDeclScope(Scope *S); 1155 1156 /// \name Name lookup 1157 /// 1158 /// These routines provide name lookup that is used during semantic 1159 /// analysis to resolve the various kinds of names (identifiers, 1160 /// overloaded operator names, constructor names, etc.) into zero or 1161 /// more declarations within a particular scope. The major entry 1162 /// points are LookupName, which performs unqualified name lookup, 1163 /// and LookupQualifiedName, which performs qualified name lookup. 1164 /// 1165 /// All name lookup is performed based on some specific criteria, 1166 /// which specify what names will be visible to name lookup and how 1167 /// far name lookup should work. These criteria are important both 1168 /// for capturing language semantics (certain lookups will ignore 1169 /// certain names, for example) and for performance, since name 1170 /// lookup is often a bottleneck in the compilation of C++. Name 1171 /// lookup criteria is specified via the LookupCriteria enumeration. 1172 /// 1173 /// The results of name lookup can vary based on the kind of name 1174 /// lookup performed, the current language, and the translation 1175 /// unit. In C, for example, name lookup will either return nothing 1176 /// (no entity found) or a single declaration. In C++, name lookup 1177 /// can additionally refer to a set of overloaded functions or 1178 /// result in an ambiguity. All of the possible results of name 1179 /// lookup are captured by the LookupResult class, which provides 1180 /// the ability to distinguish among them. 1181 //@{ 1182 1183 /// @brief Describes the kind of name lookup to perform. 1184 enum LookupNameKind { 1185 /// Ordinary name lookup, which finds ordinary names (functions, 1186 /// variables, typedefs, etc.) in C and most kinds of names 1187 /// (functions, variables, members, types, etc.) in C++. 1188 LookupOrdinaryName = 0, 1189 /// Tag name lookup, which finds the names of enums, classes, 1190 /// structs, and unions. 1191 LookupTagName, 1192 /// Member name lookup, which finds the names of 1193 /// class/struct/union members. 1194 LookupMemberName, 1195 /// Look up of an operator name (e.g., operator+) for use with 1196 /// operator overloading. This lookup is similar to ordinary name 1197 /// lookup, but will ignore any declarations that are class members. 1198 LookupOperatorName, 1199 /// Look up of a name that precedes the '::' scope resolution 1200 /// operator in C++. This lookup completely ignores operator, object, 1201 /// function, and enumerator names (C++ [basic.lookup.qual]p1). 1202 LookupNestedNameSpecifierName, 1203 /// Look up a namespace name within a C++ using directive or 1204 /// namespace alias definition, ignoring non-namespace names (C++ 1205 /// [basic.lookup.udir]p1). 1206 LookupNamespaceName, 1207 /// Look up all declarations in a scope with the given name, 1208 /// including resolved using declarations. This is appropriate 1209 /// for checking redeclarations for a using declaration. 1210 LookupUsingDeclName, 1211 /// Look up an ordinary name that is going to be redeclared as a 1212 /// name with linkage. This lookup ignores any declarations that 1213 /// are outside of the current scope unless they have linkage. See 1214 /// C99 6.2.2p4-5 and C++ [basic.link]p6. 1215 LookupRedeclarationWithLinkage, 1216 /// Look up the name of an Objective-C protocol. 1217 LookupObjCProtocolName, 1218 /// \brief Look up any declaration with any name. 1219 LookupAnyName 1220 }; 1221 1222 /// \brief Specifies whether (or how) name lookup is being performed for a 1223 /// redeclaration (vs. a reference). 1224 enum RedeclarationKind { 1225 /// \brief The lookup is a reference to this name that is not for the 1226 /// purpose of redeclaring the name. 1227 NotForRedeclaration = 0, 1228 /// \brief The lookup results will be used for redeclaration of a name, 1229 /// if an entity by that name already exists. 1230 ForRedeclaration 1231 }; 1232 1233private: 1234 bool CppLookupName(LookupResult &R, Scope *S); 1235 1236public: 1237 /// \brief Look up a name, looking for a single declaration. Return 1238 /// null if the results were absent, ambiguous, or overloaded. 1239 /// 1240 /// It is preferable to use the elaborated form and explicitly handle 1241 /// ambiguity and overloaded. 1242 NamedDecl *LookupSingleName(Scope *S, DeclarationName Name, 1243 SourceLocation Loc, 1244 LookupNameKind NameKind, 1245 RedeclarationKind Redecl 1246 = NotForRedeclaration); 1247 bool LookupName(LookupResult &R, Scope *S, 1248 bool AllowBuiltinCreation = false); 1249 bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx, 1250 bool InUnqualifiedLookup = false); 1251 bool LookupParsedName(LookupResult &R, Scope *S, CXXScopeSpec *SS, 1252 bool AllowBuiltinCreation = false, 1253 bool EnteringContext = false); 1254 ObjCProtocolDecl *LookupProtocol(IdentifierInfo *II, SourceLocation IdLoc); 1255 1256 void LookupOverloadedOperatorName(OverloadedOperatorKind Op, Scope *S, 1257 QualType T1, QualType T2, 1258 UnresolvedSetImpl &Functions); 1259 1260 DeclContextLookupResult LookupConstructors(CXXRecordDecl *Class); 1261 CXXDestructorDecl *LookupDestructor(CXXRecordDecl *Class); 1262 1263 void ArgumentDependentLookup(DeclarationName Name, bool Operator, 1264 Expr **Args, unsigned NumArgs, 1265 ADLResult &Functions); 1266 1267 void LookupVisibleDecls(Scope *S, LookupNameKind Kind, 1268 VisibleDeclConsumer &Consumer, 1269 bool IncludeGlobalScope = true); 1270 void LookupVisibleDecls(DeclContext *Ctx, LookupNameKind Kind, 1271 VisibleDeclConsumer &Consumer, 1272 bool IncludeGlobalScope = true); 1273 1274 /// \brief The context in which typo-correction occurs. 1275 /// 1276 /// The typo-correction context affects which keywords (if any) are 1277 /// considered when trying to correct for typos. 1278 enum CorrectTypoContext { 1279 /// \brief An unknown context, where any keyword might be valid. 1280 CTC_Unknown, 1281 /// \brief A context where no keywords are used (e.g. we expect an actual 1282 /// name). 1283 CTC_NoKeywords, 1284 /// \brief A context where we're correcting a type name. 1285 CTC_Type, 1286 /// \brief An expression context. 1287 CTC_Expression, 1288 /// \brief A type cast, or anything else that can be followed by a '<'. 1289 CTC_CXXCasts, 1290 /// \brief A member lookup context. 1291 CTC_MemberLookup, 1292 /// \brief The receiver of an Objective-C message send within an 1293 /// Objective-C method where 'super' is a valid keyword. 1294 CTC_ObjCMessageReceiver 1295 }; 1296 1297 DeclarationName CorrectTypo(LookupResult &R, Scope *S, CXXScopeSpec *SS, 1298 DeclContext *MemberContext = 0, 1299 bool EnteringContext = false, 1300 CorrectTypoContext CTC = CTC_Unknown, 1301 const ObjCObjectPointerType *OPT = 0); 1302 1303 void FindAssociatedClassesAndNamespaces(Expr **Args, unsigned NumArgs, 1304 AssociatedNamespaceSet &AssociatedNamespaces, 1305 AssociatedClassSet &AssociatedClasses); 1306 1307 bool DiagnoseAmbiguousLookup(LookupResult &Result); 1308 //@} 1309 1310 ObjCInterfaceDecl *getObjCInterfaceDecl(IdentifierInfo *&Id, 1311 SourceLocation IdLoc, 1312 bool TypoCorrection = false); 1313 NamedDecl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID, 1314 Scope *S, bool ForRedeclaration, 1315 SourceLocation Loc); 1316 NamedDecl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II, 1317 Scope *S); 1318 void AddKnownFunctionAttributes(FunctionDecl *FD); 1319 1320 // More parsing and symbol table subroutines. 1321 1322 // Decl attributes - this routine is the top level dispatcher. 1323 void ProcessDeclAttributes(Scope *S, Decl *D, const Declarator &PD); 1324 void ProcessDeclAttributeList(Scope *S, Decl *D, const AttributeList *AL); 1325 1326 void WarnUndefinedMethod(SourceLocation ImpLoc, ObjCMethodDecl *method, 1327 bool &IncompleteImpl, unsigned DiagID); 1328 void WarnConflictingTypedMethods(ObjCMethodDecl *ImpMethod, 1329 ObjCMethodDecl *IntfMethod); 1330 1331 bool isPropertyReadonly(ObjCPropertyDecl *PropertyDecl, 1332 ObjCInterfaceDecl *IDecl); 1333 1334 typedef llvm::DenseSet<Selector, llvm::DenseMapInfo<Selector> > SelectorSet; 1335 1336 /// CheckProtocolMethodDefs - This routine checks unimplemented 1337 /// methods declared in protocol, and those referenced by it. 1338 /// \param IDecl - Used for checking for methods which may have been 1339 /// inherited. 1340 void CheckProtocolMethodDefs(SourceLocation ImpLoc, 1341 ObjCProtocolDecl *PDecl, 1342 bool& IncompleteImpl, 1343 const SelectorSet &InsMap, 1344 const SelectorSet &ClsMap, 1345 ObjCContainerDecl *CDecl); 1346 1347 /// CheckImplementationIvars - This routine checks if the instance variables 1348 /// listed in the implelementation match those listed in the interface. 1349 void CheckImplementationIvars(ObjCImplementationDecl *ImpDecl, 1350 ObjCIvarDecl **Fields, unsigned nIvars, 1351 SourceLocation Loc); 1352 1353 /// ImplMethodsVsClassMethods - This is main routine to warn if any method 1354 /// remains unimplemented in the class or category @implementation. 1355 void ImplMethodsVsClassMethods(Scope *S, ObjCImplDecl* IMPDecl, 1356 ObjCContainerDecl* IDecl, 1357 bool IncompleteImpl = false); 1358 1359 /// DiagnoseUnimplementedProperties - This routine warns on those properties 1360 /// which must be implemented by this implementation. 1361 void DiagnoseUnimplementedProperties(Scope *S, ObjCImplDecl* IMPDecl, 1362 ObjCContainerDecl *CDecl, 1363 const SelectorSet &InsMap); 1364 1365 /// DefaultSynthesizeProperties - This routine default synthesizes all 1366 /// properties which must be synthesized in class's @implementation. 1367 void DefaultSynthesizeProperties (Scope *S, ObjCImplDecl* IMPDecl, 1368 ObjCInterfaceDecl *IDecl); 1369 1370 /// CollectImmediateProperties - This routine collects all properties in 1371 /// the class and its conforming protocols; but not those it its super class. 1372 void CollectImmediateProperties(ObjCContainerDecl *CDecl, 1373 llvm::DenseMap<IdentifierInfo *, ObjCPropertyDecl*>& PropMap, 1374 llvm::DenseMap<IdentifierInfo *, ObjCPropertyDecl*>& SuperPropMap); 1375 1376 1377 /// LookupPropertyDecl - Looks up a property in the current class and all 1378 /// its protocols. 1379 ObjCPropertyDecl *LookupPropertyDecl(const ObjCContainerDecl *CDecl, 1380 IdentifierInfo *II); 1381 1382 /// Called by ActOnProperty to handle @property declarations in 1383 //// class extensions. 1384 Decl *HandlePropertyInClassExtension(Scope *S, 1385 ObjCCategoryDecl *CDecl, 1386 SourceLocation AtLoc, 1387 FieldDeclarator &FD, 1388 Selector GetterSel, 1389 Selector SetterSel, 1390 const bool isAssign, 1391 const bool isReadWrite, 1392 const unsigned Attributes, 1393 bool *isOverridingProperty, 1394 TypeSourceInfo *T, 1395 tok::ObjCKeywordKind MethodImplKind); 1396 1397 /// Called by ActOnProperty and HandlePropertyInClassExtension to 1398 /// handle creating the ObjcPropertyDecl for a category or @interface. 1399 ObjCPropertyDecl *CreatePropertyDecl(Scope *S, 1400 ObjCContainerDecl *CDecl, 1401 SourceLocation AtLoc, 1402 FieldDeclarator &FD, 1403 Selector GetterSel, 1404 Selector SetterSel, 1405 const bool isAssign, 1406 const bool isReadWrite, 1407 const unsigned Attributes, 1408 TypeSourceInfo *T, 1409 tok::ObjCKeywordKind MethodImplKind, 1410 DeclContext *lexicalDC = 0); 1411 1412 /// AtomicPropertySetterGetterRules - This routine enforces the rule (via 1413 /// warning) when atomic property has one but not the other user-declared 1414 /// setter or getter. 1415 void AtomicPropertySetterGetterRules(ObjCImplDecl* IMPDecl, 1416 ObjCContainerDecl* IDecl); 1417 1418 void DiagnoseDuplicateIvars(ObjCInterfaceDecl *ID, ObjCInterfaceDecl *SID); 1419 1420 /// MatchTwoMethodDeclarations - Checks if two methods' type match and returns 1421 /// true, or false, accordingly. 1422 bool MatchTwoMethodDeclarations(const ObjCMethodDecl *Method, 1423 const ObjCMethodDecl *PrevMethod, 1424 bool matchBasedOnSizeAndAlignment = false, 1425 bool matchBasedOnStrictEqulity = false); 1426 1427 /// MatchAllMethodDeclarations - Check methods declaraed in interface or 1428 /// or protocol against those declared in their implementations. 1429 void MatchAllMethodDeclarations(const SelectorSet &InsMap, 1430 const SelectorSet &ClsMap, 1431 SelectorSet &InsMapSeen, 1432 SelectorSet &ClsMapSeen, 1433 ObjCImplDecl* IMPDecl, 1434 ObjCContainerDecl* IDecl, 1435 bool &IncompleteImpl, 1436 bool ImmediateClass); 1437 1438private: 1439 /// AddMethodToGlobalPool - Add an instance or factory method to the global 1440 /// pool. See descriptoin of AddInstanceMethodToGlobalPool. 1441 void AddMethodToGlobalPool(ObjCMethodDecl *Method, bool impl, bool instance); 1442 1443 /// LookupMethodInGlobalPool - Returns the instance or factory method and 1444 /// optionally warns if there are multiple signatures. 1445 ObjCMethodDecl *LookupMethodInGlobalPool(Selector Sel, SourceRange R, 1446 bool receiverIdOrClass, 1447 bool warn, bool instance); 1448 1449public: 1450 /// AddInstanceMethodToGlobalPool - All instance methods in a translation 1451 /// unit are added to a global pool. This allows us to efficiently associate 1452 /// a selector with a method declaraation for purposes of typechecking 1453 /// messages sent to "id" (where the class of the object is unknown). 1454 void AddInstanceMethodToGlobalPool(ObjCMethodDecl *Method, bool impl=false) { 1455 AddMethodToGlobalPool(Method, impl, /*instance*/true); 1456 } 1457 1458 /// AddFactoryMethodToGlobalPool - Same as above, but for factory methods. 1459 void AddFactoryMethodToGlobalPool(ObjCMethodDecl *Method, bool impl=false) { 1460 AddMethodToGlobalPool(Method, impl, /*instance*/false); 1461 } 1462 1463 /// LookupInstanceMethodInGlobalPool - Returns the method and warns if 1464 /// there are multiple signatures. 1465 ObjCMethodDecl *LookupInstanceMethodInGlobalPool(Selector Sel, SourceRange R, 1466 bool receiverIdOrClass=false, 1467 bool warn=true) { 1468 return LookupMethodInGlobalPool(Sel, R, receiverIdOrClass, 1469 warn, /*instance*/true); 1470 } 1471 1472 /// LookupFactoryMethodInGlobalPool - Returns the method and warns if 1473 /// there are multiple signatures. 1474 ObjCMethodDecl *LookupFactoryMethodInGlobalPool(Selector Sel, SourceRange R, 1475 bool receiverIdOrClass=false, 1476 bool warn=true) { 1477 return LookupMethodInGlobalPool(Sel, R, receiverIdOrClass, 1478 warn, /*instance*/false); 1479 } 1480 1481 /// LookupImplementedMethodInGlobalPool - Returns the method which has an 1482 /// implementation. 1483 ObjCMethodDecl *LookupImplementedMethodInGlobalPool(Selector Sel); 1484 1485 /// CollectIvarsToConstructOrDestruct - Collect those ivars which require 1486 /// initialization. 1487 void CollectIvarsToConstructOrDestruct(ObjCInterfaceDecl *OI, 1488 llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars); 1489 //===--------------------------------------------------------------------===// 1490 // Statement Parsing Callbacks: SemaStmt.cpp. 1491public: 1492 class FullExprArg { 1493 public: 1494 FullExprArg(Sema &actions) : E(0) { } 1495 1496 // FIXME: The const_cast here is ugly. RValue references would make this 1497 // much nicer (or we could duplicate a bunch of the move semantics 1498 // emulation code from Ownership.h). 1499 FullExprArg(const FullExprArg& Other): E(Other.E) {} 1500 1501 ExprResult release() { 1502 return move(E); 1503 } 1504 1505 Expr *get() const { return E; } 1506 1507 Expr *operator->() { 1508 return E; 1509 } 1510 1511 private: 1512 // FIXME: No need to make the entire Sema class a friend when it's just 1513 // Sema::FullExpr that needs access to the constructor below. 1514 friend class Sema; 1515 1516 explicit FullExprArg(Expr *expr) : E(expr) {} 1517 1518 Expr *E; 1519 }; 1520 1521 FullExprArg MakeFullExpr(Expr *Arg) { 1522 return FullExprArg(ActOnFinishFullExpr(Arg).release()); 1523 } 1524 1525 StmtResult ActOnExprStmt(FullExprArg Expr); 1526 1527 StmtResult ActOnNullStmt(SourceLocation SemiLoc); 1528 StmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R, 1529 MultiStmtArg Elts, 1530 bool isStmtExpr); 1531 StmtResult ActOnDeclStmt(DeclGroupPtrTy Decl, 1532 SourceLocation StartLoc, 1533 SourceLocation EndLoc); 1534 void ActOnForEachDeclStmt(DeclGroupPtrTy Decl); 1535 StmtResult ActOnCaseStmt(SourceLocation CaseLoc, Expr *LHSVal, 1536 SourceLocation DotDotDotLoc, Expr *RHSVal, 1537 SourceLocation ColonLoc); 1538 void ActOnCaseStmtBody(Stmt *CaseStmt, Stmt *SubStmt); 1539 1540 StmtResult ActOnDefaultStmt(SourceLocation DefaultLoc, 1541 SourceLocation ColonLoc, 1542 Stmt *SubStmt, Scope *CurScope); 1543 StmtResult ActOnLabelStmt(SourceLocation IdentLoc, 1544 IdentifierInfo *II, 1545 SourceLocation ColonLoc, 1546 Stmt *SubStmt); 1547 StmtResult ActOnIfStmt(SourceLocation IfLoc, 1548 FullExprArg CondVal, Decl *CondVar, 1549 Stmt *ThenVal, 1550 SourceLocation ElseLoc, Stmt *ElseVal); 1551 StmtResult ActOnStartOfSwitchStmt(SourceLocation SwitchLoc, 1552 Expr *Cond, 1553 Decl *CondVar); 1554 StmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc, 1555 Stmt *Switch, Stmt *Body); 1556 StmtResult ActOnWhileStmt(SourceLocation WhileLoc, 1557 FullExprArg Cond, 1558 Decl *CondVar, Stmt *Body); 1559 StmtResult ActOnDoStmt(SourceLocation DoLoc, Stmt *Body, 1560 SourceLocation WhileLoc, 1561 SourceLocation CondLParen, Expr *Cond, 1562 SourceLocation CondRParen); 1563 1564 StmtResult ActOnForStmt(SourceLocation ForLoc, 1565 SourceLocation LParenLoc, 1566 Stmt *First, FullExprArg Second, 1567 Decl *SecondVar, 1568 FullExprArg Third, 1569 SourceLocation RParenLoc, 1570 Stmt *Body); 1571 StmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc, 1572 SourceLocation LParenLoc, 1573 Stmt *First, Expr *Second, 1574 SourceLocation RParenLoc, Stmt *Body); 1575 1576 StmtResult ActOnGotoStmt(SourceLocation GotoLoc, 1577 SourceLocation LabelLoc, 1578 IdentifierInfo *LabelII); 1579 StmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc, 1580 SourceLocation StarLoc, 1581 Expr *DestExp); 1582 StmtResult ActOnContinueStmt(SourceLocation ContinueLoc, Scope *CurScope); 1583 StmtResult ActOnBreakStmt(SourceLocation GotoLoc, Scope *CurScope); 1584 1585 StmtResult ActOnReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp); 1586 StmtResult ActOnBlockReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp); 1587 1588 StmtResult ActOnAsmStmt(SourceLocation AsmLoc, 1589 bool IsSimple, bool IsVolatile, 1590 unsigned NumOutputs, unsigned NumInputs, 1591 IdentifierInfo **Names, 1592 MultiExprArg Constraints, 1593 MultiExprArg Exprs, 1594 Expr *AsmString, 1595 MultiExprArg Clobbers, 1596 SourceLocation RParenLoc, 1597 bool MSAsm = false); 1598 1599 1600 VarDecl *BuildObjCExceptionDecl(TypeSourceInfo *TInfo, QualType ExceptionType, 1601 IdentifierInfo *Name, SourceLocation NameLoc, 1602 bool Invalid = false); 1603 1604 Decl *ActOnObjCExceptionDecl(Scope *S, Declarator &D); 1605 1606 StmtResult ActOnObjCAtCatchStmt(SourceLocation AtLoc, SourceLocation RParen, 1607 Decl *Parm, Stmt *Body); 1608 1609 StmtResult ActOnObjCAtFinallyStmt(SourceLocation AtLoc, Stmt *Body); 1610 1611 StmtResult ActOnObjCAtTryStmt(SourceLocation AtLoc, Stmt *Try, 1612 MultiStmtArg Catch, Stmt *Finally); 1613 1614 StmtResult BuildObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw); 1615 StmtResult ActOnObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw, 1616 Scope *CurScope); 1617 StmtResult ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc, 1618 Expr *SynchExpr, 1619 Stmt *SynchBody); 1620 1621 VarDecl *BuildExceptionDeclaration(Scope *S, 1622 TypeSourceInfo *TInfo, 1623 IdentifierInfo *Name, 1624 SourceLocation Loc); 1625 Decl *ActOnExceptionDeclarator(Scope *S, Declarator &D); 1626 1627 StmtResult ActOnCXXCatchBlock(SourceLocation CatchLoc, 1628 Decl *ExDecl, Stmt *HandlerBlock); 1629 StmtResult ActOnCXXTryBlock(SourceLocation TryLoc, Stmt *TryBlock, 1630 MultiStmtArg Handlers); 1631 void DiagnoseReturnInConstructorExceptionHandler(CXXTryStmt *TryBlock); 1632 1633 bool ShouldWarnIfUnusedFileScopedDecl(const DeclaratorDecl *D) const; 1634 1635 /// \brief If it's a file scoped decl that must warn if not used, keep track 1636 /// of it. 1637 void MarkUnusedFileScopedDecl(const DeclaratorDecl *D); 1638 1639 /// DiagnoseUnusedExprResult - If the statement passed in is an expression 1640 /// whose result is unused, warn. 1641 void DiagnoseUnusedExprResult(const Stmt *S); 1642 void DiagnoseUnusedDecl(const NamedDecl *ND); 1643 1644 typedef uintptr_t ParsingDeclStackState; 1645 1646 ParsingDeclStackState PushParsingDeclaration(); 1647 void PopParsingDeclaration(ParsingDeclStackState S, Decl *D); 1648 void EmitDeprecationWarning(NamedDecl *D, SourceLocation Loc); 1649 1650 void HandleDelayedDeprecationCheck(sema::DelayedDiagnostic &DD, Decl *Ctx); 1651 1652 //===--------------------------------------------------------------------===// 1653 // Expression Parsing Callbacks: SemaExpr.cpp. 1654 1655 bool DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc); 1656 bool DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *PD, 1657 ObjCMethodDecl *Getter, 1658 SourceLocation Loc); 1659 void DiagnoseSentinelCalls(NamedDecl *D, SourceLocation Loc, 1660 Expr **Args, unsigned NumArgs); 1661 1662 void PushExpressionEvaluationContext(ExpressionEvaluationContext NewContext); 1663 1664 void PopExpressionEvaluationContext(); 1665 1666 void MarkDeclarationReferenced(SourceLocation Loc, Decl *D); 1667 void MarkDeclarationsReferencedInType(SourceLocation Loc, QualType T); 1668 void MarkDeclarationsReferencedInExpr(Expr *E); 1669 bool DiagRuntimeBehavior(SourceLocation Loc, const PartialDiagnostic &PD); 1670 1671 // Primary Expressions. 1672 SourceRange getExprRange(Expr *E) const; 1673 1674 ExprResult ActOnIdExpression(Scope *S, CXXScopeSpec &SS, UnqualifiedId &Name, 1675 bool HasTrailingLParen, bool IsAddressOfOperand); 1676 1677 bool DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R, 1678 CorrectTypoContext CTC = CTC_Unknown); 1679 1680 ExprResult LookupInObjCMethod(LookupResult &R, Scope *S, IdentifierInfo *II, 1681 bool AllowBuiltinCreation=false); 1682 1683 ExprResult ActOnDependentIdExpression(const CXXScopeSpec &SS, 1684 const DeclarationNameInfo &NameInfo, 1685 bool isAddressOfOperand, 1686 const TemplateArgumentListInfo *TemplateArgs); 1687 1688 ExprResult BuildDeclRefExpr(ValueDecl *D, QualType Ty, 1689 SourceLocation Loc, 1690 const CXXScopeSpec *SS = 0); 1691 ExprResult BuildDeclRefExpr(ValueDecl *D, QualType Ty, 1692 const DeclarationNameInfo &NameInfo, 1693 const CXXScopeSpec *SS = 0); 1694 VarDecl *BuildAnonymousStructUnionMemberPath(FieldDecl *Field, 1695 llvm::SmallVectorImpl<FieldDecl *> &Path); 1696 ExprResult 1697 BuildAnonymousStructUnionMemberReference(SourceLocation Loc, 1698 FieldDecl *Field, 1699 Expr *BaseObjectExpr = 0, 1700 SourceLocation OpLoc = SourceLocation()); 1701 ExprResult BuildPossibleImplicitMemberExpr(const CXXScopeSpec &SS, 1702 LookupResult &R, 1703 const TemplateArgumentListInfo *TemplateArgs); 1704 ExprResult BuildImplicitMemberExpr(const CXXScopeSpec &SS, 1705 LookupResult &R, 1706 const TemplateArgumentListInfo *TemplateArgs, 1707 bool IsDefiniteInstance); 1708 bool UseArgumentDependentLookup(const CXXScopeSpec &SS, 1709 const LookupResult &R, 1710 bool HasTrailingLParen); 1711 1712 ExprResult BuildQualifiedDeclarationNameExpr(CXXScopeSpec &SS, 1713 const DeclarationNameInfo &NameInfo); 1714 ExprResult BuildDependentDeclRefExpr(const CXXScopeSpec &SS, 1715 const DeclarationNameInfo &NameInfo, 1716 const TemplateArgumentListInfo *TemplateArgs); 1717 1718 ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS, 1719 LookupResult &R, 1720 bool ADL); 1721 ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS, 1722 const DeclarationNameInfo &NameInfo, 1723 NamedDecl *D); 1724 1725 ExprResult ActOnPredefinedExpr(SourceLocation Loc, tok::TokenKind Kind); 1726 ExprResult ActOnNumericConstant(const Token &); 1727 ExprResult ActOnCharacterConstant(const Token &); 1728 ExprResult ActOnParenExpr(SourceLocation L, SourceLocation R, Expr *Val); 1729 ExprResult ActOnParenOrParenListExpr(SourceLocation L, 1730 SourceLocation R, 1731 MultiExprArg Val, 1732 ParsedType TypeOfCast = ParsedType()); 1733 1734 /// ActOnStringLiteral - The specified tokens were lexed as pasted string 1735 /// fragments (e.g. "foo" "bar" L"baz"). 1736 ExprResult ActOnStringLiteral(const Token *Toks, unsigned NumToks); 1737 1738 // Binary/Unary Operators. 'Tok' is the token for the operator. 1739 ExprResult CreateBuiltinUnaryOp(SourceLocation OpLoc, unsigned OpcIn, 1740 Expr *InputArg); 1741 ExprResult BuildUnaryOp(Scope *S, SourceLocation OpLoc, 1742 UnaryOperatorKind Opc, Expr *input); 1743 ExprResult ActOnUnaryOp(Scope *S, SourceLocation OpLoc, 1744 tok::TokenKind Op, Expr *Input); 1745 1746 ExprResult CreateSizeOfAlignOfExpr(TypeSourceInfo *T, 1747 SourceLocation OpLoc, 1748 bool isSizeOf, SourceRange R); 1749 ExprResult CreateSizeOfAlignOfExpr(Expr *E, SourceLocation OpLoc, 1750 bool isSizeOf, SourceRange R); 1751 ExprResult 1752 ActOnSizeOfAlignOfExpr(SourceLocation OpLoc, bool isSizeof, bool isType, 1753 void *TyOrEx, const SourceRange &ArgRange); 1754 1755 bool CheckAlignOfExpr(Expr *E, SourceLocation OpLoc, const SourceRange &R); 1756 bool CheckSizeOfAlignOfOperand(QualType type, SourceLocation OpLoc, 1757 const SourceRange &R, bool isSizeof); 1758 1759 ExprResult ActOnPostfixUnaryOp(Scope *S, SourceLocation OpLoc, 1760 tok::TokenKind Kind, Expr *Input); 1761 1762 ExprResult ActOnArraySubscriptExpr(Scope *S, Expr *Base, SourceLocation LLoc, 1763 Expr *Idx, SourceLocation RLoc); 1764 ExprResult CreateBuiltinArraySubscriptExpr(Expr *Base, SourceLocation LLoc, 1765 Expr *Idx, SourceLocation RLoc); 1766 1767 ExprResult BuildMemberReferenceExpr(Expr *Base, QualType BaseType, 1768 SourceLocation OpLoc, bool IsArrow, 1769 CXXScopeSpec &SS, 1770 NamedDecl *FirstQualifierInScope, 1771 const DeclarationNameInfo &NameInfo, 1772 const TemplateArgumentListInfo *TemplateArgs); 1773 1774 ExprResult BuildMemberReferenceExpr(Expr *Base, QualType BaseType, 1775 SourceLocation OpLoc, bool IsArrow, 1776 const CXXScopeSpec &SS, 1777 NamedDecl *FirstQualifierInScope, 1778 LookupResult &R, 1779 const TemplateArgumentListInfo *TemplateArgs, 1780 bool SuppressQualifierCheck = false); 1781 1782 ExprResult LookupMemberExpr(LookupResult &R, Expr *&Base, 1783 bool &IsArrow, SourceLocation OpLoc, 1784 CXXScopeSpec &SS, 1785 Decl *ObjCImpDecl, 1786 bool HasTemplateArgs); 1787 1788 bool CheckQualifiedMemberReference(Expr *BaseExpr, QualType BaseType, 1789 const CXXScopeSpec &SS, 1790 const LookupResult &R); 1791 1792 ExprResult ActOnDependentMemberExpr(Expr *Base, QualType BaseType, 1793 bool IsArrow, SourceLocation OpLoc, 1794 const CXXScopeSpec &SS, 1795 NamedDecl *FirstQualifierInScope, 1796 const DeclarationNameInfo &NameInfo, 1797 const TemplateArgumentListInfo *TemplateArgs); 1798 1799 ExprResult ActOnMemberAccessExpr(Scope *S, Expr *Base, 1800 SourceLocation OpLoc, 1801 tok::TokenKind OpKind, 1802 CXXScopeSpec &SS, 1803 UnqualifiedId &Member, 1804 Decl *ObjCImpDecl, 1805 bool HasTrailingLParen); 1806 1807 void ActOnDefaultCtorInitializers(Decl *CDtorDecl); 1808 bool ConvertArgumentsForCall(CallExpr *Call, Expr *Fn, 1809 FunctionDecl *FDecl, 1810 const FunctionProtoType *Proto, 1811 Expr **Args, unsigned NumArgs, 1812 SourceLocation RParenLoc); 1813 1814 /// ActOnCallExpr - Handle a call to Fn with the specified array of arguments. 1815 /// This provides the location of the left/right parens and a list of comma 1816 /// locations. 1817 ExprResult ActOnCallExpr(Scope *S, Expr *Fn, SourceLocation LParenLoc, 1818 MultiExprArg Args, SourceLocation RParenLoc); 1819 ExprResult BuildResolvedCallExpr(Expr *Fn, NamedDecl *NDecl, 1820 SourceLocation LParenLoc, 1821 Expr **Args, unsigned NumArgs, 1822 SourceLocation RParenLoc); 1823 1824 ExprResult ActOnCastExpr(Scope *S, SourceLocation LParenLoc, 1825 ParsedType Ty, SourceLocation RParenLoc, 1826 Expr *Op); 1827 ExprResult BuildCStyleCastExpr(SourceLocation LParenLoc, 1828 TypeSourceInfo *Ty, 1829 SourceLocation RParenLoc, 1830 Expr *Op); 1831 1832 bool TypeIsVectorType(ParsedType Ty) { 1833 return GetTypeFromParser(Ty)->isVectorType(); 1834 } 1835 1836 ExprResult MaybeConvertParenListExprToParenExpr(Scope *S, Expr *ME); 1837 ExprResult ActOnCastOfParenListExpr(Scope *S, SourceLocation LParenLoc, 1838 SourceLocation RParenLoc, Expr *E, 1839 TypeSourceInfo *TInfo); 1840 1841 ExprResult ActOnCompoundLiteral(SourceLocation LParenLoc, 1842 ParsedType Ty, 1843 SourceLocation RParenLoc, 1844 Expr *Op); 1845 1846 ExprResult BuildCompoundLiteralExpr(SourceLocation LParenLoc, 1847 TypeSourceInfo *TInfo, 1848 SourceLocation RParenLoc, 1849 Expr *InitExpr); 1850 1851 ExprResult ActOnInitList(SourceLocation LParenLoc, 1852 MultiExprArg InitList, 1853 SourceLocation RParenLoc); 1854 1855 ExprResult ActOnDesignatedInitializer(Designation &Desig, 1856 SourceLocation Loc, 1857 bool GNUSyntax, 1858 ExprResult Init); 1859 1860 ExprResult ActOnBinOp(Scope *S, SourceLocation TokLoc, 1861 tok::TokenKind Kind, Expr *LHS, Expr *RHS); 1862 ExprResult BuildBinOp(Scope *S, SourceLocation OpLoc, 1863 BinaryOperatorKind Opc, Expr *lhs, Expr *rhs); 1864 ExprResult CreateBuiltinBinOp(SourceLocation TokLoc, 1865 unsigned Opc, Expr *lhs, Expr *rhs); 1866 1867 /// ActOnConditionalOp - Parse a ?: operation. Note that 'LHS' may be null 1868 /// in the case of a the GNU conditional expr extension. 1869 ExprResult ActOnConditionalOp(SourceLocation QuestionLoc, 1870 SourceLocation ColonLoc, 1871 Expr *Cond, Expr *LHS, Expr *RHS); 1872 1873 /// ActOnAddrLabel - Parse the GNU address of label extension: "&&foo". 1874 ExprResult ActOnAddrLabel(SourceLocation OpLoc, 1875 SourceLocation LabLoc, 1876 IdentifierInfo *LabelII); 1877 1878 ExprResult ActOnStmtExpr(SourceLocation LPLoc, Stmt *SubStmt, 1879 SourceLocation RPLoc); // "({..})" 1880 1881 // __builtin_offsetof(type, identifier(.identifier|[expr])*) 1882 struct OffsetOfComponent { 1883 SourceLocation LocStart, LocEnd; 1884 bool isBrackets; // true if [expr], false if .ident 1885 union { 1886 IdentifierInfo *IdentInfo; 1887 ExprTy *E; 1888 } U; 1889 }; 1890 1891 /// __builtin_offsetof(type, a.b[123][456].c) 1892 ExprResult BuildBuiltinOffsetOf(SourceLocation BuiltinLoc, 1893 TypeSourceInfo *TInfo, 1894 OffsetOfComponent *CompPtr, 1895 unsigned NumComponents, 1896 SourceLocation RParenLoc); 1897 ExprResult ActOnBuiltinOffsetOf(Scope *S, 1898 SourceLocation BuiltinLoc, 1899 SourceLocation TypeLoc, 1900 ParsedType Arg1, 1901 OffsetOfComponent *CompPtr, 1902 unsigned NumComponents, 1903 SourceLocation RParenLoc); 1904 1905 // __builtin_types_compatible_p(type1, type2) 1906 ExprResult ActOnTypesCompatibleExpr(SourceLocation BuiltinLoc, 1907 ParsedType arg1, 1908 ParsedType arg2, 1909 SourceLocation RPLoc); 1910 ExprResult BuildTypesCompatibleExpr(SourceLocation BuiltinLoc, 1911 TypeSourceInfo *argTInfo1, 1912 TypeSourceInfo *argTInfo2, 1913 SourceLocation RPLoc); 1914 1915 // __builtin_choose_expr(constExpr, expr1, expr2) 1916 ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc, 1917 Expr *cond, Expr *expr1, 1918 Expr *expr2, SourceLocation RPLoc); 1919 1920 // __builtin_va_arg(expr, type) 1921 ExprResult ActOnVAArg(SourceLocation BuiltinLoc, 1922 Expr *expr, ParsedType type, 1923 SourceLocation RPLoc); 1924 ExprResult BuildVAArgExpr(SourceLocation BuiltinLoc, 1925 Expr *expr, TypeSourceInfo *TInfo, 1926 SourceLocation RPLoc); 1927 1928 // __null 1929 ExprResult ActOnGNUNullExpr(SourceLocation TokenLoc); 1930 1931 //===------------------------- "Block" Extension ------------------------===// 1932 1933 /// ActOnBlockStart - This callback is invoked when a block literal is 1934 /// started. 1935 void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope); 1936 1937 /// ActOnBlockArguments - This callback allows processing of block arguments. 1938 /// If there are no arguments, this is still invoked. 1939 void ActOnBlockArguments(Declarator &ParamInfo, Scope *CurScope); 1940 1941 /// ActOnBlockError - If there is an error parsing a block, this callback 1942 /// is invoked to pop the information about the block from the action impl. 1943 void ActOnBlockError(SourceLocation CaretLoc, Scope *CurScope); 1944 1945 /// ActOnBlockStmtExpr - This is called when the body of a block statement 1946 /// literal was successfully completed. ^(int x){...} 1947 ExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc, 1948 Stmt *Body, Scope *CurScope); 1949 1950 //===---------------------------- C++ Features --------------------------===// 1951 1952 // Act on C++ namespaces 1953 Decl *ActOnStartNamespaceDef(Scope *S, SourceLocation InlineLoc, 1954 SourceLocation IdentLoc, 1955 IdentifierInfo *Ident, 1956 SourceLocation LBrace, 1957 AttributeList *AttrList); 1958 void ActOnFinishNamespaceDef(Decl *Dcl, SourceLocation RBrace); 1959 1960 NamespaceDecl *getStdNamespace() const; 1961 NamespaceDecl *getOrCreateStdNamespace(); 1962 1963 CXXRecordDecl *getStdBadAlloc() const; 1964 1965 Decl *ActOnUsingDirective(Scope *CurScope, 1966 SourceLocation UsingLoc, 1967 SourceLocation NamespcLoc, 1968 CXXScopeSpec &SS, 1969 SourceLocation IdentLoc, 1970 IdentifierInfo *NamespcName, 1971 AttributeList *AttrList); 1972 1973 void PushUsingDirective(Scope *S, UsingDirectiveDecl *UDir); 1974 1975 Decl *ActOnNamespaceAliasDef(Scope *CurScope, 1976 SourceLocation NamespaceLoc, 1977 SourceLocation AliasLoc, 1978 IdentifierInfo *Alias, 1979 CXXScopeSpec &SS, 1980 SourceLocation IdentLoc, 1981 IdentifierInfo *Ident); 1982 1983 void HideUsingShadowDecl(Scope *S, UsingShadowDecl *Shadow); 1984 bool CheckUsingShadowDecl(UsingDecl *UD, NamedDecl *Target, 1985 const LookupResult &PreviousDecls); 1986 UsingShadowDecl *BuildUsingShadowDecl(Scope *S, UsingDecl *UD, 1987 NamedDecl *Target); 1988 1989 bool CheckUsingDeclRedeclaration(SourceLocation UsingLoc, 1990 bool isTypeName, 1991 const CXXScopeSpec &SS, 1992 SourceLocation NameLoc, 1993 const LookupResult &Previous); 1994 bool CheckUsingDeclQualifier(SourceLocation UsingLoc, 1995 const CXXScopeSpec &SS, 1996 SourceLocation NameLoc); 1997 1998 NamedDecl *BuildUsingDeclaration(Scope *S, AccessSpecifier AS, 1999 SourceLocation UsingLoc, 2000 CXXScopeSpec &SS, 2001 const DeclarationNameInfo &NameInfo, 2002 AttributeList *AttrList, 2003 bool IsInstantiation, 2004 bool IsTypeName, 2005 SourceLocation TypenameLoc); 2006 2007 Decl *ActOnUsingDeclaration(Scope *CurScope, 2008 AccessSpecifier AS, 2009 bool HasUsingKeyword, 2010 SourceLocation UsingLoc, 2011 CXXScopeSpec &SS, 2012 UnqualifiedId &Name, 2013 AttributeList *AttrList, 2014 bool IsTypeName, 2015 SourceLocation TypenameLoc); 2016 2017 /// AddCXXDirectInitializerToDecl - This action is called immediately after 2018 /// ActOnDeclarator, when a C++ direct initializer is present. 2019 /// e.g: "int x(1);" 2020 void AddCXXDirectInitializerToDecl(Decl *Dcl, 2021 SourceLocation LParenLoc, 2022 MultiExprArg Exprs, 2023 SourceLocation RParenLoc); 2024 2025 /// InitializeVarWithConstructor - Creates an CXXConstructExpr 2026 /// and sets it as the initializer for the the passed in VarDecl. 2027 bool InitializeVarWithConstructor(VarDecl *VD, 2028 CXXConstructorDecl *Constructor, 2029 MultiExprArg Exprs); 2030 2031 /// BuildCXXConstructExpr - Creates a complete call to a constructor, 2032 /// including handling of its default argument expressions. 2033 /// 2034 /// \param ConstructKind - a CXXConstructExpr::ConstructionKind 2035 ExprResult 2036 BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType, 2037 CXXConstructorDecl *Constructor, MultiExprArg Exprs, 2038 bool RequiresZeroInit, unsigned ConstructKind); 2039 2040 // FIXME: Can re remove this and have the above BuildCXXConstructExpr check if 2041 // the constructor can be elidable? 2042 ExprResult 2043 BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType, 2044 CXXConstructorDecl *Constructor, bool Elidable, 2045 MultiExprArg Exprs, bool RequiresZeroInit, 2046 unsigned ConstructKind); 2047 2048 /// BuildCXXDefaultArgExpr - Creates a CXXDefaultArgExpr, instantiating 2049 /// the default expr if needed. 2050 ExprResult BuildCXXDefaultArgExpr(SourceLocation CallLoc, 2051 FunctionDecl *FD, 2052 ParmVarDecl *Param); 2053 2054 /// FinalizeVarWithDestructor - Prepare for calling destructor on the 2055 /// constructed variable. 2056 void FinalizeVarWithDestructor(VarDecl *VD, const RecordType *DeclInitType); 2057 2058 /// \brief Declare the implicit default constructor for the given class. 2059 /// 2060 /// \param ClassDecl The class declaration into which the implicit 2061 /// default constructor will be added. 2062 /// 2063 /// \returns The implicitly-declared default constructor. 2064 CXXConstructorDecl *DeclareImplicitDefaultConstructor( 2065 CXXRecordDecl *ClassDecl); 2066 2067 /// DefineImplicitDefaultConstructor - Checks for feasibility of 2068 /// defining this constructor as the default constructor. 2069 void DefineImplicitDefaultConstructor(SourceLocation CurrentLocation, 2070 CXXConstructorDecl *Constructor); 2071 2072 /// \brief Declare the implicit destructor for the given class. 2073 /// 2074 /// \param ClassDecl The class declaration into which the implicit 2075 /// destructor will be added. 2076 /// 2077 /// \returns The implicitly-declared destructor. 2078 CXXDestructorDecl *DeclareImplicitDestructor(CXXRecordDecl *ClassDecl); 2079 2080 /// DefineImplicitDestructor - Checks for feasibility of 2081 /// defining this destructor as the default destructor. 2082 void DefineImplicitDestructor(SourceLocation CurrentLocation, 2083 CXXDestructorDecl *Destructor); 2084 2085 /// \brief Declare the implicit copy constructor for the given class. 2086 /// 2087 /// \param S The scope of the class, which may be NULL if this is a 2088 /// template instantiation. 2089 /// 2090 /// \param ClassDecl The class declaration into which the implicit 2091 /// copy constructor will be added. 2092 /// 2093 /// \returns The implicitly-declared copy constructor. 2094 CXXConstructorDecl *DeclareImplicitCopyConstructor(CXXRecordDecl *ClassDecl); 2095 2096 /// DefineImplicitCopyConstructor - Checks for feasibility of 2097 /// defining this constructor as the copy constructor. 2098 void DefineImplicitCopyConstructor(SourceLocation CurrentLocation, 2099 CXXConstructorDecl *Constructor, 2100 unsigned TypeQuals); 2101 2102 /// \brief Declare the implicit copy assignment operator for the given class. 2103 /// 2104 /// \param S The scope of the class, which may be NULL if this is a 2105 /// template instantiation. 2106 /// 2107 /// \param ClassDecl The class declaration into which the implicit 2108 /// copy-assignment operator will be added. 2109 /// 2110 /// \returns The implicitly-declared copy assignment operator. 2111 CXXMethodDecl *DeclareImplicitCopyAssignment(CXXRecordDecl *ClassDecl); 2112 2113 /// \brief Defined an implicitly-declared copy assignment operator. 2114 void DefineImplicitCopyAssignment(SourceLocation CurrentLocation, 2115 CXXMethodDecl *MethodDecl); 2116 2117 /// \brief Force the declaration of any implicitly-declared members of this 2118 /// class. 2119 void ForceDeclarationOfImplicitMembers(CXXRecordDecl *Class); 2120 2121 /// MaybeBindToTemporary - If the passed in expression has a record type with 2122 /// a non-trivial destructor, this will return CXXBindTemporaryExpr. Otherwise 2123 /// it simply returns the passed in expression. 2124 ExprResult MaybeBindToTemporary(Expr *E); 2125 2126 bool CompleteConstructorCall(CXXConstructorDecl *Constructor, 2127 MultiExprArg ArgsPtr, 2128 SourceLocation Loc, 2129 ASTOwningVector<Expr*> &ConvertedArgs); 2130 2131 ParsedType getDestructorName(SourceLocation TildeLoc, 2132 IdentifierInfo &II, SourceLocation NameLoc, 2133 Scope *S, CXXScopeSpec &SS, 2134 ParsedType ObjectType, 2135 bool EnteringContext); 2136 2137 /// ActOnCXXNamedCast - Parse {dynamic,static,reinterpret,const}_cast's. 2138 ExprResult ActOnCXXNamedCast(SourceLocation OpLoc, 2139 tok::TokenKind Kind, 2140 SourceLocation LAngleBracketLoc, 2141 ParsedType Ty, 2142 SourceLocation RAngleBracketLoc, 2143 SourceLocation LParenLoc, 2144 Expr *E, 2145 SourceLocation RParenLoc); 2146 2147 ExprResult BuildCXXNamedCast(SourceLocation OpLoc, 2148 tok::TokenKind Kind, 2149 TypeSourceInfo *Ty, 2150 Expr *E, 2151 SourceRange AngleBrackets, 2152 SourceRange Parens); 2153 2154 ExprResult BuildCXXTypeId(QualType TypeInfoType, 2155 SourceLocation TypeidLoc, 2156 TypeSourceInfo *Operand, 2157 SourceLocation RParenLoc); 2158 ExprResult BuildCXXTypeId(QualType TypeInfoType, 2159 SourceLocation TypeidLoc, 2160 Expr *Operand, 2161 SourceLocation RParenLoc); 2162 2163 /// ActOnCXXTypeid - Parse typeid( something ). 2164 ExprResult ActOnCXXTypeid(SourceLocation OpLoc, 2165 SourceLocation LParenLoc, bool isType, 2166 void *TyOrExpr, 2167 SourceLocation RParenLoc); 2168 2169 ExprResult BuildCXXUuidof(QualType TypeInfoType, 2170 SourceLocation TypeidLoc, 2171 TypeSourceInfo *Operand, 2172 SourceLocation RParenLoc); 2173 ExprResult BuildCXXUuidof(QualType TypeInfoType, 2174 SourceLocation TypeidLoc, 2175 Expr *Operand, 2176 SourceLocation RParenLoc); 2177 2178 /// ActOnCXXUuidof - Parse __uuidof( something ). 2179 ExprResult ActOnCXXUuidof(SourceLocation OpLoc, 2180 SourceLocation LParenLoc, bool isType, 2181 void *TyOrExpr, 2182 SourceLocation RParenLoc); 2183 2184 2185 //// ActOnCXXThis - Parse 'this' pointer. 2186 ExprResult ActOnCXXThis(SourceLocation ThisLoc); 2187 2188 /// ActOnCXXBoolLiteral - Parse {true,false} literals. 2189 ExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind); 2190 2191 /// ActOnCXXNullPtrLiteral - Parse 'nullptr'. 2192 ExprResult ActOnCXXNullPtrLiteral(SourceLocation Loc); 2193 2194 //// ActOnCXXThrow - Parse throw expressions. 2195 ExprResult ActOnCXXThrow(SourceLocation OpLoc, Expr *expr); 2196 bool CheckCXXThrowOperand(SourceLocation ThrowLoc, Expr *&E); 2197 2198 /// ActOnCXXTypeConstructExpr - Parse construction of a specified type. 2199 /// Can be interpreted either as function-style casting ("int(x)") 2200 /// or class type construction ("ClassType(x,y,z)") 2201 /// or creation of a value-initialized type ("int()"). 2202 ExprResult ActOnCXXTypeConstructExpr(ParsedType TypeRep, 2203 SourceLocation LParenLoc, 2204 MultiExprArg Exprs, 2205 SourceLocation RParenLoc); 2206 2207 ExprResult BuildCXXTypeConstructExpr(TypeSourceInfo *Type, 2208 SourceLocation LParenLoc, 2209 MultiExprArg Exprs, 2210 SourceLocation RParenLoc); 2211 2212 /// ActOnCXXNew - Parsed a C++ 'new' expression. 2213 ExprResult ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal, 2214 SourceLocation PlacementLParen, 2215 MultiExprArg PlacementArgs, 2216 SourceLocation PlacementRParen, 2217 SourceRange TypeIdParens, Declarator &D, 2218 SourceLocation ConstructorLParen, 2219 MultiExprArg ConstructorArgs, 2220 SourceLocation ConstructorRParen); 2221 ExprResult BuildCXXNew(SourceLocation StartLoc, bool UseGlobal, 2222 SourceLocation PlacementLParen, 2223 MultiExprArg PlacementArgs, 2224 SourceLocation PlacementRParen, 2225 SourceRange TypeIdParens, 2226 QualType AllocType, 2227 TypeSourceInfo *AllocTypeInfo, 2228 Expr *ArraySize, 2229 SourceLocation ConstructorLParen, 2230 MultiExprArg ConstructorArgs, 2231 SourceLocation ConstructorRParen); 2232 2233 bool CheckAllocatedType(QualType AllocType, SourceLocation Loc, 2234 SourceRange R); 2235 bool FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range, 2236 bool UseGlobal, QualType AllocType, bool IsArray, 2237 Expr **PlaceArgs, unsigned NumPlaceArgs, 2238 FunctionDecl *&OperatorNew, 2239 FunctionDecl *&OperatorDelete); 2240 bool FindAllocationOverload(SourceLocation StartLoc, SourceRange Range, 2241 DeclarationName Name, Expr** Args, 2242 unsigned NumArgs, DeclContext *Ctx, 2243 bool AllowMissing, FunctionDecl *&Operator); 2244 void DeclareGlobalNewDelete(); 2245 void DeclareGlobalAllocationFunction(DeclarationName Name, QualType Return, 2246 QualType Argument, 2247 bool addMallocAttr = false); 2248 2249 bool FindDeallocationFunction(SourceLocation StartLoc, CXXRecordDecl *RD, 2250 DeclarationName Name, FunctionDecl* &Operator); 2251 2252 /// ActOnCXXDelete - Parsed a C++ 'delete' expression 2253 ExprResult ActOnCXXDelete(SourceLocation StartLoc, 2254 bool UseGlobal, bool ArrayForm, 2255 Expr *Operand); 2256 2257 DeclResult ActOnCXXConditionDeclaration(Scope *S, Declarator &D); 2258 ExprResult CheckConditionVariable(VarDecl *ConditionVar, 2259 SourceLocation StmtLoc, 2260 bool ConvertToBoolean); 2261 2262 ExprResult ActOnNoexceptExpr(SourceLocation KeyLoc, SourceLocation LParen, 2263 Expr *Operand, SourceLocation RParen); 2264 ExprResult BuildCXXNoexceptExpr(SourceLocation KeyLoc, Expr *Operand, 2265 SourceLocation RParen); 2266 2267 /// ActOnUnaryTypeTrait - Parsed one of the unary type trait support 2268 /// pseudo-functions. 2269 ExprResult ActOnUnaryTypeTrait(UnaryTypeTrait OTT, 2270 SourceLocation KWLoc, 2271 ParsedType Ty, 2272 SourceLocation RParen); 2273 2274 ExprResult BuildUnaryTypeTrait(UnaryTypeTrait OTT, 2275 SourceLocation KWLoc, 2276 TypeSourceInfo *T, 2277 SourceLocation RParen); 2278 2279 ExprResult ActOnStartCXXMemberReference(Scope *S, 2280 Expr *Base, 2281 SourceLocation OpLoc, 2282 tok::TokenKind OpKind, 2283 ParsedType &ObjectType, 2284 bool &MayBePseudoDestructor); 2285 2286 ExprResult DiagnoseDtorReference(SourceLocation NameLoc, Expr *MemExpr); 2287 2288 ExprResult BuildPseudoDestructorExpr(Expr *Base, 2289 SourceLocation OpLoc, 2290 tok::TokenKind OpKind, 2291 const CXXScopeSpec &SS, 2292 TypeSourceInfo *ScopeType, 2293 SourceLocation CCLoc, 2294 SourceLocation TildeLoc, 2295 PseudoDestructorTypeStorage DestroyedType, 2296 bool HasTrailingLParen); 2297 2298 ExprResult ActOnPseudoDestructorExpr(Scope *S, Expr *Base, 2299 SourceLocation OpLoc, 2300 tok::TokenKind OpKind, 2301 CXXScopeSpec &SS, 2302 UnqualifiedId &FirstTypeName, 2303 SourceLocation CCLoc, 2304 SourceLocation TildeLoc, 2305 UnqualifiedId &SecondTypeName, 2306 bool HasTrailingLParen); 2307 2308 /// MaybeCreateCXXExprWithTemporaries - If the list of temporaries is 2309 /// non-empty, will create a new CXXExprWithTemporaries expression. 2310 /// Otherwise, just returs the passed in expression. 2311 Expr *MaybeCreateCXXExprWithTemporaries(Expr *SubExpr); 2312 ExprResult MaybeCreateCXXExprWithTemporaries(ExprResult SubExpr); 2313 FullExpr CreateFullExpr(Expr *SubExpr); 2314 2315 ExprResult ActOnFinishFullExpr(Expr *Expr); 2316 2317 // Marks SS invalid if it represents an incomplete type. 2318 bool RequireCompleteDeclContext(CXXScopeSpec &SS, DeclContext *DC); 2319 2320 DeclContext *computeDeclContext(QualType T); 2321 DeclContext *computeDeclContext(const CXXScopeSpec &SS, 2322 bool EnteringContext = false); 2323 bool isDependentScopeSpecifier(const CXXScopeSpec &SS); 2324 CXXRecordDecl *getCurrentInstantiationOf(NestedNameSpecifier *NNS); 2325 bool isUnknownSpecialization(const CXXScopeSpec &SS); 2326 2327 /// ActOnCXXGlobalScopeSpecifier - Return the object that represents the 2328 /// global scope ('::'). 2329 NestedNameSpecifier * 2330 ActOnCXXGlobalScopeSpecifier(Scope *S, SourceLocation CCLoc); 2331 2332 bool isAcceptableNestedNameSpecifier(NamedDecl *SD); 2333 NamedDecl *FindFirstQualifierInScope(Scope *S, NestedNameSpecifier *NNS); 2334 2335 bool isNonTypeNestedNameSpecifier(Scope *S, CXXScopeSpec &SS, 2336 SourceLocation IdLoc, 2337 IdentifierInfo &II, 2338 ParsedType ObjectType); 2339 2340 NestedNameSpecifier *BuildCXXNestedNameSpecifier(Scope *S, 2341 CXXScopeSpec &SS, 2342 SourceLocation IdLoc, 2343 SourceLocation CCLoc, 2344 IdentifierInfo &II, 2345 QualType ObjectType, 2346 NamedDecl *ScopeLookupResult, 2347 bool EnteringContext, 2348 bool ErrorRecoveryLookup); 2349 2350 NestedNameSpecifier *ActOnCXXNestedNameSpecifier(Scope *S, 2351 CXXScopeSpec &SS, 2352 SourceLocation IdLoc, 2353 SourceLocation CCLoc, 2354 IdentifierInfo &II, 2355 ParsedType ObjectType, 2356 bool EnteringContext); 2357 2358 bool IsInvalidUnlessNestedName(Scope *S, CXXScopeSpec &SS, 2359 IdentifierInfo &II, 2360 ParsedType ObjectType, 2361 bool EnteringContext); 2362 2363 /// ActOnCXXNestedNameSpecifier - Called during parsing of a 2364 /// nested-name-specifier that involves a template-id, e.g., 2365 /// "foo::bar<int, float>::", and now we need to build a scope 2366 /// specifier. \p SS is empty or the previously parsed nested-name 2367 /// part ("foo::"), \p Type is the already-parsed class template 2368 /// specialization (or other template-id that names a type), \p 2369 /// TypeRange is the source range where the type is located, and \p 2370 /// CCLoc is the location of the trailing '::'. 2371 CXXScopeTy *ActOnCXXNestedNameSpecifier(Scope *S, 2372 const CXXScopeSpec &SS, 2373 ParsedType Type, 2374 SourceRange TypeRange, 2375 SourceLocation CCLoc); 2376 2377 bool ShouldEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS); 2378 2379 /// ActOnCXXEnterDeclaratorScope - Called when a C++ scope specifier (global 2380 /// scope or nested-name-specifier) is parsed, part of a declarator-id. 2381 /// After this method is called, according to [C++ 3.4.3p3], names should be 2382 /// looked up in the declarator-id's scope, until the declarator is parsed and 2383 /// ActOnCXXExitDeclaratorScope is called. 2384 /// The 'SS' should be a non-empty valid CXXScopeSpec. 2385 bool ActOnCXXEnterDeclaratorScope(Scope *S, CXXScopeSpec &SS); 2386 2387 /// ActOnCXXExitDeclaratorScope - Called when a declarator that previously 2388 /// invoked ActOnCXXEnterDeclaratorScope(), is finished. 'SS' is the same 2389 /// CXXScopeSpec that was passed to ActOnCXXEnterDeclaratorScope as well. 2390 /// Used to indicate that names should revert to being looked up in the 2391 /// defining scope. 2392 void ActOnCXXExitDeclaratorScope(Scope *S, const CXXScopeSpec &SS); 2393 2394 /// ActOnCXXEnterDeclInitializer - Invoked when we are about to parse an 2395 /// initializer for the declaration 'Dcl'. 2396 /// After this method is called, according to [C++ 3.4.1p13], if 'Dcl' is a 2397 /// static data member of class X, names should be looked up in the scope of 2398 /// class X. 2399 void ActOnCXXEnterDeclInitializer(Scope *S, Decl *Dcl); 2400 2401 /// ActOnCXXExitDeclInitializer - Invoked after we are finished parsing an 2402 /// initializer for the declaration 'Dcl'. 2403 void ActOnCXXExitDeclInitializer(Scope *S, Decl *Dcl); 2404 2405 // ParseObjCStringLiteral - Parse Objective-C string literals. 2406 ExprResult ParseObjCStringLiteral(SourceLocation *AtLocs, 2407 Expr **Strings, 2408 unsigned NumStrings); 2409 2410 Expr *BuildObjCEncodeExpression(SourceLocation AtLoc, 2411 TypeSourceInfo *EncodedTypeInfo, 2412 SourceLocation RParenLoc); 2413 CXXMemberCallExpr *BuildCXXMemberCallExpr(Expr *Exp, 2414 NamedDecl *FoundDecl, 2415 CXXMethodDecl *Method); 2416 2417 ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc, 2418 SourceLocation EncodeLoc, 2419 SourceLocation LParenLoc, 2420 ParsedType Ty, 2421 SourceLocation RParenLoc); 2422 2423 // ParseObjCSelectorExpression - Build selector expression for @selector 2424 ExprResult ParseObjCSelectorExpression(Selector Sel, 2425 SourceLocation AtLoc, 2426 SourceLocation SelLoc, 2427 SourceLocation LParenLoc, 2428 SourceLocation RParenLoc); 2429 2430 // ParseObjCProtocolExpression - Build protocol expression for @protocol 2431 ExprResult ParseObjCProtocolExpression(IdentifierInfo * ProtocolName, 2432 SourceLocation AtLoc, 2433 SourceLocation ProtoLoc, 2434 SourceLocation LParenLoc, 2435 SourceLocation RParenLoc); 2436 2437 //===--------------------------------------------------------------------===// 2438 // C++ Declarations 2439 // 2440 Decl *ActOnStartLinkageSpecification(Scope *S, 2441 SourceLocation ExternLoc, 2442 SourceLocation LangLoc, 2443 llvm::StringRef Lang, 2444 SourceLocation LBraceLoc); 2445 Decl *ActOnFinishLinkageSpecification(Scope *S, 2446 Decl *LinkageSpec, 2447 SourceLocation RBraceLoc); 2448 2449 2450 //===--------------------------------------------------------------------===// 2451 // C++ Classes 2452 // 2453 bool isCurrentClassName(const IdentifierInfo &II, Scope *S, 2454 const CXXScopeSpec *SS = 0); 2455 2456 Decl *ActOnAccessSpecifier(AccessSpecifier Access, 2457 SourceLocation ASLoc, 2458 SourceLocation ColonLoc); 2459 2460 Decl *ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS, 2461 Declarator &D, 2462 MultiTemplateParamsArg TemplateParameterLists, 2463 Expr *BitfieldWidth, 2464 Expr *Init, bool IsDefinition, 2465 bool Deleted = false); 2466 2467 MemInitResult ActOnMemInitializer(Decl *ConstructorD, 2468 Scope *S, 2469 CXXScopeSpec &SS, 2470 IdentifierInfo *MemberOrBase, 2471 ParsedType TemplateTypeTy, 2472 SourceLocation IdLoc, 2473 SourceLocation LParenLoc, 2474 Expr **Args, unsigned NumArgs, 2475 SourceLocation RParenLoc); 2476 2477 MemInitResult BuildMemberInitializer(FieldDecl *Member, Expr **Args, 2478 unsigned NumArgs, SourceLocation IdLoc, 2479 SourceLocation LParenLoc, 2480 SourceLocation RParenLoc); 2481 2482 MemInitResult BuildBaseInitializer(QualType BaseType, 2483 TypeSourceInfo *BaseTInfo, 2484 Expr **Args, unsigned NumArgs, 2485 SourceLocation LParenLoc, 2486 SourceLocation RParenLoc, 2487 CXXRecordDecl *ClassDecl); 2488 2489 bool SetBaseOrMemberInitializers(CXXConstructorDecl *Constructor, 2490 CXXBaseOrMemberInitializer **Initializers, 2491 unsigned NumInitializers, bool AnyErrors); 2492 2493 void SetIvarInitializers(ObjCImplementationDecl *ObjCImplementation); 2494 2495 2496 /// MarkBaseAndMemberDestructorsReferenced - Given a record decl, 2497 /// mark all the non-trivial destructors of its members and bases as 2498 /// referenced. 2499 void MarkBaseAndMemberDestructorsReferenced(SourceLocation Loc, 2500 CXXRecordDecl *Record); 2501 2502 /// \brief The list of classes whose vtables have been used within 2503 /// this translation unit, and the source locations at which the 2504 /// first use occurred. 2505 llvm::SmallVector<std::pair<CXXRecordDecl *, SourceLocation>, 16> 2506 VTableUses; 2507 2508 /// \brief The set of classes whose vtables have been used within 2509 /// this translation unit, and a bit that will be true if the vtable is 2510 /// required to be emitted (otherwise, it should be emitted only if needed 2511 /// by code generation). 2512 llvm::DenseMap<CXXRecordDecl *, bool> VTablesUsed; 2513 2514 /// \brief A list of all of the dynamic classes in this translation 2515 /// unit. 2516 llvm::SmallVector<CXXRecordDecl *, 16> DynamicClasses; 2517 2518 /// \brief Note that the vtable for the given class was used at the 2519 /// given location. 2520 void MarkVTableUsed(SourceLocation Loc, CXXRecordDecl *Class, 2521 bool DefinitionRequired = false); 2522 2523 /// MarkVirtualMembersReferenced - Will mark all members of the given 2524 /// CXXRecordDecl referenced. 2525 void MarkVirtualMembersReferenced(SourceLocation Loc, 2526 const CXXRecordDecl *RD); 2527 2528 /// \brief Define all of the vtables that have been used in this 2529 /// translation unit and reference any virtual members used by those 2530 /// vtables. 2531 /// 2532 /// \returns true if any work was done, false otherwise. 2533 bool DefineUsedVTables(); 2534 2535 void AddImplicitlyDeclaredMembersToClass(CXXRecordDecl *ClassDecl); 2536 2537 void ActOnMemInitializers(Decl *ConstructorDecl, 2538 SourceLocation ColonLoc, 2539 MemInitTy **MemInits, unsigned NumMemInits, 2540 bool AnyErrors); 2541 2542 void CheckCompletedCXXClass(CXXRecordDecl *Record); 2543 void ActOnFinishCXXMemberSpecification(Scope* S, SourceLocation RLoc, 2544 Decl *TagDecl, 2545 SourceLocation LBrac, 2546 SourceLocation RBrac, 2547 AttributeList *AttrList); 2548 2549 void ActOnReenterTemplateScope(Scope *S, Decl *Template); 2550 void ActOnStartDelayedMemberDeclarations(Scope *S, Decl *Record); 2551 void ActOnStartDelayedCXXMethodDeclaration(Scope *S, Decl *Method); 2552 void ActOnDelayedCXXMethodParameter(Scope *S, Decl *Param); 2553 void ActOnFinishDelayedCXXMethodDeclaration(Scope *S, Decl *Method); 2554 void ActOnFinishDelayedMemberDeclarations(Scope *S, Decl *Record); 2555 2556 Decl *ActOnStaticAssertDeclaration(SourceLocation AssertLoc, 2557 Expr *AssertExpr, 2558 Expr *AssertMessageExpr); 2559 2560 FriendDecl *CheckFriendTypeDecl(SourceLocation FriendLoc, 2561 TypeSourceInfo *TSInfo); 2562 Decl *ActOnFriendTypeDecl(Scope *S, const DeclSpec &DS, 2563 MultiTemplateParamsArg TemplateParams); 2564 Decl *ActOnFriendFunctionDecl(Scope *S, Declarator &D, bool IsDefinition, 2565 MultiTemplateParamsArg TemplateParams); 2566 2567 QualType CheckConstructorDeclarator(Declarator &D, QualType R, 2568 StorageClass& SC); 2569 void CheckConstructor(CXXConstructorDecl *Constructor); 2570 QualType CheckDestructorDeclarator(Declarator &D, QualType R, 2571 StorageClass& SC); 2572 bool CheckDestructor(CXXDestructorDecl *Destructor); 2573 void CheckConversionDeclarator(Declarator &D, QualType &R, 2574 StorageClass& SC); 2575 Decl *ActOnConversionDeclarator(CXXConversionDecl *Conversion); 2576 2577 //===--------------------------------------------------------------------===// 2578 // C++ Derived Classes 2579 // 2580 2581 /// ActOnBaseSpecifier - Parsed a base specifier 2582 CXXBaseSpecifier *CheckBaseSpecifier(CXXRecordDecl *Class, 2583 SourceRange SpecifierRange, 2584 bool Virtual, AccessSpecifier Access, 2585 TypeSourceInfo *TInfo); 2586 2587 /// SetClassDeclAttributesFromBase - Copies class decl traits 2588 /// (such as whether the class has a trivial constructor, 2589 /// trivial destructor etc) from the given base class. 2590 void SetClassDeclAttributesFromBase(CXXRecordDecl *Class, 2591 const CXXRecordDecl *BaseClass, 2592 bool BaseIsVirtual); 2593 2594 BaseResult ActOnBaseSpecifier(Decl *classdecl, 2595 SourceRange SpecifierRange, 2596 bool Virtual, AccessSpecifier Access, 2597 ParsedType basetype, SourceLocation 2598 BaseLoc); 2599 2600 bool AttachBaseSpecifiers(CXXRecordDecl *Class, CXXBaseSpecifier **Bases, 2601 unsigned NumBases); 2602 void ActOnBaseSpecifiers(Decl *ClassDecl, BaseTy **Bases, unsigned NumBases); 2603 2604 bool IsDerivedFrom(QualType Derived, QualType Base); 2605 bool IsDerivedFrom(QualType Derived, QualType Base, CXXBasePaths &Paths); 2606 2607 // FIXME: I don't like this name. 2608 void BuildBasePathArray(const CXXBasePaths &Paths, CXXCastPath &BasePath); 2609 2610 bool BasePathInvolvesVirtualBase(const CXXCastPath &BasePath); 2611 2612 bool CheckDerivedToBaseConversion(QualType Derived, QualType Base, 2613 SourceLocation Loc, SourceRange Range, 2614 CXXCastPath *BasePath = 0, 2615 bool IgnoreAccess = false); 2616 bool CheckDerivedToBaseConversion(QualType Derived, QualType Base, 2617 unsigned InaccessibleBaseID, 2618 unsigned AmbigiousBaseConvID, 2619 SourceLocation Loc, SourceRange Range, 2620 DeclarationName Name, 2621 CXXCastPath *BasePath); 2622 2623 std::string getAmbiguousPathsDisplayString(CXXBasePaths &Paths); 2624 2625 /// CheckOverridingFunctionReturnType - Checks whether the return types are 2626 /// covariant, according to C++ [class.virtual]p5. 2627 bool CheckOverridingFunctionReturnType(const CXXMethodDecl *New, 2628 const CXXMethodDecl *Old); 2629 2630 /// CheckOverridingFunctionExceptionSpec - Checks whether the exception 2631 /// spec is a subset of base spec. 2632 bool CheckOverridingFunctionExceptionSpec(const CXXMethodDecl *New, 2633 const CXXMethodDecl *Old); 2634 2635 /// CheckOverridingFunctionAttributes - Checks whether attributes are 2636 /// incompatible or prevent overriding. 2637 bool CheckOverridingFunctionAttributes(const CXXMethodDecl *New, 2638 const CXXMethodDecl *Old); 2639 2640 bool CheckPureMethod(CXXMethodDecl *Method, SourceRange InitRange); 2641 2642 //===--------------------------------------------------------------------===// 2643 // C++ Access Control 2644 // 2645 2646 enum AccessResult { 2647 AR_accessible, 2648 AR_inaccessible, 2649 AR_dependent, 2650 AR_delayed 2651 }; 2652 2653 bool SetMemberAccessSpecifier(NamedDecl *MemberDecl, 2654 NamedDecl *PrevMemberDecl, 2655 AccessSpecifier LexicalAS); 2656 2657 AccessResult CheckUnresolvedMemberAccess(UnresolvedMemberExpr *E, 2658 DeclAccessPair FoundDecl); 2659 AccessResult CheckUnresolvedLookupAccess(UnresolvedLookupExpr *E, 2660 DeclAccessPair FoundDecl); 2661 AccessResult CheckAllocationAccess(SourceLocation OperatorLoc, 2662 SourceRange PlacementRange, 2663 CXXRecordDecl *NamingClass, 2664 DeclAccessPair FoundDecl); 2665 AccessResult CheckConstructorAccess(SourceLocation Loc, 2666 CXXConstructorDecl *D, 2667 const InitializedEntity &Entity, 2668 AccessSpecifier Access, 2669 bool IsCopyBindingRefToTemp = false); 2670 AccessResult CheckDestructorAccess(SourceLocation Loc, 2671 CXXDestructorDecl *Dtor, 2672 const PartialDiagnostic &PDiag); 2673 AccessResult CheckDirectMemberAccess(SourceLocation Loc, 2674 NamedDecl *D, 2675 const PartialDiagnostic &PDiag); 2676 AccessResult CheckMemberOperatorAccess(SourceLocation Loc, 2677 Expr *ObjectExpr, 2678 Expr *ArgExpr, 2679 DeclAccessPair FoundDecl); 2680 AccessResult CheckAddressOfMemberAccess(Expr *OvlExpr, 2681 DeclAccessPair FoundDecl); 2682 AccessResult CheckBaseClassAccess(SourceLocation AccessLoc, 2683 QualType Base, QualType Derived, 2684 const CXXBasePath &Path, 2685 unsigned DiagID, 2686 bool ForceCheck = false, 2687 bool ForceUnprivileged = false); 2688 void CheckLookupAccess(const LookupResult &R); 2689 2690 void HandleDependentAccessCheck(const DependentDiagnostic &DD, 2691 const MultiLevelTemplateArgumentList &TemplateArgs); 2692 void PerformDependentDiagnostics(const DeclContext *Pattern, 2693 const MultiLevelTemplateArgumentList &TemplateArgs); 2694 2695 void HandleDelayedAccessCheck(sema::DelayedDiagnostic &DD, Decl *Ctx); 2696 2697 /// A flag to suppress access checking. 2698 bool SuppressAccessChecking; 2699 2700 void ActOnStartSuppressingAccessChecks(); 2701 void ActOnStopSuppressingAccessChecks(); 2702 2703 enum AbstractDiagSelID { 2704 AbstractNone = -1, 2705 AbstractReturnType, 2706 AbstractParamType, 2707 AbstractVariableType, 2708 AbstractFieldType, 2709 AbstractArrayType 2710 }; 2711 2712 bool RequireNonAbstractType(SourceLocation Loc, QualType T, 2713 const PartialDiagnostic &PD); 2714 void DiagnoseAbstractType(const CXXRecordDecl *RD); 2715 2716 bool RequireNonAbstractType(SourceLocation Loc, QualType T, unsigned DiagID, 2717 AbstractDiagSelID SelID = AbstractNone); 2718 2719 //===--------------------------------------------------------------------===// 2720 // C++ Overloaded Operators [C++ 13.5] 2721 // 2722 2723 bool CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl); 2724 2725 bool CheckLiteralOperatorDeclaration(FunctionDecl *FnDecl); 2726 2727 //===--------------------------------------------------------------------===// 2728 // C++ Templates [C++ 14] 2729 // 2730 void LookupTemplateName(LookupResult &R, Scope *S, CXXScopeSpec &SS, 2731 QualType ObjectType, bool EnteringContext, 2732 bool &MemberOfUnknownSpecialization); 2733 2734 TemplateNameKind isTemplateName(Scope *S, 2735 CXXScopeSpec &SS, 2736 bool hasTemplateKeyword, 2737 UnqualifiedId &Name, 2738 ParsedType ObjectType, 2739 bool EnteringContext, 2740 TemplateTy &Template, 2741 bool &MemberOfUnknownSpecialization); 2742 2743 bool DiagnoseUnknownTemplateName(const IdentifierInfo &II, 2744 SourceLocation IILoc, 2745 Scope *S, 2746 const CXXScopeSpec *SS, 2747 TemplateTy &SuggestedTemplate, 2748 TemplateNameKind &SuggestedKind); 2749 2750 bool DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl); 2751 TemplateDecl *AdjustDeclIfTemplate(Decl *&Decl); 2752 2753 Decl *ActOnTypeParameter(Scope *S, bool Typename, bool Ellipsis, 2754 SourceLocation EllipsisLoc, 2755 SourceLocation KeyLoc, 2756 IdentifierInfo *ParamName, 2757 SourceLocation ParamNameLoc, 2758 unsigned Depth, unsigned Position, 2759 SourceLocation EqualLoc, 2760 ParsedType DefaultArg); 2761 2762 QualType CheckNonTypeTemplateParameterType(QualType T, SourceLocation Loc); 2763 Decl *ActOnNonTypeTemplateParameter(Scope *S, Declarator &D, 2764 unsigned Depth, 2765 unsigned Position, 2766 SourceLocation EqualLoc, 2767 Expr *DefaultArg); 2768 Decl *ActOnTemplateTemplateParameter(Scope *S, 2769 SourceLocation TmpLoc, 2770 TemplateParamsTy *Params, 2771 IdentifierInfo *ParamName, 2772 SourceLocation ParamNameLoc, 2773 unsigned Depth, 2774 unsigned Position, 2775 SourceLocation EqualLoc, 2776 const ParsedTemplateArgument &DefaultArg); 2777 2778 TemplateParamsTy * 2779 ActOnTemplateParameterList(unsigned Depth, 2780 SourceLocation ExportLoc, 2781 SourceLocation TemplateLoc, 2782 SourceLocation LAngleLoc, 2783 Decl **Params, unsigned NumParams, 2784 SourceLocation RAngleLoc); 2785 2786 /// \brief The context in which we are checking a template parameter 2787 /// list. 2788 enum TemplateParamListContext { 2789 TPC_ClassTemplate, 2790 TPC_FunctionTemplate, 2791 TPC_ClassTemplateMember, 2792 TPC_FriendFunctionTemplate 2793 }; 2794 2795 bool CheckTemplateParameterList(TemplateParameterList *NewParams, 2796 TemplateParameterList *OldParams, 2797 TemplateParamListContext TPC); 2798 TemplateParameterList * 2799 MatchTemplateParametersToScopeSpecifier(SourceLocation DeclStartLoc, 2800 const CXXScopeSpec &SS, 2801 TemplateParameterList **ParamLists, 2802 unsigned NumParamLists, 2803 bool IsFriend, 2804 bool &IsExplicitSpecialization, 2805 bool &Invalid); 2806 2807 DeclResult CheckClassTemplate(Scope *S, unsigned TagSpec, TagUseKind TUK, 2808 SourceLocation KWLoc, CXXScopeSpec &SS, 2809 IdentifierInfo *Name, SourceLocation NameLoc, 2810 AttributeList *Attr, 2811 TemplateParameterList *TemplateParams, 2812 AccessSpecifier AS); 2813 2814 void translateTemplateArguments(const ASTTemplateArgsPtr &In, 2815 TemplateArgumentListInfo &Out); 2816 2817 QualType CheckTemplateIdType(TemplateName Template, 2818 SourceLocation TemplateLoc, 2819 const TemplateArgumentListInfo &TemplateArgs); 2820 2821 TypeResult 2822 ActOnTemplateIdType(TemplateTy Template, SourceLocation TemplateLoc, 2823 SourceLocation LAngleLoc, 2824 ASTTemplateArgsPtr TemplateArgs, 2825 SourceLocation RAngleLoc); 2826 2827 TypeResult ActOnTagTemplateIdType(TypeResult Type, 2828 TagUseKind TUK, 2829 TypeSpecifierType TagSpec, 2830 SourceLocation TagLoc); 2831 2832 ExprResult BuildTemplateIdExpr(const CXXScopeSpec &SS, 2833 LookupResult &R, 2834 bool RequiresADL, 2835 const TemplateArgumentListInfo &TemplateArgs); 2836 ExprResult BuildQualifiedTemplateIdExpr(CXXScopeSpec &SS, 2837 const DeclarationNameInfo &NameInfo, 2838 const TemplateArgumentListInfo &TemplateArgs); 2839 2840 TemplateNameKind ActOnDependentTemplateName(Scope *S, 2841 SourceLocation TemplateKWLoc, 2842 CXXScopeSpec &SS, 2843 UnqualifiedId &Name, 2844 ParsedType ObjectType, 2845 bool EnteringContext, 2846 TemplateTy &Template); 2847 2848 bool CheckClassTemplatePartialSpecializationArgs( 2849 TemplateParameterList *TemplateParams, 2850 const TemplateArgumentListBuilder &TemplateArgs, 2851 bool &MirrorsPrimaryTemplate); 2852 2853 DeclResult 2854 ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, TagUseKind TUK, 2855 SourceLocation KWLoc, 2856 CXXScopeSpec &SS, 2857 TemplateTy Template, 2858 SourceLocation TemplateNameLoc, 2859 SourceLocation LAngleLoc, 2860 ASTTemplateArgsPtr TemplateArgs, 2861 SourceLocation RAngleLoc, 2862 AttributeList *Attr, 2863 MultiTemplateParamsArg TemplateParameterLists); 2864 2865 Decl *ActOnTemplateDeclarator(Scope *S, 2866 MultiTemplateParamsArg TemplateParameterLists, 2867 Declarator &D); 2868 2869 Decl *ActOnStartOfFunctionTemplateDef(Scope *FnBodyScope, 2870 MultiTemplateParamsArg TemplateParameterLists, 2871 Declarator &D); 2872 2873 bool 2874 CheckSpecializationInstantiationRedecl(SourceLocation NewLoc, 2875 TemplateSpecializationKind NewTSK, 2876 NamedDecl *PrevDecl, 2877 TemplateSpecializationKind PrevTSK, 2878 SourceLocation PrevPtOfInstantiation, 2879 bool &SuppressNew); 2880 2881 bool CheckDependentFunctionTemplateSpecialization(FunctionDecl *FD, 2882 const TemplateArgumentListInfo &ExplicitTemplateArgs, 2883 LookupResult &Previous); 2884 2885 bool CheckFunctionTemplateSpecialization(FunctionDecl *FD, 2886 const TemplateArgumentListInfo *ExplicitTemplateArgs, 2887 LookupResult &Previous); 2888 bool CheckMemberSpecialization(NamedDecl *Member, LookupResult &Previous); 2889 2890 DeclResult 2891 ActOnExplicitInstantiation(Scope *S, 2892 SourceLocation ExternLoc, 2893 SourceLocation TemplateLoc, 2894 unsigned TagSpec, 2895 SourceLocation KWLoc, 2896 const CXXScopeSpec &SS, 2897 TemplateTy Template, 2898 SourceLocation TemplateNameLoc, 2899 SourceLocation LAngleLoc, 2900 ASTTemplateArgsPtr TemplateArgs, 2901 SourceLocation RAngleLoc, 2902 AttributeList *Attr); 2903 2904 DeclResult 2905 ActOnExplicitInstantiation(Scope *S, 2906 SourceLocation ExternLoc, 2907 SourceLocation TemplateLoc, 2908 unsigned TagSpec, 2909 SourceLocation KWLoc, 2910 CXXScopeSpec &SS, 2911 IdentifierInfo *Name, 2912 SourceLocation NameLoc, 2913 AttributeList *Attr); 2914 2915 DeclResult ActOnExplicitInstantiation(Scope *S, 2916 SourceLocation ExternLoc, 2917 SourceLocation TemplateLoc, 2918 Declarator &D); 2919 2920 TemplateArgumentLoc 2921 SubstDefaultTemplateArgumentIfAvailable(TemplateDecl *Template, 2922 SourceLocation TemplateLoc, 2923 SourceLocation RAngleLoc, 2924 Decl *Param, 2925 TemplateArgumentListBuilder &Converted); 2926 2927 /// \brief Specifies the context in which a particular template 2928 /// argument is being checked. 2929 enum CheckTemplateArgumentKind { 2930 /// \brief The template argument was specified in the code or was 2931 /// instantiated with some deduced template arguments. 2932 CTAK_Specified, 2933 2934 /// \brief The template argument was deduced via template argument 2935 /// deduction. 2936 CTAK_Deduced, 2937 2938 /// \brief The template argument was deduced from an array bound 2939 /// via template argument deduction. 2940 CTAK_DeducedFromArrayBound 2941 }; 2942 2943 bool CheckTemplateArgument(NamedDecl *Param, 2944 const TemplateArgumentLoc &Arg, 2945 TemplateDecl *Template, 2946 SourceLocation TemplateLoc, 2947 SourceLocation RAngleLoc, 2948 TemplateArgumentListBuilder &Converted, 2949 CheckTemplateArgumentKind CTAK = CTAK_Specified); 2950 2951 bool CheckTemplateArgumentList(TemplateDecl *Template, 2952 SourceLocation TemplateLoc, 2953 const TemplateArgumentListInfo &TemplateArgs, 2954 bool PartialTemplateArgs, 2955 TemplateArgumentListBuilder &Converted); 2956 2957 bool CheckTemplateTypeArgument(TemplateTypeParmDecl *Param, 2958 const TemplateArgumentLoc &Arg, 2959 TemplateArgumentListBuilder &Converted); 2960 2961 bool CheckTemplateArgument(TemplateTypeParmDecl *Param, 2962 TypeSourceInfo *Arg); 2963 bool CheckTemplateArgumentPointerToMember(Expr *Arg, 2964 TemplateArgument &Converted); 2965 bool CheckTemplateArgument(NonTypeTemplateParmDecl *Param, 2966 QualType InstantiatedParamType, Expr *&Arg, 2967 TemplateArgument &Converted, 2968 CheckTemplateArgumentKind CTAK = CTAK_Specified); 2969 bool CheckTemplateArgument(TemplateTemplateParmDecl *Param, 2970 const TemplateArgumentLoc &Arg); 2971 2972 ExprResult 2973 BuildExpressionFromDeclTemplateArgument(const TemplateArgument &Arg, 2974 QualType ParamType, 2975 SourceLocation Loc); 2976 ExprResult 2977 BuildExpressionFromIntegralTemplateArgument(const TemplateArgument &Arg, 2978 SourceLocation Loc); 2979 2980 /// \brief Enumeration describing how template parameter lists are compared 2981 /// for equality. 2982 enum TemplateParameterListEqualKind { 2983 /// \brief We are matching the template parameter lists of two templates 2984 /// that might be redeclarations. 2985 /// 2986 /// \code 2987 /// template<typename T> struct X; 2988 /// template<typename T> struct X; 2989 /// \endcode 2990 TPL_TemplateMatch, 2991 2992 /// \brief We are matching the template parameter lists of two template 2993 /// template parameters as part of matching the template parameter lists 2994 /// of two templates that might be redeclarations. 2995 /// 2996 /// \code 2997 /// template<template<int I> class TT> struct X; 2998 /// template<template<int Value> class Other> struct X; 2999 /// \endcode 3000 TPL_TemplateTemplateParmMatch, 3001 3002 /// \brief We are matching the template parameter lists of a template 3003 /// template argument against the template parameter lists of a template 3004 /// template parameter. 3005 /// 3006 /// \code 3007 /// template<template<int Value> class Metafun> struct X; 3008 /// template<int Value> struct integer_c; 3009 /// X<integer_c> xic; 3010 /// \endcode 3011 TPL_TemplateTemplateArgumentMatch 3012 }; 3013 3014 bool TemplateParameterListsAreEqual(TemplateParameterList *New, 3015 TemplateParameterList *Old, 3016 bool Complain, 3017 TemplateParameterListEqualKind Kind, 3018 SourceLocation TemplateArgLoc 3019 = SourceLocation()); 3020 3021 bool CheckTemplateDeclScope(Scope *S, TemplateParameterList *TemplateParams); 3022 3023 /// \brief Called when the parser has parsed a C++ typename 3024 /// specifier, e.g., "typename T::type". 3025 /// 3026 /// \param S The scope in which this typename type occurs. 3027 /// \param TypenameLoc the location of the 'typename' keyword 3028 /// \param SS the nested-name-specifier following the typename (e.g., 'T::'). 3029 /// \param II the identifier we're retrieving (e.g., 'type' in the example). 3030 /// \param IdLoc the location of the identifier. 3031 TypeResult 3032 ActOnTypenameType(Scope *S, SourceLocation TypenameLoc, 3033 const CXXScopeSpec &SS, const IdentifierInfo &II, 3034 SourceLocation IdLoc); 3035 3036 /// \brief Called when the parser has parsed a C++ typename 3037 /// specifier that ends in a template-id, e.g., 3038 /// "typename MetaFun::template apply<T1, T2>". 3039 /// 3040 /// \param S The scope in which this typename type occurs. 3041 /// \param TypenameLoc the location of the 'typename' keyword 3042 /// \param SS the nested-name-specifier following the typename (e.g., 'T::'). 3043 /// \param TemplateLoc the location of the 'template' keyword, if any. 3044 /// \param Ty the type that the typename specifier refers to. 3045 TypeResult 3046 ActOnTypenameType(Scope *S, SourceLocation TypenameLoc, 3047 const CXXScopeSpec &SS, SourceLocation TemplateLoc, 3048 ParsedType Ty); 3049 3050 QualType CheckTypenameType(ElaboratedTypeKeyword Keyword, 3051 NestedNameSpecifier *NNS, 3052 const IdentifierInfo &II, 3053 SourceLocation KeywordLoc, 3054 SourceRange NNSRange, 3055 SourceLocation IILoc); 3056 3057 TypeSourceInfo *RebuildTypeInCurrentInstantiation(TypeSourceInfo *T, 3058 SourceLocation Loc, 3059 DeclarationName Name); 3060 bool RebuildNestedNameSpecifierInCurrentInstantiation(CXXScopeSpec &SS); 3061 3062 ExprResult RebuildExprInCurrentInstantiation(Expr *E); 3063 3064 std::string 3065 getTemplateArgumentBindingsText(const TemplateParameterList *Params, 3066 const TemplateArgumentList &Args); 3067 3068 std::string 3069 getTemplateArgumentBindingsText(const TemplateParameterList *Params, 3070 const TemplateArgument *Args, 3071 unsigned NumArgs); 3072 3073 /// \brief Describes the result of template argument deduction. 3074 /// 3075 /// The TemplateDeductionResult enumeration describes the result of 3076 /// template argument deduction, as returned from 3077 /// DeduceTemplateArguments(). The separate TemplateDeductionInfo 3078 /// structure provides additional information about the results of 3079 /// template argument deduction, e.g., the deduced template argument 3080 /// list (if successful) or the specific template parameters or 3081 /// deduced arguments that were involved in the failure. 3082 enum TemplateDeductionResult { 3083 /// \brief Template argument deduction was successful. 3084 TDK_Success = 0, 3085 /// \brief Template argument deduction exceeded the maximum template 3086 /// instantiation depth (which has already been diagnosed). 3087 TDK_InstantiationDepth, 3088 /// \brief Template argument deduction did not deduce a value 3089 /// for every template parameter. 3090 TDK_Incomplete, 3091 /// \brief Template argument deduction produced inconsistent 3092 /// deduced values for the given template parameter. 3093 TDK_Inconsistent, 3094 /// \brief Template argument deduction failed due to inconsistent 3095 /// cv-qualifiers on a template parameter type that would 3096 /// otherwise be deduced, e.g., we tried to deduce T in "const T" 3097 /// but were given a non-const "X". 3098 TDK_Underqualified, 3099 /// \brief Substitution of the deduced template argument values 3100 /// resulted in an error. 3101 TDK_SubstitutionFailure, 3102 /// \brief Substitution of the deduced template argument values 3103 /// into a non-deduced context produced a type or value that 3104 /// produces a type that does not match the original template 3105 /// arguments provided. 3106 TDK_NonDeducedMismatch, 3107 /// \brief When performing template argument deduction for a function 3108 /// template, there were too many call arguments. 3109 TDK_TooManyArguments, 3110 /// \brief When performing template argument deduction for a function 3111 /// template, there were too few call arguments. 3112 TDK_TooFewArguments, 3113 /// \brief The explicitly-specified template arguments were not valid 3114 /// template arguments for the given template. 3115 TDK_InvalidExplicitArguments, 3116 /// \brief The arguments included an overloaded function name that could 3117 /// not be resolved to a suitable function. 3118 TDK_FailedOverloadResolution 3119 }; 3120 3121 TemplateDeductionResult 3122 DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial, 3123 const TemplateArgumentList &TemplateArgs, 3124 sema::TemplateDeductionInfo &Info); 3125 3126 TemplateDeductionResult 3127 SubstituteExplicitTemplateArguments(FunctionTemplateDecl *FunctionTemplate, 3128 const TemplateArgumentListInfo &ExplicitTemplateArgs, 3129 llvm::SmallVectorImpl<DeducedTemplateArgument> &Deduced, 3130 llvm::SmallVectorImpl<QualType> &ParamTypes, 3131 QualType *FunctionType, 3132 sema::TemplateDeductionInfo &Info); 3133 3134 TemplateDeductionResult 3135 FinishTemplateArgumentDeduction(FunctionTemplateDecl *FunctionTemplate, 3136 llvm::SmallVectorImpl<DeducedTemplateArgument> &Deduced, 3137 unsigned NumExplicitlySpecified, 3138 FunctionDecl *&Specialization, 3139 sema::TemplateDeductionInfo &Info); 3140 3141 TemplateDeductionResult 3142 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, 3143 const TemplateArgumentListInfo *ExplicitTemplateArgs, 3144 Expr **Args, unsigned NumArgs, 3145 FunctionDecl *&Specialization, 3146 sema::TemplateDeductionInfo &Info); 3147 3148 TemplateDeductionResult 3149 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, 3150 const TemplateArgumentListInfo *ExplicitTemplateArgs, 3151 QualType ArgFunctionType, 3152 FunctionDecl *&Specialization, 3153 sema::TemplateDeductionInfo &Info); 3154 3155 TemplateDeductionResult 3156 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, 3157 QualType ToType, 3158 CXXConversionDecl *&Specialization, 3159 sema::TemplateDeductionInfo &Info); 3160 3161 TemplateDeductionResult 3162 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, 3163 const TemplateArgumentListInfo *ExplicitTemplateArgs, 3164 FunctionDecl *&Specialization, 3165 sema::TemplateDeductionInfo &Info); 3166 3167 FunctionTemplateDecl *getMoreSpecializedTemplate(FunctionTemplateDecl *FT1, 3168 FunctionTemplateDecl *FT2, 3169 SourceLocation Loc, 3170 TemplatePartialOrderingContext TPOC); 3171 UnresolvedSetIterator getMostSpecialized(UnresolvedSetIterator SBegin, 3172 UnresolvedSetIterator SEnd, 3173 TemplatePartialOrderingContext TPOC, 3174 SourceLocation Loc, 3175 const PartialDiagnostic &NoneDiag, 3176 const PartialDiagnostic &AmbigDiag, 3177 const PartialDiagnostic &CandidateDiag); 3178 3179 ClassTemplatePartialSpecializationDecl * 3180 getMoreSpecializedPartialSpecialization( 3181 ClassTemplatePartialSpecializationDecl *PS1, 3182 ClassTemplatePartialSpecializationDecl *PS2, 3183 SourceLocation Loc); 3184 3185 void MarkUsedTemplateParameters(const TemplateArgumentList &TemplateArgs, 3186 bool OnlyDeduced, 3187 unsigned Depth, 3188 llvm::SmallVectorImpl<bool> &Used); 3189 void MarkDeducedTemplateParameters(FunctionTemplateDecl *FunctionTemplate, 3190 llvm::SmallVectorImpl<bool> &Deduced); 3191 3192 //===--------------------------------------------------------------------===// 3193 // C++ Template Instantiation 3194 // 3195 3196 MultiLevelTemplateArgumentList getTemplateInstantiationArgs(NamedDecl *D, 3197 const TemplateArgumentList *Innermost = 0, 3198 bool RelativeToPrimary = false, 3199 const FunctionDecl *Pattern = 0); 3200 3201 /// \brief A template instantiation that is currently in progress. 3202 struct ActiveTemplateInstantiation { 3203 /// \brief The kind of template instantiation we are performing 3204 enum InstantiationKind { 3205 /// We are instantiating a template declaration. The entity is 3206 /// the declaration we're instantiating (e.g., a CXXRecordDecl). 3207 TemplateInstantiation, 3208 3209 /// We are instantiating a default argument for a template 3210 /// parameter. The Entity is the template, and 3211 /// TemplateArgs/NumTemplateArguments provides the template 3212 /// arguments as specified. 3213 /// FIXME: Use a TemplateArgumentList 3214 DefaultTemplateArgumentInstantiation, 3215 3216 /// We are instantiating a default argument for a function. 3217 /// The Entity is the ParmVarDecl, and TemplateArgs/NumTemplateArgs 3218 /// provides the template arguments as specified. 3219 DefaultFunctionArgumentInstantiation, 3220 3221 /// We are substituting explicit template arguments provided for 3222 /// a function template. The entity is a FunctionTemplateDecl. 3223 ExplicitTemplateArgumentSubstitution, 3224 3225 /// We are substituting template argument determined as part of 3226 /// template argument deduction for either a class template 3227 /// partial specialization or a function template. The 3228 /// Entity is either a ClassTemplatePartialSpecializationDecl or 3229 /// a FunctionTemplateDecl. 3230 DeducedTemplateArgumentSubstitution, 3231 3232 /// We are substituting prior template arguments into a new 3233 /// template parameter. The template parameter itself is either a 3234 /// NonTypeTemplateParmDecl or a TemplateTemplateParmDecl. 3235 PriorTemplateArgumentSubstitution, 3236 3237 /// We are checking the validity of a default template argument that 3238 /// has been used when naming a template-id. 3239 DefaultTemplateArgumentChecking 3240 } Kind; 3241 3242 /// \brief The point of instantiation within the source code. 3243 SourceLocation PointOfInstantiation; 3244 3245 /// \brief The template in which we are performing the instantiation, 3246 /// for substitutions of prior template arguments. 3247 TemplateDecl *Template; 3248 3249 /// \brief The entity that is being instantiated. 3250 uintptr_t Entity; 3251 3252 /// \brief The list of template arguments we are substituting, if they 3253 /// are not part of the entity. 3254 const TemplateArgument *TemplateArgs; 3255 3256 /// \brief The number of template arguments in TemplateArgs. 3257 unsigned NumTemplateArgs; 3258 3259 /// \brief The source range that covers the construct that cause 3260 /// the instantiation, e.g., the template-id that causes a class 3261 /// template instantiation. 3262 SourceRange InstantiationRange; 3263 3264 ActiveTemplateInstantiation() 3265 : Kind(TemplateInstantiation), Template(0), Entity(0), TemplateArgs(0), 3266 NumTemplateArgs(0) {} 3267 3268 /// \brief Determines whether this template is an actual instantiation 3269 /// that should be counted toward the maximum instantiation depth. 3270 bool isInstantiationRecord() const; 3271 3272 friend bool operator==(const ActiveTemplateInstantiation &X, 3273 const ActiveTemplateInstantiation &Y) { 3274 if (X.Kind != Y.Kind) 3275 return false; 3276 3277 if (X.Entity != Y.Entity) 3278 return false; 3279 3280 switch (X.Kind) { 3281 case TemplateInstantiation: 3282 return true; 3283 3284 case PriorTemplateArgumentSubstitution: 3285 case DefaultTemplateArgumentChecking: 3286 if (X.Template != Y.Template) 3287 return false; 3288 3289 // Fall through 3290 3291 case DefaultTemplateArgumentInstantiation: 3292 case ExplicitTemplateArgumentSubstitution: 3293 case DeducedTemplateArgumentSubstitution: 3294 case DefaultFunctionArgumentInstantiation: 3295 return X.TemplateArgs == Y.TemplateArgs; 3296 3297 } 3298 3299 return true; 3300 } 3301 3302 friend bool operator!=(const ActiveTemplateInstantiation &X, 3303 const ActiveTemplateInstantiation &Y) { 3304 return !(X == Y); 3305 } 3306 }; 3307 3308 /// \brief List of active template instantiations. 3309 /// 3310 /// This vector is treated as a stack. As one template instantiation 3311 /// requires another template instantiation, additional 3312 /// instantiations are pushed onto the stack up to a 3313 /// user-configurable limit LangOptions::InstantiationDepth. 3314 llvm::SmallVector<ActiveTemplateInstantiation, 16> 3315 ActiveTemplateInstantiations; 3316 3317 /// \brief The number of ActiveTemplateInstantiation entries in 3318 /// \c ActiveTemplateInstantiations that are not actual instantiations and, 3319 /// therefore, should not be counted as part of the instantiation depth. 3320 unsigned NonInstantiationEntries; 3321 3322 /// \brief The last template from which a template instantiation 3323 /// error or warning was produced. 3324 /// 3325 /// This value is used to suppress printing of redundant template 3326 /// instantiation backtraces when there are multiple errors in the 3327 /// same instantiation. FIXME: Does this belong in Sema? It's tough 3328 /// to implement it anywhere else. 3329 ActiveTemplateInstantiation LastTemplateInstantiationErrorContext; 3330 3331 /// \brief The stack of calls expression undergoing template instantiation. 3332 /// 3333 /// The top of this stack is used by a fixit instantiating unresolved 3334 /// function calls to fix the AST to match the textual change it prints. 3335 llvm::SmallVector<CallExpr *, 8> CallsUndergoingInstantiation; 3336 3337 /// \brief A stack object to be created when performing template 3338 /// instantiation. 3339 /// 3340 /// Construction of an object of type \c InstantiatingTemplate 3341 /// pushes the current instantiation onto the stack of active 3342 /// instantiations. If the size of this stack exceeds the maximum 3343 /// number of recursive template instantiations, construction 3344 /// produces an error and evaluates true. 3345 /// 3346 /// Destruction of this object will pop the named instantiation off 3347 /// the stack. 3348 struct InstantiatingTemplate { 3349 /// \brief Note that we are instantiating a class template, 3350 /// function template, or a member thereof. 3351 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 3352 Decl *Entity, 3353 SourceRange InstantiationRange = SourceRange()); 3354 3355 /// \brief Note that we are instantiating a default argument in a 3356 /// template-id. 3357 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 3358 TemplateDecl *Template, 3359 const TemplateArgument *TemplateArgs, 3360 unsigned NumTemplateArgs, 3361 SourceRange InstantiationRange = SourceRange()); 3362 3363 /// \brief Note that we are instantiating a default argument in a 3364 /// template-id. 3365 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 3366 FunctionTemplateDecl *FunctionTemplate, 3367 const TemplateArgument *TemplateArgs, 3368 unsigned NumTemplateArgs, 3369 ActiveTemplateInstantiation::InstantiationKind Kind, 3370 SourceRange InstantiationRange = SourceRange()); 3371 3372 /// \brief Note that we are instantiating as part of template 3373 /// argument deduction for a class template partial 3374 /// specialization. 3375 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 3376 ClassTemplatePartialSpecializationDecl *PartialSpec, 3377 const TemplateArgument *TemplateArgs, 3378 unsigned NumTemplateArgs, 3379 SourceRange InstantiationRange = SourceRange()); 3380 3381 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 3382 ParmVarDecl *Param, 3383 const TemplateArgument *TemplateArgs, 3384 unsigned NumTemplateArgs, 3385 SourceRange InstantiationRange = SourceRange()); 3386 3387 /// \brief Note that we are substituting prior template arguments into a 3388 /// non-type or template template parameter. 3389 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 3390 TemplateDecl *Template, 3391 NonTypeTemplateParmDecl *Param, 3392 const TemplateArgument *TemplateArgs, 3393 unsigned NumTemplateArgs, 3394 SourceRange InstantiationRange); 3395 3396 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 3397 TemplateDecl *Template, 3398 TemplateTemplateParmDecl *Param, 3399 const TemplateArgument *TemplateArgs, 3400 unsigned NumTemplateArgs, 3401 SourceRange InstantiationRange); 3402 3403 /// \brief Note that we are checking the default template argument 3404 /// against the template parameter for a given template-id. 3405 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, 3406 TemplateDecl *Template, 3407 NamedDecl *Param, 3408 const TemplateArgument *TemplateArgs, 3409 unsigned NumTemplateArgs, 3410 SourceRange InstantiationRange); 3411 3412 3413 /// \brief Note that we have finished instantiating this template. 3414 void Clear(); 3415 3416 ~InstantiatingTemplate() { Clear(); } 3417 3418 /// \brief Determines whether we have exceeded the maximum 3419 /// recursive template instantiations. 3420 operator bool() const { return Invalid; } 3421 3422 private: 3423 Sema &SemaRef; 3424 bool Invalid; 3425 3426 bool CheckInstantiationDepth(SourceLocation PointOfInstantiation, 3427 SourceRange InstantiationRange); 3428 3429 InstantiatingTemplate(const InstantiatingTemplate&); // not implemented 3430 3431 InstantiatingTemplate& 3432 operator=(const InstantiatingTemplate&); // not implemented 3433 }; 3434 3435 void PrintInstantiationStack(); 3436 3437 /// \brief Determines whether we are currently in a context where 3438 /// template argument substitution failures are not considered 3439 /// errors. 3440 /// 3441 /// When this routine returns true, the emission of most diagnostics 3442 /// will be suppressed and there will be no local error recovery. 3443 bool isSFINAEContext() const; 3444 3445 /// \brief RAII class used to determine whether SFINAE has 3446 /// trapped any errors that occur during template argument 3447 /// deduction. 3448 class SFINAETrap { 3449 Sema &SemaRef; 3450 unsigned PrevSFINAEErrors; 3451 public: 3452 explicit SFINAETrap(Sema &SemaRef) 3453 : SemaRef(SemaRef), PrevSFINAEErrors(SemaRef.NumSFINAEErrors) { } 3454 3455 ~SFINAETrap() { SemaRef.NumSFINAEErrors = PrevSFINAEErrors; } 3456 3457 /// \brief Determine whether any SFINAE errors have been trapped. 3458 bool hasErrorOccurred() const { 3459 return SemaRef.NumSFINAEErrors > PrevSFINAEErrors; 3460 } 3461 }; 3462 3463 /// \brief RAII class that determines when any errors have occurred 3464 /// between the time the instance was created and the time it was 3465 /// queried. 3466 class ErrorTrap { 3467 Sema &SemaRef; 3468 unsigned PrevErrors; 3469 3470 public: 3471 explicit ErrorTrap(Sema &SemaRef) 3472 : SemaRef(SemaRef), PrevErrors(SemaRef.getDiagnostics().getNumErrors()) {} 3473 3474 /// \brief Determine whether any errors have occurred since this 3475 /// object instance was created. 3476 bool hasErrorOccurred() const { 3477 return SemaRef.getDiagnostics().getNumErrors() > PrevErrors; 3478 } 3479 }; 3480 3481 /// \brief The current instantiation scope used to store local 3482 /// variables. 3483 LocalInstantiationScope *CurrentInstantiationScope; 3484 3485 /// \brief The number of typos corrected by CorrectTypo. 3486 unsigned TyposCorrected; 3487 3488 /// \brief Worker object for performing CFG-based warnings. 3489 sema::AnalysisBasedWarnings AnalysisWarnings; 3490 3491 /// \brief An entity for which implicit template instantiation is required. 3492 /// 3493 /// The source location associated with the declaration is the first place in 3494 /// the source code where the declaration was "used". It is not necessarily 3495 /// the point of instantiation (which will be either before or after the 3496 /// namespace-scope declaration that triggered this implicit instantiation), 3497 /// However, it is the location that diagnostics should generally refer to, 3498 /// because users will need to know what code triggered the instantiation. 3499 typedef std::pair<ValueDecl *, SourceLocation> PendingImplicitInstantiation; 3500 3501 /// \brief The queue of implicit template instantiations that are required 3502 /// but have not yet been performed. 3503 std::deque<PendingImplicitInstantiation> PendingInstantiations; 3504 3505 /// \brief The queue of implicit template instantiations that are required 3506 /// and must be performed within the current local scope. 3507 /// 3508 /// This queue is only used for member functions of local classes in 3509 /// templates, which must be instantiated in the same scope as their 3510 /// enclosing function, so that they can reference function-local 3511 /// types, static variables, enumerators, etc. 3512 std::deque<PendingImplicitInstantiation> PendingLocalImplicitInstantiations; 3513 3514 void PerformPendingInstantiations(bool LocalOnly = false); 3515 3516 TypeSourceInfo *SubstType(TypeSourceInfo *T, 3517 const MultiLevelTemplateArgumentList &TemplateArgs, 3518 SourceLocation Loc, DeclarationName Entity); 3519 3520 QualType SubstType(QualType T, 3521 const MultiLevelTemplateArgumentList &TemplateArgs, 3522 SourceLocation Loc, DeclarationName Entity); 3523 3524 TypeSourceInfo *SubstFunctionDeclType(TypeSourceInfo *T, 3525 const MultiLevelTemplateArgumentList &TemplateArgs, 3526 SourceLocation Loc, 3527 DeclarationName Entity); 3528 ParmVarDecl *SubstParmVarDecl(ParmVarDecl *D, 3529 const MultiLevelTemplateArgumentList &TemplateArgs); 3530 ExprResult SubstExpr(Expr *E, 3531 const MultiLevelTemplateArgumentList &TemplateArgs); 3532 3533 StmtResult SubstStmt(Stmt *S, 3534 const MultiLevelTemplateArgumentList &TemplateArgs); 3535 3536 Decl *SubstDecl(Decl *D, DeclContext *Owner, 3537 const MultiLevelTemplateArgumentList &TemplateArgs); 3538 3539 bool 3540 SubstBaseSpecifiers(CXXRecordDecl *Instantiation, 3541 CXXRecordDecl *Pattern, 3542 const MultiLevelTemplateArgumentList &TemplateArgs); 3543 3544 bool 3545 InstantiateClass(SourceLocation PointOfInstantiation, 3546 CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern, 3547 const MultiLevelTemplateArgumentList &TemplateArgs, 3548 TemplateSpecializationKind TSK, 3549 bool Complain = true); 3550 3551 void InstantiateAttrs(const MultiLevelTemplateArgumentList &TemplateArgs, 3552 Decl *Pattern, Decl *Inst); 3553 3554 bool 3555 InstantiateClassTemplateSpecialization(SourceLocation PointOfInstantiation, 3556 ClassTemplateSpecializationDecl *ClassTemplateSpec, 3557 TemplateSpecializationKind TSK, 3558 bool Complain = true); 3559 3560 void InstantiateClassMembers(SourceLocation PointOfInstantiation, 3561 CXXRecordDecl *Instantiation, 3562 const MultiLevelTemplateArgumentList &TemplateArgs, 3563 TemplateSpecializationKind TSK); 3564 3565 void InstantiateClassTemplateSpecializationMembers( 3566 SourceLocation PointOfInstantiation, 3567 ClassTemplateSpecializationDecl *ClassTemplateSpec, 3568 TemplateSpecializationKind TSK); 3569 3570 NestedNameSpecifier * 3571 SubstNestedNameSpecifier(NestedNameSpecifier *NNS, 3572 SourceRange Range, 3573 const MultiLevelTemplateArgumentList &TemplateArgs); 3574 DeclarationNameInfo 3575 SubstDeclarationNameInfo(const DeclarationNameInfo &NameInfo, 3576 const MultiLevelTemplateArgumentList &TemplateArgs); 3577 TemplateName 3578 SubstTemplateName(TemplateName Name, SourceLocation Loc, 3579 const MultiLevelTemplateArgumentList &TemplateArgs); 3580 bool Subst(const TemplateArgumentLoc &Arg, TemplateArgumentLoc &Result, 3581 const MultiLevelTemplateArgumentList &TemplateArgs); 3582 3583 void InstantiateFunctionDefinition(SourceLocation PointOfInstantiation, 3584 FunctionDecl *Function, 3585 bool Recursive = false, 3586 bool DefinitionRequired = false); 3587 void InstantiateStaticDataMemberDefinition( 3588 SourceLocation PointOfInstantiation, 3589 VarDecl *Var, 3590 bool Recursive = false, 3591 bool DefinitionRequired = false); 3592 3593 void InstantiateMemInitializers(CXXConstructorDecl *New, 3594 const CXXConstructorDecl *Tmpl, 3595 const MultiLevelTemplateArgumentList &TemplateArgs); 3596 3597 NamedDecl *FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D, 3598 const MultiLevelTemplateArgumentList &TemplateArgs); 3599 DeclContext *FindInstantiatedContext(SourceLocation Loc, DeclContext *DC, 3600 const MultiLevelTemplateArgumentList &TemplateArgs); 3601 3602 // Objective-C declarations. 3603 Decl *ActOnStartClassInterface(SourceLocation AtInterfaceLoc, 3604 IdentifierInfo *ClassName, 3605 SourceLocation ClassLoc, 3606 IdentifierInfo *SuperName, 3607 SourceLocation SuperLoc, 3608 Decl * const *ProtoRefs, 3609 unsigned NumProtoRefs, 3610 const SourceLocation *ProtoLocs, 3611 SourceLocation EndProtoLoc, 3612 AttributeList *AttrList); 3613 3614 Decl *ActOnCompatiblityAlias( 3615 SourceLocation AtCompatibilityAliasLoc, 3616 IdentifierInfo *AliasName, SourceLocation AliasLocation, 3617 IdentifierInfo *ClassName, SourceLocation ClassLocation); 3618 3619 void CheckForwardProtocolDeclarationForCircularDependency( 3620 IdentifierInfo *PName, 3621 SourceLocation &PLoc, SourceLocation PrevLoc, 3622 const ObjCList<ObjCProtocolDecl> &PList); 3623 3624 Decl *ActOnStartProtocolInterface( 3625 SourceLocation AtProtoInterfaceLoc, 3626 IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc, 3627 Decl * const *ProtoRefNames, unsigned NumProtoRefs, 3628 const SourceLocation *ProtoLocs, 3629 SourceLocation EndProtoLoc, 3630 AttributeList *AttrList); 3631 3632 Decl *ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc, 3633 IdentifierInfo *ClassName, 3634 SourceLocation ClassLoc, 3635 IdentifierInfo *CategoryName, 3636 SourceLocation CategoryLoc, 3637 Decl * const *ProtoRefs, 3638 unsigned NumProtoRefs, 3639 const SourceLocation *ProtoLocs, 3640 SourceLocation EndProtoLoc); 3641 3642 Decl *ActOnStartClassImplementation( 3643 SourceLocation AtClassImplLoc, 3644 IdentifierInfo *ClassName, SourceLocation ClassLoc, 3645 IdentifierInfo *SuperClassname, 3646 SourceLocation SuperClassLoc); 3647 3648 Decl *ActOnStartCategoryImplementation(SourceLocation AtCatImplLoc, 3649 IdentifierInfo *ClassName, 3650 SourceLocation ClassLoc, 3651 IdentifierInfo *CatName, 3652 SourceLocation CatLoc); 3653 3654 Decl *ActOnForwardClassDeclaration(SourceLocation Loc, 3655 IdentifierInfo **IdentList, 3656 SourceLocation *IdentLocs, 3657 unsigned NumElts); 3658 3659 Decl *ActOnForwardProtocolDeclaration(SourceLocation AtProtoclLoc, 3660 const IdentifierLocPair *IdentList, 3661 unsigned NumElts, 3662 AttributeList *attrList); 3663 3664 void FindProtocolDeclaration(bool WarnOnDeclarations, 3665 const IdentifierLocPair *ProtocolId, 3666 unsigned NumProtocols, 3667 llvm::SmallVectorImpl<Decl *> &Protocols); 3668 3669 /// Ensure attributes are consistent with type. 3670 /// \param [in, out] Attributes The attributes to check; they will 3671 /// be modified to be consistent with \arg PropertyTy. 3672 void CheckObjCPropertyAttributes(Decl *PropertyPtrTy, 3673 SourceLocation Loc, 3674 unsigned &Attributes); 3675 void ProcessPropertyDecl(ObjCPropertyDecl *property, ObjCContainerDecl *DC); 3676 void DiagnosePropertyMismatch(ObjCPropertyDecl *Property, 3677 ObjCPropertyDecl *SuperProperty, 3678 const IdentifierInfo *Name); 3679 void ComparePropertiesInBaseAndSuper(ObjCInterfaceDecl *IDecl); 3680 3681 void CompareMethodParamsInBaseAndSuper(Decl *IDecl, 3682 ObjCMethodDecl *MethodDecl, 3683 bool IsInstance); 3684 3685 void CompareProperties(Decl *CDecl, Decl *MergeProtocols); 3686 3687 void DiagnoseClassExtensionDupMethods(ObjCCategoryDecl *CAT, 3688 ObjCInterfaceDecl *ID); 3689 3690 void MatchOneProtocolPropertiesInClass(Decl *CDecl, 3691 ObjCProtocolDecl *PDecl); 3692 3693 void ActOnAtEnd(Scope *S, SourceRange AtEnd, Decl *classDecl, 3694 Decl **allMethods = 0, unsigned allNum = 0, 3695 Decl **allProperties = 0, unsigned pNum = 0, 3696 DeclGroupPtrTy *allTUVars = 0, unsigned tuvNum = 0); 3697 3698 Decl *ActOnProperty(Scope *S, SourceLocation AtLoc, 3699 FieldDeclarator &FD, ObjCDeclSpec &ODS, 3700 Selector GetterSel, Selector SetterSel, 3701 Decl *ClassCategory, 3702 bool *OverridingProperty, 3703 tok::ObjCKeywordKind MethodImplKind); 3704 3705 Decl *ActOnPropertyImplDecl(Scope *S, 3706 SourceLocation AtLoc, 3707 SourceLocation PropertyLoc, 3708 bool ImplKind,Decl *ClassImplDecl, 3709 IdentifierInfo *PropertyId, 3710 IdentifierInfo *PropertyIvar); 3711 3712 struct ObjCArgInfo { 3713 IdentifierInfo *Name; 3714 SourceLocation NameLoc; 3715 // The Type is null if no type was specified, and the DeclSpec is invalid 3716 // in this case. 3717 ParsedType Type; 3718 ObjCDeclSpec DeclSpec; 3719 3720 /// ArgAttrs - Attribute list for this argument. 3721 AttributeList *ArgAttrs; 3722 }; 3723 3724 Decl *ActOnMethodDeclaration( 3725 SourceLocation BeginLoc, // location of the + or -. 3726 SourceLocation EndLoc, // location of the ; or {. 3727 tok::TokenKind MethodType, 3728 Decl *ClassDecl, ObjCDeclSpec &ReturnQT, ParsedType ReturnType, 3729 Selector Sel, 3730 // optional arguments. The number of types/arguments is obtained 3731 // from the Sel.getNumArgs(). 3732 ObjCArgInfo *ArgInfo, 3733 DeclaratorChunk::ParamInfo *CParamInfo, unsigned CNumArgs, // c-style args 3734 AttributeList *AttrList, tok::ObjCKeywordKind MethodImplKind, 3735 bool isVariadic = false); 3736 3737 // Helper method for ActOnClassMethod/ActOnInstanceMethod. 3738 // Will search "local" class/category implementations for a method decl. 3739 // Will also search in class's root looking for instance method. 3740 // Returns 0 if no method is found. 3741 ObjCMethodDecl *LookupPrivateClassMethod(Selector Sel, 3742 ObjCInterfaceDecl *CDecl); 3743 ObjCMethodDecl *LookupPrivateInstanceMethod(Selector Sel, 3744 ObjCInterfaceDecl *ClassDecl); 3745 3746 ExprResult 3747 HandleExprPropertyRefExpr(const ObjCObjectPointerType *OPT, 3748 Expr *BaseExpr, 3749 DeclarationName MemberName, 3750 SourceLocation MemberLoc); 3751 3752 ExprResult 3753 ActOnClassPropertyRefExpr(IdentifierInfo &receiverName, 3754 IdentifierInfo &propertyName, 3755 SourceLocation receiverNameLoc, 3756 SourceLocation propertyNameLoc); 3757 3758 /// \brief Describes the kind of message expression indicated by a message 3759 /// send that starts with an identifier. 3760 enum ObjCMessageKind { 3761 /// \brief The message is sent to 'super'. 3762 ObjCSuperMessage, 3763 /// \brief The message is an instance message. 3764 ObjCInstanceMessage, 3765 /// \brief The message is a class message, and the identifier is a type 3766 /// name. 3767 ObjCClassMessage 3768 }; 3769 3770 ObjCMessageKind getObjCMessageKind(Scope *S, 3771 IdentifierInfo *Name, 3772 SourceLocation NameLoc, 3773 bool IsSuper, 3774 bool HasTrailingDot, 3775 ParsedType &ReceiverType); 3776 3777 ExprResult ActOnSuperMessage(Scope *S, SourceLocation SuperLoc, 3778 Selector Sel, 3779 SourceLocation LBracLoc, 3780 SourceLocation SelectorLoc, 3781 SourceLocation RBracLoc, 3782 MultiExprArg Args); 3783 3784 ExprResult BuildClassMessage(TypeSourceInfo *ReceiverTypeInfo, 3785 QualType ReceiverType, 3786 SourceLocation SuperLoc, 3787 Selector Sel, 3788 ObjCMethodDecl *Method, 3789 SourceLocation LBracLoc, 3790 SourceLocation RBracLoc, 3791 MultiExprArg Args); 3792 3793 ExprResult ActOnClassMessage(Scope *S, 3794 ParsedType Receiver, 3795 Selector Sel, 3796 SourceLocation LBracLoc, 3797 SourceLocation SelectorLoc, 3798 SourceLocation RBracLoc, 3799 MultiExprArg Args); 3800 3801 ExprResult BuildInstanceMessage(Expr *Receiver, 3802 QualType ReceiverType, 3803 SourceLocation SuperLoc, 3804 Selector Sel, 3805 ObjCMethodDecl *Method, 3806 SourceLocation LBracLoc, 3807 SourceLocation RBracLoc, 3808 MultiExprArg Args); 3809 3810 ExprResult ActOnInstanceMessage(Scope *S, 3811 Expr *Receiver, 3812 Selector Sel, 3813 SourceLocation LBracLoc, 3814 SourceLocation SelectorLoc, 3815 SourceLocation RBracLoc, 3816 MultiExprArg Args); 3817 3818 3819 enum PragmaOptionsAlignKind { 3820 POAK_Native, // #pragma options align=native 3821 POAK_Natural, // #pragma options align=natural 3822 POAK_Packed, // #pragma options align=packed 3823 POAK_Power, // #pragma options align=power 3824 POAK_Mac68k, // #pragma options align=mac68k 3825 POAK_Reset // #pragma options align=reset 3826 }; 3827 3828 /// ActOnPragmaOptionsAlign - Called on well formed #pragma options align. 3829 void ActOnPragmaOptionsAlign(PragmaOptionsAlignKind Kind, 3830 SourceLocation PragmaLoc, 3831 SourceLocation KindLoc); 3832 3833 enum PragmaPackKind { 3834 PPK_Default, // #pragma pack([n]) 3835 PPK_Show, // #pragma pack(show), only supported by MSVC. 3836 PPK_Push, // #pragma pack(push, [identifier], [n]) 3837 PPK_Pop // #pragma pack(pop, [identifier], [n]) 3838 }; 3839 3840 /// ActOnPragmaPack - Called on well formed #pragma pack(...). 3841 void ActOnPragmaPack(PragmaPackKind Kind, 3842 IdentifierInfo *Name, 3843 Expr *Alignment, 3844 SourceLocation PragmaLoc, 3845 SourceLocation LParenLoc, 3846 SourceLocation RParenLoc); 3847 3848 /// ActOnPragmaUnused - Called on well-formed '#pragma unused'. 3849 void ActOnPragmaUnused(const Token *Identifiers, 3850 unsigned NumIdentifiers, Scope *curScope, 3851 SourceLocation PragmaLoc, 3852 SourceLocation LParenLoc, 3853 SourceLocation RParenLoc); 3854 3855 /// ActOnPragmaVisibility - Called on well formed #pragma GCC visibility... . 3856 void ActOnPragmaVisibility(bool IsPush, const IdentifierInfo* VisType, 3857 SourceLocation PragmaLoc); 3858 3859 NamedDecl *DeclClonePragmaWeak(NamedDecl *ND, IdentifierInfo *II); 3860 void DeclApplyPragmaWeak(Scope *S, NamedDecl *ND, WeakInfo &W); 3861 3862 /// ActOnPragmaWeakID - Called on well formed #pragma weak ident. 3863 void ActOnPragmaWeakID(IdentifierInfo* WeakName, 3864 SourceLocation PragmaLoc, 3865 SourceLocation WeakNameLoc); 3866 3867 /// ActOnPragmaWeakAlias - Called on well formed #pragma weak ident = ident. 3868 void ActOnPragmaWeakAlias(IdentifierInfo* WeakName, 3869 IdentifierInfo* AliasName, 3870 SourceLocation PragmaLoc, 3871 SourceLocation WeakNameLoc, 3872 SourceLocation AliasNameLoc); 3873 3874 /// AddAlignmentAttributesForRecord - Adds any needed alignment attributes to 3875 /// a the record decl, to handle '#pragma pack' and '#pragma options align'. 3876 void AddAlignmentAttributesForRecord(RecordDecl *RD); 3877 3878 /// FreePackedContext - Deallocate and null out PackContext. 3879 void FreePackedContext(); 3880 3881 /// PushVisibilityAttr - Note that we've entered a context with a 3882 /// visibility attribute. 3883 void PushVisibilityAttr(const VisibilityAttr *Attr); 3884 3885 /// AddPushedVisibilityAttribute - If '#pragma GCC visibility' was used, 3886 /// add an appropriate visibility attribute. 3887 void AddPushedVisibilityAttribute(Decl *RD); 3888 3889 /// PopPragmaVisibility - Pop the top element of the visibility stack; used 3890 /// for '#pragma GCC visibility' and visibility attributes on namespaces. 3891 void PopPragmaVisibility(); 3892 3893 /// FreeVisContext - Deallocate and null out VisContext. 3894 void FreeVisContext(); 3895 3896 /// AddAlignedAttr - Adds an aligned attribute to a particular declaration. 3897 void AddAlignedAttr(SourceLocation AttrLoc, Decl *D, Expr *E); 3898 void AddAlignedAttr(SourceLocation AttrLoc, Decl *D, TypeSourceInfo *T); 3899 3900 /// CastCategory - Get the correct forwarded implicit cast result category 3901 /// from the inner expression. 3902 ExprValueKind CastCategory(Expr *E); 3903 3904 /// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit 3905 /// cast. If there is already an implicit cast, merge into the existing one. 3906 /// If isLvalue, the result of the cast is an lvalue. 3907 void ImpCastExprToType(Expr *&Expr, QualType Type, CastKind CK, 3908 ExprValueKind VK = VK_RValue, 3909 const CXXCastPath *BasePath = 0); 3910 3911 // UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts 3912 // functions and arrays to their respective pointers (C99 6.3.2.1). 3913 Expr *UsualUnaryConversions(Expr *&expr); 3914 3915 // DefaultFunctionArrayConversion - converts functions and arrays 3916 // to their respective pointers (C99 6.3.2.1). 3917 void DefaultFunctionArrayConversion(Expr *&expr); 3918 3919 // DefaultFunctionArrayLvalueConversion - converts functions and 3920 // arrays to their respective pointers and performs the 3921 // lvalue-to-rvalue conversion. 3922 void DefaultFunctionArrayLvalueConversion(Expr *&expr); 3923 3924 // DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that 3925 // do not have a prototype. Integer promotions are performed on each 3926 // argument, and arguments that have type float are promoted to double. 3927 void DefaultArgumentPromotion(Expr *&Expr); 3928 3929 // Used for emitting the right warning by DefaultVariadicArgumentPromotion 3930 enum VariadicCallType { 3931 VariadicFunction, 3932 VariadicBlock, 3933 VariadicMethod, 3934 VariadicConstructor, 3935 VariadicDoesNotApply 3936 }; 3937 3938 /// GatherArgumentsForCall - Collector argument expressions for various 3939 /// form of call prototypes. 3940 bool GatherArgumentsForCall(SourceLocation CallLoc, 3941 FunctionDecl *FDecl, 3942 const FunctionProtoType *Proto, 3943 unsigned FirstProtoArg, 3944 Expr **Args, unsigned NumArgs, 3945 llvm::SmallVector<Expr *, 8> &AllArgs, 3946 VariadicCallType CallType = VariadicDoesNotApply); 3947 3948 // DefaultVariadicArgumentPromotion - Like DefaultArgumentPromotion, but 3949 // will warn if the resulting type is not a POD type. 3950 bool DefaultVariadicArgumentPromotion(Expr *&Expr, VariadicCallType CT, 3951 FunctionDecl *FDecl); 3952 3953 // UsualArithmeticConversions - performs the UsualUnaryConversions on it's 3954 // operands and then handles various conversions that are common to binary 3955 // operators (C99 6.3.1.8). If both operands aren't arithmetic, this 3956 // routine returns the first non-arithmetic type found. The client is 3957 // responsible for emitting appropriate error diagnostics. 3958 QualType UsualArithmeticConversions(Expr *&lExpr, Expr *&rExpr, 3959 bool isCompAssign = false); 3960 3961 /// AssignConvertType - All of the 'assignment' semantic checks return this 3962 /// enum to indicate whether the assignment was allowed. These checks are 3963 /// done for simple assignments, as well as initialization, return from 3964 /// function, argument passing, etc. The query is phrased in terms of a 3965 /// source and destination type. 3966 enum AssignConvertType { 3967 /// Compatible - the types are compatible according to the standard. 3968 Compatible, 3969 3970 /// PointerToInt - The assignment converts a pointer to an int, which we 3971 /// accept as an extension. 3972 PointerToInt, 3973 3974 /// IntToPointer - The assignment converts an int to a pointer, which we 3975 /// accept as an extension. 3976 IntToPointer, 3977 3978 /// FunctionVoidPointer - The assignment is between a function pointer and 3979 /// void*, which the standard doesn't allow, but we accept as an extension. 3980 FunctionVoidPointer, 3981 3982 /// IncompatiblePointer - The assignment is between two pointers types that 3983 /// are not compatible, but we accept them as an extension. 3984 IncompatiblePointer, 3985 3986 /// IncompatiblePointer - The assignment is between two pointers types which 3987 /// point to integers which have a different sign, but are otherwise identical. 3988 /// This is a subset of the above, but broken out because it's by far the most 3989 /// common case of incompatible pointers. 3990 IncompatiblePointerSign, 3991 3992 /// CompatiblePointerDiscardsQualifiers - The assignment discards 3993 /// c/v/r qualifiers, which we accept as an extension. 3994 CompatiblePointerDiscardsQualifiers, 3995 3996 /// IncompatibleNestedPointerQualifiers - The assignment is between two 3997 /// nested pointer types, and the qualifiers other than the first two 3998 /// levels differ e.g. char ** -> const char **, but we accept them as an 3999 /// extension. 4000 IncompatibleNestedPointerQualifiers, 4001 4002 /// IncompatibleVectors - The assignment is between two vector types that 4003 /// have the same size, which we accept as an extension. 4004 IncompatibleVectors, 4005 4006 /// IntToBlockPointer - The assignment converts an int to a block 4007 /// pointer. We disallow this. 4008 IntToBlockPointer, 4009 4010 /// IncompatibleBlockPointer - The assignment is between two block 4011 /// pointers types that are not compatible. 4012 IncompatibleBlockPointer, 4013 4014 /// IncompatibleObjCQualifiedId - The assignment is between a qualified 4015 /// id type and something else (that is incompatible with it). For example, 4016 /// "id <XXX>" = "Foo *", where "Foo *" doesn't implement the XXX protocol. 4017 IncompatibleObjCQualifiedId, 4018 4019 /// Incompatible - We reject this conversion outright, it is invalid to 4020 /// represent it in the AST. 4021 Incompatible 4022 }; 4023 4024 /// DiagnoseAssignmentResult - Emit a diagnostic, if required, for the 4025 /// assignment conversion type specified by ConvTy. This returns true if the 4026 /// conversion was invalid or false if the conversion was accepted. 4027 bool DiagnoseAssignmentResult(AssignConvertType ConvTy, 4028 SourceLocation Loc, 4029 QualType DstType, QualType SrcType, 4030 Expr *SrcExpr, AssignmentAction Action, 4031 bool *Complained = 0); 4032 4033 /// CheckAssignmentConstraints - Perform type checking for assignment, 4034 /// argument passing, variable initialization, and function return values. 4035 /// This routine is only used by the following two methods. C99 6.5.16. 4036 AssignConvertType CheckAssignmentConstraints(QualType lhs, QualType rhs); 4037 4038 // CheckSingleAssignmentConstraints - Currently used by 4039 // CheckAssignmentOperands, and ActOnReturnStmt. Prior to type checking, 4040 // this routine performs the default function/array converions. 4041 AssignConvertType CheckSingleAssignmentConstraints(QualType lhs, 4042 Expr *&rExpr); 4043 4044 // \brief If the lhs type is a transparent union, check whether we 4045 // can initialize the transparent union with the given expression. 4046 AssignConvertType CheckTransparentUnionArgumentConstraints(QualType lhs, 4047 Expr *&rExpr); 4048 4049 // Helper function for CheckAssignmentConstraints (C99 6.5.16.1p1) 4050 AssignConvertType CheckPointerTypesForAssignment(QualType lhsType, 4051 QualType rhsType); 4052 4053 AssignConvertType CheckObjCPointerTypesForAssignment(QualType lhsType, 4054 QualType rhsType); 4055 4056 // Helper function for CheckAssignmentConstraints involving two 4057 // block pointer types. 4058 AssignConvertType CheckBlockPointerTypesForAssignment(QualType lhsType, 4059 QualType rhsType); 4060 4061 bool IsStringLiteralToNonConstPointerConversion(Expr *From, QualType ToType); 4062 4063 bool CheckExceptionSpecCompatibility(Expr *From, QualType ToType); 4064 4065 bool PerformImplicitConversion(Expr *&From, QualType ToType, 4066 AssignmentAction Action, 4067 bool AllowExplicit = false); 4068 bool PerformImplicitConversion(Expr *&From, QualType ToType, 4069 AssignmentAction Action, 4070 bool AllowExplicit, 4071 ImplicitConversionSequence& ICS); 4072 bool PerformImplicitConversion(Expr *&From, QualType ToType, 4073 const ImplicitConversionSequence& ICS, 4074 AssignmentAction Action, 4075 bool IgnoreBaseAccess = false); 4076 bool PerformImplicitConversion(Expr *&From, QualType ToType, 4077 const StandardConversionSequence& SCS, 4078 AssignmentAction Action,bool IgnoreBaseAccess); 4079 4080 /// the following "Check" methods will return a valid/converted QualType 4081 /// or a null QualType (indicating an error diagnostic was issued). 4082 4083 /// type checking binary operators (subroutines of CreateBuiltinBinOp). 4084 QualType InvalidOperands(SourceLocation l, Expr *&lex, Expr *&rex); 4085 QualType CheckPointerToMemberOperands( // C++ 5.5 4086 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isIndirect); 4087 QualType CheckMultiplyDivideOperands( // C99 6.5.5 4088 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign, 4089 bool isDivide); 4090 QualType CheckRemainderOperands( // C99 6.5.5 4091 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false); 4092 QualType CheckAdditionOperands( // C99 6.5.6 4093 Expr *&lex, Expr *&rex, SourceLocation OpLoc, QualType* CompLHSTy = 0); 4094 QualType CheckSubtractionOperands( // C99 6.5.6 4095 Expr *&lex, Expr *&rex, SourceLocation OpLoc, QualType* CompLHSTy = 0); 4096 QualType CheckShiftOperands( // C99 6.5.7 4097 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false); 4098 QualType CheckCompareOperands( // C99 6.5.8/9 4099 Expr *&lex, Expr *&rex, SourceLocation OpLoc, unsigned Opc, 4100 bool isRelational); 4101 QualType CheckBitwiseOperands( // C99 6.5.[10...12] 4102 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false); 4103 QualType CheckLogicalOperands( // C99 6.5.[13,14] 4104 Expr *&lex, Expr *&rex, SourceLocation OpLoc, unsigned Opc); 4105 // CheckAssignmentOperands is used for both simple and compound assignment. 4106 // For simple assignment, pass both expressions and a null converted type. 4107 // For compound assignment, pass both expressions and the converted type. 4108 QualType CheckAssignmentOperands( // C99 6.5.16.[1,2] 4109 Expr *lex, Expr *&rex, SourceLocation OpLoc, QualType convertedType); 4110 4111 void ConvertPropertyAssignment(Expr *LHS, Expr *&RHS, QualType& LHSTy); 4112 4113 QualType CheckCommaOperands( // C99 6.5.17 4114 Expr *lex, Expr *&rex, SourceLocation OpLoc); 4115 QualType CheckConditionalOperands( // C99 6.5.15 4116 Expr *&cond, Expr *&lhs, Expr *&rhs, SourceLocation questionLoc); 4117 QualType CXXCheckConditionalOperands( // C++ 5.16 4118 Expr *&cond, Expr *&lhs, Expr *&rhs, SourceLocation questionLoc); 4119 QualType FindCompositePointerType(SourceLocation Loc, Expr *&E1, Expr *&E2, 4120 bool *NonStandardCompositeType = 0); 4121 4122 QualType FindCompositeObjCPointerType(Expr *&LHS, Expr *&RHS, 4123 SourceLocation questionLoc); 4124 4125 /// type checking for vector binary operators. 4126 QualType CheckVectorOperands(SourceLocation l, Expr *&lex, Expr *&rex); 4127 QualType CheckVectorCompareOperands(Expr *&lex, Expr *&rx, 4128 SourceLocation l, bool isRel); 4129 4130 /// type checking unary operators (subroutines of ActOnUnaryOp). 4131 /// C99 6.5.3.1, 6.5.3.2, 6.5.3.4 4132 QualType CheckIncrementDecrementOperand(Expr *op, SourceLocation OpLoc, 4133 bool isInc, bool isPrefix); 4134 QualType CheckAddressOfOperand(Expr *op, SourceLocation OpLoc); 4135 QualType CheckIndirectionOperand(Expr *op, SourceLocation OpLoc); 4136 QualType CheckRealImagOperand(Expr *&Op, SourceLocation OpLoc, bool isReal); 4137 4138 /// type checking primary expressions. 4139 QualType CheckExtVectorComponent(QualType baseType, SourceLocation OpLoc, 4140 const IdentifierInfo *Comp, 4141 SourceLocation CmpLoc); 4142 4143 /// type checking declaration initializers (C99 6.7.8) 4144 bool CheckInitList(const InitializedEntity &Entity, 4145 InitListExpr *&InitList, QualType &DeclType); 4146 bool CheckForConstantInitializer(Expr *e, QualType t); 4147 4148 // type checking C++ declaration initializers (C++ [dcl.init]). 4149 4150 /// ReferenceCompareResult - Expresses the result of comparing two 4151 /// types (cv1 T1 and cv2 T2) to determine their compatibility for the 4152 /// purposes of initialization by reference (C++ [dcl.init.ref]p4). 4153 enum ReferenceCompareResult { 4154 /// Ref_Incompatible - The two types are incompatible, so direct 4155 /// reference binding is not possible. 4156 Ref_Incompatible = 0, 4157 /// Ref_Related - The two types are reference-related, which means 4158 /// that their unqualified forms (T1 and T2) are either the same 4159 /// or T1 is a base class of T2. 4160 Ref_Related, 4161 /// Ref_Compatible_With_Added_Qualification - The two types are 4162 /// reference-compatible with added qualification, meaning that 4163 /// they are reference-compatible and the qualifiers on T1 (cv1) 4164 /// are greater than the qualifiers on T2 (cv2). 4165 Ref_Compatible_With_Added_Qualification, 4166 /// Ref_Compatible - The two types are reference-compatible and 4167 /// have equivalent qualifiers (cv1 == cv2). 4168 Ref_Compatible 4169 }; 4170 4171 ReferenceCompareResult CompareReferenceRelationship(SourceLocation Loc, 4172 QualType T1, QualType T2, 4173 bool &DerivedToBase, 4174 bool &ObjCConversion); 4175 4176 /// CheckCastTypes - Check type constraints for casting between types under 4177 /// C semantics, or forward to CXXCheckCStyleCast in C++. 4178 bool CheckCastTypes(SourceRange TyRange, QualType CastTy, Expr *&CastExpr, 4179 CastKind &Kind, CXXCastPath &BasePath, 4180 bool FunctionalStyle = false); 4181 4182 // CheckVectorCast - check type constraints for vectors. 4183 // Since vectors are an extension, there are no C standard reference for this. 4184 // We allow casting between vectors and integer datatypes of the same size. 4185 // returns true if the cast is invalid 4186 bool CheckVectorCast(SourceRange R, QualType VectorTy, QualType Ty, 4187 CastKind &Kind); 4188 4189 // CheckExtVectorCast - check type constraints for extended vectors. 4190 // Since vectors are an extension, there are no C standard reference for this. 4191 // We allow casting between vectors and integer datatypes of the same size, 4192 // or vectors and the element type of that vector. 4193 // returns true if the cast is invalid 4194 bool CheckExtVectorCast(SourceRange R, QualType VectorTy, Expr *&CastExpr, 4195 CastKind &Kind); 4196 4197 /// CXXCheckCStyleCast - Check constraints of a C-style or function-style 4198 /// cast under C++ semantics. 4199 bool CXXCheckCStyleCast(SourceRange R, QualType CastTy, Expr *&CastExpr, 4200 CastKind &Kind, CXXCastPath &BasePath, 4201 bool FunctionalStyle); 4202 4203 /// CheckMessageArgumentTypes - Check types in an Obj-C message send. 4204 /// \param Method - May be null. 4205 /// \param [out] ReturnType - The return type of the send. 4206 /// \return true iff there were any incompatible types. 4207 bool CheckMessageArgumentTypes(Expr **Args, unsigned NumArgs, Selector Sel, 4208 ObjCMethodDecl *Method, bool isClassMessage, 4209 SourceLocation lbrac, SourceLocation rbrac, 4210 QualType &ReturnType); 4211 4212 /// CheckBooleanCondition - Diagnose problems involving the use of 4213 /// the given expression as a boolean condition (e.g. in an if 4214 /// statement). Also performs the standard function and array 4215 /// decays, possibly changing the input variable. 4216 /// 4217 /// \param Loc - A location associated with the condition, e.g. the 4218 /// 'if' keyword. 4219 /// \return true iff there were any errors 4220 bool CheckBooleanCondition(Expr *&CondExpr, SourceLocation Loc); 4221 4222 ExprResult ActOnBooleanCondition(Scope *S, SourceLocation Loc, 4223 Expr *SubExpr); 4224 4225 /// DiagnoseAssignmentAsCondition - Given that an expression is 4226 /// being used as a boolean condition, warn if it's an assignment. 4227 void DiagnoseAssignmentAsCondition(Expr *E); 4228 4229 /// CheckCXXBooleanCondition - Returns true if conversion to bool is invalid. 4230 bool CheckCXXBooleanCondition(Expr *&CondExpr); 4231 4232 /// ConvertIntegerToTypeWarnOnOverflow - Convert the specified APInt to have 4233 /// the specified width and sign. If an overflow occurs, detect it and emit 4234 /// the specified diagnostic. 4235 void ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &OldVal, 4236 unsigned NewWidth, bool NewSign, 4237 SourceLocation Loc, unsigned DiagID); 4238 4239 /// Checks that the Objective-C declaration is declared in the global scope. 4240 /// Emits an error and marks the declaration as invalid if it's not declared 4241 /// in the global scope. 4242 bool CheckObjCDeclScope(Decl *D); 4243 4244 void InitBuiltinVaListType(); 4245 4246 /// VerifyIntegerConstantExpression - verifies that an expression is an ICE, 4247 /// and reports the appropriate diagnostics. Returns false on success. 4248 /// Can optionally return the value of the expression. 4249 bool VerifyIntegerConstantExpression(const Expr *E, llvm::APSInt *Result = 0); 4250 4251 /// VerifyBitField - verifies that a bit field expression is an ICE and has 4252 /// the correct width, and that the field type is valid. 4253 /// Returns false on success. 4254 /// Can optionally return whether the bit-field is of width 0 4255 bool VerifyBitField(SourceLocation FieldLoc, IdentifierInfo *FieldName, 4256 QualType FieldTy, const Expr *BitWidth, 4257 bool *ZeroWidth = 0); 4258 4259 /// \name Code completion 4260 //@{ 4261 /// \brief Describes the context in which code completion occurs. 4262 enum ParserCompletionContext { 4263 /// \brief Code completion occurs at top-level or namespace context. 4264 PCC_Namespace, 4265 /// \brief Code completion occurs within a class, struct, or union. 4266 PCC_Class, 4267 /// \brief Code completion occurs within an Objective-C interface, protocol, 4268 /// or category. 4269 PCC_ObjCInterface, 4270 /// \brief Code completion occurs within an Objective-C implementation or 4271 /// category implementation 4272 PCC_ObjCImplementation, 4273 /// \brief Code completion occurs within the list of instance variables 4274 /// in an Objective-C interface, protocol, category, or implementation. 4275 PCC_ObjCInstanceVariableList, 4276 /// \brief Code completion occurs following one or more template 4277 /// headers. 4278 PCC_Template, 4279 /// \brief Code completion occurs following one or more template 4280 /// headers within a class. 4281 PCC_MemberTemplate, 4282 /// \brief Code completion occurs within an expression. 4283 PCC_Expression, 4284 /// \brief Code completion occurs within a statement, which may 4285 /// also be an expression or a declaration. 4286 PCC_Statement, 4287 /// \brief Code completion occurs at the beginning of the 4288 /// initialization statement (or expression) in a for loop. 4289 PCC_ForInit, 4290 /// \brief Code completion occurs within the condition of an if, 4291 /// while, switch, or for statement. 4292 PCC_Condition, 4293 /// \brief Code completion occurs within the body of a function on a 4294 /// recovery path, where we do not have a specific handle on our position 4295 /// in the grammar. 4296 PCC_RecoveryInFunction, 4297 /// \brief Code completion occurs where only a type is permitted. 4298 PCC_Type 4299 }; 4300 4301 void CodeCompleteOrdinaryName(Scope *S, 4302 ParserCompletionContext CompletionContext); 4303 void CodeCompleteDeclarator(Scope *S, 4304 bool AllowNonIdentifiers, 4305 bool AllowNestedNameSpecifiers); 4306 4307 struct CodeCompleteExpressionData; 4308 void CodeCompleteExpression(Scope *S, 4309 const CodeCompleteExpressionData &Data); 4310 void CodeCompleteMemberReferenceExpr(Scope *S, Expr *Base, 4311 SourceLocation OpLoc, 4312 bool IsArrow); 4313 void CodeCompleteTag(Scope *S, unsigned TagSpec); 4314 void CodeCompleteTypeQualifiers(DeclSpec &DS); 4315 void CodeCompleteCase(Scope *S); 4316 void CodeCompleteCall(Scope *S, Expr *Fn, Expr **Args, unsigned NumArgs); 4317 void CodeCompleteInitializer(Scope *S, Decl *D); 4318 void CodeCompleteReturn(Scope *S); 4319 void CodeCompleteAssignmentRHS(Scope *S, Expr *LHS); 4320 4321 void CodeCompleteQualifiedId(Scope *S, CXXScopeSpec &SS, 4322 bool EnteringContext); 4323 void CodeCompleteUsing(Scope *S); 4324 void CodeCompleteUsingDirective(Scope *S); 4325 void CodeCompleteNamespaceDecl(Scope *S); 4326 void CodeCompleteNamespaceAliasDecl(Scope *S); 4327 void CodeCompleteOperatorName(Scope *S); 4328 void CodeCompleteConstructorInitializer(Decl *Constructor, 4329 CXXBaseOrMemberInitializer** Initializers, 4330 unsigned NumInitializers); 4331 4332 void CodeCompleteObjCAtDirective(Scope *S, Decl *ObjCImpDecl, 4333 bool InInterface); 4334 void CodeCompleteObjCAtVisibility(Scope *S); 4335 void CodeCompleteObjCAtStatement(Scope *S); 4336 void CodeCompleteObjCAtExpression(Scope *S); 4337 void CodeCompleteObjCPropertyFlags(Scope *S, ObjCDeclSpec &ODS); 4338 void CodeCompleteObjCPropertyGetter(Scope *S, Decl *ClassDecl, 4339 Decl **Methods, 4340 unsigned NumMethods); 4341 void CodeCompleteObjCPropertySetter(Scope *S, Decl *ClassDecl, 4342 Decl **Methods, 4343 unsigned NumMethods); 4344 void CodeCompleteObjCPassingType(Scope *S, ObjCDeclSpec &DS); 4345 void CodeCompleteObjCMessageReceiver(Scope *S); 4346 void CodeCompleteObjCSuperMessage(Scope *S, SourceLocation SuperLoc, 4347 IdentifierInfo **SelIdents, 4348 unsigned NumSelIdents); 4349 void CodeCompleteObjCClassMessage(Scope *S, ParsedType Receiver, 4350 IdentifierInfo **SelIdents, 4351 unsigned NumSelIdents); 4352 void CodeCompleteObjCClassMessage(Scope *S, ParsedType Receiver, 4353 IdentifierInfo **SelIdents, 4354 unsigned NumSelIdents, 4355 bool IsSuper); 4356 void CodeCompleteObjCInstanceMessage(Scope *S, ExprTy *Receiver, 4357 IdentifierInfo **SelIdents, 4358 unsigned NumSelIdents); 4359 void CodeCompleteObjCInstanceMessage(Scope *S, ExprTy *Receiver, 4360 IdentifierInfo **SelIdents, 4361 unsigned NumSelIdents, 4362 bool IsSuper); 4363 void CodeCompleteObjCForCollection(Scope *S, 4364 DeclGroupPtrTy IterationVar); 4365 void CodeCompleteObjCSelector(Scope *S, 4366 IdentifierInfo **SelIdents, 4367 unsigned NumSelIdents); 4368 void CodeCompleteObjCProtocolReferences(IdentifierLocPair *Protocols, 4369 unsigned NumProtocols); 4370 void CodeCompleteObjCProtocolDecl(Scope *S); 4371 void CodeCompleteObjCInterfaceDecl(Scope *S); 4372 void CodeCompleteObjCSuperclass(Scope *S, 4373 IdentifierInfo *ClassName, 4374 SourceLocation ClassNameLoc); 4375 void CodeCompleteObjCImplementationDecl(Scope *S); 4376 void CodeCompleteObjCInterfaceCategory(Scope *S, 4377 IdentifierInfo *ClassName, 4378 SourceLocation ClassNameLoc); 4379 void CodeCompleteObjCImplementationCategory(Scope *S, 4380 IdentifierInfo *ClassName, 4381 SourceLocation ClassNameLoc); 4382 void CodeCompleteObjCPropertyDefinition(Scope *S, Decl *ObjCImpDecl); 4383 void CodeCompleteObjCPropertySynthesizeIvar(Scope *S, 4384 IdentifierInfo *PropertyName, 4385 Decl *ObjCImpDecl); 4386 void CodeCompleteObjCMethodDecl(Scope *S, 4387 bool IsInstanceMethod, 4388 ParsedType ReturnType, 4389 Decl *IDecl); 4390 void CodeCompleteObjCMethodDeclSelector(Scope *S, 4391 bool IsInstanceMethod, 4392 bool AtParameterName, 4393 ParsedType ReturnType, 4394 IdentifierInfo **SelIdents, 4395 unsigned NumSelIdents); 4396 void CodeCompletePreprocessorDirective(bool InConditional); 4397 void CodeCompleteInPreprocessorConditionalExclusion(Scope *S); 4398 void CodeCompletePreprocessorMacroName(bool IsDefinition); 4399 void CodeCompletePreprocessorExpression(); 4400 void CodeCompletePreprocessorMacroArgument(Scope *S, 4401 IdentifierInfo *Macro, 4402 MacroInfo *MacroInfo, 4403 unsigned Argument); 4404 void CodeCompleteNaturalLanguage(); 4405 void GatherGlobalCodeCompletions( 4406 llvm::SmallVectorImpl<CodeCompletionResult> &Results); 4407 //@} 4408 4409 void PrintStats() const {} 4410 4411 //===--------------------------------------------------------------------===// 4412 // Extra semantic analysis beyond the C type system 4413 4414public: 4415 SourceLocation getLocationOfStringLiteralByte(const StringLiteral *SL, 4416 unsigned ByteNo) const; 4417 4418private: 4419 bool CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall); 4420 bool CheckBlockCall(NamedDecl *NDecl, CallExpr *TheCall); 4421 4422 bool CheckablePrintfAttr(const FormatAttr *Format, CallExpr *TheCall); 4423 bool CheckObjCString(Expr *Arg); 4424 4425 ExprResult CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); 4426 bool CheckARMBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); 4427 bool CheckX86BuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); 4428 4429 bool SemaBuiltinVAStart(CallExpr *TheCall); 4430 bool SemaBuiltinUnorderedCompare(CallExpr *TheCall); 4431 bool SemaBuiltinFPClassification(CallExpr *TheCall, unsigned NumArgs); 4432 4433public: 4434 // Used by C++ template instantiation. 4435 ExprResult SemaBuiltinShuffleVector(CallExpr *TheCall); 4436 4437private: 4438 bool SemaBuiltinPrefetch(CallExpr *TheCall); 4439 bool SemaBuiltinObjectSize(CallExpr *TheCall); 4440 bool SemaBuiltinLongjmp(CallExpr *TheCall); 4441 ExprResult SemaBuiltinAtomicOverloaded(ExprResult TheCallResult); 4442 bool SemaBuiltinConstantArg(CallExpr *TheCall, int ArgNum, 4443 llvm::APSInt &Result); 4444 4445 bool SemaCheckStringLiteral(const Expr *E, const CallExpr *TheCall, 4446 bool HasVAListArg, unsigned format_idx, 4447 unsigned firstDataArg, bool isPrintf); 4448 4449 void CheckFormatString(const StringLiteral *FExpr, const Expr *OrigFormatExpr, 4450 const CallExpr *TheCall, bool HasVAListArg, 4451 unsigned format_idx, unsigned firstDataArg, 4452 bool isPrintf); 4453 4454 void CheckNonNullArguments(const NonNullAttr *NonNull, 4455 const CallExpr *TheCall); 4456 4457 void CheckPrintfScanfArguments(const CallExpr *TheCall, bool HasVAListArg, 4458 unsigned format_idx, unsigned firstDataArg, 4459 bool isPrintf); 4460 4461 void CheckReturnStackAddr(Expr *RetValExp, QualType lhsType, 4462 SourceLocation ReturnLoc); 4463 void CheckFloatComparison(SourceLocation loc, Expr* lex, Expr* rex); 4464 void CheckImplicitConversions(Expr *E); 4465 4466 /// \brief The parser's current scope. 4467 /// 4468 /// The parser maintains this state here. 4469 Scope *CurScope; 4470 4471protected: 4472 friend class Parser; 4473 4474 /// \brief Retrieve the parser's current scope. 4475 Scope *getCurScope() const { return CurScope; } 4476}; 4477 4478/// \brief RAII object that enters a new expression evaluation context. 4479class EnterExpressionEvaluationContext { 4480 Sema &Actions; 4481 4482public: 4483 EnterExpressionEvaluationContext(Sema &Actions, 4484 Sema::ExpressionEvaluationContext NewContext) 4485 : Actions(Actions) { 4486 Actions.PushExpressionEvaluationContext(NewContext); 4487 } 4488 4489 ~EnterExpressionEvaluationContext() { 4490 Actions.PopExpressionEvaluationContext(); 4491 } 4492}; 4493 4494} // end namespace clang 4495 4496#endif 4497