Skip to content

Commit

Permalink
Make a literal hold a i128 representation always
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Snaps committed Aug 22, 2019
1 parent 0e38846 commit bbc9d9a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
24 changes: 11 additions & 13 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ pub struct Real {
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
pub enum Literal {
Null,
Integer(i64),
UnsignedInteger(u64),
Integer(i128),
FixedPoint(Real),
String(String),
Blob(Vec<u8>),
Expand All @@ -95,15 +94,21 @@ pub enum Literal {
Placeholder,
}

impl From<i128> for Literal {
fn from(i: i128) -> Self {
Literal::Integer(i)
}
}

impl From<i64> for Literal {
fn from(i: i64) -> Self {
Literal::Integer(i)
Literal::Integer(i.into())
}
}

impl From<u64> for Literal {
fn from(i: u64) -> Self {
Literal::UnsignedInteger(i)
Literal::Integer(i.into())
}
}

Expand All @@ -115,7 +120,7 @@ impl From<i32> for Literal {

impl From<u32> for Literal {
fn from(i: u32) -> Self {
Literal::UnsignedInteger(i.into())
Literal::Integer(i.into())
}
}

Expand All @@ -136,7 +141,6 @@ impl ToString for Literal {
match *self {
Literal::Null => "NULL".to_string(),
Literal::Integer(ref i) => format!("{}", i),
Literal::UnsignedInteger(ref i) => format!("{}", i),
Literal::FixedPoint(ref f) => format!("{}.{}", f.integral, f.fractional),
Literal::String(ref s) => format!("'{}'", s.replace('\'', "''")),
Literal::Blob(ref bv) => format!(
Expand Down Expand Up @@ -884,13 +888,7 @@ named!(pub integer_literal<CompleteByteSlice, Literal>,
if sign.is_some() {
intval *= -1;
}
if intval > std::i64::MAX as i128 {
Literal::UnsignedInteger(intval as u64)
} else if intval < std::i64::MIN as i128 {
panic!("{:?} can't fit in a Literal::Integer", intval)
} else {
Literal::Integer(intval as i64)
}
Literal::Integer(intval)
})
)
);
Expand Down
2 changes: 1 addition & 1 deletion src/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ named!(pub column_constraint<CompleteByteSlice, Option<ColumnConstraint>>,
})
))
| do_parse!(d: digit >> (
Literal::Integer(i64::from_str(str::from_utf8(*d).unwrap()).unwrap())
Literal::Integer(i128::from_str(str::from_utf8(*d).unwrap()).unwrap())
))
| do_parse!(tag!("''") >> (Literal::String(String::from(""))))
| do_parse!(tag_no_case!("null") >> (Literal::Null))
Expand Down

0 comments on commit bbc9d9a

Please sign in to comment.