@@ -105,47 +105,16 @@ literals = mkPattern' match
105105 ]
106106 match (CppBlock sts) = concat <$> sequence
107107 [ return "{\n"
108− , withIndent $ prettyStatements (compact sts)
108+ , withIndent $ prettyStatements sts
109109 , return $ if null sts then "" else "\n"
110110 , currentIndent
111111 , return "}"
112112 ]
113− where
114− compact :: [Cpp] -> [Cpp]
115− compact (st'@(CppIfElse (CppBinary Equal a _) _ Nothing) : sts') =
116− if length (fst cpps') > 1
117− then CppSwitch a (mkCases <$> fst cpps') : snd cpps'
118− else st' : sts'
119− where
120− cpps' = span (isIntEq a) (st' : sts')
121− compact ((CppIfElse cond1 body1 Nothing) : (CppIfElse cond2 body2 Nothing) : _)
122− | returns body1 && returns body2 &&
123− (CppUnary CppNot cond1 == cond2 ||
124− CppUnary CppNot cond2 == cond1) = [CppIfElse cond1 body1 (Just body2)]
125− where
126− returns :: Cpp -> Bool
127− returns (CppBlock rets@(_:_)) | CppReturn{} <- last rets = True
128− returns CppReturn{} = True
129− returns _ = False
130− compact (cpp' : cpps') = cpp' : compact cpps'
131− compact cpps' = cpps'
132− isIntEq :: Cpp -> Cpp -> Bool
133− isIntEq a (CppIfElse (CppBinary Equal a' (CppNumericLiteral (Left _))) (CppBlock [CppReturn _]) Nothing)
134− | a == a' = True
135− isIntEq a (CppIfElse (CppBinary Equal a' (CppCharLiteral _)) (CppBlock [CppReturn _]) Nothing)
136− | a == a' = True
137− isIntEq a (CppIfElse (CppBinary Equal a' (CppBooleanLiteral _)) (CppBlock [CppReturn _]) Nothing)
138− | a == a' = True
139− isIntEq _ _ = False
140− mkCases :: Cpp -> (Cpp, Cpp)
141− mkCases (CppIfElse (CppBinary Equal _ b') (CppBlock [body]) Nothing) = (b', body)
142− mkCases (CppIfElse (CppUnary CppNot _) (CppBlock [body]) Nothing) = (CppBooleanLiteral False, body)
143− mkCases (CppIfElse _ (CppBlock [body]) Nothing) = (CppBooleanLiteral True, body)
144− mkCases _ = error ""
145113 match (CppNamespace _ []) = return []
146114 match (CppNamespace [] sts) = fmap concat $ sequence $
147115 [ return "\n"
148116 , prettyStatements sts
117+ , return "#"
149118 ]
150119 match (CppNamespace (':':':':name) sts) = fmap concat $ sequence $
151120 [ return "\n"
@@ -154,7 +123,7 @@ literals = mkPattern' match
154123 , withIndent $ prettyStatements sts
155124 , return "\n"
156125 , currentIndent
157− , return "}"
126+ , return "}#"
158127 ]
159128 match (CppNamespace name sts) = fmap concat $ sequence $
160129 [ return "\n"
@@ -163,7 +132,7 @@ literals = mkPattern' match
163132 , withIndent $ prettyStatements sts'
164133 , return "\n"
165134 , currentIndent
166− , return "}"
135+ , return "}#"
167136 ]
168137 ++ let (cpp', cpps') = fromNested nested' in
169138 map match cpp'
@@ -426,6 +395,7 @@ prettyStatements sts = do
426395 addsemi [] = []
427396 addsemi s | all isSpace s = []
428397 addsemi s@('#':_) = s
398+ addsemi s | last s == '#' = init s
429399 addsemi s = s ++ ";"
430400
431401-- |