Supporting void with-loops
|
|
Bugzilla Link |
1120 |
Created on |
Mar 25, 2014 16:41 |
Version |
svn |
OS |
All |
Architecture |
All |
Extended Description
SaC syntax allows void with-loops. Unfortunately they are not supported by the compiler. Here are the steps that we have identified (Artem, Bodo) to fix the problem.
1) Adjusting parser. Currently the parser doesn't support void with-loops. It has been fixed in the branch called [origin/parser-fix] with a the following syntax adjustment:
A void with-loop requires void statement of the generator which can be expressed as:
with {
(...): foo ();
}: void;
in which case foo must be void,
with {
(...) { ... }: void;
}: void;
or
with {
(...) { ... }: foo ();
}: void;
where foo is void.
2) Flattening requires adjustment. The problem is that when flattening sees expression like:
with {
(...): foo ();
}: void;
it flattens it to:
with {
(...) {tmp = foo ();}: tmp;
}: void;
and obviously dies, as there is no foo which returns one argument. Solution:
normalize generators of the void with-loop as follows:
(...): foo (); -> (...) { foo (); }: void;
(...): { ... }: expr; -> (...) { ...; expr; }: void
3) Reference parameters are not being resolved properly in the void with-loops.
use IntStack: all;
int main ()
{
s = create_stack ();
with {
([0] <= [i] <[10]) { push (s, i);}
}: void ;
return 0;
}
If the reference is local, the propagate is not being inserted. See more details compiling this example.
4) Void functions make sense only if they produce side effects. Otherwise, the code cannot ever do anything useful. That is never being checked, and if one uses a void function with no side effects in the void with-loop, our compiler just breaks. Example:
void foo (int x)
{
return;
}
int main ()
{
with {
(...): foo ();
}: void;
}
Solution: introduce a new subphase in phase 5 between ewt and l2f handle_illegal_void which checks for any remaining void function or void with-loop and generates *appropriate* error messages.