Skip to content

Commit

Permalink
Revert "For loops (#21)"
Browse files Browse the repository at this point in the history
This reverts commit 03488cb.
  • Loading branch information
dwightguth authored Sep 3, 2024
1 parent 03488cb commit b61691a
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 125 deletions.
9 changes: 5 additions & 4 deletions src/solidity-syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ In each code block, various statments and nested blocks can be present.
| VariableDeclarationStatement
| ExpressionStatement
| IfStatement
| WhileStatement
| ForStatement
| EmitStatement
| ReturnStatement
| RevertStatement
Expand All @@ -188,9 +188,10 @@ Following is a list of supported statements.
syntax IfStatement ::= "if" "(" Expression ")" Statement [strict(1)]
| "if" "(" Expression ")" Statement "else" Statement [avoid, strict(1)]
syntax WhileStatement ::= "while" "(" Expression ")" Statement
syntax Block ::= "for" "(" VariableDeclarationStatement Expression ";" Expression ")" Statement [function]
rule for (Init Cond ; Post) Body => { Init while(Cond) { Body Post; } }
syntax ForStatement ::= "for" "(" InitStatement ConditionStatement PostLoopStatement ")" Statement
syntax InitStatement ::= VariableDeclarationStatement | ExpressionStatement | ";"
syntax ConditionStatement ::= ExpressionStatement | ";"
syntax PostLoopStatement ::= Expression | ""
syntax EmitStatement ::= "emit" Expression "(" CallArgumentList ")" ";" [strict(2)]
Expand Down
3 changes: 0 additions & 3 deletions src/statement.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,4 @@ module SOLIDITY-STATEMENT
rule <k> restoreEnv(E) => .K ...</k>
<env> _ => E </env>
// while statement
rule while (Cond) Body => if (Cond) {Body while(Cond) Body} else {.Statements}
endmodule
100 changes: 0 additions & 100 deletions test/regression/for.ref

This file was deleted.

14 changes: 0 additions & 14 deletions test/regression/for.sol

This file was deleted.

1 change: 0 additions & 1 deletion test/regression/for.txn

This file was deleted.

6 changes: 3 additions & 3 deletions test/regression/function.ref
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,7 @@
.List
</contract-fn-return-names>
<contract-fn-body>
{ uint256 i ; while ( i < path . length - 1 ) { { address input = path [ i ] ; address output = path [ i + 1 ] ; address [ ] memory tokens = uniswapV2Library_sortTokens ( input , output , .TypedVals ) ; uint256 amountOut = amounts [ i + 1 ] ; uint256 amount0Out = input == tokens [ 0 ] ? uint256 ( 0 , .TypedVals ) : amountOut ; uint256 amount1Out = input == tokens [ 0 ] ? amountOut : uint256 ( 0 , .TypedVals ) ; address to = i < path . length - 2 ? uniswapV2Library_pairFor ( output , path [ i + 2 ] , .TypedVals ) : _to ; UniswapV2Pair ( uniswapV2Library_pairFor ( input , output , .TypedVals ) , .TypedVals ) . swap ( amount0Out , amount1Out , to , .TypedVals ) ; .Statements } i ++ ; .Statements } .Statements } .Statements
for ( uint256 i ; i < path . length - 1 ; i ++ ) { address input = path [ i ] ; address output = path [ i + 1 ] ; address [ ] memory tokens = uniswapV2Library_sortTokens ( input , output , .TypedVals ) ; uint256 amountOut = amounts [ i + 1 ] ; uint256 amount0Out = input == tokens [ 0 ] ? uint256 ( 0 , .TypedVals ) : amountOut ; uint256 amount1Out = input == tokens [ 0 ] ? amountOut : uint256 ( 0 , .TypedVals ) ; address to = i < path . length - 2 ? uniswapV2Library_pairFor ( output , path [ i + 2 ] , .TypedVals ) : _to ; UniswapV2Pair ( uniswapV2Library_pairFor ( input , output , .TypedVals ) , .TypedVals ) . swap ( amount0Out , amount1Out , to , .TypedVals ) ; .Statements } .Statements
</contract-fn-body>
</contract-fn> <contract-fn>
<contract-fn-id>
Expand Down Expand Up @@ -1213,7 +1213,7 @@
ListItem ( amounts )
</contract-fn-return-names>
<contract-fn-body>
require ( path . length >= 2 , "UniswapV2Library: INVALID_PATH" , .TypedVals ) ; amounts = new uint256 [ ] ( path . length , .TypedVals ) ; amounts [ amounts . length - 1 ] = amountOut ; { uint256 i = path . length - 1 ; while ( i > 0 ) { { uint256 [ ] memory reserves = uniswapV2Library_getReserves ( path [ i - 1 ] , path [ i ] , .TypedVals ) ; amounts [ i - 1 ] = uniswapV2Library_getAmountIn ( amounts [ i ] , reserves [ 0 ] , reserves [ 1 ] , .TypedVals ) ; .Statements } i -- ; .Statements } .Statements } .Statements
require ( path . length >= 2 , "UniswapV2Library: INVALID_PATH" , .TypedVals ) ; amounts = new uint256 [ ] ( path . length , .TypedVals ) ; amounts [ amounts . length - 1 ] = amountOut ; for ( uint256 i = path . length - 1 ; i > 0 ; i -- ) { uint256 [ ] memory reserves = uniswapV2Library_getReserves ( path [ i - 1 ] , path [ i ] , .TypedVals ) ; amounts [ i - 1 ] = uniswapV2Library_getAmountIn ( amounts [ i ] , reserves [ 0 ] , reserves [ 1 ] , .TypedVals ) ; .Statements } .Statements
</contract-fn-body>
</contract-fn> <contract-fn>
<contract-fn-id>
Expand All @@ -1237,7 +1237,7 @@
ListItem ( amounts )
</contract-fn-return-names>
<contract-fn-body>
require ( path . length >= 2 , "UniswapV2Library: INVALID_PATH" , .TypedVals ) ; amounts = new uint256 [ ] ( path . length , .TypedVals ) ; amounts [ 0 ] = amountIn ; { uint256 i ; while ( i < path . length - 1 ) { { uint256 [ ] memory reserves = uniswapV2Library_getReserves ( path [ i ] , path [ i + 1 ] , .TypedVals ) ; amounts [ i + 1 ] = uniswapV2Library_getAmountOut ( amounts [ i ] , reserves [ 0 ] , reserves [ 1 ] , .TypedVals ) ; .Statements } i ++ ; .Statements } .Statements } .Statements
require ( path . length >= 2 , "UniswapV2Library: INVALID_PATH" , .TypedVals ) ; amounts = new uint256 [ ] ( path . length , .TypedVals ) ; amounts [ 0 ] = amountIn ; for ( uint256 i ; i < path . length - 1 ; i ++ ) { uint256 [ ] memory reserves = uniswapV2Library_getReserves ( path [ i ] , path [ i + 1 ] , .TypedVals ) ; amounts [ i + 1 ] = uniswapV2Library_getAmountOut ( amounts [ i ] , reserves [ 0 ] , reserves [ 1 ] , .TypedVals ) ; .Statements } .Statements
</contract-fn-body>
</contract-fn> <contract-fn>
<contract-fn-id>
Expand Down

0 comments on commit b61691a

Please sign in to comment.