diff options
| author | John Hodge <tpg@mutabah.net> | 2016-03-16 14:12:41 +0800 | 
|---|---|---|
| committer | John Hodge <tpg@mutabah.net> | 2016-03-16 14:12:41 +0800 | 
| commit | 967a2fd0b278c3e8f19bf8fd189304cb36000acf (patch) | |
| tree | 489405e4a2a0c2cbfbe10ff137af70b61ce299e5 | |
| parent | 124cf9fc5fb6c0b7f70ef94382efd5190019edac (diff) | |
| download | mrust-967a2fd0b278c3e8f19bf8fd189304cb36000acf.tar.gz | |
Expand - Attributes on enum variants and match arms
| -rw-r--r-- | src/expand/mod.cpp | 27 | ||||
| -rw-r--r-- | src/include/synext.hpp | 5 | ||||
| -rw-r--r-- | src/parse/root.cpp | 2 | 
3 files changed, 28 insertions, 6 deletions
| diff --git a/src/expand/mod.cpp b/src/expand/mod.cpp index 0c9fb487..e367f8ce 100644 --- a/src/expand/mod.cpp +++ b/src/expand/mod.cpp @@ -332,12 +332,22 @@ struct CExpandExpr:          this->visit_nodelete(node, node.m_val);          for(auto& arm : node.m_arms)          { -            // TODO: Attributes on match arms (is it only #[cfg] that's allowed?) +            Expand_Attrs(arm.m_attrs, stage_pre (is_early),  [&](const auto& d, const auto& a){ d.handle(a, crate,  arm); }); +            if( arm.m_patterns.size() == 0 ) +                continue ;              for(auto& pat : arm.m_patterns) {                  Expand_Pattern(is_early, crate, modstack, this->cur_mod(),  pat);              }              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); }); +        } +        // Prune deleted arms +        for(auto it = node.m_arms.begin(); it != node.m_arms.end(); ) { +            if( it->m_patterns.size() == 0 ) +                it = node.m_arms.erase(it); +            else +                ++ it;          }      }      void visit(::AST::ExprNode_If& node) override { @@ -479,7 +489,18 @@ void Expand_Mod(bool is_early, ::AST::Crate& crate, LList<const AST::Module*> mo              }              ),          (Enum, -            // TODO: Enum variants +            for(auto& var : e.e.variants()) { +                Expand_Attrs(var.m_attrs, stage_pre (is_early),  [&](const auto& d, const auto& a){ d.handle(a, crate, var); }); +                for(auto& ty : var.m_sub_types) { +                    Expand_Type(is_early, crate, modstack, mod,  ty); +                } +                for(auto& si : var.m_fields) { +                    // TODO: Attributes on struct items +                    Expand_Type(is_early, crate, modstack, mod,  si.data); +                } +                Expand_Expr(is_early, crate, modstack,  var.m_value); +                Expand_Attrs(var.m_attrs, stage_post(is_early),  [&](const auto& d, const auto& a){ d.handle(a, crate, var); }); +            }              ),          (Trait,              // TODO: Trait definition @@ -515,8 +536,6 @@ void Expand_Mod(bool is_early, ::AST::Crate& crate, LList<const AST::Module*> mo      for( const auto& mi: mod.macro_imports_res() )          DEBUG("- Imports '" << mi.name << "'"); - -    // 3. Post-recurse macros (everything else)  }  void Expand(::AST::Crate& crate)  { diff --git a/src/include/synext.hpp b/src/include/synext.hpp index 58b4f608..f33b7059 100644 --- a/src/include/synext.hpp +++ b/src/include/synext.hpp @@ -15,6 +15,7 @@ namespace AST {  //    class StructItem;      typedef Named<::TypeRef>  StructItem; +    class EnumVariant;      class Module;      class Item; @@ -49,8 +50,10 @@ public:      virtual void    handle(const AST::MetaItem& mi, AST::Crate& crate) const {}      virtual void    handle(const AST::MetaItem& mi, AST::Crate& crate, AST::MacroInvocation& mac) const {}      virtual void    handle(const AST::MetaItem& mi, AST::Crate& crate, const AST::Path& path, AST::Module& mod, AST::Item&i) const {} -    // NOTE: To delete, set the type to Invalid +    // NOTE: To delete, clear the name      virtual void    handle(const AST::MetaItem& mi, AST::Crate& crate, ::AST::StructItem& si) const {} +    // NOTE: To delete, clear the name +    virtual void    handle(const AST::MetaItem& mi, AST::Crate& crate, ::AST::EnumVariant& ev) const {}      virtual void    handle(const AST::MetaItem& mi, AST::Crate& crate, ::std::unique_ptr<AST::ExprNode>& expr) const {}      // NOTE: To delete, clear the patterns vector diff --git a/src/parse/root.cpp b/src/parse/root.cpp index 91f68867..b15f64ff 100644 --- a/src/parse/root.cpp +++ b/src/parse/root.cpp @@ -771,7 +771,7 @@ AST::Enum Parse_EnumDef(TokenStream& lex, AST::Module& mod, const AST::MetaItems                  GET_CHECK_TOK(tok, lex, TOK_COLON);
                  auto ty = Parse_Type(lex);
                  // TODO: Field attributes
 -                fields.push_back( ::AST::Named<TypeRef>(mv$(name), mv$(ty), true) );
 +                fields.push_back( ::AST::StructItem(mv$(name), mv$(ty), true) );
              } while( GET_TOK(tok, lex) == TOK_COMMA );
              CHECK_TOK(tok, TOK_BRACE_CLOSE);
              GET_TOK(tok, lex);
 | 
