Skip to content

Commit 2544bf7

Browse files
authored
Merge branch 'master' into surw
2 parents a46fb15 + 7af9a21 commit 2544bf7

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Src/PCompiler/CompilerCore/Backend/Java/MachineGenerator.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ private void WriteMonitorDecl()
117117
{
118118
WriteFunction(f);
119119
}
120+
121+
WriteToString();
122+
120123
WriteLine();
121124

122125
WriteLine($"}} // {cname} monitor definition");
@@ -964,5 +967,21 @@ private void WriteStructureAccess(IPExpr e)
964967
}
965968
}
966969

970+
private void WriteToString()
971+
{
972+
WriteLine("public String toString() {");
973+
WriteLine($"StringBuilder sb = new StringBuilder(\"{_currentMachine.Name}\");");
974+
975+
WriteLine("sb.append(\"[\");");
976+
foreach (var (sep, field) in _currentMachine.Fields.WithPrefixSep(", "))
977+
{
978+
WriteLine($"sb.append(\"{sep}{field.Name}=\" + {Names.GetNameForDecl(field)});");
979+
}
980+
WriteLine("sb.append(\"]\");");
981+
982+
WriteLine("return sb.toString();");
983+
WriteLine("} // toString()");
984+
}
985+
967986
}
968987
}

0 commit comments

Comments
 (0)