From 4166482022a6e2a951ca22ccc1b0e5c005bb481c Mon Sep 17 00:00:00 2001 From: Samuele Lorefice Date: Wed, 26 Feb 2025 16:01:16 +0100 Subject: [PATCH] Fixed naming of variables in the code generator class --- CodeGenerator/Program.cs | 51 ++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/CodeGenerator/Program.cs b/CodeGenerator/Program.cs index b8fa7b5..dc7c32d 100644 --- a/CodeGenerator/Program.cs +++ b/CodeGenerator/Program.cs @@ -16,14 +16,14 @@ namespace CodeGenerator { using CFieldRefExp = CodeFieldReferenceExpression; public static class Program { - private static BlendFile blendfile; - private static readonly StringBuilder sb = new(); + private static BlendFile _blendfile; + private static readonly StringBuilder Sb = new(); private const string OutPath = @"GeneratedOutput"; private const string Namespace = "BlendFile"; - private static HashSet customTypes; + private static HashSet _customTypes; private static void Log(string message) { - sb.AppendLine(message); + Sb.AppendLine(message); Console.WriteLine(message); } @@ -41,38 +41,38 @@ namespace CodeGenerator { OutputCodeFiles(rootNs, false); Log("Finished generating C# code!"); - File.AppendAllText("Log.txt", sb.ToString()); + File.AppendAllText("Log.txt", Sb.ToString()); } private static void ReadBlendFile() { Log("Reading empty.blend file"); - blendfile = BlendFile.FromFile("empty.blend"); + _blendfile = BlendFile.FromFile("empty.blend"); - Log($"Header: Blender v{blendfile.Hdr.Version} {blendfile.Hdr.Endian}\n" + - $"DataBlocks: {blendfile.Blocks.Count}\n" + - $"DNA1: {blendfile.SdnaStructs.Count} structures\n"); + Log($"Header: Blender v{_blendfile.Hdr.Version} {_blendfile.Hdr.Endian}\n" + + $"DataBlocks: {_blendfile.Blocks.Count}\n" + + $"DNA1: {_blendfile.SdnaStructs.Count} structures\n"); } private static CodeNamespace GenerateTypes(out CodeNamespace additionalNs) { CodeNamespace rootNs = new CodeNamespace(Namespace); - rootNs.Types.Add(GenerateDNAFieldAttributeType()); - rootNs.Types.Add(GenerateDNAClassAttributeType()); + rootNs.Types.Add(GenerateDnaFieldAttributeType()); + rootNs.Types.Add(GenerateDnaClassAttributeType()); CodeNamespace ns = new CodeNamespace(Namespace+".DNA"); ns.Imports.Add(new(rootNs.Name)); - customTypes = new(); + _customTypes = new(); - foreach (var type in blendfile.SdnaStructs) { + 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); + _customTypes.Add(type.Type); //Create a new type declaration var ctd = new CodeTypeDeclaration(type.Type); - ctd.CustomAttributes.Add(new CodeAttributeDeclaration("DNAClassAttribute", + ctd.CustomAttributes.Add(new ("DNAClassAttribute", new CodeAttributeArgument(new CodePrimitiveExpression(type.IdxType)), new CodeAttributeArgument(new CodePrimitiveExpression(type.Type)) )); @@ -115,8 +115,7 @@ namespace CodeGenerator { cmf = CreateMemberField(field); } - var size = 0; - var attributes = GenerateDNAFieldAttribute(index, field, field.M_Parent.M_Parent, totalSize, out size); + var attributes = GenerateDnaFieldAttribute(index, field, field.M_Parent.M_Parent, totalSize, out int size); totalSize += size; cmf.CustomAttributes.Add(attributes); ctd.Members.Add(cmf); @@ -137,7 +136,7 @@ namespace CodeGenerator { return ns; } - private static CodeTypeDeclaration GenerateDNAFieldAttributeType() { + private static CodeTypeDeclaration GenerateDnaFieldAttributeType() { var attributeBuilder = AttributeBuilder.Instance; return attributeBuilder.New("DNAFieldAttribute") @@ -153,7 +152,7 @@ namespace CodeGenerator { .Build(); } - private static CodeTypeDeclaration GenerateDNAClassAttributeType() { + private static CodeTypeDeclaration GenerateDnaClassAttributeType() { var attributeBuilder = AttributeBuilder.Instance; return attributeBuilder.New("DNAClassAttribute") @@ -165,7 +164,7 @@ namespace CodeGenerator { .Build(); } - private static CodeAttributeDeclaration GenerateDNAFieldAttribute(int index, BlendFile.DnaField field, + private static CodeAttributeDeclaration GenerateDnaFieldAttribute(int index, BlendFile.DnaField field, BlendFile.Dna1Body body, int offset, out int size) { string t; size = body.Lengths[field.IdxType]; @@ -219,7 +218,7 @@ namespace CodeGenerator { if (t != null) cmf = new(t, field.Name.ParseFName()); //Built-in type else { cmf = new(new CodeTypeReference(field.Type), field.Name.ParseFName()); //Custom type - customTypes.Add(field.Type); + _customTypes.Add(field.Type); } cmf.Attributes = MemberAttributes.Public; return cmf; @@ -240,7 +239,7 @@ namespace CodeGenerator { if (t != null) cmf = new(t, name); //Built-in type else { cmf = new(field.Type, name); //Custom type - customTypes.Add(field.Type); + _customTypes.Add(field.Type); } //Set the field attributes @@ -348,7 +347,7 @@ namespace CodeGenerator { return cc; } - private static void SetupCCU(out CodeGeneratorOptions genOpts, out CSharpCodeProvider provider, + private static void SetupCcu(out CodeGeneratorOptions genOpts, out CSharpCodeProvider provider, out CodeCompileUnit ccu) { genOpts = new() { BlankLinesBetweenMembers = false, @@ -373,7 +372,7 @@ namespace CodeGenerator { private static void OutputCodeFiles(CodeNamespace ns, bool outputExtraTypes = true) { string rootPath = Path.GetDirectoryName(GetOutputPath(ns, "")); if (!Path.Exists(rootPath)) Directory.CreateDirectory(rootPath!); - SetupCCU(out var codeGeneratorOptions, out var provider, out var ccu); + SetupCcu(out var codeGeneratorOptions, out var provider, out var ccu); CodeNamespace tempNs = new CodeNamespace(ns.Name); tempNs.Imports.AddRange(ns.Imports.Cast().ToArray()); ccu.Namespaces.Add(tempNs); @@ -386,8 +385,8 @@ namespace CodeGenerator { } if (!outputExtraTypes) return; - customTypes.ExceptWith(ns.Types.OfType().Select(t => t.Name)); - foreach (var type in customTypes) { + _customTypes.ExceptWith(ns.Types.OfType().Select(t => t.Name)); + foreach (var type in _customTypes) { Log($"Creating empty struct for missing {type}"); var ctd = new CodeTypeDeclaration(type) { IsStruct = true,