From 629fa5d38be99066f0fdb664796e9f7c6aea49ba Mon Sep 17 00:00:00 2001 From: John Hodge Date: Fri, 18 Mar 2016 13:06:35 +0800 Subject: AST - Switch impl blocks to contain `Item`s (merges code) --- src/ast/ast.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'src/ast/ast.cpp') diff --git a/src/ast/ast.cpp b/src/ast/ast.cpp index 0739fde2..4229f1e8 100644 --- a/src/ast/ast.cpp +++ b/src/ast/ast.cpp @@ -140,9 +140,22 @@ SERIALISE_TYPE(ImplDef::, "AST_ImplDef", { s.item(m_type); }) +void Impl::add_function(bool is_public, ::std::string name, Function fcn) +{ + m_items.push_back( Named( mv$(name), Item::make_Function({::std::move(fcn)}), is_public ) ); +} +void Impl::add_type(bool is_public, ::std::string name, TypeRef type) +{ + m_items.push_back( Named( mv$(name), Item::make_Type({TypeAlias(GenericParams(), mv$(type))}), is_public ) ); +} +void Impl::add_static(bool is_public, ::std::string name, Static v) +{ + m_items.push_back( Named( mv$(name), Item::make_Static({mv$(v)}), is_public ) ); +} + bool Impl::has_named_item(const ::std::string& name) const { - for( const auto& it : this->functions() ) + for( const auto& it : this->items() ) { if( it.name == name ) { return true; @@ -210,10 +223,10 @@ Impl Impl::make_concrete(const ::std::vector& types) const } SERIALISE_TYPE(Impl::, "AST_Impl", { s << m_def; - s << m_functions; + s << m_items; },{ s.item(m_def); - s.item(m_functions); + s.item(m_items); }) ::rust::option ImplRef::find_named_item(const ::std::string& name) const -- cgit v1.2.3