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