Use C99-designated initializer syntax for more arrays

This is in the same spirit as ef5e2e9085, 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
This commit is contained in:
Michael Paquier 2024-02-28 08:42:36 +09:00
parent e1724af42c
commit afd8ef3909
4 changed files with 128 additions and 173 deletions

View File

@ -56,12 +56,12 @@ raw_parser(const char *str, RawParseMode mode)
{ {
/* this array is indexed by RawParseMode enum */ /* this array is indexed by RawParseMode enum */
static const int mode_token[] = { static const int mode_token[] = {
0, /* RAW_PARSE_DEFAULT */ [RAW_PARSE_DEFAULT] = 0,
MODE_TYPE_NAME, /* RAW_PARSE_TYPE_NAME */ [RAW_PARSE_TYPE_NAME] = MODE_TYPE_NAME,
MODE_PLPGSQL_EXPR, /* RAW_PARSE_PLPGSQL_EXPR */ [RAW_PARSE_PLPGSQL_EXPR] = MODE_PLPGSQL_EXPR,
MODE_PLPGSQL_ASSIGN1, /* RAW_PARSE_PLPGSQL_ASSIGN1 */ [RAW_PARSE_PLPGSQL_ASSIGN1] = MODE_PLPGSQL_ASSIGN1,
MODE_PLPGSQL_ASSIGN2, /* RAW_PARSE_PLPGSQL_ASSIGN2 */ [RAW_PARSE_PLPGSQL_ASSIGN2] = MODE_PLPGSQL_ASSIGN2,
MODE_PLPGSQL_ASSIGN3 /* RAW_PARSE_PLPGSQL_ASSIGN3 */ [RAW_PARSE_PLPGSQL_ASSIGN3] = MODE_PLPGSQL_ASSIGN3,
}; };
yyextra.have_lookahead = true; yyextra.have_lookahead = true;

View File

@ -627,13 +627,13 @@ bool in_hot_standby_guc;
*/ */
const char *const GucContext_Names[] = const char *const GucContext_Names[] =
{ {
/* PGC_INTERNAL */ "internal", [PGC_INTERNAL] = "internal",
/* PGC_POSTMASTER */ "postmaster", [PGC_POSTMASTER] = "postmaster",
/* PGC_SIGHUP */ "sighup", [PGC_SIGHUP] = "sighup",
/* PGC_SU_BACKEND */ "superuser-backend", [PGC_SU_BACKEND] = "superuser-backend",
/* PGC_BACKEND */ "backend", [PGC_BACKEND] = "backend",
/* PGC_SUSET */ "superuser", [PGC_SUSET] = "superuser",
/* PGC_USERSET */ "user" [PGC_USERSET] = "user",
}; };
StaticAssertDecl(lengthof(GucContext_Names) == (PGC_USERSET + 1), StaticAssertDecl(lengthof(GucContext_Names) == (PGC_USERSET + 1),
@ -646,20 +646,20 @@ StaticAssertDecl(lengthof(GucContext_Names) == (PGC_USERSET + 1),
*/ */
const char *const GucSource_Names[] = const char *const GucSource_Names[] =
{ {
/* PGC_S_DEFAULT */ "default", [PGC_S_DEFAULT] = "default",
/* PGC_S_DYNAMIC_DEFAULT */ "default", [PGC_S_DYNAMIC_DEFAULT] = "default",
/* PGC_S_ENV_VAR */ "environment variable", [PGC_S_ENV_VAR] = "environment variable",
/* PGC_S_FILE */ "configuration file", [PGC_S_FILE] = "configuration file",
/* PGC_S_ARGV */ "command line", [PGC_S_ARGV] = "command line",
/* PGC_S_GLOBAL */ "global", [PGC_S_GLOBAL] = "global",
/* PGC_S_DATABASE */ "database", [PGC_S_DATABASE] = "database",
/* PGC_S_USER */ "user", [PGC_S_USER] = "user",
/* PGC_S_DATABASE_USER */ "database user", [PGC_S_DATABASE_USER] = "database user",
/* PGC_S_CLIENT */ "client", [PGC_S_CLIENT] = "client",
/* PGC_S_OVERRIDE */ "override", [PGC_S_OVERRIDE] = "override",
/* PGC_S_INTERACTIVE */ "interactive", [PGC_S_INTERACTIVE] = "interactive",
/* PGC_S_TEST */ "test", [PGC_S_TEST] = "test",
/* PGC_S_SESSION */ "session" [PGC_S_SESSION] = "session",
}; };
StaticAssertDecl(lengthof(GucSource_Names) == (PGC_S_SESSION + 1), StaticAssertDecl(lengthof(GucSource_Names) == (PGC_S_SESSION + 1),
@ -670,96 +670,51 @@ StaticAssertDecl(lengthof(GucSource_Names) == (PGC_S_SESSION + 1),
*/ */
const char *const config_group_names[] = const char *const config_group_names[] =
{ {
/* UNGROUPED */ [UNGROUPED] = gettext_noop("Ungrouped"),
gettext_noop("Ungrouped"), [FILE_LOCATIONS] = gettext_noop("File Locations"),
/* FILE_LOCATIONS */ [CONN_AUTH_SETTINGS] = gettext_noop("Connections and Authentication / Connection Settings"),
gettext_noop("File Locations"), [CONN_AUTH_TCP] = gettext_noop("Connections and Authentication / TCP Settings"),
/* CONN_AUTH_SETTINGS */ [CONN_AUTH_AUTH] = gettext_noop("Connections and Authentication / Authentication"),
gettext_noop("Connections and Authentication / Connection Settings"), [CONN_AUTH_SSL] = gettext_noop("Connections and Authentication / SSL"),
/* CONN_AUTH_TCP */ [RESOURCES_MEM] = gettext_noop("Resource Usage / Memory"),
gettext_noop("Connections and Authentication / TCP Settings"), [RESOURCES_DISK] = gettext_noop("Resource Usage / Disk"),
/* CONN_AUTH_AUTH */ [RESOURCES_KERNEL] = gettext_noop("Resource Usage / Kernel Resources"),
gettext_noop("Connections and Authentication / Authentication"), [RESOURCES_VACUUM_DELAY] = gettext_noop("Resource Usage / Cost-Based Vacuum Delay"),
/* CONN_AUTH_SSL */ [RESOURCES_BGWRITER] = gettext_noop("Resource Usage / Background Writer"),
gettext_noop("Connections and Authentication / SSL"), [RESOURCES_ASYNCHRONOUS] = gettext_noop("Resource Usage / Asynchronous Behavior"),
/* RESOURCES_MEM */ [WAL_SETTINGS] = gettext_noop("Write-Ahead Log / Settings"),
gettext_noop("Resource Usage / Memory"), [WAL_CHECKPOINTS] = gettext_noop("Write-Ahead Log / Checkpoints"),
/* RESOURCES_DISK */ [WAL_ARCHIVING] = gettext_noop("Write-Ahead Log / Archiving"),
gettext_noop("Resource Usage / Disk"), [WAL_RECOVERY] = gettext_noop("Write-Ahead Log / Recovery"),
/* RESOURCES_KERNEL */ [WAL_ARCHIVE_RECOVERY] = gettext_noop("Write-Ahead Log / Archive Recovery"),
gettext_noop("Resource Usage / Kernel Resources"), [WAL_RECOVERY_TARGET] = gettext_noop("Write-Ahead Log / Recovery Target"),
/* RESOURCES_VACUUM_DELAY */ [WAL_SUMMARIZATION] = gettext_noop("Write-Ahead Log / Summarization"),
gettext_noop("Resource Usage / Cost-Based Vacuum Delay"), [REPLICATION_SENDING] = gettext_noop("Replication / Sending Servers"),
/* RESOURCES_BGWRITER */ [REPLICATION_PRIMARY] = gettext_noop("Replication / Primary Server"),
gettext_noop("Resource Usage / Background Writer"), [REPLICATION_STANDBY] = gettext_noop("Replication / Standby Servers"),
/* RESOURCES_ASYNCHRONOUS */ [REPLICATION_SUBSCRIBERS] = gettext_noop("Replication / Subscribers"),
gettext_noop("Resource Usage / Asynchronous Behavior"), [QUERY_TUNING_METHOD] = gettext_noop("Query Tuning / Planner Method Configuration"),
/* WAL_SETTINGS */ [QUERY_TUNING_COST] = gettext_noop("Query Tuning / Planner Cost Constants"),
gettext_noop("Write-Ahead Log / Settings"), [QUERY_TUNING_GEQO] = gettext_noop("Query Tuning / Genetic Query Optimizer"),
/* WAL_CHECKPOINTS */ [QUERY_TUNING_OTHER] = gettext_noop("Query Tuning / Other Planner Options"),
gettext_noop("Write-Ahead Log / Checkpoints"), [LOGGING_WHERE] = gettext_noop("Reporting and Logging / Where to Log"),
/* WAL_ARCHIVING */ [LOGGING_WHEN] = gettext_noop("Reporting and Logging / When to Log"),
gettext_noop("Write-Ahead Log / Archiving"), [LOGGING_WHAT] = gettext_noop("Reporting and Logging / What to Log"),
/* WAL_RECOVERY */ [PROCESS_TITLE] = gettext_noop("Reporting and Logging / Process Title"),
gettext_noop("Write-Ahead Log / Recovery"), [STATS_MONITORING] = gettext_noop("Statistics / Monitoring"),
/* WAL_ARCHIVE_RECOVERY */ [STATS_CUMULATIVE] = gettext_noop("Statistics / Cumulative Query and Index Statistics"),
gettext_noop("Write-Ahead Log / Archive Recovery"), [AUTOVACUUM] = gettext_noop("Autovacuum"),
/* WAL_RECOVERY_TARGET */ [CLIENT_CONN_STATEMENT] = gettext_noop("Client Connection Defaults / Statement Behavior"),
gettext_noop("Write-Ahead Log / Recovery Target"), [CLIENT_CONN_LOCALE] = gettext_noop("Client Connection Defaults / Locale and Formatting"),
/* WAL_SUMMARIZATION */ [CLIENT_CONN_PRELOAD] = gettext_noop("Client Connection Defaults / Shared Library Preloading"),
gettext_noop("Write-Ahead Log / Summarization"), [CLIENT_CONN_OTHER] = gettext_noop("Client Connection Defaults / Other Defaults"),
/* REPLICATION_SENDING */ [LOCK_MANAGEMENT] = gettext_noop("Lock Management"),
gettext_noop("Replication / Sending Servers"), [COMPAT_OPTIONS_PREVIOUS] = gettext_noop("Version and Platform Compatibility / Previous PostgreSQL Versions"),
/* REPLICATION_PRIMARY */ [COMPAT_OPTIONS_CLIENT] = gettext_noop("Version and Platform Compatibility / Other Platforms and Clients"),
gettext_noop("Replication / Primary Server"), [ERROR_HANDLING_OPTIONS] = gettext_noop("Error Handling"),
/* REPLICATION_STANDBY */ [PRESET_OPTIONS] = gettext_noop("Preset Options"),
gettext_noop("Replication / Standby Servers"), [CUSTOM_OPTIONS] = gettext_noop("Customized Options"),
/* REPLICATION_SUBSCRIBERS */ [DEVELOPER_OPTIONS] = gettext_noop("Developer Options"),
gettext_noop("Replication / Subscribers"),
/* QUERY_TUNING_METHOD */
gettext_noop("Query Tuning / Planner Method Configuration"),
/* QUERY_TUNING_COST */
gettext_noop("Query Tuning / Planner Cost Constants"),
/* QUERY_TUNING_GEQO */
gettext_noop("Query Tuning / Genetic Query Optimizer"),
/* QUERY_TUNING_OTHER */
gettext_noop("Query Tuning / Other Planner Options"),
/* LOGGING_WHERE */
gettext_noop("Reporting and Logging / Where to Log"),
/* LOGGING_WHEN */
gettext_noop("Reporting and Logging / When to Log"),
/* LOGGING_WHAT */
gettext_noop("Reporting and Logging / What to Log"),
/* PROCESS_TITLE */
gettext_noop("Reporting and Logging / Process Title"),
/* STATS_MONITORING */
gettext_noop("Statistics / Monitoring"),
/* STATS_CUMULATIVE */
gettext_noop("Statistics / Cumulative Query and Index Statistics"),
/* AUTOVACUUM */
gettext_noop("Autovacuum"),
/* CLIENT_CONN_STATEMENT */
gettext_noop("Client Connection Defaults / Statement Behavior"),
/* CLIENT_CONN_LOCALE */
gettext_noop("Client Connection Defaults / Locale and Formatting"),
/* CLIENT_CONN_PRELOAD */
gettext_noop("Client Connection Defaults / Shared Library Preloading"),
/* CLIENT_CONN_OTHER */
gettext_noop("Client Connection Defaults / Other Defaults"),
/* LOCK_MANAGEMENT */
gettext_noop("Lock Management"),
/* COMPAT_OPTIONS_PREVIOUS */
gettext_noop("Version and Platform Compatibility / Previous PostgreSQL Versions"),
/* COMPAT_OPTIONS_CLIENT */
gettext_noop("Version and Platform Compatibility / Other Platforms and Clients"),
/* ERROR_HANDLING_OPTIONS */
gettext_noop("Error Handling"),
/* PRESET_OPTIONS */
gettext_noop("Preset Options"),
/* CUSTOM_OPTIONS */
gettext_noop("Customized Options"),
/* DEVELOPER_OPTIONS */
gettext_noop("Developer Options"),
/* help_config wants this array to be null-terminated */ /* help_config wants this array to be null-terminated */
NULL NULL
}; };
@ -774,11 +729,11 @@ StaticAssertDecl(lengthof(config_group_names) == (DEVELOPER_OPTIONS + 2),
*/ */
const char *const config_type_names[] = const char *const config_type_names[] =
{ {
/* PGC_BOOL */ "bool", [PGC_BOOL] = "bool",
/* PGC_INT */ "integer", [PGC_INT] = "integer",
/* PGC_REAL */ "real", [PGC_REAL] = "real",
/* PGC_STRING */ "string", [PGC_STRING] = "string",
/* PGC_ENUM */ "enum" [PGC_ENUM] = "enum",
}; };
StaticAssertDecl(lengthof(config_type_names) == (PGC_ENUM + 1), StaticAssertDecl(lengthof(config_type_names) == (PGC_ENUM + 1),

View File

@ -104,53 +104,53 @@ enum dbObjectTypePriorities
/* This table is indexed by enum DumpableObjectType */ /* This table is indexed by enum DumpableObjectType */
static const int dbObjectTypePriority[] = static const int dbObjectTypePriority[] =
{ {
PRIO_NAMESPACE, /* DO_NAMESPACE */ [DO_NAMESPACE] = PRIO_NAMESPACE,
PRIO_EXTENSION, /* DO_EXTENSION */ [DO_EXTENSION] = PRIO_EXTENSION,
PRIO_TYPE, /* DO_TYPE */ [DO_TYPE] = PRIO_TYPE,
PRIO_TYPE, /* DO_SHELL_TYPE */ [DO_SHELL_TYPE] = PRIO_TYPE,
PRIO_FUNC, /* DO_FUNC */ [DO_FUNC] = PRIO_FUNC,
PRIO_AGG, /* DO_AGG */ [DO_AGG] = PRIO_AGG,
PRIO_OPERATOR, /* DO_OPERATOR */ [DO_OPERATOR] = PRIO_OPERATOR,
PRIO_ACCESS_METHOD, /* DO_ACCESS_METHOD */ [DO_ACCESS_METHOD] = PRIO_ACCESS_METHOD,
PRIO_OPFAMILY, /* DO_OPCLASS */ [DO_OPCLASS] = PRIO_OPFAMILY,
PRIO_OPFAMILY, /* DO_OPFAMILY */ [DO_OPFAMILY] = PRIO_OPFAMILY,
PRIO_COLLATION, /* DO_COLLATION */ [DO_COLLATION] = PRIO_COLLATION,
PRIO_CONVERSION, /* DO_CONVERSION */ [DO_CONVERSION] = PRIO_CONVERSION,
PRIO_TABLE, /* DO_TABLE */ [DO_TABLE] = PRIO_TABLE,
PRIO_TABLE_ATTACH, /* DO_TABLE_ATTACH */ [DO_TABLE_ATTACH] = PRIO_TABLE_ATTACH,
PRIO_ATTRDEF, /* DO_ATTRDEF */ [DO_ATTRDEF] = PRIO_ATTRDEF,
PRIO_INDEX, /* DO_INDEX */ [DO_INDEX] = PRIO_INDEX,
PRIO_INDEX_ATTACH, /* DO_INDEX_ATTACH */ [DO_INDEX_ATTACH] = PRIO_INDEX_ATTACH,
PRIO_STATSEXT, /* DO_STATSEXT */ [DO_STATSEXT] = PRIO_STATSEXT,
PRIO_RULE, /* DO_RULE */ [DO_RULE] = PRIO_RULE,
PRIO_TRIGGER, /* DO_TRIGGER */ [DO_TRIGGER] = PRIO_TRIGGER,
PRIO_CONSTRAINT, /* DO_CONSTRAINT */ [DO_CONSTRAINT] = PRIO_CONSTRAINT,
PRIO_FK_CONSTRAINT, /* DO_FK_CONSTRAINT */ [DO_FK_CONSTRAINT] = PRIO_FK_CONSTRAINT,
PRIO_PROCLANG, /* DO_PROCLANG */ [DO_PROCLANG] = PRIO_PROCLANG,
PRIO_CAST, /* DO_CAST */ [DO_CAST] = PRIO_CAST,
PRIO_TABLE_DATA, /* DO_TABLE_DATA */ [DO_TABLE_DATA] = PRIO_TABLE_DATA,
PRIO_SEQUENCE_SET, /* DO_SEQUENCE_SET */ [DO_SEQUENCE_SET] = PRIO_SEQUENCE_SET,
PRIO_DUMMY_TYPE, /* DO_DUMMY_TYPE */ [DO_DUMMY_TYPE] = PRIO_DUMMY_TYPE,
PRIO_TSPARSER, /* DO_TSPARSER */ [DO_TSPARSER] = PRIO_TSPARSER,
PRIO_TSDICT, /* DO_TSDICT */ [DO_TSDICT] = PRIO_TSDICT,
PRIO_TSTEMPLATE, /* DO_TSTEMPLATE */ [DO_TSTEMPLATE] = PRIO_TSTEMPLATE,
PRIO_TSCONFIG, /* DO_TSCONFIG */ [DO_TSCONFIG] = PRIO_TSCONFIG,
PRIO_FDW, /* DO_FDW */ [DO_FDW] = PRIO_FDW,
PRIO_FOREIGN_SERVER, /* DO_FOREIGN_SERVER */ [DO_FOREIGN_SERVER] = PRIO_FOREIGN_SERVER,
PRIO_DEFAULT_ACL, /* DO_DEFAULT_ACL */ [DO_DEFAULT_ACL] = PRIO_DEFAULT_ACL,
PRIO_TRANSFORM, /* DO_TRANSFORM */ [DO_TRANSFORM] = PRIO_TRANSFORM,
PRIO_LARGE_OBJECT, /* DO_LARGE_OBJECT */ [DO_LARGE_OBJECT] = PRIO_LARGE_OBJECT,
PRIO_LARGE_OBJECT_DATA, /* DO_LARGE_OBJECT_DATA */ [DO_LARGE_OBJECT_DATA] = PRIO_LARGE_OBJECT_DATA,
PRIO_PRE_DATA_BOUNDARY, /* DO_PRE_DATA_BOUNDARY */ [DO_PRE_DATA_BOUNDARY] = PRIO_PRE_DATA_BOUNDARY,
PRIO_POST_DATA_BOUNDARY, /* DO_POST_DATA_BOUNDARY */ [DO_POST_DATA_BOUNDARY] = PRIO_POST_DATA_BOUNDARY,
PRIO_EVENT_TRIGGER, /* DO_EVENT_TRIGGER */ [DO_EVENT_TRIGGER] = PRIO_EVENT_TRIGGER,
PRIO_REFRESH_MATVIEW, /* DO_REFRESH_MATVIEW */ [DO_REFRESH_MATVIEW] = PRIO_REFRESH_MATVIEW,
PRIO_POLICY, /* DO_POLICY */ [DO_POLICY] = PRIO_POLICY,
PRIO_PUBLICATION, /* DO_PUBLICATION */ [DO_PUBLICATION] = PRIO_PUBLICATION,
PRIO_PUBLICATION_REL, /* DO_PUBLICATION_REL */ [DO_PUBLICATION_REL] = PRIO_PUBLICATION_REL,
PRIO_PUBLICATION_TABLE_IN_SCHEMA, /* DO_PUBLICATION_TABLE_IN_SCHEMA */ [DO_PUBLICATION_TABLE_IN_SCHEMA] = PRIO_PUBLICATION_TABLE_IN_SCHEMA,
PRIO_SUBSCRIPTION, /* DO_SUBSCRIPTION */ [DO_SUBSCRIPTION] = PRIO_SUBSCRIPTION,
PRIO_SUBSCRIPTION_REL /* DO_SUBSCRIPTION_REL */ [DO_SUBSCRIPTION_REL] = PRIO_SUBSCRIPTION_REL,
}; };
StaticAssertDecl(lengthof(dbObjectTypePriority) == (DO_SUBSCRIPTION_REL + 1), StaticAssertDecl(lengthof(dbObjectTypePriority) == (DO_SUBSCRIPTION_REL + 1),

View File

@ -31,10 +31,10 @@
* pg_relation_size(). * pg_relation_size().
*/ */
const char *const forkNames[] = { const char *const forkNames[] = {
"main", /* MAIN_FORKNUM */ [MAIN_FORKNUM] = "main",
"fsm", /* FSM_FORKNUM */ [FSM_FORKNUM] = "fsm",
"vm", /* VISIBILITYMAP_FORKNUM */ [VISIBILITYMAP_FORKNUM] = "vm",
"init" /* INIT_FORKNUM */ [INIT_FORKNUM] = "init",
}; };
StaticAssertDecl(lengthof(forkNames) == (MAX_FORKNUM + 1), StaticAssertDecl(lengthof(forkNames) == (MAX_FORKNUM + 1),