diff options
author | John Hodge <tpg@ucc.asn.au> | 2017-11-19 16:33:37 +0800 |
---|---|---|
committer | John Hodge <tpg@ucc.asn.au> | 2017-11-19 16:33:37 +0800 |
commit | f0671868e80330e8e6a23c51f67ab06bf535a273 (patch) | |
tree | 8209b2274de2478c6a566651926b0793ba7af19d | |
parent | 128681501534a77c371c63c9787ba23f5df3743b (diff) | |
download | mrust-f0671868e80330e8e6a23c51f67ab06bf535a273.tar.gz |
Proc Macro - Send attributes if in the list
-rw-r--r-- | src/expand/proc_macro.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/expand/proc_macro.cpp b/src/expand/proc_macro.cpp index 18d0ab3e..065e020f 100644 --- a/src/expand/proc_macro.cpp +++ b/src/expand/proc_macro.cpp @@ -205,6 +205,10 @@ public: void send_float(eCoreType ct, double v); //void send_fragment(); + bool attr_is_used(const ::std::string& n) const { + return ::std::find(m_proc_macro_desc.attributes.begin(), m_proc_macro_desc.attributes.end(), n) != m_proc_macro_desc.attributes.end(); + } + virtual Position getPosition() const override; virtual Token realGetToken() override; virtual Ident::Hygiene realGetHygiene() const override; @@ -602,7 +606,41 @@ namespace { void visit_attrs(const ::AST::MetaItems& attrs) { + for(const auto& a : attrs.m_items) + { + if( m_pmi.attr_is_used(a.name()) ) + { + m_pmi.send_symbol("#"); + m_pmi.send_symbol("["); + this->visit_meta_item(a); + m_pmi.send_symbol("]"); + } + } } + void visit_meta_item(const ::AST::MetaItem& i) + { + m_pmi.send_ident(i.name().c_str()); + if( i.has_noarg() ) { + } + else if( i.has_string() ) { + m_pmi.send_symbol("="); + m_pmi.send_string( i.string().c_str() ); + } + else { + assert(i.has_sub_items()); + m_pmi.send_symbol("("); + bool first = true; + for(const auto& si : i.items()) + { + if(!first) + m_pmi.send_symbol(","); + this->visit_meta_item(si); + first = false; + } + m_pmi.send_symbol(")"); + } + } + void visit_struct(const ::std::string& name, bool is_pub, const ::AST::Struct& str) { if( is_pub ) { |