mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
commit
a9283d1110
@ -53,16 +53,15 @@
|
|||||||
#include <liblangutil/Common.h>
|
#include <liblangutil/Common.h>
|
||||||
#include <liblangutil/Exceptions.h>
|
#include <liblangutil/Exceptions.h>
|
||||||
#include <liblangutil/Scanner.h>
|
#include <liblangutil/Scanner.h>
|
||||||
|
#include <boost/optional.hpp>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
using namespace langutil;
|
||||||
|
|
||||||
namespace langutil
|
string langutil::to_string(ScannerError _errorCode)
|
||||||
{
|
|
||||||
|
|
||||||
std::string to_string(ScannerError _errorCode)
|
|
||||||
{
|
{
|
||||||
switch (_errorCode)
|
switch (_errorCode)
|
||||||
{
|
{
|
||||||
@ -83,15 +82,19 @@ std::string to_string(ScannerError _errorCode)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream& os, ScannerError _errorCode)
|
|
||||||
|
ostream& langutil::operator<<(ostream& os, ScannerError _errorCode)
|
||||||
{
|
{
|
||||||
os << to_string(_errorCode);
|
return os << to_string(_errorCode);
|
||||||
return os;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace langutil
|
||||||
|
{
|
||||||
|
|
||||||
/// Scoped helper for literal recording. Automatically drops the literal
|
/// Scoped helper for literal recording. Automatically drops the literal
|
||||||
/// if aborting the scanning before it's complete.
|
/// if aborting the scanning before it's complete.
|
||||||
enum LiteralType {
|
enum LiteralType
|
||||||
|
{
|
||||||
LITERAL_TYPE_STRING,
|
LITERAL_TYPE_STRING,
|
||||||
LITERAL_TYPE_NUMBER, // not really different from string type in behaviour
|
LITERAL_TYPE_NUMBER, // not really different from string type in behaviour
|
||||||
LITERAL_TYPE_COMMENT
|
LITERAL_TYPE_COMMENT
|
||||||
@ -100,9 +103,10 @@ enum LiteralType {
|
|||||||
class LiteralScope
|
class LiteralScope
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit LiteralScope(Scanner* _self, enum LiteralType _type): m_type(_type)
|
explicit LiteralScope(Scanner* _self, enum LiteralType _type):
|
||||||
, m_scanner(_self)
|
m_type(_type),
|
||||||
, m_complete(false)
|
m_scanner(_self),
|
||||||
|
m_complete(false)
|
||||||
{
|
{
|
||||||
if (_type == LITERAL_TYPE_COMMENT)
|
if (_type == LITERAL_TYPE_COMMENT)
|
||||||
m_scanner->m_nextSkippedComment.literal.clear();
|
m_scanner->m_nextSkippedComment.literal.clear();
|
||||||
@ -125,8 +129,9 @@ private:
|
|||||||
enum LiteralType m_type;
|
enum LiteralType m_type;
|
||||||
Scanner* m_scanner;
|
Scanner* m_scanner;
|
||||||
bool m_complete;
|
bool m_complete;
|
||||||
}; // end of LiteralScope class
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void Scanner::reset(CharStream _source)
|
void Scanner::reset(CharStream _source)
|
||||||
{
|
{
|
||||||
@ -134,10 +139,10 @@ void Scanner::reset(CharStream _source)
|
|||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scanner::reset(std::shared_ptr<CharStream> _source)
|
void Scanner::reset(shared_ptr<CharStream> _source)
|
||||||
{
|
{
|
||||||
solAssert(_source.get() != nullptr, "You MUST provide a CharStream when resetting.");
|
solAssert(_source.get() != nullptr, "You MUST provide a CharStream when resetting.");
|
||||||
m_source = _source;
|
m_source = std::move(_source);
|
||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,7 +173,7 @@ bool Scanner::scanHexByte(char& o_scannedByte)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Scanner::scanUnicode(unsigned & o_codepoint)
|
boost::optional<unsigned> Scanner::scanUnicode()
|
||||||
{
|
{
|
||||||
unsigned x = 0;
|
unsigned x = 0;
|
||||||
for (int i = 0; i < 4; i++)
|
for (int i = 0; i < 4; i++)
|
||||||
@ -177,13 +182,12 @@ bool Scanner::scanUnicode(unsigned & o_codepoint)
|
|||||||
if (d < 0)
|
if (d < 0)
|
||||||
{
|
{
|
||||||
rollback(i);
|
rollback(i);
|
||||||
return false;
|
return {};
|
||||||
}
|
}
|
||||||
x = x * 16 + d;
|
x = x * 16 + d;
|
||||||
advance();
|
advance();
|
||||||
}
|
}
|
||||||
o_codepoint = x;
|
return x;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// This supports codepoints between 0000 and FFFF.
|
// This supports codepoints between 0000 and FFFF.
|
||||||
@ -664,10 +668,10 @@ bool Scanner::scanEscape()
|
|||||||
break;
|
break;
|
||||||
case 'u':
|
case 'u':
|
||||||
{
|
{
|
||||||
unsigned codepoint;
|
if (boost::optional<unsigned> codepoint = scanUnicode())
|
||||||
if (!scanUnicode(codepoint))
|
addUnicodeAsUTF8(*codepoint);
|
||||||
|
else
|
||||||
return false;
|
return false;
|
||||||
addUnicodeAsUTF8(codepoint);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case 'x':
|
case 'x':
|
||||||
@ -754,7 +758,8 @@ void Scanner::scanDecimalDigits()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// May continue with decimal digit or underscore for grouping.
|
// May continue with decimal digit or underscore for grouping.
|
||||||
do addLiteralCharAndAdvance();
|
do
|
||||||
|
addLiteralCharAndAdvance();
|
||||||
while (!m_source->isPastEndOfInput() && (isDecimalDigit(m_char) || m_char == '_'));
|
while (!m_source->isPastEndOfInput() && (isDecimalDigit(m_char) || m_char == '_'));
|
||||||
|
|
||||||
// Defer further validation of underscore to SyntaxChecker.
|
// Defer further validation of underscore to SyntaxChecker.
|
||||||
@ -865,6 +870,3 @@ tuple<Token, unsigned, unsigned> Scanner::scanIdentifierOrKeyword()
|
|||||||
literal.complete();
|
literal.complete();
|
||||||
return TokenTraits::fromIdentifierOrKeyword(m_nextToken.literal);
|
return TokenTraits::fromIdentifierOrKeyword(m_nextToken.literal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
@ -198,7 +198,7 @@ private:
|
|||||||
inline Token selectToken(char _next, Token _then, Token _else);
|
inline Token selectToken(char _next, Token _then, Token _else);
|
||||||
|
|
||||||
bool scanHexByte(char& o_scannedByte);
|
bool scanHexByte(char& o_scannedByte);
|
||||||
bool scanUnicode(unsigned& o_codepoint);
|
boost::optional<unsigned> scanUnicode();
|
||||||
|
|
||||||
/// Scans a single Solidity token.
|
/// Scans a single Solidity token.
|
||||||
void scanToken();
|
void scanToken();
|
||||||
|
Loading…
Reference in New Issue
Block a user