forked from sahilpparmar/emmCompiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ast.h
815 lines (650 loc) · 25.8 KB
/
Ast.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
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
814
815
#ifndef AST_H
#define AST_H
#include "all.h"
#include "Value.h"
#include "ProgramElem.h"
#include "SymTabEntry.h"
class BlockEntry;
class InterCodesClass;
class InterCode;
class EventEntry;
class FunctionEntry;
class LabelEntry;
class OpNode;
//enum class OpCode;
class PatNode;
//enum class PatNode;
class PrimitivePatNode;
class RulezNode;
class SymTabEntry;
class VariableEntry;
/*****************************************************************************
Here is the class hierarchy:
ProgramElem
|
AstNode
+--------------------------------------------+----------------+
| | | |
BasePatNode ExprNode RuleNode StmtNode
| | |
| | |
| +---------+----------+-----------+ |
| | | | | |
| RefExprNode OpNode ValueNode InvocationNode |
| |
| +---------------+------+-----+
| | | |
| ExprStmtNode CompoundStmtNode IfNode
|
|
+-+------------------+
| |
| |
PrimitivePatNode PatNode
******************************************************************************/
class AstNode: public ProgramElem {
public:
enum class NodeType {
PAT_NODE,
EXPR_NODE,
REACTION_NODE,
STMT_NODE,
SEQUENCE_NODE,
RULE_NODE
};
public:
AstNode(NodeType nt, int line=0, int column=0, string file="");
AstNode(const AstNode&); // copy constructor
virtual ~AstNode() {};
//virtual AstNode* clone() = 0;
NodeType nodeType() const { return nodeType_;}
virtual const Type* typeCheck() = 0;
virtual void print(ostream& os, int indent=0) const = 0;
virtual void renameRV(string prefix) {}; // new names start with given prefix
virtual bool operator==(const AstNode&) const { return false; };
virtual bool operator!=(const AstNode& a) const
{ return !operator==(a); };
private:
NodeType nodeType_;
const AstNode* operator=(const AstNode& other); /* disable asg */
};
inline ostream& operator<<(ostream& os, const AstNode& an) {
an.print(os);
return os;
};
/****************************************************************/
class ExprNode: public AstNode {
public:
enum class ExprNodeType {
REF_EXPR_NODE,
OP_NODE,
VALUE_NODE,
INV_NODE,
VREG_NODE,
PRINT_NODE
};
public:
ExprNode(ExprNodeType et, const Value* val=0, int line=0, int column=0,
string file=""); // val is saved, but not copied
ExprNode(const ExprNode&);
virtual ~ExprNode() {};
virtual ExprNode* clone() const=0;
ExprNodeType exprNodeType() const { return exprType_;};
void exprNodeType(ExprNodeType t) { exprType_ = t; };
void exprVal(Value* val) { val_ = val; };
const Value* value() const { return val_; }
const Type* coercedType() const { return coercedType_; }
void coercedType(const Type* type) { coercedType_ = type; }
void print(ostream& os, int indent=0) const=0;
virtual ExprNode* getRefNode ();
private:
ExprNodeType exprType_;
const Value *val_; // reference semantics for val_ and coercedType_
const Type* coercedType_;
};
/****************************************************************/
class RefExprNode: public ExprNode {
public:
RefExprNode(string ext, const SymTabEntry* ste=NULL,
int line=0, int column=0, string file="");
RefExprNode(const RefExprNode&);
ExprNode* clone() const { return new RefExprNode(*this); }
~RefExprNode() {};
string ext() const { return ext_;};
void ext(string str) { ext_ = str;};
const SymTabEntry* symTabEntry() const { return sym_;};
void symTabEntry(const SymTabEntry *ste) { sym_ = ste;};
void print(ostream& os, int indent=0) const;
const Type* typeCheck();
InterCodesClass* codeGen();
string getRefName() { return ext_; }
string getRegisterName();
void setRegisterName(string reg_name);
private:
string ext_;
const SymTabEntry* sym_;
};
/****************************************************************/
#define MAX_OP_ARITY 2
class OpNode: public ExprNode {
public:
enum class OpCode {
UMINUS, PLUS, MINUS, MULT, DIV, MOD,
EQ, NE, GT, LT, GE, LE,
AND, OR, NOT,
BITNOT, BITAND, BITOR, BITXOR, SHL, SHR,
ASSIGN, PRINT, INVALID
};
enum class OpPrintType {PREFIX, INFIX, POSTFIX};
struct OpInfo {
OpCode code_;
const char* name_;
int arity_;
int needParen_;
OpPrintType prtType_;
Type::TypeTag argType_[3];
// operators with > 2 args can be supported
// only if types of args k through N are identical, for 1 <= k <= 3,
// and are given by argType[k-1]
Type::TypeTag outType_;
const char *typeConstraints_;
};
public:
static const int VARIABLE = 100;
static const OpInfo opInfo[];
public:
OpNode(OpCode op, ExprNode *l, ExprNode *r=NULL,
int line=0, int column=0, string file="");
OpNode(const OpNode&);
ExprNode* clone() const { return new OpNode(*this); }
~OpNode() {};
OpCode opCode() const { return opCode_;};
const ExprNode* arg(unsigned int i) const
{ return (i < arg_.size())? arg_[i] : NULL; };
unsigned int arity() const { return arity_; }
void opCode(OpCode a) { opCode_ = a; };
ExprNode* arg(unsigned int i)
{ return (i < arg_.size())? arg_[i] : NULL; };
vector<ExprNode*>* args()
{ return &arg_; }
void print(ostream& os, int indent=0) const;
const Type* typeCheck();
InterCodesClass* codeGen();
private:
unsigned int arity_;
OpCode opCode_;
vector<ExprNode*> arg_;
};
/****************************************************************/
class ValueNode: public ExprNode {
public:
ValueNode(Value* val=0, int line=0, int column=0, string file="")
: ExprNode(ExprNode::ExprNodeType::VALUE_NODE, val, line,column,file) {
if (val != NULL) type((Type*)(val->type()));
refnode_ = this;
}
ValueNode(const ValueNode& val): ExprNode(val) {};
ExprNode* clone() const { return new ValueNode(*this); }
~ValueNode() {};
void print(ostream& os, int indent=0) const;
const Type* typeCheck();
InterCodesClass* codeGen();
string getRefName() {
ostringstream os;
Type* tp = (Type*)coercedType();
if (tp==NULL) {
tp = type();
}
if (tp && tp->tag() && Type::isBool(tp->tag())) {
os << value()->bval();
} else {
if (tp && tp->tag() && Type::isFloat(tp->tag())) {
//os.precision(1);
os.setf(ios::fixed,ios::floatfield);
os << value()->dval();
}
else {
value()->print(os,0);
}
}
return os.str();
}
string getRegisterName()
{
return getRefName();
}
private:
/* val_ field is already included in ExprNode, so no new data members */
};
/****************************************************************/
class InvocationNode: public ExprNode {
// Used to represent function invocation
public:
InvocationNode(const SymTabEntry *ste, vector<ExprNode*>* param=0,
int line=0, int column=0, string file="");
InvocationNode(const InvocationNode&);
ExprNode* clone() const { return new InvocationNode(*this); }
~InvocationNode() {};
const SymTabEntry* symTabEntry() const { return ste_; };
const vector<ExprNode*>* params() const { return params_;};
vector<ExprNode*>* params() { return params_;}
void params(vector<ExprNode*>* args) { params_ = args;};
const ExprNode* param(unsigned int i) const {
return (params_ != NULL && i < params_->size()) ? (const ExprNode*)((*params_)[i]) : NULL;
}
ExprNode* param(unsigned int i) {
return (ExprNode*)((const InvocationNode*)this->param(i));
}
void param(ExprNode* arg, unsigned int i) {
if (params_ != NULL && i < params_->size())
(*params_)[i] = arg;
}
void print(ostream& os, int indent=0) const;
const Type* typeCheck();
InterCodesClass* codeGen();
private:
vector<ExprNode*>* params_;
const SymTabEntry *ste_; // reference semantics
};
class PrintFunctionNode: public ExprNode {
// Used to represent function invocation
public:
PrintFunctionNode( vector<ExprNode*>* param=0, int line=0, int column=0, string file="");
PrintFunctionNode(const PrintFunctionNode&);
ExprNode* clone() const { return new PrintFunctionNode(*this); }
~PrintFunctionNode() {};
const vector<ExprNode*>* params() const { return params_;};
vector<ExprNode*>* params() { return params_;}
void params(vector<ExprNode*>* args) { params_ = args;};
const ExprNode* param(unsigned int i) const {
return (params_ != NULL && i < params_->size()) ? (const ExprNode*)((*params_)[i]) : NULL;
}
ExprNode* param(unsigned int i) {
return (ExprNode*)((const PrintFunctionNode*)this->param(i));
}
void param(ExprNode* arg, unsigned int i) {
if (params_ != NULL && i < params_->size())
(*params_)[i] = arg;
}
void print(ostream& os, int indent=0) const;
const Type* typeCheck();
InterCodesClass* codeGen();
private:
vector<ExprNode*>* params_;
};
/****************************************************************/
class ClassFuncInvocationNode: public ExprNode {
// Used to represent function invocation
public:
ClassFuncInvocationNode(const SymTabEntry *oste, const SymTabEntry *fste, vector<ExprNode*>* param=0,
int line=0, int column=0, string file="");
ClassFuncInvocationNode(const ClassFuncInvocationNode&);
ExprNode* clone() const { return new ClassFuncInvocationNode(*this); }
~ClassFuncInvocationNode() {};
const SymTabEntry* symTabEntryObject() const { return oste_; };
const SymTabEntry* symTabEntryFunction() const { return fste_; };
const vector<ExprNode*>* params() const { return params_;};
vector<ExprNode*>* params() { return params_;}
void params(vector<ExprNode*>* args) { params_ = args;};
const ExprNode* param(unsigned int i) const {
return (params_ != NULL && i < params_->size()) ? (const ExprNode*)((*params_)[i]) : NULL;
}
ExprNode* param(unsigned int i) {
return (ExprNode*)((const ClassFuncInvocationNode*)this->param(i));
}
void param(ExprNode* arg, unsigned int i) {
if (params_ != NULL && i < params_->size())
(*params_)[i] = arg;
}
void print(ostream& os, int indent=0) const;
const Type* typeCheck();
InterCodesClass* codeGen();
private:
vector<ExprNode*>* params_;
const SymTabEntry *oste_; // reference symbol table entry for object.
const SymTabEntry *fste_; // reference symbol table entry for function.
};
/****************************************************************/
class ClassRefExprNode: public ExprNode {
public:
ClassRefExprNode(string ext, const SymTabEntry* objSte=NULL, const SymTabEntry* varSte = NULL,
int line=0, int column=0, string file="");
ClassRefExprNode(const ClassRefExprNode&);
ExprNode* clone() const { return new ClassRefExprNode(*this); }
~ClassRefExprNode() {};
string ext() const { return ext_;};
void ext(string str) { ext_ = str;};
const SymTabEntry* symTabEntryObject() const { return objSym_;};
const SymTabEntry* symTabEntryVariable() const { return varSym_;};
void symTabEntryObject(const SymTabEntry *objSte) { objSym_ = objSte;};
void symTabEntryVariable(const SymTabEntry *varSte) { varSym_ = varSte;};
void print(ostream& os, int indent=0) const;
const Type* typeCheck();
InterCodesClass* codeGen();
private:
string ext_;
const SymTabEntry* objSym_;
const SymTabEntry* varSym_;
};
/****************************************************************/
// There are 3 kinds of PatNodes:
// PrimitivePatNodes are of the form: event|cond
// AtomicPatNodes consist of PrimitivePatNodes with one or more "||"
// operators, plus an optional negation symbol
// PatNodes consist of PatNodes or AtomicPatNodes composed with
// ".", "||" and "*" operators
// We have a single base class for pattern nodes called BasePatNode. In
// addition, the functionality of Atomic and PatNodes have been
// combined into a single class PatNode.
class BasePatNode: public AstNode {
public:
enum class PatNodeKind {PRIMITIVE, EMPTY, NEG, SEQ, OR, STAR, UNDEFINED};
public:
BasePatNode(PatNodeKind pk, int ln=0, int col=0, string f=""):
AstNode(AstNode::NodeType::PAT_NODE, ln, col, f)
{
parent_ = NULL; root_ = NULL; patKind_ = pk;
}
BasePatNode(const BasePatNode& bpn): AstNode(bpn) {
patKind_ = bpn.patKind_; parent_ = bpn.parent_; root_ = bpn.root_;
}
~BasePatNode() {};
//virtual BasepatNode* clone() const { return new BasePatNode(*this);}
PatNodeKind kind() const { return patKind_; };
void kind(PatNodeKind p) {patKind_ = p;}
const BasePatNode* parent() const { return parent_; }
BasePatNode* parent() { return parent_;}
virtual bool hasSeqOps() const=0;
virtual bool hasNeg() const=0;
virtual bool hasAnyOrOther() const=0;
virtual bool isNegatable() const {
return ((!hasSeqOps()) && (!hasNeg()));
}
private:
PatNodeKind patKind_;
BasePatNode* parent_;
BasePatNode* root_;
};
/****************************************************************/
class PrimitivePatNode: public BasePatNode {
public:
PrimitivePatNode(EventEntry* ee, vector<VariableEntry*>* params,
ExprNode* c=NULL,
int line=0, int column=0, string file="") :
BasePatNode(PatNodeKind::PRIMITIVE, line, column, file)
{
ee_ = ee;
params_ = params;
/* cond_ may contain assignments as well as other expressions */
/* condition_ contains all expresions in cond_ other than assignments */
cond_= c;
condition_ = c;
}
//PrimitivePatNode(const PrimitivePatNode& ppn);
~PrimitivePatNode() {};
//BasePatNode* clone() { return new PrimitivePatNode(*this); }
const EventEntry* event() const { return ee_; }
EventEntry* event() { return ee_; }
const vector<const VariableEntry*>* params() const {
return (vector<const VariableEntry*>*)params_; }
vector<VariableEntry*>* params() { return params_; }
const ExprNode* cond() const { return cond_; }
ExprNode* cond() { return cond_; }
void cond(ExprNode* c) { cond_ = c;}
ExprNode* condition() { return condition_; }
const ExprNode* condition() const { return condition_; }
const list<const OpNode*>& asgs() const {
return (list<const OpNode*>&)asgs_;
}
list<OpNode*>& asgs() { return asgs_; }
bool hasNeg() const {
if (kind() == BasePatNode::PatNodeKind::NEG)
return true;
return false;
}
bool hasSeqOps() const {
return false;
}
bool hasAnyOrOther() const;
void print(ostream& os, int indent=0) const;
const Type* typeCheck();
InterCodesClass* codeGen();
private:
EventEntry* ee_;
vector<VariableEntry*>* params_;
/* cond_ may contain assignments as well as other expressions */
/* condition_ contains all expresions in cond_ other than assignments */
ExprNode* cond_;
ExprNode* condition_;
list<OpNode*> asgs_;
};
/****************************************************************/
class PatNode: public BasePatNode {
public:
PatNode(int line=0, int column=0, string file="") :
BasePatNode(PatNodeKind::EMPTY, line, column, file)
{
pat1_ = NULL;
pat2_ = NULL;
}
PatNode(PatNodeKind pk, BasePatNode *p1, BasePatNode*p2 = NULL, int line = 0, int column = 0, string file = "") :
BasePatNode(pk, line, column, file)
{
pat1_ = p1;
pat2_ = p2;
}
~PatNode() {};
//AstNode* clone()
// { return new PatNode(*this); }
const BasePatNode* pat1() const { return pat1_; }
BasePatNode* pat1() { return pat1_; }
const BasePatNode* pat2() const { return pat2_; }
BasePatNode* pat2() { return pat2_; }
// TODO
bool hasNeg() const {
if (kind() == BasePatNode::PatNodeKind::NEG)
return true;
return false;
}
bool hasSeqOps() const;
bool hasAnyOrOther() const {
return true;
}
void print(ostream& os, int indent=0) const;
const Type* typeCheck();
private:
PatNode(const PatNode&);
BasePatNode *pat1_;
BasePatNode *pat2_;
};
/****************************************************************/
class StmtNode: public AstNode {
public:
enum class StmtNodeKind { ILLEGAL=-1, EXPR, IF, COMPOUND, RETURN, WHILE, BREAK, CONTINUE};
public:
StmtNode(StmtNodeKind skm, int line=0, int column=0, string file=""):
AstNode(AstNode::NodeType::STMT_NODE, line, column, file) { skind_ = skm; };
~StmtNode() {};
//AstNode* clone()
// { return new StmtNode(*this); }
StmtNodeKind stmtNodeKind() const { return skind_;}
void print(ostream& os, int indent) const = 0;
private:
StmtNodeKind skind_;
};
/****************************************************************/
class ReturnStmtNode: public StmtNode {
public:
ReturnStmtNode(ExprNode *e, FunctionEntry* fe,
int line=0, int column=0, string file=""):
StmtNode(StmtNode::StmtNodeKind::RETURN,line,column,file) { expr_ = e; fun_ = fe;};
~ReturnStmtNode() {};
void print(ostream& os, int indent) const;
const Type* typeCheck();
InterCodesClass* codeGen();
private:
ExprNode* expr_;
FunctionEntry* fun_;
};
/****************************************************************/
class ExprStmtNode: public StmtNode {
public:
ExprStmtNode(ExprNode* e, int line=0, int column=0, string file=""):
StmtNode(StmtNode::StmtNodeKind::EXPR, line, column, file) { expr_ = e; };
~ExprStmtNode() {};
//AstNode* clone()
// { return new ExprStmtNode(*this); }
void print(ostream& os, int indent) const;
const Type* typeCheck();
InterCodesClass* codeGen();
private:
ExprNode* expr_;
};
/****************************************************************/
class CompoundStmtNode: public StmtNode {
public:
CompoundStmtNode(list<StmtNode*> *Slist, int ln=0, int col=0, string fl=""):
StmtNode(StmtNode::StmtNodeKind::COMPOUND, ln, col, fl) { stmts_ = Slist; }
~CompoundStmtNode() { };
//AstNode* clone()
// { return new CompoundStmtNode(*this); }
const list<StmtNode*>* stmts() const { return stmts_; }
list<StmtNode*>* stmts() { return stmts_; }
void add(StmtNode *s) {
if (stmts_ != NULL) stmts_->push_back(s);
}
void printWithoutBraces(ostream& os, int indent) const;
void print(ostream& os, int indent) const;
const Type* typeCheck();
InterCodesClass* codeGen();
private:
CompoundStmtNode(const CompoundStmtNode&);
list<StmtNode*> *stmts_;
};
/****************************************************************/
class IfNode: public StmtNode {
public:
IfNode(ExprNode* cond, StmtNode* thenStmt,
StmtNode* elseStmt = NULL, int line = 0, int column = 0, string file = "") :
StmtNode(StmtNode::StmtNodeKind::IF, line, column, file)
{
cond_ = cond;
then_ = thenStmt;
else_ = elseStmt;
}
~IfNode() {};
//AstNode* clone()
// { return new IfNode(*this); }
const ExprNode* cond() const {return cond_;}
const StmtNode* elseStmt() const { return else_;};
const StmtNode* thenStmt() const { return then_;};
ExprNode* cond() {return cond_;}
StmtNode* elseStmt() { return else_;};
StmtNode* thenStmt() { return then_;};
void print(ostream& os, int indent) const;
const Type* typeCheck();
InterCodesClass* codeGen();
private:
ExprNode *cond_;
StmtNode *then_, *else_;
IfNode(const IfNode&);
};
/****************************************************************/
class WhileNode: public StmtNode {
public:
WhileNode(ExprNode* cond, StmtNode* bodyStmt,
int line = 0, int column = 0, string file = "") :
StmtNode(StmtNode::StmtNodeKind::WHILE, line, column, file)
{
cond_ = cond;
body_ = bodyStmt;
}
~WhileNode() {};
//AstNode* clone()
// { return new IfNode(*this); }
const ExprNode* cond() const {return cond_;}
const StmtNode* bodyStmt() const { return body_;};
ExprNode* cond() {return cond_;}
StmtNode* bodyStmt() { return body_;};
void print(ostream& os, int indent) const;
const Type* typeCheck();
InterCodesClass* codeGen();
private:
ExprNode *cond_;
StmtNode *body_;
WhileNode(const WhileNode&);
};
/****************************************************************/
class BreakStmtNode: public StmtNode {
public:
BreakStmtNode(ExprNode *e, int line=0, int column=0, string file=""):
StmtNode(StmtNode::StmtNodeKind::BREAK,line,column,file)
{
expr_ = e;
wnode_ = NULL;
}
~BreakStmtNode() {}
void print(ostream& os, int indent) const;
const Type* typeCheck();
InterCodesClass* codeGen();
private:
ExprNode* expr_; // Depth of outer while
WhileNode* wnode_; // Reference to the WhileNode it would jump to the end of
};
/****************************************************************/
class ContinueStmtNode: public StmtNode {
public:
ContinueStmtNode(ExprNode *e, int line=0, int column=0, string file=""):
StmtNode(StmtNode::StmtNodeKind::CONTINUE,line,column,file)
{
expr_ = e;
wnode_ = NULL;
}
~ContinueStmtNode() {}
void print(ostream& os, int indent) const;
const Type* typeCheck();
InterCodesClass* codeGen();
private:
ExprNode* expr_; // Depth of outer while
WhileNode* wnode_; // Reference to the WhileNode it would jump to the start of
};
/****************************************************************/
class RuleNode: public AstNode {
public:
RuleNode(BlockEntry *re, BasePatNode* pat, StmtNode* reaction,
int line=0, int column=0, string file="");
~RuleNode() {}
//AstNode* clone()
// { return new RuleNode(*this); }
const BlockEntry* ruleEntry() const { return rste_; };
BlockEntry* ruleEntry() { return rste_; };
const BasePatNode* pat() const { return pat_; };
BasePatNode* pat() { return pat_; };
const StmtNode* reaction() const { return reaction_; };
StmtNode* reaction() { return reaction_; };
void print(ostream& os, int indent=0) const;
const Type* typeCheck();
InterCodesClass* codeGen();
private:
BlockEntry *rste_;
BasePatNode *pat_;
StmtNode *reaction_;
RuleNode(const RuleNode&);
};
/****************************************************************/
class VregNode: public ExprNode
{
public:
VregNode (int line, int column, string file);
ExprNode* clone() const {return NULL; }
void print(ostream& os, int indent=0) const {}
const Type* typeCheck();
string getRefName() { return name_; }
string getRegisterName();
void setRegisterName(string reg_name);
private:
string name_;
string registerName_ ;
};
/****************************************************************/
#endif