summaryrefslogtreecommitdiff
path: root/ast.hs
diff options
context:
space:
mode:
Diffstat (limited to 'ast.hs')
-rw-r--r--ast.hs3
1 files changed, 3 insertions, 0 deletions
diff --git a/ast.hs b/ast.hs
index 2f40b84..480b133 100644
--- a/ast.hs
+++ b/ast.hs
@@ -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]