1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
#pragma once
#include "Core/Str.h"
#include "Type.h"
#include "Template.h"
namespace storm {
STORM_PKG(core.lang);
class EnumValue;
// Create regular enum.
Type *createEnum(Str *name, Size size, GcType *type);
// Create enum usable as a bitmask.
Type *createBitmaskEnum(Str *name, Size size, GcType *type);
/**
* Type for Enums from C++.
*/
class Enum : public Type {
STORM_CLASS;
public:
STORM_CTOR Enum(Str *name, Bool bitmask);
Enum(Str *name, GcType *type, Bool bitmask);
// Add new entries.
virtual void STORM_FN add(Named *n);
// Do we support bitwise operators?
inline Bool STORM_FN bitmask() const { return mask; }
// Late init.
virtual void lateInit();
// Generic to string for an enum.
void CODECALL toString(StrBuf *to, Nat v);
// Output.
virtual void STORM_FN toS(StrBuf *to) const;
protected:
// Load members.
virtual Bool STORM_FN loadAll();
// We're an integer.
virtual code::TypeDesc *STORM_FN createTypeDesc() { return code::intDesc(engine); }
private:
// Shall we support bitmask operators?
Bool mask;
// All values contained in here.
Array<EnumValue *> *values;
// Create the write function required for serialization.
Function *createWriteFn(SerializedType *type);
// Create the read function required for serialization.
Function *createReadFn();
// Create the read ctor required for serialization.
Function *createReadCtor();
// Create the toS function.
Function *createToS();
};
/**
* Enum value. Represented as an inline function.
*
* TODO: Implement as a kind of variable instead?
*/
class EnumValue : public Function {
STORM_CLASS;
public:
STORM_CTOR EnumValue(Enum *owner, Str *name, Nat value);
// The value.
Nat value;
// Output.
virtual void STORM_FN toS(StrBuf *to) const;
private:
// Generate code.
void CODECALL generate(InlineParams p);
};
}
|