Style cleanup.

This commit is contained in:
chriseth 2019-04-18 13:17:11 +02:00
parent fce19bde58
commit 2c991acff0
2 changed files with 28 additions and 26 deletions

View File

@ -53,16 +53,15 @@
#include <liblangutil/Common.h>
#include <liblangutil/Exceptions.h>
#include <liblangutil/Scanner.h>
#include <boost/optional.hpp>
#include <algorithm>
#include <ostream>
#include <tuple>
using namespace std;
using namespace langutil;
namespace langutil
{
std::string to_string(ScannerError _errorCode)
string langutil::to_string(ScannerError _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;
return os << to_string(_errorCode);
}
namespace langutil
{
/// Scoped helper for literal recording. Automatically drops the literal
/// if aborting the scanning before it's complete.
enum LiteralType {
enum LiteralType
{
LITERAL_TYPE_STRING,
LITERAL_TYPE_NUMBER, // not really different from string type in behaviour
LITERAL_TYPE_COMMENT
@ -100,9 +103,10 @@ enum LiteralType {
class LiteralScope
{
public:
explicit LiteralScope(Scanner* _self, enum LiteralType _type): m_type(_type)
, m_scanner(_self)
, m_complete(false)
explicit LiteralScope(Scanner* _self, enum LiteralType _type):
m_type(_type),
m_scanner(_self),
m_complete(false)
{
if (_type == LITERAL_TYPE_COMMENT)
m_scanner->m_nextSkippedComment.literal.clear();
@ -125,8 +129,9 @@ private:
enum LiteralType m_type;
Scanner* m_scanner;
bool m_complete;
}; // end of LiteralScope class
};
}
void Scanner::reset(CharStream _source)
{
@ -134,10 +139,10 @@ void Scanner::reset(CharStream _source)
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.");
m_source = _source;
m_source = std::move(_source);
reset();
}
@ -168,7 +173,7 @@ bool Scanner::scanHexByte(char& o_scannedByte)
return true;
}
bool Scanner::scanUnicode(unsigned & o_codepoint)
boost::optional<unsigned> Scanner::scanUnicode()
{
unsigned x = 0;
for (int i = 0; i < 4; i++)
@ -177,13 +182,12 @@ bool Scanner::scanUnicode(unsigned & o_codepoint)
if (d < 0)
{
rollback(i);
return false;
return {};
}
x = x * 16 + d;
advance();
}
o_codepoint = x;
return true;
return x;
}
// This supports codepoints between 0000 and FFFF.
@ -664,10 +668,10 @@ bool Scanner::scanEscape()
break;
case 'u':
{
unsigned codepoint;
if (!scanUnicode(codepoint))
if (boost::optional<unsigned> codepoint = scanUnicode())
addUnicodeAsUTF8(*codepoint);
else
return false;
addUnicodeAsUTF8(codepoint);
return true;
}
case 'x':
@ -754,7 +758,8 @@ void Scanner::scanDecimalDigits()
return;
// May continue with decimal digit or underscore for grouping.
do addLiteralCharAndAdvance();
do
addLiteralCharAndAdvance();
while (!m_source->isPastEndOfInput() && (isDecimalDigit(m_char) || m_char == '_'));
// Defer further validation of underscore to SyntaxChecker.
@ -865,6 +870,3 @@ tuple<Token, unsigned, unsigned> Scanner::scanIdentifierOrKeyword()
literal.complete();
return TokenTraits::fromIdentifierOrKeyword(m_nextToken.literal);
}
}

View File

@ -198,7 +198,7 @@ private:
inline Token selectToken(char _next, Token _then, Token _else);
bool scanHexByte(char& o_scannedByte);
bool scanUnicode(unsigned& o_codepoint);
boost::optional<unsigned> scanUnicode();
/// Scans a single Solidity token.
void scanToken();