From ebde44b28b551f670c9e5c4c038d03e94bfbb1d2 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Sun, 30 Jul 2017 09:17:44 +0200 Subject: Reorganise: make Position a field in Syntax types --- Sil/Check.icl | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'Sil/Check.icl') diff --git a/Sil/Check.icl b/Sil/Check.icl index c9ccecb..6179a66 100644 --- a/Sil/Check.icl +++ b/Sil/Check.icl @@ -30,24 +30,24 @@ checkProgram err prog $ appFst flatten $ mapSt (flip checkFunction) prog.p_funs err where checkMainFunction :: Program -> [Error] - checkMainFunction p = case [f \\ f <- p.p_funs | f.pos_val.f_name == "main"] of + checkMainFunction p = case [f \\ f <- p.p_funs | f.f_name == "main"] of [] -> [Ck_NoMainFunction] _ -> [] checkFunctionNames :: Program -> [Error] checkFunctionNames p = - [ Ck_DuplicateFunctionName (errpos $ hd fs) (fromPositioned $ hd fs).f_name + [ Ck_DuplicateFunctionName (errpos $ hd fs) (hd fs).f_name \\ fs <- tails [f \\ f <- p.p_funs] - | let names = [f.pos_val.f_name \\ f <- fs] + | let names = [f.f_name \\ f <- fs] in not (isEmpty names) && isMember (hd names) (tl names)] checkGlobals :: Program -> [Error] checkGlobals p = - [ Ck_BasicGlobal (errpos g) (fromPositioned g).init_name + [ Ck_BasicGlobal (errpos g) g.init_name \\ g <- p.p_globals - | (typeSize (fromPositioned g).init_type).bsize <> 0] + | (typeSize g.init_type).bsize <> 0] -checkFunction :: *(Maybe *File) (Positioned Function) -> *([Error], *Maybe *File) +checkFunction :: *(Maybe *File) Function -> *([Error], *Maybe *File) checkFunction err f = checkErrors [ checkLocals , checkReturnAndVoid @@ -55,17 +55,17 @@ checkFunction err f = checkErrors ] f $ noErrors err where - checkReturnAndVoid :: (Positioned Function) -> [Error] - checkReturnAndVoid p=:{pos_val=f} = case f.f_type of + checkReturnAndVoid :: Function -> [Error] + checkReturnAndVoid f = case f.f_type of TVoid -> case [st \\ st=:(Return (Just _)) <- allStatements f] of [] -> [] - _ -> [Ck_ReturnExpressionFromVoid (errpos p) f.f_name] - _ -> if (sureToReturn f.f_code) [] [Ck_NoReturnFromNonVoid (errpos p) f.f_name] + _ -> [Ck_ReturnExpressionFromVoid (errpos f) f.f_name] + _ -> if (sureToReturn f.f_code) [] [Ck_NoReturnFromNonVoid (errpos f) f.f_name] where sureToReturn :: CodeBlock -> Bool sureToReturn cb = case cb.cb_content of [] -> False - sts -> case fromPositioned $ last sts of + sts -> case last sts of Return _ -> True While _ cb` -> sureToReturn cb` If bs (Just e) -> all sureToReturn [e:map snd bs] @@ -73,27 +73,27 @@ where MachineStm _ -> True // Let's assume the user is not stupid _ -> False - checkMainFunctionType :: (Positioned Function) -> [Error] - checkMainFunctionType {pos_val={f_name="main",f_args=[]}} + checkMainFunctionType :: Function -> [Error] + checkMainFunctionType {f_name="main",f_args=[]} = [] - checkMainFunctionType p=:{pos_val=f=:{f_name="main"}} - = [Ck_MainFunctionInvalidType (errpos p) $ fromOk $ fromJust $ type zero f] + checkMainFunctionType f=:{f_name="main"} + = [Ck_MainFunctionInvalidType (errpos f) $ fromOk $ fromJust $ type zero f] checkMainFunctionType _ = [] - checkLocals :: (Positioned Function) -> [Error] - checkLocals p=:{pos_val=f} = + checkLocals :: Function -> [Error] + checkLocals f = checkDupName [a.arg_name \\ a <- f.f_args] f.f_code ++ concatMap checkVoid (allLocals f) where checkDupName :: [Name] CodeBlock -> [Error] checkDupName defined cb = - [Ck_DuplicateLocalName (errpos p) f.f_name l \\ l <- defined | isMember l locals] ++ + [Ck_DuplicateLocalName (errpos f) f.f_name l \\ l <- defined | isMember l locals] ++ concatMap (checkDupName (locals ++ defined)) (underlyingCBs cb) - where locals = [(fromPositioned i).init_name \\ i <- cb.cb_init] + where locals = [i.init_name \\ i <- cb.cb_init] underlyingCBs :: CodeBlock -> [CodeBlock] - underlyingCBs cb = concatMap (findCBs o fromPositioned) cb.cb_content + underlyingCBs cb = concatMap findCBs cb.cb_content where findCBs (Declaration _ _) = [] findCBs (Application _) = [] -- cgit v1.2.3