File: Enum.h

package info (click to toggle)
storm-lang 0.7.5-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 52,100 kB
  • sloc: ansic: 261,471; cpp: 140,438; sh: 14,891; perl: 9,846; python: 2,525; lisp: 2,504; asm: 860; makefile: 678; pascal: 70; java: 52; xml: 37; awk: 12
file content (89 lines) | stat: -rw-r--r-- 1,901 bytes parent folder | download | duplicates (2)
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);
	};

}