Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

roadriverrail
Copy link
Contributor

This commit adds support for a standard do while ;
form of statement. While loops were already being supported; supporting
a do/while loop mostly involves reusing code from while loops but putting
the conditional checking last.

This commit resolves issue #766

@chriseth
Copy link
Contributor

chriseth commented Aug 1, 2016

Thanks for the pull request and your interest in the project! We have to think about whether introducing do-while-loops is something we want to be part of the language or if they are an unnecessary complication. If you want to work on features that have already been agreed by the community, please talk to a team member in https://gitter.im/ethereum/solidity

@chriseth
Copy link
Contributor

Will change this to re-use the existing while loop ast node.

@roadriverrail
Copy link
Contributor Author

Were you going to do that yourself in the next couple of days? I have a road trip coming up tomorrow, and I might have the free evening or two to do that.

@chriseth
Copy link
Contributor

oh wow, even the better :-)
So the idea is to re-use the while loop ast node to reduce complexity and add a flag to it telling whether it is a do-while or a while-do-loop. It is important that this flag is also output for the two ast outputs.

@roadriverrail
Copy link
Contributor Author

Yeah, as soon as I saw your comment, I figured that's what you had in mind. I haven't looked at solc since I wrote this (major life changes), but I assume you already have some sort of context variable that gets passed around that I could store the flag in. Most compilers do.

@chriseth
Copy link
Contributor

At the point where the ast node is created in the parser, this flag should be stored inside the ast node as a regular class member.

@roadriverrail
Copy link
Contributor Author

Got it. Makes perfect sense.

On Fri, Oct 28, 2016 at 9:22 AM chriseth [email protected] wrote:

At the point where the ast node is created in the parser, this flag should
be stored inside the ast node as a regular class member.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#768 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAlhYKDAV71YbpyEQneCcuqeKYuzUJ1qks5q4iFAgaJpZM4JYwLU
.

@roadriverrail
Copy link
Contributor Author

Okay; this appears to be functionally comparable code without the extra class. Also, I saw that Why3 does not appear to support do-while, so I simulate a do-while loop for its output. I'm going to have to look at a rebase next, since the commit from main that this branch is based on has a broken "ast" and "ast-json" output.

ASTPointer<Expression> const& _condition,
ASTPointer<Statement> const& _body
ASTPointer<Statement> const& _body,
bool _isDoWhile
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use tabs for indentation.

bool ASTJsonConverter::visit(WhileStatement const& _node)
{
addJsonNode(_node, "WhileStatement", {}, true);
addJsonNode(_node,
Copy link
Contributor

Choose a reason for hiding this comment

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

Code style should be

addJsonNode(
    _node,
    _node.isDoWhile()  ?...,
    true
);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry for the style break. Did I miss the style guide somewhere? Or do you follow a well-known one by convention?

ASTPointer<Expression> condition = parseExpression();
expectToken(Token::RParen);
expectToken(Token::Semicolon);
nodeFactory.setEndPositionFromNode(body);
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be replaced by a call to nodeFactory.setEndPosition() right before expecting the semicolon.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed; that certainly explained some funny output I was seeing in the --asm dumps I normally use to confirm the results.


Expression const& condition() const { return *m_condition; }
Statement const& body() const { return *m_body; }
bool isDoWhile() const { return m_isDoWhile; }
Copy link
Contributor

Choose a reason for hiding this comment

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

Here are still some spaces, probably in more places.

@chriseth
Copy link
Contributor

chriseth commented Nov 8, 2016

Thanks! The last thing that is missing now is an entry into the changelog file and some mention of this feature in the documentation. I can also do that after merging this PR if you want.
Oh and it seems we have a conflict in grammar.txt :-(

@roadriverrail
Copy link
Contributor Author

Yeah, I'll do the pickup merging on grammar.txt. I can get the changelog
and docs updated, too. Also, do you have some sort of testing framework I
should look into writing some tests for?

On Tue, Nov 8, 2016 at 9:07 AM chriseth [email protected] wrote:

Thanks! The last thing that is missing now is an entry into the changelog
file and some mention of this feature in the documentation. I can also do
that after merging this PR if you want.
Oh and it seems we have a conflict in grammar.txt :-(


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#768 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAlhYDneCGvCORSA7Z8nWA7KHUeukOaxks5q8KxJgaJpZM4JYwLU
.

@chriseth
Copy link
Contributor

chriseth commented Nov 8, 2016

Oh of course, totally forgot about tests. I think it is enough to add an end to end test, so take a look at the file SolidityEndToEndTest.cpp. You can probably copy an example there. Running the tests is a bit tricky, because you need an eth node. Start it with eth --test -d /tmp/test and then run soltest -- --ipcpath /tmp/test/geth.ipc (or just run scripts/test.sh).

@roadriverrail
Copy link
Contributor Author

Since we're mostly done with the CR process, I squashed the commits, updated the Changelog, and added some mention of "do" to the docs, though documentation of the control structures is pretty light.

@roadriverrail
Copy link
Contributor Author

Okay. I should be able to add a test. Tonight's a pretty tight schedule, but Wednesday or Thursday should be a little bit better.

@chriseth
Copy link
Contributor

chriseth commented Nov 9, 2016

That's great, thanks!

@roadriverrail
Copy link
Contributor Author

Okay. I added a basic unit test modeled on the while loop test. I see it runs the test repeatedly with different values of n and checks it against what you expect from C++, and that seems suitable enough. I could get fancier, I suppose, with nesting and all that jazz, if there's a need.

{
u256 nfac = 1;
u256 i = 2;
do
Copy link
Contributor

Choose a reason for hiding this comment

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

Please don't use spaces for indentation.

do
{
nfac *= i++;
} while (i <= n);
Copy link
Contributor

Choose a reason for hiding this comment

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

Please put the while on the next line.

This commit adds support for a standard do <statement> while <expr>;
form of statement.  While loops were already being supported; supporting
a do/while loop mostly involves reusing code from while loops but putting
the conditional checking last.
@roadriverrail
Copy link
Contributor Author

Sincerely sorry about the style violations; I thought I checked every line for spaces last night, but it was late. Fixed.

@chriseth
Copy link
Contributor

Wonderful, thanks a lot!

@chriseth chriseth merged commit a40dcfe into argotorg:develop Nov 10, 2016
@roadriverrail
Copy link
Contributor Author

Thanks for the patience in the review process. solc is pretty easy to work on, so I'm hoping this will not be the last time you'll be seeing a PR from me.

@chriseth
Copy link
Contributor

That's great to hear! The issues marked as "soon" and/or "up-for-grabs" are probably the best to work on. If in doubt, ask on http://gitter.im/ethereum/solidity or contact me at [email protected]

@roadriverrail
Copy link
Contributor Author

Fixes #766

axic pushed a commit to ipsilon/solidity that referenced this pull request Apr 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants