Re: Converting tab-complete.c's else-if chain to a switch
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Andres Freund <andres@anarazel.de>
Cc: pgsql-hackers@lists.postgresql.org
Date: 2024-07-16T20:25:48Z
Lists: pgsql-hackers
Attachments
- v2-0001-Invent-MatchAnyN-option-for-tab-complete.c-s-Matc.patch (text/x-diff) patch v2-0001
- v2-0002-Prepare-tab-complete.c-for-preprocessing.patch (text/x-diff) patch v2-0002
- v2-0003-Convert-tab-complete-s-long-else-if-chain-to-a-sw.patch (text/x-diff) patch v2-0003
I wrote:
> Andres Freund <andres@anarazel.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
Commits
-
Don't hard-code the input file name in gen_tabcomplete.pl's output.
- c75c6f8d280a 18.0 landed
-
Avoid possible segfault in psql's tab completion.
- 95eb4cd4ff06 18.0 landed
-
Convert tab-complete's long else-if chain to a switch statement.
- f391d9dc93a2 18.0 landed
-
Prepare tab-complete.c for preprocessing.
- bd1276a3c943 18.0 landed
-
Invent "MatchAnyN" option for tab-complete.c's Matches/MatchesCS.
- ef0938f7bdd0 18.0 landed