Exemplo n.º 1
0
        /// <summary>
        /// Creates array code
        /// </summary>
        /// <param name="tree">Base tree</param>
        /// <param name="ret">Return</param>
        /// <param name="parameters">Variables</param>
        /// <param name="variables">Parameters</param>
        /// <param name="initializers">Initializers</param>
        /// <returns>List of code strings</returns>
        protected IList <string> CreateTreeCode(ObjectFormulaTree tree, string ret, string[] parameters,
                                                out IList <string> variables, out IList <string> initializers)
        {
            List <string> l = new List <string>();

            if (tree.ReturnType.IsEmpty())
            {
                variables    = new List <string>();
                initializers = new List <string>();
                return(l);
            }
            int    n    = StaticCodeCreator.GetNumber(this, tree);
            string curr = "trees[" + n + "].";
            // l.Add("currentTree = trees[" + n + "];");
            int           count = tree.Count;
            List <string> vari  = new List <string>();

            if (count > 0)
            {
                string ta = "treeArray_" + n;
                l.Add("currentArray = " + ta + ";");
                vari.Add("object[] " + ta + " = new object[" + count + "];");
            }
            for (int i = 0; i < count; i++)
            {
                ObjectFormulaTree t = tree[i];
                if (t == null)
                {
                    continue;
                }
                if (count > 0)
                {
                    string id = codeCreator[t];
                    l.Add("currentArray[" + i + "] = " + id + ";");
                }
            }
            string ss = "";
            string tt = typeCreator.GetType(tree.ReturnType);

            if (!tt.Equals("object"))
            {
                ss = "(" + tt + ")";
            }
            if (count > 0)
            {
                l.Add(ret + " = " + ss + curr + "Calculate(currentArray);");
            }
            else
            {
                l.Add(ret + " = " + ss + curr + "Calculate();");
            }
            initializers = new List <string>();
            variables    = vari;
            return(l);
        }
Exemplo n.º 2
0
        private void AddTree(ObjectFormulaTree tree, IList <string> init, IList <string> func)
        {
            int    n   = StaticCodeCreator.GetNumber(local, tree);
            string tid = local[tree];
            string f   = "Get_" + n;

            init.Add("dictionary[trees[" + n + "]] = " + f + ";");
            func.Add("");
            func.Add("object " + f + "()");
            func.Add("{");
            func.Add("\treturn " + tid + ";");
            func.Add("}");
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates code
        /// </summary>
        /// <param name="trees">Trees</param>
        /// <param name="creator">Code creator</param>
        /// <param name="local">Local code creator</param>
        /// <param name="variables">Variables</param>
        /// <param name="initializers">Initializers</param>
        /// <returns>List of code strings</returns>
        public static IList <string> CreateCode(ObjectFormulaTree[] trees, ICodeCreator creator, out ICodeCreator local,
                                                out IList <string> variables, out IList <string> initializers)
        {
            IList <string> l = StaticCodeCreator.CreateCode(trees, creator, out local,
                                                            out variables, out initializers);

            variables.Add("FormulaEditor.ObjectFormulaTree currentTree = null;");
            variables.Add("object[] currentArray = null;");
            variables.Add("double doubleValue = 0;");
            variables.Add("FormulaEditor.ObjectFormulaTree[] trees = null;");
            ObjectFormulaTree[] lt = local.Trees;
            foreach (ObjectFormulaTree tree in lt)
            {
                object ret = tree.ReturnType;
                if (ret.IsEmpty())
                {
                    continue;
                }
                string s = typeCreator.GetType(ret) + " ";
                s += local[tree];
                string cv  = creator.GetConstValue(tree);
                string def = "";
                if (cv == null)
                {
                    def = typeCreator.GetDefaultValue(ret) + "";
                    if (def.Length > 0)
                    {
                        s += " = ";
                    }
                    s += def;
                }
                else
                {
                    s += " = " + cv;
                }
                s += ";";
                variables.Add(s);
            }
            return(l);
        }