aboutsummaryrefslogtreecommitdiff
path: root/Sil/Check.icl
diff options
context:
space:
mode:
authorCamil Staps2017-07-20 08:24:33 +0000
committerCamil Staps2017-07-20 08:24:33 +0000
commitb56b655f0bea1922999305d8e88bf16e874098a3 (patch)
tree8e236349c9325cd70664c09809a58ad9f1bcd46c /Sil/Check.icl
parentAdd checks: no main, duplicate function, duplicate local (diff)
Add checks for locals with type Void
Diffstat (limited to 'Sil/Check.icl')
-rw-r--r--Sil/Check.icl16
1 files changed, 12 insertions, 4 deletions
diff --git a/Sil/Check.icl b/Sil/Check.icl
index fc80324..37ee282 100644
--- a/Sil/Check.icl
+++ b/Sil/Check.icl
@@ -28,6 +28,8 @@ where
= "Type error: an expression was returned from void function '" <+ f <+ "'."
toString (NoReturnFromNonVoidError f)
= "Type error: no return from non-void function '" <+ f <+ "'."
+ toString (LocalVoid f l)
+ = "Type error: local variable '" <+ l <+ "' in '" <+ f <+ "' cannot have type Void."
instance <<< CheckError where <<< f e = f <<< toString e <<< "\r\n"
@@ -68,12 +70,14 @@ where
_ -> False
checkLocals :: Function -> [CheckError]
- checkLocals f = check [a.arg_name \\ a <- f.f_args] f.f_code
+ checkLocals f =
+ checkDupName [a.arg_name \\ a <- f.f_args] f.f_code ++
+ concatMap checkVoid (allLocals f)
where
- check :: [Name] CodeBlock -> [CheckError]
- check defined cb =
+ checkDupName :: [Name] CodeBlock -> [CheckError]
+ checkDupName defined cb =
[DuplicateLocalName f.f_name l \\ l <- defined | isMember l locals] ++
- concatMap (check (locals ++ defined)) (underlyingCBs cb)
+ concatMap (checkDupName (locals ++ defined)) (underlyingCBs cb)
where locals = [i.init_name \\ i <- cb.cb_init]
underlyingCBs :: CodeBlock -> [CodeBlock]
@@ -87,6 +91,10 @@ where
findCBs (While _ cb) = [cb]
findCBs (MachineStm _) = []
+ checkVoid :: (Type, Name) -> [CheckError]
+ checkVoid (TVoid, n) = [LocalVoid f.f_name n]
+ checkVoid _ = []
+
checkErrors :: [(a -> [CheckError])] a *([CheckError], Maybe *File) -> *([CheckError], *Maybe *File)
checkErrors cks x st = seqSt error (concatMap (flip ($) x) cks) st