Beispiel #1
0
        bool generateMethod(XMethod xmethod, XClass xclass, StringBuilder sbOut, Chilkat.Log log, bool lowerCaseAlt = false)
        {
            sbOut.Append("\r\n\t\t# Method: " + xmethod.EntryName + "\r\n\t\t#\r\n");
            // lets add description...
            IEnumerable <string> chunked = chunkSplit(xmethod.Descrip, 100);

            foreach (var chunk in chunked)
            {
                sbOut.Append("\t\t# " + chunk.Trim().Replace("#\t\t", "# ") + "\r\n");
            }
            sbOut.Append("\t\t#\r\n");
            sbOut.Replace("=\r\n\t\t# _", " _");

            //if (xmethod.Deprecated)
            //    sbOut.Append("\t\t# This method has been deprecated. Do not use it.\r\n");
            //sbOut.Append("\t\t# ==== Attributes\r\n\t\t#\r\n");


            if (!genMethodSignature(xmethod, xclass, sbOut, log, lowerCaseAlt))
            {
                return(false);
            }

            //sbOut.Append("\t\t\t{\r\n");
            // Generate the method body here. This would include whatever code is necessary to prep input args,
            // make the call to the Chilkat API, and return the result..
            sbOut.Append("\t\t\t# ...\r\n");
            sbOut.Append("\t\tend\r\n\r\n");

            if (!lowerCaseAlt && xmethod.ToLowerCaseStringMethod() != null)
            {
                generateMethod(xmethod, xclass, sbOut, log, true);
            }
            return(true);
        }
        private static void PrepareIdentifiers()
        {
            namespaces.Clear();

            XNamespace currentNamespace = null;
            XClass     currentClass     = null;
            XRef       currentFile      = null;
            XMethod    currentMethod    = null;

            String path = null;
            int    ante, from, blockAt, to;

            foreach (string line in File.ReadAllLines(file))
            {
                ante    = 0;
                from    = 0;
                blockAt = 0;
                to      = 0;
                string[] elements = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                if (elements.Length > 0)
                {
                    switch (elements[0])
                    {
                    case "N":
                        currentNamespace = new XNamespace(elements[1]);
                        namespaces.Add(currentNamespace);
                        break;

                    case "\tC":
                        currentClass = new XClass(elements[1]);
                        currentNamespace.Classes.Add(currentClass);
                        break;

                    case "\t\tF":
                        currentFile = new XRef(new FileInfo(elements[1]), 0, 0, 0);
                        currentClass.Files.Add(currentFile);
                        break;

                    case "\t\t\tM":
                        currentMethod = new XMethod(elements[1]);
                        currentFile.Methods.Add(currentMethod);
                        string[] markers = elements[elements.Length - 1].Split(':');
                        if (markers.Length == 4)
                        {
                            int.TryParse(markers[0], out ante);
                            Array.Copy(markers, 1, markers, 0, markers.Length - 1);
                        }
                        if (int.TryParse(markers[0], out from) && int.TryParse(markers[1], out blockAt) && int.TryParse(markers[2], out to))
                        {
                            currentMethod.File = new XRef(currentFile.File, from, blockAt, to);
                        }
                        break;

                    default:
                        break;
                    }
                }
            }
        }
 private static string GetLogLine(XMethod m)
 {
     return("/*LoggingSystem to be removed from production code*/ LoggingSystem.MyLogger.Log(new LoggingSystem.LoggingElement(){ Nr= " +
            (MethodNumber++) + "," +
            " Namespace = \"" + m.Class.Namespace.Name + "\"," +
            " Class = \"" + m.Class.Name + "\"," +
            " Method = \"" + m.Class.Methods + "\" });\r\n"); // m.Class.Namespace.Name + ", " + m.Class.Name + ", " + m.Name + "";
 }
        bool generateMethod(XMethod xmethod, XClass xclass, StringBuilder sbOut, Chilkat.Log log)
        {
            sbOut.Append("\r\n// Method: " + xmethod.EntryName + "\r\n");

            if (!genMethodSignature(xmethod, xclass, sbOut, log))
            {
                return(false);
            }

            sbOut.Append("\t{\r\n");
            // Generate the method body here. This would include whatever code is necessary to prep input args,
            // make the call to the Chilkat API, and return the result..
            sbOut.Append("\t// ...\r\n");
            sbOut.Append("\t}\r\n");
            return(true);
        }
        bool genMethodSignature(XMethod xmethod, XClass xclass, StringBuilder sbOut, Chilkat.Log log)
        {
            string rtnType = m_types.gtToAxI(xmethod.m_gt, xmethod.GenericType);

            sbOut.Append(rtnType + " " + xmethod.EntryName + "(");

            // Iterate over the method args..
            int i = 1;

            foreach (MethodArg arg in xmethod.Args)
            {
                if (i > 1)
                {
                    sbOut.Append(", ");
                }
                sbOut.Append(m_types.gtToAxI(arg.Gt, arg.DataType) + " " + arg.Name);
                i++;
            }

            sbOut.Append(")\r\n");
            return(true);
        }
        bool generateClassToSb(XClass xclass, StringBuilder sbOut, Chilkat.Log log)
        {
            // We're just going to generate some pseudo-code...
            sbOut.Append("class " + xclass.GenericName + " {\r\n\r\n");

            // We could generate constructors, destructors, creation functions, etc. here...

            // Loop over properties and generate each..
            int i;

            for (i = 0; i < xclass.NumProperties; i++)
            {
                XProperty xprop = xclass.GetProperty(i);

                // Skip some properties we may not want..
                // (What you do here depends on your needs..)
                if (xprop.Deprecated)
                {
                    continue;
                }
                if (!xprop.AxEnabled)
                {
                    continue;                       // We don't want properties that do not exist in the ActiveX..
                }
                if (xprop.IsBytes)
                {
                    continue;                 // maybe we don't want to deal with the few properties that are binary data.
                }
                if (xprop.IsEventRelated())
                {
                    continue;
                }
                // ...

                if (!generateProperty(xprop, xclass, sbOut, log))
                {
                    return(false);
                }
            }

            // Loop over methods and generate each...
            for (i = 0; i < xclass.NumMethods; i++)
            {
                XMethod xmethod = xclass.GetMethod(i);

                // Skip some properties we may not want..
                // (What you do here depends on your needs..)
                if (xmethod.Deprecated)
                {
                    continue;
                }
                if (!xmethod.AxEnabled)
                {
                    continue;                         // We don't want properties that do not exist in the ActiveX..
                }
                if (xmethod.IsBytes || xmethod.HasArgWithGt(ChilkatTypes.GT_BYTES))
                {
                    continue;                                                                  // Maybe we don't want to deal with binary return values or args..
                }
                // ...

                if (!generateMethod(xmethod, xclass, sbOut, log))
                {
                    return(false);
                }
            }



            sbOut.Append("};\r\n");
            return(true);
        }
Beispiel #7
0
        bool genMethodSignature(XMethod xmethod, XClass xclass, StringBuilder sbOut, Chilkat.Log log, bool lowerCaseAlt = false)
        {
            string rtnType = m_types.gtToRubyDuck(xmethod.m_gt, xmethod.GenericType);

            if (!lowerCaseAlt && xmethod.CppMethodReturnGt == 4)
            {
                rtnType = "Boolean";
            }

            int i = 1;

            /*foreach (MethodArg arg in xmethod.Args)
             * {
             *  //if (i > 1) sbOut.Append(", ");
             *  sbOut.Append("\t\t# +" + arg.Name + "+ - " + m_types.gtToRubyDuck(arg.Gt, arg.DataType) + "\r\n");
             *  i++;
             * }
             * sbOut.Append("\t\t# returns " + rtnType + "\r\n");
             * sbOut.Append("\t\t#\r\n\t\t# YARD =>\r\n\t\t#\r\n");*/

            foreach (MethodArg arg in xmethod.Args)
            {
                //if (i > 1) sbOut.Append(", ");
                sbOut.Append("\t\t# @param " + arg.Name + " [" + m_types.gtToRubyDuck(arg.Gt, arg.DataType) + "]\r\n");
                i++;
            }

            if (!lowerCaseAlt && (xmethod.m_gt == 1 || xmethod.m_gt == 6))
            {
                sbOut.Append("\t\t# @param " + xmethod.CppOutputArgName + " [" + xmethod.CppOutputArgCppType.Replace(" &", "") + "]\r\n");
            }

            sbOut.Append("\t\t#\r\n\t\t# @return [" + rtnType + "]\r\n");
            if (xmethod.Deprecated)
            {
                sbOut.Append("\t\t# @deprecated This method has been deprecated. Do not use it.\r\n");
            }


            if (!lowerCaseAlt)
            {
                sbOut.Append("\t\tdef " + xmethod.EntryName + "(");
            }
            else
            {
                sbOut.Append("\t\tdef " + xmethod.EntryNameLowercaseNoCk + "(");
            }
            // Iterate over the method args..
            i = 1;
            foreach (MethodArg arg in xmethod.Args)
            {
                if (i > 1)
                {
                    sbOut.Append(", ");
                }
                sbOut.Append(arg.Name);
                i++;
            }

            if (!lowerCaseAlt && (xmethod.m_gt == 1 || xmethod.m_gt == 6))
            {
                if (i > 1)
                {
                    sbOut.Append(", ");
                }
                sbOut.Append(xmethod.CppOutputArgName);
            }

            sbOut.Append(")\r\n");
            return(true);
        }
Beispiel #8
0
 public CallElement(XMethod fromMethod, XMethod toMethod)
 {
     FromMethod = fromMethod;
     ToMethod   = toMethod;
 }
        public static List <XNamespace> GetNamespaces()
        {
            CallSequence = new List <CallElement>();
            XMethod       lastMethod  = null;
            List <string> linesCsproj = File.ReadAllLines(@"C:\Logs\Identifiers.txt").ToList();
            StringBuilder sb          = new StringBuilder();
            int           lines       = 0;

            List <HitRelationInfo> hitInfos   = new List <HitRelationInfo>();
            List <XNamespace>      namespaces = new List <XNamespace>();

            MethodHitInfo lastHittedInfo = null;

            foreach (string line in linesCsproj)
            {
                if (line.Length < 10)
                {
                    continue;
                }
                string pLine = line;
                lines++;
                MethodHitInfo tn = new MethodHitInfo();
                if (pLine.Substring(25, 6).Equals("silver"))
                {
                    tn.Component = 1;
                }
                else
                {
                    tn.Component = 0;
                }
                tn.Namespace = pLine.Substring(0, pLine.IndexOf("</span>"));
                tn.Namespace = tn.Namespace.Substring(tn.Namespace.LastIndexOf(">") + 1);
                XNamespace currentNamespace = namespaces.Where(p => p.Name.Equals(tn.Namespace)).FirstOrDefault();
                if (currentNamespace == null)
                {
                    currentNamespace = new XNamespace(tn.Namespace);
                    namespaces.Add(currentNamespace);
                }
                pLine    = pLine.Substring(pLine.IndexOf("</span>") + 7);
                tn.Class = pLine.Substring(0, pLine.IndexOf("</span>"));
                tn.Class = tn.Class.Substring(tn.Class.LastIndexOf(">") + 1);
                XClass currentClass =
                    currentNamespace.Classes.Where(p => p.Name.Equals(tn.Class)).FirstOrDefault();
                if (currentClass == null)
                {
                    currentClass = new XClass(tn.Class);
                    currentNamespace.Classes.Add(currentClass);
                }
                pLine     = pLine.Substring(pLine.IndexOf("</span>") + 7);
                tn.Method = pLine.Substring(0, pLine.IndexOf("</b>"));
                tn.Method = tn.Method.Substring(tn.Method.LastIndexOf(">") + 1);
                if (tn.Method.Equals(".ctor"))
                {
                    tn.Method = tn.Class + "()";
                }
                //if (MainForm.Exclusions.Contains(tn.Method))
                {
                    //continue;
                }
                XMethod currentMethod = currentClass.Methods.Where(p => p.Name.Equals(tn.Method)).FirstOrDefault();
                if (currentMethod == null)
                {
                    currentMethod        = new XMethod(tn.Method);
                    currentMethod.Parent = currentClass;
                    currentMethod.Calls  = new List <XMethod>();
                    currentClass.Methods.Add(currentMethod);
                }
                if (lastMethod != null)
                {
                    lastMethod.Calls.Add(currentMethod);
                    //if (XMethod.CallSequence.Count<50)
                    {
                        CallSequence.Add(new CallElement(lastMethod, currentMethod));
                    }
                }
                lastMethod = currentMethod;
                pLine      = pLine.Substring(pLine.IndexOf("</span>") + 7);
                string milisecondsString = "";
                int    miliseconds       = 0;
                milisecondsString = pLine.Substring(0, pLine.IndexOf("</span>"));
                milisecondsString = milisecondsString.Substring(milisecondsString.LastIndexOf(">") + 1);
                if (int.TryParse(milisecondsString, out miliseconds))
                {
                    tn.Time = tn.Time += miliseconds;
                    // no error reported. This method might be not accurate
                }
                pLine     = pLine.Substring(pLine.IndexOf("</span>") + 7);
                tn.Number = pLine.Substring(0, pLine.IndexOf("</span>"));
                tn.Number = tn.Number.Substring(tn.Number.LastIndexOf(">") + 1);
                int Nr = 0; int.TryParse(tn.Number, out Nr);
                currentMethod.ID = Nr;
            }
            return(namespaces);
        }