コード例 #1
0
ファイル: DocItemWriter.cs プロジェクト: spirits-qi/Tools
 protected string GetReadableName(DocItem item)
 {
     string name = item.Content.Attribute("name").Value;
     if (item.UniqueId.StartsWith("enum:"))
     {
         int index = item.Title.LastIndexOf(' ');
         return item.Title.Substring(0, index);
     }
     else
     {
         while (true)
         {
             item = item.Parent;
             if (item == null || !item.UniqueId.StartsWith("type:"))
             {
                 break;
             }
             else
             {
                 name = item.Content.Attribute("name").Value + "::" + name;
             }
         }
     }
     return name;
 }
コード例 #2
0
ファイル: DocItemWriter.cs プロジェクト: spirits-qi/Tools
 public static DocItemWriter CreateWriter(string name, DocItem docItem)
 {
     switch (name)
     {
         case "namespace": return new NamespaceDocItemWriter() { AssociatedDocItem = docItem };
         case "enum": return new EnumDocItemWriter() { AssociatedDocItem = docItem };
         case "type": return new TypeDocItemWriter() { AssociatedDocItem = docItem };
         case "functionGroup": return new FunctionGroupDocItemWriter() { AssociatedDocItem = docItem };
         case "function": return new FunctionDocItemWriter() { AssociatedDocItem = docItem };
         case "field": return new FieldDocItemWriter() { AssociatedDocItem = docItem };
         default: throw new ArgumentException(string.Format("Cannot create DocItemWriter for {0}.", name));
     }
 }
コード例 #3
0
ファイル: DocItemWriter.cs プロジェクト: spirits-qi/Tools
 public void Write(DocItem docItem, TextWriter writer, DocItemWriterContext context)
 {
     writer.WriteLine("/title:{0}", docItem.Title);
     writer.WriteLine("/uniqueId:{0}", docItem.UniqueId);
     writer.WriteLine("/parentUniqueId:{0}", docItem.Parent.UniqueId);
     if (!string.IsNullOrWhiteSpace(docItem.Symbol))
     {
         writer.WriteLine("/symbol:{0}", docItem.Symbol);
     }
     writer.WriteLine("/content");
     writer.WriteLine("/+h1/{0}/-h1//para/", docItem.Title);
     WriteContent(docItem, writer, context);
     if (docItem.SubItems.Count > 0)
     {
         writer.WriteLine("/+b/In This Section:/-b//crlf/");
         foreach (var item in docItem.SubItems
             .OrderBy(x => x.Title)
             )
         {
             writer.WriteLine("/nop/    /+linkid:{0}/{1}/-linkid//crlf/", item.UniqueId, item.Title);
         }
     }
 }
コード例 #4
0
ファイル: DocItemWriter.cs プロジェクト: vczh-codeplex/gac
 public void Write(DocItem docItem, TextWriter writer, DocItemWriterContext context)
 {
     writer.WriteLine("/title:{0}", docItem.Title);
     writer.WriteLine("/uniqueId:{0}", docItem.UniqueId);
     writer.WriteLine("/parentUniqueId:{0}", docItem.Parent.UniqueId);
     if (!string.IsNullOrWhiteSpace(docItem.Symbol))
     {
         writer.WriteLine("/symbol:{0}", docItem.Symbol);
     }
     writer.WriteLine("/content");
     writer.WriteLine("/+h1/{0}/-h1//para/", docItem.Title);
     WriteContent(docItem, writer, context);
     if (docItem.SubItems.Count > 0)
     {
         writer.WriteLine("/+b/In This Section:/-b//crlf/");
         foreach (var item in docItem.SubItems
                  .OrderBy(x => x.Title)
                  )
         {
             writer.WriteLine("/nop/    /+linkid:{0}/{1}/-linkid//crlf/", item.UniqueId, item.Title);
         }
     }
 }
コード例 #5
0
ファイル: DocItemWriter.cs プロジェクト: vczh-codeplex/gac
        public static DocItemWriter CreateWriter(string name, DocItem docItem)
        {
            switch (name)
            {
            case "namespace": return(new NamespaceDocItemWriter()
                {
                    AssociatedDocItem = docItem
                });

            case "enum": return(new EnumDocItemWriter()
                {
                    AssociatedDocItem = docItem
                });

            case "type": return(new TypeDocItemWriter()
                {
                    AssociatedDocItem = docItem
                });

            case "functionGroup": return(new FunctionGroupDocItemWriter()
                {
                    AssociatedDocItem = docItem
                });

            case "function": return(new FunctionDocItemWriter()
                {
                    AssociatedDocItem = docItem
                });

            case "field": return(new FieldDocItemWriter()
                {
                    AssociatedDocItem = docItem
                });

            default: throw new ArgumentException(string.Format("Cannot create DocItemWriter for {0}.", name));
            }
        }
コード例 #6
0
ファイル: DocItemWriter.cs プロジェクト: vczh-codeplex/gac
 protected override void WriteContent(DocItem docItem, TextWriter writer, DocItemWriterContext context)
 {
     {
         var describedFunctions = docItem
                                  .SubItems
                                  .Where(i => i.UniqueId.StartsWith("function:"))
                                  .Concat(docItem
                                          .SubItems
                                          .Where(i => i.UniqueId.StartsWith("functionGroup:"))
                                          .SelectMany(i => i.SubItems)
                                          )
                                  .ToDictionary(
             x => x.Content.Attribute("name").Value,
             x => new XElement[] { x.Content.Element("document").Element("member") }
             );
         WriteSubItemTable(describedFunctions, "Functions", writer, context);
     }
     {
         var describedTypes = docItem
                              .SubItems
                              .Where(i => i.UniqueId.StartsWith("type:"))
                              .Concat(docItem
                                      .SubItems
                                      .Where(i => i.UniqueId.StartsWith("enum:"))
                                      )
                              .ToDictionary(
             x =>
         {
             int index = x.Title.LastIndexOf(' ');
             return(x.Title.Substring(0, index).Trim());
         },
             x => new XElement[] { x.Content.Element("document").Element("member") }
             );
         WriteSubItemTable(describedTypes, "Types", writer, context);
     }
 }
コード例 #7
0
ファイル: DocItemWriter.cs プロジェクト: spirits-qi/Tools
 protected override void WriteContent(DocItem docItem, TextWriter writer, DocItemWriterContext context)
 {
     WriteSummaryInDocItem(docItem, writer, context);
     writer.WriteLine("/para/");
     writer.WriteLine("/+b/Members:/-b//crlf/");
     writer.WriteLine("/+table/");
     writer.WriteLine("    /+rowheader//+col/Name/-col//+col/Description/-col//-rowheader/");
     foreach (var fieldElement in docItem.Content.Elements("field"))
     {
         writer.WriteLine("    /+row/");
         string name = fieldElement.Attribute("name").Value;
         writer.WriteLine("        /+col/{0}/-col/", name);
         writer.Write("        /+col/");
         WriteSummaryIfDocumentExists(fieldElement, writer, context);
         writer.WriteLine("/-col/");
         writer.WriteLine("    /-row/");
     }
     writer.WriteLine("/-table//para/");
 }
コード例 #8
0
ファイル: DocItemAnalyzer.cs プロジェクト: spirits-qi/Tools
 public static DocItem GetItems(XElement docXml)
 {
     DocItem root = new DocItem();
     BuildItems(root, docXml, new List<Tuple<string, XElement>>());
     return root;
 }
コード例 #9
0
ファイル: DocItemWriter.cs プロジェクト: spirits-qi/Tools
 protected XElement WriteSummaryInDocItem(DocItem docItem, TextWriter writer, DocItemWriterContext context)
 {
     if (docItem.Document != null)
     {
         XElement member = docItem.Document.Element("member");
         if (member != null)
         {
             WriteSummary(member, writer, context);
             writer.WriteLine();
             return member;
         }
     }
     return null;
 }
コード例 #10
0
ファイル: DocItemAnalyzer.cs プロジェクト: spirits-qi/Tools
 public void AddSymbolDocItem(DocItem item, List<Tuple<string, XElement>> namespaces, string[] namespaceNames)
 {
     var lastNamespace = namespaces.LastOrDefault();
     AddSymbolDocItem(item, (lastNamespace == null ? null : lastNamespace.Item2), namespaceNames);
 }
コード例 #11
0
ファイル: DocItemWriter.cs プロジェクト: spirits-qi/Tools
 private XElement[] GetSubTypes(DocItem docItem)
 {
     return docItem.Content.Elements("enum").Concat(docItem.Content.Elements("type")).ToArray();
 }
コード例 #12
0
ファイル: DocItemAnalyzer.cs プロジェクト: spirits-qi/Tools
        static void BuildItems(DocItem docItem, XElement docXml, List<Tuple<string, XElement>> namespaces)
        {
            switch (docXml.Name.ToString())
            {
                case "cppdoc":
                    {
                        foreach (var subXml in docXml.Elements())
                        {
                            BuildItems(docItem, subXml, namespaces);
                        }
                    }
                    break;
                case "namespace":
                    {
                        namespaces.Add(Tuple.Create(docXml.Attribute("name").Value, docXml));
                        foreach (var subXml in docXml.Elements())
                        {
                            BuildItems(docItem, subXml, namespaces);
                        }
                        namespaces.RemoveAt(namespaces.Count - 1);
                    }
                    break;
                case "enum":
                    {
                        string typeName = docXml.Attribute("name").Value;
                        string fullName = docXml.Attribute("fullName").Value;
                        string[] namespaceNames = null;
                        Tuple<string, XElement> lastNamespace = null;
                        if (typeName == "Type" && namespaces.Count > 0)
                        {
                            var siblings = docXml.Parent.Elements().ToArray();
                            if (siblings.Length != 1 && siblings[0] != docXml)
                            {
                                throw new ArgumentException();
                            }
                            typeName = namespaces.Last().Item1 + "::" + typeName;
                            lastNamespace = namespaces.Take(namespaces.Count - 1).LastOrDefault();
                            namespaceNames = namespaces.Take(namespaces.Count - 1).Select(t => t.Item1).ToArray();
                        }
                        else
                        {
                            lastNamespace = namespaces.LastOrDefault();
                            namespaceNames = namespaces.Select(t => t.Item1).ToArray();
                        }

                        DocItem typeItem = new DocItem()
                        {
                            Name = "enum_" + fullName.Replace("::", "_"),
                            UniqueId = "enum:" + fullName,
                            Title = typeName + " Enumeration",
                            Content = docXml,
                            Document = docXml.Element("document"),
                        };

                        docItem.AddSymbolDocItem(typeItem, (lastNamespace == null ? null : lastNamespace.Item2), namespaceNames);
                    }
                    break;
                case "type":
                    {
                        string typeName = docXml.Attribute("name").Value;
                        string fullName = docXml.Attribute("fullName").Value;
                        string[] namespaceNames = namespaces.Select(t => t.Item1).ToArray();

                        DocItem typeItem = new DocItem()
                        {
                            Name = "type_" + fullName.Replace("::", "_"),
                            UniqueId = "type:" + fullName,
                            Title = typeName + " Class",
                            Content = docXml,
                        };

                        docItem.AddSymbolDocItem(typeItem, namespaces, namespaceNames);
                        foreach (var subXml in docXml.Elements())
                        {
                            BuildItems(typeItem, subXml, namespaces);
                        }
                    }
                    break;
                case "functionGroup":
                    {
                        var functions = docXml.Elements().ToArray();
                        if (functions.Length == 1)
                        {
                            BuildItems(docItem, functions[0], namespaces);
                        }
                        else
                        {
                            if (functions.Length == 0)
                            {
                                throw new ArgumentException();
                            }
                            string functionName = docXml.Attribute("name").Value;
                            string[] namespaceNames = namespaces.Select(t => t.Item1).ToArray();

                            string nameBody = "";
                            string uniqueIdBody = "";
                            if (docItem.Parent == null)
                            {
                                string[] names = namespaceNames.Where(s => s != "").ToArray();
                                if (names.Length > 0)
                                {
                                    nameBody = names.Aggregate((a, b) => a + "_" + b);
                                    uniqueIdBody = names.Aggregate((a, b) => a + "::" + b);
                                }
                            }
                            else
                            {
                                nameBody = docItem.NameBody;
                                uniqueIdBody = docItem.UniqueIdBody;
                            }

                            DocItem functionItem = new DocItem()
                            {
                                Name = "functionGroup_" + nameBody + "_" + functionName,
                                UniqueId = "functionGroup:" + uniqueIdBody + "::" + functionName,
                                Title = functionName + " Functions(overloading)",
                                Content = docXml,
                            };
                            docItem.AddSymbolDocItem(functionItem, namespaces, namespaceNames);
                            foreach (var subXml in functions)
                            {
                                BuildItems(functionItem, subXml, namespaces);
                            }
                        }
                    }
                    break;
                case "function":
                    {
                        string functionName = docXml.Attribute("name").Value;
                        string fullName = docXml.Attribute("fullName").Value;
                        string[] namespaceNames = namespaces.Select(t => t.Item1).ToArray();
                        if (functionName == fullName && docItem.Parent != null)
                        {
                            fullName = docItem.UniqueIdBody + "::" + functionName;
                        }
                        if (docItem.UniqueId != null && docItem.UniqueId.StartsWith("functionGroup:"))
                        {
                            fullName += "[" + docItem.SubItems.Count.ToString() + "]";
                        }
                        DocItem functionItem = new DocItem()
                        {
                            Name = "function_" + fullName.Replace("::", "_"),
                            UniqueId = "function:" + fullName,
                            Title = functionName + " Function",
                            Content = docXml,
                            Document = docXml.Element("document"),
                        };
                        docItem.AddSymbolDocItem(functionItem, namespaces, namespaceNames);
                    }
                    break;
                case "field":
                    {
                        string fieldName = docXml.Attribute("name").Value;
                        string fullName = docItem.UniqueIdBody + "::" + fieldName;
                        string[] namespaceNames = namespaces.Select(t => t.Item1).ToArray();
                        DocItem fieldItem = new DocItem()
                        {
                            Name = "field_" + fullName.Replace("::", "_"),
                            UniqueId = "field:" + fullName,
                            Title = fieldName + " Field",
                            Content = docXml,
                            Document = docXml.Element("document"),
                        };
                        docItem.AddSymbolDocItem(fieldItem, namespaces, namespaceNames);
                    }
                    break;
                case "document":
                    {
                        if (docItem.Document != null)
                        {
                            throw new ArgumentException();
                        }
                        if (!docItem.UniqueId.StartsWith("enum:") &&
                            !docItem.UniqueId.StartsWith("type:") &&
                            !docItem.UniqueId.StartsWith("function:"))
                        {
                            throw new ArgumentException();
                        }
                        docItem.Document = docXml;
                    }
                    break;
                case "baseType":
                    break;
                default:
                    throw new ArgumentException();
            }
        }
コード例 #13
0
ファイル: DocItemWriter.cs プロジェクト: spirits-qi/Tools
 private DocItem[] GetDirectAndIndirectBaseTypes(DocItem docItem, DocItemWriterContext context)
 {
     var baseTypeNames = GetBaseTypeElements(docItem)
         .Select(t => t.Attribute("fullName").Value)
         .ToArray();
     DocItem[] directBaseTypes = baseTypeNames
         .Where(t => context.UniqueIdItemMap.ContainsKey("type:" + t))
         .Select(t => context.UniqueIdItemMap["type:" + t])
         .ToArray();
     return directBaseTypes.Concat(directBaseTypes.SelectMany(t => GetDirectAndIndirectBaseTypes(t, context))).ToArray();
 }
コード例 #14
0
ファイル: DocItemWriter.cs プロジェクト: spirits-qi/Tools
        protected override void WriteContent(DocItem docItem, TextWriter writer, DocItemWriterContext context)
        {
            WriteSummaryInDocItem(docItem, writer, context);
            writer.WriteLine("/para/");

            var baseTypes = docItem.Content.Elements("baseType").ToArray();
            if (baseTypes.Length > 0)
            {
                writer.WriteLine("/+b/Base Types:/-b//crlf/");
                foreach (var baseType in baseTypes)
                {
                    writer.Write("/nop/    ");
                    WriteHyperlinkType(baseType.Attribute("fullName").Value, writer, context);
                    writer.WriteLine("/crlf/");
                }
                writer.WriteLine("/para/");
            }

            DocItem[] baseTypeDocItems = GetDirectAndIndirectBaseTypes(docItem, context);
            var subTypes = GetSubTypes(docItem)
                .Select(x => Tuple.Create(x, null as string))
                .Concat(baseTypeDocItems
                    .SelectMany(d => GetSubTypes(d)
                        .Select(x => Tuple.Create(x, d.UniqueId.Substring(5))))
                    )
                .ToArray();
            var subFields = GetSubFields(docItem)
                .Select(x => Tuple.Create(x, null as string))
                .Concat(baseTypeDocItems
                    .SelectMany(d => GetSubFields(d)
                        .Select(x => Tuple.Create(x, d.UniqueId.Substring(5))))
                    )
                .ToArray();
            var subFunctions = GetSubFunctions(docItem)
                .Select(x => Tuple.Create(x, null as string))
                .Concat(baseTypeDocItems
                    .SelectMany(d => GetSubFunctions(d)
                        .Select(x => Tuple.Create(x, d.UniqueId.Substring(5))))
                    )
                .ToArray();
            WriteSubItemTable(subTypes, "Sub Types", writer, context);
            WriteTypedSubItemTable(subFields, "Fields", writer, context);
            WriteSubItemTable(subFunctions, "Member Functions", writer, context);
        }
コード例 #15
0
ファイル: DocItemWriter.cs プロジェクト: spirits-qi/Tools
 protected override void WriteContent(DocItem docItem, TextWriter writer, DocItemWriterContext context)
 {
     XElement[] subFunctions = docItem.Content.Elements("function").ToArray();
     WriteSubItemTable(subFunctions, "Overloading Functions", writer, context);
 }
コード例 #16
0
ファイル: DocItemWriter.cs プロジェクト: spirits-qi/Tools
 protected override void WriteContent(DocItem docItem, TextWriter writer, DocItemWriterContext context)
 {
     WriteSummaryInDocItem(docItem, writer, context);
     writer.WriteLine("/para//+b/Type:/-b//crlf/");
     WriteHyperlinkType(docItem.Content.Element("type").Value, writer, context);
     writer.WriteLine("/para/");
 }
コード例 #17
0
ファイル: DocItemWriter.cs プロジェクト: vczh-codeplex/gac
 private XElement[] GetBaseTypeElements(DocItem docItem)
 {
     return(docItem.Content.Elements("baseType").ToArray());
 }
コード例 #18
0
ファイル: DocItemAnalyzer.cs プロジェクト: spirits-qi/Tools
 public void AddDocItem(DocItem item)
 {
     if (item.Parent == null)
     {
         item.Parent = this;
         this.SubItems.Add(item);
     }
     else
     {
         throw new ArgumentException();
     }
 }
コード例 #19
0
ファイル: DocItemWriter.cs プロジェクト: vczh-codeplex/gac
 protected abstract void WriteContent(DocItem docItem, TextWriter writer, DocItemWriterContext context);
コード例 #20
0
ファイル: DocItemAnalyzer.cs プロジェクト: spirits-qi/Tools
 public DocItem AddNamespaceDocItem(string[] names, XElement docXml)
 {
     names = names.Where(s => s != "").ToArray();
     if (names.Length == 0)
     {
         return this;
     }
     else
     {
         string namespacePath = "namespace_" + names.Aggregate((a, b) => a + "_" + b);
         DocItem item = this.SubItems.Where(i => i.Name == namespacePath).FirstOrDefault();
         if (item == null)
         {
             string namespaceName = names.Aggregate((a, b) => a + "::" + b);
             item = new DocItem()
             {
                 Name = namespacePath,
                 UniqueId = "namespace:" + namespaceName,
                 Title = namespaceName + " Namespace",
                 Content = docXml,
             };
             AddDocItem(item);
         }
         return item;
     }
 }
コード例 #21
0
ファイル: DocItemWriter.cs プロジェクト: spirits-qi/Tools
        protected override void WriteContent(DocItem docItem, TextWriter writer, DocItemWriterContext context)
        {
            XElement member = WriteSummaryInDocItem(docItem, writer, context);
            writer.WriteLine("/para/");
            string returnType = docItem.Content.Element("returnType").Value;
            XElement returnElement = member.Element("returns");
            var parameterTypes = docItem.Content.Elements("parameterType").Select(x => x.Value).ToArray();
            var parameters = docItem.Content.Elements("parameterPair")
                .ToDictionary(x => x.Attribute("name").Value, x => x.Value);
            var parameterElements = member.Elements("param").ToArray();
            foreach (var name in parameterElements.Select((x, i) => Tuple.Create(x.Attribute("name").Value, i)))
            {
                if (!parameters.ContainsKey(name.Item1))
                {
                    parameters.Add(name.Item1, parameterTypes[name.Item2]);
                }
            }

            writer.WriteLine("/+b/Signature:/-b//crlf/");
            writer.WriteLine("/+table/");
            writer.WriteLine("    /+rowheader//+col/Parameter or Return Value/-col//+col/Type/-col//+col/Description/-col//-rowheader/");
            {
                writer.WriteLine("    /+row/");
                writer.WriteLine("        /+col/return value/-col/");
                writer.Write("        /+col/");
                WriteHyperlinkType(returnType, writer, context);
                writer.WriteLine("/-col/");
                writer.Write("        /+col/");
                if (returnElement != null)
                {
                    WriteNodes(returnElement.Nodes(), writer, context);
                }
                writer.WriteLine("/-col/");
                writer.WriteLine("    /-row/");
            }
            foreach (var p in parameterElements)
            {
                string name = p.Attribute("name").Value;
                string type = parameters[name];
                var description = p.Nodes();

                writer.WriteLine("    /+row/");
                writer.WriteLine("        /+col/{0}/-col/", name);
                writer.Write("        /+col/");
                WriteHyperlinkType(type, writer, context);
                writer.WriteLine("/-col/");
                writer.Write("        /+col/");
                WriteNodes(description, writer, context);
                writer.WriteLine("/-col/");
                writer.WriteLine("    /-row/");
            }
            writer.WriteLine("/-table//para/");
        }
コード例 #22
0
ファイル: DocItemWriter.cs プロジェクト: vczh-codeplex/gac
 private XElement[] GetSubTypes(DocItem docItem)
 {
     return(docItem.Content.Elements("enum").Concat(docItem.Content.Elements("type")).ToArray());
 }
コード例 #23
0
ファイル: DocItemWriter.cs プロジェクト: spirits-qi/Tools
 protected override void WriteContent(DocItem docItem, TextWriter writer, DocItemWriterContext context)
 {
     {
         var describedFunctions = docItem
             .SubItems
             .Where(i => i.UniqueId.StartsWith("function:"))
             .Concat(docItem
                 .SubItems
                 .Where(i => i.UniqueId.StartsWith("functionGroup:"))
                 .SelectMany(i => i.SubItems)
                 )
             .ToDictionary(
                 x => x.Content.Attribute("name").Value,
                 x => new XElement[] { x.Content.Element("document").Element("member") }
                 );
         WriteSubItemTable(describedFunctions, "Functions", writer, context);
     }
     {
         var describedTypes = docItem
             .SubItems
             .Where(i => i.UniqueId.StartsWith("type:"))
             .Concat(docItem
                 .SubItems
                 .Where(i => i.UniqueId.StartsWith("enum:"))
                 )
             .ToDictionary(
                 x =>
                 {
                     int index = x.Title.LastIndexOf(' ');
                     return x.Title.Substring(0, index).Trim();
                 },
                 x => new XElement[] { x.Content.Element("document").Element("member") }
                 );
         WriteSubItemTable(describedTypes, "Types", writer, context);
     }
 }
コード例 #24
0
ファイル: DocItemWriter.cs プロジェクト: vczh-codeplex/gac
 private XElement[] GetSubFields(DocItem docItem)
 {
     return(docItem.Content.Elements("field").ToArray());
 }
コード例 #25
0
ファイル: DocItemWriter.cs プロジェクト: spirits-qi/Tools
 private XElement[] GetBaseTypeElements(DocItem docItem)
 {
     return docItem.Content.Elements("baseType").ToArray();
 }
コード例 #26
0
ファイル: DocItemWriter.cs プロジェクト: vczh-codeplex/gac
 protected override void WriteContent(DocItem docItem, TextWriter writer, DocItemWriterContext context)
 {
     XElement[] subFunctions = docItem.Content.Elements("function").ToArray();
     WriteSubItemTable(subFunctions, "Overloading Functions", writer, context);
 }
コード例 #27
0
ファイル: DocItemWriter.cs プロジェクト: spirits-qi/Tools
 private XElement[] GetSubFields(DocItem docItem)
 {
     return docItem.Content.Elements("field").ToArray();
 }
コード例 #28
0
ファイル: DocItemAnalyzer.cs プロジェクト: vczh-codeplex/gac
        static void BuildItems(DocItem docItem, XElement docXml, List <Tuple <string, XElement> > namespaces)
        {
            switch (docXml.Name.ToString())
            {
            case "cppdoc":
            {
                foreach (var subXml in docXml.Elements())
                {
                    BuildItems(docItem, subXml, namespaces);
                }
            }
            break;

            case "namespace":
            {
                namespaces.Add(Tuple.Create(docXml.Attribute("name").Value, docXml));
                foreach (var subXml in docXml.Elements())
                {
                    BuildItems(docItem, subXml, namespaces);
                }
                namespaces.RemoveAt(namespaces.Count - 1);
            }
            break;

            case "enum":
            {
                string   typeName       = docXml.Attribute("name").Value;
                string   fullName       = docXml.Attribute("fullName").Value;
                string[] namespaceNames = null;
                Tuple <string, XElement> lastNamespace = null;
                if (typeName == "Type" && namespaces.Count > 0)
                {
                    var siblings = docXml.Parent.Elements().ToArray();
                    if (siblings.Length != 1 && siblings[0] != docXml)
                    {
                        throw new ArgumentException();
                    }
                    typeName       = namespaces.Last().Item1 + "::" + typeName;
                    lastNamespace  = namespaces.Take(namespaces.Count - 1).LastOrDefault();
                    namespaceNames = namespaces.Take(namespaces.Count - 1).Select(t => t.Item1).ToArray();
                }
                else
                {
                    lastNamespace  = namespaces.LastOrDefault();
                    namespaceNames = namespaces.Select(t => t.Item1).ToArray();
                }

                DocItem typeItem = new DocItem()
                {
                    Name     = "enum_" + fullName.Replace("::", "_"),
                    UniqueId = "enum:" + fullName,
                    Title    = typeName + " Enumeration",
                    Content  = docXml,
                    Document = docXml.Element("document"),
                };

                docItem.AddSymbolDocItem(typeItem, (lastNamespace == null ? null : lastNamespace.Item2), namespaceNames);
            }
            break;

            case "type":
            {
                string   typeName       = docXml.Attribute("name").Value;
                string   fullName       = docXml.Attribute("fullName").Value;
                string[] namespaceNames = namespaces.Select(t => t.Item1).ToArray();

                DocItem typeItem = new DocItem()
                {
                    Name     = "type_" + fullName.Replace("::", "_"),
                    UniqueId = "type:" + fullName,
                    Title    = typeName + " Class",
                    Content  = docXml,
                };

                docItem.AddSymbolDocItem(typeItem, namespaces, namespaceNames);
                foreach (var subXml in docXml.Elements())
                {
                    BuildItems(typeItem, subXml, namespaces);
                }
            }
            break;

            case "functionGroup":
            {
                var functions = docXml.Elements().ToArray();
                if (functions.Length == 1)
                {
                    BuildItems(docItem, functions[0], namespaces);
                }
                else
                {
                    if (functions.Length == 0)
                    {
                        throw new ArgumentException();
                    }
                    string   functionName   = docXml.Attribute("name").Value;
                    string[] namespaceNames = namespaces.Select(t => t.Item1).ToArray();

                    string nameBody     = "";
                    string uniqueIdBody = "";
                    if (docItem.Parent == null)
                    {
                        string[] names = namespaceNames.Where(s => s != "").ToArray();
                        if (names.Length > 0)
                        {
                            nameBody     = names.Aggregate((a, b) => a + "_" + b);
                            uniqueIdBody = names.Aggregate((a, b) => a + "::" + b);
                        }
                    }
                    else
                    {
                        nameBody     = docItem.NameBody;
                        uniqueIdBody = docItem.UniqueIdBody;
                    }

                    DocItem functionItem = new DocItem()
                    {
                        Name     = "functionGroup_" + nameBody + "_" + functionName,
                        UniqueId = "functionGroup:" + uniqueIdBody + "::" + functionName,
                        Title    = functionName + " Functions(overloading)",
                        Content  = docXml,
                    };
                    docItem.AddSymbolDocItem(functionItem, namespaces, namespaceNames);
                    foreach (var subXml in functions)
                    {
                        BuildItems(functionItem, subXml, namespaces);
                    }
                }
            }
            break;

            case "function":
            {
                string   functionName   = docXml.Attribute("name").Value;
                string   fullName       = docXml.Attribute("fullName").Value;
                string[] namespaceNames = namespaces.Select(t => t.Item1).ToArray();
                if (functionName == fullName && docItem.Parent != null)
                {
                    fullName = docItem.UniqueIdBody + "::" + functionName;
                }
                if (docItem.UniqueId != null && docItem.UniqueId.StartsWith("functionGroup:"))
                {
                    fullName += "[" + docItem.SubItems.Count.ToString() + "]";
                }
                DocItem functionItem = new DocItem()
                {
                    Name     = "function_" + fullName.Replace("::", "_"),
                    UniqueId = "function:" + fullName,
                    Title    = functionName + " Function",
                    Content  = docXml,
                    Document = docXml.Element("document"),
                };
                docItem.AddSymbolDocItem(functionItem, namespaces, namespaceNames);
            }
            break;

            case "field":
            {
                string   fieldName      = docXml.Attribute("name").Value;
                string   fullName       = docItem.UniqueIdBody + "::" + fieldName;
                string[] namespaceNames = namespaces.Select(t => t.Item1).ToArray();
                DocItem  fieldItem      = new DocItem()
                {
                    Name     = "field_" + fullName.Replace("::", "_"),
                    UniqueId = "field:" + fullName,
                    Title    = fieldName + " Field",
                    Content  = docXml,
                    Document = docXml.Element("document"),
                };
                docItem.AddSymbolDocItem(fieldItem, namespaces, namespaceNames);
            }
            break;

            case "document":
            {
                if (docItem.Document != null)
                {
                    throw new ArgumentException();
                }
                if (!docItem.UniqueId.StartsWith("enum:") &&
                    !docItem.UniqueId.StartsWith("type:") &&
                    !docItem.UniqueId.StartsWith("function:"))
                {
                    throw new ArgumentException();
                }
                docItem.Document = docXml;
            }
            break;

            case "baseType":
                break;

            default:
                throw new ArgumentException();
            }
        }
コード例 #29
0
ファイル: DocItemWriter.cs プロジェクト: spirits-qi/Tools
 private XElement[] GetSubFunctions(DocItem docItem)
 {
     return docItem.Content.Elements("function")
         .Concat(
             docItem.Content.Elements("functionGroup")
                 .SelectMany(e => e.Elements("function"))
             )
         .ToArray();
 }
コード例 #30
0
ファイル: DocItemAnalyzer.cs プロジェクト: vczh-codeplex/gac
        public void AddSymbolDocItem(DocItem item, List <Tuple <string, XElement> > namespaces, string[] namespaceNames)
        {
            var lastNamespace = namespaces.LastOrDefault();

            AddSymbolDocItem(item, (lastNamespace == null ? null : lastNamespace.Item2), namespaceNames);
        }
コード例 #31
0
ファイル: DocItemWriter.cs プロジェクト: spirits-qi/Tools
 protected abstract void WriteContent(DocItem docItem, TextWriter writer, DocItemWriterContext context);
コード例 #32
0
ファイル: DocItemAnalyzer.cs プロジェクト: spirits-qi/Tools
 public void AddSymbolDocItem(DocItem item, XElement namespaceXml, string[] namespaceNames)
 {
     if (this.Parent == null)
     {
         AddNamespaceDocItem(namespaceNames, namespaceXml).AddDocItem(item);
     }
     else
     {
         AddDocItem(item);
     }
 }