public static VulkanSpecification LoadFromXmlStream(Stream specFileStream) { var spec = XDocument.Load(specFileStream); var registry = spec.Element("registry"); var commands = registry.Element("commands"); CommandDefinition[] commandDefinitions = commands.Elements("command") .Select(commandx => CommandDefinition.CreateFromXml(commandx)).ToArray(); ConstantDefinition[] constantDefinitions = registry.Elements("enums") .Where(enumx => enumx.Attribute("name").Value == "API Constants") .SelectMany(enumx => enumx.Elements("enum")) .Select(enumxx => ConstantDefinition.CreateFromXml(enumxx)).ToArray(); var types = registry.Elements("types"); TypedefDefinition[] typedefDefinitions = types.Elements("type").Where(xe => xe.Value.Contains("typedef") && xe.HasCategoryAttribute("bitmask")) .Select(xe2 => TypedefDefinition.CreateFromXml(xe2)).ToArray(); EnumDefinition[] enumDefinitions = registry.Elements("enums") .Where(enumx => enumx.GetTypeAttributeOrNull() == "enum" || enumx.GetTypeAttributeOrNull() == "bitmask") .Select(enumx => EnumDefinition.CreateFromXml(enumx)).ToArray(); StructureDefinition[] structures = types.Elements("type").Where(typex => typex.HasCategoryAttribute("struct")) .Select(typex => StructureDefinition.CreateFromXml(typex)).ToArray(); StructureDefinition[] unions = types.Elements("type") .Where(typex => typex.HasCategoryAttribute("union")) .Select(typex => StructureDefinition.CreateFromXml(typex)).ToArray(); HandleDefinition[] handles = types.Elements("type").Where(typex => typex.HasCategoryAttribute("handle")) .Select(typex => HandleDefinition.CreateFromXml(typex)).ToArray(); string[] bitmaskTypes = types.Elements("type").Where(typex => typex.HasCategoryAttribute("bitmask")) .Select(typex => typex.GetNameElement()).ToArray(); Dictionary <string, string> baseTypes = types.Elements("type").Where(typex => typex.HasCategoryAttribute("basetype")) .ToDictionary( typex => typex.GetNameElement(), typex => typex.Element("type").Value); ExtensionDefinition[] extensions = registry.Element("extensions").Elements("extension") .Select(xe => ExtensionDefinition.CreateFromXml(xe)).ToArray(); return(new VulkanSpecification( commandDefinitions, constantDefinitions, typedefDefinitions, enumDefinitions, structures, unions, handles, bitmaskTypes, baseTypes, extensions)); }
public static void WriteConstant(CsCodeWriter cw, TypeNameMappings tnm, ConstantDefinition constant) { if (constant.Comment != null) { cw.WriteLine($"///<summary>{constant.Comment}</summary>"); } cw.WriteLine($"public const {GetCSharpNameForConstantType(constant.Type)} {EnumHelpers.GetPrettyEnumName(constant.Name, "VK_")} = {NormalizeValue(constant.Value)};"); }
public static void WriteConstant(CsCodeWriter cw, TypeNameMappings tnm, ConstantDefinition constant) { }