SPRNET-467

This commit is contained in:
eeichinger
2009-07-27 16:03:21 +00:00
parent 5a2e7c6c26
commit 231e096fac
29 changed files with 1433 additions and 716 deletions

View File

@@ -71,7 +71,7 @@ public static void SetValue(object root, string expression, IDictionary variable
tesla.PlaceOfBirth.City = "Smiljan";
string evaluatedName = (string) ExpressionEvaluator.GetValue(tesla, "Name");
string evaluatedName = (string) ExpressionEvaluator.GetValue(tesla, "Name");
string evaluatedCity = (string) ExpressionEvaluator.GetValue(tesla, "PlaceOfBirth.City"));</programlisting>
The value of 'evaluatedName' is 'Nikola Tesla' and that of 'evaluatedCity'
@@ -148,7 +148,7 @@ int maxValue = (int) ExpressionEvaluator.GetValue(null, "0x7FFFFFFF"); // eval
DateTime birthday = (DateTime) ExpressionEvaluator.GetValue(null, "date('1974/08/24')");
DateTime exactBirthday =
DateTime exactBirthday =
(DateTime) ExpressionEvaluator.GetValue(null, " date('19740824T131030', 'yyyyMMddTHHmmss')");
bool trueValue = (bool) ExpressionEvaluator.GetValue(null, "true");
@@ -266,10 +266,10 @@ new string[] {'abc', 'xyz'}</programlisting></para>
<para>Methods are invoked using typical C# programming syntax. You may
also invoke methods on literals.</para>
<programlisting language="csharp">//string literal
<programlisting language="csharp">//string literal
char[] chars = (char[]) ExpressionEvaluator.GetValue(null, "'test'.ToCharArray(1, 2)")) // 't','e'
//date literal
//date literal
int year = (int) ExpressionEvaluator.GetValue(null, "date('1974/08/24').AddYears(31).Year") // 2005
// object usage, calculate age of tesla navigating from the IEEE society.
@@ -372,6 +372,26 @@ string expression = @"IsMember('Nikola Tesla') and !IsMember('Mihajlo Pupin')";
bool falseValue = (bool) ExpressionEvaluator.GetValue(ieee, expression);</programlisting></para>
</sect3>
<sect3 xml:id="expressions-bitwise">
<title>Bitwise operators</title>
<para>The bitwise operators that are supported are
<emphasis>and</emphasis>, <emphasis>or</emphasis>, <emphasis>xor</emphasis> and <emphasis>not</emphasis>. Their use is demonstrated below.
Note, that the logical and bitwise operators are the same and their interpretation depends if you pass in integral values or boolean values.
<programlisting language="csharp">// AND
int result = (int) ExpressionEvaluator.GetValue(null, "1 and 3"); // 1 & 3
// OR
int result = (int) ExpressionEvaluator.GetValue(null, "1 or 3"); // 1 | 3
// XOR
int result = (int) ExpressionEvaluator.GetValue(null, "1 xor 3"); // 1 ^ 3
// NOT
int result = (int) ExpressionEvaluator.GetValue(null, "!1"); // ~1
</para>
</sect3>
<sect3 xml:id="expressions-math">
<title>Mathematical operators</title>
@@ -386,7 +406,7 @@ int two = (int)ExpressionEvaluator.GetValue(null, "1 + 1"); // 2
String testString = (String)ExpressionEvaluator.GetValue(null, "'test' + ' ' + 'string'"); //'test string'
DateTime dt = (DateTime)ExpressionEvaluator.GetValue(null, "date('1974-08-24') + 5"); // 8/29/1974
// Subtraction
int four = (int) ExpressionEvaluator.GetValue(null, "1 - -3"); //4
@@ -450,7 +470,7 @@ Inventor tesla = (Inventor) ExpressionEvaluator.GetValue(ieee, "Officers['vp'] =
last expression in the list. Examples of this are shown below
<programlisting language="csharp">//Perform property assignments and then return Name property.
String pupin = (String) ExpressionEvaluator.GetValue(ieee.Members,
String pupin = (String) ExpressionEvaluator.GetValue(ieee.Members,
"( [1].PlaceOfBirth.City = 'Beograd'; [1].PlaceOfBirth.Country = 'Serbia'; [1].Name )"));
// pupin = "Mihajlo Pupin"</programlisting></para>
@@ -514,12 +534,12 @@ Inventor pupin = (Inventor) ExpressionEvaluator.GetValue(ieee, "Officers[Society
<programlisting language="csharp">// simple ctor
DateTime dt = (DateTime) ExpressionEvaluator.GetValue(null, "new DateTime(1974, 8, 24)");
// Register Inventor type then create new inventor instance within Add method inside an expression list.
// Register Inventor type then create new inventor instance within Add method inside an expression list.
// Then return the new count of the Members collection.
TypeRegistry.RegisterType(typeof(Inventor));
int three = (int) ExpressionEvaluator.GetValue(ieee.Members, "{ Add(new Inventor('Aleksandar Seovic', date('1974-08-24'), 'Serbian')); Count}"));
</programlisting></para>
<para>As a convenience, Spring.NET also allows you to define named
@@ -602,8 +622,8 @@ ExpressionEvaluator.GetValue(ieee, "Officers['president'].( #root.Officers.Remov
IDictionary vars = new Hashtable();
vars["queryName"] = "Nikola Tesla";
string expression = @"IsMember(#queryName)
? #queryName + ' is a member of the ' + Name + ' Society'
string expression = @"IsMember(#queryName)
? #queryName + ' is a member of the ' + Name + ' Society'
: #queryName + ' is not a member of the ' + Name + ' Society'";
String queryResultString = (String) ExpressionEvaluator.GetValue(ieee, expression, vars));
@@ -868,7 +888,7 @@ object[] ordered = exp.GetValue(input); // { 1, 2.0, "a", 'b' }
if ((int)item % 2 == 0)
{
total = NumberUtils.Add(total, item);
}
}
}
else
{
@@ -905,11 +925,11 @@ object[] ordered = exp.GetValue(input); // { 1, 2.0, "a", 'b' }
{
. . .
// Retrieve context defined in the spring/context section of
// Retrieve context defined in the spring/context section of
// the standard .NET configuration file.
IApplicationContext ctx = ContextRegistry.GetContext();
int numMovies = (int) ExpressionEvaluator.GetValue(null,
int numMovies = (int) ExpressionEvaluator.GetValue(null,
"@(MyMovieLister).MoviesDirectedBy('Roberto Benigni').Length");
. . .

View File

@@ -1,7 +1,7 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
* Copyright <20> 2002-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,15 +18,11 @@
#endregion
#region Imports
using System;
using System.Collections;
using Spring.Objects.Factory;
using Spring.Util;
#endregion
namespace Spring.Aop.Framework.AutoProxy
{
/// <summary>
@@ -46,6 +42,7 @@ namespace Spring.Aop.Framework.AutoProxy
/// <seealso cref="Spring.Aop.Framework.AutoProxy.ObjectNameAutoProxyCreator.IsMatch"/>
/// <author>Juergen Hoeller</author>
/// <author>Adhari C Mahendra (.NET)</author>
/// <author>Erich Eichinger</author>
public class ObjectNameAutoProxyCreator : AbstractFilteringAutoProxyCreator
{
private IList objectNames;

View File

@@ -176,7 +176,7 @@ namespace Spring.Expressions
/// <summary>
/// This is the entrypoint into evaluating this expression.
/// </summary>
private object GetValue(object context, IDictionary variables)
public object GetValue(object context, IDictionary variables)
{
EvaluationContext evalContext = new EvaluationContext( context,variables );
return Get( context, evalContext );
@@ -223,7 +223,7 @@ namespace Spring.Expressions
/// <summary>
/// This is the entrypoint into evaluating this expression.
/// </summary>
private void SetValue(object context,IDictionary variables,object newValue)
public void SetValue(object context,IDictionary variables,object newValue)
{
EvaluationContext evalContext = new EvaluationContext( context,variables );
Set( context, evalContext,newValue );

View File

@@ -1,7 +1,7 @@
#region License
/*
* Copyright <20> 2002-2006 the original author or authors.
* Copyright <20> 2002-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,7 +24,7 @@ using System.Runtime.Serialization;
namespace Spring.Expressions
{
/// <summary>
/// Base class for unary operators.
/// Base class for binary operators.
/// </summary>
/// <author>Aleksandar Seovic</author>
[Serializable]
@@ -33,9 +33,20 @@ namespace Spring.Expressions
/// <summary>
/// Create a new instance
/// </summary>
public BinaryOperator()
protected BinaryOperator()
{}
/// <summary>
/// Create a new instance with the supplied operands
/// </summary>
/// <param name="left"></param>
/// <param name="right"></param>
protected BinaryOperator(BaseNode left, BaseNode right)
{
base.addChild(left);
base.addChild(right);
}
/// <summary>
/// Create a new instance from SerializationInfo
/// </summary>

View File

@@ -39,6 +39,14 @@ namespace Spring.Expressions
{
}
/// <summary>
/// Create a new instance
/// </summary>
public BooleanLiteralNode(string text)
{
this.Text = text;
}
/// <summary>
/// Create a new instance from SerializationInfo
/// </summary>

View File

@@ -49,6 +49,14 @@ namespace Spring.Expressions
{
}
/// <summary>
/// Create a new instance
/// </summary>
public ConstructorNode(Type type)
:base(type.FullName)
{
}
/// <summary>
/// Create a new instance from SerializationInfo
/// </summary>

View File

@@ -22,6 +22,7 @@ tokens {
TRUE = "true";
AND = "and";
OR = "or";
XOR = "xor";
IN = "in";
IS = "is";
BETWEEN = "between";
@@ -84,7 +85,9 @@ expression : logicalOrExpression
parenExpr
: LPAREN! expression RPAREN!;
logicalOrExpression : logicalAndExpression (OR^ <AST = Spring.Expressions.OpOR> logicalAndExpression)* ;
logicalOrExpression : logicalXorExpression (OR^ <AST = Spring.Expressions.OpOR> logicalXorExpression)* ;
logicalXorExpression : logicalAndExpression (XOR^ <AST = Spring.Expressions.OpXOR> logicalAndExpression)* ;
logicalAndExpression : relationalExpression (AND^ <AST = Spring.Expressions.OpAND> relationalExpression)* ;

View File

@@ -39,6 +39,14 @@ namespace Spring.Expressions
{
}
/// <summary>
/// Create a new instance
/// </summary>
public IntLiteralNode(string text)
{
this.Text = text;
}
/// <summary>
/// Create a new instance from SerializationInfo
/// </summary>

View File

@@ -42,6 +42,23 @@ namespace Spring.Expressions
{
}
/// <summary>
/// Create a new instance
/// </summary>
public NodeWithArguments(string text)
{
this.Text = text;
}
/// <summary>
/// Append an argument node to the list of child nodes
/// </summary>
/// <param name="argumentNode"></param>
public void AddArgument(BaseNode argumentNode)
{
base.addChild(argumentNode);
}
/// <summary>
/// Create a new instance from SerializationInfo
/// </summary>

View File

@@ -19,12 +19,13 @@
#endregion
using System;
using System.Runtime.Serialization;
using System.Runtime.Serialization;
using Spring.Util;
namespace Spring.Expressions
{
/// <summary>
/// Represents logical AND operator.
/// <summary>
/// Represents AND operator (both, bitwise and logical).
/// </summary>
/// <author>Aleksandar Seovic</author>
[Serializable]
@@ -37,6 +38,14 @@ namespace Spring.Expressions
{
}
/// <summary>
/// Create a new instance
/// </summary>
public OpAND(BaseNode left, BaseNode right)
:base(left, right)
{
}
/// <summary>
/// Create a new instance from SerializationInfo
/// </summary>
@@ -53,8 +62,14 @@ namespace Spring.Expressions
/// <returns>Node's value.</returns>
protected override object Get(object context, EvaluationContext evalContext)
{
return Convert.ToBoolean(Left.GetValueInternal(context, evalContext))
&& Convert.ToBoolean(Right.GetValueInternal(context, evalContext));
object l = Left.GetValueInternal(context, evalContext);
object r = Right.GetValueInternal(context, evalContext);
if (NumberUtils.IsInteger(l) && NumberUtils.IsInteger(r))
{
return NumberUtils.BitwiseAnd(l, r);
}
return Convert.ToBoolean(l) && Convert.ToBoolean(r);
}
}
}

View File

@@ -19,12 +19,13 @@
#endregion
using System;
using System.Runtime.Serialization;
using System.Runtime.Serialization;
using Spring.Util;
namespace Spring.Expressions
{
/// <summary>
/// Represents logical NOT operator.
/// <summary>
/// Represents NOT operator (both, bitwise and logical).
/// </summary>
/// <author>Aleksandar Seovic</author>
[Serializable]
@@ -37,6 +38,14 @@ namespace Spring.Expressions
{
}
/// <summary>
/// Create a new instance
/// </summary>
public OpNOT(BaseNode operand)
:base(operand)
{
}
/// <summary>
/// Create a new instance from SerializationInfo
/// </summary>
@@ -52,8 +61,13 @@ namespace Spring.Expressions
/// <param name="evalContext">Current expression evaluation context.</param>
/// <returns>Node's value.</returns>
protected override object Get(object context, EvaluationContext evalContext)
{
return !Convert.ToBoolean(Operand.GetValueInternal(context, evalContext));
{
object operand = Operand.GetValueInternal(context, evalContext);
if (NumberUtils.IsInteger(operand))
{
return NumberUtils.BitwiseNot(operand);
}
return !Convert.ToBoolean(operand);
}
}
}

View File

@@ -19,12 +19,13 @@
#endregion
using System;
using System.Runtime.Serialization;
using System.Runtime.Serialization;
using Spring.Util;
namespace Spring.Expressions
{
/// <summary>
/// Represents logical OR operator.
/// Represents OR operator (both, bitwise and logical).
/// </summary>
/// <author>Aleksandar Seovic</author>
[Serializable]
@@ -37,6 +38,14 @@ namespace Spring.Expressions
{
}
/// <summary>
/// Create a new instance
/// </summary>
public OpOR(BaseNode left, BaseNode right)
:base(left, right)
{
}
/// <summary>
/// Create a new instance from SerializationInfo
/// </summary>
@@ -52,9 +61,15 @@ namespace Spring.Expressions
/// <param name="evalContext">Current expression evaluation context.</param>
/// <returns>Node's value.</returns>
protected override object Get(object context, EvaluationContext evalContext)
{
return Convert.ToBoolean( Left.GetValueInternal( context, evalContext ) )
|| Convert.ToBoolean( Right.GetValueInternal( context, evalContext ) );
{
object l = Left.GetValueInternal(context, evalContext);
object r = Right.GetValueInternal(context, evalContext);
if (NumberUtils.IsInteger(l) && NumberUtils.IsInteger(r))
{
return NumberUtils.BitwiseOr(l, r);
}
return Convert.ToBoolean(l) || Convert.ToBoolean(r);
}
}
}

View File

@@ -0,0 +1,73 @@
#region License
/*
* Copyright 2002-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
using System;
using System.Runtime.Serialization;
using Spring.Util;
namespace Spring.Expressions
{
/// <summary>
/// </summary>
/// <author>Erich Eichinger</author>
[Serializable]
public class OpXOR : BinaryOperator
{
/// <summary>
/// Create a new instance
/// </summary>
public OpXOR()
{ }
/// <summary>
/// Create a new instance
/// </summary>
public OpXOR(BaseNode left, BaseNode right)
:base(left, right)
{
}
/// <summary>
/// Create a new instance from SerializationInfo
/// </summary>
protected OpXOR(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
/// <summary>
/// Returns a value for the logical AND operator node.
/// </summary>
/// <param name="context">Context to evaluate expressions against.</param>
/// <param name="evalContext">Current expression evaluation context.</param>
/// <returns>Node's value.</returns>
protected override object Get(object context, EvaluationContext evalContext)
{
object l = Left.GetValueInternal(context, evalContext);
object r = Right.GetValueInternal(context, evalContext);
if (NumberUtils.IsInteger(l) && NumberUtils.IsInteger(r))
{
return NumberUtils.BitwiseXor(l, r);
}
return Convert.ToBoolean(l) ^ Convert.ToBoolean(r);
}
}
}

View File

@@ -40,68 +40,69 @@ namespace Spring.Expressions
public const int TRUE = 7;
public const int AND = 8;
public const int OR = 9;
public const int IN = 10;
public const int IS = 11;
public const int BETWEEN = 12;
public const int LIKE = 13;
public const int MATCHES = 14;
public const int NULL_LITERAL = 15;
public const int LPAREN = 16;
public const int SEMI = 17;
public const int RPAREN = 18;
public const int ASSIGN = 19;
public const int DEFAULT = 20;
public const int QMARK = 21;
public const int COLON = 22;
public const int PLUS = 23;
public const int MINUS = 24;
public const int STAR = 25;
public const int DIV = 26;
public const int MOD = 27;
public const int POWER = 28;
public const int BANG = 29;
public const int DOT = 30;
public const int POUND = 31;
public const int ID = 32;
public const int DOLLAR = 33;
public const int COMMA = 34;
public const int AT = 35;
public const int LBRACKET = 36;
public const int RBRACKET = 37;
public const int PROJECT = 38;
public const int RCURLY = 39;
public const int SELECT = 40;
public const int SELECT_FIRST = 41;
public const int SELECT_LAST = 42;
public const int TYPE = 43;
public const int QUOTE = 44;
public const int STRING_LITERAL = 45;
public const int LAMBDA = 46;
public const int PIPE = 47;
public const int LITERAL_new = 48;
public const int LCURLY = 49;
public const int INTEGER_LITERAL = 50;
public const int HEXADECIMAL_INTEGER_LITERAL = 51;
public const int REAL_LITERAL = 52;
public const int LITERAL_date = 53;
public const int EQUAL = 54;
public const int NOT_EQUAL = 55;
public const int LESS_THAN = 56;
public const int LESS_THAN_OR_EQUAL = 57;
public const int GREATER_THAN = 58;
public const int GREATER_THAN_OR_EQUAL = 59;
public const int WS = 60;
public const int BACKTICK = 61;
public const int BACKSLASH = 62;
public const int DOT_ESCAPED = 63;
public const int APOS = 64;
public const int NUMERIC_LITERAL = 65;
public const int DECIMAL_DIGIT = 66;
public const int INTEGER_TYPE_SUFFIX = 67;
public const int HEX_DIGIT = 68;
public const int EXPONENT_PART = 69;
public const int SIGN = 70;
public const int REAL_TYPE_SUFFIX = 71;
public const int XOR = 10;
public const int IN = 11;
public const int IS = 12;
public const int BETWEEN = 13;
public const int LIKE = 14;
public const int MATCHES = 15;
public const int NULL_LITERAL = 16;
public const int LPAREN = 17;
public const int SEMI = 18;
public const int RPAREN = 19;
public const int ASSIGN = 20;
public const int DEFAULT = 21;
public const int QMARK = 22;
public const int COLON = 23;
public const int PLUS = 24;
public const int MINUS = 25;
public const int STAR = 26;
public const int DIV = 27;
public const int MOD = 28;
public const int POWER = 29;
public const int BANG = 30;
public const int DOT = 31;
public const int POUND = 32;
public const int ID = 33;
public const int DOLLAR = 34;
public const int COMMA = 35;
public const int AT = 36;
public const int LBRACKET = 37;
public const int RBRACKET = 38;
public const int PROJECT = 39;
public const int RCURLY = 40;
public const int SELECT = 41;
public const int SELECT_FIRST = 42;
public const int SELECT_LAST = 43;
public const int TYPE = 44;
public const int QUOTE = 45;
public const int STRING_LITERAL = 46;
public const int LAMBDA = 47;
public const int PIPE = 48;
public const int LITERAL_new = 49;
public const int LCURLY = 50;
public const int INTEGER_LITERAL = 51;
public const int HEXADECIMAL_INTEGER_LITERAL = 52;
public const int REAL_LITERAL = 53;
public const int LITERAL_date = 54;
public const int EQUAL = 55;
public const int NOT_EQUAL = 56;
public const int LESS_THAN = 57;
public const int LESS_THAN_OR_EQUAL = 58;
public const int GREATER_THAN = 59;
public const int GREATER_THAN_OR_EQUAL = 60;
public const int WS = 61;
public const int BACKTICK = 62;
public const int BACKSLASH = 63;
public const int DOT_ESCAPED = 64;
public const int APOS = 65;
public const int NUMERIC_LITERAL = 66;
public const int DECIMAL_DIGIT = 67;
public const int INTEGER_TYPE_SUFFIX = 68;
public const int HEX_DIGIT = 69;
public const int EXPONENT_PART = 70;
public const int SIGN = 71;
public const int REAL_TYPE_SUFFIX = 72;
// CLOVER:OFF
@@ -128,15 +129,16 @@ namespace Spring.Expressions
literals = new Hashtable(100, (float) 0.4, null, Comparer.Default);
literals.Add("true", 7);
literals.Add("and", 8);
literals.Add("matches", 14);
literals.Add("in", 10);
literals.Add("null", 15);
literals.Add("between", 12);
literals.Add("matches", 15);
literals.Add("in", 11);
literals.Add("xor", 10);
literals.Add("null", 16);
literals.Add("between", 13);
literals.Add("or", 9);
literals.Add("is", 11);
literals.Add("like", 13);
literals.Add("new", 48);
literals.Add("date", 53);
literals.Add("is", 12);
literals.Add("like", 14);
literals.Add("new", 49);
literals.Add("date", 54);
literals.Add("false", 6);
}
@@ -1008,11 +1010,11 @@ tryAgain:
}
else
{
goto _loop160_breakloop;
goto _loop163_breakloop;
}
}
_loop160_breakloop: ;
_loop163_breakloop: ;
} // ( ... )*
_saveIndex = text.Length;
mQUOTE(false);
@@ -1125,11 +1127,11 @@ _loop160_breakloop: ;
}
default:
{
goto _loop165_breakloop;
goto _loop168_breakloop;
}
}
}
_loop165_breakloop: ;
_loop168_breakloop: ;
} // ( ... )*
_ttype = testLiteralsTable(_ttype);
if (_createToken && (null == _token) && (_ttype != Token.SKIP))
@@ -1145,11 +1147,11 @@ _loop165_breakloop: ;
int _ttype; IToken _token=null; int _begin=text.Length;
_ttype = NUMERIC_LITERAL;
bool synPredMatched168 = false;
bool synPredMatched171 = false;
if (((cached_LA1=='.') && ((cached_LA2 >= '0' && cached_LA2 <= '9'))))
{
int _m168 = mark();
synPredMatched168 = true;
int _m171 = mark();
synPredMatched171 = true;
inputState.guessing++;
try {
{
@@ -1159,16 +1161,16 @@ _loop165_breakloop: ;
}
catch (RecognitionException)
{
synPredMatched168 = false;
synPredMatched171 = false;
}
rewind(_m168);
rewind(_m171);
inputState.guessing--;
}
if ( synPredMatched168 )
if ( synPredMatched171 )
{
match('.');
{ // ( ... )+
int _cnt170=0;
int _cnt173=0;
for (;;)
{
if (((cached_LA1 >= '0' && cached_LA1 <= '9')))
@@ -1177,12 +1179,12 @@ _loop165_breakloop: ;
}
else
{
if (_cnt170 >= 1) { goto _loop170_breakloop; } else { throw new NoViableAltForCharException(cached_LA1, getFilename(), getLine(), getColumn());; }
if (_cnt173 >= 1) { goto _loop173_breakloop; } else { throw new NoViableAltForCharException(cached_LA1, getFilename(), getLine(), getColumn());; }
}
_cnt170++;
_cnt173++;
}
_loop170_breakloop: ;
_loop173_breakloop: ;
} // ( ... )+
{
if ((cached_LA1=='E'||cached_LA1=='e'))
@@ -1208,16 +1210,16 @@ _loop170_breakloop: ;
}
}
else {
bool synPredMatched176 = false;
bool synPredMatched179 = false;
if ((((cached_LA1 >= '0' && cached_LA1 <= '9')) && (tokenSet_1_.member(cached_LA2))))
{
int _m176 = mark();
synPredMatched176 = true;
int _m179 = mark();
synPredMatched179 = true;
inputState.guessing++;
try {
{
{ // ( ... )+
int _cnt175=0;
int _cnt178=0;
for (;;)
{
if (((cached_LA1 >= '0' && cached_LA1 <= '9')))
@@ -1226,12 +1228,12 @@ _loop170_breakloop: ;
}
else
{
if (_cnt175 >= 1) { goto _loop175_breakloop; } else { throw new NoViableAltForCharException(cached_LA1, getFilename(), getLine(), getColumn());; }
if (_cnt178 >= 1) { goto _loop178_breakloop; } else { throw new NoViableAltForCharException(cached_LA1, getFilename(), getLine(), getColumn());; }
}
_cnt175++;
_cnt178++;
}
_loop175_breakloop: ;
_loop178_breakloop: ;
} // ( ... )+
match('.');
mDECIMAL_DIGIT(false);
@@ -1239,15 +1241,15 @@ _loop175_breakloop: ;
}
catch (RecognitionException)
{
synPredMatched176 = false;
synPredMatched179 = false;
}
rewind(_m176);
rewind(_m179);
inputState.guessing--;
}
if ( synPredMatched176 )
if ( synPredMatched179 )
{
{ // ( ... )+
int _cnt178=0;
int _cnt181=0;
for (;;)
{
if (((cached_LA1 >= '0' && cached_LA1 <= '9')))
@@ -1256,16 +1258,16 @@ _loop175_breakloop: ;
}
else
{
if (_cnt178 >= 1) { goto _loop178_breakloop; } else { throw new NoViableAltForCharException(cached_LA1, getFilename(), getLine(), getColumn());; }
if (_cnt181 >= 1) { goto _loop181_breakloop; } else { throw new NoViableAltForCharException(cached_LA1, getFilename(), getLine(), getColumn());; }
}
_cnt178++;
_cnt181++;
}
_loop178_breakloop: ;
_loop181_breakloop: ;
} // ( ... )+
match('.');
{ // ( ... )+
int _cnt180=0;
int _cnt183=0;
for (;;)
{
if (((cached_LA1 >= '0' && cached_LA1 <= '9')))
@@ -1274,12 +1276,12 @@ _loop178_breakloop: ;
}
else
{
if (_cnt180 >= 1) { goto _loop180_breakloop; } else { throw new NoViableAltForCharException(cached_LA1, getFilename(), getLine(), getColumn());; }
if (_cnt183 >= 1) { goto _loop183_breakloop; } else { throw new NoViableAltForCharException(cached_LA1, getFilename(), getLine(), getColumn());; }
}
_cnt180++;
_cnt183++;
}
_loop180_breakloop: ;
_loop183_breakloop: ;
} // ( ... )+
{
if ((cached_LA1=='E'||cached_LA1=='e'))
@@ -1305,16 +1307,16 @@ _loop180_breakloop: ;
}
}
else {
bool synPredMatched187 = false;
bool synPredMatched190 = false;
if ((((cached_LA1 >= '0' && cached_LA1 <= '9')) && (tokenSet_4_.member(cached_LA2))))
{
int _m187 = mark();
synPredMatched187 = true;
int _m190 = mark();
synPredMatched190 = true;
inputState.guessing++;
try {
{
{ // ( ... )+
int _cnt185=0;
int _cnt188=0;
for (;;)
{
if (((cached_LA1 >= '0' && cached_LA1 <= '9')))
@@ -1323,12 +1325,12 @@ _loop180_breakloop: ;
}
else
{
if (_cnt185 >= 1) { goto _loop185_breakloop; } else { throw new NoViableAltForCharException(cached_LA1, getFilename(), getLine(), getColumn());; }
if (_cnt188 >= 1) { goto _loop188_breakloop; } else { throw new NoViableAltForCharException(cached_LA1, getFilename(), getLine(), getColumn());; }
}
_cnt185++;
_cnt188++;
}
_loop185_breakloop: ;
_loop188_breakloop: ;
} // ( ... )+
{
mEXPONENT_PART(false);
@@ -1337,15 +1339,15 @@ _loop185_breakloop: ;
}
catch (RecognitionException)
{
synPredMatched187 = false;
synPredMatched190 = false;
}
rewind(_m187);
rewind(_m190);
inputState.guessing--;
}
if ( synPredMatched187 )
if ( synPredMatched190 )
{
{ // ( ... )+
int _cnt189=0;
int _cnt192=0;
for (;;)
{
if (((cached_LA1 >= '0' && cached_LA1 <= '9')))
@@ -1354,12 +1356,12 @@ _loop185_breakloop: ;
}
else
{
if (_cnt189 >= 1) { goto _loop189_breakloop; } else { throw new NoViableAltForCharException(cached_LA1, getFilename(), getLine(), getColumn());; }
if (_cnt192 >= 1) { goto _loop192_breakloop; } else { throw new NoViableAltForCharException(cached_LA1, getFilename(), getLine(), getColumn());; }
}
_cnt189++;
_cnt192++;
}
_loop189_breakloop: ;
_loop192_breakloop: ;
} // ( ... )+
{
mEXPONENT_PART(false);
@@ -1379,16 +1381,16 @@ _loop189_breakloop: ;
}
}
else {
bool synPredMatched196 = false;
bool synPredMatched199 = false;
if ((((cached_LA1 >= '0' && cached_LA1 <= '9')) && (tokenSet_5_.member(cached_LA2))))
{
int _m196 = mark();
synPredMatched196 = true;
int _m199 = mark();
synPredMatched199 = true;
inputState.guessing++;
try {
{
{ // ( ... )+
int _cnt194=0;
int _cnt197=0;
for (;;)
{
if (((cached_LA1 >= '0' && cached_LA1 <= '9')))
@@ -1397,12 +1399,12 @@ _loop189_breakloop: ;
}
else
{
if (_cnt194 >= 1) { goto _loop194_breakloop; } else { throw new NoViableAltForCharException(cached_LA1, getFilename(), getLine(), getColumn());; }
if (_cnt197 >= 1) { goto _loop197_breakloop; } else { throw new NoViableAltForCharException(cached_LA1, getFilename(), getLine(), getColumn());; }
}
_cnt194++;
_cnt197++;
}
_loop194_breakloop: ;
_loop197_breakloop: ;
} // ( ... )+
{
mREAL_TYPE_SUFFIX(false);
@@ -1411,39 +1413,13 @@ _loop194_breakloop: ;
}
catch (RecognitionException)
{
synPredMatched196 = false;
synPredMatched199 = false;
}
rewind(_m196);
rewind(_m199);
inputState.guessing--;
}
if ( synPredMatched196 )
if ( synPredMatched199 )
{
{ // ( ... )+
int _cnt198=0;
for (;;)
{
if (((cached_LA1 >= '0' && cached_LA1 <= '9')))
{
mDECIMAL_DIGIT(false);
}
else
{
if (_cnt198 >= 1) { goto _loop198_breakloop; } else { throw new NoViableAltForCharException(cached_LA1, getFilename(), getLine(), getColumn());; }
}
_cnt198++;
}
_loop198_breakloop: ;
} // ( ... )+
{
mREAL_TYPE_SUFFIX(false);
}
if (0==inputState.guessing)
{
_ttype = REAL_LITERAL;
}
}
else if (((cached_LA1 >= '0' && cached_LA1 <= '9')) && (true)) {
{ // ( ... )+
int _cnt201=0;
for (;;)
@@ -1460,6 +1436,32 @@ _loop198_breakloop: ;
_cnt201++;
}
_loop201_breakloop: ;
} // ( ... )+
{
mREAL_TYPE_SUFFIX(false);
}
if (0==inputState.guessing)
{
_ttype = REAL_LITERAL;
}
}
else if (((cached_LA1 >= '0' && cached_LA1 <= '9')) && (true)) {
{ // ( ... )+
int _cnt204=0;
for (;;)
{
if (((cached_LA1 >= '0' && cached_LA1 <= '9')))
{
mDECIMAL_DIGIT(false);
}
else
{
if (_cnt204 >= 1) { goto _loop204_breakloop; } else { throw new NoViableAltForCharException(cached_LA1, getFilename(), getLine(), getColumn());; }
}
_cnt204++;
}
_loop204_breakloop: ;
} // ( ... )+
{
if ((tokenSet_6_.member(cached_LA1)))
@@ -1528,14 +1530,14 @@ _loop201_breakloop: ;
}
else
{
goto _loop213_breakloop;
goto _loop216_breakloop;
}
}
_loop213_breakloop: ;
_loop216_breakloop: ;
} // ( ... )*
{ // ( ... )+
int _cnt215=0;
int _cnt218=0;
for (;;)
{
if (((cached_LA1 >= '0' && cached_LA1 <= '9')))
@@ -1544,12 +1546,12 @@ _loop213_breakloop: ;
}
else
{
if (_cnt215 >= 1) { goto _loop215_breakloop; } else { throw new NoViableAltForCharException(cached_LA1, getFilename(), getLine(), getColumn());; }
if (_cnt218 >= 1) { goto _loop218_breakloop; } else { throw new NoViableAltForCharException(cached_LA1, getFilename(), getLine(), getColumn());; }
}
_cnt215++;
_cnt218++;
}
_loop215_breakloop: ;
_loop218_breakloop: ;
} // ( ... )+
break;
}
@@ -1565,14 +1567,14 @@ _loop215_breakloop: ;
}
else
{
goto _loop217_breakloop;
goto _loop220_breakloop;
}
}
_loop217_breakloop: ;
_loop220_breakloop: ;
} // ( ... )*
{ // ( ... )+
int _cnt219=0;
int _cnt222=0;
for (;;)
{
if (((cached_LA1 >= '0' && cached_LA1 <= '9')))
@@ -1581,12 +1583,12 @@ _loop217_breakloop: ;
}
else
{
if (_cnt219 >= 1) { goto _loop219_breakloop; } else { throw new NoViableAltForCharException(cached_LA1, getFilename(), getLine(), getColumn());; }
if (_cnt222 >= 1) { goto _loop222_breakloop; } else { throw new NoViableAltForCharException(cached_LA1, getFilename(), getLine(), getColumn());; }
}
_cnt219++;
_cnt222++;
}
_loop219_breakloop: ;
_loop222_breakloop: ;
} // ( ... )+
break;
}
@@ -1717,7 +1719,7 @@ _loop219_breakloop: ;
match("0x");
{ // ( ... )+
int _cnt205=0;
int _cnt208=0;
for (;;)
{
if ((tokenSet_7_.member(cached_LA1)))
@@ -1726,12 +1728,12 @@ _loop219_breakloop: ;
}
else
{
if (_cnt205 >= 1) { goto _loop205_breakloop; } else { throw new NoViableAltForCharException(cached_LA1, getFilename(), getLine(), getColumn());; }
if (_cnt208 >= 1) { goto _loop208_breakloop; } else { throw new NoViableAltForCharException(cached_LA1, getFilename(), getLine(), getColumn());; }
}
_cnt205++;
_cnt208++;
}
_loop205_breakloop: ;
_loop208_breakloop: ;
} // ( ... )+
{
if ((tokenSet_6_.member(cached_LA1)))

File diff suppressed because it is too large Load Diff

View File

@@ -12,68 +12,69 @@ namespace Spring.Expressions
public const int TRUE = 7;
public const int AND = 8;
public const int OR = 9;
public const int IN = 10;
public const int IS = 11;
public const int BETWEEN = 12;
public const int LIKE = 13;
public const int MATCHES = 14;
public const int NULL_LITERAL = 15;
public const int LPAREN = 16;
public const int SEMI = 17;
public const int RPAREN = 18;
public const int ASSIGN = 19;
public const int DEFAULT = 20;
public const int QMARK = 21;
public const int COLON = 22;
public const int PLUS = 23;
public const int MINUS = 24;
public const int STAR = 25;
public const int DIV = 26;
public const int MOD = 27;
public const int POWER = 28;
public const int BANG = 29;
public const int DOT = 30;
public const int POUND = 31;
public const int ID = 32;
public const int DOLLAR = 33;
public const int COMMA = 34;
public const int AT = 35;
public const int LBRACKET = 36;
public const int RBRACKET = 37;
public const int PROJECT = 38;
public const int RCURLY = 39;
public const int SELECT = 40;
public const int SELECT_FIRST = 41;
public const int SELECT_LAST = 42;
public const int TYPE = 43;
public const int QUOTE = 44;
public const int STRING_LITERAL = 45;
public const int LAMBDA = 46;
public const int PIPE = 47;
public const int LITERAL_new = 48;
public const int LCURLY = 49;
public const int INTEGER_LITERAL = 50;
public const int HEXADECIMAL_INTEGER_LITERAL = 51;
public const int REAL_LITERAL = 52;
public const int LITERAL_date = 53;
public const int EQUAL = 54;
public const int NOT_EQUAL = 55;
public const int LESS_THAN = 56;
public const int LESS_THAN_OR_EQUAL = 57;
public const int GREATER_THAN = 58;
public const int GREATER_THAN_OR_EQUAL = 59;
public const int WS = 60;
public const int BACKTICK = 61;
public const int BACKSLASH = 62;
public const int DOT_ESCAPED = 63;
public const int APOS = 64;
public const int NUMERIC_LITERAL = 65;
public const int DECIMAL_DIGIT = 66;
public const int INTEGER_TYPE_SUFFIX = 67;
public const int HEX_DIGIT = 68;
public const int EXPONENT_PART = 69;
public const int SIGN = 70;
public const int REAL_TYPE_SUFFIX = 71;
public const int XOR = 10;
public const int IN = 11;
public const int IS = 12;
public const int BETWEEN = 13;
public const int LIKE = 14;
public const int MATCHES = 15;
public const int NULL_LITERAL = 16;
public const int LPAREN = 17;
public const int SEMI = 18;
public const int RPAREN = 19;
public const int ASSIGN = 20;
public const int DEFAULT = 21;
public const int QMARK = 22;
public const int COLON = 23;
public const int PLUS = 24;
public const int MINUS = 25;
public const int STAR = 26;
public const int DIV = 27;
public const int MOD = 28;
public const int POWER = 29;
public const int BANG = 30;
public const int DOT = 31;
public const int POUND = 32;
public const int ID = 33;
public const int DOLLAR = 34;
public const int COMMA = 35;
public const int AT = 36;
public const int LBRACKET = 37;
public const int RBRACKET = 38;
public const int PROJECT = 39;
public const int RCURLY = 40;
public const int SELECT = 41;
public const int SELECT_FIRST = 42;
public const int SELECT_LAST = 43;
public const int TYPE = 44;
public const int QUOTE = 45;
public const int STRING_LITERAL = 46;
public const int LAMBDA = 47;
public const int PIPE = 48;
public const int LITERAL_new = 49;
public const int LCURLY = 50;
public const int INTEGER_LITERAL = 51;
public const int HEXADECIMAL_INTEGER_LITERAL = 52;
public const int REAL_LITERAL = 53;
public const int LITERAL_date = 54;
public const int EQUAL = 55;
public const int NOT_EQUAL = 56;
public const int LESS_THAN = 57;
public const int LESS_THAN_OR_EQUAL = 58;
public const int GREATER_THAN = 59;
public const int GREATER_THAN_OR_EQUAL = 60;
public const int WS = 61;
public const int BACKTICK = 62;
public const int BACKSLASH = 63;
public const int DOT_ESCAPED = 64;
public const int APOS = 65;
public const int NUMERIC_LITERAL = 66;
public const int DECIMAL_DIGIT = 67;
public const int INTEGER_TYPE_SUFFIX = 68;
public const int HEX_DIGIT = 69;
public const int EXPONENT_PART = 70;
public const int SIGN = 71;
public const int REAL_TYPE_SUFFIX = 72;
}
}

View File

@@ -6,65 +6,66 @@ FALSE="false"=6
TRUE="true"=7
AND="and"=8
OR="or"=9
IN="in"=10
IS="is"=11
BETWEEN="between"=12
LIKE="like"=13
MATCHES="matches"=14
NULL_LITERAL="null"=15
LPAREN=16
SEMI=17
RPAREN=18
ASSIGN=19
DEFAULT=20
QMARK=21
COLON=22
PLUS=23
MINUS=24
STAR=25
DIV=26
MOD=27
POWER=28
BANG=29
DOT=30
POUND=31
ID=32
DOLLAR=33
COMMA=34
AT=35
LBRACKET=36
RBRACKET=37
PROJECT=38
RCURLY=39
SELECT=40
SELECT_FIRST=41
SELECT_LAST=42
TYPE=43
QUOTE=44
STRING_LITERAL=45
LAMBDA=46
PIPE=47
LITERAL_new="new"=48
LCURLY=49
INTEGER_LITERAL=50
HEXADECIMAL_INTEGER_LITERAL=51
REAL_LITERAL=52
LITERAL_date="date"=53
EQUAL=54
NOT_EQUAL=55
LESS_THAN=56
LESS_THAN_OR_EQUAL=57
GREATER_THAN=58
GREATER_THAN_OR_EQUAL=59
WS=60
BACKTICK=61
BACKSLASH=62
DOT_ESCAPED=63
APOS=64
NUMERIC_LITERAL=65
DECIMAL_DIGIT=66
INTEGER_TYPE_SUFFIX=67
HEX_DIGIT=68
EXPONENT_PART=69
SIGN=70
REAL_TYPE_SUFFIX=71
XOR="xor"=10
IN="in"=11
IS="is"=12
BETWEEN="between"=13
LIKE="like"=14
MATCHES="matches"=15
NULL_LITERAL="null"=16
LPAREN=17
SEMI=18
RPAREN=19
ASSIGN=20
DEFAULT=21
QMARK=22
COLON=23
PLUS=24
MINUS=25
STAR=26
DIV=27
MOD=28
POWER=29
BANG=30
DOT=31
POUND=32
ID=33
DOLLAR=34
COMMA=35
AT=36
LBRACKET=37
RBRACKET=38
PROJECT=39
RCURLY=40
SELECT=41
SELECT_FIRST=42
SELECT_LAST=43
TYPE=44
QUOTE=45
STRING_LITERAL=46
LAMBDA=47
PIPE=48
LITERAL_new="new"=49
LCURLY=50
INTEGER_LITERAL=51
HEXADECIMAL_INTEGER_LITERAL=52
REAL_LITERAL=53
LITERAL_date="date"=54
EQUAL=55
NOT_EQUAL=56
LESS_THAN=57
LESS_THAN_OR_EQUAL=58
GREATER_THAN=59
GREATER_THAN_OR_EQUAL=60
WS=61
BACKTICK=62
BACKSLASH=63
DOT_ESCAPED=64
APOS=65
NUMERIC_LITERAL=66
DECIMAL_DIGIT=67
INTEGER_TYPE_SUFFIX=68
HEX_DIGIT=69
EXPONENT_PART=70
SIGN=71
REAL_TYPE_SUFFIX=72

View File

@@ -37,6 +37,14 @@ namespace Spring.Expressions
{
}
/// <summary>
/// Create a new instance
/// </summary>
public StringLiteralNode(string text):base()
{
this.Text = text;
}
/// <summary>
/// Create a new instance from SerializationInfo
/// </summary>

View File

@@ -36,6 +36,14 @@ namespace Spring.Expressions
{
}
/// <summary>
/// Create a new instance
/// </summary>
public UnaryOperator(BaseNode operand)
{
this.addChild(operand);
}
/// <summary>
/// Create a new instance from SerializationInfo
/// </summary>

View File

@@ -1,7 +1,7 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<ProjectType>Local</ProjectType>
<ProductVersion>9.0.21022</ProductVersion>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{710961A3-0DF4-49E4-A26E-F5B9C044AC84}</ProjectGuid>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -362,6 +362,7 @@
<Compile Include="DataBinding\IDataBound.cs" />
<Compile Include="Expressions\DefaultNode.cs" />
<Compile Include="Expressions\ExpressionConverter.cs" />
<Compile Include="Expressions\OpXOR.cs" />
<Compile Include="Expressions\SyntaxErrorException.cs" />
<Compile Include="Expressions\Parser\ExpressionLexer.cs" />
<Compile Include="Expressions\Parser\ExpressionParser.cs" />

View File

@@ -175,6 +175,112 @@ namespace Spring.Util
}
}
/// <summary>
/// Returns the bitwise not (~) of the supplied <paramref name="number"/>.
/// </summary>
/// <param name="number">The number.</param>
/// <returns>The value of ~<paramref name="number"/>.</returns>
/// <exception cref="System.ArgumentException">
/// If the supplied <paramref name="number"/> is not a supported numeric type.
/// </exception>
public static object BitwiseNot(object number)
{
if (number is bool) return !((bool) number);
else if (number is Int32) return ~((Int32) number);
else if (number is Int16) return ~((Int16) number);
else if (number is Int64) return ~((Int64) number);
else if (number is UInt16) return ~((UInt16) number);
else if (number is UInt32) return ~((UInt32) number);
else if (number is UInt64) return ~((UInt64)number);
else if (number is Byte) return ~((Byte) number);
else if (number is SByte) return ~((SByte) number);
else
{
throw new ArgumentException(string.Format("'{0}' is not one of the supported integer types.", number));
}
}
/// <summary>
/// Bitwise ANDs (&amp;) the specified integral values.
/// </summary>
/// <param name="m">The first number.</param>
/// <param name="n">The second number.</param>
/// <exception cref="System.ArgumentException">
/// If one of the supplied arguments is not a supported integral types.
/// </exception>
public static object BitwiseAnd(object m, object n)
{
CoerceTypes(ref m, ref n);
if (n is bool) return (bool)m & (bool)n;
else if (n is Int32) return (Int32)m & (Int32)n;
else if (n is Int16) return (Int16)m & (Int16)n;
else if (n is Int64) return (Int64)m & (Int64)n;
else if (n is UInt16) return (UInt16)m & (UInt16)n;
else if (n is UInt32) return (UInt32)m & (UInt32)n;
else if (n is UInt64) return (UInt64)m & (UInt64)n;
else if (n is Byte) return (Byte)m & (Byte)n;
else if (n is SByte) return (SByte)m & (SByte)n;
else
{
throw new ArgumentException(string.Format("'{0}' and/or '{1}' are not one of the supported integral types.", m, n));
}
}
/// <summary>
/// Bitwise ORs (|) the specified integral values.
/// </summary>
/// <param name="m">The first number.</param>
/// <param name="n">The second number.</param>
/// <exception cref="System.ArgumentException">
/// If one of the supplied arguments is not a supported integral types.
/// </exception>
public static object BitwiseOr(object m, object n)
{
CoerceTypes(ref m, ref n);
if (n is bool) return (bool)m | (bool)n;
else if (n is Int32) return (Int32)m | (Int32)n;
else if (n is Int16) return (Int16)m | (Int16)n;
else if (n is Int64) return (Int64)m | (Int64)n;
else if (n is UInt16) return (UInt16)m | (UInt16)n;
else if (n is UInt32) return (UInt32)m | (UInt32)n;
else if (n is UInt64) return (UInt64)m | (UInt64)n;
else if (n is Byte) return (Byte)m | (Byte)n;
else if (n is SByte) return (SByte)m | (SByte)n;
else
{
throw new ArgumentException(string.Format("'{0}' and/or '{1}' are not one of the supported integral types.", m, n));
}
}
/// <summary>
/// Bitwise XORs (^) the specified integral values.
/// </summary>
/// <param name="m">The first number.</param>
/// <param name="n">The second number.</param>
/// <exception cref="System.ArgumentException">
/// If one of the supplied arguments is not a supported integral types.
/// </exception>
public static object BitwiseXor(object m, object n)
{
CoerceTypes(ref m, ref n);
if (n is bool) return (bool)m ^ (bool)n;
else if (n is Int32) return (Int32)m ^ (Int32)n;
else if (n is Int16) return (Int16)m ^ (Int16)n;
else if (n is Int64) return (Int64)m ^ (Int64)n;
else if (n is UInt16) return (UInt16)m ^ (UInt16)n;
else if (n is UInt32) return (UInt32)m ^ (UInt32)n;
else if (n is UInt64) return (UInt64)m ^ (UInt64)n;
else if (n is Byte) return (Byte)m ^ (Byte)n;
else if (n is SByte) return (SByte)m ^ (SByte)n;
else
{
throw new ArgumentException(string.Format("'{0}' and/or '{1}' are not one of the supported integral types.", m, n));
}
}
/// <summary>
/// Adds the specified numbers.
/// </summary>
@@ -194,9 +300,11 @@ namespace Spring.Util
else if (n is SByte) return (SByte) m + (SByte) n;
else if (n is Single) return (Single) m + (Single) n;
else if (n is Double) return (Double) m + (Double) n;
else if (n is Decimal) return (Decimal) m + (Decimal) n;
return null;
else if (n is Decimal) return (Decimal) m + (Decimal) n;
else
{
throw new ArgumentException(string.Format("'{0}' and/or '{1}' are not one of the supported numeric types.", m, n));
}
}
/// <summary>
@@ -218,9 +326,11 @@ namespace Spring.Util
else if (n is SByte) return (SByte) m - (SByte) n;
else if (n is Single) return (Single) m - (Single) n;
else if (n is Double) return (Double) m - (Double) n;
else if (n is Decimal) return (Decimal) m - (Decimal) n;
return null;
else if (n is Decimal) return (Decimal) m - (Decimal) n;
else
{
throw new ArgumentException(string.Format("'{0}' and/or '{1}' are not one of the supported numeric types.", m, n));
}
}
/// <summary>
@@ -242,10 +352,12 @@ namespace Spring.Util
else if (n is SByte) return (SByte) m*(SByte) n;
else if (n is Single) return (Single) m*(Single) n;
else if (n is Double) return (Double) m*(Double) n;
else if (n is Decimal) return (Decimal) m*(Decimal) n;
return null;
}
else if (n is Decimal) return (Decimal) m*(Decimal) n;
else
{
throw new ArgumentException(string.Format("'{0}' and/or '{1}' are not one of the supported numeric types.", m, n));
}
}
/// <summary>
/// Divides the specified numbers.
@@ -266,10 +378,12 @@ namespace Spring.Util
else if (n is SByte) return (SByte) m/(SByte) n;
else if (n is Single) return (Single) m/(Single) n;
else if (n is Double) return (Double) m/(Double) n;
else if (n is Decimal) return (Decimal) m/(Decimal) n;
return null;
}
else if (n is Decimal) return (Decimal) m/(Decimal) n;
else
{
throw new ArgumentException(string.Format("'{0}' and/or '{1}' are not one of the supported numeric types.", m, n));
}
}
/// <summary>
/// Calculates remainder for the specified numbers.
@@ -290,10 +404,12 @@ namespace Spring.Util
else if (n is SByte) return (SByte) m%(SByte) n;
else if (n is Single) return (Single) m%(Single) n;
else if (n is Double) return (Double) m%(Double) n;
else if (n is Decimal) return (Decimal) m%(Decimal) n;
return null;
}
else if (n is Decimal) return (Decimal) m%(Decimal) n;
else
{
throw new ArgumentException(string.Format("'{0}' and/or '{1}' are not one of the supported numeric types.", m, n));
}
}
/// <summary>
/// Raises first number to the power of the second one.

View File

@@ -64,11 +64,9 @@ namespace Spring.Expressions
[Test]
public void CanCreatePublicInstance()
{
ConstructorNode ctorNode = new ConstructorNode();
ctorNode.Text=typeof(PublicTestClass).FullName;
StringLiteralNode sNode = new StringLiteralNode();
sNode.Text = "theValue";
ctorNode.addChild(sNode);
ConstructorNode ctorNode = new ConstructorNode(typeof(PublicTestClass));
StringLiteralNode sNode = new StringLiteralNode("theValue");
ctorNode.AddArgument(sNode);
PublicTestClass instance = (PublicTestClass) ((IExpression)ctorNode).GetValue();
Assert.AreEqual( sNode.Text, instance._s );

View File

@@ -272,11 +272,18 @@ namespace Spring.Expressions
#endregion Serialization Tests
[Test]
public void TestBitwiseXOR()
{
object value = ExpressionEvaluator.GetValue(null, "'123' + 1");
Assert.AreEqual("1231", value);
}
[Test]
public void TestMixedAddition()
{
object value = ExpressionEvaluator.GetValue(null, "'123' + 1");
Console.WriteLine(value);
Assert.AreEqual("1231", value);
}
[Test(Description="SPRNET-944")]
@@ -942,6 +949,16 @@ namespace Spring.Expressions
Assert.IsTrue((bool)ExpressionEvaluator.GetValue(ieee, expression));
}
/// <summary>
/// Tests bitwise OR operator
/// </summary>
[Test]
public void TestBitwiseOrOperator()
{
Assert.AreEqual( 1 | 2, ExpressionEvaluator.GetValue(null, "1 or 2"));
Assert.AreEqual( 1 | -2, ExpressionEvaluator.GetValue(null, "1 or -2"));
}
/// <summary>
/// Tests logical AND operator
/// </summary>
@@ -956,6 +973,16 @@ namespace Spring.Expressions
Assert.IsTrue((bool)ExpressionEvaluator.GetValue(ieee, expression));
}
/// <summary>
/// Tests bitwise OR operator
/// </summary>
[Test]
public void TestBitwiseAndOperator()
{
Assert.AreEqual(1 & 3, ExpressionEvaluator.GetValue(null, "1 and 3"));
Assert.AreEqual(1 & -1, ExpressionEvaluator.GetValue(null, "1 and -1"));
}
/// <summary>
/// Tests logical NOT operator
/// </summary>
@@ -968,6 +995,18 @@ namespace Spring.Expressions
Assert.IsFalse((bool)ExpressionEvaluator.GetValue(ieee, expression));
}
/// <summary>
/// Tests bitwise OR operator
/// </summary>
[Test]
public void TestXorOperator()
{
Assert.AreEqual(1 ^ 3, ExpressionEvaluator.GetValue(null, "1 xor 3"));
Assert.AreEqual(1 ^ -1, ExpressionEvaluator.GetValue(null, "1 xor -1"));
Assert.AreEqual(true ^ false, ExpressionEvaluator.GetValue(null, "true xor false"));
Assert.AreEqual(true ^ true, ExpressionEvaluator.GetValue(null, "true xor true"));
}
/// <summary>
/// Tests logical operator presedance
/// </summary>

View File

@@ -0,0 +1,51 @@
#region License
/*
* Copyright 2002-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
using System;
using NUnit.Framework;
namespace Spring.Expressions
{
/// <summary>
/// </summary>
/// <author>Erich Eichinger</author>
[TestFixture]
public class OpADDTests
{
[Test]
public void CanAddStrings()
{
OpADD add = new OpADD();
add.addChild( new StringLiteralNode("20"));
add.addChild( new StringLiteralNode("30"));
object result = add.GetValue(null, null);
Assert.AreEqual("2030", result);
}
[Test]
public void CanAddNumbers()
{
OpADD add = new OpADD();
add.addChild( new IntLiteralNode("20"));
add.addChild( new IntLiteralNode("30"));
object result = add.GetValue(null, null);
Assert.AreEqual(50, result);
}
}
}

View File

@@ -0,0 +1,38 @@
#region License
/*
* Copyright 2002-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
using NUnit.Framework;
namespace Spring.Expressions
{
/// <summary>
/// </summary>
/// <author>Erich Eichinger</author>
[TestFixture]
public class OpANDTests
{
[Test]
public void AndsNumbers()
{
OpAND band = new OpAND(new IntLiteralNode("2"), new IntLiteralNode("3"));
Assert.AreEqual( 2 & 3, band.GetValue(null,null) );
}
}
}

View File

@@ -0,0 +1,46 @@
#region License
/*
* Copyright 2002-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
using System;
using NUnit.Framework;
namespace Spring.Expressions
{
/// <summary>
/// </summary>
/// <author>Erich Eichinger</author>
[TestFixture]
public class OpORTests
{
[Test]
public void OrsNumbers()
{
OpOR bor = new OpOR(new IntLiteralNode("2"), new IntLiteralNode("3"));
Assert.AreEqual(2 | 3, bor.GetValue(null, null));
}
[Test]
public void OrsBooleans()
{
OpOR bor = new OpOR(new BooleanLiteralNode("false"), new BooleanLiteralNode("true"));
Assert.AreEqual(false || true , bor.GetValue(null, null));
}
}
}

View File

@@ -0,0 +1,40 @@
#region License
/*
* Copyright 2002-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
using NUnit.Framework;
namespace Spring.Expressions
{
/// <summary>
/// </summary>
/// <author>Erich Eichinger</author>
[TestFixture]
public class OpXORTests
{
[Test]
public void XorsNumbers()
{
OpXOR bxor = new OpXOR(new IntLiteralNode("2"), new IntLiteralNode("3"));
Assert.AreEqual(2 ^ 3, bxor.GetValue(null, null));
bxor = new OpXOR(new BooleanLiteralNode("true"), new BooleanLiteralNode("false"));
Assert.AreEqual(true ^ false, bxor.GetValue(null, null));
}
}
}

View File

@@ -1,7 +1,7 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<ProjectType>Local</ProjectType>
<ProductVersion>9.0.21022</ProductVersion>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{44B16BAA-6DF8-447C-9D7F-3AD3D854D904}</ProjectGuid>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -285,6 +285,10 @@
</Compile>
<Compile Include="Expressions\FunctionNodeTests.cs" />
<Compile Include="Expressions\MethodNodeTests.cs" />
<Compile Include="Expressions\OpADDTests.cs" />
<Compile Include="Expressions\OpANDTests.cs" />
<Compile Include="Expressions\OpORTests.cs" />
<Compile Include="Expressions\OpXORTests.cs" />
<Compile Include="Expressions\Processors\ConversionProcessorTests.cs" />
<Compile Include="Expressions\Processors\OrderByProcessorTests.cs" />
<Compile Include="Expressions\PropertyOrFieldNodeTests.cs" />

View File

@@ -98,5 +98,119 @@ namespace Spring.Util
{
Assert.AreEqual(-10, NumberUtils.Negate(10));
}
[Test]
public void CoercesTypes()
{
object x = (int)1;
object y = (double)2;
NumberUtils.CoerceTypes(ref x, ref y);
Assert.AreEqual(typeof(double), x.GetType());
}
[Test]
public void Add()
{
Assert.AreEqual(5, NumberUtils.Add(2, 3));
try
{
NumberUtils.Add(2, "3");
Assert.Fail();
}
catch(ArgumentException)
{}
}
[Test]
public void BitwiseNot()
{
Assert.AreEqual( ~((Byte)2), NumberUtils.BitwiseNot((Byte)2) );
Assert.AreEqual(~((SByte)2), NumberUtils.BitwiseNot((SByte)2));
Assert.AreEqual(~((Int16)2), NumberUtils.BitwiseNot((Int16)2));
Assert.AreEqual(~((UInt16)2), NumberUtils.BitwiseNot((UInt16)2));
Assert.AreEqual(~((Int32)2), NumberUtils.BitwiseNot((Int32)2));
Assert.AreEqual(~((UInt32)2), NumberUtils.BitwiseNot((UInt32)2));
Assert.AreEqual(~((Int64)2), NumberUtils.BitwiseNot((Int64)2));
Assert.AreEqual(~((UInt64)2), NumberUtils.BitwiseNot((UInt64)2));
Assert.AreEqual( false, NumberUtils.BitwiseNot(true) );
try
{
NumberUtils.BitwiseNot((double)2.0);
Assert.Fail();
}
catch(ArgumentException)
{}
}
[Test]
public void BitwiseAnd()
{
Assert.AreEqual( ((Byte)2)&((Byte)3), NumberUtils.BitwiseAnd((Byte)2, (Byte)3));
Assert.AreEqual(((SByte)2) & ((SByte)3), NumberUtils.BitwiseAnd((SByte)2, (SByte)3));
Assert.AreEqual(((Int16)2) & ((Int16)3), NumberUtils.BitwiseAnd((Int16)2, (Int16)3));
Assert.AreEqual(((UInt16)2) & ((UInt16)3), NumberUtils.BitwiseAnd((UInt16)2, (UInt16)3));
Assert.AreEqual(((Int32)2) & ((Int32)3), NumberUtils.BitwiseAnd((Int32)2, (Int32)3));
Assert.AreEqual(((UInt32)2) & ((UInt32)3), NumberUtils.BitwiseAnd((UInt32)2, (UInt32)3));
Assert.AreEqual(((Int64)2) & ((Int64)3), NumberUtils.BitwiseAnd((Int64)2, (Int64)3));
Assert.AreEqual(((UInt64)2) & ((UInt64)3), NumberUtils.BitwiseAnd((UInt64)2, (UInt64)3));
Assert.AreEqual(((UInt64)2) & ((Byte)3), NumberUtils.BitwiseAnd((UInt64)2, (Byte)3));
Assert.AreEqual(true, NumberUtils.BitwiseAnd(true, true));
Assert.AreEqual( false, NumberUtils.BitwiseAnd(false, true) );
try
{
NumberUtils.BitwiseAnd((double)2.0, 3);
Assert.Fail();
}
catch(ArgumentException)
{}
}
[Test]
public void BitwiseOr()
{
Assert.AreEqual( ((Byte)2) | ((Byte)3), NumberUtils.BitwiseOr((Byte)2, (Byte)3));
Assert.AreEqual(((SByte)2) | ((SByte)3), NumberUtils.BitwiseOr((SByte)2, (SByte)3));
Assert.AreEqual(((Int16)2) | ((Int16)3), NumberUtils.BitwiseOr((Int16)2, (Int16)3));
Assert.AreEqual(((UInt16)2) | ((UInt16)3), NumberUtils.BitwiseOr((UInt16)2, (UInt16)3));
Assert.AreEqual(((Int32)2) | ((Int32)3), NumberUtils.BitwiseOr((Int32)2, (Int32)3));
Assert.AreEqual(((UInt32)2) | ((UInt32)3), NumberUtils.BitwiseOr((UInt32)2, (UInt32)3));
Assert.AreEqual(((Int64)2) | ((Int64)3), NumberUtils.BitwiseOr((Int64)2, (Int64)3));
Assert.AreEqual(((UInt64)2) | ((UInt64)3), NumberUtils.BitwiseOr((UInt64)2, (UInt64)3));
Assert.AreEqual(((UInt64)2) | ((Byte)3), NumberUtils.BitwiseOr((UInt64)2, (Byte)3));
Assert.AreEqual(false, NumberUtils.BitwiseOr(false, false));
Assert.AreEqual(true, NumberUtils.BitwiseOr(false, true));
try
{
NumberUtils.BitwiseAnd((double)2.0, 3);
Assert.Fail();
}
catch(ArgumentException)
{}
}
[Test]
public void BitwiseXor()
{
Assert.AreEqual( ((Byte)2) ^ ((Byte)3), NumberUtils.BitwiseXor((Byte)2, (Byte)3));
Assert.AreEqual(((SByte)2) ^ ((SByte)3), NumberUtils.BitwiseXor((SByte)2, (SByte)3));
Assert.AreEqual(((Int16)2) ^ ((Int16)3), NumberUtils.BitwiseXor((Int16)2, (Int16)3));
Assert.AreEqual(((UInt16)2) ^ ((UInt16)3), NumberUtils.BitwiseXor((UInt16)2, (UInt16)3));
Assert.AreEqual(((Int32)2) ^ ((Int32)3), NumberUtils.BitwiseXor((Int32)2, (Int32)3));
Assert.AreEqual(((UInt32)2) ^ ((UInt32)3), NumberUtils.BitwiseXor((UInt32)2, (UInt32)3));
Assert.AreEqual(((Int64)2) ^ ((Int64)3), NumberUtils.BitwiseXor((Int64)2, (Int64)3));
Assert.AreEqual(((UInt64)2) ^ ((UInt64)3), NumberUtils.BitwiseXor((UInt64)2, (UInt64)3));
Assert.AreEqual(((UInt64)2) ^ ((Byte)3), NumberUtils.BitwiseXor((UInt64)2, (Byte)3));
Assert.AreEqual(false, NumberUtils.BitwiseXor(false, false));
Assert.AreEqual(false, NumberUtils.BitwiseXor(true, true));
Assert.AreEqual(true, NumberUtils.BitwiseXor(false, true));
Assert.AreEqual(true, NumberUtils.BitwiseXor(true, false));
try
{
NumberUtils.BitwiseAnd((double)2.0, 3);
Assert.Fail();
}
catch(ArgumentException)
{}
}
}
}