[PAS2C] Don't generate result variable for trivial functions consisting of single exit() call
authorunc0rr
Sat, 15 Nov 2014 13:39:58 +0300
changeset 10497 c7c50f165946
parent 10496 ba166d4e66f3
child 10498 bcd1d7ad2f3e
[PAS2C] Don't generate result variable for trivial functions consisting of single exit() call
tools/pas2c/Pas2C.hs
--- a/tools/pas2c/Pas2C.hs	Sat Nov 15 12:21:43 2014 +0300
+++ b/tools/pas2c/Pas2C.hs	Sat Nov 15 13:39:58 2014 +0300
@@ -518,7 +518,10 @@
         ph <- liftM2 ($+$) (typesAndVars2C False False True tvars) (phrase2C' phrase)
         return (p, ph)
 
-    let phrasesBlock = if isVoid then ph else t empty <+> res <> semi $+$ ph $+$ text "return" <+> res <> semi
+    let isTrivialReturn = case phrase of
+         (Phrases (BuiltInFunctionCall _ (SimpleReference (Identifier "exit" BTUnknown)) : _)) -> True
+         _ -> False
+    let phrasesBlock = if isVoid || isTrivialReturn then ph else t empty <+> res <> semi $+$ ph $+$ text "return" <+> res <> semi
     --let define = if hasVars then text "#ifndef" <+> text n $+$ funWithVarsToDefine n params $+$ text "#endif" else empty
     let inlineDecor = if inline then case notDeclared of
                                     True -> text "static inline"
@@ -919,6 +922,7 @@
         text "while" <> parens (i <+> text "!=" <+> iEnd <+> text add) <> semi
     where
         appendPhrase p (Phrases ps) = Phrases $ ps ++ [p]
+        appendPhrase _ _ = error "illegal appendPhrase call"
 phrase2C (RepeatCycle e' p') = do
     e <- expr2C e'
     p <- phrase2C (Phrases p')