-
Notifications
You must be signed in to change notification settings - Fork 0
/
cgen.h
94 lines (79 loc) · 2.46 KB
/
cgen.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
#include <assert.h>
#include <stdio.h>
#include "emit.h"
#include "cool-tree.h"
#include "symtab.h"
enum Basicness {Basic, NotBasic};
#define TRUE 1
#define FALSE 0
class CgenClassTable;
typedef CgenClassTable *CgenClassTableP;
class CgenNode;
typedef CgenNode *CgenNodeP;
class CgenClassTable : public SymbolTable<Symbol,CgenNode> {
private:
List<CgenNode> *nds;
ostream& str;
int stringclasstag;
int intclasstag;
int boolclasstag;
// The following methods emit code for
// constants and global declarations.
void code_global_data();
void code_global_text();
void code_bools(int);
void code_select_gc();
void code_constants();
void code_initializer(CgenNode *nd);
// The following creates an inheritance graph from
// a list of classes. The graph is implemented as
// a tree of `CgenNode', and class names are placed
// in the base class symbol table.
void install_basic_classes();
void install_class(CgenNodeP nd);
void install_classes(Classes cs);
void build_inheritance_tree();
void set_relations(CgenNodeP nd);
public:
CgenClassTable(Classes, ostream& str);
void code();
CgenNodeP root();
};
class CgenNode : public class__class {
private:
CgenNodeP parentnd; // Parent of class
List<CgenNode> *children; // Children of class
Basicness basic_status; // `Basic' if class is basic
// `NotBasic' otherwise
int classTag;
public:
CgenNode(Class_ c,
Basicness bstatus,
CgenClassTableP class_table);
void add_child(CgenNodeP child);
List<CgenNode> *get_children() { return children; }
void set_parentnd(CgenNodeP p);
CgenNodeP get_parentnd() { return parentnd; }
int basic() { return (basic_status == Basic); }
void set_tag(int tag) {classTag = tag;}
int tag() { return classTag; }
void code_prototype(ostream &);
void code_dispatchtable(std::map<Symbol, Symbol> &, std::vector<std::pair<Symbol,Symbol>> & , ostream &);
void override_func(std::map<Symbol, Symbol>& methodList, Feature func) {
if(!func->is_attr()){
if(methodList.find(func->get_name()) == methodList.end()){
methodList.insert(std::pair<Symbol, Symbol>(func->get_name(), name));
}
}
}
void code_methods(ostream &);
};
class BoolConst
{
private:
int val;
public:
BoolConst(int);
void code_def(ostream&, int boolclasstag);
void code_ref(ostream&) const;
};