diff --git a/Analyser/Static/Acorn/Target.hpp b/Analyser/Static/Acorn/Target.hpp index 556468fbd..d99a2dfcb 100644 --- a/Analyser/Static/Acorn/Target.hpp +++ b/Analyser/Static/Acorn/Target.hpp @@ -40,6 +40,10 @@ struct ArchimedesTarget: public ::Analyser::Static::Target, public Reflection::S std::string main_program; ArchimedesTarget() : Analyser::Static::Target(Machine::Archimedes) {} + +private: + friend Reflection::StructImpl; + void declare_fields() {} }; } diff --git a/OSBindings/Mac/Clock Signal.xcodeproj/xcshareddata/xcschemes/Clock Signal.xcscheme b/OSBindings/Mac/Clock Signal.xcodeproj/xcshareddata/xcschemes/Clock Signal.xcscheme index dbea90fe3..1dec5b8a5 100644 --- a/OSBindings/Mac/Clock Signal.xcodeproj/xcshareddata/xcschemes/Clock Signal.xcscheme +++ b/OSBindings/Mac/Clock Signal.xcodeproj/xcshareddata/xcschemes/Clock Signal.xcscheme @@ -24,8 +24,8 @@ diff --git a/Reflection/Struct.hpp b/Reflection/Struct.hpp index 67b76288e..a367d69a7 100644 --- a/Reflection/Struct.hpp +++ b/Reflection/Struct.hpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -150,6 +151,13 @@ template Type get(const Struct &target, const std::string &name, template class StructImpl: public Struct { public: + StructImpl() { + static std::once_flag once; + std::call_once(once, [this] { + static_cast(this)->declare_fields(); + }); + } + /*! @returns the value of type @c Type that is loaded from the offset registered for the field @c name. It is the caller's responsibility to provide an appropriate type of data. @@ -344,15 +352,6 @@ private: }; static inline std::unordered_map contents_; static inline std::unordered_map> permitted_enum_values_; - - // Ensure fields are declared at startup. - struct Declarer { - Declarer() { - Owner o; - o.declare_fields(); - } - }; - static Declarer declarer; };