diff options
author | Petr Machata <pmachata@redhat.com> | 2012-10-26 22:29:59 +0200 |
---|---|---|
committer | Petr Machata <pmachata@redhat.com> | 2012-10-26 22:29:59 +0200 |
commit | 818e23b064cdcafa6c04628d0d8ad5c6891fbdd9 (patch) | |
tree | 306a71e622adf92aa520e100e7a5ebdace092fff /read_config_file.c | |
parent | 2c54f0602e11eeaf7b0ca4cf92bbec3859fbb41f (diff) | |
download | ltrace-818e23b064cdcafa6c04628d0d8ad5c6891fbdd9.tar.gz |
Change backward-compatible support for void as function argument
- (void) can be converted to ()
- Now that we have param packs, void detection needs to be done differently
Diffstat (limited to 'read_config_file.c')
-rw-r--r-- | read_config_file.c | 53 |
1 files changed, 36 insertions, 17 deletions
diff --git a/read_config_file.c b/read_config_file.c index 8b3ef55..db08e99 100644 --- a/read_config_file.c +++ b/read_config_file.c @@ -975,6 +975,13 @@ add_param(Function *fun, size_t *allocdp) return 0; } +static int +param_is_void(struct param *param) +{ + return param->flavor == PARAM_FLAVOR_TYPE + && param->u.type.type->type == ARGTYPE_VOID; +} + static Function * process_line(char *buf) { char *str = buf; @@ -1058,23 +1065,6 @@ process_line(char *buf) { goto err; } - /* XXX We used to allow void parameter as a synonym to - * an argument that shouldn't be displayed. We may - * wish to re-introduce this when lenses are - * implemented, as a synonym, but backends generally - * need to know the type, so disallow bare void for - * now. */ - if (type->type == ARGTYPE_VOID) { - report_warning(filename, line_no, - "void parameter assumed to be 'int'"); - if (own) { - type_destroy(type); - free(type); - } - type = type_get_simple(ARGTYPE_INT); - own = 0; - } - param_init_type(&fun->params[fun->num_params++], type, own); eat_spaces(&str); @@ -1092,6 +1082,35 @@ process_line(char *buf) { } } + /* We used to allow void parameter as a synonym to an argument + * that shouldn't be displayed. But backends really need to + * know the exact type that they are dealing with. The proper + * way to do this these days is to use the hide lens. + * + * So if there are any voids in the parameter list, show a + * warning and assume that they are ints. If there's a sole + * void, show a warning and assume the function doesn't take + * any arguments. The latter is conservative, we can drop the + * argument altogether, instead of fetching and then not + * showing it, without breaking any observable behavior. */ + if (fun->num_params == 1 && param_is_void(&fun->params[0])) { + report_warning(filename, line_no, + "sole void parameter ignored"); + } else { + size_t i; + struct arg_type_info *type = type_get_simple(ARGTYPE_INT); + for (i = 0; i < fun->num_params; ++i) { + if (param_is_void(&fun->params[i])) { + report_warning + (filename, line_no, + "void parameter assumed to be 'int'"); + + param_destroy(&fun->params[i]); + param_init_type(&fun->params[i], type, 0); + } + } + } + if (extra_param != NULL) { assert(fun->num_params < allocd); memcpy(&fun->params[fun->num_params++], extra_param, |