1+ using System . Diagnostics ;
12using SqlServerSimulator . Parser . Tokens ;
23using SqlServerSimulator . Storage ;
34using System . Text ;
@@ -8,6 +9,7 @@ namespace SqlServerSimulator.Parser;
89/// <summary>
910/// A specific type of expression used in WHERE clauses and similar branching scenarios.
1011/// </summary>
12+ [ DebuggerDisplay ( "{DebugDisplay(),nq}" ) ]
1113internal abstract class BooleanExpression
1214{
1315 protected readonly Expression left , right ;
@@ -75,9 +77,12 @@ private static LikeExpression ParseLike(Expression left, ParserContext context,
7577 /// <param name="getColumnValue">Provides the value for a column.</param>
7678 public abstract bool Run ( Func < List < string > , SqlValue > getColumnValue ) ;
7779
78- #if DEBUG
79- public abstract override string ToString ( ) ;
80- #endif
80+ /// <summary>
81+ /// Diagnostic-only string rendering, surfaced via
82+ /// <see cref="DebuggerDisplayAttribute"/>. Production paths must not call
83+ /// this — same convention as <see cref="Expression.DebugDisplay"/>.
84+ /// </summary>
85+ internal abstract string DebugDisplay ( ) ;
8186
8287 /// <summary>
8388 /// Evaluates both sides, applies SQL Server type promotion to a common
@@ -109,59 +114,47 @@ private sealed class EqualityExpression(Expression left, ParserContext context)
109114 public override bool Run ( Func < List < string > , SqlValue > getColumnValue ) =>
110115 ComparePromoted ( left , right , getColumnValue , "equal to" , static ( l , r ) => l . Equals ( r ) ) ;
111116
112- #if DEBUG
113- public override string ToString ( ) => $ "{ left } = { right } ";
114- #endif
117+ internal override string DebugDisplay ( ) => $ "{ left . DebugDisplay ( ) } = { right . DebugDisplay ( ) } ";
115118 }
116119
117120 private sealed class InequalityExpression ( Expression left , ParserContext context ) : BooleanExpression ( left , context )
118121 {
119122 public override bool Run ( Func < List < string > , SqlValue > getColumnValue ) =>
120123 ComparePromoted ( left , right , getColumnValue , "not equal to" , static ( l , r ) => ! l . Equals ( r ) ) ;
121124
122- #if DEBUG
123- public override string ToString ( ) => $ "{ left } <> { right } ";
124- #endif
125+ internal override string DebugDisplay ( ) => $ "{ left . DebugDisplay ( ) } <> { right . DebugDisplay ( ) } ";
125126 }
126127
127128 private sealed class GreaterThanExpression ( Expression left , Expression right ) : BooleanExpression ( left , right )
128129 {
129130 public override bool Run ( Func < List < string > , SqlValue > getColumnValue ) =>
130131 ComparePromoted ( left , right , getColumnValue , "greater than" , static ( l , r ) => l . CompareTo ( r ) > 0 ) ;
131132
132- #if DEBUG
133- public override string ToString ( ) => $ "{ left } > { right } ";
134- #endif
133+ internal override string DebugDisplay ( ) => $ "{ left . DebugDisplay ( ) } > { right . DebugDisplay ( ) } ";
135134 }
136135
137136 private sealed class GreaterThanOrEqualExpression ( Expression left , ParserContext context ) : BooleanExpression ( left , context )
138137 {
139138 public override bool Run ( Func < List < string > , SqlValue > getColumnValue ) =>
140139 ComparePromoted ( left , right , getColumnValue , "greater than or equal to" , static ( l , r ) => l . CompareTo ( r ) >= 0 ) ;
141140
142- #if DEBUG
143- public override string ToString ( ) => $ "{ left } >= { right } ";
144- #endif
141+ internal override string DebugDisplay ( ) => $ "{ left . DebugDisplay ( ) } >= { right . DebugDisplay ( ) } ";
145142 }
146143
147144 private sealed class LessThanExpression ( Expression left , Expression right ) : BooleanExpression ( left , right )
148145 {
149146 public override bool Run ( Func < List < string > , SqlValue > getColumnValue ) =>
150147 ComparePromoted ( left , right , getColumnValue , "less than" , static ( l , r ) => l . CompareTo ( r ) < 0 ) ;
151148
152- #if DEBUG
153- public override string ToString ( ) => $ "{ left } < { right } ";
154- #endif
149+ internal override string DebugDisplay ( ) => $ "{ left . DebugDisplay ( ) } < { right . DebugDisplay ( ) } ";
155150 }
156151
157152 private sealed class LessThanOrEqualExpression ( Expression left , ParserContext context ) : BooleanExpression ( left , context )
158153 {
159154 public override bool Run ( Func < List < string > , SqlValue > getColumnValue ) =>
160155 ComparePromoted ( left , right , getColumnValue , "less than or equal to" , static ( l , r ) => l . CompareTo ( r ) <= 0 ) ;
161156
162- #if DEBUG
163- public override string ToString ( ) => $ "{ left } <= { right } ";
164- #endif
157+ internal override string DebugDisplay ( ) => $ "{ left . DebugDisplay ( ) } <= { right . DebugDisplay ( ) } ";
165158 }
166159
167160 /// <summary>
@@ -329,10 +322,8 @@ private static int TranslateClass(string pattern, int start, StringBuilder sb)
329322 return end + 1 ;
330323 }
331324
332- #if DEBUG
333- public override string ToString ( ) => this . escape is null
334- ? $ "{ left } { ( this . negated ? "NOT LIKE" : "LIKE" ) } { right } "
335- : $ "{ left } { ( this . negated ? "NOT LIKE" : "LIKE" ) } { right } ESCAPE { this . escape } ";
336- #endif
325+ internal override string DebugDisplay ( ) => this . escape is null
326+ ? $ "{ left . DebugDisplay ( ) } { ( this . negated ? "NOT LIKE" : "LIKE" ) } { right . DebugDisplay ( ) } "
327+ : $ "{ left . DebugDisplay ( ) } { ( this . negated ? "NOT LIKE" : "LIKE" ) } { right . DebugDisplay ( ) } ESCAPE { this . escape . DebugDisplay ( ) } ";
337328 }
338329}
0 commit comments