-
Notifications
You must be signed in to change notification settings - Fork 0
review comments #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: tmp_review_branch
Are you sure you want to change the base?
Conversation
Changed code style for whole solution.
There is circular dependency error.
…n-experiments # Conflicts: # applications/reflection-experiments/src/reflection_parsers/ast_source_parser.cpp # applications/reflection-experiments/src/reflection_parsers/ast_source_parser.h
Still circular issue.
still a little bit broken
| #include "../runtime_reflection_containers/reflected_variable.h" | ||
|
|
||
| rsl::dynamic_string reflection_code_generator::generate_variable( | ||
| rythe::reflection_containers::reflected_variable parsed_variable) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prolly want a const& here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true and real
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant const& as the input parameter, the return type can be left without const
| { | ||
| private: | ||
| rsl::hashed_string name; | ||
| rsl::dynamic_string current_namespace; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might be nicer for this to be a reflected_namespace pointer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will add a little bit later when revising runtime variables
|
|
||
| reflection_id return_type_id; | ||
| rsl::dynamic_array<reflection_id> parameters; | ||
| rsl::dynamic_array<rsl::dynamic_string> attributes; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we require custom attributes to all share a custom_attribute base class, then this could be an array of custom_attribute pointers instead, which would probably be a bit more usefull than strings. at runtime we probably want to be able to call a function like: value.has_attribute<my_attribute>() and this function should not rely on string operations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but then in the end, attributes are custom as you can have anything inside it. Then it would mean that in the end we are still working with strings. And also because custom attributes in my head should be stored added by value somehow so it could live on the stack, as we will (probably) need multiple of each attributes so having new delete for each owner of attributes does not seems like a good solution to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you don't need new or delete, you can have it be a static local variable in the generated function, and pass the pointer to that variable to this list of attributes
|
|
||
| #include <rsl/string> | ||
|
|
||
| struct reflection_id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would expect an ID to be an integer, if this what a type struct like a reflection_type then it would be more likely to have a name and attributes. IDs are used to identify things, but string operations are incredibly expensive. comparing 2 integers of any size is a lot faster than comparing strings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would be hashes
.../reflection-experiments/src/compiletime_reflection_containers/compile_reflection_container.h
Show resolved
Hide resolved
applications/reflection-experiments/src/reflection_parsers/ast_source_parser.cpp
Show resolved
Hide resolved
applications/reflection-experiments/src/reflection_properties/access_modifier.h
Outdated
Show resolved
Hide resolved
applications/reflection-experiments/src/runtime_reflection_containers/reflected_function.h
Outdated
Show resolved
Hide resolved
| reflection_properties::acess_modifier access_modifier, | ||
| bool is_static, | ||
| bool is_const, | ||
| bool is_array, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
something like is_array and array_size I'd argue is more a property of the type of the variable than the variable itself? potentially the same goes for const, size and alignment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, you are probably right, will change it later
|
|
||
| } | ||
|
|
||
| rsl::dynamic_string reflection_code_generator::get_gen_source_file(rsl::string_view source_location) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since this function is only used in the reflection_code_generator and static, it might be better to leave this as an implementation detail function, so a global function in an anonymous namespace, or marked static so it gets internal linkage
| { | ||
| rsl::id_type hash = rsl::internal::hash::default_seed; | ||
|
|
||
| this->compile_reflection_container<compile_reflected_class>::sort_container( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we mentioned that if the offset is taken into the hash, then it doesn't need to be sorted right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, but the hash itself is still an ordered ordeal, so before applying them to hash, we need to put them into correct order. If it was like in AST the hash would be different as AST itself does not guarantee source-like ordering, so we need to always hash in offset order.
| compile_reflected_variable>::get_container_hash(); | ||
| if(hash != 0) { hash = rsl::combine_hash(rsl::internal::hash::default_seed, hash, variable_container_hash); } | ||
|
|
||
| this->compile_reflection_container<compile_reflected_function>::sort_container( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the order of the functions matters in the structure hash, arguably functions don't matter at all for the structure hash
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, kinda make sense, but strictly from reflection id stand point, if we have a class that is the same in all but functions, id still say its a good idea to make it produce different hash. But for our reflection we still need to know the functions, so the difference is only do we hash functions, which id say we should do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
after giving it another thought, i also want to exclude functions from hashes, would be pretty strange if saves would fail cos you have added a function.
| #include <ostream> | ||
|
|
||
| compile_reflected_element::compile_reflected_element(rsl::dynamic_string&& name) : name(std::move(name)) {} | ||
| compile_reflected_element::compile_reflected_element(rsl::dynamic_string name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you're gonna move, then take it in as a rvalue reference. if you also want to allow copying then also supply a copy constructor using a const lvalue reference. don't take a heavy object like a string in by forced copy value.
|
|
||
| private: | ||
| rsl::dynamic_string source_location; | ||
| const rsl::dynamic_string source_location; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you make member variables const, be careful. it's good practice, but it also means that copy or move assignment is deleted. this type becomes construct only
| #include "compile_reflected_variable.h" | ||
|
|
||
| compile_reflected_variable::compile_reflected_variable(CXCursor cursor) | ||
| compile_reflected_variable::compile_reflected_variable(CXCursor& cursor, CXCursor& parent) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these could be const&, i know the clang library takes them is as a forced value copy.... but i would not take that as a good example. looking at the size of CXCursor, I'd definitely pass it around as a reference. but since it is copied for every clang_ function anyways, we have no need for it to be non-const.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tru, i have probably forgotten to change this to const
|
|
||
| template<typename T> | ||
| T& compile_reflection_container<T>::add_element(const CXCursor& cursor) | ||
| T& compile_reflection_container<T>::add_element(CXCursor& cursor, CXCursor& parent) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can be const& for the same reason i mentioned earlier
| template<typename T> | ||
| void compile_reflection_container<T>::verify_typename() const | ||
| { | ||
| static_assert(std::is_base_of_v<compile_reflected_element, T>, "T must inherit from compile_reflected_element"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static asserts don't need to be called at runtime, so they don't even need to be in a function. they can exist anywhere in the class or other member functions. static_asserts get executed at compile time. the reason why this static assert works, and the concept restriction didn't, is because this function gets instantiated later, after the type T is complete.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, i know that and in this case i wanted to do that from the start (put it in the body of class), but that didnt work, as static assert is called immideately when the class is encountered, so it still tried to use incomplete "compiletime_reflection_class", during the process of compilation. So in this case it seems to me that we had to put here.
| rsl::id_type hash = rsl::internal::hash::default_seed; | ||
|
|
||
| this->compile_reflection_container<compile_reflected_class>::sort_container( | ||
| &compile_reflection_container<compile_reflected_class>::sort_by_offset_comparator); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
arguably, contained classes don't matter for the structure hash either.... although it becomes tricky with anonymous structs and unions, so maybe rather safe than sorry and include them anyways... hmm....
|
|
||
| for(std::size_t i = 0; i < min_length; ++i) | ||
| { | ||
| if(a_string[i] < b_string[i]) { return true; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if(a_string[i] != b_string[i]) { return a_string[i] < b_string[i]; }There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fair enough
|
|
||
| extern "C" | ||
| { | ||
| #include "xxhash.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can use:
#define XXH_STATIC_LINKING_ONLY /* access advanced declarations */
#define XXH_IMPLEMENTATION /* access definitions */
and then you can add xxhash as a header only library, and then there would be no need for extern "C" either.
| // Vector is not sorted before getting to this function | ||
| rsl::id_type reflection_id::generate_structure_hash(std::vector<std::pair<std::size_t, rsl::id_type>>& members) noexcept | ||
| { | ||
| std::ranges::sort( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if the structure hash of the members already includes the offset, then sorting is not necessary
No description provided.