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