summaryrefslogtreecommitdiff
path: root/src/ast/ast.hpp
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2015-03-15 21:33:46 +0800
committerJohn Hodge <tpg@mutabah.net>2015-03-15 21:33:46 +0800
commit6b506092f331a26328a45c00565336ac810b7559 (patch)
tree0dfaa28925dd7c3ae28176161cb420b5f01aabda /src/ast/ast.hpp
parent2fffea5c08283746f0b6609024f6c1ea05bf8367 (diff)
downloadmrust-6b506092f331a26328a45c00565336ac810b7559.tar.gz
Rework type params, add ! "type"
Diffstat (limited to 'src/ast/ast.hpp')
-rw-r--r--src/ast/ast.hpp44
1 files changed, 32 insertions, 12 deletions
diff --git a/src/ast/ast.hpp b/src/ast/ast.hpp
index 81a0dbd6..8928aa97 100644
--- a/src/ast/ast.hpp
+++ b/src/ast/ast.hpp
@@ -41,7 +41,10 @@ public:
m_class( is_lifetime ? LIFETIME : TYPE ),
m_name( ::std::move(name) )
{}
- void setDefault(TypeRef type);
+ void setDefault(TypeRef type) {
+ assert(m_default.is_wildcard());
+ m_default = ::std::move(type);
+ }
const ::std::string& name() const { return m_name; }
const TypeRef& get_default() const { return m_default; }
@@ -55,25 +58,32 @@ public:
class GenericBound:
public Serialisable
{
- ::std::string m_argname;
+ TypeRef m_type;
+
::std::string m_lifetime;
- TypeRef m_trait;
+
+ bool m_optional;
+ AST::Path m_trait;
public:
+
GenericBound() {}
- GenericBound(::std::string argname, ::std::string lifetime):
- m_argname(argname),
+ GenericBound(TypeRef type, ::std::string lifetime):
+ m_type( ::std::move(type) ),
m_lifetime(lifetime)
{ }
- GenericBound(::std::string argname, TypeRef trait):
- m_argname(argname),
+ GenericBound(TypeRef type, AST::Path trait, bool optional=false):
+ m_type( ::std::move(type) ),
+ m_optional(optional),
m_trait( ::std::move(trait) )
{ }
bool is_trait() const { return m_lifetime == ""; }
- const ::std::string& name() const { return m_argname; }
- const TypeRef& type() const { return m_trait; }
+ const ::std::string& lifetime() const { return m_lifetime; }
+ const TypeRef& test() const { return m_type; }
+ const AST::Path& bound() const { return m_trait; }
- TypeRef& type() { return m_trait; }
+ TypeRef& test() { return m_type; }
+ AST::Path& bound() { return m_trait; }
friend ::std::ostream& operator<<(::std::ostream& os, const GenericBound& x);
SERIALISABLE_PROTOTYPES();
@@ -394,16 +404,26 @@ class Impl:
TypeRef m_trait;
TypeRef m_type;
+ bool m_is_negative;
ItemList<TypeRef> m_types;
ItemList<Function> m_functions;
::std::vector< ::std::pair< ::std::vector<TypeRef>, Impl > > m_concrete_impls;
public:
- Impl() {}
+ Impl(): m_is_negative(false) {}
Impl(TypeParams params, TypeRef impl_type, TypeRef trait_type):
m_params( move(params) ),
m_trait( move(trait_type) ),
- m_type( move(impl_type) )
+ m_type( move(impl_type) ),
+ m_is_negative(true)
+ {}
+
+ struct TagNegative {};
+ Impl(TagNegative, TypeParams params, TypeRef impl_type, TypeRef trait_type):
+ m_params( move(params) ),
+ m_trait( move(trait_type) ),
+ m_type( move(impl_type) ),
+ m_is_negative(true)
{}
void add_function(bool is_public, ::std::string name, Function fcn) {