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
|
#include "../../slang.h"
#include "slang-ast-reflect.h"
#include "../core/slang-smart-pointer.h"
#include "slang-ast-all.h"
#include <typeinfo>
#include <assert.h>
#include "slang-ast-generated-macro.h"
namespace Slang
{
#define SLANG_REFLECT_GET_REFLECT_CLASS_INFO(NAME, SUPER, ORIGIN, LAST, MARKER, TYPE, param) infos.infos[int(ASTNodeType::NAME)] = &NAME::kReflectClassInfo;
static ReflectClassInfo::Infos _calcInfos()
{
ReflectClassInfo::Infos infos;
memset(&infos, 0, sizeof(infos));
SLANG_ALL_ASTNode_NodeBase(SLANG_REFLECT_GET_REFLECT_CLASS_INFO, _)
SLANG_ALL_ASTNode_Substitutions(SLANG_REFLECT_GET_REFLECT_CLASS_INFO, _)
return infos;
}
/* static */const ReflectClassInfo::Infos ReflectClassInfo::kInfos = _calcInfos();
bool ReflectClassInfo::isSubClassOfSlow(const ThisType& super) const
{
ReflectClassInfo const* info = this;
while (info)
{
if (info == &super)
return true;
info = info->m_superClass;
}
return false;
}
// Now try and implement all of the classes
// Macro generated is of the format
template <typename T>
struct CreateImpl
{
static void* create() { return new T; }
};
#define SLANG_GET_SUPER_BASE(SUPER) nullptr
#define SLANG_GET_SUPER_INNER(SUPER) &SUPER::kReflectClassInfo
#define SLANG_GET_SUPER_LEAF(SUPER) &SUPER::kReflectClassInfo
#define SLANG_GET_CREATE_FUNC_ABSTRACT(NAME) nullptr
#define SLANG_GET_CREATE_FUNC_NONE(NAME) &CreateImpl<NAME>::create
#define SLANG_GET_CREATE_FUNC_NON_VISITOR_ABSTRACT(NAME) nullptr
#define SLANG_GET_CREATE_FUNC_NON_VISITOR(NAME) &CreateImpl<NAME>::create
#define SLANG_REFLECT_CLASS_INFO(NAME, SUPER, ORIGIN, LAST, MARKER, TYPE, param) \
/* static */const ReflectClassInfo NAME::kReflectClassInfo = { uint32_t(ASTNodeType::NAME), uint32_t(ASTNodeType::LAST), SLANG_GET_SUPER_##TYPE(SUPER), #NAME, SLANG_GET_CREATE_FUNC_##MARKER(NAME) };
SLANG_ALL_ASTNode_NodeBase(SLANG_REFLECT_CLASS_INFO, _)
SLANG_ALL_ASTNode_Substitutions(SLANG_REFLECT_CLASS_INFO, _)
} // namespace Slang
|