diff options
author | Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com> | 2023-04-03 20:44:45 +0200 |
---|---|---|
committer | CohenArthur <arthur.cohen@embecosm.com> | 2023-04-04 12:05:02 +0000 |
commit | f749a7fa0b411b6d71e81ff5a95c3bad54eca09b (patch) | |
tree | 07ae4863f7d54704c87a18a36686cc5d303daaa0 | |
parent | 8b017829f1d22ea6ef0cd9cb05c29e04b5776de0 (diff) | |
download | gcc-f749a7fa0b411b6d71e81ff5a95c3bad54eca09b.zip gcc-f749a7fa0b411b6d71e81ff5a95c3bad54eca09b.tar.gz gcc-f749a7fa0b411b6d71e81ff5a95c3bad54eca09b.tar.bz2 |
ast: Move pattern implementation out of rust-ast
Move rust-pattern implementation out of rust-ast.cc in their own file.
gcc/rust/ChangeLog:
* Make-lang.in: Add two new files to the list of sources.
* ast/rust-ast-full.h: Add new ast formatting header.
* ast/rust-ast.cc (enum indent_mode): Move formatting function
to it's own file.
(indent_spaces): Likewise.
(get_string_in_delims): Likewise.
(enum AttrMode): Likewise.
(get_mode_dump_desc): Likewise.
(append_attributes): Likewise.
(unquote_string): Likewise.
(GroupedExpr::as_string): Move pattern implementation to it's
own file.
(RangePattern::as_string): Likewise.
(RangePatternBoundLiteral::as_string): Likewise.
(SlicePattern::as_string): Likewise.
(AltPattern::as_string): Likewise.
(TuplePatternItemsMultiple::as_string): Likewise.
(TuplePatternItemsRanged::as_string): Likewise.
(TuplePattern::as_string): Likewise.
(StructPatternField::as_string): Likewise.
(StructPatternFieldIdent::as_string): Likewise.
(StructPatternFieldTuplePat::as_string): Likewise.
(StructPatternFieldIdentPat::as_string): Likewise.
(StructPatternElements::as_string): Likewise.
(StructPattern::as_string): Likewise.
(LiteralPattern::as_string): Likewise.
(ReferencePattern::as_string): Likewise.
(IdentifierPattern::as_string): Likewise.
(TupleStructItemsNoRange::as_string): Likewise.
(TupleStructItemsRange::as_string): Likewise.
(TupleStructPattern::as_string): Likewise.
(GroupedExpr::accept_vis): Likewise.
(LiteralPattern::accept_vis): Likewise.
(IdentifierPattern::accept_vis): Likewise.
(WildcardPattern::accept_vis): Likewise.
(RestPattern::accept_vis): Likewise.
(RangePatternBoundLiteral::accept_vis): Likewise.
(RangePatternBoundPath::accept_vis): Likewise.
(RangePatternBoundQualPath::accept_vis): Likewise.
(RangePattern::accept_vis): Likewise.
(ReferencePattern::accept_vis): Likewise.
(StructPatternFieldTuplePat::accept_vis): Likewise.
(StructPatternFieldIdentPat::accept_vis): Likewise.
(StructPatternFieldIdent::accept_vis): Likewise.
(StructPattern::accept_vis): Likewise.
(TupleStructItemsNoRange::accept_vis): Likewise.
(TupleStructItemsRange::accept_vis): Likewise.
(TupleStructPattern::accept_vis): Likewise.
(TuplePatternItemsMultiple::accept_vis): Likewise.
(TuplePatternItemsRanged::accept_vis): Likewise.
(TuplePattern::accept_vis): Likewise.
(GroupedPattern::accept_vis): Likewise.
(SlicePattern::accept_vis): Likewise.
(AltPattern::accept_vis): Likewise.
* ast/rust-ast-formatting.cc: New file.
* ast/rust-ast-formatting.h: New file.
* ast/rust-pattern.cc: New file.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
-rw-r--r-- | gcc/rust/Make-lang.in | 2 | ||||
-rw-r--r-- | gcc/rust/ast/rust-ast-formatting.cc | 106 | ||||
-rw-r--r-- | gcc/rust/ast/rust-ast-formatting.h | 59 | ||||
-rw-r--r-- | gcc/rust/ast/rust-ast-full.h | 1 | ||||
-rw-r--r-- | gcc/rust/ast/rust-ast.cc | 530 | ||||
-rw-r--r-- | gcc/rust/ast/rust-pattern.cc | 468 |
6 files changed, 636 insertions, 530 deletions
diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in index 6b5861a..f02536e 100644 --- a/gcc/rust/Make-lang.in +++ b/gcc/rust/Make-lang.in @@ -73,7 +73,9 @@ GRS_OBJS = \ rust/rust-cfg-parser.o \ rust/rust-parse.o \ rust/rust-ast.o \ + rust/rust-ast-formatting.o \ rust/rust-path.o \ + rust/rust-pattern.o \ rust/rust-ast-fragment.o \ rust/rust-ast-dump.o \ rust/rust-ast-tokenstream.o \ diff --git a/gcc/rust/ast/rust-ast-formatting.cc b/gcc/rust/ast/rust-ast-formatting.cc new file mode 100644 index 0000000..4c13ef0 --- /dev/null +++ b/gcc/rust/ast/rust-ast-formatting.cc @@ -0,0 +1,106 @@ +/* General AST-related method implementations for Rust frontend. + Copyright (C) 2009-2023 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +<http://www.gnu.org/licenses/>. */ + +#include "rust-ast-full.h" + +namespace Rust { +namespace AST { + +std::string +indent_spaces (enum indent_mode mode) +{ + static int indent = 0; + std::string str = ""; + if (out == mode) + indent--; + for (int i = 0; i < indent; i++) + str += " "; + if (enter == mode) + indent++; + + return str; +} + +std::string +get_string_in_delims (std::string str_input, DelimType delim_type) +{ + switch (delim_type) + { + case PARENS: + return "(" + str_input + ")"; + case SQUARE: + return "[" + str_input + "]"; + case CURLY: + return "{" + str_input + "}"; + default: + return "ERROR-MARK-STRING (delims)"; + } + gcc_unreachable (); +} + +std::string +get_mode_dump_desc (AttrMode mode) +{ + switch (mode) + { + case OUTER: + return "outer attributes"; + case INNER: + return "inner attributes"; + default: + gcc_unreachable (); + return ""; + } +} + +std::string +append_attributes (std::vector<Attribute> attrs, AttrMode mode) +{ + indent_spaces (enter); + + std::string str + = "\n" + indent_spaces (stay) + get_mode_dump_desc (mode) + ": "; + // str += "\n" + indent_spaces (stay) + "inner attributes: "; + if (attrs.empty ()) + { + str += "none"; + } + else + { + /* note that this does not print them with outer or "inner attribute" + * syntax - just prints the body */ + for (const auto &attr : attrs) + str += "\n" + indent_spaces (stay) + attr.as_string (); + } + + indent_spaces (out); + + return str; +} + +std::string +unquote_string (std::string input) +{ + rust_assert (input.front () == '"'); + rust_assert (input.back () == '"'); + return input.substr (1, input.length () - 2); +} + +} // namespace AST +} // namespace Rust diff --git a/gcc/rust/ast/rust-ast-formatting.h b/gcc/rust/ast/rust-ast-formatting.h new file mode 100644 index 0000000..04e20cc --- /dev/null +++ b/gcc/rust/ast/rust-ast-formatting.h @@ -0,0 +1,59 @@ +// Copyright (C) 2020-2023 Free Software Foundation, Inc. + +// This file is part of GCC. + +// GCC is free software; you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation; either version 3, or (at your option) any later +// version. + +// GCC is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. + +// You should have received a copy of the GNU General Public License +// along with GCC; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#ifndef RUST_AST_FORMATTING_H +#define RUST_AST_FORMATTING_H + +namespace Rust { +namespace AST { + +enum indent_mode +{ + enter, + out, + stay +}; + +enum AttrMode +{ + OUTER, + INNER +}; + +std::string +indent_spaces (enum indent_mode mode); + +// Gets a string in a certain delim type. +std::string +get_string_in_delims (std::string str_input, DelimType delim_type); + +std::string +get_mode_dump_desc (AttrMode mode); + +// Adds lines below adding attributes +std::string +append_attributes (std::vector<Attribute> attrs, AttrMode mode); + +// Removes the beginning and end quotes of a quoted string. +std::string +unquote_string (std::string input); + +} // namespace AST +} // namespace Rust + +#endif /* ! RUST_AST_FORMATTING_H */ diff --git a/gcc/rust/ast/rust-ast-full.h b/gcc/rust/ast/rust-ast-full.h index 711039b..557b71e 100644 --- a/gcc/rust/ast/rust-ast-full.h +++ b/gcc/rust/ast/rust-ast-full.h @@ -20,6 +20,7 @@ #define RUST_AST_FULL_H // Use as a fast way of including all aspects of the AST (i.e. all headers) #include "rust-ast.h" +#include "rust-ast-formatting.h" #include "rust-expr.h" #include "rust-item.h" #include "rust-path.h" diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc index c0a54a5..7ba9be1 100644 --- a/gcc/rust/ast/rust-ast.cc +++ b/gcc/rust/ast/rust-ast.cc @@ -35,102 +35,6 @@ along with GCC; see the file COPYING3. If not see namespace Rust { namespace AST { -enum indent_mode -{ - enter, - out, - stay -}; - -std::string -indent_spaces (enum indent_mode mode) -{ - static int indent = 0; - std::string str = ""; - if (out == mode) - indent--; - for (int i = 0; i < indent; i++) - str += " "; - if (enter == mode) - indent++; - - return str; -} - -// Gets a string in a certain delim type. -std::string -get_string_in_delims (std::string str_input, DelimType delim_type) -{ - switch (delim_type) - { - case PARENS: - return "(" + str_input + ")"; - case SQUARE: - return "[" + str_input + "]"; - case CURLY: - return "{" + str_input + "}"; - default: - return "ERROR-MARK-STRING (delims)"; - } - gcc_unreachable (); -} - -enum AttrMode -{ - OUTER, - INNER -}; - -std::string -get_mode_dump_desc (AttrMode mode) -{ - switch (mode) - { - case OUTER: - return "outer attributes"; - case INNER: - return "inner attributes"; - default: - gcc_unreachable (); - return ""; - } -} - -// Adds lines below adding attributes -std::string -append_attributes (std::vector<Attribute> attrs, AttrMode mode) -{ - indent_spaces (enter); - - std::string str - = "\n" + indent_spaces (stay) + get_mode_dump_desc (mode) + ": "; - // str += "\n" + indent_spaces (stay) + "inner attributes: "; - if (attrs.empty ()) - { - str += "none"; - } - else - { - /* note that this does not print them with outer or "inner attribute" - * syntax - just prints the body */ - for (const auto &attr : attrs) - str += "\n" + indent_spaces (stay) + attr.as_string (); - } - - indent_spaces (out); - - return str; -} - -// Removes the beginning and end quotes of a quoted string. -std::string -unquote_string (std::string input) -{ - rust_assert (input.front () == '"'); - rust_assert (input.back () == '"'); - return input.substr (1, input.length () - 2); -} - std::string Crate::as_string () const { @@ -1472,22 +1376,6 @@ ReturnExpr::as_string () const } std::string -GroupedExpr::as_string () const -{ - std::string str ("Grouped expr:"); - - // outer attrs - str += append_attributes (outer_attrs, OUTER); - - // inner attributes - str += append_attributes (inner_attrs, INNER); - - str += "\n Expr in parens: " + expr_in_parens->as_string (); - - return str; -} - -std::string RangeToExpr::as_string () const { return ".." + to->as_string (); @@ -2466,286 +2354,6 @@ ForLoopExpr::as_string () const } std::string -RangePattern::as_string () const -{ - // TODO: maybe rewrite to work with non-linearisable bounds - if (has_ellipsis_syntax) - return lower->as_string () + "..." + upper->as_string (); - else - return lower->as_string () + "..=" + upper->as_string (); -} - -std::string -RangePatternBoundLiteral::as_string () const -{ - std::string str; - - if (has_minus) - str += "-"; - - str += literal.as_string (); - - return str; -} - -std::string -SlicePattern::as_string () const -{ - std::string str ("SlicePattern: "); - - for (const auto &pattern : items) - str += "\n " + pattern->as_string (); - - return str; -} - -std::string -AltPattern::as_string () const -{ - std::string str ("AltPattern: "); - - for (const auto &pattern : alts) - str += "\n " + pattern->as_string (); - - return str; -} - -std::string -TuplePatternItemsMultiple::as_string () const -{ - std::string str; - - for (const auto &pattern : patterns) - str += "\n " + pattern->as_string (); - - return str; -} - -std::string -TuplePatternItemsRanged::as_string () const -{ - std::string str; - - str += "\n Lower patterns: "; - if (lower_patterns.empty ()) - { - str += "none"; - } - else - { - for (const auto &lower : lower_patterns) - str += "\n " + lower->as_string (); - } - - str += "\n Upper patterns: "; - if (upper_patterns.empty ()) - { - str += "none"; - } - else - { - for (const auto &upper : upper_patterns) - str += "\n " + upper->as_string (); - } - - return str; -} - -std::string -TuplePattern::as_string () const -{ - return "TuplePattern: " + items->as_string (); -} - -std::string -StructPatternField::as_string () const -{ - // outer attributes - std::string str = append_attributes (outer_attrs, OUTER); - - return str; -} - -std::string -StructPatternFieldIdent::as_string () const -{ - std::string str = StructPatternField::as_string (); - - str += "\n"; - - if (has_ref) - str += "ref "; - - if (has_mut) - str += "mut "; - - str += ident; - - return str; -} - -std::string -StructPatternFieldTuplePat::as_string () const -{ - // TODO: maybe rewrite to work with non-linearisable patterns - std::string str = StructPatternField::as_string (); - - str += "\n"; - - str += std::to_string (index) + " : " + tuple_pattern->as_string (); - - return str; -} - -std::string -StructPatternFieldIdentPat::as_string () const -{ - // TODO: maybe rewrite to work with non-linearisable patterns - std::string str = StructPatternField::as_string (); - - str += "\n"; - - str += ident + " : " + ident_pattern->as_string (); - - return str; -} - -std::string -StructPatternElements::as_string () const -{ - std::string str ("\n Fields: "); - - if (!has_struct_pattern_fields ()) - { - str += "none"; - } - else - { - for (const auto &field : fields) - str += "\n " + field->as_string (); - } - - str += "\n Etc: "; - if (has_struct_pattern_etc) - str += "true"; - else - str += "false"; - - return str; -} - -std::string -StructPattern::as_string () const -{ - std::string str ("StructPattern: \n Path: "); - - str += path.as_string (); - - str += "\n Struct pattern elems: "; - if (!has_struct_pattern_elems ()) - str += "none"; - else - str += elems.as_string (); - - return str; -} - -std::string -LiteralPattern::as_string () const -{ - return lit.as_string (); -} - -std::string -ReferencePattern::as_string () const -{ - // TODO: maybe rewrite to work with non-linearisable patterns - std::string str ("&"); - - if (has_two_amps) - str += "&"; - - if (is_mut) - str += "mut "; - - str += pattern->as_string (); - - return str; -} - -std::string -IdentifierPattern::as_string () const -{ - // TODO: maybe rewrite to work with non-linearisable patterns - std::string str; - - if (is_ref) - str += "ref "; - - if (is_mut) - str += "mut "; - - str += variable_ident; - - if (has_pattern_to_bind ()) - str += " @ " + to_bind->as_string (); - - return str; -} - -std::string -TupleStructItemsNoRange::as_string () const -{ - std::string str; - - for (const auto &pattern : patterns) - str += "\n " + pattern->as_string (); - - return str; -} - -std::string -TupleStructItemsRange::as_string () const -{ - std::string str ("\n Lower patterns: "); - - if (lower_patterns.empty ()) - { - str += "none"; - } - else - { - for (const auto &lower : lower_patterns) - str += "\n " + lower->as_string (); - } - - str += "\n Upper patterns: "; - if (upper_patterns.empty ()) - { - str += "none"; - } - else - { - for (const auto &upper : upper_patterns) - str += "\n " + upper->as_string (); - } - - return str; -} - -std::string -TupleStructPattern::as_string () const -{ - std::string str ("TupleStructPattern: \n Path: "); - - str += path.as_string (); - - str += "\n Tuple struct items: " + items->as_string (); - - return str; -} - -std::string LetStmt::as_string () const { // TODO: rewrite to work with non-linearisable types and exprs @@ -4764,12 +4372,6 @@ CompoundAssignmentExpr::accept_vis (ASTVisitor &vis) } void -GroupedExpr::accept_vis (ASTVisitor &vis) -{ - vis.visit (*this); -} - -void ArrayElemsValues::accept_vis (ASTVisitor &vis) { vis.visit (*this); @@ -5256,138 +4858,6 @@ MacroInvocation::accept_vis (ASTVisitor &vis) } void -LiteralPattern::accept_vis (ASTVisitor &vis) -{ - vis.visit (*this); -} - -void -IdentifierPattern::accept_vis (ASTVisitor &vis) -{ - vis.visit (*this); -} - -void -WildcardPattern::accept_vis (ASTVisitor &vis) -{ - vis.visit (*this); -} - -void -RestPattern::accept_vis (ASTVisitor &vis) -{ - vis.visit (*this); -} - -void -RangePatternBoundLiteral::accept_vis (ASTVisitor &vis) -{ - vis.visit (*this); -} - -void -RangePatternBoundPath::accept_vis (ASTVisitor &vis) -{ - vis.visit (*this); -} - -void -RangePatternBoundQualPath::accept_vis (ASTVisitor &vis) -{ - vis.visit (*this); -} - -void -RangePattern::accept_vis (ASTVisitor &vis) -{ - vis.visit (*this); -} - -void -ReferencePattern::accept_vis (ASTVisitor &vis) -{ - vis.visit (*this); -} - -void -StructPatternFieldTuplePat::accept_vis (ASTVisitor &vis) -{ - vis.visit (*this); -} - -void -StructPatternFieldIdentPat::accept_vis (ASTVisitor &vis) -{ - vis.visit (*this); -} - -void -StructPatternFieldIdent::accept_vis (ASTVisitor &vis) -{ - vis.visit (*this); -} - -void -StructPattern::accept_vis (ASTVisitor &vis) -{ - vis.visit (*this); -} - -void -TupleStructItemsNoRange::accept_vis (ASTVisitor &vis) -{ - vis.visit (*this); -} - -void -TupleStructItemsRange::accept_vis (ASTVisitor &vis) -{ - vis.visit (*this); -} - -void -TupleStructPattern::accept_vis (ASTVisitor &vis) -{ - vis.visit (*this); -} - -void -TuplePatternItemsMultiple::accept_vis (ASTVisitor &vis) -{ - vis.visit (*this); -} - -void -TuplePatternItemsRanged::accept_vis (ASTVisitor &vis) -{ - vis.visit (*this); -} - -void -TuplePattern::accept_vis (ASTVisitor &vis) -{ - vis.visit (*this); -} - -void -GroupedPattern::accept_vis (ASTVisitor &vis) -{ - vis.visit (*this); -} - -void -SlicePattern::accept_vis (ASTVisitor &vis) -{ - vis.visit (*this); -} - -void -AltPattern::accept_vis (ASTVisitor &vis) -{ - vis.visit (*this); -} - -void EmptyStmt::accept_vis (ASTVisitor &vis) { vis.visit (*this); diff --git a/gcc/rust/ast/rust-pattern.cc b/gcc/rust/ast/rust-pattern.cc new file mode 100644 index 0000000..14179ca --- /dev/null +++ b/gcc/rust/ast/rust-pattern.cc @@ -0,0 +1,468 @@ +/* General AST-related method implementations for Rust frontend. + Copyright (C) 2009-2023 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +<http://www.gnu.org/licenses/>. */ + +#include "rust-system.h" +#include "rust-ast-full.h" +#include "rust-diagnostics.h" +#include "rust-ast-visitor.h" +#include "rust-macro.h" +#include "rust-session-manager.h" +#include "rust-lex.h" +#include "rust-parse.h" +#include "rust-operators.h" + +namespace Rust { +namespace AST { + +std::string +LiteralPattern::as_string () const +{ + return lit.as_string (); +} + +std::string +IdentifierPattern::as_string () const +{ + // TODO: maybe rewrite to work with non-linearisable patterns + std::string str; + + if (is_ref) + str += "ref "; + + if (is_mut) + str += "mut "; + + str += variable_ident; + + if (has_pattern_to_bind ()) + str += " @ " + to_bind->as_string (); + + return str; +} + +std::string +RangePatternBoundLiteral::as_string () const +{ + std::string str; + + if (has_minus) + str += "-"; + + str += literal.as_string (); + + return str; +} + +std::string +RangePattern::as_string () const +{ + // TODO: maybe rewrite to work with non-linearisable bounds + if (has_ellipsis_syntax) + return lower->as_string () + "..." + upper->as_string (); + else + return lower->as_string () + "..=" + upper->as_string (); +} + +std::string +ReferencePattern::as_string () const +{ + // TODO: maybe rewrite to work with non-linearisable patterns + std::string str ("&"); + + if (has_two_amps) + str += "&"; + + if (is_mut) + str += "mut "; + + str += pattern->as_string (); + + return str; +} + +std::string +StructPatternField::as_string () const +{ + // outer attributes + std::string str = append_attributes (outer_attrs, OUTER); + + return str; +} + +std::string +StructPatternFieldTuplePat::as_string () const +{ + // TODO: maybe rewrite to work with non-linearisable patterns + std::string str = StructPatternField::as_string (); + + str += "\n"; + + str += std::to_string (index) + " : " + tuple_pattern->as_string (); + + return str; +} + +std::string +StructPatternFieldIdentPat::as_string () const +{ + // TODO: maybe rewrite to work with non-linearisable patterns + std::string str = StructPatternField::as_string (); + + str += "\n"; + + str += ident + " : " + ident_pattern->as_string (); + + return str; +} + +std::string +StructPatternFieldIdent::as_string () const +{ + std::string str = StructPatternField::as_string (); + + str += "\n"; + + if (has_ref) + str += "ref "; + + if (has_mut) + str += "mut "; + + str += ident; + + return str; +} + +std::string +StructPatternElements::as_string () const +{ + std::string str ("\n Fields: "); + + if (!has_struct_pattern_fields ()) + { + str += "none"; + } + else + { + for (const auto &field : fields) + str += "\n " + field->as_string (); + } + + str += "\n Etc: "; + if (has_struct_pattern_etc) + str += "true"; + else + str += "false"; + + return str; +} + +std::string +StructPattern::as_string () const +{ + std::string str ("StructPattern: \n Path: "); + + str += path.as_string (); + + str += "\n Struct pattern elems: "; + if (!has_struct_pattern_elems ()) + str += "none"; + else + str += elems.as_string (); + + return str; +} + +std::string +TupleStructItemsNoRange::as_string () const +{ + std::string str; + + for (const auto &pattern : patterns) + str += "\n " + pattern->as_string (); + + return str; +} + +std::string +TupleStructItemsRange::as_string () const +{ + std::string str ("\n Lower patterns: "); + + if (lower_patterns.empty ()) + { + str += "none"; + } + else + { + for (const auto &lower : lower_patterns) + str += "\n " + lower->as_string (); + } + + str += "\n Upper patterns: "; + if (upper_patterns.empty ()) + { + str += "none"; + } + else + { + for (const auto &upper : upper_patterns) + str += "\n " + upper->as_string (); + } + + return str; +} + +std::string +TupleStructPattern::as_string () const +{ + std::string str ("TupleStructPattern: \n Path: "); + + str += path.as_string (); + + str += "\n Tuple struct items: " + items->as_string (); + + return str; +} + +std::string +TuplePatternItemsMultiple::as_string () const +{ + std::string str; + + for (const auto &pattern : patterns) + str += "\n " + pattern->as_string (); + + return str; +} + +std::string +TuplePatternItemsRanged::as_string () const +{ + std::string str; + + str += "\n Lower patterns: "; + if (lower_patterns.empty ()) + { + str += "none"; + } + else + { + for (const auto &lower : lower_patterns) + str += "\n " + lower->as_string (); + } + + str += "\n Upper patterns: "; + if (upper_patterns.empty ()) + { + str += "none"; + } + else + { + for (const auto &upper : upper_patterns) + str += "\n " + upper->as_string (); + } + + return str; +} + +std::string +TuplePattern::as_string () const +{ + return "TuplePattern: " + items->as_string (); +} + +std::string +GroupedExpr::as_string () const +{ + std::string str ("Grouped expr:"); + + // outer attrs + str += append_attributes (outer_attrs, OUTER); + + // inner attributes + str += append_attributes (inner_attrs, INNER); + + str += "\n Expr in parens: " + expr_in_parens->as_string (); + + return str; +} + +std::string +SlicePattern::as_string () const +{ + std::string str ("SlicePattern: "); + + for (const auto &pattern : items) + str += "\n " + pattern->as_string (); + + return str; +} + +std::string +AltPattern::as_string () const +{ + std::string str ("AltPattern: "); + + for (const auto &pattern : alts) + str += "\n " + pattern->as_string (); + + return str; +} + +void +AltPattern::accept_vis (ASTVisitor &vis) +{ + vis.visit (*this); +} + +void +GroupedPattern::accept_vis (ASTVisitor &vis) +{ + vis.visit (*this); +} + +void +GroupedExpr::accept_vis (ASTVisitor &vis) +{ + vis.visit (*this); +} + +void +SlicePattern::accept_vis (ASTVisitor &vis) +{ + vis.visit (*this); +} + +void +TuplePatternItemsRanged::accept_vis (ASTVisitor &vis) +{ + vis.visit (*this); +} + +void +TuplePattern::accept_vis (ASTVisitor &vis) +{ + vis.visit (*this); +} + +void +TuplePatternItemsMultiple::accept_vis (ASTVisitor &vis) +{ + vis.visit (*this); +} + +void +LiteralPattern::accept_vis (ASTVisitor &vis) +{ + vis.visit (*this); +} + +void +IdentifierPattern::accept_vis (ASTVisitor &vis) +{ + vis.visit (*this); +} + +void +WildcardPattern::accept_vis (ASTVisitor &vis) +{ + vis.visit (*this); +} + +void +RestPattern::accept_vis (ASTVisitor &vis) +{ + vis.visit (*this); +} + +void +RangePatternBoundLiteral::accept_vis (ASTVisitor &vis) +{ + vis.visit (*this); +} + +void +RangePatternBoundPath::accept_vis (ASTVisitor &vis) +{ + vis.visit (*this); +} + +void +RangePatternBoundQualPath::accept_vis (ASTVisitor &vis) +{ + vis.visit (*this); +} + +void +RangePattern::accept_vis (ASTVisitor &vis) +{ + vis.visit (*this); +} + +void +ReferencePattern::accept_vis (ASTVisitor &vis) +{ + vis.visit (*this); +} + +void +StructPatternFieldTuplePat::accept_vis (ASTVisitor &vis) +{ + vis.visit (*this); +} + +void +StructPatternFieldIdentPat::accept_vis (ASTVisitor &vis) +{ + vis.visit (*this); +} + +void +StructPatternFieldIdent::accept_vis (ASTVisitor &vis) +{ + vis.visit (*this); +} + +void +StructPattern::accept_vis (ASTVisitor &vis) +{ + vis.visit (*this); +} + +void +TupleStructItemsNoRange::accept_vis (ASTVisitor &vis) +{ + vis.visit (*this); +} + +void +TupleStructItemsRange::accept_vis (ASTVisitor &vis) +{ + vis.visit (*this); +} + +void +TupleStructPattern::accept_vis (ASTVisitor &vis) +{ + vis.visit (*this); +} + +} // namespace AST +} // namespace Rust |