Skip to content

Commit be37e92

Browse files
committed
constexpr DdlNodes
+ noexcept + const changes
1 parent db3a009 commit be37e92

File tree

2 files changed

+47
-50
lines changed

2 files changed

+47
-50
lines changed

src/dsql/DdlNodes.epp

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ static void checkFkPairTypes(const rel_t masterType, const QualifiedName& master
9595
const rel_t childType, const QualifiedName& childName);
9696
static void modifyLocalFieldPosition(thread_db* tdbb, jrd_tra* transaction,
9797
const QualifiedName& relationName, const MetaName& fieldName, USHORT newPosition);
98-
static rel_t relationType(SSHORT relationTypeNull, SSHORT relationType);
98+
static rel_t relationType(SSHORT relationTypeNull, SSHORT relationType) noexcept;
9999
static void saveField(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch, const MetaName& fieldName);
100100
static void saveRelation(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch,
101101
const QualifiedName& relationName, bool view, bool creating);
@@ -110,7 +110,7 @@ static void updateRdbFields(const TypeClause* type,
110110
SSHORT& collationIdNull, SSHORT& collationId,
111111
SSHORT& segmentLengthNull, SSHORT& segmentLength);
112112

113-
static const char* const CHECK_CONSTRAINT_EXCEPTION = "check_constraint";
113+
static constexpr const char* CHECK_CONSTRAINT_EXCEPTION = "check_constraint";
114114

115115
DATABASE DB = STATIC "ODS.RDB";
116116

@@ -310,7 +310,7 @@ static void checkViewDependency(thread_db* tdbb, jrd_tra* transaction,
310310
X.RDB$RELATION_NAME EQ Z.RDB$RELATION_NAME AND
311311
Y.RDB$VIEW_CONTEXT EQ Z.RDB$VIEW_CONTEXT
312312
{
313-
QualifiedName viewName(Z.RDB$VIEW_NAME, Z.RDB$SCHEMA_NAME);
313+
const QualifiedName viewName(Z.RDB$VIEW_NAME, Z.RDB$SCHEMA_NAME);
314314

315315
// msg 206: Column %s from table %s is referenced in %s.
316316
status_exception::raise(
@@ -711,7 +711,7 @@ static void modifyLocalFieldPosition(thread_db* tdbb, jrd_tra* transaction,
711711
}
712712

713713
// Find the position of the last field in the relation.
714-
SLONG maxPosition = SLONG(newPos) - 1;
714+
const SLONG maxPosition = SLONG(newPos) - 1;
715715

716716
// If the existing position of the field is less than the new position of
717717
// the field, subtract 1 to move the fields to their new positions otherwise,
@@ -759,7 +759,7 @@ static void modifyLocalFieldPosition(thread_db* tdbb, jrd_tra* transaction,
759759
}
760760

761761
// Convert RDB$RELATION_TYPE to rel_t type.
762-
static rel_t relationType(SSHORT relationTypeNull, SSHORT relationType)
762+
static inline rel_t relationType(SSHORT relationTypeNull, SSHORT relationType) noexcept
763763
{
764764
return relationTypeNull ? rel_persistent : rel_t(relationType);
765765
}
@@ -5097,7 +5097,7 @@ void AlterDomainNode::checkUpdate(const dyn_fld& origFld, const dyn_fld& newFld)
50975097
//
50985098
// This function returns an error code if the conversion can not be made. If the conversion can be
50995099
// made, FB_SUCCESS is returned.
5100-
ULONG AlterDomainNode::checkUpdateNumericType(const dyn_fld& origFld, const dyn_fld& newFld)
5100+
ULONG AlterDomainNode::checkUpdateNumericType(const dyn_fld& origFld, const dyn_fld& newFld) noexcept
51015101
{
51025102
// Since dsc_scale is negative, the sum of precision and scale produces
51035103
// the width of the integral part.
@@ -6896,7 +6896,8 @@ void RelationNode::makeConstraint(thread_db* tdbb, DsqlCompilerScratch* dsqlScra
68966896

68976897
if (clause->constraintType == AddConstraintClause::CTYPE_NOT_NULL)
68986898
break;
6899-
// AddConstraintClause::CTYPE_PK falls into
6899+
6900+
[[fallthrough]];
69006901

69016902
case AddConstraintClause::CTYPE_UNIQUE:
69026903
{
@@ -6992,7 +6993,7 @@ void RelationNode::makeConstraint(thread_db* tdbb, DsqlCompilerScratch* dsqlScra
69926993

69936994
default:
69946995
fb_assert(0);
6995-
// fall into
6996+
[[fallthrough]];
69966997

69976998
case RefActionClause::ACTION_NONE:
69986999
constraint.create->refUpdateAction = RI_ACTION_NONE;
@@ -7021,7 +7022,7 @@ void RelationNode::makeConstraint(thread_db* tdbb, DsqlCompilerScratch* dsqlScra
70217022

70227023
default:
70237024
fb_assert(0);
7024-
// fall into
7025+
[[fallthrough]];
70257026

70267027
case RefActionClause::ACTION_NONE:
70277028
constraint.create->refDeleteAction = RI_ACTION_NONE;
@@ -7883,7 +7884,7 @@ void CreateRelationNode::execute(thread_db* tdbb, DsqlCompilerScratch* dsqlScrat
78837884
}
78847885
END_STORE
78857886

7886-
bool replicationEnabled;
7887+
bool replicationEnabled = false;
78877888

78887889
if (replicationState.isAssigned())
78897890
replicationEnabled = replicationState.asBool();
@@ -8490,7 +8491,7 @@ void AlterRelationNode::modifyField(thread_db* tdbb, DsqlCompilerScratch* dsqlSc
84908491
{
84918492
found = true;
84928493

8493-
bool isView = !REL.RDB$VIEW_BLR.NULL;
8494+
const bool isView = !REL.RDB$VIEW_BLR.NULL;
84948495

84958496
if (!isView && (!FLD.RDB$COMPUTED_BLR.NULL != (clause->computed != NULL)))
84968497
{
@@ -9440,7 +9441,7 @@ void CreateAlterViewNode::execute(thread_db* tdbb, DsqlCompilerScratch* dsqlScra
94409441

94419442
SCL_check_schema(tdbb, PREL.RDB$SCHEMA_NAME, SCL_usage);
94429443

9443-
if (auto priv = SCL_get_mask(tdbb, QualifiedName(PREL.RDB$RELATION_NAME, PREL.RDB$SCHEMA_NAME), "");
9444+
if (const auto priv = SCL_get_mask(tdbb, QualifiedName(PREL.RDB$RELATION_NAME, PREL.RDB$SCHEMA_NAME), "");
94449445
!(priv & SCL_select)
94459446
)
94469447
{
@@ -9641,7 +9642,7 @@ void CreateAlterViewNode::execute(thread_db* tdbb, DsqlCompilerScratch* dsqlScra
96419642
FLD.RDB$SCHEMA_NAME EQ RFL.RDB$FIELD_SOURCE_SCHEMA_NAME AND
96429643
FLD.RDB$FIELD_NAME EQ RFL.RDB$FIELD_SOURCE
96439644
{
9644-
bool wasInternalDomain = fb_utils::implicit_domain(FLD.RDB$FIELD_NAME);
9645+
const bool wasInternalDomain = fb_utils::implicit_domain(FLD.RDB$FIELD_NAME);
96459646
fb_assert(wasInternalDomain);
96469647

96479648
if (wasInternalDomain)
@@ -9704,7 +9705,7 @@ void CreateAlterViewNode::execute(thread_db* tdbb, DsqlCompilerScratch* dsqlScra
97049705
FLD.RDB$SCHEMA_NAME EQ RFL.RDB$FIELD_SOURCE_SCHEMA_NAME AND
97059706
FLD.RDB$FIELD_NAME EQ RFL.RDB$FIELD_SOURCE
97069707
{
9707-
bool wasInternalDomain = fb_utils::implicit_domain(FLD.RDB$FIELD_NAME);
9708+
const bool wasInternalDomain = fb_utils::implicit_domain(FLD.RDB$FIELD_NAME);
97089709
fb_assert(wasInternalDomain);
97099710

97109711
if (wasInternalDomain)
@@ -9920,7 +9921,6 @@ void CreateAlterViewNode::createCheckTrigger(thread_db* tdbb, DsqlCompilerScratc
99209921
const NestConst<ValueExprNode>* const end = fieldsNode->items.end();
99219922
NestConst<ValueExprNode>* ptr2 = valuesNode->items.begin();
99229923
const NestConst<ValueExprNode>* const end2 = valuesNode->items.end();
9923-
int andArg = 0;
99249924

99259925
BinaryBoolNode* andNode = FB_NEW_POOL(pool) BinaryBoolNode(pool, blr_and);
99269926

@@ -11447,13 +11447,11 @@ void MappingNode::execute(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch, jrd
1144711447

1144811448
fb_assert(op == MAP_DROP || op == MAP_COMMENT || fromType);
1144911449

11450-
short plugNull = plugin ? FALSE : TRUE;
11451-
short dbNull = db ? FALSE : TRUE;
11452-
short fromNull = from ? FALSE : TRUE;
11450+
const short plugNull = plugin ? FALSE : TRUE;
11451+
const short dbNull = db ? FALSE : TRUE;
11452+
const short fromNull = from ? FALSE : TRUE;
1145311453

11454-
char usingText[2];
11455-
usingText[0] = mode;
11456-
usingText[1] = '\0';
11454+
const char usingText[2]{ mode, '\0' };
1145711455

1145811456
AutoCacheRequest request1(tdbb, drq_map_mod, DYN_REQUESTS);
1145911457
bool found = false;
@@ -12086,7 +12084,7 @@ void GrantRevokeNode::modifyPrivileges(thread_db* tdbb, jrd_tra* transaction, SS
1208612084
grantRevoke(tdbb, transaction, object, user, "A", NULL, option);
1208712085
else if (i->second)
1208812086
{
12089-
char privs0[2] = {i->first, '\0'};
12087+
const char privs0[2] = {i->first, '\0'};
1209012088

1209112089
for (const auto& field : *i->second)
1209212090
grantRevoke(tdbb, transaction, object, user, privs0, field, option);
@@ -12282,7 +12280,7 @@ void GrantRevokeNode::grantRevoke(thread_db* tdbb, jrd_tra* transaction, const G
1228212280
}
1228312281

1228412282
crdb = true;
12285-
size_t len = strlen(cPtr);
12283+
const size_t len = strlen(cPtr);
1228612284
memmove(cPtr, cPtr + 1, len);
1228712285
}
1228812286

@@ -12353,7 +12351,7 @@ void GrantRevokeNode::grantRevoke(thread_db* tdbb, jrd_tra* transaction, const G
1235312351

1235412352
case obj_privilege: // Should convert symbolic privilege name to bit number
1235512353
{
12356-
USHORT p = convertPrivilegeFromString(tdbb, transaction, user.object);
12354+
const USHORT p = convertPrivilegeFromString(tdbb, transaction, user.object);
1235712355
user.object.printf("%d", p);
1235812356
}
1235912357
break;
@@ -12530,7 +12528,7 @@ void GrantRevokeNode::grantRevoke(thread_db* tdbb, jrd_tra* transaction, const G
1253012528

1253112529
if (crdb)
1253212530
{
12533-
CreateDbJob job(userType, user.object);
12531+
const CreateDbJob job(userType, user.object);
1253412532
createDbJobs.push(job);
1253512533

1253612534
if (!privileges[0])

src/dsql/DdlNodes.h

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -747,15 +747,15 @@ class CreateAlterTriggerNode final : public DdlNode, public TriggerDefinition
747747
void executeCreate(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch, jrd_tra* transaction);
748748
void compile(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch);
749749

750-
static inline bool hasOldContext(const unsigned value)
750+
static inline bool hasOldContext(const unsigned value) noexcept
751751
{
752752
const unsigned val1 = ((value + 1) >> 1) & 3;
753753
const unsigned val2 = ((value + 1) >> 3) & 3;
754754
const unsigned val3 = ((value + 1) >> 5) & 3;
755755
return (val1 && val1 != 1) || (val2 && val2 != 1) || (val3 && val3 != 1);
756756
}
757757

758-
static inline bool hasNewContext(const unsigned value)
758+
static inline bool hasNewContext(const unsigned value) noexcept
759759
{
760760
const unsigned val1 = ((value + 1) >> 1) & 3;
761761
const unsigned val2 = ((value + 1) >> 3) & 3;
@@ -983,7 +983,7 @@ class AlterDomainNode final : public DdlNode
983983

984984
public:
985985
static void checkUpdate(const dyn_fld& origFld, const dyn_fld& newFld);
986-
static ULONG checkUpdateNumericType(const dyn_fld& origFld, const dyn_fld& newFld);
986+
static ULONG checkUpdateNumericType(const dyn_fld& origFld, const dyn_fld& newFld) noexcept;
987987
static void getDomainType(thread_db* tdbb, jrd_tra* transaction, dyn_fld& dynFld);
988988
static void modifyLocalFieldIndex(thread_db* tdbb, jrd_tra* transaction,
989989
const QualifiedName& relationName, const MetaName& fieldName,
@@ -1411,7 +1411,7 @@ class RelationNode : public DdlNode
14111411
TYPE_ALTER_PUBLICATION
14121412
};
14131413

1414-
explicit Clause(MemoryPool& p, Type aType)
1414+
explicit Clause(MemoryPool& p, Type aType) noexcept
14151415
: type(aType)
14161416
{
14171417
}
@@ -1421,12 +1421,12 @@ class RelationNode : public DdlNode
14211421

14221422
struct RefActionClause
14231423
{
1424-
static const unsigned ACTION_CASCADE = 1;
1425-
static const unsigned ACTION_SET_DEFAULT = 2;
1426-
static const unsigned ACTION_SET_NULL = 3;
1427-
static const unsigned ACTION_NONE = 4;
1424+
static constexpr unsigned ACTION_CASCADE = 1;
1425+
static constexpr unsigned ACTION_SET_DEFAULT = 2;
1426+
static constexpr unsigned ACTION_SET_NULL = 3;
1427+
static constexpr unsigned ACTION_NONE = 4;
14281428

1429-
RefActionClause(MemoryPool& p, unsigned aUpdateAction, unsigned aDeleteAction)
1429+
RefActionClause(MemoryPool& p, unsigned aUpdateAction, unsigned aDeleteAction) noexcept
14301430
: updateAction(aUpdateAction),
14311431
deleteAction(aDeleteAction)
14321432
{
@@ -1473,13 +1473,13 @@ class RelationNode : public DdlNode
14731473

14741474
struct IdentityOptions
14751475
{
1476-
IdentityOptions(MemoryPool&, IdentityType aType)
1476+
IdentityOptions(MemoryPool&, IdentityType aType) noexcept
14771477
: type(aType),
14781478
restart(false)
14791479
{
14801480
}
14811481

1482-
IdentityOptions(MemoryPool&)
1482+
IdentityOptions(MemoryPool&) noexcept
14831483
: restart(false)
14841484
{
14851485
}
@@ -1696,8 +1696,8 @@ class CreateRelationNode final : public RelationNode
16961696
public:
16971697
const Firebird::string* externalFile;
16981698
std::optional<rel_t> relationType = rel_persistent;
1699-
bool preserveRowsOpt;
1700-
bool deleteRowsOpt;
1699+
bool preserveRowsOpt = false;
1700+
bool deleteRowsOpt = false;
17011701
bool createIfNotExistsOnly = false;
17021702
};
17031703

@@ -2580,7 +2580,7 @@ class GrantRevokeNode final : public PrivilegesNode, private ExecInSecurityDb
25802580
const QualifiedName& relation, const MetaName& field);
25812581

25822582
// Diagnostics print helper.
2583-
static const char* privilegeName(char symbol)
2583+
static constexpr const char* privilegeName(char symbol) noexcept
25842584
{
25852585
switch (UPPER7(symbol))
25862586
{
@@ -2597,9 +2597,8 @@ class GrantRevokeNode final : public PrivilegesNode, private ExecInSecurityDb
25972597
case 'C': return "CREATE";
25982598
case 'L': return "ALTER";
25992599
case 'O': return "DROP";
2600+
default: return "<Unknown>";
26002601
}
2601-
2602-
return "<Unknown>";
26032602
}
26042603

26052604
struct CreateDbJob
@@ -2632,16 +2631,16 @@ class GrantRevokeNode final : public PrivilegesNode, private ExecInSecurityDb
26322631
class AlterDatabaseNode final : public DdlNode
26332632
{
26342633
public:
2635-
static const unsigned CLAUSE_BEGIN_BACKUP = 0x01;
2636-
static const unsigned CLAUSE_END_BACKUP = 0x02;
2637-
static const unsigned CLAUSE_DROP_DIFFERENCE = 0x04;
2638-
static const unsigned CLAUSE_CRYPT = 0x08;
2639-
static const unsigned CLAUSE_ENABLE_PUB = 0x10;
2640-
static const unsigned CLAUSE_DISABLE_PUB = 0x20;
2641-
static const unsigned CLAUSE_PUB_INCL_TABLE = 0x40;
2642-
static const unsigned CLAUSE_PUB_EXCL_TABLE = 0x80;
2634+
static constexpr unsigned CLAUSE_BEGIN_BACKUP = 0x01;
2635+
static constexpr unsigned CLAUSE_END_BACKUP = 0x02;
2636+
static constexpr unsigned CLAUSE_DROP_DIFFERENCE = 0x04;
2637+
static constexpr unsigned CLAUSE_CRYPT = 0x08;
2638+
static constexpr unsigned CLAUSE_ENABLE_PUB = 0x10;
2639+
static constexpr unsigned CLAUSE_DISABLE_PUB = 0x20;
2640+
static constexpr unsigned CLAUSE_PUB_INCL_TABLE = 0x40;
2641+
static constexpr unsigned CLAUSE_PUB_EXCL_TABLE = 0x80;
26432642

2644-
static const unsigned RDB_DATABASE_MASK =
2643+
static constexpr unsigned RDB_DATABASE_MASK =
26452644
CLAUSE_BEGIN_BACKUP | CLAUSE_END_BACKUP | CLAUSE_DROP_DIFFERENCE;
26462645

26472646
public:

0 commit comments

Comments
 (0)