mirror of
https://github.com/Ryujinx/Opentk.git
synced 2024-12-23 23:35:28 +00:00
Added "reuse" directive for enums
Sometimes an enum may reuse the tokens of another enum verbatim (possibly adding a few extra tokens.) The reuse directive simplifies the handling of this case: <enum name="Foo"> <reuse enum="Bar" /> </enum>
This commit is contained in:
parent
20e70062f8
commit
6921509680
|
@ -333,6 +333,9 @@ namespace Bind
|
||||||
|
|
||||||
if (nav != null)
|
if (nav != null)
|
||||||
{
|
{
|
||||||
|
var reuse_list = new List<KeyValuePair<Enum, string>>();
|
||||||
|
|
||||||
|
// First pass: collect all available tokens and enums
|
||||||
foreach (XPathNavigator node in nav.SelectChildren("enum", String.Empty))
|
foreach (XPathNavigator node in nav.SelectChildren("enum", String.Empty))
|
||||||
{
|
{
|
||||||
Enum e = new Enum()
|
Enum e = new Enum()
|
||||||
|
@ -344,7 +347,6 @@ namespace Bind
|
||||||
if (String.IsNullOrEmpty(e.Name))
|
if (String.IsNullOrEmpty(e.Name))
|
||||||
throw new InvalidOperationException(String.Format("Empty name for enum element {0}", node.ToString()));
|
throw new InvalidOperationException(String.Format("Empty name for enum element {0}", node.ToString()));
|
||||||
|
|
||||||
|
|
||||||
// It seems that all flag collections contain "Mask" in their names.
|
// It seems that all flag collections contain "Mask" in their names.
|
||||||
// This looks like a heuristic, but it holds 100% in practice
|
// This looks like a heuristic, but it holds 100% in practice
|
||||||
// (checked all enums to make sure).
|
// (checked all enums to make sure).
|
||||||
|
@ -372,9 +374,17 @@ namespace Bind
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case "reuse":
|
||||||
|
var reuse_enum = param.GetAttribute("enum", String.Empty).Trim();
|
||||||
|
reuse_list.Add(new KeyValuePair<Enum, string>(e, reuse_enum));
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new NotSupportedException();
|
throw new NotSupportedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (c != null)
|
||||||
|
{
|
||||||
Utilities.Merge(all, c);
|
Utilities.Merge(all, c);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -390,7 +400,9 @@ namespace Bind
|
||||||
e.ConstantCollection[c.Name] = c;
|
e.ConstantCollection[c.Name] = c;
|
||||||
}
|
}
|
||||||
else if (existing.Reference == null && c.Reference != null)
|
else if (existing.Reference == null && c.Reference != null)
|
||||||
{ } // Keep existing
|
{
|
||||||
|
// Keep existing
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Console.WriteLine("[Warning] Conflicting token {0}.{1} with value {2} != {3}",
|
Console.WriteLine("[Warning] Conflicting token {0}.{1} with value {2} != {3}",
|
||||||
|
@ -403,9 +415,41 @@ namespace Bind
|
||||||
Console.WriteLine("[Warning] Failed to add constant {0} to enum {1}: {2}", c.Name, e.Name, ex.Message);
|
Console.WriteLine("[Warning] Failed to add constant {0} to enum {1}: {2}", c.Name, e.Name, ex.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Utilities.Merge(enums, e);
|
Utilities.Merge(enums, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Second pass: resolve "reuse" directives
|
||||||
|
restart:
|
||||||
|
foreach (var pair in reuse_list)
|
||||||
|
{
|
||||||
|
var e = pair.Key;
|
||||||
|
var reuse = pair.Value;
|
||||||
|
var count = e.ConstantCollection.Count;
|
||||||
|
|
||||||
|
if (enums.ContainsKey(reuse))
|
||||||
|
{
|
||||||
|
var reuse_enum = enums[reuse];
|
||||||
|
foreach (var token in reuse_enum.ConstantCollection.Values)
|
||||||
|
{
|
||||||
|
Utilities.Merge(e, token);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine("[Warning] Reuse token not found: {0}", reuse);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count != e.ConstantCollection.Count)
|
||||||
|
{
|
||||||
|
// Restart resolution of reuse directives whenever
|
||||||
|
// we modify an enum. This is the simplest (brute) way
|
||||||
|
// to resolve chains of reuse directives:
|
||||||
|
// e.g. enum A reuses B which reuses C
|
||||||
|
goto restart;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Utilities.Merge(enums, all);
|
Utilities.Merge(enums, all);
|
||||||
|
|
Loading…
Reference in a new issue