diff --git a/functions.cpp b/functions.cpp index 04f5099..ef15cd4 100644 --- a/functions.cpp +++ b/functions.cpp @@ -3,7 +3,7 @@ #include "./shunting-yard-exceptions.h" /* * * * * class Function * * * * */ -packToken Function::call(packToken _this, Function* func, +packToken Function::call(packToken _this, const Function* func, TokenList* args, TokenMap scope) { // Build the local namespace: TokenMap kwargs; diff --git a/functions.h b/functions.h index c41c164..8c8efa1 100644 --- a/functions.h +++ b/functions.h @@ -8,7 +8,7 @@ typedef std::list args_t; class Function : public TokenBase { public: - static packToken call(packToken _this, Function* func, + static packToken call(packToken _this, const Function* func, TokenList* args, TokenMap scope); public: Function() { this->type = FUNC; } diff --git a/objects.cpp b/objects.cpp index fab004c..ef6e4cc 100644 --- a/objects.cpp +++ b/objects.cpp @@ -110,7 +110,7 @@ MapData_t& MapData_t::operator=(const MapData_t& other) { /* * * * * TokenMap Class: * * * * */ -packToken* TokenMap::find(std::string key) { +packToken* TokenMap::find(const std::string& key) { TokenMap_t::iterator it = map().find(key); if (it != map().end()) { @@ -122,7 +122,19 @@ packToken* TokenMap::find(std::string key) { } } -TokenMap* TokenMap::findMap(std::string key) { +const packToken* TokenMap::find(const std::string& key) const { + TokenMap_t::const_iterator it = map().find(key); + + if (it != map().end()) { + return &it->second; + } else if (parent()) { + return parent()->find(key); + } else { + return 0; + } +} + +TokenMap* TokenMap::findMap(const std::string& key) { TokenMap_t::iterator it = map().find(key); if (it != map().end()) { diff --git a/objects.h b/objects.h index a549450..1115731 100644 --- a/objects.h +++ b/objects.h @@ -93,8 +93,9 @@ struct TokenMap : public pack, public Iterable { } public: - packToken* find(std::string key); - TokenMap* findMap(std::string key); + packToken* find(const std::string& key); + const packToken* find(const std::string& key) const; + TokenMap* findMap(const std::string& key); void assign(std::string key, TokenBase* value); void insert(std::string key, TokenBase* value);