|
1790 | 1790 | (when (clause? (car o))
|
1791 | 1791 | (set! i (1+ i)))
|
1792 | 1792 | n))))
|
| 1793 | + |
| 1794 | + (define (flatten-cases c) |
| 1795 | + (define (flatten-case case) |
| 1796 | + (pmatch case |
| 1797 | + ((case ,test (case . ,body)) |
| 1798 | + (append `((case ,test (expr-stmt))) (flatten-case `(case ,@body)))) |
| 1799 | + ((case ,test ,casebody (case . ,body)) |
| 1800 | + (append `((case ,test ,casebody)) (flatten-case `(case ,@body)))) |
| 1801 | + ((default (case . ,body)) |
| 1802 | + (append `((default (expr-stmt))) (flatten-case `(case ,@body)))) |
| 1803 | + ((default ,defbody (case . ,body)) |
| 1804 | + (append `((default ,defbody)) (flatten-case `(case ,@body)))) |
| 1805 | + ((case ,test (default . ,body)) |
| 1806 | + (append `((case ,test (expr-stmt))) (flatten-case `(default ,@body)))) |
| 1807 | + ((default ,rest) |
| 1808 | + (list case)) |
| 1809 | + ((case ,test) |
| 1810 | + (list case)) |
| 1811 | + ((case ,test ,expr) |
| 1812 | + (list case)) |
| 1813 | + (,s (list s)))) |
| 1814 | + (fold (lambda (x acc) (append acc (flatten-case x))) '() c)) |
| 1815 | + |
| 1816 | + |
| 1817 | + |
1793 | 1818 | (let* ((info (append-text info (ast->comment `(switch ,expr (compd-stmt (block-item-list (ellipsis)))))))
|
| 1819 | + (statements (flatten-cases statements)) |
1794 | 1820 | (here (number->string (length text)))
|
1795 | 1821 | (label (string-append "_" (.function info) "_" here "_"))
|
1796 | 1822 | (break-label (string-append label "break"))
|
|
1926 | 1952 | (let* ((i-string (number->string i))
|
1927 | 1953 | (i+1-string (number->string (1+ i)))
|
1928 | 1954 | (body-label (string-append label "body" i-string))
|
1929 |
| - (next-body-label (string-append label "body" i+1-string)) |
1930 | 1955 | (clause-label (string-append label "clause" i-string))
|
| 1956 | + (first? (= i 0)) |
1931 | 1957 | (last? (= i count))
|
1932 | 1958 | (break-label (string-append label "break"))
|
1933 | 1959 | (next-clause-label (string-append label "clause" i+1-string))
|
|
1953 | 1979 | (let ((info (if clause? (append-text info (wrap-as `((#:label ,clause-label))))
|
1954 | 1980 | info)))
|
1955 | 1981 | (append-text info (test->text test))))
|
1956 |
| - ((case ,test (case . ,case1)) |
1957 |
| - (let ((info (if clause? (append-text info (wrap-as `((#:label ,clause-label)))) |
1958 |
| - info))) |
1959 |
| - (fold (cut switch->info #f label count <> i <>) info (cons `(case ,test) `((case ,@case1)))))) |
1960 | 1982 | ((case ,test (default . ,rest))
|
1961 | 1983 | (let ((info (if clause? (append-text info (wrap-as `((#:label ,clause-label))))
|
1962 | 1984 | info)))
|
1963 | 1985 | (fold (cut switch->info #f label count <> i <>) info (cons `(case ,test) `(default ,@rest)))))
|
1964 | 1986 | ((case ,test ,statement)
|
1965 |
| - (let* ((info (if clause? (append-text info (wrap-as `((#:label ,clause-label)))) |
| 1987 | + (let* ((info (if first? info (append-text info (jump body-label)))) ; Enables fallthrough |
| 1988 | + (info (if clause? (append-text info (wrap-as `((#:label ,clause-label)))) |
1966 | 1989 | info))
|
1967 | 1990 | (info (switch->info #f label count `(case ,test) i info))
|
1968 | 1991 | (info (append-text info (jump next-clause-label)))
|
1969 | 1992 | (info (append-text info (wrap-as `((#:label ,body-label)))))
|
1970 |
| - (info (ast->info statement info)) |
1971 |
| - ;; 66-local-char-array -- fallthrough FIXME |
1972 |
| - ;; (info (if last? info |
1973 |
| - ;; (append-text info (jump next-body-label)))) |
1974 |
| - ) |
| 1993 | + (info (ast->info statement info))) |
1975 | 1994 | info))
|
1976 |
| - ((case ,test (case . ,case1) . ,rest) |
1977 |
| - (let ((info (if clause? (append-text info (wrap-as `((#:label ,clause-label)))) |
1978 |
| - info))) |
1979 |
| - (fold (cut switch->info #f label count <> i <>) info (cons `(case ,test) `((case ,@case1) ,@rest))))) |
1980 | 1995 | ((default (case . ,case1) . ,rest)
|
1981 | 1996 | (let* ((info (if clause? (append-text info (wrap-as `((#:label ,clause-label))))
|
1982 | 1997 | info))
|
|
0 commit comments