Update copyright to LGPL on all files
[dyninst.git] / dyninstAPI / src / BPatch_typePrivate.h
1 /*
2  * Copyright (c) 1996-2009 Barton P. Miller
3  * 
4  * We provide the Paradyn Parallel Performance Tools (below
5  * described as "Paradyn") on an AS IS basis, and do not warrant its
6  * validity or performance.  We reserve the right to update, modify,
7  * or discontinue this software at any time.  We shall have no
8  * obligation to supply such updates or modifications or any other
9  * form of support to you.
10  * 
11  * By your use of Paradyn, you understand and agree that we (or any
12  * other person or entity with proprietary rights in Paradyn) are
13  * under no obligation to provide either maintenance services,
14  * update services, notices of latent defects, or correction of
15  * defects for Paradyn.
16  * 
17  * This library is free software; you can redistribute it and/or
18  * modify it under the terms of the GNU Lesser General Public
19  * License as published by the Free Software Foundation; either
20  * version 2.1 of the License, or (at your option) any later version.
21  * 
22  * This library is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
25  * Lesser General Public License for more details.
26  * 
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
30  */
31
32 #ifndef _BPatch_typePrivate_h_
33 #define _BPatch_typePrivate_h_
34
35 #include "BPatch_dll.h"
36 #include "BPatch_Vector.h"
37 #include <string.h>     
38 #include "BPatch_type.h"
39
40 class BPatch_function;
41
42 // Interfaces to be implemented by intermediate subtypes
43 // We have to do this thanks to reference types and C++'s lovely 
44 // multiple inheritance
45
46 class BPATCH_DLL_EXPORT BPatch_fieldListInterface {
47  public:
48    virtual ~BPatch_fieldListInterface() {};
49    virtual BPatch_Vector<BPatch_field *> * getComponents() const = 0;
50 };
51
52 class BPATCH_DLL_EXPORT BPatch_rangedInterface {
53  public:
54    virtual ~BPatch_rangedInterface() {};
55    virtual const char *getLow() const = 0;
56    virtual const char *getHigh() const  = 0;
57 };  
58
59 // Intermediate types (interfaces + BPatch_type)
60
61 class BPATCH_DLL_EXPORT BPatch_fieldListType : public BPatch_type, public BPatch_fieldListInterface {
62  private:
63    void fixupComponents();
64  protected:
65    BPatch_Vector<BPatch_field *> fieldList;
66    BPatch_Vector<BPatch_field *> *derivedFieldList;
67    BPatch_fieldListType(const char *name, int _ID, BPatch_dataClass type);
68    /* Each subclass may need to update its size after adding a field */
69    virtual void postFieldInsert(int offset, int nsize) = 0;
70  public:
71    //void fixupUnknown(BPatch_module *m);
72    ~BPatch_fieldListType();
73    bool operator==(const BPatch_type &) const;
74    BPatch_Vector<BPatch_field *> * getComponents() const;
75    /* Add field for Enum */
76    void addField(const char *_fieldname, int value);
77    /* Add field for C++(has visibility) Enum */
78    void addField(const char * _fieldname,  BPatch_dataClass _typeDes, int value,
79                  BPatch_visibility _vis);
80    /* Add field for C++ struct or union */
81    void addField(const char * _fieldname,  BPatch_dataClass _typeDes, 
82                  BPatch_type *_type, int _offset, int _size);
83    /* Add field for C++(has visibility) struct or union */
84    void addField(const char * _fieldname,  BPatch_dataClass _typeDes, 
85                  BPatch_type *_type, int _offset, int _size, BPatch_visibility _vis);
86    /* Add field for Function parameter */
87    void addField(BPatch_type *_type);
88 };
89
90 class BPATCH_DLL_EXPORT BPatch_rangedType : public BPatch_type, public BPatch_rangedInterface {
91  protected:
92    char *low;
93    char *hi;
94  protected:
95    BPatch_rangedType(const char *_name, int _ID, BPatch_dataClass _class, int _size, const char *_low, const char *_hi); 
96    BPatch_rangedType(const char *_name, int _ID, BPatch_dataClass _class, int _size, int _low, int _hi);
97  public:
98    ~BPatch_rangedType();
99    bool operator==(const BPatch_type &) const;
100    const char *getLow() const { return low; }
101    const char *getHigh() const { return hi; }
102 };
103
104 // Derived classes from BPatch_type
105
106 #ifdef DYNINST_CLASS_NAME
107 #undef DYNINST_CLASS_NAME
108 #endif
109 #define DYNINST_CLASS_NAME BPatch_typeEnum
110
111 class BPATCH_DLL_EXPORT BPatch_typeEnum : public BPatch_fieldListType {
112  protected:
113    void postFieldInsert(int,int) {}
114  public:
115    BPatch_typeEnum(int _ID, const char *_name = NULL);
116    BPatch_typeEnum(const char *_name);
117    API_EXPORT(Int, (otype),
118    bool,isCompatible,(BPatch_type *otype));
119 };
120
121 #ifdef DYNINST_CLASS_NAME
122 #undef DYNINST_CLASS_NAME
123 #endif
124 #define DYNINST_CLASS_NAME BPatch_typePointer
125 class BPATCH_DLL_EXPORT BPatch_typePointer : public BPatch_type {
126  private:
127    BPatch_type *ptr; /* Type that we point to */
128  public:
129    BPatch_typePointer(int _ID, BPatch_type *_ptr, const char *_name = NULL);
130    BPatch_typePointer(BPatch_type *_ptr, const char *_name);
131    ~BPatch_typePointer() { ptr->decrRefCount(); }
132    BPatch_type *getConstituentType() const { return ptr; }
133    API_EXPORT(Int, (otype),
134    bool,isCompatible,(BPatch_type *otype));
135    void fixupUnknowns(BPatch_module *);
136    void setPtr(BPatch_type *_ptr);
137 };
138
139 #ifdef DYNINST_CLASS_NAME
140 #undef DYNINST_CLASS_NAME
141 #endif
142 #define DYNINST_CLASS_NAME BPatch_typeFunction
143 class BPATCH_DLL_EXPORT BPatch_typeFunction : public BPatch_fieldListType {
144  protected:
145    void postFieldInsert(int, int) {}
146  private:
147    BPatch_type *retType; /* Return type of the function */
148  public:
149    BPatch_typeFunction(int _ID, BPatch_type *_retType, const char *_name = NULL);
150    ~BPatch_typeFunction() { retType->decrRefCount(); }
151    BPatch_type *getConstituentType() const { return retType; }
152    API_EXPORT(Int, (otype),
153    bool,isCompatible,(BPatch_type *otype));
154    void fixupUnknowns(BPatch_module *);
155    void setRetType(BPatch_type *rtype);
156    void setName(const char *name);
157 };
158
159 #ifdef DYNINST_CLASS_NAME
160 #undef DYNINST_CLASS_NAME
161 #endif
162 #define DYNINST_CLASS_NAME BPatch_typeRange
163 class BPATCH_DLL_EXPORT BPatch_typeRange : public BPatch_rangedType {
164  public:
165    BPatch_typeRange(int _ID, int _size, const char *_low, const char *_hi, const char *_name);
166    API_EXPORT(Int, (otype),
167    bool,isCompatible,(BPatch_type *otype));
168 };
169
170 #ifdef DYNINST_CLASS_NAME
171 #undef DYNINST_CLASS_NAME
172 #endif
173 #define DYNINST_CLASS_NAME BPatch_typeArray
174 class BPATCH_DLL_EXPORT BPatch_typeArray : public BPatch_rangedType {
175  private:
176    BPatch_type *arrayElem;
177    unsigned int sizeHint;
178  protected:
179    void updateSize();
180  public:
181    bool operator==(const BPatch_type &otype) const;
182    void merge(BPatch_type *other);
183    BPatch_typeArray(int _ID, BPatch_type *_base, int _low, int _hi, const char *_name, unsigned int sizeHint = 0);
184    BPatch_typeArray(BPatch_type *_base, int _low, int _hi, const char *_name);
185    ~BPatch_typeArray() { arrayElem->decrRefCount(); }
186    BPatch_type *getConstituentType() const { return arrayElem; }
187    API_EXPORT(Int, (otype),
188    bool,isCompatible,(BPatch_type *otype));
189    void fixupUnknowns(BPatch_module *);
190 };
191
192 #ifdef DYNINST_CLASS_NAME
193 #undef DYNINST_CLASS_NAME
194 #endif
195 #define DYNINST_CLASS_NAME BPatch_typeStruct
196 class BPATCH_DLL_EXPORT BPatch_typeStruct : public BPatch_fieldListType {
197  protected:
198    void updateSize();
199    void postFieldInsert(int, int nsize) { size += nsize; }
200  public:
201    void merge(BPatch_type *other);
202    BPatch_typeStruct(int _ID, const char *_name = NULL);
203    BPatch_typeStruct(const char *_name);
204    API_EXPORT(Int, (otype),
205    bool,isCompatible,(BPatch_type *otype));
206    void fixupUnknowns(BPatch_module *);
207 };
208
209 #ifdef DYNINST_CLASS_NAME
210 #undef DYNINST_CLASS_NAME
211 #endif
212 #define DYNINST_CLASS_NAME BPatch_typeUnion
213 class BPATCH_DLL_EXPORT BPatch_typeUnion : public BPatch_fieldListType {
214  private:
215    BPatch_Vector<BPatch_field *> fieldList;
216  protected:
217    void updateSize();
218    void postFieldInsert(int, int nsize) { if ((unsigned int) nsize > size) size = nsize; }
219  public:
220    void merge(BPatch_type *other);
221    BPatch_typeUnion(int _ID, const char *_name = NULL);
222    BPatch_typeUnion(const char *name);
223    API_EXPORT(Int, (otype),
224    bool,isCompatible,(BPatch_type *otype));
225    void fixupUnknowns(BPatch_module *);
226 };
227
228 #ifdef DYNINST_CLASS_NAME
229 #undef DYNINST_CLASS_NAME
230 #endif
231 #define DYNINST_CLASS_NAME BPatch_typeScalar
232 class BPATCH_DLL_EXPORT BPatch_typeScalar : public BPatch_type {
233  public:
234    BPatch_typeScalar(int _ID, unsigned int _size, const char *_name = NULL);
235    BPatch_typeScalar(unsigned int _size, const char *_name);
236    API_EXPORT(Int, (otype),
237    bool,isCompatible,(BPatch_type *otype));
238 };
239
240 #ifdef DYNINST_CLASS_NAME
241 #undef DYNINST_CLASS_NAME
242 #endif
243 #define DYNINST_CLASS_NAME BPatch_typeCommon
244 class BPATCH_DLL_EXPORT BPatch_typeCommon : public BPatch_fieldListType {
245  private:
246    BPatch_Vector<BPatch_cblock *> cblocks;
247  protected:
248    void postFieldInsert(int offset, int nsize) { if ((unsigned int) (offset + nsize) > size) size = offset + nsize; }
249  public:
250    BPatch_typeCommon(int _ID, const char *_name = NULL);
251    BPatch_typeCommon(const char *_name);
252    BPatch_Vector<BPatch_cblock *> *getCblocks() const { return const_cast<BPatch_Vector<BPatch_cblock*>*>(&cblocks); }
253    void beginCommonBlock();
254    void endCommonBlock(BPatch_function *, void *baseAddr);
255    void fixupUnknowns(BPatch_module *);
256 };
257
258 // Typedefs and eferences are special, because we have to treat 
259 // them as a union of BPatch_type, BPatch_fieldListType, and BPatch_rangedType
260
261 #ifdef DYNINST_CLASS_NAME
262 #undef DYNINST_CLASS_NAME
263 #endif
264 #define DYNINST_CLASS_NAME BPatch_typeTypedef
265 class BPATCH_DLL_EXPORT BPatch_typeTypedef : public BPatch_type, public BPatch_fieldListInterface, public BPatch_rangedInterface {
266  private:
267    BPatch_type *base; /* The type that we refer to */
268    unsigned int sizeHint;
269  protected:
270    void updateSize();
271  public:
272    BPatch_typeTypedef(int _ID, BPatch_type *_base, const char *_name = NULL, unsigned int _sizeHint = 0);
273    BPatch_typeTypedef(BPatch_type *_base, const char *_name);
274    ~BPatch_typeTypedef() { base->decrRefCount(); }
275    bool operator==(const BPatch_type &otype) const;
276    bool isCompatible(BPatch_type *otype) { return base->isCompatible(otype); }
277    BPatch_type *getConstituentType() const { return base; }
278    // Overriding the interfaces to use the underlying object
279    BPatch_Vector<BPatch_field *> * getComponents() const;
280    const char *getLow() const;
281    const char *getHigh() const;
282    void fixupUnknowns(BPatch_module *);
283 };
284
285 #ifdef DYNINST_CLASS_NAME
286 #undef DYNINST_CLASS_NAME
287 #endif
288 #define DYNINST_CLASS_NAME BPatch_typeRef
289 class BPATCH_DLL_EXPORT BPatch_typeRef : public BPatch_type, public BPatch_fieldListInterface, public BPatch_rangedInterface {
290  private:
291    BPatch_type *refType; /* Type that we refer to */
292  public:
293    BPatch_typeRef(int _ID, BPatch_type *_refType, const char *_name = NULL);
294    ~BPatch_typeRef() { refType->decrRefCount(); }
295    bool operator==(const BPatch_type &otype) const;
296    API_EXPORT(Int, (otype),
297    bool,isCompatible,(BPatch_type *otype));
298    BPatch_type *getConstituentType() const { return refType; }
299    // Overriding the interfaces to use the underlying object
300    BPatch_Vector<BPatch_field *> * getComponents() const;
301    const char *getLow() const;
302    const char *getHigh() const;
303    void fixupUnknowns(BPatch_module *);
304 };
305
306 #endif