summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Hodge (sonata) <tpg@mutabah.net>2015-01-18 12:56:30 +0800
committerJohn Hodge (sonata) <tpg@mutabah.net>2015-01-18 12:56:30 +0800
commitba61031285402285e88a16f3788c20f455acc8e3 (patch)
tree8407f6ea4cbe1e5a2aed163ef5a4ebb22b5ddad4 /src
parent0390dc8a92c3c8d12421d529915ab350234301c3 (diff)
downloadmrust-ba61031285402285e88a16f3788c20f455acc8e3.tar.gz
Added support for associated types in impl blocks
Diffstat (limited to 'src')
-rw-r--r--src/ast/ast.cpp3
-rw-r--r--src/ast/ast.hpp11
-rw-r--r--src/ast/path.cpp4
-rw-r--r--src/parse/root.cpp7
4 files changed, 22 insertions, 3 deletions
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<Item<Function> > m_functions;
+ ItemList<TypeRef> m_types;
+ ItemList<Function> 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<Function>( ::std::move(name), ::std::move(fcn), is_public ) );
}
+ void add_type(bool is_public, ::std::string name, TypeRef type) {
+ m_types.push_back( Item<TypeRef>( ::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<Function>& functions() const { return m_functions; }
+ const ItemList<TypeRef>& types() const { return m_types; }
TypeParams& params() { return m_params; }
TypeRef& trait() { return m_trait; }
TypeRef& type() { return m_type; }
- ::std::vector<Item<Function> >& functions() { return m_functions; }
+ ItemList<Function>& functions() { return m_functions; }
+ ItemList<TypeRef>& 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 << "["<<path.m_crate<<"]";
for(const auto& n : path.m_nodes)
os << n;
break;
diff --git a/src/parse/root.cpp b/src/parse/root.cpp
index 2c0acd4e..1ab010bd 100644
--- a/src/parse/root.cpp
+++ b/src/parse/root.cpp
@@ -640,6 +640,13 @@ AST::Impl Parse_Impl(TokenStream& lex)
}
switch(tok.type())
{
+ case TOK_RWORD_TYPE: {
+ GET_CHECK_TOK(tok, lex, TOK_IDENT);
+ ::std::string name = tok.str();
+ GET_CHECK_TOK(tok, lex, TOK_EQUAL);
+ impl.add_type(is_public, name, Parse_Type(lex));
+ GET_CHECK_TOK(tok, lex, TOK_SEMICOLON);
+ break; }
case TOK_RWORD_FN: {
GET_CHECK_TOK(tok, lex, TOK_IDENT);
::std::string name = tok.str();