Handle multiple /signatures/add statements in the same file.

Trim enum and constant names before adding them to the relevant collection.
Fixed handling of extensions in enum names.
This commit is contained in:
the_fiddler 2010-12-03 11:24:58 +00:00
parent c4b50469c8
commit 057dfb9448
2 changed files with 43 additions and 7 deletions

View file

@ -52,11 +52,37 @@ namespace Bind
public EnumCollection Process(EnumCollection enums)
{
var nav = Overrides.CreateNavigator();
ProcessDeleteOverrides(enums, nav);
ProcessAddOverrides(enums, nav);
enums = ProcessNames(enums, nav);
enums = ProcessConstants(enums, nav);
return enums;
}
void ProcessAddOverrides(EnumCollection enums, XPathNavigator nav)
{
foreach (XPathNavigator add_node in nav.Select("/signatures/add"))
{
var new_enums = new XmlSpecReader().ReadEnums(add_node);
Utilities.Merge(enums, new_enums);
}
}
void ProcessDeleteOverrides(EnumCollection enums, XPathNavigator nav)
{
var del = nav.SelectSingleNode("/signatures/delete");
if (del != null)
{
foreach (XPathNavigator d in del.SelectChildren("function", String.Empty))
{
string name = d.GetAttribute("name", String.Empty);
if (enums.ContainsKey(name))
enums.Remove(name);
}
}
}
static EnumCollection ProcessNames(EnumCollection enums, XPathNavigator nav)
{
EnumCollection processed_enums = new EnumCollection();
@ -99,9 +125,16 @@ namespace Bind
StringBuilder translator = new StringBuilder(name.Length);
// Process according to these rules:
// 0. If name starts with a vendor name, make the first letter after that uppercase.
// 1. if current char is '_', '-' remove it and make next char uppercase
// 2. if current char is or '0-9' keep it and make next char uppercase.
// 3. if current character is uppercase make next char lowercase.
var ext = Utilities.GetGL2Extension(name);
if (ext != String.Empty)
{
name = name.Replace(ext.ToUpper(), ext);
}
bool is_after_underscore_or_number = true;
bool is_previous_uppercase = false;
foreach (char c in name)
@ -141,7 +174,7 @@ namespace Bind
translator.Replace("AttribIp", "AttribIP");
translator.Replace("SRgb", "Srgb");
name = translator.ToString();
name = translator.ToString().Trim();
if (name.StartsWith(Settings.EnumPrefix))
name = name.Substring(Settings.EnumPrefix.Length);
@ -152,7 +185,7 @@ namespace Bind
{
foreach (var e in enums.Values)
{
var processed_constants = new Dictionary<string, Constant>(e.ConstantCollection.Count);
var processed_constants = new SortedDictionary<string, Constant>();
foreach (Constant c in e.ConstantCollection.Values)
{
c.Name = TranslateConstantName(c.Name, false);
@ -245,7 +278,7 @@ namespace Bind
else
translator.Append(s);
return translator.ToString();
return translator.ToString().Trim();
}
public static string TranslateConstantValue(string value)

View file

@ -76,13 +76,16 @@ namespace Bind
return MarkCLSCompliance(wrappers);
}
private void ProcessAddOverrides(DelegateCollection delegates, XPathNavigator nav)
void ProcessAddOverrides(DelegateCollection delegates, XPathNavigator nav)
{
var new_delegates = new XmlSpecReader().ReadDelegates(nav.SelectSingleNode("/signatures/add"));
foreach (XPathNavigator add_node in nav.Select("/signatures/add"))
{
var new_delegates = new XmlSpecReader().ReadDelegates(add_node);
Utilities.Merge(delegates, new_delegates);
}
}
private void ProcessDeleteOverrides(DelegateCollection delegates, XPathNavigator nav)
void ProcessDeleteOverrides(DelegateCollection delegates, XPathNavigator nav)
{
var del = nav.SelectSingleNode("/signatures/delete");
if (del != null)