mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-18 19:06:10 +00:00
Using API for loading types instead of json cmd, fixed viewing of types
This commit is contained in:
parent
a2465ee0bb
commit
bf1c4a2128
@ -3506,15 +3506,30 @@ QList<VTableDescription> CutterCore::getAllVTables()
|
||||
|
||||
QList<TypeDescription> CutterCore::getAllTypes()
|
||||
{
|
||||
QList<TypeDescription> types;
|
||||
CORE_LOCK();
|
||||
QList<TypeDescription> types_desc;
|
||||
RzList *types = rz_type_db_get_base_types(core->analysis->typedb);
|
||||
RzListIter *it;
|
||||
RzBaseType *btype;
|
||||
|
||||
types.append(getAllPrimitiveTypes());
|
||||
types.append(getAllUnions());
|
||||
types.append(getAllStructs());
|
||||
types.append(getAllEnums());
|
||||
types.append(getAllTypedefs());
|
||||
CutterRListForeach(types, it, RzBaseType, btype)
|
||||
{
|
||||
TypeDescription typeDescription;
|
||||
typeDescription.type = btype->name;
|
||||
if (btype->kind == RZ_BASE_TYPE_KIND_STRUCT) {
|
||||
typeDescription.category = "Struct";
|
||||
} else if (btype->kind == RZ_BASE_TYPE_KIND_ENUM) {
|
||||
typeDescription.category = "Enum";
|
||||
} else if (btype->kind == RZ_BASE_TYPE_KIND_ATOMIC) {
|
||||
typeDescription.category = "Primitive";
|
||||
} else if (btype->kind == RZ_BASE_TYPE_KIND_TYPEDEF) {
|
||||
typeDescription.category = "Typedef";
|
||||
}
|
||||
typeDescription.size = btype->size;
|
||||
types_desc << typeDescription;
|
||||
}
|
||||
|
||||
return types;
|
||||
return types_desc;
|
||||
}
|
||||
|
||||
QList<TypeDescription> CutterCore::getAllPrimitiveTypes()
|
||||
@ -3620,22 +3635,12 @@ QString CutterCore::addTypes(const char *str)
|
||||
{
|
||||
CORE_LOCK();
|
||||
char *error_msg = nullptr;
|
||||
char *parsed = rz_type_parse_c_string(core->analysis->typedb, str, &error_msg);
|
||||
int result = rz_type_parse_string(core->analysis->typedb, str, &error_msg);
|
||||
|
||||
QString error;
|
||||
|
||||
if (!parsed) {
|
||||
if (error_msg) {
|
||||
error = error_msg;
|
||||
rz_mem_free(error_msg);
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
rz_type_db_save_parsed_type(core->analysis->typedb, parsed);
|
||||
rz_mem_free(parsed);
|
||||
|
||||
if (error_msg) {
|
||||
error = error_msg;
|
||||
if (result && error_msg) {
|
||||
error = QString(error_msg);
|
||||
rz_mem_free(error_msg);
|
||||
}
|
||||
|
||||
@ -3649,16 +3654,23 @@ QString CutterCore::getTypeAsC(QString name, QString category)
|
||||
if (name.isEmpty() || category.isEmpty()) {
|
||||
return output;
|
||||
}
|
||||
QString typeName = sanitizeStringForCommand(name);
|
||||
|
||||
const char *name_char = name.toStdString().c_str();
|
||||
RzBaseType *rzBaseType;
|
||||
|
||||
if (category == "Struct") {
|
||||
output = cmdRaw(QString("tsc %1").arg(typeName));
|
||||
rzBaseType = rz_type_db_get_struct(core->analysis->typedb, name_char);
|
||||
} else if (category == "Union") {
|
||||
output = cmdRaw(QString("tuc %1").arg(typeName));
|
||||
rzBaseType = rz_type_db_get_union(core->analysis->typedb, name_char);
|
||||
} else if (category == "Enum") {
|
||||
output = cmdRaw(QString("tec %1").arg(typeName));
|
||||
rzBaseType = rz_type_db_get_enum(core->analysis->typedb, name_char);
|
||||
} else if (category == "Typedef") {
|
||||
output = cmdRaw(QString("ttc %1").arg(typeName));
|
||||
rzBaseType = rz_type_db_get_typedef(core->analysis->typedb, name_char);
|
||||
}
|
||||
|
||||
char *output_char = rz_type_db_base_type_as_string(core->analysis->typedb, rzBaseType);
|
||||
|
||||
output = QString(output_char);
|
||||
return output;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user