General cleanup of the generator code
This commit is contained in:
@@ -16,15 +16,14 @@ namespace CodeGenerator {
|
|||||||
using CThisRefExp = CodeThisReferenceExpression;
|
using CThisRefExp = CodeThisReferenceExpression;
|
||||||
using CFieldRefExp = CodeFieldReferenceExpression;
|
using CFieldRefExp = CodeFieldReferenceExpression;
|
||||||
|
|
||||||
public class Program {
|
public static class Program {
|
||||||
public static BlendFile blendfile;
|
private static BlendFile blendfile;
|
||||||
private static StringBuilder sb = new();
|
private static readonly StringBuilder sb = new();
|
||||||
private const string OutPath = @"GeneratedOutput\";
|
private const string OutPath = @"GeneratedOutput\";
|
||||||
private const string Namespace = "BlendFile";
|
private const string Namespace = "BlendFile";
|
||||||
private static readonly string[] AdaptedTypes = new[] { "uchar" };
|
|
||||||
private static HashSet<string> customTypes;
|
private static HashSet<string> customTypes;
|
||||||
|
|
||||||
public static void Log(string message) {
|
private static void Log(string message) {
|
||||||
sb.AppendLine(message);
|
sb.AppendLine(message);
|
||||||
Console.WriteLine(message);
|
Console.WriteLine(message);
|
||||||
}
|
}
|
||||||
@@ -36,8 +35,7 @@ namespace CodeGenerator {
|
|||||||
Log("Generating C# code...");
|
Log("Generating C# code...");
|
||||||
|
|
||||||
Log("Pass 1: Generating types");
|
Log("Pass 1: Generating types");
|
||||||
CodeNamespace rootNs;
|
CodeNamespace ns = GenerateTypes(out var rootNs);
|
||||||
CodeNamespace ns = GenerateTypes(out rootNs);
|
|
||||||
|
|
||||||
Log("Pass 2: Writing out code");
|
Log("Pass 2: Writing out code");
|
||||||
OutputCodeFiles(ns);
|
OutputCodeFiles(ns);
|
||||||
@@ -369,7 +367,7 @@ namespace CodeGenerator {
|
|||||||
return cmf;
|
return cmf;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CodeExpression GenerateArrayInitExpression(CodeTypeReference type, IEnumerable<int> dimensions) {
|
private static CodeExpression GenerateArrayInitExpression(CodeTypeReference type, IEnumerable<int> dimensions) {
|
||||||
var dimValues = dimensions as int[] ?? dimensions.ToArray();
|
var dimValues = dimensions as int[] ?? dimensions.ToArray();
|
||||||
string dims = string.Concat(dimValues.Take(dimValues.Count() - 1).Select(d => $"{d},"));
|
string dims = string.Concat(dimValues.Take(dimValues.Count() - 1).Select(d => $"{d},"));
|
||||||
dims += dimValues.Last();
|
dims += dimValues.Last();
|
||||||
@@ -377,8 +375,9 @@ namespace CodeGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static CodeTypeConstructor GenerateStaticConstructor(CodeTypeDeclaration ctd) {
|
private static CodeTypeConstructor GenerateStaticConstructor(CodeTypeDeclaration ctd) {
|
||||||
CodeTypeConstructor ctc = new CodeTypeConstructor();
|
CodeTypeConstructor ctc = new CodeTypeConstructor {
|
||||||
ctc.Attributes = MemberAttributes.Static;
|
Attributes = MemberAttributes.Static
|
||||||
|
};
|
||||||
ctc.Statements.AddRange(ctd.Members
|
ctc.Statements.AddRange(ctd.Members
|
||||||
.OfType<CodeMemberField>()
|
.OfType<CodeMemberField>()
|
||||||
.Where(f => f.Type.ArrayRank > 0)
|
.Where(f => f.Type.ArrayRank > 0)
|
||||||
@@ -409,8 +408,9 @@ namespace CodeGenerator {
|
|||||||
.OfType<CodeMemberField>()
|
.OfType<CodeMemberField>()
|
||||||
.Select(f =>
|
.Select(f =>
|
||||||
{
|
{
|
||||||
var cpde = new CParamDeclExp(f.Type, f.Name);
|
var cpde = new CParamDeclExp(f.Type, f.Name) {
|
||||||
cpde.Direction = FieldDirection.In;
|
Direction = FieldDirection.In
|
||||||
|
};
|
||||||
return cpde;
|
return cpde;
|
||||||
}).ToArray());
|
}).ToArray());
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user