-
Notifications
You must be signed in to change notification settings - Fork 4
/
ast.h
1836 lines (1406 loc) · 45.5 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
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ast.h -- Classes of the Abstract Syntax Tree (AST)
//
// KPL Compiler
//
// Copyright 2002-2007, Harry H. Porter III
//
// This file may be freely copied, modified and compiled, on the sole
// condition that if you modify it...
// (1) Your name and the date of modification is added to this comment
// under "Modifications by", and
// (2) Your name and the date of modification is added to the printHelp()
// routine in file "main.cc" under "Modifications by".
//
// Original Author:
// 06/15/02 - Harry H. Porter III
//
// Modifcations by:
// 03/15/06 - Harry H. Porter III
//
//class AstNode; // ...
class Header; // HEADER
class Code; // CODE
class Uses; // USES
class Renaming; // RENAMING
class Abstract; // ...
class Interface; // INTERFACE
class ClassDef; // CLASS_DEF
class Behavior; // BEHAVIOR
class TypeDef; // TYPE_DEF
class ConstDecl; // CONST_DECL
class ErrorDecl; // ERROR_DECL
class FunctionProto; // FUNCTION_PROTO
class MethodProto; // METHOD_PROTO
class MethOrFunction; // ...
class Function; // FUNCTION
class Method; // METHOD
class TypeParm; // TYPE_PARM
class TypeArg; // TYPE_ARG
class Type; // ...
class CharType; // CHAR_TYPE
class IntType; // INT_TYPE
class DoubleType; // DOUBLE_TYPE
class BoolType; // BOOL_TYPE
class VoidType; // VOID_TYPE
class TypeOfNullType; // TYPE_OF_NULL_TYPE
class AnyType; // ANY_TYPE
class PtrType; // PTR_TYPE
class ArrayType; // ARRAY_TYPE
class RecordType; // RECORD_TYPE
class FunctionType; // FUNCTION_TYPE
class NamedType; // NAMED_TYPE
class Statement; // ...
class IfStmt; // IF_STMT
class AssignStmt; // ASSIGN_STMT
class CallStmt; // CALL_STMT
class SendStmt; // SEND_STMT
class WhileStmt; // WHILE_STMT
class DoStmt; // DO_STMT
class BreakStmt; // BREAK_STMT
class ContinueStmt; // CONTINUE_STMT
class ReturnStmt; // RETURN_STMT
class ForStmt; // FOR_STMT
class SwitchStmt; // SWITCH_STMT
class TryStmt; // TRY_STMT
class ThrowStmt; // THROW_STMT
class FreeStmt; // FREE_STMT
class DebugStmt; // DEBUG_STMT
class Case; // CASE
class Catch; // CATCH
class VarDecl; // ...
class Global; // GLOBAL
class Local; // LOCAL
class Parameter; // PARAMETER
class ClassField; // CLASS_FIELD
class RecordField; // RECORD_FIELD
class Expression; // ...
class Constant; // ...
class IntConst; // INT_CONST
class DoubleConst; // DOUBLE_CONST
class CharConst; // CHAR_CONST
class StringConst; // STRING_CONST
class BoolConst; // BOOL_CONST
class NullConst; // NULL_CONST
class CallExpr; // CALL_EXPR
class SendExpr; // SEND_EXPR
class SelfExpr; // SELF_EXPR
class SuperExpr; // SUPER_EXPR
class FieldAccess; // FIELD_ACCESS
class ArrayAccess; // ARRAY_ACCESS
class Constructor; // CONSTRUCTOR
class ClosureExpr; // CLOSURE_EXPR
class VariableExpr; // VARIABLE_EXPR
class AsPtrToExpr; // AS_PTR_TO_EXPR
class AsIntegerExpr; // AS_INTEGER_EXPR
class ArraySizeExpr; // ARRAY_SIZE_EXPR
class IsInstanceOfExpr; // IS_INSTANCE_OF_EXPR
class IsKindOfExpr; // IS_KIND_OF_EXPR
class SizeOfExpr; // SIZE_OF_EXPR
class DynamicCheck; // DYNAMIC_CHECK
class Argument; // ARGUMENT
class CountValue; // COUNT_VALUE
class FieldInit; // FIELD_INIT
//---------- AstNode ----------
class AstNode {
public:
int op; // e.g., HEADER, IF_STMT, SEND_EXPR, etc.
Token tokn;
AstNode (int oper) {
op = oper;
tokn = token;
}
~AstNode () {}
virtual void prettyPrint (int indent);
void positionAt (AstNode * node) {
tokn = node->tokn;
}
void positionAtToken (Token tok) {
tokn = tok;
}
};
//---------- Header ----------
class Header : public AstNode {
public:
Header * next;
String * packageName; // e.g., "MyPack"
Uses * uses; // Linked list, may be NULL
ConstDecl * consts; // Linked list, may be NULL
ErrorDecl * errors; // Linked list, may be NULL
Global * globals; // Linked list, may be NULL
TypeDef * typeDefs; // Linked list, may be NULL
FunctionProto * functionProtos; // Linked list, may be NULL
Interface * interfaces; // Linked list, may be NULL
ClassDef * classes; // Linked list, may be NULL
int hashVal; // The pseudo-random code for this token sequence
int mark; // 0=unseen, 1=processing, 2=done
Header * tempNext; // Used in topoProcessAllPackages
Mapping<String,AstNode> * // String --> ConstDecl,Global,TypeDef,
packageMapping; // FunctionProto, Interface, ClassDef
Mapping<String,ErrorDecl> * // String --> ErrorDecl
errorMapping; //
Function * functions; // For mainHeader; same as in code file
Function * closures; // All closures we have encountered;
Header () : AstNode (HEADER) {
next = NULL;
packageName = NULL;
uses = NULL;
consts = NULL;
errors = NULL;
globals = NULL;
typeDefs = NULL;
functionProtos = NULL;
interfaces = NULL;
classes = NULL;
hashVal = 0;
mark = 0;
tempNext = NULL;
packageMapping = NULL;
errorMapping = NULL;
functions = NULL;
closures = NULL;
}
~Header () {}
virtual void prettyPrint (int indent);
};
//---------- Code ----------
class Code : public AstNode {
public:
String * packageName; // e.g., "MyPack"
ConstDecl * consts; // Linked list, may be NULL
ErrorDecl * errors; // Linked list, may be NULL
Global * globals; // Linked list, may be NULL
TypeDef * typeDefs; // Linked list, may be NULL
Function * functions; // Linked list, may be NULL
Interface * interfaces; // Linked list, may be NULL
ClassDef * classes; // Linked list, may be NULL
Behavior * behaviors; // Linked list, may be NULL
int hashVal; // The pseudo-random code for this token sequence
Code () : AstNode (CODE) {
packageName = NULL;
consts = NULL;
errors = NULL;
globals = NULL;
typeDefs = NULL;
functions = NULL;
interfaces = NULL;
classes = NULL;
behaviors = NULL;
hashVal = 0;
}
~ Code () {}
virtual void prettyPrint (int indent);
};
//---------- Uses ----------
class Uses : public AstNode {
public:
Uses * next;
String * id; // name of package (e.g., "SysPack")
Renaming * renamings; // Linked list, may be NULL
Header * myDef; // Null if errors in topoProcessing Headers
Uses () : AstNode (USES) {
next = NULL;
id = NULL;
renamings = NULL;
myDef = NULL;
}
~ Uses () {}
virtual void prettyPrint (int indent);
};
//---------- Renaming ----------
class Renaming : public AstNode {
public:
Renaming * next;
String * from; // e.g., "foo" or "++"
String * to; // e.g., "superFoo" or "^++"
Renaming () : AstNode (RENAMING) {
next = NULL;
from = NULL;
to = NULL;
}
~ Renaming () {}
virtual void prettyPrint (int indent);
};
//---------- Abstract ----------
class Abstract : public AstNode {
public:
String * id; // E.g., "MyClass" or "MyInterface"
Header * myHeader; // Never NULL (set in
// . topoProcessClasses / Interfaces)
Abstract * nextAbstract; // A list of all classes & interfaces
Mapping<Abstract,Abstract> * // All sub-Abstracts in this package
knownSubAbstracts; // . (including self)
Mapping<Abstract,Abstract> * // All super-Abstracts in this package
superAbstractsInThisPackage; // . (including self)
Mapping<Abstract,Abstract> * // Minimal super-Abstracts that are
supersAbstractsInOtherPackages;// . not in this package
Mapping<String,MethodProto> * // String --> MethodProto
selectorMapping; // For Classes: This includes copies of
// MethodProtos inherited from our superclass
// For Interfaces: Initially this
// includes only the local MethodProtos
// from this interface; after "checkExtends"
// it includes inherited MethodProtos, too
Mapping<Offset,String> * // This maps offsets to selectors
offsetToSelector; // .
Mapping<String,Offset> * // This maps selectors to offsets
selectorToOffset; // .
Mapping<Offset,String> * // Indicates that an offset has been reserved
unavailableOffsets; // . in this Abstract (and for which message);
// . (The message may not be in this Abstract,
// . but the offset in nonetheless occupied.)
char * newName; // ClassDef: label on dispatch table
// Interface: label on Interface Descriptor
Abstract (int op) : AstNode (op) {
id = NULL;
myHeader = NULL;
nextAbstract = NULL;
knownSubAbstracts = NULL;
superAbstractsInThisPackage = NULL;
supersAbstractsInOtherPackages = NULL;
selectorMapping = NULL;
offsetToSelector = NULL;
selectorToOffset = NULL;
unavailableOffsets = NULL;
newName = NULL;
}
~ Abstract () {}
virtual void prettyPrint (int indent);
};
//---------- Interface ----------
class Interface : public Abstract {
public:
Interface * next;
TypeParm * typeParms; // Linked list, may be NULL
TypeArg * extends; // Linked list of NamedTypes, may be NULL
MethodProto * methodProtos; // Linked list, may be NULL (locals only)
int mark; // 0=unseen, 1=processing, 2=done
Interface * tempNext; // temp, used in topo-sorting
int isPrivate; // 1=from code file, 0=from header file
MethodProto * // A list of (copies of) inherited
inheritedMethodProtos; // messages
Interface () : Abstract (INTERFACE) {
next = NULL;
typeParms = NULL;
extends = NULL;
methodProtos = NULL;
mark = 0;
tempNext = NULL;
isPrivate = 0;
inheritedMethodProtos = NULL;
}
~ Interface () {}
virtual void prettyPrint (int indent);
};
//---------- ClassDef ----------
class ClassDef : public Abstract {
public:
ClassDef * next;
TypeParm * typeParms; // Linked list, may be NULL
TypeArg * implements; // Linked list, may be NULL
NamedType * superclass; // NULL means class = "Object"
ClassField * fields; // Linked list, may be NULL
MethodProto * methodProtos; // Linked list, may be NULL, in order
// (copies of inherited protos added at front)
int mark; // 0=unseen, 1=processing, 2=done
ClassDef * tempNext; // temp var, used in topo-sorting
int isPrivate; // 1=from code file, 0=from header file
Method * methods; // From Behavior, may be NULL;
// Does not include inherited methods.
ClassDef * superclassDef; // To our superclass, NULL if errors or none
Mapping<TypeParm,Type> * // This mapping maps TypeParms from the
superclassMapping; // superclass's ClassDef to types in our
// 'superclass' clause
Mapping<String,AstNode> * // String --> ClassField; parent=packageMapping
classMapping; // Includes copies of inherited ClassFields
Mapping<String,Method> * // String --> Method; includes only local methods
localMethodMapping; // (not inherited methods)
int sizeInBytes; // Size, including class ptr; -1 = problems
Type * typeOfSelf; // e.g., "Person" or Person[T]"
ClassDef () : Abstract (CLASS_DEF) {
next = NULL;
typeParms = NULL;
implements = NULL;
superclass = NULL;
fields = NULL;
methodProtos = NULL;
mark = 0;
tempNext = NULL;
isPrivate = 0;
methods = NULL;
superclassDef = NULL;
superclassMapping = NULL;
classMapping = NULL;
localMethodMapping = NULL;
selectorMapping = NULL;
sizeInBytes = -1;
typeOfSelf = NULL;
}
~ ClassDef () {}
virtual void prettyPrint (int indent);
};
//---------- Behavior ----------
class Behavior : public AstNode {
public:
Behavior * next;
String * id;
Method * methods; // Linked list, may be NULL
Behavior () : AstNode (BEHAVIOR) {
next = NULL;
id = NULL;
methods = NULL;
}
~ Behavior () {}
virtual void prettyPrint (int indent);
};
//---------- TypeDef ----------
class TypeDef : public AstNode {
public:
TypeDef * next;
String * id;
Type * type;
int mark;
TypeDef () : AstNode (TYPE_DEF) {
next = NULL;
id = NULL;
type = NULL;
mark = 0;
}
~ TypeDef () {}
virtual void prettyPrint (int indent);
};
//---------- ConstDecl ----------
class ConstDecl : public AstNode {
public:
ConstDecl * next;
String * id;
Expression * expr;
int isPrivate; // 1=in code file, 0=in header file
ConstDecl () : AstNode (CONST_DECL) {
next = NULL;
id = NULL;
expr = NULL;
isPrivate = 0;
}
~ ConstDecl () {}
virtual void prettyPrint (int indent);
};
//---------- ErrorDecl ----------
class ErrorDecl : public AstNode {
public:
ErrorDecl * next;
String * id;
Parameter * parmList; // Linked list, may be NULL
// int isPrivate; // 1=in code file, 0=in header file
char * newName; // E.g., "_Error_P_MyPackageName_OriginalName"
int totalParmSize;
ErrorDecl () : AstNode (ERROR_DECL) {
next = NULL;
id = NULL;
parmList = NULL;
// isPrivate = 0;
newName = NULL;
totalParmSize = 0;
}
~ ErrorDecl () {}
virtual void prettyPrint (int indent);
};
//---------- FunctionProto ----------
class FunctionProto : public AstNode {
public:
FunctionProto * next;
String * id;
Parameter * parmList; // Linked list, may be NULL
Type * retType; // Never NULL
int isExternal; // 1=external
int isPrivate; // 0=not in header file, 1=in header file
Header * myHeader; // The package containing this function
Function * myFunction; // NULL if none or if error
char * newName; // E.g., "bar", "_function_123_foo", "_closure_321"
int totalParmSize; // Size of all parms, including padding
int retSize; // Size of return result (-1 = void, could be 1)
FunctionProto () : AstNode (FUNCTION_PROTO) {
next = NULL;
id = NULL;
parmList = NULL;
retType = NULL;
isExternal = 0;
isPrivate = 0;
myHeader = NULL;
myFunction = NULL;
totalParmSize = 0;
retSize = 0;
}
~ FunctionProto () {}
virtual void prettyPrint (int indent);
};
//---------- MethodProto ----------
class MethodProto : public AstNode {
public:
MethodProto * next;
int kind; // INFIX, PREFIX, KEYWORD, NORMAL
String * selector; // e.g., "foo", "+", "at:put:"
Parameter * parmList; // Linked list, may be NULL
Type * retType; // Never NULL
Method * myMethod; // For Classes: Only NULL when errors; may
// point to Methods in a superclass
// For interfaces: Always NULL
int totalParmSize; // Size of all parms, including padding
int retSize; // Size of return result (-1 = void, could be 1)
int offset; // The offset in the dispatch table
MethodProto () : AstNode (METHOD_PROTO) {
next = NULL;
selector = NULL;
parmList = NULL;
retType = NULL;
kind = EOF;
myMethod = NULL;
totalParmSize = 0;
retSize = 0;
offset = -1;
}
~ MethodProto () {}
virtual void prettyPrint (int indent);
};
//---------- MethOrFunction ----------
class MethOrFunction : public AstNode {
public:
Parameter * parmList; // Linked list, may be NULL
Type * retType; // Never NULL
Local * locals; // Linked list, may be NULL
Statement * stmts; // Linked list, may be NULL
int frameSize; // Frame size in bytes
char * newName; // Methods: e.g., "_Method_P_MyPackageName_47"
// Funs: "bar", "_function_123_foo", "_closure_321"
int maxArgBytes; // Minimum is zero if we call no funs or meths
int totalParmSize; // Size of all parms, including padding
int containsTry; // 1=there is a TRY stmt in this function
Local * catchStackSave; // The temp where the catch stack will be saved
Catch * catchList; // List of all catches in this function
MethOrFunction (int op) : AstNode (op) {
parmList = NULL;
retType = NULL;
locals = NULL;
stmts = NULL;
frameSize = -1;
newName = NULL;
maxArgBytes = -1;
totalParmSize = 0;
containsTry = 0;
catchStackSave = NULL;
catchList = NULL;
}
~ MethOrFunction () {}
virtual void prettyPrint (int indent);
};
//---------- Function ----------
class Function : public MethOrFunction {
public:
Function * next;
String * id; // NULL = Closure
FunctionProto * myProto; // Null if error or closure
Function () : MethOrFunction (FUNCTION) {
next = NULL;
id = NULL;
myProto = NULL;
}
~ Function () {}
virtual void prettyPrint (int indent);
};
//---------- Method ----------
class Method : public MethOrFunction {
public:
Method * next;
int kind; // INFIX, PREFIX, KEYWORD, NORMAL
String * selector; // e.g., "foo", "+", "at:put:"
MethodProto * myMethodProto; // Only NULL when errors
ClassDef * myClass; // Class in which this code appeared
Method () : MethOrFunction (METHOD) {
next = NULL;
kind = 0;
selector = NULL;
myMethodProto = NULL;
myClass = NULL;
}
~ Method () {}
virtual void prettyPrint (int indent);
};
//---------- TypeParm ----------
class TypeParm : public AstNode {
//
// This represents something like [T1: Object, T2: String]
//
public:
TypeParm * next;
String * id;
Type * type;
int fourByteRestricted; // 1=used in field, local, or parm decl
TypeParm () : AstNode (TYPE_PARM) {
next = NULL;
id = NULL;
type = NULL;
fourByteRestricted = 0;
}
~ TypeParm () {}
virtual void prettyPrint (int indent);
};
//---------- TypeArg ----------
class TypeArg : public AstNode {
//
// This represents something like "int, char, List[String]"
//
public:
TypeArg * next;
Type * type;
int offset; // Only for typeArgs in FunctionTypes
int sizeInBytes; // Only for typeArgs in FunctionTypes
TypeArg () : AstNode (TYPE_ARG) {
next = NULL;
type = NULL;
offset = -1;
sizeInBytes = -1;
}
~ TypeArg () {}
virtual void prettyPrint (int indent);
};
//---------- Type ----------
class Type : public AstNode {
public:
Type (int op) : AstNode (op) { }
~ Type () {}
virtual void prettyPrint (int indent);
};
//---------- CharType ----------
class CharType : public Type {
public:
CharType () : Type (CHAR_TYPE) { }
~ CharType () {}
virtual void prettyPrint (int indent);
};
//---------- IntType ----------
class IntType : public Type {
public:
IntType () : Type (INT_TYPE) { }
~ IntType () {}
virtual void prettyPrint (int indent);
};
//---------- DoubleType ----------
class DoubleType : public Type {
public:
DoubleType () : Type (DOUBLE_TYPE) { }
~ DoubleType () {}
virtual void prettyPrint (int indent);
};
//---------- BoolType ----------
class BoolType : public Type {
public:
BoolType () : Type (BOOL_TYPE) { }
~ BoolType () {}
virtual void prettyPrint (int indent);
};
//---------- VoidType ----------
class VoidType : public Type {
public:
VoidType () : Type (VOID_TYPE) { }
~ VoidType () {}
virtual void prettyPrint (int indent);
};
//---------- TypeOfNullType ----------
class TypeOfNullType : public Type {
public:
TypeOfNullType () : Type (TYPE_OF_NULL_TYPE) { }
~ TypeOfNullType () {}
virtual void prettyPrint (int indent);
};
//---------- AnyType ----------
class AnyType : public Type {
public:
AnyType () : Type (ANY_TYPE) { }
~ AnyType () {}
virtual void prettyPrint (int indent);
};
//---------- PtrType ----------
class PtrType : public Type {
public:
Type * baseType;
PtrType () : Type (PTR_TYPE) {
baseType = NULL;
}
~ PtrType () {}
virtual void prettyPrint (int indent);
};
//---------- ArrayType ----------
class ArrayType : public Type {
public:
Expression * sizeExpr; // May be NULL
Type * baseType;
int sizeInBytes; // -1 = error or "array [*] of ..."
int sizeOfElements; // size of each element
ArrayType () : Type (ARRAY_TYPE) {
sizeExpr = NULL;
baseType = NULL;
sizeInBytes = -1;
sizeOfElements = -1;
}
~ ArrayType () {}
virtual void prettyPrint (int indent);
};
//---------- RecordType ----------
class RecordType : public Type {
public:
RecordField * fields; // Null only if syntax error
int sizeInBytes; // Always a mulitple of 4
Mapping<String, RecordField> * // String --> RecordField
fieldMapping; //
RecordType () : Type (RECORD_TYPE) {
fields = NULL;
sizeInBytes = -1;
fieldMapping = NULL;
}
~ RecordType () {}
virtual void prettyPrint (int indent);
};
//---------- FunctionType ----------
class FunctionType : public Type {
public:
TypeArg * parmTypes; // may be NULL
Type * retType; // never NULL
int totalParmSize; // Size of all parms, including return value!
int retSize; // Size of return result (-1 = void, could be 1)
FunctionType () : Type (FUNCTION_TYPE) {
parmTypes = NULL;
retType = NULL;
totalParmSize = -1;
retSize = 0;
}
~ FunctionType () {}
virtual void prettyPrint (int indent);
};
//---------- NamedType ----------
class NamedType : public Type {
//
// This represents something like "Person" or "Dictionary [String, int]"
//
public:
String * id;
TypeArg * typeArgs; // May be NULL
AstNode * myDef; // Interface, ClassDef, TypeParm,
// or TypeDef, or NULL if error
Mapping <TypeParm, Type> * subst; // Used only for class and interfaces;
// may be NULL
NamedType () : Type (NAMED_TYPE) {
id = NULL;
typeArgs = NULL;
myDef = NULL;
subst = NULL;
}
~ NamedType () {}
virtual void prettyPrint (int indent);
};
//---------- Statement ----------
class Statement : public AstNode {
public:
Statement * next; // Statements are kept on linked lists
Statement (int op) : AstNode (op) {
next = NULL;
}
~ Statement () {}
virtual void prettyPrint (int indent);
};
//---------- IfStmt ----------
class IfStmt : public Statement {
public:
Expression * expr;
Statement * thenStmts; // may be NULL
Statement * elseStmts; // may be NULL
IfStmt () : Statement (IF_STMT) {
expr = NULL;
thenStmts = NULL;
elseStmts = NULL;
}
~ IfStmt () {}
virtual void prettyPrint (int indent);
};
//---------- AssignStmt ----------
class AssignStmt : public Statement {
public:
Expression * lvalue;
Expression * expr;
int sizeInBytes; // The number of bytes to be copied
int dynamicCheck; // 0 means no special check is needed
ClassDef * classDef; // For dynamicCheck == 2 or 3
int arraySize; // For dynamicCheck == 5, 6, or 7
AssignStmt () : Statement (ASSIGN_STMT) {
lvalue = NULL;
expr = NULL;
sizeInBytes = -1;
dynamicCheck = 0;
classDef = NULL;
arraySize = -1;
}
~ AssignStmt () {}
virtual void prettyPrint (int indent);
};
//---------- CallStmt ----------
class CallStmt : public Statement {
public:
CallExpr * expr; // NULL if error
CallStmt () : Statement (CALL_STMT) {
expr = NULL;
}
~ CallStmt () {}
virtual void prettyPrint (int indent);
};
//---------- SendStmt ----------
class SendStmt : public Statement {
public:
SendExpr * expr; // NULL if error
SendStmt () : Statement (SEND_STMT) {
expr = NULL;
}
~ SendStmt () {}
virtual void prettyPrint (int indent);
};
//---------- WhileStmt ----------
class WhileStmt : public Statement {
public:
Expression * expr;
Statement * stmts;
int containsAnyBreaks;
int containsAnyContinues;
char * topLabel;
char * exitLabel;
WhileStmt () : Statement (WHILE_STMT) {
expr = NULL;
stmts = NULL;
containsAnyBreaks = 0;
containsAnyContinues = 0;
topLabel = NULL;
exitLabel = NULL;
}
~ WhileStmt () {}
virtual void prettyPrint (int indent);
};
//---------- DoStmt ----------
class DoStmt : public Statement {
public:
Statement * stmts;
Expression * expr;
int containsAnyBreaks;
int containsAnyContinues;
char * exitLabel;
char * testLabel;