summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustyna Ilczuk <justyna.ilczuk@gmail.com>2013-01-04 13:24:14 +0100
committerJustyna Ilczuk <justyna.ilczuk@gmail.com>2013-01-04 13:24:14 +0100
commit22d6df9927970690136cb46c2728a21bb5830c41 (patch)
treeff87b5515a9c99db9298256ee5769f988a2ebf28
parent02bced0b5dbcd1dc9ccdc6f7bcd5c7ba09b28179 (diff)
downloadsencha-lang-22d6df9927970690136cb46c2728a21bb5830c41.tar.gz
sencha-lang-22d6df9927970690136cb46c2728a21bb5830c41.tar.bz2
sencha-lang-22d6df9927970690136cb46c2728a21bb5830c41.tar.xz
sencha-lang-22d6df9927970690136cb46c2728a21bb5830c41.zip
More small improvements.
-rw-r--r--Sencha-lang/Context.cpp14
-rw-r--r--Sencha-lang/Context.h8
-rw-r--r--Sencha-lang/ContextManager.cpp4
-rw-r--r--Sencha-lang/Parser.cpp3
4 files changed, 23 insertions, 6 deletions
diff --git a/Sencha-lang/Context.cpp b/Sencha-lang/Context.cpp
index c516801..e49c440 100644
--- a/Sencha-lang/Context.cpp
+++ b/Sencha-lang/Context.cpp
@@ -17,6 +17,20 @@ Context::~Context() {
// TODO Auto-generated destructor stub
}
+bool Context::contains_function(std::string name)
+{
+ return contains_sfunction(name) || contains_nfunction(name);
+}
+
+bool Context::contains_sfunction(std::string name)
+{
+ return this->registered_sfunctions.count(name) == 1;
+}
+
+bool Context::contains_nfunction(std::string name)
+{
+ return this->registered_functions.count(name);
+}
void Context::register_function(std::string name, PointerToNativeFunction f)
{
diff --git a/Sencha-lang/Context.h b/Sencha-lang/Context.h
index 916cbd4..0a99731 100644
--- a/Sencha-lang/Context.h
+++ b/Sencha-lang/Context.h
@@ -34,13 +34,17 @@ public:
void add(std::string name, SenchaObject object);
void set(std::string name, SenchaObject object);
SenchaObject get(std::string name);
+ bool contains_function(std::string name);
+ bool contains_sfunction(std::string name);
+ bool contains_nfunction(std::string name);
+ std::map<std::string, PointerToNativeFunction> registered_functions;
+ std::map<std::string, SenchaFunction *> registered_sfunctions;
virtual ~Context();
private:
unsigned int index;
- std::map<std::string, PointerToNativeFunction> registered_functions;
- std::map<std::string, SenchaFunction *> registered_sfunctions;
+
std::map<std::string, SenchaObject> object_store;
};
diff --git a/Sencha-lang/ContextManager.cpp b/Sencha-lang/ContextManager.cpp
index 74a3ac0..5575862 100644
--- a/Sencha-lang/ContextManager.cpp
+++ b/Sencha-lang/ContextManager.cpp
@@ -28,12 +28,12 @@ Context * ContextManager::create_new_context()
SenchaObject ContextManager::execute_function(std::string name, std::vector<ASTExpression *> arguments)
{
SenchaObject result;
- if(contexts["global"]->registered_functions.count(name) == 1)
+ if(contexts["global"]->contains_nfunction(name))
{
result = contexts["global"]->registered_functions[name](arguments);
}
- else if(contexts["global"]->registered_sfunctions.count(name) == 1)
+ else if(contexts["global"]->contains_sfunction(name))
{
std::vector<SenchaObject> evaluated_arguments;
for(auto argument : arguments)
diff --git a/Sencha-lang/Parser.cpp b/Sencha-lang/Parser.cpp
index 0bcbc2f..481e983 100644
--- a/Sencha-lang/Parser.cpp
+++ b/Sencha-lang/Parser.cpp
@@ -120,8 +120,7 @@ bool Parser::is_type()
bool Parser::is_function_name()
{
- if(context_manager->context("global")->registered_functions.count(tok_value) == 1 ||
- context_manager->context("global")->registered_sfunctions.count(tok_value))
+ if(context_manager->context("global")->contains_function(tok_value))
{
read_next();
return true;