summaryrefslogtreecommitdiff
path: root/src/ast
diff options
context:
space:
mode:
Diffstat (limited to 'src/ast')
-rw-r--r--src/ast/ast.cpp13
-rw-r--r--src/ast/ast.hpp14
-rw-r--r--src/ast/path.hpp2
3 files changed, 17 insertions, 12 deletions
diff --git a/src/ast/ast.cpp b/src/ast/ast.cpp
index f5d87d72..b8e6d381 100644
--- a/src/ast/ast.cpp
+++ b/src/ast/ast.cpp
@@ -78,9 +78,10 @@ Impl Impl::make_concrete(const ::std::vector<TypeRef>& types) const
*/
}
-::rust::option<Impl&> Impl::matches(const TypeRef& trait, const TypeRef& type)
+::rust::option<Impl&> Impl::matches(const Path& trait, const TypeRef& type)
{
DEBUG("this = " << *this);
+
if( m_params.ty_params().size() > 0 )
{
::std::vector<TypeRef> param_types(m_params.ty_params().size());
@@ -92,7 +93,8 @@ Impl Impl::make_concrete(const ::std::vector<TypeRef>& types) const
assert( (unsigned)idx < param_types.size() );
param_types[idx].merge_with( ty );
};
- m_trait.match_args(trait, c);
+ throw CompileError::Todo("Match arguments in path for m_trait");
+ //m_trait.match_args(TypeRef(trait), c);
m_type.match_args(type, c);
// Check that conditions match
@@ -180,12 +182,13 @@ const Module& Crate::get_root_module(const ::std::string& name) const {
throw ParseError::Generic("crate name unknown");
}
-::rust::option<Impl&> Crate::find_impl(const TypeRef& trait, const TypeRef& type)
+::rust::option<Impl&> Crate::find_impl(const Path& trait, const TypeRef& type)
{
+ // TODO: Do a sort to allow a binary search
DEBUG("trait = " << trait << ", type = " << type);
// TODO: Support autoderef here? NO
- if( trait.is_wildcard() && !type.is_path() )
+ if( trait == Path() && !type.is_path() )
{
// You can only have 'impl <type> { }' for user-defined types (i.e. paths)
// - Return failure
@@ -801,7 +804,7 @@ bool TypeParams::check_params(Crate& crate, ::std::vector<TypeRef>& types, bool
{
const auto& trait = bound.bound();
// Check if 'type' impls 'trait'
- if( !crate.find_impl(type, trait).is_some() )
+ if( !crate.find_impl(trait, trait).is_some() )
{
throw ::std::runtime_error( FMT("No matching impl of "<<trait<<" for "<<type));
}
diff --git a/src/ast/ast.hpp b/src/ast/ast.hpp
index af73dca2..182652cc 100644
--- a/src/ast/ast.hpp
+++ b/src/ast/ast.hpp
@@ -439,7 +439,7 @@ class Impl:
public Serialisable
{
TypeParams m_params;
- TypeRef m_trait;
+ Path m_trait;
TypeRef m_type;
bool m_is_negative;
@@ -449,7 +449,7 @@ class Impl:
::std::vector< ::std::pair< ::std::vector<TypeRef>, Impl > > m_concrete_impls;
public:
Impl(): m_is_negative(false) {}
- Impl(TypeParams params, TypeRef impl_type, TypeRef trait_type):
+ Impl(TypeParams params, TypeRef impl_type, Path trait_type):
m_params( move(params) ),
m_trait( move(trait_type) ),
m_type( move(impl_type) ),
@@ -457,7 +457,7 @@ public:
{}
struct TagNegative {};
- Impl(TagNegative, TypeParams params, TypeRef impl_type, TypeRef trait_type):
+ Impl(TagNegative, TypeParams params, TypeRef impl_type, Path trait_type):
m_params( move(params) ),
m_trait( move(trait_type) ),
m_type( move(impl_type) ),
@@ -472,20 +472,20 @@ public:
}
const TypeParams& params() const { return m_params; }
- const TypeRef& trait() const { return m_trait; }
+ const Path& 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; }
+ Path& trait() { return m_trait; }
TypeRef& type() { return m_type; }
ItemList<Function>& functions() { return m_functions; }
ItemList<TypeRef>& types() { return m_types; }
Impl make_concrete(const ::std::vector<TypeRef>& types) const;
- ::rust::option<Impl&> matches(const TypeRef& trait, const TypeRef& type);
+ ::rust::option<Impl&> matches(const Path& trait, const TypeRef& type);
friend ::std::ostream& operator<<(::std::ostream& os, const Impl& impl);
SERIALISABLE_PROTOTYPES();
@@ -693,7 +693,7 @@ public:
void post_parse();
- ::rust::option<Impl&> find_impl(const TypeRef& trait, const TypeRef& type);
+ ::rust::option<Impl&> find_impl(const Path& trait, const TypeRef& type);
Function& lookup_method(const TypeRef& type, const char *name);
void load_extern_crate(::std::string name);
diff --git a/src/ast/path.hpp b/src/ast/path.hpp
index 94af94da..2355c88b 100644
--- a/src/ast/path.hpp
+++ b/src/ast/path.hpp
@@ -266,6 +266,8 @@ public:
Ordering ord(const Path& x) const;
bool operator==(const Path& x) const { return ord(x) == OrdEqual; }
+ bool operator!=(const Path& x) const { return ord(x) != OrdEqual; }
+ bool operator<(const Path& x) const { return ord(x) != OrdLess; }
SERIALISABLE_PROTOTYPES();
void print_pretty(::std::ostream& os) const;