diff options
author | Philip Herron <philip.herron@embecosm.com> | 2021-02-25 17:44:42 +0000 |
---|---|---|
committer | Philip Herron <herron.philip@googlemail.com> | 2021-03-03 22:46:24 +0000 |
commit | a886a9c06ed237a2fa8cff9d708f694066b18e66 (patch) | |
tree | 6805a79a9dbecc5d6975e1ace93a91517beb612e /gcc/rust/backend | |
parent | e76855ab401d70361cc8c1738d95127b6f45df86 (diff) | |
download | gcc-a886a9c06ed237a2fa8cff9d708f694066b18e66.zip gcc-a886a9c06ed237a2fa8cff9d708f694066b18e66.tar.gz gcc-a886a9c06ed237a2fa8cff9d708f694066b18e66.tar.bz2 |
Add in TyTy support for an initial String Literal
This gives the apropriate reference type over const char *.
Fixes #85
Diffstat (limited to 'gcc/rust/backend')
-rw-r--r-- | gcc/rust/backend/rust-compile-context.h | 10 | ||||
-rw-r--r-- | gcc/rust/backend/rust-compile-expr.h | 8 | ||||
-rw-r--r-- | gcc/rust/backend/rust-compile-tyty.h | 7 |
3 files changed, 23 insertions, 2 deletions
diff --git a/gcc/rust/backend/rust-compile-context.h b/gcc/rust/backend/rust-compile-context.h index b191554..a4c32d8 100644 --- a/gcc/rust/backend/rust-compile-context.h +++ b/gcc/rust/backend/rust-compile-context.h @@ -268,8 +268,6 @@ public: return compiler.translated; } - virtual ~TyTyResolveCompile () {} - void visit (TyTy::ErrorType &) override { gcc_unreachable (); } void visit (TyTy::InferType &) override { gcc_unreachable (); } @@ -460,6 +458,14 @@ public: translated = ctx->get_backend ()->reference_type (base_compiled_type); } + void visit (TyTy::StrType &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 86d4062..b48d79e 100644 --- a/gcc/rust/backend/rust-compile-expr.h +++ b/gcc/rust/backend/rust-compile-expr.h @@ -225,6 +225,14 @@ public: } return; + case HIR::Literal::STRING: { + auto base = ctx->get_backend ()->string_constant_expression ( + literal_value->as_string ()); + translated + = ctx->get_backend ()->address_expression (base, expr.get_locus ()); + } + 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 683a9a7..e043a50 100644 --- a/gcc/rust/backend/rust-compile-tyty.h +++ b/gcc/rust/backend/rust-compile-tyty.h @@ -209,6 +209,13 @@ public: Linemap::predeclared_location ()); } + void visit (TyTy::StrType &) override + { + Btype *raw_str = backend->raw_str_type (); + translated + = backend->named_type ("str", raw_str, Linemap::predeclared_location ()); + } + private: TyTyCompile (::Backend *backend) : backend (backend), translated (nullptr), |