summaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
Diffstat (limited to 'src/include')
-rw-r--r--src/include/synext.hpp90
-rw-r--r--src/include/synext_decorator.hpp75
-rw-r--r--src/include/synext_macro.hpp40
3 files changed, 118 insertions, 87 deletions
diff --git a/src/include/synext.hpp b/src/include/synext.hpp
index ae1c14f6..76b41996 100644
--- a/src/include/synext.hpp
+++ b/src/include/synext.hpp
@@ -4,93 +4,9 @@
#ifndef _SYNEXT_HPP_
#define _SYNEXT_HPP_
-#include "../ast/item.hpp"
-#include <span.hpp>
-
-class TypeRef;
-namespace AST {
- class Crate;
- class MetaItem;
- class Path;
-
- struct StructItem;
- struct TupleItem;
- struct EnumVariant;
-
- class Module;
- class Item;
-
- class Expr;
- class ExprNode;
- struct ExprNode_Match_Arm;
-
- class MacroInvocation;
-
- class ImplDef;
-}
-class TokenTree;
-class TokenStream;
-
-
-#include "../common.hpp" // for mv$ and other things
-#include <string>
-#include <memory>
-
-enum class AttrStage
-{
- EarlyPre,
- EarlyPost,
- LatePre,
- LatePost,
-};
-
-class ExpandDecorator
-{
- void unexpected(const Span& sp, const AST::MetaItem& mi, const char* loc_str) const;
-public:
- virtual AttrStage stage() const = 0;
-
- virtual void handle(const Span& sp, const AST::MetaItem& mi, AST::Crate& crate) const { unexpected(sp, mi, "crate"); }
- virtual void handle(const Span& sp, const AST::MetaItem& mi, AST::Crate& crate, AST::MacroInvocation& mac) const { unexpected(sp, mi, "macro invocation"); }
- virtual void handle(const Span& sp, const AST::MetaItem& mi, AST::Crate& crate, const AST::Path& path, AST::Module& mod, AST::Item&i) const { unexpected(sp, mi, "item"); }
- // NOTE: To delete, set the type to `_`
- virtual void handle(const Span& sp, const AST::MetaItem& mi, AST::Crate& crate, const AST::Module& mod, AST::ImplDef& impl) const { unexpected(sp, mi, "impl"); }
- // NOTE: To delete, clear the name
- virtual void handle(const Span& sp, const AST::MetaItem& mi, AST::Crate& crate, ::AST::StructItem& si) const { unexpected(sp, mi, "struct item"); }
- // NOTE: To delete, make the type invalid
- virtual void handle(const Span& sp, const AST::MetaItem& mi, AST::Crate& crate, ::AST::TupleItem& si) const { unexpected(sp, mi, "tuple item"); }
- // NOTE: To delete, clear the name
- virtual void handle(const Span& sp, const AST::MetaItem& mi, AST::Crate& crate, ::AST::EnumVariant& ev) const { unexpected(sp, mi, "enum variant"); }
-
- virtual void handle(const Span& sp, const AST::MetaItem& mi, AST::Crate& crate, ::std::unique_ptr<AST::ExprNode>& expr) const { unexpected(sp, mi, "expression"); }
- // NOTE: To delete, clear the patterns vector
- virtual void handle(const Span& sp, const AST::MetaItem& mi, AST::Crate& crate, ::AST::ExprNode_Match_Arm& expr) const { unexpected(sp, mi, "match arm"); }
-};
-
-class ExpandProcMacro
-{
-public:
- virtual bool expand_early() const = 0;
-
- virtual ::std::unique_ptr<TokenStream> expand(const Span& sp, const AST::Crate& crate, const ::std::string& ident, const TokenTree& tt, AST::Module& mod) = 0;
-};
-
-#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_##_handler_class;
-#define STATIC_MACRO(ident, _handler_class) \
- struct register_##_handler_class##_c {\
- register_##_handler_class##_c() {\
- Register_Synext_Macro( ident, ::std::unique_ptr<ExpandProcMacro>(new _handler_class()) ); \
- } \
- } s_register_##_handler_class;
-
-extern void Register_Synext_Decorator(::std::string name, ::std::unique_ptr<ExpandDecorator> handler);
-extern void Register_Synext_Macro(::std::string name, ::std::unique_ptr<ExpandProcMacro> handler);
-
+#include "../common.hpp" // for LList
+#include "synext_decorator.hpp"
+#include "synext_macro.hpp"
extern void Expand_Expr(bool is_early, ::AST::Crate& crate, LList<const AST::Module*> modstack, ::std::unique_ptr<AST::ExprNode>& node);
diff --git a/src/include/synext_decorator.hpp b/src/include/synext_decorator.hpp
new file mode 100644
index 00000000..5ae1af53
--- /dev/null
+++ b/src/include/synext_decorator.hpp
@@ -0,0 +1,75 @@
+/*
+ */
+#pragma once
+#ifndef _SYNEXT_DECORATOR_HPP_
+#define _SYNEXT_DECORATOR_HPP_
+
+#include <string>
+#include <memory>
+#include <span.hpp>
+#include "../ast/item.hpp"
+
+class TypeRef;
+namespace AST {
+ class Crate;
+ class MetaItem;
+ class Path;
+
+ struct StructItem;
+ struct TupleItem;
+ struct EnumVariant;
+
+ class Module;
+ class Item;
+
+ class Expr;
+ class ExprNode;
+ struct ExprNode_Match_Arm;
+
+ class MacroInvocation;
+
+ class ImplDef;
+}
+
+enum class AttrStage
+{
+ EarlyPre,
+ EarlyPost,
+ LatePre,
+ LatePost,
+};
+
+class ExpandDecorator
+{
+ void unexpected(const Span& sp, const AST::MetaItem& mi, const char* loc_str) const;
+public:
+ virtual AttrStage stage() const = 0;
+
+ virtual void handle(const Span& sp, const AST::MetaItem& mi, AST::Crate& crate) const { unexpected(sp, mi, "crate"); }
+ virtual void handle(const Span& sp, const AST::MetaItem& mi, AST::Crate& crate, AST::MacroInvocation& mac) const { unexpected(sp, mi, "macro invocation"); }
+ virtual void handle(const Span& sp, const AST::MetaItem& mi, AST::Crate& crate, const AST::Path& path, AST::Module& mod, AST::Item&i) const { unexpected(sp, mi, "item"); }
+ // NOTE: To delete, set the type to `_`
+ virtual void handle(const Span& sp, const AST::MetaItem& mi, AST::Crate& crate, const AST::Module& mod, AST::ImplDef& impl) const { unexpected(sp, mi, "impl"); }
+ // NOTE: To delete, clear the name
+ virtual void handle(const Span& sp, const AST::MetaItem& mi, AST::Crate& crate, ::AST::StructItem& si) const { unexpected(sp, mi, "struct item"); }
+ // NOTE: To delete, make the type invalid
+ virtual void handle(const Span& sp, const AST::MetaItem& mi, AST::Crate& crate, ::AST::TupleItem& si) const { unexpected(sp, mi, "tuple item"); }
+ // NOTE: To delete, clear the name
+ virtual void handle(const Span& sp, const AST::MetaItem& mi, AST::Crate& crate, ::AST::EnumVariant& ev) const { unexpected(sp, mi, "enum variant"); }
+
+ virtual void handle(const Span& sp, const AST::MetaItem& mi, AST::Crate& crate, ::std::unique_ptr<AST::ExprNode>& expr) const { unexpected(sp, mi, "expression"); }
+ // NOTE: To delete, clear the patterns vector
+ virtual void handle(const Span& sp, const AST::MetaItem& mi, AST::Crate& crate, ::AST::ExprNode_Match_Arm& expr) const { unexpected(sp, mi, "match arm"); }
+};
+
+#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_##_handler_class;
+
+extern void Register_Synext_Decorator(::std::string name, ::std::unique_ptr<ExpandDecorator> handler);
+
+#endif
+
diff --git a/src/include/synext_macro.hpp b/src/include/synext_macro.hpp
new file mode 100644
index 00000000..1aa7fef5
--- /dev/null
+++ b/src/include/synext_macro.hpp
@@ -0,0 +1,40 @@
+/*
+ */
+#pragma once
+#ifndef _SYNEXT_MACRO_HPP_
+#define _SYNEXT_MACRO_HPP_
+
+//#include "../common.hpp" // for mv$ and other things
+#include <string>
+#include <memory>
+#include <span.hpp>
+
+class TypeRef;
+namespace AST {
+ class Crate;
+ class Module;
+}
+class TokenTree;
+class TokenStream;
+
+
+
+class ExpandProcMacro
+{
+public:
+ virtual bool expand_early() const = 0;
+
+ virtual ::std::unique_ptr<TokenStream> expand(const Span& sp, const AST::Crate& crate, const ::std::string& ident, const TokenTree& tt, AST::Module& mod) = 0;
+};
+
+#define STATIC_MACRO(ident, _handler_class) \
+ struct register_##_handler_class##_c {\
+ register_##_handler_class##_c() {\
+ Register_Synext_Macro( ident, ::std::unique_ptr<ExpandProcMacro>(new _handler_class()) ); \
+ } \
+ } s_register_##_handler_class;
+
+extern void Register_Synext_Macro(::std::string name, ::std::unique_ptr<ExpandProcMacro> handler);
+
+#endif
+