~ubuntu-branches/ubuntu/wily/aspectc++/wily

« back to all changes in this revision

Viewing changes to Puma/src/infos/CClassInfo.h

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2005-12-23 10:49:40 UTC
  • Revision ID: james.westby@ubuntu.com-20051223104940-ig4klhoi991zs7km
Tags: upstream-0.99+1.0pre2
ImportĀ upstreamĀ versionĀ 0.99+1.0pre2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// This file is part of PUMA.
 
2
// Copyright (C) 1999-2003  The PUMA developer team.
 
3
//                                                                
 
4
// This program is free software;  you can redistribute it and/or 
 
5
// modify it under the terms of the GNU General Public License as 
 
6
// published by the Free Software Foundation; either version 2 of 
 
7
// the License, or (at your option) any later version.            
 
8
//                                                                
 
9
// This program is distributed in the hope that it will be useful,
 
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of 
 
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  
 
12
// GNU General Public License for more details.                   
 
13
//                                                                
 
14
// You should have received a copy of the GNU General Public      
 
15
// License along with this program; if not, write to the Free     
 
16
// Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, 
 
17
// MA  02111-1307  USA                                            
 
18
 
 
19
#ifndef __CClassInfo_h__
 
20
#define __CClassInfo_h__
 
21
 
 
22
// class/struct info 
 
23
// knows its base and derived classes
 
24
 
 
25
#include "Puma/CRecord.h"
 
26
#include "Puma/CTypeInfo.h"
 
27
#include "Puma/CBaseClassInfo.h"
 
28
#include "Puma/CTokens.h"
 
29
#include "Puma/CProtection.h"
 
30
 
 
31
namespace Puma {
 
32
 
 
33
/** \file 
 
34
 *  Representation of a C/C++ 'class' or 'struct'.
 
35
 *  \see Puma::CClassInfo */
 
36
 
 
37
/** \class CClassInfo CClassInfo.h Puma/infos/CClassInfo.h
 
38
 *  A CClassInfo object represents a C++ 'class' or 'struct'. Most of 
 
39
 *  the functionality of CClassInfo inherited by Puma::CRecord. It
 
40
 *  mainly manages the list of base classes and the list of derived
 
41
 *  classes. Note that a 'union', although syntactically very similar,
 
42
 *  is not represented by a CClassInfo object. */
 
43
class CClassInfo : public CRecord {
 
44
  Array<CBaseClassInfo*> _BaseClasses;
 
45
  Array<CClassInfo*> _Derived;
 
46
  // true if class has dependent base classes
 
47
  bool _DepBaseClass;
 
48
 
 
49
protected:
 
50
  /** This constructor is to be used by classes inherited from
 
51
   *  CClassInfo. It makes it possible to set another object id
 
52
   *  than \c CLASS_INFO for abstractions not representing a 
 
53
   *  standard C++ class (e.g. CClassInstance).
 
54
   *  \param id The object id to be used instead of \c CLASS_INFO. */
 
55
  CClassInfo (ObjectId id);
 
56
 
 
57
public: 
 
58
  /** Construct a new CClassInfo object. */
 
59
  CClassInfo ();
 
60
  /** Destroy the CClassInfo object. If the object id is 
 
61
   *  \c CLASS_INFO, Puma::CObjectInfo::CleanUp() is called. */
 
62
  ~CClassInfo ();
 
63
 
 
64
  /** Get the base info object of the info object. <b>The 
 
65
   *  corresponding information is not yet set!</b>
 
66
   *  \return This method always returns \c NULL.
 
67
   *  \warning Do not use this method. */
 
68
  CClassInfo *BaseObject () const;
 
69
  /** Get the info object of the class definition. 
 
70
   *  \return The info or \e this if the class is not defined. */
 
71
  CClassInfo *DefObject () const;
 
72
  /** Get the type information object for the class. */
 
73
  CTypeClass *TypeInfo () const;
 
74
 
 
75
  /** Get the number of the base classes of the class. */
 
76
  unsigned BaseClasses () const;
 
77
  /** Get the number of classes derived from the class. */
 
78
  unsigned DerivedClasses() const;
 
79
  /** Get the n-th base class. 
 
80
   *  \param n The number of the base class to return. 
 
81
   *  \return The base class info or \c NULL if \e n is not valid. */
 
82
  CBaseClassInfo *BaseClass (unsigned n) const;
 
83
  /** Get the base class with the given name. 
 
84
   *  \param name The name of the base class to return.
 
85
   *  \return The base class info or \c NULL if there is no base 
 
86
   *          class with the given name. */
 
87
  CBaseClassInfo *BaseClass (const char *name) const;
 
88
  /** Get the n-th derived class. 
 
89
   *  \param n The number of the derived class to return. 
 
90
   *  \return The class info of the derived class or \c NULL 
 
91
   *          if \e n is not valid. */
 
92
  CClassInfo *DerivedClass (unsigned n) const;
 
93
  /** Get the derived class with the given name. 
 
94
   *  \param name The name of the derived class to return.
 
95
   *  \return The class info of the derived class or \c NULL 
 
96
   *          if there is no derived class with the given name. */
 
97
  CClassInfo *DerivedClass (const char *name) const;
 
98
  
 
99
  /** Return \e true if the given class is a base class of the class.
 
100
   *  \param ci The class info of the possible base class.
 
101
   *  \param recursive If \e false it is only checked whether \e ci
 
102
   *         is a direct base class. */
 
103
  bool isBaseClass (const CClassInfo *ci, bool recursive = false) const;
 
104
  /** Return \e true if the given class is a derived class of the class.
 
105
   *  \param ci The class info of the possible base class.
 
106
   *  \param recursive If \e false it is only checked whether \e ci
 
107
   *         is directly derived from the class. */
 
108
  bool isDerivedClass (const CClassInfo *ci, bool recursive = false) const;
 
109
  /** Mark the class to have a base class that depends on template 
 
110
   *  parameters. 
 
111
   *  \param depends \e true if there is a dependent base class. */
 
112
  void hasDepBaseClass (bool depends);
 
113
  /** Return \e true if the class has a base class that depends on 
 
114
   *  template parameters. */
 
115
  bool hasDepBaseClass () const;
 
116
 
 
117
  /** Add a base class to the class.
 
118
   *  \param bc The base class info object. */
 
119
  void addBaseClass (CBaseClassInfo *bc);
 
120
  /** Add a derived class to the class.
 
121
   *  \param dc The class info object of the derived class. */
 
122
  void addDerivedClass (CClassInfo *dc);
 
123
  /** Remove the given base class from the class.
 
124
   *  \param bc The base class info object to remove. */
 
125
  void removeBaseClass (const CBaseClassInfo *bc);
 
126
  /** Remove the given base class from the class.
 
127
   *  \param bc The class info object of the base class to remove. */
 
128
  void removeBaseClass (const CClassInfo *bc);
 
129
  /** Remove the given derived class from the class.
 
130
   *  \param dc The class info object of the derived class to remove. */
 
131
  void removeDerivedClass (const CClassInfo *dc);
 
132
 
 
133
  /** Create a new base class info object.
 
134
   *  \param bc The class info of the base class or \c NULL to create
 
135
   *         an empty base class info object. 
 
136
   *  \return The new base class info object. */
 
137
  CBaseClassInfo *newBaseClass (CClassInfo *bc = 0);
 
138
 
 
139
  /** Return \e true if the class is declared using the keyword 'struct'. */
 
140
  bool isStruct () const;
 
141
  
 
142
  /** Returns the accessibility of a particular member or base class member.
 
143
   *  For example, if the accessibility is "private", the object can be
 
144
   *  accessed by members of this class, but not by other classes.
 
145
   *  \param oi The object info of the checked function/attribute/...
 
146
   *  \return The accessibility, i.e. private, public, protected, or none */
 
147
  CProtection::Type Accessibility (CObjectInfo *oi) const;
 
148
  
 
149
  /** Returns true if the argument function overrides any virtual function
 
150
   *  defined in this class or any of its base classes.
 
151
   *  \param fi function info object of the checked function. */
 
152
   bool overridesVirtual (const CFunctionInfo *fi) const;
 
153
   
 
154
  /** Returns true if this class is an aggregate according to 8.5.1-1. */
 
155
   bool isAggregate () const;
 
156
 
 
157
};
 
158
 
 
159
inline CClassInfo::CClassInfo (ObjectId id) :
 
160
  CRecord (id),
 
161
  _DepBaseClass (false)
 
162
 {}
 
163
inline CClassInfo::CClassInfo () :
 
164
  CRecord (CObjectInfo::CLASS_INFO),
 
165
  _DepBaseClass (false)
 
166
 {}
 
167
 
 
168
inline CClassInfo *CClassInfo::BaseObject () const
 
169
 { return (CClassInfo*)CObjectInfo::BaseObject (); }
 
170
inline CTypeClass *CClassInfo::TypeInfo () const
 
171
 { return (CTypeClass*)CObjectInfo::TypeInfo (); }
 
172
 
 
173
inline unsigned CClassInfo::BaseClasses () const
 
174
 { return _BaseClasses.length (); }
 
175
inline unsigned CClassInfo::DerivedClasses () const
 
176
 { return _Derived.length (); }
 
177
inline CBaseClassInfo *CClassInfo::BaseClass (unsigned n) const
 
178
 { return _BaseClasses.lookup (n); }
 
179
inline CClassInfo *CClassInfo::DerivedClass (unsigned n) const
 
180
 { return _Derived.lookup (n); }
 
181
 
 
182
inline bool CClassInfo::hasDepBaseClass () const
 
183
 { return _DepBaseClass; }
 
184
inline void CClassInfo::hasDepBaseClass (bool v)
 
185
 { _DepBaseClass = v; }
 
186
 
 
187
 
 
188
} // namespace Puma
 
189
 
 
190
#endif /* __CClassInfo_h__ */