Ejemplo n.º 1
0
 internal override FnObject CreateFnIfWithSameType(
     FnObject <bool> condition,
     FnObject trueArg,
     FnObject falseArg)
 {
     return((FnObject) new FnIf <T>(condition, trueArg, falseArg));
 }
Ejemplo n.º 2
0
        internal override FnObject CheckAndCache()
        {
            for (int index = 0; index < this.ArgsInfo.Length; ++index)
            {
                this.ArgsInfo[index].SetValue((object)this, (object)(this.ArgsInfo[index].GetValue((object)this) as FnObject).CheckAndCache());
            }
            FnObject fnObject = !this.IsCachable() ? (FnObject)this : (FnObject) new FnConstant <T>(this.GetValue());

            this.ClearDataPostCache();
            return(fnObject);
        }
Ejemplo n.º 3
0
 internal FunctalExpression(
     FnObject <T> executionNode,
     string rawExpression,
     Dictionary <string, FnObject> parameters,
     FnVariable <bool> isPreExecute)
     : base(isPreExecute)
 {
     this.RawExpression = rawExpression;
     this.ExecutionNode = executionNode;
     this.Parameters    = parameters;
 }
Ejemplo n.º 4
0
        internal override FnObject CheckAndCache()
        {
            // Optimize child FnObjects.
            Condition = Condition.CheckAndCache() as FnObject <Boolean>;
            TrueArg   = TrueArg.CheckAndCache() as FnObject <T>;
            FalseArg  = FalseArg.CheckAndCache() as FnObject <T>;

            // Optimize this node.
            if (IsCachable())
            {
                return(new FnConstant <T>(GetValue()));
            }

            // Can't optimize.
            return(this);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Creates an <see cref="FnIf"/> object with the same wrapped type as this <see cref="FnObject"/>.
 /// </summary>
 /// <param name="condition">The conditional for the <see cref="FnIf"/>.</param>
 /// <param name="trueArg">The execution tree to execute if <see cref="condition"/> returns true.</param>
 /// <param name="falseArg">The execution tree to execute if <see cref="condition"/> returns false.</param>
 internal abstract FnObject CreateFnIfWithSameType(FnObject <bool> condition, FnObject trueArg, FnObject falseArg);
Ejemplo n.º 6
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="condition">
 /// A boolean expression which determines if trueArg or falseArg is executed and returned.
 /// </param>
 /// <param name="trueArg">An expression whose value is returned if condition returns true.</param>
 /// <param name="falseArg">An expression whose value is returned if condition returns false.</param>
 internal FnIf(FnObject <bool> condition, FnObject trueArg, FnObject falseArg)
 {
     Condition = condition;
     TrueArg   = trueArg as FnObject <T>;
     FalseArg  = falseArg as FnObject <T>;
 }
Ejemplo n.º 7
0
        public FnObject CreateObjectWithPointer(
            List <FnObject> arguments,
            Dictionary <string, FnObject> parameters,
            FnVariable <bool> isPreExecute)
        {
            for (int index1 = 0; index1 < this.FunctionPointers.Count; ++index1)
            {
                Type[] functionTypeArray = this.FunctionPointers[index1].GetFunctionTypeArray();
                if (functionTypeArray.Length == arguments.Count)
                {
                    for (int index2 = 0; index2 < functionTypeArray.Length && !(functionTypeArray[index2] != arguments[index2].GetWrappedObjectType()); ++index2)
                    {
                        if (index2 == functionTypeArray.Length - 1)
                        {
                            return(this.FunctionPointers[index1].CreateObjectWithPointer(arguments, parameters, isPreExecute));
                        }
                    }
                }
            }
            List <int> intList = new List <int>(this.FunctionPointers.Count);

            for (int index1 = 0; index1 < this.FunctionPointers.Count; ++index1)
            {
                Type[] functionTypeArray = this.FunctionPointers[index1].GetFunctionTypeArray();
                if (functionTypeArray.Length == arguments.Count)
                {
                    intList.Add(0);
                    for (int index2 = 0; index2 < functionTypeArray.Length; ++index2)
                    {
                        if (functionTypeArray[index2] != arguments[index2].GetWrappedObjectType())
                        {
                            int ambiguityScore = FunctalResources.GetAmbiguityScore(functionTypeArray[index2], arguments[index2].GetWrappedObjectType());
                            if (ambiguityScore <= 0)
                            {
                                intList[index1] = -1;
                                break;
                            }
                            intList[index1] += ambiguityScore;
                        }
                    }
                }
                else
                {
                    intList.Add(-1);
                }
            }
            int index3 = -1;
            int num    = 1;

            for (int index1 = 0; index1 < intList.Count; ++index1)
            {
                if (intList[index1] >= 0)
                {
                    if (index3 == -1)
                    {
                        index3 = index1;
                    }
                    else if (intList[index1] < intList[index3])
                    {
                        index3 = index1;
                        num    = 1;
                    }
                    else if (intList[index1] == intList[index3])
                    {
                        ++num;
                    }
                }
            }
            if (index3 >= 0 && num == 1)
            {
                for (int index1 = 0; index1 < arguments.Count; ++index1)
                {
                    if (this.FunctionPointers[index3].GetFunctionTypeArray()[index1] != arguments[index1].GetWrappedObjectType())
                    {
                        List <FnObject> fnObjectList     = arguments;
                        int             index2           = index1;
                        FnFunctionGroup conversionSwitch = FunctalResources.ImplicitConversionSwitches[this.FunctionPointers[index3].GetFunctionTypeArray()[index1]];
                        List <FnObject> arguments1       = new List <FnObject>();
                        arguments1.Add(arguments[index1]);
                        Dictionary <string, FnObject> parameters1   = parameters;
                        FnVariable <bool>             isPreExecute1 = isPreExecute;
                        FnObject objectWithPointer = conversionSwitch.CreateObjectWithPointer(arguments1, parameters1, isPreExecute1);
                        fnObjectList[index2] = objectWithPointer;
                    }
                }
                return(this.FunctionPointers[index3].CreateObjectWithPointer(arguments, parameters, isPreExecute));
            }
            if (index3 >= 0 && num > 1)
            {
                throw new ArgumentException("The function call is too ambiguous to resolve, use more specific argument types", arguments.ToString());
            }
            throw new ArgumentException("The function has no overloads which match the specified arguments", arguments.ToString());
        }