in SharpGen.Platform/CppParser.cs [478:548]
private CppInterface ParseInterface(XElement xElement)
{
// If element is already transformed, return it
var cppInterface = xElement.Annotation<CppInterface>();
if (cppInterface != null)
return cppInterface;
// Else, create a new CppInterface
cppInterface = new CppInterface(xElement.AttributeValue("name"));
xElement.AddAnnotation(cppInterface);
// Enter Interface description
Logger.PushContext("Interface:[{0}]", cppInterface.Name);
// Calculate offset method using inheritance
var offsetMethod = 0;
var basesValue = xElement.AttributeValue("bases");
var bases = basesValue?.Split(' ') ?? Enumerable.Empty<string>();
foreach (var xElementBaseId in bases)
{
if (string.IsNullOrEmpty(xElementBaseId))
continue;
var xElementBase = _mapIdToXElement[xElementBaseId];
CppInterface cppInterfaceBase = null;
Logger.RunInContext("Base", () => { cppInterfaceBase = ParseInterface(xElementBase); });
if (string.IsNullOrEmpty(cppInterface.Base) && IsTypeBinded(xElementBase))
cppInterface.Base = cppInterfaceBase.Name;
offsetMethod += cppInterfaceBase.TotalMethodCount;
}
// Parse annotations
ParseAnnotations(xElement, cppInterface);
int offsetMethodBase = offsetMethod;
var methods = new List<CppMethod>();
// Parse methods
foreach (var method in xElement.Elements())
{
// Parse method with pure virtual (=0) and that do not override any other methods
if (method.Name.LocalName == "Method" && !string.IsNullOrWhiteSpace(method.AttributeValue("pure_virtual"))
&& string.IsNullOrWhiteSpace(method.AttributeValue("overrides")))
{
CppMethod cppMethod = new(method.AttributeValue("name"));
ParseCallable(cppMethod, method);
methods.Add(cppMethod);
cppMethod.Offset = offsetMethod++;
}
}
SetMethodsWindowsOffset(methods, offsetMethodBase);
// Add the methods to the interface with the correct offsets
foreach (var cppMethod in methods)
{
cppInterface.Add(cppMethod);
}
cppInterface.TotalMethodCount = offsetMethod;
// Leave Interface
Logger.PopContext();
return cppInterface;
}