aboutsummaryrefslogtreecommitdiff
path: root/Sil/Check.icl
diff options
context:
space:
mode:
authorCamil Staps2017-07-19 19:58:43 +0000
committerCamil Staps2017-07-19 19:58:43 +0000
commite0f3331379c36d326ee7d44bc32e3aea6354b9fd (patch)
treeceef7b3c46d56d8ef84c0fbcf259a653d73205d0 /Sil/Check.icl
parentReturn code for compiler (diff)
Add NoReturnFromNonVoidError
Diffstat (limited to 'Sil/Check.icl')
-rw-r--r--Sil/Check.icl21
1 files changed, 16 insertions, 5 deletions
diff --git a/Sil/Check.icl b/Sil/Check.icl
index fa93ac9..0784291 100644
--- a/Sil/Check.icl
+++ b/Sil/Check.icl
@@ -1,10 +1,11 @@
implementation module Sil.Check
import StdFile
-from StdFunc import flip
+from StdFunc import flip, o
import StdList
import StdOverloaded
import StdString
+import StdTuple
from Data.Func import $, mapSt, seqSt
import Data.Maybe
@@ -26,14 +27,24 @@ checkProgram :: *(Maybe *File) Program -> *([CheckError], *Maybe *File)
checkProgram err prog = checkFunction err (hd prog.p_funs) //appFst flatten $ mapSt (flip checkFunction) prog.p_funs err
checkFunction :: *(Maybe *File) Function -> *([CheckError], *Maybe *File)
-checkFunction err f = checkErrors [checkReturnExpressionFromVoid] f err
+checkFunction err f = checkErrors [checkReturnAndVoid] f err
where
- checkReturnExpressionFromVoid :: Function -> Maybe CheckError
- checkReturnExpressionFromVoid f = case f.f_type of
+ checkReturnAndVoid :: Function -> Maybe CheckError
+ checkReturnAndVoid f = case f.f_type of
TVoid -> case [st \\ st=:(Return (Just _)) <- allStatements f] of
[] -> Nothing
_ -> Just $ ReturnExpressionFromVoidError f.f_name
- _ -> Nothing
+ _ -> if (sureToReturn f.f_code) Nothing (Just $ NoReturnFromNonVoidError f.f_name)
+
+ sureToReturn :: CodeBlock -> Bool
+ sureToReturn cb = case cb.cb_content of
+ [] -> False
+ sts -> case last sts of
+ Return _ -> True
+ While _ cb` -> sureToReturn cb`
+ If bs (Just e) -> all sureToReturn [e:map snd bs]
+ If bs Nothing -> all (sureToReturn o snd) bs
+ _ -> False
checkErrors :: [(a -> Maybe CheckError)] a *(Maybe *File) -> *([CheckError], *Maybe *File)
checkErrors cks x err = seqSt error (catMaybes $ map (flip ($) x) cks) $ noErrors err