Support c string literals

This commit is contained in:
Lukas Wirth 2023-05-18 11:06:05 +02:00
parent 099b5b3b15
commit 4b577e2bc8
21 changed files with 176 additions and 34 deletions

View file

@ -85,6 +85,7 @@ impl fmt::Display for FloatTypeWrapper {
pub enum Literal {
String(Box<str>),
ByteString(Box<[u8]>),
CString(Box<str>),
Char(char),
Bool(bool),
Int(i128, Option<BuiltinInt>),
@ -135,6 +136,10 @@ impl From<ast::LiteralKind> for Literal {
let text = s.value().map(Box::from).unwrap_or_else(Default::default);
Literal::String(text)
}
LiteralKind::CString(s) => {
let text = s.value().map(Box::from).unwrap_or_else(Default::default);
Literal::CString(text)
}
LiteralKind::Byte(b) => {
Literal::Uint(b.value().unwrap_or_default() as u128, Some(BuiltinUint::U8))
}