Exemple #1
0
        private static void TraverseDefinitions(XElement node, List <PFNDefinition> list, ref bool inside)
        {
            if (node.Name == "h4")
            {
                if (node.Value == "C Specification")
                {
                    inside = true;
                }
            }
            else if (node.Name == "code")
            {
                if (inside)
                {
                    XAttribute attrClass = node.Attribute("class");
                    if (attrClass != null && attrClass.Value == "language-c++")
                    {
                        string v    = node.Value;
                        var    item = new PFNDefinition()
                        {
                            raw = v,
                        };
                        list.Add(item);
                        inside = false;
                    }
                }
            }

            foreach (XElement item in node.Elements())
            {
                TraverseDefinitions(item, list, ref inside);
            }
        }
Exemple #2
0
        public static void Dump()
        {
            XElement root = XElement.Load(filename);
            var      lstDefinition = new List <PFNDefinition>(); bool inside = false;

            TraverseDefinitions(root, lstDefinition, ref inside);
            var lstItemComment = new List <PFNItemComment>(); inside = false;

            TraverseItemComments(root, lstItemComment, ref inside);
            var lstComment = new List <string>(); inside = false;

            TraverseComments(root, lstComment, ref inside);

            using (var sw = new System.IO.StreamWriter("PFNs.gen.cs")) {
                for (int i = 0; i < lstDefinition.Count; i++)
                {
                    PFNDefinition definition = lstDefinition[i];
                    //sw.WriteLine(definition.raw);
                    string[]       definitionLines           = definition.Dump();
                    PFNItemComment itemComment               = lstItemComment[i];
                    Dictionary <string, string> item2Comment = itemComment.Dump();

                    sw.WriteLine($"// PFN: {i}");
                    string comment = lstComment[i];
                    sw.WriteLine($"/// <summary>{comment}</summary>");
                    {
                        string line = definitionLines[0];
                        sw.WriteLine(line); // public unsafe delegate ...
                    }
                    for (int j = 1; j < definitionLines.Length; j++)
                    {
                        string line = definitionLines[j];
                        if (item2Comment != null)
                        {
                            string strComment = ParseItemComment(line, item2Comment);
                            if (strComment != string.Empty)
                            {
                                strComment = strComment.Replace("\r\n", "\n");
                                strComment = strComment.Replace("\r", "\n");
                                strComment = strComment.Replace("\n", $"{Environment.NewLine}    /// ");
                                strComment = Helper.RemoveBraces(strComment);
                                sw.WriteLine($"    /// <summary>{strComment}</summary>");
                            }
                        }
                        {
                            line = line.Trim();
                            var l = line.Replace("const char* ", "IntPtr ");
                            l = l.Replace("const*", "/*-const-*/ *");
                            l = l.Replace("const ", "/*-const-*/ ");
                            l = l.Replace(" const", " /*-const-*/");
                            l = l.Replace("size_t ", "Int32 ");
                            l = l.Replace("uint8_t* ", "byte* ");
                            l = l.Replace("uint8_t ", " byte ");
                            l = l.Replace("uint16_t* ", "UInt16* ");
                            l = l.Replace("uint16_t ", "UInt16 ");
                            l = l.Replace("uint32_t* ", "UInt32* ");
                            l = l.Replace("uint32_t ", "UInt32 ");
                            l = l.Replace("uint64_t* ", "UInt64* ");
                            l = l.Replace("uint64_t ", "UInt64 ");
                            l = l.Replace("int32_t* ", "Int32* ");
                            l = l.Replace("int32_t ", "Int32 ");
                            l = l.Replace("int64_t* ", "Int64* ");
                            l = l.Replace("int64_t ", "Int64 ");
                            l = l.Replace("struct ", "/* struct */ ");
                            l = l.Replace(" object", " _object");
                            l = l.Replace(" event", " _event");
                            l = "    " + l;
                            sw.WriteLine(l);
                        }
                    }
                    if (definitionLines.Length < 2)
                    {
                        sw.WriteLine(");");
                    }
                }
            }
            Console.WriteLine("Done");
        }