Browse Source

Minor Style fixes

cl-refactor
Lefteris Karapetsas 10 years ago
parent
commit
c0151476ad
  1. 6
      libsolidity/AST.cpp
  2. 16
      libsolidity/AST.h
  3. 12
      libsolidity/Token.h
  4. 18
      libsolidity/Types.cpp
  5. 8
      test/SolidityScanner.cpp

6
libsolidity/AST.cpp

@ -599,10 +599,10 @@ Literal::Literal(Location const& _location, Token::Value _token,
Token::Value _sub): Token::Value _sub):
PrimaryExpression(_location), m_token(_token), m_value(_value) PrimaryExpression(_location), m_token(_token), m_value(_value)
{ {
if(Token::isEtherSubdenomination(_sub)) if (Token::isEtherSubdenomination(_sub))
m_subDenomination = static_cast<Literal::ethSubDenomination>(_sub); m_subDenomination = static_cast<Literal::SubDenomination>(_sub);
else else
m_subDenomination = Literal::ethSubDenomination::NONE; m_subDenomination = Literal::SubDenomination::NONE;
} }
void Literal::checkTypeRequirements() void Literal::checkTypeRequirements()

16
libsolidity/AST.h

@ -1117,12 +1117,14 @@ private:
class Literal: public PrimaryExpression class Literal: public PrimaryExpression
{ {
public: public:
enum class ethSubDenomination { enum class SubDenomination
{
NONE = Token::ILLEGAL, NONE = Token::ILLEGAL,
WEI = Token::ETH_SUB_WEI, WEI = Token::SubWei,
SZABO = Token::ETH_SUB_SZABO, SZABO = Token::SubSzabo,
FINNEY = Token::ETH_SUB_FINNEY, FINNEY = Token::SubFinney,
ETHER = Token::ETH_SUB_ETHER}; ETHER = Token::SubEther
};
Literal(Location const& _location, Token::Value _token, Literal(Location const& _location, Token::Value _token,
ASTPointer<ASTString> const& _value, ASTPointer<ASTString> const& _value,
Token::Value _sub = Token::ILLEGAL); Token::Value _sub = Token::ILLEGAL);
@ -1134,12 +1136,12 @@ public:
/// @returns the non-parsed value of the literal /// @returns the non-parsed value of the literal
ASTString const& getValue() const { return *m_value; } ASTString const& getValue() const { return *m_value; }
ethSubDenomination getSubDenomination() const { return m_subDenomination; } SubDenomination getSubDenomination() const { return m_subDenomination; }
private: private:
Token::Value m_token; Token::Value m_token;
ASTPointer<ASTString> m_value; ASTPointer<ASTString> m_value;
ethSubDenomination m_subDenomination; SubDenomination m_subDenomination;
}; };
/// @} /// @}

12
libsolidity/Token.h

@ -174,11 +174,11 @@ namespace solidity
K(WHILE, "while", 0) \ K(WHILE, "while", 0) \
\ \
\ \
/* Ether subdenominations */ \ /* Ether subdenominations */ \
K(ETH_SUB_WEI, "wei", 0) \ K(SubWei, "wei", 0) \
K(ETH_SUB_SZABO, "szabo", 0) \ K(SubSzabo, "szabo", 0) \
K(ETH_SUB_FINNEY, "finney", 0) \ K(SubFinney, "finney", 0) \
K(ETH_SUB_ETHER, "ether", 0) \ K(SubEther, "ether", 0) \
/* type keywords, keep them in this order, keep int as first keyword /* type keywords, keep them in this order, keep int as first keyword
* the implementation in Types.cpp has to be synced to this here * the implementation in Types.cpp has to be synced to this here
* TODO more to be added */ \ * TODO more to be added */ \
@ -383,7 +383,7 @@ public:
static bool isCountOp(Value op) { return op == INC || op == DEC; } static bool isCountOp(Value op) { return op == INC || op == DEC; }
static bool isShiftOp(Value op) { return (SHL <= op) && (op <= SHR); } static bool isShiftOp(Value op) { return (SHL <= op) && (op <= SHR); }
static bool isVisibilitySpecifier(Value op) { return op == PUBLIC || op == PRIVATE || op == PROTECTED; } static bool isVisibilitySpecifier(Value op) { return op == PUBLIC || op == PRIVATE || op == PROTECTED; }
static bool isEtherSubdenomination(Value op) { return op == ETH_SUB_WEI || op == ETH_SUB_SZABO || op == ETH_SUB_FINNEY || op == Token::ETH_SUB_ETHER; } static bool isEtherSubdenomination(Value op) { return op == SubWei || op == SubSzabo || op == SubFinney || op == Token::SubEther; }
// Returns a string corresponding to the JS token string // Returns a string corresponding to the JS token string
// (.e., "<" for the token LT) or NULL if the token doesn't // (.e., "<" for the token LT) or NULL if the token doesn't

18
libsolidity/Types.cpp

@ -338,19 +338,21 @@ u256 IntegerConstantType::literalValue(Literal const* _literal) const
else else
value = s2u(s256(m_value)); value = s2u(s256(m_value));
if (_literal) { if (_literal)
Literal::ethSubDenomination sub =_literal->getSubDenomination(); {
switch(sub) { Literal::SubDenomination sub =_literal->getSubDenomination();
case Literal::ethSubDenomination::WEI: switch(sub)
case Literal::ethSubDenomination::NONE: {
case Literal::SubDenomination::WEI:
case Literal::SubDenomination::NONE:
break; break;
case Literal::ethSubDenomination::SZABO: case Literal::SubDenomination::SZABO:
value *= u256(1000000000000); value *= u256(1000000000000);
break; break;
case Literal::ethSubDenomination::FINNEY: case Literal::SubDenomination::FINNEY:
value *= u256(1000000000000000); value *= u256(1000000000000000);
break; break;
case Literal::ethSubDenomination::ETHER: case Literal::SubDenomination::ETHER:
value *= u256(1000000000000000000); value *= u256(1000000000000000000);
break; break;
} }

8
test/SolidityScanner.cpp

@ -258,10 +258,10 @@ BOOST_AUTO_TEST_CASE(comments_mixed_in_sequence)
BOOST_AUTO_TEST_CASE(ether_subdenominations) BOOST_AUTO_TEST_CASE(ether_subdenominations)
{ {
Scanner scanner(CharStream("wei szabo finney ether")); Scanner scanner(CharStream("wei szabo finney ether"));
BOOST_CHECK_EQUAL(scanner.getCurrentToken(), Token::ETH_SUB_WEI); BOOST_CHECK_EQUAL(scanner.getCurrentToken(), Token::SubWei);
BOOST_CHECK_EQUAL(scanner.next(), Token::ETH_SUB_SZABO); BOOST_CHECK_EQUAL(scanner.next(), Token::SubSzabo);
BOOST_CHECK_EQUAL(scanner.next(), Token::ETH_SUB_FINNEY); BOOST_CHECK_EQUAL(scanner.next(), Token::SubFinney);
BOOST_CHECK_EQUAL(scanner.next(), Token::ETH_SUB_ETHER); BOOST_CHECK_EQUAL(scanner.next(), Token::SubEther);
} }
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()

Loading…
Cancel
Save