1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
/*
*/
#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 ImplDef;
}
enum class AttrStage
{
Pre,
Post,
};
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, 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
|