private string InflectNativeReturnType(XmlCommandData command) { string type = command.ReturnType; if (command.ReturnTypeGroup == "ErrorCode") return command.ReturnTypeGroup; switch (command.ReturnType) { default: type = this.InflectType(command.ReturnType, false); break; } return type; }
private void ParseCommands(XDocument doc, XmlSpecData data, Options options) { foreach (var commandSetNode in doc.Root.Elements("commands")) { foreach (var commandNode in commandSetNode.Elements()) { XmlCommandData commandData = new XmlCommandData() { Name = this.EnsureCommandNameHasPrefix(commandNode.GetElementValue("proto", "name"), options), ReturnType = commandNode.GetElementValue("proto", "ptype"), ReturnTypeGroup = commandNode.GetElementAttributeValue("proto", "group"), Alias = commandNode.GetElementAttributeValue("alias", "name") }; if (commandData.ReturnType == null) commandData.ReturnType = commandNode.Element("proto").GetTexts().First().Trim(); // "void *" => "void*" if (commandData.ReturnType.EndsWith(" *")) commandData.ReturnType = commandData.ReturnType.Substring(0, commandData.ReturnType.Length - 2) + "*"; foreach (var commandParamNode in commandNode.Elements("param")) { XmlCommandParamData commandParamData = new XmlCommandParamData() { Name = commandParamNode.GetElementValue("name"), Type = commandParamNode.GetElementValue("ptype"), TypeGroup = commandParamNode.GetAttributeValue("group"), Length = commandParamNode.GetAttributeValue("len") }; if (commandParamData.Type == null) { commandParamData.Type = commandParamNode.GetTexts().First().Trim(); } else { var texts = commandParamNode.GetTexts(); if (texts.Count() == 1 && texts.First().Contains("*")) { commandParamData.Type = commandParamData.Type + new string('*', texts.First().Count(x => x == '*')); } else if ( texts.Count() == 2 && texts.First().Trim() == "const" && texts.Last().Contains("*")) { commandParamData.Type = "const " + commandParamData.Type + new string('*', texts.Last().Count(x => x == '*')); } } // "const void *" => "const void*" if (commandParamData.Type.EndsWith(" *")) commandParamData.Type = commandParamData.Type.Substring(0, commandParamData.Type.Length - 2) + "*"; commandData.Params.Add(commandParamData); } data.Commands.Add(commandData); } } }