From e5386e875a4f0a42af36e3a285a19f0693b24d6c Mon Sep 17 00:00:00 2001 From: heromyth Date: Fri, 14 May 2021 15:57:23 +0800 Subject: [PATCH] Wrong global variables declaration --- source/hunt/sql/ast/SQLSetQuantifier.d | 8 +- source/hunt/sql/ast/expr/SQLAggregateExpr.d | 2 - source/hunt/sql/ast/expr/SQLBetweenExpr.d | 1 - source/hunt/sql/ast/expr/SQLBinaryOpExpr.d | 2 - source/hunt/sql/ast/expr/SQLCaseExpr.d | 3 - source/hunt/sql/ast/expr/SQLCaseStatement.d | 1 - source/hunt/sql/ast/expr/SQLContainsExpr.d | 2 - source/hunt/sql/ast/expr/SQLExistsExpr.d | 1 - source/hunt/sql/ast/expr/SQLInListExpr.d | 2 - source/hunt/sql/ast/expr/SQLInSubQueryExpr.d | 2 - .../hunt/sql/ast/expr/SQLMethodInvokeExpr.d | 2 - source/hunt/sql/ast/expr/SQLNotExpr.d | 2 - source/hunt/sql/ast/expr/SQLQueryExpr.d | 2 - source/hunt/sql/ast/expr/SQLUnaryExpr.d | 1 - .../mysql/parser/MySqlStatementParser.d | 48 ++++---- .../postgresql/parser/PGSQLStatementParser.d | 6 +- source/hunt/sql/parser/CharTypes.d | 114 +++++++++--------- .../sql/parser/NotAllowCommentException.d | 1 - source/hunt/sql/parser/SymbolTable.d | 15 ++- source/hunt/sql/stat/TableStat.d | 36 ++++-- source/hunt/sql/util/PGUtils.d | 5 +- source/hunt/sql/visitor/SQLEvalVisitor.d | 28 +++-- source/hunt/sql/visitor/SchemaStatVisitor.d | 33 ++--- 23 files changed, 161 insertions(+), 156 deletions(-) diff --git a/source/hunt/sql/ast/SQLSetQuantifier.d b/source/hunt/sql/ast/SQLSetQuantifier.d index a096531..10ebf3d 100755 --- a/source/hunt/sql/ast/SQLSetQuantifier.d +++ b/source/hunt/sql/ast/SQLSetQuantifier.d @@ -4,11 +4,11 @@ module hunt.sql.ast.SQLSetQuantifier; public interface SQLSetQuantifier { // SQL 92 - public static int ALL = 1; - public static int DISTINCT = 2; + enum int ALL = 1; + enum int DISTINCT = 2; - public static int UNIQUE = 3; - public static int DISTINCTROW = 4; + enum int UNIQUE = 3; + enum int DISTINCTROW = 4; // !SetQuantifier } diff --git a/source/hunt/sql/ast/expr/SQLAggregateExpr.d b/source/hunt/sql/ast/expr/SQLAggregateExpr.d index 1444393..afb7a30 100755 --- a/source/hunt/sql/ast/expr/SQLAggregateExpr.d +++ b/source/hunt/sql/ast/expr/SQLAggregateExpr.d @@ -13,8 +13,6 @@ import hunt.collection; public class SQLAggregateExpr : SQLExprImpl , SQLReplaceable { - private static long serialVersionUID = 1L; - protected string methodName; protected long _methodNameHashCod64; diff --git a/source/hunt/sql/ast/expr/SQLBetweenExpr.d b/source/hunt/sql/ast/expr/SQLBetweenExpr.d index 0112340..1c49818 100755 --- a/source/hunt/sql/ast/expr/SQLBetweenExpr.d +++ b/source/hunt/sql/ast/expr/SQLBetweenExpr.d @@ -24,7 +24,6 @@ import hunt.sql.ast.expr.SQLBooleanExpr; public class SQLBetweenExpr : SQLExprImpl , SQLReplaceable //Serializable, { - private static long serialVersionUID = 1L; public SQLExpr testExpr; private bool not; public SQLExpr beginExpr; diff --git a/source/hunt/sql/ast/expr/SQLBinaryOpExpr.d b/source/hunt/sql/ast/expr/SQLBinaryOpExpr.d index 57f3426..9b50995 100755 --- a/source/hunt/sql/ast/expr/SQLBinaryOpExpr.d +++ b/source/hunt/sql/ast/expr/SQLBinaryOpExpr.d @@ -37,8 +37,6 @@ import hunt.util.StringBuilder; public class SQLBinaryOpExpr : SQLExprImpl , SQLReplaceable//, Serializable { - - private static long serialVersionUID = 1L; public SQLExpr left; public SQLExpr right; public SQLBinaryOperator operator; diff --git a/source/hunt/sql/ast/expr/SQLCaseExpr.d b/source/hunt/sql/ast/expr/SQLCaseExpr.d index b5bc6d7..39e35df 100755 --- a/source/hunt/sql/ast/expr/SQLCaseExpr.d +++ b/source/hunt/sql/ast/expr/SQLCaseExpr.d @@ -26,7 +26,6 @@ import hunt.util.StringBuilder; public class SQLCaseExpr : SQLExprImpl , SQLReplaceable//, Serializable { - private static long serialVersionUID = 1L; private List!Item items; private SQLExpr valueExpr; private SQLExpr elseExpr; @@ -107,8 +106,6 @@ public class SQLCaseExpr : SQLExprImpl , SQLReplaceable//, Serializable public static class Item : SQLObjectImpl , SQLReplaceable//, Serializable { - - private static long serialVersionUID = 1L; private SQLExpr conditionExpr; private SQLExpr valueExpr; diff --git a/source/hunt/sql/ast/expr/SQLCaseStatement.d b/source/hunt/sql/ast/expr/SQLCaseStatement.d index 323ddeb..b681a37 100755 --- a/source/hunt/sql/ast/expr/SQLCaseStatement.d +++ b/source/hunt/sql/ast/expr/SQLCaseStatement.d @@ -79,7 +79,6 @@ public class SQLCaseStatement : SQLStatementImpl //, Serializable public static class Item : SQLObjectImpl //, Serializable { - private static long serialVersionUID = 1L; private SQLExpr conditionExpr; private SQLStatement statement; diff --git a/source/hunt/sql/ast/expr/SQLContainsExpr.d b/source/hunt/sql/ast/expr/SQLContainsExpr.d index 2d47fff..4b6c740 100755 --- a/source/hunt/sql/ast/expr/SQLContainsExpr.d +++ b/source/hunt/sql/ast/expr/SQLContainsExpr.d @@ -23,8 +23,6 @@ import hunt.sql.ast.expr.SQLBooleanExpr; public class SQLContainsExpr : SQLExprImpl , SQLReplaceable//, Serializable { - - private static long serialVersionUID = 1L; private bool not = false; private SQLExpr expr; private List!SQLExpr targetList; diff --git a/source/hunt/sql/ast/expr/SQLExistsExpr.d b/source/hunt/sql/ast/expr/SQLExistsExpr.d index ec141a0..d196be7 100755 --- a/source/hunt/sql/ast/expr/SQLExistsExpr.d +++ b/source/hunt/sql/ast/expr/SQLExistsExpr.d @@ -28,7 +28,6 @@ import hunt.sql.ast.SQLObject; public class SQLExistsExpr : SQLExprImpl //, Serializable { - private static long serialVersionUID = 1L; public bool not = false; public SQLSelect subQuery; diff --git a/source/hunt/sql/ast/expr/SQLInListExpr.d b/source/hunt/sql/ast/expr/SQLInListExpr.d index c2d3b42..ac53014 100755 --- a/source/hunt/sql/ast/expr/SQLInListExpr.d +++ b/source/hunt/sql/ast/expr/SQLInListExpr.d @@ -26,8 +26,6 @@ import hunt.sql.ast.expr.SQLBooleanExpr; public class SQLInListExpr : SQLExprImpl //, Serializable { - - private static long serialVersionUID = 1L; private bool not = false; private SQLExpr expr; private List!SQLExpr targetList; diff --git a/source/hunt/sql/ast/expr/SQLInSubQueryExpr.d b/source/hunt/sql/ast/expr/SQLInSubQueryExpr.d index c83c7f5..b3c0512 100755 --- a/source/hunt/sql/ast/expr/SQLInSubQueryExpr.d +++ b/source/hunt/sql/ast/expr/SQLInSubQueryExpr.d @@ -29,8 +29,6 @@ import hunt.util.StringBuilder; public class SQLInSubQueryExpr : SQLExprImpl //, Serializable { - - private static long serialVersionUID = 1L; private bool not = false; private SQLExpr expr; diff --git a/source/hunt/sql/ast/expr/SQLMethodInvokeExpr.d b/source/hunt/sql/ast/expr/SQLMethodInvokeExpr.d index 7f40d92..98f030c 100755 --- a/source/hunt/sql/ast/expr/SQLMethodInvokeExpr.d +++ b/source/hunt/sql/ast/expr/SQLMethodInvokeExpr.d @@ -29,8 +29,6 @@ import hunt.util.StringBuilder; public class SQLMethodInvokeExpr : SQLExprImpl , SQLReplaceable//, Serializable { - - private static long serialVersionUID = 1L; private string name; private SQLExpr owner; private List!SQLExpr parameters; diff --git a/source/hunt/sql/ast/expr/SQLNotExpr.d b/source/hunt/sql/ast/expr/SQLNotExpr.d index be50ed7..d4b716b 100755 --- a/source/hunt/sql/ast/expr/SQLNotExpr.d +++ b/source/hunt/sql/ast/expr/SQLNotExpr.d @@ -10,8 +10,6 @@ import hunt.util.StringBuilder; public class SQLNotExpr : SQLExprImpl //, Serializable { - - private static long serialVersionUID = 1L; public SQLExpr expr; public this(){ diff --git a/source/hunt/sql/ast/expr/SQLQueryExpr.d b/source/hunt/sql/ast/expr/SQLQueryExpr.d index 3d9f654..e47910b 100755 --- a/source/hunt/sql/ast/expr/SQLQueryExpr.d +++ b/source/hunt/sql/ast/expr/SQLQueryExpr.d @@ -12,8 +12,6 @@ import hunt.util.StringBuilder; public class SQLQueryExpr : SQLExprImpl //, Serializable { - - private static long serialVersionUID = 1L; public SQLSelect subQuery; public this(){ diff --git a/source/hunt/sql/ast/expr/SQLUnaryExpr.d b/source/hunt/sql/ast/expr/SQLUnaryExpr.d index ae53f83..bdaa12d 100755 --- a/source/hunt/sql/ast/expr/SQLUnaryExpr.d +++ b/source/hunt/sql/ast/expr/SQLUnaryExpr.d @@ -10,7 +10,6 @@ import hunt.sql.ast.SQLObject; public class SQLUnaryExpr : SQLExprImpl // Serializable { - private static long serialVersionUID = 1L; private SQLExpr expr; private SQLUnaryOperator operator; diff --git a/source/hunt/sql/dialect/mysql/parser/MySqlStatementParser.d b/source/hunt/sql/dialect/mysql/parser/MySqlStatementParser.d index 02261a6..59607ad 100755 --- a/source/hunt/sql/dialect/mysql/parser/MySqlStatementParser.d +++ b/source/hunt/sql/dialect/mysql/parser/MySqlStatementParser.d @@ -56,30 +56,30 @@ import hunt.sql.dialect.mysql.parser.MySqlSelectIntoParser; public class MySqlStatementParser : SQLStatementParser { - private static string AUTO_INCREMENT = "AUTO_INCREMENT"; - private static string COLLATE2 = "COLLATE"; - private static string CHAIN = "CHAIN"; - private static string ENGINES = "ENGINES"; - private static string ENGINE = "ENGINE"; - private static string BINLOG = "BINLOG"; - private static string EVENTS = "EVENTS"; - private static string SESSION = "SESSION"; - private static string GLOBAL = "GLOBAL"; - private static string VARIABLES = "VARIABLES"; - private static string STATUS = "STATUS"; - private static string RESET = "RESET"; - private static string DESCRIBE = "DESCRIBE"; - private static string WRITE = "WRITE"; - private static string READ = "READ"; - private static string LOCAL = "LOCAL"; - private static string TABLES = "TABLES"; - private static string TEMPORARY = "TEMPORARY"; - private static string SPATIAL = "SPATIAL"; - private static string LOW_PRIORITY = "LOW_PRIORITY"; - private static string CONNECTION = "CONNECTION"; - private static string EXTENDED = "EXTENDED"; - private static string PARTITIONS = "PARTITIONS"; - private static string FORMAT = "FORMAT"; + private enum string AUTO_INCREMENT = "AUTO_INCREMENT"; + private enum string COLLATE2 = "COLLATE"; + private enum string CHAIN = "CHAIN"; + private enum string ENGINES = "ENGINES"; + private enum string ENGINE = "ENGINE"; + private enum string BINLOG = "BINLOG"; + private enum string EVENTS = "EVENTS"; + private enum string SESSION = "SESSION"; + private enum string GLOBAL = "GLOBAL"; + private enum string VARIABLES = "VARIABLES"; + private enum string STATUS = "STATUS"; + private enum string RESET = "RESET"; + private enum string DESCRIBE = "DESCRIBE"; + private enum string WRITE = "WRITE"; + private enum string READ = "READ"; + private enum string LOCAL = "LOCAL"; + private enum string TABLES = "TABLES"; + private enum string TEMPORARY = "TEMPORARY"; + private enum string SPATIAL = "SPATIAL"; + private enum string LOW_PRIORITY = "LOW_PRIORITY"; + private enum string CONNECTION = "CONNECTION"; + private enum string EXTENDED = "EXTENDED"; + private enum string PARTITIONS = "PARTITIONS"; + private enum string FORMAT = "FORMAT"; private int maxIntoClause = -1; diff --git a/source/hunt/sql/dialect/postgresql/parser/PGSQLStatementParser.d b/source/hunt/sql/dialect/postgresql/parser/PGSQLStatementParser.d index 2e16ada..f269706 100755 --- a/source/hunt/sql/dialect/postgresql/parser/PGSQLStatementParser.d +++ b/source/hunt/sql/dialect/postgresql/parser/PGSQLStatementParser.d @@ -43,9 +43,9 @@ import hunt.text; import std.uni; public class PGSQLStatementParser : SQLStatementParser { - public static string TIME_ZONE = "TIME ZONE"; - public static string TIME = "TIME"; - public static string LOCAL = "LOCAL"; + enum string TIME_ZONE = "TIME ZONE"; + enum string TIME = "TIME"; + enum string LOCAL = "LOCAL"; public this(PGExprParser parser) { super(parser); diff --git a/source/hunt/sql/parser/CharTypes.d b/source/hunt/sql/parser/CharTypes.d index ff8c934..63377c6 100755 --- a/source/hunt/sql/parser/CharTypes.d +++ b/source/hunt/sql/parser/CharTypes.d @@ -1,65 +1,26 @@ module hunt.sql.parser.CharTypes; //import hunt.sql.parser.LayoutCharacters.EOI; -import std.conv; import hunt.sql.parser.LayoutCharacters; -public class CharTypes { - - private static bool[] hexFlags = new bool[256]; - - - public static bool isHex(char c) { - return c < 256 && hexFlags[c]; - } - - public static bool isDigit(char c) { - return c >= '0' && c <= '9'; - } - - private static bool[] firstIdentifierFlags = new bool[256]; - - - public static bool isFirstIdentifierChar(char c) { - if (c <= firstIdentifierFlags.length) { - return firstIdentifierFlags[c]; - } - return c != ' ' && c != ','; - } - - private static string[] stringCache = new string[256]; - private static bool[] identifierFlags = new bool[256]; - - - public static bool isIdentifierChar(char c) { - if (c <= identifierFlags.length) { - return identifierFlags[c]; - } - return c != ' ' && c != ',' && c != ')'; - } +import std.conv; +import std.stdio; - public static string valueOf(char ch) { - if (ch < stringCache.length) { - return stringCache[ch]; - } - return null; - } +public class CharTypes { - private static bool[] whitespaceFlags = new bool[256]; + private __gshared bool[] hexFlags; + private __gshared bool[] firstIdentifierFlags; + private __gshared string[] stringCache; + private __gshared bool[] identifierFlags; + private __gshared bool[] whitespaceFlags; - /** - * @return false if {@link LayoutCharacters#EOI} - */ - public static bool isWhitespace(char c) { - return (c <= whitespaceFlags.length && whitespaceFlags[c]) // - || c == ' '; // Chinese space - } + shared static this() { + hexFlags = new bool[256]; + firstIdentifierFlags = new bool[256]; + stringCache = new string[256]; + identifierFlags = new bool[256]; + whitespaceFlags = new bool[256]; -} - -static this() -{ - import std.stdio; for (dchar c = 0; c < CharTypes.hexFlags.length; ++c) { if (c >= 'A' && c <= 'F') { CharTypes.hexFlags[c] = true; @@ -111,6 +72,49 @@ static this() CharTypes.whitespaceFlags[i] = true; } - CharTypes.whitespaceFlags[160] = true; // 特别处理 + CharTypes.whitespaceFlags[160] = true; + } + + + public static bool isHex(char c) { + return c < 256 && hexFlags[c]; + } + + public static bool isDigit(char c) { + return c >= '0' && c <= '9'; + } + -} \ No newline at end of file + public static bool isFirstIdentifierChar(char c) { + if (c <= firstIdentifierFlags.length) { + return firstIdentifierFlags[c]; + } + return c != ' ' && c != ','; + } + + + + public static bool isIdentifierChar(char c) { + if (c <= identifierFlags.length) { + return identifierFlags[c]; + } + return c != ' ' && c != ',' && c != ')'; + } + + public static string valueOf(char ch) { + if (ch < stringCache.length) { + return stringCache[ch]; + } + return null; + } + + + /** + * @return false if {@link LayoutCharacters#EOI} + */ + public static bool isWhitespace(char c) { + return (c <= whitespaceFlags.length && whitespaceFlags[c]) // + || c == ' '; // Chinese space + } + +} diff --git a/source/hunt/sql/parser/NotAllowCommentException.d b/source/hunt/sql/parser/NotAllowCommentException.d index 5ff5926..c1b4d81 100755 --- a/source/hunt/sql/parser/NotAllowCommentException.d +++ b/source/hunt/sql/parser/NotAllowCommentException.d @@ -18,7 +18,6 @@ import hunt.sql.parser.ParserException; public class NotAllowCommentException : ParserException { - private static long serialVersionUID = 1L; public this(){ this("comment not allow"); diff --git a/source/hunt/sql/parser/SymbolTable.d b/source/hunt/sql/parser/SymbolTable.d index 7e60fb1..4517cec 100755 --- a/source/hunt/sql/parser/SymbolTable.d +++ b/source/hunt/sql/parser/SymbolTable.d @@ -1,18 +1,23 @@ module hunt.sql.parser.SymbolTable; +import std.concurrency:initOnce; + /** */ public class SymbolTable { // private enum UTF8 = "UTF-8"; // private static bool JVM_16; - static this() - { - global = new SymbolTable(32768); + // static this() + // { + // global = new SymbolTable(32768); + // } + + static SymbolTable global() { + __gshared SymbolTable inst; + return initOnce!inst(new SymbolTable(32768)); } - public static SymbolTable global; - private Entry[] entries; private int indexMask; diff --git a/source/hunt/sql/stat/TableStat.d b/source/hunt/sql/stat/TableStat.d index 0273b78..52d9cba 100755 --- a/source/hunt/sql/stat/TableStat.d +++ b/source/hunt/sql/stat/TableStat.d @@ -730,17 +730,31 @@ public class TableStat public static class Mode { - static const Mode Insert = new Mode(1); // - static const Mode Update = new Mode(2); // - static const Mode Delete = new Mode(4); // - static const Mode Select = new Mode(8); // - static const Mode Merge = new Mode(16); // - static const Mode Truncate = new Mode(32); - static const Mode Alter = new Mode(64); // - static const Mode Drop = new Mode(128); // - static const Mode DropIndex = new Mode(256); - static const Mode CreateIndex = new Mode(512); - static const Mode Replace = new Mode(1024); + __gshared Mode Insert; + __gshared Mode Update; + __gshared Mode Delete; + __gshared Mode Select; + __gshared Mode Merge; + __gshared Mode Truncate; + __gshared Mode Alter; + __gshared Mode Drop; + __gshared Mode DropIndex; + __gshared Mode CreateIndex; + __gshared Mode Replace; + + shared static this() { + Insert = new Mode(1); // + Update = new Mode(2); // + Delete = new Mode(4); // + Select = new Mode(8); // + Merge = new Mode(16); // + Truncate = new Mode(32); + Alter = new Mode(64); // + Drop = new Mode(128); // + DropIndex = new Mode(256); + CreateIndex = new Mode(512); + Replace = new Mode(1024); + } public int mark; diff --git a/source/hunt/sql/util/PGUtils.d b/source/hunt/sql/util/PGUtils.d index 0c150a1..8941776 100755 --- a/source/hunt/sql/util/PGUtils.d +++ b/source/hunt/sql/util/PGUtils.d @@ -66,8 +66,9 @@ public class PGUtils { return words.contains(name_lower); } - private static long[] pseudoColumnHashCodes; - static this(){ + private __gshared long[] pseudoColumnHashCodes; + + shared static this(){ long[] array = [ FnvHash.Constants.CURRENT_TIMESTAMP ]; diff --git a/source/hunt/sql/visitor/SQLEvalVisitor.d b/source/hunt/sql/visitor/SQLEvalVisitor.d index 70009a9..0852a2a 100755 --- a/source/hunt/sql/visitor/SQLEvalVisitor.d +++ b/source/hunt/sql/visitor/SQLEvalVisitor.d @@ -20,13 +20,27 @@ import hunt.collection; import hunt.sql.visitor.functions.Function; import hunt.sql.visitor.SQLASTVisitor; -public interface SQLEvalVisitor : SQLASTVisitor { - - public static string EVAL_VALUE = "eval.value"; - public static string EVAL_EXPR = "eval.expr"; - public static const Object EVAL_ERROR = new Object(); - public static const Object EVAL_VALUE_COUNT = new Object(); - public static const Object EVAL_VALUE_NULL = new Object(); +import std.concurrency : initOnce; + +interface SQLEvalVisitor : SQLASTVisitor { + + enum string EVAL_VALUE = "eval.value"; + enum string EVAL_EXPR = "eval.expr"; + + static Object EVAL_ERROR() { + __gshared Object inst; + return initOnce!inst(new Object()); + } + + static Object EVAL_VALUE_COUNT() { + __gshared Object inst; + return initOnce!inst(new Object()); + } + + static Object EVAL_VALUE_NULL() { + __gshared Object inst; + return initOnce!inst(new Object()); + } Function getFunction(string funcName); diff --git a/source/hunt/sql/visitor/SchemaStatVisitor.d b/source/hunt/sql/visitor/SchemaStatVisitor.d index feab2a5..21c59a5 100755 --- a/source/hunt/sql/visitor/SchemaStatVisitor.d +++ b/source/hunt/sql/visitor/SchemaStatVisitor.d @@ -1650,27 +1650,18 @@ public class SchemaStatVisitor : SQLASTVisitorAdapter { TableStat.Mode mode = getMode(); if (mode !is null) { - switch (mode.mark) { - case TableStat.Mode.Delete.mark: - stat.incrementDeleteCount(); - break; - case TableStat.Mode.Insert.mark: - stat.incrementInsertCount(); - break; - case TableStat.Mode.Update.mark: - stat.incrementUpdateCount(); - break; - case TableStat.Mode.Select.mark: - stat.incrementSelectCount(); - break; - case TableStat.Mode.Merge.mark: - stat.incrementMergeCount(); - break; - case TableStat.Mode.Drop.mark: - stat.incrementDropCount(); - break; - default: - break; + if(mode.mark == TableStat.Mode.Delete.mark) { + stat.incrementDeleteCount(); + } else if(mode.mark == TableStat.Mode.Insert.mark) { + stat.incrementInsertCount(); + } else if(mode.mark == TableStat.Mode.Update.mark) { + stat.incrementUpdateCount(); + } else if(mode.mark == TableStat.Mode.Select.mark) { + stat.incrementSelectCount(); + } else if(mode.mark == TableStat.Mode.Merge.mark) { + stat.incrementMergeCount(); + } else if(mode.mark == TableStat.Mode.Drop.mark) { + stat.incrementDropCount(); } } } else {