Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update IMemory interface and tryEvaluate for expression #3635

Merged
merged 24 commits into from
Mar 31, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
6188caa
expand the interface expression evaluation to take an extra option
boydc2014 Mar 27, 2020
2d9207b
expand IMemory to accept a boolean flag
boydc2014 Mar 27, 2020
3533c74
Update ExpressionEvaluator.cs
boydc2014 Mar 27, 2020
bc08c6a
adjust the order of parameter of EvalauteChildren
boydc2014 Mar 30, 2020
e08c340
fix boolean context in where
boydc2014 Mar 30, 2020
b6f747d
fix doc
boydc2014 Mar 30, 2020
768385f
fix customzied memory in LG
boydc2014 Mar 30, 2020
5b8a28c
fix customized funtion inside onConditions
boydc2014 Mar 30, 2020
51c7b74
fix doc
boydc2014 Mar 30, 2020
570e9ea
Swallow error in bool
boydc2014 Mar 30, 2020
ae1aa0e
Fix DSM for the new interface
boydc2014 Mar 30, 2020
44763c6
Revert "Fix DSM for the new interface"
boydc2014 Mar 30, 2020
dd57286
Switch to a specific null substitution delegate
boydc2014 Mar 31, 2020
075a04c
Fix Element
boydc2014 Mar 31, 2020
ba61dde
fix the type issue
boydc2014 Mar 31, 2020
3cd4f0d
revert LG memory change
boydc2014 Mar 31, 2020
5868ae3
update OnCondition
boydc2014 Mar 31, 2020
01c4408
Remove delegate in favor of Func
boydc2014 Mar 31, 2020
fc63341
Add constructor and copy constructor
boydc2014 Mar 31, 2020
6291383
Made comparision boolean context also with test cases
boydc2014 Mar 31, 2020
a6c2303
remove unintended change in csproj
boydc2014 Mar 31, 2020
8e50a25
revert changes in csproj
boydc2014 Mar 31, 2020
33f1078
go back using Comparison for bool()
boydc2014 Mar 31, 2020
ed0ac59
catch error in Where func
boydc2014 Mar 31, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libraries/AdaptiveExpressions/Constant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class Constant : Expression
/// </summary>
/// <param name="value">Constant value.</param>
public Constant(object value = null)
: base(new ExpressionEvaluator(ExpressionType.Constant, (expression, state) => ((expression as Constant).Value, null)))
: base(new ExpressionEvaluator(ExpressionType.Constant, (expression, state, _) => ((expression as Constant).Value, null)))
{
Value = value;
}
Expand Down
23 changes: 14 additions & 9 deletions libraries/AdaptiveExpressions/Expression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public static Expression LambaExpression(EvaluateExpressionDelegate function)
/// <param name="function">Lambda expression to evaluate.</param>
/// <returns>New expression.</returns>
public static Expression Lambda(Func<object, object> function)
=> new Expression(new ExpressionEvaluator(ExpressionType.Lambda, (expression, state) =>
=> new Expression(new ExpressionEvaluator(ExpressionType.Lambda, (expression, state, _) =>
{
object value = null;
string error = null;
Expand Down Expand Up @@ -481,9 +481,10 @@ public void ValidateTree()
/// Global state to evaluate accessor expressions against. Can be <see cref="System.Collections.Generic.IDictionary{String, Object}"/>,
/// <see cref="System.Collections.IDictionary"/> otherwise reflection is used to access property and then indexer.
/// </param>
/// <param name="options">Options used in the evaluation. </param>
/// <returns>Computed value and an error string. If the string is non-null, then there was an evaluation error.</returns>
public (object value, string error) TryEvaluate(object state)
=> this.TryEvaluate<object>(MemoryFactory.Create(state));
public (object value, string error) TryEvaluate(object state, Options options = null)
=> this.TryEvaluate<object>(MemoryFactory.Create(state), options);

/// <summary>
/// Evaluate the expression.
Expand All @@ -492,9 +493,10 @@ public void ValidateTree()
/// Global state to evaluate accessor expressions against. Can be <see cref="System.Collections.Generic.IDictionary{String, Object}"/>,
/// <see cref="System.Collections.IDictionary"/> otherwise reflection is used to access property and then indexer.
/// </param>
/// <param name="options">Options used in the evaluation. </param>
/// <returns>Computed value and an error string. If the string is non-null, then there was an evaluation error.</returns>
public (object value, string error) TryEvaluate(IMemory state)
=> this.TryEvaluate<object>(state);
public (object value, string error) TryEvaluate(IMemory state, Options options = null)
=> this.TryEvaluate<object>(state, options);

/// <summary>
/// Evaluate the expression.
Expand All @@ -504,9 +506,10 @@ public void ValidateTree()
/// Global state to evaluate accessor expressions against. Can be <see cref="System.Collections.Generic.IDictionary{String, Object}"/>,
/// <see cref="System.Collections.IDictionary"/> otherwise reflection is used to access property and then indexer.
/// </param>
/// <param name="options">Options used in the evaluation. </param>
/// <returns>Computed value and an error string. If the string is non-null, then there was an evaluation error.</returns>
public (T value, string error) TryEvaluate<T>(object state)
=> this.TryEvaluate<T>(MemoryFactory.Create(state));
public (T value, string error) TryEvaluate<T>(object state, Options options = null)
=> this.TryEvaluate<T>(MemoryFactory.Create(state), options);

/// <summary>
/// Evaluate the expression.
Expand All @@ -516,10 +519,12 @@ public void ValidateTree()
/// Global state to evaluate accessor expressions against. Can be <see cref="System.Collections.Generic.IDictionary{String, Object}"/>,
/// <see cref="System.Collections.IDictionary"/> otherwise reflection is used to access property and then indexer.
/// </param>
/// <param name="options">Options used in the evaluation. </param>
/// <returns>Computed value and an error string. If the string is non-null, then there was an evaluation error.</returns>
public (T value, string error) TryEvaluate<T>(IMemory state)
public (T value, string error) TryEvaluate<T>(IMemory state, Options options = null)
{
var (result, error) = Evaluator.TryEvaluate(this, state);
var opts = options ?? new Options();
var (result, error) = Evaluator.TryEvaluate(this, state, opts);
if (error != null)
{
return (default(T), error);
Expand Down
8 changes: 5 additions & 3 deletions libraries/AdaptiveExpressions/ExpressionEvaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ namespace AdaptiveExpressions
/// </remarks>
/// <param name="expression">Expression to evaluate.</param>
/// <param name="state">Global state information.</param>
/// <param name="options">Options for the evaluation.</param>
/// <returns>Value and error string that is non-null if there is an error.</returns>
public delegate (object value, string error) EvaluateExpressionDelegate(Expression expression, IMemory state);
public delegate (object value, string error) EvaluateExpressionDelegate(Expression expression, IMemory state, Options options);

/// <summary>
/// Delegate to lookup function information from the type.
Expand Down Expand Up @@ -105,9 +106,10 @@ public ExpressionEvaluator Negation
/// </summary>
/// <param name="expression">Expression to evaluate.</param>
/// <param name="state">Global state information.</param>
/// <param name="options">Options used in the evaluation. </param>
/// <returns>Value and error string that is non-null if there is an error.</returns>
public (object value, string error) TryEvaluate(Expression expression, IMemory state)
=> _evaluator(expression, state);
public (object value, string error) TryEvaluate(Expression expression, IMemory state, Options options)
=> _evaluator(expression, state, options);

/// <summary>
/// Validate an expression.
Expand Down
Loading