Re: Converting tab-complete.c's else-if chain to a switch

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andres Freund <andres(at)anarazel(dot)de>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Converting tab-complete.c's else-if chain to a switch
Date: 2024-07-16 20:25:48
Message-ID: 3429573.1721161548@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I wrote:
> Andres Freund <andres(at)anarazel(dot)de> writes:
>> Hm, the fact that we are continuing to use the same macros in the switch makes
>> it a bit painful to edit the .in.c in an editor with compiler-warnings
>> integration - I see a lot of reported errors ("Expression is not an integer
>> constant expression") due to case statements not being something that the
>> normal C switch can handle.

> Ugh, good point.

> Thinking a bit further outside the box ... maybe the original source
> code could be like it is now (or more likely, like it is after 0002,
> with the switch-to-be stuff all in a separate function), and we
> could make the preprocessor perform the else-to-switch conversion
> every time instead of viewing that as a one-time conversion?
> That would make it a bit more fragile, but perhaps not impossibly so.

I modified the preprocessor to work like that, and I like the results
better than what I had. This version of the patch is set up so that
both the preprocessor input and output files are legal, functional C:
without preprocessing it runs through the else-if chain, but after
preprocessing it uses a loop around the switch. Maybe that's
overkill, but to do anything less you have to make assumptions about
how smart the editor's compiler helper is. That doesn't sound like
an arms race that I want to engage in.

0001 attached is the same as the v1 version, but 0002 does a little
more than before, and then 0003 adds the preprocessor. (I fixed the
bogus install rule, too.)

regards, tom lane

Attachment Content-Type Size
v2-0001-Invent-MatchAnyN-option-for-tab-complete.c-s-Matc.patch text/x-diff 31.7 KB
v2-0002-Prepare-tab-complete.c-for-preprocessing.patch text/x-diff 16.8 KB
v2-0003-Convert-tab-complete-s-long-else-if-chain-to-a-sw.patch text/x-diff 13.5 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2024-07-16 20:26:59 Re: [18] Policy on IMMUTABLE functions and Unicode updates
Previous Message Joe Conway 2024-07-16 20:18:50 Re: [18] Policy on IMMUTABLE functions and Unicode updates