-
Notifications
You must be signed in to change notification settings - Fork 251
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[reflection][feat]Reflect with macro (#722)
- Loading branch information
Showing
11 changed files
with
628 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#pragma once | ||
#include "common_macro.hpp" | ||
|
||
#define WRAP_ARGS0(w, o) | ||
#define WRAP_ARGS1(w, o, _1) w(o, _1) | ||
#include "generate/arg_list_macro_gen.hpp" | ||
|
||
#define WRAP_ARGS_(w, object, ...) \ | ||
YLT_CONCAT(WRAP_ARGS, YLT_ARG_COUNT(__VA_ARGS__)) \ | ||
(w, object, __VA_ARGS__) | ||
#define WRAP_ARGS(w, object, ...) WRAP_ARGS_(w, object, __VA_ARGS__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#pragma once | ||
|
||
#define YLT_MACRO_EXPAND(...) __VA_ARGS__ | ||
|
||
#define YLT_ARG_COUNT(...) \ | ||
YLT_MACRO_EXPAND(YLT_ARG_COUNT_IMPL( \ | ||
0, ##__VA_ARGS__, 124, 123, 122, 121, 120, 119, 118, 117, 116, 115, 114, \ | ||
113, 112, 111, 110, 109, 108, 107, 106, 105, 104, 103, 102, 101, 100, \ | ||
99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, \ | ||
81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, \ | ||
63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, \ | ||
45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, \ | ||
27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, \ | ||
9, 8, 7, 6, 5, 4, 3, 2, 1, 0)) | ||
|
||
#define YLT_ARG_COUNT_IMPL( \ | ||
_0, _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, _71, _72, _73, _74, _75, _76, \ | ||
_77, _78, _79, _80, _81, _82, _83, _84, _85, _86, _87, _88, _89, _90, _91, \ | ||
_92, _93, _94, _95, _96, _97, _98, _99, _100, _101, _102, _103, _104, \ | ||
_105, _106, _107, _108, _109, _110, _111, _112, _113, _114, _115, _116, \ | ||
_117, _118, _119, _120, _121, _122, _123, _124, N, ...) \ | ||
N |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#pragma once | ||
#include "args_count.hpp" | ||
#define YLT_CONCAT_(l, r) l##r | ||
|
||
#define YLT_CONCAT(l, r) YLT_CONCAT_(l, r) | ||
|
||
#define CONCAT_MEMBER(t, x) t.x | ||
|
||
#define CONCAT_ADDR(T, x) &T::x | ||
|
||
#define CONCAT_NAME(t, x) #x | ||
|
||
namespace ylt::reflection { | ||
template <typename T> | ||
struct identity {}; | ||
} // namespace ylt::reflection |
136 changes: 136 additions & 0 deletions
136
include/ylt/reflection/internal/generate/arg_list_macro_gen.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
/*The following boilerplate code was generated using a Python script: | ||
macro = "#define WRAP_ARGS" | ||
with open("generated_args.txt", "w", encoding="utf-8") as codefile: | ||
codefile.write( | ||
"\n".join( | ||
[ | ||
f"{macro}{i}(w,o,_1, ...) w(o, _1), | ||
WRAP_ARGS{i-1}(w,o,__VA_ARGS__)" for i in range(2, 126) | ||
] | ||
) | ||
) | ||
*/ | ||
#define WRAP_ARGS2(w, o, _1, ...) w(o, _1), WRAP_ARGS1(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS3(w, o, _1, ...) w(o, _1), WRAP_ARGS2(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS4(w, o, _1, ...) w(o, _1), WRAP_ARGS3(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS5(w, o, _1, ...) w(o, _1), WRAP_ARGS4(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS6(w, o, _1, ...) w(o, _1), WRAP_ARGS5(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS7(w, o, _1, ...) w(o, _1), WRAP_ARGS6(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS8(w, o, _1, ...) w(o, _1), WRAP_ARGS7(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS9(w, o, _1, ...) w(o, _1), WRAP_ARGS8(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS10(w, o, _1, ...) w(o, _1), WRAP_ARGS9(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS11(w, o, _1, ...) w(o, _1), WRAP_ARGS10(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS12(w, o, _1, ...) w(o, _1), WRAP_ARGS11(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS13(w, o, _1, ...) w(o, _1), WRAP_ARGS12(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS14(w, o, _1, ...) w(o, _1), WRAP_ARGS13(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS15(w, o, _1, ...) w(o, _1), WRAP_ARGS14(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS16(w, o, _1, ...) w(o, _1), WRAP_ARGS15(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS17(w, o, _1, ...) w(o, _1), WRAP_ARGS16(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS18(w, o, _1, ...) w(o, _1), WRAP_ARGS17(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS19(w, o, _1, ...) w(o, _1), WRAP_ARGS18(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS20(w, o, _1, ...) w(o, _1), WRAP_ARGS19(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS21(w, o, _1, ...) w(o, _1), WRAP_ARGS20(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS22(w, o, _1, ...) w(o, _1), WRAP_ARGS21(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS23(w, o, _1, ...) w(o, _1), WRAP_ARGS22(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS24(w, o, _1, ...) w(o, _1), WRAP_ARGS23(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS25(w, o, _1, ...) w(o, _1), WRAP_ARGS24(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS26(w, o, _1, ...) w(o, _1), WRAP_ARGS25(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS27(w, o, _1, ...) w(o, _1), WRAP_ARGS26(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS28(w, o, _1, ...) w(o, _1), WRAP_ARGS27(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS29(w, o, _1, ...) w(o, _1), WRAP_ARGS28(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS30(w, o, _1, ...) w(o, _1), WRAP_ARGS29(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS31(w, o, _1, ...) w(o, _1), WRAP_ARGS30(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS32(w, o, _1, ...) w(o, _1), WRAP_ARGS31(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS33(w, o, _1, ...) w(o, _1), WRAP_ARGS32(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS34(w, o, _1, ...) w(o, _1), WRAP_ARGS33(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS35(w, o, _1, ...) w(o, _1), WRAP_ARGS34(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS36(w, o, _1, ...) w(o, _1), WRAP_ARGS35(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS37(w, o, _1, ...) w(o, _1), WRAP_ARGS36(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS38(w, o, _1, ...) w(o, _1), WRAP_ARGS37(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS39(w, o, _1, ...) w(o, _1), WRAP_ARGS38(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS40(w, o, _1, ...) w(o, _1), WRAP_ARGS39(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS41(w, o, _1, ...) w(o, _1), WRAP_ARGS40(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS42(w, o, _1, ...) w(o, _1), WRAP_ARGS41(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS43(w, o, _1, ...) w(o, _1), WRAP_ARGS42(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS44(w, o, _1, ...) w(o, _1), WRAP_ARGS43(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS45(w, o, _1, ...) w(o, _1), WRAP_ARGS44(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS46(w, o, _1, ...) w(o, _1), WRAP_ARGS45(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS47(w, o, _1, ...) w(o, _1), WRAP_ARGS46(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS48(w, o, _1, ...) w(o, _1), WRAP_ARGS47(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS49(w, o, _1, ...) w(o, _1), WRAP_ARGS48(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS50(w, o, _1, ...) w(o, _1), WRAP_ARGS49(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS51(w, o, _1, ...) w(o, _1), WRAP_ARGS50(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS52(w, o, _1, ...) w(o, _1), WRAP_ARGS51(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS53(w, o, _1, ...) w(o, _1), WRAP_ARGS52(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS54(w, o, _1, ...) w(o, _1), WRAP_ARGS53(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS55(w, o, _1, ...) w(o, _1), WRAP_ARGS54(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS56(w, o, _1, ...) w(o, _1), WRAP_ARGS55(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS57(w, o, _1, ...) w(o, _1), WRAP_ARGS56(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS58(w, o, _1, ...) w(o, _1), WRAP_ARGS57(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS59(w, o, _1, ...) w(o, _1), WRAP_ARGS58(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS60(w, o, _1, ...) w(o, _1), WRAP_ARGS59(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS61(w, o, _1, ...) w(o, _1), WRAP_ARGS60(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS62(w, o, _1, ...) w(o, _1), WRAP_ARGS61(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS63(w, o, _1, ...) w(o, _1), WRAP_ARGS62(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS64(w, o, _1, ...) w(o, _1), WRAP_ARGS63(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS65(w, o, _1, ...) w(o, _1), WRAP_ARGS64(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS66(w, o, _1, ...) w(o, _1), WRAP_ARGS65(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS67(w, o, _1, ...) w(o, _1), WRAP_ARGS66(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS68(w, o, _1, ...) w(o, _1), WRAP_ARGS67(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS69(w, o, _1, ...) w(o, _1), WRAP_ARGS68(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS70(w, o, _1, ...) w(o, _1), WRAP_ARGS69(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS71(w, o, _1, ...) w(o, _1), WRAP_ARGS70(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS72(w, o, _1, ...) w(o, _1), WRAP_ARGS71(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS73(w, o, _1, ...) w(o, _1), WRAP_ARGS72(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS74(w, o, _1, ...) w(o, _1), WRAP_ARGS73(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS75(w, o, _1, ...) w(o, _1), WRAP_ARGS74(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS76(w, o, _1, ...) w(o, _1), WRAP_ARGS75(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS77(w, o, _1, ...) w(o, _1), WRAP_ARGS76(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS78(w, o, _1, ...) w(o, _1), WRAP_ARGS77(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS79(w, o, _1, ...) w(o, _1), WRAP_ARGS78(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS80(w, o, _1, ...) w(o, _1), WRAP_ARGS79(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS81(w, o, _1, ...) w(o, _1), WRAP_ARGS80(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS82(w, o, _1, ...) w(o, _1), WRAP_ARGS81(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS83(w, o, _1, ...) w(o, _1), WRAP_ARGS82(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS84(w, o, _1, ...) w(o, _1), WRAP_ARGS83(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS85(w, o, _1, ...) w(o, _1), WRAP_ARGS84(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS86(w, o, _1, ...) w(o, _1), WRAP_ARGS85(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS87(w, o, _1, ...) w(o, _1), WRAP_ARGS86(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS88(w, o, _1, ...) w(o, _1), WRAP_ARGS87(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS89(w, o, _1, ...) w(o, _1), WRAP_ARGS88(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS90(w, o, _1, ...) w(o, _1), WRAP_ARGS89(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS91(w, o, _1, ...) w(o, _1), WRAP_ARGS90(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS92(w, o, _1, ...) w(o, _1), WRAP_ARGS91(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS93(w, o, _1, ...) w(o, _1), WRAP_ARGS92(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS94(w, o, _1, ...) w(o, _1), WRAP_ARGS93(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS95(w, o, _1, ...) w(o, _1), WRAP_ARGS94(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS96(w, o, _1, ...) w(o, _1), WRAP_ARGS95(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS97(w, o, _1, ...) w(o, _1), WRAP_ARGS96(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS98(w, o, _1, ...) w(o, _1), WRAP_ARGS97(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS99(w, o, _1, ...) w(o, _1), WRAP_ARGS98(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS100(w, o, _1, ...) w(o, _1), WRAP_ARGS99(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS101(w, o, _1, ...) w(o, _1), WRAP_ARGS100(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS102(w, o, _1, ...) w(o, _1), WRAP_ARGS101(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS103(w, o, _1, ...) w(o, _1), WRAP_ARGS102(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS104(w, o, _1, ...) w(o, _1), WRAP_ARGS103(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS105(w, o, _1, ...) w(o, _1), WRAP_ARGS104(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS106(w, o, _1, ...) w(o, _1), WRAP_ARGS105(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS107(w, o, _1, ...) w(o, _1), WRAP_ARGS106(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS108(w, o, _1, ...) w(o, _1), WRAP_ARGS107(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS109(w, o, _1, ...) w(o, _1), WRAP_ARGS108(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS110(w, o, _1, ...) w(o, _1), WRAP_ARGS109(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS111(w, o, _1, ...) w(o, _1), WRAP_ARGS110(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS112(w, o, _1, ...) w(o, _1), WRAP_ARGS111(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS113(w, o, _1, ...) w(o, _1), WRAP_ARGS112(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS114(w, o, _1, ...) w(o, _1), WRAP_ARGS113(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS115(w, o, _1, ...) w(o, _1), WRAP_ARGS114(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS116(w, o, _1, ...) w(o, _1), WRAP_ARGS115(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS117(w, o, _1, ...) w(o, _1), WRAP_ARGS116(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS118(w, o, _1, ...) w(o, _1), WRAP_ARGS117(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS119(w, o, _1, ...) w(o, _1), WRAP_ARGS118(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS120(w, o, _1, ...) w(o, _1), WRAP_ARGS119(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS121(w, o, _1, ...) w(o, _1), WRAP_ARGS120(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS122(w, o, _1, ...) w(o, _1), WRAP_ARGS121(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS123(w, o, _1, ...) w(o, _1), WRAP_ARGS122(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS124(w, o, _1, ...) w(o, _1), WRAP_ARGS123(w, o, __VA_ARGS__) | ||
#define WRAP_ARGS125(w, o, _1, ...) w(o, _1), WRAP_ARGS124(w, o, __VA_ARGS__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.