-
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
Open
GlynLeine
wants to merge
46
commits into
tmp_review_branch
Choose a base branch
from
main
base: tmp_review_branch
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
976709a
wip
NiZe42 962a012
fix hashed_string, move notes.cpp to outside of the project
GlynLeine 649c171
update rsl to get argh
GlynLeine ce30cac
Update rsl
NiZe42 d85b8d5
Merge remote-tracking branch 'origin/main'
NiZe42 c6661fa
update rsl
GlynLeine 703a691
Merge branch 'main' of https://github.com/Rythe-Interactive/reflectio…
GlynLeine ad2f7c0
added working AST
NiZe42 a703465
added parameters
NiZe42 5d4713e
rsl::cli_parser alias
GlynLeine 0011ea3
broken codegen
NiZe42 2d88278
Merge branch 'main' of https://github.com/Rythe-Interactive/reflectio…
NiZe42 dada67b
wip
NiZe42 1211ae8
update rsl
GlynLeine fbe1f85
wip
NiZe42 a989037
update rsl again
GlynLeine 291ea76
wip broken print
NiZe42 f0e3701
update rsl, rbs, and set debug args in project
GlynLeine e890759
update rsl
GlynLeine ba17054
small suggestion
GlynLeine e236e0b
works for hashed string too
GlynLeine 561eb14
WIP
NiZe42 0323990
started adding compile reflection
NiZe42 0b064a1
not compiling variable container
NiZe42 da5308d
Started reworking parser yet again.
NiZe42 f3a2294
changed some more code style, continued with restructure
NiZe42 1269573
some minor review notes
GlynLeine 9e913f5
almost done ast_parser
NiZe42 617706a
Merge branch 'main' of https://github.com/Rythe-Interactive/reflectio…
NiZe42 88878ba
added comments back in, fixed a little error
NiZe42 fb29c5c
Implemented templates for containers
NiZe42 10f00e9
wip printing, added base element class
NiZe42 097dd6d
working parser with printing
NiZe42 22a031a
little print improvement
NiZe42 005669b
started code_gen
NiZe42 f3cc14a
added hashing
NiZe42 0023950
WIP not working code gen
NiZe42 3746067
implemented reviews
NiZe42 fc81672
WIP hashing system
NiZe42 7aa6a4c
WIP still broken hashing
NiZe42 5485e1d
finished hashing
NiZe42 ade8f67
added const to constructors
NiZe42 31f27f3
fixed hashing bugs
NiZe42 dc954b3
WIP
NiZe42 35ca05d
continued codegen
NiZe42 733a099
fix bug
NiZe42 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| rythe-build-system\premake5 --file=rythe-build-system/premake5.lua vs2022 --workspace-name=reflection-experiments | ||
| rythe-build-system\premake5 --file=rythe-build-system/premake5.lua vs2022 --workspace-name=reflection-experiments | ||
| pause |
This file contains hidden or 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
File renamed without changes.
57 changes: 57 additions & 0 deletions
57
applications/reflection-experiments/src/code_gen/example.h
This file contains hidden or 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,57 @@ | ||
| #pragma once | ||
| #include "../runtime_reflection_containers/runtime_reflected_class.h" | ||
| #include "../runtime_reflection_containers/runtime_reflected_variable.h" | ||
| #include "../runtime_reflection_containers/runtime_reflected_function.h" | ||
|
|
||
| /* This is example of generated from this file: | ||
| namespace examle_namespace | ||
| { | ||
| class target_class | ||
| { | ||
| public: | ||
| int int_variable; | ||
|
|
||
| void void_function(int int_parameter); | ||
|
|
||
| class nested_class | ||
| { | ||
| public: | ||
| nested_class() : value(0) {} | ||
|
|
||
| void set_value(int v) | ||
| { | ||
| value = v; | ||
| } | ||
|
|
||
| int get_value() const | ||
| { | ||
| return value; | ||
| } | ||
|
|
||
| private: | ||
| int value; | ||
| }; | ||
| private: | ||
| char char_variable; | ||
| }; | ||
| } | ||
| */ | ||
|
|
||
| class example_file_generated | ||
| { | ||
| public: | ||
| void add_reflected_file() | ||
| { | ||
| // All defined types in this file should go in here. | ||
| static const runtime_reflected_class classes[2] = { | ||
| runtime_reflected_class( | ||
| rsl::dynamic_string::from_buffer("example_namespace::target_class"), | ||
| reflection_id(12875366372301390368, 31932944099034707, 15853025086180115556)), | ||
| runtime_reflected_class( | ||
| rsl::dynamic_string::from_buffer("example_namespace::target_class::nested_class"), | ||
| reflection_id(8627741348740311923, 10691473971882747459, 3168970719907517523)) | ||
| }; | ||
|
|
||
| for(auto reflected_class : classes) { context.add_type(&reflected_class); } | ||
| } | ||
| }; |
183 changes: 183 additions & 0 deletions
183
applications/reflection-experiments/src/code_gen/reflection_code_generator.cpp
This file contains hidden or 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,183 @@ | ||
| #include "reflection_code_generator.h" | ||
| #include "D:/MyProjects/reflection-experiments/applications/reflection-experiments/src/target/test.hpp" | ||
| #include <fstream> | ||
| #include <iostream> | ||
| #include <stdio.h> | ||
|
|
||
| #include "../runtime_reflection_containers/runtime_reflected_variable.h" | ||
|
|
||
| const rsl::dynamic_string reflection_code_generator::generate_variable( | ||
| [[maybe_unused]] runtime_reflected_variable parsed_variable) | ||
| { | ||
| /* | ||
| std::string pad = " "; | ||
| std::ostringstream out; | ||
|
|
||
| out << "rythe::reflection_containers::runtime_reflected_variable(\n"; | ||
|
|
||
| const char* name = parsed_variable.get_name().data(); | ||
| out << pad << "\"" << name << "\"\n"; | ||
|
|
||
| const char* name_space = parsed_variable.get_namespace().data(); | ||
| out << pad << "\"" << name_space << "\"\n"; | ||
|
|
||
| switch(parsed_variable.get_access_modifier()) | ||
| { | ||
| case reflection_properties::access_modifier::public_access: | ||
| out << pad << "reflection_properties::acess_modifier::public_access,\n"; | ||
| break; | ||
| case reflection_properties::access_modifier::protected_access: | ||
| out << pad << "reflection_properties::acess_modifier::protected_access,\n"; | ||
| break; | ||
| case reflection_properties::access_modifier::private_access: | ||
| out << pad << "reflection_properties::acess_modifier::private_access,\n"; | ||
| break; | ||
| default: | ||
| out << pad << "reflection_properties::acess_modifier::public_access,\n"; | ||
| break; | ||
| } | ||
|
|
||
| out << pad << (parsed_variable.get_is_static() ? "true" : "false") << ",\n"; | ||
| out << pad << (parsed_variable.get_is_const() ? "true" : "false") << ",\n"; | ||
| out << pad << (parsed_variable.get_is_array() ? "true" : "false") << ",\n"; | ||
| out << pad << parsed_variable.get_array_size() << ",\n"; | ||
|
|
||
| out << pad << parsed_variable.get_offset() << ",\n"; | ||
| out << pad << parsed_variable.get_size() << ",\n"; | ||
| out << pad << parsed_variable.get_alignment() << ",\n"; | ||
|
|
||
| //const char* type_str = parsed_variable.get_type_id().get_type().data(); | ||
| //out << pad << "reflection_id(rsl::dynamic_string::from_string_length(" << type_str << ")),\n"; | ||
|
|
||
| const auto& attributes = parsed_variable.get_attributes(); | ||
| out << pad << "rsl::dynamic_array<rsl::dynamic_string>{"; | ||
| if(!attributes.empty()) { out << "\n"; } | ||
| for (int i = 0; i < attributes.size(); ++i) { | ||
| const char* attribute = attributes[i].data(); | ||
| out << pad << " rsl::dynamic_string::from_buffer(" | ||
| << attribute << ", " << (attribute ? attributes.size() : 0) << ")"; | ||
| if (i + 1 < attributes) out << ","; | ||
| out << "\n"; | ||
| } | ||
|
|
||
| if(!attributes.empty()) { out << pad; } | ||
| out << "}\n"; | ||
|
|
||
| out << " )"; | ||
|
|
||
| std::string string = out.str(); | ||
| return rsl::dynamic_string::from_buffer(string.c_str(), string.size()); | ||
| */ | ||
| return {}; | ||
| } | ||
|
|
||
| reflection_code_generator::reflection_code_generator() {} | ||
|
|
||
| reflection_code_generator::~reflection_code_generator() {} | ||
|
|
||
| void reflection_code_generator::generate_reflected_file(const compile_reflected_file& compile_file) | ||
| { | ||
| const rsl::string_view source_location = compile_file.get_source_location(); | ||
| std::ofstream file(get_gen_source_file(source_location).data()); | ||
| if(!file.is_open()) { std::cout << "Could not open file " << source_location.data() << " for writing.\n"; } | ||
|
|
||
| file << "#include \"runtime_reflected_variable.hpp\"\n"; | ||
| file << "using namespace rythe::reflection_containers;\n\n"; | ||
| file << "void generate_variable(rythe::reflection_containers::runtime_reflected_variable parsed_variable) {\n"; | ||
| //file << " auto var = " << generate_variable(parsed_variable).data() << ";\n"; | ||
| file << "}\n"; | ||
| } | ||
|
|
||
| rsl::dynamic_string reflection_code_generator::get_gen_source_file(rsl::string_view source_location) | ||
| { | ||
| if(source_location.size() >= 256) | ||
| { | ||
| std::cout << "source_path is too long\n"; | ||
| return {}; | ||
| } | ||
|
|
||
| char buffer[256]; | ||
| std::memcpy(buffer, source_location.data(), source_location.size()); | ||
| buffer[source_location.size()] = '\0'; | ||
|
|
||
| char* lastSlash = std::strrchr(buffer, '/'); | ||
| if(lastSlash != nullptr) { *lastSlash = '\0'; } | ||
|
|
||
| strcat_s(buffer, sizeof(buffer), "/generated"); | ||
|
|
||
| return rsl::dynamic_string::from_buffer(buffer, std::strlen(buffer)); | ||
| } | ||
|
|
||
|
|
||
| /* | ||
| rsl::dynamic_string reflection_code_generator::generate_variable(rythe::reflection_containers::runtime_reflected_variable parsed_variable) { | ||
|
|
||
| std::string pad = " "; | ||
| std::ostringstream out; | ||
|
|
||
| out << "rythe::reflection_containers::runtime_reflected_variable(\n"; | ||
|
|
||
| const char* name = parsed_variable.get_source_location().data(); | ||
| out << pad << "\"" << name << "\"\n"; | ||
|
|
||
| const char* name_space = parsed_variable.get_namespace().data(); | ||
| out << pad << "\"" << name_space << "\"\n"; | ||
|
|
||
| switch (parsed_variable.get_access_modifier()) { | ||
| case reflection_properties::acess_modifier::public_access: | ||
| out << pad << "reflection_properties::acess_modifier::public_access,\n"; break; | ||
| case reflection_properties::acess_modifier::protected_access: | ||
| out << pad << "reflection_properties::acess_modifier::protected_access,\n"; break; | ||
| case reflection_properties::acess_modifier::private_access: | ||
| out << pad << "reflection_properties::acess_modifier::private_access,\n"; break; | ||
| default: | ||
| out << pad << "reflection_properties::acess_modifier::public_access,\n"; break; | ||
| } | ||
|
|
||
| out << pad << (parsed_variable.get_is_static() ? "true" : "false") << ",\n"; | ||
| out << pad << (parsed_variable.get_is_const() ? "true" : "false") << ",\n"; | ||
| out << pad << (parsed_variable.get_is_array() ? "true" : "false") << ",\n"; | ||
| out << pad << parsed_variable.get_array_size() << ",\n"; | ||
|
|
||
| out << pad << parsed_variable.get_offset() << ",\n"; | ||
| out << pad << parsed_variable.get_size() << ",\n"; | ||
| out << pad << parsed_variable.get_alignment() << ",\n"; | ||
|
|
||
| const char* type_str = parsed_variable.get_type_id().get_type().data(); | ||
| out << pad << "reflection_id(rsl::dynamic_string::from_buffer(" | ||
| << type_str << ", " << (type_str ? std::strlen(type_str) : 0) << ")),\n"; | ||
|
|
||
| const auto& attributes = parsed_variable.get_attributes(); | ||
| out << pad << "rsl::dynamic_array<rsl::dynamic_string>{"; | ||
| if (!attributes.empty()) out << "\n"; | ||
| for (int i = 0; i < attributes.size(); ++i) { | ||
| const char* attribute = attributes[i].data(); | ||
| out << pad << " rsl::dynamic_string::from_buffer(" | ||
| << attribute << ", " << (attribute ? attributes.size() : 0) << ")"; | ||
| if (i + 1 < attributes) out << ","; | ||
| out << "\n"; | ||
| } | ||
| if (!attributes.empty()) out << pad; | ||
| out << "}\n"; | ||
|
|
||
| out << " )"; | ||
|
|
||
| std::string string = out.str(); | ||
| return rsl::dynamic_string::from_buffer(string.c_str(), string.size()); | ||
| } | ||
| */ | ||
|
|
||
| void reflection_code_generator::generate_reflected_variable_file( | ||
| const runtime_reflected_variable& parsed_variable, | ||
| const std::string& outFile) | ||
| { | ||
| std::cout << "reflection_code_generator::generate_reflected_variable_file\n"; | ||
| std::ofstream file(outFile); | ||
| if(!file.is_open()) { std::cout << "Could not open file " << outFile << " for writing.\n"; } | ||
|
|
||
| file << "#include \"runtime_reflected_variable.hpp\"\n"; | ||
| file << "using namespace rythe::reflection_containers;\n\n"; | ||
| file << "void generate_variable(rythe::reflection_containers::runtime_reflected_variable parsed_variable) {\n"; | ||
| file << " auto var = " << generate_variable(parsed_variable).data() << ";\n"; | ||
| file << "}\n"; | ||
| } | ||
21 changes: 21 additions & 0 deletions
21
applications/reflection-experiments/src/code_gen/reflection_code_generator.h
This file contains hidden or 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,21 @@ | ||
| #pragma once | ||
| #include "../runtime_reflection_containers/runtime_reflected_variable.h" | ||
| #include <sstream> | ||
| #include <rsl/containers> | ||
| #include "../compiletime_reflection_containers/compile_reflected_file.h" | ||
|
|
||
| class reflection_code_generator | ||
| { | ||
| public: | ||
| const rsl::dynamic_string generate_variable(runtime_reflected_variable parsed_variable); | ||
|
|
||
| reflection_code_generator(); | ||
| ~reflection_code_generator(); | ||
|
|
||
| void generate_reflected_variable_file( | ||
| const runtime_reflected_variable& parsed_variable, | ||
| const std::string& outFile); | ||
|
|
||
| void generate_reflected_file(const compile_reflected_file& file); | ||
| static rsl::dynamic_string get_gen_source_file(rsl::string_view source_location); | ||
| }; |
5 changes: 5 additions & 0 deletions
5
applications/reflection-experiments/src/compiletime_reflection_containers.h
This file contains hidden or 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,5 @@ | ||
| #pragme once | ||
|
|
||
| #include "compiletime_reflection_containers/compile_reflected_class.h" | ||
| #include "compiletime_reflection_containers/compile_reflected_file.h" | ||
| #include "reflection_id/reflection_id.h" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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_generatorand 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