summaryrefslogtreecommitdiff
path: root/src/expand
diff options
context:
space:
mode:
authorJohn Hodge <tpg@ucc.asn.au>2019-10-06 12:23:25 +0800
committerJohn Hodge <tpg@ucc.asn.au>2019-10-06 12:23:25 +0800
commit848aa5c4dc438aedaaf5e1146e4788a1f0c43eff (patch)
tree5cd12eb35dd3aa34a442fae516477cb630c8db31 /src/expand
parent7f1410e86893d92f80f4c299943aaad5ee4bea73 (diff)
downloadmrust-848aa5c4dc438aedaaf5e1146e4788a1f0c43eff.tar.gz
AST - Clean up location of attributes and span on mod-level items
Diffstat (limited to 'src/expand')
-rw-r--r--src/expand/derive.cpp22
-rw-r--r--src/expand/mod.cpp30
-rw-r--r--src/expand/proc_macro.cpp9
-rw-r--r--src/expand/test_harness.cpp10
4 files changed, 36 insertions, 35 deletions
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") });
}