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 */
static const int mode_token[] = {
0, /* RAW_PARSE_DEFAULT */
MODE_TYPE_NAME, /* RAW_PARSE_TYPE_NAME */
MODE_PLPGSQL_EXPR, /* RAW_PARSE_PLPGSQL_EXPR */
MODE_PLPGSQL_ASSIGN1, /* RAW_PARSE_PLPGSQL_ASSIGN1 */
MODE_PLPGSQL_ASSIGN2, /* RAW_PARSE_PLPGSQL_ASSIGN2 */
MODE_PLPGSQL_ASSIGN3 /* RAW_PARSE_PLPGSQL_ASSIGN3 */
[RAW_PARSE_DEFAULT] = 0,
[RAW_PARSE_TYPE_NAME] = MODE_TYPE_NAME,
[RAW_PARSE_PLPGSQL_EXPR] = MODE_PLPGSQL_EXPR,
[RAW_PARSE_PLPGSQL_ASSIGN1] = MODE_PLPGSQL_ASSIGN1,
[RAW_PARSE_PLPGSQL_ASSIGN2] = MODE_PLPGSQL_ASSIGN2,
[RAW_PARSE_PLPGSQL_ASSIGN3] = MODE_PLPGSQL_ASSIGN3,
};
yyextra.have_lookahead = true;

View file

@ -627,13 +627,13 @@ bool in_hot_standby_guc;
*/
const char *const GucContext_Names[] =
{
/* PGC_INTERNAL */ "internal",
/* PGC_POSTMASTER */ "postmaster",
/* PGC_SIGHUP */ "sighup",
/* PGC_SU_BACKEND */ "superuser-backend",
/* PGC_BACKEND */ "backend",
/* PGC_SUSET */ "superuser",
/* PGC_USERSET */ "user"
[PGC_INTERNAL] = "internal",
[PGC_POSTMASTER] = "postmaster",
[PGC_SIGHUP] = "sighup",
[PGC_SU_BACKEND] = "superuser-backend",
[PGC_BACKEND] = "backend",
[PGC_SUSET] = "superuser",
[PGC_USERSET] = "user",
};
StaticAssertDecl(lengthof(GucContext_Names) == (PGC_USERSET + 1),
@ -646,20 +646,20 @@ StaticAssertDecl(lengthof(GucContext_Names) == (PGC_USERSET + 1),
*/
const char *const GucSource_Names[] =
{
/* PGC_S_DEFAULT */ "default",
/* PGC_S_DYNAMIC_DEFAULT */ "default",
/* PGC_S_ENV_VAR */ "environment variable",
/* PGC_S_FILE */ "configuration file",
/* PGC_S_ARGV */ "command line",
/* PGC_S_GLOBAL */ "global",
/* PGC_S_DATABASE */ "database",
/* PGC_S_USER */ "user",
/* PGC_S_DATABASE_USER */ "database user",
/* PGC_S_CLIENT */ "client",
/* PGC_S_OVERRIDE */ "override",
/* PGC_S_INTERACTIVE */ "interactive",
/* PGC_S_TEST */ "test",
/* PGC_S_SESSION */ "session"
[PGC_S_DEFAULT] = "default",
[PGC_S_DYNAMIC_DEFAULT] = "default",
[PGC_S_ENV_VAR] = "environment variable",
[PGC_S_FILE] = "configuration file",
[PGC_S_ARGV] = "command line",
[PGC_S_GLOBAL] = "global",
[PGC_S_DATABASE] = "database",
[PGC_S_USER] = "user",
[PGC_S_DATABASE_USER] = "database user",
[PGC_S_CLIENT] = "client",
[PGC_S_OVERRIDE] = "override",
[PGC_S_INTERACTIVE] = "interactive",
[PGC_S_TEST] = "test",
[PGC_S_SESSION] = "session",
};
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[] =
{
/* UNGROUPED */
gettext_noop("Ungrouped"),
/* FILE_LOCATIONS */
gettext_noop("File Locations"),
/* CONN_AUTH_SETTINGS */
gettext_noop("Connections and Authentication / Connection Settings"),
/* CONN_AUTH_TCP */
gettext_noop("Connections and Authentication / TCP Settings"),
/* CONN_AUTH_AUTH */
gettext_noop("Connections and Authentication / Authentication"),
/* CONN_AUTH_SSL */
gettext_noop("Connections and Authentication / SSL"),
/* RESOURCES_MEM */
gettext_noop("Resource Usage / Memory"),
/* RESOURCES_DISK */
gettext_noop("Resource Usage / Disk"),
/* RESOURCES_KERNEL */
gettext_noop("Resource Usage / Kernel Resources"),
/* RESOURCES_VACUUM_DELAY */
gettext_noop("Resource Usage / Cost-Based Vacuum Delay"),
/* RESOURCES_BGWRITER */
gettext_noop("Resource Usage / Background Writer"),
/* RESOURCES_ASYNCHRONOUS */
gettext_noop("Resource Usage / Asynchronous Behavior"),
/* WAL_SETTINGS */
gettext_noop("Write-Ahead Log / Settings"),
/* WAL_CHECKPOINTS */
gettext_noop("Write-Ahead Log / Checkpoints"),
/* WAL_ARCHIVING */
gettext_noop("Write-Ahead Log / Archiving"),
/* WAL_RECOVERY */
gettext_noop("Write-Ahead Log / Recovery"),
/* WAL_ARCHIVE_RECOVERY */
gettext_noop("Write-Ahead Log / Archive Recovery"),
/* WAL_RECOVERY_TARGET */
gettext_noop("Write-Ahead Log / Recovery Target"),
/* WAL_SUMMARIZATION */
gettext_noop("Write-Ahead Log / Summarization"),
/* REPLICATION_SENDING */
gettext_noop("Replication / Sending Servers"),
/* REPLICATION_PRIMARY */
gettext_noop("Replication / Primary Server"),
/* REPLICATION_STANDBY */
gettext_noop("Replication / Standby Servers"),
/* REPLICATION_SUBSCRIBERS */
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"),
[UNGROUPED] = gettext_noop("Ungrouped"),
[FILE_LOCATIONS] = gettext_noop("File Locations"),
[CONN_AUTH_SETTINGS] = gettext_noop("Connections and Authentication / Connection Settings"),
[CONN_AUTH_TCP] = gettext_noop("Connections and Authentication / TCP Settings"),
[CONN_AUTH_AUTH] = gettext_noop("Connections and Authentication / Authentication"),
[CONN_AUTH_SSL] = gettext_noop("Connections and Authentication / SSL"),
[RESOURCES_MEM] = gettext_noop("Resource Usage / Memory"),
[RESOURCES_DISK] = gettext_noop("Resource Usage / Disk"),
[RESOURCES_KERNEL] = gettext_noop("Resource Usage / Kernel Resources"),
[RESOURCES_VACUUM_DELAY] = gettext_noop("Resource Usage / Cost-Based Vacuum Delay"),
[RESOURCES_BGWRITER] = gettext_noop("Resource Usage / Background Writer"),
[RESOURCES_ASYNCHRONOUS] = gettext_noop("Resource Usage / Asynchronous Behavior"),
[WAL_SETTINGS] = gettext_noop("Write-Ahead Log / Settings"),
[WAL_CHECKPOINTS] = gettext_noop("Write-Ahead Log / Checkpoints"),
[WAL_ARCHIVING] = gettext_noop("Write-Ahead Log / Archiving"),
[WAL_RECOVERY] = gettext_noop("Write-Ahead Log / Recovery"),
[WAL_ARCHIVE_RECOVERY] = gettext_noop("Write-Ahead Log / Archive Recovery"),
[WAL_RECOVERY_TARGET] = gettext_noop("Write-Ahead Log / Recovery Target"),
[WAL_SUMMARIZATION] = gettext_noop("Write-Ahead Log / Summarization"),
[REPLICATION_SENDING] = gettext_noop("Replication / Sending Servers"),
[REPLICATION_PRIMARY] = gettext_noop("Replication / Primary Server"),
[REPLICATION_STANDBY] = gettext_noop("Replication / Standby Servers"),
[REPLICATION_SUBSCRIBERS] = 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 */
NULL
};
@ -774,11 +729,11 @@ StaticAssertDecl(lengthof(config_group_names) == (DEVELOPER_OPTIONS + 2),
*/
const char *const config_type_names[] =
{
/* PGC_BOOL */ "bool",
/* PGC_INT */ "integer",
/* PGC_REAL */ "real",
/* PGC_STRING */ "string",
/* PGC_ENUM */ "enum"
[PGC_BOOL] = "bool",
[PGC_INT] = "integer",
[PGC_REAL] = "real",
[PGC_STRING] = "string",
[PGC_ENUM] = "enum",
};
StaticAssertDecl(lengthof(config_type_names) == (PGC_ENUM + 1),

View file

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

View file

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