about summary refs log tree commit diff
path: root/src/ast
diff options
context:
space:
mode:
Diffstat (limited to 'src/ast')
-rw-r--r--src/ast/hir.rs4
-rw-r--r--src/ast/mod.rs19
2 files changed, 18 insertions, 5 deletions
diff --git a/src/ast/hir.rs b/src/ast/hir.rs
index 151ddd529872..9db6919f6f53 100644
--- a/src/ast/hir.rs
+++ b/src/ast/hir.rs
@@ -26,7 +26,7 @@ impl<'a, T> Binding<'a, T> {
 pub enum Expr<'a, T> {
     Ident(Ident<'a>, T),
 
-    Literal(Literal, T),
+    Literal(Literal<'a>, T),
 
     UnaryOp {
         op: UnaryOperator,
@@ -158,7 +158,7 @@ impl<'a, T> Expr<'a, T> {
     {
         match self {
             Expr::Ident(id, t) => Expr::Ident(id.to_owned(), t.clone()),
-            Expr::Literal(lit, t) => Expr::Literal(lit.clone(), t.clone()),
+            Expr::Literal(lit, t) => Expr::Literal(lit.to_owned(), t.clone()),
             Expr::UnaryOp { op, rhs, type_ } => Expr::UnaryOp {
                 op: *op,
                 rhs: Box::new((**rhs).to_owned()),
diff --git a/src/ast/mod.rs b/src/ast/mod.rs
index cef366d16e04..5526c5348350 100644
--- a/src/ast/mod.rs
+++ b/src/ast/mod.rs
@@ -107,9 +107,20 @@ pub enum UnaryOperator {
 }
 
 #[derive(Debug, PartialEq, Eq, Clone)]
-pub enum Literal {
+pub enum Literal<'a> {
     Int(u64),
     Bool(bool),
+    String(Cow<'a, str>),
+}
+
+impl<'a> Literal<'a> {
+    pub fn to_owned(&self) -> Literal<'static> {
+        match self {
+            Literal::Int(i) => Literal::Int(*i),
+            Literal::Bool(b) => Literal::Bool(*b),
+            Literal::String(s) => Literal::String(Cow::Owned(s.clone().into_owned())),
+        }
+    }
 }
 
 #[derive(Debug, PartialEq, Eq, Clone)]
@@ -133,7 +144,7 @@ impl<'a> Binding<'a> {
 pub enum Expr<'a> {
     Ident(Ident<'a>),
 
-    Literal(Literal),
+    Literal(Literal<'a>),
 
     UnaryOp {
         op: UnaryOperator,
@@ -174,7 +185,7 @@ impl<'a> Expr<'a> {
     pub fn to_owned(&self) -> Expr<'static> {
         match self {
             Expr::Ident(ref id) => Expr::Ident(id.to_owned()),
-            Expr::Literal(ref lit) => Expr::Literal(lit.clone()),
+            Expr::Literal(ref lit) => Expr::Literal(lit.to_owned()),
             Expr::UnaryOp { op, rhs } => Expr::UnaryOp {
                 op: *op,
                 rhs: Box::new((**rhs).to_owned()),
@@ -247,6 +258,7 @@ pub enum Type {
     Int,
     Float,
     Bool,
+    CString,
     Function(FunctionType),
 }
 
@@ -256,6 +268,7 @@ impl Display for Type {
             Type::Int => f.write_str("int"),
             Type::Float => f.write_str("float"),
             Type::Bool => f.write_str("bool"),
+            Type::CString => f.write_str("cstring"),
             Type::Function(ft) => ft.fmt(f),
         }
     }