Ghidra Decompiler Analysis Engine
type.hh
Go to the documentation of this file.
1 /* ###
2  * IP: GHIDRA
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
18 
19 #ifndef __CPUI_TYPE__
20 #define __CPUI_TYPE__
21 
22 #include "address.hh"
23 
25 extern void print_data(ostream &s,uint1 *buffer,int4 size,const Address &baseaddr);
26 //extern void print_char(ostream &s,int4 onechar);
27 //extern bool print_string(ostream &s,uint1 *buffer,int4 size);
28 
34  TYPE_VOID = 10,
37  TYPE_INT = 7,
38  TYPE_UINT = 6,
39  TYPE_BOOL = 5,
40  TYPE_CODE = 4,
41  TYPE_FLOAT = 3,
42 
43  TYPE_PTR = 2,
44  TYPE_ARRAY = 1,
46 };
47 
49 extern void metatype2string(type_metatype metatype,string &res);
50 
52 extern type_metatype string2metatype(const string &metastring);
53 
54 class Architecture; // Forward declarations
55 class Scope;
56 class TypeFactory;
57 struct DatatypeCompare;
58 
62 class Datatype {
63 protected:
65  enum {
66  coretype = 1,
67  // Bits above the first bit are considered a sub-metatype
68  // If the metatypes are equal, we compare on sub-metatype
69  // Currently this is only used to order int, char, and enum
70  // The order of the sub-metatype is reversed so that
71  // char comes before int1
72  chartype = 2,
73  enumtype = 4,
74  poweroftwo = 8,
75  utf16 = 16,
76  utf32 = 32,
79  };
80  friend class TypeFactory;
81  friend struct DatatypeCompare;
82  int4 size;
83  string name;
85  uint4 flags;
86  uint8 id;
87  void restoreXmlBasic(const Element *el);
88  virtual void restoreXml(const Element *el,TypeFactory &typegrp);
89  static uint8 hashName(const string &nm);
90  static uint8 hashSize(uint8 id,int4 size);
91 public:
93  Datatype(const Datatype &op) { size = op.size; name=op.name; metatype=op.metatype; flags=op.flags; id=op.id; }
95  Datatype(int4 s,type_metatype m) { size=s; metatype=m; flags=0; id=0; }
97  Datatype(int4 s,type_metatype m,const string &n) { name=n; size=s; metatype=m; flags=0; id=0; }
98  virtual ~Datatype(void) {}
99  bool isCoreType(void) const { return ((flags&coretype)!=0); }
100  bool isCharPrint(void) const { return ((flags&(chartype|utf16|utf32|opaque_string))!=0); }
101  bool isEnumType(void) const { return ((flags&enumtype)!=0); }
102  bool isPowerOfTwo(void) const { return ((flags&poweroftwo)!=0); }
103  bool isASCII(void) const { return ((flags&chartype)!=0); }
104  bool isUTF16(void) const { return ((flags&utf16)!=0); }
105  bool isUTF32(void) const { return ((flags&utf32)!=0); }
106  bool isVariableLength(void) const { return ((flags&variable_length)!=0); }
107  bool hasSameVariableBase(const Datatype *ct) const;
108  bool isOpaqueString(void) const { return ((flags&opaque_string)!=0); }
109  uint4 getInheritable(void) const { return (flags & coretype); }
110  type_metatype getMetatype(void) const { return metatype; }
111  uint8 getId(void) const { return id; }
112  int4 getSize(void) const { return size; }
113  const string &getName(void) const { return name; }
114  virtual void printRaw(ostream &s) const;
115  virtual Datatype *getSubType(uintb off,uintb *newoff) const;
116  virtual Datatype *nearestArrayedComponentForward(uintb off,uintb *newoff,int4 *elSize) const;
117  virtual Datatype *nearestArrayedComponentBackward(uintb off,uintb *newoff,int4 *elSize) const;
118  virtual int4 numDepend(void) const { return 0; }
119  virtual Datatype *getDepend(int4 index) const { return (Datatype *)0; }
120  virtual void printNameBase(ostream &s) const { if (!name.empty()) s<<name[0]; }
121  virtual int4 compare(const Datatype &op,int4 level) const;
122  virtual int4 compareDependency(const Datatype &op) const;
123  virtual Datatype *clone(void) const=0;
124  virtual void saveXml(ostream &s) const;
125  int4 typeOrder(const Datatype &op) const { if (this==&op) return 0; return compare(op,10); }
126  int4 typeOrderBool(const Datatype &op) const;
127  void saveXmlBasic(ostream &s) const;
128  void saveXmlRef(ostream &s) const;
129  bool isPtrsubMatching(uintb offset) const;
130 };
131 
133 struct TypeField {
134  int4 offset;
135  string name;
137  bool operator<(const TypeField &op2) const { return (offset < op2.offset); }
138 };
139 
143  bool operator()(const Datatype *a,const Datatype *b) const {
144  int4 res = a->compareDependency(*b);
145  if (res != 0) return (res<0);
146  return a->getId() < b->getId(); }
147 };
148 
152  bool operator()(const Datatype *a,const Datatype *b) const {
153  int4 res = a->getName().compare( b->getName() );
154  if (res != 0) return (res < 0);
155  return a->getId() < b->getId(); }
156 };
157 
159 typedef set<Datatype *,DatatypeCompare> DatatypeSet;
160 
162 typedef set<Datatype *,DatatypeNameCompare> DatatypeNameSet;
163 
167 class TypeBase : public Datatype {
168 protected:
169  friend class TypeFactory;
170 public:
172  TypeBase(const TypeBase &op) : Datatype(op) {}
174  TypeBase(int4 s,type_metatype m) : Datatype(s,m) {}
176  TypeBase(int4 s,type_metatype m,const string &n) : Datatype(s,m,n) {}
177  virtual Datatype *clone(void) const { return new TypeBase(*this); }
178 };
179 
183 class TypeChar : public TypeBase {
184 protected:
185  friend class TypeFactory;
186 public:
190  TypeChar(const string &n) : TypeBase(1,TYPE_INT,n) { flags |= Datatype::chartype; }
191  virtual Datatype *clone(void) const { return new TypeChar(*this); }
192  virtual void saveXml(ostream &s) const;
193 };
194 
198 class TypeUnicode : public TypeBase { // Unicode character type
199  void setflags(void);
200 protected:
201  friend class TypeFactory;
202  virtual void restoreXml(const Element *el,TypeFactory &typegrp);
203 public:
204  TypeUnicode(void) : TypeBase(0,TYPE_INT) {}
205  TypeUnicode(const TypeUnicode &op) : TypeBase(op) {}
206  TypeUnicode(const string &nm,int4 sz,type_metatype m);
207  virtual Datatype *clone(void) const { return new TypeUnicode(*this); }
208  virtual void saveXml(ostream &s) const;
209 };
210 
215 class TypeVoid : public Datatype {
216 protected:
217  friend class TypeFactory;
218 public:
223  virtual Datatype *clone(void) const { return new TypeVoid(*this); }
224  virtual void saveXml(ostream &s) const;
225 };
226 
228 class TypePointer : public Datatype {
229 protected:
230  friend class TypeFactory;
232  uint4 wordsize;
233  virtual void restoreXml(const Element *el,TypeFactory &typegrp);
236 public:
238  TypePointer(const TypePointer &op) : Datatype(op) { ptrto = op.ptrto; wordsize=op.wordsize; }
240  TypePointer(int4 s,Datatype *pt,uint4 ws) : Datatype(s,TYPE_PTR) { ptrto = pt; flags = ptrto->getInheritable(); wordsize=ws; }
241  Datatype *getPtrTo(void) const { return ptrto; }
242  uint4 getWordSize(void) const { return wordsize; }
243  virtual void printRaw(ostream &s) const;
244  virtual int4 numDepend(void) const { return 1; }
245  virtual Datatype *getDepend(int4 index) const { return ptrto; }
246  virtual void printNameBase(ostream &s) const { s << 'p'; ptrto->printNameBase(s); }
247  virtual int4 compare(const Datatype &op,int4 level) const; // For tree structure
248  virtual int4 compareDependency(const Datatype &op) const; // For tree structure
249  virtual Datatype *clone(void) const { return new TypePointer(*this); }
250  virtual void saveXml(ostream &s) const;
251 };
252 
254 class TypeArray : public Datatype {
255 protected:
256  friend class TypeFactory;
258  int4 arraysize;
259  virtual void restoreXml(const Element *el,TypeFactory &typegrp);
262 public:
264  TypeArray(const TypeArray &op) : Datatype(op) { arrayof = op.arrayof; arraysize = op.arraysize; }
266  TypeArray(int4 n,Datatype *ao) : Datatype(n*ao->getSize(),TYPE_ARRAY) {
267  arraysize = n; arrayof = ao; }
268  Datatype *getBase(void) const { return arrayof; }
269  int4 numElements(void) const { return arraysize; }
270  Datatype *getSubEntry(int4 off,int4 sz,int4 *newoff,int4 *el) const;
271  virtual void printRaw(ostream &s) const;
272  virtual Datatype *getSubType(uintb off,uintb *newoff) const;
273  virtual int4 numDepend(void) const { return 1; }
274  virtual Datatype *getDepend(int4 index) const { return arrayof; }
275  virtual void printNameBase(ostream &s) const { s << 'a'; arrayof->printNameBase(s); }
276  virtual int4 compare(const Datatype &op,int4 level) const; // For tree structure
277  virtual int4 compareDependency(const Datatype &op) const; // For tree structure
278  virtual Datatype *clone(void) const { return new TypeArray(*this); }
279  virtual void saveXml(ostream &s) const;
280 };
281 
286 class TypeEnum : public TypeBase {
287 protected:
288  friend class TypeFactory;
289  map<uintb,string> namemap;
290  vector<uintb> masklist;
291  void setNameMap(const map<uintb,string> &nmap);
292  virtual void restoreXml(const Element *el,TypeFactory &typegrp);
293 public:
295  TypeEnum(const TypeEnum &op);
297  TypeEnum(int4 s,type_metatype m) : TypeBase(s,m) { flags |= enumtype; }
299  TypeEnum(int4 s,type_metatype m,const string &nm) : TypeBase(s,m,nm) { flags |= enumtype; }
300  map<uintb,string>::const_iterator beginEnum(void) const { return namemap.begin(); }
301  map<uintb,string>::const_iterator endEnum(void) const { return namemap.end(); }
302  bool getMatches(uintb val,vector<string> &matchname) const;
303  virtual int4 compare(const Datatype &op,int4 level) const;
304  virtual int4 compareDependency(const Datatype &op) const;
305  virtual Datatype *clone(void) const { return new TypeEnum(*this); }
306  virtual void saveXml(ostream &s) const;
307 };
308 
310 class TypeStruct : public Datatype {
311 protected:
312  friend class TypeFactory;
313  vector<TypeField> field;
314  void setFields(const vector<TypeField> &fd);
315  int4 getFieldIter(int4 off) const;
316  int4 getLowerBoundField(int4 off) const;
317  virtual void restoreXml(const Element *el,TypeFactory &typegrp);
318 public:
319  TypeStruct(const TypeStruct &op);
320  TypeStruct(const string &n) : Datatype(0,TYPE_STRUCT,n) {}
321  vector<TypeField>::const_iterator beginField(void) const { return field.begin(); }
322  vector<TypeField>::const_iterator endField(void) const { return field.end(); }
323  const TypeField *getField(int4 off,int4 sz,int4 *newoff) const;
324  virtual Datatype *getSubType(uintb off,uintb *newoff) const;
325  virtual Datatype *nearestArrayedComponentForward(uintb off,uintb *newoff,int4 *elSize) const;
326  virtual Datatype *nearestArrayedComponentBackward(uintb off,uintb *newoff,int4 *elSize) const;
327  virtual int4 numDepend(void) const { return field.size(); }
328  virtual Datatype *getDepend(int4 index) const { return field[index].type; }
329  virtual int4 compare(const Datatype &op,int4 level) const; // For tree structure
330  virtual int4 compareDependency(const Datatype &op) const; // For tree structure
331  virtual Datatype *clone(void) const { return new TypeStruct(*this); }
332  virtual void saveXml(ostream &s) const;
333 };
334 
335 class FuncProto; // Forward declaration
336 class ProtoModel;
337 
341 class TypeCode : public Datatype {
342 protected:
343  friend class TypeFactory;
346  void set(TypeFactory *tfact,ProtoModel *model,
347  Datatype *outtype,const vector<Datatype *> &intypes,
348  bool dotdotdot,Datatype *voidtype);
349  virtual void restoreXml(const Element *el,TypeFactory &typegrp);
350 public:
351  TypeCode(const TypeCode &op);
352  TypeCode(const string &nm);
353  int4 compareBasic(const TypeCode *op) const;
354  const FuncProto *getPrototype(void) const { return proto; }
355  void setProperties(bool isConstructor,bool isDestructor);
356  virtual ~TypeCode(void);
357  virtual void printRaw(ostream &s) const;
358  virtual Datatype *getSubType(uintb off,uintb *newoff) const;
359  virtual int4 compare(const Datatype &op,int4 level) const;
360  virtual int4 compareDependency(const Datatype &op) const;
361  virtual Datatype *clone(void) const { return new TypeCode(*this); }
362  virtual void saveXml(ostream &s) const;
363 };
364 
370 class TypeSpacebase : public Datatype {
371  friend class TypeFactory;
372  AddrSpace *spaceid;
373  Address localframe;
374  Architecture *glb;
375  virtual void restoreXml(const Element *el,TypeFactory &typegrp);
376 public:
379  spaceid = op.spaceid; localframe=op.localframe; glb=op.glb;
380  }
383  : Datatype(0,TYPE_SPACEBASE), localframe(frame) { spaceid = id; glb = g; }
384  Scope *getMap(void) const;
385  Address getAddress(uintb off,int4 sz,const Address &point) const;
386  virtual Datatype *getSubType(uintb off,uintb *newoff) const;
387  virtual Datatype *nearestArrayedComponentForward(uintb off,uintb *newoff,int4 *elSize) const;
388  virtual Datatype *nearestArrayedComponentBackward(uintb off,uintb *newoff,int4 *elSize) const;
389  virtual int4 compare(const Datatype &op,int4 level) const;
390  virtual int4 compareDependency(const Datatype &op) const; // For tree structure
391  virtual Datatype *clone(void) const { return new TypeSpacebase(*this); }
392  virtual void saveXml(ostream &s) const;
393 };
394 
396 class TypeFactory {
397  int4 sizeOfInt;
398  int4 align;
399  int4 enumsize;
400  type_metatype enumtype;
401  DatatypeSet tree;
402  DatatypeNameSet nametree;
403  Datatype *typecache[9][8];
404  Datatype *typecache10;
405  Datatype *typecache16;
406  Datatype *type_nochar;
407  Datatype *findNoName(Datatype &ct);
408  Datatype *findAdd(Datatype &ct);
409  void orderRecurse(vector<Datatype *> &deporder,DatatypeSet &mark,Datatype *ct) const;
410  Datatype *restoreXmlTypeNoRef(const Element *el,bool forcecore);
411  void clearCache(void);
412  TypeChar *getTypeChar(const string &n);
413  TypeUnicode *getTypeUnicode(const string &nm,int4 sz,type_metatype m);
414  TypeCode *getTypeCode(const string &n);
415 protected:
417  Datatype *findByIdLocal(const string &nm,uint8 id) const;
418  virtual Datatype *findById(const string &n,uint8 id);
419 public:
421  void setupSizes(void);
422  void clear(void);
423  void clearNoncore(void);
424  virtual ~TypeFactory(void);
425  void setStructAlign(int4 al) { align = al; }
426  int4 getStructAlign(void) const { return align; }
427  int4 getSizeOfInt(void) const { return sizeOfInt; }
428  Architecture *getArch(void) const { return glb; }
429  Datatype *findByName(const string &n);
430  Datatype *setName(Datatype *ct,const string &n);
431  bool setFields(vector<TypeField> &fd,TypeStruct *ot,int4 fixedsize,uint4 flags);
432  bool setEnumValues(const vector<string> &namelist,
433  const vector<uintb> &vallist,
434  const vector<bool> &assignlist,
435  TypeEnum *te);
436  Datatype *restoreXmlType(const Element *el);
437  Datatype *restoreXmlTypeWithCodeFlags(const Element *el,bool isConstructor,bool isDestructor);
438  TypeVoid *getTypeVoid(void);
440  Datatype *getBase(int4 s,type_metatype m);
441  Datatype *getBase(int4 s,type_metatype m,const string &n);
442  TypeCode *getTypeCode(void);
443  TypePointer *getTypePointerStripArray(int4 s,Datatype *pt,uint4 ws);
444  TypePointer *getTypePointer(int4 s,Datatype *pt,uint4 ws);
445  TypePointer *getTypePointerNoDepth(int4 s,Datatype *pt,uint4 ws);
446  TypeArray *getTypeArray(int4 as,Datatype *ao);
447  TypeStruct *getTypeStruct(const string &n);
448  TypeEnum *getTypeEnum(const string &n);
449  TypeSpacebase *getTypeSpacebase(AddrSpace *id,const Address &addr);
450  TypeCode *getTypeCode(ProtoModel *model,Datatype *outtype,
451  const vector<Datatype *> &intypes,
452  bool dotdotdot);
453  void destroyType(Datatype *ct);
454  Datatype *downChain(Datatype *ptrtype,uintb &off);
456  void dependentOrder(vector<Datatype *> &deporder) const;
457  void saveXml(ostream &s) const;
458  void saveXmlCoreTypes(ostream &s) const;
459  void restoreXml(const Element *el);
460  void restoreXmlCoreTypes(const Element *el);
461  void parseDataOrganization(const Element *el);
462  void parseEnumConfig(const Element *el);
463  void setCoreType(const string &name,int4 size,type_metatype meta,bool chartp);
464  void cacheCoreTypes(void);
465 };
466 
473 inline int4 Datatype::typeOrderBool(const Datatype &op) const
474 
475 {
476  if (this == &op) return 0;
477  if (metatype == TYPE_BOOL) return 1; // Never prefer bool over other data-types
478  if (op.metatype == TYPE_BOOL) return -1;
479  return compare(op,10);
480 }
481 
482 #endif
Datatype::hasSameVariableBase
bool hasSameVariableBase(const Datatype *ct) const
Are these the same variable length data-type.
Definition: type.cc:70
TypeUnicode::restoreXml
virtual void restoreXml(const Element *el, TypeFactory &typegrp)
Restore data-type from XML.
Definition: type.cc:457
TypeArray::TypeArray
TypeArray(int4 n, Datatype *ao)
Construct given an array size and element data-type.
Definition: type.hh:266
Datatype::nearestArrayedComponentForward
virtual Datatype * nearestArrayedComponentForward(uintb off, uintb *newoff, int4 *elSize) const
Definition: type.cc:114
TypePointer::TypePointer
TypePointer(void)
Internal constructor for use with restoreXml.
Definition: type.hh:235
TypePointer::TypePointer
TypePointer(int4 s, Datatype *pt, uint4 ws)
Construct from a size, pointed-to type, and wordsize.
Definition: type.hh:240
TypeEnum::TypeEnum
TypeEnum(int4 s, type_metatype m)
Construct from a size and meta-type (TYPE_INT or TYPE_UINT)
Definition: type.hh:297
AddrSpace
A region where processor data is stored.
Definition: space.hh:73
TypePointer
Datatype object representing a pointer.
Definition: type.hh:228
TypeArray::clone
virtual Datatype * clone(void) const
Clone the data-type.
Definition: type.hh:278
TypePointer::wordsize
uint4 wordsize
What size unit does the pointer address.
Definition: type.hh:232
metatype2string
void metatype2string(type_metatype metatype, string &res)
Convert type meta-type to name.
Definition: type.cc:169
TypeArray::restoreXml
virtual void restoreXml(const Element *el, TypeFactory &typegrp)
Restore data-type from XML.
Definition: type.cc:624
TypeEnum::TypeEnum
TypeEnum(int4 s, type_metatype m, const string &nm)
Construct from a size, meta-type, and name.
Definition: type.hh:299
TypeArray::saveXml
virtual void saveXml(ostream &s) const
Serialize the data-type to XML.
Definition: type.cc:613
Datatype::utf32
@ utf32
32-bit wide chars in unicode UTF32
Definition: type.hh:76
TypeFactory::getTypePointer
TypePointer * getTypePointer(int4 s, Datatype *pt, uint4 ws)
Construct an absolute pointer data-type.
Definition: type.cc:2038
TypeFactory::getBase
Datatype * getBase(int4 s, type_metatype m)
Get atomic type.
Definition: type.cc:1947
TypePointer::TypePointer
TypePointer(const TypePointer &op)
Construct from another TypePointer.
Definition: type.hh:238
TypeFactory::restoreXmlType
Datatype * restoreXmlType(const Element *el)
Restore Datatype from XML.
Definition: type.cc:2188
TypeArray::arraysize
int4 arraysize
Number of elements in the array.
Definition: type.hh:258
TypeCode::printRaw
virtual void printRaw(ostream &s) const
Print a description of the type to stream.
Definition: type.cc:1150
Datatype::getSubType
virtual Datatype * getSubType(uintb off, uintb *newoff) const
Recover component data-type one-level down.
Definition: type.cc:100
TypeChar::saveXml
virtual void saveXml(ostream &s) const
Serialize the data-type to XML.
Definition: type.cc:435
TYPE_ARRAY
@ TYPE_ARRAY
Array data-type, made up of a sequence of "element" datatype.
Definition: type.hh:44
TypeUnicode::TypeUnicode
TypeUnicode(const string &nm, int4 sz, type_metatype m)
Construct given name,size, meta-type.
Definition: type.cc:465
TypeBase::TypeBase
TypeBase(int4 s, type_metatype m)
Construct TypeBase from a size and meta-type.
Definition: type.hh:174
TypeFactory::clearNoncore
void clearNoncore(void)
Clear out non-core types.
Definition: type.cc:1604
Datatype::isPtrsubMatching
bool isPtrsubMatching(uintb offset) const
Is this data-type suitable as input to a CPUI_PTRSUB op.
Definition: type.cc:323
TypeStruct::getFieldIter
int4 getFieldIter(int4 off) const
Get index into field list.
Definition: type.cc:847
TypeFactory::saveXml
void saveXml(ostream &s) const
Save this container to stream.
Definition: type.cc:2248
TypePointer::ptrto
Datatype * ptrto
Type being pointed to.
Definition: type.hh:231
Datatype::opaque_string
@ opaque_string
Structure that should be treated as a string.
Definition: type.hh:77
TypeSpacebase::getMap
Scope * getMap(void) const
Get the symbol table indexed by this.
Definition: type.cc:1309
TypeArray::arrayof
Datatype * arrayof
type of which we have an array
Definition: type.hh:257
TypeSpacebase::getSubType
virtual Datatype * getSubType(uintb off, uintb *newoff) const
Recover component data-type one-level down.
Definition: type.cc:1321
TypeFactory::setupSizes
void setupSizes(void)
Derive some size information from Architecture.
Definition: type.cc:1495
Datatype::poweroftwo
@ poweroftwo
An enumeration type where all values are of 2^^n form.
Definition: type.hh:74
TypeFactory::getTypeSpacebase
TypeSpacebase * getTypeSpacebase(AddrSpace *id, const Address &addr)
Create a "spacebase" type.
Definition: type.cc:2107
Datatype::chartype
@ chartype
ASCII character data.
Definition: type.hh:72
TYPE_INT
@ TYPE_INT
Signed integer. Signed is considered less specific than unsigned in C.
Definition: type.hh:37
TypeFactory::findById
virtual Datatype * findById(const string &n, uint8 id)
Search by name and id.
Definition: type.cc:1657
Datatype::name
string name
Name of type.
Definition: type.hh:83
TypeCode::set
void set(TypeFactory *tfact, ProtoModel *model, Datatype *outtype, const vector< Datatype * > &intypes, bool dotdotdot, Datatype *voidtype)
Establish a function pointer.
Definition: type.cc:1101
print_data
void print_data(ostream &s, uint1 *buffer, int4 size, const Address &baseaddr)
Print a hex dump of a data buffer to stream.
Definition: type.cc:27
TypeFactory::destroyType
void destroyType(Datatype *ct)
Remove a data-type from this.
Definition: type.cc:2132
TypeFactory::setEnumValues
bool setEnumValues(const vector< string > &namelist, const vector< uintb > &vallist, const vector< bool > &assignlist, TypeEnum *te)
Set named values for an enumeration.
Definition: type.cc:1818
Datatype::Datatype
Datatype(int4 s, type_metatype m)
Construct the base data-type providing size and meta-type.
Definition: type.hh:95
TypeStruct::setFields
void setFields(const vector< TypeField > &fd)
Establish fields for this.
Definition: type.cc:828
Datatype::id
uint8 id
A unique id for the type (or 0 if an id is not assigned)
Definition: type.hh:86
TypeChar
Base type for character data-types: i.e. char.
Definition: type.hh:183
TypeFactory::getTypeEnum
TypeEnum * getTypeEnum(const string &n)
Create an (empty) enumeration.
Definition: type.cc:2095
TypeArray::printRaw
virtual void printRaw(ostream &s) const
Print a description of the type to stream.
Definition: type.cc:552
Datatype::hashSize
static uint8 hashSize(uint8 id, int4 size)
Reversibly hash size into id.
Definition: type.cc:426
TypeUnicode::clone
virtual Datatype * clone(void) const
Clone the data-type.
Definition: type.hh:207
TypeCode::compareBasic
int4 compareBasic(const TypeCode *op) const
Compare surface characteristics of two TypeCodes.
Definition: type.cc:1177
TypeFactory::findByIdLocal
Datatype * findByIdLocal(const string &nm, uint8 id) const
Search locally by name and id.
Definition: type.cc:1633
Datatype::Datatype
Datatype(const Datatype &op)
Construct the base data-type copying low-level properties of another.
Definition: type.hh:93
TypeFactory::~TypeFactory
virtual ~TypeFactory(void)
Destructor.
Definition: type.cc:1623
TypeCode
Datatype object representing executable code.
Definition: type.hh:341
Scope
A collection of Symbol objects within a single (namespace or functional) scope.
Definition: database.hh:402
TypeStruct
A composite Datatype object: A "structure" with component "fields".
Definition: type.hh:310
TypeCode::restoreXml
virtual void restoreXml(const Element *el, TypeFactory &typegrp)
Restore data-type from XML.
Definition: type.cc:1287
TypeSpacebase::saveXml
virtual void saveXml(ostream &s) const
Serialize the data-type to XML.
Definition: type.cc:1447
TypeStruct::getLowerBoundField
int4 getLowerBoundField(int4 off) const
Get index of last field before or equal to given offset.
Definition: type.cc:871
TypePointer::restoreXml
virtual void restoreXml(const Element *el, TypeFactory &typegrp)
Restore data-type from XML.
Definition: type.cc:537
TYPE_SPACEBASE
@ TYPE_SPACEBASE
Placeholder for symbol/type look-up calculations.
Definition: type.hh:35
TypeFactory::getTypePointerNoDepth
TypePointer * getTypePointerNoDepth(int4 s, Datatype *pt, uint4 ws)
Construct a depth limited pointer data-type.
Definition: type.cc:2050
DatatypeCompare
Compare two Datatype pointers for equivalence of their description.
Definition: type.hh:141
Element
An XML element. A node in the DOM tree.
Definition: xml.hh:150
Datatype::utf16
@ utf16
16-bit wide chars in unicode UTF16
Definition: type.hh:75
TypeFactory::getTypeVoid
TypeVoid * getTypeVoid(void)
Get the "void" data-type.
Definition: type.cc:1891
TypeArray::compare
virtual int4 compare(const Datatype &op, int4 level) const
Compare for functional equivalence.
Definition: type.cc:559
TypeEnum::masklist
vector< uintb > masklist
Masks for each bitfield within the enum.
Definition: type.hh:290
Datatype::saveXml
virtual void saveXml(ostream &s) const
Serialize the data-type to XML.
Definition: type.cc:268
Datatype::typeOrderBool
int4 typeOrderBool(const Datatype &op) const
Order this with -op-, treating bool data-type as special.
Definition: type.hh:473
TypeFactory::restoreXmlCoreTypes
void restoreXmlCoreTypes(const Element *el)
Initialize basic type names.
Definition: type.cc:2476
Architecture
Manager for all the major decompiler subsystems.
Definition: architecture.hh:119
DatatypeNameCompare
Compare two Datatype pointers: first by name, then by id.
Definition: type.hh:150
TypeArray::TypeArray
TypeArray(const TypeArray &op)
Construct from another TypeArray.
Definition: type.hh:264
TypeFactory::downChain
Datatype * downChain(Datatype *ptrtype, uintb &off)
Find a sub-type matching a pointer and offset.
Definition: type.cc:2150
TypeUnicode
The unicode data-type: i.e. wchar.
Definition: type.hh:198
TypeBase::clone
virtual Datatype * clone(void) const
Clone the data-type.
Definition: type.hh:177
TypeFactory::setName
Datatype * setName(Datatype *ct, const string &n)
Set the given types name.
Definition: type.cc:1732
string2metatype
type_metatype string2metatype(const string &metastring)
Convert string to type meta-type.
Definition: type.cc:214
TypeFactory::setFields
bool setFields(vector< TypeField > &fd, TypeStruct *ot, int4 fixedsize, uint4 flags)
Set fields on a TypeStruct.
Definition: type.cc:1754
TypeChar::TypeChar
TypeChar(const string &n)
Construct a char (always 1-byte) given a name.
Definition: type.hh:190
Datatype::coretype
@ coretype
This is a basic type which will never be redefined.
Definition: type.hh:66
TypeStruct::nearestArrayedComponentBackward
virtual Datatype * nearestArrayedComponentBackward(uintb off, uintb *newoff, int4 *elSize) const
Definition: type.cc:925
TypeEnum::restoreXml
virtual void restoreXml(const Element *el, TypeFactory &typegrp)
Restore data-type from XML.
Definition: type.cc:797
TypeStruct::saveXml
virtual void saveXml(ostream &s) const
Serialize the data-type to XML.
Definition: type.cc:1049
TypeCode::proto
FuncProto * proto
If non-null, this describes the prototype of the underlying function.
Definition: type.hh:344
TYPE_PTR
@ TYPE_PTR
Pointer data-type.
Definition: type.hh:43
TypeEnum
An enumerated Datatype object: an integer with named values.
Definition: type.hh:286
ProtoModel
A prototype model: a model for passing parameters between functions.
Definition: fspec.hh:622
TypeEnum::compare
virtual int4 compare(const Datatype &op, int4 level) const
Compare for functional equivalence.
Definition: type.cc:752
Datatype::restoreXml
virtual void restoreXml(const Element *el, TypeFactory &typegrp)
Restore data-type from XML.
Definition: type.cc:394
TypeStruct::getField
const TypeField * getField(int4 off, int4 sz, int4 *newoff) const
Get field based on offset.
Definition: type.cc:897
Datatype::hashName
static uint8 hashName(const string &nm)
Produce a data-type id by hashing the type name.
Definition: type.cc:404
TypeSpacebase::compare
virtual int4 compare(const Datatype &op, int4 level) const
Compare for functional equivalence.
Definition: type.cc:1413
TypeArray::getSubType
virtual Datatype * getSubType(uintb off, uintb *newoff) const
Recover component data-type one-level down.
Definition: type.cc:587
TypeFactory::setCoreType
void setCoreType(const string &name, int4 size, type_metatype meta, bool chartp)
Create a core data-type.
Definition: type.cc:1522
TypeArray::compareDependency
virtual int4 compareDependency(const Datatype &op) const
Compare for storage in tree structure.
Definition: type.cc:575
TypeFactory::concretize
Datatype * concretize(Datatype *ct)
Convert given data-type to concrete form.
Definition: type.cc:2173
TypeFactory::getTypeArray
TypeArray * getTypeArray(int4 as, Datatype *ao)
Construct an array data-type.
Definition: type.cc:2071
TypeSpacebase::clone
virtual Datatype * clone(void) const
Clone the data-type.
Definition: type.hh:391
TypeCode::setProperties
void setProperties(bool isConstructor, bool isDestructor)
Set additional function properties.
Definition: type.cc:1163
TypeFactory::clear
void clear(void)
Clear out all types.
Definition: type.cc:1591
TypeVoid
Formal "void" data-type object.
Definition: type.hh:215
TypeField::offset
int4 offset
Offset (into containing struct) of subfield.
Definition: type.hh:134
TypePointer::clone
virtual Datatype * clone(void) const
Clone the data-type.
Definition: type.hh:249
TypeEnum::TypeEnum
TypeEnum(const TypeEnum &op)
Construct from another TypeEnum.
Definition: type.cc:637
TypeCode::compare
virtual int4 compare(const Datatype &op, int4 level) const
Compare for functional equivalence.
Definition: type.cc:1220
TypeStruct::getSubType
virtual Datatype * getSubType(uintb off, uintb *newoff) const
Recover component data-type one-level down.
Definition: type.cc:913
TypeBase
Base class for the fundamental atomic types.
Definition: type.hh:167
TypePointer::saveXml
virtual void saveXml(ostream &s) const
Serialize the data-type to XML.
Definition: type.cc:525
Datatype::metatype
type_metatype metatype
Meta-type - type disregarding size.
Definition: type.hh:84
TypeEnum::getMatches
bool getMatches(uintb val, vector< string > &matchname) const
Recover the named representation.
Definition: type.cc:715
TypeEnum::namemap
map< uintb, string > namemap
Map from integer to name.
Definition: type.hh:289
TypeBase::TypeBase
TypeBase(int4 s, type_metatype m, const string &n)
Construct TypeBase from a size, meta-type, and name.
Definition: type.hh:176
DatatypeCompare::operator()
bool operator()(const Datatype *a, const Datatype *b) const
Comparison operator.
Definition: type.hh:143
TypeFactory::getTypeStruct
TypeStruct * getTypeStruct(const string &n)
Create an (empty) structure.
Definition: type.cc:2081
TypeFactory::parseDataOrganization
void parseDataOrganization(const Element *el)
Parse the <data_organization> tag.
Definition: type.cc:2493
TypeField::name
string name
Name of subfield.
Definition: type.hh:135
TypeSpacebase::compareDependency
virtual int4 compareDependency(const Datatype &op) const
Compare for storage in tree structure.
Definition: type.cc:1419
Datatype::restoreXmlBasic
void restoreXmlBasic(const Element *el)
Recover basic data-type properties.
Definition: type.cc:351
TypeFactory::parseEnumConfig
void parseEnumConfig(const Element *el)
Parse the <enum> tag.
Definition: type.cc:2527
Datatype::flags
uint4 flags
Boolean properties of the type.
Definition: type.hh:85
TypeField
Specifies subfields of a structure or what a pointer points to.
Definition: type.hh:133
TypeFactory::dependentOrder
void dependentOrder(vector< Datatype * > &deporder) const
Place all data-types in dependency order.
Definition: type.cc:1879
TypeArray::TypeArray
TypeArray(void)
Internal constructor for restoreXml.
Definition: type.hh:261
DatatypeNameSet
set< Datatype *, DatatypeNameCompare > DatatypeNameSet
A set of data-types sorted by name.
Definition: type.hh:162
TypeSpacebase::getAddress
Address getAddress(uintb off, int4 sz, const Address &point) const
Construct an Address given an offset.
Definition: type.cc:1437
Address
A low-level machine address for labelling bytes and data.
Definition: address.hh:46
TypeFactory::restoreXml
void restoreXml(const Element *el)
Restore this container from a stream.
Definition: type.cc:2448
TypePointer::printRaw
virtual void printRaw(ostream &s) const
Print a description of the type to stream.
Definition: type.cc:486
TypeFactory::TypeFactory
TypeFactory(Architecture *g)
Construct a factory.
Definition: type.cc:1470
Datatype::saveXmlRef
void saveXmlRef(ostream &s) const
Write an XML reference of this to stream.
Definition: type.cc:306
Datatype
The base datatype class for the decompiler.
Definition: type.hh:62
TypeArray
Datatype object representing an array of elements.
Definition: type.hh:254
TYPE_VOID
@ TYPE_VOID
Standard "void" type, absence of type.
Definition: type.hh:34
TypeFactory
Container class for all Datatype objects in an Architecture.
Definition: type.hh:396
TypeCode::saveXml
virtual void saveXml(ostream &s) const
Serialize the data-type to XML.
Definition: type.cc:1276
TypeEnum::clone
virtual Datatype * clone(void) const
Clone the data-type.
Definition: type.hh:305
Datatype::size
int4 size
Size (of variable holding a value of this type)
Definition: type.hh:82
Datatype::compareDependency
virtual int4 compareDependency(const Datatype &op) const
Compare for storage in tree structure.
Definition: type.cc:150
TypeFactory::saveXmlCoreTypes
void saveXmlCoreTypes(ostream &s) const
Save core types to stream.
Definition: type.cc:2279
DatatypeNameCompare::operator()
bool operator()(const Datatype *a, const Datatype *b) const
Comparison operator.
Definition: type.hh:152
TYPE_CODE
@ TYPE_CODE
Data is actual executable code.
Definition: type.hh:40
TypeEnum::setNameMap
void setNameMap(const map< uintb, string > &nmap)
Establish the value -> name map.
Definition: type.cc:648
TypeFactory::getBaseNoChar
Datatype * getBaseNoChar(int4 s, type_metatype m)
Get atomic type excluding "char".
Definition: type.cc:1935
TypeStruct::TypeStruct
TypeStruct(const TypeStruct &op)
Construct from another TypeStruct.
Definition: type.cc:818
TypeFactory::restoreXmlTypeWithCodeFlags
Datatype * restoreXmlTypeWithCodeFlags(const Element *el, bool isConstructor, bool isDestructor)
Restore data-type from XML with extra "code" flags.
Definition: type.cc:2220
TypeFactory::getTypePointerStripArray
TypePointer * getTypePointerStripArray(int4 s, Datatype *pt, uint4 ws)
Construct a pointer data-type, stripping an ARRAY level.
Definition: type.cc:2024
TypeArray::getSubEntry
Datatype * getSubEntry(int4 off, int4 sz, int4 *newoff, int4 *el) const
Figure out what a byte range overlaps.
Definition: type.cc:601
TypeFactory::getTypeCode
TypeCode * getTypeCode(void)
Get an "anonymous" function data-type.
Definition: type.cc:1994
TYPE_UNKNOWN
@ TYPE_UNKNOWN
An unknown low-level type. Treated as an unsigned integer.
Definition: type.hh:36
Datatype::clone
virtual Datatype * clone(void) const =0
Clone the data-type.
TYPE_STRUCT
@ TYPE_STRUCT
Structure data-type, made up of component datatypes.
Definition: type.hh:45
TypeSpacebase
Special Datatype object used to describe pointers that index into the symbol table.
Definition: type.hh:370
TypeCode::clone
virtual Datatype * clone(void) const
Clone the data-type.
Definition: type.hh:361
TypeVoid::clone
virtual Datatype * clone(void) const
Clone the data-type.
Definition: type.hh:223
TypeCode::TypeCode
TypeCode(const TypeCode &op)
Construct from another TypeCode.
Definition: type.cc:1125
TypeStruct::restoreXml
virtual void restoreXml(const Element *el, TypeFactory &typegrp)
Restore data-type from XML.
Definition: type.cc:1067
TypeBase::TypeBase
TypeBase(const TypeBase &op)
Construct TypeBase copying properties from another data-type.
Definition: type.hh:172
TypeCode::factory
TypeFactory * factory
Factory owning this.
Definition: type.hh:345
DatatypeSet
set< Datatype *, DatatypeCompare > DatatypeSet
A set of data-types sorted by function.
Definition: type.hh:159
TypeStruct::clone
virtual Datatype * clone(void) const
Clone the data-type.
Definition: type.hh:331
TypeChar::clone
virtual Datatype * clone(void) const
Clone the data-type.
Definition: type.hh:191
Datatype::nearestArrayedComponentBackward
virtual Datatype * nearestArrayedComponentBackward(uintb off, uintb *newoff, int4 *elSize) const
Definition: type.cc:127
TypeFactory::glb
Architecture * glb
The Architecture object that owns this TypeFactory.
Definition: type.hh:416
TypeVoid::TypeVoid
TypeVoid(void)
Constructor.
Definition: type.hh:222
TypeField::type
Datatype * type
type of subfield
Definition: type.hh:136
TypeCode::getSubType
virtual Datatype * getSubType(uintb off, uintb *newoff) const
Recover component data-type one-level down.
Definition: type.cc:1212
TypeVoid::TypeVoid
TypeVoid(const TypeVoid &op)
Construct from another TypeVoid.
Definition: type.hh:220
TypeSpacebase::TypeSpacebase
TypeSpacebase(AddrSpace *id, const Address &frame, Architecture *g)
Construct given an address space, scope, and architecture.
Definition: type.hh:382
Datatype::variable_length
@ variable_length
May be other structures with same name different lengths.
Definition: type.hh:78
Datatype::printRaw
virtual void printRaw(ostream &s) const
Print a description of the type to stream.
Definition: type.cc:83
address.hh
Classes for specifying addresses and other low-level constants.
TypeSpacebase::TypeSpacebase
TypeSpacebase(const TypeSpacebase &op)
Construct from another TypeSpacebase.
Definition: type.hh:378
Datatype::enumtype
@ enumtype
An enumeration type (as well as an integer)
Definition: type.hh:73
Datatype::saveXmlBasic
void saveXmlBasic(ostream &s) const
Save basic data-type properties.
Definition: type.cc:279
TypeSpacebase::nearestArrayedComponentForward
virtual Datatype * nearestArrayedComponentForward(uintb off, uintb *newoff, int4 *elSize) const
Definition: type.cc:1345
TypeUnicode::saveXml
virtual void saveXml(ostream &s) const
Serialize the data-type to XML.
Definition: type.cc:471
TypePointer::compare
virtual int4 compare(const Datatype &op, int4 level) const
Compare for functional equivalence.
Definition: type.cc:493
TypeStruct::field
vector< TypeField > field
The list of fields.
Definition: type.hh:313
FuncProto
A function prototype.
Definition: fspec.hh:1164
type_metatype
type_metatype
Definition: type.hh:33
TypeCode::compareDependency
virtual int4 compareDependency(const Datatype &op) const
Compare for storage in tree structure.
Definition: type.cc:1250
TYPE_BOOL
@ TYPE_BOOL
Boolean.
Definition: type.hh:39
Datatype::compare
virtual int4 compare(const Datatype &op, int4 level) const
Compare for functional equivalence.
Definition: type.cc:139
TypeEnum::compareDependency
virtual int4 compareDependency(const Datatype &op) const
Compare for storage in tree structure.
Definition: type.cc:758
TypeVoid::saveXml
virtual void saveXml(ostream &s) const
Serialize the data-type to XML.
Definition: type.cc:480
TypeStruct::nearestArrayedComponentForward
virtual Datatype * nearestArrayedComponentForward(uintb off, uintb *newoff, int4 *elSize) const
Definition: type.cc:952
TypePointer::compareDependency
virtual int4 compareDependency(const Datatype &op) const
Compare for storage in tree structure.
Definition: type.cc:511
TypeChar::TypeChar
TypeChar(const TypeChar &op)
Construct TypeChar copying properties from another data-type.
Definition: type.hh:188
TypeFactory::findByName
Datatype * findByName(const string &n)
Return type of given name.
Definition: type.cc:1666
TypeEnum::saveXml
virtual void saveXml(ostream &s) const
Serialize the data-type to XML.
Definition: type.cc:780
TYPE_FLOAT
@ TYPE_FLOAT
Floating-point.
Definition: type.hh:41
TypeStruct::compareDependency
virtual int4 compareDependency(const Datatype &op) const
Compare for storage in tree structure.
Definition: type.cc:1021
TYPE_UINT
@ TYPE_UINT
Unsigned integer.
Definition: type.hh:38
Datatype::Datatype
Datatype(int4 s, type_metatype m, const string &n)
Construct the base data-type providing size, meta-type, and name.
Definition: type.hh:97
TypeFactory::cacheCoreTypes
void cacheCoreTypes(void)
Cache common types.
Definition: type.cc:1544
TypeStruct::compare
virtual int4 compare(const Datatype &op, int4 level) const
Compare for functional equivalence.
Definition: type.cc:980
TypeSpacebase::nearestArrayedComponentBackward
virtual Datatype * nearestArrayedComponentBackward(uintb off, uintb *newoff, int4 *elSize) const
Definition: type.cc:1394