diff --git a/assignments/PA4/semant.h b/assignments/PA4/semant.h index 1d97e01..e8c6694 100644 --- a/assignments/PA4/semant.h +++ b/assignments/PA4/semant.h @@ -25,19 +25,23 @@ typedef ClassTable *ClassTableP; class ClassGraphNode { private: + // tree-shape relation maintainer ClassGraphNode* parent; std::vector children; + // the `class__class` object for which it builds graph Class_ self; + // for cycle detection int mark = 0; public: // Note that, Class_ = Class__class*, itself is a ptr type, so just use it ClassGraphNode(Class_ self_class, ClassGraphNode* parent_class = nullptr) : parent(parent_class), self(self_class) { } + // Explicitly disable copy constructor ClassGraphNode(const ClassGraphNode&) = delete; ClassGraphNode& operator=(const ClassGraphNode) = delete; + // Long time no C++, god knows if the destructor works or not... ~ ClassGraphNode() { - // Long time no C++, god knows if the destructor works or not... while (!children.empty()) { auto child = children[children.size() - 1]; children.pop_back(); @@ -112,9 +116,14 @@ private: int semant_errors; void install_basic_classes(); ostream& error_stream; + + // Root of the Inheritance Graph (hopefully it is a tree if the program is correct) ClassGraphNode* class_root; - std::map name_to_node; + // 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 name_to_node; public: ClassTable(Classes);