From 04f2ba433a051a66921015416809535966f9fb0a Mon Sep 17 00:00:00 2001 From: the_fiddler Date: Wed, 14 Oct 2009 22:50:25 +0000 Subject: [PATCH] Support adding new enum definitions through overrides.xml. --- Source/Bind/ES/ESGenerator.cs | 45 ++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/Source/Bind/ES/ESGenerator.cs b/Source/Bind/ES/ESGenerator.cs index 1d43fea5..c88cde39 100644 --- a/Source/Bind/ES/ESGenerator.cs +++ b/Source/Bind/ES/ESGenerator.cs @@ -96,31 +96,38 @@ namespace Bind.ES public override EnumCollection ReadEnums(StreamReader specFile) { + // First, read all enum definitions from spec and override file. + // Afterwards, read all token/enum overrides from overrides file. + // Every single enum is merged into + EnumCollection enums = new EnumCollection(); Enum all = new Enum() { Name = Settings.CompleteEnumName }; - XPathDocument doc = new XPathDocument(specFile); - XPathNavigator nav = doc.CreateNavigator().SelectSingleNode("/signatures"); - + XPathDocument specs = new XPathDocument(specFile); XPathDocument overrides = new XPathDocument(new StreamReader(Path.Combine(Settings.InputPath, functionOverridesFile))); - - foreach (XPathNavigator node in nav.SelectChildren("enum", String.Empty)) + + foreach (XPathNavigator nav in new XPathNavigator[] { + specs.CreateNavigator().SelectSingleNode("/signatures"), + overrides.CreateNavigator().SelectSingleNode("/overrides") }) { - Enum e = new Enum() - { - Name = node.GetAttribute("name", String.Empty), - Type = node.GetAttribute("type", String.Empty) - }; - if (String.IsNullOrEmpty(e.Name)) - throw new InvalidOperationException(String.Format("Empty name for enum element {0}", node.ToString())); - - foreach (XPathNavigator param in node.SelectChildren(XPathNodeType.Element)) + foreach (XPathNavigator node in nav.SelectChildren("enum", String.Empty)) { - Constant c = new Constant(param.GetAttribute("name", String.Empty), param.GetAttribute("value", String.Empty)); - Utilities.Merge(all, c); - e.ConstantCollection.Add(c.Name, c); - } + Enum e = new Enum() + { + Name = node.GetAttribute("name", String.Empty), + Type = node.GetAttribute("type", String.Empty) + }; + if (String.IsNullOrEmpty(e.Name)) + throw new InvalidOperationException(String.Format("Empty name for enum element {0}", node.ToString())); - Utilities.Merge(enums, e); + foreach (XPathNavigator param in node.SelectChildren(XPathNodeType.Element)) + { + Constant c = new Constant(param.GetAttribute("name", String.Empty), param.GetAttribute("value", String.Empty)); + Utilities.Merge(all, c); + e.ConstantCollection.Add(c.Name, c); + } + + Utilities.Merge(enums, e); + } } Utilities.Merge(enums, all);