Skip to content

Commit b61691a

Browse files
authored
Revert "For loops (#21)"
This reverts commit 03488cb.
1 parent 03488cb commit b61691a

File tree

6 files changed

+8
-125
lines changed

6 files changed

+8
-125
lines changed

src/solidity-syntax.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ In each code block, various statments and nested blocks can be present.
168168
| VariableDeclarationStatement
169169
| ExpressionStatement
170170
| IfStatement
171-
| WhileStatement
171+
| ForStatement
172172
| EmitStatement
173173
| ReturnStatement
174174
| RevertStatement
@@ -188,9 +188,10 @@ Following is a list of supported statements.
188188
syntax IfStatement ::= "if" "(" Expression ")" Statement [strict(1)]
189189
| "if" "(" Expression ")" Statement "else" Statement [avoid, strict(1)]
190190
191-
syntax WhileStatement ::= "while" "(" Expression ")" Statement
192-
syntax Block ::= "for" "(" VariableDeclarationStatement Expression ";" Expression ")" Statement [function]
193-
rule for (Init Cond ; Post) Body => { Init while(Cond) { Body Post; } }
191+
syntax ForStatement ::= "for" "(" InitStatement ConditionStatement PostLoopStatement ")" Statement
192+
syntax InitStatement ::= VariableDeclarationStatement | ExpressionStatement | ";"
193+
syntax ConditionStatement ::= ExpressionStatement | ";"
194+
syntax PostLoopStatement ::= Expression | ""
194195
195196
syntax EmitStatement ::= "emit" Expression "(" CallArgumentList ")" ";" [strict(2)]
196197

src/statement.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,4 @@ module SOLIDITY-STATEMENT
4545
rule <k> restoreEnv(E) => .K ...</k>
4646
<env> _ => E </env>
4747
48-
// while statement
49-
rule while (Cond) Body => if (Cond) {Body while(Cond) Body} else {.Statements}
50-
5148
endmodule

test/regression/for.ref

Lines changed: 0 additions & 100 deletions
This file was deleted.

test/regression/for.sol

Lines changed: 0 additions & 14 deletions
This file was deleted.

test/regression/for.txn

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/regression/function.ref

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -987,7 +987,7 @@
987987
.List
988988
</contract-fn-return-names>
989989
<contract-fn-body>
990-
{ 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
990+
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
991991
</contract-fn-body>
992992
</contract-fn> <contract-fn>
993993
<contract-fn-id>
@@ -1213,7 +1213,7 @@
12131213
ListItem ( amounts )
12141214
</contract-fn-return-names>
12151215
<contract-fn-body>
1216-
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
1216+
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
12171217
</contract-fn-body>
12181218
</contract-fn> <contract-fn>
12191219
<contract-fn-id>
@@ -1237,7 +1237,7 @@
12371237
ListItem ( amounts )
12381238
</contract-fn-return-names>
12391239
<contract-fn-body>
1240-
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
1240+
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
12411241
</contract-fn-body>
12421242
</contract-fn> <contract-fn>
12431243
<contract-fn-id>

0 commit comments

Comments
 (0)