Re: [PATCH 7/9] pre-process: add the -dM option to dump macro definitions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On 20/11/2018 00:18, Luc Van Oostenryck wrote:
> On Mon, Nov 19, 2018 at 08:52:42PM +0000, Ramsay Jones wrote:
>>
>> The current -dD option outputs the macro definitions, in addition to the
>> pre-processed text. In contrast, the -dM option outputs only the macro
>> definitions.
>>
>> Signed-off-by: Ramsay Jones <ramsay@xxxxxxxxxxxxxxxxxxxx>
>> ---
>>  lib.c                                      | 41 +++++++++++++++++-----
>>  lib.h                                      |  1 +
>>  validation/preprocessor/dump-macros-only.c | 36 +++++++++++++++++++
>>  validation/preprocessor/dump-macros.c      |  6 ++++
>>  4 files changed, 75 insertions(+), 9 deletions(-)
>>  create mode 100644 validation/preprocessor/dump-macros-only.c
>>
>> diff --git a/lib.c b/lib.c
>> index 07a5b9c..23c3d27 100644
>> --- a/lib.c
>> +++ b/lib.c
>> @@ -287,6 +287,7 @@ int Wunknown_attribute = 0;
>>  int Wvla = 1;
>>  
>>  int dump_macro_defs = 0;
>> +int dump_macros_only = 0;
>>  
>>  int dbg_compound = 0;
>>  int dbg_dead = 0;
>> @@ -794,16 +795,34 @@ static char **handle_switch_v(char *arg, char **next)
>>  	return next;
>>  }
>>  
>> -static struct flag dumps[] = {
>> -	{ "D", &dump_macro_defs},
>> -};
>> -
>>  static char **handle_switch_d(char *arg, char **next)
>>  {
>> -	char ** ret = handle_onoff_switch(arg, next, dumps, ARRAY_SIZE(dumps));
>> -	if (ret)
>> -		return ret;
>> +	char *arg_char = arg + 1;
>>  
>> +	/*
>> +	 * -d<CHARS>, where <CHARS> is a sequence of characters, not preceded
>> +	 * by a space. If you specify characters whose behaviour conflicts,
>> +	 * the result is undefined.
>> +	 */
>> +	while (*arg_char) {
>> +		switch (*arg_char) {
>> +		case 'M': /* dump just the macro definitions */
>> +			dump_macros_only = 1;
>> +			dump_macro_defs = 0;
> 
> I prefer a small change in the logic to have dump_macro_defs set
> here too.

Hmm, I don't quite follow.

> 
>> +			break;
>> +		case 'D': /* like 'M', but also output pre-processed text */
>> +			dump_macro_defs = 1;
>> +			dump_macros_only = 0;
>> +			break;
> 
> 
>> +		case 'N': /* like 'D', but only output macro names not bodies */
>> +			break;
>> +		case 'I': /* like 'D', but also output #include directives */
>> +			break;
>> +		case 'U': /* like 'D', but only output expanded macros */
>> +			break;
> 
> Do you have a specific reason to add those three too?
> Now if someone use 'gcc -d[NIU] ...' will silently succeed, right?

Heh, yeah, I was going to see how much effort it would take to
implement all of the options that gcc provides, so I put these
here as a reminder/place-holder ... but didn't get back to it! :-D

> Just asking, since I'm not sure yet if it is a good thing or not.

Yep, they should probably error out.

ATB,
Ramsay Jones




[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux