@@ -16,6 +16,7 @@ public class NumberParser
1616 private static readonly char [ ] Qualifiers = { 'U' , 'u' , 'L' , 'l' , 'F' , 'f' , 'D' , 'd' , 'M' , 'm' } ;
1717 private static readonly char [ ] QualifiersHex = { 'U' , 'u' , 'L' , 'l' } ;
1818 private static readonly string [ ] QualifiersReal = { "F" , "f" , "D" , "d" , "M" , "m" } ;
19+ private readonly ConstantExpressionHelper _constantExpressionHelper ;
1920
2021 private readonly CultureInfo _culture ;
2122
@@ -26,6 +27,7 @@ public class NumberParser
2627 public NumberParser ( ParsingConfig ? config )
2728 {
2829 _culture = config ? . NumberParseCulture ?? CultureInfo . InvariantCulture ;
30+ _constantExpressionHelper = ConstantExpressionHelperFactory . GetInstance ( config ?? ParsingConfig . Default ) ;
2931 }
3032
3133 /// <summary>
@@ -77,38 +79,38 @@ public Expression ParseIntegerLiteral(int tokenPosition, string text)
7779 {
7880 if ( qualifier == "U" || qualifier == "u" )
7981 {
80- return ConstantExpressionHelper . CreateLiteral ( ( uint ) unsignedValue , text ) ;
82+ return _constantExpressionHelper . CreateLiteral ( ( uint ) unsignedValue , text ) ;
8183 }
8284
8385 if ( qualifier == "L" || qualifier == "l" )
8486 {
85- return ConstantExpressionHelper . CreateLiteral ( ( long ) unsignedValue , text ) ;
87+ return _constantExpressionHelper . CreateLiteral ( ( long ) unsignedValue , text ) ;
8688 }
8789
8890 if ( QualifiersReal . Contains ( qualifier ) )
8991 {
9092 return ParseRealLiteral ( text , qualifier [ 0 ] , false ) ;
9193 }
9294
93- return ConstantExpressionHelper . CreateLiteral ( unsignedValue , text ) ;
95+ return _constantExpressionHelper . CreateLiteral ( unsignedValue , text ) ;
9496 }
9597
9698 if ( unsignedValue <= int . MaxValue )
9799 {
98- return ConstantExpressionHelper . CreateLiteral ( ( int ) unsignedValue , text ) ;
100+ return _constantExpressionHelper . CreateLiteral ( ( int ) unsignedValue , text ) ;
99101 }
100102
101103 if ( unsignedValue <= uint . MaxValue )
102104 {
103- return ConstantExpressionHelper . CreateLiteral ( ( uint ) unsignedValue , text ) ;
105+ return _constantExpressionHelper . CreateLiteral ( ( uint ) unsignedValue , text ) ;
104106 }
105107
106108 if ( unsignedValue <= long . MaxValue )
107109 {
108- return ConstantExpressionHelper . CreateLiteral ( ( long ) unsignedValue , text ) ;
110+ return _constantExpressionHelper . CreateLiteral ( ( long ) unsignedValue , text ) ;
109111 }
110112
111- return ConstantExpressionHelper . CreateLiteral ( unsignedValue , text ) ;
113+ return _constantExpressionHelper . CreateLiteral ( unsignedValue , text ) ;
112114 }
113115
114116 if ( isHexadecimal || isBinary )
@@ -135,7 +137,7 @@ public Expression ParseIntegerLiteral(int tokenPosition, string text)
135137 {
136138 if ( qualifier == "L" || qualifier == "l" )
137139 {
138- return ConstantExpressionHelper . CreateLiteral ( value , text ) ;
140+ return _constantExpressionHelper . CreateLiteral ( value , text ) ;
139141 }
140142
141143 if ( QualifiersReal . Contains ( qualifier ) )
@@ -148,10 +150,10 @@ public Expression ParseIntegerLiteral(int tokenPosition, string text)
148150
149151 if ( value <= int . MaxValue )
150152 {
151- return ConstantExpressionHelper . CreateLiteral ( ( int ) value , text ) ;
153+ return _constantExpressionHelper . CreateLiteral ( ( int ) value , text ) ;
152154 }
153155
154- return ConstantExpressionHelper . CreateLiteral ( value , text ) ;
156+ return _constantExpressionHelper . CreateLiteral ( value , text ) ;
155157 }
156158
157159 /// <summary>
@@ -163,18 +165,18 @@ public Expression ParseRealLiteral(string text, char qualifier, bool stripQualif
163165 {
164166 case 'f' :
165167 case 'F' :
166- return ConstantExpressionHelper . CreateLiteral ( ParseNumber ( stripQualifier ? text . Substring ( 0 , text . Length - 1 ) : text , typeof ( float ) ) ! , text ) ;
168+ return _constantExpressionHelper . CreateLiteral ( ParseNumber ( stripQualifier ? text . Substring ( 0 , text . Length - 1 ) : text , typeof ( float ) ) ! , text ) ;
167169
168170 case 'm' :
169171 case 'M' :
170- return ConstantExpressionHelper . CreateLiteral ( ParseNumber ( stripQualifier ? text . Substring ( 0 , text . Length - 1 ) : text , typeof ( decimal ) ) ! , text ) ;
172+ return _constantExpressionHelper . CreateLiteral ( ParseNumber ( stripQualifier ? text . Substring ( 0 , text . Length - 1 ) : text , typeof ( decimal ) ) ! , text ) ;
171173
172174 case 'd' :
173175 case 'D' :
174- return ConstantExpressionHelper . CreateLiteral ( ParseNumber ( stripQualifier ? text . Substring ( 0 , text . Length - 1 ) : text , typeof ( double ) ) ! , text ) ;
176+ return _constantExpressionHelper . CreateLiteral ( ParseNumber ( stripQualifier ? text . Substring ( 0 , text . Length - 1 ) : text , typeof ( double ) ) ! , text ) ;
175177
176178 default :
177- return ConstantExpressionHelper . CreateLiteral ( ParseNumber ( text , typeof ( double ) ) ! , text ) ;
179+ return _constantExpressionHelper . CreateLiteral ( ParseNumber ( text , typeof ( double ) ) ! , text ) ;
178180 }
179181 }
180182
@@ -285,12 +287,12 @@ private Expression ParseAsBinary(int tokenPosition, string text, bool isNegative
285287 {
286288 if ( RegexBinary32 . IsMatch ( text ) )
287289 {
288- return ConstantExpressionHelper . CreateLiteral ( ( isNegative ? - 1 : 1 ) * Convert . ToInt32 ( text , 2 ) , text ) ;
290+ return _constantExpressionHelper . CreateLiteral ( ( isNegative ? - 1 : 1 ) * Convert . ToInt32 ( text , 2 ) , text ) ;
289291 }
290292
291293 if ( RegexBinary64 . IsMatch ( text ) )
292294 {
293- return ConstantExpressionHelper . CreateLiteral ( ( isNegative ? - 1 : 1 ) * Convert . ToInt64 ( text , 2 ) , text ) ;
295+ return _constantExpressionHelper . CreateLiteral ( ( isNegative ? - 1 : 1 ) * Convert . ToInt64 ( text , 2 ) , text ) ;
294296 }
295297
296298 throw new ParseException ( string . Format ( _culture , Res . InvalidBinaryIntegerLiteral , text ) , tokenPosition ) ;
0 commit comments