From ba61031285402285e88a16f3788c20f455acc8e3 Mon Sep 17 00:00:00 2001 From: "John Hodge (sonata)" Date: Sun, 18 Jan 2015 12:56:30 +0800 Subject: Added support for associated types in impl blocks --- src/ast/ast.cpp | 3 ++- src/ast/ast.hpp | 11 +++++++++-- src/ast/path.cpp | 4 ++++ src/parse/root.cpp | 7 +++++++ 4 files changed, 22 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/ast/ast.cpp b/src/ast/ast.cpp index c8cf8188..696978fb 100644 --- a/src/ast/ast.cpp +++ b/src/ast/ast.cpp @@ -327,7 +327,8 @@ SERIALISE_TYPE(TypeParam::, "AST_TypeParam", { ::std::ostream& operator<<(::std::ostream& os, const GenericBound& x) { - return os << "GenericBound(" << x.m_argname << "," << x.m_lifetime << "," << x.m_trait << ")"; + //return os << "GenericBound(" << x.m_argname << "," << x.m_lifetime << "," << x.m_trait << ")"; + return os << x.m_argname << ": ('" << x.m_lifetime << " + " << x.m_trait << ")"; } SERIALISE_TYPE_S(GenericBound, { s.item(m_argname); diff --git a/src/ast/ast.hpp b/src/ast/ast.hpp index a57b4308..20d28467 100644 --- a/src/ast/ast.hpp +++ b/src/ast/ast.hpp @@ -315,7 +315,8 @@ class Impl: TypeRef m_trait; TypeRef m_type; - ::std::vector > m_functions; + ItemList m_types; + ItemList m_functions; public: Impl() {} Impl(TypeParams params, TypeRef impl_type, TypeRef trait_type): @@ -327,15 +328,21 @@ public: void add_function(bool is_public, ::std::string name, Function fcn) { m_functions.push_back( Item( ::std::move(name), ::std::move(fcn), is_public ) ); } + void add_type(bool is_public, ::std::string name, TypeRef type) { + m_types.push_back( Item( ::std::move(name), ::std::move(type), is_public ) ); + } const TypeParams& params() const { return m_params; } const TypeRef& trait() const { return m_trait; } const TypeRef& type() const { return m_type; } + const ItemList& functions() const { return m_functions; } + const ItemList& types() const { return m_types; } TypeParams& params() { return m_params; } TypeRef& trait() { return m_trait; } TypeRef& type() { return m_type; } - ::std::vector >& functions() { return m_functions; } + ItemList& functions() { return m_functions; } + ItemList& types() { return m_types; } friend ::std::ostream& operator<<(::std::ostream& os, const Impl& impl); SERIALISABLE_PROTOTYPES(); diff --git a/src/ast/path.cpp b/src/ast/path.cpp index e1a265bf..16c9c5cc 100644 --- a/src/ast/path.cpp +++ b/src/ast/path.cpp @@ -306,7 +306,11 @@ Path& Path::operator+=(const Path& other) { case Path::RELATIVE: os << "self"; + for(const auto& n : path.m_nodes) + os << n; + break; case Path::ABSOLUTE: + os << "["<