Skip to content

Commit 476a450

Browse files
committed
Fix conversion warnings in dsql and Parser/parse
+ constexpr and misc. changes
1 parent 21c38fc commit 476a450

File tree

6 files changed

+55
-56
lines changed

6 files changed

+55
-56
lines changed

src/dsql/Parser.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ int Parser::yylex()
276276

277277
// Lets skip spaces before store lastLine/lastColumn. This is necessary to avoid yyReducePosn
278278
// produce invalid line/column information - CORE-4381.
279-
bool spacesSkipped = yylexSkipSpaces();
279+
const bool spacesSkipped = yylexSkipSpaces();
280280

281281
yyposn.lastLine = lex.lines;
282282
yyposn.lastColumn = lex.ptr - lex.line_start;
@@ -399,7 +399,7 @@ int Parser::yylexAux()
399399
MemoryPool& pool = *tdbb->getDefaultPool();
400400

401401
SSHORT c = lex.ptr[-1];
402-
UCHAR tok_class = classes(c);
402+
const UCHAR tok_class = classes(c);
403403
char string[MAX_TOKEN_LEN];
404404

405405
// Depending on tok_class of token, parse token
@@ -602,7 +602,6 @@ int Parser::yylexAux()
602602

603603
bool hexerror = false;
604604
Firebird::string temp;
605-
int leadNibble = -1;
606605

607606
// Scan over the hex string converting adjacent bytes into nibble values.
608607
// Every other nibble, write the saved byte to the temp space.
@@ -753,7 +752,7 @@ int Parser::yylexAux()
753752
memcmp(lex.ptr, endChar, endCharSize) == 0 &&
754753
lex.ptr[endCharSize] == '\'')
755754
{
756-
size_t len = lex.ptr - start;
755+
const FB_SIZE_T len = lex.ptr - start;
757756

758757
if (len > MAX_STR_SIZE)
759758
{
@@ -966,7 +965,7 @@ int Parser::yylexAux()
966965
FB_UINT64 number = 0;
967966
Int128 num128;
968967
int expVal = 0;
969-
FB_UINT64 limit_by_10 = MAX_SINT64 / 10;
968+
constexpr FB_UINT64 limit_by_10 = MAX_SINT64 / 10;
970969
int scale = 0;
971970
int expSign = 1;
972971

src/dsql/Parser.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ class Parser : public Firebird::PermanentStorage
128128
};
129129

130130
public:
131-
static const int MAX_TOKEN_LEN = 256;
131+
static inline constexpr int MAX_TOKEN_LEN = 256;
132132

133133
public:
134134
Parser(thread_db* tdbb, MemoryPool& pool, MemoryPool* aStatementPool, DsqlCompilerScratch* aScratch,
@@ -380,14 +380,14 @@ class Parser : public Firebird::PermanentStorage
380380
USHORT client_dialect;
381381
USHORT db_dialect;
382382
const bool requireSemicolon;
383-
USHORT parser_version;
383+
USHORT parser_version = 0;
384384
Firebird::CharSet* charSet;
385385

386386
Firebird::CharSet* metadataCharSet;
387387
Firebird::string transformedString;
388388
Firebird::GenericMap<Firebird::NonPooled<IntlString*, StrMark> > strMarks;
389389
bool stmt_ambiguous;
390-
DsqlStatement* parsedStatement;
390+
DsqlStatement* parsedStatement = nullptr;
391391

392392
// Parser feedback for lexer
393393
QualifiedName* introducerCharSetName = nullptr;
@@ -398,10 +398,10 @@ class Parser : public Firebird::PermanentStorage
398398

399399
// These value/posn of the root non-terminal are returned to the caller
400400
YYSTYPE yyretlval;
401-
Position yyretposn;
401+
Position yyretposn{};
402402

403-
int yynerrs;
404-
int yym; // ASF: moved from local variable of Parser::parseAux()
403+
int yynerrs = 0;
404+
int yym = 0; // ASF: moved from local variable of Parser::parseAux()
405405

406406
// Current parser state
407407
yyparsestate* yyps;

src/dsql/chars.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@
2121
* Contributor(s): ______________________________________.
2222
*/
2323

24-
const SCHAR CHR_LETTER = 1;
25-
const SCHAR CHR_DIGIT = 2;
26-
const SCHAR CHR_IDENT = 4;
27-
const SCHAR CHR_QUOTE = 8;
28-
const SCHAR CHR_WHITE = 16;
29-
const SCHAR CHR_HEX = 32;
30-
const SCHAR CHR_INTRODUCER = 64;
24+
inline constexpr SCHAR CHR_LETTER = 1;
25+
inline constexpr SCHAR CHR_DIGIT = 2;
26+
inline constexpr SCHAR CHR_IDENT = 4;
27+
inline constexpr SCHAR CHR_QUOTE = 8;
28+
inline constexpr SCHAR CHR_WHITE = 16;
29+
inline constexpr SCHAR CHR_HEX = 32;
30+
inline constexpr SCHAR CHR_INTRODUCER = 64;
3131

3232
// Use the functions at the end of this file; do not reference the array directly.
3333

34-
static const SCHAR classes_array[] = {
34+
static inline constexpr SCHAR classes_array[] = {
3535
/* 000 */ 0,
3636
/* 001 */ 0,
3737
/* 002 */ 0,
@@ -290,12 +290,12 @@ static const SCHAR classes_array[] = {
290290
/* 255 */ 0
291291
};
292292

293-
inline SCHAR classes(int idx)
293+
inline SCHAR classes(int idx) noexcept
294294
{
295295
return classes_array[(UCHAR) idx];
296296
}
297297

298-
inline SCHAR classes(UCHAR idx)
298+
inline SCHAR classes(UCHAR idx) noexcept
299299
{
300300
return classes_array[idx];
301301
}

src/dsql/dsql.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ unsigned DSQL_debug = 0;
100100

101101
namespace
102102
{
103-
const UCHAR record_info[] =
103+
inline constexpr UCHAR record_info[] =
104104
{
105105
isc_info_req_update_count, isc_info_req_delete_count,
106106
isc_info_req_select_count, isc_info_req_insert_count
@@ -1029,7 +1029,7 @@ static void sql_info(thread_db* tdbb,
10291029
[](void* arg, SSHORT offset, const char* line)
10301030
{
10311031
auto& localPath = *static_cast<decltype(path)*>(arg);
1032-
auto lineLen = strlen(line);
1032+
auto lineLen = fb_strlen(line);
10331033

10341034
// Trim trailing spaces.
10351035
while (lineLen > 0 && line[lineLen - 1] == ' ')
@@ -1097,7 +1097,7 @@ static void sql_info(thread_db* tdbb,
10971097
items++;
10981098
break;
10991099
}
1100-
// else fall into
1100+
[[fallthrough]];
11011101

11021102
default:
11031103
buffer[0] = item;

src/dsql/dsql.h

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ DEFINE_TRACE_ROUTINE(dsql_trace);
6767
#include "../dsql/sym.h"
6868

6969
// Context aliases used in triggers
70-
const char* const OLD_CONTEXT_NAME = "OLD";
71-
const char* const NEW_CONTEXT_NAME = "NEW";
70+
inline constexpr const char* OLD_CONTEXT_NAME = "OLD";
71+
inline constexpr const char* NEW_CONTEXT_NAME = "NEW";
7272

73-
const int OLD_CONTEXT_VALUE = 0;
74-
const int NEW_CONTEXT_VALUE = 1;
73+
inline constexpr int OLD_CONTEXT_VALUE = 0;
74+
inline constexpr int NEW_CONTEXT_VALUE = 1;
7575

7676
namespace Jrd
7777
{
@@ -126,11 +126,11 @@ class dsql_dbb : public pool_alloc<dsql_type_dbb>
126126
Firebird::LeftPooledMap<Firebird::string, DsqlDmlRequest*> dbb_cursors; // known cursors in database
127127
Firebird::AutoPtr<DsqlStatementCache> dbb_statement_cache;
128128

129-
MemoryPool& dbb_pool; // The current pool for the dbb
130-
Attachment* dbb_attachment;
129+
MemoryPool& dbb_pool; // The current pool for the dbb
130+
Attachment* dbb_attachment;
131131
Firebird::FullPooledMap<MetaName, QualifiedName> dbb_schemas_dfl_charset;
132132
QualifiedName dbb_dfl_charset;
133-
bool dbb_no_charset;
133+
bool dbb_no_charset = false;
134134

135135
dsql_dbb(MemoryPool& p, Attachment* attachment);
136136
~dsql_dbb();
@@ -156,13 +156,13 @@ class dsql_rel : public pool_alloc<dsql_type_rel>
156156
{
157157
}
158158

159-
dsql_fld* rel_fields; // Field block
159+
dsql_fld* rel_fields = nullptr; // Field block
160160
//dsql_rel* rel_base_relation; // base relation for an updatable view
161-
QualifiedName rel_name; // Name of relation
161+
QualifiedName rel_name; // Name of relation
162162
MetaName rel_owner; // Owner of relation
163-
USHORT rel_id; // Relation id
164-
USHORT rel_dbkey_length;
165-
USHORT rel_flags;
163+
USHORT rel_id = 0; // Relation id
164+
USHORT rel_dbkey_length = 0;
165+
USHORT rel_flags = 0;
166166
};
167167

168168
// rel_flags bits
@@ -542,16 +542,16 @@ class dsql_ctx : public pool_alloc<dsql_type_ctx>
542542

543543
// Flag values for ctx_flags
544544

545-
const USHORT CTX_outer_join = 0x01; // reference is part of an outer join
546-
const USHORT CTX_system = 0x02; // Context generated by system (NEW/OLD in triggers, check-constraint, RETURNING)
547-
const USHORT CTX_null = 0x04; // Fields of the context should be resolved to NULL constant
548-
const USHORT CTX_returning = 0x08; // Context generated by RETURNING
549-
const USHORT CTX_recursive = 0x10; // Context has secondary number (ctx_recursive) generated for recursive UNION
550-
const USHORT CTX_view_with_check_store = 0x20; // Context of WITH CHECK OPTION view's store trigger
551-
const USHORT CTX_view_with_check_modify = 0x40; // Context of WITH CHECK OPTION view's modify trigger
552-
const USHORT CTX_cursor = 0x80; // Context is a cursor
553-
const USHORT CTX_lateral = 0x100; // Context is a lateral derived table
554-
const USHORT CTX_blr_fields = 0x200; // Fields of the context are defined inside BLR
545+
inline constexpr USHORT CTX_outer_join = 0x01; // reference is part of an outer join
546+
inline constexpr USHORT CTX_system = 0x02; // Context generated by system (NEW/OLD in triggers, check-constraint, RETURNING)
547+
inline constexpr USHORT CTX_null = 0x04; // Fields of the context should be resolved to NULL constant
548+
inline constexpr USHORT CTX_returning = 0x08; // Context generated by RETURNING
549+
inline constexpr USHORT CTX_recursive = 0x10; // Context has secondary number (ctx_recursive) generated for recursive UNION
550+
inline constexpr USHORT CTX_view_with_check_store = 0x20; // Context of WITH CHECK OPTION view's store trigger
551+
inline constexpr USHORT CTX_view_with_check_modify = 0x40; // Context of WITH CHECK OPTION view's modify trigger
552+
inline constexpr USHORT CTX_cursor = 0x80; // Context is a cursor
553+
inline constexpr USHORT CTX_lateral = 0x100; // Context is a lateral derived table
554+
inline constexpr USHORT CTX_blr_fields = 0x200; // Fields of the context are defined inside BLR
555555

556556
//! Aggregate/union map block to map virtual fields to their base
557557
//! TMN: NOTE! This datatype should definitely be renamed!
@@ -652,7 +652,7 @@ class IntlString
652652

653653
Firebird::string toUtf8(jrd_tra* transaction) const;
654654

655-
const QualifiedName& getCharSet() const
655+
const QualifiedName& getCharSet() const noexcept
656656
{
657657
return charset;
658658
}
@@ -662,7 +662,7 @@ class IntlString
662662
charset = value;
663663
}
664664

665-
const Firebird::string& getString() const
665+
const Firebird::string& getString() const noexcept
666666
{
667667
return s;
668668
}
@@ -690,7 +690,7 @@ class Lim64String : public Firebird::string
690690
scale(sc)
691691
{ }
692692

693-
int getScale()
693+
int getScale() noexcept
694694
{
695695
return scale;
696696
}
@@ -782,7 +782,7 @@ struct SignatureParameter
782782
std::optional<SSHORT> fieldCharSetId;
783783
std::optional<SSHORT> fieldPrecision;
784784

785-
bool operator >(const SignatureParameter& o) const
785+
bool operator >(const SignatureParameter& o) const noexcept
786786
{
787787
return type > o.type || (type == o.type && number > o.number);
788788
}

src/dsql/parse.y

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,12 @@
101101
// since UNIX isn't standard, we have to define
102102
// stuff which is in <limits.h> (which isn't available on all UNIXes...
103103

104-
const long SHRT_POS_MAX = 32767;
105-
const long SHRT_UNSIGNED_MAX = 65535;
106-
const long SHRT_NEG_MAX = 32768;
107-
const int POSITIVE = 0;
108-
const int NEGATIVE = 1;
109-
const int UNSIGNED = 2;
104+
inline constexpr long SHRT_POS_MAX = 32767;
105+
inline constexpr long SHRT_UNSIGNED_MAX = 65535;
106+
inline constexpr long SHRT_NEG_MAX = 32768;
107+
inline constexpr int POSITIVE = 0;
108+
inline constexpr int NEGATIVE = 1;
109+
inline constexpr int UNSIGNED = 2;
110110

111111
//const int MIN_CACHE_BUFFERS = 250;
112112
//const int DEF_CACHE_BUFFERS = 1000;

0 commit comments

Comments
 (0)