From: Michael Wallner Date: Mon, 15 Feb 2016 16:58:59 +0000 (+0100) Subject: fix parseing/dumping functors X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=b9bd15b69df3c3284ca38ed761d20dd8b084d5f3;p=m6w6%2Fext-psi fix parseing/dumping functors --- diff --git a/src/context_dump.c b/src/context_dump.c index efa99c6..2c6e8c0 100644 --- a/src/context_dump.c +++ b/src/context_dump.c @@ -16,30 +16,11 @@ static inline void dump_enum_items(int fd, decl_enum_items *items, unsigned leve #define is_anon_type(name, type) !strncmp(name, type "@", sizeof(type)) static inline void dump_decl_type(int fd, decl_type *t, unsigned level) { - size_t j; - switch (t->type) { case PSI_T_POINTER: dprintf(fd, "%s *", t->name); return; - case PSI_T_FUNCTION: - dump_decl_arg(fd, t->func->func, level); - dprintf(fd, "("); - if (t->func->args) { - for (j = 0; j < t->func->args->count; ++j) { - if (j) { - dprintf(fd, ", "); - } - dump_decl_arg(fd, t->func->args->args[j], level+1); - } - if (t->func->args->varargs) { - dprintf(fd, ", ..."); - } - } - dprintf(fd, ")"); - return; - case PSI_T_STRUCT: dprintf(fd, "struct "); if (!strncmp(t->name, "struct@", sizeof("struct"))) { @@ -75,9 +56,27 @@ static inline void dump_decl_var(int fd, decl_var *v) { } static inline void dump_decl_arg(int fd, decl_arg *a, unsigned level) { - dump_decl_type(fd, a->type, level); + if (a->type->type == PSI_T_FUNCTION) { + dump_decl_type(fd, a->type->func->func->type, level); + dprintf(fd, " ("); + dump_decl_var(fd, a->var); + dprintf(fd, ")("); + if (a->type->func->args) { + size_t j; - if (a->type->type != PSI_T_FUNCTION) { + for (j = 0; j < a->type->func->args->count; ++j) { + if (j) { + dprintf(fd, ", "); + } + dump_decl_arg(fd, a->type->func->args->args[j], level+1); + } + if (a->type->func->args->varargs) { + dprintf(fd, ", ..."); + } + } + dprintf(fd, ")"); + } else { + dump_decl_type(fd, a->type, level); dprintf(fd, " "); dump_decl_var(fd, a->var); } diff --git a/src/parser_proc.y b/src/parser_proc.y index 6a582cb..8ec585d 100644 --- a/src/parser_proc.y +++ b/src/parser_proc.y @@ -315,27 +315,37 @@ decl_func(func) ::= VOID(T) NAME(N). { func->var->token = N; func->token = N; } -decl_typedef_body(def) ::= VOID(T) indirection(i) LPAREN ASTERISK NAME(N) RPAREN decl_typedef_body_fn_args(args). { +decl_typedef_body(def) ::= VOID(T) indirection(decl_i) LPAREN indirection(type_i) NAME(N) RPAREN decl_typedef_body_fn_args(args). { decl_arg *func_ = init_decl_arg( init_decl_type(T->type, T->text), - init_decl_var(N->text, i, 0) + init_decl_var(N->text, decl_i, 0) ); func_->type->token = T; func_->var->token = N; func_->token = N; - def = init_decl_arg(init_decl_type(PSI_T_FUNCTION, func_->var->name), copy_decl_var(func_->var)); + + def = init_decl_arg( + init_decl_type(PSI_T_FUNCTION, func_->var->name), + copy_decl_var(func_->var) + ); + def->var->pointer_level = type_i; def->type->token = PSI_TokenCopy(func_->token); def->type->func = init_decl(init_decl_abi("default"), func_, args); } -decl_typedef_body(def) ::= CONST VOID(T) pointers(i) LPAREN ASTERISK NAME(N) RPAREN decl_typedef_body_fn_args(args). { +decl_typedef_body(def) ::= CONST VOID(T) pointers(decl_i) LPAREN indirection(type_i) NAME(N) RPAREN decl_typedef_body_fn_args(args). { decl_arg *func_ = init_decl_arg( init_decl_type(T->type, T->text), - init_decl_var(N->text, i, 0) + init_decl_var(N->text, decl_i, 0) ); func_->type->token = T; func_->var->token = N; func_->token = N; - def = init_decl_arg(init_decl_type(PSI_T_FUNCTION, func_->var->name), copy_decl_var(func_->var)); + + def = init_decl_arg( + init_decl_type(PSI_T_FUNCTION, func_->var->name), + copy_decl_var(func_->var) + ); + def->var->pointer_level = type_i; def->type->token = PSI_TokenCopy(func_->token); def->type->func = init_decl(init_decl_abi("default"), func_, args); } @@ -373,14 +383,19 @@ decl_vars(vars) ::= decl_vars(vars_) COMMA decl_var(var). { decl_arg(arg_) ::= const_decl_type(type) decl_var(var). { arg_ = init_decl_arg(type, var); } -decl_typedef_body(def) ::= const_decl_type(type_) indirection(i) LPAREN ASTERISK NAME(N) RPAREN decl_typedef_body_fn_args(args). { +decl_typedef_body(def) ::= const_decl_type(type_) indirection(decl_i) LPAREN indirection(type_i) NAME(N) RPAREN decl_typedef_body_fn_args(args). { decl_arg *func_ = init_decl_arg( type_, - init_decl_var(N->text, i, 0) + init_decl_var(N->text, decl_i, 0) ); func_->var->token = N; func_->token = N; - def = init_decl_arg(init_decl_type(PSI_T_FUNCTION, func_->var->name), copy_decl_var(func_->var)); + + def = init_decl_arg( + init_decl_type(PSI_T_FUNCTION, func_->var->name), + copy_decl_var(func_->var) + ); + def->var->pointer_level = type_i; def->type->token = PSI_TokenCopy(func_->token); def->type->func = init_decl(init_decl_abi("default"), func_, args); }