gccrs: Move SingleASTNode implementation out of header
Those functions implementation put additional constraints on the headers which makes the codebase harder to work with. gcc/rust/ChangeLog: * ast/rust-ast.h: Move implementation from here... * ast/rust-ast.cc (SingleASTNode::SingleASTNode): ...to here. (SingleASTNode::operator=): ...and here... (SingleASTNode::accept_vis): ...and here... (SingleASTNode::is_error): ...and here... (SingleASTNode::as_string): ...also here. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
This commit is contained in:
parent
74ef5529c8
commit
55bfecc95a
2 changed files with 179 additions and 164 deletions
|
@ -17,6 +17,7 @@ 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.h"
|
||||
#include "rust-system.h"
|
||||
#include "rust-ast-full.h"
|
||||
#include "rust-diagnostics.h"
|
||||
|
@ -37,6 +38,179 @@ along with GCC; see the file COPYING3. If not see
|
|||
namespace Rust {
|
||||
namespace AST {
|
||||
|
||||
SingleASTNode::SingleASTNode (SingleASTNode const &other)
|
||||
{
|
||||
kind = other.kind;
|
||||
switch (kind)
|
||||
{
|
||||
case EXPRESSION:
|
||||
expr = other.expr->clone_expr ();
|
||||
break;
|
||||
|
||||
case ITEM:
|
||||
item = other.item->clone_item ();
|
||||
break;
|
||||
|
||||
case STMT:
|
||||
stmt = other.stmt->clone_stmt ();
|
||||
break;
|
||||
|
||||
case EXTERN:
|
||||
external_item = other.external_item->clone_external_item ();
|
||||
break;
|
||||
|
||||
case TRAIT:
|
||||
trait_item = other.trait_item->clone_trait_item ();
|
||||
break;
|
||||
|
||||
case IMPL:
|
||||
impl_item = other.impl_item->clone_inherent_impl_item ();
|
||||
break;
|
||||
|
||||
case TRAIT_IMPL:
|
||||
trait_impl_item = other.trait_impl_item->clone_trait_impl_item ();
|
||||
break;
|
||||
|
||||
case TYPE:
|
||||
type = other.type->clone_type ();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
SingleASTNode
|
||||
SingleASTNode::operator= (SingleASTNode const &other)
|
||||
{
|
||||
kind = other.kind;
|
||||
switch (kind)
|
||||
{
|
||||
case EXPRESSION:
|
||||
expr = other.expr->clone_expr ();
|
||||
break;
|
||||
|
||||
case ITEM:
|
||||
item = other.item->clone_item ();
|
||||
break;
|
||||
|
||||
case STMT:
|
||||
stmt = other.stmt->clone_stmt ();
|
||||
break;
|
||||
|
||||
case EXTERN:
|
||||
external_item = other.external_item->clone_external_item ();
|
||||
break;
|
||||
|
||||
case TRAIT:
|
||||
trait_item = other.trait_item->clone_trait_item ();
|
||||
break;
|
||||
|
||||
case IMPL:
|
||||
impl_item = other.impl_item->clone_inherent_impl_item ();
|
||||
break;
|
||||
|
||||
case TRAIT_IMPL:
|
||||
trait_impl_item = other.trait_impl_item->clone_trait_impl_item ();
|
||||
break;
|
||||
|
||||
case TYPE:
|
||||
type = other.type->clone_type ();
|
||||
break;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
void
|
||||
SingleASTNode::accept_vis (ASTVisitor &vis)
|
||||
{
|
||||
switch (kind)
|
||||
{
|
||||
case EXPRESSION:
|
||||
expr->accept_vis (vis);
|
||||
break;
|
||||
|
||||
case ITEM:
|
||||
item->accept_vis (vis);
|
||||
break;
|
||||
|
||||
case STMT:
|
||||
stmt->accept_vis (vis);
|
||||
break;
|
||||
|
||||
case EXTERN:
|
||||
external_item->accept_vis (vis);
|
||||
break;
|
||||
|
||||
case TRAIT:
|
||||
trait_item->accept_vis (vis);
|
||||
break;
|
||||
|
||||
case IMPL:
|
||||
impl_item->accept_vis (vis);
|
||||
break;
|
||||
|
||||
case TRAIT_IMPL:
|
||||
trait_impl_item->accept_vis (vis);
|
||||
break;
|
||||
|
||||
case TYPE:
|
||||
type->accept_vis (vis);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
SingleASTNode::is_error ()
|
||||
{
|
||||
switch (kind)
|
||||
{
|
||||
case EXPRESSION:
|
||||
return expr == nullptr;
|
||||
case ITEM:
|
||||
return item == nullptr;
|
||||
case STMT:
|
||||
return stmt == nullptr;
|
||||
case EXTERN:
|
||||
return external_item == nullptr;
|
||||
case TRAIT:
|
||||
return trait_item == nullptr;
|
||||
case IMPL:
|
||||
return impl_item == nullptr;
|
||||
case TRAIT_IMPL:
|
||||
return trait_impl_item == nullptr;
|
||||
case TYPE:
|
||||
return type == nullptr;
|
||||
}
|
||||
|
||||
rust_unreachable ();
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string
|
||||
SingleASTNode::as_string () const
|
||||
{
|
||||
switch (kind)
|
||||
{
|
||||
case EXPRESSION:
|
||||
return "Expr: " + expr->as_string ();
|
||||
case ITEM:
|
||||
return "Item: " + item->as_string ();
|
||||
case STMT:
|
||||
return "Stmt: " + stmt->as_string ();
|
||||
case EXTERN:
|
||||
return "External Item: " + external_item->as_string ();
|
||||
case TRAIT:
|
||||
return "Trait Item: " + trait_item->as_string ();
|
||||
case IMPL:
|
||||
return "Impl Item: " + impl_item->as_string ();
|
||||
case TRAIT_IMPL:
|
||||
return "Trait Impl Item: " + trait_impl_item->as_string ();
|
||||
case TYPE:
|
||||
return "Type: " + type->as_string ();
|
||||
}
|
||||
|
||||
rust_unreachable ();
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string
|
||||
Crate::as_string () const
|
||||
{
|
||||
|
|
|
@ -1708,84 +1708,9 @@ public:
|
|||
: kind (TYPE), type (std::move (type))
|
||||
{}
|
||||
|
||||
SingleASTNode (SingleASTNode const &other)
|
||||
{
|
||||
kind = other.kind;
|
||||
switch (kind)
|
||||
{
|
||||
case EXPRESSION:
|
||||
expr = other.expr->clone_expr ();
|
||||
break;
|
||||
SingleASTNode (SingleASTNode const &other);
|
||||
|
||||
case ITEM:
|
||||
item = other.item->clone_item ();
|
||||
break;
|
||||
|
||||
case STMT:
|
||||
stmt = other.stmt->clone_stmt ();
|
||||
break;
|
||||
|
||||
case EXTERN:
|
||||
external_item = other.external_item->clone_external_item ();
|
||||
break;
|
||||
|
||||
case TRAIT:
|
||||
trait_item = other.trait_item->clone_trait_item ();
|
||||
break;
|
||||
|
||||
case IMPL:
|
||||
impl_item = other.impl_item->clone_inherent_impl_item ();
|
||||
break;
|
||||
|
||||
case TRAIT_IMPL:
|
||||
trait_impl_item = other.trait_impl_item->clone_trait_impl_item ();
|
||||
break;
|
||||
|
||||
case TYPE:
|
||||
type = other.type->clone_type ();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
SingleASTNode operator= (SingleASTNode const &other)
|
||||
{
|
||||
kind = other.kind;
|
||||
switch (kind)
|
||||
{
|
||||
case EXPRESSION:
|
||||
expr = other.expr->clone_expr ();
|
||||
break;
|
||||
|
||||
case ITEM:
|
||||
item = other.item->clone_item ();
|
||||
break;
|
||||
|
||||
case STMT:
|
||||
stmt = other.stmt->clone_stmt ();
|
||||
break;
|
||||
|
||||
case EXTERN:
|
||||
external_item = other.external_item->clone_external_item ();
|
||||
break;
|
||||
|
||||
case TRAIT:
|
||||
trait_item = other.trait_item->clone_trait_item ();
|
||||
break;
|
||||
|
||||
case IMPL:
|
||||
impl_item = other.impl_item->clone_inherent_impl_item ();
|
||||
break;
|
||||
|
||||
case TRAIT_IMPL:
|
||||
trait_impl_item = other.trait_impl_item->clone_trait_impl_item ();
|
||||
break;
|
||||
|
||||
case TYPE:
|
||||
type = other.type->clone_type ();
|
||||
break;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
SingleASTNode operator= (SingleASTNode const &other);
|
||||
|
||||
SingleASTNode (SingleASTNode &&other) = default;
|
||||
SingleASTNode &operator= (SingleASTNode &&other) = default;
|
||||
|
@ -1863,95 +1788,11 @@ public:
|
|||
return std::move (type);
|
||||
}
|
||||
|
||||
void accept_vis (ASTVisitor &vis) override
|
||||
{
|
||||
switch (kind)
|
||||
{
|
||||
case EXPRESSION:
|
||||
expr->accept_vis (vis);
|
||||
break;
|
||||
void accept_vis (ASTVisitor &vis) override;
|
||||
|
||||
case ITEM:
|
||||
item->accept_vis (vis);
|
||||
break;
|
||||
bool is_error ();
|
||||
|
||||
case STMT:
|
||||
stmt->accept_vis (vis);
|
||||
break;
|
||||
|
||||
case EXTERN:
|
||||
external_item->accept_vis (vis);
|
||||
break;
|
||||
|
||||
case TRAIT:
|
||||
trait_item->accept_vis (vis);
|
||||
break;
|
||||
|
||||
case IMPL:
|
||||
impl_item->accept_vis (vis);
|
||||
break;
|
||||
|
||||
case TRAIT_IMPL:
|
||||
trait_impl_item->accept_vis (vis);
|
||||
break;
|
||||
|
||||
case TYPE:
|
||||
type->accept_vis (vis);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool is_error ()
|
||||
{
|
||||
switch (kind)
|
||||
{
|
||||
case EXPRESSION:
|
||||
return expr == nullptr;
|
||||
case ITEM:
|
||||
return item == nullptr;
|
||||
case STMT:
|
||||
return stmt == nullptr;
|
||||
case EXTERN:
|
||||
return external_item == nullptr;
|
||||
case TRAIT:
|
||||
return trait_item == nullptr;
|
||||
case IMPL:
|
||||
return impl_item == nullptr;
|
||||
case TRAIT_IMPL:
|
||||
return trait_impl_item == nullptr;
|
||||
case TYPE:
|
||||
return type == nullptr;
|
||||
}
|
||||
|
||||
rust_unreachable ();
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string as_string () const
|
||||
{
|
||||
switch (kind)
|
||||
{
|
||||
case EXPRESSION:
|
||||
return "Expr: " + expr->as_string ();
|
||||
case ITEM:
|
||||
return "Item: " + item->as_string ();
|
||||
case STMT:
|
||||
return "Stmt: " + stmt->as_string ();
|
||||
case EXTERN:
|
||||
return "External Item: " + external_item->as_string ();
|
||||
case TRAIT:
|
||||
return "Trait Item: " + trait_item->as_string ();
|
||||
case IMPL:
|
||||
return "Impl Item: " + impl_item->as_string ();
|
||||
case TRAIT_IMPL:
|
||||
return "Trait Impl Item: " + trait_impl_item->as_string ();
|
||||
case TYPE:
|
||||
return "Type: " + type->as_string ();
|
||||
}
|
||||
|
||||
rust_unreachable ();
|
||||
return "";
|
||||
}
|
||||
std::string as_string () const;
|
||||
};
|
||||
|
||||
// A crate AST object - holds all the data for a single compilation unit
|
||||
|
|
Loading…
Add table
Reference in a new issue