@@ -10019,31 +10019,9 @@ void GenC::writeArgTemporary(const FuMethod * method, const FuVar * param, const
10019
10019
writeOwningTemporary(arg);
10020
10020
}
10021
10021
10022
- bool GenC::hasTemporariesToDestruct(const FuExpr * expr)
10022
+ bool GenC::hasTemporariesToDestruct() const
10023
10023
{
10024
- return containsTemporariesToDestruct(expr) || expr->isNewString(false);
10025
- }
10026
-
10027
- bool GenC::containsTemporariesToDestruct(const FuExpr * expr)
10028
- {
10029
- if (const FuAggregateInitializer *init = dynamic_cast<const FuAggregateInitializer *>(expr))
10030
- return std::any_of(init->items.begin(), init->items.end(), [](const std::shared_ptr<FuExpr> &field) { return hasTemporariesToDestruct(field.get()); });
10031
- else if (dynamic_cast<const FuLiteral *>(expr) || dynamic_cast<const FuLambdaExpr *>(expr))
10032
- return false;
10033
- else if (const FuInterpolatedString *interp = dynamic_cast<const FuInterpolatedString *>(expr))
10034
- return std::any_of(interp->parts.begin(), interp->parts.end(), [](const FuInterpolatedPart &part) { return hasTemporariesToDestruct(part.argument.get()); });
10035
- else if (const FuSymbolReference *symbol = dynamic_cast<const FuSymbolReference *>(expr))
10036
- return symbol->left != nullptr && hasTemporariesToDestruct(symbol->left.get());
10037
- else if (const FuUnaryExpr *unary = dynamic_cast<const FuUnaryExpr *>(expr))
10038
- return unary->inner != nullptr && containsTemporariesToDestruct(unary->inner.get());
10039
- else if (const FuBinaryExpr *binary = dynamic_cast<const FuBinaryExpr *>(expr))
10040
- return hasTemporariesToDestruct(binary->left.get()) || (binary->op != FuToken::is && hasTemporariesToDestruct(binary->right.get()));
10041
- else if (const FuSelectExpr *select = dynamic_cast<const FuSelectExpr *>(expr))
10042
- return containsTemporariesToDestruct(select->cond.get());
10043
- else if (const FuCallExpr *call = dynamic_cast<const FuCallExpr *>(expr))
10044
- return (call->method->left != nullptr && hasTemporariesToDestruct(call->method->left.get())) || std::any_of(call->arguments.begin(), call->arguments.end(), [](const std::shared_ptr<FuExpr> &arg) { return hasTemporariesToDestruct(arg.get()); });
10045
- else
10046
- std::abort();
10024
+ return std::any_of(this->currentTemporaries.begin(), this->currentTemporaries.end(), [](const FuExpr * temp) { return !dynamic_cast<const FuType *>(temp); });
10047
10025
}
10048
10026
10049
10027
void GenC::cleanupTemporary(int i, const FuExpr * temp)
@@ -11779,7 +11757,7 @@ void GenC::visitForeach(const FuForeach * statement)
11779
11757
11780
11758
void GenC::startIf(const FuExpr * expr)
11781
11759
{
11782
- if (std::any_of(this->currentTemporaries.begin(), this->currentTemporaries.end(), [](const FuExpr * temp) { return !dynamic_cast<const FuType *>(temp); } )) {
11760
+ if (hasTemporariesToDestruct( )) {
11783
11761
if (!this->conditionVarInScope) {
11784
11762
this->conditionVarInScope = true;
11785
11763
write("bool ");
@@ -11807,44 +11785,44 @@ void GenC::visitLock(const FuLock * statement)
11807
11785
11808
11786
void GenC::visitReturn(const FuReturn * statement)
11809
11787
{
11810
- if (statement->value == nullptr) {
11788
+ if (statement->value == nullptr || dynamic_cast<const FuLiteral *>(statement->value.get()) ) {
11811
11789
writeDestructAll();
11812
- if (std::ssize(this->currentMethod->throws) > 0)
11790
+ if (statement->value == nullptr && std::ssize(this->currentMethod->throws) > 0)
11813
11791
writeLine("return true;");
11814
11792
else
11815
11793
GenCCpp::visitReturn(statement);
11816
11794
}
11817
11795
else {
11818
- const FuMethod * throwingMethod = dynamic_cast<const FuNumericType *>(this->currentMethod->type.get()) ? getThrowingMethod(statement->value.get()) : nullptr;
11819
- const FuRangeType * methodRange;
11820
- const FuRangeType * throwingRange;
11821
- if (throwingMethod != nullptr && ((methodRange = dynamic_cast<const FuRangeType *>(this->currentMethod->type.get())) ? (throwingRange = dynamic_cast<const FuRangeType *>(throwingMethod->type.get())) && methodRange->min == throwingRange->min : !!dynamic_cast<const FuFloatingType *>(throwingMethod->type.get())))
11822
- throwingMethod = nullptr;
11823
- if (dynamic_cast<const FuLiteral *>(statement->value.get()) || (throwingMethod == nullptr && std::ssize(this->varsToDestruct) == 0 && !containsTemporariesToDestruct(statement->value.get()))) {
11824
- writeDestructAll();
11825
- GenCCpp::visitReturn(statement);
11796
+ const FuSymbolReference * symbol;
11797
+ const FuVar * local;
11798
+ if ((symbol = dynamic_cast<const FuSymbolReference *>(statement->value.get())) && (local = dynamic_cast<const FuVar *>(symbol->symbol))) {
11799
+ if (std::find(this->varsToDestruct.begin(), this->varsToDestruct.end(), local) != this->varsToDestruct.end()) {
11800
+ writeDestructAll(local);
11801
+ write("return ");
11802
+ const FuClassType * resultPtr;
11803
+ if ((resultPtr = dynamic_cast<const FuClassType *>(this->currentMethod->type.get())) && !dynamic_cast<const FuStorageType *>(resultPtr))
11804
+ writeClassPtr(resultPtr->class_, symbol, FuPriority::argument);
11805
+ else
11806
+ symbol->accept(this, FuPriority::argument);
11807
+ writeCharLine(';');
11808
+ }
11809
+ else {
11810
+ writeDestructAll();
11811
+ GenCCpp::visitReturn(statement);
11812
+ }
11826
11813
}
11827
11814
else {
11828
- const FuSymbolReference * symbol;
11829
- const FuVar * local;
11830
- if ((symbol = dynamic_cast<const FuSymbolReference *>(statement->value.get())) && (local = dynamic_cast<const FuVar *>(symbol->symbol))) {
11831
- if (std::find(this->varsToDestruct.begin(), this->varsToDestruct.end(), local) != this->varsToDestruct.end()) {
11832
- writeDestructAll(local);
11833
- write("return ");
11834
- const FuClassType * resultPtr;
11835
- if ((resultPtr = dynamic_cast<const FuClassType *>(this->currentMethod->type.get())) && !dynamic_cast<const FuStorageType *>(resultPtr))
11836
- writeClassPtr(resultPtr->class_, symbol, FuPriority::argument);
11837
- else
11838
- symbol->accept(this, FuPriority::argument);
11839
- writeCharLine(';');
11840
- }
11841
- else {
11842
- writeDestructAll();
11843
- GenCCpp::visitReturn(statement);
11844
- }
11815
+ writeTemporaries(statement->value.get());
11816
+ const FuMethod * throwingMethod = dynamic_cast<const FuNumericType *>(this->currentMethod->type.get()) ? getThrowingMethod(statement->value.get()) : nullptr;
11817
+ const FuRangeType * methodRange;
11818
+ const FuRangeType * throwingRange;
11819
+ if (throwingMethod != nullptr && ((methodRange = dynamic_cast<const FuRangeType *>(this->currentMethod->type.get())) ? (throwingRange = dynamic_cast<const FuRangeType *>(throwingMethod->type.get())) && methodRange->min == throwingRange->min : !!dynamic_cast<const FuFloatingType *>(throwingMethod->type.get())))
11820
+ throwingMethod = nullptr;
11821
+ if (throwingMethod == nullptr && std::ssize(this->varsToDestruct) == 0 && !hasTemporariesToDestruct()) {
11822
+ writeDestructAll();
11823
+ GenCCpp::visitReturn(statement);
11845
11824
}
11846
11825
else {
11847
- writeTemporaries(statement->value.get());
11848
11826
ensureChildBlock();
11849
11827
startDefinition(this->currentMethod->type.get(), true, true);
11850
11828
write("returnValue = ");
0 commit comments