feat(autogen): analyze prop flags

This commit is contained in:
maelstrom 2025-04-26 01:53:00 +02:00
parent 10c78cd647
commit 85e1efe5b3
3 changed files with 55 additions and 26 deletions

View file

@ -143,6 +143,20 @@ void processField(CXCursor cur, ClassAnalysis* state) {
anly.name = result["name"];
anly.fieldName = fieldName;
anly.category = result["category"];
anly.onUpdateCallback = result["on_update"];
if (result.count("hidden"))
anly.flags = anly.flags | PropertyFlags::PropertyFlag_Hidden;
if (result.count("no_save"))
anly.flags = anly.flags | PropertyFlags::PropertyFlag_NoSave;
if (result.count("unit_float"))
anly.flags = anly.flags | PropertyFlags::PropertyFlag_UnitFloat;
if (result.count("readonly"))
anly.flags = anly.flags | PropertyFlags::PropertyFlag_Readonly;
CXType type = clang_getCursorType(cur);
anly.backingFieldType = x_clang_toString(clang_getTypeSpelling(type)).c_str();
state->properties.push_back(anly);
}

View file

@ -4,23 +4,37 @@
#include <string>
#include <vector>
struct PropertyAnalysis {
std::string name;
std::string fieldName;
std::string backingFieldType;
};
enum ClassFlags {
ClassFlag_NotCreatable = 1<<0,
ClassFlag_Service = 1<<1,
ClassFlag_Hidden = 1<<2,
};
enum PropertyFlags {
PropertyFlag_Hidden = 1 << 0,
PropertyFlag_NoSave = 1 << 1,
PropertyFlag_UnitFloat = 1 << 2,
PropertyFlag_Readonly = 1 << 3,
};
struct PropertyAnalysis {
std::string name;
std::string fieldName;
std::string backingFieldType;
std::string onUpdateCallback;
std::string category;
PropertyFlags flags;
};
// https://stackoverflow.com/a/1448478/16255372
inline ClassFlags operator|(ClassFlags a, ClassFlags b) {
return static_cast<ClassFlags>(static_cast<int>(a) | static_cast<int>(b));
}
inline PropertyFlags operator|(PropertyFlags a, PropertyFlags b) {
return static_cast<PropertyFlags>(static_cast<int>(a) | static_cast<int>(b));
}
struct ClassAnalysis {
std::string name;
std::string baseClass;

View file

@ -40,27 +40,28 @@ int main(int argc, char** argv) {
analyzeClasses("../core/src/objects/part.h", argv[1], &state);
for (auto& [_, clazz] : state.classes) {
printf("Class: %s\n", clazz.name.c_str());
if (clazz.baseClass != "")
printf("==> Base class: %s\n", clazz.baseClass.c_str());
if (clazz.explorerIcon != "")
printf("==> Explorer icon: %s\n", clazz.explorerIcon.c_str());
printf("==> Flags (%x): ", clazz.flags);
if (clazz.flags & ClassFlag_Service)
printf("INSTANCE_SERVICE ");
if (clazz.flags & ClassFlag_NotCreatable)
printf("INSTANCE_NOT_CREATABLE ");
if (clazz.flags & ClassFlag_Hidden)
printf("INSTANCE_HIDDEN");
printf("\n");
if (!clazz.properties.empty())
printf("==> Properties:\n");
for (auto prop : clazz.properties) {
printf("====> %s (%s)\n", prop.name.c_str(), prop.fieldName.c_str());
}
}
// for (auto& [_, clazz] : state.classes) {
// printf("Class: %s\n", clazz.name.c_str());
// if (clazz.baseClass != "")
// printf("==> Base class: %s\n", clazz.baseClass.c_str());
// if (clazz.explorerIcon != "")
// printf("==> Explorer icon: %s\n", clazz.explorerIcon.c_str());
// printf("==> Flags (%x): ", clazz.flags);
// if (clazz.flags & ClassFlag_Service)
// printf("INSTANCE_SERVICE ");
// if (clazz.flags & ClassFlag_NotCreatable)
// printf("INSTANCE_NOT_CREATABLE ");
// if (clazz.flags & ClassFlag_Hidden)
// printf("INSTANCE_HIDDEN");
// printf("\n");
// if (!clazz.properties.empty())
// printf("==> Properties:\n");
// for (auto prop : clazz.properties) {
// printf("====> %s (%s) (%s)\n", prop.name.c_str(), prop.fieldName.c_str(), prop.backingFieldType.c_str());
// }
// }
// First-pass: Analyze type hierarchy
// for (std::string path : headerFiles) {