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 | |
| 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')
| -rw-r--r-- | src/include/main_bindings.hpp | 16 | ||||
| -rw-r--r-- | src/include/synext.hpp | 52 |
2 files changed, 49 insertions, 19 deletions
diff --git a/src/include/main_bindings.hpp b/src/include/main_bindings.hpp index 91bac742..dc9ef9eb 100644 --- a/src/include/main_bindings.hpp +++ b/src/include/main_bindings.hpp @@ -3,12 +3,26 @@ #ifndef _MAIN_BINDINGS_HPP_ #define _MAIN_BINDINGS_HPP_ -#include "../ast/ast.hpp" +#include <string> + +namespace AST { + class Crate; + class Flat; +} /// Parse a crate from the given file extern AST::Crate Parse_Crate(::std::string mainfile); + + +extern void Expand_Decorators_Pre(::AST::Crate& crate); +extern void Expand_Macros(::AST::Crate& crate); +extern void Expand_Decorators_Post(::AST::Crate& crate); +extern void Expand_Sugar(::AST::Crate& crate); + /// Process #[] decorators extern void Process_Decorators(AST::Crate& crate); + + /// Resolve all in-text paths to absolute variants extern void ResolvePaths(AST::Crate& crate); /// Check that generic bounds are valid 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 |
