Skip to content

Commit

Permalink
Support type names and values with commas
Browse files Browse the repository at this point in the history
This commit fixes the codegen tool so that the macro-based generated
code generates code compatible with types and expressions containing
commas, such as the type 'map<int, string>'. Now all metadata arguments
are enclosed by parens to make sure the values are expanded to the right
enclosing macro call.
  • Loading branch information
Manu343726 committed Dec 18, 2018
1 parent 91ae3b9 commit 42d78a5
Show file tree
Hide file tree
Showing 5 changed files with 321 additions and 283 deletions.
167 changes: 97 additions & 70 deletions include/tinyrefl/backend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -950,84 +950,107 @@ constexpr

#define TINYREFL_SEQUENCE(elems) \
::tinyrefl::meta::list<TINYREFL_PP_UNWRAP elems>
#define TINYREFL_TYPE(name, fullname) fullname
#define TINYREFL_VALUE(type, value) ::ctti::static_value<type, value>
#define TINYREFL_TYPE(name, fullname) TINYREFL_PP_UNWRAP fullname
#define TINYREFL_VALUE(type, value) \
::ctti::static_value<TINYREFL_PP_UNWRAP type, TINYREFL_PP_UNWRAP value>
#define TINYREFL_ATTRIBUTE(name, namespace_, full_attribute, args) \
::tinyrefl::backend:: \
attribute_metadata<name, namespace_, full_attribute, args>
::tinyrefl::backend::attribute_metadata< \
TINYREFL_PP_UNWRAP name, \
TINYREFL_PP_UNWRAP namespace_, \
TINYREFL_PP_UNWRAP full_attribute, \
TINYREFL_PP_UNWRAP args>
#define TINYREFL_CONSTRUCTOR( \
name, fullname, class_type, signature, attributes) \
::tinyrefl::backend::constructor<name, class_type, signature, attributes>
#define TINYREFL_MEMBER_FUNCTION( \
name, \
fullname, \
parent_class_type, \
return_type, \
signature, \
pointer, \
attributes) \
::tinyrefl::backend::member<fullname, pointer, attributes>
::tinyrefl::backend::constructor< \
TINYREFL_PP_UNWRAP name, \
TINYREFL_PP_UNWRAP class_type, \
TINYREFL_PP_UNWRAP signature, \
TINYREFL_PP_UNWRAP attributes>
#define TINYREFL_MEMBER_FUNCTION( \
name, \
fullname, \
parent_class_type, \
return_type, \
signature, \
pointer, \
attributes) \
::tinyrefl::backend::member< \
TINYREFL_PP_UNWRAP fullname, \
TINYREFL_PP_UNWRAP pointer, \
TINYREFL_PP_UNWRAP attributes>
#define TINYREFL_MEMBER_VARIABLE( \
name, fullname, parent_class_type, value_type, pointer, attributes) \
::tinyrefl::backend::member<fullname, pointer, attributes>
::tinyrefl::backend::member< \
TINYREFL_PP_UNWRAP fullname, \
TINYREFL_PP_UNWRAP pointer, \
TINYREFL_PP_UNWRAP attributes>
#define TINYREFL_ENUM_VALUE(name, fullname, type, value, attributes) \
::tinyrefl::backend::enum_value<fullname, value, attributes>

#define TINYREFL_REFLECT_MEMBER(member) \
namespace tinyrefl \
{ \
namespace backend \
{ \
template<> \
struct metadata_of<typename member::pointer_static_value> \
{ \
using type = member; \
}; \
} /* namespace backend */ \
::tinyrefl::backend::enum_value< \
TINYREFL_PP_UNWRAP fullname, \
TINYREFL_PP_UNWRAP value, \
TINYREFL_PP_UNWRAP attributes>

#define TINYREFL_REFLECT_MEMBER_IMPL(...) \
namespace tinyrefl \
{ \
namespace backend \
{ \
template<> \
struct metadata_of<typename __VA_ARGS__::pointer_static_value> \
{ \
using type = __VA_ARGS__; \
}; \
} /* namespace backend */ \
} // namespace tinyrefl

#define TINYREFL_REFLECT_ENUM_VALUE(value) \
namespace tinyrefl \
{ \
namespace backend \
{ \
template<> \
struct metadata_of<typename value::value_static_value> \
{ \
using type = value; \
}; \
} /* namespace backend */ \
#define TINYREFL_REFLECT_MEMBER(member) \
TINYREFL_REFLECT_MEMBER_IMPL(TINYREFL_PP_UNWRAP member)

#define TINYREFL_REFLECT_ENUM_VALUE_IMPL(...) \
namespace tinyrefl \
{ \
namespace backend \
{ \
template<> \
struct metadata_of<typename __VA_ARGS__::value_static_value> \
{ \
using type = __VA_ARGS__; \
}; \
} /* namespace backend */ \
} // namespace tinyrefl

#define TINYREFL_REFLECT_CLASS( \
classname, \
classtype, \
bases, \
ctors, \
functions, \
variables, \
classes, \
enums, \
attributes) \
namespace tinyrefl \
{ \
namespace backend \
{ \
template<> \
struct metadata_of<classtype> \
{ \
using type = class_< \
classname, \
classtype, \
bases, \
ctors, \
functions, \
variables, \
classes, \
enums, \
attributes>; \
}; \
} /* namespace backend */ \
#define TINYREFL_REFLECT_ENUM_VALUE(value) \
TINYREFL_REFLECT_ENUM_VALUE_IMPL(TINYREFL_PP_UNWRAP value)

#define TINYREFL_REFLECT_CLASS( \
classname, \
classtype, \
bases, \
ctors, \
functions, \
variables, \
classes, \
enums, \
attributes) \
namespace tinyrefl \
{ \
namespace backend \
{ \
template<> \
struct metadata_of<TINYREFL_PP_UNWRAP classtype> \
{ \
using type = class_< \
TINYREFL_PP_UNWRAP classname, \
TINYREFL_PP_UNWRAP classtype, \
TINYREFL_PP_UNWRAP bases, \
TINYREFL_PP_UNWRAP ctors, \
TINYREFL_PP_UNWRAP functions, \
TINYREFL_PP_UNWRAP variables, \
TINYREFL_PP_UNWRAP classes, \
TINYREFL_PP_UNWRAP enums, \
TINYREFL_PP_UNWRAP attributes>; \
}; \
} /* namespace backend */ \
} // namespace tinyrefl

#define TINYREFL_REFLECT_ENUM(name, enum_type, values, attributes) \
Expand All @@ -1036,9 +1059,13 @@ constexpr
namespace backend \
{ \
template<> \
struct metadata_of<enum_type> \
struct metadata_of<TINYREFL_PP_UNWRAP enum_type> \
{ \
using type = enum_<name, enum_type, values, attributes>; \
using type = enum_< \
TINYREFL_PP_UNWRAP name, \
TINYREFL_PP_UNWRAP enum_type, \
TINYREFL_PP_UNWRAP values, \
TINYREFL_PP_UNWRAP attributes>; \
}; \
} /* namespace backend */ \
} // namespace tinyrefl
Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ add_tinyrefl_test(tinyrefl-test
example.cpp
)
target_link_libraries(tinyrefl-test PRIVATE tinyrefl)
#target_compile_options(tinyrefl-test PRIVATE -E)

tinyrefl_tool(TARGET tinyrefl-test
HEADERS
Expand Down
Loading

0 comments on commit 42d78a5

Please sign in to comment.