aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend/rust-compile-expr.h
diff options
context:
space:
mode:
authorMark Wielaard <mark@klomp.org>2021-07-25 14:12:42 +0200
committerMark Wielaard <mark@klomp.org>2021-07-25 14:54:13 +0200
commitdf2b3b15dc95d5d74f6a630ee84296fb5b76c03f (patch)
treecefadc8af71ae3c09ff21b59e873ffffe1430adc /gcc/rust/backend/rust-compile-expr.h
parent314b62ec787abdf320fcca8ceb09b8c9bcf72512 (diff)
downloadgcc-df2b3b15dc95d5d74f6a630ee84296fb5b76c03f.zip
gcc-df2b3b15dc95d5d74f6a630ee84296fb5b76c03f.tar.gz
gcc-df2b3b15dc95d5d74f6a630ee84296fb5b76c03f.tar.bz2
Support byte and byte string literals
A byte literal is an u8 created as a ascii char or hex escape e.g. b'X'. A byte string literal is a string created from ascii or hex chars. bytes are represented as u8 and byte strings as str (with just ascii < 256 chars), but it should really be &'static [u8; n].
Diffstat (limited to 'gcc/rust/backend/rust-compile-expr.h')
-rw-r--r--gcc/rust/backend/rust-compile-expr.h9
1 files changed, 8 insertions, 1 deletions
diff --git a/gcc/rust/backend/rust-compile-expr.h b/gcc/rust/backend/rust-compile-expr.h
index dff4712..fa6a539 100644
--- a/gcc/rust/backend/rust-compile-expr.h
+++ b/gcc/rust/backend/rust-compile-expr.h
@@ -278,7 +278,14 @@ public:
}
return;
- case HIR::Literal::STRING: {
+ case HIR::Literal::BYTE: {
+ char c = literal_value->as_string ().c_str ()[0];
+ translated = ctx->get_backend ()->char_constant_expression (c);
+ }
+ return;
+
+ case HIR::Literal::STRING:
+ case HIR::Literal::BYTE_STRING: {
auto base = ctx->get_backend ()->string_constant_expression (
literal_value->as_string ());
translated