aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/ast/rust-ast.cc
diff options
context:
space:
mode:
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>2024-05-21 10:23:55 +0200
committerArthur Cohen <arthur.cohen@embecosm.com>2025-03-17 16:35:33 +0100
commita0f4c30e52aebcb5c71ea5eba98fb20dbbc56858 (patch)
tree2771e39bae0a9e77ae3839714809190423fed642 /gcc/rust/ast/rust-ast.cc
parent949892cb959fa9c9d7f148aae746181cefd8b956 (diff)
downloadgcc-a0f4c30e52aebcb5c71ea5eba98fb20dbbc56858.zip
gcc-a0f4c30e52aebcb5c71ea5eba98fb20dbbc56858.tar.gz
gcc-a0f4c30e52aebcb5c71ea5eba98fb20dbbc56858.tar.bz2
gccrs: Parse raw ref operator
The raw ref operator is an unstable feature required to obtain a pointer to unaligned adresses (mainly unaligned struct fields) without UB. gcc/rust/ChangeLog: * ast/rust-ast-builder.cc (Builder::ref): Adapt constructor to the new API. * ast/rust-ast-collector.cc (TokenCollector::visit): Emit a raw weak keyword when required. * ast/rust-ast.cc (BorrowExpr::as_string): Change as_string representation to handle raw ref operator. * ast/rust-expr.h (class BorrowExpr): Add raw discriminant. * expand/rust-macro-builtins-include.cc: Adapt constructor to the new API. * parse/rust-parse-impl.h: Handle the raw weak keyword. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Diffstat (limited to 'gcc/rust/ast/rust-ast.cc')
-rw-r--r--gcc/rust/ast/rust-ast.cc18
1 files changed, 13 insertions, 5 deletions
diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc
index 8045a68..38cb7cf 100644
--- a/gcc/rust/ast/rust-ast.cc
+++ b/gcc/rust/ast/rust-ast.cc
@@ -20,6 +20,7 @@ along with GCC; see the file COPYING3. If not see
#include "rust-ast.h"
#include "optional.h"
#include "rust-builtin-ast-nodes.h"
+#include "rust-common.h"
#include "rust-system.h"
#include "rust-ast-full.h"
#include "rust-diagnostics.h"
@@ -1570,12 +1571,19 @@ BorrowExpr::as_string () const
std::string str ("&");
- if (double_borrow)
- str += "&";
-
- if (is_mut)
- str += "mut ";
+ if (raw_borrow)
+ {
+ str += "raw ";
+ str += get_is_mut () ? "const " : "mut ";
+ }
+ else
+ {
+ if (double_borrow)
+ str += "&";
+ if (get_is_mut ())
+ str += "mut ";
+ }
str += main_or_left_expr->as_string ();
return str;