aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>2023-03-22 14:44:05 +0100
committerArthur Cohen <arthur.cohen@embecosm.com>2023-03-30 16:48:26 +0200
commitf9fcd37d055c8e46aaecfa4a5af91e0108670c17 (patch)
treeba3d25688e860250bbc5fd69dfcc631780737eda
parent439c05ae3a8563a49cdf292f1ca0a84c0b43eb58 (diff)
downloadgcc-f9fcd37d055c8e46aaecfa4a5af91e0108670c17.zip
gcc-f9fcd37d055c8e46aaecfa4a5af91e0108670c17.tar.gz
gcc-f9fcd37d055c8e46aaecfa4a5af91e0108670c17.tar.bz2
ast: Add some expr TokenStream visitors
Implement some TokenStream expression visitor functions. gcc/rust/ChangeLog: * ast/rust-ast-tokenstream.cc (TokenStream::visit): Implement visitor. * ast/rust-ast-tokenstream.h: Add function prototype for missing component. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
-rw-r--r--gcc/rust/ast/rust-ast-tokenstream.cc87
-rw-r--r--gcc/rust/ast/rust-ast-tokenstream.h1
2 files changed, 73 insertions, 15 deletions
diff --git a/gcc/rust/ast/rust-ast-tokenstream.cc b/gcc/rust/ast/rust-ast-tokenstream.cc
index d68c19a..18337ac 100644
--- a/gcc/rust/ast/rust-ast-tokenstream.cc
+++ b/gcc/rust/ast/rust-ast-tokenstream.cc
@@ -998,36 +998,93 @@ TokenStream::visit (ArrayIndexExpr &expr)
}
void
-TokenStream::visit (TupleExpr &)
-{}
+TokenStream::visit (TupleExpr &expr)
+{
+ visit_items_as_lines (expr.get_outer_attrs ());
+ tokens.push_back (Rust::Token::make (LEFT_PAREN, expr.get_locus ()));
+ visit_items_joined_by_separator (expr.get_tuple_elems (), COMMA);
+ tokens.push_back (Rust::Token::make (RIGHT_PAREN, Location ()));
+}
void
-TokenStream::visit (TupleIndexExpr &)
-{}
+TokenStream::visit (TupleIndexExpr &expr)
+{
+ visit (expr.get_tuple_expr ());
+ tokens.push_back (Rust::Token::make (DOT, expr.get_locus ()));
+ tokens.push_back (
+ Rust::Token::make_int (Location (),
+ std::to_string (expr.get_tuple_index ())));
+}
void
-TokenStream::visit (StructExprStruct &)
-{}
+TokenStream::visit (StructExprStruct &expr)
+{
+ visit (expr.get_struct_name ());
+ tokens.push_back (Rust::Token::make (LEFT_CURLY, expr.get_locus ()));
+ // FIXME: Reference says it should have fields but node doesn't have them for
+ // now. We need to disambiguate with StructExprUnit and visit fields.
+ gcc_unreachable ();
+ tokens.push_back (Rust::Token::make (RIGHT_CURLY, Location ()));
+}
void
-TokenStream::visit (StructExprFieldIdentifier &)
-{}
+TokenStream::visit (StructExprFieldIdentifier &expr)
+{
+ // TODO: Add attributes
+ // visit_items_as_lines (expr.get_attrs ());
+ auto id = expr.get_field_name ();
+ tokens.push_back (
+ Rust::Token::make_identifier (expr.get_locus (), std::move (id)));
+}
void
-TokenStream::visit (StructExprFieldIdentifierValue &)
-{}
+TokenStream::visit (StructExprFieldIdentifierValue &expr)
+{
+ // TODO: Add attributes
+ // visit_items_as_lines (expr.get_attrs ());
+ auto id = expr.get_field_name ();
+ tokens.push_back (
+ Rust::Token::make_identifier (expr.get_locus (), std::move (id)));
+ tokens.push_back (Rust::Token::make (COLON, Location ()));
+ visit (expr.get_value ());
+}
void
-TokenStream::visit (StructExprFieldIndexValue &)
-{}
+TokenStream::visit (StructExprFieldIndexValue &expr)
+{
+ // TODO: Add attributes
+ // visit_items_as_lines (expr.get_attrs ());
+ tokens.push_back (Rust::Token::make_int (expr.get_locus (),
+ std::to_string (expr.get_index ())));
+ tokens.push_back (Rust::Token::make (COLON, Location ()));
+ visit (expr.get_value ());
+}
void
-TokenStream::visit (StructExprStructFields &)
-{}
+TokenStream::visit (StructBase &base)
+{
+ tokens.push_back (Rust::Token::make (DOT_DOT, Location ()));
+ visit (base.get_base_struct ());
+}
+
+void
+TokenStream::visit (StructExprStructFields &expr)
+{
+ visit_items_joined_by_separator (expr.get_fields (), COMMA);
+ if (expr.has_struct_base ())
+ {
+ tokens.push_back (Rust::Token::make (COMMA, Location ()));
+ visit (expr.get_struct_base ());
+ trailing_comma ();
+ }
+}
void
TokenStream::visit (StructExprStructBase &)
-{}
+{
+ // FIXME: Implement this node
+ gcc_unreachable ();
+}
void
TokenStream::visit (CallExpr &expr)
diff --git a/gcc/rust/ast/rust-ast-tokenstream.h b/gcc/rust/ast/rust-ast-tokenstream.h
index 58459c6..58b90fb 100644
--- a/gcc/rust/ast/rust-ast-tokenstream.h
+++ b/gcc/rust/ast/rust-ast-tokenstream.h
@@ -161,6 +161,7 @@ private:
void visit (StructExprFieldIdentifier &field);
void visit (StructExprFieldIdentifierValue &field);
void visit (StructExprFieldIndexValue &field);
+ void visit (StructBase &base);
void visit (StructExprStructFields &expr);
void visit (StructExprStructBase &expr);
void visit (CallExpr &expr);