Skip to content

Commit 18eff27

Browse files
committed
misc const/constexpr in show
1 parent 481669a commit 18eff27

File tree

2 files changed

+41
-43
lines changed

2 files changed

+41
-43
lines changed

src/isql/show.epp

Lines changed: 40 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ static SINT64 ISQL_vax_integer(const UCHAR* bytes, USHORT length)
152152
// Initialize types
153153

154154
// Keep this array in sync with obj.h in jrd.
155-
static const SCHAR* Object_types[] =
155+
static constexpr const SCHAR* Object_types[] =
156156
{
157157
"Table",
158158
"View",
@@ -178,21 +178,21 @@ static const SCHAR* Object_types[] =
178178

179179

180180

181-
const SCHAR* Trigger_prefix_types[] =
181+
constexpr const SCHAR* Trigger_prefix_types[] =
182182
{
183183
"BEFORE", // keyword
184184
"AFTER" // keyword
185185
};
186186

187-
const SCHAR* Trigger_suffix_types[] =
187+
constexpr const SCHAR* Trigger_suffix_types[] =
188188
{
189189
"",
190190
"INSERT", // keyword
191191
"UPDATE", // keyword
192192
"DELETE" // keyword
193193
};
194194

195-
const SCHAR* Db_trigger_types[] =
195+
constexpr const SCHAR* Db_trigger_types[] =
196196
{
197197
"CONNECT", // keyword
198198
"DISCONNECT", // keyword
@@ -216,7 +216,7 @@ enum priv_flag {
216216
};
217217

218218

219-
static const struct
219+
static constexpr struct
220220
{
221221
USHORT priv_flag;
222222
const char* priv_string;
@@ -236,12 +236,12 @@ static const struct
236236

237237
// strlen of each element above, + strlen(", ") for separators
238238

239-
const int MAX_PRIV_LIST = (6 + 2 + 7 + 2 + 6 + 2 + 6 + 2 + 6 + 2 + 10 + 2 + 6 + 2 + 5 + 2 + 4 + 1);
239+
constexpr int MAX_PRIV_LIST = (6 + 2 + 7 + 2 + 6 + 2 + 6 + 2 + 6 + 2 + 10 + 2 + 6 + 2 + 5 + 2 + 4 + 1);
240240

241-
const int PRIV_UPDATE_POS = 4;
242-
const int PRIV_REFERENCES_POS = 5;
241+
constexpr int PRIV_UPDATE_POS = 4;
242+
constexpr int PRIV_REFERENCES_POS = 5;
243243

244-
const int RELATION_PRIV_ALL = priv_SELECT | priv_INSERT | priv_UPDATE | priv_DELETE | priv_REFERENCES;
244+
constexpr int RELATION_PRIV_ALL = priv_SELECT | priv_INSERT | priv_UPDATE | priv_DELETE | priv_REFERENCES;
245245

246246
struct PrivilegeFields
247247
{
@@ -252,7 +252,7 @@ struct PrivilegeFields
252252
// Added support to display FORCED WRITES status. - PR 27-NOV-2001
253253
// Added support to display transaction info when next_transaction id is fixed.
254254
// Added support to display ODS version. CVC 26-Aug-2004.
255-
static const UCHAR db_items[] =
255+
static constexpr UCHAR db_items[] =
256256
{
257257
isc_info_page_size,
258258
isc_info_db_size_in_pages,
@@ -286,7 +286,7 @@ static const UCHAR db_items[] =
286286
* This same BPB is safe to use for both V3 & V4 db's - as
287287
* a V3 db will ignore the source_ & target_interp values.
288288
*/
289-
static const UCHAR metadata_text_bpb[] =
289+
static constexpr UCHAR metadata_text_bpb[] =
290290
{
291291
isc_bpb_version1,
292292
isc_bpb_source_type, 1, isc_blob_text,
@@ -297,12 +297,12 @@ static const UCHAR metadata_text_bpb[] =
297297

298298
// trigger action helpers
299299

300-
inline int TRIGGER_ACTION_PREFIX(int value)
300+
inline int TRIGGER_ACTION_PREFIX(int value) noexcept
301301
{
302302
return (value + 1) & 1;
303303
}
304304

305-
inline int TRIGGER_ACTION_SUFFIX(int value, int slot)
305+
inline int TRIGGER_ACTION_SUFFIX(int value, int slot) noexcept
306306
{
307307
return ((value + 1) >> (slot * 2 - 1)) & 3;
308308
}
@@ -314,7 +314,7 @@ const string SHOW_trigger_action(SINT64 type)
314314
case TRIGGER_TYPE_DML:
315315
{
316316
char buffer[256];
317-
int prefix = TRIGGER_ACTION_PREFIX(type);
317+
const int prefix = TRIGGER_ACTION_PREFIX(type);
318318
strcpy(buffer, Trigger_prefix_types[prefix]);
319319
int suffix = TRIGGER_ACTION_SUFFIX(type, 1);
320320
strcat(buffer, " ");
@@ -386,7 +386,7 @@ void SHOW_comments(bool force)
386386
if (isqlGlob.major_ods >= ODS_VERSION11 || force)
387387
{
388388
char banner[BUFFER_LENGTH128];
389-
fb_utils::snprintf(banner, sizeof(banner), "%s/* Comments for database objects. */%s", NEWLINE, NEWLINE);
389+
snprintf(banner, sizeof(banner), "%s/* Comments for database objects. */%s", NEWLINE, NEWLINE);
390390
show_comments(cmmExtract, banner);
391391
}
392392
}
@@ -426,7 +426,7 @@ void SHOW_dbb_parameters(Firebird::IAttachment* db_handle,
426426

427427
for (Firebird::ClumpletReader p(Firebird::ClumpletReader::InfoResponse, buffer, sizeof(buffer)); !p.isEof(); p.moveNext())
428428
{
429-
UCHAR item = p.getClumpTag();
429+
const UCHAR item = p.getClumpTag();
430430
SINT64 value_out = 0;
431431

432432
/*
@@ -676,7 +676,7 @@ void SHOW_dbb_parameters(Firebird::IAttachment* db_handle,
676676
}
677677

678678

679-
void SHOW_read_owner()
679+
void SHOW_read_owner() noexcept
680680
{
681681
/**************************************
682682
*
@@ -786,7 +786,7 @@ static void set_grantee(int user_type, const QualifiedMetaString& name, string&
786786
}
787787

788788

789-
static USHORT convert_privilege_to_code(char privilege)
789+
static USHORT convert_privilege_to_code(char privilege) noexcept
790790
{
791791
switch (privilege)
792792
{
@@ -804,9 +804,9 @@ static USHORT convert_privilege_to_code(char privilege)
804804
case 'G':
805805
// Execute should not be here
806806
return 0;
807+
default:
808+
return priv_UNKNOWN;
807809
}
808-
809-
return priv_UNKNOWN;
810810
}
811811

812812

@@ -1304,7 +1304,7 @@ processing_state SHOW_grants(const std::optional<QualifiedMetaString>& name,
13041304
PRV.RDB$PRIVILEGE EQ 'M'
13051305
SORTED BY PRV.RDB$USER_SCHEMA_NAME, PRV.RDB$USER
13061306
{
1307-
MetaString role_name(PRV.RDB$RELATION_NAME);
1307+
const MetaString role_name(PRV.RDB$RELATION_NAME);
13081308

13091309
user_string = IUTILS_name_to_string(PRV.RDB$USER);
13101310

@@ -1317,7 +1317,7 @@ processing_state SHOW_grants(const std::optional<QualifiedMetaString>& name,
13171317
if (!PRV.RDB$FIELD_NAME.NULL && PRV.RDB$FIELD_NAME[0] == 'D')
13181318
default_option = " DEFAULT";
13191319

1320-
fb_utils::snprintf(Print_buffer, sizeof(Print_buffer), "GRANT%s %s TO %s%s%s%s%s",
1320+
snprintf(Print_buffer, sizeof(Print_buffer), "GRANT%s %s TO %s%s%s%s%s",
13211321
default_option,
13221322
IUTILS_name_to_string(role_name).c_str(),
13231323
user_string.c_str(), with_option, granted_by(PRV.RDB$GRANTOR, PRV.RDB$GRANTOR.NULL).c_str(),
@@ -1733,15 +1733,15 @@ void SHOW_print_metadata_text_blob(FILE* fp, ISC_QUAD* blobid, bool escape_squot
17331733
while (true)
17341734
{
17351735
unsigned int length;
1736-
int cc = blob->getSegment(fbStatus, sizeof(buffer) - 1, buffer, &length);
1736+
const int cc = blob->getSegment(fbStatus, sizeof(buffer) - 1, buffer, &length);
17371737
if (cc == Firebird::IStatus::RESULT_NO_DATA || cc == Firebird::IStatus::RESULT_ERROR)
17381738
break;
17391739

17401740
// ASF: In Windows, \n characters are printed as \r\n in text mode.
17411741
// If the original string has \r\n, they're printed as \r\r\n, resulting
17421742
// in mixed/wrong line endings. So here, we filter any \r present just
17431743
// before \n.
1744-
bool prevEndedWithCr = endedWithCr;
1744+
const bool prevEndedWithCr = endedWithCr;
17451745

17461746
if ((endedWithCr = length != 0 && buffer[length - 1] == '\r'))
17471747
--length;
@@ -3463,9 +3463,7 @@ static void show_db()
34633463

34643464
// First general database parameters
34653465

3466-
bool translate = true;
3467-
3468-
SHOW_dbb_parameters(DB, db_items, sizeof(db_items), translate, NEWLINE);
3466+
SHOW_dbb_parameters(DB, db_items, sizeof(db_items), true, NEWLINE);
34693467

34703468
FOR DBB IN RDB$DATABASE
34713469
CROSS CS IN RDB$CHARACTER_SETS
@@ -4141,7 +4139,7 @@ static processing_state show_functions(const std::optional<QualifiedMetaString>&
41414139
*
41424140
**************************************/
41434141

4144-
int systemFlag = system ? 1 : 0;
4142+
const int systemFlag = system ? 1 : 0;
41454143

41464144
// If no function name was given, just list the functions
41474145
if (!name)
@@ -4616,7 +4614,7 @@ static processing_state show_generators(const std::optional<QualifiedMetaString>
46164614

46174615
Firebird::AlignedBuffer<20> outBuffer;
46184616
fb_assert(outMetadata->getMessageLength(fbStatus) <= outBuffer.size());
4619-
unsigned off = outMetadata->getOffset(fbStatus, 0);
4617+
const unsigned off = outMetadata->getOffset(fbStatus, 0);
46204618
if (ISQL_errmsg (fbStatus))
46214619
return ps_ERR;
46224620

@@ -4644,7 +4642,7 @@ static processing_state show_generators(const std::optional<QualifiedMetaString>
46444642
continue;
46454643

46464644
found = true;
4647-
ISC_INT64 val = use64 ? *((ISC_INT64*) &outBuffer[off]) : *((SLONG*) &outBuffer[off]);
4645+
const ISC_INT64 val = use64 ? *((ISC_INT64*) &outBuffer[off]) : *((SLONG*) &outBuffer[off]);
46484646

46494647
isqlGlob.printf("Generator %s, current value: %" SQUADFORMAT,
46504648
IUTILS_name_to_string(genName).c_str(), val);
@@ -4655,7 +4653,7 @@ static processing_state show_generators(const std::optional<QualifiedMetaString>
46554653
WITH G2.RDB$SCHEMA_NAME EQUIV NULLIF(genName.schema.c_str(), '') AND
46564654
G2.RDB$GENERATOR_NAME = genName.object.c_str()
46574655
{
4658-
ISC_INT64 initval = !G2.RDB$INITIAL_VALUE.NULL ? G2.RDB$INITIAL_VALUE : 0;
4656+
const ISC_INT64 initval = !G2.RDB$INITIAL_VALUE.NULL ? G2.RDB$INITIAL_VALUE : 0;
46594657
isqlGlob.printf(", initial value: %" SQUADFORMAT ", increment: %" SLONGFORMAT,
46604658
initval, G2.RDB$GENERATOR_INCREMENT);
46614659
}
@@ -4853,7 +4851,7 @@ static processing_state show_packages(const std::optional<QualifiedMetaString>&
48534851
SORTED BY PACK.RDB$SCHEMA_NAME, PACK.RDB$PACKAGE_NAME
48544852
{
48554853
const QualifiedMetaString packageName(PACK.RDB$PACKAGE_NAME, PACK.RDB$SCHEMA_NAME);
4856-
bool system_flag = !PACK.RDB$SYSTEM_FLAG.NULL && PACK.RDB$SYSTEM_FLAG > 0;
4854+
const bool system_flag = !PACK.RDB$SYSTEM_FLAG.NULL && PACK.RDB$SYSTEM_FLAG > 0;
48574855

48584856
if (system_flag == sys)
48594857
{
@@ -4932,7 +4930,7 @@ static processing_state show_packages(const std::optional<QualifiedMetaString>&
49324930
}
49334931

49344932

4935-
static void printMap(bool extract, bool global, const MetaString& name, char* usng, const MetaString& plugin,
4933+
static void printMap(bool extract, bool global, const MetaString& name, const char* usng, const MetaString& plugin,
49364934
const MetaString& db, const MetaString& fromType, const MetaString& from, short toType, const MetaString& to)
49374935
{
49384936
if (extract)
@@ -4969,7 +4967,7 @@ static void printMap(bool extract, bool global, const MetaString& name, char* us
49694967
if (db.hasData())
49704968
isqlGlob.printf("IN %s ", IUTILS_name_to_string(db).c_str());
49714969

4972-
bool anyObj = from == "*";
4970+
const bool anyObj = from == "*";
49734971
isqlGlob.printf("FROM %s", anyObj ? "ANY " : "");
49744972
isqlGlob.printf("%s ", IUTILS_name_to_string(fromType).c_str());
49754973
if (!anyObj)
@@ -5089,7 +5087,7 @@ static processing_state show_proc(const std::optional<QualifiedMetaString>& name
50895087
FOR PRC IN RDB$PROCEDURES
50905088
SORTED BY PRC.RDB$SCHEMA_NAME, PRC.RDB$PACKAGE_NAME, PRC.RDB$PROCEDURE_NAME
50915089
{
5092-
bool system_flag = !PRC.RDB$SYSTEM_FLAG.NULL && PRC.RDB$SYSTEM_FLAG > 0;
5090+
const bool system_flag = !PRC.RDB$SYSTEM_FLAG.NULL && PRC.RDB$SYSTEM_FLAG > 0;
50935091

50945092
if (system_flag == sys)
50955093
{
@@ -5499,7 +5497,7 @@ bool SHOW_system_privileges(const MetaString& name, const char* prefix, bool lf)
54995497
{
55005498
for (unsigned byte = 0; byte < sizeof(X.RDB$SYSTEM_PRIVILEGES); ++byte)
55015499
{
5502-
char b = X.RDB$SYSTEM_PRIVILEGES[byte];
5500+
const char b = X.RDB$SYSTEM_PRIVILEGES[byte];
55035501
for (int bit = 0; bit < 8; ++bit)
55045502
{
55055503
if (b & (1 << bit))
@@ -5557,7 +5555,7 @@ static processing_state show_role(const std::optional<MetaString>& name, bool sy
55575555
SORTED BY X.RDB$ROLE_NAME
55585556
{
55595557
const MetaString roleName(X.RDB$ROLE_NAME);
5560-
bool system_flag = !X.RDB$SYSTEM_FLAG.NULL && X.RDB$SYSTEM_FLAG > 0;
5558+
const bool system_flag = !X.RDB$SYSTEM_FLAG.NULL && X.RDB$SYSTEM_FLAG > 0;
55615559

55625560
if (system_flag == system)
55635561
{
@@ -5659,7 +5657,7 @@ static processing_state show_schemas(const std::optional<MetaString>& name, bool
56595657
SORTED BY SCH.RDB$SCHEMA_NAME
56605658
{
56615659
const MetaString schemaName(SCH.RDB$SCHEMA_NAME);
5662-
bool systemFlag = !SCH.RDB$SYSTEM_FLAG.NULL && SCH.RDB$SYSTEM_FLAG > 0;
5660+
const bool systemFlag = !SCH.RDB$SYSTEM_FLAG.NULL && SCH.RDB$SYSTEM_FLAG > 0;
56635661

56645662
if ((name && name != schemaName) || (!name && systemFlag != system))
56655663
continue;
@@ -6585,13 +6583,13 @@ static processing_state show_users12()
65856583
Firebird::AlignedBuffer<MAX_SQL_IDENTIFIER_SIZE + 32> outBuffer;
65866584
fb_assert(outMetadata->getMessageLength(fbStatus) <= outBuffer.size());
65876585

6588-
char* mark = (char*) &outBuffer[outMetadata->getOffset(fbStatus, 0)];
6586+
const char* mark = reinterpret_cast<char*>(&outBuffer[outMetadata->getOffset(fbStatus, 0)]);
65896587
if (ISQL_errmsg (fbStatus))
65906588
return ps_ERR;
65916589
vary* username = (vary*) &outBuffer[outMetadata->getOffset(fbStatus, 1)];
65926590
if (ISQL_errmsg (fbStatus))
65936591
return ps_ERR;
6594-
int* cnt = (int*) &outBuffer[outMetadata->getOffset(fbStatus, 2)];
6592+
const int* cnt = reinterpret_cast<int*>(&outBuffer[outMetadata->getOffset(fbStatus, 2)]);
65956593
if (ISQL_errmsg (fbStatus))
65966594
return ps_ERR;
65976595

@@ -6702,11 +6700,11 @@ static processing_state show_users()
67026700
rc = SKIP; // We found at least one user.
67036701
}
67046702

6705-
unsigned len = p.getBytes()[0];
6703+
const unsigned len = p.getBytes()[0];
67066704
fb_assert(len == p.getClumpLength() - 1);
67076705
const UCHAR* uname = p.getBytes() + 1;
67086706
// Let's mark all attachments with our same user with a # prefix.
6709-
bool same(len == my_user->vary_length && !memcmp(my_user->vary_string, uname, len));
6707+
const bool same = (len == my_user->vary_length && !memcmp(my_user->vary_string, uname, len));
67106708
isqlGlob.printf("%c %.*s", same ? '#' : ' ', len, uname);
67116709
isqlGlob.printf("\n");
67126710
}

src/isql/show_proto.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void SHOW_grant_roles(const SCHAR*, bool*, const TEXT*);
4141
void SHOW_print_metadata_text_blob(FILE*, ISC_QUAD*, bool escape_squote = false,
4242
bool avoid_end_in_single_line_comment = false);
4343
processing_state SHOW_metadata(const FrontendParser::AnyShowNode& node);
44-
void SHOW_read_owner();
44+
void SHOW_read_owner() noexcept;
4545
const Firebird::string SHOW_trigger_action(SINT64);
4646
processing_state SHOW_maps(bool extract, const std::optional<Firebird::MetaString>& name);
4747
bool SHOW_system_privileges(const Firebird::MetaString& name, const char* prfx, bool lf);

0 commit comments

Comments
 (0)