[Kst] kdeextragear-2/kst

George Staikos staikos at kde.org
Thu Mar 3 00:04:01 CET 2005


CVS commit by staikos: 

add a Negative node so that printing out the tree is "pretty"


  M +5 -0      kst/enodefactory.cpp   1.10
  M +1 -0      kst/enodefactory.h   1.9
  M +33 -0     kst/enodes.cpp   1.41
  M +12 -0     kst/enodes.h   1.27
  M +1 -1      kst/eparse.c   1.17
  M +1 -1      kst/eparse.y   1.17
  M +2 -2      tests/COVERAGE   1.7
  M +2 -2      tests/testeqparser.cpp   1.26


--- kdeextragear-2/kst/kst/enodefactory.cpp  #1.9:1.10
@@ -88,4 +88,9 @@ void *NewNot(void *n) {
 
 
+void *NewNegation(void *n) {
+  return new Negation(static_cast<Node*>(n));
+}
+
+
 void DeleteNode(void *n) {
   delete static_cast<Node*>(n);

--- kdeextragear-2/kst/kst/enodefactory.h  #1.8:1.9
@@ -49,4 +49,5 @@ extern "C" {
   void *NewNumber(double n);
   void *NewNot(void *n);
+  void *NewNegation(void *n);
   void AppendArgument(void *list, void *arg);
 

--- kdeextragear-2/kst/kst/enodes.cpp  #1.40:1.41
@@ -802,4 +802,37 @@ QString Number::text() const {
 
 /////////////////////////////////////////////////////////////////
+Negation::Negation(Node *node)
+: Node(), _n(node) {
+  //printf("%p: New Negation: %p\n", (void*)this, (void*)n);
+}
+
+
+Negation::~Negation() {
+  delete _n;
+  _n = 0L;
+}
+
+
+double Negation::value(Context *ctx) {
+  double v = _n->value(ctx);
+  return (v == v) ? -v : v;
+}
+
+
+bool Negation::isConst() {
+  return _n->isConst();
+}
+
+
+QString Negation::text() const {
+  if (_parentheses) {
+    return QString("(-") + _n->text() + ")";
+  } else {
+    return QString("-") + _n->text();
+  }
+}
+
+
+/////////////////////////////////////////////////////////////////
 LogicalNot::LogicalNot(Node *node)
 : Node(), _n(node) {

--- kdeextragear-2/kst/kst/enodes.h  #1.26:1.27
@@ -210,4 +210,16 @@ namespace Equation {
 
 
+  class Negation : public Node {
+    public:
+      Negation(Node *node);
+      ~Negation();
+      bool isConst();
+      double value(Context*);
+      QString text() const;
+
+    protected:
+      Node *_n;
+  };
+
   class LogicalNot : public Node {
     public:

--- kdeextragear-2/kst/kst/eparse.c  #1.16:1.17
@@ -1479,5 +1479,5 @@ yyreduce:
   case 57:
 #line 173 "eparse.y"
-    { yyval.n = NewSubtraction(NewNumber(0), yyvsp[0].n); }
+    { yyval.n = NewNegation(yyvsp[0].n); }
     break;
 

--- kdeextragear-2/kst/kst/eparse.y  #1.16:1.17
@@ -171,5 +171,5 @@ TERM		:	TERM T_MULTIPLY NEG
 
 NEG             :       T_SUBTRACT NEG %prec U_SUBTRACT
-                        { $<n>$ = NewSubtraction(NewNumber(0), $<n>2); }
+                        { $<n>$ = NewNegation($<n>2); }
                 |       T_NOT NEG
                         { $<n>$ = NewNot($<n>2); }

--- kdeextragear-2/kst/tests/COVERAGE  #1.6:1.7
@@ -3,6 +3,6 @@
 
 Test: testeqparser
-Last Run: 03/01/05
-Failures: 2
+Last Run: 03/02/05
+Failures: 0
 
 File                    Cov     Notes

--- kdeextragear-2/kst/tests/testeqparser.cpp  #1.25:1.26
@@ -478,7 +478,7 @@ int main(int argc, char **argv) {
   testText(" ((3 * x)) ", "(3*x)");
   testText(" ((3 * x)) ", "(3*x)");
-  testText("(-3)", "-3");
+  testText("(-3)", "(-3)");
   testText("(x)", "x");
-  testText("(3*(-(x+5)))", "3*-(x+5)");
+  testText("(3*(-(x+5)))", "(3*(-(x+5)))");
   testText("(sin((x)))", "sin(x)");
 




More information about the Kst mailing list