Skip to content

Commit afd8ef3

Browse files
committed
Use C99-designated initializer syntax for more arrays
This is in the same spirit as ef5e2e9, updating this time some arrays in parser.c, relpath.c, guc_tables.c and pg_dump_sort.c so as the order of their elements has no need to match the enum structures they are based on anymore. Author: Jelte Fennema-Nio Reviewed-by: Jian He, Japin Li Discussion: https://postgr.es/m/CAGECzQT3caUbcCcszNewCCmMbCuyP7XNAm60J3ybd6PN5kH2Dw@mail.gmail.com
1 parent e1724af commit afd8ef3

File tree

4 files changed

+128
-173
lines changed

4 files changed

+128
-173
lines changed

src/backend/parser/parser.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ raw_parser(const char *str, RawParseMode mode)
5656
{
5757
/* this array is indexed by RawParseMode enum */
5858
static const int mode_token[] = {
59-
0, /* RAW_PARSE_DEFAULT */
60-
MODE_TYPE_NAME, /* RAW_PARSE_TYPE_NAME */
61-
MODE_PLPGSQL_EXPR, /* RAW_PARSE_PLPGSQL_EXPR */
62-
MODE_PLPGSQL_ASSIGN1, /* RAW_PARSE_PLPGSQL_ASSIGN1 */
63-
MODE_PLPGSQL_ASSIGN2, /* RAW_PARSE_PLPGSQL_ASSIGN2 */
64-
MODE_PLPGSQL_ASSIGN3 /* RAW_PARSE_PLPGSQL_ASSIGN3 */
59+
[RAW_PARSE_DEFAULT] = 0,
60+
[RAW_PARSE_TYPE_NAME] = MODE_TYPE_NAME,
61+
[RAW_PARSE_PLPGSQL_EXPR] = MODE_PLPGSQL_EXPR,
62+
[RAW_PARSE_PLPGSQL_ASSIGN1] = MODE_PLPGSQL_ASSIGN1,
63+
[RAW_PARSE_PLPGSQL_ASSIGN2] = MODE_PLPGSQL_ASSIGN2,
64+
[RAW_PARSE_PLPGSQL_ASSIGN3] = MODE_PLPGSQL_ASSIGN3,
6565
};
6666

6767
yyextra.have_lookahead = true;

src/backend/utils/misc/guc_tables.c

+71-116
Original file line numberDiff line numberDiff line change
@@ -627,13 +627,13 @@ bool in_hot_standby_guc;
627627
*/
628628
const char *const GucContext_Names[] =
629629
{
630-
/* PGC_INTERNAL */ "internal",
631-
/* PGC_POSTMASTER */ "postmaster",
632-
/* PGC_SIGHUP */ "sighup",
633-
/* PGC_SU_BACKEND */ "superuser-backend",
634-
/* PGC_BACKEND */ "backend",
635-
/* PGC_SUSET */ "superuser",
636-
/* PGC_USERSET */ "user"
630+
[PGC_INTERNAL] = "internal",
631+
[PGC_POSTMASTER] = "postmaster",
632+
[PGC_SIGHUP] = "sighup",
633+
[PGC_SU_BACKEND] = "superuser-backend",
634+
[PGC_BACKEND] = "backend",
635+
[PGC_SUSET] = "superuser",
636+
[PGC_USERSET] = "user",
637637
};
638638

639639
StaticAssertDecl(lengthof(GucContext_Names) == (PGC_USERSET + 1),
@@ -646,20 +646,20 @@ StaticAssertDecl(lengthof(GucContext_Names) == (PGC_USERSET + 1),
646646
*/
647647
const char *const GucSource_Names[] =
648648
{
649-
/* PGC_S_DEFAULT */ "default",
650-
/* PGC_S_DYNAMIC_DEFAULT */ "default",
651-
/* PGC_S_ENV_VAR */ "environment variable",
652-
/* PGC_S_FILE */ "configuration file",
653-
/* PGC_S_ARGV */ "command line",
654-
/* PGC_S_GLOBAL */ "global",
655-
/* PGC_S_DATABASE */ "database",
656-
/* PGC_S_USER */ "user",
657-
/* PGC_S_DATABASE_USER */ "database user",
658-
/* PGC_S_CLIENT */ "client",
659-
/* PGC_S_OVERRIDE */ "override",
660-
/* PGC_S_INTERACTIVE */ "interactive",
661-
/* PGC_S_TEST */ "test",
662-
/* PGC_S_SESSION */ "session"
649+
[PGC_S_DEFAULT] = "default",
650+
[PGC_S_DYNAMIC_DEFAULT] = "default",
651+
[PGC_S_ENV_VAR] = "environment variable",
652+
[PGC_S_FILE] = "configuration file",
653+
[PGC_S_ARGV] = "command line",
654+
[PGC_S_GLOBAL] = "global",
655+
[PGC_S_DATABASE] = "database",
656+
[PGC_S_USER] = "user",
657+
[PGC_S_DATABASE_USER] = "database user",
658+
[PGC_S_CLIENT] = "client",
659+
[PGC_S_OVERRIDE] = "override",
660+
[PGC_S_INTERACTIVE] = "interactive",
661+
[PGC_S_TEST] = "test",
662+
[PGC_S_SESSION] = "session",
663663
};
664664

665665
StaticAssertDecl(lengthof(GucSource_Names) == (PGC_S_SESSION + 1),
@@ -670,96 +670,51 @@ StaticAssertDecl(lengthof(GucSource_Names) == (PGC_S_SESSION + 1),
670670
*/
671671
const char *const config_group_names[] =
672672
{
673-
/* UNGROUPED */
674-
gettext_noop("Ungrouped"),
675-
/* FILE_LOCATIONS */
676-
gettext_noop("File Locations"),
677-
/* CONN_AUTH_SETTINGS */
678-
gettext_noop("Connections and Authentication / Connection Settings"),
679-
/* CONN_AUTH_TCP */
680-
gettext_noop("Connections and Authentication / TCP Settings"),
681-
/* CONN_AUTH_AUTH */
682-
gettext_noop("Connections and Authentication / Authentication"),
683-
/* CONN_AUTH_SSL */
684-
gettext_noop("Connections and Authentication / SSL"),
685-
/* RESOURCES_MEM */
686-
gettext_noop("Resource Usage / Memory"),
687-
/* RESOURCES_DISK */
688-
gettext_noop("Resource Usage / Disk"),
689-
/* RESOURCES_KERNEL */
690-
gettext_noop("Resource Usage / Kernel Resources"),
691-
/* RESOURCES_VACUUM_DELAY */
692-
gettext_noop("Resource Usage / Cost-Based Vacuum Delay"),
693-
/* RESOURCES_BGWRITER */
694-
gettext_noop("Resource Usage / Background Writer"),
695-
/* RESOURCES_ASYNCHRONOUS */
696-
gettext_noop("Resource Usage / Asynchronous Behavior"),
697-
/* WAL_SETTINGS */
698-
gettext_noop("Write-Ahead Log / Settings"),
699-
/* WAL_CHECKPOINTS */
700-
gettext_noop("Write-Ahead Log / Checkpoints"),
701-
/* WAL_ARCHIVING */
702-
gettext_noop("Write-Ahead Log / Archiving"),
703-
/* WAL_RECOVERY */
704-
gettext_noop("Write-Ahead Log / Recovery"),
705-
/* WAL_ARCHIVE_RECOVERY */
706-
gettext_noop("Write-Ahead Log / Archive Recovery"),
707-
/* WAL_RECOVERY_TARGET */
708-
gettext_noop("Write-Ahead Log / Recovery Target"),
709-
/* WAL_SUMMARIZATION */
710-
gettext_noop("Write-Ahead Log / Summarization"),
711-
/* REPLICATION_SENDING */
712-
gettext_noop("Replication / Sending Servers"),
713-
/* REPLICATION_PRIMARY */
714-
gettext_noop("Replication / Primary Server"),
715-
/* REPLICATION_STANDBY */
716-
gettext_noop("Replication / Standby Servers"),
717-
/* REPLICATION_SUBSCRIBERS */
718-
gettext_noop("Replication / Subscribers"),
719-
/* QUERY_TUNING_METHOD */
720-
gettext_noop("Query Tuning / Planner Method Configuration"),
721-
/* QUERY_TUNING_COST */
722-
gettext_noop("Query Tuning / Planner Cost Constants"),
723-
/* QUERY_TUNING_GEQO */
724-
gettext_noop("Query Tuning / Genetic Query Optimizer"),
725-
/* QUERY_TUNING_OTHER */
726-
gettext_noop("Query Tuning / Other Planner Options"),
727-
/* LOGGING_WHERE */
728-
gettext_noop("Reporting and Logging / Where to Log"),
729-
/* LOGGING_WHEN */
730-
gettext_noop("Reporting and Logging / When to Log"),
731-
/* LOGGING_WHAT */
732-
gettext_noop("Reporting and Logging / What to Log"),
733-
/* PROCESS_TITLE */
734-
gettext_noop("Reporting and Logging / Process Title"),
735-
/* STATS_MONITORING */
736-
gettext_noop("Statistics / Monitoring"),
737-
/* STATS_CUMULATIVE */
738-
gettext_noop("Statistics / Cumulative Query and Index Statistics"),
739-
/* AUTOVACUUM */
740-
gettext_noop("Autovacuum"),
741-
/* CLIENT_CONN_STATEMENT */
742-
gettext_noop("Client Connection Defaults / Statement Behavior"),
743-
/* CLIENT_CONN_LOCALE */
744-
gettext_noop("Client Connection Defaults / Locale and Formatting"),
745-
/* CLIENT_CONN_PRELOAD */
746-
gettext_noop("Client Connection Defaults / Shared Library Preloading"),
747-
/* CLIENT_CONN_OTHER */
748-
gettext_noop("Client Connection Defaults / Other Defaults"),
749-
/* LOCK_MANAGEMENT */
750-
gettext_noop("Lock Management"),
751-
/* COMPAT_OPTIONS_PREVIOUS */
752-
gettext_noop("Version and Platform Compatibility / Previous PostgreSQL Versions"),
753-
/* COMPAT_OPTIONS_CLIENT */
754-
gettext_noop("Version and Platform Compatibility / Other Platforms and Clients"),
755-
/* ERROR_HANDLING_OPTIONS */
756-
gettext_noop("Error Handling"),
757-
/* PRESET_OPTIONS */
758-
gettext_noop("Preset Options"),
759-
/* CUSTOM_OPTIONS */
760-
gettext_noop("Customized Options"),
761-
/* DEVELOPER_OPTIONS */
762-
gettext_noop("Developer Options"),
673+
[UNGROUPED] = gettext_noop("Ungrouped"),
674+
[FILE_LOCATIONS] = gettext_noop("File Locations"),
675+
[CONN_AUTH_SETTINGS] = gettext_noop("Connections and Authentication / Connection Settings"),
676+
[CONN_AUTH_TCP] = gettext_noop("Connections and Authentication / TCP Settings"),
677+
[CONN_AUTH_AUTH] = gettext_noop("Connections and Authentication / Authentication"),
678+
[CONN_AUTH_SSL] = gettext_noop("Connections and Authentication / SSL"),
679+
[RESOURCES_MEM] = gettext_noop("Resource Usage / Memory"),
680+
[RESOURCES_DISK] = gettext_noop("Resource Usage / Disk"),
681+
[RESOURCES_KERNEL] = gettext_noop("Resource Usage / Kernel Resources"),
682+
[RESOURCES_VACUUM_DELAY] = gettext_noop("Resource Usage / Cost-Based Vacuum Delay"),
683+
[RESOURCES_BGWRITER] = gettext_noop("Resource Usage / Background Writer"),
684+
[RESOURCES_ASYNCHRONOUS] = gettext_noop("Resource Usage / Asynchronous Behavior"),
685+
[WAL_SETTINGS] = gettext_noop("Write-Ahead Log / Settings"),
686+
[WAL_CHECKPOINTS] = gettext_noop("Write-Ahead Log / Checkpoints"),
687+
[WAL_ARCHIVING] = gettext_noop("Write-Ahead Log / Archiving"),
688+
[WAL_RECOVERY] = gettext_noop("Write-Ahead Log / Recovery"),
689+
[WAL_ARCHIVE_RECOVERY] = gettext_noop("Write-Ahead Log / Archive Recovery"),
690+
[WAL_RECOVERY_TARGET] = gettext_noop("Write-Ahead Log / Recovery Target"),
691+
[WAL_SUMMARIZATION] = gettext_noop("Write-Ahead Log / Summarization"),
692+
[REPLICATION_SENDING] = gettext_noop("Replication / Sending Servers"),
693+
[REPLICATION_PRIMARY] = gettext_noop("Replication / Primary Server"),
694+
[REPLICATION_STANDBY] = gettext_noop("Replication / Standby Servers"),
695+
[REPLICATION_SUBSCRIBERS] = gettext_noop("Replication / Subscribers"),
696+
[QUERY_TUNING_METHOD] = gettext_noop("Query Tuning / Planner Method Configuration"),
697+
[QUERY_TUNING_COST] = gettext_noop("Query Tuning / Planner Cost Constants"),
698+
[QUERY_TUNING_GEQO] = gettext_noop("Query Tuning / Genetic Query Optimizer"),
699+
[QUERY_TUNING_OTHER] = gettext_noop("Query Tuning / Other Planner Options"),
700+
[LOGGING_WHERE] = gettext_noop("Reporting and Logging / Where to Log"),
701+
[LOGGING_WHEN] = gettext_noop("Reporting and Logging / When to Log"),
702+
[LOGGING_WHAT] = gettext_noop("Reporting and Logging / What to Log"),
703+
[PROCESS_TITLE] = gettext_noop("Reporting and Logging / Process Title"),
704+
[STATS_MONITORING] = gettext_noop("Statistics / Monitoring"),
705+
[STATS_CUMULATIVE] = gettext_noop("Statistics / Cumulative Query and Index Statistics"),
706+
[AUTOVACUUM] = gettext_noop("Autovacuum"),
707+
[CLIENT_CONN_STATEMENT] = gettext_noop("Client Connection Defaults / Statement Behavior"),
708+
[CLIENT_CONN_LOCALE] = gettext_noop("Client Connection Defaults / Locale and Formatting"),
709+
[CLIENT_CONN_PRELOAD] = gettext_noop("Client Connection Defaults / Shared Library Preloading"),
710+
[CLIENT_CONN_OTHER] = gettext_noop("Client Connection Defaults / Other Defaults"),
711+
[LOCK_MANAGEMENT] = gettext_noop("Lock Management"),
712+
[COMPAT_OPTIONS_PREVIOUS] = gettext_noop("Version and Platform Compatibility / Previous PostgreSQL Versions"),
713+
[COMPAT_OPTIONS_CLIENT] = gettext_noop("Version and Platform Compatibility / Other Platforms and Clients"),
714+
[ERROR_HANDLING_OPTIONS] = gettext_noop("Error Handling"),
715+
[PRESET_OPTIONS] = gettext_noop("Preset Options"),
716+
[CUSTOM_OPTIONS] = gettext_noop("Customized Options"),
717+
[DEVELOPER_OPTIONS] = gettext_noop("Developer Options"),
763718
/* help_config wants this array to be null-terminated */
764719
NULL
765720
};
@@ -774,11 +729,11 @@ StaticAssertDecl(lengthof(config_group_names) == (DEVELOPER_OPTIONS + 2),
774729
*/
775730
const char *const config_type_names[] =
776731
{
777-
/* PGC_BOOL */ "bool",
778-
/* PGC_INT */ "integer",
779-
/* PGC_REAL */ "real",
780-
/* PGC_STRING */ "string",
781-
/* PGC_ENUM */ "enum"
732+
[PGC_BOOL] = "bool",
733+
[PGC_INT] = "integer",
734+
[PGC_REAL] = "real",
735+
[PGC_STRING] = "string",
736+
[PGC_ENUM] = "enum",
782737
};
783738

784739
StaticAssertDecl(lengthof(config_type_names) == (PGC_ENUM + 1),

src/bin/pg_dump/pg_dump_sort.c

+47-47
Original file line numberDiff line numberDiff line change
@@ -104,53 +104,53 @@ enum dbObjectTypePriorities
104104
/* This table is indexed by enum DumpableObjectType */
105105
static const int dbObjectTypePriority[] =
106106
{
107-
PRIO_NAMESPACE, /* DO_NAMESPACE */
108-
PRIO_EXTENSION, /* DO_EXTENSION */
109-
PRIO_TYPE, /* DO_TYPE */
110-
PRIO_TYPE, /* DO_SHELL_TYPE */
111-
PRIO_FUNC, /* DO_FUNC */
112-
PRIO_AGG, /* DO_AGG */
113-
PRIO_OPERATOR, /* DO_OPERATOR */
114-
PRIO_ACCESS_METHOD, /* DO_ACCESS_METHOD */
115-
PRIO_OPFAMILY, /* DO_OPCLASS */
116-
PRIO_OPFAMILY, /* DO_OPFAMILY */
117-
PRIO_COLLATION, /* DO_COLLATION */
118-
PRIO_CONVERSION, /* DO_CONVERSION */
119-
PRIO_TABLE, /* DO_TABLE */
120-
PRIO_TABLE_ATTACH, /* DO_TABLE_ATTACH */
121-
PRIO_ATTRDEF, /* DO_ATTRDEF */
122-
PRIO_INDEX, /* DO_INDEX */
123-
PRIO_INDEX_ATTACH, /* DO_INDEX_ATTACH */
124-
PRIO_STATSEXT, /* DO_STATSEXT */
125-
PRIO_RULE, /* DO_RULE */
126-
PRIO_TRIGGER, /* DO_TRIGGER */
127-
PRIO_CONSTRAINT, /* DO_CONSTRAINT */
128-
PRIO_FK_CONSTRAINT, /* DO_FK_CONSTRAINT */
129-
PRIO_PROCLANG, /* DO_PROCLANG */
130-
PRIO_CAST, /* DO_CAST */
131-
PRIO_TABLE_DATA, /* DO_TABLE_DATA */
132-
PRIO_SEQUENCE_SET, /* DO_SEQUENCE_SET */
133-
PRIO_DUMMY_TYPE, /* DO_DUMMY_TYPE */
134-
PRIO_TSPARSER, /* DO_TSPARSER */
135-
PRIO_TSDICT, /* DO_TSDICT */
136-
PRIO_TSTEMPLATE, /* DO_TSTEMPLATE */
137-
PRIO_TSCONFIG, /* DO_TSCONFIG */
138-
PRIO_FDW, /* DO_FDW */
139-
PRIO_FOREIGN_SERVER, /* DO_FOREIGN_SERVER */
140-
PRIO_DEFAULT_ACL, /* DO_DEFAULT_ACL */
141-
PRIO_TRANSFORM, /* DO_TRANSFORM */
142-
PRIO_LARGE_OBJECT, /* DO_LARGE_OBJECT */
143-
PRIO_LARGE_OBJECT_DATA, /* DO_LARGE_OBJECT_DATA */
144-
PRIO_PRE_DATA_BOUNDARY, /* DO_PRE_DATA_BOUNDARY */
145-
PRIO_POST_DATA_BOUNDARY, /* DO_POST_DATA_BOUNDARY */
146-
PRIO_EVENT_TRIGGER, /* DO_EVENT_TRIGGER */
147-
PRIO_REFRESH_MATVIEW, /* DO_REFRESH_MATVIEW */
148-
PRIO_POLICY, /* DO_POLICY */
149-
PRIO_PUBLICATION, /* DO_PUBLICATION */
150-
PRIO_PUBLICATION_REL, /* DO_PUBLICATION_REL */
151-
PRIO_PUBLICATION_TABLE_IN_SCHEMA, /* DO_PUBLICATION_TABLE_IN_SCHEMA */
152-
PRIO_SUBSCRIPTION, /* DO_SUBSCRIPTION */
153-
PRIO_SUBSCRIPTION_REL /* DO_SUBSCRIPTION_REL */
107+
[DO_NAMESPACE] = PRIO_NAMESPACE,
108+
[DO_EXTENSION] = PRIO_EXTENSION,
109+
[DO_TYPE] = PRIO_TYPE,
110+
[DO_SHELL_TYPE] = PRIO_TYPE,
111+
[DO_FUNC] = PRIO_FUNC,
112+
[DO_AGG] = PRIO_AGG,
113+
[DO_OPERATOR] = PRIO_OPERATOR,
114+
[DO_ACCESS_METHOD] = PRIO_ACCESS_METHOD,
115+
[DO_OPCLASS] = PRIO_OPFAMILY,
116+
[DO_OPFAMILY] = PRIO_OPFAMILY,
117+
[DO_COLLATION] = PRIO_COLLATION,
118+
[DO_CONVERSION] = PRIO_CONVERSION,
119+
[DO_TABLE] = PRIO_TABLE,
120+
[DO_TABLE_ATTACH] = PRIO_TABLE_ATTACH,
121+
[DO_ATTRDEF] = PRIO_ATTRDEF,
122+
[DO_INDEX] = PRIO_INDEX,
123+
[DO_INDEX_ATTACH] = PRIO_INDEX_ATTACH,
124+
[DO_STATSEXT] = PRIO_STATSEXT,
125+
[DO_RULE] = PRIO_RULE,
126+
[DO_TRIGGER] = PRIO_TRIGGER,
127+
[DO_CONSTRAINT] = PRIO_CONSTRAINT,
128+
[DO_FK_CONSTRAINT] = PRIO_FK_CONSTRAINT,
129+
[DO_PROCLANG] = PRIO_PROCLANG,
130+
[DO_CAST] = PRIO_CAST,
131+
[DO_TABLE_DATA] = PRIO_TABLE_DATA,
132+
[DO_SEQUENCE_SET] = PRIO_SEQUENCE_SET,
133+
[DO_DUMMY_TYPE] = PRIO_DUMMY_TYPE,
134+
[DO_TSPARSER] = PRIO_TSPARSER,
135+
[DO_TSDICT] = PRIO_TSDICT,
136+
[DO_TSTEMPLATE] = PRIO_TSTEMPLATE,
137+
[DO_TSCONFIG] = PRIO_TSCONFIG,
138+
[DO_FDW] = PRIO_FDW,
139+
[DO_FOREIGN_SERVER] = PRIO_FOREIGN_SERVER,
140+
[DO_DEFAULT_ACL] = PRIO_DEFAULT_ACL,
141+
[DO_TRANSFORM] = PRIO_TRANSFORM,
142+
[DO_LARGE_OBJECT] = PRIO_LARGE_OBJECT,
143+
[DO_LARGE_OBJECT_DATA] = PRIO_LARGE_OBJECT_DATA,
144+
[DO_PRE_DATA_BOUNDARY] = PRIO_PRE_DATA_BOUNDARY,
145+
[DO_POST_DATA_BOUNDARY] = PRIO_POST_DATA_BOUNDARY,
146+
[DO_EVENT_TRIGGER] = PRIO_EVENT_TRIGGER,
147+
[DO_REFRESH_MATVIEW] = PRIO_REFRESH_MATVIEW,
148+
[DO_POLICY] = PRIO_POLICY,
149+
[DO_PUBLICATION] = PRIO_PUBLICATION,
150+
[DO_PUBLICATION_REL] = PRIO_PUBLICATION_REL,
151+
[DO_PUBLICATION_TABLE_IN_SCHEMA] = PRIO_PUBLICATION_TABLE_IN_SCHEMA,
152+
[DO_SUBSCRIPTION] = PRIO_SUBSCRIPTION,
153+
[DO_SUBSCRIPTION_REL] = PRIO_SUBSCRIPTION_REL,
154154
};
155155

156156
StaticAssertDecl(lengthof(dbObjectTypePriority) == (DO_SUBSCRIPTION_REL + 1),

src/common/relpath.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131
* pg_relation_size().
3232
*/
3333
const char *const forkNames[] = {
34-
"main", /* MAIN_FORKNUM */
35-
"fsm", /* FSM_FORKNUM */
36-
"vm", /* VISIBILITYMAP_FORKNUM */
37-
"init" /* INIT_FORKNUM */
34+
[MAIN_FORKNUM] = "main",
35+
[FSM_FORKNUM] = "fsm",
36+
[VISIBILITYMAP_FORKNUM] = "vm",
37+
[INIT_FORKNUM] = "init",
3838
};
3939

4040
StaticAssertDecl(lengthof(forkNames) == (MAX_FORKNUM + 1),

0 commit comments

Comments
 (0)