File tree Expand file tree Collapse file tree 7 files changed +87
-10
lines changed Expand file tree Collapse file tree 7 files changed +87
-10
lines changed Original file line number Diff line number Diff line change @@ -1650,10 +1650,15 @@ public abstract class GenBase : FuVisitor
1650
1650
WriteChar(')');
1651
1651
}
1652
1652
1653
- void WriteIf!(FuIf statement )
1653
+ protected virtual void StartIf!(FuExpr expr )
1654
1654
{
1655
1655
Write("if (");
1656
- StartIfWhile(statement.Cond);
1656
+ StartIfWhile(expr);
1657
+ }
1658
+
1659
+ void WriteIf!(FuIf statement)
1660
+ {
1661
+ StartIf(statement.Cond);
1657
1662
WriteChild(statement.OnTrue);
1658
1663
if (statement.OnFalse != null) {
1659
1664
Write("else");
Original file line number Diff line number Diff line change @@ -2881,6 +2881,20 @@ public class GenC : GenCCpp
2881
2881
NotSupported(statement.Collection, statement.Collection.Type.ToString());
2882
2882
}
2883
2883
2884
+ protected override void StartIf!(FuExpr expr)
2885
+ {
2886
+ WriteCTemporaries(expr);
2887
+ if (this.CurrentTemporaries.Any(temp => !(temp is FuType))) {
2888
+ Write("bool fucondition = "); // FIXME: already in scope
2889
+ expr.Accept(this, FuPriority.Argument);
2890
+ WriteCharLine(';');
2891
+ CleanupTemporaries();
2892
+ Write("if (fucondition)");
2893
+ }
2894
+ else
2895
+ base.StartIf(expr);
2896
+ }
2897
+
2884
2898
internal override void VisitLock!(FuLock statement)
2885
2899
{
2886
2900
Write("mtx_lock(&");
Original file line number Diff line number Diff line change @@ -8026,10 +8026,15 @@ void GenBase::startIfWhile(const FuExpr * expr)
8026
8026
writeChar(')');
8027
8027
}
8028
8028
8029
- void GenBase::writeIf (const FuIf * statement )
8029
+ void GenBase::startIf (const FuExpr * expr )
8030
8030
{
8031
8031
write("if (");
8032
- startIfWhile(statement->cond.get());
8032
+ startIfWhile(expr);
8033
+ }
8034
+
8035
+ void GenBase::writeIf(const FuIf * statement)
8036
+ {
8037
+ startIf(statement->cond.get());
8033
8038
writeChild(statement->onTrue.get());
8034
8039
if (statement->onFalse != nullptr) {
8035
8040
write("else");
@@ -11797,6 +11802,20 @@ void GenC::visitForeach(const FuForeach * statement)
11797
11802
notSupported(statement->collection.get(), statement->collection->type->toString());
11798
11803
}
11799
11804
11805
+ void GenC::startIf(const FuExpr * expr)
11806
+ {
11807
+ writeCTemporaries(expr);
11808
+ if (std::any_of(this->currentTemporaries.begin(), this->currentTemporaries.end(), [](const FuExpr * temp) { return !dynamic_cast<const FuType *>(temp); })) {
11809
+ write("bool fucondition = ");
11810
+ expr->accept(this, FuPriority::argument);
11811
+ writeCharLine(';');
11812
+ cleanupTemporaries();
11813
+ write("if (fucondition)");
11814
+ }
11815
+ else
11816
+ GenBase::startIf(expr);
11817
+ }
11818
+
11800
11819
void GenC::visitLock(const FuLock * statement)
11801
11820
{
11802
11821
write("mtx_lock(&");
Original file line number Diff line number Diff line change @@ -8215,10 +8215,15 @@ void StartIfWhile(FuExpr expr)
8215
8215
WriteChar(')');
8216
8216
}
8217
8217
8218
- void WriteIf(FuIf statement )
8218
+ protected virtual void StartIf(FuExpr expr )
8219
8219
{
8220
8220
Write("if (");
8221
- StartIfWhile(statement.Cond);
8221
+ StartIfWhile(expr);
8222
+ }
8223
+
8224
+ void WriteIf(FuIf statement)
8225
+ {
8226
+ StartIf(statement.Cond);
8222
8227
WriteChild(statement.OnTrue);
8223
8228
if (statement.OnFalse != null) {
8224
8229
Write("else");
@@ -12069,6 +12074,20 @@ internal override void VisitForeach(FuForeach statement)
12069
12074
NotSupported(statement.Collection, statement.Collection.Type.ToString());
12070
12075
}
12071
12076
12077
+ protected override void StartIf(FuExpr expr)
12078
+ {
12079
+ WriteCTemporaries(expr);
12080
+ if (this.CurrentTemporaries.Exists(temp => !(temp is FuType))) {
12081
+ Write("bool fucondition = ");
12082
+ expr.Accept(this, FuPriority.Argument);
12083
+ WriteCharLine(';');
12084
+ CleanupTemporaries();
12085
+ Write("if (fucondition)");
12086
+ }
12087
+ else
12088
+ base.StartIf(expr);
12089
+ }
12090
+
12072
12091
internal override void VisitLock(FuLock statement)
12073
12092
{
12074
12093
Write("mtx_lock(&");
Original file line number Diff line number Diff line change @@ -1857,6 +1857,7 @@ class GenBase : public FuVisitor
1857
1857
virtual void writeChild (FuStatement * statement);
1858
1858
virtual void startBreakGoto ();
1859
1859
virtual bool embedIfWhileIsVar (const FuExpr * expr, bool write);
1860
+ virtual void startIf (const FuExpr * expr);
1860
1861
void defineVar (const FuExpr * value);
1861
1862
virtual void writeSwitchCaseTypeVar (const FuExpr * value);
1862
1863
virtual void writeSwitchValue (const FuExpr * expr);
@@ -2080,6 +2081,7 @@ class GenC : public GenCCpp
2080
2081
void writeIndexingExpr (const FuBinaryExpr * expr, FuPriority parent) override ;
2081
2082
void writeResource (std::string_view name, int length) override ;
2082
2083
void cleanupBlock (const FuBlock * statement) override ;
2084
+ void startIf (const FuExpr * expr) override ;
2083
2085
void writeSwitchCaseBody (const std::vector<std::shared_ptr<FuStatement>> * statements) override ;
2084
2086
void writeStatements (const std::vector<std::shared_ptr<FuStatement>> * statements) override ;
2085
2087
void writeEnum (const FuEnum * enu) override ;
Original file line number Diff line number Diff line change @@ -8537,10 +8537,15 @@ export class GenBase extends FuVisitor
8537
8537
this.writeChar(41);
8538
8538
}
8539
8539
8540
- #writeIf(statement )
8540
+ startIf(expr )
8541
8541
{
8542
8542
this.write("if (");
8543
- this.#startIfWhile(statement.cond);
8543
+ this.#startIfWhile(expr);
8544
+ }
8545
+
8546
+ #writeIf(statement)
8547
+ {
8548
+ this.startIf(statement.cond);
8544
8549
this.writeChild(statement.onTrue);
8545
8550
if (statement.onFalse != null) {
8546
8551
this.write("else");
@@ -12465,6 +12470,20 @@ export class GenC extends GenCCpp
12465
12470
this.notSupported(statement.collection, statement.collection.type.toString());
12466
12471
}
12467
12472
12473
+ startIf(expr)
12474
+ {
12475
+ this.#writeCTemporaries(expr);
12476
+ if (this.currentTemporaries.some(temp => !(temp instanceof FuType))) {
12477
+ this.write("bool fucondition = ");
12478
+ expr.accept(this, FuPriority.ARGUMENT);
12479
+ this.writeCharLine(59);
12480
+ this.cleanupTemporaries();
12481
+ this.write("if (fucondition)");
12482
+ }
12483
+ else
12484
+ super.startIf(expr);
12485
+ }
12486
+
12468
12487
visitLock(statement)
12469
12488
{
12470
12489
this.write("mtx_lock(&");
Original file line number Diff line number Diff line change @@ -352,8 +352,7 @@ public static class Test
352
352
{
353
353
public static bool Run()
354
354
{
355
- JsonElement# json; //FAIL: c leak TODO; cl
356
- json = JsonElement.Parse("\"foo\"");
355
+ JsonElement# json = JsonElement.Parse("\"foo\""); //FAIL: cl
357
356
if (!json.IsString() || json.GetString() != "foo")
358
357
return false;
359
358
json = JsonElement.Parse("10.5");
You can’t perform that action at this time.
0 commit comments