summaryrefslogtreecommitdiff
path: root/src/expand
diff options
context:
space:
mode:
Diffstat (limited to 'src/expand')
-rw-r--r--src/expand/derive.cpp45
-rw-r--r--src/expand/mod.cpp63
2 files changed, 77 insertions, 31 deletions
diff --git a/src/expand/derive.cpp b/src/expand/derive.cpp
index 028a8d9b..0096f809 100644
--- a/src/expand/derive.cpp
+++ b/src/expand/derive.cpp
@@ -58,27 +58,34 @@ public:
// Generate code for Debug
AST::ExprNodeP node;
- node = NEWNODE(AST::ExprNode_NamedValue, AST::Path("f"));
- node = NEWNODE(AST::ExprNode_CallMethod,
- mv$(node), AST::PathNode("debug_struct",{}),
- vec$( NEWNODE(AST::ExprNode_String, name) )
- );
- for( const auto& fld : str.fields() )
- {
+ TU_MATCH(AST::StructData, (str.m_data), (e),
+ (Struct,
+ node = NEWNODE(AST::ExprNode_NamedValue, AST::Path("f"));
node = NEWNODE(AST::ExprNode_CallMethod,
- mv$(node), AST::PathNode("field",{}),
- vec$(
- NEWNODE(AST::ExprNode_String, fld.name),
- NEWNODE(AST::ExprNode_UniOp, AST::ExprNode_UniOp::REF,
- NEWNODE(AST::ExprNode_Field,
- NEWNODE(AST::ExprNode_NamedValue, AST::Path("self")),
- fld.name
- )
- )
- )
+ mv$(node), AST::PathNode("debug_struct",{}),
+ vec$( NEWNODE(AST::ExprNode_String, name) )
);
- }
- node = NEWNODE(AST::ExprNode_CallMethod, mv$(node), AST::PathNode("finish",{}), {});
+ for( const auto& fld : e.ents )
+ {
+ node = NEWNODE(AST::ExprNode_CallMethod,
+ mv$(node), AST::PathNode("field",{}),
+ vec$(
+ NEWNODE(AST::ExprNode_String, fld.m_name),
+ NEWNODE(AST::ExprNode_UniOp, AST::ExprNode_UniOp::REF,
+ NEWNODE(AST::ExprNode_Field,
+ NEWNODE(AST::ExprNode_NamedValue, AST::Path("self")),
+ fld.m_name
+ )
+ )
+ )
+ );
+ }
+ node = NEWNODE(AST::ExprNode_CallMethod, mv$(node), AST::PathNode("finish",{}), {});
+ ),
+ (Tuple,
+ assert(!"TODO: derive() debug on tuple struct");
+ )
+ )
DEBUG("node = " << *node);
diff --git a/src/expand/mod.cpp b/src/expand/mod.cpp
index e367f8ce..d7a142e9 100644
--- a/src/expand/mod.cpp
+++ b/src/expand/mod.cpp
@@ -483,22 +483,61 @@ void Expand_Mod(bool is_early, ::AST::Crate& crate, LList<const AST::Module*> mo
),
(Struct,
- for(auto& fld : e.e.fields()) {
- // TODO: Attributes on struct items
- Expand_Type(is_early, crate, modstack, mod, fld.data);
- }
+ TU_MATCH(AST::StructData, (e.e.m_data), (sd),
+ (Struct,
+ for(auto it = sd.ents.begin(); it != sd.ents.end(); ) {
+ auto& si = *it;
+ Expand_Attrs(si.m_attrs, stage_pre (is_early), [&](const auto& d, const auto& a){ d.handle(a, crate, si); });
+ Expand_Type(is_early, crate, modstack, mod, si.m_type);
+ Expand_Attrs(si.m_attrs, stage_post(is_early), [&](const auto& d, const auto& a){ d.handle(a, crate, si); });
+
+ if( si.m_name == "" )
+ it = sd.ents.erase(it);
+ else
+ ++it;
+ }
+ ),
+ (Tuple,
+ for(auto it = sd.ents.begin(); it != sd.ents.end(); ) {
+ auto& si = *it;
+ //Expand_Attrs(si.m_attrs, stage_pre (is_early), [&](const auto& d, const auto& a){ d.handle(a, crate, si); });
+ Expand_Type(is_early, crate, modstack, mod, si.m_type);
+ //Expand_Attrs(si.m_attrs, stage_post(is_early), [&](const auto& d, const auto& a){ d.handle(a, crate, si); });
+
+ if( ! si.m_type.is_valid() )
+ it = sd.ents.erase(it);
+ else
+ ++it;
+ }
+ )
+ )
),
(Enum,
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);
+ TU_MATCH(::AST::EnumVariantData, (var.m_data), (e),
+ (Value,
+ Expand_Expr(is_early, crate, modstack, e.m_value);
+ ),
+ (Tuple,
+ for(auto& ty : e.m_sub_types) {
+ Expand_Type(is_early, crate, modstack, mod, ty);
+ }
+ ),
+ (Struct,
+ for(auto it = e.m_fields.begin(); it != e.m_fields.end(); ) {
+ auto& si = *it;
+ Expand_Attrs(si.m_attrs, stage_pre (is_early), [&](const auto& d, const auto& a){ d.handle(a, crate, si); });
+ Expand_Type(is_early, crate, modstack, mod, si.m_type);
+ Expand_Attrs(si.m_attrs, stage_post(is_early), [&](const auto& d, const auto& a){ d.handle(a, crate, si); });
+
+ if( si.m_name == "" )
+ it = e.m_fields.erase(it);
+ else
+ ++it;
+ }
+ )
+ )
Expand_Attrs(var.m_attrs, stage_post(is_early), [&](const auto& d, const auto& a){ d.handle(a, crate, var); });
}
),