From 3ae8d55860cbe95f80d5e5c76ca71883dbde0e10 Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Thu, 11 Feb 2021 15:04:26 +0000 Subject: Add char type This might need changes in the Lexer to allow for wchar_t to be preserved. Addresses #85 --- gcc/rust/backend/rust-compile-context.h | 8 ++++++++ gcc/rust/backend/rust-compile-expr.h | 7 +++++++ gcc/rust/backend/rust-compile-tyty.h | 6 ++++++ 3 files changed, 21 insertions(+) (limited to 'gcc/rust/backend') diff --git a/gcc/rust/backend/rust-compile-context.h b/gcc/rust/backend/rust-compile-context.h index 76255b0..3955a5b 100644 --- a/gcc/rust/backend/rust-compile-context.h +++ b/gcc/rust/backend/rust-compile-context.h @@ -437,6 +437,14 @@ public: translated = compiled_type; } + void visit (TyTy::CharType &type) override + { + ::Btype *compiled_type = nullptr; + bool ok = ctx->lookup_compiled_types (type.get_ty_ref (), &compiled_type); + rust_assert (ok); + translated = compiled_type; + } + private: TyTyResolveCompile (Context *ctx) : ctx (ctx) {} diff --git a/gcc/rust/backend/rust-compile-expr.h b/gcc/rust/backend/rust-compile-expr.h index 1e4aef6..c63479c 100644 --- a/gcc/rust/backend/rust-compile-expr.h +++ b/gcc/rust/backend/rust-compile-expr.h @@ -218,6 +218,13 @@ public: } return; + case HIR::Literal::CHAR: { + // FIXME needs wchar_t + char c = literal_value->as_string ().c_str ()[0]; + translated = ctx->get_backend ()->wchar_constant_expression (c); + } + return; + default: rust_fatal_error (expr.get_locus (), "unknown literal"); return; diff --git a/gcc/rust/backend/rust-compile-tyty.h b/gcc/rust/backend/rust-compile-tyty.h index 0629cbe..f591696 100644 --- a/gcc/rust/backend/rust-compile-tyty.h +++ b/gcc/rust/backend/rust-compile-tyty.h @@ -201,6 +201,12 @@ public: Linemap::predeclared_location ()); } + void visit (TyTy::CharType &) override + { + translated = backend->named_type ("char", backend->wchar_type (), + Linemap::predeclared_location ()); + } + private: TyTyCompile (::Backend *backend) : backend (backend), translated (nullptr), -- cgit v1.1