@@ -105,47 +105,16 @@ literals = mkPattern' match
106 match (CppBlock sts) = concat <$> sequence
106 match (CppBlock sts) = concat <$> sequence
107 [ return "{\n"
107 [ return "{\n"
108− , withIndent $ prettyStatements (compact sts)
108+ , withIndent $ prettyStatements sts
109 , return $ if null sts then "" else "\n"
109 , return $ if null sts then "" else "\n"
110 , currentIndent
110 , currentIndent
111 , return "}"
111 , return "}"
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'
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)]
126− returns :: Cpp -> Bool
127− returns (CppBlock rets@(_:_)) | CppReturn{} <- last rets = True
128− returns CppReturn{} = True
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)
135− isIntEq a (CppIfElse (CppBinary Equal a' (CppCharLiteral _)) (CppBlock [CppReturn _]) Nothing)
137− isIntEq a (CppIfElse (CppBinary Equal a' (CppBooleanLiteral _)) (CppBlock [CppReturn _]) Nothing)
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 ""
145 match (CppNamespace _ []) = return []
113 match (CppNamespace _ []) = return []
146 match (CppNamespace [] sts) = fmap concat $ sequence $
114 match (CppNamespace [] sts) = fmap concat $ sequence $
147 [ return "\n"
115 [ return "\n"
148 , prettyStatements sts
116 , prettyStatements sts
150 match (CppNamespace (':':':':name) sts) = fmap concat $ sequence $
119 match (CppNamespace (':':':':name) sts) = fmap concat $ sequence $
151 [ return "\n"
120 [ return "\n"
@@ -154,7 +123,7 @@ literals = mkPattern' match
154 , withIndent $ prettyStatements sts
123 , withIndent $ prettyStatements sts
155 , return "\n"
124 , return "\n"
156 , currentIndent
125 , currentIndent
157− , return "}"
126+ , return "}#"
159 match (CppNamespace name sts) = fmap concat $ sequence $
128 match (CppNamespace name sts) = fmap concat $ sequence $
160 [ return "\n"
129 [ return "\n"
@@ -163,7 +132,7 @@ literals = mkPattern' match
163 , withIndent $ prettyStatements sts'
132 , withIndent $ prettyStatements sts'
164 , return "\n"
133 , return "\n"
165 , currentIndent
134 , currentIndent
166− , return "}"
135+ , return "}#"
168 ++ let (cpp', cpps') = fromNested nested' in
137 ++ let (cpp', cpps') = fromNested nested' in
169 map match cpp'
138 map match cpp'
@@ -426,6 +395,7 @@ prettyStatements sts = do
426 addsemi [] = []
395 addsemi [] = []
427 addsemi s | all isSpace s = []
396 addsemi s | all isSpace s = []
428 addsemi s@('#':_) = s
397 addsemi s@('#':_) = s
398+ addsemi s | last s == '#' = init s
429 addsemi s = s ++ ";"
399 addsemi s = s ++ ";"