summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2016-05-24 21:55:06 +0800
committerJohn Hodge <tpg@mutabah.net>2016-05-24 21:55:06 +0800
commit23cba420f497b5da5b0a63f078cea2ef2291078a (patch)
tree96d60ee57ac0014f3a359b94a0ae3db94bae7acd
parent74868acb8e3db00cbab565abd6fbd76cbf763674 (diff)
downloadmrust-23cba420f497b5da5b0a63f078cea2ef2291078a.tar.gz
AST - Spans, spans everywhere!
-rw-r--r--src/ast/ast.cpp2
-rw-r--r--src/ast/ast.hpp9
-rw-r--r--src/ast/attrs.hpp6
-rw-r--r--src/ast/generics.hpp4
-rw-r--r--src/ast/pattern.hpp3
-rw-r--r--src/expand/cfg.cpp18
-rw-r--r--src/expand/concat.cpp2
-rw-r--r--src/expand/derive.cpp14
-rw-r--r--src/expand/file_line.cpp4
-rw-r--r--src/expand/format_args.cpp8
-rw-r--r--src/expand/lang_item.cpp8
-rw-r--r--src/expand/macro_rules.cpp8
-rw-r--r--src/expand/mod.cpp54
-rw-r--r--src/expand/std_prelude.cpp8
-rw-r--r--src/expand/stringify.cpp2
-rw-r--r--src/hir/from_ast.cpp54
-rw-r--r--src/include/synext.hpp22
-rw-r--r--src/parse/root.cpp33
-rw-r--r--src/resolve/absolute.cpp64
-rw-r--r--src/resolve/index.cpp88
20 files changed, 221 insertions, 190 deletions
diff --git a/src/ast/ast.cpp b/src/ast/ast.cpp
index 90fd8286..804b7cac 100644
--- a/src/ast/ast.cpp
+++ b/src/ast/ast.cpp
@@ -24,7 +24,7 @@ namespace {
MetaItems MetaItems::clone() const
{
- return MetaItems( clone_mivec(m_items) );
+ return MetaItems( m_span, clone_mivec(m_items) );
}
void MetaItems::push_back(MetaItem i)
diff --git a/src/ast/ast.hpp b/src/ast/ast.hpp
index 2c379f9a..9c4dc7c1 100644
--- a/src/ast/ast.hpp
+++ b/src/ast/ast.hpp
@@ -200,13 +200,13 @@ class Trait:
public Serialisable
{
GenericParams m_params;
- ::std::vector<AST::Path> m_supertraits;
+ ::std::vector< Spanned<AST::Path> > m_supertraits;
bool m_is_marker;
NamedList<Item> m_items;
public:
Trait() {}
- Trait(GenericParams params, ::std::vector<Path> supertraits):
+ Trait(GenericParams params, ::std::vector< Spanned<Path> > supertraits):
m_params( mv$(params) ),
m_supertraits( mv$(supertraits) )
{
@@ -214,8 +214,8 @@ public:
const GenericParams& params() const { return m_params; }
GenericParams& params() { return m_params; }
- const ::std::vector<Path>& supertraits() const { return m_supertraits; }
- ::std::vector<Path>& supertraits() { return m_supertraits; }
+ const ::std::vector<Spanned<Path> >& supertraits() const { return m_supertraits; }
+ ::std::vector<Spanned<Path> >& supertraits() { return m_supertraits; }
const NamedList<Item>& items() const { return m_items; }
NamedList<Item>& items() { return m_items; }
@@ -386,6 +386,7 @@ public:
ImplDef& operator=(ImplDef&&) = default;
// Accessors
+ const Span& span() const { return m_span; }
const MetaItems& attrs() const { return m_attrs; }
const GenericParams& params() const { return m_params; }
diff --git a/src/ast/attrs.hpp b/src/ast/attrs.hpp
index 82cf2154..a2b82c40 100644
--- a/src/ast/attrs.hpp
+++ b/src/ast/attrs.hpp
@@ -11,13 +11,15 @@ class MetaItems:
public Serialisable
{
public:
+ Span m_span;
::std::vector<MetaItem> m_items;
MetaItems() {}
- MetaItems(MetaItems&&) noexcept = default;
+ MetaItems(MetaItems&&) = default;
MetaItems& operator=(MetaItems&&) = default;
MetaItems(const MetaItems&) = delete;
- MetaItems(::std::vector<MetaItem> items):
+ MetaItems(Span sp, ::std::vector<MetaItem> items):
+ m_span( mv$(sp) ),
m_items( mv$(items) )
{
}
diff --git a/src/ast/generics.hpp b/src/ast/generics.hpp
index 288de0a3..4e436e25 100644
--- a/src/ast/generics.hpp
+++ b/src/ast/generics.hpp
@@ -65,11 +65,13 @@ TAGGED_UNION_EX( GenericBound, (: public Serialisable), Lifetime,
})
),
- (), (),
+ (, span(x.span) ), ( span = x.span; ),
(
public:
SERIALISABLE_PROTOTYPES();
+ Span span;
+
GenericBound clone() const {
TU_MATCH(GenericBound, ( (*this) ), (ent),
(Lifetime, return make_Lifetime({ent.test, ent.bound}); ),
diff --git a/src/ast/pattern.hpp b/src/ast/pattern.hpp
index 199d6692..468bf306 100644
--- a/src/ast/pattern.hpp
+++ b/src/ast/pattern.hpp
@@ -45,6 +45,7 @@ public:
(Slice, struct { ::std::vector<Pattern> leading; ::std::string extra_bind; ::std::vector<Pattern> trailing; } )
);
private:
+ Span m_span;
::std::string m_binding;
BindType m_binding_type;
bool m_binding_mut;
@@ -125,6 +126,8 @@ public:
}
+ const Span& span() const { return m_span; }
+ void set_span(Span sp) { m_span = mv$(sp); }
// Accessors
const ::std::string& binding() const { return m_binding; }
const BindType& binding_type() const { assert(m_binding != ""); return m_binding_type; }
diff --git a/src/expand/cfg.cpp b/src/expand/cfg.cpp
index 345c46ab..70ac6ac1 100644
--- a/src/expand/cfg.cpp
+++ b/src/expand/cfg.cpp
@@ -82,7 +82,7 @@ class CCfgExpander:
{
bool expand_early() const override { return true; }
- ::std::unique_ptr<TokenStream> expand(Span sp, const ::AST::Crate& crate, const ::std::string& ident, const TokenTree& tt, AST::Module& mod) override
+ ::std::unique_ptr<TokenStream> expand(const Span& sp, const ::AST::Crate& crate, const ::std::string& ident, const TokenTree& tt, AST::Module& mod) override
{
if( ident != "" ) {
ERROR(sp, E0000, "cfg! doesn't take an identifier");
@@ -108,36 +108,36 @@ class CCfgHandler:
AttrStage stage() const override { return AttrStage::EarlyPre; }
- void handle(const AST::MetaItem& mi, ::AST::Crate& crate, AST::MacroInvocation& mac) const override {
+ void handle(const Span& sp, const AST::MetaItem& mi, ::AST::Crate& crate, AST::MacroInvocation& mac) const override {
DEBUG("#[cfg] mac! - " << mi);
- if( check_cfg(mac.span(), mi) ) {
+ if( check_cfg(sp, mi) ) {
// Leave as is
}
else {
mac.clear();
}
}
- void handle(const AST::MetaItem& mi, ::AST::Crate& crate, const AST::Path& path, AST::Module& mod, AST::Item&i) const override {
+ void handle(const Span& sp, const AST::MetaItem& mi, ::AST::Crate& crate, const AST::Path& path, AST::Module& mod, AST::Item&i) const override {
DEBUG("#[cfg] item - " << mi);
- if( check_cfg(Span(), mi) ) {
+ if( check_cfg(sp, mi) ) {
// Leave
}
else {
i = AST::Item::make_None({});
}
}
- void handle(const AST::MetaItem& mi, ::AST::Crate& crate, ::std::unique_ptr<AST::ExprNode>& expr) const override {
+ void handle(const Span& sp, const AST::MetaItem& mi, ::AST::Crate& crate, ::std::unique_ptr<AST::ExprNode>& expr) const override {
DEBUG("#[cfg] expr - " << mi);
- if( check_cfg(Span(expr->get_pos()), mi) ) {
+ if( check_cfg(sp, mi) ) {
// Leave
}
else {
expr.reset();
}
}
- void handle(const AST::MetaItem& mi, AST::Crate& crate, const AST::Module& mod, AST::ImplDef& impl) const override {
+ void handle(const Span& sp, const AST::MetaItem& mi, AST::Crate& crate, const AST::Module& mod, AST::ImplDef& impl) const override {
DEBUG("#[cfg] impl - " << mi);
- if( check_cfg(Span(), mi) ) {
+ if( check_cfg(sp, mi) ) {
// Leave
}
else {
diff --git a/src/expand/concat.cpp b/src/expand/concat.cpp
index c7da73a1..1838df30 100644
--- a/src/expand/concat.cpp
+++ b/src/expand/concat.cpp
@@ -11,7 +11,7 @@ class CConcatExpander:
{
bool expand_early() const override { return true; }
- ::std::unique_ptr<TokenStream> expand(Span sp, const AST::Crate& crate, const ::std::string& ident, const TokenTree& tt, AST::Module& mod) override
+ ::std::unique_ptr<TokenStream> expand(const Span& sp, const AST::Crate& crate, const ::std::string& ident, const TokenTree& tt, AST::Module& mod) override
{
Token tok;
diff --git a/src/expand/derive.cpp b/src/expand/derive.cpp
index 0270eaa6..06369787 100644
--- a/src/expand/derive.cpp
+++ b/src/expand/derive.cpp
@@ -50,9 +50,9 @@ public:
// TODO: be correct herhe and use "core" as the crate name
// - Requires handling the crate_name crate attribute correctly
const AST::Path debug_trait("", { AST::PathNode("fmt", {}), AST::PathNode("Debug", {}) });
- const TypeRef ret_type(Span(), AST::Path("", {AST::PathNode("fmt",{}), AST::PathNode("Result",{})}) );
- const TypeRef f_type(TypeRef::TagReference(), Span(), true,
- TypeRef(Span(), AST::Path("", {AST::PathNode("fmt",{}), AST::PathNode("Formatter", {})}))
+ const TypeRef ret_type(sp, AST::Path("", {AST::PathNode("fmt",{}), AST::PathNode("Result",{})}) );
+ const TypeRef f_type(TypeRef::TagReference(), sp, true,
+ TypeRef(sp, AST::Path("", {AST::PathNode("fmt",{}), AST::PathNode("Formatter", {})}))
);
const ::std::string& name = type.path().nodes().back().name();
@@ -112,7 +112,7 @@ public:
AST::GenericParams(),
ret_type,
vec$(
- ::std::make_pair( AST::Pattern(AST::Pattern::TagBind(), "self"), TypeRef(TypeRef::TagReference(), Span(), false, TypeRef("Self")) ),
+ ::std::make_pair( AST::Pattern(AST::Pattern::TagBind(), "self"), TypeRef(TypeRef::TagReference(), sp, false, TypeRef("Self")) ),
::std::make_pair( AST::Pattern(AST::Pattern::TagBind(), "f"), f_type )
)
);
@@ -148,7 +148,7 @@ static void derive_item(const Span& sp, AST::Module& mod, const AST::MetaItem& a
bool fail = false;
const auto& params = item.params();
- TypeRef type(Span(), path);
+ TypeRef type(sp, path);
for( const auto& param : params.ty_params() )
type.path().nodes().back().args().push_back( TypeRef(TypeRef::TagArg(), param.name()) );
@@ -175,13 +175,13 @@ class Decorator_Derive:
{
public:
AttrStage stage() const override { return AttrStage::LatePost; }
- void handle(const AST::MetaItem& attr, ::AST::Crate& crate, const AST::Path& path, AST::Module& mod, AST::Item& i) const override
+ void handle(const Span& sp, const AST::MetaItem& attr, ::AST::Crate& crate, const AST::Path& path, AST::Module& mod, AST::Item& i) const override
{
TU_MATCH_DEF(::AST::Item, (i), (e),
(
),
(Struct,
- derive_item(i.span, mod, attr, path, e);
+ derive_item(sp, mod, attr, path, e);
)
)
}
diff --git a/src/expand/file_line.cpp b/src/expand/file_line.cpp
index 2532613f..75ce5679 100644
--- a/src/expand/file_line.cpp
+++ b/src/expand/file_line.cpp
@@ -8,7 +8,7 @@ class CExpanderFile:
{
bool expand_early() const override { return true; }
- ::std::unique_ptr<TokenStream> expand(Span sp, const AST::Crate& crate, const ::std::string& ident, const TokenTree& tt, AST::Module& mod) override
+ ::std::unique_ptr<TokenStream> expand(const Span& sp, const AST::Crate& crate, const ::std::string& ident, const TokenTree& tt, AST::Module& mod) override
{
return box$( TTStreamO(TokenTree(Token(TOK_STRING, sp.filename.c_str()))) );
}
@@ -19,7 +19,7 @@ class CExpanderLine:
{
bool expand_early() const override { return true; }
- ::std::unique_ptr<TokenStream> expand(Span sp, const AST::Crate& crate, const ::std::string& ident, const TokenTree& tt, AST::Module& mod) override
+ ::std::unique_ptr<TokenStream> expand(const Span& sp, const AST::Crate& crate, const ::std::string& ident, const TokenTree& tt, AST::Module& mod) override
{
return box$( TTStreamO(TokenTree(Token((uint64_t)sp.start_line, CORETYPE_I32))) );
}
diff --git a/src/expand/format_args.cpp b/src/expand/format_args.cpp
index 6a3665ec..ab320e3f 100644
--- a/src/expand/format_args.cpp
+++ b/src/expand/format_args.cpp
@@ -11,7 +11,7 @@ class CFormatArgsExpander:
{
bool expand_early() const override { return true; }
- ::std::unique_ptr<TokenStream> expand(Span sp, const ::AST::Crate& crate, const ::std::string& ident, const TokenTree& tt, AST::Module& mod) override
+ ::std::unique_ptr<TokenStream> expand(const Span& sp, const ::AST::Crate& crate, const ::std::string& ident, const TokenTree& tt, AST::Module& mod) override
{
Token tok;
@@ -45,9 +45,9 @@ class CFormatArgsExpander:
}
// TODO: Expand format_args!
- ::std::vector<TokenTree> toks;
- toks.push_back( TokenTree(TOK_PAREN_OPEN) );
- toks.push_back( TokenTree(TOK_PAREN_CLOSE) );
+ ::std::vector<TokenTree> toks;
+ toks.push_back( TokenTree(TOK_PAREN_OPEN) );
+ toks.push_back( TokenTree(TOK_PAREN_CLOSE) );
return box$( TTStreamO(TokenTree(mv$(toks))) );
}
};
diff --git a/src/expand/lang_item.cpp b/src/expand/lang_item.cpp
index f794bb32..d381d17c 100644
--- a/src/expand/lang_item.cpp
+++ b/src/expand/lang_item.cpp
@@ -101,11 +101,11 @@ class Decorator_LangItem:
{
public:
AttrStage stage() const override { return AttrStage::EarlyPost; }
- void handle(const AST::MetaItem& attr, AST::Crate& crate, const AST::Path& path, AST::Module& mod, AST::Item& i) const override
+ void handle(const Span& sp, const AST::MetaItem& attr, AST::Crate& crate, const AST::Path& path, AST::Module& mod, AST::Item& i) const override
{
TU_MATCH_DEF(::AST::Item, (i), (e),
(
- TODO(Span(), "Unknown item type with #[lang=\""<<attr<<"\"] attached at " << path);
+ TODO(sp, "Unknown item type with #[lang=\""<<attr<<"\"] attached at " << path);
),
(Function,
handle_lang_item(crate, path, attr.string(), AST::ITEM_FN);
@@ -119,7 +119,7 @@ public:
)
}
- void handle(const AST::MetaItem& mi, AST::Crate& crate, const AST::Module& mod, AST::ImplDef& impl) const override {
+ void handle(const Span& sp, const AST::MetaItem& mi, AST::Crate& crate, const AST::Module& mod, AST::ImplDef& impl) const override {
const ::std::string& name = mi.string();
if( name == "i8" ) {}
@@ -135,7 +135,7 @@ public:
else if( name == "const_ptr" ) {}
else if( name == "mut_ptr" ) {}
else {
- throw CompileError::Generic(FMT("Unknown lang item '" << name << "' on impl"));
+ ERROR(sp, E0000, "Unknown lang item '" << name << "' on impl");
}
}
};
diff --git a/src/expand/macro_rules.cpp b/src/expand/macro_rules.cpp
index 1689746c..4f5d33cf 100644
--- a/src/expand/macro_rules.cpp
+++ b/src/expand/macro_rules.cpp
@@ -11,7 +11,7 @@ class CMacroRulesExpander:
{
bool expand_early() const override { return true; }
- ::std::unique_ptr<TokenStream> expand(Span sp, const ::AST::Crate& crate, const ::std::string& ident, const TokenTree& tt, AST::Module& mod) override
+ ::std::unique_ptr<TokenStream> expand(const Span& sp, const ::AST::Crate& crate, const ::std::string& ident, const TokenTree& tt, AST::Module& mod) override
{
if( ident == "" )
ERROR(sp, E0000, "macro_rules! requires an identifier" );
@@ -30,11 +30,11 @@ class CMacroUseHandler:
{
AttrStage stage() const override { return AttrStage::EarlyPost; }
- void handle(const AST::MetaItem& mi, ::AST::Crate& crate, const AST::Path& path, AST::Module& mod, AST::Item& i) const override
+ void handle(const Span& sp, const AST::MetaItem& mi, ::AST::Crate& crate, const AST::Path& path, AST::Module& mod, AST::Item& i) const override
{
TRACE_FUNCTION_F("path=" << path);
if( !i.is_Module() )
- throw ::std::runtime_error("ERROR: Use of #[macro_use] on non-module");
+ ERROR(sp, E0000, "Use of #[macro_use] on non-module");
const auto& submod = i.as_Module();
@@ -59,7 +59,7 @@ class CMacroUseHandler:
goto _good;
}
}
- ERROR(Span(), E0000, "Couldn't find macro " << name);
+ ERROR(sp, E0000, "Couldn't find macro " << name);
_good:
(void)0;
}
diff --git a/src/expand/mod.cpp b/src/expand/mod.cpp
index 0cb2c9c7..c46c7d84 100644
--- a/src/expand/mod.cpp
+++ b/src/expand/mod.cpp
@@ -26,9 +26,9 @@ void Register_Synext_Macro(::std::string name, ::std::unique_ptr<ExpandProcMacro
}
-void ExpandDecorator::unexpected(const AST::MetaItem& mi, const char* loc_str) const
+void ExpandDecorator::unexpected(const Span& sp, const AST::MetaItem& mi, const char* loc_str) const
{
- ERROR(Span(), E0000, "Unexpected attribute " << mi.name() << " on " << loc_str);
+ ERROR(sp, E0000, "Unexpected attribute " << mi.name() << " on " << loc_str);
}
namespace {
@@ -40,38 +40,38 @@ namespace {
}
}
-void Expand_Attr(const ::AST::MetaItem& a, AttrStage stage, ::std::function<void(const ExpandDecorator& d,const ::AST::MetaItem& a)> f)
+void Expand_Attr(const Span& sp, const ::AST::MetaItem& a, AttrStage stage, ::std::function<void(const Span& sp, const ExpandDecorator& d,const ::AST::MetaItem& a)> f)
{
for( auto& d : g_decorators ) {
if( d.first == a.name() ) {
DEBUG("#[" << d.first << "] " << (int)d.second->stage() << "-" << (int)stage);
if( d.second->stage() == stage ) {
- f(*d.second, a);
+ f(sp, *d.second, a);
}
}
}
}
-void Expand_Attrs(const ::AST::MetaItems& attrs, AttrStage stage, ::std::function<void(const ExpandDecorator& d,const ::AST::MetaItem& a)> f)
+void Expand_Attrs(const ::AST::MetaItems& attrs, AttrStage stage, ::std::function<void(const Span& sp, const ExpandDecorator& d,const ::AST::MetaItem& a)> f)
{
for( auto& a : attrs.m_items )
{
if( a.name() == "cfg_attr" ) {
- if( check_cfg(Span(), a.items().at(0)) ) {
- Expand_Attr(a.items().at(1), stage, f);
+ if( check_cfg(attrs.m_span, a.items().at(0)) ) {
+ Expand_Attr(attrs.m_span, a.items().at(1), stage, f);
}
}
else {
- Expand_Attr(a, stage, f);
+ Expand_Attr(attrs.m_span, a, stage, f);
}
}
}
void Expand_Attrs(const ::AST::MetaItems& attrs, AttrStage stage, ::AST::Crate& crate, const ::AST::Path& path, ::AST::Module& mod, ::AST::Item& item)
{
- Expand_Attrs(attrs, stage, [&](const auto& d, const auto& a){ d.handle(a, crate, path, mod, item); });
+ Expand_Attrs(attrs, stage, [&](const auto& sp, const auto& d, const auto& a){ d.handle(sp, a, crate, path, mod, item); });
}
void Expand_Attrs(const ::AST::MetaItems& attrs, AttrStage stage, ::AST::Crate& crate, ::AST::Module& mod, ::AST::ImplDef& impl)
{
- Expand_Attrs(attrs, stage, [&](const auto& d, const auto& a){ d.handle(a, crate, mod, impl); });
+ Expand_Attrs(attrs, stage, [&](const auto& sp, const auto& d, const auto& a){ d.handle(sp, a, crate, mod, impl); });
}
::std::unique_ptr<TokenStream> Expand_Macro(
@@ -245,7 +245,7 @@ struct CExpandExpr:
void visit(::std::unique_ptr<AST::ExprNode>& cnode) {
if(cnode.get())
- Expand_Attrs(cnode->attrs(), stage_pre(is_early), [&](const auto& d, const auto& a){ d.handle(a, this->crate, cnode); });
+ Expand_Attrs(cnode->attrs(), stage_pre(is_early), [&](const auto& sp, const auto& d, const auto& a){ d.handle(sp, a, this->crate, cnode); });
if(cnode.get())
{
cnode->visit(*this);
@@ -261,7 +261,7 @@ struct CExpandExpr:
}
if(cnode.get())
- Expand_Attrs(cnode->attrs(), stage_post(is_early), [&](const auto& d, const auto& a){ d.handle(a, this->crate, cnode); });
+ Expand_Attrs(cnode->attrs(), stage_post(is_early), [&](const auto& sp, const auto& d, const auto& a){ d.handle(sp, a, this->crate, cnode); });
assert( ! this->replacement );
}
void visit_nodelete(const ::AST::ExprNode& parent, ::std::unique_ptr<AST::ExprNode>& cnode) {
@@ -409,7 +409,7 @@ struct CExpandExpr:
this->visit_nodelete(node, node.m_val);
for(auto& arm : node.m_arms)
{
- Expand_Attrs(arm.m_attrs, stage_pre (is_early), [&](const auto& d, const auto& a){ d.handle(a, crate, arm); });
+ Expand_Attrs(arm.m_attrs, stage_pre (is_early), [&](const auto& sp, const auto& d, const auto& a){ d.handle(sp, a, crate, arm); });
if( arm.m_patterns.size() == 0 )
continue ;
for(auto& pat : arm.m_patterns) {
@@ -417,7 +417,7 @@ struct CExpandExpr:
}
this->visit_nodelete(node, arm.m_cond);
this->visit_nodelete(node, arm.m_code);
- Expand_Attrs(arm.m_attrs, stage_post(is_early), [&](const auto& d, const auto& a){ d.handle(a, crate, arm); });
+ Expand_Attrs(arm.m_attrs, stage_post(is_early), [&](const auto& sp, const auto& d, const auto& a){ d.handle(sp, a, crate, arm); });
}
// Prune deleted arms
for(auto it = node.m_arms.begin(); it != node.m_arms.end(); ) {
@@ -560,13 +560,13 @@ void Expand_Mod(bool is_early, ::AST::Crate& crate, LList<const AST::Module*> mo
auto mi_owned = mv$(mi);
auto& attrs = mi_owned.attrs();
- Expand_Attrs(attrs, stage_pre(is_early), [&](const auto& d, const auto& a){ d.handle(a, crate, mi_owned); });
+ Expand_Attrs(attrs, stage_pre(is_early), [&](const auto& sp, const auto& d, const auto& a){ d.handle(sp, a, crate, mi_owned); });
auto ttl = Expand_Macro(is_early, crate, modstack, mod, mi_owned);
if( ! ttl.get() )
{
- Expand_Attrs(attrs, stage_post(is_early), [&](const auto& d, const auto& a){ d.handle(a, crate, mi_owned); });
+ Expand_Attrs(attrs, stage_post(is_early), [&](const auto& sp, const auto& d, const auto& a){ d.handle(sp, a, crate, mi_owned); });
// - Return ownership to the list
mod.macro_invs()[i] = mv$(mi_owned);
}
@@ -608,9 +608,9 @@ void Expand_Mod(bool is_early, ::AST::Crate& crate, LList<const AST::Module*> mo
(Struct,
for(auto it = sd.ents.begin(); it != sd.ents.end(); ) {
auto& si = *it;
- Expand_Attrs(si.m_attrs, stage_pre (is_early), [&](const auto& d, const auto& a){ d.handle(a, crate, si); });
+ Expand_Attrs(si.m_attrs, stage_pre (is_early), [&](const auto& sp, const auto& d, const auto& a){ d.handle(sp, a, crate, si); });
Expand_Type(is_early, crate, modstack, mod, si.m_type);
- Expand_Attrs(si.m_attrs, stage_post(is_early), [&](const auto& d, const auto& a){ d.handle(a, crate, si); });
+ Expand_Attrs(si.m_attrs, stage_post(is_early), [&](const auto& sp, const auto& d, const auto& a){ d.handle(sp, a, crate, si); });
if( si.m_name == "" )
it = sd.ents.erase(it);
@@ -621,9 +621,9 @@ void Expand_Mod(bool is_early, ::AST::Crate& crate, LList<const AST::Module*> mo
(Tuple,
for(auto it = sd.ents.begin(); it != sd.ents.end(); ) {
auto& si = *it;
- Expand_Attrs(si.m_attrs, stage_pre (is_early), [&](const auto& d, const auto& a){ d.handle(a, crate, si); });
+ Expand_Attrs(si.m_attrs, stage_pre (is_early), [&](const auto& sp, const auto& d, const auto& a){ d.handle(sp, a, crate, si); });
Expand_Type(is_early, crate, modstack, mod, si.m_type);
- Expand_Attrs(si.m_attrs, stage_post(is_early), [&](const auto& d, const auto& a){ d.handle(a, crate, si); });
+ Expand_Attrs(si.m_attrs, stage_post(is_early), [&](const auto& sp, const auto& d, const auto& a){ d.handle(sp, a, crate, si); });
if( ! si.m_type.is_valid() )
it = sd.ents.erase(it);
@@ -635,7 +635,7 @@ void Expand_Mod(bool is_early, ::AST::Crate& crate, LList<const AST::Module*> mo
),
(Enum,
for(auto& var : e.variants()) {
- Expand_Attrs(var.m_attrs, stage_pre (is_early), [&](const auto& d, const auto& a){ d.handle(a, crate, var); });
+ Expand_Attrs(var.m_attrs, stage_pre (is_early), [&](const auto& sp, const auto& d, const auto& a){ d.handle(sp, a, crate, var); });
TU_MATCH(::AST::EnumVariantData, (var.m_data), (e),
(Value,
Expand_Expr(is_early, crate, modstack, e.m_value);
@@ -648,9 +648,9 @@ void Expand_Mod(bool is_early, ::AST::Crate& crate, LList<const AST::Module*> mo
(Struct,
for(auto it = e.m_fields.begin(); it != e.m_fields.end(); ) {
auto& si = *it;
- Expand_Attrs(si.m_attrs, stage_pre (is_early), [&](const auto& d, const auto& a){ d.handle(a, crate, si); });
+ Expand_Attrs(si.m_attrs, stage_pre (is_early), [&](const auto& sp, const auto& d, const auto& a){ d.handle(sp, a, crate, si); });
Expand_Type(is_early, crate, modstack, mod, si.m_type);
- Expand_Attrs(si.m_attrs, stage_post(is_early), [&](const auto& d, const auto& a){ d.handle(a, crate, si); });
+ Expand_Attrs(si.m_attrs, stage_post(is_early), [&](const auto& sp, const auto& d, const auto& a){ d.handle(sp, a, crate, si); });
if( si.m_name == "" )
it = e.m_fields.erase(it);
@@ -659,7 +659,7 @@ void Expand_Mod(bool is_early, ::AST::Crate& crate, LList<const AST::Module*> mo
}
)
)
- Expand_Attrs(var.m_attrs, stage_post(is_early), [&](const auto& d, const auto& a){ d.handle(a, crate, var); });
+ Expand_Attrs(var.m_attrs, stage_post(is_early), [&](const auto& sp, const auto& d, const auto& a){ d.handle(sp, a, crate, var); });
}
),
(Trait,
@@ -819,7 +819,7 @@ void Expand(::AST::Crate& crate)
auto modstack = LList<const ::AST::Module*>(nullptr, &crate.m_root_module);
// 1. Crate attributes
- Expand_Attrs(crate.m_attrs, AttrStage::EarlyPre, [&](const auto& d, const auto& a){ d.handle(a, crate); });
+ Expand_Attrs(crate.m_attrs, AttrStage::EarlyPre, [&](const auto& sp, const auto& d, const auto& a){ d.handle(sp, a, crate); });
// Load libstd/libcore
switch( crate.m_load_std )
@@ -827,12 +827,12 @@ void Expand(::AST::Crate& crate)
case ::AST::Crate::LOAD_STD:
if( crate.m_prelude_path != AST::Path() )
crate.m_prelude_path = AST::Path("std", {AST::PathNode("prelude"), AST::PathNode("v1")});
- TODO(Span(), "Load libstd");
+ TODO(Span("",0,0,0,0), "Load libstd");
break;
case ::AST::Crate::LOAD_CORE:
if( crate.m_prelude_path != AST::Path() )
crate.m_prelude_path = AST::Path("core", {AST::PathNode("prelude")});
- TODO(Span(), "Load libcore");
+ TODO(Span("",0,0,0,0), "Load libcore");
break;
case ::AST::Crate::LOAD_NONE:
break;
diff --git a/src/expand/std_prelude.cpp b/src/expand/std_prelude.cpp
index c8ad6471..b7493570 100644
--- a/src/expand/std_prelude.cpp
+++ b/src/expand/std_prelude.cpp
@@ -9,9 +9,9 @@ class Decorator_NoStd:
public:
AttrStage stage() const override { return AttrStage::EarlyPre; }
- void handle(const AST::MetaItem& mi, AST::Crate& crate) const override {
+ void handle(const Span& sp, const AST::MetaItem& mi, AST::Crate& crate) const override {
if( crate.m_load_std != AST::Crate::LOAD_STD ) {
- ERROR(Span()/*mi.span()*/, E0000, "Invalid use of #![no_std] with itself or #![no_core]");
+ ERROR(sp, E0000, "Invalid use of #![no_std] with itself or #![no_core]");
}
crate.m_load_std = AST::Crate::LOAD_CORE;
}
@@ -22,9 +22,9 @@ class Decorator_NoCore:
public:
AttrStage stage() const override { return AttrStage::EarlyPre; }
- void handle(const AST::MetaItem& mi, AST::Crate& crate) const override {
+ void handle(const Span& sp, const AST::MetaItem& mi, AST::Crate& crate) const override {
if( crate.m_load_std != AST::Crate::LOAD_STD ) {
- ERROR(Span()/*mi.span()*/, E0000, "Invalid use of #![no_core] with itself or #![no_std]");
+ ERROR(sp, E0000, "Invalid use of #![no_core] with itself or #![no_std]");
}
crate.m_load_std = AST::Crate::LOAD_NONE;
}
diff --git a/src/expand/stringify.cpp b/src/expand/stringify.cpp
index e4abb99b..ea54a6f6 100644
--- a/src/expand/stringify.cpp
+++ b/src/expand/stringify.cpp
@@ -8,7 +8,7 @@ class CExpander:
{
bool expand_early() const override { return true; }
- ::std::unique_ptr<TokenStream> expand(Span sp, const AST::Crate& crate, const ::std::string& ident, const TokenTree& tt, AST::Module& mod) override
+ ::std::unique_ptr<TokenStream> expand(const Span& sp, const AST::Crate& crate, const ::std::string& ident, const TokenTree& tt, AST::Module& mod) override
{
Token tok;
::std::string rv;
diff --git a/src/hir/from_ast.cpp b/src/hir/from_ast.cpp
index 925f34f0..df73d4ec 100644
--- a/src/hir/from_ast.cpp
+++ b/src/hir/from_ast.cpp
@@ -46,17 +46,17 @@
(IsTrait,
rv.m_bounds.push_back(::HIR::GenericBound::make_TraitBound({
LowerHIR_Type(e.type),
- ::HIR::TraitPath { LowerHIR_GenericPath(Span(), e.trait), e.hrls }
+ ::HIR::TraitPath { LowerHIR_GenericPath(bound.span, e.trait), e.hrls }
}));
),
(MaybeTrait,
rv.m_bounds.push_back(::HIR::GenericBound::make_TraitUnbound({
LowerHIR_Type(e.type),
- LowerHIR_GenericPath(Span(), e.trait)
+ LowerHIR_GenericPath(bound.span, e.trait)
}));
),
(NotTrait,
- TODO(Span(), "Negative trait bounds");
+ TODO(bound.span, "Negative trait bounds");
),
(Equality,
@@ -89,10 +89,10 @@
}
TU_MATCH(::AST::Pattern::Data, (pat.data()), (e),
(MaybeBind,
- BUG(Span(), "Encountered MaybeBind pattern");
+ BUG(pat.span(), "Encountered MaybeBind pattern");
),
(Macro,
- BUG(Span(), "Encountered Macro pattern");
+ BUG(pat.span(), "Encountered Macro pattern");
),
(Any,
return ::HIR::Pattern {
@@ -137,13 +137,13 @@
TU_MATCH_DEF(::AST::PathBinding, (e.path.binding()), (pb),
(
- BUG(Span(), "Encountered StructTuple pattern not pointing to a enum variant or a struct - " << e.path);
+ BUG(pat.span(), "Encountered StructTuple pattern not pointing to a enum variant or a struct - " << e.path);
),
(EnumVar,
return ::HIR::Pattern {
mv$(binding),
::HIR::Pattern::Data::make_EnumTuple({
- LowerHIR_GenericPath(Span(), e.path),
+ LowerHIR_GenericPath(pat.span(), e.path),
mv$(sub_patterns)
})
};
@@ -152,7 +152,7 @@
return ::HIR::Pattern {
mv$(binding),
::HIR::Pattern::Data::make_StructTuple({
- LowerHIR_GenericPath(Span(), e.path),
+ LowerHIR_GenericPath(pat.span(), e.path),
mv$(sub_patterns)
})
};
@@ -167,13 +167,13 @@
TU_MATCH_DEF(::AST::PathBinding, (e.path.binding()), (pb),
(
- BUG(Span(), "Encountered Struct pattern not pointing to a enum variant or a struct");
+ BUG(pat.span(), "Encountered Struct pattern not pointing to a enum variant or a struct");
),
(EnumVar,
return ::HIR::Pattern {
mv$(binding),
::HIR::Pattern::Data::make_EnumStruct({
- LowerHIR_GenericPath(Span(), e.path),
+ LowerHIR_GenericPath(pat.span(), e.path),
mv$(sub_patterns)
})
};
@@ -182,7 +182,7 @@
return ::HIR::Pattern {
mv$(binding),
::HIR::Pattern::Data::make_Struct({
- LowerHIR_GenericPath(Span(), e.path),
+ LowerHIR_GenericPath(pat.span(), e.path),
mv$(sub_patterns)
})
};
@@ -192,7 +192,7 @@
(Value,
struct H {
- static ::HIR::CoreType get_int_type(const ::eCoreType ct) {
+ static ::HIR::CoreType get_int_type(const Span& sp, const ::eCoreType ct) {
switch(ct)
{
case CORETYPE_ANY: return ::HIR::CoreType::Str;
@@ -214,17 +214,17 @@
case CORETYPE_BOOL: return ::HIR::CoreType::Bool;
default:
- BUG(Span(), "Unknown type for integer literal in pattern - " << ct );
+ BUG(sp, "Unknown type for integer literal in pattern - " << ct );
}
}
- static ::HIR::Pattern::Value lowerhir_pattern_value(const ::AST::Pattern::Value& v) {
+ static ::HIR::Pattern::Value lowerhir_pattern_value(const Span& sp, const ::AST::Pattern::Value& v) {
TU_MATCH(::AST::Pattern::Value, (v), (e),
(Invalid,
- BUG(Span(), "Encountered Invalid value in Pattern");
+ BUG(sp, "Encountered Invalid value in Pattern");
),
(Integer,
return ::HIR::Pattern::Value::make_Integer({
- H::get_int_type(e.type),
+ H::get_int_type(sp, e.type),
e.value
});
),
@@ -232,7 +232,7 @@
return ::HIR::Pattern::Value::make_String(e);
),
(Named,
- return ::HIR::Pattern::Value::make_Named( LowerHIR_Path(Span(), e) );
+ return ::HIR::Pattern::Value::make_Named( LowerHIR_Path(sp, e) );
)
)
throw "BUGCHECK: Reached end of LowerHIR_Pattern::H::lowerhir_pattern_value";
@@ -242,7 +242,7 @@
return ::HIR::Pattern {
mv$(binding),
::HIR::Pattern::Data::make_Value({
- H::lowerhir_pattern_value(e.start)
+ H::lowerhir_pattern_value(pat.span(), e.start)
})
};
}
@@ -250,8 +250,8 @@
return ::HIR::Pattern {
mv$(binding),
::HIR::Pattern::Data::make_Range({
- H::lowerhir_pattern_value(e.start),
- H::lowerhir_pattern_value(e.end)
+ H::lowerhir_pattern_value(pat.span(), e.start),
+ H::lowerhir_pattern_value(pat.span(), e.end)
})
};
}
@@ -348,7 +348,7 @@
return ::HIR::GenericPath(mv$(sp), mv$(params));
)
else {
- BUG(Span(), "Encountered non-Absolute path when creating ::HIR::GenericPath - " << path);
+ BUG(sp, "Encountered non-Absolute path when creating ::HIR::GenericPath - " << path);
}
}
::HIR::Path LowerHIR_Path(const Span& sp, const ::AST::Path& path)
@@ -374,7 +374,7 @@
),
(UFCS,
if( e.nodes.size() != 1 )
- TODO(Span(), "Handle UFCS with multiple nodes - " << path);
+ TODO(sp, "Handle UFCS with multiple nodes - " << path);
if( ! e.trait )
{
return ::HIR::Path(::HIR::Path::Data::make_UfcsInherent({
@@ -599,8 +599,8 @@
::std::vector< ::HIR::GenericPath> supertraits;
for(const auto& st : f.supertraits()) {
- if( st.is_valid() ) {
- supertraits.push_back( LowerHIR_GenericPath(Span(), st) );
+ if( st.ent.is_valid() ) {
+ supertraits.push_back( LowerHIR_GenericPath(st.sp, st.ent) );
}
else {
lifetime = "static";
@@ -618,7 +618,7 @@
{
TU_MATCH_DEF(::AST::Item, (item.data), (i),
(
- BUG(Span(), "Encountered unexpected item type in trait");
+ BUG(item.data.span, "Encountered unexpected item type in trait");
),
(Type,
rv.m_types.insert( ::std::make_pair(item.name, ::HIR::AssociatedType {
@@ -793,7 +793,7 @@ void LowerHIR_Module_Impls(const ::AST::Module& ast_mod, ::HIR::Crate& hir_crat
{
TU_MATCH_DEF(::AST::Item, (item.data), (e),
(
- ERROR(Span(), E0000, "Unexpected item type in trait impl");
+ ERROR(item.data.span, E0000, "Unexpected item type in trait impl");
),
// TODO: Associated constants
(Type,
@@ -825,7 +825,7 @@ void LowerHIR_Module_Impls(const ::AST::Module& ast_mod, ::HIR::Crate& hir_crat
{
TU_MATCH_DEF(::AST::Item, (item.data), (e),
(
- ERROR(Span(), E0000, "Unexpected item type in inherent impl");
+ ERROR(item.data.span, E0000, "Unexpected item type in inherent impl");
),
(Function,
methods.insert( ::std::make_pair(item.name, LowerHIR_Function(e)) );
diff --git a/src/include/synext.hpp b/src/include/synext.hpp
index 40e3d073..3ac3fb37 100644
--- a/src/include/synext.hpp
+++ b/src/include/synext.hpp
@@ -46,25 +46,25 @@ enum class AttrStage
class ExpandDecorator
{
- void unexpected(const AST::MetaItem& mi, const char* loc_str) const;
+ void unexpected(const Span& sp, const AST::MetaItem& mi, const char* loc_str) const;
public:
virtual AttrStage stage() const = 0;
- virtual void handle(const AST::MetaItem& mi, AST::Crate& crate) const { unexpected(mi, "crate"); }
- virtual void handle(const AST::MetaItem& mi, AST::Crate& crate, AST::MacroInvocation& mac) const { unexpected(mi, "macro invocation"); }
- virtual void handle(const AST::MetaItem& mi, AST::Crate& crate, const AST::Path& path, AST::Module& mod, AST::Item&i) const { unexpected(mi, "item"); }
+ virtual void handle(const Span& sp, const AST::MetaItem& mi, AST::Crate& crate) const { unexpected(sp, mi, "crate"); }
+ virtual void handle(const Span& sp, const AST::MetaItem& mi, AST::Crate& crate, AST::MacroInvocation& mac) const { unexpected(sp, mi, "macro invocation"); }
+ virtual void handle(const Span& sp, const AST::MetaItem& mi, AST::Crate& crate, const AST::Path& path, AST::Module& mod, AST::Item&i) const { unexpected(sp, mi, "item"); }
// NOTE: To delete, set the type to `_`
- virtual void handle(const AST::MetaItem& mi, AST::Crate& crate, const AST::Module& mod, AST::ImplDef& impl) const { unexpected(mi, "impl"); }
+ virtual void handle(const Span& sp, const AST::MetaItem& mi, AST::Crate& crate, const AST::Module& mod, AST::ImplDef& impl) const { unexpected(sp, mi, "impl"); }
// NOTE: To delete, clear the name
- virtual void handle(const AST::MetaItem& mi, AST::Crate& crate, ::AST::StructItem& si) const { unexpected(mi, "struct item"); }
+ virtual void handle(const Span& sp, const AST::MetaItem& mi, AST::Crate& crate, ::AST::StructItem& si) const { unexpected(sp, mi, "struct item"); }
// NOTE: To delete, make the type invalid
- virtual void handle(const AST::MetaItem& mi, AST::Crate& crate, ::AST::TupleItem& si) const { unexpected(mi, "tuple item"); }
+ virtual void handle(const Span& sp, const AST::MetaItem& mi, AST::Crate& crate, ::AST::TupleItem& si) const { unexpected(sp, mi, "tuple item"); }
// NOTE: To delete, clear the name
- virtual void handle(const AST::MetaItem& mi, AST::Crate& crate, ::AST::EnumVariant& ev) const { unexpected(mi, "enum variant"); }
+ virtual void handle(const Span& sp, const AST::MetaItem& mi, AST::Crate& crate, ::AST::EnumVariant& ev) const { unexpected(sp, mi, "enum variant"); }
- virtual void handle(const AST::MetaItem& mi, AST::Crate& crate, ::std::unique_ptr<AST::ExprNode>& expr) const { unexpected(mi, "expression"); }
+ virtual void handle(const Span& sp, const AST::MetaItem& mi, AST::Crate& crate, ::std::unique_ptr<AST::ExprNode>& expr) const { unexpected(sp, mi, "expression"); }
// NOTE: To delete, clear the patterns vector
- virtual void handle(const AST::MetaItem& mi, AST::Crate& crate, ::AST::ExprNode_Match_Arm& expr) const { unexpected(mi, "match arm"); }
+ virtual void handle(const Span& sp, const AST::MetaItem& mi, AST::Crate& crate, ::AST::ExprNode_Match_Arm& expr) const { unexpected(sp, mi, "match arm"); }
};
class ExpandProcMacro
@@ -72,7 +72,7 @@ class ExpandProcMacro
public:
virtual bool expand_early() const = 0;
- virtual ::std::unique_ptr<TokenStream> expand(Span sp, const AST::Crate& crate, const ::std::string& ident, const TokenTree& tt, AST::Module& mod) = 0;
+ 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_DECORATOR(ident, _handler_class) \
diff --git a/src/parse/root.cpp b/src/parse/root.cpp
index 80cffdfe..9deb3446 100644
--- a/src/parse/root.cpp
+++ b/src/parse/root.cpp
@@ -24,6 +24,7 @@ Spanned<T> get_spanned(TokenStream& lex, ::std::function<T()> f) {
mv$(v)
};
}
+#define GET_SPANNED(type, lex, val) get_spanned< type >(lex, [&](){ return val; })
::std::string dirname(::std::string input) {
while( input.size() > 0 && input.back() != '/' ) {
@@ -545,17 +546,17 @@ AST::Trait Parse_TraitDef(TokenStream& lex, AST::Module& mod, const AST::MetaIte
}
// Trait bounds "trait Trait : 'lifetime + OtherTrait + OtherTrait2"
- ::std::vector<AST::Path> supertraits;
+ ::std::vector<Spanned<AST::Path> > supertraits;
if(tok.type() == TOK_COLON)
{
do {
if( GET_TOK(tok, lex) == TOK_LIFETIME ) {
// TODO: Need a better way of indiciating 'static than just an invalid path
- supertraits.push_back( AST::Path() );
+ supertraits.push_back( make_spanned( Span(tok.get_pos()), AST::Path() ) );
}
else {
lex.putback(tok);
- supertraits.push_back( Parse_Path(lex, PATH_GENERIC_TYPE) );
+ supertraits.push_back( GET_SPANNED(::AST::Path, lex, Parse_Path(lex, PATH_GENERIC_TYPE)) );
}
} while( GET_TOK(tok, lex) == TOK_PLUS );
}
@@ -858,7 +859,7 @@ void Parse_Impl(TokenStream& lex, AST::Module& mod, AST::MetaItems attrs, bool i
// "impl !Trait for Type {}"
if( GET_TOK(tok, lex) == TOK_EXCLAM )
{
- trait_path = get_spanned< ::AST::Path>(lex, [&]() { return Parse_Path(lex, PATH_GENERIC_TYPE); });
+ trait_path = GET_SPANNED(::AST::Path, lex, Parse_Path(lex, PATH_GENERIC_TYPE));
GET_CHECK_TOK(tok, lex, TOK_RWORD_FOR);
impl_type = Parse_Type(lex);
@@ -951,7 +952,7 @@ void Parse_Impl_Item(TokenStream& lex, AST::Impl& impl)
{
TRACE_FUNCTION;
Token tok;
-
+
GET_TOK(tok, lex);
AST::MetaItems item_attrs;
@@ -963,6 +964,8 @@ void Parse_Impl_Item(TokenStream& lex, AST::Impl& impl)
}
SET_ATTRS(lex, item_attrs);
+ auto ps = lex.start_span();
+
bool is_public = false;
if(tok.type() == TOK_RWORD_PUB) {
is_public = true;
@@ -1049,6 +1052,8 @@ void Parse_Impl_Item(TokenStream& lex, AST::Impl& impl)
default:
throw ParseError::Unexpected(lex, tok);
}
+
+ impl.items().back().data.span = lex.end_span(ps);
}
void Parse_ExternBlock(TokenStream& lex, AST::Module& mod, ::std::string abi, ::AST::MetaItems block_attrs)
@@ -1299,6 +1304,8 @@ void Parse_Mod_Item(TokenStream& lex, bool file_controls_dir, const ::std::strin
//TRACE_FUNCTION;
Token tok;
+ auto ps = lex.start_span();
+ #define APPLY_SPAN_ITEM() mod.items().back().data.span = lex.end_span(ps)
// The actual item!
switch( GET_TOK(tok, lex) )
{
@@ -1325,6 +1332,7 @@ void Parse_Mod_Item(TokenStream& lex, bool file_controls_dir, const ::std::strin
GET_CHECK_TOK(tok, lex, TOK_IDENT);
auto i = Parse_FunctionDefWithCode(lex, abi, meta_items, false);
mod.add_function(is_public, tok.str(), mv$(i), mv$(meta_items));
+ APPLY_SPAN_ITEM();
break; }
// `extern "<ABI>" { ...`
case TOK_BRACE_OPEN:
@@ -1339,6 +1347,7 @@ void Parse_Mod_Item(TokenStream& lex, bool file_controls_dir, const ::std::strin
GET_CHECK_TOK(tok, lex, TOK_IDENT);
auto i = Parse_FunctionDefWithCode(lex, "C", meta_items, false);
mod.add_function(is_public, tok.str(), mv$(i), mv$(meta_items));
+ APPLY_SPAN_ITEM();
break; }
// `extern { ...`
case TOK_BRACE_OPEN:
@@ -1368,6 +1377,7 @@ void Parse_Mod_Item(TokenStream& lex, bool file_controls_dir, const ::std::strin
AST::Expr val = Parse_Expr(lex);
GET_CHECK_TOK(tok, lex, TOK_SEMICOLON);
mod.add_static(is_public, name, AST::Static(AST::Static::CONST, type, val), mv$(meta_items));
+ APPLY_SPAN_ITEM();
break; }
case TOK_RWORD_UNSAFE: {
GET_CHECK_TOK(tok, lex, TOK_RWORD_FN);
@@ -1377,6 +1387,7 @@ void Parse_Mod_Item(TokenStream& lex, bool file_controls_dir, const ::std::strin
meta_items.push_back( AST::MetaItem("#CONST") );
auto i = Parse_FunctionDefWithCode(lex, "rust", meta_items, false);
mod.add_function(is_public, tok.str(), mv$(i), mv$(meta_items));
+ APPLY_SPAN_ITEM();
break; }
case TOK_RWORD_FN: {
GET_CHECK_TOK(tok, lex, TOK_IDENT);
@@ -1385,6 +1396,7 @@ void Parse_Mod_Item(TokenStream& lex, bool file_controls_dir, const ::std::strin
// - self not allowed, not prototype
auto i = Parse_FunctionDefWithCode(lex, "rust", meta_items, false);
mod.add_function(is_public, tok.str(), mv$(i), mv$(meta_items));
+ APPLY_SPAN_ITEM();
break; }
default:
throw ParseError::Unexpected(lex, tok, {TOK_IDENT, TOK_RWORD_FN});
@@ -1413,6 +1425,7 @@ void Parse_Mod_Item(TokenStream& lex, bool file_controls_dir, const ::std::strin
AST::Static((is_mut ? AST::Static::MUT : AST::Static::STATIC), type, val),
mv$(meta_items)
);
+ APPLY_SPAN_ITEM();
break; }
// `unsafe fn`
@@ -1435,6 +1448,7 @@ void Parse_Mod_Item(TokenStream& lex, bool file_controls_dir, const ::std::strin
GET_CHECK_TOK(tok, lex, TOK_IDENT);
auto i = Parse_FunctionDefWithCode(lex, abi, meta_items, false);
mod.add_function(is_public, tok.str(), mv$(i), mv$(meta_items));
+ APPLY_SPAN_ITEM();
break; }
// `unsafe fn`
case TOK_RWORD_FN: {
@@ -1445,6 +1459,7 @@ void Parse_Mod_Item(TokenStream& lex, bool file_controls_dir, const ::std::strin
auto i = Parse_FunctionDefWithCode(lex, "rust", meta_items, false);
//i.set_unsafe();
mod.add_function(is_public, tok.str(), mv$(i), mv$(meta_items));
+ APPLY_SPAN_ITEM();
break; }
// `unsafe trait`
case TOK_RWORD_TRAIT: {
@@ -1454,6 +1469,7 @@ void Parse_Mod_Item(TokenStream& lex, bool file_controls_dir, const ::std::strin
auto i = Parse_TraitDef(lex, mod, meta_items);
//i.set_unsafe();
mod.add_trait(is_public, name, mv$(i), mv$(meta_items));
+ APPLY_SPAN_ITEM();
break; }
// `unsafe impl`
case TOK_RWORD_IMPL:
@@ -1470,6 +1486,7 @@ void Parse_Mod_Item(TokenStream& lex, bool file_controls_dir, const ::std::strin
// - self not allowed, not prototype
auto i = Parse_FunctionDefWithCode(lex, "rust", meta_items, false);
mod.add_function(is_public, name, mv$(i), mv$(meta_items));
+ APPLY_SPAN_ITEM();
break; }
// `type`
case TOK_RWORD_TYPE: {
@@ -1477,6 +1494,7 @@ void Parse_Mod_Item(TokenStream& lex, bool file_controls_dir, const ::std::strin
auto name = mv$(tok.str());
auto i = Parse_TypeAlias(lex, meta_items);
mod.add_typealias(is_public, mv$(name), mv$(i), mv$(meta_items));
+ APPLY_SPAN_ITEM();
break; }
// `struct`
case TOK_RWORD_STRUCT: {
@@ -1484,6 +1502,7 @@ void Parse_Mod_Item(TokenStream& lex, bool file_controls_dir, const ::std::strin
auto name = mv$(tok.str());
auto i = Parse_Struct(lex, meta_items);
mod.add_struct( is_public, name, mv$(i), mv$(meta_items) );
+ APPLY_SPAN_ITEM();
break; }
// `enum`
case TOK_RWORD_ENUM: {
@@ -1491,6 +1510,7 @@ void Parse_Mod_Item(TokenStream& lex, bool file_controls_dir, const ::std::strin
::std::string name = tok.str();
auto i = Parse_EnumDef(lex, mod, meta_items);
mod.add_enum(is_public, name, mv$(i), mv$(meta_items));
+ APPLY_SPAN_ITEM();
break; }
// `impl`
case TOK_RWORD_IMPL:
@@ -1502,6 +1522,7 @@ void Parse_Mod_Item(TokenStream& lex, bool file_controls_dir, const ::std::strin
::std::string name = tok.str();
auto i = Parse_TraitDef(lex, mod, meta_items);
mod.add_trait(is_public, name, mv$(i), mv$(meta_items));
+ APPLY_SPAN_ITEM();
break; }
case TOK_RWORD_MOD: {
@@ -1591,11 +1612,13 @@ void Parse_Mod_Item(TokenStream& lex, bool file_controls_dir, const ::std::strin
}
submod.prescan();
mod.add_submod(is_public, mv$(name), mv$(submod), mv$(meta_items));
+ APPLY_SPAN_ITEM();
break; }
default:
throw ParseError::Unexpected(lex, tok);
}
+ #undef APPLY_SPAN_ITEM
}
void Parse_ModRoot_Items(TokenStream& lex, AST::Module& mod, bool file_controls_dir, const ::std::string& path)
diff --git a/src/resolve/absolute.cpp b/src/resolve/absolute.cpp
index 103497e6..91176ee0 100644
--- a/src/resolve/absolute.cpp
+++ b/src/resolve/absolute.cpp
@@ -110,12 +110,12 @@ struct Context
void push_block() {
m_block_level += 1;
}
- unsigned int push_var(const ::std::string& name) {
+ unsigned int push_var(const Span& sp, const ::std::string& name) {
// TODO: Handle avoiding duplicate bindings in a pattern
if( m_frozen_bind_set )
{
if( !m_name_context.back().is_VarBlock() ) {
- BUG(Span(), "resolve/absolute.cpp - Context::push_var - No block");
+ BUG(sp, "resolve/absolute.cpp - Context::push_var - No block");
}
auto& vb = m_name_context.back().as_VarBlock();
for( const auto& v : vb.variables )
@@ -125,7 +125,7 @@ struct Context
return v.value;
}
}
- ERROR(Span(), E0000, "Mismatched bindings in pattern");
+ ERROR(sp, E0000, "Mismatched bindings in pattern");
}
else
{
@@ -335,7 +335,7 @@ struct Context
auto ct = coretype_fromstring(name);
if( ct != CORETYPE_INVAL )
{
- return ::AST::Path( ::AST::Path::TagUfcs(), TypeRef(Span(), ct), ::std::vector< ::AST::PathNode>() );
+ return ::AST::Path( ::AST::Path::TagUfcs(), TypeRef(Span("-",0,0,0,0), ct), ::std::vector< ::AST::PathNode>() );
}
return AST::Path();
@@ -975,15 +975,15 @@ void Resolve_Absolute_Generic(Context& context, ::AST::GenericParams& params)
),
(IsTrait,
Resolve_Absolute_Type(context, e.type);
- Resolve_Absolute_Path(context, Span(), Context::LookupMode::Type, e.trait);
+ Resolve_Absolute_Path(context, bound.span, Context::LookupMode::Type, e.trait);
),
(MaybeTrait,
Resolve_Absolute_Type(context, e.type);
- Resolve_Absolute_Path(context, Span(), Context::LookupMode::Type, e.trait);
+ Resolve_Absolute_Path(context, bound.span, Context::LookupMode::Type, e.trait);
),
(NotTrait,
Resolve_Absolute_Type(context, e.type);
- Resolve_Absolute_Path(context, Span(), Context::LookupMode::Type, e.trait);
+ Resolve_Absolute_Path(context, bound.span, Context::LookupMode::Type, e.trait);
),
(Equality,
Resolve_Absolute_Type(context, e.type);
@@ -994,7 +994,7 @@ void Resolve_Absolute_Generic(Context& context, ::AST::GenericParams& params)
}
// Locals shouldn't be possible, as they'd end up as MaybeBind. Will assert the path class.
-void Resolve_Absolute_PatternValue(/*const*/ Context& context, ::AST::Pattern::Value& val)
+void Resolve_Absolute_PatternValue(/*const*/ Context& context, const Span& sp, ::AST::Pattern::Value& val)
{
TU_MATCH(::AST::Pattern::Value, (val), (e),
(Invalid, ),
@@ -1002,7 +1002,7 @@ void Resolve_Absolute_PatternValue(/*const*/ Context& context, ::AST::Pattern::V
(String, ),
(Named,
//assert( ! e.is_trivial() );
- Resolve_Absolute_Path(context, Span(), Context::LookupMode::Constant, e);
+ Resolve_Absolute_Path(context, sp, Context::LookupMode::Constant, e);
)
)
}
@@ -1011,9 +1011,9 @@ void Resolve_Absolute_Pattern(Context& context, bool allow_refutable, ::AST::Pa
TRACE_FUNCTION_F("allow_refutable = " << allow_refutable << ", pat = " << pat);
if( pat.binding() != "" ) {
if( !pat.data().is_Any() && ! allow_refutable )
- TODO(Span(), "Resolve_Absolute_Pattern - Encountered bound destructuring pattern");
+ TODO(pat.span(), "Resolve_Absolute_Pattern - Encountered bound destructuring pattern");
// TODO: Record the local variable number in the binding
- context.push_var( pat.binding() );
+ context.push_var( pat.span(), pat.binding() );
}
TU_MATCH( ::AST::Pattern::Data, (pat.data()), (e),
@@ -1029,15 +1029,15 @@ void Resolve_Absolute_Pattern(Context& context, bool allow_refutable, ::AST::Pa
else {
pat = ::AST::Pattern(::AST::Pattern::TagBind(), mv$(name));
// TODO: Record the local variable number in the binding
- context.push_var( pat.binding() );
+ context.push_var( pat.span(), pat.binding() );
}
}
else {
- TODO(Span(), "Resolve_Absolute_Pattern - Encountered MaybeBind in irrefutable context - replace with binding");
+ TODO(pat.span(), "Resolve_Absolute_Pattern - Encountered MaybeBind in irrefutable context - replace with binding");
}
),
(Macro,
- BUG(Span(), "Resolve_Absolute_Pattern - Encountered Macro");
+ BUG(pat.span(), "Resolve_Absolute_Pattern - Encountered Macro");
),
(Any,
// Ignore '_'
@@ -1050,9 +1050,9 @@ void Resolve_Absolute_Pattern(Context& context, bool allow_refutable, ::AST::Pa
),
(Value,
if( ! allow_refutable )
- BUG(Span(), "Resolve_Absolute_Pattern - Enountered refutable pattern where only irrefutable allowed");
- Resolve_Absolute_PatternValue(context, e.start);
- Resolve_Absolute_PatternValue(context, e.end);
+ BUG(pat.span(), "Resolve_Absolute_Pattern - Enountered refutable pattern where only irrefutable allowed");
+ Resolve_Absolute_PatternValue(context, pat.span(), e.start);
+ Resolve_Absolute_PatternValue(context, pat.span(), e.end);
),
(Tuple,
for(auto& sp : e.sub_patterns)
@@ -1060,22 +1060,22 @@ void Resolve_Absolute_Pattern(Context& context, bool allow_refutable, ::AST::Pa
),
(StructTuple,
// TODO: This isn't a type lookup, it's a pattern lookup (allowing imported enum variants, e.g. `Some(_)` to work)
- Resolve_Absolute_Path(context, Span(), Context::LookupMode::Pattern, e.path);
+ Resolve_Absolute_Path(context, pat.span(), Context::LookupMode::Pattern, e.path);
for(auto& sp : e.sub_patterns)
Resolve_Absolute_Pattern(context, allow_refutable, sp);
),
(Struct,
- Resolve_Absolute_Path(context, Span(), Context::LookupMode::Type, e.path);
+ Resolve_Absolute_Path(context, pat.span(), Context::LookupMode::Type, e.path);
for(auto& sp : e.sub_patterns)
Resolve_Absolute_Pattern(context, allow_refutable, sp.second);
),
(Slice,
if( !allow_refutable )
- BUG(Span(), "Resolve_Absolute_Pattern - Enountered refutable pattern where only irrefutable allowed");
+ BUG(pat.span(), "Resolve_Absolute_Pattern - Enountered refutable pattern where only irrefutable allowed");
for(auto& sp : e.leading)
Resolve_Absolute_Pattern(context, allow_refutable, sp);
if( e.extra_bind != "" && e.extra_bind != "_" ) {
- context.push_var( e.extra_bind );
+ context.push_var( pat.span(), e.extra_bind );
}
for(auto& sp : e.trailing)
Resolve_Absolute_Pattern(context, allow_refutable, sp);
@@ -1090,11 +1090,11 @@ void Resolve_Absolute_ImplItems(Context& item_context, ::AST::NamedList< ::AST:
{
TU_MATCH(AST::Item, (i.data), (e),
(None, ),
- (Module, BUG(Span(), "Resolve_Absolute_ImplItems - Module");),
- (Crate , BUG(Span(), "Resolve_Absolute_ImplItems - Crate");),
- (Enum , BUG(Span(), "Resolve_Absolute_ImplItems - Enum");),
- (Trait , BUG(Span(), "Resolve_Absolute_ImplItems - Trait");),
- (Struct, BUG(Span(), "Resolve_Absolute_ImplItems - Struct");),
+ (Module, BUG(i.data.span, "Resolve_Absolute_ImplItems - Module");),
+ (Crate , BUG(i.data.span, "Resolve_Absolute_ImplItems - Crate");),
+ (Enum , BUG(i.data.span, "Resolve_Absolute_ImplItems - Enum");),
+ (Trait , BUG(i.data.span, "Resolve_Absolute_ImplItems - Trait");),
+ (Struct, BUG(i.data.span, "Resolve_Absolute_ImplItems - Struct");),
(Type,
DEBUG("Type - " << i.name);
assert( e.params().ty_params().size() == 0 );
@@ -1128,7 +1128,7 @@ void Resolve_Absolute_ImplItems(Context& item_context, ::AST::NamedList< ::AST:
),
(Static,
DEBUG("Static - " << i.name);
- TODO(Span(), "Resolve_Absolute_ImplItems - Static");
+ TODO(i.data.span, "Resolve_Absolute_ImplItems - Static");
)
)
}
@@ -1185,12 +1185,12 @@ void Resolve_Absolute_Mod( Context item_context, ::AST::Module& mod )
Resolve_Absolute_Generic(item_context, e.params());
for(auto& st : e.supertraits()) {
- if( !st.is_valid() ) {
+ if( !st.ent.is_valid() ) {
DEBUG("- ST 'static");
}
else {
- DEBUG("- ST " << st);
- Resolve_Absolute_Path(item_context, Span(), Context::LookupMode::Type, st);
+ DEBUG("- ST " << st.ent);
+ Resolve_Absolute_Path(item_context, st.sp, Context::LookupMode::Type, st.ent);
}
}
@@ -1266,7 +1266,7 @@ void Resolve_Absolute_Mod( Context item_context, ::AST::Module& mod )
Resolve_Absolute_Path(item_context, def.trait().sp, Context::LookupMode::Type, def.trait().ent);
if( impl.items().size() != 0 ) {
- ERROR(Span(), E0000, "impl Trait for .. with methods");
+ ERROR(def.span(), E0000, "impl Trait for .. with methods");
}
item_context.pop(def.params());
@@ -1299,7 +1299,7 @@ void Resolve_Absolute_Mod( Context item_context, ::AST::Module& mod )
Resolve_Absolute_Type(item_context, impl_def.type());
if( !impl_def.trait().ent.is_valid() )
- BUG(Span(), "Encountered negative impl with no trait");
+ BUG(impl_def.span(), "Encountered negative impl with no trait");
Resolve_Absolute_Path(item_context, impl_def.trait().sp, Context::LookupMode::Type, impl_def.trait().ent);
// No items
diff --git a/src/resolve/index.cpp b/src/resolve/index.cpp
index e84bddd1..d3fdf57d 100644
--- a/src/resolve/index.cpp
+++ b/src/resolve/index.cpp
@@ -37,7 +37,7 @@ enum class IndexName
throw "";
}
-void _add_item(AST::Module& mod, IndexName location, const ::std::string& name, bool is_pub, ::AST::Path ir, bool error_on_collision=true)
+void _add_item(const Span& sp, AST::Module& mod, IndexName location, const ::std::string& name, bool is_pub, ::AST::Path ir, bool error_on_collision=true)
{
DEBUG("Add " << location << " item '" << name << "': " << ir);
auto& list = get_mod_index(mod, location);
@@ -50,7 +50,7 @@ void _add_item(AST::Module& mod, IndexName location, const ::std::string& name,
{
if( error_on_collision )
{
- ERROR(Span(), E0000, "Duplicate definition of name '" << name << "' in " << location << " scope (" << mod.path() << ")");
+ ERROR(sp, E0000, "Duplicate definition of name '" << name << "' in " << location << " scope (" << mod.path() << ")");
}
else
{
@@ -58,14 +58,14 @@ void _add_item(AST::Module& mod, IndexName location, const ::std::string& name,
}
}
}
-void _add_item_type(AST::Module& mod, const ::std::string& name, bool is_pub, ::AST::Path ir, bool error_on_collision=true)
+void _add_item_type(const Span& sp, AST::Module& mod, const ::std::string& name, bool is_pub, ::AST::Path ir, bool error_on_collision=true)
{
- _add_item(mod, IndexName::Namespace, name, is_pub, ::AST::Path(ir), error_on_collision);
- _add_item(mod, IndexName::Type, name, is_pub, mv$(ir), error_on_collision);
+ _add_item(sp, mod, IndexName::Namespace, name, is_pub, ::AST::Path(ir), error_on_collision);
+ _add_item(sp, mod, IndexName::Type, name, is_pub, mv$(ir), error_on_collision);
}
-void _add_item_value(AST::Module& mod, const ::std::string& name, bool is_pub, ::AST::Path ir, bool error_on_collision=true)
+void _add_item_value(const Span& sp, AST::Module& mod, const ::std::string& name, bool is_pub, ::AST::Path ir, bool error_on_collision=true)
{
- _add_item(mod, IndexName::Value, name, is_pub, mv$(ir), error_on_collision);
+ _add_item(sp, mod, IndexName::Value, name, is_pub, mv$(ir), error_on_collision);
}
void Resolve_Index_Module_Base(AST::Module& mod)
@@ -82,42 +82,42 @@ void Resolve_Index_Module_Base(AST::Module& mod)
// - Types/modules only
(Module,
p.bind( ::AST::PathBinding::make_Module({&e}) );
- _add_item(mod, IndexName::Namespace, i.name, i.is_pub, mv$(p));
+ _add_item(i.data.span, mod, IndexName::Namespace, i.name, i.is_pub, mv$(p));
),
(Crate,
- TODO(Span(), "Crate in Resolve_Index_Module");
+ TODO(i.data.span, "Crate in Resolve_Index_Module");
//p.bind( ::AST::PathBinding::make_Crate(e) );
- //_add_item(mod, IndexName::Namespace, i.name, i.is_pub, mv$(p));
+ //_add_item(i.data.span, mod, IndexName::Namespace, i.name, i.is_pub, mv$(p));
),
(Enum,
p.bind( ::AST::PathBinding::make_Enum({&e}) );
- _add_item_type(mod, i.name, i.is_pub, mv$(p));
+ _add_item_type(i.data.span, mod, i.name, i.is_pub, mv$(p));
),
(Trait,
p.bind( ::AST::PathBinding::make_Trait({&e}) );
- _add_item_type(mod, i.name, i.is_pub, mv$(p));
+ _add_item_type(i.data.span, mod, i.name, i.is_pub, mv$(p));
),
(Type,
p.bind( ::AST::PathBinding::make_TypeAlias({&e}) );
- _add_item_type(mod, i.name, i.is_pub, mv$(p));
+ _add_item_type(i.data.span, mod, i.name, i.is_pub, mv$(p));
),
// - Mixed
(Struct,
p.bind( ::AST::PathBinding::make_Struct({&e}) );
// - If the struct is a tuple-like struct (or unit-like), it presents in the value namespace
if( e.m_data.is_Tuple() ) {
- _add_item_value(mod, i.name, i.is_pub, p);
+ _add_item_value(i.data.span, mod, i.name, i.is_pub, p);
}
- _add_item_type(mod, i.name, i.is_pub, mv$(p));
+ _add_item_type(i.data.span, mod, i.name, i.is_pub, mv$(p));
),
// - Values only
(Function,
p.bind( ::AST::PathBinding::make_Function({&e}) );
- _add_item_value(mod, i.name, i.is_pub, mv$(p));
+ _add_item_value(i.data.span, mod, i.name, i.is_pub, mv$(p));
),
(Static,
p.bind( ::AST::PathBinding::make_Static({&e}) );
- _add_item_value(mod, i.name, i.is_pub, mv$(p));
+ _add_item_value(i.data.span, mod, i.name, i.is_pub, mv$(p));
)
)
}
@@ -147,22 +147,22 @@ void Resolve_Index_Module_Base(AST::Module& mod)
BUG(sp, "Import was bound to struct method");
),
- (Module, _add_item(mod, IndexName::Namespace, i.name, i.is_pub, i.data.path); ),
- //(Crate, _add_item_type(mod, IndexName::Namespace, i.name, i.is_pub, i.data.path); ),
- (Enum, _add_item_type(mod, i.name, i.is_pub, i.data.path); ),
- (Trait, _add_item_type(mod, i.name, i.is_pub, i.data.path); ),
- (TypeAlias, _add_item_type(mod, i.name, i.is_pub, i.data.path); ),
+ (Module, _add_item(sp, mod, IndexName::Namespace, i.name, i.is_pub, i.data.path); ),
+ //(Crate, _add_item_type(sp, mod, IndexName::Namespace, i.name, i.is_pub, i.data.path); ),
+ (Enum, _add_item_type(sp, mod, i.name, i.is_pub, i.data.path); ),
+ (Trait, _add_item_type(sp, mod, i.name, i.is_pub, i.data.path); ),
+ (TypeAlias, _add_item_type(sp, mod, i.name, i.is_pub, i.data.path); ),
(Struct,
- _add_item_type(mod, i.name, i.is_pub, i.data.path);
+ _add_item_type(sp, mod, i.name, i.is_pub, i.data.path);
// - If the struct is a tuple-like struct, it presents in the value namespace
if( e.struct_->m_data.is_Tuple() ) {
- _add_item_value(mod, i.name, i.is_pub, i.data.path);
+ _add_item_value(sp, mod, i.name, i.is_pub, i.data.path);
}
),
- (Static , _add_item_value(mod, i.name, i.is_pub, i.data.path); ),
- (Function, _add_item_value(mod, i.name, i.is_pub, i.data.path); ),
- (EnumVar , _add_item_value(mod, i.name, i.is_pub, i.data.path); )
+ (Static , _add_item_value(sp, mod, i.name, i.is_pub, i.data.path); ),
+ (Function, _add_item_value(sp, mod, i.name, i.is_pub, i.data.path); ),
+ (EnumVar , _add_item_value(sp, mod, i.name, i.is_pub, i.data.path); )
)
}
else
@@ -236,12 +236,12 @@ void Resolve_Index_Module_Wildcard(AST::Module& mod, bool handle_pub)
}
for(const auto& vi : e.module_->m_type_items) {
if( vi.second.is_pub ) {
- _add_item_type( mod, vi.first, i.is_pub, vi.second.path, false );
+ _add_item_type( sp, mod, vi.first, i.is_pub, vi.second.path, false );
}
}
for(const auto& vi : e.module_->m_value_items) {
if( vi.second.is_pub ) {
- _add_item_value( mod, vi.first, i.is_pub, vi.second.path, false );
+ _add_item_value( sp, mod, vi.first, i.is_pub, vi.second.path, false );
}
}
),
@@ -251,10 +251,10 @@ void Resolve_Index_Module_Wildcard(AST::Module& mod, bool handle_pub)
::AST::Path p = mod.path() + ev.m_name;
p.bind( ::AST::PathBinding::make_EnumVar({e.enum_, idx}) );
if( ev.m_data.is_Struct() ) {
- _add_item_type ( mod, ev.m_name, i.is_pub, mv$(p), false );
+ _add_item_type ( sp, mod, ev.m_name, i.is_pub, mv$(p), false );
}
else {
- _add_item_value( mod, ev.m_name, i.is_pub, mv$(p), false );
+ _add_item_value( sp, mod, ev.m_name, i.is_pub, mv$(p), false );
}
idx += 1;
@@ -285,10 +285,10 @@ void Resolve_Index_Module_Wildcard(AST::Module& mod, bool handle_pub)
}
-void Resolve_Index_Module_Normalise_Path(const ::AST::Crate& crate, ::AST::Path& path)
+void Resolve_Index_Module_Normalise_Path(const ::AST::Crate& crate, const Span& sp, ::AST::Path& path)
{
const auto& info = path.m_class.as_Absolute();
- if( info.crate != "" ) TODO(Span(), "Resolve_Index_Module_Normalise_Path - Crates");
+ if( info.crate != "" ) TODO(sp, "Resolve_Index_Module_Normalise_Path - Crates");
const ::AST::Module* mod = &crate.m_root_module;
for( unsigned int i = 0; i < info.nodes.size(); i ++ )
@@ -301,13 +301,13 @@ void Resolve_Index_Module_Normalise_Path(const ::AST::Crate& crate, ::AST::Path&
if( it == mod->m_namespace_items.end() )
it = mod->m_value_items.find( node.name() );
if( it == mod->m_value_items.end() )
- ERROR(Span(), E0000, "Couldn't find final node of path " << path);
+ ERROR(sp, E0000, "Couldn't find final node of path " << path);
const auto& ie = it->second;
if( ie.is_import ) {
// TODO: Prevent infinite recursion if the user does something dumb
path = ::AST::Path(ie.path);
- Resolve_Index_Module_Normalise_Path(crate, path);
+ Resolve_Index_Module_Normalise_Path(crate, sp, path);
}
else {
// All good
@@ -316,16 +316,16 @@ void Resolve_Index_Module_Normalise_Path(const ::AST::Crate& crate, ::AST::Path&
else {
auto it = mod->m_namespace_items.find( node.name() );
if( it == mod->m_namespace_items.end() )
- ERROR(Span(), E0000, "Couldn't find node " << i << " of path " << path);
+ ERROR(sp, E0000, "Couldn't find node " << i << " of path " << path);
const auto& ie = it->second;
if( ie.is_import ) {
- TODO(Span(), "Replace imports");
+ TODO(sp, "Replace imports");
}
else {
TU_MATCH_DEF(::AST::PathBinding, (ie.path.binding()), (e),
(
- BUG(Span(), "Path " << path << " pointed to non-module " << ie.path);
+ BUG(sp, "Path " << path << " pointed to non-module " << ie.path);
),
(Module,
mod = e.module_;
@@ -339,24 +339,24 @@ void Resolve_Index_Module_Normalise_Path(const ::AST::Crate& crate, ::AST::Path&
}
}
}
-void Resolve_Index_Module_Normalise(const ::AST::Crate& crate, ::AST::Module& mod)
+void Resolve_Index_Module_Normalise(const ::AST::Crate& crate, const Span& mod_span, ::AST::Module& mod)
{
TRACE_FUNCTION_F("mod = " << mod.path());
for( auto& item : mod.items() )
{
TU_IFLET(AST::Item, item.data, Module, e,
- Resolve_Index_Module_Normalise(crate, e);
+ Resolve_Index_Module_Normalise(crate, item.data.span, e);
)
}
for( auto& ent : mod.m_namespace_items ) {
- Resolve_Index_Module_Normalise_Path(crate, ent.second.path);
+ Resolve_Index_Module_Normalise_Path(crate, mod_span, ent.second.path);
}
for( auto& ent : mod.m_type_items ) {
- Resolve_Index_Module_Normalise_Path(crate, ent.second.path);
+ Resolve_Index_Module_Normalise_Path(crate, mod_span, ent.second.path);
}
for( auto& ent : mod.m_value_items ) {
- Resolve_Index_Module_Normalise_Path(crate, ent.second.path);
+ Resolve_Index_Module_Normalise_Path(crate, mod_span, ent.second.path);
}
}
@@ -370,5 +370,5 @@ void Resolve_Index(AST::Crate& crate)
Resolve_Index_Module_Wildcard(crate.m_root_module, false);
// - Normalise the index (ensuring all paths point directly to the item)
- Resolve_Index_Module_Normalise(crate, crate.m_root_module);
+ Resolve_Index_Module_Normalise(crate, Span(), crate.m_root_module);
}