19
19
#ifndef __CClassDatabase_h__
20
20
#define __CClassDatabase_h__
22
#include "Puma/CScopeInfo.h"
23
#include "Puma/CProject.h"
23
* Alias for CSemDatabase. */
25
#include "Puma/CSemDatabase.h"
36
class CTemplateParamInfo;
42
* Database of all semantic objects (infos) of a project.
43
* \see Puma::CClassDatabase */
45
/** \class CClassDatabase CClassDatabase.h Puma/infos/CClassDatabase.h
46
* A CClassDatabase object is a database of all semantic objects
47
* (infos) of a project. */
48
class CClassDatabase {
50
Array<CObjectInfo*> _Classes; // index of classes
51
Array<CObjectInfo*> _Unions; // index of unions
52
Array<CObjectInfo*> _Enums; // index of enums
53
Array<CObjectInfo*> _Typedefs; // index of typedefs
54
Array<CObjectInfo*> _Functions; // index of functions
55
Array<CObjectInfo*> _Files; // index of files
57
CProject *_Project; // associated project
59
multimap<int,CFunctionInfo*> _builtin_ops; // map for built-in operator lookup
62
/** Construct a class database object.
63
* \param prj The corresponding project.
64
* \param size Not used. */
65
CClassDatabase (CProject &prj, int size = 997);
66
/** Destruct the class database. Also destroys all infos
68
virtual ~CClassDatabase ();
70
// access to the database entries /////////////////////////////
72
/** Get the number of semantic object infos. */
73
unsigned ObjectInfos () const;
74
/** Get the number of class infos. */
75
unsigned ClassInfos () const;
76
/** Get the number of union infos. */
77
unsigned UnionInfos () const;
78
/** Get the number of enumeration infos. */
79
unsigned EnumInfos () const;
80
/** Get the number of typedef infos. */
81
unsigned TypedefInfos () const;
82
/** Get the number of function infos. */
83
unsigned FunctionInfos () const;
84
/** Get the number of on-demand generated built-in operator functions. */
85
unsigned FileInfos () const;
86
/** Get the n-th semantic object info.
87
* \param n The number of the info.
88
* \return The info or \c NULL if \e n is invalid. */
89
CObjectInfo *ObjectInfo (unsigned n) const;
90
/** Get the n-th class info.
91
* \param n The number of the info.
92
* \return The info or \c NULL if \e n is invalid. */
93
CClassInfo *ClassInfo (unsigned n) const;
94
/** Get the n-th union info.
95
* \param n The number of the info.
96
* \return The info or \c NULL if \e n is invalid. */
97
CUnionInfo *UnionInfo (unsigned n) const;
98
/** Get the n-th enumeration info.
99
* \param n The number of the info.
100
* \return The info or \c NULL if \e n is invalid. */
101
CEnumInfo *EnumInfo (unsigned n) const;
102
/** Get the n-th typedef info.
103
* \param n The number of the info.
104
* \return The info or \c NULL if \e n is invalid. */
105
CTypedefInfo *TypedefInfo (unsigned n) const;
106
/** Get the n-th function info.
107
* \param n The number of the info.
108
* \return The info or \c NULL if \e n is invalid. */
109
CFunctionInfo *FunctionInfo (unsigned n) const;
110
/** Get the n-th on-demand generated built-in operator info.
111
* \param n The number of the info.
112
* \return The info or \c NULL if \e n is invalid. */
113
CFileInfo *FileInfo (unsigned n) const;
115
/** Get the semantic object info identified by the given
116
* source code position.
117
* \param pos The position in the source code.
118
* \return The info or \c NULL if the info could not be identified. */
119
CObjectInfo *ObjectInfo (Token *pos) const;
120
/** Get the semantic object info identified by the given
121
* source code position.
122
* \param pos The position in the source code.
123
* \return The info or \c NULL if the info could not be identified. */
124
CObjectInfo *ObjectInfo (CT_Token *pos) const;
127
// Administration /////////////////////////////////////////////
129
/** Insert a new semantic object into the database.
130
* \param info The semantic object info to insert. */
131
void Insert (CObjectInfo *info);
132
/** Remove the given semantic object from the database.
133
* \param info The semantic object info to remove. */
134
void Remove (CObjectInfo *info);
135
/** Get a function info object for a built-in operator.
136
* \param name Operator name.
137
* \param tok Operator token type, used as a key for fast lookup.
138
* \param rtype result type of the operator. Not used for lookup,
139
* only for object creation.
140
* \param t0 first argument type.
141
* \param t1 second argument type or \c NULL.
142
* \return on-demand generated operator function object. */
143
CFunctionInfo *BuiltinOperator (const char *name, int tok, CTypeInfo *rtype,
144
CTypeInfo *t0, CTypeInfo *t1);
145
/** Dump the contents of the database. The dump is indented as
146
* tree corresponding to the nesting of the semantic objects.
147
* \param out The output stream to dump to.
148
* \param depth The max. depth in the tree to be dumped. */
149
void Dump (ostream &out, int depth = 0) const;
151
/** Get the project info delivered to the constructor of the database. */
152
CProject *Project () const;
155
void CreateParameter (CFunctionInfo *fi, CTypeInfo *type) const;
157
void Dump (ostream &, CStructure *, int, int) const;
158
void DumpType (ostream &, CObjectInfo *, int) const;
159
void DumpUsing (ostream &, CUsingInfo *, int) const;
160
void DumpFunction (ostream &, CFunctionInfo *, int, int) const;
161
void DumpAttribute (ostream &, CAttributeInfo *, int) const;
162
void DumpNamespace (ostream &, CNamespaceInfo *, int) const;
163
void DumpQualities (ostream &, CObjectInfo *) const;
164
void DumpScopeName (ostream &, CStructure *) const;
165
void DumpLocalScope (ostream &, CObjectInfo *, int) const;
166
void DumpTemplateParam (ostream &, CTemplateParamInfo *, int) const;
167
void indent (ostream &, int) const;
169
// unsigned Infos (const char *, unsigned) const;
170
// CObjectInfo *Info (const char *, unsigned, unsigned) const;
173
inline CClassDatabase::CClassDatabase (CProject &p, int size) :
177
inline unsigned CClassDatabase::ObjectInfos () const
178
{ return ClassInfos () + UnionInfos () + EnumInfos () +
179
TypedefInfos () + FunctionInfos () + FileInfos (); }
180
inline unsigned CClassDatabase::ClassInfos () const
181
{ return _Classes.length (); }
182
inline unsigned CClassDatabase::UnionInfos () const
183
{ return _Unions.length (); }
184
inline unsigned CClassDatabase::EnumInfos () const
185
{ return _Enums.length (); }
186
inline unsigned CClassDatabase::TypedefInfos () const
187
{ return _Typedefs.length (); }
188
inline unsigned CClassDatabase::FunctionInfos () const
189
{ return _Functions.length (); }
190
inline unsigned CClassDatabase::FileInfos () const
191
{ return _Files.length (); }
193
inline CClassInfo *CClassDatabase::ClassInfo (unsigned i) const
194
{ return (CClassInfo*)_Classes.lookup (i); }
195
inline CUnionInfo *CClassDatabase::UnionInfo (unsigned i) const
196
{ return (CUnionInfo*)_Unions.lookup (i); }
197
inline CEnumInfo *CClassDatabase::EnumInfo (unsigned i) const
198
{ return (CEnumInfo*)_Enums.lookup (i); }
199
inline CTypedefInfo *CClassDatabase::TypedefInfo (unsigned i) const
200
{ return (CTypedefInfo*)_Typedefs.lookup (i); }
201
inline CFunctionInfo *CClassDatabase::FunctionInfo (unsigned i) const
202
{ return (CFunctionInfo*)_Functions.lookup (i); }
203
inline CFileInfo *CClassDatabase::FileInfo (unsigned i) const
204
{ return (CFileInfo*)_Files.lookup (i); }
206
inline CProject *CClassDatabase::Project () const
30
/** Backward compatibility alias for CSemDatabase. */
31
typedef CSemDatabase CClassDatabase;
210
34
} // namespace Puma