1
2
3
4
5
6 #ifndef CMAJOR_CMSXI_VALUE_INCLUDED
7 #define CMAJOR_CMSXI_VALUE_INCLUDED
8 #include <cmajor/cmsxi/CmsxiApi.hpp>
9 #include <vector>
10 #include <string>
11 #include <set>
12 #include <unordered_map>
13 #include <stdint.h>
14
15 namespace cmsxi {
16
17 class Type;
18 class PtrType;
19 class Context;
20 class GlobalVariable;
21
22 class Value
23 {
24 public:
25 Value();
26 virtual ~Value();
27 virtual Type* GetType(Context& context) = 0;
28 virtual std::string Name(Context& context) = 0;
29 virtual bool IsLongValue() const { return false; }
30 virtual bool IsAggregateValue() const { return false; }
31 virtual bool IsStringValue() const { return false; }
32 virtual void AddDependencies(GlobalVariable* variable, const std::std::unordered_map<std::string, GlobalVariable*>&nameMap, std::std::unordered_map<GlobalVariable*, std::std::set<GlobalVariable*>>&dependencies,
33 Context& context);
34 };
35
36 class ConstantValue : public Value
37 {
38 public:
39 std::string Name(Context& context) override { return "constant"; }
40 };
41
42 class BoolValue : public ConstantValue
43 {
44 public:
45 BoolValue();
46 BoolValue(bool value_);
47 Type* GetType(Context& context) override;
48 std::string Name(Context& context) override;
49 private:
50 bool value;
51 };
52
53 class SByteValue : public ConstantValue
54 {
55 public:
56 SByteValue();
57 SByteValue(int8_t value_);
58 Type* GetType(Context& context) override;
59 std::string Name(Context& context) override;
60 private:
61 int8_t value;
62 };
63
64 class ByteValue : public ConstantValue
65 {
66 public:
67 ByteValue();
68 ByteValue(uint8_t value_);
69 Type* GetType(Context& context) override;
70 std::string Name(Context& context) override;
71 private:
72 uint8_t value;
73 };
74
75 class ShortValue : public ConstantValue
76 {
77 public:
78 ShortValue();
79 ShortValue(int16_t value_);
80 Type* GetType(Context& context) override;
81 std::string Name(Context& context) override;
82 private:
83 int16_t value;
84 };
85
86 class UShortValue : public ConstantValue
87 {
88 public:
89 UShortValue();
90 UShortValue(uint16_t value_);
91 Type* GetType(Context& context) override;
92 std::string Name(Context& context) override;
93 private:
94 uint16_t value;
95 };
96
97 class IntValue : public ConstantValue
98 {
99 public:
100 IntValue();
101 IntValue(int32_t value_);
102 Type* GetType(Context& context) override;
103 std::string Name(Context& context) override;
104 private:
105 int32_t value;
106 };
107
108 class UIntValue : public ConstantValue
109 {
110 public:
111 UIntValue();
112 UIntValue(uint32_t value_);
113 Type* GetType(Context& context) override;
114 std::string Name(Context& context) override;
115 private:
116 uint32_t value;
117 };
118
119 class LongValue : public ConstantValue
120 {
121 public:
122 LongValue();
123 LongValue(int64_t value_);
124 Type* GetType(Context& context) override;
125 std::string Name(Context& context) override;
126 bool IsLongValue() const override { return true; }
127 int64_t GetValue() const { return value; }
128 private:
129 int64_t value;
130 };
131
132 class ULongValue : public ConstantValue
133 {
134 public:
135 ULongValue();
136 ULongValue(uint64_t value_);
137 Type* GetType(Context& context) override;
138 std::string Name(Context& context) override;
139 private:
140 uint64_t value;
141 };
142
143 class FloatValue : public ConstantValue
144 {
145 public:
146 FloatValue();
147 FloatValue(float value_);
148 Type* GetType(Context& context) override;
149 std::string Name(Context& context) override;
150 private:
151 float value;
152 };
153
154 class DoubleValue : public ConstantValue
155 {
156 public:
157 DoubleValue();
158 DoubleValue(double value_);
159 Type* GetType(Context& context) override;
160 std::string Name(Context& context) override;
161 private:
162 double value;
163 };
164
165 class NullValue : public ConstantValue
166 {
167 public:
168 NullValue(PtrType* ptrType_);
169 Type* GetType(Context& context) override;
170 std::string Name(Context& context) override;
171 private:
172 PtrType* ptrType;
173 };
174
175 class ArrayValue : public ConstantValue
176 {
177 public:
178 ArrayValue(Type* type_, const std::std::vector<ConstantValue*>&elements_, conststd::string&prefix_);
179 std::string Name(Context& context) override;
180 Type* GetType(Context& context) override { return type; }
181 void AddElement(ConstantValue* element);
182 bool IsAggregateValue() const override { return true; }
183 void AddDependencies(GlobalVariable* variable, const std::std::unordered_map<std::string, GlobalVariable*>&nameMap, std::std::unordered_map<GlobalVariable*, std::std::set<GlobalVariable*>>&dependencies,
184 Context& context) override;
185 private:
186 Type* type;
187 std::vector<ConstantValue*> elements;
188 std::string prefix;
189 };
190
191 class StructureValue : public ConstantValue
192 {
193 public:
194 StructureValue(Type* type_, const std::std::vector<ConstantValue*>&members_);
195 std::string Name(Context& context) override;
196 Type* GetType(Context& context) override;
197 void AddMember(ConstantValue* member);
198 bool IsAggregateValue() const override { return true; }
199 void AddDependencies(GlobalVariable* variable, const std::std::unordered_map<std::string, GlobalVariable*>&nameMap, std::std::unordered_map<GlobalVariable*, std::std::set<GlobalVariable*>>&dependencies,
200 Context& context) override;
201 private:
202 Type* type;
203 std::vector<ConstantValue*> members;
204 };
205
206 class StringValue : public ConstantValue
207 {
208 public:
209 StringValue(Type* type_, const std::string& value_);
210 std::string Name(Context& context) override;
211 Type* GetType(Context& context) override;
212 bool IsStringValue() const override { return true; }
213 private:
214 Type* type;
215 std::string value;
216 };
217
218 class ConversionValue : public ConstantValue
219 {
220 public:
221 ConversionValue(Type* type_, ConstantValue* from_);
222 std::string Name(Context& context) override;
223 Type* GetType(Context& context) override;
224 void AddDependencies(GlobalVariable* variable, const std::std::unordered_map<std::string, GlobalVariable*>&nameMap, std::std::unordered_map<GlobalVariable*, std::std::set<GlobalVariable*>>&dependencies,
225 Context& context) override;
226 private:
227 Type* type;
228 ConstantValue* from;
229 };
230
231 class ClsIdValue : public ConstantValue
232 {
233 public:
234 ClsIdValue(const std::string& typeId_);
235 std::string Name(Context& context) override;
236 Type* GetType(Context& context) override;
237 private:
238 std::string typeId;
239 };
240
241 }
242
243 #endif // CMAJOR_CMSXI_VALUE_INCLUDED