public CustomFunctionOverload(CustomFunction function) { Name = function.Name; IsConstant = function.IsConstant; _rootNode = new CustomFunctionOverloadNode(); _rootNode.Build(function); }
public void Build(CustomFunction function, int index = 0) { var paramTypes = function.ParameterTypes; if (index >= paramTypes.Length) { if (LeafFunction != null) { throw new RuntimeException("The custom function with same name and same parameter types is already defined"); } LeafFunction = function; return; } CustomFunctionOverloadNode nextNode; switch (paramTypes[index]) { case Type.Integer: if (_integerNode == null) { _integerNode = new CustomFunctionOverloadNode(); } nextNode = _integerNode; break; case Type.Float: if (_floatNode == null) { _floatNode = new CustomFunctionOverloadNode(); } nextNode = _floatNode; break; case Type.Boolean: if (_booleanNode == null) { _booleanNode = new CustomFunctionOverloadNode(); } nextNode = _booleanNode; break; default: throw new ArgumentOutOfRangeException(nameof(paramTypes), paramTypes[index], "Unsupported parameter type"); } nextNode.Build(function, index + 1); }
private static CustomFunction FindOverload(Type[] paramTypes, int index, CustomFunctionOverloadNode primary, CustomFunctionOverloadNode secondary) { CustomFunction function = null; if (primary != null) { function = primary.Find(paramTypes, index + 1); } if (function == null && secondary != null) { function = secondary.Find(paramTypes, index + 1); } return(function); }