diff options
-rw-r--r-- | src/ast/ast.cpp | 68 | ||||
-rw-r--r-- | src/ast/ast.hpp | 24 | ||||
-rw-r--r-- | src/ast/attrs.hpp | 1 | ||||
-rw-r--r-- | src/ast/crate.cpp | 18 | ||||
-rw-r--r-- | src/ast/dump.cpp | 16 | ||||
-rw-r--r-- | src/ast/item.hpp | 13 | ||||
-rw-r--r-- | src/expand/derive.cpp | 22 | ||||
-rw-r--r-- | src/expand/mod.cpp | 30 | ||||
-rw-r--r-- | src/expand/proc_macro.cpp | 9 | ||||
-rw-r--r-- | src/expand/test_harness.cpp | 10 | ||||
-rw-r--r-- | src/hir/from_ast.cpp | 40 | ||||
-rw-r--r-- | src/parse/root.cpp | 47 | ||||
-rw-r--r-- | src/parse/token.cpp | 4 | ||||
-rw-r--r-- | src/resolve/absolute.cpp | 52 | ||||
-rw-r--r-- | src/resolve/index.cpp | 24 |
15 files changed, 182 insertions, 196 deletions
diff --git a/src/ast/ast.cpp b/src/ast/ast.cpp index f1a68680..827ac2d1 100644 --- a/src/ast/ast.cpp +++ b/src/ast/ast.cpp @@ -107,18 +107,15 @@ Function Function::clone() const return rv; } -void Trait::add_type(RcString name, AttributeList attrs, TypeRef type) { - m_items.push_back( Named<Item>(mv$(name), Item::make_Type({TypeAlias(GenericParams(), mv$(type))}), true) ); - m_items.back().data.attrs = mv$(attrs); +void Trait::add_type(Span sp, RcString name, AttributeList attrs, TypeRef type) { + m_items.push_back( Named<Item>(sp, mv$(attrs), true, mv$(name), Item::make_Type({TypeAlias(GenericParams(), mv$(type))})) ); } -void Trait::add_function(RcString name, AttributeList attrs, Function fcn) { +void Trait::add_function(Span sp, RcString name, AttributeList attrs, Function fcn) { DEBUG("trait fn " << name); - m_items.push_back( Named<Item>(mv$(name), Item::make_Function({mv$(fcn)}), true) ); - m_items.back().data.attrs = mv$(attrs); + m_items.push_back( Named<Item>(sp, mv$(attrs), true, mv$(name), Item::make_Function({mv$(fcn)})) ); } -void Trait::add_static(RcString name, AttributeList attrs, Static v) { - m_items.push_back( Named<Item>(mv$(name), Item::make_Static({mv$(v)}), true) ); - m_items.back().data.attrs = mv$(attrs); +void Trait::add_static(Span sp, RcString name, AttributeList attrs, Static v) { + m_items.push_back( Named<Item>(sp, mv$(attrs), true, mv$(name), Item::make_Static({mv$(v)})) ); } void Trait::set_is_marker() { m_is_marker = true; @@ -143,7 +140,7 @@ Trait Trait::clone() const auto rv = Trait(m_params.clone(), m_supertraits); for(const auto& item : m_items) { - rv.m_items.push_back( Named<Item> { item.name, item.data.clone(), item.is_pub } ); + rv.m_items.push_back( Named<Item> { item.span, item.attrs.clone(), item.is_pub, item.name, item.data.clone() } ); } return rv; } @@ -208,21 +205,21 @@ Union Union::clone() const return os << "impl<" << impl.m_params << "> " << impl.m_trait.ent << " for " << impl.m_type << ""; } -void Impl::add_function(bool is_public, bool is_specialisable, RcString name, Function fcn) +void Impl::add_function(Span sp, AttributeList attrs, bool is_public, bool is_specialisable, RcString name, Function fcn) { DEBUG("impl fn " << name); - m_items.push_back( ImplItem { is_public, is_specialisable, mv$(name), box$( Item::make_Function(mv$(fcn)) ) } ); + m_items.push_back( ImplItem { sp, mv$(attrs), is_public, is_specialisable, mv$(name), box$( Item::make_Function(mv$(fcn)) ) } ); } -void Impl::add_type(bool is_public, bool is_specialisable, RcString name, TypeRef type) +void Impl::add_type(Span sp, AttributeList attrs, bool is_public, bool is_specialisable, RcString name, TypeRef type) { - m_items.push_back( ImplItem { is_public, is_specialisable, mv$(name), box$( Item::make_Type(TypeAlias(GenericParams(), mv$(type))) ) } ); + m_items.push_back( ImplItem { sp, mv$(attrs), is_public, is_specialisable, mv$(name), box$( Item::make_Type(TypeAlias(GenericParams(), mv$(type))) ) } ); } -void Impl::add_static(bool is_public, bool is_specialisable, RcString name, Static v) +void Impl::add_static(Span sp, AttributeList attrs, bool is_public, bool is_specialisable, RcString name, Static v) { - m_items.push_back( ImplItem { is_public, is_specialisable, mv$(name), box$( Item::make_Static(mv$(v)) ) } ); + m_items.push_back( ImplItem { sp, mv$(attrs), is_public, is_specialisable, mv$(name), box$( Item::make_Static(mv$(v)) ) } ); } void Impl::add_macro_invocation(MacroInvocation item) { - m_items.push_back( ImplItem { false, false, "", box$( Item::make_MacroInv(mv$(item)) ) } ); + m_items.push_back( ImplItem { item.span(), {}, false, false, "", box$( Item::make_MacroInv(mv$(item)) ) } ); } bool Impl::has_named_item(const RcString& name) const @@ -262,7 +259,7 @@ UseItem UseItem::clone() const void ExternBlock::add_item(Named<Item> named_item) { - ASSERT_BUG(named_item.data.span, named_item.data.is_Function() || named_item.data.is_Static() || named_item.data.is_Type(), "Incorrect item type for ExternBlock - " << named_item.data.tag_str()); + ASSERT_BUG(named_item.span, named_item.data.is_Function() || named_item.data.is_Static() || named_item.data.is_Type(), "Incorrect item type for ExternBlock - " << named_item.data.tag_str()); m_items.push_back( mv$(named_item) ); } ExternBlock ExternBlock::clone() const @@ -286,55 +283,54 @@ void Module::add_item( Named<Item> named_item ) { if( i.name == "" ) { } else { - DEBUG(m_my_path << "::" << i.name << " = " << i.data.tag_str() << ", attrs = " << i.data.attrs); + DEBUG(m_my_path << "::" << i.name << " = " << i.data.tag_str() << ", attrs = " << i.attrs); } } -void Module::add_item(bool is_pub, RcString name, Item it, AttributeList attrs) { - it.attrs = mv$(attrs); - add_item( Named<Item>( mv$(name), mv$(it), is_pub ) ); +void Module::add_item(Span sp, bool is_pub, RcString name, Item it, AttributeList attrs) { + add_item( Named<Item>( mv$(sp), mv$(attrs), is_pub, mv$(name), mv$(it) ) ); } -void Module::add_ext_crate(bool is_public, RcString ext_name, RcString imp_name, AttributeList attrs) { - this->add_item( is_public, imp_name, Item::make_Crate({mv$(ext_name)}), mv$(attrs) ); +void Module::add_ext_crate(Span sp, bool is_pub, RcString ext_name, RcString imp_name, AttributeList attrs) { + this->add_item( mv$(sp), is_pub, imp_name, Item::make_Crate({mv$(ext_name)}), mv$(attrs) ); } void Module::add_macro_invocation(MacroInvocation item) { - this->add_item( false, "", Item( mv$(item) ), ::AST::AttributeList {} ); + this->add_item( item.span(), false, "", Item( mv$(item) ), ::AST::AttributeList {} ); } void Module::add_macro(bool is_exported, RcString name, MacroRulesPtr macro) { - m_macros.push_back( Named<MacroRulesPtr>( mv$(name), mv$(macro), is_exported ) ); + m_macros.push_back( Named<MacroRulesPtr>( Span(), {}, /*is_pub=*/is_exported, mv$(name), mv$(macro) ) ); } void Module::add_macro_import(RcString name, const MacroRules& mr) { - m_macro_import_res.push_back( Named<const MacroRules*>( mv$(name), &mr, false ) ); + m_macro_import_res.push_back( Named<const MacroRules*>( Span(), /*attrs=*/{}, /*is_pub=*/false, mv$(name), &mr) ); } Item Item::clone() const { TU_MATCHA( (*this), (e), (None, - return AST::Item(e); + return Item(e); ), (MacroInv, - TODO(this->span, "Clone on Item::MacroInv"); + TODO(Span(), "Clone on Item::MacroInv"); ), (Macro, - TODO(this->span, "Clone on Item::Macro"); + TODO(Span(), "Clone on Item::Macro"); ), (Use, - return AST::Item(e.clone()); + return Item(e.clone()); ), (ExternBlock, - TODO(this->span, "Clone on Item::" << this->tag_str()); + TODO(Span(), "Clone on Item::" << this->tag_str()); ), (Impl, - TODO(this->span, "Clone on Item::Impl"); + TODO(Span(), "Clone on Item::" << this->tag_str()); ), (NegImpl, - TODO(this->span, "Clone on Item::NegImpl"); + TODO(Span(), "Clone on Item::" << this->tag_str()); ), (Module, - TODO(this->span, "Clone on Item::Module"); + TODO(Span(), "Clone on Item::" << this->tag_str()); ), (Crate, - return AST::Item(e); + return Item(e); ), (Type, return AST::Item(e.clone()); diff --git a/src/ast/ast.hpp b/src/ast/ast.hpp index a6c06e76..1f42a764 100644 --- a/src/ast/ast.hpp +++ b/src/ast/ast.hpp @@ -223,9 +223,9 @@ public: const NamedList<Item>& items() const { return m_items; } NamedList<Item>& items() { return m_items; } - void add_type(RcString name, AttributeList attrs, TypeRef type); - void add_function(RcString name, AttributeList attrs, Function fcn); - void add_static(RcString name, AttributeList attrs, Static v); + void add_type(Span sp, RcString name, AttributeList attrs, TypeRef type); + void add_function(Span sp, RcString name, AttributeList attrs, Function fcn); + void add_static(Span sp, RcString name, AttributeList attrs, Static v); void set_is_marker(); bool is_marker() const; @@ -424,6 +424,8 @@ class Impl { public: struct ImplItem { + Span sp; + AttributeList attrs; bool is_pub; // Ignored for trait impls bool is_specialisable; RcString name; @@ -446,9 +448,9 @@ public: {} Impl& operator=(Impl&&) = default; - void add_function(bool is_public, bool is_specialisable, RcString name, Function fcn); - void add_type(bool is_public, bool is_specialisable, RcString name, TypeRef type); - void add_static(bool is_public, bool is_specialisable, RcString name, Static v); + void add_function(Span sp, AttributeList attrs, bool is_public, bool is_specialisable, RcString name, Function fcn); + void add_type(Span sp, AttributeList attrs, bool is_public, bool is_specialisable, RcString name, TypeRef type); + void add_static(Span sp, AttributeList attrs, bool is_public, bool is_specialisable, RcString name, Static v); void add_macro_invocation( MacroInvocation inv ); const ImplDef& def() const { return m_def; } @@ -570,8 +572,8 @@ public: ::std::shared_ptr<AST::Module> add_anon(); void add_item(Named<Item> item); - void add_item(bool is_pub, RcString name, Item it, AttributeList attrs); - void add_ext_crate(bool is_public, RcString ext_name, RcString imp_name, AttributeList attrs); + void add_item(Span sp, bool is_pub, RcString name, Item it, AttributeList attrs); + void add_ext_crate(Span sp, bool is_pub, RcString ext_name, RcString imp_name, AttributeList attrs); void add_macro_invocation(MacroInvocation item); void add_macro(bool is_exported, RcString name, MacroRulesPtr macro); @@ -621,12 +623,8 @@ TAGGED_UNION_EX(Item, (), None, (Static, Static) ), - (, attrs(mv$(x.attrs))), (attrs = mv$(x.attrs);), + (), (), ( - public: - AttributeList attrs; - Span span; - Item clone() const; ) ); diff --git a/src/ast/attrs.hpp b/src/ast/attrs.hpp index 04328130..7a6ce864 100644 --- a/src/ast/attrs.hpp +++ b/src/ast/attrs.hpp @@ -8,6 +8,7 @@ #ifndef _AST_ATTRS_HPP_ #define _AST_ATTRS_HPP_ +#include <tagged_union.hpp> namespace AST { diff --git a/src/ast/crate.cpp b/src/ast/crate.cpp index 726a00c6..e788f6e0 100644 --- a/src/ast/crate.cpp +++ b/src/ast/crate.cpp @@ -32,12 +32,13 @@ namespace { fcn(mod); for( auto& sm : mod.items() ) { - TU_IFLET(::AST::Item, sm.data, Module, e, - if( check_item_cfg(sm.data.attrs) ) + if( auto* e = sm.data.opt_Module() ) + { + if( check_item_cfg(sm.attrs) ) { - iterate_module(e, fcn); + iterate_module(*e, fcn); } - ) + } } // TODO: What about if an anon mod has been #[cfg]-d out? // - For now, disable @@ -61,12 +62,13 @@ void Crate::load_externs() auto cb = [this](Module& mod) { for( /*const*/ auto& it : mod.items() ) { - TU_IFLET(AST::Item, it.data, Crate, c, - if( check_item_cfg(it.data.attrs) ) + if( auto* c = it.data.opt_Crate() ) + { + if( check_item_cfg(it.attrs) ) { - c.name = load_extern_crate( it.data.span, c.name.c_str() ); + c->name = load_extern_crate( it.span, c->name.c_str() ); } - ) + } } }; iterate_module(m_root_module, cb); diff --git a/src/ast/dump.cpp b/src/ast/dump.cpp index 9fb34099..4e880a76 100644 --- a/src/ast/dump.cpp +++ b/src/ast/dump.cpp @@ -653,7 +653,7 @@ void RustPrinter::handle_module(const AST::Module& mod) if( !item.data.is_Crate() ) continue ; const auto& e = item.data.as_Crate(); - print_attrs(item.data.attrs); + print_attrs(item.attrs); m_os << indent() << "extern crate \"" << e.name << "\" as " << item.name << ";\n"; } @@ -662,7 +662,7 @@ void RustPrinter::handle_module(const AST::Module& mod) if( !item.data.is_ExternBlock() ) continue ; const auto& e = item.data.as_ExternBlock(); - print_attrs(item.data.attrs); + print_attrs(item.attrs); m_os << indent() << "extern \"" << e.abi() << "\" {}\n"; } @@ -690,7 +690,7 @@ void RustPrinter::handle_module(const AST::Module& mod) m_os << "\n"; need_nl = false; } - print_attrs(item.data.attrs); + print_attrs(item.attrs); m_os << indent() << (item.is_pub ? "pub " : "") << "type " << item.name; print_params(e.params()); m_os << " = " << e.type(); @@ -705,7 +705,7 @@ void RustPrinter::handle_module(const AST::Module& mod) const auto& e = item.data.as_Struct(); m_os << "\n"; - print_attrs(item.data.attrs); + print_attrs(item.attrs); m_os << indent() << (item.is_pub ? "pub " : "") << "struct " << item.name; handle_struct(e); } @@ -716,7 +716,7 @@ void RustPrinter::handle_module(const AST::Module& mod) const auto& e = item.data.as_Enum(); m_os << "\n"; - print_attrs(item.data.attrs); + print_attrs(item.attrs); m_os << indent() << (item.is_pub ? "pub " : "") << "enum " << item.name; handle_enum(e); } @@ -727,7 +727,7 @@ void RustPrinter::handle_module(const AST::Module& mod) const auto& e = item.data.as_Trait(); m_os << "\n"; - print_attrs(item.data.attrs); + print_attrs(item.attrs); m_os << indent() << (item.is_pub ? "pub " : "") << "trait " << item.name; handle_trait(e); } @@ -741,7 +741,7 @@ void RustPrinter::handle_module(const AST::Module& mod) m_os << "\n"; need_nl = false; } - print_attrs(item.data.attrs); + print_attrs(item.attrs); m_os << indent() << (item.is_pub ? "pub " : ""); switch( e.s_class() ) { @@ -760,7 +760,7 @@ void RustPrinter::handle_module(const AST::Module& mod) const auto& e = item.data.as_Function(); m_os << "\n"; - print_attrs(item.data.attrs); + print_attrs(item.attrs); handle_function(item.is_pub, item.name, e); } diff --git a/src/ast/item.hpp b/src/ast/item.hpp index ee83a8db..a5b0b1a5 100644 --- a/src/ast/item.hpp +++ b/src/ast/item.hpp @@ -9,15 +9,18 @@ #include <string> #include <vector> +#include "attrs.hpp" namespace AST { template <typename T> struct Named { + Span span; + AttributeList attrs; + bool is_pub; RcString name; T data; - bool is_pub; Named(): is_pub(false) @@ -25,10 +28,12 @@ struct Named Named(Named&&) = default; Named(const Named&) = default; Named& operator=(Named&&) = default; - Named(RcString name, T data, bool is_pub): + Named(Span sp, AttributeList attrs, bool is_pub, RcString name, T data): + span(sp), + attrs( ::std::move(attrs) ), + is_pub( is_pub ), name( ::std::move(name) ), - data( ::std::move(data) ), - is_pub( is_pub ) + data( ::std::move(data) ) { } }; diff --git a/src/expand/derive.cpp b/src/expand/derive.cpp index 25523fa4..d92cbe79 100644 --- a/src/expand/derive.cpp +++ b/src/expand/derive.cpp @@ -393,7 +393,7 @@ class Deriver_Debug: AST::GenericParams params = get_params_with_bounds(sp, p, debug_trait, mv$(types_to_bound)); AST::Impl rv( AST::ImplDef( AST::AttributeList(), mv$(params), make_spanned(sp, debug_trait), type.clone() ) ); - rv.add_function(false, false, "fmt", mv$(fcn)); + rv.add_function(sp, {}, false, false, "fmt", mv$(fcn)); return mv$(rv); } @@ -564,7 +564,7 @@ class Deriver_PartialEq: AST::GenericParams params = get_params_with_bounds(sp, p, trait_path, mv$(types_to_bound)); AST::Impl rv( AST::ImplDef( AST::AttributeList(), mv$(params), make_spanned(sp, trait_path), type.clone() ) ); - rv.add_function(false, false, "eq", mv$(fcn)); + rv.add_function(sp, {}, false, false, "eq", mv$(fcn)); return mv$(rv); } AST::ExprNodeP compare_and_ret(Span sp, const RcString& core_name, AST::ExprNodeP v1, AST::ExprNodeP v2) const @@ -716,7 +716,7 @@ class Deriver_PartialOrd: AST::GenericParams params = get_params_with_bounds(sp, p, trait_path, mv$(types_to_bound)); AST::Impl rv( AST::ImplDef( AST::AttributeList(), mv$(params), make_spanned(sp, trait_path), type.clone() ) ); - rv.add_function(false, false, "partial_cmp", mv$(fcn)); + rv.add_function(sp, {}, false, false, "partial_cmp", mv$(fcn)); return mv$(rv); } @@ -906,7 +906,7 @@ class Deriver_Eq: AST::GenericParams params = get_params_with_bounds(sp, p, trait_path, mv$(types_to_bound)); AST::Impl rv( AST::ImplDef( AST::AttributeList(), mv$(params), make_spanned(sp, trait_path), type.clone() ) ); - rv.add_function(false, false, "assert_receiver_is_total_eq", mv$(fcn)); + rv.add_function(sp, {}, false, false, "assert_receiver_is_total_eq", mv$(fcn)); return mv$(rv); } AST::ExprNodeP assert_is_eq(const AST::Path& method_path, AST::ExprNodeP val) const { @@ -1042,7 +1042,7 @@ class Deriver_Ord: AST::GenericParams params = get_params_with_bounds(sp, p, trait_path, mv$(types_to_bound)); AST::Impl rv( AST::ImplDef( AST::AttributeList(), mv$(params), make_spanned(sp, trait_path), type.clone() ) ); - rv.add_function(false, false, "cmp", mv$(fcn)); + rv.add_function(sp, {}, false, false, "cmp", mv$(fcn)); return mv$(rv); } @@ -1225,7 +1225,7 @@ class Deriver_Clone: AST::GenericParams params = get_params_with_bounds(sp, p, trait_path, mv$(types_to_bound)); AST::Impl rv( AST::ImplDef( AST::AttributeList(), mv$(params), make_spanned(sp, trait_path), type.clone() ) ); - rv.add_function(false, false, "clone", mv$(fcn)); + rv.add_function(sp, {}, false, false, "clone", mv$(fcn)); return mv$(rv); } AST::ExprNodeP clone_val_ref(const RcString& core_name, AST::ExprNodeP val) const { @@ -1425,7 +1425,7 @@ class Deriver_Default: AST::GenericParams params = get_params_with_bounds(sp, p, trait_path, mv$(types_to_bound)); AST::Impl rv( AST::ImplDef( AST::AttributeList(), mv$(params), make_spanned(sp, trait_path), type.clone() ) ); - rv.add_function(false, false, "default", mv$(fcn)); + rv.add_function(sp, {}, false, false, "default", mv$(fcn)); return mv$(rv); } AST::ExprNodeP default_call(const RcString& core_name) const { @@ -1511,7 +1511,7 @@ class Deriver_Hash: AST::GenericParams params = get_params_with_bounds(sp, p, trait_path, mv$(types_to_bound)); AST::Impl rv( AST::ImplDef( AST::AttributeList(), mv$(params), make_spanned(sp, trait_path), type.clone() ) ); - rv.add_function(false, false, "hash", mv$(fcn)); + rv.add_function(sp, {}, false, false, "hash", mv$(fcn)); return mv$(rv); } AST::ExprNodeP hash_val_ref(const RcString& core_name, AST::ExprNodeP val) const { @@ -1657,7 +1657,7 @@ class Deriver_RustcEncodable: AST::GenericParams params = get_params_with_bounds(sp, p, trait_path, mv$(types_to_bound)); AST::Impl rv( AST::ImplDef( AST::AttributeList(), mv$(params), make_spanned(sp, trait_path), type.clone() ) ); - rv.add_function(false, false, "encode", mv$(fcn)); + rv.add_function(sp, {}, false, false, "encode", mv$(fcn)); return mv$(rv); } AST::ExprNodeP enc_val_direct(AST::ExprNodeP val) const { @@ -1887,7 +1887,7 @@ class Deriver_RustcDecodable: AST::GenericParams params = get_params_with_bounds(sp, p, trait_path, mv$(types_to_bound)); AST::Impl rv( AST::ImplDef( AST::AttributeList(), mv$(params), make_spanned(sp, trait_path), type.clone() ) ); - rv.add_function(false, false, "decode", mv$(fcn)); + rv.add_function(sp, {}, false, false, "decode", mv$(fcn)); return mv$(rv); } AST::ExprNodeP dec_val() const { @@ -2135,7 +2135,7 @@ static void derive_item(const Span& sp, const AST::Crate& crate, AST::Module& mo DEBUG("- " << trait.name()); auto dp = find_impl(trait.name()); if( dp ) { - mod.add_item(false, "", dp->handle_item(sp, opts, params, type, item), {} ); + mod.add_item(sp, false, "", dp->handle_item(sp, opts, params, type, item), {} ); continue ; } diff --git a/src/expand/mod.cpp b/src/expand/mod.cpp index d9a19b2c..41308611 100644 --- a/src/expand/mod.cpp +++ b/src/expand/mod.cpp @@ -976,13 +976,13 @@ void Expand_Impl(::AST::Crate& crate, LList<const AST::Module*> modstack, ::AST: for( unsigned int idx = 0; idx < impl.items().size(); idx ++ ) { auto& i = impl.items()[idx]; - DEBUG(" - " << i.name << " :: " << i.data->attrs); + DEBUG(" - " << i.name << " :: " << i.attrs); // TODO: Make a path from the impl definition? Requires having the impl def resolved to be correct // - Does it? the namespace is essentially the same. There may be issues with wherever the path is used though //::AST::Path path = modpath + i.name; - auto attrs = mv$(i.data->attrs); + auto attrs = mv$(i.attrs); Expand_Attrs(attrs, AttrStage::Pre, crate, AST::Path(), mod, *i.data); TU_MATCH_DEF(AST::Item, (*i.data), (e), @@ -1037,8 +1037,8 @@ void Expand_Impl(::AST::Crate& crate, LList<const AST::Module*> modstack, ::AST: auto& i = impl.items()[idx]; Expand_Attrs(attrs, AttrStage::Post, crate, AST::Path(), mod, *i.data); // TODO: How would this be populated? It got moved out? - if( i.data->attrs.m_items.size() == 0 ) - i.data->attrs = mv$(attrs); + if( i.attrs.m_items.size() == 0 ) + i.attrs = mv$(attrs); } } @@ -1085,7 +1085,7 @@ void Expand_Mod(::AST::Crate& crate, LList<const AST::Module*> modstack, ::AST:: if( crate.m_prelude_path != AST::Path() ) { if( mod.m_insert_prelude && ! mod.is_anon() ) { - mod.add_item(false, "", ::AST::UseItem { Span(), ::make_vec1(::AST::UseItem::Ent { Span(), crate.m_prelude_path, "" }) }, {}); + mod.add_item(Span(), false, "", ::AST::UseItem { Span(), ::make_vec1(::AST::UseItem::Ent { Span(), crate.m_prelude_path, "" }) }, {}); } } @@ -1094,10 +1094,10 @@ void Expand_Mod(::AST::Crate& crate, LList<const AST::Module*> modstack, ::AST:: { auto& i = mod.items()[idx]; - DEBUG("- " << modpath << "::" << i.name << " (" << ::AST::Item::tag_to_str(i.data.tag()) << ") :: " << i.data.attrs); + DEBUG("- " << modpath << "::" << i.name << " (" << ::AST::Item::tag_to_str(i.data.tag()) << ") :: " << i.attrs); ::AST::Path path = modpath + i.name; - auto attrs = mv$(i.data.attrs); + auto attrs = mv$(i.attrs); Expand_Attrs(attrs, AttrStage::Pre, crate, path, mod, i.data); auto dat = mv$(i.data); @@ -1159,7 +1159,7 @@ void Expand_Mod(::AST::Crate& crate, LList<const AST::Module*> modstack, ::AST:: // Can't recurse into an `extern crate` if(crate.m_extern_crates.count(e.name) == 0) { - e.name = crate.load_extern_crate( i.data.span, e.name ); + e.name = crate.load_extern_crate( i.span, e.name ); } } @@ -1257,7 +1257,7 @@ void Expand_Mod(::AST::Crate& crate, LList<const AST::Module*> modstack, ::AST:: { auto& ti = trait_items[idx]; DEBUG(" - " << ti.name << " " << ti.data.tag_str()); - auto attrs = mv$(ti.data.attrs); + auto attrs = mv$(ti.attrs); Expand_Attrs(attrs, AttrStage::Pre, crate, AST::Path(), mod, ti.data); TU_MATCH_DEF(AST::Item, (ti.data), (e), @@ -1312,8 +1312,8 @@ void Expand_Mod(::AST::Crate& crate, LList<const AST::Module*> modstack, ::AST:: auto& ti = trait_items[idx]; Expand_Attrs(attrs, AttrStage::Post, crate, AST::Path(), mod, ti.data); - if( ti.data.attrs.m_items.size() == 0 ) - ti.data.attrs = mv$(attrs); + if( ti.attrs.m_items.size() == 0 ) + ti.attrs = mv$(attrs); } } } @@ -1344,8 +1344,8 @@ void Expand_Mod(::AST::Crate& crate, LList<const AST::Module*> modstack, ::AST:: i.data = mv$(dat); } // TODO: When would this _not_ be empty? - if( i.data.attrs.m_items.size() == 0 ) - i.data.attrs = mv$(attrs); + if( i.attrs.m_items.size() == 0 ) + i.attrs = mv$(attrs); } } @@ -1408,7 +1408,7 @@ void Expand(::AST::Crate& crate) crate.m_extern_crates.at("std").with_all_macros([&](const auto& name, const auto& mac) { crate.m_root_module.add_macro_import( name, mac ); }); - crate.m_root_module.add_ext_crate(false, "std", "std", ::AST::AttributeList {}); + crate.m_root_module.add_ext_crate(Span(), /*is_pub=*/false, "std", "std", /*attrs=*/{}); break; case ::AST::Crate::LOAD_CORE: if( crate.m_prelude_path == AST::Path() ) @@ -1416,7 +1416,7 @@ void Expand(::AST::Crate& crate) crate.m_extern_crates.at("core").with_all_macros([&](const auto& name, const auto& mac) { crate.m_root_module.add_macro_import( name, mac ); }); - crate.m_root_module.add_ext_crate(false, "core", "core", ::AST::AttributeList {}); + crate.m_root_module.add_ext_crate(Span(), /*is_pub=*/false, "core", "core", /*attrs=*/{}); break; case ::AST::Crate::LOAD_NONE: break; diff --git a/src/expand/proc_macro.cpp b/src/expand/proc_macro.cpp index fa515702..6914f8df 100644 --- a/src/expand/proc_macro.cpp +++ b/src/expand/proc_macro.cpp @@ -121,12 +121,12 @@ void Expand_ProcMacro(::AST::Crate& crate) auto newmod = ::AST::Module { ::AST::Path("", { ::AST::PathNode("proc_macro#") }) }; // - TODO: These need to be loaded too. // > They don't actually need to exist here, just be loaded (and use absolute paths) - newmod.add_ext_crate(false, "proc_macro", "proc_macro", {}); + newmod.add_ext_crate(Span(), false, "proc_macro", "proc_macro", {}); - newmod.add_item(false, "main", mv$(main_fn), {}); - newmod.add_item(false, "MACROS", mv$(tests_list), {}); + newmod.add_item(Span(), false, "main", mv$(main_fn), {}); + newmod.add_item(Span(), false, "MACROS", mv$(tests_list), {}); - crate.m_root_module.add_item(false, "proc_macro#", mv$(newmod), {}); + crate.m_root_module.add_item(Span(), false, "proc_macro#", mv$(newmod), {}); crate.m_lang_items["mrustc-main"] = ::AST::Path("", { AST::PathNode("proc_macro#"), AST::PathNode("main") }); } @@ -757,6 +757,7 @@ namespace { if( !pmi.check_good() ) return ::std::unique_ptr<TokenStream>(); // 2. Feed item as a token stream. + // TODO: Get attributes from the caller, filter based on the macro's options then pass to the child. Visitor(sp, pmi).visit_struct(item_name, false, i); pmi.send_done(); // 3. Return boxed invocation instance diff --git a/src/expand/test_harness.cpp b/src/expand/test_harness.cpp index 36b60632..456f90e4 100644 --- a/src/expand/test_harness.cpp +++ b/src/expand/test_harness.cpp @@ -114,12 +114,12 @@ void Expand_TestHarness(::AST::Crate& crate) auto newmod = ::AST::Module { ::AST::Path("", { ::AST::PathNode("test#") }) }; // - TODO: These need to be loaded too. // > They don't actually need to exist here, just be loaded (and use absolute paths) - newmod.add_ext_crate(false, "std", "std", {}); - newmod.add_ext_crate(false, "test", "test", {}); + newmod.add_ext_crate(Span(), false, "std", "std", {}); + newmod.add_ext_crate(Span(), false, "test", "test", {}); - newmod.add_item(false, "main", mv$(main_fn), {}); - newmod.add_item(false, "TESTS", mv$(tests_list), {}); + newmod.add_item(Span(), false, "main", mv$(main_fn), {}); + newmod.add_item(Span(), false, "TESTS", mv$(tests_list), {}); - crate.m_root_module.add_item(false, "test#", mv$(newmod), {}); + crate.m_root_module.add_item(Span(), false, "test#", mv$(newmod), {}); crate.m_lang_items["mrustc-main"] = ::AST::Path("", { AST::PathNode("test#"), AST::PathNode("main") }); } diff --git a/src/hir/from_ast.cpp b/src/hir/from_ast.cpp index e271a809..54644806 100644 --- a/src/hir/from_ast.cpp +++ b/src/hir/from_ast.cpp @@ -1194,7 +1194,7 @@ namespace { TU_MATCH_DEF(::AST::Item, (item.data), (i), ( - BUG(item.data.span, "Encountered unexpected item type in trait"); + BUG(item.span, "Encountered unexpected item type in trait"); ), (None, // Ignore. @@ -1212,18 +1212,18 @@ namespace { { TU_MATCH(::HIR::GenericBound, (b), (be), (TypeLifetime, - ASSERT_BUG(item.data.span, be.type == ::HIR::TypeRef("Self", 0xFFFF), "Invalid lifetime bound on associated type"); + ASSERT_BUG(item.span, be.type == ::HIR::TypeRef("Self", 0xFFFF), "Invalid lifetime bound on associated type"); lifetime_bound = mv$(be.valid_for); ), (TraitBound, - ASSERT_BUG(item.data.span, be.type == ::HIR::TypeRef("Self", 0xFFFF), "Invalid trait bound on associated type"); + ASSERT_BUG(item.span, be.type == ::HIR::TypeRef("Self", 0xFFFF), "Invalid trait bound on associated type"); trait_bounds.push_back( mv$(be.trait) ); ), (Lifetime, - BUG(item.data.span, "Unexpected lifetime-lifetime bound on associated type"); + BUG(item.span, "Unexpected lifetime-lifetime bound on associated type"); ), (TypeEquality, - BUG(item.data.span, "Unexpected type equality bound on associated type"); + BUG(item.span, "Unexpected type equality bound on associated type"); ) ) } @@ -1236,7 +1236,7 @@ namespace { ), (Function, ::HIR::TypeRef self_type {"Self", 0xFFFF}; - auto fcn = LowerHIR_Function(item_path, item.data.attrs, i, self_type); + auto fcn = LowerHIR_Function(item_path, item.attrs, i, self_type); fcn.m_save_code = true; rv.m_values.insert( ::std::make_pair(item.name, ::HIR::TraitValueItem::make_Function( mv$(fcn) )) ); ), @@ -1434,7 +1434,7 @@ void _add_mod_mac_item(::HIR::Module& mod, RcString name, ::HIR::Publicity is_pu for( const auto& item : ast_mod.items() ) { - const auto& sp = item.data.span; + const auto& sp = item.span; auto item_path = ::HIR::ItemPath(path, item.name.c_str()); DEBUG(item_path << " " << item.data.tag_str()); TU_MATCH(::AST::Item, (item.data), (e), @@ -1452,7 +1452,7 @@ void _add_mod_mac_item(::HIR::Module& mod, RcString name, ::HIR::Publicity is_pu TODO(sp, "Expand ExternBlock"); } // Insert a record of the `link` attribute - for(const auto& a : item.data.attrs.m_items) + for(const auto& a : item.attrs.m_items) { if( a.name() != "link" ) continue ; @@ -1484,7 +1484,7 @@ void _add_mod_mac_item(::HIR::Module& mod, RcString name, ::HIR::Publicity is_pu // Ignore - The index is used to add `Import`s ), (Module, - _add_mod_ns_item( mod, item.name, get_pub(item.is_pub), LowerHIR_Module(e, mv$(item_path)) ); + _add_mod_ns_item( mod, item.name, get_pub(item.is_pub), LowerHIR_Module(e, mv$(item_path)) ); ), (Crate, // All 'extern crate' items should be normalised into a list in the crate root @@ -1496,7 +1496,7 @@ void _add_mod_mac_item(::HIR::Module& mod, RcString name, ::HIR::Publicity is_pu { if( !e.params().lft_params().empty() || !e.params().ty_params().empty() || !e.params().bounds().empty() ) { - ERROR(item.data.span, E0000, "Generics on extern type"); + ERROR(item.span, E0000, "Generics on extern type"); } _add_mod_ns_item(mod, item.name, get_pub(item.is_pub), ::HIR::ExternType {}); break; @@ -1513,20 +1513,20 @@ void _add_mod_mac_item(::HIR::Module& mod, RcString name, ::HIR::Publicity is_pu } else { } - _add_mod_ns_item( mod, item.name, get_pub(item.is_pub), LowerHIR_Struct(item_path, e, item.data.attrs) ); + _add_mod_ns_item( mod, item.name, get_pub(item.is_pub), LowerHIR_Struct(item_path, e, item.attrs) ); ), (Enum, - auto enm = LowerHIR_Enum(item_path, e, item.data.attrs, [&](auto name, auto str){ _add_mod_ns_item(mod, name, get_pub(item.is_pub), mv$(str)); }); + auto enm = LowerHIR_Enum(item_path, e, item.attrs, [&](auto name, auto str){ _add_mod_ns_item(mod, name, get_pub(item.is_pub), mv$(str)); }); _add_mod_ns_item( mod, item.name, get_pub(item.is_pub), mv$(enm) ); ), (Union, - _add_mod_ns_item( mod, item.name, get_pub(item.is_pub), LowerHIR_Union(item_path, e, item.data.attrs) ); + _add_mod_ns_item( mod, item.name, get_pub(item.is_pub), LowerHIR_Union(item_path, e, item.attrs) ); ), (Trait, _add_mod_ns_item( mod, item.name, get_pub(item.is_pub), LowerHIR_Trait(item_path.get_simple_path(), e) ); ), (Function, - _add_mod_val_item(mod, item.name, get_pub(item.is_pub), LowerHIR_Function(item_path, item.data.attrs, e, ::HIR::TypeRef{})); + _add_mod_val_item(mod, item.name, get_pub(item.is_pub), LowerHIR_Function(item_path, item.attrs, e, ::HIR::TypeRef{})); ), (Static, if( e.s_class() == ::AST::Static::CONST ) @@ -1660,7 +1660,7 @@ void LowerHIR_Module_Impls(const ::AST::Module& ast_mod, ::HIR::Crate& hir_crat ::HIR::ItemPath item_path(path, item.name.c_str()); TU_MATCH_DEF(::AST::Item, (*item.data), (e), ( - BUG(item.data->span, "Unexpected item type in trait impl - " << item.data->tag_str()); + BUG(item.sp, "Unexpected item type in trait impl - " << item.data->tag_str()); ), (None, ), @@ -1676,7 +1676,7 @@ void LowerHIR_Module_Impls(const ::AST::Module& ast_mod, ::HIR::Crate& hir_crat } }) ); } else { - TODO(item.data->span, "Associated statics in trait impl"); + TODO(item.sp, "Associated statics in trait impl"); } ), (Type, @@ -1685,7 +1685,7 @@ void LowerHIR_Module_Impls(const ::AST::Module& ast_mod, ::HIR::Crate& hir_crat ), (Function, DEBUG("- method " << item.name); - methods.insert( ::std::make_pair(item.name, ::HIR::TraitImpl::ImplEnt< ::HIR::Function> { item.is_specialisable, LowerHIR_Function(item_path, item.data->attrs, e, type) }) ); + methods.insert( ::std::make_pair(item.name, ::HIR::TraitImpl::ImplEnt< ::HIR::Function> { item.is_specialisable, LowerHIR_Function(item_path, item.attrs, e, type) }) ); ) ) } @@ -1738,7 +1738,7 @@ void LowerHIR_Module_Impls(const ::AST::Module& ast_mod, ::HIR::Crate& hir_crat ::HIR::ItemPath item_path(path, item.name.c_str()); TU_MATCH_DEF(::AST::Item, (*item.data), (e), ( - BUG(item.data->span, "Unexpected item type in inherent impl - " << item.data->tag_str()); + BUG(item.sp, "Unexpected item type in inherent impl - " << item.data->tag_str()); ), (None, ), @@ -1753,12 +1753,12 @@ void LowerHIR_Module_Impls(const ::AST::Module& ast_mod, ::HIR::Crate& hir_crat } }) ); } else { - TODO(item.data->span, "Associated statics in inherent impl"); + TODO(item.sp, "Associated statics in inherent impl"); } ), (Function, methods.insert( ::std::make_pair(item.name, ::HIR::TypeImpl::VisImplEnt< ::HIR::Function> { - get_pub(item.is_pub), item.is_specialisable, LowerHIR_Function(item_path, item.data->attrs, e, type) + get_pub(item.is_pub), item.is_specialisable, LowerHIR_Function(item_path, item.attrs, e, type) } ) ); ) ) diff --git a/src/parse/root.cpp b/src/parse/root.cpp index 064e127f..e81055ec 100644 --- a/src/parse/root.cpp +++ b/src/parse/root.cpp @@ -653,7 +653,7 @@ AST::Named<AST::Item> Parse_Trait_Item(TokenStream& lex) ::AST::MacroInvocation inv; if( Parse_MacroInvocation_Opt(lex, inv) ) { - return AST::Named<AST::Item>( "", AST::Item(mv$(inv)), false ); + return AST::Named<AST::Item>( lex.end_span(ps), mv$(item_attrs), false, "", AST::Item(mv$(inv)) ); } } @@ -772,8 +772,7 @@ AST::Named<AST::Item> Parse_Trait_Item(TokenStream& lex) throw ParseError::Unexpected(lex, tok); } - rv.attrs = ::std::move( item_attrs ); - return ::AST::Named<::AST::Item>( mv$(name), mv$(rv), true ); + return ::AST::Named<::AST::Item>( lex.end_span(ps), mv$(item_attrs), true, mv$(name), mv$(rv) ); } AST::Trait Parse_TraitDef(TokenStream& lex, const AST::AttributeList& meta_items) @@ -1189,7 +1188,7 @@ void Parse_Impl_Item(TokenStream& lex, AST::Impl& impl) if( Parse_MacroInvocation_Opt(lex, inv) ) { impl.add_macro_invocation( mv$(inv) ); - impl.items().back().data->attrs = mv$(item_attrs); + impl.items().back().attrs = mv$(item_attrs); return ; } } @@ -1214,8 +1213,9 @@ void Parse_Impl_Item(TokenStream& lex, AST::Impl& impl) GET_CHECK_TOK(tok, lex, TOK_IDENT); auto name = tok.istr(); GET_CHECK_TOK(tok, lex, TOK_EQUAL); - impl.add_type(is_public, is_specialisable, name, Parse_Type(lex)); + auto ty = Parse_Type(lex); GET_CHECK_TOK(tok, lex, TOK_SEMICOLON); + impl.add_type(lex.end_span(ps), mv$(item_attrs), is_public, is_specialisable, name, mv$(ty)); break; } case TOK_RWORD_UNSAFE: fn_is_unsafe = true; @@ -1235,7 +1235,7 @@ void Parse_Impl_Item(TokenStream& lex, AST::Impl& impl) GET_CHECK_TOK(tok, lex, TOK_SEMICOLON); auto i = ::AST::Static(AST::Static::CONST, mv$(ty), mv$(val)); - impl.add_static( is_public, is_specialisable, mv$(name), mv$(i) ); + impl.add_static( lex.end_span(ps), mv$(item_attrs), is_public, is_specialisable, mv$(name), mv$(i) ); break ; } else if( tok.type() == TOK_RWORD_UNSAFE ) @@ -1266,15 +1266,12 @@ void Parse_Impl_Item(TokenStream& lex, AST::Impl& impl) DEBUG("Function " << name); // - Self allowed, can't be prototype-form auto fcn = Parse_FunctionDefWithCode(lex, abi, true, fn_is_unsafe, fn_is_const); - impl.add_function(is_public, is_specialisable, mv$(name), mv$(fcn)); + impl.add_function(lex.end_span(ps), mv$(item_attrs), is_public, is_specialisable, mv$(name), mv$(fcn)); break; } default: throw ParseError::Unexpected(lex, tok); } - - impl.items().back().data->span = lex.end_span(ps); - impl.items().back().data->attrs = mv$(item_attrs); // Empty for functions } AST::ExternBlock Parse_ExternBlock(TokenStream& lex, ::std::string abi, ::AST::AttributeList& block_attrs) @@ -1305,10 +1302,7 @@ AST::ExternBlock Parse_ExternBlock(TokenStream& lex, ::std::string abi, ::AST::A auto i = ::AST::Item( Parse_FunctionDef(lex, abi, false, true, true,false) ); GET_CHECK_TOK(tok, lex, TOK_SEMICOLON); - i.attrs = mv$(meta_items); - i.span = lex.end_span(ps); - - rv.add_item( AST::Named<AST::Item> { mv$(name), mv$(i), is_public } ); + rv.add_item( AST::Named<AST::Item> { lex.end_span(ps), mv$(meta_items), is_public, mv$(name), mv$(i) } ); break; } case TOK_RWORD_STATIC: { bool is_mut = false; @@ -1323,9 +1317,7 @@ AST::ExternBlock Parse_ExternBlock(TokenStream& lex, ::std::string abi, ::AST::A GET_CHECK_TOK(tok, lex, TOK_SEMICOLON); auto i = ::AST::Item(::AST::Static( (is_mut ? ::AST::Static::MUT : ::AST::Static::STATIC), mv$(type), ::AST::Expr() )); - i.attrs = mv$(meta_items); - i.span = lex.end_span(ps); - rv.add_item( AST::Named<AST::Item> { mv$(name), mv$(i), is_public } ); + rv.add_item( AST::Named<AST::Item> { lex.end_span(ps), mv$(meta_items), is_public, mv$(name), mv$(i) } ); break; } case TOK_RWORD_TYPE: { GET_CHECK_TOK(tok, lex, TOK_IDENT); @@ -1334,9 +1326,7 @@ AST::ExternBlock Parse_ExternBlock(TokenStream& lex, ::std::string abi, ::AST::A auto sp = lex.end_span(ps); //TODO(sp, "Extern type"); auto i = ::AST::Item(::AST::TypeAlias( ::AST::GenericParams(), ::TypeRef(sp) )); - i.attrs = mv$(meta_items); - i.span = mv$(sp); - rv.add_item( AST::Named<AST::Item> { mv$(name), mv$(i), is_public } ); + rv.add_item( AST::Named<AST::Item> { mv$(sp), mv$(meta_items), is_public, mv$(name), mv$(i) } ); break; } default: throw ParseError::Unexpected(lex, tok, {TOK_RWORD_FN, TOK_RWORD_STATIC, TOK_RWORD_TYPE}); @@ -1643,7 +1633,7 @@ namespace { auto rv = tok.take_frag_item(); // Transfer new attributes onto the item for(auto& mi : meta_items.m_items) - rv.data.attrs.m_items.push_back( mv$(mi) ); + rv.attrs.m_items.push_back( mv$(mi) ); return rv; } @@ -1656,11 +1646,7 @@ namespace { ::AST::MacroInvocation inv; if( Parse_MacroInvocation_Opt(lex, inv) ) { - item_data = ::AST::Item( mv$(inv) ); - item_data.attrs = mv$(meta_items); - item_data.span = lex.end_span(ps); - - return ::AST::Named< ::AST::Item> { "", mv$(item_data), false }; + return ::AST::Named< ::AST::Item> { lex.end_span(ps), mv$(meta_items), false, "", ::AST::Item( mv$(inv) ) }; } } @@ -1849,7 +1835,7 @@ namespace { else { BUG(lex.point_span(), "Parse_Impl returned a variant other than Impl or NegImpl"); } - return ::AST::Named< ::AST::Item> { "", mv$(impl), false }; + return ::AST::Named< ::AST::Item> { Span(), {}, false, "", mv$(impl) }; } // `unsafe auto trait` case TOK_IDENT: @@ -1915,7 +1901,7 @@ namespace { break; // `impl` case TOK_RWORD_IMPL: - return ::AST::Named< ::AST::Item> { "", Parse_Impl(lex, mv$(meta_items)), false }; + return ::AST::Named< ::AST::Item> { Span(), {}, false, "", Parse_Impl(lex, mv$(meta_items)) }; // `trait` case TOK_RWORD_TRAIT: GET_CHECK_TOK(tok, lex, TOK_IDENT); @@ -2121,10 +2107,7 @@ namespace { throw ParseError::Unexpected(lex, tok); } - item_data.attrs = mv$(meta_items); - item_data.span = lex.end_span(ps); - - return ::AST::Named< ::AST::Item> { mv$(item_name), mv$(item_data), is_public }; + return ::AST::Named< ::AST::Item> { lex.end_span(ps), mv$(meta_items), is_public, mv$(item_name), mv$(item_data) }; } void Parse_Mod_Item(TokenStream& lex, AST::Module& mod, AST::AttributeList meta_items) diff --git a/src/parse/token.cpp b/src/parse/token.cpp index 73ae7d93..900108ab 100644 --- a/src/parse/token.cpp +++ b/src/parse/token.cpp @@ -110,8 +110,8 @@ Token::Token(const InterpolatedFragment& frag) case InterpolatedFragment::ITEM: { m_type = TOK_INTERPOLATED_ITEM; const auto& named = *reinterpret_cast<const AST::Named<AST::Item>*>(frag.m_ptr); - ::AST::Item item = named.data.clone(); - m_data = new AST::Named<AST::Item>( named.name, mv$(item), named.is_pub ); + auto item = named.data.clone(); + m_data = new AST::Named<AST::Item>( named.span, named.attrs.clone(), named.is_pub, named.name, mv$(item) ); break; } } } diff --git a/src/resolve/absolute.cpp b/src/resolve/absolute.cpp index d26bb699..ae094f7e 100644 --- a/src/resolve/absolute.cpp +++ b/src/resolve/absolute.cpp @@ -2030,19 +2030,19 @@ void Resolve_Absolute_ImplItems(Context& item_context, ::AST::NamedList< ::AST: TU_MATCH(AST::Item, (i.data), (e), (None, ), (MacroInv, - //BUG(i.data.span, "Resolve_Absolute_ImplItems - MacroInv"); + //BUG(i.span, "Resolve_Absolute_ImplItems - MacroInv"); ), - (ExternBlock, BUG(i.data.span, "Resolve_Absolute_ImplItems - " << i.data.tag_str());), - (Impl, BUG(i.data.span, "Resolve_Absolute_ImplItems - " << i.data.tag_str());), - (NegImpl, BUG(i.data.span, "Resolve_Absolute_ImplItems - " << i.data.tag_str());), - (Macro, BUG(i.data.span, "Resolve_Absolute_ImplItems - " << i.data.tag_str());), - (Use, BUG(i.data.span, "Resolve_Absolute_ImplItems - Use");), - (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");), - (Union , BUG(i.data.span, "Resolve_Absolute_ImplItems - Union");), + (ExternBlock, BUG(i.span, "Resolve_Absolute_ImplItems - " << i.data.tag_str());), + (Impl, BUG(i.span, "Resolve_Absolute_ImplItems - " << i.data.tag_str());), + (NegImpl, BUG(i.span, "Resolve_Absolute_ImplItems - " << i.data.tag_str());), + (Macro, BUG(i.span, "Resolve_Absolute_ImplItems - " << i.data.tag_str());), + (Use, BUG(i.span, "Resolve_Absolute_ImplItems - Use");), + (Module, BUG(i.span, "Resolve_Absolute_ImplItems - Module");), + (Crate , BUG(i.span, "Resolve_Absolute_ImplItems - Crate");), + (Enum , BUG(i.span, "Resolve_Absolute_ImplItems - Enum");), + (Trait , BUG(i.span, "Resolve_Absolute_ImplItems - Trait");), + (Struct, BUG(i.span, "Resolve_Absolute_ImplItems - Struct");), + (Union , BUG(i.span, "Resolve_Absolute_ImplItems - Union");), (Type, DEBUG("Type - " << i.name); assert( e.params().ty_params().size() == 0 ); @@ -2077,17 +2077,17 @@ void Resolve_Absolute_ImplItems(Context& item_context, ::std::vector< ::AST::Im (None, ), (MacroInv, ), - (Impl , BUG(i.data->span, "Resolve_Absolute_ImplItems - " << i.data->tag_str());), - (NegImpl, BUG(i.data->span, "Resolve_Absolute_ImplItems - " << i.data->tag_str());), - (ExternBlock, BUG(i.data->span, "Resolve_Absolute_ImplItems - " << i.data->tag_str());), - (Macro , BUG(i.data->span, "Resolve_Absolute_ImplItems - " << i.data->tag_str());), - (Use , BUG(i.data->span, "Resolve_Absolute_ImplItems - " << i.data->tag_str());), - (Module, BUG(i.data->span, "Resolve_Absolute_ImplItems - " << i.data->tag_str());), - (Crate , BUG(i.data->span, "Resolve_Absolute_ImplItems - " << i.data->tag_str());), - (Enum , BUG(i.data->span, "Resolve_Absolute_ImplItems - " << i.data->tag_str());), - (Trait , BUG(i.data->span, "Resolve_Absolute_ImplItems - " << i.data->tag_str());), - (Struct, BUG(i.data->span, "Resolve_Absolute_ImplItems - " << i.data->tag_str());), - (Union , BUG(i.data->span, "Resolve_Absolute_ImplItems - " << i.data->tag_str());), + (Impl , BUG(i.sp, "Resolve_Absolute_ImplItems - " << i.data->tag_str());), + (NegImpl, BUG(i.sp, "Resolve_Absolute_ImplItems - " << i.data->tag_str());), + (ExternBlock, BUG(i.sp, "Resolve_Absolute_ImplItems - " << i.data->tag_str());), + (Macro , BUG(i.sp, "Resolve_Absolute_ImplItems - " << i.data->tag_str());), + (Use , BUG(i.sp, "Resolve_Absolute_ImplItems - " << i.data->tag_str());), + (Module, BUG(i.sp, "Resolve_Absolute_ImplItems - " << i.data->tag_str());), + (Crate , BUG(i.sp, "Resolve_Absolute_ImplItems - " << i.data->tag_str());), + (Enum , BUG(i.sp, "Resolve_Absolute_ImplItems - " << i.data->tag_str());), + (Trait , BUG(i.sp, "Resolve_Absolute_ImplItems - " << i.data->tag_str());), + (Struct, BUG(i.sp, "Resolve_Absolute_ImplItems - " << i.data->tag_str());), + (Union , BUG(i.sp, "Resolve_Absolute_ImplItems - " << i.data->tag_str());), (Type, DEBUG("Type - " << i.name); assert( e.params().ty_params().size() == 0 ); @@ -2253,7 +2253,7 @@ void Resolve_Absolute_Mod( Context item_context, ::AST::Module& mod ) { TU_MATCH_DEF(AST::Item, (i2.data), (e2), ( - BUG(i2.data.span, "Unexpected item in ExternBlock - " << i2.data.tag_str()); + BUG(i.span, "Unexpected item in ExternBlock - " << i2.data.tag_str()); ), (None, ), @@ -2281,7 +2281,7 @@ void Resolve_Absolute_Mod( Context item_context, ::AST::Module& mod ) Resolve_Absolute_Generic(item_context, def.params()); if( e.items().size() != 0 ) { - ERROR(i.data.span, E0000, "impl Trait for .. with methods"); + ERROR(i.span, E0000, "impl Trait for .. with methods"); } item_context.pop(def.params()); @@ -2318,7 +2318,7 @@ void Resolve_Absolute_Mod( Context item_context, ::AST::Module& mod ) item_context.m_ibl_target_generics = &impl_def.params(); Resolve_Absolute_Type(item_context, impl_def.type()); if( !impl_def.trait().ent.is_valid() ) - BUG(i.data.span, "Encountered negative impl with no trait"); + BUG(i.span, "Encountered negative impl with no trait"); Resolve_Absolute_Path(item_context, impl_def.trait().sp, Context::LookupMode::Type, impl_def.trait().ent); item_context.m_ibl_target_generics = nullptr; diff --git a/src/resolve/index.cpp b/src/resolve/index.cpp index bde59da8..1511583e 100644 --- a/src/resolve/index.cpp +++ b/src/resolve/index.cpp @@ -131,28 +131,28 @@ void Resolve_Index_Module_Base(const AST::Crate& crate, AST::Module& mod) // - Types/modules only (Module, p.m_bindings.type = ::AST::PathBinding_Type::make_Module({&e}); - _add_item(i.data.span, mod, IndexName::Namespace, i.name, i.is_pub, mv$(p)); + _add_item(i.span, mod, IndexName::Namespace, i.name, i.is_pub, mv$(p)); ), (Crate, - ASSERT_BUG(i.data.span, crate.m_extern_crates.count(e.name) > 0, "Referenced crate '" << e.name << "' isn't loaded for `extern crate`"); + ASSERT_BUG(i.span, crate.m_extern_crates.count(e.name) > 0, "Referenced crate '" << e.name << "' isn't loaded for `extern crate`"); p.m_bindings.type = ::AST::PathBinding_Type::make_Crate({ &crate.m_extern_crates.at(e.name) }); - _add_item(i.data.span, mod, IndexName::Namespace, i.name, i.is_pub, mv$(p)); + _add_item(i.span, mod, IndexName::Namespace, i.name, i.is_pub, mv$(p)); ), (Enum, p.m_bindings.type = ::AST::PathBinding_Type::make_Enum({&e}); - _add_item_type(i.data.span, mod, i.name, i.is_pub, mv$(p)); + _add_item_type(i.span, mod, i.name, i.is_pub, mv$(p)); ), (Union, p.m_bindings.type = ::AST::PathBinding_Type::make_Union({&e}); - _add_item_type(i.data.span, mod, i.name, i.is_pub, mv$(p)); + _add_item_type(i.span, mod, i.name, i.is_pub, mv$(p)); ), (Trait, p.m_bindings.type = ::AST::PathBinding_Type::make_Trait({&e}); - _add_item_type(i.data.span, mod, i.name, i.is_pub, mv$(p)); + _add_item_type(i.span, mod, i.name, i.is_pub, mv$(p)); ), (Type, p.m_bindings.type = ::AST::PathBinding_Type::make_TypeAlias({&e}); - _add_item_type(i.data.span, mod, i.name, i.is_pub, mv$(p)); + _add_item_type(i.span, mod, i.name, i.is_pub, mv$(p)); ), // - Mixed (Struct, @@ -160,18 +160,18 @@ void Resolve_Index_Module_Base(const AST::Crate& crate, AST::Module& mod) // - If the struct is a tuple-like struct (or unit-like), it presents in the value namespace if( ! e.m_data.is_Struct() ) { p.m_bindings.value = ::AST::PathBinding_Value::make_Struct({&e}); - _add_item_value(i.data.span, mod, i.name, i.is_pub, p); + _add_item_value(i.span, mod, i.name, i.is_pub, p); } - _add_item_type(i.data.span, mod, i.name, i.is_pub, mv$(p)); + _add_item_type(i.span, mod, i.name, i.is_pub, mv$(p)); ), // - Values only (Function, p.m_bindings.value = ::AST::PathBinding_Value::make_Function({&e}); - _add_item_value(i.data.span, mod, i.name, i.is_pub, mv$(p)); + _add_item_value(i.span, mod, i.name, i.is_pub, mv$(p)); ), (Static, p.m_bindings.value = ::AST::PathBinding_Value::make_Static({&e}); - _add_item_value(i.data.span, mod, i.name, i.is_pub, mv$(p)); + _add_item_value(i.span, mod, i.name, i.is_pub, mv$(p)); ) ) } @@ -761,7 +761,7 @@ void Resolve_Index_Module_Normalise(const ::AST::Crate& crate, const Span& mod_s for( auto& item : mod.items() ) { TU_IFLET(AST::Item, item.data, Module, e, - Resolve_Index_Module_Normalise(crate, item.data.span, e); + Resolve_Index_Module_Normalise(crate, item.span, e); ) } |