Decl.h revision d85b5b9b8fcf53906d9a61649b3657ca0d902017
1c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch//===--- Decl.h - Classes for representing declarations ---------*- C++ -*-===//
2c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott//
3c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott//                     The LLVM Compiler Infrastructure
4c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott//
5c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// This file is distributed under the University of Illinois Open Source
6c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// License. See LICENSE.TXT for details.
7c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott//
8c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott//===----------------------------------------------------------------------===//
9c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott//
10c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott//  This file defines the Decl subclasses.
11c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott//
12c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott//===----------------------------------------------------------------------===//
13c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
14c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#ifndef LLVM_CLANG_AST_DECL_H
15c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#define LLVM_CLANG_AST_DECL_H
16c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
17c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#include "clang/AST/APValue.h"
18c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#include "clang/AST/DeclBase.h"
19c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#include "clang/AST/Redeclarable.h"
20c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#include "clang/AST/DeclarationName.h"
21c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#include "clang/AST/ExternalASTSource.h"
22c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
23c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottnamespace clang {
24c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottclass Expr;
25c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottclass FunctionTemplateDecl;
26c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottclass Stmt;
27c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottclass CompoundStmt;
28c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottclass StringLiteral;
29c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottclass TemplateArgumentList;
30c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottclass MemberSpecializationInfo;
31c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottclass FunctionTemplateSpecializationInfo;
32c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottclass TypeLoc;
33c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
34c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott/// \brief A container of type source information.
35c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott///
36c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott/// A client can read the relevant info using TypeLoc wrappers, e.g:
37c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott/// @code
38c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott/// TypeLoc TL = DeclaratorInfo->getTypeLoc();
39c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott/// if (PointerLoc *PL = dyn_cast<PointerLoc>(&TL))
40c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott///   PL->getStarLoc().print(OS, SrcMgr);
41c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott/// @endcode
42c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott///
43c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottclass DeclaratorInfo {
44c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  QualType Ty;
45c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  // Contains a memory block after the class, used for type source information,
46c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  // allocated by ASTContext.
47c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  friend class ASTContext;
48c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  DeclaratorInfo(QualType ty) : Ty(ty) { }
49c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottpublic:
50c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// \brief Return the type wrapped by this type source info.
51c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  QualType getType() const { return Ty; }
52c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
53c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// \brief Return the TypeLoc wrapper for the type source info.
54c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  TypeLoc getTypeLoc() const;
55c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott};
56c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
57c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott/// UnresolvedSet - A set of unresolved declarations.  This is needed
58c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott/// in a lot of places, but isn't really worth breaking into its own
59c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott/// header right now.
60c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottclass UnresolvedSet {
61c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  typedef llvm::SmallVector<NamedDecl*, 4> DeclsTy;
62c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  DeclsTy Decls;
63c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
64c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottpublic:
65c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  void addDecl(NamedDecl *D) {
66c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    Decls.push_back(D);
67c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  }
68c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
69c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  bool replace(const NamedDecl* Old, NamedDecl *New) {
70c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    for (DeclsTy::iterator I = Decls.begin(), E = Decls.end(); I != E; ++I)
71c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott      if (*I == Old)
72c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        return (*I = New, true);
73c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    return false;
74c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  }
75c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
76c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  typedef DeclsTy::const_iterator iterator;
77c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  iterator begin() const { return Decls.begin(); }
78c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  iterator end() const { return Decls.end(); }
79c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott};
80c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
81c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott/// TranslationUnitDecl - The top declaration context.
82c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottclass TranslationUnitDecl : public Decl, public DeclContext {
83c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  ASTContext &Ctx;
84c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
85c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  explicit TranslationUnitDecl(ASTContext &ctx)
86c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    : Decl(TranslationUnit, 0, SourceLocation()),
87c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott      DeclContext(TranslationUnit),
88c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott      Ctx(ctx) {}
89c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottpublic:
90c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  ASTContext &getASTContext() const { return Ctx; }
91c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
92c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  static TranslationUnitDecl *Create(ASTContext &C);
933345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  // Implement isa/cast/dyncast/etc.
94c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  static bool classof(const Decl *D) { return D->getKind() == TranslationUnit; }
95c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  static bool classof(const TranslationUnitDecl *D) { return true; }
96c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  static DeclContext *castToDeclContext(const TranslationUnitDecl *D) {
97c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    return static_cast<DeclContext *>(const_cast<TranslationUnitDecl*>(D));
98c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  }
99c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  static TranslationUnitDecl *castFromDeclContext(const DeclContext *DC) {
100c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    return static_cast<TranslationUnitDecl *>(const_cast<DeclContext*>(DC));
101c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  }
1023345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick};
103c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
104c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott/// NamedDecl - This represents a decl with a name.  Many decls have names such
105c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott/// as ObjCMethodDecl, but not @class, etc.
1063345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrickclass NamedDecl : public Decl {
107c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// Name - The name of this declaration, which is typically a normal
108c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// identifier but may also be a special kind of name (C++
109c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// constructor, Objective-C selector, etc.)
1103345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  DeclarationName Name;
111c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
112c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottprotected:
113c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  NamedDecl(Kind DK, DeclContext *DC, SourceLocation L, DeclarationName N)
1143345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    : Decl(DK, DC, L), Name(N) { }
115c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
116c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottpublic:
117c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// getIdentifier - Get the identifier that names this declaration,
1183345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  /// if there is one. This will return NULL if this declaration has
119c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// no name (e.g., for an unnamed class) or if the name is a special
120c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// name (C++ constructor, Objective-C selector, etc.).
121c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  IdentifierInfo *getIdentifier() const { return Name.getAsIdentifierInfo(); }
122c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
123c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// getName - Get the name of identifier for this declaration as a StringRef.
124c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// This requires that the declaration have a name and that it be a simple
125c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// identifier.
126c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  llvm::StringRef getName() const {
127c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    assert(Name.isIdentifier() && "Name is not a simple identifier");
128c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    return getIdentifier() ? getIdentifier()->getName() : "";
129c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  }
130c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
131c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// getNameAsCString - Get the name of identifier for this declaration as a
132c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// C string (const char*).  This requires that the declaration have a name
133c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// and that it be a simple identifier.
134c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  //
135c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  // FIXME: Deprecated, move clients to getName().
136c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  const char *getNameAsCString() const {
137c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    assert(Name.isIdentifier() && "Name is not a simple identifier");
138c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    return getIdentifier() ? getIdentifier()->getNameStart() : "";
139c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  }
140c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
141c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  /// getNameAsString - Get a human-readable name for the declaration, even if
142c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  /// it is one of the special kinds of names (C++ constructor, Objective-C
143c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  /// selector, etc).  Creating this name requires expensive string
144c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  /// manipulation, so it should be called only when performance doesn't matter.
145c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  /// For simple declarations, getNameAsCString() should suffice.
146c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  //
147c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // FIXME: This function should be renamed to indicate that it is not just an
148c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // alternate form of getName(), and clients should move as appropriate.
149c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  //
150c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // FIXME: Deprecated, move clients to getName().
151c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  std::string getNameAsString() const { return Name.getAsString(); }
152c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
153c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// getDeclName - Get the actual, stored name of the declaration,
154c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// which may be a special name.
155c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  DeclarationName getDeclName() const { return Name; }
156c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
157c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// \brief Set the name of this declaration.
158c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  void setDeclName(DeclarationName N) { Name = N; }
159c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
160c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// getQualifiedNameAsString - Returns human-readable qualified name for
161c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// declaration, like A::B::i, for i being member of namespace A::B.
162c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// If declaration is not member of context which can be named (record,
163c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// namespace), it will return same result as getNameAsString().
164c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// Creating this name is expensive, so it should be called only when
165c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// performance doesn't matter.
166c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  std::string getQualifiedNameAsString() const;
167c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  std::string getQualifiedNameAsString(const PrintingPolicy &Policy) const;
168c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
169c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// getNameForDiagnostic - Appends a human-readable name for this
170c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// declaration into the given string.
171c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  ///
172c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// This is the method invoked by Sema when displaying a NamedDecl
173c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// in a diagnostic.  It does not necessarily produce the same
174c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// result as getNameAsString(); for example, class template
175c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// specializations are printed with their template arguments.
176c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  ///
177c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// TODO: use an API that doesn't require so many temporary strings
178c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  virtual void getNameForDiagnostic(std::string &S,
179c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott                                    const PrintingPolicy &Policy,
180c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott                                    bool Qualified) const {
181c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    if (Qualified)
182c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott      S += getQualifiedNameAsString(Policy);
183c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    else
184c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott      S += getNameAsString();
185c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  }
186c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
187c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// declarationReplaces - Determine whether this declaration, if
188c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// known to be well-formed within its context, will replace the
189c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// declaration OldD if introduced into scope. A declaration will
190c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// replace another declaration if, for example, it is a
191c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// redeclaration of the same variable or function, but not if it is
192c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// a declaration of a different kind (function vs. class) or an
193c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// overloaded function.
194c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  bool declarationReplaces(NamedDecl *OldD) const;
195c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
196c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// \brief Determine whether this declaration has linkage.
197c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  bool hasLinkage() const;
198c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
199c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// \brief Describes the different kinds of linkage
200c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// (C++ [basic.link], C99 6.2.2) that an entity may have.
201c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  enum Linkage {
202c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    /// \brief No linkage, which means that the entity is unique and
203c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    /// can only be referred to from within its scope.
204c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    NoLinkage = 0,
205c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
206c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    /// \brief Internal linkage, which indicates that the entity can
207c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    /// be referred to from within the translation unit (but not other
208c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    /// translation units).
209c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    InternalLinkage,
210c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
211c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    /// \brief External linkage, which indicates that the entity can
212c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    /// be referred to from other translation units.
213c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    ExternalLinkage
214c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  };
215c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
216c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// \brief Determine what kind of linkage this entity has.
217c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  Linkage getLinkage() const;
218c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
219c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// \brief Looks through UsingDecls and ObjCCompatibleAliasDecls for
220c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// the underlying named decl.
221c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  NamedDecl *getUnderlyingDecl();
222c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  const NamedDecl *getUnderlyingDecl() const {
223c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    return const_cast<NamedDecl*>(this)->getUnderlyingDecl();
224c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  }
225c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
226c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  static bool classof(const Decl *D) {
227c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    return D->getKind() >= NamedFirst && D->getKind() <= NamedLast;
228c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  }
229c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  static bool classof(const NamedDecl *D) { return true; }
230c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott};
231c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
232c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott/// NamespaceDecl - Represent a C++ namespace.
233c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottclass NamespaceDecl : public NamedDecl, public DeclContext {
234c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  SourceLocation LBracLoc, RBracLoc;
235c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
2363345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  // For extended namespace definitions:
237c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  //
238c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  // namespace A { int x; }
239c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  // namespace A { int y; }
240c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  //
241c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  // there will be one NamespaceDecl for each declaration.
242c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  // NextNamespace points to the next extended declaration.
243c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  // OrigNamespace points to the original namespace declaration.
244c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  // OrigNamespace of the first namespace decl points to itself.
245c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  NamespaceDecl *OrigNamespace, *NextNamespace;
246c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
247c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  NamespaceDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id)
248c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    : NamedDecl(Namespace, DC, L, Id), DeclContext(Namespace) {
249c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    OrigNamespace = this;
250c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    NextNamespace = 0;
251c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  }
252c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottpublic:
253c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  static NamespaceDecl *Create(ASTContext &C, DeclContext *DC,
254c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott                               SourceLocation L, IdentifierInfo *Id);
255c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
256c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  virtual void Destroy(ASTContext& C);
257c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
258c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  // \brief Returns true if this is an anonymous namespace declaration.
259c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  //
260c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  // For example:
261c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  //   namespace {
262c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  //     ...
263c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  //   };
264c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  // q.v. C++ [namespace.unnamed]
265c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  bool isAnonymousNamespace() const {
266c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    return !getIdentifier();
267c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  }
268c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
269c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  NamespaceDecl *getNextNamespace() { return NextNamespace; }
270c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  const NamespaceDecl *getNextNamespace() const { return NextNamespace; }
271c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  void setNextNamespace(NamespaceDecl *ND) { NextNamespace = ND; }
272c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
273c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  NamespaceDecl *getOriginalNamespace() const {
274c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    return OrigNamespace;
275c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  }
276c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  void setOriginalNamespace(NamespaceDecl *ND) { OrigNamespace = ND; }
277c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
278c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  virtual NamespaceDecl *getCanonicalDecl() { return OrigNamespace; }
279c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  const NamespaceDecl *getCanonicalDecl() const { return OrigNamespace; }
280c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
281c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  virtual SourceRange getSourceRange() const {
282c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    return SourceRange(getLocation(), RBracLoc);
283c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  }
284c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
285c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  SourceLocation getLBracLoc() const { return LBracLoc; }
286c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  SourceLocation getRBracLoc() const { return RBracLoc; }
287c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  void setLBracLoc(SourceLocation LBrace) { LBracLoc = LBrace; }
288c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  void setRBracLoc(SourceLocation RBrace) { RBracLoc = RBrace; }
289c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
290c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  // Implement isa/cast/dyncast/etc.
291c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  static bool classof(const Decl *D) { return D->getKind() == Namespace; }
292c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  static bool classof(const NamespaceDecl *D) { return true; }
293c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  static DeclContext *castToDeclContext(const NamespaceDecl *D) {
294c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    return static_cast<DeclContext *>(const_cast<NamespaceDecl*>(D));
295c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  }
296c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  static NamespaceDecl *castFromDeclContext(const DeclContext *DC) {
297c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    return static_cast<NamespaceDecl *>(const_cast<DeclContext*>(DC));
298c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  }
299c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott};
300c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
301c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott/// ValueDecl - Represent the declaration of a variable (in which case it is
302c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott/// an lvalue) a function (in which case it is a function designator) or
303c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch/// an enum constant.
3043345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrickclass ValueDecl : public NamedDecl {
305c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  QualType DeclType;
306c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
307c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottprotected:
308c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  ValueDecl(Kind DK, DeclContext *DC, SourceLocation L,
309c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott            DeclarationName N, QualType T)
310c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    : NamedDecl(DK, DC, L, N), DeclType(T) {}
311c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottpublic:
312c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  QualType getType() const { return DeclType; }
313c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  void setType(QualType newType) { DeclType = newType; }
314c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
315c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  // Implement isa/cast/dyncast/etc.
316c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  static bool classof(const Decl *D) {
317c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    return D->getKind() >= ValueFirst && D->getKind() <= ValueLast;
318c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  }
319c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  static bool classof(const ValueDecl *D) { return true; }
320c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott};
321c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
322c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott/// \brief Represents a ValueDecl that came out of a declarator.
323c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott/// Contains type source information through DeclaratorInfo.
324c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottclass DeclaratorDecl : public ValueDecl {
325c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  DeclaratorInfo *DeclInfo;
326c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
327c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottprotected:
328c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  DeclaratorDecl(Kind DK, DeclContext *DC, SourceLocation L,
329c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott                 DeclarationName N, QualType T, DeclaratorInfo *DInfo)
330c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    : ValueDecl(DK, DC, L, N, T), DeclInfo(DInfo) {}
331c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
332c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottpublic:
333c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  DeclaratorInfo *getDeclaratorInfo() const { return DeclInfo; }
3343345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  void setDeclaratorInfo(DeclaratorInfo *DInfo) { DeclInfo = DInfo; }
3353345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick
336c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  SourceLocation getTypeSpecStartLoc() const;
337c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
338c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  // Implement isa/cast/dyncast/etc.
339c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  static bool classof(const Decl *D) {
340c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    return D->getKind() >= DeclaratorFirst && D->getKind() <= DeclaratorLast;
341c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  }
342c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  static bool classof(const DeclaratorDecl *D) { return true; }
343c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott};
344c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
345c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott/// \brief Structure used to store a statement, the constant value to
346c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott/// which it was evaluated (if any), and whether or not the statement
347c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott/// is an integral constant expression (if known).
348c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottstruct EvaluatedStmt {
3493345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  EvaluatedStmt() : WasEvaluated(false), CheckedICE(false), IsICE(false) { }
3503345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick
351c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// \brief Whether this statement was already evaluated.
352c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  bool WasEvaluated : 1;
353c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
354c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// \brief Whether we already checked whether this statement was an
355c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// integral constant expression.
356c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  bool CheckedICE : 1;
357c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
358c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// \brief Whether this statement is an integral constant
359c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// expression. Only valid if CheckedICE is true.
360c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  bool IsICE : 1;
361c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
362c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  Stmt *Value;
363c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  APValue Evaluated;
364c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott};
365c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
3663345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick// \brief Describes the kind of template specialization that a
3673345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick// particular template specialization declaration represents.
368c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottenum TemplateSpecializationKind {
369c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// This template specialization was formed from a template-id but
3703345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  /// has not yet been declared, defined, or instantiated.
371c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  TSK_Undeclared = 0,
372c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// This template specialization was implicitly instantiated from a
3733345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  /// template. (C++ [temp.inst]).
374c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  TSK_ImplicitInstantiation,
375c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// This template specialization was declared or defined by an
3763345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  /// explicit specialization (C++ [temp.expl.spec]) or partial
377c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// specialization (C++ [temp.class.spec]).
378c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  TSK_ExplicitSpecialization,
379c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// This template specialization was instantiated from a template
380c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// due to an explicit instantiation declaration request
381c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// (C++0x [temp.explicit]).
382c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  TSK_ExplicitInstantiationDeclaration,
383c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// This template specialization was instantiated from a template
384c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// due to an explicit instantiation definition request
385c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// (C++ [temp.explicit]).
386c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  TSK_ExplicitInstantiationDefinition
387c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott};
388c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
389c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott/// VarDecl - An instance of this class is created to represent a variable
3903345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick/// declaration or definition.
391c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottclass VarDecl : public DeclaratorDecl, public Redeclarable<VarDecl> {
392c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottpublic:
393c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  enum StorageClass {
3943345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    None, Auto, Register, Extern, Static, PrivateExtern
395c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  };
396c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
397c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// getStorageClassSpecifierString - Return the string used to
3983345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  /// specify the storage class \arg SC.
399c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  ///
400c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// It is illegal to call this function with SC == None.
401c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  static const char *getStorageClassSpecifierString(StorageClass SC);
4023345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick
403c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottprotected:
404c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// \brief Placeholder type used in Init to denote an unparsed C++ default
405c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// argument.
406c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  struct UnparsedDefaultArgument;
4073345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick
4083345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  /// \brief Placeholder type used in Init to denote an uninstantiated C++
409c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// default argument.
410c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  struct UninstantiatedDefaultArgument;
411c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
4123345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  typedef llvm::PointerUnion4<Stmt *, EvaluatedStmt *,
413c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott                              UnparsedDefaultArgument *,
414c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott                              UninstantiatedDefaultArgument *> InitType;
415c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
416c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// \brief The initializer for this variable or, for a ParmVarDecl, the
417c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// C++ default argument.
418c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  mutable InitType Init;
419c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
420c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottprivate:
421c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  // FIXME: This can be packed into the bitfields in Decl.
422c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  unsigned SClass : 3;
423c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  bool ThreadSpecified : 1;
4243345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  bool HasCXXDirectInit : 1;
4253345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick
4263345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  /// DeclaredInCondition - Whether this variable was declared in a
427c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// condition, e.g., if (int x = foo()) { ... }.
428c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  bool DeclaredInCondition : 1;
4293345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick
430c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  friend class StmtIteratorBase;
431c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottprotected:
432c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  VarDecl(Kind DK, DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
433c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott          QualType T, DeclaratorInfo *DInfo, StorageClass SC)
434c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    : DeclaratorDecl(DK, DC, L, Id, T, DInfo), Init(),
435c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott      ThreadSpecified(false), HasCXXDirectInit(false),
436c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott      DeclaredInCondition(false) {
437c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    SClass = SC;
438c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  }
439c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
440c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  typedef Redeclarable<VarDecl> redeclarable_base;
441c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  virtual VarDecl *getNextRedeclaration() { return RedeclLink.getNext(); }
442c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
4433345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrickpublic:
444c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  typedef redeclarable_base::redecl_iterator redecl_iterator;
445c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  redecl_iterator redecls_begin() const {
446c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    return redeclarable_base::redecls_begin();
447c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  }
448c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  redecl_iterator redecls_end() const {
449c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    return redeclarable_base::redecls_end();
450c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  }
451c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
4523345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  static VarDecl *Create(ASTContext &C, DeclContext *DC,
453c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott                         SourceLocation L, IdentifierInfo *Id,
454c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott                         QualType T, DeclaratorInfo *DInfo, StorageClass S);
455c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
456c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  virtual ~VarDecl();
457c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  virtual void Destroy(ASTContext& C);
458c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
459c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  StorageClass getStorageClass() const { return (StorageClass)SClass; }
460c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  void setStorageClass(StorageClass SC) { SClass = SC; }
4613345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick
462c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  virtual SourceRange getSourceRange() const;
463c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
464c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  const Expr *getInit() const {
465c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    if (Init.isNull())
466c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott      return 0;
467c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
468c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    const Stmt *S = Init.dyn_cast<Stmt *>();
469c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    if (!S) {
470c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch      if (EvaluatedStmt *ES = Init.dyn_cast<EvaluatedStmt*>())
471c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        S = ES->Value;
472c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    }
473c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    return (const Expr*) S;
474c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  }
475c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  Expr *getInit() {
476c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    if (Init.isNull())
477c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott      return 0;
478c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
4793345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    Stmt *S = Init.dyn_cast<Stmt *>();
4803345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    if (!S) {
481c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott      if (EvaluatedStmt *ES = Init.dyn_cast<EvaluatedStmt*>())
482c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        S = ES->Value;
483c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    }
484c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
485c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    return (Expr*) S;
486c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  }
487c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
4883345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  /// \brief Retrieve the address of the initializer expression.
4893345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  Stmt **getInitAddress() {
4903345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    if (EvaluatedStmt *ES = Init.dyn_cast<EvaluatedStmt*>())
4913345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick      return &ES->Value;
4923345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick
4933345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    // This union hack tip-toes around strict-aliasing rules.
4943345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    union {
4953345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick      InitType *InitPtr;
496c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott      Stmt **StmtPtr;
4973345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    };
498c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
4993345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    InitPtr = &Init;
5003345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    return StmtPtr;
501c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  }
502c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
5033345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  void setInit(ASTContext &C, Expr *I);
504c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
505c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// \brief Note that constant evaluation has computed the given
506c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// value for this variable's initializer.
507c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  void setEvaluatedValue(ASTContext &C, const APValue &Value) const {
508c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    EvaluatedStmt *Eval = Init.dyn_cast<EvaluatedStmt *>();
509c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    if (!Eval) {
510c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott      Stmt *S = Init.get<Stmt *>();
511c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott      Eval = new (C) EvaluatedStmt;
512c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott      Eval->Value = S;
513c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott      Init = Eval;
514c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    }
515c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
5163345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    Eval->WasEvaluated = true;
517c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    Eval->Evaluated = Value;
518c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  }
519c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
520c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// \brief Return the already-evaluated value of this variable's
521c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// initializer, or NULL if the value is not yet known.
522c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  APValue *getEvaluatedValue() const {
523c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    if (EvaluatedStmt *Eval = Init.dyn_cast<EvaluatedStmt *>())
524c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott      if (Eval->WasEvaluated)
525c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott        return &Eval->Evaluated;
526c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
527c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    return 0;
528c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  }
5293345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick
530c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// \brief Determines whether it is already known whether the
531c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// initializer is an integral constant expression or not.
532c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  bool isInitKnownICE() const {
533c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    if (EvaluatedStmt *Eval = Init.dyn_cast<EvaluatedStmt *>())
534c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott      return Eval->CheckedICE;
535c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
536c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    return false;
537c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  }
538c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
539c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// \brief Determines whether the initializer is an integral
540c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// constant expression.
541c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  ///
5423345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  /// \pre isInitKnownICE()
543c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  bool isInitICE() const {
5443345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    assert(isInitKnownICE() &&
545c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott           "Check whether we already know that the initializer is an ICE");
546c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    return Init.get<EvaluatedStmt *>()->IsICE;
547c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  }
548c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
549c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// \brief Note that we now know whether the initializer is an
550c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// integral constant expression.
551c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  void setInitKnownICE(ASTContext &C, bool IsICE) const {
552c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    EvaluatedStmt *Eval = Init.dyn_cast<EvaluatedStmt *>();
553c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    if (!Eval) {
554c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott      Stmt *S = Init.get<Stmt *>();
5553345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick      Eval = new (C) EvaluatedStmt;
556c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott      Eval->Value = S;
557c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott      Init = Eval;
5583345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    }
559c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
560c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    Eval->CheckedICE = true;
561c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    Eval->IsICE = IsICE;
562c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  }
563c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
564731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  /// \brief Retrieve the definition of this variable, which may come
565731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  /// from a previous declaration. Def will be set to the VarDecl that
566731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  /// contains the initializer, and the result will be that
567731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  /// initializer.
568731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  const Expr *getDefinition(const VarDecl *&Def) const;
569731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
570731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  void setThreadSpecified(bool T) { ThreadSpecified = T; }
571731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  bool isThreadSpecified() const {
572731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick    return ThreadSpecified;
573c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  }
5743345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick
575c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  void setCXXDirectInitializer(bool T) { HasCXXDirectInit = T; }
576c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
5773345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  /// hasCXXDirectInitializer - If true, the initializer was a direct
578c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// initializer, e.g: "int x(1);". The Init expression will be the expression
579c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// inside the parens or a "ClassType(a,b,c)" class constructor expression for
580c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// class types. Clients can distinguish between "int x(1);" and "int x=1;"
581c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// by checking hasCXXDirectInitializer.
582c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  ///
583c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  bool hasCXXDirectInitializer() const {
5843345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    return HasCXXDirectInit;
585c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  }
586c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
5873345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  /// isDeclaredInCondition - Whether this variable was declared as
588c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// part of a condition in an if/switch/while statement, e.g.,
589c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// @code
5903345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  /// if (int x = foo()) { ... }
591c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// @endcode
592c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  bool isDeclaredInCondition() const {
593c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    return DeclaredInCondition;
5943345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  }
595c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  void setDeclaredInCondition(bool InCondition) {
596c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    DeclaredInCondition = InCondition;
5973345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  }
598c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
599c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  virtual VarDecl *getCanonicalDecl();
600c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  const VarDecl *getCanonicalDecl() const {
601c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    return const_cast<VarDecl*>(this)->getCanonicalDecl();
602c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  }
603c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
604c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// hasLocalStorage - Returns true if a variable with function scope
605c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  ///  is a non-static local variable.
606c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  bool hasLocalStorage() const {
6073345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    if (getStorageClass() == None)
608c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott      return !isFileVarDecl();
609c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
6103345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    // Return true for:  Auto, Register.
611c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    // Return false for: Extern, Static, PrivateExtern.
612c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
613c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    return getStorageClass() <= Register;
614c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  }
615c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
616c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// hasExternStorage - Returns true if a variable has extern or
617c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// __private_extern__ storage.
618c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  bool hasExternalStorage() const {
619c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    return getStorageClass() == Extern || getStorageClass() == PrivateExtern;
6203345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  }
6213345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick
6223345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  /// hasGlobalStorage - Returns true for all variables that do not
623c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  ///  have local storage.  This includs all global variables as well
624c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  ///  as static variables declared within a function.
6253345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  bool hasGlobalStorage() const { return !hasLocalStorage(); }
626c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
627c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// isBlockVarDecl - Returns true for local variable declarations.  Note that
628c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// this includes static variables inside of functions.
629c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  ///
630c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  ///   void foo() { int x; static int y; extern int z; }
631c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  ///
632c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  bool isBlockVarDecl() const {
633c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    if (getKind() != Decl::Var)
634c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott      return false;
635c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    if (const DeclContext *DC = getDeclContext())
6363345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick      return DC->getLookupContext()->isFunctionOrMethod();
637c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    return false;
6383345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  }
639c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
640c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// \brief Determines whether this is a static data member.
641c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  ///
642c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// This will only be true in C++, and applies to, e.g., the
643c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// variable 'x' in:
644c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// \code
645c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// struct S {
646c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  ///   static int x;
647c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// };
648c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// \endcode
649c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  bool isStaticDataMember() const {
650c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    return getDeclContext()->isRecord();
651c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  }
652c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
653c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// \brief Determine whether this is or was instantiated from an out-of-line
654c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// definition of a static data member.
655c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  bool isOutOfLine() const;
656c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
657c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  /// \brief If this is a static data member, find its out-of-line definition.
658c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  VarDecl *getOutOfLineDefinition();
659c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
660c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  /// \brief If this variable is an instantiated static data member of a
661c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  /// class template specialization, returns the templated static data member
662c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  /// from which it was instantiated.
663c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  VarDecl *getInstantiatedFromStaticDataMember() const;
664c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
665c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  /// \brief If this variable is a static data member, determine what kind of
666c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  /// template specialization or instantiation this is.
667c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  TemplateSpecializationKind getTemplateSpecializationKind() const;
668c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
669c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  /// \brief If this variable is an instantiation of a static data member of a
670c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  /// class template specialization, retrieves the member specialization
671c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  /// information.
672c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  MemberSpecializationInfo *getMemberSpecializationInfo() const;
673c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
674c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  /// \brief For a static data member that was instantiated from a static
675c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  /// data member of a class template, set the template specialiation kind.
676c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void setTemplateSpecializationKind(TemplateSpecializationKind TSK,
6773345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick                        SourceLocation PointOfInstantiation = SourceLocation());
6783345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick
6793345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  /// isFileVarDecl - Returns true for file scoped variable declaration.
6803345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  bool isFileVarDecl() const {
6813345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    if (getKind() != Decl::Var)
6823345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick      return false;
6833345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    if (const DeclContext *Ctx = getDeclContext()) {
6843345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick      Ctx = Ctx->getLookupContext();
6853345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick      if (isa<TranslationUnitDecl>(Ctx) || isa<NamespaceDecl>(Ctx) )
6863345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick        return true;
6873345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    }
6883345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    if (isStaticDataMember())
6893345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick      return true;
6903345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick
6913345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    return false;
6923345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  }
6933345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick
6943345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  /// \brief Determine whether this is a tentative definition of a
6953345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  /// variable in C.
6963345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  bool isTentativeDefinition(ASTContext &Context) const;
6973345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick
6983345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  /// \brief Determines whether this variable is a variable with
6993345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  /// external, C linkage.
7003345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  bool isExternC() const;
7013345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick
7023345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  // Implement isa/cast/dyncast/etc.
7033345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  static bool classof(const Decl *D) {
7043345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    return D->getKind() >= VarFirst && D->getKind() <= VarLast;
7053345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  }
7063345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  static bool classof(const VarDecl *D) { return true; }
7073345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick};
7083345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick
7093345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrickclass ImplicitParamDecl : public VarDecl {
7103345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrickprotected:
7113345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  ImplicitParamDecl(Kind DK, DeclContext *DC, SourceLocation L,
7123345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick                    IdentifierInfo *Id, QualType Tw)
7133345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    : VarDecl(DK, DC, L, Id, Tw, /*DInfo=*/0, VarDecl::None) {}
7143345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrickpublic:
7153345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  static ImplicitParamDecl *Create(ASTContext &C, DeclContext *DC,
7163345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick                                   SourceLocation L, IdentifierInfo *Id,
7173345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick                                   QualType T);
7183345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  // Implement isa/cast/dyncast/etc.
7193345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  static bool classof(const ImplicitParamDecl *D) { return true; }
7203345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  static bool classof(const Decl *D) { return D->getKind() == ImplicitParam; }
7213345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick};
7223345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick
7233345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick/// ParmVarDecl - Represent a parameter to a function.
7243345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrickclass ParmVarDecl : public VarDecl {
7253345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  // NOTE: VC++ treats enums as signed, avoid using the ObjCDeclQualifier enum
7263345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  /// FIXME: Also can be paced into the bitfields in Decl.
7273345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  /// in, inout, etc.
7283345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  unsigned objcDeclQualifier : 6;
7293345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick
7303345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  /// \brief Retrieves the fake "value" of an unparsed
7313345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  static Expr *getUnparsedDefaultArgValue() {
7323345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    uintptr_t Value = (uintptr_t)-1;
7333345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    // Mask off the low bits
7343345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    Value &= ~(uintptr_t)0x07;
7353345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    return reinterpret_cast<Expr*> (Value);
7363345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  }
7373345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick
7383345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrickprotected:
7393345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  ParmVarDecl(Kind DK, DeclContext *DC, SourceLocation L,
7403345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick              IdentifierInfo *Id, QualType T, DeclaratorInfo *DInfo,
7413345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick              StorageClass S, Expr *DefArg)
7423345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  : VarDecl(DK, DC, L, Id, T, DInfo, S), objcDeclQualifier(OBJC_TQ_None) {
7433345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    setDefaultArg(DefArg);
7443345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  }
7453345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick
7463345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrickpublic:
7473345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  static ParmVarDecl *Create(ASTContext &C, DeclContext *DC,
7483345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick                             SourceLocation L,IdentifierInfo *Id,
7493345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick                             QualType T, DeclaratorInfo *DInfo,
7503345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick                             StorageClass S, Expr *DefArg);
7513345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick
7523345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  ObjCDeclQualifier getObjCDeclQualifier() const {
7533345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    return ObjCDeclQualifier(objcDeclQualifier);
7543345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  }
7553345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  void setObjCDeclQualifier(ObjCDeclQualifier QTVal) {
7563345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    objcDeclQualifier = QTVal;
7573345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  }
7583345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick
7593345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  const Expr *getDefaultArg() const {
7603345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    assert(!hasUnparsedDefaultArg() && "Default argument is not yet parsed!");
7613345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    assert(!hasUninstantiatedDefaultArg() &&
7623345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick           "Default argument is not yet instantiated!");
7633345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    return getInit();
7643345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  }
7653345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  Expr *getDefaultArg() {
7663345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    assert(!hasUnparsedDefaultArg() && "Default argument is not yet parsed!");
7673345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    assert(!hasUninstantiatedDefaultArg() &&
7683345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick           "Default argument is not yet instantiated!");
7693345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    return getInit();
7703345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  }
7713345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  void setDefaultArg(Expr *defarg) {
7723345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    Init = reinterpret_cast<Stmt *>(defarg);
7733345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  }
7743345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick
7753345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  /// \brief Retrieve the source range that covers the entire default
7763345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  /// argument.
7773345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  SourceRange getDefaultArgRange() const;
7783345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  void setUninstantiatedDefaultArg(Expr *arg) {
7793345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    Init = reinterpret_cast<UninstantiatedDefaultArgument *>(arg);
7803345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  }
7813345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  Expr *getUninstantiatedDefaultArg() {
7823345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    return (Expr *)Init.get<UninstantiatedDefaultArgument *>();
7833345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  }
7843345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  const Expr *getUninstantiatedDefaultArg() const {
785c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    return (const Expr *)Init.get<UninstantiatedDefaultArgument *>();
786c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  }
787c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
788c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  /// hasDefaultArg - Determines whether this parameter has a default argument,
789c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  /// either parsed or not.
790c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  bool hasDefaultArg() const {
791c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    return getInit() || hasUnparsedDefaultArg() ||
792c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott      hasUninstantiatedDefaultArg();
793c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  }
794c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
795c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// hasUnparsedDefaultArg - Determines whether this parameter has a
796c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// default argument that has not yet been parsed. This will occur
797c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// during the processing of a C++ class whose member functions have
798c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// default arguments, e.g.,
799c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// @code
800c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  ///   class X {
801c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  ///   public:
802c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  ///     void f(int x = 17); // x has an unparsed default argument now
803c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  ///   }; // x has a regular default argument now
804c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// @endcode
805c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  bool hasUnparsedDefaultArg() const {
806c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    return Init.is<UnparsedDefaultArgument*>();
807c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  }
808c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
809c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  bool hasUninstantiatedDefaultArg() const {
810c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    return Init.is<UninstantiatedDefaultArgument*>();
811c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  }
812c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
813c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// setUnparsedDefaultArg - Specify that this parameter has an
814c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// unparsed default argument. The argument will be replaced with a
815c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// real default argument via setDefaultArg when the class
816c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// definition enclosing the function declaration that owns this
817c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// default argument is completed.
818c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  void setUnparsedDefaultArg() {
819c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    Init = (UnparsedDefaultArgument *)0;
820c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  }
821c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
822c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  QualType getOriginalType() const {
823c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    if (getDeclaratorInfo())
824c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott      return getDeclaratorInfo()->getType();
825c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    return getType();
826c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  }
827c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
828c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// setOwningFunction - Sets the function declaration that owns this
829c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// ParmVarDecl. Since ParmVarDecls are often created before the
830c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// FunctionDecls that own them, this routine is required to update
831c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// the DeclContext appropriately.
832c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  void setOwningFunction(DeclContext *FD) { setDeclContext(FD); }
833c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
834c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  // Implement isa/cast/dyncast/etc.
835c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  static bool classof(const Decl *D) {
836c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    return (D->getKind() == ParmVar);
837c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  }
838c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  static bool classof(const ParmVarDecl *D) { return true; }
839c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott};
840c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
841c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott/// FunctionDecl - An instance of this class is created to represent a
842c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott/// function declaration or definition.
843c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott///
844c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott/// Since a given function can be declared several times in a program,
845c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott/// there may be several FunctionDecls that correspond to that
846c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott/// function. Only one of those FunctionDecls will be found when
847c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott/// traversing the list of declarations in the context of the
848c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott/// FunctionDecl (e.g., the translation unit); this FunctionDecl
849c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott/// contains all of the information known about the function. Other,
850c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott/// previous declarations of the function are available via the
851c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott/// getPreviousDeclaration() chain.
852c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottclass FunctionDecl : public DeclaratorDecl, public DeclContext,
853c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott                     public Redeclarable<FunctionDecl> {
854c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottpublic:
855c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  enum StorageClass {
856c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    None, Extern, Static, PrivateExtern
857c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  };
858c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
8593345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrickprivate:
860c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// ParamInfo - new[]'d array of pointers to VarDecls for the formal
861c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// parameters of this function.  This is null if a prototype or if there are
862c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// no formals.
863c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  ParmVarDecl **ParamInfo;
864c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
865c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  LazyDeclStmtPtr Body;
866c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
867c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  // FIXME: This can be packed into the bitfields in Decl.
868c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  // NOTE: VC++ treats enums as signed, avoid using the StorageClass enum
869c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  unsigned SClass : 2;
870c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  bool IsInline : 1;
871c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  bool IsVirtualAsWritten : 1;
872c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  bool IsPure : 1;
873c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  bool HasInheritedPrototype : 1;
874c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  bool HasWrittenPrototype : 1;
875c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  bool IsDeleted : 1;
876c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  bool IsTrivial : 1; // sunk from CXXMethodDecl
877c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  bool IsCopyAssignment : 1;  // sunk from CXXMethodDecl
878c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  bool HasImplicitReturnZero : 1;
879c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
880c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// \brief End part of this FunctionDecl's source range.
881c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  ///
882c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// We could compute the full range in getSourceRange(). However, when we're
883c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// dealing with a function definition deserialized from a PCH/AST file,
884c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// we can only compute the full range once the function body has been
885c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// de-serialized, so it's far better to have the (sometimes-redundant)
886c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// EndRangeLoc.
887c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  SourceLocation EndRangeLoc;
888c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
889c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// \brief The template or declaration that this declaration
890c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// describes or was instantiated from, respectively.
891c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  ///
892c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// For non-templates, this value will be NULL. For function
893c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// declarations that describe a function template, this will be a
894c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// pointer to a FunctionTemplateDecl. For member functions
895c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// of class template specializations, this will be a MemberSpecializationInfo
896c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// pointer containing information about the specialization.
897c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// For function template specializations, this will be a
898c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// FunctionTemplateSpecializationInfo, which contains information about
899c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// the template being specialized and the template arguments involved in
900c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// that specialization.
901c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  llvm::PointerUnion3<FunctionTemplateDecl *,
902c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott                      MemberSpecializationInfo *,
903c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott                      FunctionTemplateSpecializationInfo *>
904c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    TemplateOrSpecialization;
905c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
906c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottprotected:
907c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  FunctionDecl(Kind DK, DeclContext *DC, SourceLocation L,
908c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott               DeclarationName N, QualType T, DeclaratorInfo *DInfo,
909c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott               StorageClass S, bool isInline)
910c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    : DeclaratorDecl(DK, DC, L, N, T, DInfo),
911c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott      DeclContext(DK),
912c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott      ParamInfo(0), Body(),
913c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott      SClass(S), IsInline(isInline),
914c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott      IsVirtualAsWritten(false), IsPure(false), HasInheritedPrototype(false),
915c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott      HasWrittenPrototype(true), IsDeleted(false), IsTrivial(false),
916c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott      IsCopyAssignment(false),
917c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott      HasImplicitReturnZero(false),
918c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott      EndRangeLoc(L), TemplateOrSpecialization() {}
919c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
920c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  virtual ~FunctionDecl() {}
921c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  virtual void Destroy(ASTContext& C);
922c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
923c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  typedef Redeclarable<FunctionDecl> redeclarable_base;
924c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual FunctionDecl *getNextRedeclaration() { return RedeclLink.getNext(); }
925c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
926c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochpublic:
927c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  typedef redeclarable_base::redecl_iterator redecl_iterator;
928c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  redecl_iterator redecls_begin() const {
929c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    return redeclarable_base::redecls_begin();
930c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  }
931c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  redecl_iterator redecls_end() const {
932c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    return redeclarable_base::redecls_end();
933c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  }
934c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
935c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  static FunctionDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L,
936c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott                              DeclarationName N, QualType T,
937c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott                              DeclaratorInfo *DInfo,
938c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch                              StorageClass S = None, bool isInline = false,
939c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch                              bool hasWrittenPrototype = true);
940c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
941c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual void getNameForDiagnostic(std::string &S,
942c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch                                    const PrintingPolicy &Policy,
943c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch                                    bool Qualified) const;
944c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
945c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual SourceRange getSourceRange() const {
946c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    return SourceRange(getLocation(), EndRangeLoc);
947c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  }
948c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  void setLocEnd(SourceLocation E) {
949c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    EndRangeLoc = E;
950c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  }
951c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
952c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// getBody - Retrieve the body (definition) of the function. The
953c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// function body might be in any of the (re-)declarations of this
954c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// function. The variant that accepts a FunctionDecl pointer will
955c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// set that function declaration to the actual declaration
956c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// containing the body (if there is one).
957c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  Stmt *getBody(const FunctionDecl *&Definition) const;
958c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
959c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  virtual Stmt *getBody() const {
960c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    const FunctionDecl* Definition;
961c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott    return getBody(Definition);
962c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  }
963c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
964c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// isThisDeclarationADefinition - Returns whether this specific
965c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// declaration of the function is also a definition. This does not
966c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// determine whether the function has been defined (e.g., in a
967c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// previous definition); for that information, use getBody.
968c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// FIXME: Should return true if function is deleted or defaulted. However,
969c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// CodeGenModule.cpp uses it, and I don't know if this would break it.
970c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  bool isThisDeclarationADefinition() const { return Body; }
971c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
972c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  void setBody(Stmt *B);
973c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  void setLazyBody(uint64_t Offset) { Body = Offset; }
974c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
975c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// Whether this function is marked as virtual explicitly.
976c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  bool isVirtualAsWritten() const { return IsVirtualAsWritten; }
977c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  void setVirtualAsWritten(bool V) { IsVirtualAsWritten = V; }
978c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
979c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// Whether this virtual function is pure, i.e. makes the containing class
980c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  /// abstract.
981c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  bool isPure() const { return IsPure; }
982c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott  void setPure(bool P = true) { IsPure = P; }
983c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
984c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  /// Whether this function is "trivial" in some specialized C++ senses.
985c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  /// Can only be true for default constructors, copy constructors,
986c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  /// copy assignment operators, and destructors.  Not meaningful until
987  /// the class has been fully built by Sema.
988  bool isTrivial() const { return IsTrivial; }
989  void setTrivial(bool IT) { IsTrivial = IT; }
990
991  bool isCopyAssignment() const { return IsCopyAssignment; }
992  void setCopyAssignment(bool CA) { IsCopyAssignment = CA; }
993
994  /// Whether falling off this function implicitly returns null/zero.
995  /// If a more specific implicit return value is required, front-ends
996  /// should synthesize the appropriate return statements.
997  bool hasImplicitReturnZero() const { return HasImplicitReturnZero; }
998  void setHasImplicitReturnZero(bool IRZ) { HasImplicitReturnZero = IRZ; }
999
1000  /// \brief Whether this function has a prototype, either because one
1001  /// was explicitly written or because it was "inherited" by merging
1002  /// a declaration without a prototype with a declaration that has a
1003  /// prototype.
1004  bool hasPrototype() const {
1005    return HasWrittenPrototype || HasInheritedPrototype;
1006  }
1007
1008  bool hasWrittenPrototype() const { return HasWrittenPrototype; }
1009  void setHasWrittenPrototype(bool P) { HasWrittenPrototype = P; }
1010
1011  /// \brief Whether this function inherited its prototype from a
1012  /// previous declaration.
1013  bool hasInheritedPrototype() const { return HasInheritedPrototype; }
1014  void setHasInheritedPrototype(bool P = true) { HasInheritedPrototype = P; }
1015
1016  /// \brief Whether this function has been deleted.
1017  ///
1018  /// A function that is "deleted" (via the C++0x "= delete" syntax)
1019  /// acts like a normal function, except that it cannot actually be
1020  /// called or have its address taken. Deleted functions are
1021  /// typically used in C++ overload resolution to attract arguments
1022  /// whose type or lvalue/rvalue-ness would permit the use of a
1023  /// different overload that would behave incorrectly. For example,
1024  /// one might use deleted functions to ban implicit conversion from
1025  /// a floating-point number to an Integer type:
1026  ///
1027  /// @code
1028  /// struct Integer {
1029  ///   Integer(long); // construct from a long
1030  ///   Integer(double) = delete; // no construction from float or double
1031  ///   Integer(long double) = delete; // no construction from long double
1032  /// };
1033  /// @endcode
1034  bool isDeleted() const { return IsDeleted; }
1035  void setDeleted(bool D = true) { IsDeleted = D; }
1036
1037  /// \brief Determines whether this is a function "main", which is
1038  /// the entry point into an executable program.
1039  bool isMain() const;
1040
1041  /// \brief Determines whether this function is a function with
1042  /// external, C linkage.
1043  bool isExternC() const;
1044
1045  /// \brief Determines whether this is a global function.
1046  bool isGlobal() const;
1047
1048  void setPreviousDeclaration(FunctionDecl * PrevDecl);
1049
1050  virtual const FunctionDecl *getCanonicalDecl() const;
1051  virtual FunctionDecl *getCanonicalDecl();
1052
1053  unsigned getBuiltinID() const;
1054
1055  unsigned getNumParmVarDeclsFromType() const;
1056
1057  // Iterator access to formal parameters.
1058  unsigned param_size() const { return getNumParams(); }
1059  typedef ParmVarDecl **param_iterator;
1060  typedef ParmVarDecl * const *param_const_iterator;
1061
1062  param_iterator param_begin() { return ParamInfo; }
1063  param_iterator param_end()   { return ParamInfo+param_size(); }
1064
1065  param_const_iterator param_begin() const { return ParamInfo; }
1066  param_const_iterator param_end() const   { return ParamInfo+param_size(); }
1067
1068  /// getNumParams - Return the number of parameters this function must have
1069  /// based on its functiontype.  This is the length of the PararmInfo array
1070  /// after it has been created.
1071  unsigned getNumParams() const;
1072
1073  const ParmVarDecl *getParamDecl(unsigned i) const {
1074    assert(i < getNumParams() && "Illegal param #");
1075    return ParamInfo[i];
1076  }
1077  ParmVarDecl *getParamDecl(unsigned i) {
1078    assert(i < getNumParams() && "Illegal param #");
1079    return ParamInfo[i];
1080  }
1081  void setParams(ASTContext& C, ParmVarDecl **NewParamInfo, unsigned NumParams);
1082
1083  /// getMinRequiredArguments - Returns the minimum number of arguments
1084  /// needed to call this function. This may be fewer than the number of
1085  /// function parameters, if some of the parameters have default
1086  /// arguments (in C++).
1087  unsigned getMinRequiredArguments() const;
1088
1089  QualType getResultType() const {
1090    return getType()->getAs<FunctionType>()->getResultType();
1091  }
1092  StorageClass getStorageClass() const { return StorageClass(SClass); }
1093  void setStorageClass(StorageClass SC) { SClass = SC; }
1094
1095  /// \brief Determine whether the "inline" keyword was specified for this
1096  /// function.
1097  bool isInlineSpecified() const { return IsInline; }
1098
1099  /// Set whether the "inline" keyword was specified for this function.
1100  void setInlineSpecified(bool I) { IsInline = I; }
1101
1102  /// \brief Determine whether this function should be inlined, because it is
1103  /// either marked "inline" or is a member function of a C++ class that
1104  /// was defined in the class body.
1105  bool isInlined() const;
1106
1107  bool isInlineDefinitionExternallyVisible() const;
1108
1109  /// isOverloadedOperator - Whether this function declaration
1110  /// represents an C++ overloaded operator, e.g., "operator+".
1111  bool isOverloadedOperator() const {
1112    return getOverloadedOperator() != OO_None;
1113  };
1114
1115  OverloadedOperatorKind getOverloadedOperator() const;
1116
1117  /// \brief If this function is an instantiation of a member function
1118  /// of a class template specialization, retrieves the function from
1119  /// which it was instantiated.
1120  ///
1121  /// This routine will return non-NULL for (non-templated) member
1122  /// functions of class templates and for instantiations of function
1123  /// templates. For example, given:
1124  ///
1125  /// \code
1126  /// template<typename T>
1127  /// struct X {
1128  ///   void f(T);
1129  /// };
1130  /// \endcode
1131  ///
1132  /// The declaration for X<int>::f is a (non-templated) FunctionDecl
1133  /// whose parent is the class template specialization X<int>. For
1134  /// this declaration, getInstantiatedFromFunction() will return
1135  /// the FunctionDecl X<T>::A. When a complete definition of
1136  /// X<int>::A is required, it will be instantiated from the
1137  /// declaration returned by getInstantiatedFromMemberFunction().
1138  FunctionDecl *getInstantiatedFromMemberFunction() const;
1139
1140  /// \brief If this function is an instantiation of a member function of a
1141  /// class template specialization, retrieves the member specialization
1142  /// information.
1143  MemberSpecializationInfo *getMemberSpecializationInfo() const;
1144
1145  /// \brief Specify that this record is an instantiation of the
1146  /// member function FD.
1147  void setInstantiationOfMemberFunction(FunctionDecl *FD,
1148                                        TemplateSpecializationKind TSK);
1149
1150  /// \brief Retrieves the function template that is described by this
1151  /// function declaration.
1152  ///
1153  /// Every function template is represented as a FunctionTemplateDecl
1154  /// and a FunctionDecl (or something derived from FunctionDecl). The
1155  /// former contains template properties (such as the template
1156  /// parameter lists) while the latter contains the actual
1157  /// description of the template's
1158  /// contents. FunctionTemplateDecl::getTemplatedDecl() retrieves the
1159  /// FunctionDecl that describes the function template,
1160  /// getDescribedFunctionTemplate() retrieves the
1161  /// FunctionTemplateDecl from a FunctionDecl.
1162  FunctionTemplateDecl *getDescribedFunctionTemplate() const {
1163    return TemplateOrSpecialization.dyn_cast<FunctionTemplateDecl*>();
1164  }
1165
1166  void setDescribedFunctionTemplate(FunctionTemplateDecl *Template) {
1167    TemplateOrSpecialization = Template;
1168  }
1169
1170  /// \brief Determine whether this function is a function template
1171  /// specialization.
1172  bool isFunctionTemplateSpecialization() const {
1173    return getPrimaryTemplate() != 0;
1174  }
1175
1176  /// \brief If this function is actually a function template specialization,
1177  /// retrieve information about this function template specialization.
1178  /// Otherwise, returns NULL.
1179  FunctionTemplateSpecializationInfo *getTemplateSpecializationInfo() const {
1180    return TemplateOrSpecialization.
1181             dyn_cast<FunctionTemplateSpecializationInfo*>();
1182  }
1183
1184  /// \brief Determines whether this function is a function template
1185  /// specialization or a member of a class template specialization that can
1186  /// be implicitly instantiated.
1187  bool isImplicitlyInstantiable() const;
1188
1189  /// \brief Retrieve the function declaration from which this function could
1190  /// be instantiated, if it is an instantiation (rather than a non-template
1191  /// or a specialization, for example).
1192  FunctionDecl *getTemplateInstantiationPattern() const;
1193
1194  /// \brief Retrieve the primary template that this function template
1195  /// specialization either specializes or was instantiated from.
1196  ///
1197  /// If this function declaration is not a function template specialization,
1198  /// returns NULL.
1199  FunctionTemplateDecl *getPrimaryTemplate() const;
1200
1201  /// \brief Retrieve the template arguments used to produce this function
1202  /// template specialization from the primary template.
1203  ///
1204  /// If this function declaration is not a function template specialization,
1205  /// returns NULL.
1206  const TemplateArgumentList *getTemplateSpecializationArgs() const;
1207
1208  /// \brief Specify that this function declaration is actually a function
1209  /// template specialization.
1210  ///
1211  /// \param Context the AST context in which this function resides.
1212  ///
1213  /// \param Template the function template that this function template
1214  /// specialization specializes.
1215  ///
1216  /// \param TemplateArgs the template arguments that produced this
1217  /// function template specialization from the template.
1218  ///
1219  /// \param InsertPos If non-NULL, the position in the function template
1220  /// specialization set where the function template specialization data will
1221  /// be inserted.
1222  ///
1223  /// \param TSK the kind of template specialization this is.
1224  void setFunctionTemplateSpecialization(ASTContext &Context,
1225                                         FunctionTemplateDecl *Template,
1226                                      const TemplateArgumentList *TemplateArgs,
1227                                         void *InsertPos,
1228                    TemplateSpecializationKind TSK = TSK_ImplicitInstantiation);
1229
1230  /// \brief Determine what kind of template instantiation this function
1231  /// represents.
1232  TemplateSpecializationKind getTemplateSpecializationKind() const;
1233
1234  /// \brief Determine what kind of template instantiation this function
1235  /// represents.
1236  void setTemplateSpecializationKind(TemplateSpecializationKind TSK,
1237                        SourceLocation PointOfInstantiation = SourceLocation());
1238
1239  /// \brief Retrieve the (first) point of instantiation of a function template
1240  /// specialization or a member of a class template specialization.
1241  ///
1242  /// \returns the first point of instantiation, if this function was
1243  /// instantiated from a template; otherwie, returns an invalid source
1244  /// location.
1245  SourceLocation getPointOfInstantiation() const;
1246
1247  /// \brief Determine whether this is or was instantiated from an out-of-line
1248  /// definition of a member function.
1249  bool isOutOfLine() const;
1250
1251  // Implement isa/cast/dyncast/etc.
1252  static bool classof(const Decl *D) {
1253    return D->getKind() >= FunctionFirst && D->getKind() <= FunctionLast;
1254  }
1255  static bool classof(const FunctionDecl *D) { return true; }
1256  static DeclContext *castToDeclContext(const FunctionDecl *D) {
1257    return static_cast<DeclContext *>(const_cast<FunctionDecl*>(D));
1258  }
1259  static FunctionDecl *castFromDeclContext(const DeclContext *DC) {
1260    return static_cast<FunctionDecl *>(const_cast<DeclContext*>(DC));
1261  }
1262};
1263
1264
1265/// FieldDecl - An instance of this class is created by Sema::ActOnField to
1266/// represent a member of a struct/union/class.
1267class FieldDecl : public DeclaratorDecl {
1268  // FIXME: This can be packed into the bitfields in Decl.
1269  bool Mutable : 1;
1270  Expr *BitWidth;
1271protected:
1272  FieldDecl(Kind DK, DeclContext *DC, SourceLocation L,
1273            IdentifierInfo *Id, QualType T, DeclaratorInfo *DInfo,
1274            Expr *BW, bool Mutable)
1275    : DeclaratorDecl(DK, DC, L, Id, T, DInfo), Mutable(Mutable), BitWidth(BW) {
1276  }
1277
1278public:
1279  static FieldDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L,
1280                           IdentifierInfo *Id, QualType T,
1281                           DeclaratorInfo *DInfo, Expr *BW, bool Mutable);
1282
1283  /// isMutable - Determines whether this field is mutable (C++ only).
1284  bool isMutable() const { return Mutable; }
1285
1286  /// \brief Set whether this field is mutable (C++ only).
1287  void setMutable(bool M) { Mutable = M; }
1288
1289  /// isBitfield - Determines whether this field is a bitfield.
1290  bool isBitField() const { return BitWidth != NULL; }
1291
1292  /// @brief Determines whether this is an unnamed bitfield.
1293  bool isUnnamedBitfield() const { return BitWidth != NULL && !getDeclName(); }
1294
1295  /// isAnonymousStructOrUnion - Determines whether this field is a
1296  /// representative for an anonymous struct or union. Such fields are
1297  /// unnamed and are implicitly generated by the implementation to
1298  /// store the data for the anonymous union or struct.
1299  bool isAnonymousStructOrUnion() const;
1300
1301  Expr *getBitWidth() const { return BitWidth; }
1302  void setBitWidth(Expr *BW) { BitWidth = BW; }
1303
1304  // Implement isa/cast/dyncast/etc.
1305  static bool classof(const Decl *D) {
1306    return D->getKind() >= FieldFirst && D->getKind() <= FieldLast;
1307  }
1308  static bool classof(const FieldDecl *D) { return true; }
1309};
1310
1311/// EnumConstantDecl - An instance of this object exists for each enum constant
1312/// that is defined.  For example, in "enum X {a,b}", each of a/b are
1313/// EnumConstantDecl's, X is an instance of EnumDecl, and the type of a/b is a
1314/// TagType for the X EnumDecl.
1315class EnumConstantDecl : public ValueDecl {
1316  Stmt *Init; // an integer constant expression
1317  llvm::APSInt Val; // The value.
1318protected:
1319  EnumConstantDecl(DeclContext *DC, SourceLocation L,
1320                   IdentifierInfo *Id, QualType T, Expr *E,
1321                   const llvm::APSInt &V)
1322    : ValueDecl(EnumConstant, DC, L, Id, T), Init((Stmt*)E), Val(V) {}
1323
1324  virtual ~EnumConstantDecl() {}
1325public:
1326
1327  static EnumConstantDecl *Create(ASTContext &C, EnumDecl *DC,
1328                                  SourceLocation L, IdentifierInfo *Id,
1329                                  QualType T, Expr *E,
1330                                  const llvm::APSInt &V);
1331
1332  virtual void Destroy(ASTContext& C);
1333
1334  const Expr *getInitExpr() const { return (const Expr*) Init; }
1335  Expr *getInitExpr() { return (Expr*) Init; }
1336  const llvm::APSInt &getInitVal() const { return Val; }
1337
1338  void setInitExpr(Expr *E) { Init = (Stmt*) E; }
1339  void setInitVal(const llvm::APSInt &V) { Val = V; }
1340
1341  // Implement isa/cast/dyncast/etc.
1342  static bool classof(const Decl *D) { return D->getKind() == EnumConstant; }
1343  static bool classof(const EnumConstantDecl *D) { return true; }
1344
1345  friend class StmtIteratorBase;
1346};
1347
1348
1349/// TypeDecl - Represents a declaration of a type.
1350///
1351class TypeDecl : public NamedDecl {
1352  /// TypeForDecl - This indicates the Type object that represents
1353  /// this TypeDecl.  It is a cache maintained by
1354  /// ASTContext::getTypedefType, ASTContext::getTagDeclType, and
1355  /// ASTContext::getTemplateTypeParmType, and TemplateTypeParmDecl.
1356  mutable Type *TypeForDecl;
1357  friend class ASTContext;
1358  friend class DeclContext;
1359  friend class TagDecl;
1360  friend class TemplateTypeParmDecl;
1361  friend class ClassTemplateSpecializationDecl;
1362  friend class TagType;
1363
1364protected:
1365  TypeDecl(Kind DK, DeclContext *DC, SourceLocation L,
1366           IdentifierInfo *Id)
1367    : NamedDecl(DK, DC, L, Id), TypeForDecl(0) {}
1368
1369public:
1370  // Low-level accessor
1371  Type *getTypeForDecl() const { return TypeForDecl; }
1372  void setTypeForDecl(Type *TD) { TypeForDecl = TD; }
1373
1374  // Implement isa/cast/dyncast/etc.
1375  static bool classof(const Decl *D) {
1376    return D->getKind() >= TypeFirst && D->getKind() <= TypeLast;
1377  }
1378  static bool classof(const TypeDecl *D) { return true; }
1379};
1380
1381
1382class TypedefDecl : public TypeDecl {
1383  /// UnderlyingType - This is the type the typedef is set to.
1384  DeclaratorInfo *DInfo;
1385
1386  TypedefDecl(DeclContext *DC, SourceLocation L,
1387              IdentifierInfo *Id, DeclaratorInfo *DInfo)
1388    : TypeDecl(Typedef, DC, L, Id), DInfo(DInfo) {}
1389
1390  virtual ~TypedefDecl() {}
1391public:
1392
1393  static TypedefDecl *Create(ASTContext &C, DeclContext *DC,
1394                             SourceLocation L, IdentifierInfo *Id,
1395                             DeclaratorInfo *DInfo);
1396
1397  DeclaratorInfo *getTypeDeclaratorInfo() const {
1398    return DInfo;
1399  }
1400
1401  QualType getUnderlyingType() const {
1402    return DInfo->getType();
1403  }
1404  void setTypeDeclaratorInfo(DeclaratorInfo *newType) {
1405    DInfo = newType;
1406  }
1407
1408  // Implement isa/cast/dyncast/etc.
1409  static bool classof(const Decl *D) { return D->getKind() == Typedef; }
1410  static bool classof(const TypedefDecl *D) { return true; }
1411};
1412
1413class TypedefDecl;
1414
1415/// TagDecl - Represents the declaration of a struct/union/class/enum.
1416class TagDecl
1417  : public TypeDecl, public DeclContext, public Redeclarable<TagDecl> {
1418public:
1419  // This is really ugly.
1420  typedef ElaboratedType::TagKind TagKind;
1421  static const TagKind TK_struct = ElaboratedType::TK_struct;
1422  static const TagKind TK_union = ElaboratedType::TK_union;
1423  static const TagKind TK_class = ElaboratedType::TK_class;
1424  static const TagKind TK_enum = ElaboratedType::TK_enum;
1425
1426private:
1427  // FIXME: This can be packed into the bitfields in Decl.
1428  /// TagDeclKind - The TagKind enum.
1429  unsigned TagDeclKind : 2;
1430
1431  /// IsDefinition - True if this is a definition ("struct foo {};"), false if
1432  /// it is a declaration ("struct foo;").
1433  bool IsDefinition : 1;
1434
1435  /// TypedefForAnonDecl - If a TagDecl is anonymous and part of a typedef,
1436  /// this points to the TypedefDecl. Used for mangling.
1437  TypedefDecl *TypedefForAnonDecl;
1438
1439  SourceLocation TagKeywordLoc;
1440  SourceLocation RBraceLoc;
1441
1442protected:
1443  TagDecl(Kind DK, TagKind TK, DeclContext *DC, SourceLocation L,
1444          IdentifierInfo *Id, TagDecl *PrevDecl,
1445          SourceLocation TKL = SourceLocation())
1446    : TypeDecl(DK, DC, L, Id), DeclContext(DK), TypedefForAnonDecl(0),
1447      TagKeywordLoc(TKL) {
1448    assert((DK != Enum || TK == TK_enum) &&"EnumDecl not matched with TK_enum");
1449    TagDeclKind = TK;
1450    IsDefinition = false;
1451    setPreviousDeclaration(PrevDecl);
1452  }
1453
1454  typedef Redeclarable<TagDecl> redeclarable_base;
1455  virtual TagDecl *getNextRedeclaration() { return RedeclLink.getNext(); }
1456
1457public:
1458  typedef redeclarable_base::redecl_iterator redecl_iterator;
1459  redecl_iterator redecls_begin() const {
1460    return redeclarable_base::redecls_begin();
1461  }
1462  redecl_iterator redecls_end() const {
1463    return redeclarable_base::redecls_end();
1464  }
1465
1466  SourceLocation getRBraceLoc() const { return RBraceLoc; }
1467  void setRBraceLoc(SourceLocation L) { RBraceLoc = L; }
1468
1469  SourceLocation getTagKeywordLoc() const { return TagKeywordLoc; }
1470  void setTagKeywordLoc(SourceLocation TKL) { TagKeywordLoc = TKL; }
1471
1472  virtual SourceRange getSourceRange() const;
1473
1474  virtual TagDecl* getCanonicalDecl();
1475  const TagDecl* getCanonicalDecl() const {
1476    return const_cast<TagDecl*>(this)->getCanonicalDecl();
1477  }
1478
1479  /// isDefinition - Return true if this decl has its body specified.
1480  bool isDefinition() const {
1481    return IsDefinition;
1482  }
1483
1484  /// \brief Whether this declaration declares a type that is
1485  /// dependent, i.e., a type that somehow depends on template
1486  /// parameters.
1487  bool isDependentType() const { return isDependentContext(); }
1488
1489  /// @brief Starts the definition of this tag declaration.
1490  ///
1491  /// This method should be invoked at the beginning of the definition
1492  /// of this tag declaration. It will set the tag type into a state
1493  /// where it is in the process of being defined.
1494  void startDefinition();
1495
1496  /// @brief Completes the definition of this tag declaration.
1497  void completeDefinition();
1498
1499  /// getDefinition - Returns the TagDecl that actually defines this
1500  ///  struct/union/class/enum.  When determining whether or not a
1501  ///  struct/union/class/enum is completely defined, one should use this method
1502  ///  as opposed to 'isDefinition'.  'isDefinition' indicates whether or not a
1503  ///  specific TagDecl is defining declaration, not whether or not the
1504  ///  struct/union/class/enum type is defined.  This method returns NULL if
1505  ///  there is no TagDecl that defines the struct/union/class/enum.
1506  TagDecl* getDefinition(ASTContext& C) const;
1507
1508  const char *getKindName() const {
1509    return ElaboratedType::getNameForTagKind(getTagKind());
1510  }
1511
1512  /// getTagKindForTypeSpec - Converts a type specifier (DeclSpec::TST)
1513  /// into a tag kind.  It is an error to provide a type specifier
1514  /// which *isn't* a tag kind here.
1515  static TagKind getTagKindForTypeSpec(unsigned TypeSpec);
1516
1517  TagKind getTagKind() const {
1518    return TagKind(TagDeclKind);
1519  }
1520
1521  void setTagKind(TagKind TK) { TagDeclKind = TK; }
1522
1523  bool isStruct() const { return getTagKind() == TK_struct; }
1524  bool isClass()  const { return getTagKind() == TK_class; }
1525  bool isUnion()  const { return getTagKind() == TK_union; }
1526  bool isEnum()   const { return getTagKind() == TK_enum; }
1527
1528  TypedefDecl *getTypedefForAnonDecl() const { return TypedefForAnonDecl; }
1529  void setTypedefForAnonDecl(TypedefDecl *TDD) { TypedefForAnonDecl = TDD; }
1530
1531  // Implement isa/cast/dyncast/etc.
1532  static bool classof(const Decl *D) {
1533    return D->getKind() >= TagFirst && D->getKind() <= TagLast;
1534  }
1535  static bool classof(const TagDecl *D) { return true; }
1536
1537  static DeclContext *castToDeclContext(const TagDecl *D) {
1538    return static_cast<DeclContext *>(const_cast<TagDecl*>(D));
1539  }
1540  static TagDecl *castFromDeclContext(const DeclContext *DC) {
1541    return static_cast<TagDecl *>(const_cast<DeclContext*>(DC));
1542  }
1543
1544  void setDefinition(bool V) { IsDefinition = V; }
1545};
1546
1547/// EnumDecl - Represents an enum.  As an extension, we allow forward-declared
1548/// enums.
1549class EnumDecl : public TagDecl {
1550  /// IntegerType - This represent the integer type that the enum corresponds
1551  /// to for code generation purposes.  Note that the enumerator constants may
1552  /// have a different type than this does.
1553  QualType IntegerType;
1554
1555  /// \brief If the enumeration was instantiated from an enumeration
1556  /// within a class or function template, this pointer refers to the
1557  /// enumeration declared within the template.
1558  EnumDecl *InstantiatedFrom;
1559
1560  EnumDecl(DeclContext *DC, SourceLocation L,
1561           IdentifierInfo *Id, EnumDecl *PrevDecl, SourceLocation TKL)
1562    : TagDecl(Enum, TK_enum, DC, L, Id, PrevDecl, TKL), InstantiatedFrom(0) {
1563      IntegerType = QualType();
1564    }
1565public:
1566  EnumDecl *getCanonicalDecl() {
1567    return cast<EnumDecl>(TagDecl::getCanonicalDecl());
1568  }
1569  const EnumDecl *getCanonicalDecl() const {
1570    return cast<EnumDecl>(TagDecl::getCanonicalDecl());
1571  }
1572
1573  static EnumDecl *Create(ASTContext &C, DeclContext *DC,
1574                          SourceLocation L, IdentifierInfo *Id,
1575                          SourceLocation TKL, EnumDecl *PrevDecl);
1576
1577  virtual void Destroy(ASTContext& C);
1578
1579  /// completeDefinition - When created, the EnumDecl corresponds to a
1580  /// forward-declared enum. This method is used to mark the
1581  /// declaration as being defined; it's enumerators have already been
1582  /// added (via DeclContext::addDecl). NewType is the new underlying
1583  /// type of the enumeration type.
1584  void completeDefinition(ASTContext &C, QualType NewType);
1585
1586  // enumerator_iterator - Iterates through the enumerators of this
1587  // enumeration.
1588  typedef specific_decl_iterator<EnumConstantDecl> enumerator_iterator;
1589
1590  enumerator_iterator enumerator_begin() const {
1591    return enumerator_iterator(this->decls_begin());
1592  }
1593
1594  enumerator_iterator enumerator_end() const {
1595    return enumerator_iterator(this->decls_end());
1596  }
1597
1598  /// getIntegerType - Return the integer type this enum decl corresponds to.
1599  /// This returns a null qualtype for an enum forward definition.
1600  QualType getIntegerType() const { return IntegerType; }
1601
1602  /// \brief Set the underlying integer type.
1603  void setIntegerType(QualType T) { IntegerType = T; }
1604
1605  /// \brief Returns the enumeration (declared within the template)
1606  /// from which this enumeration type was instantiated, or NULL if
1607  /// this enumeration was not instantiated from any template.
1608  EnumDecl *getInstantiatedFromMemberEnum() const {
1609    return InstantiatedFrom;
1610  }
1611
1612  void setInstantiationOfMemberEnum(EnumDecl *IF) { InstantiatedFrom = IF; }
1613
1614  static bool classof(const Decl *D) { return D->getKind() == Enum; }
1615  static bool classof(const EnumDecl *D) { return true; }
1616};
1617
1618
1619/// RecordDecl - Represents a struct/union/class.  For example:
1620///   struct X;                  // Forward declaration, no "body".
1621///   union Y { int A, B; };     // Has body with members A and B (FieldDecls).
1622/// This decl will be marked invalid if *any* members are invalid.
1623///
1624class RecordDecl : public TagDecl {
1625  // FIXME: This can be packed into the bitfields in Decl.
1626  /// HasFlexibleArrayMember - This is true if this struct ends with a flexible
1627  /// array member (e.g. int X[]) or if this union contains a struct that does.
1628  /// If so, this cannot be contained in arrays or other structs as a member.
1629  bool HasFlexibleArrayMember : 1;
1630
1631  /// AnonymousStructOrUnion - Whether this is the type of an
1632  /// anonymous struct or union.
1633  bool AnonymousStructOrUnion : 1;
1634
1635  /// HasObjectMember - This is true if this struct has at least one
1636  /// member containing an object
1637  bool HasObjectMember : 1;
1638
1639protected:
1640  RecordDecl(Kind DK, TagKind TK, DeclContext *DC,
1641             SourceLocation L, IdentifierInfo *Id,
1642             RecordDecl *PrevDecl, SourceLocation TKL);
1643  virtual ~RecordDecl();
1644
1645public:
1646  static RecordDecl *Create(ASTContext &C, TagKind TK, DeclContext *DC,
1647                            SourceLocation L, IdentifierInfo *Id,
1648                            SourceLocation TKL = SourceLocation(),
1649                            RecordDecl* PrevDecl = 0);
1650
1651  virtual void Destroy(ASTContext& C);
1652
1653  bool hasFlexibleArrayMember() const { return HasFlexibleArrayMember; }
1654  void setHasFlexibleArrayMember(bool V) { HasFlexibleArrayMember = V; }
1655
1656  /// isAnonymousStructOrUnion - Whether this is an anonymous struct
1657  /// or union. To be an anonymous struct or union, it must have been
1658  /// declared without a name and there must be no objects of this
1659  /// type declared, e.g.,
1660  /// @code
1661  ///   union { int i; float f; };
1662  /// @endcode
1663  /// is an anonymous union but neither of the following are:
1664  /// @code
1665  ///  union X { int i; float f; };
1666  ///  union { int i; float f; } obj;
1667  /// @endcode
1668  bool isAnonymousStructOrUnion() const { return AnonymousStructOrUnion; }
1669  void setAnonymousStructOrUnion(bool Anon) {
1670    AnonymousStructOrUnion = Anon;
1671  }
1672
1673  bool hasObjectMember() const { return HasObjectMember; }
1674  void setHasObjectMember (bool val) { HasObjectMember = val; }
1675
1676  /// \brief Determines whether this declaration represents the
1677  /// injected class name.
1678  ///
1679  /// The injected class name in C++ is the name of the class that
1680  /// appears inside the class itself. For example:
1681  ///
1682  /// \code
1683  /// struct C {
1684  ///   // C is implicitly declared here as a synonym for the class name.
1685  /// };
1686  ///
1687  /// C::C c; // same as "C c;"
1688  /// \endcode
1689  bool isInjectedClassName() const;
1690
1691  /// getDefinition - Returns the RecordDecl that actually defines this
1692  ///  struct/union/class.  When determining whether or not a struct/union/class
1693  ///  is completely defined, one should use this method as opposed to
1694  ///  'isDefinition'.  'isDefinition' indicates whether or not a specific
1695  ///  RecordDecl is defining declaration, not whether or not the record
1696  ///  type is defined.  This method returns NULL if there is no RecordDecl
1697  ///  that defines the struct/union/tag.
1698  RecordDecl* getDefinition(ASTContext& C) const {
1699    return cast_or_null<RecordDecl>(TagDecl::getDefinition(C));
1700  }
1701
1702  // Iterator access to field members. The field iterator only visits
1703  // the non-static data members of this class, ignoring any static
1704  // data members, functions, constructors, destructors, etc.
1705  typedef specific_decl_iterator<FieldDecl> field_iterator;
1706
1707  field_iterator field_begin() const {
1708    return field_iterator(decls_begin());
1709  }
1710  field_iterator field_end() const {
1711    return field_iterator(decls_end());
1712  }
1713
1714  // field_empty - Whether there are any fields (non-static data
1715  // members) in this record.
1716  bool field_empty() const {
1717    return field_begin() == field_end();
1718  }
1719
1720  /// completeDefinition - Notes that the definition of this type is
1721  /// now complete.
1722  void completeDefinition(ASTContext& C);
1723
1724  static bool classof(const Decl *D) {
1725    return D->getKind() >= RecordFirst && D->getKind() <= RecordLast;
1726  }
1727  static bool classof(const RecordDecl *D) { return true; }
1728};
1729
1730class FileScopeAsmDecl : public Decl {
1731  StringLiteral *AsmString;
1732  FileScopeAsmDecl(DeclContext *DC, SourceLocation L, StringLiteral *asmstring)
1733    : Decl(FileScopeAsm, DC, L), AsmString(asmstring) {}
1734public:
1735  static FileScopeAsmDecl *Create(ASTContext &C, DeclContext *DC,
1736                                  SourceLocation L, StringLiteral *Str);
1737
1738  const StringLiteral *getAsmString() const { return AsmString; }
1739  StringLiteral *getAsmString() { return AsmString; }
1740  void setAsmString(StringLiteral *Asm) { AsmString = Asm; }
1741
1742  static bool classof(const Decl *D) {
1743    return D->getKind() == FileScopeAsm;
1744  }
1745  static bool classof(const FileScopeAsmDecl *D) { return true; }
1746};
1747
1748/// BlockDecl - This represents a block literal declaration, which is like an
1749/// unnamed FunctionDecl.  For example:
1750/// ^{ statement-body }   or   ^(int arg1, float arg2){ statement-body }
1751///
1752class BlockDecl : public Decl, public DeclContext {
1753  // FIXME: This can be packed into the bitfields in Decl.
1754  bool isVariadic : 1;
1755  /// ParamInfo - new[]'d array of pointers to ParmVarDecls for the formal
1756  /// parameters of this function.  This is null if a prototype or if there are
1757  /// no formals.
1758  ParmVarDecl **ParamInfo;
1759  unsigned NumParams;
1760
1761  Stmt *Body;
1762
1763protected:
1764  BlockDecl(DeclContext *DC, SourceLocation CaretLoc)
1765    : Decl(Block, DC, CaretLoc), DeclContext(Block),
1766      isVariadic(false), ParamInfo(0), NumParams(0), Body(0) {}
1767
1768  virtual ~BlockDecl();
1769  virtual void Destroy(ASTContext& C);
1770
1771public:
1772  static BlockDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L);
1773
1774  SourceLocation getCaretLocation() const { return getLocation(); }
1775
1776  bool IsVariadic() const { return isVariadic; }
1777  void setIsVariadic(bool value) { isVariadic = value; }
1778
1779  CompoundStmt *getCompoundBody() const { return (CompoundStmt*) Body; }
1780  Stmt *getBody() const { return (Stmt*) Body; }
1781  void setBody(CompoundStmt *B) { Body = (Stmt*) B; }
1782
1783  // Iterator access to formal parameters.
1784  unsigned param_size() const { return getNumParams(); }
1785  typedef ParmVarDecl **param_iterator;
1786  typedef ParmVarDecl * const *param_const_iterator;
1787
1788  bool param_empty() const { return NumParams == 0; }
1789  param_iterator param_begin()  { return ParamInfo; }
1790  param_iterator param_end()   { return ParamInfo+param_size(); }
1791
1792  param_const_iterator param_begin() const { return ParamInfo; }
1793  param_const_iterator param_end() const   { return ParamInfo+param_size(); }
1794
1795  unsigned getNumParams() const;
1796  const ParmVarDecl *getParamDecl(unsigned i) const {
1797    assert(i < getNumParams() && "Illegal param #");
1798    return ParamInfo[i];
1799  }
1800  ParmVarDecl *getParamDecl(unsigned i) {
1801    assert(i < getNumParams() && "Illegal param #");
1802    return ParamInfo[i];
1803  }
1804  void setParams(ASTContext& C, ParmVarDecl **NewParamInfo, unsigned NumParams);
1805
1806  // Implement isa/cast/dyncast/etc.
1807  static bool classof(const Decl *D) { return D->getKind() == Block; }
1808  static bool classof(const BlockDecl *D) { return true; }
1809  static DeclContext *castToDeclContext(const BlockDecl *D) {
1810    return static_cast<DeclContext *>(const_cast<BlockDecl*>(D));
1811  }
1812  static BlockDecl *castFromDeclContext(const DeclContext *DC) {
1813    return static_cast<BlockDecl *>(const_cast<DeclContext*>(DC));
1814  }
1815};
1816
1817/// Insertion operator for diagnostics.  This allows sending NamedDecl's
1818/// into a diagnostic with <<.
1819inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
1820                                           NamedDecl* ND) {
1821  DB.AddTaggedVal(reinterpret_cast<intptr_t>(ND), Diagnostic::ak_nameddecl);
1822  return DB;
1823}
1824
1825}  // end namespace clang
1826
1827#endif
1828