forked from sorbet/sorbet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTrees.h
685 lines (558 loc) · 24.4 KB
/
Trees.h
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
#ifndef SORBET_TREES_H
#define SORBET_TREES_H
#include "common/common.h"
#include "core/Context.h"
#include "core/LocalVariable.h"
#include "core/SymbolRef.h"
#include "core/Types.h"
#include <memory>
#include <vector>
//
// This file defines the IR that most of the middle phases of Sorbet operate on
// and manipulate. It aims to be a middle ground between the parser output
// (very verbose and fine grained) and the CFG data structure (very easy to
// typecheck but very hard to do ad-hoc transformations on).
//
// This IR is best learned by example. Try using the `--print` option to sorbet
// on a handful of test/testdata files. Since there are multiple phases that
// return this IR, there are multiple valid print options which will show you
// an ast::Expression.
//
// Another good way to discover things is to grep for the class name in the
// various *-raw.exp snapshot tests to fine a test file that uses that node.
// Keep in mind that this IR is meant to be somewhat coarse grained, so one
// node type can likely have been created from multiple Ruby constructs.
//
namespace sorbet::ast {
class Expression {
public:
Expression(core::LocOffsets loc);
virtual ~Expression() = default;
virtual std::string toStringWithTabs(const core::GlobalState &gs, int tabs = 0) const = 0;
std::string toString(const core::GlobalState &gs) const {
return toStringWithTabs(gs);
}
virtual std::string nodeName() = 0;
virtual std::string showRaw(const core::GlobalState &gs, int tabs = 0) = 0;
std::unique_ptr<Expression> deepCopy() const;
virtual void _sanityCheck() = 0;
const core::LocOffsets loc;
class DeepCopyError {};
// This function should be private but it makes it hard to access from template methods in TreeCopy.cc
virtual std::unique_ptr<Expression> _deepCopy(const Expression *avoid, bool root = false) const = 0;
bool isSelfReference() const;
};
CheckSize(Expression, 16, 8);
struct ParsedFile {
std::unique_ptr<ast::Expression> tree;
core::FileRef file;
};
/**
* Stores a vector of `ParsedFile`s. May be empty if pass was canceled or encountered an error.
* TODO: Modify to store reason if we ever have multiple reasons for a pass to stop. Currently, it's only empty if the
* pass is canceled in LSP mode.
*/
class ParsedFilesOrCancelled final {
private:
std::optional<std::vector<ParsedFile>> trees;
public:
ParsedFilesOrCancelled();
ParsedFilesOrCancelled(std::vector<ParsedFile> &&trees);
bool hasResult() const;
std::vector<ParsedFile> &result();
};
template <class To> To *cast_tree(Expression *what) {
static_assert(!std::is_pointer<To>::value, "To has to be a pointer");
static_assert(std::is_assignable<Expression *&, To *>::value, "Ill Formed To, has to be a subclass of Expression");
return fast_cast<Expression, To>(what);
}
// A variant of cast_tree that preserves the const-ness (if const in, then const out)
template <class To> const To *cast_tree_const(const Expression *what) {
static_assert(!std::is_pointer<To>::value, "To has to be a pointer");
static_assert(std::is_assignable<Expression *&, To *>::value, "Ill Formed To, has to be a subclass of Expression");
return fast_cast<Expression, To>(const_cast<Expression *>(what));
}
template <class To> bool isa_tree(Expression *what) {
return cast_tree<To>(what) != nullptr;
}
class Reference : public Expression {
public:
Reference(core::LocOffsets loc);
};
CheckSize(Reference, 16, 8);
class Declaration : public Expression {
public:
core::Loc declLoc;
core::SymbolRef symbol;
Declaration(core::LocOffsets loc, core::Loc declLoc, core::SymbolRef symbol);
};
CheckSize(Declaration, 32, 8);
class ClassDef final : public Declaration {
public:
enum class Kind : u1 {
Module,
Class,
};
Kind kind;
static constexpr int EXPECTED_RHS_COUNT = 4;
using RHS_store = InlinedVector<std::unique_ptr<Expression>, EXPECTED_RHS_COUNT>;
RHS_store rhs;
std::unique_ptr<Expression> name;
// For unresolved names. Once they are typeAlias to Symbols they go into the Symbol
static constexpr int EXPECTED_ANCESTORS_COUNT = 2;
using ANCESTORS_store = InlinedVector<std::unique_ptr<Expression>, EXPECTED_ANCESTORS_COUNT>;
ANCESTORS_store ancestors;
ANCESTORS_store singletonAncestors;
ClassDef(core::LocOffsets loc, core::Loc declLoc, core::SymbolRef symbol, std::unique_ptr<Expression> name,
ANCESTORS_store ancestors, RHS_store rhs, ClassDef::Kind kind);
virtual std::string toStringWithTabs(const core::GlobalState &gs, int tabs = 0) const;
virtual std::string showRaw(const core::GlobalState &gs, int tabs = 0);
virtual std::string nodeName();
virtual std::unique_ptr<Expression> _deepCopy(const Expression *avoid, bool root = false) const;
private:
virtual void _sanityCheck();
};
CheckSize(ClassDef, 136, 8);
class MethodDef final : public Declaration {
public:
std::unique_ptr<Expression> rhs;
static constexpr int EXPECTED_ARGS_COUNT = 2;
using ARGS_store = InlinedVector<std::unique_ptr<Expression>, EXPECTED_ARGS_COUNT>;
ARGS_store args;
core::NameRef name;
struct Flags {
bool isSelfMethod : 1;
bool isRewriterSynthesized : 1;
// In C++20 we can replace this with bit field initialzers
Flags() : isSelfMethod(false), isRewriterSynthesized(false) {}
};
CheckSize(Flags, 1, 1);
Flags flags;
MethodDef(core::LocOffsets loc, core::Loc declLoc, core::SymbolRef symbol, core::NameRef name, ARGS_store args,
std::unique_ptr<Expression> rhs, Flags flags);
virtual std::string toStringWithTabs(const core::GlobalState &gs, int tabs = 0) const;
virtual std::string showRaw(const core::GlobalState &gs, int tabs = 0);
virtual std::string nodeName();
virtual std::unique_ptr<Expression> _deepCopy(const Expression *avoid, bool root = false) const;
private:
virtual void _sanityCheck();
};
CheckSize(MethodDef, 72, 8);
class If final : public Expression {
public:
std::unique_ptr<Expression> cond;
std::unique_ptr<Expression> thenp;
std::unique_ptr<Expression> elsep;
If(core::LocOffsets loc, std::unique_ptr<Expression> cond, std::unique_ptr<Expression> thenp,
std::unique_ptr<Expression> elsep);
virtual std::string toStringWithTabs(const core::GlobalState &gs, int tabs = 0) const;
virtual std::string showRaw(const core::GlobalState &gs, int tabs = 0);
virtual std::string nodeName();
virtual std::unique_ptr<Expression> _deepCopy(const Expression *avoid, bool root = false) const;
private:
virtual void _sanityCheck();
};
CheckSize(If, 40, 8);
class While final : public Expression {
public:
std::unique_ptr<Expression> cond;
std::unique_ptr<Expression> body;
While(core::LocOffsets loc, std::unique_ptr<Expression> cond, std::unique_ptr<Expression> body);
virtual std::string toStringWithTabs(const core::GlobalState &gs, int tabs = 0) const;
virtual std::string showRaw(const core::GlobalState &gs, int tabs = 0);
virtual std::string nodeName();
virtual std::unique_ptr<Expression> _deepCopy(const Expression *avoid, bool root = false) const;
private:
virtual void _sanityCheck();
};
CheckSize(While, 32, 8);
class Break final : public Expression {
public:
std::unique_ptr<Expression> expr;
Break(core::LocOffsets loc, std::unique_ptr<Expression> expr);
virtual std::string toStringWithTabs(const core::GlobalState &gs, int tabs = 0) const;
virtual std::string showRaw(const core::GlobalState &gs, int tabs = 0);
virtual std::string nodeName();
virtual std::unique_ptr<Expression> _deepCopy(const Expression *avoid, bool root = false) const;
private:
virtual void _sanityCheck();
};
CheckSize(Break, 24, 8);
class Retry final : public Expression {
public:
Retry(core::LocOffsets loc);
virtual std::string toStringWithTabs(const core::GlobalState &gs, int tabs = 0) const;
virtual std::string showRaw(const core::GlobalState &gs, int tabs = 0);
virtual std::string nodeName();
virtual std::unique_ptr<Expression> _deepCopy(const Expression *avoid, bool root = false) const;
private:
virtual void _sanityCheck();
};
CheckSize(Retry, 16, 8);
class Next final : public Expression {
public:
std::unique_ptr<Expression> expr;
Next(core::LocOffsets loc, std::unique_ptr<Expression> expr);
virtual std::string toStringWithTabs(const core::GlobalState &gs, int tabs = 0) const;
virtual std::string showRaw(const core::GlobalState &gs, int tabs = 0);
virtual std::string nodeName();
virtual std::unique_ptr<Expression> _deepCopy(const Expression *avoid, bool root = false) const;
private:
virtual void _sanityCheck();
};
CheckSize(Next, 24, 8);
class Return final : public Expression {
public:
std::unique_ptr<Expression> expr;
Return(core::LocOffsets loc, std::unique_ptr<Expression> expr);
virtual std::string toStringWithTabs(const core::GlobalState &gs, int tabs = 0) const;
virtual std::string showRaw(const core::GlobalState &gs, int tabs = 0);
virtual std::string nodeName();
virtual std::unique_ptr<Expression> _deepCopy(const Expression *avoid, bool root = false) const;
private:
virtual void _sanityCheck();
};
CheckSize(Return, 24, 8);
class RescueCase final : public Expression {
public:
static constexpr int EXPECTED_EXCEPTION_COUNT = 2;
using EXCEPTION_store = InlinedVector<std::unique_ptr<Expression>, EXPECTED_EXCEPTION_COUNT>;
EXCEPTION_store exceptions;
// If present, var is always an UnresolvedIdent[kind=Local] up until the
// namer, at which point it is a Local.
std::unique_ptr<Expression> var;
std::unique_ptr<Expression> body;
RescueCase(core::LocOffsets loc, EXCEPTION_store exceptions, std::unique_ptr<Expression> var,
std::unique_ptr<Expression> body);
virtual std::string toStringWithTabs(const core::GlobalState &gs, int tabs = 0) const;
virtual std::string showRaw(const core::GlobalState &gs, int tabs = 0);
virtual std::string nodeName();
virtual std::unique_ptr<Expression> _deepCopy(const Expression *avoid, bool root = false) const;
private:
virtual void _sanityCheck();
};
CheckSize(RescueCase, 56, 8);
class Rescue final : public Expression {
public:
static constexpr int EXPECTED_RESCUE_CASE_COUNT = 2;
using RESCUE_CASE_store = InlinedVector<std::unique_ptr<RescueCase>, EXPECTED_RESCUE_CASE_COUNT>;
std::unique_ptr<Expression> body;
RESCUE_CASE_store rescueCases;
std::unique_ptr<Expression> else_;
std::unique_ptr<Expression> ensure;
Rescue(core::LocOffsets loc, std::unique_ptr<Expression> body, RESCUE_CASE_store rescueCases,
std::unique_ptr<Expression> else_, std::unique_ptr<Expression> ensure);
virtual std::string toStringWithTabs(const core::GlobalState &gs, int tabs = 0) const;
virtual std::string showRaw(const core::GlobalState &gs, int tabs = 0);
virtual std::string nodeName();
virtual std::unique_ptr<Expression> _deepCopy(const Expression *avoid, bool root = false) const;
private:
virtual void _sanityCheck();
};
CheckSize(Rescue, 64, 8);
class Local final : public Reference {
public:
core::LocalVariable localVariable;
Local(core::LocOffsets loc, core::LocalVariable localVariable1);
virtual std::string toStringWithTabs(const core::GlobalState &gs, int tabs = 0) const;
virtual std::string showRaw(const core::GlobalState &gs, int tabs = 0);
virtual std::string nodeName();
virtual std::unique_ptr<Expression> _deepCopy(const Expression *avoid, bool root = false) const;
private:
virtual void _sanityCheck();
};
CheckSize(Local, 24, 8);
class UnresolvedIdent final : public Reference {
public:
enum class Kind : u1 {
Local,
Instance,
Class,
Global,
};
core::NameRef name;
Kind kind;
UnresolvedIdent(core::LocOffsets loc, Kind kind, core::NameRef name);
virtual std::string toStringWithTabs(const core::GlobalState &gs, int tabs = 0) const;
virtual std::string showRaw(const core::GlobalState &gs, int tabs = 0);
virtual std::string nodeName();
virtual std::unique_ptr<Expression> _deepCopy(const Expression *avoid, bool root = false) const;
private:
virtual void _sanityCheck();
};
CheckSize(UnresolvedIdent, 24, 8);
class RestArg final : public Reference {
public:
std::unique_ptr<Reference> expr;
RestArg(core::LocOffsets loc, std::unique_ptr<Reference> arg);
virtual std::string toStringWithTabs(const core::GlobalState &gs, int tabs = 0) const;
virtual std::string showRaw(const core::GlobalState &gs, int tabs = 0);
virtual std::string nodeName();
virtual std::unique_ptr<Expression> _deepCopy(const Expression *avoid, bool root = false) const;
private:
virtual void _sanityCheck();
};
CheckSize(RestArg, 24, 8);
class KeywordArg final : public Reference {
public:
std::unique_ptr<Reference> expr;
KeywordArg(core::LocOffsets loc, std::unique_ptr<Reference> expr);
virtual std::string toStringWithTabs(const core::GlobalState &gs, int tabs = 0) const;
virtual std::string showRaw(const core::GlobalState &gs, int tabs = 0);
virtual std::string nodeName();
virtual std::unique_ptr<Expression> _deepCopy(const Expression *avoid, bool root = false) const;
private:
virtual void _sanityCheck();
};
CheckSize(KeywordArg, 24, 8);
class OptionalArg final : public Reference {
public:
std::unique_ptr<Reference> expr;
std::unique_ptr<Expression> default_;
OptionalArg(core::LocOffsets loc, std::unique_ptr<Reference> expr, std::unique_ptr<Expression> default_);
virtual std::string toStringWithTabs(const core::GlobalState &gs, int tabs = 0) const;
virtual std::string showRaw(const core::GlobalState &gs, int tabs = 0);
virtual std::string nodeName();
virtual std::unique_ptr<Expression> _deepCopy(const Expression *avoid, bool root = false) const;
private:
virtual void _sanityCheck();
};
CheckSize(OptionalArg, 32, 8);
class BlockArg final : public Reference {
public:
std::unique_ptr<Reference> expr;
BlockArg(core::LocOffsets loc, std::unique_ptr<Reference> expr);
virtual std::string toStringWithTabs(const core::GlobalState &gs, int tabs = 0) const;
virtual std::string showRaw(const core::GlobalState &gs, int tabs = 0);
virtual std::string nodeName();
virtual std::unique_ptr<Expression> _deepCopy(const Expression *avoid, bool root = false) const;
private:
virtual void _sanityCheck();
};
CheckSize(BlockArg, 24, 8);
class ShadowArg final : public Reference {
public:
std::unique_ptr<Reference> expr;
ShadowArg(core::LocOffsets loc, std::unique_ptr<Reference> expr);
virtual std::string toStringWithTabs(const core::GlobalState &gs, int tabs = 0) const;
virtual std::string showRaw(const core::GlobalState &gs, int tabs = 0);
virtual std::string nodeName();
virtual std::unique_ptr<Expression> _deepCopy(const Expression *avoid, bool root = false) const;
private:
virtual void _sanityCheck();
};
CheckSize(ShadowArg, 24, 8);
class Assign final : public Expression {
public:
std::unique_ptr<Expression> lhs;
std::unique_ptr<Expression> rhs;
Assign(core::LocOffsets loc, std::unique_ptr<Expression> lhs, std::unique_ptr<Expression> rhs);
virtual std::string toStringWithTabs(const core::GlobalState &gs, int tabs = 0) const;
virtual std::string showRaw(const core::GlobalState &gs, int tabs = 0);
virtual std::string nodeName();
virtual std::unique_ptr<Expression> _deepCopy(const Expression *avoid, bool root = false) const;
private:
virtual void _sanityCheck();
};
CheckSize(Assign, 32, 8);
class Block;
class Send final : public Expression {
public:
core::NameRef fun;
struct Flags {
bool isPrivateOk : 1;
bool isRewriterSynthesized : 1;
// In C++20 we can replace this with bit field initialzers
Flags() : isPrivateOk(false), isRewriterSynthesized(false) {}
};
CheckSize(Flags, 1, 1);
Flags flags;
std::unique_ptr<Expression> recv;
static constexpr int EXPECTED_ARGS_COUNT = 2;
using ARGS_store = InlinedVector<std::unique_ptr<Expression>, EXPECTED_ARGS_COUNT>;
ARGS_store args;
std::unique_ptr<Block> block; // null if no block passed
Send(core::LocOffsets loc, std::unique_ptr<Expression> recv, core::NameRef fun, ARGS_store args,
std::unique_ptr<Block> block = nullptr, Flags flags = {});
virtual std::string toStringWithTabs(const core::GlobalState &gs, int tabs = 0) const;
virtual std::string showRaw(const core::GlobalState &gs, int tabs = 0);
virtual std::string nodeName();
virtual std::unique_ptr<Expression> _deepCopy(const Expression *avoid, bool root = false) const;
private:
virtual void _sanityCheck();
};
CheckSize(Send, 64, 8);
class Cast final : public Expression {
public:
// The name of the cast operator.
core::NameRef cast;
core::TypePtr type;
std::unique_ptr<Expression> arg;
Cast(core::LocOffsets loc, core::TypePtr ty, std::unique_ptr<Expression> arg, core::NameRef cast);
virtual std::string toStringWithTabs(const core::GlobalState &gs, int tabs = 0) const;
virtual std::string showRaw(const core::GlobalState &gs, int tabs = 0);
virtual std::string nodeName();
virtual std::unique_ptr<Expression> _deepCopy(const Expression *avoid, bool root = false) const;
private:
virtual void _sanityCheck();
};
CheckSize(Cast, 48, 8);
class Hash final : public Expression {
public:
static constexpr int EXPECTED_ENTRY_COUNT = 2;
using ENTRY_store = InlinedVector<std::unique_ptr<Expression>, EXPECTED_ENTRY_COUNT>;
ENTRY_store keys;
ENTRY_store values;
Hash(core::LocOffsets loc, ENTRY_store keys, ENTRY_store values);
virtual std::string toStringWithTabs(const core::GlobalState &gs, int tabs = 0) const;
virtual std::string showRaw(const core::GlobalState &gs, int tabs = 0);
virtual std::string nodeName();
virtual std::unique_ptr<Expression> _deepCopy(const Expression *avoid, bool root = false) const;
private:
virtual void _sanityCheck();
};
CheckSize(Hash, 64, 8);
class Array final : public Expression {
public:
static constexpr int EXPECTED_ENTRY_COUNT = 4;
using ENTRY_store = InlinedVector<std::unique_ptr<Expression>, EXPECTED_ENTRY_COUNT>;
ENTRY_store elems;
Array(core::LocOffsets loc, ENTRY_store elems);
virtual std::string toStringWithTabs(const core::GlobalState &gs, int tabs = 0) const;
virtual std::string showRaw(const core::GlobalState &gs, int tabs = 0);
virtual std::string nodeName();
virtual std::unique_ptr<Expression> _deepCopy(const Expression *avoid, bool root = false) const;
private:
virtual void _sanityCheck();
};
CheckSize(Array, 56, 8);
class Literal final : public Expression {
public:
core::TypePtr value;
Literal(core::LocOffsets loc, const core::TypePtr &value);
virtual std::string toStringWithTabs(const core::GlobalState &gs, int tabs = 0) const;
virtual std::string showRaw(const core::GlobalState &gs, int tabs = 0);
virtual std::string nodeName();
bool isString(const core::GlobalState &gs) const;
bool isSymbol(const core::GlobalState &gs) const;
bool isNil(const core::GlobalState &gs) const;
core::NameRef asString(const core::GlobalState &gs) const;
core::NameRef asSymbol(const core::GlobalState &gs) const;
bool isTrue(const core::GlobalState &gs) const;
bool isFalse(const core::GlobalState &gs) const;
virtual std::unique_ptr<Expression> _deepCopy(const Expression *avoid, bool root = false) const;
private:
virtual void _sanityCheck();
};
CheckSize(Literal, 32, 8);
class UnresolvedConstantLit final : public Expression {
public:
core::NameRef cnst;
std::unique_ptr<Expression> scope;
UnresolvedConstantLit(core::LocOffsets loc, std::unique_ptr<Expression> scope, core::NameRef cnst);
virtual std::string toStringWithTabs(const core::GlobalState &gs, int tabs = 0) const;
virtual std::string showRaw(const core::GlobalState &gs, int tabs = 0);
virtual std::string nodeName();
virtual std::unique_ptr<Expression> _deepCopy(const Expression *avoid, bool root = false) const;
private:
virtual void _sanityCheck();
};
CheckSize(UnresolvedConstantLit, 32, 8);
class ConstantLit final : public Expression {
public:
core::SymbolRef symbol; // If this is a normal constant. This symbol may be already dealiased.
// For constants that failed resolution, symbol will be set to StubModule and resolutionScopes
// will be set to whatever nesting scope we estimate the constant could have been defined in.
using ResolutionScopes = InlinedVector<core::SymbolRef, 1>;
ResolutionScopes resolutionScopes;
std::unique_ptr<UnresolvedConstantLit> original;
ConstantLit(core::LocOffsets loc, core::SymbolRef symbol, std::unique_ptr<UnresolvedConstantLit> original);
virtual std::string toStringWithTabs(const core::GlobalState &gs, int tabs = 0) const;
virtual std::string showRaw(const core::GlobalState &gs, int tabs = 0);
virtual std::string nodeName();
virtual std::unique_ptr<Expression> _deepCopy(const Expression *avoid, bool root = false) const;
std::optional<std::pair<core::SymbolRef, std::vector<core::NameRef>>>
fullUnresolvedPath(const core::GlobalState &gs) const;
private:
virtual void _sanityCheck();
};
CheckSize(ConstantLit, 56, 8);
class ZSuperArgs final : public Expression {
public:
// null if no block passed
ZSuperArgs(core::LocOffsets loc);
virtual std::string toStringWithTabs(const core::GlobalState &gs, int tabs = 0) const;
virtual std::string showRaw(const core::GlobalState &gs, int tabs = 0);
virtual std::string nodeName();
virtual std::unique_ptr<Expression> _deepCopy(const Expression *avoid, bool root = false) const;
private:
virtual void _sanityCheck();
};
CheckSize(ZSuperArgs, 16, 8);
class Block final : public Expression {
public:
MethodDef::ARGS_store args;
std::unique_ptr<Expression> body;
Block(core::LocOffsets loc, MethodDef::ARGS_store args, std::unique_ptr<Expression> body);
virtual std::string toStringWithTabs(const core::GlobalState &gs, int tabs = 0) const;
virtual std::string showRaw(const core::GlobalState &gs, int tabs = 0);
virtual std::string nodeName();
virtual std::unique_ptr<Expression> _deepCopy(const Expression *avoid, bool root = false) const;
virtual void _sanityCheck();
};
CheckSize(Block, 48, 8);
class InsSeq final : public Expression {
public:
static constexpr int EXPECTED_STATS_COUNT = 4;
using STATS_store = InlinedVector<std::unique_ptr<Expression>, EXPECTED_STATS_COUNT>;
// Statements
STATS_store stats;
// The distinguished final expression (determines return value)
std::unique_ptr<Expression> expr;
InsSeq(core::LocOffsets locOffsets, STATS_store stats, std::unique_ptr<Expression> expr);
virtual std::string toStringWithTabs(const core::GlobalState &gs, int tabs = 0) const;
virtual std::string showRaw(const core::GlobalState &gs, int tabs = 0);
virtual std::string nodeName();
virtual std::unique_ptr<Expression> _deepCopy(const Expression *avoid, bool root = false) const;
private:
virtual void _sanityCheck();
};
CheckSize(InsSeq, 64, 8);
class EmptyTree final : public Expression {
public:
EmptyTree();
virtual std::string toStringWithTabs(const core::GlobalState &gs, int tabs = 0) const;
virtual std::string showRaw(const core::GlobalState &gs, int tabs = 0);
virtual std::string nodeName();
virtual std::unique_ptr<Expression> _deepCopy(const Expression *avoid, bool root = false) const;
private:
virtual void _sanityCheck();
};
CheckSize(EmptyTree, 16, 8);
/** https://git.corp.stripe.com/gist/nelhage/51564501674174da24822e60ad770f64
*
* [] - prototype only
*
* / Control Flow <- while, if, for, break, next, retry, return, rescue, case
* Pre-CFG-Node <-
* \ Instruction <- assign, send, [new], ident, named_arg, hash, array, literals(symbols, ints, floats,
* strings, constants, nil), constants(resolver will desugar it into literals), array_splat(*), hash_splat(**), self,
* insseq, Block)
*
* \ Definition <- class(name, parent, mixins, body)
* module
* def
* defself
* const_assign
*
*
*
* know id for: top, bottom, kernel?, basicobject, class, module [postponed], unit, Hash, Array, String, Symbol, float,
* int, numeric, double, unknown
*
*
*
* Desugar string concatenation into series of .to_s calls and string concatenations
*/
} // namespace sorbet::ast
#endif // SORBET_TREES_H