Added Type stubbing
This commit is contained in:
@@ -23,6 +23,7 @@ namespace CodeGenerator {
|
||||
private const string OutPath = @"Blendfile\DNA";
|
||||
private const string Namespace = "BlendFile.DNA";
|
||||
private static readonly string[] AdaptedTypes = new[] { "uchar" };
|
||||
private static HashSet<string> customTypes;
|
||||
|
||||
public static void Log(string message) {
|
||||
sb.AppendLine(message);
|
||||
@@ -56,11 +57,17 @@ namespace CodeGenerator {
|
||||
|
||||
private static CodeNamespace GenerateTypes() {
|
||||
CodeNamespace ns = new CodeNamespace(Namespace);
|
||||
|
||||
customTypes = new();
|
||||
|
||||
foreach (var type in blendfile.SdnaStructs) {
|
||||
Log($"Generating struct {type.Type}");
|
||||
bool referenceSelf = false;
|
||||
bool referencePointer = false;
|
||||
|
||||
//Add the type to the custom types list
|
||||
customTypes.Add(type.Type);
|
||||
|
||||
//Create a new type declaration
|
||||
var ctd = new CodeTypeDeclaration(type.Type);
|
||||
|
||||
@@ -115,7 +122,10 @@ namespace CodeGenerator {
|
||||
CodeMemberField cmf;
|
||||
//Check if the type is a built-in type or a custom type
|
||||
if (t != null) cmf = new(t, field.Name.ParseFName()); //Built-in type
|
||||
else cmf = new(new CodeTypeReference(field.Type), field.Name.ParseFName()); //Custom type
|
||||
else {
|
||||
cmf = new(new CodeTypeReference(field.Type), field.Name.ParseFName()); //Custom type
|
||||
customTypes.Add(field.Type);
|
||||
}
|
||||
cmf.Attributes = MemberAttributes.Public;
|
||||
return cmf;
|
||||
}
|
||||
@@ -144,7 +154,10 @@ namespace CodeGenerator {
|
||||
|
||||
//Check if the type is a built-in type or a custom type
|
||||
if (t != null) cmf = new(t, name); //Built-in type
|
||||
else cmf = new(field.Type, name); //Custom type
|
||||
else {
|
||||
cmf = new(field.Type, name); //Custom type
|
||||
customTypes.Add(field.Type);
|
||||
}
|
||||
|
||||
//Set the field attributes
|
||||
cmf.Attributes = MemberAttributes.Public;
|
||||
@@ -211,7 +224,8 @@ namespace CodeGenerator {
|
||||
return cc;
|
||||
}
|
||||
|
||||
private static void SetupCCU(out CodeGeneratorOptions genOpts, out CSharpCodeProvider provider, out CodeCompileUnit ccu) {
|
||||
private static void SetupCCU(out CodeGeneratorOptions genOpts, out CSharpCodeProvider provider,
|
||||
out CodeCompileUnit ccu) {
|
||||
genOpts = new() {
|
||||
BlankLinesBetweenMembers = false,
|
||||
BracingStyle = "Block",
|
||||
@@ -245,6 +259,17 @@ namespace CodeGenerator {
|
||||
provider.GenerateCodeFromCompileUnit(ccu, sw, codeGeneratorOptions);
|
||||
tempNs.Types.Remove(type);
|
||||
}
|
||||
customTypes.ExceptWith(ns.Types.OfType<CodeTypeDeclaration>().Select(t => t.Name));
|
||||
foreach (var type in customTypes) {
|
||||
Log($"Creating empty struct for missing {type}");
|
||||
var ctd = new CodeTypeDeclaration(type) {
|
||||
IsStruct = true,
|
||||
Attributes = MemberAttributes.Public
|
||||
};
|
||||
tempNs.Types.Add(ctd);
|
||||
}
|
||||
using var finalsw = new StreamWriter($"{OutPath}\\_ExtraTypes.cs");
|
||||
provider.GenerateCodeFromCompileUnit(ccu, finalsw, codeGeneratorOptions);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user