Repository navigation
Expand file tree
/
Copy pathast.cc
More file actions
813 lines (663 loc) · 19.5 KB
/
Copy pathast.cc
File metadata and controls
813 lines (663 loc) · 19.5 KB
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
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
#include "ast.h"
#include "code_gen.h"
#include "error.h"
#include "mem_pool.h"
#include "parser.h"
#include "token.h"
#include "evaluator.h"
static MemPoolImp<BinaryOp> binaryOpPool;
static MemPoolImp<ConditionalOp> conditionalOpPool;
static MemPoolImp<FuncCall> funcCallPool;
static MemPoolImp<Declaration> initializationPool;
static MemPoolImp<Object> objectPool;
static MemPoolImp<Identifier> identifierPool;
static MemPoolImp<Enumerator> enumeratorPool;
static MemPoolImp<Constant> constantPool;
static MemPoolImp<TempVar> tempVarPool;
static MemPoolImp<UnaryOp> unaryOpPool;
static MemPoolImp<EmptyStmt> emptyStmtPool;
static MemPoolImp<IfStmt> ifStmtPool;
static MemPoolImp<JumpStmt> jumpStmtPool;
static MemPoolImp<ReturnStmt> returnStmtPool;
static MemPoolImp<LabelStmt> labelStmtPool;
static MemPoolImp<CompoundStmt> compoundStmtPool;
static MemPoolImp<FuncDef> funcDefPool;
/*
* Accept
*/
void Declaration::Accept(Visitor* v)
{
v->VisitDeclaration(this);
}
void EmptyStmt::Accept(Visitor* v) {
//assert(false);
//v->VisitEmptyStmt(this);
}
void LabelStmt::Accept(Visitor* v) {
v->VisitLabelStmt(this);
}
void IfStmt::Accept(Visitor* v) {
v->VisitIfStmt(this);
}
void JumpStmt::Accept(Visitor* v) {
v->VisitJumpStmt(this);
}
void ReturnStmt::Accept(Visitor* v) {
v->VisitReturnStmt(this);
}
void CompoundStmt::Accept(Visitor* v) {
v->VisitCompoundStmt(this);
}
void BinaryOp::Accept(Visitor* v) {
v->VisitBinaryOp(this);
}
void UnaryOp::Accept(Visitor* v) {
v->VisitUnaryOp(this);
}
void ConditionalOp::Accept(Visitor* v) {
v->VisitConditionalOp(this);
}
void FuncCall::Accept(Visitor* v) {
v->VisitFuncCall(this);
}
void Object::Accept(Visitor* v) {
v->VisitObject(this);
}
void Constant::Accept(Visitor* v) {
v->VisitConstant(this);
}
void Enumerator::Accept(Visitor* v)
{
v->VisitEnumerator(this);
}
void TempVar::Accept(Visitor* v) {
v->VisitTempVar(this);
}
void FuncDef::Accept(Visitor* v) {
v->VisitFuncDef(this);
}
void TranslationUnit::Accept(Visitor* v) {
v->VisitTranslationUnit(this);
}
Expr* Expr::MayCast(Expr* expr)
{
auto arrType = expr->Type()->ToArrayType();
if (arrType) {
auto pointer = Type::NewPointerType(arrType->Derived());
pointer->SetQual(Q_CONST);
return UnaryOp::New(expr->Tok(), Token::CAST, expr, pointer);
}
auto funcType = expr->Type()->ToFuncType();
if (funcType) {
auto pointer = Type::NewPointerType(funcType);
return UnaryOp::New(expr->Tok(), Token::CAST, expr, pointer);
}
return expr;
}
BinaryOp* BinaryOp::New(const Token* tok, Expr* lhs, Expr* rhs)
{
return New(tok, tok->Tag(), lhs, rhs);
}
BinaryOp* BinaryOp::New(const Token* tok, int op, Expr* lhs, Expr* rhs)
{
switch (op) {
case ',':
case '.':
case '=':
case '*':
case '/':
case '%':
case '+':
case '-':
case '&':
case '^':
case '|':
case '<':
case '>':
case Token::LEFT_OP:
case Token::RIGHT_OP:
case Token::LE_OP:
case Token::GE_OP:
case Token::EQ_OP:
case Token::NE_OP:
case Token::AND_OP:
case Token::OR_OP:
break;
default:
assert(0);
}
auto ret = new (binaryOpPool.Alloc()) BinaryOp(op, lhs, rhs);
ret->_pool = &binaryOpPool;
ret->TypeChecking();
return ret;
}
ArithmType* BinaryOp::Promote(void)
{
// Both lhs and rhs are ensured to be have arithmetic type
auto lhsType = _lhs->Type()->ToArithmType();
auto rhsType = _rhs->Type()->ToArithmType();
auto type = MaxType(lhsType, rhsType);
if (lhsType != type) {// Pointer comparation is enough!
_lhs = UnaryOp::New(_tok, Token::CAST, _lhs, type);
}
if (rhsType != type) {
_rhs = UnaryOp::New(_tok, Token::CAST, _rhs, type);
}
return type;
}
/*
* Type checking
*/
void BinaryOp::TypeChecking(void)
{
switch (_op) {
case '.':
return MemberRefOpTypeChecking();
//case ']':
// return SubScriptingOpTypeChecking();
case '*':
case '/':
case '%':
return MultiOpTypeChecking();
case '+':
case '-':
return AdditiveOpTypeChecking();
case Token::LEFT_OP:
case Token::RIGHT_OP:
return ShiftOpTypeChecking();
case '<':
case '>':
case Token::LE_OP:
case Token::GE_OP:
return RelationalOpTypeChecking();
case Token::EQ_OP:
case Token::NE_OP:
return EqualityOpTypeChecking();
case '&':
case '^':
case '|':
return BitwiseOpTypeChecking();
case Token::AND_OP:
case Token::OR_OP:
return LogicalOpTypeChecking();
case '=':
return AssignOpTypeChecking();
default:
assert(0);
}
}
void BinaryOp::SubScriptingOpTypeChecking(void)
{
auto lhsType = _lhs->Type()->ToPointerType();
if (nullptr == lhsType) {
Error(_tok, "an pointer expected");
}
if (!_rhs->Type()->IsInteger()) {
Error(_tok, "the operand of [] should be intger");
}
// The type of [] operator is the derived type
_type = lhsType->Derived();
}
void BinaryOp::MemberRefOpTypeChecking(void)
{
_type = _rhs->Type();
}
void BinaryOp::MultiOpTypeChecking(void)
{
auto lhsType = _lhs->Type()->ToArithmType();
auto rhsType = _rhs->Type()->ToArithmType();
if (lhsType == nullptr || rhsType == nullptr) {
Error(_tok, "operands should have arithmetic type");
}
if ('%' == _op &&
!(_lhs->Type()->IsInteger()
&& _rhs->Type()->IsInteger())) {
Error(_tok, "operands of '%%' should be integers");
}
//TODO: type promotion
_type = Promote();
}
/*
* Additive operator is only allowed between:
* 1. arithmetic types (bool, interger, floating)
* 2. pointer can be used:
* 1. lhs of MINUS operator, and rhs must be integer or pointer;
* 2. lhs/rhs of ADD operator, and the other operand must be integer;
*/
void BinaryOp::AdditiveOpTypeChecking(void)
{
auto lhsType = _lhs->Type()->ToPointerType();
auto rhsType = _rhs->Type()->ToPointerType();
if (lhsType) {
if (_op == Token::MINUS) {
if ((rhsType && *lhsType != *rhsType)
|| !_rhs->Type()->IsInteger()) {
Error(_tok, "invalid operands to binary -");
}
_type = Type::NewArithmType(T_LONG); // ptrdiff_t
} else if (!_rhs->Type()->IsInteger()) {
Error(_tok, "invalid operands to binary -");
} else {
_type = _lhs->Type();
}
} else if (rhsType) {
if (_op != Token::ADD || !_lhs->Type()->IsInteger()) {
Error(_tok, "invalid operands to binary '%s'",
_tok->Str().c_str());
}
_type = _rhs->Type();
std::swap(_lhs, _rhs); // To simplify code gen
} else {
auto lhsType = _lhs->Type()->ToArithmType();
auto rhsType = _rhs->Type()->ToArithmType();
if (lhsType == nullptr || rhsType == nullptr) {
Error(_tok, "invalid operands to binary %s",
_tok->Str().c_str());
}
_type = Promote();
}
}
void BinaryOp::ShiftOpTypeChecking(void)
{
if (!_lhs->Type()->IsInteger() || !_rhs->Type()->IsInteger()) {
Error(_tok, "expect integers for shift operator '%s'",
_tok->Str());
}
Promote();
_type = _lhs->Type();
}
void BinaryOp::RelationalOpTypeChecking(void)
{
if (!_lhs->Type()->IsReal() || !_rhs->Type()->IsReal()) {
Error(_tok, "expect integer/float"
" for relational operator '%s'", _tok->Str());
}
Promote();
_type = Type::NewArithmType(T_INT);
}
void BinaryOp::EqualityOpTypeChecking(void)
{
auto lhsType = _lhs->Type()->ToPointerType();
auto rhsType = _rhs->Type()->ToPointerType();
if (lhsType || rhsType) {
if (!lhsType->Compatible(*rhsType)) {
Error(_tok, "incompatible pointers of operands");
}
} else {
auto lhsType = _lhs->Type()->ToArithmType();
auto rhsType = _rhs->Type()->ToArithmType();
if (lhsType == nullptr || rhsType == nullptr) {
Error(_tok, "invalid operands to binary %s",
_tok->Str());
}
Promote();
}
_type = Type::NewArithmType(T_INT);
}
void BinaryOp::BitwiseOpTypeChecking(void)
{
if (_lhs->Type()->IsInteger() || _rhs->Type()->IsInteger()) {
Error(_tok, "operands of '&' should be integer");
}
_type = Promote();
}
void BinaryOp::LogicalOpTypeChecking(void)
{
if (!_lhs->Type()->IsScalar()
|| !_rhs->Type()->IsScalar()) {
Error(_tok, "the operand should be arithmetic type or pointer");
}
Promote();
_type = Type::NewArithmType(T_INT);
}
void BinaryOp::AssignOpTypeChecking(void)
{
if (!_lhs->IsLVal()) {
Error(_lhs->Tok(), "lvalue expression expected");
} else if (_lhs->Type()->IsConst()) {
Error(_lhs->Tok(), "can't modifiy 'const' qualified expression");
} else if (!_lhs->Type()->Compatible(*_rhs->Type())) {
Error(_lhs->Tok(), "uncompatible types");
}
// The other constraints are lefted to cast operator
_rhs = UnaryOp::New(_tok,Token::CAST, _rhs, _lhs->Type());
_type = _lhs->Type();
}
/*
* Unary Operators
*/
UnaryOp* UnaryOp::New(const Token* tok,
int op, Expr* operand, ::Type* type)
{
auto ret = new (unaryOpPool.Alloc()) UnaryOp(op, operand, type);
ret->_pool = &unaryOpPool;
ret->TypeChecking();
return ret;
}
bool UnaryOp::IsLVal(void) {
// only deref('*') could be lvalue;
// so it's only deref will override this func
switch (_op) {
case Token::DEREF: return !Type()->ToArrayType();
case Token::CAST: return _operand->IsLVal();
default: return false;
}
}
void UnaryOp::TypeChecking(void)
{
switch (_op) {
case Token::POSTFIX_INC:
case Token::POSTFIX_DEC:
case Token::PREFIX_INC:
case Token::PREFIX_DEC:
return IncDecOpTypeChecking();
case Token::ADDR:
return AddrOpTypeChecking();
case Token::DEREF:
return DerefOpTypeChecking();
case Token::PLUS:
case Token::MINUS:
case '~':
case '!':
return UnaryArithmOpTypeChecking();
case Token::CAST:
return CastOpTypeChecking();
default:
assert(false);
}
}
void UnaryOp::IncDecOpTypeChecking(void)
{
if (!_operand->IsLVal()) {
Error(_tok, "lvalue expression expected");
} else if (_operand->Type()->IsConst()) {
Error(_tok, "can't modifiy 'const' qualified expression");
}
_type = _operand->Type();
}
void UnaryOp::AddrOpTypeChecking(void)
{
FuncType* funcType = _operand->Type()->ToFuncType();
if (funcType == nullptr && !_operand->IsLVal()) {
Error(_tok, "expression must be an lvalue or function designator");
}
_type = Type::NewPointerType(_operand->Type());
}
void UnaryOp::DerefOpTypeChecking(void)
{
auto pointerType = _operand->Type()->ToPointerType();
if (pointerType == nullptr) {
Error(_tok, "pointer expected for deref operator '*'");
}
_type = pointerType->Derived();
}
void UnaryOp::UnaryArithmOpTypeChecking(void)
{
if (Token::PLUS == _op || Token::MINUS == _op) {
if (!_operand->Type()->IsArithm())
Error(_tok, "Arithmetic type expected");
} else if ('~' == _op) {
if (!_operand->Type()->IsInteger())
Error(_tok, "integer expected for operator '~'");
} else if (!_operand->Type()->IsScalar()) {
Error(_tok,
"arithmetic type or pointer expected for operator '!'");
}
_type = _operand->Type();
}
void UnaryOp::CastOpTypeChecking(void)
{
// The _type has been initiated to dest type
if (!_type->IsScalar()) {
Error(_tok, "the cast type should be arithemetic type or pointer");
}
if (_type->IsFloat() && _operand->Type()->ToPointerType()) {
Error(_tok, "can't cast a pointer to floating");
} else if (_type->ToPointerType() && _operand->Type()->IsFloat()) {
Error(_tok, "can't cast a floating to pointer");
}
}
/*
* Conditional Operator
*/
ConditionalOp* ConditionalOp::New(const Token* tok,
Expr* cond, Expr* exprTrue, Expr* exprFalse)
{
auto ret = new (conditionalOpPool.Alloc())
ConditionalOp(cond, exprTrue, exprFalse);
ret->_pool = &conditionalOpPool;
ret->TypeChecking();
return ret;
}
ArithmType* ConditionalOp::Promote(void)
{
auto lhsType = _exprTrue->Type()->ToArithmType();
auto rhsType = _exprFalse->Type()->ToArithmType();
auto type = MaxType(lhsType, rhsType);
if (lhsType != type) {// Pointer comparation is enough!
_exprTrue = UnaryOp::New(_tok, Token::CAST, _exprTrue, type);
}
if (rhsType != type) {
_exprFalse = UnaryOp::New(_tok, Token::CAST, _exprFalse, type);
}
return type;
}
void ConditionalOp::TypeChecking(void)
{
if (!_cond->Type()->IsScalar()) {
Error(_cond->Tok(), "scalar is required");
}
auto lhsType = _exprTrue->Type();
auto rhsType = _exprFalse->Type();
if (!lhsType->Compatible(*rhsType)) {
Error(_exprTrue->Tok(), "incompatible types of true/false expression");
} else {
_type = lhsType;
}
lhsType = lhsType->ToArithmType();
rhsType = rhsType->ToArithmType();
if (lhsType && rhsType) {
_type = Promote();
}
}
/*
* Function Call
*/
FuncCall* FuncCall::New(Expr* designator, const std::list<Expr*>& args)
{
auto ret = new (funcCallPool.Alloc()) FuncCall(designator, args);
ret->_pool = &funcCallPool;
ret->TypeChecking();
return ret;
}
void FuncCall::TypeChecking(void)
{
auto pointerType = _designator->Type()->ToPointerType();
FuncType* funcType;
if (!pointerType || !(funcType = pointerType->Derived()->ToFuncType())) {
Error(_tok, "'%s' is not a function", _tok->Str());
}
auto arg = _args.begin();
for (auto paramType: funcType->ParamTypes()) {
if (arg == _args.end()) {
Error(_tok, "too few arguments for function ''");
}
if (!paramType->Compatible(*(*arg)->Type())) {
// : function name
Error(_tok, "incompatible type for argument 1 of ''");
}
++arg;
}
if (arg != _args.end() && !funcType->Variadic()) {
Error(_tok, "too many arguments for function ''");
}
_type = funcType->Derived();
}
/*
* Identifier
*/
Identifier* Identifier::New(const Token* tok,
::Type* type, ::Scope* scope, enum Linkage linkage)
{
auto ret = new (identifierPool.Alloc())
Identifier(tok, type, scope, linkage);
ret->_pool = &identifierPool;
return ret;
}
Enumerator* Enumerator::New(const Token* tok, ::Scope* scope, int val)
{
auto ret = new (enumeratorPool.Alloc()) Enumerator(tok, scope, val);
ret->_pool = &enumeratorPool;
return ret;
}
Declaration* Declaration::New(Object* obj)
{
auto ret = new (initializationPool.Alloc()) Declaration(obj);
ret->_pool = &initializationPool;
return ret;
}
void Declaration::AddInit(int offset, Type* type, Expr* expr)
{
auto qual = type->Qual();
type->SetQual(0);
// To trigger type checking
auto obj = Object::New(expr->Tok(), type, nullptr);
auto binary = BinaryOp::New(expr->Tok(), '=', obj, expr);
type->SetQual(qual);
expr = binary->_rhs; // Maybe added cast
/*
if (_obj->IsStatic()) {
// Delay until code gen
auto width = type->Width();
if (type->IsInteger()) {
auto val = Evaluator<long>().Eval(expr);
_staticInits.push_back({offset, width, val, ""});
} else if (type->IsFloat()) {
auto val = Evaluator<double>().Eval(expr);
auto lval = *reinterpret_cast<long*>(&val);
printf("%lf\n%ld\n", val, lval);
_staticInits.push_back({offset, width, lval, ""});
} else if (type->ToPointerType()) {
auto addr = Evaluator<Addr>().Eval(expr);
_staticInits.push_back({offset, width, addr._offset, addr._label});
} else { assert(false); }
} else {
_inits.push_back({offset, type, expr});
}
*/
_inits.push_back({offset, type, expr});
}
StaticInitializer Declaration::GetStaticInit(const Initializer& init)
{
// Delay until code gen
auto width = init._type->Width();
if (init._type->IsInteger()) {
auto val = Evaluator<long>().Eval(init._expr);
return {init._offset, width, val, ""};
} else if (init._type->IsFloat()) {
auto val = Evaluator<double>().Eval(init._expr);
auto lval = *reinterpret_cast<long*>(&val);
return {init._offset, width, lval, ""};
} else if (init._type->ToPointerType()) {
auto addr = Evaluator<Addr>().Eval(init._expr);
return {init._offset, width, addr._offset, addr._label};
} else {
assert(false);
return StaticInitializer(); //Make compiler happy
}
}
/*
* Object
*/
Object* Object::New(const Token* tok,
::Type* type, ::Scope* scope, int storage, enum Linkage linkage)
{
auto ret = new (objectPool.Alloc())
Object(tok, type, scope, storage, linkage);
ret->_pool = &objectPool;
return ret;
}
/*
* Constant
*/
Constant* Constant::New(const Token* tok, int tag, long val)
{
auto type = Type::NewArithmType(tag);
auto ret = new (constantPool.Alloc()) Constant(tok, type, val);
ret->_pool = &constantPool;
return ret;
}
Constant* Constant::New(const Token* tok, int tag, double val)
{
auto type = Type::NewArithmType(tag);
auto ret = new (constantPool.Alloc()) Constant(tok, type, val);
ret->_pool = &constantPool;
return ret;
}
Constant* Constant::New(const Token* tok, const std::string* val)
{
static auto derived = Type::NewArithmType(T_CHAR);
derived->SetQual(Q_CONST);
static auto type = Type::NewPointerType(derived);
auto ret = new (constantPool.Alloc()) Constant(tok, type, val);
ret->_pool = &constantPool;
static long tag = 0;
ret->_tag = tag++;
return ret;
}
/*
* TempVar
*/
TempVar* TempVar::New(::Type* type)
{
auto ret = new (tempVarPool.Alloc()) TempVar(type);
ret->_pool = &tempVarPool;
return ret;
}
/*
* Statement
*/
EmptyStmt* EmptyStmt::New(void)
{
auto ret = new (emptyStmtPool.Alloc()) EmptyStmt();
ret->_pool = &emptyStmtPool;
return ret;
}
//else stmt Ĭ���� null
IfStmt* IfStmt::New(Expr* cond, Stmt* then, Stmt* els)
{
auto ret = new (ifStmtPool.Alloc()) IfStmt(cond, then, els);
ret->_pool = &ifStmtPool;
return ret;
}
CompoundStmt* CompoundStmt::New(std::list<Stmt*>& stmts, ::Scope* scope)
{
auto ret = new (compoundStmtPool.Alloc()) CompoundStmt(stmts, scope);
ret->_pool = &compoundStmtPool;
return ret;
}
JumpStmt* JumpStmt::New(LabelStmt* label)
{
auto ret = new (jumpStmtPool.Alloc()) JumpStmt(label);
ret->_pool = &jumpStmtPool;
return ret;
}
ReturnStmt* ReturnStmt::New(Expr* expr)
{
auto ret = new (returnStmtPool.Alloc()) ReturnStmt(expr);
ret->_pool = &returnStmtPool;
return ret;
}
LabelStmt* LabelStmt::New(void)
{
auto ret = new (labelStmtPool.Alloc()) LabelStmt();
ret->_pool = &labelStmtPool;
return ret;
}
FuncDef* FuncDef::New(const Token* tok, FuncType* type,
const std::list<Object*>& params, CompoundStmt* stmt)
{
auto ret = new (funcDefPool.Alloc()) FuncDef(tok, type, params, stmt);
ret->_pool = &funcDefPool;
return ret;
}