From 124cf9fc5fb6c0b7f70ef94382efd5190019edac Mon Sep 17 00:00:00 2001 From: John Hodge Date: Tue, 15 Mar 2016 21:32:48 +0800 Subject: Expand - More attribute handling --- src/ast/ast.hpp | 2 ++ src/ast/expr.cpp | 2 +- src/ast/expr.hpp | 28 ++++++++++++++-------------- src/expand/mod.cpp | 11 +++++++++-- src/include/synext.hpp | 23 ++++++++++++----------- src/parse/expr.cpp | 4 ++-- 6 files changed, 40 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/ast/ast.hpp b/src/ast/ast.hpp index ed6ad07b..c05e7aa4 100644 --- a/src/ast/ast.hpp +++ b/src/ast/ast.hpp @@ -44,6 +44,7 @@ enum eItemType }; typedef Named StructItem; + class Crate; class TypeAlias: @@ -321,6 +322,7 @@ class Impl: { ImplDef m_def; + //NamedList m_items; NamedList m_types; NamedList m_functions; NamedList m_statics; diff --git a/src/ast/expr.cpp b/src/ast/expr.cpp index 104c6094..0c40c741 100644 --- a/src/ast/expr.cpp +++ b/src/ast/expr.cpp @@ -237,7 +237,7 @@ NODE(ExprNode_Loop, { //os << "LOOP [" << m_label << "] " << m_pattern << " in/= " << m_cond << " " << m_code; }) -SERIALISE_TYPE_A(ExprNode_Match::Arm::, "ExprNode_Match_Arm", { +SERIALISE_TYPE_A(ExprNode_Match_Arm::, "ExprNode_Match_Arm", { s.item(m_patterns); s.item(m_cond); s.item(m_code); diff --git a/src/ast/expr.hpp b/src/ast/expr.hpp index 214be267..19b7cddc 100644 --- a/src/ast/expr.hpp +++ b/src/ast/expr.hpp @@ -236,26 +236,26 @@ struct ExprNode_Loop: NODE_METHODS(); }; -struct ExprNode_Match: - public ExprNode +struct ExprNode_Match_Arm: + public Serialisable { - struct Arm: - public Serialisable - { - MetaItems m_attrs; - ::std::vector m_patterns; - unique_ptr m_cond; - - unique_ptr m_code; + MetaItems m_attrs; + ::std::vector m_patterns; + unique_ptr m_cond; - SERIALISABLE_PROTOTYPES(); - }; + unique_ptr m_code; + + SERIALISABLE_PROTOTYPES(); +}; +struct ExprNode_Match: + public ExprNode +{ unique_ptr m_val; - ::std::vector m_arms; + ::std::vector m_arms; ExprNode_Match() {} - ExprNode_Match(unique_ptr val, ::std::vector arms): + ExprNode_Match(unique_ptr val, ::std::vector arms): m_val( ::std::move(val) ), m_arms( ::std::move(arms) ) { diff --git a/src/expand/mod.cpp b/src/expand/mod.cpp index 2f936f1f..0c9fb487 100644 --- a/src/expand/mod.cpp +++ b/src/expand/mod.cpp @@ -179,7 +179,10 @@ void Expand_Type(bool is_early, ::AST::Crate& crate, LList m (Primitive, ), (Function, - TODO(ty.span(), "Expand function type " << ty); + Type_Function& tf = e.info; + Expand_Type(is_early, crate, modstack, mod, *tf.m_rettype); + for(auto& st : tf.m_arg_types) + Expand_Type(is_early, crate, modstack, mod, st); ), (Tuple, for(auto& st : e.inner_types) @@ -470,7 +473,10 @@ void Expand_Mod(bool is_early, ::AST::Crate& crate, LList mo ), (Struct, - // TODO: Struct items + for(auto& fld : e.e.fields()) { + // TODO: Attributes on struct items + Expand_Type(is_early, crate, modstack, mod, fld.data); + } ), (Enum, // TODO: Enum variants @@ -504,6 +510,7 @@ void Expand_Mod(bool is_early, ::AST::Crate& crate, LList mo for( auto& i : mod.impls() ) { DEBUG("- " << i); + // TODO: Expand impls } for( const auto& mi: mod.macro_imports_res() ) diff --git a/src/include/synext.hpp b/src/include/synext.hpp index aa72e985..58b4f608 100644 --- a/src/include/synext.hpp +++ b/src/include/synext.hpp @@ -7,16 +7,21 @@ #include "../ast/item.hpp" #include +class TypeRef; namespace AST { class Crate; class MetaItem; class Path; + +// class StructItem; + typedef Named<::TypeRef> StructItem; class Module; class Item; - class ExprNode; class Expr; + class ExprNode; + class ExprNode_Match_Arm; class MacroInvocation; } @@ -44,16 +49,12 @@ 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 {} - virtual void handle(const AST::MetaItem& mi, AST::Crate& crate, ::std::unique_ptr& expr) const {}; -}; - -enum class MacroPosition -{ - Item, - Stmt, - Expr, - Type, - Pattern, + // NOTE: To delete, set the type to Invalid + virtual void handle(const AST::MetaItem& mi, AST::Crate& crate, ::AST::StructItem& si) const {} + + virtual void handle(const AST::MetaItem& mi, AST::Crate& crate, ::std::unique_ptr& expr) const {} + // NOTE: To delete, clear the patterns vector + virtual void handle(const AST::MetaItem& mi, AST::Crate& crate, ::AST::ExprNode_Match_Arm& expr) const {} }; class ExpandProcMacro diff --git a/src/parse/expr.cpp b/src/parse/expr.cpp index ee5698e8..58c82a0b 100644 --- a/src/parse/expr.cpp +++ b/src/parse/expr.cpp @@ -340,12 +340,12 @@ ExprNodeP Parse_Expr_Match(TokenStream& lex) //ASSERT(lex, !CHECK_PARSE_FLAG(lex, disallow_struct_literal) ); GET_CHECK_TOK(tok, lex, TOK_BRACE_OPEN); - ::std::vector< AST::ExprNode_Match::Arm > arms; + ::std::vector< AST::ExprNode_Match_Arm > arms; do { if( GET_TOK(tok, lex) == TOK_BRACE_CLOSE ) break; lex.putback(tok); - AST::ExprNode_Match::Arm arm; + AST::ExprNode_Match_Arm arm; ::AST::MetaItems arm_attrs; while( LOOK_AHEAD(lex) == TOK_ATTR_OPEN ) { -- cgit v1.2.3