diff options
author | John Hodge <tpg@mutabah.net> | 2016-03-06 17:41:46 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-03-06 17:41:46 +0800 |
commit | 859d43ae7012da10a58de5926d096dc817596fce (patch) | |
tree | 66a0dc09e8be4e5c7763bfc4af0cfae488c2c595 /src/include/synext.hpp | |
parent | f430222343e18fec9f97c9b9fdfdc17667b94505 (diff) | |
download | mrust-859d43ae7012da10a58de5926d096dc817596fce.tar.gz |
HUGE REFACTOR - Move named module items into a tagged union
- Item attributes now "owned" by the parent
Diffstat (limited to 'src/include/synext.hpp')
-rw-r--r-- | src/include/synext.hpp | 52 |
1 files changed, 34 insertions, 18 deletions
diff --git a/src/include/synext.hpp b/src/include/synext.hpp index d4026930..6d229aef 100644 --- a/src/include/synext.hpp +++ b/src/include/synext.hpp @@ -1,11 +1,10 @@ /* */ +#pragma once #ifndef _SYNEXT_HPP_ #define _SYNEXT_HPP_ -#include "../common.hpp" // for mv$ and other things -#include <string> -#include <memory> +#include "../ast/item.hpp" namespace AST { class Crate; @@ -13,30 +12,47 @@ namespace AST { class Path; class Module; + class Item; + + class ExprNode; + class Expr; - class Struct; - class Trait; + class MacroInvocation; } +class TokenTree; + + +#include "../common.hpp" // for mv$ and other things +#include <string> +#include <memory> + + +class ExpandDecorator +{ +public: + virtual bool expand_before_macros() const = 0; + + 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::ExprNode& expr) const {}; +}; + -class CDecoratorHandler +class ExpandProcMacro { public: - virtual void handle_item(AST::Crate&, AST::Module&, const AST::MetaItem&, const AST::Path&, AST::Struct& ) const - { - } - virtual void handle_item(AST::Crate&, AST::Module&, const AST::MetaItem&, const AST::Path&, AST::Trait& ) const - { - } + virtual AST::Expr expand(const ::std::string& ident, const TokenTree& tt, AST::Module& mod) = 0; }; -#define STATIC_SYNEXT(_type, ident, _typename) \ - struct register_##_typename##_c {\ - register_##_typename##_c() {\ - Register_Synext_##_type( ident, ::std::unique_ptr<C##_type##Handler>(new _typename()) ); \ +#define STATIC_DECORATOR(ident, _handler_class) \ + struct register_##_handler_class##_c {\ + register_##_handler_class##_c() {\ + Register_Synext_Decorator( ident, ::std::unique_ptr<ExpandDecorator>(new _handler_class()) ); \ } \ - } s_register_##_typename; + } s_register_##_handler_class; -extern void Register_Synext_Decorator(::std::string name, ::std::unique_ptr<CDecoratorHandler> handler); +extern void Register_Synext_Decorator(::std::string name, ::std::unique_ptr<ExpandDecorator> handler); #endif |