summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/expand/mod.cpp26
-rw-r--r--src/hir/dump.cpp10
-rw-r--r--src/hir/type.hpp6
-rw-r--r--src/hir_expand/ufcs_everything.cpp6
-rw-r--r--src/hir_typeck/helpers.cpp1
-rw-r--r--src/include/synext_decorator.hpp25
-rw-r--r--src/include/synext_macro.hpp25
-rw-r--r--src/macro_rules/eval.cpp2
-rw-r--r--src/parse/tokenstream.cpp2
9 files changed, 80 insertions, 23 deletions
diff --git a/src/expand/mod.cpp b/src/expand/mod.cpp
index 788b2109..81a3c5b6 100644
--- a/src/expand/mod.cpp
+++ b/src/expand/mod.cpp
@@ -15,6 +15,8 @@
#include <ast/expr.hpp>
#include "cfg.hpp"
+DecoratorDef* g_decorators_list = nullptr;
+MacroDef* g_macros_list = nullptr;
::std::map< ::std::string, ::std::unique_ptr<ExpandDecorator> > g_decorators;
::std::map< ::std::string, ::std::unique_ptr<ExpandProcMacro> > g_macros;
@@ -24,10 +26,18 @@ void Expand_Expr(::AST::Crate& crate, LList<const AST::Module*> modstack, AST::E
void Expand_Expr(::AST::Crate& crate, LList<const AST::Module*> modstack, ::std::shared_ptr<AST::ExprNode>& node);
void Register_Synext_Decorator(::std::string name, ::std::unique_ptr<ExpandDecorator> handler) {
- g_decorators[name] = mv$(handler);
+ g_decorators.insert(::std::make_pair( mv$(name), mv$(handler) ));
}
void Register_Synext_Macro(::std::string name, ::std::unique_ptr<ExpandProcMacro> handler) {
- g_macros[name] = mv$(handler);
+ g_macros.insert(::std::make_pair( mv$(name), mv$(handler) ));
+}
+void Register_Synext_Decorator_Static(DecoratorDef* def) {
+ def->prev = g_decorators_list;
+ g_decorators_list = def;
+}
+void Register_Synext_Macro_Static(MacroDef* def) {
+ def->prev = g_macros_list;
+ g_macros_list = def;
}
@@ -1062,6 +1072,18 @@ void Expand_Mod_IndexAnon(::AST::Crate& crate, ::AST::Module& mod)
}
void Expand(::AST::Crate& crate)
{
+ // Fill macro/decorator map from init list
+ while(g_decorators_list)
+ {
+ g_decorators.insert(::std::make_pair( mv$(g_decorators_list->name), mv$(g_decorators_list->def) ));
+ g_decorators_list = g_decorators_list->prev;
+ }
+ while (g_macros_list)
+ {
+ g_macros.insert(::std::make_pair(mv$(g_macros_list->name), mv$(g_macros_list->def)));
+ g_macros_list = g_macros_list->prev;
+ }
+
auto modstack = LList<const ::AST::Module*>(nullptr, &crate.m_root_module);
// 1. Crate attributes
diff --git a/src/hir/dump.cpp b/src/hir/dump.cpp
index 8bcffa4e..649116e0 100644
--- a/src/hir/dump.cpp
+++ b/src/hir/dump.cpp
@@ -261,7 +261,14 @@ namespace {
}
void visit_constant(::HIR::ItemPath p, ::HIR::Constant& item) override
{
- m_os << indent() << "const " << p.get_name() << ": " << item.m_type << " = " << item.m_value_res << ";\n";
+ m_os << indent() << "const " << p.get_name() << ": " << item.m_type << " = " << item.m_value_res;
+ if( item.m_value )
+ {
+ m_os << " /*= ";
+ item.m_value->visit(*this);
+ m_os << "*/";
+ }
+ m_os << ";\n";
}
// - Misc
@@ -523,6 +530,7 @@ namespace {
m_os << ", ";
}
m_os << ")";
+ m_os << "/* : " << node.m_res_type << " */";
}
void visit(::HIR::ExprNode_CallValue& node) override
{
diff --git a/src/hir/type.hpp b/src/hir/type.hpp
index b5b10c4e..a832e8e9 100644
--- a/src/hir/type.hpp
+++ b/src/hir/type.hpp
@@ -123,7 +123,7 @@ public:
)
);
- TAGGED_UNION(Data, Infer,
+ TAGGED_UNION(Data, Diverge,
(Infer, struct {
unsigned int index;
InferClass ty_class;
@@ -177,7 +177,9 @@ public:
Data m_data;
- TypeRef() {}
+ TypeRef():
+ m_data(Data::make_Infer({ ~0u, InferClass::None }))
+ {}
TypeRef(TypeRef&& ) = default;
TypeRef(const TypeRef& ) = delete;
TypeRef& operator=(TypeRef&& ) = default;
diff --git a/src/hir_expand/ufcs_everything.cpp b/src/hir_expand/ufcs_everything.cpp
index 23b9c288..44921105 100644
--- a/src/hir_expand/ufcs_everything.cpp
+++ b/src/hir_expand/ufcs_everything.cpp
@@ -385,8 +385,10 @@ namespace {
auto ty_r_ref = ::HIR::TypeRef::new_borrow( ::HIR::BorrowType::Shared, ty_r.clone() );
::std::vector< ::HIR::ExprNodeP> args;
- args.push_back(NEWNODE(ty_l_ref.clone(), Borrow, node.m_left ->span(), ::HIR::BorrowType::Shared, mv$(node.m_left ) ));
- args.push_back(NEWNODE(ty_r_ref.clone(), Borrow, node.m_right->span(), ::HIR::BorrowType::Shared, mv$(node.m_right) ));
+ auto sp_left = node.m_left ->span();
+ auto sp_right = node.m_right->span();
+ args.push_back(NEWNODE(ty_l_ref.clone(), Borrow, sp_left , ::HIR::BorrowType::Shared, mv$(node.m_left ) ));
+ args.push_back(NEWNODE(ty_r_ref.clone(), Borrow, sp_right, ::HIR::BorrowType::Shared, mv$(node.m_right) ));
m_replacement = NEWNODE(mv$(node.m_res_type), CallPath, sp,
::HIR::Path(ty_l.clone(), mv$(trait), method),
diff --git a/src/hir_typeck/helpers.cpp b/src/hir_typeck/helpers.cpp
index 8f7dd2f2..a1c64bec 100644
--- a/src/hir_typeck/helpers.cpp
+++ b/src/hir_typeck/helpers.cpp
@@ -436,6 +436,7 @@ void HMTypeInferrence::add_ivars(::HIR::TypeRef& type)
e.index = this->new_ivar();
this->get_type(type).m_data.as_Infer().ty_class = e.ty_class;
this->mark_change();
+ DEBUG("New ivar " << type);
}
),
(Diverge,
diff --git a/src/include/synext_decorator.hpp b/src/include/synext_decorator.hpp
index c3985855..4988c624 100644
--- a/src/include/synext_decorator.hpp
+++ b/src/include/synext_decorator.hpp
@@ -57,14 +57,25 @@ public:
virtual void handle(const Span& sp, const AST::MetaItem& mi, AST::Crate& crate, ::AST::ExprNode_Match_Arm& expr) const { unexpected(sp, mi, "match arm"); }
};
-#define STATIC_DECORATOR(ident, _handler_class) \
- struct register_##_handler_class##_c {\
- register_##_handler_class##_c() {\
- Register_Synext_Decorator( ident, ::std::unique_ptr<ExpandDecorator>(new _handler_class()) ); \
- } \
- } s_register_##_handler_class;
-
+struct DecoratorDef;
extern void Register_Synext_Decorator(::std::string name, ::std::unique_ptr<ExpandDecorator> handler);
+extern void Register_Synext_Decorator_Static(DecoratorDef* def);
+
+struct DecoratorDef
+{
+ DecoratorDef* prev;
+ ::std::string name;
+ ::std::unique_ptr<ExpandDecorator> def;
+ DecoratorDef(::std::string name, ::std::unique_ptr<ExpandDecorator> def):
+ name(::std::move(name)),
+ def(::std::move(def)),
+ prev(nullptr)
+ {
+ Register_Synext_Decorator_Static(this);
+ }
+};
+
+#define STATIC_DECORATOR(ident, _handler_class) static DecoratorDef s_register_##_handler_class ( ident, ::std::unique_ptr<ExpandDecorator>(new _handler_class()) );
#endif
diff --git a/src/include/synext_macro.hpp b/src/include/synext_macro.hpp
index 400016d9..c109b56e 100644
--- a/src/include/synext_macro.hpp
+++ b/src/include/synext_macro.hpp
@@ -25,14 +25,25 @@ public:
virtual ::std::unique_ptr<TokenStream> expand(const Span& sp, const AST::Crate& crate, const ::std::string& ident, const TokenTree& tt, AST::Module& mod) = 0;
};
-#define STATIC_MACRO(ident, _handler_class) \
- struct register_##_handler_class##_c {\
- register_##_handler_class##_c() {\
- Register_Synext_Macro( ident, ::std::unique_ptr<ExpandProcMacro>(new _handler_class()) ); \
- } \
- } s_register_##_handler_class;
-
+struct MacroDef;
extern void Register_Synext_Macro(::std::string name, ::std::unique_ptr<ExpandProcMacro> handler);
+extern void Register_Synext_Macro_Static(MacroDef* def);
+
+struct MacroDef
+{
+ MacroDef* prev;
+ ::std::string name;
+ ::std::unique_ptr<ExpandProcMacro> def;
+ MacroDef(::std::string name, ::std::unique_ptr<ExpandProcMacro> def) :
+ name(::std::move(name)),
+ def(::std::move(def)),
+ prev(nullptr)
+ {
+ Register_Synext_Macro_Static(this);
+ }
+};
+
+#define STATIC_MACRO(ident, _handler_class) static MacroDef s_register_##_handler_class(ident, ::std::unique_ptr<ExpandProcMacro>(new _handler_class()));
#endif
diff --git a/src/macro_rules/eval.cpp b/src/macro_rules/eval.cpp
index 11ec74f2..18ef563e 100644
--- a/src/macro_rules/eval.cpp
+++ b/src/macro_rules/eval.cpp
@@ -564,7 +564,7 @@ public:
const MacroExpansionEnt* next_ent();
const ::std::vector<unsigned int> iterations() const { return m_iterations; }
- unsigned int top_pos() const { return m_offsets[0].read_pos; }
+ unsigned int top_pos() const { if(m_offsets.empty()) return 0; return m_offsets[0].read_pos; }
private:
const MacroExpansionEnt& getCurLayerEnt() const;
diff --git a/src/parse/tokenstream.cpp b/src/parse/tokenstream.cpp
index 20b53431..8cb9a910 100644
--- a/src/parse/tokenstream.cpp
+++ b/src/parse/tokenstream.cpp
@@ -24,7 +24,7 @@ TokenStream::~TokenStream()
Token TokenStream::innerGetToken()
{
Token ret = this->realGetToken();
- if( ret.get_pos().filename == "" )
+ if( ret != TOK_EOF && ret.get_pos().filename == "" )
ret.set_pos( this->getPosition() );
//DEBUG("ret.get_pos() = " << ret.get_pos());
return ret;