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> 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());
|
CutterRListForeach(types, it, RzBaseType, btype)
|
||||||
types.append(getAllUnions());
|
{
|
||||||
types.append(getAllStructs());
|
TypeDescription typeDescription;
|
||||||
types.append(getAllEnums());
|
typeDescription.type = btype->name;
|
||||||
types.append(getAllTypedefs());
|
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()
|
QList<TypeDescription> CutterCore::getAllPrimitiveTypes()
|
||||||
@ -3620,22 +3635,12 @@ QString CutterCore::addTypes(const char *str)
|
|||||||
{
|
{
|
||||||
CORE_LOCK();
|
CORE_LOCK();
|
||||||
char *error_msg = nullptr;
|
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;
|
QString error;
|
||||||
|
|
||||||
if (!parsed) {
|
if (result && error_msg) {
|
||||||
if (error_msg) {
|
error = QString(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;
|
|
||||||
rz_mem_free(error_msg);
|
rz_mem_free(error_msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3649,16 +3654,23 @@ QString CutterCore::getTypeAsC(QString name, QString category)
|
|||||||
if (name.isEmpty() || category.isEmpty()) {
|
if (name.isEmpty() || category.isEmpty()) {
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
QString typeName = sanitizeStringForCommand(name);
|
|
||||||
|
const char *name_char = name.toStdString().c_str();
|
||||||
|
RzBaseType *rzBaseType;
|
||||||
|
|
||||||
if (category == "Struct") {
|
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") {
|
} 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") {
|
} 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") {
|
} 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;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user