diff options
author | Camil Staps | 2017-07-30 09:53:24 +0200 |
---|---|---|
committer | Camil Staps | 2017-07-30 09:53:24 +0200 |
commit | ad519a42876796f969900e687cea80c799dd40ec (patch) | |
tree | 608f3250dc4924be286d3c296f74db9bfed5dabd /Sil/Syntax.icl | |
parent | Reorganise: make Position a field in Syntax types (diff) |
Add positions to Statements
Diffstat (limited to 'Sil/Syntax.icl')
-rw-r--r-- | Sil/Syntax.icl | 45 |
1 files changed, 27 insertions, 18 deletions
diff --git a/Sil/Syntax.icl b/Sil/Syntax.icl index 0749dde..e28d616 100644 --- a/Sil/Syntax.icl +++ b/Sil/Syntax.icl @@ -15,13 +15,13 @@ import Sil.Util.Printer instance toString Statement where - toString (Declaration n a) = n <+ " := " <+ a <+ ";" - toString (Application e) = toString e <+ ";" - toString (Return Nothing) = "return;" - toString (Return (Just a)) = "return " <+ a <+ ";" - toString (If bs e) = "if ..." - toString (MachineStm s) = "|~" <+ s - toString _ = "<<unimplemented Statement>>" + toString (Declaration _ n a) = n <+ " := " <+ a <+ ";" + toString (Application _ e) = toString e <+ ";" + toString (Return _ Nothing) = "return;" + toString (Return _ (Just a)) = "return " <+ a <+ ";" + toString (If _ bs e) = "if ..." + toString (MachineStm _ s) = "|~" <+ s + toString _ = "<<unimplemented Statement>>" instance toString Arg where toString arg = arg.arg_type <+ " " <+ arg.arg_name @@ -68,6 +68,15 @@ where instance getPos Function where getPos f = f.f_pos instance getPos Initialisation where getPos i = i.init_pos +instance getPos Statement +where + getPos (Declaration p _ _) = p + getPos (Application p _) = p + getPos (Return p _) = p + getPos (If p _ _) = p + getPos (While p _ _) = p + getPos (MachineStm p _) = p + instance allStatements Program where allStatements p = concatMap allStatements p.p_funs @@ -79,13 +88,13 @@ where allStatements cb = concatMap allStatements cb.cb_content instance allStatements Statement where - allStatements st=:(Declaration _ _) = [st] - allStatements st=:(Application _) = [st] - allStatements st=:(Return _) = [st] - allStatements st=:(If bs Nothing) = [st:concatMap (allStatements o snd) bs] - allStatements st=:(If bs (Just e)) = [st:allStatements e ++ concatMap (allStatements o snd) bs] - allStatements st=:(While _ cb) = [st:allStatements cb] - allStatements st=:(MachineStm _) = [st] + allStatements st=:(Declaration _ _ _) = [st] + allStatements st=:(Application _ _) = [st] + allStatements st=:(Return _ _) = [st] + allStatements st=:(If _ bs Nothing) = [st:concatMap (allStatements o snd) bs] + allStatements st=:(If _ bs (Just e)) = [st:allStatements e ++ concatMap (allStatements o snd) bs] + allStatements st=:(While _ _ cb) = [st:allStatements cb] + allStatements st=:(MachineStm _ _) = [st] instance allCodeBlocks Function where allCodeBlocks f = allCodeBlocks f.f_code @@ -94,10 +103,10 @@ 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 _ = [] + 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 |