summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ast/ast.cpp2
-rw-r--r--src/ast/path.cpp2
-rw-r--r--src/ast/pattern.cpp2
-rw-r--r--src/hir/from_ast.cpp39
-rw-r--r--src/hir/hir.hpp4
-rw-r--r--src/hir/path.hpp3
-rw-r--r--src/hir/type.hpp2
-rw-r--r--src/include/tagged_union.hpp2
-rw-r--r--src/types.cpp3
9 files changed, 36 insertions, 23 deletions
diff --git a/src/ast/ast.cpp b/src/ast/ast.cpp
index 5d314756..88897f57 100644
--- a/src/ast/ast.cpp
+++ b/src/ast/ast.cpp
@@ -654,7 +654,7 @@ SERIALISE_TYPE(TypeParam::, "AST_TypeParam", {
}
-#define SERIALISE_TU_ARM(CLASS, NAME, TAG, ...) case CLASS::TAG_##TAG: { *this = CLASS::make_null_##TAG(); auto& NAME = this->as_##TAG(); (void)&NAME; __VA_ARGS__ } break;
+#define SERIALISE_TU_ARM(CLASS, NAME, TAG, ...) case CLASS::TAG_##TAG: { *this = CLASS::make_##TAG({}); auto& NAME = this->as_##TAG(); (void)&NAME; __VA_ARGS__ } break;
#define SERIALISE_TU_ARMS(CLASS, NAME, ...) TU_GMA(__VA_ARGS__)(SERIALISE_TU_ARM, (CLASS, NAME), __VA_ARGS__)
#define SERIALISE_TU(PATH, TAG, NAME, ...) \
void operator%(::Serialiser& s, PATH::Tag c) { s << PATH::tag_to_str(c); } \
diff --git a/src/ast/path.cpp b/src/ast/path.cpp
index 484ac7b7..fb1e60cf 100644
--- a/src/ast/path.cpp
+++ b/src/ast/path.cpp
@@ -551,7 +551,7 @@ void operator%(::Deserialiser& s, Path::Class::Tag& c) {
s.item(n);
c = Path::Class::tag_from_str(n);
}
-#define _D(VAR, ...) case Class::TAG_##VAR: { m_class = Class::make_null_##VAR(); auto& ent = m_class.as_##VAR(); (void)&ent; __VA_ARGS__ } break;
+#define _D(VAR, ...) case Class::TAG_##VAR: { m_class = Class::make_##VAR({}); auto& ent = m_class.as_##VAR(); (void)&ent; __VA_ARGS__ } break;
::std::unique_ptr<Path> Path::from_deserialiser(Deserialiser& s) {
Path p;
s.item(p);
diff --git a/src/ast/pattern.cpp b/src/ast/pattern.cpp
index 7033534d..d7168bc9 100644
--- a/src/ast/pattern.cpp
+++ b/src/ast/pattern.cpp
@@ -162,7 +162,7 @@ void operator%(::Deserialiser& s, Pattern::Data::Tag& c) {
s.item(n);
c = Pattern::Data::tag_from_str(n);
}
-#define _D(VAR, ...) case Pattern::Data::TAG_##VAR: { m_data = Pattern::Data::make_null_##VAR(); auto& ent = m_data.as_##VAR(); (void)&ent; __VA_ARGS__ } break;
+#define _D(VAR, ...) case Pattern::Data::TAG_##VAR: { m_data = Pattern::Data::make_##VAR({}); auto& ent = m_data.as_##VAR(); (void)&ent; __VA_ARGS__ } break;
SERIALISE_TYPE(Pattern::, "Pattern", {
s.item(m_binding);
s % m_data.tag();
diff --git a/src/hir/from_ast.cpp b/src/hir/from_ast.cpp
index 7b481594..b0d56b39 100644
--- a/src/hir/from_ast.cpp
+++ b/src/hir/from_ast.cpp
@@ -1,10 +1,11 @@
+#include "common.hpp"
#include "hir.hpp"
#include <main_bindings.hpp>
#include <ast/ast.hpp>
#include <ast/crate.hpp>
-::HIR::Module LowerHIR_Module(::AST::Module module, ::HIR::SimplePath path);
+::HIR::Module LowerHIR_Module(const ::AST::Module& module, ::HIR::SimplePath path);
/// \brief Converts the AST into HIR format
///
@@ -13,10 +14,14 @@
::HIR::CratePtr LowerHIR_FromAST(::AST::Crate crate)
{
::std::unordered_map< ::std::string, MacroRules > macros;
- auto rootmod = LowerHIR_Module( mv$(crate.m_root_module), ::HIR::SimplePath("") );
+ auto rootmod = LowerHIR_Module( crate.m_root_module, ::HIR::SimplePath("") );
return ::HIR::CratePtr( ::HIR::Crate { mv$(rootmod), mv$(macros) } );
}
+::HIR::GenericParams LowerHIR_GenericParams(const ::AST::GenericParams& gp)
+{
+ throw ::std::runtime_error("TODO: LowerHIR_GenericParams");
+}
::HIR::Expr LowerHIR_Expr(const ::AST::Expr& e)
{
@@ -39,7 +44,7 @@
throw ::std::runtime_error("TODO: LowerHIR_Struct");
return ::HIR::Struct {
- LowerHIR_GenericParams(e.params()),
+ LowerHIR_GenericParams(ta.params()),
mv$(data)
};
}
@@ -58,13 +63,13 @@
}
void _add_mod_ns_item(::HIR::Module& mod, ::std::string name, bool is_pub, ::HIR::TypeItem ti) {
- mod.m_mod_items.insert( ::std::make_pair( mv$(name), ::HIR::VisEnt< ::HIR::TypeItem> { is_pub, mv$(ti) } ) );
+ mod.m_mod_items.insert( ::std::make_pair( mv$(name), ::make_unique_ptr(::HIR::VisEnt< ::HIR::TypeItem> { is_pub, mv$(ti) }) ) );
}
void _add_mod_val_item(::HIR::Module& mod, ::std::string name, bool is_pub, ::HIR::ValueItem ti) {
- mod.m_value_items.insert( ::std::make_pair( mv$(name), ::HIR::VisEnt< ::HIR::ValueItem> { is_pub, mv$(ti) } ) );
+ mod.m_value_items.insert( ::std::make_pair( mv$(name), ::make_unique_ptr(::HIR::VisEnt< ::HIR::ValueItem> { is_pub, mv$(ti) }) ) );
}
-::HIR::Module LowerHIR_Module(::AST::Module module, ::HIR::SimplePath path)
+::HIR::Module LowerHIR_Module(::AST::Module& module, ::HIR::SimplePath path)
{
::HIR::Module mod { };
@@ -75,45 +80,45 @@ void _add_mod_val_item(::HIR::Module& mod, ::std::string name, bool is_pub, ::H
(None,
),
(Module,
- _add_mod_ns_item( mod, item.name, item.is_pub, LowerHIR_Module( mv$(e), mv$(item_path)) );
+ _add_mod_ns_item( mod, item.name, item.is_pub, LowerHIR_Module(e, mv$(item_path)) );
),
(Crate,
// TODO: All 'extern crate' items should be normalised into a list in the crate root
),
(Type,
- _add_mod_ns_item( mod, item.name, item.is_pub, ::HIR::TypeItem::make_TypeAlias( LowerHIR_TypeAlias(mv$(e)) ) );
+ _add_mod_ns_item( mod, item.name, item.is_pub, ::HIR::TypeItem::make_TypeAlias( LowerHIR_TypeAlias(e) ) );
),
(Struct,
TU_IFLET( ::AST::StructData, e.m_data, Struct, e2,
- ::HIR::TypeRef ty = ::HIR::TypeRef(mv$(item_path));
+ ::HIR::TypeRef ty = ::HIR::TypeRef( ::HIR::Path(mv$(item_path)) );
if( e2.ents.size() == 0 )
_add_mod_val_item( mod, item.name, item.is_pub, ::HIR::ValueItem::make_StructConstant({mv$(ty)}) );
else
_add_mod_val_item( mod, item.name, item.is_pub, ::HIR::ValueItem::make_StructConstructor({mv$(ty)}) );
)
- _add_mod_ns_item( mod, item.name, item.is_pub, LowerHIR_Struct(mv$(e)) );
+ _add_mod_ns_item( mod, item.name, item.is_pub, LowerHIR_Struct(e) );
),
(Enum,
- _add_mod_ns_item( mod, item.name, item.is_pub, LowerHIR_Enum(mv$(e)) );
+ _add_mod_ns_item( mod, item.name, item.is_pub, LowerHIR_Enum(e) );
),
(Trait,
- _add_mod_ns_item( mod, item.name, item.is_pub, LowerHIR_Trait(mv$(e)) );
+ _add_mod_ns_item( mod, item.name, item.is_pub, LowerHIR_Trait(e) );
),
(Function,
- _add_mod_val_item(mod, item.name, item.is_pub, LowerHIR_Function(mv$(e)));
+ _add_mod_val_item(mod, item.name, item.is_pub, LowerHIR_Function(e));
),
(Static,
if( e.s_class() == ::AST::Static::CONST )
_add_mod_val_item(mod, item.name, item.is_pub, ::HIR::ValueItem::make_Constant(::HIR::Constant {
::HIR::GenericParams {},
- LowerHIR_Type( mv$(e.type()) ),
- LowerHIR_Expr( mv$(e.value()) )
+ LowerHIR_Type( e.type() ),
+ LowerHIR_Expr( e.value() )
}));
else {
_add_mod_val_item(mod, item.name, item.is_pub, ::HIR::ValueItem::make_Static(::HIR::Static {
(e.s_class() == ::AST::Static::MUT),
- LowerHIR_Type( mv$(e.type()) ),
- LowerHIR_Expr( mv$(e.value()) )
+ LowerHIR_Type( e.type() ),
+ LowerHIR_Expr( e.value() )
}));
}
)
diff --git a/src/hir/hir.hpp b/src/hir/hir.hpp
index 03fe0bde..60702d82 100644
--- a/src/hir/hir.hpp
+++ b/src/hir/hir.hpp
@@ -108,7 +108,9 @@ struct AssociatedType
GenericParams m_params; // For bounds, and maybe HKT?
::HIR::TypeRef m_default;
};
-TAGGED_UNION(TraitValueItem, Static,
+TAGGED_UNION(TraitValueItem, None,
+ (None, struct {}),
+ (Constant, Constant),
(Static, Static),
(Function, Function)
);
diff --git a/src/hir/path.hpp b/src/hir/path.hpp
index cf17be17..62c70ce2 100644
--- a/src/hir/path.hpp
+++ b/src/hir/path.hpp
@@ -40,6 +40,9 @@ class Path
// Two possibilities
// - UFCS
// - Generic path
+public:
+ Path(GenericPath _);
+ Path(SimplePath _);
};
} // namespace HIR
diff --git a/src/hir/type.hpp b/src/hir/type.hpp
index 0b0ff488..e0023188 100644
--- a/src/hir/type.hpp
+++ b/src/hir/type.hpp
@@ -18,6 +18,8 @@ class TypeRef
// - Tuple
// - Borrow
// - Pointer
+public:
+ TypeRef(::HIR::Path _);
};
} // namespace HIR
diff --git a/src/include/tagged_union.hpp b/src/include/tagged_union.hpp
index 2a240d68..de524558 100644
--- a/src/include/tagged_union.hpp
+++ b/src/include/tagged_union.hpp
@@ -120,7 +120,7 @@
// Internals of TU_CONS
#define TU_CONS_I(__name, __tag, __type) \
__name(__type v): m_tag(TAG_##__tag) { new (m_data) __type( ::std::move(v) ); } \
- static self_t make_null_##__tag() { self_t ret; ret.m_tag = TAG_##__tag; new (ret.m_data) __type; return ::std::move(ret); } \
+ /*static self_t make_null_##__tag() { self_t ret; ret.m_tag = TAG_##__tag; new (ret.m_data) __type; return ::std::move(ret); }*/ \
static self_t make_##__tag(__type v) \
{\
return __name( ::std::move(v) );\
diff --git a/src/types.cpp b/src/types.cpp
index 845af9d2..f3777666 100644
--- a/src/types.cpp
+++ b/src/types.cpp
@@ -798,7 +798,7 @@ void operator%(::Deserialiser& s, TypeData::Tag& c) {
}
#define _S(VAR, ...) case TypeData::TAG_##VAR: { const auto& ent = m_data.as_##VAR(); (void)&ent; __VA_ARGS__ } break;
-#define _D(VAR, ...) case TypeData::TAG_##VAR: { m_data = TypeData::make_null_##VAR(); auto& ent = m_data.as_##VAR(); (void)&ent; __VA_ARGS__ } break;
+#define _D(VAR, ...) case TypeData::TAG_##VAR: { m_data = TypeData::make_##VAR({}); auto& ent = m_data.as_##VAR(); (void)&ent; __VA_ARGS__ } break;
SERIALISE_TYPE(TypeRef::, "TypeRef", {
s % m_data.tag();
switch(m_data.tag())
@@ -854,6 +854,7 @@ SERIALISE_TYPE(TypeRef::, "TypeRef", {
_D(Any)
_D(Unit)
_D(Macro,
+ m_data = TypeData::make_Macro({});
s.item( ent.inv );
)
_D(Primitive,