diff --git a/src/NHibernate/Dialect/BitwiseFunctionOperation.cs b/src/NHibernate/Dialect/BitwiseFunctionOperation.cs new file mode 100644 index 00000000000..43faa74fa63 --- /dev/null +++ b/src/NHibernate/Dialect/BitwiseFunctionOperation.cs @@ -0,0 +1,112 @@ +using System; +using System.Collections; +using NHibernate.Dialect.Function; +using NHibernate.Engine; +using NHibernate.SqlCommand; +using NHibernate.Type; + +namespace NHibernate.Dialect +{ + /// + /// Treats bitwise operations as SQL function calls. + /// + [Serializable] + public class BitwiseFunctionOperation : ISQLFunction + { + private readonly string _functionName; + private SqlStringBuilder _sqlBuffer; + private Queue _args; + + /// + /// Creates an instance of this class using the provided function name + /// + /// + /// The bitwise function name as defined by the SQL-Dialect + /// + public BitwiseFunctionOperation(string functionName) + { + _functionName = functionName; + } + + #region ISQLFunction Members + + public IType ReturnType(IType columnType, IMapping mapping) + { + return NHibernateUtil.Int64; + } + + public bool HasArguments + { + get { return true; } + } + + public bool HasParenthesesIfNoArguments + { + get { return true; } + } + + public SqlString Render(IList args, ISessionFactoryImplementor factory) + { + Prepare(args); + + AddFunctionName(); + OpenParens(); + AddArguments(); + CloseParens(); + + return SqlResult(); + } + + #endregion + + private void Prepare(IList args) + { + _sqlBuffer = new SqlStringBuilder(); + _args = new Queue(); + foreach (var arg in args) + { + if (!IsParens(arg.ToString())) + _args.Enqueue(arg); + } + } + + private static bool IsParens(string candidate) + { + return candidate == "(" || candidate == ")"; + } + + private void AddFunctionName() + { + _sqlBuffer.Add(_functionName); + } + + private void OpenParens() + { + _sqlBuffer.Add("("); + } + + private void AddArguments() + { + while (_args.Count > 0) + { + var arg = _args.Dequeue(); + if (arg is Parameter || arg is SqlString) + _sqlBuffer.AddObject(arg); + else + _sqlBuffer.Add(arg.ToString()); + if (_args.Count > 0) + _sqlBuffer.Add(", "); + } + } + + private void CloseParens() + { + _sqlBuffer.Add(")"); + } + + private SqlString SqlResult() + { + return _sqlBuffer.ToSqlString(); + } + } +} diff --git a/src/NHibernate/Dialect/BitwiseNativeOperation.cs b/src/NHibernate/Dialect/BitwiseNativeOperation.cs new file mode 100644 index 00000000000..e6682e28a80 --- /dev/null +++ b/src/NHibernate/Dialect/BitwiseNativeOperation.cs @@ -0,0 +1,109 @@ +using System; +using System.Collections; +using NHibernate.Dialect.Function; +using NHibernate.Engine; +using NHibernate.SqlCommand; +using NHibernate.Type; + +namespace NHibernate.Dialect +{ + /// + /// Treats bitwise operations as native operations. + /// + /// + [Serializable] + public class BitwiseNativeOperation : ISQLFunction + { + private readonly string _sqlOpToken; + private readonly bool _isNot; + private Queue _args; + private SqlStringBuilder _sqlBuffer; + + /// + /// creates an instance using the giving token + /// + /// + /// The operation token + /// + /// + /// Use this constructor only if the token DOES NOT represent a NOT-Operation + /// + public BitwiseNativeOperation(string sqlOpToken) + : this(sqlOpToken, false) + { + } + + /// + /// creates an instance using the giving token and the flag indicating a NOT-Operation + /// + /// + /// + public BitwiseNativeOperation(string sqlOpToken, bool isNot) + { + _sqlOpToken = sqlOpToken; + _isNot = isNot; + } + + #region ISQLFunction Members + + public IType ReturnType(IType columnType, IMapping mapping) + { + return NHibernateUtil.Int64; + } + + public bool HasArguments + { + get { return true; } + } + + public bool HasParenthesesIfNoArguments + { + get { return false; } + } + + public SqlString Render(IList args, ISessionFactoryImplementor factory) + { + Prepare(args); + if (_isNot == false) + AddFirstArgument(); + AddToken(); + AddRestOfArguments(); + + return _sqlBuffer.ToSqlString(); + } + + #endregion + + private void Prepare(IList args) + { + _sqlBuffer = new SqlStringBuilder(); + _args = new Queue(args); + } + + private void AddFirstArgument() + { + AddToBuffer(_args.Dequeue()); + } + + private void AddToken() + { + AddToBuffer(string.Format(" {0} ", _sqlOpToken)); + } + + private void AddRestOfArguments() + { + while (_args.Count > 0) + { + AddToBuffer(_args.Dequeue()); + } + } + + private void AddToBuffer(object arg) + { + if (arg is Parameter || arg is SqlString) + _sqlBuffer.AddObject(arg); + else + _sqlBuffer.Add(arg.ToString()); + } + } +} diff --git a/src/NHibernate/Dialect/Dialect.cs b/src/NHibernate/Dialect/Dialect.cs index daca3d9cb37..b1ac22bed63 100644 --- a/src/NHibernate/Dialect/Dialect.cs +++ b/src/NHibernate/Dialect/Dialect.cs @@ -113,6 +113,12 @@ protected Dialect() RegisterFunction("month", new SQLFunctionTemplate(NHibernateUtil.Int32, "extract(month from ?1)")); RegisterFunction("year", new SQLFunctionTemplate(NHibernateUtil.Int32, "extract(year from ?1)")); + // Bitwise operations + RegisterFunction("band", new BitwiseNativeOperation("&")); + RegisterFunction("bor", new BitwiseNativeOperation("|")); + RegisterFunction("bxor", new BitwiseNativeOperation("^")); + RegisterFunction("bnot", new BitwiseNativeOperation("~", true)); + RegisterFunction("str", new SQLFunctionTemplate(NHibernateUtil.String, "cast(?1 as char)")); // register hibernate types for default use in scalar sqlquery type auto detection diff --git a/src/NHibernate/Dialect/FirebirdDialect.cs b/src/NHibernate/Dialect/FirebirdDialect.cs index bfd286674d7..be3949adf42 100644 --- a/src/NHibernate/Dialect/FirebirdDialect.cs +++ b/src/NHibernate/Dialect/FirebirdDialect.cs @@ -322,6 +322,11 @@ private void OverrideStandardHQLFunctions() RegisterFunction("str", new SQLFunctionTemplate(NHibernateUtil.String, "cast(?1 as VARCHAR(255))")); RegisterFunction("sysdate", new CastedFunction("today", NHibernateUtil.Date)); RegisterFunction("date", new SQLFunctionTemplate(NHibernateUtil.Date, "cast(?1 as date)")); + // Bitwise operations + RegisterFunction("band", new BitwiseFunctionOperation("bin_and")); + RegisterFunction("bor", new BitwiseFunctionOperation("bin_or")); + RegisterFunction("bxor", new BitwiseFunctionOperation("bin_xor")); + RegisterFunction("bnot", new BitwiseFunctionOperation("bin_not")); } private void RegisterFirebirdServerEmbeddedFunctions() @@ -349,9 +354,6 @@ private void RegisterExternalFbAndIbStandardUDFs() private void RegisterMathematicalFunctions() { RegisterFunction("abs", new StandardSQLFunction("abs", NHibernateUtil.Double)); - RegisterFunction("bin_and", new StandardSQLFunction("bin_and", NHibernateUtil.Int32)); - RegisterFunction("bin_or", new StandardSQLFunction("bin_or", NHibernateUtil.Int32)); - RegisterFunction("bin_xor", new StandardSQLFunction("bin_xor", NHibernateUtil.Int32)); RegisterFunction("ceiling", new StandardSQLFunction("ceiling", NHibernateUtil.Double)); RegisterFunction("div", new StandardSQLFunction("div", NHibernateUtil.Double)); RegisterFunction("dpower", new StandardSQLFunction("dpower", NHibernateUtil.Double)); diff --git a/src/NHibernate/Hql/Ast/ANTLR/Generated/HqlLexer.cs b/src/NHibernate/Hql/Ast/ANTLR/Generated/HqlLexer.cs index 89b36914346..7c659839b76 100644 --- a/src/NHibernate/Hql/Ast/ANTLR/Generated/HqlLexer.cs +++ b/src/NHibernate/Hql/Ast/ANTLR/Generated/HqlLexer.cs @@ -8,7 +8,7 @@ // //------------------------------------------------------------------------------ -// $ANTLR 3.5.0.2 Hql.g 2014-08-03 19:45:41 +// $ANTLR 3.5.0.2 Hql.g 2015-02-24 17:27:14 // The variable 'variable' is assigned but its value is never used. #pragma warning disable 219 diff --git a/src/NHibernate/Hql/Ast/ANTLR/Generated/HqlParser.cs b/src/NHibernate/Hql/Ast/ANTLR/Generated/HqlParser.cs index 1a0cc689fef..644a27594ff 100644 --- a/src/NHibernate/Hql/Ast/ANTLR/Generated/HqlParser.cs +++ b/src/NHibernate/Hql/Ast/ANTLR/Generated/HqlParser.cs @@ -8,7 +8,7 @@ // //------------------------------------------------------------------------------ -// $ANTLR 3.5.0.2 Hql.g 2014-08-03 19:45:40 +// $ANTLR 3.5.0.2 Hql.g 2015-02-24 17:27:14 // The variable 'variable' is assigned but its value is never used. #pragma warning disable 219 diff --git a/src/NHibernate/Hql/Ast/ANTLR/Generated/HqlSqlWalker.cs b/src/NHibernate/Hql/Ast/ANTLR/Generated/HqlSqlWalker.cs index ac001fabccc..7c5fbeb8119 100644 --- a/src/NHibernate/Hql/Ast/ANTLR/Generated/HqlSqlWalker.cs +++ b/src/NHibernate/Hql/Ast/ANTLR/Generated/HqlSqlWalker.cs @@ -8,7 +8,7 @@ // //------------------------------------------------------------------------------ -// $ANTLR 3.5.0.2 HqlSqlWalker.g 2014-10-10 11:16:23 +// $ANTLR 3.5.0.2 HqlSqlWalker.g 2015-02-24 17:27:15 // The variable 'variable' is assigned but its value is never used. #pragma warning disable 219 @@ -2585,7 +2585,7 @@ private AstTreeRuleReturnScope orderExpr() partial void EnterRule_resultVariableRef(); partial void LeaveRule_resultVariableRef(); // $ANTLR start "resultVariableRef" - // HqlSqlWalker.g:158:1: resultVariableRef : i= identifier -> ^( RESULT_VARIABLE_REF[$i.start.ToString()] ) ; + // HqlSqlWalker.g:158:1: resultVariableRef : i= identifier -> ^( RESULT_VARIABLE_REF[$i.tree.Text] ) ; [GrammarRule("resultVariableRef")] private AstTreeRuleReturnScope resultVariableRef() { @@ -2607,7 +2607,7 @@ private AstTreeRuleReturnScope resultVariableRef() DebugLocation(158, 1); try { - // HqlSqlWalker.g:162:2: (i= identifier -> ^( RESULT_VARIABLE_REF[$i.start.ToString()] ) ) + // HqlSqlWalker.g:162:2: (i= identifier -> ^( RESULT_VARIABLE_REF[$i.tree.Text] ) ) DebugEnterAlt(1); // HqlSqlWalker.g:162:4: i= identifier { @@ -2632,14 +2632,14 @@ private AstTreeRuleReturnScope resultVariableRef() RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.Tree:null); root_0 = (IASTNode)adaptor.Nil(); - // 163:2: -> ^( RESULT_VARIABLE_REF[$i.start.ToString()] ) + // 163:2: -> ^( RESULT_VARIABLE_REF[$i.tree.Text] ) { DebugLocation(163, 5); - // HqlSqlWalker.g:163:5: ^( RESULT_VARIABLE_REF[$i.start.ToString()] ) + // HqlSqlWalker.g:163:5: ^( RESULT_VARIABLE_REF[$i.tree.Text] ) { IASTNode root_1 = (IASTNode)adaptor.Nil(); DebugLocation(163, 7); - root_1 = (IASTNode)adaptor.BecomeRoot((IASTNode)adaptor.Create(RESULT_VARIABLE_REF, (i!=null?((IASTNode)i.Start):default(IASTNode)).ToString()), root_1); + root_1 = (IASTNode)adaptor.BecomeRoot((IASTNode)adaptor.Create(RESULT_VARIABLE_REF, (i!=null?((IASTNode)i.Tree):default(IASTNode)).Text), root_1); adaptor.AddChild(root_0, root_1); } diff --git a/src/NHibernate/Hql/Ast/ANTLR/Generated/SqlGenerator.cs b/src/NHibernate/Hql/Ast/ANTLR/Generated/SqlGenerator.cs index ae177f08b33..778b0c848b2 100644 --- a/src/NHibernate/Hql/Ast/ANTLR/Generated/SqlGenerator.cs +++ b/src/NHibernate/Hql/Ast/ANTLR/Generated/SqlGenerator.cs @@ -8,7 +8,7 @@ // //------------------------------------------------------------------------------ -// $ANTLR 3.5.0.2 SqlGenerator.g 2014-10-10 10:44:17 +// $ANTLR 3.5.0.2 SqlGenerator.g 2015-02-24 17:27:16 // The variable 'variable' is assigned but its value is never used. #pragma warning disable 219 @@ -6051,22 +6051,28 @@ private void bitwiseExpr() DebugLocation(308, 6); Match(input,BAND,Follow._BAND_in_bitwiseExpr1709); if (state.failed) return; - Match(input, TokenTypes.Down, null); if (state.failed) return; DebugLocation(308, 11); - PushFollow(Follow._expr_in_bitwiseExpr1711); - expr(); - PopFollow(); - if (state.failed) return; - DebugLocation(308, 16); if (state.backtracking == 0) { - Out("&"); + BeginBitwiseOp("band"); } - DebugLocation(308, 30); + + Match(input, TokenTypes.Down, null); if (state.failed) return; + DebugLocation(308, 39); + PushFollow(Follow._expr_in_bitwiseExpr1713); + expr(); + PopFollow(); + if (state.failed) return; + DebugLocation(308, 44); PushFollow(Follow._nestedExpr_in_bitwiseExpr1715); nestedExpr(); PopFollow(); if (state.failed) return; + DebugLocation(308, 55); + if (state.backtracking == 0) + { + EndBitwiseOp("band"); + } Match(input, TokenTypes.Up, null); if (state.failed) return; @@ -6079,24 +6085,30 @@ private void bitwiseExpr() { DebugLocation(309, 4); DebugLocation(309, 6); - Match(input,BOR,Follow._BOR_in_bitwiseExpr1722); if (state.failed) return; + Match(input,BOR,Follow._BOR_in_bitwiseExpr1724); if (state.failed) return; - Match(input, TokenTypes.Down, null); if (state.failed) return; DebugLocation(309, 10); - PushFollow(Follow._expr_in_bitwiseExpr1724); - expr(); - PopFollow(); - if (state.failed) return; - DebugLocation(309, 15); if (state.backtracking == 0) { - Out("|"); + BeginBitwiseOp("bor"); } - DebugLocation(309, 29); - PushFollow(Follow._nestedExpr_in_bitwiseExpr1728); + + Match(input, TokenTypes.Down, null); if (state.failed) return; + DebugLocation(309, 37); + PushFollow(Follow._expr_in_bitwiseExpr1728); + expr(); + PopFollow(); + if (state.failed) return; + DebugLocation(309, 42); + PushFollow(Follow._nestedExpr_in_bitwiseExpr1730); nestedExpr(); PopFollow(); if (state.failed) return; + DebugLocation(309, 53); + if (state.backtracking == 0) + { + EndBitwiseOp("bor"); + } Match(input, TokenTypes.Up, null); if (state.failed) return; @@ -6109,24 +6121,30 @@ private void bitwiseExpr() { DebugLocation(310, 4); DebugLocation(310, 6); - Match(input,BXOR,Follow._BXOR_in_bitwiseExpr1735); if (state.failed) return; + Match(input,BXOR,Follow._BXOR_in_bitwiseExpr1739); if (state.failed) return; - Match(input, TokenTypes.Down, null); if (state.failed) return; DebugLocation(310, 11); - PushFollow(Follow._expr_in_bitwiseExpr1737); - expr(); - PopFollow(); - if (state.failed) return; - DebugLocation(310, 16); if (state.backtracking == 0) { - Out("^"); + BeginBitwiseOp("bxor"); } - DebugLocation(310, 30); - PushFollow(Follow._nestedExpr_in_bitwiseExpr1741); + + Match(input, TokenTypes.Down, null); if (state.failed) return; + DebugLocation(310, 39); + PushFollow(Follow._expr_in_bitwiseExpr1743); + expr(); + PopFollow(); + if (state.failed) return; + DebugLocation(310, 44); + PushFollow(Follow._nestedExpr_in_bitwiseExpr1745); nestedExpr(); PopFollow(); if (state.failed) return; + DebugLocation(310, 55); + if (state.backtracking == 0) + { + EndBitwiseOp("bxor"); + } Match(input, TokenTypes.Up, null); if (state.failed) return; @@ -6139,20 +6157,25 @@ private void bitwiseExpr() { DebugLocation(311, 4); DebugLocation(311, 6); - Match(input,BNOT,Follow._BNOT_in_bitwiseExpr1748); if (state.failed) return; + Match(input,BNOT,Follow._BNOT_in_bitwiseExpr1754); if (state.failed) return; DebugLocation(311, 11); if (state.backtracking == 0) { - Out("~"); + BeginBitwiseOp("bnot"); } Match(input, TokenTypes.Down, null); if (state.failed) return; - DebugLocation(311, 25); - PushFollow(Follow._nestedExpr_in_bitwiseExpr1752); + DebugLocation(311, 39); + PushFollow(Follow._nestedExpr_in_bitwiseExpr1758); nestedExpr(); PopFollow(); if (state.failed) return; + DebugLocation(311, 50); + if (state.backtracking == 0) + { + EndBitwiseOp("bnot"); + } Match(input, TokenTypes.Up, null); if (state.failed) return; @@ -6223,11 +6246,11 @@ private void multiplicativeExpr() { DebugLocation(315, 4); DebugLocation(315, 6); - Match(input,STAR,Follow._STAR_in_multiplicativeExpr1766); if (state.failed) return; + Match(input,STAR,Follow._STAR_in_multiplicativeExpr1773); if (state.failed) return; Match(input, TokenTypes.Down, null); if (state.failed) return; DebugLocation(315, 11); - PushFollow(Follow._nestedExpr_in_multiplicativeExpr1768); + PushFollow(Follow._nestedExpr_in_multiplicativeExpr1775); nestedExpr(); PopFollow(); if (state.failed) return; @@ -6237,7 +6260,7 @@ private void multiplicativeExpr() Out("*"); } DebugLocation(315, 36); - PushFollow(Follow._nestedExpr_in_multiplicativeExpr1772); + PushFollow(Follow._nestedExpr_in_multiplicativeExpr1779); nestedExpr(); PopFollow(); if (state.failed) return; @@ -6253,11 +6276,11 @@ private void multiplicativeExpr() { DebugLocation(316, 4); DebugLocation(316, 6); - Match(input,DIV,Follow._DIV_in_multiplicativeExpr1779); if (state.failed) return; + Match(input,DIV,Follow._DIV_in_multiplicativeExpr1786); if (state.failed) return; Match(input, TokenTypes.Down, null); if (state.failed) return; DebugLocation(316, 10); - PushFollow(Follow._nestedExpr_in_multiplicativeExpr1781); + PushFollow(Follow._nestedExpr_in_multiplicativeExpr1788); nestedExpr(); PopFollow(); if (state.failed) return; @@ -6267,7 +6290,7 @@ private void multiplicativeExpr() Out("/"); } DebugLocation(316, 35); - PushFollow(Follow._nestedExprAfterMinusDiv_in_multiplicativeExpr1785); + PushFollow(Follow._nestedExprAfterMinusDiv_in_multiplicativeExpr1792); nestedExprAfterMinusDiv(); PopFollow(); if (state.failed) return; @@ -6502,7 +6525,7 @@ private void nestedExpr() Out("("); } DebugLocation(321, 36); - PushFollow(Follow._additiveExpr_in_nestedExpr1807); + PushFollow(Follow._additiveExpr_in_nestedExpr1814); additiveExpr(); PopFollow(); if (state.failed) return; @@ -6524,7 +6547,7 @@ private void nestedExpr() Out("("); } DebugLocation(322, 35); - PushFollow(Follow._bitwiseExpr_in_nestedExpr1822); + PushFollow(Follow._bitwiseExpr_in_nestedExpr1829); bitwiseExpr(); PopFollow(); if (state.failed) return; @@ -6541,7 +6564,7 @@ private void nestedExpr() // SqlGenerator.g:323:4: expr { DebugLocation(323, 4); - PushFollow(Follow._expr_in_nestedExpr1829); + PushFollow(Follow._expr_in_nestedExpr1836); expr(); PopFollow(); if (state.failed) return; @@ -6873,7 +6896,7 @@ private void nestedExprAfterMinusDiv() Out("("); } DebugLocation(328, 38); - PushFollow(Follow._arithmeticExpr_in_nestedExprAfterMinusDiv1851); + PushFollow(Follow._arithmeticExpr_in_nestedExprAfterMinusDiv1858); arithmeticExpr(); PopFollow(); if (state.failed) return; @@ -6890,7 +6913,7 @@ private void nestedExprAfterMinusDiv() // SqlGenerator.g:329:4: expr { DebugLocation(329, 4); - PushFollow(Follow._expr_in_nestedExprAfterMinusDiv1858); + PushFollow(Follow._expr_in_nestedExprAfterMinusDiv1865); expr(); PopFollow(); if (state.failed) return; @@ -6961,7 +6984,7 @@ private void caseExpr() { DebugLocation(333, 4); DebugLocation(333, 6); - Match(input,CASE,Follow._CASE_in_caseExpr1870); if (state.failed) return; + Match(input,CASE,Follow._CASE_in_caseExpr1877); if (state.failed) return; DebugLocation(333, 11); if (state.backtracking == 0) @@ -6995,7 +7018,7 @@ private void caseExpr() { DebugLocation(334, 5); DebugLocation(334, 7); - Match(input,WHEN,Follow._WHEN_in_caseExpr1880); if (state.failed) return; + Match(input,WHEN,Follow._WHEN_in_caseExpr1887); if (state.failed) return; DebugLocation(334, 12); if (state.backtracking == 0) @@ -7005,7 +7028,7 @@ private void caseExpr() Match(input, TokenTypes.Down, null); if (state.failed) return; DebugLocation(334, 32); - PushFollow(Follow._booleanExpr_in_caseExpr1884); + PushFollow(Follow._booleanExpr_in_caseExpr1891); booleanExpr(false); PopFollow(); if (state.failed) return; @@ -7015,7 +7038,7 @@ private void caseExpr() Out(" then "); } DebugLocation(334, 70); - PushFollow(Follow._expr_in_caseExpr1889); + PushFollow(Follow._expr_in_caseExpr1896); expr(); PopFollow(); if (state.failed) return; @@ -7062,7 +7085,7 @@ private void caseExpr() { DebugLocation(335, 5); DebugLocation(335, 7); - Match(input,ELSE,Follow._ELSE_in_caseExpr1901); if (state.failed) return; + Match(input,ELSE,Follow._ELSE_in_caseExpr1908); if (state.failed) return; DebugLocation(335, 12); if (state.backtracking == 0) @@ -7072,7 +7095,7 @@ private void caseExpr() Match(input, TokenTypes.Down, null); if (state.failed) return; DebugLocation(335, 31); - PushFollow(Follow._expr_in_caseExpr1905); + PushFollow(Follow._expr_in_caseExpr1912); expr(); PopFollow(); if (state.failed) return; @@ -7103,7 +7126,7 @@ private void caseExpr() { DebugLocation(337, 4); DebugLocation(337, 6); - Match(input,CASE2,Follow._CASE2_in_caseExpr1921); if (state.failed) return; + Match(input,CASE2,Follow._CASE2_in_caseExpr1928); if (state.failed) return; DebugLocation(337, 12); if (state.backtracking == 0) @@ -7113,7 +7136,7 @@ private void caseExpr() Match(input, TokenTypes.Down, null); if (state.failed) return; DebugLocation(337, 30); - PushFollow(Follow._expr_in_caseExpr1925); + PushFollow(Follow._expr_in_caseExpr1932); expr(); PopFollow(); if (state.failed) return; @@ -7142,7 +7165,7 @@ private void caseExpr() { DebugLocation(338, 5); DebugLocation(338, 7); - Match(input,WHEN,Follow._WHEN_in_caseExpr1932); if (state.failed) return; + Match(input,WHEN,Follow._WHEN_in_caseExpr1939); if (state.failed) return; DebugLocation(338, 12); if (state.backtracking == 0) @@ -7152,7 +7175,7 @@ private void caseExpr() Match(input, TokenTypes.Down, null); if (state.failed) return; DebugLocation(338, 32); - PushFollow(Follow._expr_in_caseExpr1936); + PushFollow(Follow._expr_in_caseExpr1943); expr(); PopFollow(); if (state.failed) return; @@ -7162,7 +7185,7 @@ private void caseExpr() Out(" then "); } DebugLocation(338, 56); - PushFollow(Follow._expr_in_caseExpr1940); + PushFollow(Follow._expr_in_caseExpr1947); expr(); PopFollow(); if (state.failed) return; @@ -7209,7 +7232,7 @@ private void caseExpr() { DebugLocation(339, 5); DebugLocation(339, 7); - Match(input,ELSE,Follow._ELSE_in_caseExpr1952); if (state.failed) return; + Match(input,ELSE,Follow._ELSE_in_caseExpr1959); if (state.failed) return; DebugLocation(339, 12); if (state.backtracking == 0) @@ -7219,7 +7242,7 @@ private void caseExpr() Match(input, TokenTypes.Down, null); if (state.failed) return; DebugLocation(339, 31); - PushFollow(Follow._expr_in_caseExpr1956); + PushFollow(Follow._expr_in_caseExpr1963); expr(); PopFollow(); if (state.failed) return; @@ -7287,7 +7310,7 @@ private void aggregate() { DebugLocation(344, 4); DebugLocation(344, 7); - a=(IASTNode)Match(input,AGGREGATE,Follow._AGGREGATE_in_aggregate1980); if (state.failed) return; + a=(IASTNode)Match(input,AGGREGATE,Follow._AGGREGATE_in_aggregate1987); if (state.failed) return; DebugLocation(344, 18); if (state.backtracking == 0) @@ -7297,7 +7320,7 @@ private void aggregate() Match(input, TokenTypes.Down, null); if (state.failed) return; DebugLocation(344, 41); - PushFollow(Follow._expr_in_aggregate1985); + PushFollow(Follow._expr_in_aggregate1992); expr(); PopFollow(); if (state.failed) return; @@ -7354,11 +7377,11 @@ private void methodCall() { DebugLocation(349, 4); DebugLocation(349, 7); - m=(IASTNode)Match(input,METHOD_CALL,Follow._METHOD_CALL_in_methodCall2004); if (state.failed) return; + m=(IASTNode)Match(input,METHOD_CALL,Follow._METHOD_CALL_in_methodCall2011); if (state.failed) return; Match(input, TokenTypes.Down, null); if (state.failed) return; DebugLocation(349, 21); - i=(IASTNode)Match(input,METHOD_NAME,Follow._METHOD_NAME_in_methodCall2008); if (state.failed) return; + i=(IASTNode)Match(input,METHOD_NAME,Follow._METHOD_NAME_in_methodCall2015); if (state.failed) return; DebugLocation(349, 34); if (state.backtracking == 0) { @@ -7384,7 +7407,7 @@ private void methodCall() { DebugLocation(350, 5); DebugLocation(350, 7); - Match(input,EXPR_LIST,Follow._EXPR_LIST_in_methodCall2017); if (state.failed) return; + Match(input,EXPR_LIST,Follow._EXPR_LIST_in_methodCall2024); if (state.failed) return; if (input.LA(1) == TokenTypes.Down) { @@ -7408,7 +7431,7 @@ private void methodCall() // SqlGenerator.g:350:18: arguments { DebugLocation(350, 18); - PushFollow(Follow._arguments_in_methodCall2020); + PushFollow(Follow._arguments_in_methodCall2027); arguments(); PopFollow(); if (state.failed) return; @@ -7508,7 +7531,7 @@ private void arguments() // SqlGenerator.g:355:5: expr { DebugLocation(355, 5); - PushFollow(Follow._expr_in_arguments2045); + PushFollow(Follow._expr_in_arguments2052); expr(); PopFollow(); if (state.failed) return; @@ -7520,7 +7543,7 @@ private void arguments() // SqlGenerator.g:355:12: comparisonExpr[true] { DebugLocation(355, 12); - PushFollow(Follow._comparisonExpr_in_arguments2049); + PushFollow(Follow._comparisonExpr_in_arguments2056); comparisonExpr(true); PopFollow(); if (state.failed) return; @@ -7588,7 +7611,7 @@ private void arguments() // SqlGenerator.g:355:71: expr { DebugLocation(355, 71); - PushFollow(Follow._expr_in_arguments2058); + PushFollow(Follow._expr_in_arguments2065); expr(); PopFollow(); if (state.failed) return; @@ -7600,7 +7623,7 @@ private void arguments() // SqlGenerator.g:355:78: comparisonExpr[true] { DebugLocation(355, 78); - PushFollow(Follow._comparisonExpr_in_arguments2062); + PushFollow(Follow._comparisonExpr_in_arguments2069); comparisonExpr(true); PopFollow(); if (state.failed) return; @@ -7692,7 +7715,7 @@ private void parameter() // SqlGenerator.g:359:4: n= NAMED_PARAM { DebugLocation(359, 5); - n=(IASTNode)Match(input,NAMED_PARAM,Follow._NAMED_PARAM_in_parameter2080); if (state.failed) return; + n=(IASTNode)Match(input,NAMED_PARAM,Follow._NAMED_PARAM_in_parameter2087); if (state.failed) return; DebugLocation(359, 18); if (state.backtracking == 0) { @@ -7706,7 +7729,7 @@ private void parameter() // SqlGenerator.g:360:4: p= PARAM { DebugLocation(360, 5); - p=(IASTNode)Match(input,PARAM,Follow._PARAM_in_parameter2089); if (state.failed) return; + p=(IASTNode)Match(input,PARAM,Follow._PARAM_in_parameter2096); if (state.failed) return; DebugLocation(360, 12); if (state.backtracking == 0) { @@ -7855,7 +7878,7 @@ private void addrExpr() { DebugLocation(370, 4); DebugLocation(370, 7); - r=(IASTNode)Match(input,DOT,Follow._DOT_in_addrExpr2126); if (state.failed) return; + r=(IASTNode)Match(input,DOT,Follow._DOT_in_addrExpr2133); if (state.failed) return; Match(input, TokenTypes.Down, null); if (state.failed) return; DebugLocation(370, 12); @@ -7878,7 +7901,7 @@ private void addrExpr() // SqlGenerator.g:371:4: i= ALIAS_REF { DebugLocation(371, 5); - i=(IASTNode)Match(input,ALIAS_REF,Follow._ALIAS_REF_in_addrExpr2140); if (state.failed) return; + i=(IASTNode)Match(input,ALIAS_REF,Follow._ALIAS_REF_in_addrExpr2147); if (state.failed) return; DebugLocation(371, 16); if (state.backtracking == 0) { @@ -7893,7 +7916,7 @@ private void addrExpr() { DebugLocation(372, 4); DebugLocation(372, 7); - j=(IASTNode)Match(input,INDEX_OP,Follow._INDEX_OP_in_addrExpr2150); if (state.failed) return; + j=(IASTNode)Match(input,INDEX_OP,Follow._INDEX_OP_in_addrExpr2157); if (state.failed) return; if (input.LA(1) == TokenTypes.Down) { @@ -7957,7 +7980,7 @@ private void addrExpr() // SqlGenerator.g:373:4: v= RESULT_VARIABLE_REF { DebugLocation(373, 5); - v=(IASTNode)Match(input,RESULT_VARIABLE_REF,Follow._RESULT_VARIABLE_REF_in_addrExpr2163); if (state.failed) return; + v=(IASTNode)Match(input,RESULT_VARIABLE_REF,Follow._RESULT_VARIABLE_REF_in_addrExpr2170); if (state.failed) return; DebugLocation(373, 26); if (state.backtracking == 0) { @@ -8009,7 +8032,7 @@ private void sqlToken() { DebugLocation(377, 4); DebugLocation(377, 7); - t=(IASTNode)Match(input,SQL_TOKEN,Follow._SQL_TOKEN_in_sqlToken2179); if (state.failed) return; + t=(IASTNode)Match(input,SQL_TOKEN,Follow._SQL_TOKEN_in_sqlToken2186); if (state.failed) return; DebugLocation(377, 18); if (state.backtracking == 0) @@ -8134,7 +8157,7 @@ private void synpred2_SqlGenerator_fragment() // SqlGenerator.g:321:5: additiveExpr { DebugLocation(321, 5); - PushFollow(Follow._additiveExpr_in_synpred2_SqlGenerator1800); + PushFollow(Follow._additiveExpr_in_synpred2_SqlGenerator1807); additiveExpr(); PopFollow(); if (state.failed) return; @@ -8167,7 +8190,7 @@ private void synpred3_SqlGenerator_fragment() // SqlGenerator.g:322:5: bitwiseExpr { DebugLocation(322, 5); - PushFollow(Follow._bitwiseExpr_in_synpred3_SqlGenerator1815); + PushFollow(Follow._bitwiseExpr_in_synpred3_SqlGenerator1822); bitwiseExpr(); PopFollow(); if (state.failed) return; @@ -8200,7 +8223,7 @@ private void synpred4_SqlGenerator_fragment() // SqlGenerator.g:328:5: arithmeticExpr { DebugLocation(328, 5); - PushFollow(Follow._arithmeticExpr_in_synpred4_SqlGenerator1844); + PushFollow(Follow._arithmeticExpr_in_synpred4_SqlGenerator1851); arithmeticExpr(); PopFollow(); if (state.failed) return; @@ -8441,61 +8464,61 @@ private static class Follow public static readonly BitSet _expr_in_additiveExpr1692 = new BitSet(new ulong[]{0x8801003140ED150UL,0x561444C01F814010UL,0x428080UL}); public static readonly BitSet _nestedExprAfterMinusDiv_in_additiveExpr1696 = new BitSet(new ulong[]{0x8UL}); public static readonly BitSet _BAND_in_bitwiseExpr1709 = new BitSet(new ulong[]{0x4UL}); - public static readonly BitSet _expr_in_bitwiseExpr1711 = new BitSet(new ulong[]{0x8801003140ED150UL,0x561444C01F814010UL,0x428080UL}); + public static readonly BitSet _expr_in_bitwiseExpr1713 = new BitSet(new ulong[]{0x8801003140ED150UL,0x561444C01F814010UL,0x428080UL}); public static readonly BitSet _nestedExpr_in_bitwiseExpr1715 = new BitSet(new ulong[]{0x8UL}); - public static readonly BitSet _BOR_in_bitwiseExpr1722 = new BitSet(new ulong[]{0x4UL}); - public static readonly BitSet _expr_in_bitwiseExpr1724 = new BitSet(new ulong[]{0x8801003140ED150UL,0x561444C01F814010UL,0x428080UL}); - public static readonly BitSet _nestedExpr_in_bitwiseExpr1728 = new BitSet(new ulong[]{0x8UL}); - public static readonly BitSet _BXOR_in_bitwiseExpr1735 = new BitSet(new ulong[]{0x4UL}); - public static readonly BitSet _expr_in_bitwiseExpr1737 = new BitSet(new ulong[]{0x8801003140ED150UL,0x561444C01F814010UL,0x428080UL}); - public static readonly BitSet _nestedExpr_in_bitwiseExpr1741 = new BitSet(new ulong[]{0x8UL}); - public static readonly BitSet _BNOT_in_bitwiseExpr1748 = new BitSet(new ulong[]{0x4UL}); - public static readonly BitSet _nestedExpr_in_bitwiseExpr1752 = new BitSet(new ulong[]{0x8UL}); - public static readonly BitSet _STAR_in_multiplicativeExpr1766 = new BitSet(new ulong[]{0x4UL}); - public static readonly BitSet _nestedExpr_in_multiplicativeExpr1768 = new BitSet(new ulong[]{0x8801003140ED150UL,0x561444C01F814010UL,0x428080UL}); - public static readonly BitSet _nestedExpr_in_multiplicativeExpr1772 = new BitSet(new ulong[]{0x8UL}); - public static readonly BitSet _DIV_in_multiplicativeExpr1779 = new BitSet(new ulong[]{0x4UL}); - public static readonly BitSet _nestedExpr_in_multiplicativeExpr1781 = new BitSet(new ulong[]{0x8801003140ED150UL,0x561444C01F814010UL,0x428080UL}); - public static readonly BitSet _nestedExprAfterMinusDiv_in_multiplicativeExpr1785 = new BitSet(new ulong[]{0x8UL}); - public static readonly BitSet _additiveExpr_in_nestedExpr1807 = new BitSet(new ulong[]{0x2UL}); - public static readonly BitSet _bitwiseExpr_in_nestedExpr1822 = new BitSet(new ulong[]{0x2UL}); - public static readonly BitSet _expr_in_nestedExpr1829 = new BitSet(new ulong[]{0x2UL}); - public static readonly BitSet _arithmeticExpr_in_nestedExprAfterMinusDiv1851 = new BitSet(new ulong[]{0x2UL}); - public static readonly BitSet _expr_in_nestedExprAfterMinusDiv1858 = new BitSet(new ulong[]{0x2UL}); - public static readonly BitSet _CASE_in_caseExpr1870 = new BitSet(new ulong[]{0x4UL}); - public static readonly BitSet _WHEN_in_caseExpr1880 = new BitSet(new ulong[]{0x4UL}); - public static readonly BitSet _booleanExpr_in_caseExpr1884 = new BitSet(new ulong[]{0x8801003140ED150UL,0x561444C01F814010UL,0x428080UL}); - public static readonly BitSet _expr_in_caseExpr1889 = new BitSet(new ulong[]{0x8UL}); - public static readonly BitSet _ELSE_in_caseExpr1901 = new BitSet(new ulong[]{0x4UL}); - public static readonly BitSet _expr_in_caseExpr1905 = new BitSet(new ulong[]{0x8UL}); - public static readonly BitSet _CASE2_in_caseExpr1921 = new BitSet(new ulong[]{0x4UL}); - public static readonly BitSet _expr_in_caseExpr1925 = new BitSet(new ulong[]{0x0UL,0x0UL,0x2UL}); - public static readonly BitSet _WHEN_in_caseExpr1932 = new BitSet(new ulong[]{0x4UL}); - public static readonly BitSet _expr_in_caseExpr1936 = new BitSet(new ulong[]{0x8801003140ED150UL,0x561444C01F814010UL,0x428080UL}); - public static readonly BitSet _expr_in_caseExpr1940 = new BitSet(new ulong[]{0x8UL}); - public static readonly BitSet _ELSE_in_caseExpr1952 = new BitSet(new ulong[]{0x4UL}); - public static readonly BitSet _expr_in_caseExpr1956 = new BitSet(new ulong[]{0x8UL}); - public static readonly BitSet _AGGREGATE_in_aggregate1980 = new BitSet(new ulong[]{0x4UL}); - public static readonly BitSet _expr_in_aggregate1985 = new BitSet(new ulong[]{0x8UL}); - public static readonly BitSet _METHOD_CALL_in_methodCall2004 = new BitSet(new ulong[]{0x4UL}); - public static readonly BitSet _METHOD_NAME_in_methodCall2008 = new BitSet(new ulong[]{0x80000000008UL}); - public static readonly BitSet _EXPR_LIST_in_methodCall2017 = new BitSet(new ulong[]{0x4UL}); - public static readonly BitSet _arguments_in_methodCall2020 = new BitSet(new ulong[]{0x8UL}); - public static readonly BitSet _expr_in_arguments2045 = new BitSet(new ulong[]{0xC941243140EF152UL,0x561444C01FF34A5CUL,0x428080UL}); - public static readonly BitSet _comparisonExpr_in_arguments2049 = new BitSet(new ulong[]{0xC941243140EF152UL,0x561444C01FF34A5CUL,0x428080UL}); - public static readonly BitSet _expr_in_arguments2058 = new BitSet(new ulong[]{0xC941243140EF152UL,0x561444C01FF34A5CUL,0x428080UL}); - public static readonly BitSet _comparisonExpr_in_arguments2062 = new BitSet(new ulong[]{0xC941243140EF152UL,0x561444C01FF34A5CUL,0x428080UL}); - public static readonly BitSet _NAMED_PARAM_in_parameter2080 = new BitSet(new ulong[]{0x2UL}); - public static readonly BitSet _PARAM_in_parameter2089 = new BitSet(new ulong[]{0x2UL}); - public static readonly BitSet _DOT_in_addrExpr2126 = new BitSet(new ulong[]{0x4UL}); - public static readonly BitSet _ALIAS_REF_in_addrExpr2140 = new BitSet(new ulong[]{0x2UL}); - public static readonly BitSet _INDEX_OP_in_addrExpr2150 = new BitSet(new ulong[]{0x4UL}); - public static readonly BitSet _RESULT_VARIABLE_REF_in_addrExpr2163 = new BitSet(new ulong[]{0x2UL}); - public static readonly BitSet _SQL_TOKEN_in_sqlToken2179 = new BitSet(new ulong[]{0x4UL}); + public static readonly BitSet _BOR_in_bitwiseExpr1724 = new BitSet(new ulong[]{0x4UL}); + public static readonly BitSet _expr_in_bitwiseExpr1728 = new BitSet(new ulong[]{0x8801003140ED150UL,0x561444C01F814010UL,0x428080UL}); + public static readonly BitSet _nestedExpr_in_bitwiseExpr1730 = new BitSet(new ulong[]{0x8UL}); + public static readonly BitSet _BXOR_in_bitwiseExpr1739 = new BitSet(new ulong[]{0x4UL}); + public static readonly BitSet _expr_in_bitwiseExpr1743 = new BitSet(new ulong[]{0x8801003140ED150UL,0x561444C01F814010UL,0x428080UL}); + public static readonly BitSet _nestedExpr_in_bitwiseExpr1745 = new BitSet(new ulong[]{0x8UL}); + public static readonly BitSet _BNOT_in_bitwiseExpr1754 = new BitSet(new ulong[]{0x4UL}); + public static readonly BitSet _nestedExpr_in_bitwiseExpr1758 = new BitSet(new ulong[]{0x8UL}); + public static readonly BitSet _STAR_in_multiplicativeExpr1773 = new BitSet(new ulong[]{0x4UL}); + public static readonly BitSet _nestedExpr_in_multiplicativeExpr1775 = new BitSet(new ulong[]{0x8801003140ED150UL,0x561444C01F814010UL,0x428080UL}); + public static readonly BitSet _nestedExpr_in_multiplicativeExpr1779 = new BitSet(new ulong[]{0x8UL}); + public static readonly BitSet _DIV_in_multiplicativeExpr1786 = new BitSet(new ulong[]{0x4UL}); + public static readonly BitSet _nestedExpr_in_multiplicativeExpr1788 = new BitSet(new ulong[]{0x8801003140ED150UL,0x561444C01F814010UL,0x428080UL}); + public static readonly BitSet _nestedExprAfterMinusDiv_in_multiplicativeExpr1792 = new BitSet(new ulong[]{0x8UL}); + public static readonly BitSet _additiveExpr_in_nestedExpr1814 = new BitSet(new ulong[]{0x2UL}); + public static readonly BitSet _bitwiseExpr_in_nestedExpr1829 = new BitSet(new ulong[]{0x2UL}); + public static readonly BitSet _expr_in_nestedExpr1836 = new BitSet(new ulong[]{0x2UL}); + public static readonly BitSet _arithmeticExpr_in_nestedExprAfterMinusDiv1858 = new BitSet(new ulong[]{0x2UL}); + public static readonly BitSet _expr_in_nestedExprAfterMinusDiv1865 = new BitSet(new ulong[]{0x2UL}); + public static readonly BitSet _CASE_in_caseExpr1877 = new BitSet(new ulong[]{0x4UL}); + public static readonly BitSet _WHEN_in_caseExpr1887 = new BitSet(new ulong[]{0x4UL}); + public static readonly BitSet _booleanExpr_in_caseExpr1891 = new BitSet(new ulong[]{0x8801003140ED150UL,0x561444C01F814010UL,0x428080UL}); + public static readonly BitSet _expr_in_caseExpr1896 = new BitSet(new ulong[]{0x8UL}); + public static readonly BitSet _ELSE_in_caseExpr1908 = new BitSet(new ulong[]{0x4UL}); + public static readonly BitSet _expr_in_caseExpr1912 = new BitSet(new ulong[]{0x8UL}); + public static readonly BitSet _CASE2_in_caseExpr1928 = new BitSet(new ulong[]{0x4UL}); + public static readonly BitSet _expr_in_caseExpr1932 = new BitSet(new ulong[]{0x0UL,0x0UL,0x2UL}); + public static readonly BitSet _WHEN_in_caseExpr1939 = new BitSet(new ulong[]{0x4UL}); + public static readonly BitSet _expr_in_caseExpr1943 = new BitSet(new ulong[]{0x8801003140ED150UL,0x561444C01F814010UL,0x428080UL}); + public static readonly BitSet _expr_in_caseExpr1947 = new BitSet(new ulong[]{0x8UL}); + public static readonly BitSet _ELSE_in_caseExpr1959 = new BitSet(new ulong[]{0x4UL}); + public static readonly BitSet _expr_in_caseExpr1963 = new BitSet(new ulong[]{0x8UL}); + public static readonly BitSet _AGGREGATE_in_aggregate1987 = new BitSet(new ulong[]{0x4UL}); + public static readonly BitSet _expr_in_aggregate1992 = new BitSet(new ulong[]{0x8UL}); + public static readonly BitSet _METHOD_CALL_in_methodCall2011 = new BitSet(new ulong[]{0x4UL}); + public static readonly BitSet _METHOD_NAME_in_methodCall2015 = new BitSet(new ulong[]{0x80000000008UL}); + public static readonly BitSet _EXPR_LIST_in_methodCall2024 = new BitSet(new ulong[]{0x4UL}); + public static readonly BitSet _arguments_in_methodCall2027 = new BitSet(new ulong[]{0x8UL}); + public static readonly BitSet _expr_in_arguments2052 = new BitSet(new ulong[]{0xC941243140EF152UL,0x561444C01FF34A5CUL,0x428080UL}); + public static readonly BitSet _comparisonExpr_in_arguments2056 = new BitSet(new ulong[]{0xC941243140EF152UL,0x561444C01FF34A5CUL,0x428080UL}); + public static readonly BitSet _expr_in_arguments2065 = new BitSet(new ulong[]{0xC941243140EF152UL,0x561444C01FF34A5CUL,0x428080UL}); + public static readonly BitSet _comparisonExpr_in_arguments2069 = new BitSet(new ulong[]{0xC941243140EF152UL,0x561444C01FF34A5CUL,0x428080UL}); + public static readonly BitSet _NAMED_PARAM_in_parameter2087 = new BitSet(new ulong[]{0x2UL}); + public static readonly BitSet _PARAM_in_parameter2096 = new BitSet(new ulong[]{0x2UL}); + public static readonly BitSet _DOT_in_addrExpr2133 = new BitSet(new ulong[]{0x4UL}); + public static readonly BitSet _ALIAS_REF_in_addrExpr2147 = new BitSet(new ulong[]{0x2UL}); + public static readonly BitSet _INDEX_OP_in_addrExpr2157 = new BitSet(new ulong[]{0x4UL}); + public static readonly BitSet _RESULT_VARIABLE_REF_in_addrExpr2170 = new BitSet(new ulong[]{0x2UL}); + public static readonly BitSet _SQL_TOKEN_in_sqlToken2186 = new BitSet(new ulong[]{0x4UL}); public static readonly BitSet _SQL_TOKEN_in_synpred1_SqlGenerator370 = new BitSet(new ulong[]{0x2UL}); - public static readonly BitSet _additiveExpr_in_synpred2_SqlGenerator1800 = new BitSet(new ulong[]{0x2UL}); - public static readonly BitSet _bitwiseExpr_in_synpred3_SqlGenerator1815 = new BitSet(new ulong[]{0x2UL}); - public static readonly BitSet _arithmeticExpr_in_synpred4_SqlGenerator1844 = new BitSet(new ulong[]{0x2UL}); + public static readonly BitSet _additiveExpr_in_synpred2_SqlGenerator1807 = new BitSet(new ulong[]{0x2UL}); + public static readonly BitSet _bitwiseExpr_in_synpred3_SqlGenerator1822 = new BitSet(new ulong[]{0x2UL}); + public static readonly BitSet _arithmeticExpr_in_synpred4_SqlGenerator1851 = new BitSet(new ulong[]{0x2UL}); } #endregion Follow sets } diff --git a/src/NHibernate/Hql/Ast/ANTLR/SqlGenerator.cs b/src/NHibernate/Hql/Ast/ANTLR/SqlGenerator.cs index ff6dc69cbd7..d30f872da8b 100644 --- a/src/NHibernate/Hql/Ast/ANTLR/SqlGenerator.cs +++ b/src/NHibernate/Hql/Ast/ANTLR/SqlGenerator.cs @@ -41,7 +41,8 @@ public partial class SqlGenerator : IErrorReporter private readonly SqlStringBuilder sqlStringBuilder = new SqlStringBuilder(); private ISqlWriter writer; - public SqlGenerator(ISessionFactoryImplementor sfi, ITreeNodeStream input) : this(input) + public SqlGenerator(ISessionFactoryImplementor sfi, ITreeNodeStream input) + : this(input) { parseErrorHandler = new ErrorCounter(); sessionFactory = sfi; @@ -134,7 +135,7 @@ private void Out(IASTNode n) } else if (n is SqlNode) { - Out(((SqlNode) n).RenderText(sessionFactory)); + Out(((SqlNode)n).RenderText(sessionFactory)); } else { @@ -147,7 +148,7 @@ private void Out(IASTNode n) } else if (n is IParameterContainer) { - var parameterContainer = (IParameterContainer) n; + var parameterContainer = (IParameterContainer)n; if (parameterContainer.HasEmbeddedParameters) { IParameterSpecification[] specifications = parameterContainer.GetEmbeddedParameters(); @@ -178,8 +179,8 @@ protected virtual void FromFragmentSeparator(IASTNode a) return; } - var left = (FromElement) a; - var right = (FromElement) next; + var left = (FromElement)a; + var right = (FromElement)next; /////////////////////////////////////////////////////////////////////// // HACK ALERT !!!!!!!!!!!!!!!!!!!!!!!!!!!! @@ -192,7 +193,7 @@ protected virtual void FromFragmentSeparator(IASTNode a) // writes something to the SQL while (right != null && !HasText(right)) { - right = (FromElement) right.NextSibling; + right = (FromElement)right.NextSibling; } if (right == null) @@ -235,8 +236,8 @@ protected virtual void NestedFromFragment(IASTNode d, IASTNode parent) if (parent != null && HasText(parent)) { // again, both should be FromElements - var left = (FromElement) parent; - var right = (FromElement) d; + var left = (FromElement)parent; + var right = (FromElement)d; if (right.RealOrigin == left) { // right represents a joins originating from left... @@ -268,7 +269,7 @@ private SqlStringBuilder GetStringBuilder() private void BeginFunctionTemplate(IASTNode m, IASTNode i) { - var methodNode = (MethodNode) m; + var methodNode = (MethodNode)m; ISQLFunction template = methodNode.SQLFunction; if (template == null) { @@ -286,7 +287,7 @@ private void BeginFunctionTemplate(IASTNode m, IASTNode i) private void EndFunctionTemplate(IASTNode m) { - var methodNode = (MethodNode) m; + var methodNode = (MethodNode)m; ISQLFunction template = methodNode.SQLFunction; if (template == null) { @@ -295,7 +296,7 @@ private void EndFunctionTemplate(IASTNode m) else { // this function has a template -> restore output, apply the template and write the result out - var functionArguments = (FunctionArguments) writer; // TODO: Downcast to avoid using an interface? Yuck. + var functionArguments = (FunctionArguments)writer; // TODO: Downcast to avoid using an interface? Yuck. writer = outputStack[0]; outputStack.RemoveAt(0); Out(template.Render(functionArguments.Args, sessionFactory)); @@ -315,7 +316,7 @@ private void StartQuery() private void EndQuery() { - SqlString sqlString = GetSqlStringWithLimitsIfNeeded((QueryWriter) writer); + SqlString sqlString = GetSqlStringWithLimitsIfNeeded((QueryWriter)writer); writer = outputStack[0]; outputStack.RemoveAt(0); @@ -345,23 +346,23 @@ private SqlString GetSqlStringWithLimitsIfNeeded(QueryWriter queryWriter) // The dialect can move the given parameters where he need, what it can't do is generates new parameters, losing the BackTrack. var dialect = sessionFactory.Dialect; return dialect.GetLimitString(queryWriter.ToSqlString(), - queryWriter.Skip.HasValue - ? (int?) dialect.GetOffsetValue(queryWriter.Skip.Value) - : null, - queryWriter.Take.HasValue - ? (int?) dialect.GetLimitValue(queryWriter.Skip ?? 0, queryWriter.Take.Value) - : null, - skipParameter, - takeParameter); + queryWriter.Skip.HasValue + ? (int?)dialect.GetOffsetValue(queryWriter.Skip.Value) + : null, + queryWriter.Take.HasValue + ? (int?)dialect.GetLimitValue(queryWriter.Skip ?? 0, queryWriter.Take.Value) + : null, + skipParameter, + takeParameter); } private void Skip(IASTNode node) { - var queryWriter = (QueryWriter) writer; + var queryWriter = (QueryWriter)writer; var pnode = node as ParameterNode; if (pnode != null) { - queryWriter.SkipParameter = (IPageableParameterSpecification) pnode.HqlParameterSpecification; + queryWriter.SkipParameter = (IPageableParameterSpecification)pnode.HqlParameterSpecification; collectedParameters.Add(pnode.HqlParameterSpecification); return; } @@ -370,17 +371,40 @@ private void Skip(IASTNode node) private void Take(IASTNode node) { - var queryWriter = (QueryWriter) writer; + var queryWriter = (QueryWriter)writer; var pnode = node as ParameterNode; if (pnode != null) { - queryWriter.TakeParameter = (IPageableParameterSpecification) pnode.HqlParameterSpecification; + queryWriter.TakeParameter = (IPageableParameterSpecification)pnode.HqlParameterSpecification; collectedParameters.Add(pnode.HqlParameterSpecification); return; } queryWriter.Take = Convert.ToInt32(node.Text); } + private void BeginBitwiseOp(string op) + { + var function = sessionFactory.SQLFunctionRegistry.FindSQLFunction(op.ToLowerInvariant()); + if (function == null) + return; + + outputStack.Insert(0, writer); + writer = new BitwiseOpWriter(); + } + + private void EndBitwiseOp(string op) + { + ISQLFunction function = sessionFactory.SQLFunctionRegistry.FindSQLFunction(op.ToLowerInvariant()); + if (function == null) + return; + + var functionArguments = (BitwiseOpWriter)writer; + writer = outputStack[0]; + outputStack.RemoveAt(0); + + Out(function.Render(functionArguments.Args, sessionFactory)); + } + #region Nested type: DefaultWriter /// @@ -555,5 +579,42 @@ private interface ISqlWriter } #endregion + + #region Nested type: BitwiseOperation + + private class BitwiseOpWriter : ISqlWriter + { + private readonly List _args = new List(); + + #region ISqlWriter Members + + public void Clause(string clause) + { + Clause(SqlString.Parse(clause)); + } + + public void Clause(SqlString clause) + { + _args.Add(clause); + } + + public void PushParameter(Parameter parameter) + { + _args.Add(new SqlString(parameter)); + } + + public void CommaBetweenParameters(string comma) + { + } + + #endregion + + public IList Args + { + get { return _args; } + } + } + + #endregion } } \ No newline at end of file diff --git a/src/NHibernate/Hql/Ast/ANTLR/SqlGenerator.g b/src/NHibernate/Hql/Ast/ANTLR/SqlGenerator.g index 74b2b64c7dc..ea621f234b1 100644 --- a/src/NHibernate/Hql/Ast/ANTLR/SqlGenerator.g +++ b/src/NHibernate/Hql/Ast/ANTLR/SqlGenerator.g @@ -305,10 +305,10 @@ additiveExpr ; bitwiseExpr - : ^(BAND expr { Out("&"); } nestedExpr) - | ^(BOR expr { Out("|"); } nestedExpr) - | ^(BXOR expr { Out("^"); } nestedExpr) - | ^(BNOT { Out("~"); } nestedExpr) + : ^(BAND { BeginBitwiseOp("band"); } expr nestedExpr { EndBitwiseOp("band"); }) + | ^(BOR { BeginBitwiseOp("bor"); } expr nestedExpr { EndBitwiseOp("bor"); }) + | ^(BXOR { BeginBitwiseOp("bxor"); } expr nestedExpr { EndBitwiseOp("bxor"); }) + | ^(BNOT { BeginBitwiseOp("bnot"); } nestedExpr { EndBitwiseOp("bnot"); }) ; multiplicativeExpr diff --git a/src/NHibernate/NHibernate.csproj b/src/NHibernate/NHibernate.csproj index 9557e898e11..2ee0a05aae0 100644 --- a/src/NHibernate/NHibernate.csproj +++ b/src/NHibernate/NHibernate.csproj @@ -137,6 +137,7 @@ + @@ -156,6 +157,7 @@ +