[jruby-joni] 169/194: refactor warnings and remove warnings reference from regex object

Hideki Yamane henrich at moszumanska.debian.org
Thu Feb 1 12:04:38 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 03a31ddb534595235cd916ee926d049bcf2fdce1
Author: Marcin Mielzynski <lopx at gazeta.pl>
Date:   Tue Jan 16 21:05:37 2018 +0100

    refactor warnings and remove warnings reference from regex object
---
 src/org/joni/Analyser.java           |  4 ++--
 src/org/joni/ByteCodePrinter.java    |  3 ---
 src/org/joni/Config.java             |  2 +-
 src/org/joni/Lexer.java              |  6 +++---
 src/org/joni/Parser.java             |  4 ++--
 src/org/joni/Regex.java              | 10 ++--------
 src/org/joni/ScanEnvironment.java    | 10 ++++++----
 src/org/joni/WarnCallback.java       |  5 +++++
 src/org/joni/ast/QuantifierNode.java |  9 +++------
 test/org/joni/test/Test.java         |  6 +-----
 10 files changed, 25 insertions(+), 34 deletions(-)

diff --git a/src/org/joni/Analyser.java b/src/org/joni/Analyser.java
index f38e45d..8372efe 100644
--- a/src/org/joni/Analyser.java
+++ b/src/org/joni/Analyser.java
@@ -54,8 +54,8 @@ import org.joni.constants.TargetInfo;
 
 final class Analyser extends Parser {
 
-    protected Analyser(Regex regex, Syntax syntax, byte[]bytes, int p, int end) {
-        super(regex, syntax, bytes, p, end);
+    protected Analyser(Regex regex, Syntax syntax, byte[]bytes, int p, int end, WarnCallback warnings) {
+        super(regex, syntax, bytes, p, end, warnings);
     }
 
     protected final void compile() {
diff --git a/src/org/joni/ByteCodePrinter.java b/src/org/joni/ByteCodePrinter.java
index 8a235a0..edb7e07 100644
--- a/src/org/joni/ByteCodePrinter.java
+++ b/src/org/joni/ByteCodePrinter.java
@@ -20,7 +20,6 @@
 package org.joni;
 
 import org.jcodings.Encoding;
-import org.joni.ast.CClassNode;
 import org.joni.constants.Arguments;
 import org.joni.constants.OPCode;
 import org.joni.constants.OPSize;
@@ -31,14 +30,12 @@ class ByteCodePrinter {
     final int codeLength;
     final byte[][] templates;
     final Encoding enc;
-    final WarnCallback warnings;
 
     public ByteCodePrinter(Regex regex) {
         code = regex.code;
         codeLength = regex.codeLength;
         templates = regex.templates;
         enc = regex.enc;
-        warnings = regex.warnings;
     }
 
     public String byteCodeListToString() {
diff --git a/src/org/joni/Config.java b/src/org/joni/Config.java
index 107551c..67ee911 100644
--- a/src/org/joni/Config.java
+++ b/src/org/joni/Config.java
@@ -33,7 +33,7 @@ public interface Config extends org.jcodings.Config {
 
     final boolean USE_MONOMANIAC_CHECK_CAPTURES_IN_ENDLESS_REPEAT = true; /* /(?:()|())*\2/ */
     final boolean USE_NEWLINE_AT_END_OF_STRING_HAS_EMPTY_LINE = true;     /* /\n$/ =~ "\n" */
-    final boolean USE_WARNING_REDUNDANT_NESTED_REPEAT_OPERATOR = false;
+    final boolean USE_WARNING_REDUNDANT_NESTED_REPEAT_OPERATOR = true;
 
     final boolean CASE_FOLD_IS_APPLIED_INSIDE_NEGATIVE_CCLASS = true;
 
diff --git a/src/org/joni/Lexer.java b/src/org/joni/Lexer.java
index 1aa18cd..5e5e203 100644
--- a/src/org/joni/Lexer.java
+++ b/src/org/joni/Lexer.java
@@ -38,9 +38,9 @@ class Lexer extends ScannerSupport {
     protected final Syntax syntax;              // fast access to syntax
     protected final Token token = new Token();  // current token
 
-    protected Lexer(Regex regex, Syntax syntax, byte[]bytes, int p, int end) {
+    protected Lexer(Regex regex, Syntax syntax, byte[]bytes, int p, int end, WarnCallback warnings) {
         super(regex.enc, bytes, p, end);
-        this.env = new ScanEnvironment(regex, syntax);
+        this.env = new ScanEnvironment(regex, syntax, warnings);
         this.syntax = env.syntax;
     }
 
@@ -1315,7 +1315,7 @@ class Lexer extends ScannerSupport {
 
     protected final void syntaxWarn(String message) {
         if (Config.USE_WARN) {
-            env.reg.warnings.warn(message + ": /" + new String(bytes, getBegin(), getEnd()) + "/");
+            env.warnings.warn(message + ": /" + new String(bytes, getBegin(), getEnd()) + "/");
         }
     }
 }
diff --git a/src/org/joni/Parser.java b/src/org/joni/Parser.java
index 5107546..b668e3a 100644
--- a/src/org/joni/Parser.java
+++ b/src/org/joni/Parser.java
@@ -55,8 +55,8 @@ class Parser extends Lexer {
     protected int returnCode; // return code used by parser methods (they itself return parsed nodes)
                               // this approach will not affect recursive calls
 
-    protected Parser(Regex regex, Syntax syntax, byte[]bytes, int p, int end) {
-        super(regex, syntax, bytes, p, end);
+    protected Parser(Regex regex, Syntax syntax, byte[]bytes, int p, int end, WarnCallback warnings) {
+        super(regex, syntax, bytes, p, end, warnings);
         this.regex = regex;
     }
 
diff --git a/src/org/joni/Regex.java b/src/org/joni/Regex.java
index eb281d4..923a7b8 100644
--- a/src/org/joni/Regex.java
+++ b/src/org/joni/Regex.java
@@ -54,14 +54,12 @@ public final class Regex {
     int[]repeatRangeLo;
     int[]repeatRangeHi;
 
-    public WarnCallback warnings;
     public MatcherFactory factory;
 
     final Encoding enc;
     int options;
     int userOptions;
     Object userObject;
-    //final Syntax syntax;
     final int caseFoldFlag;
 
     BytesHash<NameEntry> nameTable;        // named entries
@@ -84,7 +82,7 @@ public final class Regex {
     int dMin;                               /* min-distance of exact or map */
     int dMax;                               /* max-distance of exact or map */
 
-    byte[][]templates;
+    byte[][]templates;                      /* fixed pattern strings not embedded in bytecode */
     int templateNum;
 
     public Regex(CharSequence cs) {
@@ -151,11 +149,7 @@ public final class Regex {
         this.enc = enc;
         this.options = option;
         this.caseFoldFlag = caseFoldFlag;
-        this.warnings = warnings;
-
-        new Analyser(this, syntax, bytes, p, end).compile();
-
-        this.warnings = null;
+        new Analyser(this, syntax, bytes, p, end, warnings).compile();
     }
 
     public Matcher matcher(byte[]bytes) {
diff --git a/src/org/joni/ScanEnvironment.java b/src/org/joni/ScanEnvironment.java
index 1818873..f2130a0 100644
--- a/src/org/joni/ScanEnvironment.java
+++ b/src/org/joni/ScanEnvironment.java
@@ -37,6 +37,7 @@ public final class ScanEnvironment {
     int backrefedMem;
 
     final public Regex reg;
+    public final WarnCallback warnings;
 
     int numCall;
     UnsetAddrList unsetAddrList; // USE_SUBEXP_CALL
@@ -56,9 +57,10 @@ public final class ScanEnvironment {
     int numPrecReadNotNodes;
     Node precReadNotNodes[];
 
-    public ScanEnvironment(Regex regex, Syntax syntax) {
+    public ScanEnvironment(Regex regex, Syntax syntax, WarnCallback warnings) {
         this.reg = regex;
         this.syntax = syntax;
+        this.warnings = warnings;
         option = reg.options;
         caseFoldFlag = reg.caseFoldFlag;
         enc = reg.enc;
@@ -134,7 +136,7 @@ public final class ScanEnvironment {
     void ccEscWarn(String s) {
         if (Config.USE_WARN) {
             if (syntax.warnCCOpNotEscaped() && syntax.backSlashEscapeInCC()) {
-                reg.warnings.warn("character class has '" + s + "' without escape");
+                warnings.warn("character class has '" + s + "' without escape");
             }
         }
     }
@@ -142,7 +144,7 @@ public final class ScanEnvironment {
     void closeBracketWithoutEscapeWarn(String s) {
         if (Config.USE_WARN) {
             if (syntax.warnCCOpNotEscaped()) {
-                reg.warnings.warn("regular expression has '" + s + "' without escape");
+                warnings.warn("regular expression has '" + s + "' without escape");
             }
         }
     }
@@ -150,7 +152,7 @@ public final class ScanEnvironment {
     void ccDuplicateWarn() {
         if (syntax.warnCCDup() && (warningsFlag & SyntaxProperties.WARN_CC_DUP) == 0) {
             warningsFlag |= SyntaxProperties.WARN_CC_DUP;
-            reg.warnings.warn("character class has duplicated range");
+            warnings.warn("character class has duplicated range");
         }
     }
 }
diff --git a/src/org/joni/WarnCallback.java b/src/org/joni/WarnCallback.java
index b5f2a27..60bf578 100644
--- a/src/org/joni/WarnCallback.java
+++ b/src/org/joni/WarnCallback.java
@@ -29,5 +29,10 @@ public interface WarnCallback {
         }
     };
 
+    WarnCallback NONE = new WarnCallback() {
+        public void warn(String message) {
+        }
+    };
+
     void warn(String message);
 }
diff --git a/src/org/joni/ast/QuantifierNode.java b/src/org/joni/ast/QuantifierNode.java
index cbbf08d..5c35e7e 100644
--- a/src/org/joni/ast/QuantifierNode.java
+++ b/src/org/joni/ast/QuantifierNode.java
@@ -250,14 +250,11 @@ public final class QuantifierNode extends StateNode {
                     case ASIS:
                         break;
                     case DEL:
-                        env.reg.warnings.warn(new String(bytes, p, end) +
-                                " redundant nested repeat operator");
+                        env.warnings.warn("regular expression has redundant nested repeat operator " + PopularQStr[targetQNum] + " /" + new String(bytes, p, end) + "/");
                         break;
                     default:
-                        env.reg.warnings.warn(new String(bytes, p, end) +
-                            " nested repeat operator " + PopularQStr[targetQNum] +
-                            " and " + PopularQStr[nestQNum] + " was replaced with '" +
-                            ReduceQStr[REDUCE_TABLE[targetQNum][nestQNum].ordinal()] + "'");
+                        env.warnings.warn("nested repeat operator '" + PopularQStr[targetQNum] + "' and '" + PopularQStr[nestQNum] +
+                                "' was replaced with '" + ReduceQStr[REDUCE_TABLE[targetQNum][nestQNum].ordinal()] + "' in regular expression " + "/" + new String(bytes, p, end) + "/");
                     }
                 }
             } // USE_WARNING_REDUNDANT_NESTED_REPEAT_OPERATOR
diff --git a/test/org/joni/test/Test.java b/test/org/joni/test/Test.java
index 5feeddc..ed961b9 100644
--- a/test/org/joni/test/Test.java
+++ b/test/org/joni/test/Test.java
@@ -35,10 +35,6 @@ import org.joni.exception.JOniException;
 
 public abstract class Test {
     static final boolean VERBOSE = false;
-    static final WarnCallback TEST_WARNINGS = new WarnCallback() {
-        public void warn(String message) {
-        }
-    };
 
     int nsucc;
     int nerror;
@@ -84,7 +80,7 @@ public abstract class Test {
         Regex reg;
 
         try {
-            reg = new Regex(pattern, 0, length(pattern), option, encoding(), syntax(), TEST_WARNINGS);
+            reg = new Regex(pattern, 0, length(pattern), option, encoding(), syntax(), WarnCallback.NONE);
         } catch (JOniException je) {
             Config.err.println(reprTest(pattern, str, option));
             je.printStackTrace(Config.err);

-- 
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