/// <summary>
        /// Convert the user code into a C#/Java language version that can
        /// be used byt he program.
        /// </summary>
        /// <param name="Function">User Defined components</param>
        /// <returns>True/False upon success failure</returns>
        private String WriteUserFunction(GPLanguageWriter.tagUserDefinedFunction Function)
        {
            StringBuilder FunctionCode = new StringBuilder();

            //
            // Build the function name and parameter list
            WriteUserFunctionPrototype(Function, FunctionCode);
            FunctionCode.AppendLine();
            //
            // Opening brace
            FunctionCode.AppendLine("{");
            //
            // Place the user code but first, do a little diddy that makes
            // sure the code in indented in a pretty way.
            StringBuilder UserCode = new StringBuilder(Function.UserCode);

            UserCode.Replace("\n", "\n\t");
            FunctionCode.AppendLine(UserCode.ToString());

            //
            // Closing brace
            FunctionCode.AppendLine("}");

            return(FunctionCode.ToString());
        }
Beispiel #2
0
        /// <summary>
        /// Add the source code form of a language specific function to the object
        /// </summary>
        /// <param name="Name"></param>
        /// <param name="Arity"></param>
        /// <param name="UserCode"></param>
        /// <returns></returns>
        public bool AddFunction(String Name, short Arity, String UserCode)
        {
            GPLanguageWriter.tagUserDefinedFunction func = new GPLanguageWriter.tagUserDefinedFunction();
            func.Name     = Name;
            func.Arity    = Arity;
            func.UserCode = UserCode;
            m_FunctionSetCode.Add(Name.ToUpper(), func);

            return(true);
        }
 /// <summary>
 /// My first refactored method!  This writes the prototype for a function, needed
 /// by the function writer and up in the header declaration.
 /// </summary>
 /// <param name="Function"></param>
 /// <param name="FunctionCode"></param>
 private void WriteUserFunctionPrototype(GPLanguageWriter.tagUserDefinedFunction Function, StringBuilder FunctionCode)
 {
     FunctionCode.Append("double " + Function.Name + "(");
     for (short Param = 0; Param < Function.Arity; Param++)
     {
         //
         // See if we should add a comma
         if (Param > 0)
         {
             FunctionCode.Append(", ");
         }
         FunctionCode.Append("double p" + Param);
     }
     FunctionCode.Append(")");
 }
Beispiel #4
0
        /// <summary>
        /// Convert the user code into a C#/Java language version that can
        /// be used byt he program.
        /// </summary>
        /// <param name="Function">User Defined components</param>
        private void WriteUserFunction(GPLanguageWriter.tagUserDefinedFunction Function)
        {
            WriteFunctionPrototype(Function.Name, Function.Arity, "p");
            //
            // Place the indexed memory Common block here
            WriteFortranString("      REAL Memory(" + m_Program.CountMemory + ")");
            WriteFortranString("      COMMON /idxmemory/ Memory");
            WriteFortranString("");

            //
            // Place the user code but first, do a little diddy that makes
            // sure the code in indented in a pretty way.
            StringBuilder UserCode = new StringBuilder(Function.UserCode);

            UserCode.Replace("\n", "\n      ");
            m_Writer.Write("      ");                   // Need to indent the first line
            WriteFortranString(UserCode.ToString());

            //
            // Close off the function
            WriteFortranString("      RETURN");
            WriteFortranString("      END");
        }
        /// <summary>
        /// Convert the user code into a VB.NET language version that can
        /// be used by the program.
        /// </summary>
        /// <param name="Function">User Defined components</param>
        /// <returns>True/False upon success failure</returns>
        private String WriteUserFunction(GPLanguageWriter.tagUserDefinedFunction Function)
        {
            StringBuilder FunctionCode = new StringBuilder();

            //
            // Build the function name and parameter list
            FunctionCode.Append("\tPrivate Function " + Function.Name + "(");
            for (short Param = 0; Param < Function.Arity; Param++)
            {
                //
                // See if we should add a comma
                if (Param > 0)
                {
                    FunctionCode.Append(", ");
                }
                FunctionCode.Append("ByVal p" + Param + " As Double");
            }
            FunctionCode.AppendLine(") As Double");

            //
            // Space between declaration and body
            FunctionCode.AppendLine();
            //
            // Place the user code but first, do a little diddy that makes
            // sure the code in indented in a pretty way.
            StringBuilder UserCode = new StringBuilder(Function.UserCode);

            UserCode.Replace("\n", "\n\t\t");
            FunctionCode.AppendLine("\t\t" + UserCode.ToString());

            //
            // Close the function
            FunctionCode.AppendLine("\tEnd Function");
            FunctionCode.AppendLine();

            return(FunctionCode.ToString());
        }
        /// <summary>
        /// Convert the user code into a C#/Java language version that can
        /// be used byt he program.
        /// </summary>
        /// <param name="Function">User Defined components</param>
        /// <returns>True/False upon success failure</returns>
        private String WriteUserFunction(GPLanguageWriter.tagUserDefinedFunction Function)
        {
            StringBuilder FunctionCode = new StringBuilder();

            //
            // Build the function name and parameter list
            FunctionCode.Append("\tprivate double " + Function.Name + "(");
            for (short Param = 0; Param < Function.Arity; Param++)
            {
                //
                // See if we should add a comma
                if (Param > 0)
                {
                    FunctionCode.Append(", ");
                }
                FunctionCode.Append("double p" + Param);
            }
            FunctionCode.AppendLine(")");

            //
            // Opening brace & initial tab indent
            FunctionCode.AppendLine("\t{");
            FunctionCode.Append("\t\t");
            //
            // Place the user code but first, do a little diddy that makes
            // sure the code in indented in a pretty way.
            StringBuilder UserCode = new StringBuilder(Function.UserCode);

            UserCode.Replace("\n", "\n\t\t");
            FunctionCode.AppendLine(UserCode.ToString());

            //
            // Closing brace
            FunctionCode.AppendLine("\t}");

            return(FunctionCode.ToString());
        }