Skip to content
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

Add getCanonicalTypeName() for Field and Variable types. #15

Open
wants to merge 12 commits into
base: dev
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,7 @@ void ReflectionCodeGenModule::declareAndDefineRegisterChildClassMethod(kodgen::S

inout_result += "staticField = childClass.addStaticField(\"" + field.name + "\", " +
(structClass.type.isTemplateType() ? computeClassTemplateEntityId(structClass, field) : computeClassNestedEntityId("ChildClass", field)) + ", " +
"\"" + field.type.getCanonicalName(true) + "\", " +
"rfk::getType<" + field.type.getName() + ">(), "
"static_cast<rfk::EFieldFlags>(" + std::to_string(computeRefurekuFieldFlags(field)) + "), "
"&" + structClass.name + "::" + field.name + ", "
Expand All @@ -935,6 +936,7 @@ void ReflectionCodeGenModule::declareAndDefineRegisterChildClassMethod(kodgen::S

inout_result += "field = childClass.addField(\"" + field.name + "\", " +
(structClass.type.isTemplateType() ? computeClassTemplateEntityId(structClass, field) : computeClassNestedEntityId("ChildClass", field)) + ", " +
"\"" + field.type.getCanonicalName(true) + "\", " +
"rfk::getType<" + field.type.getName() + ">(), "
"static_cast<rfk::EFieldFlags>(" + std::to_string(computeRefurekuFieldFlags(field)) + "), "
"offsetof(ChildClass, " + field.name + "), "
Expand Down Expand Up @@ -1385,7 +1387,8 @@ void ReflectionCodeGenModule::defineGetVariableFunction(kodgen::VariableInfo con
inout_result += "template <> rfk::Variable const* rfk::getVariable<&" + variable.getFullName() + ">() noexcept {" + env.getSeparator() +
"static bool initialized = false;" + env.getSeparator() +
"static rfk::Variable variable(\"" + variable.name + "\", " +
getEntityId(variable) + ", "
getEntityId(variable) + ", " +
"\"" + variable.type.getCanonicalName(true) + "\", " +
"rfk::getType<decltype(" + fullName + ")>(), "
"&" + fullName + ", "
"static_cast<rfk::EVarFlags>(" + std::to_string(computeRefurekuVariableFlags(variable)) + ")"
Expand Down
3 changes: 3 additions & 0 deletions Refureku/Generator/RefurekuSettings.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ projectIncludeDirectories = [
# Must be one of "msvc", "clang++", "g++"
compilerExeName = "clang++"

# Ignores parsing errors, may lead to incorrect type information for non-reflected types.
shouldFailCodeGenerationOnClangErrors = false

# Abort parsing on first encountered error
shouldAbortParsingOnFirstError = true

Expand Down
8 changes: 4 additions & 4 deletions Refureku/Generator/Source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ void printGenerationResult(kodgen::ILogger& logger, kodgen::CodeGenResult const&
}
}

void parseAndGenerate(fs::path&& settingsFilePath)
bool parseAndGenerate(fs::path&& settingsFilePath)
{
kodgen::DefaultLogger logger;

Expand Down Expand Up @@ -138,12 +138,12 @@ void parseAndGenerate(fs::path&& settingsFilePath)

//Result
printGenerationResult(logger, genResult);

return genResult.completed;
}

/** Can provide the path to the settings file as 1st parameter */
int main(int argc, char** argv)
{
parseAndGenerate((argc > 1) ? fs::path(argv[1]) : fs::path());

return EXIT_SUCCESS;
return !parseAndGenerate((argc > 1) ? fs::path(argv[1]) : fs::path());
}
Original file line number Diff line number Diff line change
Expand Up @@ -170,18 +170,21 @@ namespace rfk
/**
* @brief Add a field to the struct.
*
* @param name Name of the field.
* @param id Unique entity id of the field.
* @param type Type of the field.
* @param flags Field flags.
* @param owner Struct the field is belonging to.
* @param memoryOffset Offset in bytes of the field in the owner struct (obtained from offsetof).
* @param outerEntity Struct the field was first declared in (in case of inherited field, outerEntity is the parent struct).
* @param name Name of the field.
* @param id Unique entity id of the field.
* @param canonicalTypeName Name of this variable's type simplified by unwinding all aliases, typedefs,
* without qualifiers, namespaces and nested classes.
* @param type Type of the field.
* @param flags Field flags.
* @param owner Struct the field is belonging to.
* @param memoryOffset Offset in bytes of the field in the owner struct (obtained from offsetof).
* @param outerEntity Struct the field was first declared in (in case of inherited field, outerEntity is the parent struct).
*
* @return A pointer to the added field. The pointer is made from the iterator, so is unvalidated as soon as the iterator is unvalidated.
*/
RFK_NODISCARD inline Field* addField(char const* name,
std::size_t id,
char const* canonicalTypeName,
Type const& type,
EFieldFlags flags,
Struct const* owner,
Expand All @@ -191,26 +194,30 @@ namespace rfk
/**
* @brief Add a static field to the struct.
*
* @param name Name of the static field.
* @param id Unique entity id of the static field.
* @param type Type of the static field.
* @param flags Field flags.
* @param owner Struct the static field is belonging to.
* @param fieldPtr Pointer to the static field.
* @param outerEntity Struct the field was first declared in (in case of inherited field, outerEntity is the parent struct).
* @param name Name of the static field.
* @param id Unique entity id of the static field.
* @param canonicalTypeName Name of this variable's type simplified by unwinding all aliases, typedefs,
* without qualifiers, namespaces and nested classes.
* @param type Type of the static field.
* @param flags Field flags.
* @param owner Struct the static field is belonging to.
* @param fieldPtr Pointer to the static field.
* @param outerEntity Struct the field was first declared in (in case of inherited field, outerEntity is the parent struct).
*
* @return A pointer to the added static field.
* The pointer is made from the iterator, so is unvalidated as soon as the iterator is unvalidated.
*/
RFK_NODISCARD inline StaticField* addStaticField(char const* name,
std::size_t id,
char const* canonicalTypeName,
Type const& type,
EFieldFlags flags,
Struct const* owner,
void* fieldPtr,
Struct const* outerEntity) noexcept;
RFK_NODISCARD inline StaticField* addStaticField(char const* name,
std::size_t id,
char const* canonicalTypeName,
Type const& type,
EFieldFlags flags,
Struct const* owner,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,34 +49,34 @@ inline void Struct::StructImpl::addNestedArchetype(Archetype const* nestedArchet
result->setOuterEntity(outerEntity);
}

inline Field* Struct::StructImpl::addField(char const* name, std::size_t id, Type const& type, EFieldFlags flags,
inline Field* Struct::StructImpl::addField(char const* name, std::size_t id, char const* canonicalTypeName, Type const& type, EFieldFlags flags,
Struct const* owner, std::size_t memoryOffset, Struct const* outerEntity) noexcept
{
assert(name != nullptr);
assert((flags & EFieldFlags::Static) != EFieldFlags::Static);

//The hash is based on the field name which is immutable, so it's safe to const_cast to update other members.
return const_cast<Field*>(&*_fields.emplace(name, id, type, flags, owner, memoryOffset, outerEntity));
return const_cast<Field*>(&*_fields.emplace(name, id, canonicalTypeName, type, flags, owner, memoryOffset, outerEntity));
}

inline StaticField* Struct::StructImpl::addStaticField(char const* name, std::size_t id, Type const& type, EFieldFlags flags,
inline StaticField* Struct::StructImpl::addStaticField(char const* name, std::size_t id, char const* canonicalTypeName, Type const& type, EFieldFlags flags,
Struct const* owner, void* fieldPtr, Struct const* outerEntity) noexcept
{
assert(name != nullptr);
assert((flags & EFieldFlags::Static) == EFieldFlags::Static);

//The hash is based on the static field name which is immutable, so it's safe to const_cast to update other members.
return const_cast<StaticField*>(&*_staticFields.emplace(name, id, type, flags, owner, fieldPtr, outerEntity));
return const_cast<StaticField*>(&*_staticFields.emplace(name, id, canonicalTypeName, type, flags, owner, fieldPtr, outerEntity));
}

inline StaticField* Struct::StructImpl::addStaticField(char const* name, std::size_t id, Type const& type, EFieldFlags flags,
inline StaticField* Struct::StructImpl::addStaticField(char const* name, std::size_t id, char const* canonicalTypeName, Type const& type, EFieldFlags flags,
Struct const* owner, void const* fieldPtr, Struct const* outerEntity) noexcept
{
assert(name != nullptr);
assert((flags & EFieldFlags::Static) == EFieldFlags::Static);

//The hash is based on the static field name which is immutable, so it's safe to const_cast to update other members.
return const_cast<StaticField*>(&*_staticFields.emplace(name, id, type, flags, owner, fieldPtr, outerEntity));
return const_cast<StaticField*>(&*_staticFields.emplace(name, id, canonicalTypeName, type, flags, owner, fieldPtr, outerEntity));
}

inline Method* Struct::StructImpl::addMethod(char const* name, std::size_t id, Type const& returnType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace rfk
public:
inline FieldBaseImpl(char const* name,
std::size_t id,
char const* canonicalTypeName,
Type const& type,
EFieldFlags flags,
Struct const* owner,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* See the LICENSE.md file for full license details.
*/

inline FieldBase::FieldBaseImpl::FieldBaseImpl(char const* name, std::size_t id, Type const& type, EFieldFlags flags, Struct const* owner, Entity const* outerEntity) noexcept:
VariableBaseImpl(name, id, EEntityKind::Field, type, outerEntity),
inline FieldBase::FieldBaseImpl::FieldBaseImpl(char const* name, std::size_t id, char const* canonicalTypeName, Type const& type, EFieldFlags flags, Struct const* owner, Entity const* outerEntity) noexcept:
VariableBaseImpl(name, id, EEntityKind::Field, canonicalTypeName, type, outerEntity),
_flags{flags},
_owner{owner}
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace rfk
public:
inline FieldImpl(char const* name,
std::size_t id,
char const* canonicalTypeName,
Type const& type,
EFieldFlags flags,
Struct const* owner,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
* See the LICENSE.md file for full license details.
*/

inline Field::FieldImpl::FieldImpl(char const* name, std::size_t id, Type const& type, EFieldFlags flags,
inline Field::FieldImpl::FieldImpl(char const* name, std::size_t id, char const* canonicalTypeName, Type const& type, EFieldFlags flags,
Struct const* owner, std::size_t memoryOffset, Entity const* outerEntity) noexcept:
FieldBaseImpl(name, id, type, flags, owner, outerEntity),
FieldBaseImpl(name, id, canonicalTypeName, type, flags, owner, outerEntity),
_memoryOffset{memoryOffset}
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@ namespace rfk
public:
inline StaticFieldImpl(char const* name,
std::size_t id,
Type const& type,
char const* canonicalTypeName,
Type const& type,
EFieldFlags flags,
Struct const* owner,
void* ptr,
Entity const* outerEntity) noexcept;
inline StaticFieldImpl(char const* name,
std::size_t id,
Type const& type,
char const* canonicalTypeName,
Type const& type,
EFieldFlags flags,
Struct const* owner,
void const* constPtr,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
*/


inline StaticField::StaticFieldImpl::StaticFieldImpl(char const* name, std::size_t id, Type const& type, EFieldFlags flags,
inline StaticField::StaticFieldImpl::StaticFieldImpl(char const* name, std::size_t id, char const* canonicalTypeName, Type const& type, EFieldFlags flags,
Struct const* owner, void* ptr, Entity const* outerEntity) noexcept:
FieldBaseImpl(name, id, type, flags, owner, outerEntity),
FieldBaseImpl(name, id, canonicalTypeName, type, flags, owner, outerEntity),
_ptr{ptr}
{
}

inline StaticField::StaticFieldImpl::StaticFieldImpl(char const* name, std::size_t id, Type const& type, EFieldFlags flags,
inline StaticField::StaticFieldImpl::StaticFieldImpl(char const* name, std::size_t id, char const* canonicalTypeName, Type const& type, EFieldFlags flags,
Struct const* owner, void const* constPtr, Entity const* outerEntity) noexcept:
FieldBaseImpl(name, id, type, flags, owner, outerEntity),
FieldBaseImpl(name, id, canonicalTypeName, type, flags, owner, outerEntity),
_constPtr{constPtr}
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,16 @@ namespace rfk
/** Type of this variable. */
Type const& _type;

/**
* Name of this variable's type simplified by unwinding all aliases, typedefs.
*/
std::string _canonicalTypeName;

public:
inline VariableBaseImpl(char const* name,
std::size_t id,
EEntityKind kind,
char const* canonicalTypeName,
Type const& type,
Entity const* outerEntity) noexcept;

Expand All @@ -30,7 +36,14 @@ namespace rfk
*
* @return _type.
*/
inline Type const& getType() const noexcept;
inline Type const& getType() const noexcept;

/**
* @brief Getter for the field _canonicalTypeName.
*
* @return _canonicalTypeName.
*/
inline char const* getCanonicalTypeName() const noexcept;
};

#include "Refureku/TypeInfo/Variables/VariableBaseImpl.inl"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@
* See the LICENSE.md file for full license details.
*/

inline VariableBase::VariableBaseImpl::VariableBaseImpl(char const* name, std::size_t id, EEntityKind kind, Type const& type, Entity const* outerEntity) noexcept:
inline VariableBase::VariableBaseImpl::VariableBaseImpl(char const* name, std::size_t id, EEntityKind kind, char const* canonicalTypeName, Type const& type, Entity const* outerEntity) noexcept:
EntityImpl(name, id, kind, outerEntity),
_type{type}
_type{type},
_canonicalTypeName{canonicalTypeName}
{
}

inline Type const& VariableBase::VariableBaseImpl::getType() const noexcept
{
return _type;
}

inline char const* VariableBase::VariableBaseImpl::getCanonicalTypeName() const noexcept
{
return _canonicalTypeName.data();
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ namespace rfk
public:
inline VariableImpl(char const* name,
std::size_t id,
Type const& type,
char const* canonicalTypeName,
Type const& type,
void* ptr,
EVarFlags flags) noexcept;
inline VariableImpl(char const* name,
std::size_t id,
Type const& type,
char const* canonicalTypeName,
Type const& type,
void const* constPtr,
EVarFlags flags) noexcept;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
* See the LICENSE.md file for full license details.
*/

inline Variable::VariableImpl::VariableImpl(char const* name, std::size_t id, Type const& type, void* ptr, EVarFlags flags) noexcept:
VariableBaseImpl(name, id, EEntityKind::Variable, type, nullptr),
inline Variable::VariableImpl::VariableImpl(char const* name, std::size_t id, char const* canonicalTypeName, Type const& type, void* ptr, EVarFlags flags) noexcept:
VariableBaseImpl(name, id, EEntityKind::Variable, canonicalTypeName, type, nullptr),
_flags{flags},
_ptr{ptr}
{
}

inline Variable::VariableImpl::VariableImpl(char const* name, std::size_t id, Type const& type, void const* constPtr, EVarFlags flags) noexcept:
VariableBaseImpl(name, id, EEntityKind::Variable, type, nullptr),
inline Variable::VariableImpl::VariableImpl(char const* name, std::size_t id, char const* canonicalTypeName, Type const& type, void const* constPtr, EVarFlags flags) noexcept:
VariableBaseImpl(name, id, EEntityKind::Variable, canonicalTypeName, type, nullptr),
_flags{flags},
_constPtr{constPtr}
{
Expand Down
2 changes: 1 addition & 1 deletion Refureku/Library/Include/Public/Refureku/Object.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace rfk
Object(Object&&) = default;
virtual ~Object() = default;

virtual Struct const& getArchetype() const noexcept = 0;
virtual Struct const& getArchetype() const noexcept;

Object& operator=(Object const&) = default;
Object& operator=(Object&&) = default;
Expand Down
Loading