From d1d84ced588b40bdec67ee8bdb184a31d3ae9e7d Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sat, 27 Feb 2016 10:06:54 +0800 Subject: Parse/impl - Handle macro invocations --- src/ast/ast.hpp | 72 ++++++++++++++++++++++++++++++--------------------------- 1 file changed, 38 insertions(+), 34 deletions(-) (limited to 'src/ast/ast.hpp') diff --git a/src/ast/ast.hpp b/src/ast/ast.hpp index 4165b34d..2aea5ac1 100644 --- a/src/ast/ast.hpp +++ b/src/ast/ast.hpp @@ -214,6 +214,40 @@ using ItemList = ::std::vector >; typedef Item StructItem; class Crate; +class MacroInvocation: + public Serialisable +{ + MetaItems m_attrs; + ::std::string m_macro_name; + ::std::string m_ident; + TokenTree m_input; +public: + MacroInvocation() + { + } + + MacroInvocation(MetaItems attrs, ::std::string macro, ::std::string ident, TokenTree input): + m_attrs( mv$(attrs) ), + m_macro_name( mv$(macro) ), + m_ident( mv$(ident) ), + m_input( mv$(input) ) + { + } + + static ::std::unique_ptr from_deserialiser(Deserialiser& s) { + auto i = new MacroInvocation; + s.item( *i ); + return ::std::unique_ptr(i); + } + + SERIALISABLE_PROTOTYPES(); + + friend ::std::ostream& operator<<(::std::ostream& os, const MacroInvocation& x) { + os << x.m_attrs << x.m_macro_name << "! " << x.m_ident << x.m_input; + return os; + } +}; + class TypeAlias: public Serialisable { @@ -511,6 +545,7 @@ class Impl: ItemList m_types; ItemList m_functions; ItemList m_statics; + ::std::vector m_macro_invocations; ::std::vector< ::std::pair< ::std::vector, Impl > > m_concrete_impls; public: @@ -529,6 +564,9 @@ public: void add_static(bool is_public, ::std::string name, Static v) { m_statics.push_back( Item( mv$(name), mv$(v), is_public ) ); } + void add_macro_invocation( MacroInvocation inv ) { + m_macro_invocations.push_back( mv$(inv) ); + } const ImplDef& def() const { return m_def; } const ItemList& functions() const { return m_functions; } @@ -558,40 +596,6 @@ class Module; typedef void fcn_visitor_t(const AST::Crate& crate, const AST::Module& mod, Function& fcn); -class MacroInvocation: - public Serialisable -{ - MetaItems m_attrs; - ::std::string m_macro_name; - ::std::string m_ident; - TokenTree m_input; -public: - MacroInvocation() - { - } - - MacroInvocation(MetaItems attrs, ::std::string macro, ::std::string ident, TokenTree input): - m_attrs( mv$(attrs) ), - m_macro_name( mv$(macro) ), - m_ident( mv$(ident) ), - m_input( mv$(input) ) - { - } - - static ::std::unique_ptr from_deserialiser(Deserialiser& s) { - auto i = new MacroInvocation; - s.item( *i ); - return ::std::unique_ptr(i); - } - - SERIALISABLE_PROTOTYPES(); - - friend ::std::ostream& operator<<(::std::ostream& os, const MacroInvocation& x) { - os << x.m_attrs << x.m_macro_name << "! " << x.m_ident << x.m_input; - return os; - } -}; - /// Representation of a parsed (and being converted) function class Module: public Serialisable -- cgit v1.2.3