diff options
author | John Hodge <tpg@ucc.asn.au> | 2019-10-06 15:21:42 +0800 |
---|---|---|
committer | John Hodge <tpg@ucc.asn.au> | 2019-10-06 15:21:42 +0800 |
commit | 16bd8829c108000e0d52d76329b88ab9e6a34e12 (patch) | |
tree | 12ebefa87f9c2b16f25dbc6988706383caff1bc1 | |
parent | a110ad4d5ea36b33ec4e0045513baf952f297f6f (diff) | |
download | mrust-16bd8829c108000e0d52d76329b88ab9e6a34e12.tar.gz |
Expand - Hand attributes to item attribute handlers
-rw-r--r-- | src/expand/cfg.cpp | 2 | ||||
-rw-r--r-- | src/expand/crate_tags.cpp | 2 | ||||
-rw-r--r-- | src/expand/derive.cpp | 2 | ||||
-rw-r--r-- | src/expand/lang_item.cpp | 8 | ||||
-rw-r--r-- | src/expand/macro_rules.cpp | 6 | ||||
-rw-r--r-- | src/expand/mod.cpp | 5 | ||||
-rw-r--r-- | src/expand/proc_macro.cpp | 2 | ||||
-rw-r--r-- | src/expand/std_prelude.cpp | 4 | ||||
-rw-r--r-- | src/expand/test.cpp | 6 | ||||
-rw-r--r-- | src/include/synext_decorator.hpp | 3 |
10 files changed, 21 insertions, 19 deletions
diff --git a/src/expand/cfg.cpp b/src/expand/cfg.cpp index 7e922779..3475b87b 100644 --- a/src/expand/cfg.cpp +++ b/src/expand/cfg.cpp @@ -122,7 +122,7 @@ class CCfgHandler: crate.m_root_module.items().clear(); } } - void handle(const Span& sp, const AST::Attribute& mi, ::AST::Crate& crate, const AST::Path& path, AST::Module& mod, AST::Item&i) const override { + void handle(const Span& sp, const AST::Attribute& mi, ::AST::Crate& crate, const AST::Path& path, AST::Module& mod, slice<const AST::Attribute> attrs, AST::Item&i) const override { TRACE_FUNCTION_FR("#[cfg] item - " << mi, (i.is_None() ? "Deleted" : "")); if( check_cfg(sp, mi) ) { // Leave diff --git a/src/expand/crate_tags.cpp b/src/expand/crate_tags.cpp index 1a2abf83..849ec459 100644 --- a/src/expand/crate_tags.cpp +++ b/src/expand/crate_tags.cpp @@ -63,7 +63,7 @@ public: crate.m_lang_items.insert(::std::make_pair( "mrustc-allocator", AST::Path("",{}) )); } - void handle(const Span& sp, const AST::Attribute& mi, ::AST::Crate& crate, const AST::Path& path, AST::Module& mod, AST::Item&i) const override { + void handle(const Span& sp, const AST::Attribute& mi, ::AST::Crate& crate, const AST::Path& path, AST::Module& mod, slice<const AST::Attribute> attrs, AST::Item&i) const override { if( ! i.is_Function() ) { ERROR(sp, E0000, "#[allocator] can only be put on functions and the crate - found on " << i.tag_str()); } diff --git a/src/expand/derive.cpp b/src/expand/derive.cpp index d92cbe79..f67a761d 100644 --- a/src/expand/derive.cpp +++ b/src/expand/derive.cpp @@ -2184,7 +2184,7 @@ class Decorator_Derive: { public: AttrStage stage() const override { return AttrStage::Post; } - void handle(const Span& sp, const AST::Attribute& attr, ::AST::Crate& crate, const AST::Path& path, AST::Module& mod, AST::Item& i) const override + void handle(const Span& sp, const AST::Attribute& attr, ::AST::Crate& crate, const AST::Path& path, AST::Module& mod, slice<const AST::Attribute> attrs, AST::Item& i) const override { TU_MATCH_DEF(::AST::Item, (i), (e), ( diff --git a/src/expand/lang_item.cpp b/src/expand/lang_item.cpp index 035bd5bd..328bce9c 100644 --- a/src/expand/lang_item.cpp +++ b/src/expand/lang_item.cpp @@ -173,7 +173,7 @@ class Decorator_LangItem: { public: AttrStage stage() const override { return AttrStage::Post; } - void handle(const Span& sp, const AST::Attribute& attr, AST::Crate& crate, const AST::Path& path, AST::Module& mod, AST::Item& i) const override + void handle(const Span& sp, const AST::Attribute& attr, AST::Crate& crate, const AST::Path& path, AST::Module& mod, slice<const AST::Attribute> attrs, AST::Item& i) const override { TU_MATCH_DEF(::AST::Item, (i), (e), ( @@ -250,7 +250,7 @@ class Decorator_Main: { public: AttrStage stage() const override { return AttrStage::Post; } - void handle(const Span& sp, const AST::Attribute& attr, AST::Crate& crate, const AST::Path& path, AST::Module& mod, AST::Item& i) const override + void handle(const Span& sp, const AST::Attribute& attr, AST::Crate& crate, const AST::Path& path, AST::Module& mod, slice<const AST::Attribute> attrs, AST::Item& i) const override { if( i.is_None() ) { // Ignore. @@ -274,7 +274,7 @@ class Decorator_Start: { public: AttrStage stage() const override { return AttrStage::Post; } - void handle(const Span& sp, const AST::Attribute& attr, AST::Crate& crate, const AST::Path& path, AST::Module& mod, AST::Item& i) const override + void handle(const Span& sp, const AST::Attribute& attr, AST::Crate& crate, const AST::Path& path, AST::Module& mod, slice<const AST::Attribute> attrs, AST::Item& i) const override { TU_IFLET(::AST::Item, i, Function, e, auto rv = crate.m_lang_items.insert(::std::make_pair( ::std::string("mrustc-start"), ::AST::Path(path) )); @@ -295,7 +295,7 @@ class Decorator_PanicImplementation: { public: AttrStage stage() const override { return AttrStage::Post; } - void handle(const Span& sp, const AST::Attribute& attr, AST::Crate& crate, const AST::Path& path, AST::Module& mod, AST::Item& i) const override + void handle(const Span& sp, const AST::Attribute& attr, AST::Crate& crate, const AST::Path& path, AST::Module& mod, slice<const AST::Attribute> attrs, AST::Item& i) const override { TU_IFLET(::AST::Item, i, Function, e, auto rv = crate.m_lang_items.insert(::std::make_pair( ::std::string("mrustc-panic_implementation"), ::AST::Path(path) )); diff --git a/src/expand/macro_rules.cpp b/src/expand/macro_rules.cpp index 7a49bcf6..3b6e4efa 100644 --- a/src/expand/macro_rules.cpp +++ b/src/expand/macro_rules.cpp @@ -41,7 +41,7 @@ class CMacroUseHandler: { AttrStage stage() const override { return AttrStage::Post; } - void handle(const Span& sp, const AST::Attribute& mi, ::AST::Crate& crate, const AST::Path& path, AST::Module& mod, AST::Item& i) const override + void handle(const Span& sp, const AST::Attribute& mi, ::AST::Crate& crate, const AST::Path& path, AST::Module& mod, slice<const AST::Attribute> attrs, AST::Item& i) const override { TRACE_FUNCTION_F("path=" << path); @@ -125,7 +125,7 @@ class CMacroExportHandler: { AttrStage stage() const override { return AttrStage::Post; } - void handle(const Span& sp, const AST::Attribute& mi, ::AST::Crate& crate, const AST::Path& path, AST::Module& mod, AST::Item& i) const override + void handle(const Span& sp, const AST::Attribute& mi, ::AST::Crate& crate, const AST::Path& path, AST::Module& mod, slice<const AST::Attribute> attrs, AST::Item& i) const override { if( i.is_None() ) { } @@ -152,7 +152,7 @@ class CMacroReexportHandler: public ExpandDecorator { AttrStage stage() const override { return AttrStage::Post; } - void handle(const Span& sp, const AST::Attribute& mi, ::AST::Crate& crate, const AST::Path& path, AST::Module& mod, AST::Item& i) const override + void handle(const Span& sp, const AST::Attribute& mi, ::AST::Crate& crate, const AST::Path& path, AST::Module& mod, slice<const AST::Attribute> attrs, AST::Item& i) const override { if( !i.is_Crate() ) { ERROR(sp, E0000, "Use of #[macro_reexport] on non-crate - " << i.tag_str()); diff --git a/src/expand/mod.cpp b/src/expand/mod.cpp index 2e0d8b97..f19acda7 100644 --- a/src/expand/mod.cpp +++ b/src/expand/mod.cpp @@ -86,7 +86,8 @@ void Expand_Attrs_CfgAttr(AST::AttributeList& attrs) auto& a = *it; if( a.name() == "cfg_attr" ) { if( check_cfg(a.span(), a.items().at(0)) ) { - a = mv$(a.items().at(1)); + auto inner_attr = mv$(a.items().at(1)); + a = mv$(inner_attr); ++ it; } else { @@ -103,7 +104,7 @@ void Expand_Attrs(const ::AST::AttributeList& attrs, AttrStage stage, ::AST::Cr Expand_Attrs(attrs, stage, [&](const auto& sp, const auto& d, const auto& a){ if(!item.is_None()) { // TODO: Pass attributes _after_ this attribute - d.handle(sp, a, crate, path, mod, item/*, attrs*/); + d.handle(sp, a, crate, path, mod, slice<const AST::Attribute>(&a, &attrs.m_items.back() - &a), item); } }); } diff --git a/src/expand/proc_macro.cpp b/src/expand/proc_macro.cpp index 6914f8df..8ed0da59 100644 --- a/src/expand/proc_macro.cpp +++ b/src/expand/proc_macro.cpp @@ -35,7 +35,7 @@ class Decorator_ProcMacroDerive: { public: AttrStage stage() const override { return AttrStage::Post; } - void handle(const Span& sp, const AST::Attribute& attr, ::AST::Crate& crate, const AST::Path& path, AST::Module& mod, AST::Item& i) const override + void handle(const Span& sp, const AST::Attribute& attr, ::AST::Crate& crate, const AST::Path& path, AST::Module& mod, slice<const AST::Attribute> attrs, AST::Item& i) const override { if( i.is_None() ) return; diff --git a/src/expand/std_prelude.cpp b/src/expand/std_prelude.cpp index 52c1554c..58b56cf7 100644 --- a/src/expand/std_prelude.cpp +++ b/src/expand/std_prelude.cpp @@ -47,7 +47,7 @@ class Decorator_NoPrelude: public: AttrStage stage() const override { return AttrStage::Pre; } - void handle(const Span& sp, const AST::Attribute& mi, ::AST::Crate& crate, const AST::Path& path, AST::Module& mod, AST::Item&i) const override { + void handle(const Span& sp, const AST::Attribute& mi, ::AST::Crate& crate, const AST::Path& path, AST::Module& mod, slice<const AST::Attribute> attrs, AST::Item&i) const override { if( i.is_Module() ) { i.as_Module().m_insert_prelude = false; } @@ -63,7 +63,7 @@ class Decorator_PreludeImport: public: AttrStage stage() const override { return AttrStage::Post; } - void handle(const Span& sp, const AST::Attribute& mi, ::AST::Crate& crate, const AST::Path& path, AST::Module& mod, AST::Item&i) const override { + void handle(const Span& sp, const AST::Attribute& mi, ::AST::Crate& crate, const AST::Path& path, AST::Module& mod, slice<const AST::Attribute> attrs, AST::Item&i) const override { if( i.is_Use() ) { const auto& p = i.as_Use().entries.front().path; // TODO: Ensure that this statement is a glob (has a name of "") diff --git a/src/expand/test.cpp b/src/expand/test.cpp index cc7ddc83..eec1414d 100644 --- a/src/expand/test.cpp +++ b/src/expand/test.cpp @@ -14,7 +14,7 @@ class CTestHandler: { AttrStage stage() const override { return AttrStage::Post; } - void handle(const Span& sp, const AST::Attribute& mi, ::AST::Crate& crate, const AST::Path& path, AST::Module& mod, AST::Item&i) const override { + void handle(const Span& sp, const AST::Attribute& mi, ::AST::Crate& crate, const AST::Path& path, AST::Module& mod, slice<const AST::Attribute> attrs, AST::Item&i) const override { if( ! i.is_Function() ) { ERROR(sp, E0000, "#[test] can only be put on functions - found on " << i.tag_str()); } @@ -42,7 +42,7 @@ class CTestHandler_SP: { AttrStage stage() const override { return AttrStage::Post; } - void handle(const Span& sp, const AST::Attribute& mi, ::AST::Crate& crate, const AST::Path& path, AST::Module& mod, AST::Item&i) const override { + void handle(const Span& sp, const AST::Attribute& mi, ::AST::Crate& crate, const AST::Path& path, AST::Module& mod, slice<const AST::Attribute> attrs, AST::Item&i) const override { if( ! i.is_Function() ) { ERROR(sp, E0000, "#[should_panic] can only be put on functions - found on " << i.tag_str()); } @@ -76,7 +76,7 @@ class CTestHandler_Ignore: { AttrStage stage() const override { return AttrStage::Post; } - void handle(const Span& sp, const AST::Attribute& mi, ::AST::Crate& crate, const AST::Path& path, AST::Module& mod, AST::Item&i) const override { + void handle(const Span& sp, const AST::Attribute& mi, ::AST::Crate& crate, const AST::Path& path, AST::Module& mod, slice<const AST::Attribute> attrs, AST::Item&i) const override { if( ! i.is_Function() ) { ERROR(sp, E0000, "#[ignore] can only be put on functions - found on " << i.tag_str()); } diff --git a/src/include/synext_decorator.hpp b/src/include/synext_decorator.hpp index eaed3154..c910f6c0 100644 --- a/src/include/synext_decorator.hpp +++ b/src/include/synext_decorator.hpp @@ -12,6 +12,7 @@ #include <string> #include <memory> #include <span.hpp> +#include <slice.hpp> #include "../ast/item.hpp" #include "../ast/expr.hpp" @@ -48,7 +49,7 @@ public: virtual AttrStage stage() const = 0; virtual void handle(const Span& sp, const AST::Attribute& mi, AST::Crate& crate) const { unexpected(sp, mi, "crate"); } - virtual void handle(const Span& sp, const AST::Attribute& mi, AST::Crate& crate, const AST::Path& path, AST::Module& mod, AST::Item&i) const { unexpected(sp, mi, "item"); } + virtual void handle(const Span& sp, const AST::Attribute& mi, AST::Crate& crate, const AST::Path& path, AST::Module& mod, slice<const AST::Attribute> attrs, AST::Item&i) const { unexpected(sp, mi, "item"); } // NOTE: To delete, set the type to `_` virtual void handle(const Span& sp, const AST::Attribute& mi, AST::Crate& crate, const AST::Module& mod, AST::ImplDef& impl) const { unexpected(sp, mi, "impl"); } // NOTE: To delete, clear the name |