• Immutable Page
  • Info
  • Attachments

roelkluin/gres tests/loops

First store all occurrences of loops in a file. gg -A40 "(while|for)" -- '*.c' '*.h' > ../out/loop_A40

Error: the same index is used in a nested loop

gres --FiL="../out/loop_A40" \
"(while \(|for \([^;]*;) @...&@ [+-]* (@w) ([+-][+-] [<>]|[<>]=) ((@K|@d|@K \(...\))) @&...@ (;\(-..\))?\)
 @in_branches
 (while \(|for \([^;]*;) @...&@ [+-]* \6 ([+-][+-] [<>]|[<>]=) ((@K|@d|@K \(...\))) @&...@ (;\(-..\))?\)" | less

Error: the same index is used in the header of a nested for loop

gres --FiL="../out/loop_A40" \
"(while \(|for \([^;]*;) @...&@ [+-]* (@w) ([+-][+-] [<>]|[<>]=) ((@K|@d|@K \(...\))) @&...@ (;\(-..\))?\)
 @in_branches \n
 for \(\(-8.\)@Q2\6@Q1\(-8.\)\)" | less

The test after the loop is off by 1 (extended example of [[gres_examples]]):

gres --FiL="../out/loop_A40" \
"while \( @...&|@ (@V) (<|\!=) (@d|@w) @&|...@ \) (\{\{-..\} \n)? \5 ([+*|]=|= \5 \+)@n
if \( @...&|@ \5 (>|<=) \7 @&|...@ \)" \
"(for \([^;]*;|while \() @...&|@
         \+* (@V) (<|\!=|\+\+ <=) (@d|@w) @&|...@
         (; (\+\+ \6|\6 \+\+|\6 = \6 \+ 1|\6 = 1 \+ \6))? \)
    \{.8.\}
@n
if \( @...&|@ \6 (>|<=) \8 @&|...@ \)"

Similarly off by one after decrementing in a loop:

gres --FiL="../out/loop_A40" \
"while \( @...&|@ (@V) (>|\!=) (@d|@w) @&|...@ \) (\{\{-..\} \n)? \5 (-=|= \5 -)@n
if \( @...&|@ \5 (<|>=) \7 @&|...@ \)" \
"(for \([^;]*;|while \() @...&|@
         -* (@V) (>|\!=) (@d|@w) @&|...@
         (; (-- \6|\6 --|\6 = \6 - 1|\6 = 1 - \6))? \)
    \{.8.\}
@n
if \( @...&|@ \6 (<|>=) \8 @&|...@ \)"

Using a variable after the loop, can be out of bounds after max or before min.

gres --FiL="../out/loop_A40" \
"(while \(|for \([^;]*;) @...&@ [+-]* (@w) ([+-][+-] [<>]|[+-][+-] [\!]=|[<>]=)? ((@K|@d|@K \(...\)))? @&...@ (;\(-..\))?\)
   @branch@n
 (for \()? \6 .?=@n
 [^\n]*\[ \6 \]" \
"(while \(|for \([^;]*;) @...&@ [+-]* (@w) ([+-][+-] [<>]|[+-][+-] [\!]=|[<>]=)? ((@K|@d|@K \(...\)))? @&...@ (;\(-..\))?\)
   @branch@n
 [^\n]*\[ \6 \]" | less

break in loop, but the variable after loop, can be out of bounds after max or before min.

gres --FiL="../out/loop_A40" \
"if \(@...&@ [+-]* (@w) ([+-][+-] [<>]|[+-][+-] [\!]=|[<>]=)? ((@K|@d|@K \(...\)))? @&...@ (;\(-..\))?\)
  (break ;|\{-8.\}\n break; \})
 \{-8.\}\}@n
 (for \()? \5 .?=@n
[^\n]*\[ \5 \]" \
"if \(@...&@ [+-]* (@w) ([+-][+-] [<>]|[+-][+-] [\!]=|[<>]=)? ((@K|@d|@K \(...\)))? @&...@ (;\(-..\))?\)
  (break ;|\{-8.\}\n break; \})
 \{-8.\}\}@n
[^\n]*\[ \5 \]" | less
Tell others about this page:

last edited 2010-02-18 21:18:02 by roelkluin