Skip to content

Commit dc69c45

Browse files
committed
Move PRINTIL, PRINTCS to the public static feature flags
1 parent c787a53 commit dc69c45

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

src/FastExpressionCompiler/TestTools.cs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
// Control
2-
#if DEBUG
3-
#define PRINTIL
4-
#define PRINTCS
5-
#define PRINTEXPR
6-
#endif
7-
8-
using System;
1+
using System;
92
using System.Linq;
103
using System.Text;
114
using System.Reflection;
@@ -32,6 +25,19 @@ namespace FastExpressionCompiler;
3225
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "This is used for the testing purposes only.")]
3326
public static class TestTools
3427
{
28+
public static bool AllowPrintIL = false;
29+
public static bool AllowPrintCS = false;
30+
public static bool AllowPrintExpression = false;
31+
32+
static TestTools()
33+
{
34+
#if DEBUG
35+
AllowPrintIL = true;
36+
AllowPrintCS = true;
37+
AllowPrintExpression = true;
38+
#endif
39+
}
40+
3541
public static void AssertOpCodes(this Delegate @delegate, params OpCode[] expectedCodes) =>
3642
AssertOpCodes(@delegate.Method, expectedCodes);
3743

@@ -63,20 +69,19 @@ public static void AssertOpCodes(this MethodInfo method, params OpCode[] expecte
6369

6470
public static void PrintExpression(this Expression expr, bool completeTypeNames = false)
6571
{
66-
#if PRINTEXPR
72+
if (!AllowPrintExpression) return;
6773
Console.WriteLine(
6874
expr.ToExpressionString(out var _, out var _, out var _,
6975
stripNamespace: true,
7076
printType: completeTypeNames ? null : CodePrinter.PrintTypeStripOuterClasses,
7177
indentSpaces: 4)
7278
);
73-
#endif
7479
}
7580

7681
public static void PrintCSharp(this Expression expr, bool completeTypeNames = false,
7782
[CallerMemberName] string caller = "", [CallerFilePath] string filePath = "")
7883
{
79-
#if PRINTCS
84+
if (!AllowPrintIL) return;
8085
Console.WriteLine();
8186
Console.WriteLine($"//{Path.GetFileNameWithoutExtension(filePath)}.{caller}");
8287

@@ -89,52 +94,47 @@ public static void PrintCSharp(this Expression expr, bool completeTypeNames = fa
8994
indentSpaces: 4);
9095
sb.Append(';');
9196
Console.WriteLine(sb.ToString());
92-
#endif
9397
}
9498

9599
public static void PrintCSharp(this Expression expr, Func<string, string> transform,
96100
[CallerMemberName] string caller = "", [CallerFilePath] string filePath = "")
97101
{
98-
#if PRINTCS
102+
if (!AllowPrintCS) return;
99103
Console.WriteLine();
100104
Console.WriteLine($"//{Path.GetFileNameWithoutExtension(filePath)}.{caller}");
101105
Console.WriteLine(transform(expr.ToCSharpString()));
102-
#endif
103106
}
104107

105108
public static void PrintCSharp(this Expression expr, CodePrinter.ObjectToCode objectToCode,
106109
[CallerMemberName] string caller = "", [CallerFilePath] string filePath = "")
107110
{
108-
#if PRINTCS
111+
if (!AllowPrintCS) return;
112+
109113
Console.WriteLine();
110114
Console.WriteLine($"//{Path.GetFileNameWithoutExtension(filePath)}.{caller}");
111115
Console.WriteLine(expr.ToCSharpString(objectToCode));
112-
#endif
113116
}
114117

115118
public static void PrintCSharp(this Expression expr, ref string result)
116119
{
117-
#if PRINTCS
120+
if (!AllowPrintCS) return;
118121
Console.WriteLine(result = expr.ToCSharpString());
119-
#endif
120122
}
121123

122124
public static void PrintIL(this Delegate @delegate, [CallerMemberName] string tag = null)
123125
{
124-
#if PRINTIL
126+
if (!AllowPrintIL) return;
125127
@delegate.Method.PrintIL(tag);
126-
#endif
127128
}
128129

129130
public static void PrintIL(this MethodInfo method, string tag = null)
130131
{
131-
#if PRINTIL
132+
if (!AllowPrintIL) return;
132133
var s = new StringBuilder();
133134
s.Append(tag == null ? "<il>" : "<" + tag + ">").AppendLine();
134135
method.ToILString(s);
135136
s.AppendLine().Append(tag == null ? "</il>" : "</" + tag + ">");
136137
Console.WriteLine(s);
137-
#endif
138138
}
139139
}
140140

test/FastExpressionCompiler.TestsRunner/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class Program
99
{
1010
public static void Main()
1111
{
12-
// new Issue55_CompileFast_crash_with_ref_parameter().Run();
12+
new Issue55_CompileFast_crash_with_ref_parameter().Run();
1313

1414
// todo: @wip add to FEC, check the possibility of the increment compilation and the artifacts reusability
1515
// new LightExpression.UnitTests.ConstantAndConversionTests().Run();

0 commit comments

Comments
 (0)