diff options
author | CohenArthur <arthur.cohen@epita.fr> | 2021-08-03 16:22:46 +0200 |
---|---|---|
committer | CohenArthur <arthur.cohen@epita.fr> | 2021-08-03 17:55:22 +0200 |
commit | 2e45247314936f2a662a4f5ed34799942277f911 (patch) | |
tree | 13f1907b98c342c1f95ef9c5a39a76489bd037be /gcc | |
parent | 76d9871594d5eac8a78a3434f6ab9761da339cd0 (diff) | |
download | gcc-2e45247314936f2a662a4f5ed34799942277f911.zip gcc-2e45247314936f2a662a4f5ed34799942277f911.tar.gz gcc-2e45247314936f2a662a4f5ed34799942277f911.tar.bz2 |
module: Merge both as_string() implementations
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/ast/rust-ast-full-test.cc | 36 |
1 files changed, 9 insertions, 27 deletions
diff --git a/gcc/rust/ast/rust-ast-full-test.cc b/gcc/rust/ast/rust-ast-full-test.cc index 5d32139..dfd9cdb 100644 --- a/gcc/rust/ast/rust-ast-full-test.cc +++ b/gcc/rust/ast/rust-ast-full-test.cc @@ -379,22 +379,20 @@ VisItem::as_string () const std::string Module::as_string () const { - std::string vis_item = VisItem::as_string (); + std::string str = VisItem::as_string () + "mod " + module_name; - return vis_item + "mod " + module_name; -} - -std::string -ModuleBodied::as_string () const -{ - // get module string for "[vis] mod [name]" - std::string str = Module::as_string (); + // Return early if we're dealing with an unloaded module as their body resides + // in a different file + if (kind == ModuleKind::UNLOADED) + return str + "\n no body (reference to external file)\n"; // inner attributes str += append_attributes (inner_attrs, INNER); // items str += "\n items: "; + + // This can still happen if the module is loaded but empty, i.e. `mod foo {}` if (items.empty ()) { str += "none"; @@ -419,16 +417,6 @@ ModuleBodied::as_string () const } std::string -ModuleNoBody::as_string () const -{ - std::string str = Module::as_string (); - - str += "\n no body (reference to external file)"; - - return str + "\n"; -} - -std::string StaticItem::as_string () const { std::string str = VisItem::as_string (); @@ -4053,7 +4041,7 @@ AttrInputMetaItemContainer::as_string () const /* Override that calls the function recursively on all items contained within * the module. */ void -ModuleBodied::add_crate_name (std::vector<std::string> &names) const +Module::add_crate_name (std::vector<std::string> &names) const { /* TODO: test whether module has been 'cfg'-ed out to determine whether to * exclude it from search */ @@ -5381,13 +5369,7 @@ Method::accept_vis (ASTVisitor &vis) } void -ModuleBodied::accept_vis (ASTVisitor &vis) -{ - vis.visit (*this); -} - -void -ModuleNoBody::accept_vis (ASTVisitor &vis) +Module::accept_vis (ASTVisitor &vis) { vis.visit (*this); } |