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