mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
added keyword type and some tests, changes in lexical cast
This commit is contained in:
parent
d0bb87ae88
commit
d0054a8d29
@ -109,26 +109,26 @@ char const Token::m_tokenType[] =
|
|||||||
{
|
{
|
||||||
TOKEN_LIST(KT, KK)
|
TOKEN_LIST(KT, KK)
|
||||||
};
|
};
|
||||||
unsigned Token::extractUnsigned(string::const_iterator _begin, string::const_iterator _end)
|
int Token::parseSize(string::const_iterator _begin, string::const_iterator _end)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
unsigned short m = boost::lexical_cast<unsigned short>(boost::make_iterator_range(_begin, _end));
|
unsigned int m = boost::lexical_cast<int>(boost::make_iterator_range(_begin, _end));
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
catch(const boost::bad_lexical_cast &)
|
catch(boost::bad_lexical_cast const&)
|
||||||
{
|
{
|
||||||
return 0;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tuple<Token::Value, unsigned short, unsigned short> Token::fromIdentifierOrKeyword(string const& _literal)
|
tuple<Token::Value, unsigned int, unsigned int> Token::fromIdentifierOrKeyword(string const& _literal)
|
||||||
{
|
{
|
||||||
auto positionM = find_if(_literal.begin(), _literal.end(), ::isdigit);
|
auto positionM = find_if(_literal.begin(), _literal.end(), ::isdigit);
|
||||||
if (positionM != _literal.end())
|
if (positionM != _literal.end())
|
||||||
{
|
{
|
||||||
string baseType(_literal.begin(), positionM);
|
string baseType(_literal.begin(), positionM);
|
||||||
auto positionX = find_if_not(positionM, _literal.end(), ::isdigit);
|
auto positionX = find_if_not(positionM, _literal.end(), ::isdigit);
|
||||||
unsigned short m = extractUnsigned(positionM, positionX);
|
int m = parseSize(positionM, positionX);
|
||||||
Token::Value keyword = keywordByName(baseType);
|
Token::Value keyword = keywordByName(baseType);
|
||||||
if (keyword == Token::Bytes)
|
if (keyword == Token::Bytes)
|
||||||
{
|
{
|
||||||
@ -147,8 +147,8 @@ tuple<Token::Value, unsigned short, unsigned short> Token::fromIdentifierOrKeywo
|
|||||||
}
|
}
|
||||||
else if (keyword == Token::UFixed || keyword == Token::Fixed)
|
else if (keyword == Token::UFixed || keyword == Token::Fixed)
|
||||||
{
|
{
|
||||||
auto positionN = find_if_not(positionX++, _literal.end(), ::isdigit);
|
auto positionN = find_if_not(++positionX, _literal.end(), ::isdigit);
|
||||||
unsigned short n = extractUnsigned(positionX++, positionN);
|
int n = parseSize(++positionX, positionN);
|
||||||
if (
|
if (
|
||||||
0 < m + n &&
|
0 < m + n &&
|
||||||
m + n <= 256 &&
|
m + n <= 256 &&
|
||||||
|
@ -231,6 +231,7 @@ namespace solidity
|
|||||||
K(Type, "type", 0) \
|
K(Type, "type", 0) \
|
||||||
K(TypeOf, "typeof", 0) \
|
K(TypeOf, "typeof", 0) \
|
||||||
K(Using, "using", 0) \
|
K(Using, "using", 0) \
|
||||||
|
T(Timestamp, "timestamp", 0) \
|
||||||
/* Illegal token - not able to scan. */ \
|
/* Illegal token - not able to scan. */ \
|
||||||
T(Illegal, "ILLEGAL", 0) \
|
T(Illegal, "ILLEGAL", 0) \
|
||||||
\
|
\
|
||||||
@ -304,11 +305,11 @@ public:
|
|||||||
return m_precedence[tok];
|
return m_precedence[tok];
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::tuple<Token::Value, unsigned short, unsigned short> fromIdentifierOrKeyword(std::string const& _literal);
|
static std::tuple<Token::Value, unsigned int, unsigned int> fromIdentifierOrKeyword(std::string const& _literal);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// @returns 0 on error (invalid digit or number too large)
|
// @returns -1 on error (invalid digit or number too large)
|
||||||
static unsigned extractUnsigned(std::string::const_iterator _begin, std::string::const_iterator _end);
|
static int parseSize(std::string::const_iterator _begin, std::string::const_iterator _end);
|
||||||
// @returns the keyword with name @a _name or Token::Identifier of no such keyword exists.
|
// @returns the keyword with name @a _name or Token::Identifier of no such keyword exists.
|
||||||
static Token::Value keywordByName(std::string const& _name);
|
static Token::Value keywordByName(std::string const& _name);
|
||||||
static char const* const m_name[NUM_TOKENS];
|
static char const* const m_name[NUM_TOKENS];
|
||||||
|
@ -3232,6 +3232,19 @@ BOOST_AUTO_TEST_CASE(int10abc_is_identifier)
|
|||||||
BOOST_CHECK(success(text));
|
BOOST_CHECK(success(text));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(invalid_fixed_types)
|
||||||
|
{
|
||||||
|
char const* text = R"(
|
||||||
|
contract test {
|
||||||
|
function f() {
|
||||||
|
fixed0x7 a = .3;
|
||||||
|
fixed99999999999999999999999999999999999999x7 b = 9.5;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
BOOST_CHECK(!success(text));
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(library_functions_do_not_have_value)
|
BOOST_AUTO_TEST_CASE(library_functions_do_not_have_value)
|
||||||
{
|
{
|
||||||
char const* text = R"(
|
char const* text = R"(
|
||||||
|
Loading…
Reference in New Issue
Block a user