Skip to content

Removed SHR (>>>) operator #15848

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions docs/grammar/SolidityLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ AssignBitXor: '^=';
AssignBitAnd: '&=';
AssignShl: '<<=';
AssignSar: '>>=';
AssignShr: '>>>=';
AssignAdd: '+=';
AssignSub: '-=';
AssignMul: '*=';
Expand All @@ -140,7 +139,6 @@ BitXor: '^';
BitAnd: '&';
Shl: '<<';
Sar: '>>';
Shr: '>>>';
Add: '+';
Sub: '-';
Mul: '*';
Expand Down
2 changes: 1 addition & 1 deletion docs/grammar/SolidityParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ expression:
;

//@doc:inline
assignOp: Assign | AssignBitOr | AssignBitXor | AssignBitAnd | AssignShl | AssignSar | AssignShr | AssignAdd | AssignSub | AssignMul | AssignDiv | AssignMod;
assignOp: Assign | AssignBitOr | AssignBitXor | AssignBitAnd | AssignShl | AssignSar | AssignAdd | AssignSub | AssignMul | AssignDiv | AssignMod;
tupleExpression: LParen (expression? ( Comma expression?)* ) RParen;
/**
* An inline array expression denotes a statically sized array of the common type of the contained expressions.
Expand Down
6 changes: 2 additions & 4 deletions liblangutil/Scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -562,18 +562,16 @@ void Scanner::scanToken()
token = Token::LessThan;
break;
case '>':
// > >= >> >>= >>> >>>=
// > >= >> >>=
advance();
if (m_char == '=')
token = selectToken(Token::GreaterThanOrEqual);
else if (m_char == '>')
{
// >> >>= >>> >>>=
// >> >>=
advance();
if (m_char == '=')
token = selectToken(Token::AssignSar);
else if (m_char == '>')
token = selectToken('=', Token::AssignShr, Token::SHR);
else
token = Token::SAR;
}
Expand Down
4 changes: 1 addition & 3 deletions liblangutil/Token.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ namespace solidity::langutil
T(AssignBitAnd, "&=", 2) \
T(AssignShl, "<<=", 2) \
T(AssignSar, ">>=", 2) \
T(AssignShr, ">>>=", 2) \
T(AssignAdd, "+=", 2) \
T(AssignSub, "-=", 2) \
T(AssignMul, "*=", 2) \
Expand All @@ -111,7 +110,6 @@ namespace solidity::langutil
T(BitAnd, "&", 10) \
T(SHL, "<<", 11) \
T(SAR, ">>", 11) \
T(SHR, ">>>", 11) \
T(Add, "+", 12) \
T(Sub, "-", 12) \
T(Mul, "*", 13) \
Expand Down Expand Up @@ -314,7 +312,7 @@ namespace TokenTraits
constexpr bool isBooleanOp(Token op) { return (Token::Or <= op && op <= Token::And) || op == Token::Not; }
constexpr bool isUnaryOp(Token op) { return (Token::Not <= op && op <= Token::Delete) || op == Token::Sub; }
constexpr bool isCountOp(Token op) { return op == Token::Inc || op == Token::Dec; }
constexpr bool isShiftOp(Token op) { return (Token::SHL <= op) && (op <= Token::SHR); }
constexpr bool isShiftOp(Token op) { return op == Token::SHL; }
constexpr bool isVariableVisibilitySpecifier(Token op) { return op == Token::Public || op == Token::Private || op == Token::Internal; }
constexpr bool isVisibilitySpecifier(Token op) { return isVariableVisibilitySpecifier(op) || op == Token::External; }
constexpr bool isLocationSpecifier(Token op) { return op == Token::Memory || op == Token::Storage || op == Token::CallData; }
Expand Down
6 changes: 2 additions & 4 deletions libsolidity/ast/Types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -573,10 +573,8 @@ namespace

bool isValidShiftAndAmountType(Token _operator, Type const& _shiftAmountType)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
bool isValidShiftAndAmountType(Token _operator, Type const& _shiftAmountType)
bool isValidShiftAndAmountType(Token, Type const& _shiftAmountType)

The build failures in CI are due to warnings about an unused variable here. Not giving it a name would solve that, but even better would be to remove the argument entirely (i.e. also on the call-sites).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback , will make the required changes.

{
// Disable >>> here.
if (_operator == Token::SHR)
return false;
else if (IntegerType const* otherInt = dynamic_cast<decltype(otherInt)>(&_shiftAmountType))

if (IntegerType const* otherInt = dynamic_cast<decltype(otherInt)>(&_shiftAmountType))
return !otherInt->isSigned();
else if (RationalNumberType const* otherRat = dynamic_cast<decltype(otherRat)>(&_shiftAmountType))
return !otherRat->isFractional() && otherRat->integerType() && !otherRat->integerType()->isSigned();
Expand Down
1 change: 0 additions & 1 deletion libsolidity/codegen/ExpressionCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2662,7 +2662,6 @@ void ExpressionCompiler::appendShiftOperatorCode(Token _operator, Type const& _v

}
break;
case Token::SHR:
default:
solAssert(false, "Unknown shift operator.");
}
Expand Down
5 changes: 0 additions & 5 deletions libsolidity/formal/SMTEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1941,7 +1941,6 @@ smtutil::Expression SMTEncoder::bitwiseOperation(
Token::BitOr,
Token::BitXor,
Token::SHL,
Token::SHR,
Token::SAR
};
solAssert(validOperators.count(_op), "");
Expand All @@ -1967,9 +1966,6 @@ smtutil::Expression SMTEncoder::bitwiseOperation(
case Token::SHL:
result = bvLeft << bvRight;
break;
case Token::SHR:
result = bvLeft >> bvRight;
break;
case Token::SAR:
result = isSigned ?
smtutil::Expression::ashr(bvLeft, bvRight) :
Expand Down Expand Up @@ -2233,7 +2229,6 @@ smtutil::Expression SMTEncoder::compoundAssignment(Assignment const& _assignment
{Token::AssignBitOr, Token::BitOr},
{Token::AssignBitXor, Token::BitXor},
{Token::AssignShl, Token::SHL},
{Token::AssignShr, Token::SHR},
{Token::AssignSar, Token::SAR}
};
Token op = _assignment.assignmentOperator();
Expand Down
6 changes: 2 additions & 4 deletions test/liblangutil/Scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,8 @@ BOOST_AUTO_TEST_CASE(locations)
BOOST_AUTO_TEST_CASE(ambiguities)
{
// test scanning of some operators which need look-ahead
TestScanner scanner("<=" "<" "+ +=a++ =>" "<<" ">>" " >>=" ">>>" ">>>=" " >>>>>=><<=");
TestScanner scanner("<=" "<" "+ +=a++ =>" "<<" ">>" " >>=");

BOOST_CHECK_EQUAL(scanner.currentToken(), Token::LessThanOrEqual);
BOOST_CHECK_EQUAL(scanner.next(), Token::LessThan);
BOOST_CHECK_EQUAL(scanner.next(), Token::Add);
Expand All @@ -465,10 +466,7 @@ BOOST_AUTO_TEST_CASE(ambiguities)
BOOST_CHECK_EQUAL(scanner.next(), Token::SHL);
BOOST_CHECK_EQUAL(scanner.next(), Token::SAR);
BOOST_CHECK_EQUAL(scanner.next(), Token::AssignSar);
BOOST_CHECK_EQUAL(scanner.next(), Token::SHR);
BOOST_CHECK_EQUAL(scanner.next(), Token::AssignShr);
// the last "monster" token combination
BOOST_CHECK_EQUAL(scanner.next(), Token::SHR);
BOOST_CHECK_EQUAL(scanner.next(), Token::AssignSar);
BOOST_CHECK_EQUAL(scanner.next(), Token::GreaterThan);
BOOST_CHECK_EQUAL(scanner.next(), Token::AssignShl);
Expand Down