summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2015-03-26 10:40:57 +0800
committerJohn Hodge <tpg@mutabah.net>2015-03-26 10:40:57 +0800
commit7634647e1fcb7b1b6bcefd992d65b6b25277dfcc (patch)
tree10139bc0066fb1ac38b13e780426b85c5a2f2300
parentc7fa1f97f7b5a9eb4cf984e52a007d4dc51effa7 (diff)
downloadmrust-7634647e1fcb7b1b6bcefd992d65b6b25277dfcc.tar.gz
Remove the ASSOCIATED type (now handled by the UFCS path type)
-rw-r--r--src/ast/path.cpp2
-rw-r--r--src/parse/paths.cpp20
-rw-r--r--src/parse/root.cpp3
-rw-r--r--src/parse/types.cpp7
-rw-r--r--src/types.cpp31
-rw-r--r--src/types.hpp15
6 files changed, 28 insertions, 50 deletions
diff --git a/src/ast/path.cpp b/src/ast/path.cpp
index c722dbc9..9548730e 100644
--- a/src/ast/path.cpp
+++ b/src/ast/path.cpp
@@ -429,7 +429,7 @@ void Path::print_pretty(::std::ostream& os) const
os << path.m_nodes[0].name();
break;
case Path::UFCS:
- os << "<" << path.m_ufcs[0] << " as " << path.m_ufcs[1] << ">";
+ os << "/*ufcs*/<" << path.m_ufcs[0] << " as " << path.m_ufcs[1] << ">";
for(const auto& n : path.m_nodes)
os << "::" << n;
}
diff --git a/src/parse/paths.cpp b/src/parse/paths.cpp
index 3fb1d779..a8c6802d 100644
--- a/src/parse/paths.cpp
+++ b/src/parse/paths.cpp
@@ -17,10 +17,24 @@ AST::Path Parse_PathFrom(TokenStream& lex, AST::Path path, eParsePathGenericMo
AST::Path Parse_Path(TokenStream& lex, eParsePathGenericMode generic_mode)
{
Token tok;
- if( GET_TOK(tok, lex) == TOK_DOUBLE_COLON )
- return Parse_Path(lex, true, generic_mode);
- else
+ switch( GET_TOK(tok, lex) )
{
+ case TOK_DOUBLE_COLON:
+ return Parse_Path(lex, true, generic_mode);
+ case TOK_LT: {
+ TypeRef ty = Parse_Type(lex);
+ TypeRef trait;
+ if( GET_TOK(tok, lex) == TOK_RWORD_AS ) {
+ trait = Parse_Type(lex);
+ }
+ else
+ lex.putback(tok);
+ GET_CHECK_TOK(tok, lex, TOK_GT);
+ // TODO: Terminating the "path" here is sometimes valid
+ GET_CHECK_TOK(tok, lex, TOK_DOUBLE_COLON);
+ return Parse_PathFrom(lex, AST::Path(AST::Path::TagUfcs(), ty, trait), PATH_GENERIC_EXPR);
+ }
+ default:
lex.putback(tok);
return Parse_Path(lex, false, generic_mode);
}
diff --git a/src/parse/root.cpp b/src/parse/root.cpp
index 78ae4d2a..c7518422 100644
--- a/src/parse/root.cpp
+++ b/src/parse/root.cpp
@@ -457,7 +457,8 @@ AST::Trait Parse_TraitDef(TokenStream& lex, const AST::MetaItems& meta_items)
if( GET_TOK(tok, lex) == TOK_COLON )
{
// Bounded associated type
- TypeRef a_type = TypeRef(TypeRef::TagAssoc(), TypeRef(TypeRef::TagArg(), "Self"), TypeRef(), name);
+ TypeRef a_type = TypeRef( AST::Path(AST::Path::TagUfcs(), TypeRef(TypeRef::TagArg(), "Self"), TypeRef())+ name);
+ //TypeRef a_type = TypeRef(TypeRef::TagAssoc(), TypeRef(TypeRef::TagArg(), "Self"), TypeRef(), name);
Parse_TypeBound(lex, params, a_type);
GET_TOK(tok, lex);
}
diff --git a/src/parse/types.cpp b/src/parse/types.cpp
index bbbdd4f8..2070a0d2 100644
--- a/src/parse/types.cpp
+++ b/src/parse/types.cpp
@@ -63,7 +63,11 @@ TypeRef Parse_Type(TokenStream& lex)
case TOK_RWORD_FN:
return Parse_Type_Fn(lex, "");
// '<' - An associated type cast
- case TOK_LT: {
+ case TOK_LT:
+ lex.putback(tok);
+ return TypeRef(TypeRef::TagPath(), Parse_Path(lex, PATH_GENERIC_TYPE));
+ #if 0
+ {
DEBUG("Associated type");
// TODO: This should instead use the path code, not a special case in typing
// <Type as Trait>::Inner
@@ -77,6 +81,7 @@ TypeRef Parse_Type(TokenStream& lex)
::std::string inner_name = tok.str();
return TypeRef(TypeRef::TagAssoc(), ::std::move(base), ::std::move(trait), ::std::move(inner_name));
}
+ #endif
// <ident> - Either a primitive, or a path
case TOK_IDENT:
// or a primitive
diff --git a/src/types.cpp b/src/types.cpp
index 0817f670..0d38ae26 100644
--- a/src/types.cpp
+++ b/src/types.cpp
@@ -66,8 +66,6 @@ bool TypeRef::deref(bool is_implicit)
case TypeRef::ARRAY:
case TypeRef::PATH:
throw ::std::runtime_error("TODO: Search for an impl of Deref");
- case TypeRef::ASSOCIATED:
- throw ::std::runtime_error("TODO: TypeRef::deref on ASSOCIATED");
case TypeRef::MULTIDST:
throw ::std::runtime_error("TODO: TypeRef::deref on MULTIDST");
}
@@ -140,8 +138,6 @@ void TypeRef::merge_with(const TypeRef& other)
throw ::std::runtime_error("TODO: TypeRef::merge_with on GENERIC");
case TypeRef::PATH:
throw ::std::runtime_error("TODO: TypeRef::merge_with on PATH");
- case TypeRef::ASSOCIATED:
- throw ::std::runtime_error("TODO: TypeRef::merge_with on ASSOCIATED");
case TypeRef::MULTIDST:
throw ::std::runtime_error("TODO: TypeRef::merge_with on MULTIDST");
}
@@ -182,10 +178,6 @@ void TypeRef::resolve_args(::std::function<TypeRef(const char*)> fcn)
p.resolve_args(fcn);
}
break;
- case TypeRef::ASSOCIATED:
- for(auto& t : m_inner_types )
- t.resolve_args(fcn);
- break;
case TypeRef::MULTIDST:
for(auto& t : m_inner_types )
t.resolve_args(fcn);
@@ -277,8 +269,6 @@ void TypeRef::match_args(const TypeRef& other, ::std::function<void(const char*,
}
}
break;
- case TypeRef::ASSOCIATED:
- throw ::std::runtime_error("TODO: TypeRef::match_args on ASSOCIATED");
case TypeRef::MULTIDST:
throw ::std::runtime_error("TODO: TypeRef::match_args on MULTIDST");
}
@@ -316,17 +306,6 @@ bool TypeRef::is_concrete() const
return false;
}
return true;
- case TypeRef::ASSOCIATED:
- for(const auto& t : m_inner_types )
- if( not t.is_concrete() )
- return false;
- for(const auto& n : m_path.nodes())
- {
- for(const auto& p : n.args())
- if( not p.is_concrete() )
- return false;
- }
- return true;
case TypeRef::MULTIDST:
for(const auto& t : m_inner_types )
if( not t.is_concrete() )
@@ -370,8 +349,6 @@ bool TypeRef::operator==(const TypeRef& x) const
throw ::std::runtime_error("BUGCHECK - Can't compare generic type");
case TypeRef::PATH:
return m_path == x.m_path;
- case TypeRef::ASSOCIATED:
- return m_path == x.m_path && m_inner_types == x.m_inner_types;
case TypeRef::MULTIDST:
return m_inner_types == x.m_inner_types;
}
@@ -439,9 +416,6 @@ bool TypeRef::operator==(const TypeRef& x) const
case TypeRef::PATH:
os << tr.m_path;
break;
- case TypeRef::ASSOCIATED:
- os << "<" << tr.m_inner_types[0] << " as " << tr.m_inner_types[1] << ">::" << tr.m_path[0].name();
- break;
case TypeRef::MULTIDST:
os << "(";
for( const auto& it : tr.m_inner_types ) {
@@ -496,7 +470,6 @@ const char* TypeRef::class_name(TypeRef::Class c) {
_(ARRAY)
_(GENERIC)
_(PATH)
- _(ASSOCIATED)
_(MULTIDST)
#undef _
}
@@ -517,7 +490,6 @@ void operator>>(::Deserialiser& d, TypeRef::Class& c) {
else _(ARRAY)
else _(GENERIC)
else _(PATH)
- else _(ASSOCIATED)
else _(MULTIDST)
else
throw ::std::runtime_error("Deserialise failure - " + n);
@@ -597,9 +569,6 @@ void PrettyPrintType::print(::std::ostream& os) const
case TypeRef::PATH:
os << m_type.m_path;
break;
- case TypeRef::ASSOCIATED:
- os << "<" << m_type.m_inner_types[0].print_pretty() << " as " << m_type.m_inner_types[1].print_pretty() << ">::" << m_type.m_path[0].name();
- break;
}
#endif
}
diff --git a/src/types.hpp b/src/types.hpp
index ab4c5250..5f7c6111 100644
--- a/src/types.hpp
+++ b/src/types.hpp
@@ -56,7 +56,6 @@ class TypeRef:
GENERIC,
PATH,
MULTIDST, // Multi-trait DST (e.g. Trait + Send + Sync)
- ASSOCIATED,
};
Class m_class;
@@ -160,16 +159,6 @@ public:
m_inner_types.push_back( TypeRef(::std::move(t)) );
}
- struct TagAssoc {};
- TypeRef(TagAssoc, TypeRef base, TypeRef trait, ::std::string assoc_name):
- TypeRef(::std::move(base), ::std::move(trait), ::std::move(assoc_name))
- {}
- TypeRef(TypeRef base, TypeRef trait, ::std::string assoc_name):
- m_class(ASSOCIATED),
- m_path( {AST::PathNode(assoc_name, {})} ),
- m_inner_types( {::std::move(base), ::std::move(trait)} )
- {}
-
/// Dereference the type (return the result of *type_instance)
bool deref(bool is_implicit);
/// Merge with another type (combines known aspects, conflitcs cause an exception)
@@ -191,8 +180,8 @@ public:
bool is_reference() const { return m_class == REFERENCE; }
bool is_tuple() const { return m_class == TUPLE; }
const ::std::string& type_param() const { assert(is_type_param()); return m_path[0].name(); }
- AST::Path& path() { assert(is_path() || m_class == ASSOCIATED); return m_path; }
- const AST::Path& path() const { assert(is_path() || m_class == ASSOCIATED); return m_path; }
+ AST::Path& path() { assert(is_path()); return m_path; }
+ const AST::Path& path() const { assert(is_path()); return m_path; }
::std::vector<TypeRef>& sub_types() { return m_inner_types; }
const ::std::vector<TypeRef>& sub_types() const { return m_inner_types; }