1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-06-25 18:30:07 +00:00

Starts working towards a registration-based model of reflective enums.

This commit is contained in:
Thomas Harte 2020-03-09 22:05:31 -04:00
parent a99bb3ba6d
commit ce80825abb
5 changed files with 55 additions and 17 deletions

View File

@ -10,24 +10,21 @@
#define Analyser_Static_Macintosh_Target_h
#include "../../../Reflection/Enum.h"
#include "../../../Reflection/Struct.h"
namespace Analyser {
namespace Static {
namespace Macintosh {
struct Target: public ::Analyser::Static::Target {
ReflectiveEnum(Model, int, Mac128k, Mac512k, Mac512ke, MacPlus);
struct Target: public ::Analyser::Static::Target, public Reflection::Struct<Target> {
ReflectableEnum(Model, int, Mac128k, Mac512k, Mac512ke, MacPlus);
Target() {
// Model m;
// printf("%s\n", __declaration(m));
printf("%zu\n", Reflection::Enum<Model>::size());
// for(size_t c = 0; c < Reflection::Enum<Model>::size(); ++c) {
// const auto name = Reflection::Enum<Model>::toString(Model(c));
// printf("%.*s\n", int(name.size()), name.data());
// }
// Boilerplate for declaring fields and potential values.
if(needs_declare()) {
declare(&model, "model");
declare_enum(&model, EnumDeclaration(Model));
}
}
Model model = Model::MacPlus;
@ -37,5 +34,4 @@ struct Target: public ::Analyser::Static::Target {
}
}
#endif /* Analyser_Static_Macintosh_Target_h */

View File

@ -51,6 +51,9 @@ namespace {
constexpr int CLOCK_RATE = 7833600;
Analyser::Static::Macintosh::Target nothing;
}
namespace Apple {

View File

@ -1040,6 +1040,8 @@
4B38F3471F2EC11D00D9235D /* AmstradCPC.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = AmstradCPC.hpp; path = AmstradCPC/AmstradCPC.hpp; sourceTree = "<group>"; };
4B3940E51DA83C8300427841 /* AsyncTaskQueue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = AsyncTaskQueue.cpp; path = ../../Concurrency/AsyncTaskQueue.cpp; sourceTree = "<group>"; };
4B3940E61DA83C8300427841 /* AsyncTaskQueue.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = AsyncTaskQueue.hpp; path = ../../Concurrency/AsyncTaskQueue.hpp; sourceTree = "<group>"; };
4B3AF7D02413470E00873C0B /* Enum.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Enum.h; sourceTree = "<group>"; };
4B3AF7D12413472200873C0B /* Struct.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Struct.h; sourceTree = "<group>"; };
4B3BA0C21D318AEB005DD7A7 /* C1540Tests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = C1540Tests.swift; sourceTree = "<group>"; };
4B3BA0C51D318B44005DD7A7 /* C1540Bridge.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = C1540Bridge.h; sourceTree = "<group>"; };
4B3BA0C61D318B44005DD7A7 /* C1540Bridge.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = C1540Bridge.mm; sourceTree = "<group>"; };
@ -1138,7 +1140,6 @@
4B643F3C1D77AE5C00D431D6 /* CSMachine+Target.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "CSMachine+Target.h"; sourceTree = "<group>"; };
4B643F3E1D77B88000D431D6 /* DocumentController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DocumentController.swift; sourceTree = "<group>"; };
4B644ED023F0FB55006C0CC5 /* ScanSynchroniser.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = ScanSynchroniser.hpp; sourceTree = "<group>"; };
4B644ED123FAF162006C0CC5 /* Enum.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = Enum.h; path = ../../Reflection/Enum.h; sourceTree = "<group>"; };
4B65085F22F4CF8D009C1100 /* Keyboard.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = Keyboard.cpp; sourceTree = "<group>"; };
4B670A832401CB8400D4E002 /* z80memptr.tap */ = {isa = PBXFileReference; lastKnownFileType = file; path = z80memptr.tap; sourceTree = "<group>"; };
4B670A852401CB8400D4E002 /* z80ccf.tap */ = {isa = PBXFileReference; lastKnownFileType = file; path = z80ccf.tap; sourceTree = "<group>"; };
@ -2195,6 +2196,16 @@
name = Concurrency;
sourceTree = "<group>";
};
4B3AF7CF2413470E00873C0B /* Reflection */ = {
isa = PBXGroup;
children = (
4B3AF7D02413470E00873C0B /* Enum.h */,
4B3AF7D12413472200873C0B /* Struct.h */,
);
name = Reflection;
path = ../../Reflection;
sourceTree = "<group>";
};
4B3BA0C41D318B44005DD7A7 /* Bridges */ = {
isa = PBXGroup;
children = (
@ -3247,7 +3258,6 @@
4BB73E951B587A5100552FC2 = {
isa = PBXGroup;
children = (
4B644ED123FAF162006C0CC5 /* Enum.h */,
4BC76E6A1C98F43700E6EF73 /* Accelerate.framework */,
4B51F70820A521D700AFA2C1 /* Activity */,
4B8944E2201967B4007DE474 /* Analyser */,
@ -3265,6 +3275,7 @@
4B366DFD1B5C165F0026627B /* Outputs */,
4BB73EDD1B587CA500552FC2 /* Processors */,
4BB73E9F1B587A5100552FC2 /* Products */,
4B3AF7CF2413470E00873C0B /* Reflection */,
4B055A7B1FAE84A50060FFFF /* SDL */,
4B2409591C45DF85004DA684 /* SignalProcessing */,
4B69FB391C4D908A00B5F0AA /* Storage */,

View File

@ -10,9 +10,17 @@
#define Enum_h
#include <cctype>
#include <string>
namespace Reflection {
#define ReflectableEnum(Name, Type, ...) \
enum class Name: Type { Mac128k, Mac512k, Mac512ke, MacPlus }; \
constexpr static const char *__declaration##Name = #__VA_ARGS__;
#define EnumDeclaration(Name) __declaration##Name
template <typename EnumType> struct Enum {
static size_t size() {
return members().size();
@ -69,8 +77,16 @@ template <typename EnumType> struct Enum {
Enum members must take default values, and this enum must be in the global scope.
*/
#define ReflectiveEnum(Name, Type, ...) \
enum class Name: Type { __VA_ARGS__ }; \
constexpr const char *__declaration(Name) { return #__VA_ARGS__; }
//#define DefX #define X
//#define ForwardDeclareReflectiveEnum(Namespace, Name, ...) \
// #define HAT
// DeclName(m) m(__VA_ARGS__)
// constexpr const char *__declaration(Namespace::Name) { return __VA_ARGS__; }
//#define DefineReflectiveEnum(Name, Type) \
// enum class Name: Type { Mac128k, Mac512k, Mac512ke, MacPlus };
#endif /* Enum_h */

View File

@ -57,6 +57,10 @@ template <typename Owner> class Struct {
to determine whether a class of this type has already established the
reflective fields.
*/
/*!
Exposes the field pointed to by @c t for reflection as @c name.
*/
template <typename Type> void declare(Type *t, const std::string &name) {
contents_.emplace(
std::make_pair(
@ -65,6 +69,14 @@ template <typename Owner> class Struct {
));
}
/*!
Provides the original declaration of an enum.
*/
template <typename Type> void declare_enum(Type *t, const char *declaration) {
// TODO: something.
printf("%s\n", declaration);
}
/*!
@returns @c true if this
*/