Refactor base types initialization to be done during API processing

This commit is contained in:
Wojtek Figat
2021-05-27 23:34:55 +02:00
parent 2a6f1df76e
commit b3d9ec687d
12 changed files with 185 additions and 210 deletions

View File

@@ -26,14 +26,14 @@ namespace Flax.Build.Bindings
{
base.Init(buildData);
if (ForceNoPod || (InterfaceNames != null && InterfaceNames.Count != 0))
if (ForceNoPod || (Interfaces != null && Interfaces.Count != 0))
{
_isPod = false;
return;
}
// Structure is POD (plain old data) only if all of it's fields are (and has no base type ro base type is also POD)
_isPod = BaseType == null || (BindingsGenerator.FindApiTypeInfo(buildData, BaseType, Parent)?.IsPod ?? false);
_isPod = BaseType == null || (BaseType?.IsPod ?? false);
for (int i = 0; _isPod && i < Fields.Count; i++)
{
var field = Fields[i];
@@ -42,6 +42,29 @@ namespace Flax.Build.Bindings
_isPod = false;
}
}
foreach (var fieldInfo in Fields)
{
if (fieldInfo.Type.IsBitField)
throw new NotImplementedException($"TODO: support bit-fields in structure fields (found field {fieldInfo} in structure {Name})");
// Pointers are fine
if (fieldInfo.Type.IsPtr)
continue;
// In-build types
if (BindingsGenerator.CSharpNativeToManagedBasicTypes.ContainsKey(fieldInfo.Type.Type))
continue;
if (BindingsGenerator.CSharpNativeToManagedDefault.ContainsKey(fieldInfo.Type.Type))
continue;
// Find API type info for this field type
var apiType = BindingsGenerator.FindApiTypeInfo(buildData, fieldInfo.Type, this);
if (apiType != null)
continue;
throw new Exception($"Unknown field type '{fieldInfo.Type} {fieldInfo.Name}' in structure '{Name}'.");
}
}
public override void Write(BinaryWriter writer)