decompiler  1.0.0
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
ghidra::TypeFactory Class Reference

Container class for all Datatype objects in an Architecture. More...

#include <type.hh>

Inheritance diagram for ghidra::TypeFactory:
ghidra::TypeFactoryGhidra

Public Member Functions

 TypeFactory (Architecture *g)
 Construct a factory. More...
 
void setupSizes (void)
 Derive some size information from Architecture. More...
 
void clear (void)
 Clear out all types. More...
 
void clearNoncore (void)
 Clear out non-core types. More...
 
virtual ~TypeFactory (void)
 Destructor.
 
void setStructAlign (int4 al)
 Set the default structure alignment.
 
int4 getStructAlign (void) const
 Get the default structure alignment.
 
int4 getSizeOfInt (void) const
 Get the size of the default "int".
 
int4 getSizeOfLong (void) const
 Get the size of the default "long".
 
int4 getSizeOfPointer (void) const
 Get the size of pointers.
 
int4 getSizeOfAltPointer (void) const
 Get size of alternate pointers (or 0)
 
ArchitecturegetArch (void) const
 Get the Architecture object.
 
DatatypefindByName (const string &n)
 Return type of given name. More...
 
DatatypesetName (Datatype *ct, const string &n)
 Set the given types name. More...
 
void setDisplayFormat (Datatype *ct, uint4 format)
 Set the display format associated with the given data-type. More...
 
bool setFields (vector< TypeField > &fd, TypeStruct *ot, int4 fixedsize, uint4 flags)
 Set fields on a TypeStruct. More...
 
bool setFields (vector< TypeField > &fd, TypeUnion *ot, int4 fixedsize, uint4 flags)
 Set fields on a TypeUnion. More...
 
void setPrototype (const FuncProto *fp, TypeCode *newCode, uint4 flags)
 Set the prototype on a TypeCode. More...
 
bool setEnumValues (const vector< string > &namelist, const vector< uintb > &vallist, const vector< bool > &assignlist, TypeEnum *te)
 Set named values for an enumeration. More...
 
DatatypedecodeType (Decoder &decoder)
 Restore Datatype from a stream. More...
 
DatatypedecodeTypeWithCodeFlags (Decoder &decoder, bool isConstructor, bool isDestructor)
 Restore data-type from an element and extra "code" flags. More...
 
TypeVoidgetTypeVoid (void)
 Get the "void" data-type. More...
 
DatatypegetBaseNoChar (int4 s, type_metatype m)
 Get atomic type excluding "char". More...
 
DatatypegetBase (int4 s, type_metatype m)
 Get atomic type. More...
 
DatatypegetBase (int4 s, type_metatype m, const string &n)
 Get named atomic type. More...
 
TypeCodegetTypeCode (void)
 Get an "anonymous" function data-type. More...
 
TypePointergetTypePointerStripArray (int4 s, Datatype *pt, uint4 ws)
 Construct a pointer data-type, stripping an ARRAY level. More...
 
TypePointergetTypePointer (int4 s, Datatype *pt, uint4 ws)
 Construct an absolute pointer data-type. More...
 
TypePointergetTypePointer (int4 s, Datatype *pt, uint4 ws, const string &n)
 Construct a named pointer data-type. More...
 
TypePointergetTypePointerNoDepth (int4 s, Datatype *pt, uint4 ws)
 Construct a depth limited pointer data-type. More...
 
TypeArraygetTypeArray (int4 as, Datatype *ao)
 Construct an array data-type. More...
 
TypeStructgetTypeStruct (const string &n)
 Create an (empty) structure. More...
 
TypePartialStructgetTypePartialStruct (Datatype *contain, int4 off, int4 sz)
 Create a partial structure.
 
TypeUniongetTypeUnion (const string &n)
 Create an (empty) union. More...
 
TypePartialUniongetTypePartialUnion (TypeUnion *contain, int4 off, int4 sz)
 Create a partial union.
 
TypeEnumgetTypeEnum (const string &n)
 Create an (empty) enumeration. More...
 
TypeSpacebasegetTypeSpacebase (AddrSpace *id, const Address &addr)
 Create a "spacebase" type. More...
 
TypeCodegetTypeCode (ProtoModel *model, Datatype *outtype, const vector< Datatype *> &intypes, bool dotdotdot)
 Create a "function" datatype. More...
 
DatatypegetTypedef (Datatype *ct, const string &name, uint8 id, uint4 format)
 Create a new typedef data-type. More...
 
TypePointerRelgetTypePointerRel (TypePointer *parentPtr, Datatype *ptrTo, int4 off)
 Get pointer offset relative to a container. More...
 
TypePointerRelgetTypePointerRel (int4 sz, Datatype *parent, Datatype *ptrTo, int4 ws, int4 off, const string &nm)
 Build a named pointer offset into a larger container. More...
 
TypePointergetTypePointerWithSpace (Datatype *ptrTo, AddrSpace *spc, const string &nm)
 Build a named pointer with an address space attribute. More...
 
TypePointerresizePointer (TypePointer *ptr, int4 newSize)
 Build a resized pointer based on the given pointer. More...
 
DatatypegetExactPiece (Datatype *ct, int4 offset, int4 size)
 Get the data-type associated with piece of a structured data-type. More...
 
void destroyType (Datatype *ct)
 Remove a data-type from this. More...
 
Datatypeconcretize (Datatype *ct)
 Convert given data-type to concrete form. More...
 
void dependentOrder (vector< Datatype *> &deporder) const
 Place all data-types in dependency order. More...
 
void encode (Encoder &encoder) const
 Encode this container to stream. More...
 
void encodeCoreTypes (Encoder &encoder) const
 Encode core types to stream. More...
 
void decode (Decoder &decoder)
 Decode this from a <typegrp> element. More...
 
void decodeCoreTypes (Decoder &decoder)
 Initialize basic data-types from a stream. More...
 
void decodeDataOrganization (Decoder &decoder)
 Parse a <data_organization> element. More...
 
void parseEnumConfig (Decoder &decoder)
 Parse the <enum> tag. More...
 
void setCoreType (const string &name, int4 size, type_metatype meta, bool chartp)
 Create a core data-type. More...
 
void cacheCoreTypes (void)
 Cache common types. More...
 

Protected Member Functions

DatatypefindByIdLocal (const string &nm, uint8 id) const
 Search locally by name and id. More...
 
virtual DatatypefindById (const string &n, uint8 id, int4 sz)
 Search by name and/or id. More...
 

Protected Attributes

Architectureglb
 The Architecture object that owns this TypeFactory.
 

Private Member Functions

DatatypefindNoName (Datatype &ct)
 Find data-type (in this container) by function. More...
 
void insert (Datatype *newtype)
 Insert pointer into the cross-reference sets. More...
 
DatatypefindAdd (Datatype &ct)
 Find data-type in this container or add it. More...
 
void orderRecurse (vector< Datatype *> &deporder, DatatypeSet &mark, Datatype *ct) const
 Write out dependency list. More...
 
DatatypedecodeTypedef (Decoder &decoder)
 Restore a <def> element describing a typedef. More...
 
DatatypedecodeStruct (Decoder &decoder, bool forcecore)
 Restore a <type> element describing a structure. More...
 
DatatypedecodeUnion (Decoder &decoder, bool forcecore)
 Restore a <type> element describing a union. More...
 
DatatypedecodeCode (Decoder &decoder, bool isConstructor, bool isDestructor, bool forcecore)
 Restore an element describing a code object. More...
 
DatatypedecodeTypeNoRef (Decoder &decoder, bool forcecore)
 Restore from a stream. More...
 
void clearCache (void)
 Clear the common type cache. More...
 
TypeChargetTypeChar (const string &n)
 Create a default "char" type. More...
 
TypeUnicodegetTypeUnicode (const string &nm, int4 sz, type_metatype m)
 Create a default "unicode" type. More...
 
TypeCodegetTypeCode (const string &n)
 Create a default "code" type. More...
 
void recalcPointerSubmeta (Datatype *base, sub_metatype sub)
 Recalculate submeta for pointers to given base data-type. More...
 

Private Attributes

int4 sizeOfInt
 Size of the core "int" datatype.
 
int4 sizeOfLong
 Size of the core "long" datatype.
 
int4 sizeOfPointer
 Size of pointers (into default data address space)
 
int4 sizeOfAltPointer
 Size of alternate pointers used by architecture (if not 0)
 
int4 align
 Alignment of structures.
 
int4 enumsize
 Size of an enumerated type.
 
type_metatype enumtype
 Default enumeration meta-type (when parsing C)
 
DatatypeSet tree
 Datatypes within this factory (sorted by function)
 
DatatypeNameSet nametree
 Cross-reference by name.
 
Datatypetypecache [9][8]
 Matrix of the most common atomic data-types.
 
Datatypetypecache10
 Specially cached 10-byte float type.
 
Datatypetypecache16
 Specially cached 16-byte float type.
 
Datatypetype_nochar
 Same dimensions as char but acts and displays as an INT.
 

Detailed Description

Container class for all Datatype objects in an Architecture.

Constructor & Destructor Documentation

◆ TypeFactory()

ghidra::TypeFactory::TypeFactory ( Architecture g)

Construct a factory.

Initialize an empty container

Parameters
gis the owning Architecture

Member Function Documentation

◆ cacheCoreTypes()

void ghidra::TypeFactory::cacheCoreTypes ( void  )

Cache common types.

Run through the list of "core" data-types and cache the most commonly accessed ones for quick access (avoiding the tree lookup). The "core" data-types must have been previously initialized.

References ghidra::Datatype::getMetatype(), ghidra::Datatype::getSize(), ghidra::Datatype::isASCII(), ghidra::Datatype::isCharPrint(), ghidra::Datatype::isCoreType(), ghidra::Datatype::isEnumType(), ghidra::TYPE_BOOL, ghidra::TYPE_CODE, ghidra::TYPE_FLOAT, ghidra::TYPE_INT, ghidra::TYPE_UINT, ghidra::TYPE_UNKNOWN, and ghidra::TYPE_VOID.

Referenced by ghidra::ArchitectureGhidra::buildTypegrp().

◆ clear()

void ghidra::TypeFactory::clear ( void  )

Clear out all types.

Remove all Datatype objects owned by this TypeFactory.

◆ clearCache()

void ghidra::TypeFactory::clearCache ( void  )
private

Clear the common type cache.

Clear the matrix of commonly used atomic types.

◆ clearNoncore()

void ghidra::TypeFactory::clearNoncore ( void  )

Clear out non-core types.

Delete anything that isn't a core type.

References ghidra::Datatype::isCoreType().

◆ concretize()

Datatype * ghidra::TypeFactory::concretize ( Datatype ct)

Convert given data-type to concrete form.

The data-type propagation system can push around data-types that are partial or are otherwise unrepresentable in the source language. This method substitutes those data-types with a concrete data-type that is representable, or returns the same data-type if is already concrete. Its important that the returned data-type have the same size as the original data-type regardless.

Parameters
ctis the given data-type
Returns
the concrete data-type

References ghidra::Datatype::getMetatype(), ghidra::Datatype::getSize(), ghidra::TYPE_CODE, and ghidra::TYPE_UNKNOWN.

Referenced by ghidra::ScopeLocal::createEntry().

◆ decode()

void ghidra::TypeFactory::decode ( Decoder decoder)

Decode this from a <typegrp> element.

Scan configuration parameters of the factory and parse elements describing data-types into this container.

Parameters
decoderis the stream decoder

References ghidra::Decoder::closeElement(), ghidra::Datatype::enumtype, ghidra::Decoder::openElement(), ghidra::Decoder::peekElement(), ghidra::Decoder::readBool(), ghidra::Decoder::readSignedInteger(), ghidra::TYPE_INT, and ghidra::TYPE_UINT.

◆ decodeCode()

Datatype * ghidra::TypeFactory::decodeCode ( Decoder decoder,
bool  isConstructor,
bool  isDestructor,
bool  forcecore 
)
private

Restore an element describing a code object.

If necessary create a stub object before parsing the prototype description, to deal with recursive definitions

Parameters
decoderis the stream decoder
isConstructoris true if any prototype should be treated as a constructor
isDestructoris true if any prototype should be treated as a destructor
forcecoreis true if the data-type is considered core
Returns
the newly minted code data-type

References ghidra::Datatype::compareDependency(), ghidra::Datatype::coretype, ghidra::TypeCode::decodePrototype(), ghidra::TypeCode::decodeStub(), ghidra::Datatype::flags, ghidra::Datatype::getMetatype(), ghidra::Datatype::id, ghidra::Datatype::isIncomplete(), ghidra::Datatype::name, ghidra::TypeCode::proto, ghidra::TypeCode::setPrototype(), and ghidra::TYPE_CODE.

◆ decodeCoreTypes()

void ghidra::TypeFactory::decodeCoreTypes ( Decoder decoder)

Initialize basic data-types from a stream.

Parse data-type elements into this container. This stream is presumed to contain "core" datatypes and the cached matrix will be populated from this set.

Parameters
decoderis the stream decoder

References ghidra::Decoder::closeElement(), ghidra::Decoder::openElement(), and ghidra::Decoder::peekElement().

Referenced by ghidra::ArchitectureGhidra::buildTypegrp().

◆ decodeDataOrganization()

void ghidra::TypeFactory::decodeDataOrganization ( Decoder decoder)

Parse a <data_organization> element.

Recover various sizes relevant to this container, such as the default size of "int" and structure alignment, by parsing a <data_organization> element.

Parameters
decoderis the stream decoder

References ghidra::Decoder::closeElement(), ghidra::Decoder::closeElementSkipping(), ghidra::Decoder::openElement(), and ghidra::Decoder::readSignedInteger().

◆ decodeStruct()

Datatype * ghidra::TypeFactory::decodeStruct ( Decoder decoder,
bool  forcecore 
)
private

Restore a <type> element describing a structure.

If necessary create a stub object before parsing the field descriptions, to deal with recursive definitions

Parameters
decoderis the stream decoder
forcecoreis true if the data-type is considered core
Returns
the newly minted structure data-type

References ghidra::Datatype::compareDependency(), ghidra::Datatype::coretype, ghidra::Datatype::decodeBasic(), ghidra::TypeStruct::decodeFields(), ghidra::TypeStruct::field, ghidra::Datatype::flags, ghidra::Datatype::getMetatype(), ghidra::Datatype::id, ghidra::Datatype::isIncomplete(), ghidra::Datatype::name, ghidra::Datatype::size, and ghidra::TYPE_STRUCT.

◆ decodeType()

Datatype * ghidra::TypeFactory::decodeType ( Decoder decoder)

◆ decodeTypedef()

Datatype * ghidra::TypeFactory::decodeTypedef ( Decoder decoder)
private

Restore a <def> element describing a typedef.

Scan the new id and name. A subtag references the data-type being typedefed. Construct the new data-type based on the referenced data-type but with new name and id.

Parameters
decoderis the stream decoder
Returns
the constructed typedef data-type

References ghidra::Datatype::encodeIntegerFormat(), ghidra::TypeStruct::field, ghidra::TypeUnion::field, ghidra::Datatype::flags, ghidra::Datatype::getMetatype(), ghidra::Decoder::getNextAttributeId(), ghidra::Datatype::getTypedef(), ghidra::Datatype::hashName(), ghidra::Datatype::hashSize(), ghidra::Datatype::isVariableLength(), ghidra::Datatype::name, ghidra::Decoder::readString(), ghidra::Decoder::readUnsignedInteger(), ghidra::Datatype::size, ghidra::TYPE_STRUCT, and ghidra::TYPE_UNION.

◆ decodeTypeNoRef()

Datatype * ghidra::TypeFactory::decodeTypeNoRef ( Decoder decoder,
bool  forcecore 
)
private

◆ decodeTypeWithCodeFlags()

Datatype * ghidra::TypeFactory::decodeTypeWithCodeFlags ( Decoder decoder,
bool  isConstructor,
bool  isDestructor 
)

Restore data-type from an element and extra "code" flags.

Kludge to get flags into code pointer types, when they can't come through the stream

Parameters
decoderis the stream decoder
isConstructortoggles "constructor" property on "function" datatypes
isDestructortoggles "destructor" property on "function" datatypes
Returns
the decoded Datatype object

References ghidra::TypePointer::calcTruncate(), ghidra::Decoder::closeElement(), ghidra::Datatype::decodeBasic(), ghidra::Datatype::getMetatype(), ghidra::Decoder::getNextAttributeId(), ghidra::Decoder::openElement(), ghidra::TypePointer::ptrto, ghidra::Decoder::readUnsignedInteger(), ghidra::TYPE_PTR, and ghidra::TypePointer::wordsize.

Referenced by ghidra::CPoolRecord::decode().

◆ decodeUnion()

Datatype * ghidra::TypeFactory::decodeUnion ( Decoder decoder,
bool  forcecore 
)
private

Restore a <type> element describing a union.

If necessary create a stub object before parsing the field descriptions, to deal with recursive definitions

Parameters
decoderis the stream decoder
forcecoreis true if the data-type is considered core
Returns
the newly minted union data-type

References ghidra::Datatype::compareDependency(), ghidra::Datatype::coretype, ghidra::Datatype::decodeBasic(), ghidra::TypeUnion::decodeFields(), ghidra::TypeUnion::field, ghidra::Datatype::flags, ghidra::Datatype::getMetatype(), ghidra::Datatype::id, ghidra::Datatype::isIncomplete(), ghidra::Datatype::name, ghidra::Datatype::size, and ghidra::TYPE_UNION.

◆ dependentOrder()

void ghidra::TypeFactory::dependentOrder ( vector< Datatype *> &  deporder) const

Place all data-types in dependency order.

Place data-types in an order such that if the definition of data-type "a" depends on the definition of data-type "b", then "b" occurs earlier in the order

Parameters
deporderwill hold the generated dependency list of data-types

Referenced by ghidra::PrintC::docTypeDefinitions().

◆ destroyType()

void ghidra::TypeFactory::destroyType ( Datatype ct)

Remove a data-type from this.

The indicated Datatype object is removed from this container. Indirect references (via TypeArray TypeStruct etc.) are not affected

Parameters
ctis the data-type to destroy

References ghidra::Datatype::isCoreType().

◆ encode()

void ghidra::TypeFactory::encode ( Encoder encoder) const

Encode this container to stream.

All data-types, in dependency order, are encoded to a stream

Parameters
encoderis the stream encoder

References ghidra::Encoder::closeElement(), ghidra::Datatype::enumtype, ghidra::Encoder::openElement(), ghidra::TYPE_ARRAY, ghidra::TYPE_INT, ghidra::TYPE_PTR, ghidra::TYPE_STRUCT, ghidra::TYPE_UNION, ghidra::Encoder::writeBool(), and ghidra::Encoder::writeSignedInteger().

◆ encodeCoreTypes()

void ghidra::TypeFactory::encodeCoreTypes ( Encoder encoder) const

Encode core types to stream.

Any data-type within this container marked as core will be encodeded as a <coretypes> element.

Parameters
encoderis the stream encoder

References ghidra::Encoder::closeElement(), ghidra::Datatype::encode(), ghidra::Datatype::getMetatype(), ghidra::Datatype::isCoreType(), ghidra::Encoder::openElement(), ghidra::TYPE_ARRAY, ghidra::TYPE_PTR, ghidra::TYPE_STRUCT, and ghidra::TYPE_UNION.

Referenced by ghidra::RawBinaryArchitecture::encode(), ghidra::XmlArchitecture::encode(), and ghidra::BfdArchitecture::encode().

◆ findAdd()

Datatype * ghidra::TypeFactory::findAdd ( Datatype ct)
private

Find data-type in this container or add it.

Use quickest method (name or id is possible) to locate the matching data-type. If its not currently in this container, clone the data-type and add it to the container.

Parameters
ctis the data-type to match
Returns
the matching Datatype object in this container

References ghidra::Datatype::clone(), ghidra::Datatype::compareDependency(), ghidra::Datatype::id, and ghidra::Datatype::name.

◆ findById()

Datatype * ghidra::TypeFactory::findById ( const string &  n,
uint8  id,
int4  sz 
)
protectedvirtual

Search by name and/or id.

The id is expected to resolve uniquely. Internally, different length instances of a variable length data-type are stored as separate Datatype objects. A non-zero size can be given to distinguish these cases. Derived classes may search outside this container.

Parameters
nis the name of the data-type
idis the type id of the data-type
szis the given distinguishing size if non-zero
Returns
the matching Datatype object

Reimplemented in ghidra::TypeFactoryGhidra.

References ghidra::Datatype::hashSize().

Referenced by ghidra::TypeFactoryGhidra::findById().

◆ findByIdLocal()

Datatype * ghidra::TypeFactory::findByIdLocal ( const string &  n,
uint8  id 
) const
protected

Search locally by name and id.

Looking just within this container, find a Datatype by name and/or id.

Parameters
nis the name of the data-type
idis the type id of the data-type
Returns
the matching Datatype object

References ghidra::Datatype::id, and ghidra::TYPE_UNKNOWN.

◆ findByName()

Datatype * ghidra::TypeFactory::findByName ( const string &  n)

Return type of given name.

Find type with given name. If there are more than, return first.

Parameters
nis the name to search for
Returns
a Datatype object with the name or NULL

◆ findNoName()

Datatype * ghidra::TypeFactory::findNoName ( Datatype ct)
private

Find data-type (in this container) by function.

Find data-type without reference to name, using the functional comparators For this to work, the type must be built out of dependencies that are already present in this type factory

Parameters
ctis the data-type to match
Returns
the matching Datatype or NULL

◆ getBase() [1/2]

Datatype * ghidra::TypeFactory::getBase ( int4  s,
type_metatype  m 
)

Get atomic type.

Get one of the "base" datatypes. This routine is called a lot, so we go through a cache first.

Parameters
sis the desired size
mis the desired meta-type
Returns
the Datatype object

References ghidra::TYPE_FLOAT, and ghidra::TYPE_UNKNOWN.

Referenced by ghidra::MapState::addGuard(), ghidra::RuleSubRight::applyOp(), ghidra::CastStrategyC::arithmeticOutputStandard(), ghidra::LabSymbol::buildType(), ghidra::EquateSymbol::decode(), ghidra::ScopeInternal::decodeCollision(), ghidra::EquateSymbol::EquateSymbol(), ghidra::TypeOp::getInputLocal(), ghidra::TypeOpBinary::getInputLocal(), ghidra::TypeOpUnary::getInputLocal(), ghidra::TypeOpFunc::getInputLocal(), ghidra::TypeOpCbranch::getInputLocal(), ghidra::TypeOpPtradd::getInputLocal(), ghidra::TypeOpPtrsub::getInputLocal(), ghidra::TypeOpCpoolref::getInputLocal(), ghidra::TypeOpInsert::getInputLocal(), ghidra::TypeOpExtract::getInputLocal(), ghidra::TypeOp::getOutputLocal(), ghidra::TypeOpBinary::getOutputLocal(), ghidra::TypeOpUnary::getOutputLocal(), ghidra::TypeOpFunc::getOutputLocal(), ghidra::TypeOpPtradd::getOutputLocal(), ghidra::TypeOpPtrsub::getOutputLocal(), ghidra::TypeOpCpoolref::getOutputLocal(), ghidra::TypeOpIntLeft::getOutputToken(), ghidra::TypeOpIntRight::getOutputToken(), ghidra::TypeOpIntSright::getOutputToken(), ghidra::TypeOpPiece::getOutputToken(), ghidra::TypeOpSubpiece::getOutputToken(), ghidra::TypeOpPtrsub::getOutputToken(), ghidra::TypePointerRel::getPtrToFromParent(), ghidra::TypeCode::getSubType(), ghidra::Funcdata::mapGlobals(), ghidra::RangeHint::merge(), ghidra::Funcdata::newConstant(), ghidra::Funcdata::newUnique(), ghidra::Funcdata::newUniqueOut(), ghidra::Funcdata::newVarnode(), ghidra::Funcdata::newVarnodeCallSpecs(), ghidra::Funcdata::newVarnodeIop(), ghidra::Funcdata::newVarnodeOut(), ghidra::Funcdata::newVarnodeSpace(), ghidra::FuncProto::paramShift(), ghidra::TypeOpEqual::propagateAcrossCompare(), ghidra::TypeOpIntAdd::propagateAddIn2Out(), ghidra::TypeOpCopy::propagateType(), ghidra::TypeOpIntXor::propagateType(), ghidra::TypeOpIntAnd::propagateType(), ghidra::TypeOpIntOr::propagateType(), ghidra::TypeOpMulti::propagateType(), ghidra::TypeOpIndirect::propagateType(), ghidra::ParameterBasic::resetSizeLockType(), ghidra::FuncProto::updateInputNoTypes(), ghidra::FuncProto::updateInputTypes(), and ghidra::FuncProto::updateOutputNoTypes().

◆ getBase() [2/2]

Datatype * ghidra::TypeFactory::getBase ( int4  s,
type_metatype  m,
const string &  n 
)

Get named atomic type.

Get or create a "base" type with a specified name and properties

Parameters
sis the desired size
mis the desired meta-type
nis the desired name
Returns
the Database object

References ghidra::Datatype::hashName(), and ghidra::Datatype::id.

◆ getBaseNoChar()

Datatype * ghidra::TypeFactory::getBaseNoChar ( int4  s,
type_metatype  m 
)

Get atomic type excluding "char".

Get a "base" data-type, given its size and metatype. If a 1-byte integer is requested, do NOT return a TypeChar

Parameters
sis the size of the data-type
mis the meta-type of the data-type
Returns
the Datatype object

References ghidra::TYPE_INT.

Referenced by ghidra::TypeOpIntLeft::getInputLocal(), ghidra::TypeOpIntRight::getInputLocal(), and ghidra::TypeOpIntSright::getInputLocal().

◆ getExactPiece()

Datatype * ghidra::TypeFactory::getExactPiece ( Datatype ct,
int4  offset,
int4  size 
)

Get the data-type associated with piece of a structured data-type.

Drill down into nested data-types until we get to a data-type that exactly matches the given offset and size, and return this data-type. Any union data-type encountered terminates the process and a partial union data-type is constructed and returned. If the range indicated by the offset and size contains only a partial field or crosses field boundaries, null is returned.

Parameters
ctis the structured data-type
offsetis the starting byte offset for the piece
sizeis the number of bytes in the piece
Returns
the data-type of the piece or null

References ghidra::Datatype::getMetatype(), ghidra::Datatype::getSize(), ghidra::Datatype::getSubType(), ghidra::Datatype::size, ghidra::TYPE_ARRAY, ghidra::TYPE_STRUCT, and ghidra::TYPE_UNION.

Referenced by ghidra::RulePieceStructure::applyOp(), ghidra::ActionInferTypes::buildLocaltypes(), ghidra::SymbolEntry::getSizedType(), ghidra::SplitDatatype::getValueDatatype(), and ghidra::ActionInferTypes::propagateRef().

◆ getTypeArray()

TypeArray * ghidra::TypeFactory::getTypeArray ( int4  as,
Datatype ao 
)

Construct an array data-type.

Parameters
asis the number of elements in the desired array
aois the data-type of the array element
Returns
the TypeArray object

References ghidra::Datatype::getStripped(), and ghidra::Datatype::hasStripped().

Referenced by ghidra::ScopeLocal::createEntry().

◆ getTypeChar()

TypeChar * ghidra::TypeFactory::getTypeChar ( const string &  n)
private

Create a default "char" type.

This creates a 1-byte character datatype (assumed to use UTF8 encoding)

Parameters
nis the name to give the data-type
Returns
the new character Datatype object

References ghidra::Datatype::hashName(), and ghidra::Datatype::id.

◆ getTypeCode() [1/3]

TypeCode * ghidra::TypeFactory::getTypeCode ( const string &  nm)
private

Create a default "code" type.

Create a "function" or "executable" Datatype object This is used for anonymous function pointers with no prototype

Parameters
nmis the name of the data-type
Returns
the new Datatype object

References ghidra::Datatype::displayName, ghidra::Datatype::hashName(), ghidra::Datatype::id, ghidra::Datatype::markComplete(), and ghidra::Datatype::name.

Referenced by ghidra::ExternRefSymbol::buildNameType(), ghidra::FunctionSymbol::buildType(), ghidra::TypeOpCbranch::getInputLocal(), ghidra::TypeOpCallind::getInputLocal(), ghidra::TypeOpIndirect::getInputLocal(), and ghidra::Funcdata::newCodeRef().

◆ getTypeCode() [2/3]

TypeCode * ghidra::TypeFactory::getTypeCode ( void  )

Get an "anonymous" function data-type.

Retrieve or create the core "code" Datatype object This has no prototype attached to it and is appropriate for anonymous function pointers.

Returns
the TypeCode object

References ghidra::Datatype::markComplete(), ghidra::TYPE_CODE, and ghidra::TYPE_FLOAT.

◆ getTypeCode() [3/3]

TypeCode * ghidra::TypeFactory::getTypeCode ( ProtoModel model,
Datatype outtype,
const vector< Datatype *> &  intypes,
bool  dotdotdot 
)

Create a "function" datatype.

Creates a TypeCode object and associates a specific function prototype with it.

Parameters
modelis the prototype model associated with the function
outtypeis the return type of the function
intypesis the array of input parameters of the function
dotdotdotis true if the function takes variable arguments
Returns
the TypeCode object

References ghidra::Datatype::markComplete(), and ghidra::TypeCode::setPrototype().

◆ getTypedef()

Datatype * ghidra::TypeFactory::getTypedef ( Datatype ct,
const string &  name,
uint8  id,
uint4  format 
)

Create a new typedef data-type.

Find or create a data-type identical to the given data-type except for its name and id. If the name and id already describe an incompatible data-type, an exception is thrown.

Parameters
ctis the given data-type to clone
nameis the new name for the clone
idis the new id for the clone (or 0)
formatis a particular format to force when printing (or zero)
Returns
the (found or created) typedef data-type

References ghidra::Datatype::clone(), ghidra::Datatype::coretype, ghidra::Datatype::displayName, ghidra::Datatype::flags, ghidra::Datatype::getTypedef(), ghidra::Datatype::hashName(), ghidra::Datatype::id, ghidra::Datatype::name, ghidra::Datatype::setDisplayFormat(), and ghidra::Datatype::typedefImm.

◆ getTypeEnum()

TypeEnum * ghidra::TypeFactory::getTypeEnum ( const string &  n)

Create an (empty) enumeration.

The created enumeration will have no named values and a default configuration Named values must be added later.

Parameters
nis the name of the enumeration
Returns
the TypeEnum object

References ghidra::Datatype::enumtype, ghidra::Datatype::hashName(), and ghidra::Datatype::id.

◆ getTypePointer() [1/2]

TypePointer * ghidra::TypeFactory::getTypePointer ( int4  s,
Datatype pt,
uint4  ws 
)

◆ getTypePointer() [2/2]

TypePointer * ghidra::TypeFactory::getTypePointer ( int4  s,
Datatype pt,
uint4  ws,
const string &  n 
)

Construct a named pointer data-type.

The given name is attached, which distinguishes the returned data-type from other unnamed (or differently named) pointers that otherwise have the same attributes.

Parameters
sis the size of the pointer
ptis the pointed-to data-type
wsis the wordsize associated with the pointer
nis the given name to attach to the pointer
Returns
the TypePointer object

References ghidra::TypePointer::calcTruncate(), ghidra::Datatype::displayName, ghidra::Datatype::getStripped(), ghidra::Datatype::hashName(), ghidra::Datatype::hasStripped(), ghidra::Datatype::id, and ghidra::Datatype::name.

◆ getTypePointerNoDepth()

TypePointer * ghidra::TypeFactory::getTypePointerNoDepth ( int4  s,
Datatype pt,
uint4  ws 
)

Construct a depth limited pointer data-type.

Parameters
sis the size of the pointer
ptis the pointed-to data-type
wsis the wordsize associated with the pointer
Returns
the TypePointer object

References ghidra::Datatype::getMetatype(), ghidra::Datatype::getSize(), ghidra::TYPE_PTR, and ghidra::TYPE_UNKNOWN.

Referenced by ghidra::TypeOpLoad::propagateType(), and ghidra::TypeOpStore::propagateType().

◆ getTypePointerRel() [1/2]

TypePointerRel * ghidra::TypeFactory::getTypePointerRel ( TypePointer parentPtr,
Datatype ptrTo,
int4  off 
)

Get pointer offset relative to a container.

Find/create a pointer data-type that points at a known offset relative to a containing data-type. The resulting data-type is unnamed and ephemeral.

Parameters
parentPtris a model pointer data-type, pointing to the containing data-type
ptrTois the data-type being pointed directly to
offis the offset of the pointed-to data-type relative to the container
Returns
the new/matching pointer

References ghidra::TypePointerRel::markEphemeral(), ghidra::TypePointer::ptrto, ghidra::Datatype::size, and ghidra::TypePointer::wordsize.

Referenced by ghidra::TypeOpIntAdd::propagateAddIn2Out().

◆ getTypePointerRel() [2/2]

TypePointerRel * ghidra::TypeFactory::getTypePointerRel ( int4  sz,
Datatype parent,
Datatype ptrTo,
int4  ws,
int4  off,
const string &  nm 
)

Build a named pointer offset into a larger container.

The resulting data-type is named and not ephemeral and will display as a formal data-type in decompiler output.

Parameters
szis the size in bytes of the pointer
parentis data-type of the parent container being indirectly pointed to
ptrTois the data-type being pointed directly to
wsis the addressable unit size of pointed to data
offis the offset of the pointed-to data-type relative to the container
nmis the name to associate with the pointer
Returns
the new/matching pointer

References ghidra::Datatype::displayName, ghidra::Datatype::hashName(), ghidra::Datatype::id, and ghidra::Datatype::name.

◆ getTypePointerStripArray()

TypePointer * ghidra::TypeFactory::getTypePointerStripArray ( int4  s,
Datatype pt,
uint4  ws 
)

Construct a pointer data-type, stripping an ARRAY level.

This creates a pointer to a given data-type. If the given data-type is an array, the TYPE_ARRAY property is stripped off, and a pointer to the array element data-type is returned.

Parameters
sis the size of the pointer
ptis the pointed-to data-type
wsis the wordsize associated with the pointer
Returns
the TypePointer object

References ghidra::TypePointer::calcTruncate(), ghidra::Datatype::getMetatype(), ghidra::Datatype::getStripped(), ghidra::Datatype::hasStripped(), and ghidra::TYPE_ARRAY.

Referenced by ghidra::TypePointer::downChain(), ghidra::ScoreUnionFields::ScoreUnionFields(), and ghidra::Funcdata::spacebaseConstant().

◆ getTypePointerWithSpace()

TypePointer * ghidra::TypeFactory::getTypePointerWithSpace ( Datatype ptrTo,
AddrSpace spc,
const string &  nm 
)

Build a named pointer with an address space attribute.

The new data-type acts like a typedef of a normal pointer but can affect the resolution of constants by the type propagation system.

Parameters
ptrTois the data-type being pointed directly to
spcis the address space to associate with the pointer
nmis the name to associate with the pointer
Returns
the new/matching pointer

References ghidra::TypePointer::calcTruncate(), ghidra::Datatype::displayName, ghidra::Datatype::hashName(), ghidra::Datatype::id, and ghidra::Datatype::name.

◆ getTypeSpacebase()

TypeSpacebase * ghidra::TypeFactory::getTypeSpacebase ( AddrSpace id,
const Address addr 
)

Create a "spacebase" type.

Creates the special TypeSpacebase with an associated address space and scope

Parameters
idis the address space
addrspecifies the function scope, or isInvalid() for global scope
Returns
the TypeSpacebase object

Referenced by ghidra::Funcdata::spacebase(), and ghidra::Funcdata::spacebaseConstant().

◆ getTypeStruct()

TypeStruct * ghidra::TypeFactory::getTypeStruct ( const string &  n)

Create an (empty) structure.

The created structure will be incomplete and have no fields. They must be added later.

Parameters
nis the name of the structure
Returns
the TypeStruct object

References ghidra::Datatype::displayName, ghidra::Datatype::hashName(), ghidra::Datatype::id, and ghidra::Datatype::name.

◆ getTypeUnicode()

TypeUnicode * ghidra::TypeFactory::getTypeUnicode ( const string &  nm,
int4  sz,
type_metatype  m 
)
private

Create a default "unicode" type.

This creates a multi-byte character data-type (using UTF16 or UTF32 encoding)

Parameters
nmis the name to give the data-type
szis the size of the data-type in bytes
mis the presumed meta-type when treating the character as an integer
Returns
the new character Datatype object

References ghidra::Datatype::hashName(), and ghidra::Datatype::id.

◆ getTypeUnion()

TypeUnion * ghidra::TypeFactory::getTypeUnion ( const string &  n)

Create an (empty) union.

The created union will be incomplete and have no fields. They must be added later.

Parameters
nis the name of the union
Returns
the TypeUnion object

References ghidra::Datatype::displayName, ghidra::Datatype::hashName(), ghidra::Datatype::id, and ghidra::Datatype::name.

◆ getTypeVoid()

TypeVoid * ghidra::TypeFactory::getTypeVoid ( void  )

◆ insert()

void ghidra::TypeFactory::insert ( Datatype newtype)
private

Insert pointer into the cross-reference sets.

Internal method for finally inserting a new Datatype pointer

Parameters
newtypeis the new pointer

References ghidra::Datatype::getId(), ghidra::Datatype::id, ghidra::Datatype::printRaw(), and ghidra::TypeCode::printRaw().

◆ orderRecurse()

void ghidra::TypeFactory::orderRecurse ( vector< Datatype *> &  deporder,
DatatypeSet mark,
Datatype ct 
) const
private

Write out dependency list.

Recursively write out all the components of a data-type in dependency order Component data-types will come before the data-type containing them in the list.

Parameters
deporderholds the ordered list of data-types to construct
markis a "marking" container to prevent cycles
ctis the data-type to have written out

References ghidra::Datatype::getDepend(), ghidra::Datatype::numDepend(), ghidra::Datatype::size, and ghidra::Datatype::typedefImm.

◆ parseEnumConfig()

void ghidra::TypeFactory::parseEnumConfig ( Decoder decoder)

Parse the <enum> tag.

Recover default enumeration properties (size and meta-type) from an <enum> XML tag. Should probably consider this deprecated. These values are only used by the internal C parser. param el is the XML element

References ghidra::Decoder::closeElement(), ghidra::Datatype::enumtype, ghidra::Decoder::openElement(), ghidra::Decoder::readBool(), ghidra::Decoder::readSignedInteger(), ghidra::TYPE_INT, and ghidra::TYPE_UINT.

◆ recalcPointerSubmeta()

void ghidra::TypeFactory::recalcPointerSubmeta ( Datatype base,
sub_metatype  sub 
)
private

Recalculate submeta for pointers to given base data-type.

Search for pointers that match the given ptrto and sub-metatype and change it to the current calculated sub-metatype. A change in the sub-metatype may involve reinserting the pointer data-type in the functional tree.

Parameters
baseis the given base data-type
subis the type of pointer to search for

References ghidra::Datatype::getMetatype(), ghidra::TypePointer::ptrto, ghidra::Datatype::submeta, and ghidra::TYPE_PTR.

◆ resizePointer()

TypePointer * ghidra::TypeFactory::resizePointer ( TypePointer ptr,
int4  newSize 
)

Build a resized pointer based on the given pointer.

All the properties of the original pointer are preserved, except the size is changed.

Parameters
ptris the original pointer
newSizeis the size of the new pointer in bytes
Returns
the resized pointer

References ghidra::Datatype::getStripped(), ghidra::Datatype::hasStripped(), ghidra::TypePointer::ptrto, and ghidra::TypePointer::wordsize.

Referenced by ghidra::TypePointer::calcTruncate(), ghidra::TypeOpPiece::propagateType(), ghidra::TypeOpSubpiece::propagateType(), and ghidra::TypeOpSegment::propagateType().

◆ setCoreType()

void ghidra::TypeFactory::setCoreType ( const string &  name,
int4  size,
type_metatype  meta,
bool  chartp 
)

Create a core data-type.

Manually create a "base" core type. This currently must be called before any pointers or arrays are defined off of the type.

Parameters
nameis the data-type name
sizeis the size of the data-type
metais the meta-type of the data-type
chartpis true if a character type should be created

References ghidra::Datatype::coretype, ghidra::Datatype::flags, ghidra::TYPE_CODE, and ghidra::TYPE_VOID.

Referenced by ghidra::ArchitectureGhidra::buildTypegrp().

◆ setDisplayFormat()

void ghidra::TypeFactory::setDisplayFormat ( Datatype ct,
uint4  format 
)

Set the display format associated with the given data-type.

The display format for the data-type is changed based on the given format. A value of zero clears any preexisting format. Otherwise the value can be one of: 1=hex, 2=dec, 4=oct, 8=bin, 16=char

Parameters
ctis the given data-type to change
formatis the given format

References ghidra::Datatype::setDisplayFormat().

◆ setEnumValues()

bool ghidra::TypeFactory::setEnumValues ( const vector< string > &  namelist,
const vector< uintb > &  vallist,
const vector< bool > &  assignlist,
TypeEnum te 
)

Set named values for an enumeration.

Set the list of enumeration values and identifiers for a TypeEnum Fill in any values for any names that weren't explicitly assigned and check for duplicates.

Parameters
namelistis the list of names in the enumeration
vallistis the corresponding list of values assigned to names in namelist
assignlistis true if the corresponding name in namelist has an assigned value
teis the enumeration object to modify
Returns
true if the modification is successful (no duplicate names)

References ghidra::calc_mask(), ghidra::Datatype::getSize(), and ghidra::TypeEnum::setNameMap().

◆ setFields() [1/2]

bool ghidra::TypeFactory::setFields ( vector< TypeField > &  fd,
TypeStruct ot,
int4  fixedsize,
uint4  flags 
)

Set fields on a TypeStruct.

Make sure all the offsets are fully established then set fields of the structure If fixedsize is greater than 0, force the final structure to have that size. This method should only be used on an incomplete structure. It will mark the structure as complete.

Parameters
fdis the list of fields to set
otis the TypeStruct object to modify
fixedsizeis 0 or the forced size of the structure
flagsare other flags to set on the structure
Returns
true if modification was successful

References ghidra::Datatype::flags, ghidra::Datatype::getMetatype(), ghidra::Datatype::getName(), ghidra::Datatype::getSize(), ghidra::Datatype::isIncomplete(), ghidra::Datatype::opaque_string, ghidra::TypeStruct::setFields(), ghidra::Datatype::size, ghidra::SUB_PTR, ghidra::SUB_PTR_STRUCT, ghidra::Datatype::type_incomplete, ghidra::TYPE_VOID, and ghidra::Datatype::variable_length.

◆ setFields() [2/2]

bool ghidra::TypeFactory::setFields ( vector< TypeField > &  fd,
TypeUnion ot,
int4  fixedsize,
uint4  flags 
)

Set fields on a TypeUnion.

If fixedsize is greater than 0, force the final structure to have that size. This method should only be used on an incomplete union. It will mark the union as complete.

Parameters
fdis the list of fields to set
otis the TypeUnion object to modify
fixedsizeis 0 or the forced size of the union
flagsare other flags to set on the union
Returns
true if modification was successful

References ghidra::Datatype::flags, ghidra::Datatype::getMetatype(), ghidra::Datatype::getName(), ghidra::Datatype::isIncomplete(), ghidra::TypeUnion::setFields(), ghidra::Datatype::size, ghidra::Datatype::type_incomplete, ghidra::TYPE_VOID, and ghidra::Datatype::variable_length.

◆ setName()

Datatype * ghidra::TypeFactory::setName ( Datatype ct,
const string &  n 
)

Set the given types name.

This routine renames a Datatype object and fixes up cross-referencing

Parameters
ctis the data-type to rename
nis the new name
Returns
the renamed Datatype object

References ghidra::Datatype::displayName, ghidra::Datatype::hashName(), ghidra::Datatype::id, and ghidra::Datatype::name.

◆ setPrototype()

void ghidra::TypeFactory::setPrototype ( const FuncProto fp,
TypeCode newCode,
uint4  flags 
)

Set the prototype on a TypeCode.

The given prototype is copied into the given code data-type This method should only be used on an incomplete TypeCode. It will mark the TypeCode as complete.

Parameters
fpis the given prototype to copy
newCodeis the given code data-type
flagsare additional flags to transfer into the code data-type

References ghidra::Datatype::flags, ghidra::Datatype::isIncomplete(), ghidra::TypeCode::setPrototype(), ghidra::Datatype::type_incomplete, and ghidra::Datatype::variable_length.

◆ setupSizes()

void ghidra::TypeFactory::setupSizes ( void  )

The documentation for this class was generated from the following files: