Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
private sealed class MaskedExpression : Expression
{
private Expression _original;
private Func<Context, bool> _condition;
private Func<Context, JSValue> _optimizedExpression;
protected internal override bool LValueModifier
{
get
{
return _original.LValueModifier;
}
}
protected internal override bool NeedDecompose
{
get
{
return _original.NeedDecompose;
}
}
public override int Position
{
get
{
return _original.Position;
}
internal set
{
_original.Position = value;
}
}
internal override bool ResultInTempContainer
{
get
{
return _original.ResultInTempContainer;
}
}
protected internal override PredictedType ResultType
{
get
{
return _original.ResultType;
}
}
protected internal override bool ContextIndependent
{
get
{
return _original.ContextIndependent;
}
}
public override bool Eliminated
{
get
{
return _original.Eliminated;
}
internal set
{
_original.Eliminated = value;
}
}
public override int Length
{
get
{
return _original.Length;
}
internal set
{
_original.Length = value;
}
}
public MaskedExpression(New original, Func<Context, bool> condition, Func<Context, JSValue> optimizedExpression)
{
_original = original;
_condition = condition;
_optimizedExpression = optimizedExpression;
}
public override JSValue Evaluate(Context context)
{
if (_condition(context))
return _optimizedExpression(context);
else
return _original.Evaluate(context);
}
public override bool Build(ref CodeNode _this, int expressionDepth, Dictionary<string, VariableDescriptor> variables, CodeContext codeContext, CompilerMessageCallback message, FunctionInfo stats, Options opts)
{
return _original.Build(ref _this, expressionDepth, variables, codeContext, message, stats, opts);
}
public override void Decompose(ref Expression self, IList<CodeNode> result)
{
_original.Decompose(ref self, result);
}
protected internal override JSValue EvaluateForWrite(Context context)
{
return _original.EvaluateForWrite(context);
}
protected internal override CodeNode[] getChildsImpl()
{
return _original.getChildsImpl();
}
public override void Optimize(ref CodeNode _this, FunctionDefinition owner, CompilerMessageCallback message, Options opts, FunctionInfo stats)
{
_original.Optimize(ref _this, owner, message, opts, stats);
}
public override void RebuildScope(FunctionInfo functionInfo, Dictionary<string, VariableDescriptor> transferedVariables, int scopeBias)
{
_original.RebuildScope(functionInfo, transferedVariables, scopeBias);
}
internal override System.Linq.Expressions.Expression TryCompile(bool selfCompile, bool forAssign, Type expectedType, List<CodeNode> dynamicValues)
{
return _original.TryCompile(selfCompile, forAssign, expectedType, dynamicValues);
}
public override T Visit<T>(Visitor<T> visitor)
{
return _original.Visit<T>(visitor);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment