Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 38 additions & 18 deletions gcc/rust/ast/rust-ast-collector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -397,13 +397,20 @@ TokenCollector::visit (Token &tok)
push (Rust::Token::make_identifier (tok.get_locus (), std::move (data)));
break;
case INT_LITERAL:
push (Rust::Token::make_int (tok.get_locus (), std::move (data),
tok.get_type_hint ()));
break;
case FLOAT_LITERAL:
push (Rust::Token::make_float (tok.get_locus (), std::move (data),
{
auto suffix_start = data.length ();
push (Rust::Token::make_int (tok.get_locus (), std::move (data),
suffix_start, LITERALBASE_DECIMAL,
tok.get_type_hint ()));
break;
break;
}
case FLOAT_LITERAL:
{
auto suffix_start = data.length ();
push (Rust::Token::make_float (tok.get_locus (), std::move (data),
suffix_start, tok.get_type_hint ()));
break;
}
case STRING_LITERAL:
push (Rust::Token::make_string (tok.get_locus (), std::move (data)));
break;
Expand Down Expand Up @@ -857,13 +864,20 @@ TokenCollector::visit (Literal &lit, location_t locus)
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 ()));
break;
case Literal::LitType::FLOAT:
push (Rust::Token::make_float (locus, std::move (value),
{
auto val_len = value.length ();
push (Rust::Token::make_int (locus, std::move (value), val_len,
LITERALBASE_DECIMAL,
lit.get_type_hint ()));
break;
break;
}
case Literal::LitType::FLOAT:
{
auto val_len = value.length ();
push (Rust::Token::make_float (locus, std::move (value), val_len,
lit.get_type_hint ()));
break;
}
case Literal::LitType::BOOL:
{
if (value == Values::Keywords::FALSE_LITERAL)
Expand Down Expand Up @@ -1237,8 +1251,10 @@ TokenCollector::visit (TupleIndexExpr &expr)
describe_node (std::string ("TupleIndexExpr"), [this, &expr] () {
visit (expr.get_tuple_expr ());
push (Rust::Token::make (DOT, expr.get_locus ()));
push (Rust::Token::make_int (UNDEF_LOCATION,
std::to_string (expr.get_tuple_index ())));
auto str = std::to_string (expr.get_tuple_index ());
auto suffix_start = str.length ();
push (Rust::Token::make_int (UNDEF_LOCATION, str, suffix_start,
LITERALBASE_DECIMAL));
});
}

Expand Down Expand Up @@ -1277,8 +1293,10 @@ TokenCollector::visit (StructExprFieldIndexValue &expr)
{
describe_node (std::string ("StructExprFieldIndexValue"), [this, &expr] () {
visit_items_as_lines (expr.get_outer_attrs ());
push (Rust::Token::make_int (expr.get_locus (),
std::to_string (expr.get_index ())));
auto str = std::to_string (expr.get_index ());
auto suffix_start = str.length ();
push (Rust::Token::make_int (expr.get_locus (), str, suffix_start,
LITERALBASE_DECIMAL));
push (Rust::Token::make (COLON, UNDEF_LOCATION));
visit (expr.get_value ());
});
Expand Down Expand Up @@ -2885,8 +2903,10 @@ TokenCollector::visit (StructPatternFieldTuplePat &pattern)
describe_node (std::string ("StructPatternFieldTuplePat"), [this,
&pattern] () {
visit_items_as_lines (pattern.get_outer_attrs ());
push (Rust::Token::make_int (pattern.get_locus (),
std::to_string (pattern.get_index ())));
auto str = std::to_string (pattern.get_index ());
auto suffix_start = str.length ();
push (Rust::Token::make_int (pattern.get_locus (), str, suffix_start,
LITERALBASE_DECIMAL));
push (Rust::Token::make (COLON, pattern.get_locus ()));
visit (pattern.get_index_pattern ());
});
Expand Down
11 changes: 8 additions & 3 deletions gcc/rust/expand/rust-macro-builtins-location.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "rust-ast-fragment.h"
#include "rust-macro-builtins.h"
#include "rust-macro-builtins-helpers.h"
#include "rust-token.h"

namespace Rust {
tl::optional<AST::Fragment>
Expand All @@ -39,8 +40,10 @@ MacroBuiltin::column_handler (location_t invoc_locus, AST::MacroInvocData &,
{
auto current_column = LOCATION_COLUMN (invoc_locus);

auto str = std::to_string (current_column);
auto str_len = str.length ();
auto column_tok = make_token (
Token::make_int (invoc_locus, std::to_string (current_column)));
Token::make_int (invoc_locus, str, str_len, LITERALBASE_DECIMAL));
auto column_no = AST::SingleASTNode (std::unique_ptr<AST::Expr> (
new AST::LiteralExpr (std::to_string (current_column), AST::Literal::INT,
PrimitiveCoreType::CORETYPE_U32, {}, invoc_locus)));
Expand All @@ -57,8 +60,10 @@ MacroBuiltin::line_handler (location_t invoc_locus, AST::MacroInvocData &,
auto line_no = AST::SingleASTNode (std::unique_ptr<AST::Expr> (
new AST::LiteralExpr (std::to_string (current_line), AST::Literal::INT,
PrimitiveCoreType::CORETYPE_U32, {}, invoc_locus)));
auto tok
= make_token (Token::make_int (invoc_locus, std::to_string (current_line)));
auto str = std::to_string (current_line);
auto str_len = str.length ();
auto tok = make_token (
Token::make_int (invoc_locus, str, str_len, LITERALBASE_DECIMAL));

return AST::Fragment ({line_no}, std::move (tok));
}
Expand Down
Loading
Loading