Skip to content
Merged
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
3 changes: 1 addition & 2 deletions gcc/rust/ast/rust-ast-collector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2061,8 +2061,7 @@ TokenCollector::visit (ConstantItem &item)
}
else
{
auto id = item.get_identifier ();
push (Rust::Token::make_identifier (UNDEF_LOCATION, std::move (id)));
push (Rust::Token::make_identifier (item.get_identifier ()));
}
push (Rust::Token::make (COLON, UNDEF_LOCATION));
visit (item.get_type ());
Expand Down
2 changes: 1 addition & 1 deletion gcc/rust/ast/rust-ast.cc
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ ConstantItem::as_string () const
{
std::string str = VisItem::as_string ();

str += "const " + identifier;
str += "const " + identifier.as_string ();

// DEBUG: null pointer check
if (type == nullptr)
Expand Down
2 changes: 2 additions & 0 deletions gcc/rust/ast/rust-ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class Identifier
return ident == other.ident;
}

operator const std::string & () const { return ident; }

private:
std::string ident;
location_t loc;
Expand Down
10 changes: 5 additions & 5 deletions gcc/rust/ast/rust-item.h
Original file line number Diff line number Diff line change
Expand Up @@ -2450,7 +2450,7 @@ class ConstantItem : public VisItem, public AssociatedItem
// either has an identifier or "_" - maybe handle in identifier?
// bool identifier_is_underscore;
// if no identifier declared, identifier will be "_"
std::string identifier;
Identifier identifier;

std::unique_ptr<Type> type;
std::unique_ptr<Expr> const_expr;
Expand All @@ -2460,15 +2460,15 @@ class ConstantItem : public VisItem, public AssociatedItem
public:
std::string as_string () const override;

ConstantItem (std::string ident, Visibility vis, std::unique_ptr<Type> type,
ConstantItem (Identifier ident, Visibility vis, std::unique_ptr<Type> type,
std::unique_ptr<Expr> const_expr,
std::vector<Attribute> outer_attrs, location_t locus)
: VisItem (std::move (vis), std::move (outer_attrs)),
identifier (std::move (ident)), type (std::move (type)),
const_expr (std::move (const_expr)), locus (locus)
{}

ConstantItem (std::string ident, Visibility vis, std::unique_ptr<Type> type,
ConstantItem (Identifier ident, Visibility vis, std::unique_ptr<Type> type,
std::vector<Attribute> outer_attrs, location_t locus)
: VisItem (std::move (vis), std::move (outer_attrs)),
identifier (std::move (ident)), type (std::move (type)),
Expand Down Expand Up @@ -2511,7 +2511,7 @@ class ConstantItem : public VisItem, public AssociatedItem

/* Returns whether constant item is an "unnamed" (wildcard underscore used
* as identifier) constant. */
bool is_unnamed () const { return identifier == "_"; }
bool is_unnamed () const { return identifier.as_string () == "_"; }

location_t get_locus () const override final { return locus; }

Expand Down Expand Up @@ -2556,7 +2556,7 @@ class ConstantItem : public VisItem, public AssociatedItem
return type;
}

std::string get_identifier () const { return identifier; }
const Identifier &get_identifier () const { return identifier; }

Item::Kind get_item_kind () const override
{
Expand Down
2 changes: 1 addition & 1 deletion gcc/rust/hir/rust-ast-lower-extern.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class ASTLoweringExternItem : public ASTLoweringBase
= static_cast<AST::IdentifierPattern &> (param.get_pattern ());
Identifier param_name = param_kind == AST::Pattern::Kind::Identifier
? param_ident.get_ident ()
: std::string ("_");
: Identifier ("_", param.get_locus ());

HIR::Type *param_type = ASTLoweringType::translate (param.get_type ());

Expand Down
8 changes: 8 additions & 0 deletions gcc/rust/lex/rust-token.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "rust-token.h"
#include "rust-diagnostics.h"
#include "rust-unicode.h"
#include "rust-ast.h"

namespace Rust {
// Hackily defined way to get token description for enum value using x-macros
Expand Down Expand Up @@ -234,6 +235,13 @@ escape_special_chars (const std::string &source, Context ctx)

} // namespace

TokenPtr
Token::make_identifier (const Identifier &ident)
{
std::string str = ident;
return make_identifier (ident.get_locus (), std::move (str));
}

std::string
Token::as_string () const
{
Expand Down
6 changes: 6 additions & 0 deletions gcc/rust/lex/rust-token.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
#include "rust-unicode.h"

namespace Rust {

// used by Rust::Token::make_identifier
class Identifier;

// "Primitive core types" in Rust - the different int and float types, as well
// as some others
enum PrimitiveCoreType
Expand Down Expand Up @@ -329,6 +333,8 @@ class Token
return TokenPtr (new Token (IDENTIFIER, locus, std::move (str)));
}

static TokenPtr make_identifier (const Identifier &ident);

// Makes and returns a new TokenPtr of type INT_LITERAL.
static TokenPtr make_int (location_t locus, std::string &&str,
PrimitiveCoreType type_hint = CORETYPE_UNKNOWN)
Expand Down