Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

improve operators ++ and --:

- Barely implement postfix variants
- Use functions instead of operators for the implementation
  • Loading branch information...
commit a8a097aa357d0b7dee49857f71581731ccf992ac 1 parent 53b8b9d
@NotFound authored
View
16 winxedxx.h
@@ -549,6 +549,22 @@ inline int operator <= (int i, const WxxObjectPtr &obj)
return i <= int(obj);
}
+//*********** operators ++ and -- prefix ****************
+
+int & wxx_preinc(int &i);
+WxxObjectPtr & wxx_preinc(WxxObjectPtr &o);
+
+int & wxx_predec(int &i);
+WxxObjectPtr & wxx_predec(WxxObjectPtr &o);
+
+//*********** operators ++ and -- postfix ****************
+
+int wxx_postinc(int &i);
+WxxObjectPtr wxx_postinc(WxxObjectPtr &o);
+
+int wxx_postdec(int &i);
+WxxObjectPtr wxx_postdec(WxxObjectPtr &o);
+
//*********** operator + ****************
int wxx_add(int i1, int i2);
View
35 winxedxx.winxed
@@ -756,6 +756,26 @@ function emitExpr(var out, :VarCastExpr expr)
}
}
+function emitExpr(var out, :OpPreIncExpr expr)
+{
+ emit_plainfun1(out, "wxx_preinc", expr.subexpr);
+}
+
+function emitExpr(var out, :OpPreDecExpr expr)
+{
+ emit_plainfun1(out, "wxx_predec", expr.subexpr);
+}
+
+function emitExpr(var out, :OpPostIncExpr expr)
+{
+ emit_plainfun1(out, "wxx_postinc", expr.subexpr);
+}
+
+function emitExpr(var out, :OpPostDecExpr expr)
+{
+ emit_plainfun1(out, "wxx_postdec", expr.subexpr);
+}
+
//**********************************************************************
function emit_callargs(out, args)
@@ -1329,21 +1349,6 @@ function emitExpr(var out, var expr)
case expr instanceof OpNotExpr:
emit_OpNotExpr(out, expr);
break;
- case expr instanceof OpPreIncExpr:
- out.print("++");
- emit_expr(out, expr.subexpr);
- break;
- case expr instanceof OpPreDecExpr:
- out.print("--");
- emit_expr(out, expr.subexpr);
- break;
- case expr instanceof OpPostIncExpr:
- emit_expr(out, expr.subexpr);
- out.print("++");
- break;
- case expr instanceof OpPostDecExpr:
- emit_expr(out, expr.subexpr);
- out.print("--");
case expr instanceof OpUnaryMinusExpr:
out.print("-");
emit_expr(out, expr.subexpr);
View
4 winxedxx_objectptr.cxx
@@ -158,13 +158,13 @@ WxxObjectPtr::operator std::string () const
return object->get_string();
}
-WxxObjectPtr & WxxObjectPtr::operator++()
+WxxObjectPtr & WxxObjectPtr::increment()
{
object->increment();
return *this;
}
-WxxObjectPtr & WxxObjectPtr::operator--()
+WxxObjectPtr & WxxObjectPtr::decrement()
{
object->decrement();
return *this;
View
4 winxedxx_types.h
@@ -73,8 +73,8 @@ class WxxObjectPtr
operator bool() const;
operator double() const;
operator std::string() const;
- WxxObjectPtr & operator++();
- WxxObjectPtr & operator--();
+ WxxObjectPtr & increment();
+ WxxObjectPtr & decrement();
int is_null() const;
int instanceof(const std::string &type) const;
std::string get_string() const;
View
57 winxedxx_util.cxx
@@ -1,10 +1,7 @@
// winxedxx_util.cxx
// (C) 2011-2012 Julián Albo
-#include "winxedxx_types.h"
-#include "winxedxx_object.h"
-#include "winxedxx_default.h"
-#include "winxedxx_integer.h"
+#include "winxedxx.h"
#include "winxedxx_handle.h"
#include "winxedxx_ptr.h"
#include "winxedxx_bytebuffer.h"
@@ -114,6 +111,58 @@ std::string wxx_repeat_string(std::string s, int n)
return result;
}
+//*********** operators ++ and -- prefix ****************
+
+int & wxx_preinc(int &i)
+{
+ return ++i;
+}
+
+WxxObjectPtr & wxx_preinc(WxxObjectPtr &o)
+{
+ return o.increment();
+}
+
+int & wxx_predec(int &i)
+{
+ return --i;
+}
+
+WxxObjectPtr & wxx_predec(WxxObjectPtr &o)
+{
+ return o.decrement();
+}
+
+//*********** operators ++ and -- postfix ****************
+
+// Incorrect implementation for object ptr, but enough for some uses.
+// It must modify in place the content pointed by the operand,
+// this makes it point to a new object.
+
+int wxx_postinc(int &i)
+{
+ return i++;
+}
+
+WxxObjectPtr wxx_postinc(WxxObjectPtr &o)
+{
+ WxxObjectPtr r(o);
+ o = wxx_add(r, 1);
+ return r;
+}
+
+int wxx_postdec(int &i)
+{
+ return i--;
+}
+
+WxxObjectPtr wxx_postdec(WxxObjectPtr &o)
+{
+ WxxObjectPtr r(o);
+ o = wxx_sub(r, 1);
+ return r;
+}
+
//*********** operator + ****************
int wxx_add(int i1, int i2)
Please sign in to comment.
Something went wrong with that request. Please try again.