public override ICallable GetCalled(InterpretationContext context, ExplanationPart explain)
{
ICallable retVal = null;
Function leftFunction = Left.GetCalled(context, explain) as Function;
List<Parameter> unboundLeft = getUnboundParameter(context, leftFunction);
if (leftFunction == null || unboundLeft.Count == 0)
{
leftFunction = Left.GetValue(context, explain) as Function;
unboundLeft = getUnboundParametersFromValue(leftFunction);
}
Function rightFunction = Right.GetCalled(context, explain) as Function;
List<Parameter> unboundRight = getUnboundParameter(context, rightFunction);
if (rightFunction == null || unboundRight.Count == 0)
{
rightFunction = Right.GetValue(context, explain) as Function;
unboundRight = getUnboundParametersFromValue(rightFunction);
}
int max = Math.Max(unboundLeft.Count, unboundRight.Count);
if (max == 0)
{
if (leftFunction == null)
{
if (rightFunction == null)
{
retVal = GetValue(context, explain) as ICallable;
}
else
{
if (rightFunction.FormalParameters.Count == 1)
{
// ReSharper disable once ExpressionIsAlwaysNull
retVal = CreateGraphResult(context, leftFunction, unboundLeft, rightFunction, unboundRight,
explain);
}
else if (rightFunction.FormalParameters.Count == 2)
{
// ReSharper disable once ExpressionIsAlwaysNull
retVal = CreateSurfaceResult(context, leftFunction, unboundLeft, rightFunction, unboundRight,
explain);
}
else
{
retVal = GetValue(context, explain) as ICallable;
}
}
}
else if (rightFunction == null)
{
if (leftFunction.FormalParameters.Count == 1)
{
// ReSharper disable once ExpressionIsAlwaysNull
retVal = CreateGraphResult(context, leftFunction, unboundLeft, rightFunction, unboundRight,
explain);
}
else if (leftFunction.FormalParameters.Count == 2)
{
// ReSharper disable once ExpressionIsAlwaysNull
retVal = CreateSurfaceResult(context, leftFunction, unboundLeft, rightFunction, unboundRight,
explain);
}
else
{
retVal = GetValue(context, explain) as ICallable;
}
}
else
{
retVal = GetValue(context, explain) as ICallable;
}
if (retVal == null)
{
AddError("Cannot create ICallable when there are no unbound parameters", RuleChecksEnum.ExecutionFailed);
}
}
else if (max == 1)
{
retVal = CreateGraphResult(context, leftFunction, unboundLeft, rightFunction, unboundRight, explain);
}
else if (max == 2)
{
retVal = CreateSurfaceResult(context, leftFunction, unboundLeft, rightFunction, unboundRight, explain);
}
else
{
AddError("Cannot create graph or structure when more that 2 parameters are unbound", RuleChecksEnum.ExecutionFailed);
}
return retVal;
}