-
Notifications
You must be signed in to change notification settings - Fork 29
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
scriptcomp: add initializers to for, while, switch statements #136
base: master
Are you sure you want to change the base?
Conversation
How does it handle nested loops that use the same variable name? Are they scoped properly? for (int x = 0; x < 100; x++)
{
for (int x = 0; x < 10; x++)
{
}
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just leaving a few nits here while I actually make sense of the bigger change. This will take a while.
Ran a nested scope test. Results are on discord, but I'll put there here for record-keeping purposes. Test code snippet: for (int x = 0; x < 5; x++)
{
Debug(c(" start outer loop -> x = " + _i(x), COLOR_ORANGE));
for (int x = 3; x > 0; x--)
{
Debug(c(" inner loop -> x = " + _i(x), COLOR_RED_LIGHT));
}
Debug(c(" end outer loop -> x = " + _i(x), COLOR_GREEN_LIGHT));
} I think it meets your intent, but if this test is too simple, let me know. |
78f9f25
to
a1f56c3
Compare
…crementers to for statements This change add the ability to use initialization and arbitrary statements within for, while and switch statements. Any variables defined or initialized within a for, while or switch statement will be scoped within the associated compound statement and any child scopes. add add comment back
a1f56c3
to
9e1cba8
Compare
I've run all the tests I can think of here, but I also know how it's supposed to work, so I'm probably missing some ideas on how to break it. If you guys have any tests you'd like run against this PR, let me know and I'll run 'em. |
This change adds the ability to use initialization and arbitrary statements within for, while and switch statements. Any variables defined or initialized within a for, while or switch statement will be scoped within the associated compound statement and any child scopes.
All legacy constructs are supported. Initialization statements are optional in
for
,while
orswitch
statements.Testing
Simple initializer in
for
statement:Initializer/declaration list and comma-separated increment statements in
for
statement:Function calls in initializer and increments statements in
for
statement:Function calls in nested
for
loops:Arbitrary statements in initializers and incrementers in
for
statement:Simple initializer in
while
statement:Function call in initializer for
switch
statementChangelog
Added
for
,while
andswitch
statements.for
statements.Licence