feat update sled for linux

This commit is contained in:
tqcq 2024-03-05 09:45:08 +08:00
parent 6566f11269
commit 9540ca05ed
5 changed files with 56 additions and 55 deletions

2
3rdparty/sled vendored

@ -1 +1 @@
Subproject commit 4402688c9c63e9885de1bf99cd718150b036ac7a Subproject commit 5900bdf0f6adf9b01b7e6d3844d4ef1e4b3009c7

View File

@ -18,8 +18,8 @@ add_executable(meta
src/types/field.cc src/types/field.cc
src/types/method.cc src/types/method.cc
src/registry.cc src/registry.cc
runtime/test.gen.cc # runtime/test.gen.cc
runtime/reflection.gen.cc # runtime/reflection.gen.cc
) )
### add clang ### add clang

View File

@ -7,6 +7,7 @@
#include <sled/log/log.h> #include <sled/log/log.h>
#include <string> #include <string>
#include <type_traits> #include <type_traits>
#include <unordered_map>
#include <vector> #include <vector>
namespace meta { namespace meta {

View File

@ -4,12 +4,11 @@
/** /**
* Class * Class
**/ **/
test::Test::Test_Class::Test_Class() test::Test::Test_Class::Test_Class() : ::meta::reflection::Class("test::Test", nullptr) {}
: ::meta::reflection::Class("test::Test", nullptr)
{
}
void test::Test::Test_Class::Register() { void
test::Test::Test_Class::Register()
{
auto self = new test::Test::Test_Class(); auto self = new test::Test::Test_Class();
auto clz = std::shared_ptr<::meta::reflection::Class>(self); auto clz = std::shared_ptr<::meta::reflection::Class>(self);
// self->AddBaseClassProxy(); // self->AddBaseClassProxy();
@ -22,69 +21,71 @@ void test::Test::Test_Class::Register() {
::meta::reflection::Registry::Instance()->RegisterClass(clz); ::meta::reflection::Registry::Instance()->RegisterClass(clz);
} }
void test::Test::Test_Class::AddBaseClassProxy(std::shared_ptr<::meta::reflection::Class> base) {
void
test::Test::Test_Class::AddBaseClassProxy(std::shared_ptr<::meta::reflection::Class> base)
{
AddBaseClass(base); AddBaseClass(base);
} }
void test::Test::Test_Class::AddMethodProxy(std::shared_ptr<::meta::reflection::Method> method) {
void
test::Test::Test_Class::AddMethodProxy(std::shared_ptr<::meta::reflection::Method> method)
{
AddMethod(method); AddMethod(method);
} }
void test::Test::Test_Class::AddFieldProxy(std::shared_ptr<::meta::reflection::Field> field) {
void
test::Test::Test_Class::AddFieldProxy(std::shared_ptr<::meta::reflection::Field> field)
{
AddField(field); AddField(field);
} }
/** /**
* Field * Field
**/ **/
test::Test::Test_Field::Test_Field( test::Test::Test_Field::Test_Field(const std::string &name,
const std::string& name, std::shared_ptr<::meta::reflection::Class> parent)
std::shared_ptr<::meta::reflection::Class> parent) : ::meta::reflection::Field(name, parent)
: ::meta::reflection::Field(name, parent) {} {}
::meta::reflection::any test::Test::Test_Field::GetImpl(void* instance) const { ::meta::reflection::any
::test::Test* obj = (::test::Test*)instance; test::Test::Test_Field::GetImpl(void *instance) const
{
::test::Test *obj = (::test::Test *) instance;
if (strcmp(Name().c_str(), "length_") == 0) { if (strcmp(Name().c_str(), "length_") == 0) { return obj->length_; }
return obj->length_; if (strcmp(Name().c_str(), "size_") == 0) { return obj->size_; }
}
if (strcmp(Name().c_str(), "size_") == 0) {
return obj->size_;
}
return ::meta::reflection::any{}; return ::meta::reflection::any{};
} }
void test::Test::Test_Field::SetImpl(void* instance, const ::meta::reflection::any& value) const { void
::test::Test* obj = (::test::Test*)instance; test::Test::Test_Field::SetImpl(void *instance, const ::meta::reflection::any &value) const
if(strcmp(Name().c_str(), "length_") == 0) { obj->length_ = ::meta::reflection::any_cast<int>(value);} {
if(strcmp(Name().c_str(), "size_") == 0) { obj->size_ = ::meta::reflection::any_cast<int>(value);} ::test::Test *obj = (::test::Test *) instance;
if (strcmp(Name().c_str(), "length_") == 0) {
obj->length_ = ::meta::reflection::any_cast<int>(value);
}
if (strcmp(Name().c_str(), "size_") == 0) {
obj->size_ = ::meta::reflection::any_cast<int>(value);
}
} }
/** /**
* Method * Method
**/ **/
test::Test::Test_Method::Test_Method( test::Test::Test_Method::Test_Method(const std::string &name,
const std::string& name, std::shared_ptr<::meta::reflection::Class> parent)
std::shared_ptr<::meta::reflection::Class> parent) : ::meta::reflection::Method(name, parent)
: ::meta::reflection::Method(name, parent) {} {}
::meta::reflection::any test::Test::Test_Method::InvokeImpl(void* instance, const std::vector<::meta::reflection::any> &params) const { ::meta::reflection::any
::test::Test* obj = (::test::Test*)instance; test::Test::Test_Method::InvokeImpl(void *instance,
const std::vector<::meta::reflection::any> &params) const
{
::test::Test *obj = (::test::Test *) instance;
if (strcmp(Name().c_str(), "size") == 0) { if (strcmp(Name().c_str(), "size") == 0) { return obj->size(); }
return if (strcmp(Name().c_str(), "length") == 0) { return obj->length(); }
obj->
size(
);
}
if (strcmp(Name().c_str(), "length") == 0) {
return
obj->
length(
);
}
return ::meta::reflection::any{}; return ::meta::reflection::any{};
} }

View File

@ -1,7 +1,6 @@
#include "generators/base_generator.h" #include "generators/base_generator.h"
#include "reflection.h" #include "reflection.h"
#include "registry.h" #include "registry.h"
#include "test.gen.h"
#include "types/class.h" #include "types/class.h"
#include "clang/parser.h" #include "clang/parser.h"
#include <fstream> #include <fstream>
@ -126,7 +125,7 @@ main(int argc, char *argv[])
Generator generator2("template/class_proxy_source.inja", "runtime/test.gen.cc"); Generator generator2("template/class_proxy_source.inja", "runtime/test.gen.cc");
generator2.Generate(); generator2.Generate();
::meta::reflection::Registry::RegisterAll(); // ::meta::reflection::Registry::RegisterAll();
TestFunc(); TestFunc();
return 0; return 0;
} }
@ -137,13 +136,13 @@ TestFunc()
auto clz = ::meta::reflection::Registry::Instance()->GetClass("test::Test"); auto clz = ::meta::reflection::Registry::Instance()->GetClass("test::Test");
if (clz) { if (clz) {
LOGI(kTag, "class={}", clz->Name()); LOGI(kTag, "class={}", clz->Name());
::test::Test test; // ::test::Test test;
auto size_method = clz->GetMethod("size"); auto size_method = clz->GetMethod("size");
auto size_field = clz->GetField("size_"); auto size_field = clz->GetField("size_");
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
size_field->Set(&test, i); // size_field->Set(&test, i);
LOGI(kTag, "size_field={}", size_field->GetAndCast<int>(&test)); // LOGI(kTag, "size_field={}", size_field->GetAndCast<int>(&test));
LOGI(kTag, "size_invoke={}", size_method->InvokeAndCast<size_t>(&test)); // LOGI(kTag, "size_invoke={}", size_method->InvokeAndCast<size_t>(&test));
} }
} else { } else {
LOGE(kTag, "class not found"); LOGE(kTag, "class not found");