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

No fields found in struct #4

Closed
exuvo opened this issue Apr 26, 2021 · 8 comments
Closed

No fields found in struct #4

exuvo opened this issue Apr 26, 2021 · 8 comments

Comments

@exuvo
Copy link

exuvo commented Apr 26, 2021

The generator runs with no errors but the resulting rfk.h does not contain any references to the field my struct has, only the base struct name. What am i missing?

Ex rfk::Struct const & s = CircleComponent::staticGetArchetype(); s.fields.size() is zero. s.memorySize however is 4 as i expect.

I am on linux building refureku as a subproject in cmake from source with gcc 10.2.0. RefurekuSettings is set using cmakes configure_file. I had to update the included libclang to my local libclang.so.11.1 as i have newer system libraries than what the older one was built against. I had to comment out the Library tests as it just keeps trying to use my projects RefurekuSettings.toml which obviously does not work for the tests. I can't even find the RefurekuSettings.toml for the tests so i was unable to fix that.

...
#include "refureku/SimpleComponents.rfk.h"
...
struct RFKStruct() CircleComponent {
		float radius = 1; // in m
		CircleComponent_GENERATED
};
...
File_GENERATED

Complete file if you want.

#pragma once

/**
*	Source file: /home/exuvo/code/Aurora-C/src/starsystems/components/SimpleComponents.hpp
*/

#include "EntityMacros.h"

#include <Refureku/Misc/DisableWarningMacros.h>
#include <Refureku/TypeInfo/Namespaces/Namespace.h>
#include <Refureku/TypeInfo/Namespaces/NamespaceFragment.h>
#include <Refureku/TypeInfo/Namespaces/NamespaceFragmentRegisterer.h>
#include <Refureku/TypeInfo/Archetypes/Class.h>
#include <Refureku/TypeInfo/Archetypes/Enum.h>
#include <Refureku/TypeInfo/Archetypes/ArchetypeRegisterer.h>
#include <Refureku/TypeInfo/Entity/DefaultEntityRegisterer.h>


#define __RFK8251021941809742048u_GenerateFieldsMetadata	\
	registerChild<CircleComponent>(&type);	\

#define __RFK8251021941809742048u_GenerateFieldHelperMethods	\
private:	\
	template <typename ParentType, typename ChildType>	\
	static constexpr void recurseRegisterChild([[maybe_unused]] rfk::Struct* childArchetype)	\
	{	\
		if constexpr (rfk::isReflectedClass<ParentType>)	\
		{	\
			ParentType::template registerChild<ChildType>(childArchetype);	\
		}	\
	}	\
public:	\
	template <typename ChildType>	\
	static void registerChild(rfk::Struct* childArchetype) noexcept	\
	{	\
		rfk::Struct const& thisArchetype = staticGetArchetype();	\
		if (childArchetype != &thisArchetype)	\
		{	\
			const_cast<rfk::Struct&>(thisArchetype).children.insert(childArchetype);	\
		}	\
	}

#define __RFK8251021941809742048u_GenerateMethodsMetadata	\

#define __RFK8251021941809742048u_GenerateArchetypeProperties	\
	

#define __RFK8251021941809742048u_GenerateDefaultInstantiatorSetup	\
	type.setDefaultInstantiator(&rfk::defaultInstantiator<CircleComponent>);

#define __RFK8251021941809742048u_GetTypeDeclaration	\
	__RFK8251021941809742048u_GenerateFieldHelperMethods	\
	public:	\
		inline static rfk::Struct const& staticGetArchetype() noexcept;	\
	

#ifdef KODGEN_PARSING
#define __RFK8251021941809742048u_GetTypeDefinition
#else
#define __RFK8251021941809742048u_GetTypeDefinition	\
		inline rfk::Struct const& CircleComponent::staticGetArchetype() noexcept	\
		{	\
			static bool			initialized = false;	\
			static rfk::Struct	type("CircleComponent", 8251021941809742048u, sizeof(CircleComponent));	\
			\
			if (!initialized)	\
			{	\
				initialized = true;	\
			\
				__RFK8251021941809742048u_GenerateArchetypeProperties	\
					\
					\
				__RFK8251021941809742048u_GenerateFieldsMetadata	\
				__RFK8251021941809742048u_GenerateDefaultInstantiatorSetup	\
				__RFK8251021941809742048u_GenerateMethodsMetadata	\
			}	\
			\
			return type;	\
		}

#endif
#define __RFK8251021941809742048u_RegisterArchetype	\
	private:	\
		static inline rfk::ArchetypeRegisterer __rfkArchetypeRegisterer = &staticGetArchetype();


#ifdef KODGEN_PARSING
#define CircleComponent_GENERATED
#else
#define CircleComponent_GENERATED	\
	friend rfk::Struct;	\
	friend rfk::hasField___rfkArchetypeRegisterer<CircleComponent, rfk::ArchetypeRegisterer>;	\
	__RFK8251021941809742048u_GetTypeDeclaration	\
	__RFK8251021941809742048u_RegisterArchetype	\
		\
	private:

#endif

#ifdef __RFKNativeProperties_GENERATED
	#undef __RFKNativeProperties_GENERATED
#endif

#define __RFKNativeProperties_GENERATED	\
	

#ifdef File_GENERATED
	#undef File_GENERATED
#endif
#define File_GENERATED	\
	__RFK8251021941809742048u_GetTypeDefinition	\
	__RFKNativeProperties_GENERATED	\



@jsoysouvanh
Copy link
Owner

Hi exuvo,

I think you are missing the RFKField() macro before the fields you want to reflect.
Try this

#include "refureku/SimpleComponents.rfk.h"
...
struct RFKStruct() CircleComponent
{
    RFKField()
    float radius = 1; // in m

    CircleComponent_GENERATED
};
...
File_GENERATED

Let me know if this fixes your problem.

@exuvo
Copy link
Author

exuvo commented Apr 26, 2021 via email

@jsoysouvanh
Copy link
Owner

Sure, you are probably looking for the ParseAllNested property.
Use it like this:

#include <Refureku/NativeProperties.h>

#include "refureku/SimpleComponents.rfk.h"
...
struct RFKStruct(ParseAllNested) CircleComponent
{
    float radius = 1; // in m

    CircleComponent_GENERATED
};
...
File_GENERATED

Let me know if this works out for you :)

@exuvo
Copy link
Author

exuvo commented Apr 26, 2021

Had to set(GEN_PROPERTY_RTTI ON) too for the linking but it is working now!

@exuvo exuvo closed this as completed Apr 26, 2021
@exuvo
Copy link
Author

exuvo commented Apr 26, 2021

Followup question: What is the best way to check the type of a field? Is field.type.archetype == rfk::getArchetype<float>() valid or should i be doing something else?

I see field.type which has a few is methods for some general information and its archetype->name has the literal name ex "float".

@jsoysouvanh
Copy link
Owner

The type of a field (class rfk::Type) is its archetype + all potential qualifiers (*, &, const, etc...).
Do you want to check the type (including its qualifiers), or the archetype, which is the class/struct/fundamental type without qualifiers?

For example if you want to check if your field is a float*, you'll use:

field.type == rfk::Type::getType<float*>()

If you just wanna compare the archetype (regardless of the field qualifiers), you can write:

field.type.archetype == rfk::getArchetype<float>()

By the way, the rfk::getArchetype method automatically discards all type qualifiers so:

field.type.archetype == rfk::getArchetype<float*>()

will also return true if your field is a simple float.

@exuvo
Copy link
Author

exuvo commented Apr 26, 2021

Ok thanks that clears everything up.

@jsoysouvanh
Copy link
Owner

You're very welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants