[Kst] kdeextragear-2/kst

George Staikos staikos at kde.org
Thu Nov 25 08:25:08 CET 2004


CVS commit by staikos: 

Fix bug in the fold visitor that makes it miss the toplevel optimization


  M +14 -3     kst/enodes.cpp   1.33
  M +3 -3      kst/enodes.h   1.22
  M +2 -2      kst/kstequation.cpp   1.14
  M +1 -1      kst/ksteventmonitorentry.cpp   1.27
  M +2 -2      tests/testeqparser.cpp   1.21


--- kdeextragear-2/kst/kst/ksteventmonitorentry.cpp  #1.26:1.27
@@ -160,5 +160,5 @@ KstObject::UpdateType EventMonitorEntry:
         if (rc == 0) {
           _pExpression = static_cast<Equation::Node*>(ParsedEquation);
-          Equation::FoldVisitor vis(&ctx, _pExpression);
+          Equation::FoldVisitor vis(&ctx, &_pExpression);
           _pExpression->collectVectors(_vectorsUsed);
 

--- kdeextragear-2/kst/kst/kstequation.cpp  #1.13:1.14
@@ -245,5 +245,5 @@ void KstEquation::setEquation(const QStr
       ctx.sampleCount = _ns;
       ctx.xVector = *_xVector;
-      Equation::FoldVisitor vis(&ctx, _pe);
+      Equation::FoldVisitor vis(&ctx, &_pe);
       _pe->collectVectors(VectorsUsed);
       _pe->update(-1, &ctx);
@@ -416,5 +416,5 @@ bool KstEquation::FillY(bool force) {
     if (rc == 0) {
       _pe = static_cast<Equation::Node*>(ParsedEquation);
-      Equation::FoldVisitor vis(&ctx, _pe);
+      Equation::FoldVisitor vis(&ctx, &_pe);
       _pe->collectVectors(VectorsUsed);
       ParsedEquation = 0L;

--- kdeextragear-2/kst/kst/enodes.h  #1.21:1.22
@@ -172,5 +172,5 @@ namespace Equation {
     public:
       NodeVisitor();
-      virtual ~NodeVisitor() = 0;
+      virtual ~NodeVisitor();
 
       virtual void visitNode(Node*) = 0;
@@ -181,5 +181,5 @@ namespace Equation {
   class FoldVisitor : public NodeVisitor {
     public:
-      FoldVisitor(Context*, Node*);
+      FoldVisitor(Context*, Node**);
       virtual ~FoldVisitor();
       
@@ -188,5 +188,5 @@ namespace Equation {
     
     protected:
-      Context* _ctx;
+      Context *_ctx;
   };
 

--- kdeextragear-2/kst/kst/enodes.cpp  #1.32:1.33
@@ -899,8 +899,18 @@ NodeVisitor::NodeVisitor() {
 
 
+NodeVisitor::~NodeVisitor() {
+}
+
+
 /////////////////////////////////////////////////////////////////
 
-FoldVisitor::FoldVisitor(Context* ctxIn, Node* rootNode) : NodeVisitor(), _ctx(ctxIn) {
-  rootNode->visit(this);
+FoldVisitor::FoldVisitor(Context* ctxIn, Node** rootNode) : NodeVisitor(), _ctx(ctxIn) {
+  if ((*rootNode)->isConst() && dynamic_cast<Number*>(*rootNode) == 0L) {
+    double v = (*rootNode)->value(ctxIn);
+    delete *rootNode;
+    *rootNode = new Number(v);
+  } else {
+    (*rootNode)->visit(this);
+  }
   _ctx = 0L; // avoids context being marked as 'still reachable'
 }
@@ -912,8 +922,9 @@ FoldVisitor::~FoldVisitor() {
 
 void FoldVisitor::visitNode(Node*) {
+  // useful?
 }
 
 
-void FoldVisitor::visitBinaryNode(BinaryNode * n) {
+void FoldVisitor::visitBinaryNode(BinaryNode *n) {
   if (n->left()->isConst() && dynamic_cast<Number*>(n->left()) == 0L) {
     double v = n->left()->value(_ctx);

--- kdeextragear-2/kst/tests/testeqparser.cpp  #1.20:1.21
@@ -37,6 +37,6 @@ bool doTest(const char *equation, double
       ctx.sampleCount = xVector->length();
     }
-    Equation::FoldVisitor vis(&ctx, eq);
-    if (eq->isConst()) {
+    Equation::FoldVisitor vis(&ctx, &eq);
+    if (eq->isConst() && !dynamic_cast<Equation::Number*>(eq)) {
       if (!optimizerFailed) {
         optimizerFailed = true;





More information about the Kst mailing list