Skip to content

Commit b643bdd

Browse files
committed
fix(RDFunction): always refer 'function' typedef, minor fixes
1 parent a7ca4c1 commit b643bdd

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

‎src/core/function.c‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -231,23 +231,21 @@ void rd_i_function_rebuild_graph(RDFunction* self,
231231
}
232232

233233
const char* rd_i_function_to_str(const RDFunction* self, RDContext* ctx) {
234-
RDName n;
235-
if(!rd_i_get_name(ctx, self->address, false, &n)) return NULL;
236-
237-
const RDTypeDef* func_def = rd_i_typedef_find(ctx, n.value);
238-
if(!func_def || func_def->kind != RD_TKIND_FUNC) return NULL;
239-
240234
RDCharVect* t_buf = &ctx->type_buf;
241235
str_clear(&ctx->tdef_buf);
242236

243-
const RDFunctionType* f_type = &func_def->func_;
237+
const RDFunctionType* f_type = &self->type_def->func_;
244238

245239
if(f_type->ret.has_value) {
246240
str_append(&ctx->tdef_buf, rd_i_type_to_str(&f_type->ret.value, t_buf));
247241
str_push(&ctx->tdef_buf, ' ');
248242
}
249243

250-
str_append(&ctx->tdef_buf, func_def->name);
244+
RDName n; // try to get the name
245+
if(rd_i_get_name(ctx, self->address, false, &n))
246+
str_append(&ctx->tdef_buf, n.value);
247+
else
248+
str_append(&ctx->tdef_buf, self->type_def->name);
251249

252250
if(f_type->args.has_value) {
253251

@@ -294,8 +292,12 @@ RDFunction* rd_i_function_create(RDContext* ctx, RDAddress address) {
294292
*self = (RDFunction){
295293
.context = ctx,
296294
.address = address,
295+
.type_def = rd_i_typedef_find(ctx, "function"),
297296
};
298297

298+
assert(self->type_def);
299+
assert(self->type_def->kind == RD_TKIND_FUNC);
300+
299301
return self;
300302
}
301303

0 commit comments

Comments
 (0)