summaryrefslogtreecommitdiff
path: root/src/ast/types.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ast/types.hpp')
-rw-r--r--src/ast/types.hpp93
1 files changed, 81 insertions, 12 deletions
diff --git a/src/ast/types.hpp b/src/ast/types.hpp
index 820bcf27..b6d9d6f5 100644
--- a/src/ast/types.hpp
+++ b/src/ast/types.hpp
@@ -7,12 +7,70 @@
#include "coretypes.hpp"
#include "ast/path.hpp"
#include "ast/macro.hpp"
-#include <serialise.hpp>
#include <tagged_union.hpp>
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; }
+ bool is_unbound() const { return m_binding == BINDING_UNBOUND; }
+ bool is_infer() const { return m_binding == BINDING_INFER; }
+
+ 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
@@ -37,6 +95,7 @@ struct TypeArgRef
struct Type_Function
{
+ AST::HigherRankedBounds hrbs;
bool is_unsafe;
::std::string m_abi;
::std::unique_ptr<TypeRef> m_rettype;
@@ -44,7 +103,8 @@ struct Type_Function
bool is_variadic;
Type_Function() {}
- Type_Function(bool is_unsafe, ::std::string abi, ::std::unique_ptr<TypeRef> ret, ::std::vector<TypeRef> args, bool is_variadic):
+ Type_Function(AST::HigherRankedBounds hrbs, bool is_unsafe, ::std::string abi, ::std::unique_ptr<TypeRef> ret, ::std::vector<TypeRef> args, bool is_variadic):
+ hrbs(mv$(hrbs)),
is_unsafe(is_unsafe),
m_abi(mv$(abi)),
m_rettype(mv$(ret)),
@@ -57,6 +117,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 { }),
@@ -75,6 +143,7 @@ TAGGED_UNION(TypeData, None,
::std::vector<TypeRef> inner_types;
}),
(Borrow, struct {
+ AST::LifetimeRef lifetime;
bool is_mut;
::std::unique_ptr<TypeRef> inner;
}),
@@ -94,12 +163,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;
})
);
@@ -171,15 +240,15 @@ public:
m_data(TypeData::make_Tuple({::std::move(inner_types)}))
{}
struct TagFunction {};
- TypeRef(TagFunction, Span sp, bool is_unsafe, ::std::string abi, ::std::vector<TypeRef> args, bool is_variadic, TypeRef ret):
+ TypeRef(TagFunction, Span sp, AST::HigherRankedBounds hrbs, bool is_unsafe, ::std::string abi, ::std::vector<TypeRef> args, bool is_variadic, TypeRef ret):
m_span(mv$(sp)),
- m_data(TypeData::make_Function({ Type_Function( is_unsafe, abi, box$(ret), mv$(args), is_variadic ) }))
+ m_data(TypeData::make_Function({ Type_Function( mv$(hrbs), is_unsafe, abi, box$(ret), mv$(args), is_variadic ) }))
{}
struct TagReference {};
- TypeRef(TagReference , Span sp, bool is_mut, TypeRef inner_type):
+ TypeRef(TagReference , Span sp, AST::LifetimeRef lft, bool is_mut, TypeRef inner_type):
m_span(mv$(sp)),
- m_data(TypeData::make_Borrow({ is_mut, ::make_unique_ptr(mv$(inner_type)) }))
+ m_data(TypeData::make_Borrow({ ::std::move(lft), is_mut, ::make_unique_ptr(mv$(inner_type)) }))
{}
struct TagPointer {};
TypeRef(TagPointer , Span sp, bool is_mut, TypeRef inner_type):
@@ -215,9 +284,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) }))
{}