aboutsummaryrefslogtreecommitdiff
path: root/Sil/Syntax.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/Syntax.icl
parentAdd checks: no main, duplicate function, duplicate local (diff)
Add checks for locals with type Void
Diffstat (limited to 'Sil/Syntax.icl')
-rw-r--r--Sil/Syntax.icl20
1 files changed, 20 insertions, 0 deletions
diff --git a/Sil/Syntax.icl b/Sil/Syntax.icl
index f78ba83..8083eba 100644
--- a/Sil/Syntax.icl
+++ b/Sil/Syntax.icl
@@ -77,6 +77,26 @@ where
allStatements st=:(While _ cb) = [st:allStatements cb]
allStatements st=:(MachineStm _) = [st]
+instance allCodeBlocks Function where allCodeBlocks f = allCodeBlocks f.f_code
+
+instance allCodeBlocks CodeBlock
+where allCodeBlocks cb = [cb:concatMap allCodeBlocks cb.cb_content]
+
+instance allCodeBlocks Statement
+where
+ allCodeBlocks (If bs Nothing) = concatMap (allCodeBlocks o snd) bs
+ allCodeBlocks (If bs (Just e)) = [e:concatMap (allCodeBlocks o snd) bs]
+ allCodeBlocks (While _ cb) = [cb]
+ allCodeBlocks _ = []
+
+instance allLocals Function
+where
+ allLocals f = [(a.arg_type, a.arg_name) \\ a <- f.f_args] ++
+ allLocals f.f_code
+
+instance allLocals CodeBlock
+where allLocals cb = [(i.init_type, i.init_name) \\ i <- cb.cb_init]
+
typeSize :: Type -> Int
typeSize TVoid = 0
typeSize TBool = 1