Skip to content

Commit b41b128

Browse files
committed
Replace unneeded checks with asserts. Move the JRD-level validation from pass2() to parse().
1 parent 4330b1c commit b41b128

File tree

2 files changed

+100
-97
lines changed

2 files changed

+100
-97
lines changed

src/dsql/ExprNodes.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12321,6 +12321,8 @@ DmlNode* SysFuncCallNode::parse(thread_db* tdbb, MemoryPool& pool, CompilerScrat
1232112321

1232212322
node->args = PAR_args(tdbb, csb);
1232312323

12324+
node->function->checkArgsMismatch(node->args->items.getCount());
12325+
1232412326
if (name == "MAKE_DBKEY")
1232512327
{
1232612328
// Special handling for system function MAKE_DBKEY:
@@ -12447,8 +12449,6 @@ ValueExprNode* SysFuncCallNode::pass2(thread_db* tdbb, CompilerScratch* csb)
1244712449
{
1244812450
ValueExprNode::pass2(tdbb, csb);
1244912451

12450-
function->checkArgsMismatch(args->items.getCount());
12451-
1245212452
dsc desc;
1245312453
getDesc(tdbb, csb, &desc);
1245412454
impureOffset = csb->allocImpure<impure_value>();

src/jrd/SysFunction.cpp

Lines changed: 98 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -611,24 +611,27 @@ void setParamsInt64(DataTypeUtilBase*, const SysFunction*, int argsCount, dsc**
611611

612612
void setParamsSecondInteger(DataTypeUtilBase*, const SysFunction*, int argsCount, dsc** args)
613613
{
614-
if (argsCount >= 2)
615-
{
616-
if (args[1]->isUnknown())
617-
args[1]->makeLong(0);
618-
}
614+
fb_assert(argsCount >= 2);
615+
616+
if (args[1]->isUnknown())
617+
args[1]->makeLong(0);
619618
}
620619

621620

622621
void setParamsAsciiVal(DataTypeUtilBase*, const SysFunction*, int argsCount, dsc** args)
623622
{
624-
if (argsCount >= 1 && args[0]->isUnknown())
623+
fb_assert(argsCount >= 1);
624+
625+
if (args[0]->isUnknown())
625626
args[0]->makeText(1, CS_ASCII);
626627
}
627628

628629

629630
void setParamsBlobAppend(DataTypeUtilBase*, const SysFunction*, int argsCount, dsc** args)
630631
{
631-
if (argsCount >= 1 && args[0]->isUnknown())
632+
fb_assert(argsCount >= 1);
633+
634+
if (args[0]->isUnknown())
632635
args[0]->makeBlob(isc_blob_text, CS_dynamic);
633636

634637
for (int i = 1; i < argsCount; ++i)
@@ -641,14 +644,18 @@ void setParamsBlobAppend(DataTypeUtilBase*, const SysFunction*, int argsCount, d
641644

642645
void setParamsCharToUuid(DataTypeUtilBase*, const SysFunction*, int argsCount, dsc** args)
643646
{
644-
if (argsCount >= 1 && args[0]->isUnknown())
647+
fb_assert(argsCount >= 1);
648+
649+
if (args[0]->isUnknown())
645650
args[0]->makeText(Uuid::STR_LEN, ttype_ascii);
646651
}
647652

648653

649654
void setParamsDateAdd(DataTypeUtilBase*, const SysFunction*, int argsCount, dsc** args)
650655
{
651-
if (argsCount >= 1 && args[0]->isUnknown())
656+
fb_assert(argsCount >= 3);
657+
658+
if (args[0]->isUnknown())
652659
{
653660
if (args[1]->dsc_address && // constant
654661
CVT_get_long(args[1], 0, JRD_get_thread_data()->getAttachment()->att_dec_status, ERR_post) == blr_extract_millisecond)
@@ -659,31 +666,32 @@ void setParamsDateAdd(DataTypeUtilBase*, const SysFunction*, int argsCount, dsc*
659666
args[0]->makeInt64(0);
660667
}
661668

662-
if (argsCount >= 3 && args[2]->isUnknown())
669+
if (args[2]->isUnknown())
663670
args[2]->makeTimestamp();
664671
}
665672

666673

667674
void setParamsDateDiff(DataTypeUtilBase*, const SysFunction*, int argsCount, dsc** args)
668675
{
669-
if (argsCount >= 3)
676+
fb_assert(argsCount >= 3);
677+
678+
if (args[1]->isUnknown() && args[2]->isUnknown())
670679
{
671-
if (args[1]->isUnknown() && args[2]->isUnknown())
672-
{
673-
args[1]->makeTimestamp();
674-
args[2]->makeTimestamp();
675-
}
676-
else if (args[1]->isUnknown())
677-
*args[1] = *args[2];
678-
else if (args[2]->isUnknown())
679-
*args[2] = *args[1];
680+
args[1]->makeTimestamp();
681+
args[2]->makeTimestamp();
680682
}
683+
else if (args[1]->isUnknown())
684+
*args[1] = *args[2];
685+
else if (args[2]->isUnknown())
686+
*args[2] = *args[1];
681687
}
682688

683689

684690
void setParamsUnicodeVal(DataTypeUtilBase*, const SysFunction*, int argsCount, dsc** args)
685691
{
686-
if (argsCount >= 1 && args[0]->isUnknown())
692+
fb_assert(argsCount >= 1);
693+
694+
if (args[0]->isUnknown())
687695
args[0]->makeText(4, CS_UTF8);
688696
}
689697

@@ -819,23 +827,24 @@ void setParamsRsaPublic(DataTypeUtilBase*, const SysFunction*, int argsCount, ds
819827

820828
void setParamsFirstLastDay(DataTypeUtilBase*, const SysFunction*, int argsCount, dsc** args)
821829
{
822-
if (argsCount >= 2)
823-
{
824-
if (args[1]->isUnknown())
825-
args[1]->makeTimestamp();
826-
}
830+
fb_assert(argsCount >= 2);
831+
832+
if (args[1]->isUnknown())
833+
args[1]->makeTimestamp();
827834
}
828835

829836

830837
void setParamsGetSetContext(DataTypeUtilBase*, const SysFunction*, int argsCount, dsc** args)
831838
{
832-
if (argsCount >= 1 && args[0]->isUnknown())
839+
fb_assert(argsCount >= 2);
840+
841+
if (args[0]->isUnknown())
833842
{
834843
args[0]->makeVarying(80, ttype_none);
835844
args[0]->setNullable(true);
836845
}
837846

838-
if (argsCount >= 2 && args[1]->isUnknown())
847+
if (args[1]->isUnknown())
839848
{
840849
args[1]->makeVarying(80, ttype_none);
841850
args[1]->setNullable(true);
@@ -861,86 +870,84 @@ void setParamsMakeDbkey(DataTypeUtilBase*, const SysFunction*, int argsCount, ds
861870
{
862871
// MAKE_DBKEY ( REL_NAME | REL_ID, RECNUM [, DPNUM [, PPNUM] ] )
863872

864-
if (argsCount > 1)
865-
{
866-
if (args[0]->isUnknown())
867-
args[0]->makeLong(0);
873+
fb_assert(argsCount >= 2);
868874

869-
if (args[1]->isUnknown())
870-
args[1]->makeInt64(0);
871-
}
875+
if (args[0]->isUnknown())
876+
args[0]->makeLong(0);
872877

873-
if (argsCount > 2 && args[2]->isUnknown())
878+
if (args[1]->isUnknown())
879+
args[1]->makeInt64(0);
880+
881+
if (argsCount >= 3 && args[2]->isUnknown())
874882
args[2]->makeInt64(0);
875883

876-
if (argsCount > 3 && args[3]->isUnknown())
884+
if (argsCount >= 4 && args[3]->isUnknown())
877885
args[3]->makeInt64(0);
878886
}
879887

880888

881889
void setParamsOverlay(DataTypeUtilBase*, const SysFunction*, int argsCount, dsc** args)
882890
{
883-
if (argsCount >= 3)
891+
fb_assert(argsCount >= 3);
892+
893+
if (!(args[0]->isUnknown() && args[1]->isUnknown()))
884894
{
885-
if (!(args[0]->isUnknown() && args[1]->isUnknown()))
886-
{
887-
if (args[1]->isUnknown())
888-
*args[1] = *args[0];
889-
else if (args[0]->isUnknown())
890-
*args[0] = *args[1];
891-
}
895+
if (args[1]->isUnknown())
896+
*args[1] = *args[0];
897+
else if (args[0]->isUnknown())
898+
*args[0] = *args[1];
899+
}
892900

893-
if (argsCount >= 4)
901+
if (argsCount >= 4)
902+
{
903+
if (args[2]->isUnknown() && args[3]->isUnknown())
894904
{
895-
if (args[2]->isUnknown() && args[3]->isUnknown())
896-
{
897-
args[2]->makeLong(0);
898-
args[3]->makeLong(0);
899-
}
900-
else if (args[2]->isUnknown())
901-
*args[2] = *args[3];
902-
else if (args[3]->isUnknown())
903-
*args[3] = *args[2];
904-
}
905-
906-
if (args[2]->isUnknown())
907905
args[2]->makeLong(0);
906+
args[3]->makeLong(0);
907+
}
908+
else if (args[2]->isUnknown())
909+
*args[2] = *args[3];
910+
else if (args[3]->isUnknown())
911+
*args[3] = *args[2];
908912
}
913+
914+
if (args[2]->isUnknown())
915+
args[2]->makeLong(0);
909916
}
910917

911918

912919
void setParamsPosition(DataTypeUtilBase*, const SysFunction*, int argsCount, dsc** args)
913920
{
914-
if (argsCount >= 2)
915-
{
916-
if (args[0]->isUnknown())
917-
*args[0] = *args[1];
921+
fb_assert(argsCount >= 2);
918922

919-
if (args[1]->isUnknown())
920-
*args[1] = *args[0];
921-
}
923+
if (args[0]->isUnknown())
924+
*args[0] = *args[1];
925+
926+
if (args[1]->isUnknown())
927+
*args[1] = *args[0];
922928
}
923929

924930

925931
void setParamsRoundTrunc(DataTypeUtilBase*, const SysFunction*, int argsCount, dsc** args)
926932
{
927-
if (argsCount >= 1)
928-
{
929-
if (args[0]->isUnknown())
930-
args[0]->makeDouble();
933+
fb_assert(argsCount >= 1);
931934

932-
if (argsCount >= 2)
933-
{
934-
if (args[1]->isUnknown())
935-
args[1]->makeLong(0);
936-
}
935+
if (args[0]->isUnknown())
936+
args[0]->makeDouble();
937+
938+
if (argsCount >= 2)
939+
{
940+
if (args[1]->isUnknown())
941+
args[1]->makeLong(0);
937942
}
938943
}
939944

940945

941946
void setParamsUuidToChar(DataTypeUtilBase*, const SysFunction*, int argsCount, dsc** args)
942947
{
943-
if (argsCount >= 1 && args[0]->isUnknown())
948+
fb_assert(argsCount >= 1);
949+
950+
if (args[0]->isUnknown())
944951
args[0]->makeText(16, ttype_binary);
945952
}
946953

@@ -1304,23 +1311,20 @@ void makeBlobAppend(DataTypeUtilBase* dataTypeUtil, const SysFunction* function,
13041311
result->makeBlob(isc_blob_untyped, ttype_binary);
13051312
result->setNullable(true);
13061313

1307-
if (argsCount > 0)
1314+
for (int i = 0; i < argsCount; ++i)
13081315
{
1309-
for (int i = 0; i < argsCount; ++i)
1310-
{
1311-
if (makeBlobAppendBlob(result, args[i]))
1312-
break;
1313-
}
1316+
if (makeBlobAppendBlob(result, args[i]))
1317+
break;
1318+
}
13141319

1315-
result->setNullable(true);
1320+
result->setNullable(true);
13161321

1317-
for (int i = 0; i < argsCount; ++i)
1322+
for (int i = 0; i < argsCount; ++i)
1323+
{
1324+
if (!args[i]->isNullable())
13181325
{
1319-
if (!args[i]->isNullable())
1320-
{
1321-
result->setNullable(false);
1322-
break;
1323-
}
1326+
result->setNullable(false);
1327+
break;
13241328
}
13251329
}
13261330
}
@@ -1417,13 +1421,12 @@ void makeFirstLastDayResult(DataTypeUtilBase*, const SysFunction*, dsc* result,
14171421

14181422
result->makeDate();
14191423

1420-
if (argsCount >= 2)
1421-
{
1422-
if (args[1]->dsc_dtype == dtype_timestamp)
1423-
result->makeTimestamp();
1424-
else if (args[1]->dsc_dtype == dtype_timestamp_tz)
1425-
result->makeTimestampTz();
1426-
}
1424+
fb_assert(argsCount >= 2);
1425+
1426+
if (args[1]->dsc_dtype == dtype_timestamp)
1427+
result->makeTimestamp();
1428+
else if (args[1]->dsc_dtype == dtype_timestamp_tz)
1429+
result->makeTimestampTz();
14271430

14281431
result->setNullable(isNullable);
14291432
}

0 commit comments

Comments
 (0)