Permalink
Browse files

implement 'exists'

  • Loading branch information...
1 parent 57a77d6 commit 000b8f10de7766f1b75d8b2b75e879dfaa65217e @NotFound committed Oct 24, 2011
Showing with 30 additions and 2 deletions.
  1. +1 −1 t/base/features.winxed
  2. +6 −0 winxedxx.h
  3. +4 −1 winxedxx.winxed
  4. +11 −0 winxedxx_classes.cxx
  5. +1 −0 winxedxx_default.h
  6. +1 −0 winxedxx_null.h
  7. +1 −0 winxedxx_object.h
  8. +4 −0 winxedxx_objectptr.cxx
  9. +1 −0 winxedxx_types.h
View
2 t/base/features.winxed
@@ -87,7 +87,7 @@ function test_hash(test)
var hash = { "a" : 1, "b" : "x" };
test.is_string(hash["b"], "x", "hash element initialized");
test.nok(exists hash["none"], "hash exists false case");
- test.todo(exists hash["a"], "hash exists true case");
+ test.ok(exists hash["a"], "hash exists true case");
}
namespace Foo
View
6 winxedxx.h
@@ -100,6 +100,7 @@ class WxxHash : public WxxDefault
WxxObjectPtr &set_pmc_keyed(const std::string &s, const WxxObjectPtr &value);
WxxObjectPtr get_pmc_keyed(const std::string &s);
WxxObjectPtr get_pmc_keyed(const char *s);
+ int exists(const std::string &key);
private:
std::map<std::string, WxxObjectPtr> hsh;
};
@@ -369,6 +370,11 @@ WxxObjectPtr & WxxHash::set_pmc_keyed(const std::string &s, const WxxObjectPtr &
return hsh[s];
}
+int WxxHash::exists(const std::string &key)
+{
+ return hsh.find(key) != hsh.end();
+}
+
//*************************************************************
WxxNCI::WxxNCI(const std::string &funcname) :
View
5 winxedxx.winxed
@@ -873,7 +873,10 @@ function emit_OpExistsExpr(out, expr)
SyntaxError("exits with invalid operator", expr);
// Fake implementation to allow some testing
- out.print("false");
+ emit_expr(out, subexpr.left);
+ var arg = subexpr.args.getarg(0);
+ out.print(".exists");
+ emit_expr(out, arg);
}
function emit_memberexpr(out, expr)
View
11 winxedxx_classes.cxx
@@ -114,6 +114,12 @@ WxxObjectPtr & WxxNull::set_pmc_keyed(const std::string &s, const WxxObjectPtr &
return winxedxxnull;
}
+int WxxNull::exists(const std::string &key)
+{
+ nullaccess("exists");
+ return 0;
+}
+
WxxObjectPtr & WxxNull::get_attr_str(const std::string &s)
{
nullaccess("get_attr_str");
@@ -277,6 +283,11 @@ WxxObjectPtr & WxxDefault::set_pmc_keyed(const std::string &s, const WxxObjectPt
notimplemented("set_pmc_keyed");
return winxedxxnull;
}
+int WxxDefault::exists(const std::string &key)
+{
+ notimplemented("exists");
+ return 0;
+}
WxxObjectPtr & WxxDefault::get_attr_str(const std::string &s)
{
View
1 winxedxx_default.h
@@ -33,6 +33,7 @@ class WxxDefault : public WxxObject
WxxObjectPtr get_pmc_keyed(const char *s);
void set_pmc_keyed(int i, const WxxObjectPtr &value);
WxxObjectPtr & set_pmc_keyed(const std::string &s, const WxxObjectPtr &value);
+ int exists(const std::string &key);
WxxObjectPtr & get_attr_str(const std::string &s);
void set_attr_str(const std::string &s, const WxxObjectPtr &value);
WxxObjectPtr get_iter();
View
1 winxedxx_null.h
@@ -27,6 +27,7 @@ class WxxNull : public WxxObject
WxxObjectPtr get_pmc_keyed(const std::string &s);
WxxObjectPtr get_pmc_keyed(const char *s);
void set_pmc_keyed(int i, const WxxObjectPtr &value);
+ int exists(const std::string &key);
WxxObjectPtr & set_pmc_keyed(const std::string &s, const WxxObjectPtr &value);
WxxObjectPtr & get_attr_str(const std::string &s);
void set_attr_str(const std::string &s, const WxxObjectPtr &value);
View
1 winxedxx_object.h
@@ -26,6 +26,7 @@ class WxxObject
virtual WxxObjectPtr get_pmc_keyed(const std::string &s) = 0;
virtual WxxObjectPtr get_pmc_keyed(const char *s) = 0;
virtual void set_pmc_keyed(int i, const WxxObjectPtr &value) = 0;
+ virtual int exists(const std::string &key) = 0;
virtual WxxObjectPtr & set_pmc_keyed(const std::string &s, const WxxObjectPtr &value) = 0;
virtual WxxObjectPtr & get_attr_str(const std::string &s) = 0;
virtual void set_attr_str(const std::string &s, const WxxObjectPtr &value) = 0;
View
4 winxedxx_objectptr.cxx
@@ -187,6 +187,10 @@ WxxObjectPtr & WxxObjectPtr::set_pmc_keyed(const std::string &s, const WxxObject
{
return object->set_pmc_keyed(s, value);
}
+int WxxObjectPtr::exists(const std::string &key)
+{
+ return object->exists(key);
+}
void WxxObjectPtr::print()
{
View
1 winxedxx_types.h
@@ -65,6 +65,7 @@ class WxxObjectPtr
WxxObjectPtr get_pmc_keyed(const char *s);
void set_pmc_keyed(int i, const WxxObjectPtr &value);
WxxObjectPtr & set_pmc_keyed(const std::string &s, const WxxObjectPtr &value);
+ int exists(const std::string &key);
void print();
WxxObjectPtr & get_attr_str(const std::string &s);
void set_attr_str(const std::string &s, const WxxObjectPtr &value);

0 comments on commit 000b8f1

Please sign in to comment.