@@ -135,26 +135,11 @@ class LiteralScope
135
135
bool m_complete;
136
136
};
137
137
138
- void Scanner::reset (CharStream _source)
139
- {
140
- m_source = make_shared<CharStream>(std::move (_source));
141
- m_sourceName = make_shared<string>(m_source->name ());
142
- reset ();
143
- }
144
-
145
- void Scanner::reset (shared_ptr<CharStream> _source)
146
- {
147
- solAssert (_source.get () != nullptr , " You MUST provide a CharStream when resetting." );
148
- m_source = std::move (_source);
149
- m_sourceName = make_shared<string>(m_source->name ());
150
- reset ();
151
- }
152
-
153
138
void Scanner::reset ()
154
139
{
155
- m_source-> reset ();
140
+ m_source. reset ();
156
141
m_kind = ScannerKind::Solidity;
157
- m_char = m_source-> get ();
142
+ m_char = m_source. get ();
158
143
skipWhitespace ();
159
144
next ();
160
145
next ();
@@ -163,7 +148,7 @@ void Scanner::reset()
163
148
164
149
void Scanner::setPosition (size_t _offset)
165
150
{
166
- m_char = m_source-> setPosition (_offset);
151
+ m_char = m_source. setPosition (_offset);
167
152
scanToken ();
168
153
next ();
169
154
next ();
@@ -229,7 +214,7 @@ void Scanner::rescan()
229
214
rollbackTo = static_cast <size_t >(m_tokens[Current].location .start );
230
215
else
231
216
rollbackTo = static_cast <size_t >(m_skippedComments[Current].location .start );
232
- m_char = m_source-> rollback (m_source-> position () - rollbackTo);
217
+ m_char = m_source. rollback (m_source. position () - rollbackTo);
233
218
next ();
234
219
next ();
235
220
next ();
@@ -324,12 +309,12 @@ Token Scanner::skipSingleLineComment()
324
309
{
325
310
// Line terminator is not part of the comment. If it is a
326
311
// non-ascii line terminator, it will result in a parser error.
327
- size_t startPosition = m_source-> position ();
312
+ size_t startPosition = m_source. position ();
328
313
while (!isUnicodeLinebreak ())
329
314
if (!advance ())
330
315
break ;
331
316
332
- ScannerError unicodeDirectionError = validateBiDiMarkup (* m_source, startPosition);
317
+ ScannerError unicodeDirectionError = validateBiDiMarkup (m_source, startPosition);
333
318
if (unicodeDirectionError != ScannerError::NoError)
334
319
return setError (unicodeDirectionError);
335
320
@@ -362,28 +347,28 @@ bool Scanner::tryScanEndOfLine()
362
347
size_t Scanner::scanSingleLineDocComment ()
363
348
{
364
349
LiteralScope literal (this , LITERAL_TYPE_COMMENT);
365
- size_t endPosition = m_source-> position ();
350
+ size_t endPosition = m_source. position ();
366
351
367
352
skipWhitespaceExceptUnicodeLinebreak ();
368
353
369
354
while (!isSourcePastEndOfInput ())
370
355
{
371
- endPosition = m_source-> position ();
356
+ endPosition = m_source. position ();
372
357
if (tryScanEndOfLine ())
373
358
{
374
359
// Check if next line is also a single-line comment.
375
360
// If any whitespaces were skipped, use source position before.
376
361
if (!skipWhitespaceExceptUnicodeLinebreak ())
377
- endPosition = m_source-> position ();
362
+ endPosition = m_source. position ();
378
363
379
- if (!m_source-> isPastEndOfInput (3 ) &&
380
- m_source-> get (0 ) == ' /' &&
381
- m_source-> get (1 ) == ' /' &&
382
- m_source-> get (2 ) == ' /' )
364
+ if (!m_source. isPastEndOfInput (3 ) &&
365
+ m_source. get (0 ) == ' /' &&
366
+ m_source. get (1 ) == ' /' &&
367
+ m_source. get (2 ) == ' /' )
383
368
{
384
- if (!m_source-> isPastEndOfInput (4 ) && m_source-> get (3 ) == ' /' )
369
+ if (!m_source. isPastEndOfInput (4 ) && m_source. get (3 ) == ' /' )
385
370
break ; // "////" is not a documentation comment
386
- m_char = m_source-> advanceAndGet (3 );
371
+ m_char = m_source. advanceAndGet (3 );
387
372
if (atEndOfLine ())
388
373
continue ;
389
374
addCommentLiteralChar (' \n ' );
@@ -404,7 +389,7 @@ size_t Scanner::scanSingleLineDocComment()
404
389
405
390
Token Scanner::skipMultiLineComment ()
406
391
{
407
- size_t startPosition = m_source-> position ();
392
+ size_t startPosition = m_source. position ();
408
393
while (!isSourcePastEndOfInput ())
409
394
{
410
395
char prevChar = m_char;
@@ -415,7 +400,7 @@ Token Scanner::skipMultiLineComment()
415
400
// multi-line comments are treated as whitespace.
416
401
if (prevChar == ' *' && m_char == ' /' )
417
402
{
418
- ScannerError unicodeDirectionError = validateBiDiMarkup (* m_source, startPosition);
403
+ ScannerError unicodeDirectionError = validateBiDiMarkup (m_source, startPosition);
419
404
if (unicodeDirectionError != ScannerError::NoError)
420
405
return setError (unicodeDirectionError);
421
406
@@ -442,32 +427,32 @@ Token Scanner::scanMultiLineDocComment()
442
427
if (atEndOfLine ())
443
428
{
444
429
skipWhitespace ();
445
- if (!m_source-> isPastEndOfInput (1 ) && m_source-> get (0 ) == ' *' && m_source-> get (1 ) == ' *' )
430
+ if (!m_source. isPastEndOfInput (1 ) && m_source. get (0 ) == ' *' && m_source. get (1 ) == ' *' )
446
431
{ // it is unknown if this leads to the end of the comment
447
432
addCommentLiteralChar (' *' );
448
433
advance ();
449
434
}
450
- else if (!m_source-> isPastEndOfInput (1 ) && m_source-> get (0 ) == ' *' && m_source-> get (1 ) != ' /' )
435
+ else if (!m_source. isPastEndOfInput (1 ) && m_source. get (0 ) == ' *' && m_source. get (1 ) != ' /' )
451
436
{ // skip first '*' in subsequent lines
452
- m_char = m_source-> advanceAndGet (1 );
437
+ m_char = m_source. advanceAndGet (1 );
453
438
if (atEndOfLine ()) // ignores empty lines
454
439
continue ;
455
440
if (charsAdded)
456
441
addCommentLiteralChar (' \n ' ); // corresponds to the end of previous line
457
442
}
458
- else if (!m_source-> isPastEndOfInput (1 ) && m_source-> get (0 ) == ' *' && m_source-> get (1 ) == ' /' )
443
+ else if (!m_source. isPastEndOfInput (1 ) && m_source. get (0 ) == ' *' && m_source. get (1 ) == ' /' )
459
444
{ // if after newline the comment ends, don't insert the newline
460
- m_char = m_source-> advanceAndGet (2 );
445
+ m_char = m_source. advanceAndGet (2 );
461
446
endFound = true ;
462
447
break ;
463
448
}
464
449
else if (charsAdded)
465
450
addCommentLiteralChar (' \n ' );
466
451
}
467
452
468
- if (!m_source-> isPastEndOfInput (1 ) && m_source-> get (0 ) == ' *' && m_source-> get (1 ) == ' /' )
453
+ if (!m_source. isPastEndOfInput (1 ) && m_source. get (0 ) == ' *' && m_source. get (1 ) == ' /' )
469
454
{
470
- m_char = m_source-> advanceAndGet (2 );
455
+ m_char = m_source. advanceAndGet (2 );
471
456
endFound = true ;
472
457
break ;
473
458
}
@@ -822,11 +807,11 @@ bool Scanner::isUnicodeLinebreak()
822
807
if (0x0a <= m_char && m_char <= 0x0d )
823
808
// line feed, vertical tab, form feed, carriage return
824
809
return true ;
825
- if (!m_source-> isPastEndOfInput (1 ) && uint8_t (m_source-> get (0 )) == 0xc2 && uint8_t (m_source-> get (1 )) == 0x85 )
810
+ if (!m_source. isPastEndOfInput (1 ) && uint8_t (m_source. get (0 )) == 0xc2 && uint8_t (m_source. get (1 )) == 0x85 )
826
811
// NEL - U+0085, C2 85 in utf8
827
812
return true ;
828
- if (!m_source-> isPastEndOfInput (2 ) && uint8_t (m_source-> get (0 )) == 0xe2 && uint8_t (m_source-> get (1 )) == 0x80 && (
829
- uint8_t (m_source-> get (2 )) == 0xa8 || uint8_t (m_source-> get (2 )) == 0xa9
813
+ if (!m_source. isPastEndOfInput (2 ) && uint8_t (m_source. get (0 )) == 0xe2 && uint8_t (m_source. get (1 )) == 0x80 && (
814
+ uint8_t (m_source. get (2 )) == 0xa8 || uint8_t (m_source. get (2 )) == 0xa9
830
815
))
831
816
// LS - U+2028, E2 80 A8 in utf8
832
817
// PS - U+2029, E2 80 A9 in utf8
@@ -836,7 +821,7 @@ bool Scanner::isUnicodeLinebreak()
836
821
837
822
Token Scanner::scanString (bool const _isUnicode)
838
823
{
839
- size_t startPosition = m_source-> position ();
824
+ size_t startPosition = m_source. position ();
840
825
char const quote = m_char;
841
826
advance (); // consume quote
842
827
LiteralScope literal (this , LITERAL_TYPE_STRING);
@@ -867,7 +852,7 @@ Token Scanner::scanString(bool const _isUnicode)
867
852
868
853
if (_isUnicode)
869
854
{
870
- ScannerError unicodeDirectionError = validateBiDiMarkup (* m_source, startPosition);
855
+ ScannerError unicodeDirectionError = validateBiDiMarkup (m_source, startPosition);
871
856
if (unicodeDirectionError != ScannerError::NoError)
872
857
return setError (unicodeDirectionError);
873
858
}
@@ -921,7 +906,7 @@ void Scanner::scanDecimalDigits()
921
906
// May continue with decimal digit or underscore for grouping.
922
907
do
923
908
addLiteralCharAndAdvance ();
924
- while (!m_source-> isPastEndOfInput () && (isDecimalDigit (m_char) || m_char == ' _' ));
909
+ while (!m_source. isPastEndOfInput () && (isDecimalDigit (m_char) || m_char == ' _' ));
925
910
926
911
// Defer further validation of underscore to SyntaxChecker.
927
912
}
@@ -967,15 +952,15 @@ Token Scanner::scanNumber(char _charSeen)
967
952
scanDecimalDigits (); // optional
968
953
if (m_char == ' .' )
969
954
{
970
- if (!m_source-> isPastEndOfInput (1 ) && m_source-> get (1 ) == ' _' )
955
+ if (!m_source. isPastEndOfInput (1 ) && m_source. get (1 ) == ' _' )
971
956
{
972
957
// Assume the input may be a floating point number with leading '_' in fraction part.
973
958
// Recover by consuming it all but returning `Illegal` right away.
974
959
addLiteralCharAndAdvance (); // '.'
975
960
addLiteralCharAndAdvance (); // '_'
976
961
scanDecimalDigits ();
977
962
}
978
- if (m_source-> isPastEndOfInput () || !isDecimalDigit (m_source-> get (1 )))
963
+ if (m_source. isPastEndOfInput () || !isDecimalDigit (m_source. get (1 )))
979
964
{
980
965
// A '.' has to be followed by a number.
981
966
literal.complete ();
@@ -992,7 +977,7 @@ Token Scanner::scanNumber(char _charSeen)
992
977
solAssert (kind != HEX, " 'e'/'E' must be scanned as part of the hex number" );
993
978
if (kind != DECIMAL)
994
979
return setError (ScannerError::IllegalExponent);
995
- else if (!m_source-> isPastEndOfInput (1 ) && m_source-> get (1 ) == ' _' )
980
+ else if (!m_source. isPastEndOfInput (1 ) && m_source. get (1 ) == ' _' )
996
981
{
997
982
// Recover from wrongly placed underscore as delimiter in literal with scientific
998
983
// notation by consuming until the end.
0 commit comments