blog-static/code/compiler/11/env.cpp
Danila Fedorin d7846e0b32
Some checks failed
continuous-integration/drone/push Build is failing
Fork off code for part 11 of compiler series.
2020-04-09 23:48:53 -07:00

24 lines
619 B
C++

#include "env.hpp"
int env_var::get_offset(const std::string& name) const {
if(name == this->name) return 0;
if(parent) return parent->get_offset(name) + 1;
throw 0;
}
bool env_var::has_variable(const std::string& name) const {
if(name == this->name) return true;
if(parent) return parent->has_variable(name);
return false;
}
int env_offset::get_offset(const std::string& name) const {
if(parent) return parent->get_offset(name) + offset;
throw 0;
}
bool env_offset::has_variable(const std::string& name) const {
if(parent) return parent->has_variable(name);
return false;
}