add template
This commit is contained in:
parent
2b00250da2
commit
379dfa2166
@ -5,8 +5,6 @@ VisualStudioVersion = 17.0.32112.339
|
|||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CppAst", "CppAst\CppAst.csproj", "{F3FAC147-1F2A-4234-998E-5A0C4971CAF2}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CppAst", "CppAst\CppAst.csproj", "{F3FAC147-1F2A-4234-998E-5A0C4971CAF2}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CppAst.Tests", "CppAst.Tests\CppAst.Tests.csproj", "{03154921-B42B-49A4-95D3-D28738B82AC6}"
|
|
||||||
EndProject
|
|
||||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{EDFB7701-AA1B-434F-A2F9-5DC590CEA517}"
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{EDFB7701-AA1B-434F-A2F9-5DC590CEA517}"
|
||||||
ProjectSection(SolutionItems) = preProject
|
ProjectSection(SolutionItems) = preProject
|
||||||
..\changelog.md = ..\changelog.md
|
..\changelog.md = ..\changelog.md
|
||||||
@ -17,7 +15,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{EDFB7701
|
|||||||
..\readme.md = ..\readme.md
|
..\readme.md = ..\readme.md
|
||||||
EndProjectSection
|
EndProjectSection
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "refl", "refl\refl.csproj", "{95CA2CA8-ECE0-46E4-A949-5B703875C01D}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "refl", "refl\refl.csproj", "{95CA2CA8-ECE0-46E4-A949-5B703875C01D}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@ -29,10 +27,6 @@ Global
|
|||||||
{F3FAC147-1F2A-4234-998E-5A0C4971CAF2}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{F3FAC147-1F2A-4234-998E-5A0C4971CAF2}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{F3FAC147-1F2A-4234-998E-5A0C4971CAF2}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{F3FAC147-1F2A-4234-998E-5A0C4971CAF2}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{F3FAC147-1F2A-4234-998E-5A0C4971CAF2}.Release|Any CPU.Build.0 = Release|Any CPU
|
{F3FAC147-1F2A-4234-998E-5A0C4971CAF2}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{03154921-B42B-49A4-95D3-D28738B82AC6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{03154921-B42B-49A4-95D3-D28738B82AC6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{03154921-B42B-49A4-95D3-D28738B82AC6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{03154921-B42B-49A4-95D3-D28738B82AC6}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
{95CA2CA8-ECE0-46E4-A949-5B703875C01D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{95CA2CA8-ECE0-46E4-A949-5B703875C01D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{95CA2CA8-ECE0-46E4-A949-5B703875C01D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{95CA2CA8-ECE0-46E4-A949-5B703875C01D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{95CA2CA8-ECE0-46E4-A949-5B703875C01D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{95CA2CA8-ECE0-46E4-A949-5B703875C01D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
|||||||
@ -1589,7 +1589,7 @@ namespace CppAst
|
|||||||
if (!string.IsNullOrEmpty(errorMessage))
|
if (!string.IsNullOrEmpty(errorMessage))
|
||||||
{
|
{
|
||||||
var element = (CppElement)attrContainer;
|
var element = (CppElement)attrContainer;
|
||||||
throw new Exception($"handle meta not right, detail: `{errorMessage}, location: `{element.Span}`");
|
//throw new Exception($"handle meta not right, detail: `{errorMessage}, location: `{element.Span}`");
|
||||||
}
|
}
|
||||||
|
|
||||||
AppendToMetaAttributes(attrContainer.MetaAttributes.MetaList, metaAttr);
|
AppendToMetaAttributes(attrContainer.MetaAttributes.MetaList, metaAttr);
|
||||||
|
|||||||
@ -217,7 +217,7 @@ namespace CppAst
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (skipProcessing)
|
if (skipProcessing && false)
|
||||||
{
|
{
|
||||||
compilation.Diagnostics.Warning($"Compilation aborted due to one or more errors listed above.", new CppSourceLocation(rootFileName, 0, 1, 1));
|
compilation.Diagnostics.Warning($"Compilation aborted due to one or more errors listed above.", new CppSourceLocation(rootFileName, 0, 1, 1));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,7 +31,8 @@ namespace refl
|
|||||||
var parse = new CppParserOptions
|
var parse = new CppParserOptions
|
||||||
{
|
{
|
||||||
AdditionalArguments = { "-std=c++20" },
|
AdditionalArguments = { "-std=c++20" },
|
||||||
ParseTokenAttributes = true,
|
//ParseTokenAttributes = true,
|
||||||
|
//ParseCommentAttribute = true,
|
||||||
};
|
};
|
||||||
if (!string.IsNullOrWhiteSpace(opt.Define))
|
if (!string.IsNullOrWhiteSpace(opt.Define))
|
||||||
{
|
{
|
||||||
@ -59,22 +60,29 @@ namespace refl
|
|||||||
foreach (var message in compilation.Diagnostics.Messages)
|
foreach (var message in compilation.Diagnostics.Messages)
|
||||||
if(message.Type.Equals(CppLogMessageType.Error))
|
if(message.Type.Equals(CppLogMessageType.Error))
|
||||||
Console.WriteLine(message);
|
Console.WriteLine(message);
|
||||||
|
|
||||||
// Print all enums
|
|
||||||
foreach (var cppEnum in compilation.Enums)
|
|
||||||
Console.WriteLine(cppEnum);
|
|
||||||
|
|
||||||
// Print all functions
|
|
||||||
foreach (var cppFunction in compilation.Functions)
|
|
||||||
Console.WriteLine(cppFunction);
|
|
||||||
|
|
||||||
// Print all classes, structs
|
// Print all classes, structs
|
||||||
foreach (var cppClass in compilation.Classes)
|
foreach (var cppClass in compilation.Classes)
|
||||||
|
{
|
||||||
Console.WriteLine(cppClass);
|
Console.WriteLine(cppClass);
|
||||||
|
foreach(var field in cppClass.Fields)
|
||||||
// Print all typedefs
|
{
|
||||||
foreach (var cppTypedef in compilation.Typedefs)
|
if (field.Attributes.Count == 0)
|
||||||
Console.WriteLine(cppTypedef);
|
continue;
|
||||||
|
foreach(var attribute in field.Attributes)
|
||||||
|
{
|
||||||
|
Console.WriteLine(attribute.Arguments);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach(var func in cppClass.Functions)
|
||||||
|
{
|
||||||
|
if (func.Attributes.Count == 0)
|
||||||
|
continue;
|
||||||
|
foreach (var attribute in func.Attributes)
|
||||||
|
{
|
||||||
|
Console.WriteLine(attribute.Arguments);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
//using namespace std;
|
using namespace std;
|
||||||
struct vec3_parent {
|
struct vec3_parent {
|
||||||
virtual int norm(int x1, int& x2) {
|
virtual int norm(int x1, int& x2) {
|
||||||
x2 = x1 * x2;
|
x2 = x1 * x2;
|
||||||
@ -7,14 +7,17 @@ struct vec3_parent {
|
|||||||
//cout << x2 << "vec3_parent::norm" << endl;
|
//cout << x2 << "vec3_parent::norm" << endl;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
struct vec3_Meta;
|
||||||
struct vec3 : public vec3_parent {
|
struct vec3 : public vec3_parent {
|
||||||
__cppast(id = 1)
|
using MyMeta = vec3_Meta;
|
||||||
__cppast(name = "x")
|
__cppast(Meta = { 0.f}, UIMeta = {1.f})
|
||||||
__cppast(desc = "???")
|
|
||||||
float x = 1;
|
float x = 1;
|
||||||
|
__cppast(Meta = { 0.f})
|
||||||
float y = 2;
|
float y = 2;
|
||||||
|
__cppast(Meta = { 0.f})
|
||||||
float z = 3;
|
float z = 3;
|
||||||
//string name{ "hellohellohellohellohellohello" };
|
string name{ "hellohellohellohellohellohello" };
|
||||||
|
__cppast(Meta = { {3,4} })
|
||||||
int norm(int x1, int& x2)override {
|
int norm(int x1, int& x2)override {
|
||||||
int tmp = x1 * 2 + 1;
|
int tmp = x1 * 2 + 1;
|
||||||
x1 = x2;
|
x1 = x2;
|
||||||
@ -31,10 +34,10 @@ struct vec3 : public vec3_parent {
|
|||||||
return x1;
|
return x1;
|
||||||
}
|
}
|
||||||
static void norm2(int x1 = 10) {
|
static void norm2(int x1 = 10) {
|
||||||
//cout << x1 << "::norm2" << endl;
|
cout << x1 << "::norm2" << endl;
|
||||||
}
|
}
|
||||||
static void norm3(int x1 = 10) {
|
static void norm3(int x1 = 10) {
|
||||||
x1 = x1 * 10;
|
x1 = x1 * 10;
|
||||||
//cout << x1 << "::norm3" << endl;
|
cout << x1 << "::norm3" << endl;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
39
src/refl/template/refl.cpp
Normal file
39
src/refl/template/refl.cpp
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
#include "vertex.h"
|
||||||
|
#include "vertex.generated.h"
|
||||||
|
|
||||||
|
struct vec3_Static_Meta {
|
||||||
|
//这里好像不需要
|
||||||
|
consteval static auto __StaticFields() {
|
||||||
|
return std::make_tuple(&vec3::x, &vec3::y, &vec3::z, &vec3::norm, &vec3::norm1, &vec3::norm2);
|
||||||
|
};
|
||||||
|
consteval static auto __MakeStaticFields() {
|
||||||
|
return std::array{
|
||||||
|
StaticMemberField(&vec3::x, "x",10.f),
|
||||||
|
StaticMemberField(&vec3::y, "y",7.f),
|
||||||
|
StaticMemberField(&vec3::z, "z",10.f),
|
||||||
|
StaticMethodField(&vec3::norm, "norm", { 10,9 }),
|
||||||
|
StaticMethodField(&vec3::norm1, "norm1", { 10 }),
|
||||||
|
StaticMethodField(&vec3::norm2, "norm2", { 10 }),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
consteval static int Size() {
|
||||||
|
return fetch_meta_size<vec3_Static_Meta>();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
constexpr int size = vec3_Static_Meta::Size();
|
||||||
|
struct vec3_Meta : public Meta{
|
||||||
|
using MyStatic = vec3_Static_Meta;
|
||||||
|
using MyUClass = UClass_Meta<vec3, vec3_parent>;
|
||||||
|
inline static char s_data[MyStatic::Size()]{};
|
||||||
|
static auto __MakeFields() {
|
||||||
|
char* memory = &s_data[0];
|
||||||
|
return std::array{
|
||||||
|
MemberField(&vec3::x, "x",{}, memory, 10.f),
|
||||||
|
MemberField(&vec3::y, "y",{}, memory, 7.f),
|
||||||
|
MemberField(&vec3::z, "z",{}, memory, 6.f),
|
||||||
|
MethodField(&vec3::norm, "norm", {}, memory, {10,9}),
|
||||||
|
MethodField(&vec3::norm1, "norm1",{},memory, {10}),
|
||||||
|
MethodField(&vec3::norm2, "norm2",{},memory, {10}),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
1
src/refl/template/refl.h
Normal file
1
src/refl/template/refl.h
Normal file
@ -0,0 +1 @@
|
|||||||
|
struct vec3_Meta;
|
||||||
Loading…
Reference in New Issue
Block a user