From: ansh <[email protected]>
gcc/rust/ChangeLog:
* ast/rust-ast-collector.cc (TokenCollector::visit):
Handle case for RAW_STRING_LITERAL.
* ast/rust-ast.cc (AttributeParser::parse_meta_item_inner):
Likewise.
(AttributeParser::parse_literal): Likewise.
* ast/rust-ast.h: Likewise.
* hir/rust-ast-lower-base.cc (ASTLoweringBase::lower_literal):
Likewise.
* lex/rust-lex.cc (Lexer::parse_raw_string): Likewise.
* lex/rust-token.cc (Token::as_string): Likewise.
* lex/rust-token.h (enum PrimitiveCoreType): Likewise.
* parse/rust-parse-impl.h (Parser::parse_attr_input): Likewise.
(Parser::parse_literal_expr): Likewise.
(Parser::parse_pattern_no_alt): Likewise.
Signed-off-by: ansh <[email protected]>
---
gcc/rust/ast/rust-ast-collector.cc | 6 ++++++
gcc/rust/ast/rust-ast.cc | 5 +++++
gcc/rust/ast/rust-ast.h | 2 ++
gcc/rust/hir/rust-ast-lower-base.cc | 3 +++
gcc/rust/lex/rust-lex.cc | 2 +-
gcc/rust/lex/rust-token.cc | 3 +++
gcc/rust/lex/rust-token.h | 8 ++++++++
gcc/rust/parse/rust-parse-impl.h | 17 +++++++++++++++++
8 files changed, 45 insertions(+), 1 deletion(-)
diff --git a/gcc/rust/ast/rust-ast-collector.cc
b/gcc/rust/ast/rust-ast-collector.cc
index f1d5c8c6c32..6980fef6c51 100644
--- a/gcc/rust/ast/rust-ast-collector.cc
+++ b/gcc/rust/ast/rust-ast-collector.cc
@@ -398,6 +398,9 @@ TokenCollector::visit (Token &tok)
case BYTE_STRING_LITERAL:
push (Rust::Token::make_byte_string (tok.get_locus (), std::move
(data)));
break;
+ case RAW_STRING_LITERAL:
+ push (Rust::Token::make_raw_string (tok.get_locus (), std::move (data)));
+ break;
case INNER_DOC_COMMENT:
push (Rust::Token::make_inner_doc_comment (tok.get_locus (),
std::move (data)));
@@ -777,6 +780,9 @@ TokenCollector::visit (Literal &lit, location_t locus)
case Literal::LitType::BYTE_STRING:
push (Rust::Token::make_byte_string (locus, std::move (value)));
break;
+ case Literal::LitType::RAW_STRING:
+ push (Rust::Token::make_raw_string (locus, std::move (value)));
+ break;
case Literal::LitType::INT:
push (
Rust::Token::make_int (locus, std::move (value), lit.get_type_hint ()));
diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc
index 2ff2e133037..bf7d31d8676 100644
--- a/gcc/rust/ast/rust-ast.cc
+++ b/gcc/rust/ast/rust-ast.cc
@@ -3506,6 +3506,7 @@ AttributeParser::parse_meta_item_inner ()
case STRING_LITERAL:
case BYTE_CHAR_LITERAL:
case BYTE_STRING_LITERAL:
+ case RAW_STRING_LITERAL:
case INT_LITERAL:
case FLOAT_LITERAL:
case TRUE_LITERAL:
@@ -3788,6 +3789,10 @@ AttributeParser::parse_literal ()
skip_token ();
return Literal (tok->as_string (), Literal::BYTE_STRING,
tok->get_type_hint ());
+ case RAW_STRING_LITERAL:
+ skip_token ();
+ return Literal (tok->as_string (), Literal::RAW_STRING,
+ tok->get_type_hint ());
case INT_LITERAL:
skip_token ();
return Literal (tok->as_string (), Literal::INT, tok->get_type_hint ());
diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h
index ee1c58c8fd6..4f40efff2a9 100644
--- a/gcc/rust/ast/rust-ast.h
+++ b/gcc/rust/ast/rust-ast.h
@@ -250,6 +250,7 @@ public:
{
case STRING_LITERAL:
case BYTE_STRING_LITERAL:
+ case RAW_STRING_LITERAL:
return true;
default:
return false;
@@ -311,6 +312,7 @@ public:
STRING,
BYTE,
BYTE_STRING,
+ RAW_STRING,
INT,
FLOAT,
BOOL,
diff --git a/gcc/rust/hir/rust-ast-lower-base.cc
b/gcc/rust/hir/rust-ast-lower-base.cc
index 0f928a4f462..906706e0205 100644
--- a/gcc/rust/hir/rust-ast-lower-base.cc
+++ b/gcc/rust/hir/rust-ast-lower-base.cc
@@ -928,6 +928,9 @@ ASTLoweringBase::lower_literal (const AST::Literal &literal)
case AST::Literal::LitType::BYTE_STRING:
type = HIR::Literal::LitType::BYTE_STRING;
break;
+ case AST::Literal::LitType::RAW_STRING: // TODO: Lower raw string literals.
+ rust_unreachable ();
+ break;
case AST::Literal::LitType::INT:
type = HIR::Literal::LitType::INT;
break;
diff --git a/gcc/rust/lex/rust-lex.cc b/gcc/rust/lex/rust-lex.cc
index 3315e67dfc0..f4b8861adcc 100644
--- a/gcc/rust/lex/rust-lex.cc
+++ b/gcc/rust/lex/rust-lex.cc
@@ -2218,7 +2218,7 @@ Lexer::parse_raw_string (location_t loc, int
initial_hash_count)
str.shrink_to_fit ();
- return Token::make_string (loc, std::move (str));
+ return Token::make_raw_string (loc, std::move (str));
}
template <typename IsDigitFunc>
diff --git a/gcc/rust/lex/rust-token.cc b/gcc/rust/lex/rust-token.cc
index 05424766afc..8493889db9f 100644
--- a/gcc/rust/lex/rust-token.cc
+++ b/gcc/rust/lex/rust-token.cc
@@ -247,6 +247,9 @@ Token::as_string () const
case BYTE_STRING_LITERAL:
return "b\"" + escape_special_chars (get_str (), Context::String)
+ "\"";
+ case RAW_STRING_LITERAL:
+ return "r\"" + escape_special_chars (get_str (), Context::String)
+ + "\"";
case CHAR_LITERAL:
return "'" + escape_special_chars (get_str (), Context::Char) + "'";
case BYTE_CHAR_LITERAL:
diff --git a/gcc/rust/lex/rust-token.h b/gcc/rust/lex/rust-token.h
index f53b1ca7ee7..aa2f308dd88 100644
--- a/gcc/rust/lex/rust-token.h
+++ b/gcc/rust/lex/rust-token.h
@@ -128,6 +128,7 @@ enum PrimitiveCoreType
RS_TOKEN (STRING_LITERAL, "string literal")
\
RS_TOKEN (CHAR_LITERAL, "character literal")
\
RS_TOKEN (BYTE_STRING_LITERAL, "byte string literal")
\
+ RS_TOKEN (RAW_STRING_LITERAL, "raw string literal")
\
RS_TOKEN (BYTE_CHAR_LITERAL, "byte character literal")
\
RS_TOKEN (LIFETIME, "lifetime") /* TODO: improve token type */
\
/* Have "interpolated" tokens (whatever that means)? identifer, path, type,
\
@@ -377,6 +378,12 @@ public:
return TokenPtr (new Token (BYTE_STRING_LITERAL, locus, std::move (str)));
}
+ // Makes and returns a new TokenPtr of type RAW_STRING_LITERAL.
+ static TokenPtr make_raw_string (location_t locus, std::string &&str)
+ {
+ return TokenPtr (new Token (RAW_STRING_LITERAL, locus, std::move (str)));
+ }
+
// Makes and returns a new TokenPtr of type INNER_DOC_COMMENT.
static TokenPtr make_inner_doc_comment (location_t locus, std::string &&str)
{
@@ -450,6 +457,7 @@ return *str;
case STRING_LITERAL:
case BYTE_CHAR_LITERAL:
case BYTE_STRING_LITERAL:
+ case RAW_STRING_LITERAL:
return true;
default:
return false;
diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index 7a9c0b72869..d5383ada21e 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -854,6 +854,9 @@ Parser<ManagedTokenSource>::parse_attr_input ()
case BYTE_STRING_LITERAL:
lit_type = AST::Literal::BYTE_STRING;
break;
+ case RAW_STRING_LITERAL:
+ lit_type = AST::Literal::RAW_STRING;
+ break;
case STRING_LITERAL:
default:
lit_type = AST::Literal::STRING;
@@ -7511,6 +7514,11 @@ Parser<ManagedTokenSource>::parse_literal_expr
(AST::AttrVec outer_attrs)
literal_value = t->get_str ();
lexer.skip_token ();
break;
+ case RAW_STRING_LITERAL:
+ type = AST::Literal::RAW_STRING;
+ literal_value = t->get_str ();
+ lexer.skip_token ();
+ break;
case INT_LITERAL:
type = AST::Literal::INT;
literal_value = t->get_str ();
@@ -10481,6 +10489,11 @@ Parser<ManagedTokenSource>::parse_pattern_no_alt ()
return std::unique_ptr<AST::LiteralPattern> (
new AST::LiteralPattern (t->get_str (), AST::Literal::BYTE_STRING,
t->get_locus (), t->get_type_hint ()));
+ case RAW_STRING_LITERAL:
+ lexer.skip_token ();
+ return std::unique_ptr<AST::LiteralPattern> (
+ new AST::LiteralPattern (t->get_str (), AST::Literal::RAW_STRING,
+ t->get_locus (), t->get_type_hint ()));
// raw string and raw byte string literals too if they are readded to
// lexer
case MINUS:
@@ -12275,6 +12288,10 @@ Parser<ManagedTokenSource>::null_denotation_not_path (
return std::unique_ptr<AST::LiteralExpr> (
new AST::LiteralExpr (tok->get_str (), AST::Literal::BYTE_STRING,
tok->get_type_hint (), {}, tok->get_locus ()));
+ case RAW_STRING_LITERAL:
+ return std::unique_ptr<AST::LiteralExpr> (
+ new AST::LiteralExpr (tok->get_str (), AST::Literal::RAW_STRING,
+ tok->get_type_hint (), {}, tok->get_locus ()));
case CHAR_LITERAL:
return std::unique_ptr<AST::LiteralExpr> (
new AST::LiteralExpr (tok->get_str (), AST::Literal::CHAR,
--
2.45.2