[jruby-joni] 151/194: fix node swapping

Hideki Yamane henrich at moszumanska.debian.org
Thu Feb 1 12:04:36 UTC 2018


This is an automated email from the git hooks/post-receive script.

henrich pushed a commit to branch debian/sid
in repository jruby-joni.

commit 45fc49bb646a7c3a162fe5eae873c1df23b6c7e6
Author: Marcin Mielzynski <lopx at gazeta.pl>
Date:   Thu Jan 11 18:56:56 2018 +0100

    fix node swapping
---
 src/org/joni/Analyser.java           | 22 +++++---------
 src/org/joni/Parser.java             |  3 +-
 src/org/joni/ast/AnchorNode.java     |  4 +--
 src/org/joni/ast/CallNode.java       | 10 ------
 src/org/joni/ast/EncloseNode.java    |  4 +--
 src/org/joni/ast/ListNode.java       | 59 +++++-------------------------------
 src/org/joni/ast/Node.java           | 43 +++++++-------------------
 src/org/joni/ast/QuantifierNode.java |  4 +--
 8 files changed, 35 insertions(+), 114 deletions(-)

diff --git a/src/org/joni/Analyser.java b/src/org/joni/Analyser.java
index b604b1f..01d641f 100644
--- a/src/org/joni/Analyser.java
+++ b/src/org/joni/Analyser.java
@@ -32,8 +32,6 @@ import static org.joni.ast.ListNode.newAlt;
 import static org.joni.ast.ListNode.newList;
 import static org.joni.ast.QuantifierNode.isRepeatInfinite;
 
-import java.util.HashSet;
-
 import org.jcodings.CaseFoldCodeItem;
 import org.jcodings.ObjPtr;
 import org.jcodings.Ptr;
@@ -43,8 +41,8 @@ import org.joni.ast.BackRefNode;
 import org.joni.ast.CClassNode;
 import org.joni.ast.CTypeNode;
 import org.joni.ast.CallNode;
-import org.joni.ast.ListNode;
 import org.joni.ast.EncloseNode;
+import org.joni.ast.ListNode;
 import org.joni.ast.Node;
 import org.joni.ast.QuantifierNode;
 import org.joni.ast.StringNode;
@@ -104,17 +102,13 @@ final class Analyser extends Parser {
             }
         } // USE_NAMED_GROUP
 
-        if (Config.DEBUG_PARSE_TREE_RAW && Config.DEBUG_PARSE_TREE) {
-            Config.log.println("<RAW TREE>");
-            Config.log.println(root + "\n");
-        }
+        if (Config.DEBUG_PARSE_TREE && Config.DEBUG_PARSE_TREE_RAW) Config.log.println("<RAW TREE>\n" + root + "\n");
 
-        root = setupTree(root, 0);
-        if (Config.DEBUG_PARSE_TREE) {
-            if (Config.DEBUG_PARSE_TREE_RAW) Config.log.println("<TREE>");
-            root.verifyTree(new HashSet<Node>(), env.reg.warnings);
-            Config.log.println(root + "\n");
-        }
+        Node.RootNode top = Node.newRoot(root);
+        setupTree(root, 0);
+        root = top.getRoot();
+
+        if (Config.DEBUG_PARSE_TREE) Config.log.println("<TREE>\n" + root + "\n");
 
         regex.captureHistory = env.captureHistory;
         regex.btMemStart = env.btMemStart;
@@ -1883,7 +1877,7 @@ final class Analyser extends Parser {
                     if (len * qn.lower <= EXPAND_STRING_MAX_LENGTH) {
                         StringNode str = new StringNode();
                         str.flag = sn.flag;
-                        str.swap(qn);
+                        qn.swap(str);
                         int n = qn.lower;
                         for (int i = 0; i < n; i++) {
                             str.catBytes(sn.bytes, sn.p, sn.end);
diff --git a/src/org/joni/Parser.java b/src/org/joni/Parser.java
index c8c46de..14dbb8c 100644
--- a/src/org/joni/Parser.java
+++ b/src/org/joni/Parser.java
@@ -1331,7 +1331,8 @@ class Parser extends Lexer {
                 target = qn;
             } else if (ret == 2) { /* split case: /abc+/ */
                 target = ListNode.newList(target, null);
-                ListNode tmp = ((ListNode)target).setTail(ListNode.newList(qn, null));
+                ListNode tmp = ListNode.newList(qn, null);
+                ((ListNode)target).setTail(tmp);
 
                 fetchToken();
                 return parseExpRepeatForCar(target, tmp, group);
diff --git a/src/org/joni/ast/AnchorNode.java b/src/org/joni/ast/AnchorNode.java
index 205091e..49c4f7e 100644
--- a/src/org/joni/ast/AnchorNode.java
+++ b/src/org/joni/ast/AnchorNode.java
@@ -39,8 +39,8 @@ public final class AnchorNode extends Node {
     }
 
     @Override
-    protected void setChild(Node newChild) {
-        target = newChild;
+    protected void setChild(Node child) {
+        target = child;
     }
 
     @Override
diff --git a/src/org/joni/ast/CallNode.java b/src/org/joni/ast/CallNode.java
index ff450f0..1bc7f9e 100644
--- a/src/org/joni/ast/CallNode.java
+++ b/src/org/joni/ast/CallNode.java
@@ -19,10 +19,7 @@
  */
 package org.joni.ast;
 
-import java.util.Set;
-
 import org.joni.UnsetAddrList;
-import org.joni.WarnCallback;
 
 public final class CallNode extends StateNode {
     public final byte[]name;
@@ -62,13 +59,6 @@ public final class CallNode extends StateNode {
     }
 
     @Override
-    public void verifyTree(Set<Node> set, WarnCallback warnings) {
-        if (target == null || target.parent == this)
-            warnings.warn(this.getAddressName() + " doesn't point to a target or the target has been stolen");
-        // do not recurse here
-    }
-
-    @Override
     public String toString(int level) {
         StringBuilder value = new StringBuilder(super.toString(level));
         value.append("\n  name: " + new String(name, nameP, nameEnd - nameP));
diff --git a/src/org/joni/ast/EncloseNode.java b/src/org/joni/ast/EncloseNode.java
index cc86d92..8d49371 100644
--- a/src/org/joni/ast/EncloseNode.java
+++ b/src/org/joni/ast/EncloseNode.java
@@ -56,8 +56,8 @@ public final class EncloseNode extends StateNode implements EncloseType {
     }
 
     @Override
-    protected void setChild(Node newChild) {
-        target = newChild;
+    protected void setChild(Node child) {
+        target = child;
     }
 
     @Override
diff --git a/src/org/joni/ast/ListNode.java b/src/org/joni/ast/ListNode.java
index 1423c32..76aaeaf 100644
--- a/src/org/joni/ast/ListNode.java
+++ b/src/org/joni/ast/ListNode.java
@@ -19,9 +19,6 @@
  */
 package org.joni.ast;
 
-import java.util.Set;
-
-import org.joni.WarnCallback;
 import org.joni.exception.ErrorMessages;
 import org.joni.exception.InternalException;
 
@@ -47,11 +44,8 @@ public final class ListNode extends Node {
 
     public static ListNode listAdd(ListNode list, Node value) {
         ListNode n = newList(value, null);
-
         if (list != null) {
-            while (list.tail != null) {
-                list = list.tail;
-            }
+            while (list.tail != null) list = list.tail;
             list.setTail(n);
         }
         return n;
@@ -66,8 +60,8 @@ public final class ListNode extends Node {
     }
 
     @Override
-    protected void setChild(Node newChild) {
-        value = newChild;
+    protected void setChild(Node child) {
+        value = child;
     }
 
     @Override
@@ -75,50 +69,13 @@ public final class ListNode extends Node {
         return value;
     }
 
-    @Override
-    public void swap(Node with) {
-        if (tail != null) {
-            tail.parent = with;
-            if (with instanceof ListNode) {
-                ListNode withCan = (ListNode)with;
-                withCan.tail.parent = this;
-                ListNode tmp = tail;
-                tail = withCan.tail;
-                withCan.tail = tmp;
-            }
-        }
-        super.swap(with);
-    }
-
-    @Override
-    public void verifyTree(Set<Node> set, WarnCallback warnings) {
-        if (!set.contains(this)) {
-            set.add(this);
-            if (value != null) {
-                if (value.parent != this) {
-                    warnings.warn("broken list value: " + this.getAddressName() + " -> " +  value.getAddressName());
-                }
-                value.verifyTree(set,warnings);
-            }
-            if (tail != null) {
-                if (tail.parent != this) {
-                    warnings.warn("broken list tail: " + this.getAddressName() + " -> " +  tail.getAddressName());
-                }
-                tail.verifyTree(set,warnings);
-            }
-        }
-    }
-
-    public Node setValue(Node ca) {
-        value = ca;
-        ca.parent = this;
-        return value;
+    public void setValue(Node value) {
+        this.value = value;
+        value.parent = this;
     }
 
-    public ListNode setTail(ListNode cd) {
-        tail = cd;
-        cd.parent = this;
-        return tail;
+    public void setTail(ListNode tail) {
+        this.tail = tail;
     }
 
     @Override
diff --git a/src/org/joni/ast/Node.java b/src/org/joni/ast/Node.java
index 7ff61ff..cbbcff1 100644
--- a/src/org/joni/ast/Node.java
+++ b/src/org/joni/ast/Node.java
@@ -19,9 +19,6 @@
  */
 package org.joni.ast;
 
-import java.util.Set;
-
-import org.joni.WarnCallback;
 import org.joni.constants.NodeType;
 
 public abstract class Node implements NodeType {
@@ -40,37 +37,19 @@ public abstract class Node implements NodeType {
         return 1 << getType();
     }
 
-    protected void setChild(Node tgt){}         // default definition
-    protected Node getChild(){return null;};    // default definition
-
-    public void swap(Node with) {
-        Node tmp;
-
-        //if (getChild() != null) getChild().parent = with;
-        //if (with.getChild() != null) with.getChild().parent = this;
-
-        //tmp = getChild();
-        //setChild(with.getChild());
-        //with.setChild(tmp);
-
-        if (parent != null) parent.setChild(with);
-
-        if (with.parent != null) with.parent.setChild(this);
-
-        tmp = parent;
-        parent = with.parent;
-        with.parent = tmp;
+    protected void setChild(Node tgt){
+        // default definition
     }
 
-    // overridden by ConsAltNode and CallNode
-    public void verifyTree(Set<Node> set, WarnCallback warnings) {
-        if (!set.contains(this) && getChild() != null) {
-            set.add(this);
-            if (getChild().parent != this) {
-                warnings.warn("broken link to child: " + this.getAddressName() + " -> " + getChild().getAddressName());
-            }
-            getChild().verifyTree(set, warnings);
-        }
+    protected Node getChild(){
+        // default definition
+        return null;
+    };
+
+    public void swap(Node with) {
+        with.parent = parent;
+        parent.setChild(with);
+        parent = null;
     }
 
     public abstract String getName();
diff --git a/src/org/joni/ast/QuantifierNode.java b/src/org/joni/ast/QuantifierNode.java
index 3837e43..cbbf08d 100644
--- a/src/org/joni/ast/QuantifierNode.java
+++ b/src/org/joni/ast/QuantifierNode.java
@@ -58,8 +58,8 @@ public final class QuantifierNode extends StateNode {
     }
 
     @Override
-    protected void setChild(Node newChild) {
-        target = newChild;
+    protected void setChild(Node child) {
+        target = child;
     }
 
     @Override

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/jruby-joni.git



More information about the pkg-java-commits mailing list