diff options
author | Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com> | 2023-03-22 14:44:05 +0100 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2024-01-16 18:28:41 +0100 |
commit | 2e08b1d26b82ea19378e052ad30104d4af6b4bf1 (patch) | |
tree | 8f6f57f31f88f6df1f93dc67afe43f2dbb9535a1 | |
parent | 06dcc5fdf4d72e4c43beb1a2eb3376c4e252e1f4 (diff) | |
download | gcc-2e08b1d26b82ea19378e052ad30104d4af6b4bf1.zip gcc-2e08b1d26b82ea19378e052ad30104d4af6b4bf1.tar.gz gcc-2e08b1d26b82ea19378e052ad30104d4af6b4bf1.tar.bz2 |
gccrs: 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.cc | 87 | ||||
-rw-r--r-- | gcc/rust/ast/rust-ast-tokenstream.h | 1 |
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); |