add some comment

This commit is contained in:
ridethepig 2023-03-24 17:40:42 +08:00
parent 67b8d25d85
commit 2c4d9cdcc8

View File

@ -25,19 +25,23 @@ typedef ClassTable *ClassTableP;
class ClassGraphNode { class ClassGraphNode {
private: private:
// tree-shape relation maintainer
ClassGraphNode* parent; ClassGraphNode* parent;
std::vector<ClassGraphNode*> children; std::vector<ClassGraphNode*> children;
// the `class__class` object for which it builds graph
Class_ self; Class_ self;
// for cycle detection
int mark = 0; int mark = 0;
public: public:
// Note that, Class_ = Class__class*, itself is a ptr type, so just use it // Note that, Class_ = Class__class*, itself is a ptr type, so just use it
ClassGraphNode(Class_ self_class, ClassGraphNode* parent_class = nullptr) : ClassGraphNode(Class_ self_class, ClassGraphNode* parent_class = nullptr) :
parent(parent_class), self(self_class) { } parent(parent_class), self(self_class) { }
// Explicitly disable copy constructor
ClassGraphNode(const ClassGraphNode&) = delete; ClassGraphNode(const ClassGraphNode&) = delete;
ClassGraphNode& operator=(const ClassGraphNode) = delete; ClassGraphNode& operator=(const ClassGraphNode) = delete;
~ ClassGraphNode() {
// Long time no C++, god knows if the destructor works or not... // Long time no C++, god knows if the destructor works or not...
~ ClassGraphNode() {
while (!children.empty()) { while (!children.empty()) {
auto child = children[children.size() - 1]; auto child = children[children.size() - 1];
children.pop_back(); children.pop_back();
@ -112,9 +116,14 @@ private:
int semant_errors; int semant_errors;
void install_basic_classes(); void install_basic_classes();
ostream& error_stream; ostream& error_stream;
// Root of the Inheritance Graph (hopefully it is a tree if the program is correct)
ClassGraphNode* class_root; ClassGraphNode* class_root;
std::map<Symbol, ClassGraphNode*> name_to_node;
// again, the correctness of using ptr can be inferred from `Single Copy` of the symbol string // again, the correctness of using ptr can be inferred from `Single Copy` of the symbol string
// Actually, we could use the provided symbol table instead of a stl map for this
// anyways we don't need name shadowing here, I just save my effort
std::map<Symbol, ClassGraphNode*> name_to_node;
public: public:
ClassTable(Classes); ClassTable(Classes);