#ifndef MT2Q2A_H #define MT2Q2A_H ///////////////////////////////////////////// // MT2Q2a.h - Scope class #include #include class Scope { public: std::string& name() { return _name; } std::string& type() { return _type; } size_t& complexity() { return _complexity; } std::vector& childType() { return _childType; } static bool match(Scope* pS1, Scope* pS2); private: std::string _name = "unknown"; std::string _type = "unknown"; size_t _complexity = 0; std::vector _childType; // child scope types must be added in }; // order encountered in parent scope inline bool Scope::match(Scope* pS1, Scope* pS2) { if (pS1->type() != pS2->type()) return false; size_t complexityTolerance = 1; bool complexityMatch = (pS1->complexity() < pS2->complexity() + complexityTolerance) && (pS1->complexity() > pS2->complexity() - complexityTolerance); bool childTypeMatch = true; if (pS1->childType().size() == pS2->childType().size()) { for (size_t i = 0; i < pS1->childType().size(); ++i) { if (pS1->childType()[i] != pS2->childType()[i]) { childTypeMatch = false; // assumes each child type added in break; // order encountered in parent scope } } } else { childTypeMatch = false; } return childTypeMatch && complexityMatch; } #endif