From a4c6b7b751429b3cd7ed0804c2cab210bc9f00e9 Mon Sep 17 00:00:00 2001 From: Nala Ginrut Date: Tue, 5 May 2020 17:42:22 +0800 Subject: Fix string literal printing in AST dump --- gcc/rust/ast/rust-ast-full-test.cc | 3 ++- gcc/rust/ast/rust-ast.h | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) (limited to 'gcc') diff --git a/gcc/rust/ast/rust-ast-full-test.cc b/gcc/rust/ast/rust-ast-full-test.cc index ea19c6b..347ad54 100644 --- a/gcc/rust/ast/rust-ast-full-test.cc +++ b/gcc/rust/ast/rust-ast-full-test.cc @@ -242,7 +242,8 @@ Token::as_string () const // return get_token_description(token_id); // maybe fixed - stores everything as string though, so storage-inefficient - return str; + ::std::string quote = is_string_lit () ? "\"" : ""; + return quote + str + quote; } ::std::string diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h index 5378378..b86d3cf 100644 --- a/gcc/rust/ast/rust-ast.h +++ b/gcc/rust/ast/rust-ast.h @@ -213,6 +213,18 @@ public: } } + inline bool is_string_lit () const + { + switch (token_id) + { + case STRING_LITERAL: + case BYTE_STRING_LITERAL: + return true; + default: + return false; + } + } + ::std::string as_string () const; virtual void accept_vis (ASTVisitor &vis) OVERRIDE; -- cgit v1.1