From b56b655f0bea1922999305d8e88bf16e874098a3 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Thu, 20 Jul 2017 08:24:33 +0000 Subject: Add checks for locals with type Void --- Sil/Check.icl | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'Sil/Check.icl') 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 -- cgit v1.2.3