This repository has been archived by the owner on Oct 13, 2018. It is now read-only.
/
info
69 lines (67 loc) · 2.28 KB
/
info
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
Goto statement is considered harmful... really it is
therefor we need to add some terminology
all gotos mentioned below are jumps on constant labels, thus all gotos that have variables are converted to a case statement which has multiple jumps, depending on all the possible variables
simple block = no gotos or labels, easy to convert (all compound statements, if/for and other loops are terminated inside it)
so f.e :
for %%i in (*.txt) do (
type %%i
echo "bla"
)
is a simple block
this however isn't :
for %%i in (*.txt) do (
type %%i
while this isn't, because for isn't terminated (then again, it's not even a command)
simple block + simple block = simple block
hidden loop is a block that contains only one label and the rest of the code contains only one goto statement corresponding to the label
hidden loop also has only simple blocks in between
hidden loop can be transformed to a if/while statement if the jump is above/below the code
note that hidden loops happen outside of loops or both the goto statement and jump destination are inside the same loop
f.e:
for ... (
type %%i
:dest
echo "bla"
if something... (
goto dest
)
)
this isn't a hidden loop
for ... (
type %%i
:dest
echo "bla"
)
if something...(
goto dest
)
multi jump block is a block that contains multiple labels and/or goto statements that have simple or hidden blocks, and all of the jumps/labels when viewed separately would be hidden blocks
that is, no jump is inside a different loop or similar
f.e
for ... (
type %%i
:dest
echo "bla"
:dest2
if something... (
goto dest
)
if something_else (
goto dest2
)
)
multi jump block can be translated by adding an enclosing while loop, couple of variables and if statements
the remaining type of jumps is one where jump destinations are to different loops, we call this hard jumps
hard jumps can have multi jump blocks and weaker (hidden loops and simple blocks)
f.e
for ... (
type %%i
:dest
echo "bla"
)
if something...(
goto dest
)
in the general case, these need to be resolved by a restructure of that part of the code, which can be non trivial
and as such it's currently not implemented
TODO: add special loops for simulated break/continue, maybe even return