@@ -185,17 +185,19 @@ class REPL_EXTERNAL_VISIBILITY Value final {
185
185
}
186
186
REPL_BUILTIN_TYPES
187
187
#undef X
188
+
189
+ Builtins (const Builtins &) = delete ;
190
+ Builtins &operator =(const Builtins &) = delete ;
188
191
};
189
192
190
193
// / Represents an array of `Value` elements.
191
194
struct ArrValue {
192
- std::vector< Value> Elements;
195
+ Value * Elements;
193
196
uint64_t ArrSize;
194
- ArrValue (uint64_t Size) : ArrSize(Size) {
195
- Elements.reserve (ArrSize);
196
- for (uint64_t I = 0 ; I < ArrSize; ++I)
197
- Elements.emplace_back ();
198
- }
197
+ ArrValue (uint64_t Size) : Elements(new Value[Size]), ArrSize(Size) {}
198
+ ~ArrValue () { delete[] Elements; }
199
+ ArrValue (const ArrValue &) = delete ;
200
+ ArrValue &operator =(const ArrValue &) = delete ;
199
201
};
200
202
201
203
// / Represents a pointer. Holds the address and optionally a pointee `Value`.
@@ -207,13 +209,37 @@ class REPL_EXTERNAL_VISIBILITY Value final {
207
209
if (Pointee != nullptr )
208
210
delete Pointee;
209
211
}
212
+
213
+ PtrValue (const PtrValue &) = delete ;
214
+ PtrValue &operator =(const PtrValue &) = delete ;
210
215
};
211
216
212
217
// / Represents a string value (wrapper over std::string).
213
218
struct StrValue {
214
- std::string StringBuf;
215
- StrValue (std::string str) : StringBuf(std::move(str)) {}
216
- ~StrValue () = default ;
219
+ char *Buf;
220
+ size_t Length;
221
+
222
+ StrValue (const char *Str) {
223
+ Length = strlen (Str);
224
+ Buf = new char [Length + 1 ];
225
+ memcpy (Buf, Str, Length);
226
+ Buf[Length] = ' \0 ' ;
227
+ }
228
+
229
+ ~StrValue () { delete[] Buf; }
230
+
231
+ StrValue (const StrValue &) = delete ;
232
+ StrValue &operator =(const StrValue &) = delete ;
233
+
234
+ void set (const char *Str) {
235
+ delete[] Buf;
236
+ Length = strlen (Str);
237
+ Buf = new char [Length + 1 ];
238
+ memcpy (Buf, Str, Length);
239
+ Buf[Length] = ' \0 ' ;
240
+ }
241
+
242
+ const char *get () const { return Buf; }
217
243
};
218
244
219
245
public:
@@ -230,7 +256,7 @@ class REPL_EXTERNAL_VISIBILITY Value final {
230
256
std::optional<ValueCleanup> Cleanup = std::nullopt ;
231
257
232
258
public:
233
- Value () = default ;
259
+ Value () : VKind(K_None) {}
234
260
explicit Value (QualType Ty) : Ty(Ty), VKind(K_None) {}
235
261
Value (const Value &RHS);
236
262
Value (Value &&RHS)
@@ -335,23 +361,18 @@ class REPL_EXTERNAL_VISIBILITY Value final {
335
361
// ---- String accessors ----
336
362
void setStrVal (const char *buf) {
337
363
assert (isStr () && " Not a Str" );
338
- asStr ().StringBuf = buf;
339
- }
340
-
341
- StringRef getStrVal () {
342
- assert (isStr () && " Not a Str" );
343
- return StringRef (asStr ().StringBuf );
364
+ asStr ().set (buf);
344
365
}
345
366
346
- const StringRef getStrVal () const {
367
+ const char * getStrVal () const {
347
368
assert (isStr () && " Not a Str" );
348
- return StringRef ( asStr ().StringBuf );
369
+ return asStr ().get ( );
349
370
}
350
371
351
372
// ---- Array accessors ----
352
373
uint64_t getArraySize () const { return asArray ().ArrSize ; }
353
374
354
- uint64_t getArrayInitializedElts () const { return asArray ().Elements . size () ; }
375
+ uint64_t getArrayInitializedElts () const { return asArray ().ArrSize ; }
355
376
356
377
Value &getArrayInitializedElt (unsigned I) {
357
378
assert (isArray () && " Invalid accessor" );
@@ -427,7 +448,7 @@ class REPL_EXTERNAL_VISIBILITY Value final {
427
448
VKind = K_Pointer;
428
449
}
429
450
430
- void MakeStr (std::string Str = " " ) {
451
+ void MakeStr (const char *Str ) {
431
452
assert (isAbsent () && " Bad state change" );
432
453
new ((void *)(char *)&Data) StrValue (Str);
433
454
VKind = K_Str;
0 commit comments