diff options
author | tomsmeding <tom.smeding@gmail.com> | 2017-02-02 22:29:41 +0100 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2017-02-02 22:30:16 +0100 |
commit | 185623be46dfd9a60e5a021259a6c7778cfb07cd (patch) | |
tree | 8bbbe2edeec7fb7018a52f5cf52ed0a24ab48e59 /ast.hs | |
parent | dd1a2323e743df5ca3109bae6e213cd7b02dddee (diff) |
Parse and typecheck casts
Diffstat (limited to 'ast.hs')
-rw-r--r-- | ast.hs | 3 |
1 files changed, 3 insertions, 0 deletions
@@ -57,6 +57,7 @@ data UnaryOperator data Expression -- (Maybe Type)'s are type annotations by the type checker = ExLit Literal (Maybe Type) + | ExCast Type Expression -- No type annotation needed | ExBinOp BinaryOperator Expression Expression (Maybe Type) | ExUnOp UnaryOperator Expression (Maybe Type) deriving (Show) @@ -84,6 +85,7 @@ exUnOp_ uo e = ExUnOp uo e Nothing exTypeOf :: Expression -> Maybe Type exTypeOf (ExLit _ mt) = mt +exTypeOf (ExCast t _) = Just t exTypeOf (ExBinOp _ _ _ mt) = mt exTypeOf (ExUnOp _ _ mt) = mt @@ -160,6 +162,7 @@ instance PShow UnaryOperator where instance PShow Expression where pshow (ExLit lit Nothing) = pshow lit pshow (ExLit lit (Just t)) = concat ["(", pshow lit, " :: ", pshow t, ")"] + pshow (ExCast t ex) = concat ["cast(", pshow t, ")(", pshow ex, ")"] pshow (ExBinOp op a b Nothing) = concat ["(", pshow a, " ", pshow op, " ", pshow b, ")"] pshow (ExBinOp op a b (Just t)) = concat ["(", pshow a, " ", pshow op, " ", pshow b, " :: ", pshow t, ")"] pshow (ExUnOp op a Nothing) = concat [pshow op, pshow a] |