Browse Source

Addressing issues in Enum style fix

cl-refactor
Lefteris Karapetsas 10 years ago
parent
commit
c68f7f2790
  1. 4
      libsolidity/AST.cpp
  2. 10
      libsolidity/ExpressionCompiler.cpp
  3. 8
      libsolidity/Scanner.cpp
  4. 1
      libsolidity/Token.cpp
  5. 80
      libsolidity/Token.h
  6. 4
      libsolidity/Types.h
  7. 2
      test/SolidityScanner.cpp

4
libsolidity/AST.cpp

@ -449,7 +449,7 @@ void Expression::requireLValue()
void UnaryOperation::checkTypeRequirements() void UnaryOperation::checkTypeRequirements()
{ {
// INC, DEC, ADD, SUB, NOT, BitNot, DELETE // Inc, Dec, Add, Sub, Not, BitNot, Delete
m_subExpression->checkTypeRequirements(); m_subExpression->checkTypeRequirements();
if (m_operator == Token::Value::Inc || m_operator == Token::Value::Dec || m_operator == Token::Value::Delete) if (m_operator == Token::Value::Inc || m_operator == Token::Value::Dec || m_operator == Token::Value::Delete)
m_subExpression->requireLValue(); m_subExpression->requireLValue();
@ -553,7 +553,7 @@ void FunctionCall::checkTypeRequirements()
bool FunctionCall::isTypeConversion() const bool FunctionCall::isTypeConversion() const
{ {
return m_expression->getType()->getCategory() == Type::Category::Type; return m_expression->getType()->getCategory() == Type::Category::TypeType;
} }
void NewExpression::checkTypeRequirements() void NewExpression::checkTypeRequirements()

10
libsolidity/ExpressionCompiler.cpp

@ -483,7 +483,7 @@ void ExpressionCompiler::endVisit(MemberAccess const& _memberAccess)
m_currentLValue.retrieveValueIfLValueNotRequested(_memberAccess); m_currentLValue.retrieveValueIfLValueNotRequested(_memberAccess);
break; break;
} }
case Type::Category::Type: case Type::Category::TypeType:
{ {
TypeType const& type = dynamic_cast<TypeType const&>(*_memberAccess.getExpression().getType()); TypeType const& type = dynamic_cast<TypeType const&>(*_memberAccess.getExpression().getType());
if (type.getMembers().getMemberType(member)) if (type.getMembers().getMemberType(member))
@ -583,10 +583,10 @@ void ExpressionCompiler::appendAndOrOperatorCode(BinaryOperation const& _binaryO
void ExpressionCompiler::appendCompareOperatorCode(Token::Value _operator, Type const& _type) void ExpressionCompiler::appendCompareOperatorCode(Token::Value _operator, Type const& _type)
{ {
if (_operator == Token::Equals || _operator == Token::NotEquals) if (_operator == Token::Equal || _operator == Token::NotEqual)
{ {
m_context << eth::Instruction::EQ; m_context << eth::Instruction::EQ;
if (_operator == Token::NotEquals) if (_operator == Token::NotEqual)
m_context << eth::Instruction::ISZERO; m_context << eth::Instruction::ISZERO;
} }
else else
@ -596,11 +596,11 @@ void ExpressionCompiler::appendCompareOperatorCode(Token::Value _operator, Type
switch (_operator) switch (_operator)
{ {
case Token::GreaterThanOrEquals: case Token::GreaterThanOrEqual:
m_context << (c_isSigned ? eth::Instruction::SLT : eth::Instruction::LT) m_context << (c_isSigned ? eth::Instruction::SLT : eth::Instruction::LT)
<< eth::Instruction::ISZERO; << eth::Instruction::ISZERO;
break; break;
case Token::LessThanOrEquals: case Token::LessThanOrEqual:
m_context << (c_isSigned ? eth::Instruction::SGT : eth::Instruction::GT) m_context << (c_isSigned ? eth::Instruction::SGT : eth::Instruction::GT)
<< eth::Instruction::ISZERO; << eth::Instruction::ISZERO;
break; break;

8
libsolidity/Scanner.cpp

@ -401,7 +401,7 @@ void Scanner::scanToken()
// < <= << <<= // < <= << <<=
advance(); advance();
if (m_char == '=') if (m_char == '=')
token = selectToken(Token::LessThanOrEquals); token = selectToken(Token::LessThanOrEqual);
else if (m_char == '<') else if (m_char == '<')
token = selectToken('=', Token::AssignShl, Token::SHL); token = selectToken('=', Token::AssignShl, Token::SHL);
else else
@ -411,7 +411,7 @@ void Scanner::scanToken()
// > >= >> >>= >>> >>>= // > >= >> >>= >>> >>>=
advance(); advance();
if (m_char == '=') if (m_char == '=')
token = selectToken(Token::GreaterThanOrEquals); token = selectToken(Token::GreaterThanOrEqual);
else if (m_char == '>') else if (m_char == '>')
{ {
// >> >>= >>> >>>= // >> >>= >>> >>>=
@ -430,7 +430,7 @@ void Scanner::scanToken()
// = == => // = == =>
advance(); advance();
if (m_char == '=') if (m_char == '=')
token = selectToken(Token::Equals); token = selectToken(Token::Equal);
else if (m_char == '>') else if (m_char == '>')
token = selectToken(Token::Arrow); token = selectToken(Token::Arrow);
else else
@ -440,7 +440,7 @@ void Scanner::scanToken()
// ! != // ! !=
advance(); advance();
if (m_char == '=') if (m_char == '=')
token = selectToken(Token::NotEquals); token = selectToken(Token::NotEqual);
else else
token = Token::Not; token = Token::Not;
break; break;

1
libsolidity/Token.cpp

@ -79,7 +79,6 @@ int8_t const Token::m_precedence[NUM_TOKENS] =
char const Token::m_tokenType[] = char const Token::m_tokenType[] =
{ {
TOKEN_LIST(KT, KK) TOKEN_LIST(KT, KK)
}; };
Token::Value Token::fromIdentifierOrKeyword(const std::string& _name) Token::Value Token::fromIdentifierOrKeyword(const std::string& _name)
{ {

80
libsolidity/Token.h

@ -122,12 +122,12 @@ namespace solidity
/* Compare operators sorted by precedence. */ \ /* Compare operators sorted by precedence. */ \
/* IsCompareOp() relies on this block of enum values */ \ /* IsCompareOp() relies on this block of enum values */ \
/* being contiguous and sorted in the same order! */ \ /* being contiguous and sorted in the same order! */ \
T(Equals, "==", 6) \ T(Equal, "==", 6) \
T(NotEquals, "!=", 6) \ T(NotEqual, "!=", 6) \
T(LessThan, "<", 7) \ T(LessThan, "<", 7) \
T(GreaterThan, ">", 7) \ T(GreaterThan, ">", 7) \
T(LessThanOrEquals, "<=", 7) \ T(LessThanOrEqual, "<=", 7) \
T(GreaterThanOrEquals, ">=", 7) \ T(GreaterThanOrEqual, ">=", 7) \
K(In, "in", 7) \ K(In, "in", 7) \
\ \
/* Unary operators. */ \ /* Unary operators. */ \
@ -183,7 +183,7 @@ namespace solidity
K(Int24, "int24", 0) \ K(Int24, "int24", 0) \
K(Int32, "int32", 0) \ K(Int32, "int32", 0) \
K(Int40, "int40", 0) \ K(Int40, "int40", 0) \
K(INT48, "int48", 0) \ K(Int48, "int48", 0) \
K(Int56, "int56", 0) \ K(Int56, "int56", 0) \
K(Int64, "int64", 0) \ K(Int64, "int64", 0) \
K(Int72, "int72", 0) \ K(Int72, "int72", 0) \
@ -210,39 +210,39 @@ namespace solidity
K(Int240, "int240", 0) \ K(Int240, "int240", 0) \
K(Int248, "int248", 0) \ K(Int248, "int248", 0) \
K(Int256, "int256", 0) \ K(Int256, "int256", 0) \
K(Uint, "uint", 0) \ K(UInt, "uint", 0) \
K(Uint8, "uint8", 0) \ K(UInt8, "uint8", 0) \
K(Uint16, "uint16", 0) \ K(UInt16, "uint16", 0) \
K(Uint24, "uint24", 0) \ K(UInt24, "uint24", 0) \
K(Uint32, "uint32", 0) \ K(UInt32, "uint32", 0) \
K(Uint40, "uint40", 0) \ K(UInt40, "uint40", 0) \
K(Uint48, "uint48", 0) \ K(UInt48, "uint48", 0) \
K(Uint56, "uint56", 0) \ K(UInt56, "uint56", 0) \
K(Uint64, "uint64", 0) \ K(UInt64, "uint64", 0) \
K(Uint72, "uint72", 0) \ K(UInt72, "uint72", 0) \
K(Uint80, "uint80", 0) \ K(UInt80, "uint80", 0) \
K(Uint88, "uint88", 0) \ K(UInt88, "uint88", 0) \
K(Uint96, "uint96", 0) \ K(UInt96, "uint96", 0) \
K(Uint104, "uint104", 0) \ K(UInt104, "uint104", 0) \
K(Uint112, "uint112", 0) \ K(UInt112, "uint112", 0) \
K(Uint120, "uint120", 0) \ K(UInt120, "uint120", 0) \
K(Uint128, "uint128", 0) \ K(UInt128, "uint128", 0) \
K(Uint136, "uint136", 0) \ K(UInt136, "uint136", 0) \
K(Uint144, "uint144", 0) \ K(UInt144, "uint144", 0) \
K(Uint152, "uint152", 0) \ K(UInt152, "uint152", 0) \
K(Uint160, "uint160", 0) \ K(UInt160, "uint160", 0) \
K(Uint168, "uint168", 0) \ K(UInt168, "uint168", 0) \
K(Uint176, "uint178", 0) \ K(UInt176, "uint178", 0) \
K(Uint184, "uint184", 0) \ K(UInt184, "uint184", 0) \
K(Uint192, "uint192", 0) \ K(UInt192, "uint192", 0) \
K(Uint200, "uint200", 0) \ K(UInt200, "uint200", 0) \
K(Uint208, "uint208", 0) \ K(UInt208, "uint208", 0) \
K(Uint216, "uint216", 0) \ K(UInt216, "uint216", 0) \
K(Uint224, "uint224", 0) \ K(UInt224, "uint224", 0) \
K(Uint232, "uint232", 0) \ K(UInt232, "uint232", 0) \
K(Uint240, "uint240", 0) \ K(UInt240, "uint240", 0) \
K(Uint248, "uint248", 0) \ K(UInt248, "uint248", 0) \
K(Uint256, "uint256", 0) \ K(UInt256, "uint256", 0) \
K(Hash, "hash", 0) \ K(Hash, "hash", 0) \
K(Hash8, "hash8", 0) \ K(Hash8, "hash8", 0) \
K(Hash16, "hash16", 0) \ K(Hash16, "hash16", 0) \
@ -363,9 +363,9 @@ public:
static bool isAssignmentOp(Value tok) { return Assign <= tok && tok <= AssignMod; } static bool isAssignmentOp(Value tok) { return Assign <= tok && tok <= AssignMod; }
static bool isBinaryOp(Value op) { return Comma <= op && op <= Mod; } static bool isBinaryOp(Value op) { return Comma <= op && op <= Mod; }
static bool isCommutativeOp(Value op) { return op == BitOr || op == BitXor || op == BitAnd || static bool isCommutativeOp(Value op) { return op == BitOr || op == BitXor || op == BitAnd ||
op == Add || op == Mul || op == Equals || op == NotEquals; } op == Add || op == Mul || op == Equal || op == NotEqual; }
static bool isArithmeticOp(Value op) { return Add <= op && op <= Mod; } static bool isArithmeticOp(Value op) { return Add <= op && op <= Mod; }
static bool isCompareOp(Value op) { return Equals <= op && op <= In; } static bool isCompareOp(Value op) { return Equal <= op && op <= In; }
static Value AssignmentToBinaryOp(Value op) static Value AssignmentToBinaryOp(Value op)
{ {

4
libsolidity/Types.h

@ -78,7 +78,7 @@ public:
{ {
Integer, IntegerConstant, Bool, Real, Integer, IntegerConstant, Bool, Real,
String, Contract, Struct, Function, String, Contract, Struct, Function,
Mapping, Void, Type, Modifier, Magic Mapping, Void, TypeType, Modifier, Magic
}; };
///@{ ///@{
@ -478,7 +478,7 @@ public:
class TypeType: public Type class TypeType: public Type
{ {
public: public:
virtual Category getCategory() const override { return Category::Type; } virtual Category getCategory() const override { return Category::TypeType; }
explicit TypeType(TypePointer const& _actualType, ContractDefinition const* _currentContract = nullptr): explicit TypeType(TypePointer const& _actualType, ContractDefinition const* _currentContract = nullptr):
m_actualType(_actualType), m_currentContract(_currentContract) {} m_actualType(_actualType), m_currentContract(_currentContract) {}
TypePointer const& getActualType() const { return m_actualType; } TypePointer const& getActualType() const { return m_actualType; }

2
test/SolidityScanner.cpp

@ -147,7 +147,7 @@ BOOST_AUTO_TEST_CASE(ambiguities)
{ {
// test scanning of some operators which need look-ahead // test scanning of some operators which need look-ahead
Scanner scanner(CharStream("<=""<""+ +=a++ =>""<<")); Scanner scanner(CharStream("<=""<""+ +=a++ =>""<<"));
BOOST_CHECK_EQUAL(scanner.getCurrentToken(), Token::LessThanOrEquals); BOOST_CHECK_EQUAL(scanner.getCurrentToken(), Token::LessThanOrEqual);
BOOST_CHECK_EQUAL(scanner.next(), Token::LessThan); BOOST_CHECK_EQUAL(scanner.next(), Token::LessThan);
BOOST_CHECK_EQUAL(scanner.next(), Token::Add); BOOST_CHECK_EQUAL(scanner.next(), Token::Add);
BOOST_CHECK_EQUAL(scanner.next(), Token::AssignAdd); BOOST_CHECK_EQUAL(scanner.next(), Token::AssignAdd);

Loading…
Cancel
Save