DataDictionary.Interpreter.BinaryExpression.GetStaticCallable C# (CSharp) Method

GetStaticCallable() public method

Provides the ICallable which corresponds to this expression
public GetStaticCallable ( ) : ICallable
return ICallable
        public override ICallable GetStaticCallable()
        {
            if (_staticCallable == null)
            {
                ICallable left = Left.GetStaticCallable();
                if (left != null)
                {
                    ICallable right = Right.GetStaticCallable();
                    if (right != null)
                    {
                        if (left.FormalParameters.Count == right.FormalParameters.Count)
                        {
                            bool match = true;
                            for (int i = 0; i < left.FormalParameters.Count; i++)
                            {
                                Type leftType = ((Parameter) left.FormalParameters[i]).Type;
                                Type rightType = ((Parameter) right.FormalParameters[i]).Type;
                                if (!leftType.Equals(rightType))
                                {
                                    AddError("Non matching formal parameter type for parameter " + i + " " + leftType +
                                             " vs " + rightType, RuleChecksEnum.SemanticAnalysisError);
                                    match = false;
                                }
                            }

                            if (left.ReturnType != right.ReturnType)
                            {
                                AddError("Non matching return types " + left.ReturnType + " vs " + right.ReturnType, RuleChecksEnum.SemanticAnalysisError);
                                match = false;
                            }

                            if (match)
                            {
                                // Create a dummy funciton for type analysis
                                Function function = (Function) acceptor.getFactory().createFunction();
                                function.Name = ToString();
                                function.ReturnType = left.ReturnType;
                                foreach (Parameter param in left.FormalParameters)
                                {
                                    Parameter parameter = (Parameter) acceptor.getFactory().createParameter();
                                    parameter.Name = param.Name;
                                    parameter.Type = param.Type;
                                    parameter.Enclosing = function;
                                    function.appendParameters(parameter);
                                }
                                function.Enclosing = Root;
                                _staticCallable = function;
                            }
                        }
                        else
                        {
                            AddError("Invalid number of parameters, " + Left + " and " + Right +
                                     " should have the same number of parameters", RuleChecksEnum.SemanticAnalysisError);
                        }
                    }
                    else
                    {
                        // Left is not null, but right is.
                        // Ensure that right type corresponds to left return type
                        // and return left
                        Type rightType = Right.GetExpressionType();
                        if (rightType.Match(left.ReturnType))
                        {
                            _staticCallable = left;
                        }
                        else
                        {
                            AddError(Left + "(" + left.ReturnType + " ) does not correspond to " + Right + "(" +
                                     rightType + ")", RuleChecksEnum.SemanticAnalysisError);
                        }
                    }
                }
                else
                {
                    ICallable right = Right.GetStaticCallable();
                    if (right != null)
                    {
                        // Right is not null, but left is.
                        // Ensure that left type corresponds to right return type
                        // and return right
                        Type leftType = Left.GetExpressionType();
                        if ((leftType.Match(right.ReturnType)))
                        {
                            _staticCallable = right;
                        }
                        else
                        {
                            AddError(Left + "(" + leftType + ") does not correspond to " + Right + "(" +
                                     right.ReturnType + ")", RuleChecksEnum.SemanticAnalysisError);
                        }
                    }
                }
            }

            return _staticCallable;
        }