diff options
author | John Hodge <tpg@mutabah.net> | 2018-05-20 22:01:59 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2018-05-20 22:01:59 +0800 |
commit | de9ecd7a2d70359b34e77ded57e5aa9284345ac5 (patch) | |
tree | 29ab42c6c06960720bd67f0b8ebaec807ad0284e /src/ast/types.hpp | |
parent | 134be5198993096ab5216b6d52a8937430c733b0 (diff) | |
download | mrust-de9ecd7a2d70359b34e77ded57e5aa9284345ac5.tar.gz |
AST - Refactor lifetime/HRB handling
Diffstat (limited to 'src/ast/types.hpp')
-rw-r--r-- | src/ast/types.hpp | 77 |
1 files changed, 71 insertions, 6 deletions
diff --git a/src/ast/types.hpp b/src/ast/types.hpp index 820bcf27..49cae373 100644 --- a/src/ast/types.hpp +++ b/src/ast/types.hpp @@ -13,6 +13,63 @@ namespace AST { class ExprNode; class Expr; +class LifetimeParam; +} + +namespace AST { + + // Defined here for dependency reasons + class HigherRankedBounds + { + public: + ::std::vector<LifetimeParam> m_lifetimes; + //::std::vector<TypeParam> m_types; + //::std::vector<GenericBound> m_bounds; + + bool empty() const { + return m_lifetimes.empty(); + } + + friend ::std::ostream& operator<<(::std::ostream& os, const HigherRankedBounds& x); + }; + + class LifetimeRef + { + static const uint16_t BINDING_STATIC = 0xFFFF; + static const uint16_t BINDING_UNBOUND = 0xFFFE; + static const uint16_t BINDING_INFER = 0xFFFD; + + Ident m_name; + uint16_t m_binding; + + LifetimeRef(Ident name, uint32_t binding): + m_name( ::std::move(name) ), + m_binding( binding ) + { + } + public: + LifetimeRef(): + LifetimeRef("", BINDING_INFER) + { + } + LifetimeRef(Ident name): + LifetimeRef(::std::move(name), BINDING_UNBOUND) + { + } + static LifetimeRef new_static() { + return LifetimeRef("static", BINDING_STATIC); + } + + void set_binding(uint16_t b) { assert(m_binding == BINDING_UNBOUND); m_binding = b; } + + const Ident& name() const { return m_name; } + Ordering ord(const LifetimeRef& x) const { return ::ord(m_name.name, x.m_name.name); } + bool operator==(const LifetimeRef& x) const { return ord(x) == OrdEqual; } + bool operator!=(const LifetimeRef& x) const { return ord(x) != OrdEqual; } + bool operator<(const LifetimeRef& x) const { return ord(x) == OrdLess; }; + + friend ::std::ostream& operator<<(::std::ostream& os, const LifetimeRef& x); + }; } class PrettyPrintType @@ -57,6 +114,14 @@ struct Type_Function Ordering ord(const Type_Function& x) const; }; +struct Type_TraitPath +{ + AST::HigherRankedBounds hrbs; + AST::Path path; + + Ordering ord(const Type_TraitPath& x) const; +}; + TAGGED_UNION(TypeData, None, (None, struct { }), (Any, struct { }), @@ -94,12 +159,12 @@ TAGGED_UNION(TypeData, None, AST::Path path; }), (TraitObject, struct { - ::std::vector<::std::string> hrls; - ::std::vector<AST::Path> traits; + ::std::vector<Type_TraitPath> traits; + ::std::vector<AST::LifetimeRef> lifetimes; }), (ErasedType, struct { - ::std::vector<::std::string> hrls; - ::std::vector<AST::Path> traits; + ::std::vector<Type_TraitPath> traits; + ::std::vector<AST::LifetimeRef> lifetimes; }) ); @@ -215,9 +280,9 @@ public: TypeRef(TagPath(), mv$(sp), mv$(path)) {} - TypeRef( Span sp, ::std::vector<::std::string> hrls, ::std::vector<AST::Path> traits ): + TypeRef( Span sp, ::std::vector<Type_TraitPath> traits, ::std::vector<AST::LifetimeRef> lifetimes ): m_span(mv$(sp)), - m_data(TypeData::make_TraitObject({ mv$(hrls), ::std::move(traits) })) + m_data(TypeData::make_TraitObject({ ::std::move(traits), mv$(lifetimes) })) {} |