DeclCXX.h revision 64bffa9a6f40e5a3d5556f994f09f7bf45eecd4c
1//===-- DeclCXX.h - Classes for representing C++ declarations -*- C++ -*-=====//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10//  This file defines the C++ Decl subclasses.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_AST_DECLCXX_H
15#define LLVM_CLANG_AST_DECLCXX_H
16
17#include "clang/AST/Decl.h"
18#include "llvm/ADT/SmallVector.h"
19
20namespace clang {
21class CXXRecordDecl;
22class CXXConstructorDecl;
23
24/// OverloadedFunctionDecl - An instance of this class represents a
25/// set of overloaded functions. All of the functions have the same
26/// name and occur within the same scope.
27///
28/// An OverloadedFunctionDecl has no ownership over the FunctionDecl
29/// nodes it contains. Rather, the FunctionDecls are owned by the
30/// enclosing scope (which also owns the OverloadedFunctionDecl
31/// node). OverloadedFunctionDecl is used primarily to store a set of
32/// overloaded functions for name lookup.
33class OverloadedFunctionDecl : public NamedDecl {
34protected:
35  OverloadedFunctionDecl(DeclContext *DC, IdentifierInfo *Id)
36    : NamedDecl(OverloadedFunction, SourceLocation(), Id) { }
37
38  /// Functions - the set of overloaded functions contained in this
39  /// overload set.
40  llvm::SmallVector<FunctionDecl *, 4> Functions;
41
42public:
43  typedef llvm::SmallVector<FunctionDecl *, 4>::iterator function_iterator;
44  typedef llvm::SmallVector<FunctionDecl *, 4>::const_iterator
45    function_const_iterator;
46
47  static OverloadedFunctionDecl *Create(ASTContext &C, DeclContext *DC,
48                                        IdentifierInfo *Id);
49
50  /// addOverload - Add an overloaded function FD to this set of
51  /// overloaded functions.
52  void addOverload(FunctionDecl *FD) {
53    assert((!getNumFunctions() || (FD->getDeclContext() == getDeclContext())) &&
54           "Overloaded functions must all be in the same context");
55    assert(FD->getIdentifier() == getIdentifier() &&
56           "Overloaded functions must have the same name.");
57    Functions.push_back(FD);
58  }
59
60  function_iterator function_begin() { return Functions.begin(); }
61  function_iterator function_end() { return Functions.end(); }
62  function_const_iterator function_begin() const { return Functions.begin(); }
63  function_const_iterator function_end() const { return Functions.end(); }
64
65  /// getNumFunctions - the number of overloaded functions stored in
66  /// this set.
67  unsigned getNumFunctions() const { return Functions.size(); }
68
69  /// getFunction - retrieve the ith function in the overload set.
70  const FunctionDecl *getFunction(unsigned i) const {
71    assert(i < getNumFunctions() && "Illegal function #");
72    return Functions[i];
73  }
74  FunctionDecl *getFunction(unsigned i) {
75    assert(i < getNumFunctions() && "Illegal function #");
76    return Functions[i];
77  }
78
79  // getDeclContext - Get the context of these overloaded functions.
80  DeclContext *getDeclContext() {
81    assert(getNumFunctions() > 0 && "Context of an empty overload set");
82    return getFunction(0)->getDeclContext();
83  }
84
85  // Implement isa/cast/dyncast/etc.
86  static bool classof(const Decl *D) {
87    return D->getKind() == OverloadedFunction;
88  }
89  static bool classof(const OverloadedFunctionDecl *D) { return true; }
90
91protected:
92  /// EmitImpl - Serialize this FunctionDecl.  Called by Decl::Emit.
93  virtual void EmitImpl(llvm::Serializer& S) const;
94
95  /// CreateImpl - Deserialize an OverloadedFunctionDecl.  Called by
96  /// Decl::Create.
97  static OverloadedFunctionDecl* CreateImpl(llvm::Deserializer& D,
98                                            ASTContext& C);
99
100  friend Decl* Decl::Create(llvm::Deserializer& D, ASTContext& C);
101  friend class CXXRecordDecl;
102};
103
104/// CXXFieldDecl - Represents an instance field of a C++ struct/union/class.
105class CXXFieldDecl : public FieldDecl {
106  CXXRecordDecl *Parent;
107
108  CXXFieldDecl(CXXRecordDecl *RD, SourceLocation L, IdentifierInfo *Id,
109               QualType T, Expr *BW = NULL)
110    : FieldDecl(CXXField, L, Id, T, BW), Parent(RD) {}
111public:
112  static CXXFieldDecl *Create(ASTContext &C, CXXRecordDecl *RD,SourceLocation L,
113                              IdentifierInfo *Id, QualType T, Expr *BW = NULL);
114
115  void setAccess(AccessSpecifier AS) { Access = AS; }
116  AccessSpecifier getAccess() const { return AccessSpecifier(Access); }
117  CXXRecordDecl *getParent() const { return Parent; }
118
119  // Implement isa/cast/dyncast/etc.
120  static bool classof(const Decl *D) { return D->getKind() == CXXField; }
121  static bool classof(const CXXFieldDecl *D) { return true; }
122};
123
124/// CXXBaseSpecifier - A base class of a C++ class.
125///
126/// Each CXXBaseSpecifier represents a single, direct base class (or
127/// struct) of a C++ class (or struct). It specifies the type of that
128/// base class, whether it is a virtual or non-virtual base, and what
129/// level of access (public, protected, private) is used for the
130/// derivation. For example:
131///
132/// @code
133///   class A { };
134///   class B { };
135///   class C : public virtual A, protected B { };
136/// @endcode
137///
138/// In this code, C will have two CXXBaseSpecifiers, one for "public
139/// virtual A" and the other for "protected B".
140class CXXBaseSpecifier {
141  /// Range - The source code range that covers the full base
142  /// specifier, including the "virtual" (if present) and access
143  /// specifier (if present).
144  SourceRange Range;
145
146  /// Virtual - Whether this is a virtual base class or not.
147  bool Virtual : 1;
148
149  /// BaseOfClass - Whether this is the base of a class (true) or of a
150  /// struct (false). This determines the mapping from the access
151  /// specifier as written in the source code to the access specifier
152  /// used for semantic analysis.
153  bool BaseOfClass : 1;
154
155  /// Access - Access specifier as written in the source code (which
156  /// may be AS_none). The actual type of data stored here is an
157  /// AccessSpecifier, but we use "unsigned" here to work around a
158  /// VC++ bug.
159  unsigned Access : 2;
160
161  /// BaseType - The type of the base class. This will be a class or
162  /// struct (or a typedef of such).
163  QualType BaseType;
164
165public:
166  CXXBaseSpecifier() { }
167
168  CXXBaseSpecifier(SourceRange R, bool V, bool BC, AccessSpecifier A, QualType T)
169    : Range(R), Virtual(V), BaseOfClass(BC), Access(A), BaseType(T) { }
170
171  /// getSourceRange - Retrieves the source range that contains the
172  /// entire base specifier.
173  SourceRange getSourceRange() const { return Range; }
174
175  /// isVirtual - Determines whether the base class is a virtual base
176  /// class (or not).
177  bool isVirtual() const { return Virtual; }
178
179  /// getAccessSpecifier - Returns the access specifier for this base
180  /// specifier. This is the actual base specifier as used for
181  /// semantic analysis, so the result can never be AS_none. To
182  /// retrieve the access specifier as written in the source code, use
183  /// getAccessSpecifierAsWritten().
184  AccessSpecifier getAccessSpecifier() const {
185    if ((AccessSpecifier)Access == AS_none)
186      return BaseOfClass? AS_private : AS_public;
187    else
188      return (AccessSpecifier)Access;
189  }
190
191  /// getAccessSpecifierAsWritten - Retrieves the access specifier as
192  /// written in the source code (which may mean that no access
193  /// specifier was explicitly written). Use getAccessSpecifier() to
194  /// retrieve the access specifier for use in semantic analysis.
195  AccessSpecifier getAccessSpecifierAsWritten() const {
196    return (AccessSpecifier)Access;
197  }
198
199  /// getType - Retrieves the type of the base class. This type will
200  /// always be an unqualified class type.
201  QualType getType() const { return BaseType; }
202};
203
204/// CXXRecordDecl - Represents a C++ struct/union/class.
205/// CXXRecordDecl differs from RecordDecl in several ways. First, it
206/// is a DeclContext, because it can contain other
207/// declarations. Second, it provides additional C++ fields, including
208/// storage for base classes and constructors.
209class CXXRecordDecl : public RecordDecl, public DeclContext {
210  /// UserDeclaredConstructor - True when this class has a
211  /// user-declared constructor.
212  bool UserDeclaredConstructor : 1;
213
214  /// UserDeclaredCopyConstructor - True when this class has a
215  /// user-defined copy constructor.
216  bool UserDeclaredCopyConstructor : 1;
217
218  /// Aggregate - True when this class is an aggregate.
219  bool Aggregate : 1;
220
221  /// Bases - Base classes of this class.
222  /// FIXME: This is wasted space for a union.
223  CXXBaseSpecifier *Bases;
224
225  /// NumBases - The number of base class specifiers in Bases.
226  unsigned NumBases;
227
228  /// Constructors - Overload set containing the constructors of this
229  /// C++ class. Each of the entries in this overload set is a
230  /// CXXConstructorDecl.
231  OverloadedFunctionDecl Constructors;
232
233  CXXRecordDecl(TagKind TK, DeclContext *DC,
234                SourceLocation L, IdentifierInfo *Id)
235    : RecordDecl(CXXRecord, TK, DC, L, Id), DeclContext(CXXRecord),
236      UserDeclaredConstructor(false), UserDeclaredCopyConstructor(false),
237      Aggregate(true), Bases(0), NumBases(0), Constructors(DC, Id) { }
238
239  ~CXXRecordDecl();
240
241public:
242  /// base_class_iterator - Iterator that traverses the base classes
243  /// of a clas.
244  typedef CXXBaseSpecifier*       base_class_iterator;
245
246  /// base_class_const_iterator - Iterator that traverses the base
247  /// classes of a clas.
248  typedef const CXXBaseSpecifier* base_class_const_iterator;
249
250  static CXXRecordDecl *Create(ASTContext &C, TagKind TK, DeclContext *DC,
251                               SourceLocation L, IdentifierInfo *Id,
252                               CXXRecordDecl* PrevDecl=0);
253
254  /// setBases - Sets the base classes of this struct or class.
255  void setBases(CXXBaseSpecifier const * const *Bases, unsigned NumBases);
256
257  /// getNumBases - Retrieves the number of base classes of this
258  /// class.
259  unsigned getNumBases() const { return NumBases; }
260
261  base_class_iterator       bases_begin()       { return Bases; }
262  base_class_const_iterator bases_begin() const { return Bases; }
263  base_class_iterator       bases_end()         { return Bases + NumBases; }
264  base_class_const_iterator bases_end()   const { return Bases + NumBases; }
265
266  const CXXFieldDecl *getMember(unsigned i) const {
267    return cast<const CXXFieldDecl>(RecordDecl::getMember(i));
268  }
269  CXXFieldDecl *getMember(unsigned i) {
270    return cast<CXXFieldDecl>(RecordDecl::getMember(i));
271  }
272
273  /// getMember - If the member doesn't exist, or there are no members, this
274  /// function will return 0;
275  CXXFieldDecl *getMember(IdentifierInfo *name) {
276    return cast_or_null<CXXFieldDecl>(RecordDecl::getMember(name));
277  }
278
279  /// getConstructors - Retrieve the overload set containing all of
280  /// the constructors of this class.
281  OverloadedFunctionDecl       *getConstructors()       { return &Constructors; }
282
283  /// getConstructors - Retrieve the overload set containing all of
284  /// the constructors of this class.
285  const OverloadedFunctionDecl *getConstructors() const { return &Constructors; }
286
287  /// hasConstCopyConstructor - Determines whether this class has a
288  /// copy constructor that accepts a const-qualified argument.
289  bool hasConstCopyConstructor(ASTContext &Context) const;
290
291  /// addConstructor - Add another constructor to the list of constructors.
292  void addConstructor(ASTContext &Context, CXXConstructorDecl *ConDecl);
293
294  /// hasUserDeclaredConstructor - Whether this class has any
295  /// user-declared constructors. When true, a default constructor
296  /// will not be implicitly declared.
297  bool hasUserDeclaredConstructor() const { return UserDeclaredConstructor; }
298
299  /// hasUserDeclaredCopyConstructor - Whether this class has a
300  /// user-declared copy constructor. When false, a copy constructor
301  /// will be implicitly declared.
302  bool hasUserDeclaredCopyConstructor() const {
303    return UserDeclaredCopyConstructor;
304  }
305
306  /// isAggregate - Whether this class is an aggregate (C++
307  /// [dcl.init.aggr]), which is a class with no user-declared
308  /// constructors, no private or protected non-static data members,
309  /// no base classes, and no virtual functions (C++ [dcl.init.aggr]p1).
310  bool isAggregate() const { return Aggregate; }
311
312  /// setAggregate - Set whether this class is an aggregate (C++
313  /// [dcl.init.aggr]).
314  void setAggregate(bool Agg) { Aggregate = Agg; }
315
316  /// viewInheritance - Renders and displays an inheritance diagram
317  /// for this C++ class and all of its base classes (transitively) using
318  /// GraphViz.
319  void viewInheritance(ASTContext& Context) const;
320
321  static bool classof(const Decl *D) { return D->getKind() == CXXRecord; }
322  static bool classof(const CXXRecordDecl *D) { return true; }
323  static DeclContext *castToDeclContext(const CXXRecordDecl *D) {
324    return static_cast<DeclContext *>(const_cast<CXXRecordDecl*>(D));
325  }
326  static CXXRecordDecl *castFromDeclContext(const DeclContext *DC) {
327    return static_cast<CXXRecordDecl *>(const_cast<DeclContext*>(DC));
328  }
329
330  virtual void Destroy(ASTContext& C);
331
332protected:
333  /// EmitImpl - Serialize this CXXRecordDecl.  Called by Decl::Emit.
334  // FIXME: Implement this.
335  //virtual void EmitImpl(llvm::Serializer& S) const;
336
337  /// CreateImpl - Deserialize a CXXRecordDecl.  Called by Decl::Create.
338  // FIXME: Implement this.
339  static CXXRecordDecl* CreateImpl(Kind DK, llvm::Deserializer& D, ASTContext& C);
340
341  friend Decl* Decl::Create(llvm::Deserializer& D, ASTContext& C);
342};
343
344/// CXXMethodDecl - Represents a static or instance method of a
345/// struct/union/class.
346class CXXMethodDecl : public FunctionDecl {
347  CXXMethodDecl(CXXRecordDecl *RD, SourceLocation L,
348               IdentifierInfo *Id, QualType T,
349               bool isStatic, bool isInline, ScopedDecl *PrevDecl)
350    : FunctionDecl(CXXMethod, RD, L, Id, T, (isStatic ? Static : None),
351                   isInline, PrevDecl) {}
352
353protected:
354  CXXMethodDecl(Kind DK, CXXRecordDecl *RD, SourceLocation L,
355                IdentifierInfo *Id, QualType T,
356                bool isStatic, bool isInline, ScopedDecl *PrevDecl)
357    : FunctionDecl(DK, RD, L, Id, T, (isStatic ? Static : None),
358                   isInline, PrevDecl) {}
359
360public:
361  static CXXMethodDecl *Create(ASTContext &C, CXXRecordDecl *RD,
362                              SourceLocation L, IdentifierInfo *Id,
363                              QualType T, bool isStatic = false,
364                              bool isInline = false,  ScopedDecl *PrevDecl = 0);
365
366  bool isStatic() const { return getStorageClass() == Static; }
367  bool isInstance() const { return !isStatic(); }
368
369  void setAccess(AccessSpecifier AS) { Access = AS; }
370  AccessSpecifier getAccess() const { return AccessSpecifier(Access); }
371
372  /// getParent - Returns the parent of this method declaration, which
373  /// is the class in which this method is defined.
374  const CXXRecordDecl *getParent() const {
375    return cast<CXXRecordDecl>(FunctionDecl::getParent());
376  }
377
378  /// getParent - Returns the parent of this method declaration, which
379  /// is the class in which this method is defined.
380  CXXRecordDecl *getParent() {
381    return const_cast<CXXRecordDecl *>(
382             cast<CXXRecordDecl>(FunctionDecl::getParent()));
383  }
384
385  /// getThisType - Returns the type of 'this' pointer.
386  /// Should only be called for instance methods.
387  QualType getThisType(ASTContext &C) const;
388
389  unsigned getTypeQualifiers() const {
390    return getType()->getAsFunctionTypeProto()->getTypeQuals();
391  }
392
393  // Implement isa/cast/dyncast/etc.
394  static bool classof(const Decl *D) {
395    return D->getKind() >= CXXMethod && D->getKind() <= CXXConstructor;
396  }
397  static bool classof(const CXXMethodDecl *D) { return true; }
398
399protected:
400  /// EmitImpl - Serialize this CXXMethodDecl.  Called by Decl::Emit.
401  // FIXME: Implement this.
402  //virtual void EmitImpl(llvm::Serializer& S) const;
403
404  /// CreateImpl - Deserialize a CXXMethodDecl.  Called by Decl::Create.
405  // FIXME: Implement this.
406  static CXXMethodDecl* CreateImpl(llvm::Deserializer& D, ASTContext& C);
407
408  friend Decl* Decl::Create(llvm::Deserializer& D, ASTContext& C);
409};
410
411/// CXXBaseOrMemberInitializer - Represents a C++ base or member
412/// initializer, which is part of a constructor initializer that
413/// initializes one non-static member variable or one base class. For
414/// example, in the following, both 'A(a)' and 'f(3.14159)' are member
415/// initializers:
416///
417/// @code
418/// class A { };
419/// class B : public A {
420///   float f;
421/// public:
422///   B(A& a) : A(a), f(3.14159) { }
423/// };
424class CXXBaseOrMemberInitializer {
425  /// BaseOrMember - This points to the entity being initialized,
426  /// which is either a base class (a Type) or a non-static data
427  /// member (a CXXFieldDecl). When the low bit is 1, it's a base
428  /// class; when the low bit is 0, it's a member.
429  uintptr_t BaseOrMember;
430
431  /// Args - The arguments used to initialize the base or member.
432  Expr **Args;
433  unsigned NumArgs;
434
435public:
436  /// CXXBaseOrMemberInitializer - Creates a new base-class initializer.
437  explicit
438  CXXBaseOrMemberInitializer(QualType BaseType, Expr **Args, unsigned NumArgs);
439
440  /// CXXBaseOrMemberInitializer - Creates a new member initializer.
441  explicit
442  CXXBaseOrMemberInitializer(CXXFieldDecl *Member, Expr **Args, unsigned NumArgs);
443
444  /// ~CXXBaseOrMemberInitializer - Destroy the base or member initializer.
445  ~CXXBaseOrMemberInitializer();
446
447  /// arg_iterator - Iterates through the member initialization
448  /// arguments.
449  typedef Expr **arg_iterator;
450
451  /// arg_const_iterator - Iterates through the member initialization
452  /// arguments.
453  typedef Expr * const * arg_const_iterator;
454
455  /// isBaseInitializer - Returns true when this initializer is
456  /// initializing a base class.
457  bool isBaseInitializer() const { return (BaseOrMember & 0x1) != 0; }
458
459  /// isMemberInitializer - Returns true when this initializer is
460  /// initializing a non-static data member.
461  bool isMemberInitializer() const { return (BaseOrMember & 0x1) == 0; }
462
463  /// getBaseClass - If this is a base class initializer, returns the
464  /// type used to specify the initializer. The resulting type will be
465  /// a class type or a typedef of a class type. If this is not a base
466  /// class initializer, returns NULL.
467  Type *getBaseClass() {
468    if (isBaseInitializer())
469      return reinterpret_cast<Type*>(BaseOrMember & ~0x01);
470    else
471      return 0;
472  }
473
474  /// getBaseClass - If this is a base class initializer, returns the
475  /// type used to specify the initializer. The resulting type will be
476  /// a class type or a typedef of a class type. If this is not a base
477  /// class initializer, returns NULL.
478  const Type *getBaseClass() const {
479    if (isBaseInitializer())
480      return reinterpret_cast<const Type*>(BaseOrMember & ~0x01);
481    else
482      return 0;
483  }
484
485  /// getMember - If this is a member initializer, returns the
486  /// declaration of the non-static data member being
487  /// initialized. Otherwise, returns NULL.
488  CXXFieldDecl *getMember() {
489    if (isMemberInitializer())
490      return reinterpret_cast<CXXFieldDecl *>(BaseOrMember);
491    else
492      return 0;
493  }
494
495  /// begin() - Retrieve an iterator to the first initializer argument.
496  arg_iterator       begin()       { return Args; }
497  /// begin() - Retrieve an iterator to the first initializer argument.
498  arg_const_iterator begin() const { return Args; }
499
500  /// end() - Retrieve an iterator past the last initializer argument.
501  arg_iterator       end()       { return Args + NumArgs; }
502  /// end() - Retrieve an iterator past the last initializer argument.
503  arg_const_iterator end() const { return Args + NumArgs; }
504
505  /// getNumArgs - Determine the number of arguments used to
506  /// initialize the member or base.
507  unsigned getNumArgs() const { return NumArgs; }
508};
509
510/// CXXConstructorDecl - Represents a C++ constructor within a
511/// class. For example:
512///
513/// @code
514/// class X {
515/// public:
516///   explicit X(int); // represented by a CXXConstructorDecl.
517/// };
518/// @endcode
519class CXXConstructorDecl : public CXXMethodDecl {
520  /// Explicit - Whether this constructor is explicit.
521  bool Explicit : 1;
522
523  /// ImplicitlyDeclared - Whether this constructor was implicitly
524  /// declared. When false, the constructor was declared by the user.
525  bool ImplicitlyDeclared : 1;
526
527  /// ImplicitlyDefined - Whether this constructor was implicitly
528  /// defined by the compiler. When false, the constructor was defined
529  /// by the user. In C++03, this flag will have the same value as
530  /// ImplicitlyDeclared. In C++0x, however, a constructor that is
531  /// explicitly defaulted (i.e., defined with " = default") will have
532  /// @c !ImplicitlyDeclared && ImplicitlyDefined.
533  bool ImplicitlyDefined : 1;
534
535  /// FIXME: Add support for base and member initializers.
536
537  CXXConstructorDecl(CXXRecordDecl *RD, SourceLocation L,
538                     IdentifierInfo *Id, QualType T,
539                     bool isExplicit, bool isInline, bool isImplicitlyDeclared)
540    : CXXMethodDecl(CXXConstructor, RD, L, Id, T, false, isInline, /*PrevDecl=*/0),
541      Explicit(isExplicit), ImplicitlyDeclared(isImplicitlyDeclared),
542      ImplicitlyDefined(false) { }
543
544public:
545  static CXXConstructorDecl *Create(ASTContext &C, CXXRecordDecl *RD,
546                                    SourceLocation L, IdentifierInfo *Id,
547                                    QualType T, bool isExplicit,
548                                    bool isInline, bool isImplicitlyDeclared);
549
550  /// isExplicit - Whether this constructor was marked "explicit" or not.
551  bool isExplicit() const { return Explicit; }
552
553  /// isImplicitlyDeclared - Whether this constructor was implicitly
554  /// declared. If false, then this constructor was explicitly
555  /// declared by the user.
556  bool isImplicitlyDeclared() const { return ImplicitlyDeclared; }
557
558  /// isImplicitlyDefined - Whether this constructor was implicitly
559  /// defined. If false, then this constructor was defined by the
560  /// user. This operation can only be invoked if the constructor has
561  /// already been defined.
562  bool isImplicitlyDefined() const {
563    assert(getBody() != 0 &&
564           "Can only get the implicit-definition flag once the constructor has been defined");
565    return ImplicitlyDefined;
566  }
567
568  /// setImplicitlyDefined - Set whether this constructor was
569  /// implicitly defined or not.
570  void setImplicitlyDefined(bool ID) {
571    assert(getBody() != 0 &&
572           "Can only set the implicit-definition flag once the constructor has been defined");
573    ImplicitlyDefined = ID;
574  }
575
576  /// isDefaultConstructor - Whether this constructor is a default
577  /// constructor (C++ [class.ctor]p5), which can be used to
578  /// default-initialize a class of this type.
579  bool isDefaultConstructor() const;
580
581  /// isCopyConstructor - Whether this constructor is a copy
582  /// constructor (C++ [class.copy]p2, which can be used to copy the
583  /// class. @p TypeQuals will be set to the qualifiers on the
584  /// argument type. For example, @p TypeQuals would be set to @c
585  /// QualType::Const for the following copy constructor:
586  ///
587  /// @code
588  /// class X {
589  /// public:
590  ///   X(const X&);
591  /// };
592  /// @endcode
593  bool isCopyConstructor(ASTContext &Context, unsigned &TypeQuals) const;
594
595  /// isCopyConstructor - Whether this constructor is a copy
596  /// constructor (C++ [class.copy]p2, which can be used to copy the
597  /// class.
598  bool isCopyConstructor(ASTContext &Context) const {
599    unsigned TypeQuals = 0;
600    return isCopyConstructor(Context, TypeQuals);
601  }
602
603  /// isConvertingConstructor - Whether this constructor is a
604  /// converting constructor (C++ [class.conv.ctor]), which can be
605  /// used for user-defined conversions.
606  bool isConvertingConstructor() const;
607
608  // Implement isa/cast/dyncast/etc.
609  static bool classof(const Decl *D) {
610    return D->getKind() == CXXConstructor;
611  }
612  static bool classof(const CXXConstructorDecl *D) { return true; }
613
614  /// EmitImpl - Serialize this CXXConstructorDecl.  Called by Decl::Emit.
615  // FIXME: Implement this.
616  //virtual void EmitImpl(llvm::Serializer& S) const;
617
618  /// CreateImpl - Deserialize a CXXConstructorDecl.  Called by Decl::Create.
619  // FIXME: Implement this.
620  static CXXConstructorDecl* CreateImpl(llvm::Deserializer& D, ASTContext& C);
621};
622
623/// CXXClassVarDecl - Represents a static data member of a struct/union/class.
624class CXXClassVarDecl : public VarDecl {
625
626  CXXClassVarDecl(CXXRecordDecl *RD, SourceLocation L,
627              IdentifierInfo *Id, QualType T, ScopedDecl *PrevDecl)
628    : VarDecl(CXXClassVar, RD, L, Id, T, None, PrevDecl) {}
629public:
630  static CXXClassVarDecl *Create(ASTContext &C, CXXRecordDecl *RD,
631                             SourceLocation L,IdentifierInfo *Id,
632                             QualType T, ScopedDecl *PrevDecl);
633
634  void setAccess(AccessSpecifier AS) { Access = AS; }
635  AccessSpecifier getAccess() const { return AccessSpecifier(Access); }
636
637  // Implement isa/cast/dyncast/etc.
638  static bool classof(const Decl *D) { return D->getKind() == CXXClassVar; }
639  static bool classof(const CXXClassVarDecl *D) { return true; }
640
641protected:
642  /// EmitImpl - Serialize this CXXClassVarDecl. Called by Decl::Emit.
643  // FIXME: Implement this.
644  //virtual void EmitImpl(llvm::Serializer& S) const;
645
646  /// CreateImpl - Deserialize a CXXClassVarDecl.  Called by Decl::Create.
647  // FIXME: Implement this.
648  static CXXClassVarDecl* CreateImpl(llvm::Deserializer& D, ASTContext& C);
649
650  friend Decl* Decl::Create(llvm::Deserializer& D, ASTContext& C);
651};
652
653
654/// CXXClassMemberWrapper - A wrapper class for C++ class member decls.
655/// Common functions like set/getAccess are included here to avoid bloating
656/// the interface of non-C++ specific decl classes, like NamedDecl.
657class CXXClassMemberWrapper {
658  Decl *MD;
659
660public:
661  CXXClassMemberWrapper(Decl *D) : MD(D) {
662    assert(isMember(D) && "Not a C++ class member!");
663  }
664
665  AccessSpecifier getAccess() const {
666    return AccessSpecifier(MD->Access);
667  }
668
669  void setAccess(AccessSpecifier AS) {
670    assert(AS != AS_none && "Access must be specified.");
671    MD->Access = AS;
672  }
673
674  CXXRecordDecl *getParent() const {
675    if (ScopedDecl *SD = dyn_cast<ScopedDecl>(MD)) {
676      return cast<CXXRecordDecl>(SD->getDeclContext());
677    }
678    return cast<CXXFieldDecl>(MD)->getParent();
679  }
680
681  static bool isMember(Decl *D) {
682    if (ScopedDecl *SD = dyn_cast<ScopedDecl>(D)) {
683      return isa<CXXRecordDecl>(SD->getDeclContext());
684    }
685    return isa<CXXFieldDecl>(D);
686  }
687};
688
689/// LinkageSpecDecl - This represents a linkage specification.  For example:
690///   extern "C" void foo();
691///
692class LinkageSpecDecl : public Decl {
693public:
694  /// LanguageIDs - Used to represent the language in a linkage
695  /// specification.  The values are part of the serialization abi for
696  /// ASTs and cannot be changed without altering that abi.  To help
697  /// ensure a stable abi for this, we choose the DW_LANG_ encodings
698  /// from the dwarf standard.
699  enum LanguageIDs { lang_c = /* DW_LANG_C */ 0x0002,
700  lang_cxx = /* DW_LANG_C_plus_plus */ 0x0004 };
701private:
702  /// Language - The language for this linkage specification.
703  LanguageIDs Language;
704  /// D - This is the Decl of the linkage specification.
705  Decl *D;
706
707  LinkageSpecDecl(SourceLocation L, LanguageIDs lang, Decl *d)
708  : Decl(LinkageSpec, L), Language(lang), D(d) {}
709public:
710  static LinkageSpecDecl *Create(ASTContext &C, SourceLocation L,
711                                 LanguageIDs Lang, Decl *D);
712
713  LanguageIDs getLanguage() const { return Language; }
714  const Decl *getDecl() const { return D; }
715  Decl *getDecl() { return D; }
716
717  static bool classof(const Decl *D) {
718    return D->getKind() == LinkageSpec;
719  }
720  static bool classof(const LinkageSpecDecl *D) { return true; }
721
722protected:
723  void EmitInRec(llvm::Serializer& S) const;
724  void ReadInRec(llvm::Deserializer& D, ASTContext& C);
725};
726
727
728
729} // end namespace clang
730
731#endif
732