single_ast_node: Add TYPE kind

This commit is contained in:
Arthur Cohen 2022-03-28 10:33:25 +02:00
parent e8b9587d3a
commit cf94fd8d51
1 changed files with 28 additions and 0 deletions

View File

@ -1515,6 +1515,7 @@ public:
TRAIT,
IMPL,
TRAIT_IMPL,
TYPE,
};
private:
@ -1528,6 +1529,7 @@ private:
std::unique_ptr<TraitItem> trait_item;
std::unique_ptr<InherentImplItem> impl_item;
std::unique_ptr<TraitImplItem> trait_impl_item;
std::unique_ptr<Type> type;
public:
SingleASTNode (std::unique_ptr<Expr> expr)
@ -1558,6 +1560,10 @@ public:
: kind (TRAIT_IMPL), trait_impl_item (std::move (trait_impl_item))
{}
SingleASTNode (std::unique_ptr<Type> type)
: kind (TYPE), type (std::move (type))
{}
SingleASTNode (SingleASTNode const &other)
{
kind = other.kind;
@ -1590,6 +1596,10 @@ public:
case TRAIT_IMPL:
trait_impl_item = other.trait_impl_item->clone_trait_impl_item ();
break;
case TYPE:
type = other.type->clone_type ();
break;
}
}
@ -1625,6 +1635,10 @@ public:
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;
}
@ -1699,6 +1713,12 @@ public:
return std::move (trait_impl_item);
}
std::unique_ptr<Type> take_type ()
{
rust_assert (!is_error ());
return std::move (type);
}
void accept_vis (ASTVisitor &vis)
{
switch (kind)
@ -1730,6 +1750,10 @@ public:
case TRAIT_IMPL:
trait_impl_item->accept_vis (vis);
break;
case TYPE:
type->accept_vis (vis);
break;
}
}
@ -1751,6 +1775,8 @@ public:
return impl_item == nullptr;
case TRAIT_IMPL:
return trait_impl_item == nullptr;
case TYPE:
return type == nullptr;
}
gcc_unreachable ();
@ -1775,6 +1801,8 @@ public:
return "Impl Item: " + impl_item->as_string ();
case TRAIT_IMPL:
return "Trait Impl Item: " + impl_item->as_string ();
case TYPE:
return "Type: " + type->as_string ();
}
gcc_unreachable ();