diff options
author | John Hodge <tpg@mutabah.net> | 2016-03-18 13:58:11 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-03-18 13:58:11 +0800 |
commit | 485dfcb3fe4ddfeb7c0342ec288807fde3ef9504 (patch) | |
tree | e027424cbe73fd799ac524bf82ddebc201fde8f8 /src/ast/ast.cpp | |
parent | 629fa5d38be99066f0fdb664796e9f7c6aea49ba (diff) | |
download | mrust-485dfcb3fe4ddfeb7c0342ec288807fde3ef9504.tar.gz |
AST - Switch traits to contain items
Diffstat (limited to 'src/ast/ast.cpp')
-rw-r--r-- | src/ast/ast.cpp | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/src/ast/ast.cpp b/src/ast/ast.cpp index 4229f1e8..16fad76e 100644 --- a/src/ast/ast.cpp +++ b/src/ast/ast.cpp @@ -501,13 +501,31 @@ SERIALISE_TYPE(Function::, "AST_Function", { SERIALISE_TYPE(Trait::, "AST_Trait", {
s << m_params;
- s << m_types;
- s << m_functions;
+ s << m_items;
},{
s.item(m_params);
- s.item(m_types);
- s.item(m_functions);
+ s.item(m_items);
})
+void Trait::add_type(::std::string name, TypeRef type) {
+ m_items.push_back( Named<Item>(mv$(name), Item::make_Type({TypeAlias(GenericParams(), mv$(type))}), true) );
+}
+void Trait::add_function(::std::string name, Function fcn) {
+ m_items.push_back( Named<Item>(mv$(name), Item::make_Function({mv$(fcn)}), true) );
+}
+void Trait::add_static(::std::string name, Static v) {
+ m_items.push_back( Named<Item>(mv$(name), Item::make_Static({mv$(v)}), true) );
+}
+bool Trait::has_named_item(const ::std::string& name, bool& out_is_fcn) const
+{
+ for( const auto& i : m_items )
+ {
+ if( i.name == name ) {
+ out_is_fcn = i.data.is_Function();
+ return true;
+ }
+ }
+ return false;
+}
SERIALISE_TYPE_A(EnumVariant::, "AST_EnumVariant", {
s.item(m_attrs);
|