@@ -8913,32 +8913,12 @@ bool GenCCpp::isUTF8GetString(const FuCallExpr * call)
8913
8913
return call->method->symbol->id == FuId::uTF8GetString;
8914
8914
}
8915
8915
8916
- const FuExpr * GenCCpp::getStringSubstringPtr(const FuCallExpr * call)
8917
- {
8918
- return isUTF8GetString(call) ? call->arguments[0].get() : call->method->left.get();
8919
- }
8920
-
8921
- const FuExpr * GenCCpp::getStringSubstringOffset(const FuCallExpr * call)
8922
- {
8923
- return call->arguments[isUTF8GetString(call) ? 1 : 0].get();
8924
- }
8925
-
8926
- const FuExpr * GenCCpp::getStringSubstringLength(const FuCallExpr * call)
8927
- {
8928
- return call->arguments[isUTF8GetString(call) ? 2 : 1].get();
8929
- }
8930
-
8931
- void GenCCpp::writeStringPtrAdd(const FuCallExpr * call)
8932
- {
8933
- writeArrayPtrAdd(getStringSubstringPtr(call), getStringSubstringOffset(call));
8934
- }
8935
-
8936
8916
const FuExpr * GenCCpp::isTrimSubstring(const FuBinaryExpr * expr)
8937
8917
{
8938
8918
const FuCallExpr * call = isStringSubstring(expr->right.get());
8939
8919
const FuSymbolReference * leftSymbol;
8940
- if (call != nullptr && !isUTF8GetString(call) && (leftSymbol = dynamic_cast<const FuSymbolReference *>(expr->left.get())) && getStringSubstringPtr( call)-> isReferenceTo(leftSymbol->symbol) && getStringSubstringOffset( call) ->isLiteralZero())
8941
- return getStringSubstringLength( call);
8920
+ if (call != nullptr && !isUTF8GetString(call) && (leftSymbol = dynamic_cast<const FuSymbolReference *>(expr->left.get())) && call->method->left-> isReferenceTo(leftSymbol->symbol) && call->arguments[0] ->isLiteralZero())
8921
+ return call->arguments[1].get( );
8942
8922
return nullptr;
8943
8923
}
8944
8924
@@ -9139,11 +9119,15 @@ void GenC::writeInterpolatedStringArgBase(const FuExpr * expr)
9139
9119
writeTemporaryOrExpr(expr, FuPriority::argument);
9140
9120
}
9141
9121
9142
- void GenC::writeStringPtrAddCast (const FuCallExpr * call )
9122
+ void GenC::writeStringPtrAdd (const FuExpr * obj, bool utf8GetString, const std::vector<std::shared_ptr<FuExpr>> * args, bool cast )
9143
9123
{
9144
- if (isUTF8GetString(call))
9145
- write("(const char *) ");
9146
- writeStringPtrAdd(call);
9124
+ if (utf8GetString) {
9125
+ if (cast)
9126
+ write("(const char *) ");
9127
+ writeArrayPtrAdd((*args)[0].get(), (*args)[1].get());
9128
+ }
9129
+ else
9130
+ writeArrayPtrAdd(obj, (*args)[0].get());
9147
9131
}
9148
9132
9149
9133
bool GenC::isDictionaryClassStgIndexing(const FuExpr * expr)
@@ -9197,7 +9181,7 @@ void GenC::writeInterpolatedStringArg(const FuExpr * expr)
9197
9181
if (call != nullptr) {
9198
9182
getStringSubstringLength(call)->accept(this, FuPriority::argument);
9199
9183
write(", ");
9200
- writeStringPtrAddCast (call);
9184
+ writeStringPtrAdd (call->method->left.get(), isUTF8GetString(call), &call->arguments, true );
9201
9185
}
9202
9186
else {
9203
9187
const FuClassType * klass;
@@ -9732,14 +9716,19 @@ void GenC::writeNewArray(const FuType * elementType, const FuExpr * lengthExpr,
9732
9716
writeChar(')');
9733
9717
}
9734
9718
9719
+ const FuExpr * GenC::getStringSubstringLength(const FuCallExpr * call)
9720
+ {
9721
+ return call->arguments[isUTF8GetString(call) ? 2 : 1].get();
9722
+ }
9723
+
9735
9724
void GenC::writeStringStorageValue(const FuExpr * expr)
9736
9725
{
9737
9726
const FuCallExpr * call = isStringSubstring(expr);
9738
9727
if (call != nullptr) {
9739
9728
include("string.h");
9740
9729
this->stringSubstring = true;
9741
9730
write("FuString_Substring(");
9742
- writeStringPtrAddCast (call);
9731
+ writeStringPtrAdd (call->method->left.get(), isUTF8GetString(call), &call->arguments, true );
9743
9732
write(", ");
9744
9733
getStringSubstringLength(call)->accept(this, FuPriority::argument);
9745
9734
writeChar(')');
@@ -10512,7 +10501,7 @@ void GenC::writeSubstringEqual(const FuCallExpr * call, std::string_view literal
10512
10501
writeChar('(');
10513
10502
include("string.h");
10514
10503
write("memcmp(");
10515
- writeStringPtrAdd(call);
10504
+ writeStringPtrAdd(call->method->left.get(), isUTF8GetString(call), &call->arguments, false );
10516
10505
write(", ");
10517
10506
visitLiteralString(literal);
10518
10507
write(", ");
@@ -12856,12 +12845,13 @@ void GenCl::writeSubstringEqual(const FuCallExpr * call, std::string_view litera
12856
12845
if (isUTF8GetString(call)) {
12857
12846
this->bytesEqualsString = true;
12858
12847
write("FuBytes_Equals(");
12848
+ writeArrayPtrAdd(call->arguments[0].get(), call->arguments[1].get());
12859
12849
}
12860
12850
else {
12861
12851
this->stringStartsWith = true;
12862
12852
write("FuString_StartsWith(");
12853
+ writeArrayPtrAdd(call->method->left.get(), call->arguments[0].get());
12863
12854
}
12864
- writeStringPtrAdd(call);
12865
12855
write(", ");
12866
12856
visitLiteralString(literal);
12867
12857
writeChar(')');
@@ -14544,16 +14534,19 @@ void GenCpp::writeStronglyCoerced(const FuType * type, const FuExpr * expr)
14544
14534
}
14545
14535
else {
14546
14536
const FuCallExpr * call = isStringSubstring(expr);
14547
- if (call != nullptr && type->id == FuId::stringStorageType && getStringSubstringPtr( call)->type->id != FuId::stringStorageType) {
14537
+ if (call != nullptr && type->id == FuId::stringStorageType && (isUTF8GetString( call) ? call->arguments[0] : call->method->left )->type->id != FuId::stringStorageType) {
14548
14538
write("std::string(");
14549
- bool cast = isUTF8GetString(call);
14550
- if (cast)
14539
+ if (isUTF8GetString(call)) {
14551
14540
write("reinterpret_cast<const char *>(");
14552
- writeStringPtrAdd(call);
14553
- if (cast)
14554
- writeChar(')');
14555
- write(", ");
14556
- getStringSubstringLength(call)->accept(this, FuPriority::argument);
14541
+ writeArrayPtrAdd(call->arguments[0].get(), call->arguments[1].get());
14542
+ write("), ");
14543
+ call->arguments[2]->accept(this, FuPriority::argument);
14544
+ }
14545
+ else {
14546
+ writeArrayPtrAdd(call->method->left.get(), call->arguments[0].get());
14547
+ write(", ");
14548
+ call->arguments[1]->accept(this, FuPriority::argument);
14549
+ }
14557
14550
writeChar(')');
14558
14551
}
14559
14552
else
0 commit comments