Skip to content

Commit b216489

Browse files
committed
Enhancement: TypeStore rendering of expressions.
TypeStore.Write was writing raw strings to the text output. If these strings contained '\n', the output would vary depending on whether LF -> CRLF translation was on or off. Also, control characters were impossible to see in the output.
1 parent fab753d commit b216489

76 files changed

Lines changed: 4309 additions & 4358 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/Core/Types/Field.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
*/
1919
#endregion
2020

21-
22-
using Reko.Core.Types;
21+
namespace Reko.Core.Types;
2322

2423
/// <summary>
2524
/// Represents a field in a structure or class.

src/Core/Types/TypeStore.cs

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ public IList<EquivalenceClass> UsedEquivalenceClasses
333333
public void Write(bool showExprAddresses, TextWriter w)
334334
{
335335
var writer = new TextFormatter(w);
336+
var codeFormatter = new CodeFormatter(writer);
336337
writer.WriteLine("// Equivalence classes ////////////");
337338
foreach (TypeVariable tv in TypeVariables)
338339
{
@@ -342,7 +343,7 @@ public void Write(bool showExprAddresses, TextWriter w)
342343
foreach (TypeVariable tvMember in tv.Class.ClassMembers)
343344
{
344345
writer.Write("\t{0}", tvMember);
345-
WriteExpressionOf(tvMember, showExprAddresses, writer);
346+
WriteExpressionOf(tvMember, showExprAddresses, codeFormatter);
346347
writer.WriteLine();
347348
}
348349
}
@@ -351,7 +352,7 @@ public void Write(bool showExprAddresses, TextWriter w)
351352
writer.WriteLine("// Type Variables ////////////");
352353
foreach (TypeVariable tv in TypeVariables)
353354
{
354-
WriteEntry(tv, showExprAddresses, writer);
355+
WriteEntry(tv, showExprAddresses, codeFormatter);
355356
}
356357
}
357358

@@ -360,41 +361,44 @@ public void Write(bool showExprAddresses, TextWriter w)
360361
/// </summary>
361362
/// <param name="tv">Type varaible</param>
362363
/// <param name="showExprAddresses">If trie show the address of the expression.</param>
363-
/// <param name="writer">Output sink.</param>
364-
public void WriteExpressionOf(TypeVariable tv, bool showExprAddresses, Formatter writer)
364+
/// <param name="codeFormatter">Output sink.</param>
365+
public void WriteExpressionOf(TypeVariable tv, bool showExprAddresses, CodeFormatter codeFormatter)
365366
{
367+
var formatter = codeFormatter.InnerFormatter;
366368
if (tvSources.TryGetValue(tv, out (Address? addr, Expression e) dbg) &&
367369
dbg.e is { })
368370
{
369-
writer.Write(" (in {0}", dbg.e);
371+
formatter.Write(" (in ");
372+
dbg.e.Accept(codeFormatter);
370373
if (showExprAddresses && dbg.addr is { })
371374
{
372-
writer.Write(" @ {0}", dbg.addr);
375+
formatter.Write(" @ {0}", dbg.addr);
373376
}
374377
if (dbg.e.DataType is { })
375378
{
376-
writer.Write(" : ");
377-
writer.Write(dbg.e.DataType);
379+
formatter.Write(" : ");
380+
formatter.Write(dbg.e.DataType);
378381
}
379-
writer.Write(")");
382+
formatter.Write(")");
380383
}
381384
}
382385

383-
private void WriteEntry(TypeVariable tv, bool showExprAddresses, Formatter writer)
386+
private void WriteEntry(TypeVariable tv, bool showExprAddresses, CodeFormatter codeFormatter)
384387
{
385-
writer.Write(tv.Name);
386-
writer.Write(":");
387-
WriteExpressionOf(tv, showExprAddresses, writer);
388-
writer.WriteLine();
388+
var formatter = codeFormatter.InnerFormatter;
389+
formatter.Write(tv.Name);
390+
formatter.Write(":");
391+
WriteExpressionOf(tv, showExprAddresses, codeFormatter);
392+
formatter.WriteLine();
389393

390-
writer.Write(" Class: ");
391-
writer.WriteLine(tv.Class.Name);
394+
formatter.Write(" Class: ");
395+
formatter.WriteLine(tv.Class.Name);
392396

393-
writer.Write(" DataType: ");
394-
writer.WriteLine(tv.DataType);
397+
formatter.Write(" DataType: ");
398+
formatter.WriteLine(tv.DataType);
395399

396-
writer.Write(" OrigDataType: ");
397-
writer.WriteLine(tv.OriginalDataType);
400+
formatter.Write(" OrigDataType: ");
401+
formatter.WriteLine(tv.OriginalDataType);
398402
}
399403

400404
/// <inheritdoc/>

src/Reko-decompiler.slnx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@
695695
<Build Solution="Debug|ARM64" Project="false" />
696696
<Build Solution="Release|ARM64" Project="false" />
697697
</Project>
698-
<Project Path="Installers/WixInstaller/WixInstaller.wixproj">
698+
<Project Path="Installers/WixInstaller/WixInstaller.wixproj" Id="b1916638-ef20-4692-8c95-1c5ad6c67d30">
699699
<BuildDependency Project="ImageLoaders/Llvm/LLVM.csproj" />
700700
<BuildType Solution="UnixDebug|Any CPU" Project="Release" />
701701
<BuildType Solution="UnixDebug|ARM64" Project="Debug" />

src/UnitTests/Decompiler/Typing/TraitMapping.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ private List<Trait> GetTypeTraits(TypeVariable t)
7575

7676
public void Write(TextWriter tw)
7777
{
78-
var formatter = new TextFormatter(tw);
78+
var formatter = new CodeFormatter(new TextFormatter(tw));
7979
foreach (KeyValuePair<TypeVariable,List<Trait>> de in items)
8080
{
8181
tw.Write(de.Key);
82-
store.WriteExpressionOf(de.Key, false, writer: formatter);
82+
store.WriteExpressionOf(de.Key, false, codeFormatter: formatter);
8383
tw.WriteLine();
8484
foreach (Trait tr in de.Value)
8585
{

src/tests/Typing/ExaUsrGlobals_Addr32.exp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ globals_t: (in globals : ptr32)
44
Class: Eq_1
55
DataType:
66
OrigDataType:
7-
T_2: (in 10001200 : ptr32)
7+
T_2: (in 0x10001200<p32> : ptr32)
88
Class: Eq_2
99
DataType: (ptr32 real32)
1010
OrigDataType: (ptr32 real32)

src/tests/Typing/TerAddress.exp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ globals_t: (in globals : (ptr32 (struct "Globals")))
3030
Class: Eq_1
3131
DataType: (ptr32 Eq_1)
3232
OrigDataType: (ptr32 (struct "Globals"))
33-
T_2: (in 00001020 : ptr32)
33+
T_2: (in 0x00001020<p32> : ptr32)
3434
Class: Eq_2
3535
DataType: (ptr32 real64)
3636
OrigDataType: (ptr32 (struct (0 T_3 t0000)))
@@ -42,7 +42,7 @@ T_4: (in CONVERT(Mem0[0x00001020<p32>:real64], real64, real32) : real32)
4242
Class: Eq_4
4343
DataType: real32
4444
OrigDataType: real32
45-
T_5: (in 00002028 : ptr32)
45+
T_5: (in 0x00002028<p32> : ptr32)
4646
Class: Eq_5
4747
DataType: (ptr32 real32)
4848
OrigDataType: (ptr32 (struct (0 T_6 t0000)))

subjects/Archives/ArTar/hello.reko/hello_O1.h

Lines changed: 18 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)