Skip to content

Commit

Permalink
Method rename, hopefully fixing Java testing flakiness
Browse files Browse the repository at this point in the history
  • Loading branch information
robin-aws committed Oct 27, 2022
1 parent 057bf25 commit 7e3d243
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Source/DafnyCore/Compilers/Compiler-go.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2097,7 +2097,7 @@ protected void TrCharLiteral(CharLiteralExpr chr, ConcreteSyntaxTree wr) {
var v = (string)chr.Value;
wr.Write("_dafny.Char(");
// See comment in TrStringLiteral for why we can't just translate directly sometimes.
if (Util.Escapes(v, false).Any(e => e.StartsWith(@"\u"))) {
if (Util.TokensWithEscapes(v, false).Any(e => e.StartsWith(@"\u"))) {
var c = Util.UnescapedCharacters(v, false).Single();
wr.Write($"{(int)c}");
} else {
Expand All @@ -2116,7 +2116,7 @@ protected override void TrStringLiteral(StringLiteralExpr str, ConcreteSyntaxTre
// _dafny.SeqOfString("..."), since there's no way to encode the right data in the Go string literal.
// Instead, if any escapes are present, just emit a sequence of the direct UTF-16 code units instead.
var s = (string)str.Value;
if (!str.IsVerbatim && Util.Escapes(s, false).Any(e => e.StartsWith(@"\u"))) {
if (!str.IsVerbatim && Util.TokensWithEscapes(s, false).Any(e => e.StartsWith(@"\u"))) {
wr.Write("_dafny.SeqOfChars(");
var comma = "";
foreach (var c in Util.UnescapedCharacters(s, str.IsVerbatim)) {
Expand Down
2 changes: 1 addition & 1 deletion Source/DafnyCore/Compilers/Compiler-java.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2094,7 +2094,7 @@ private string FieldName(Formal formal, int i) {

protected override void EmitPrintStmt(ConcreteSyntaxTree wr, Expression arg) {
var wStmts = wr.Fork();
wr.Write("System.out.print(");
wr.Write($"{DafnyHelpersClass}.utf8Out.print(");
EmitToString(wr, arg, wStmts);
wr.WriteLine(");");
}
Expand Down
6 changes: 3 additions & 3 deletions Source/DafnyCore/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public static string RemoveEscaping(string s, bool isVerbatimString) {
/// </summary>
public static IEnumerable<char> UnescapedCharacters(string p, bool isVerbatimString) {
if (isVerbatimString) {
foreach (var s in Escapes(p, true)) {
foreach (var s in TokensWithEscapes(p, true)) {
if (s == "\"\"") {
yield return '"';
} else {
Expand All @@ -213,7 +213,7 @@ public static IEnumerable<char> UnescapedCharacters(string p, bool isVerbatimStr
}
}
} else {
foreach (var s in Escapes(p, false)) {
foreach (var s in TokensWithEscapes(p, false)) {
switch (s) {
case @"\'": yield return '\''; break;
case @"\""": yield return '"'; break;
Expand All @@ -240,7 +240,7 @@ public static IEnumerable<char> UnescapedCharacters(string p, bool isVerbatimStr
/// For example, "ab\tuv\u12345" may be broken up as ["a", "b", "\t", "u", "v", "\u1234", "5"].
/// Consecutive non-escaped characters may or may not be enumerated as a single string.
/// </summary>
public static IEnumerable<string> Escapes(string p, bool isVerbatimString) {
public static IEnumerable<string> TokensWithEscapes(string p, bool isVerbatimString) {
Contract.Requires(p != null);
if (isVerbatimString) {
var skipNext = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,20 @@
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;

public class Helpers {

public static PrintStream utf8Out;
static {
try {
utf8Out = new PrintStream(System.out, true, "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}

public static DafnySequence<? extends DafnySequence<? extends Character>> FromMainArguments(String[] args) {
@SuppressWarnings("unchecked")
TypeDescriptor<DafnySequence<? extends Character>> type = DafnySequence.<Character>_typeDescriptor(TypeDescriptor.CHAR);
Expand Down

0 comments on commit 7e3d243

Please sign in to comment.