Code Reformat
This commit is contained in:
@@ -39,7 +39,9 @@ namespace CodeGenerator {
|
|||||||
|
|
||||||
private static void LogNow(string message, LogType type = LogType.Info) {
|
private static void LogNow(string message, LogType type = LogType.Info) {
|
||||||
string msg = $"{DateTime.Now:yy-MM-dd HH:mm:ss}|{type.ToString()}|{message}";
|
string msg = $"{DateTime.Now:yy-MM-dd HH:mm:ss}|{type.ToString()}|{message}";
|
||||||
lock (Sb){ Sb.AppendLine(msg); }
|
lock (Sb) {
|
||||||
|
Sb.AppendLine(msg);
|
||||||
|
}
|
||||||
Console.WriteLine(msg);
|
Console.WriteLine(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,7 +56,8 @@ namespace CodeGenerator {
|
|||||||
long start = 0;
|
long start = 0;
|
||||||
|
|
||||||
bool loggerExit = false;
|
bool loggerExit = false;
|
||||||
Thread logger = new(() => {
|
Thread logger = new(() =>
|
||||||
|
{
|
||||||
start = sw.ElapsedTicks;
|
start = sw.ElapsedTicks;
|
||||||
LogNow($"Logger started! In {sw.ElapsedMilliseconds}ms");
|
LogNow($"Logger started! In {sw.ElapsedMilliseconds}ms");
|
||||||
// ReSharper disable once AccessToModifiedClosure LoopVariableIsNeverChangedInsideLoop
|
// ReSharper disable once AccessToModifiedClosure LoopVariableIsNeverChangedInsideLoop
|
||||||
@@ -99,7 +102,8 @@ namespace CodeGenerator {
|
|||||||
Total: {(decimal)(initTime + readTime + genTime + writeTime) / TimeSpan.TicksPerMillisecond,10:N4} ms
|
Total: {(decimal)(initTime + readTime + genTime + writeTime) / TimeSpan.TicksPerMillisecond,10:N4} ms
|
||||||
""");
|
""");
|
||||||
loggerExit = true;
|
loggerExit = true;
|
||||||
while(logger.IsAlive) { }
|
while (logger.IsAlive) {
|
||||||
|
}
|
||||||
Thread.Sleep(1000);
|
Thread.Sleep(1000);
|
||||||
lock (Sb) {
|
lock (Sb) {
|
||||||
File.AppendAllText("Log.txt", Sb.ToString());
|
File.AppendAllText("Log.txt", Sb.ToString());
|
||||||
@@ -115,8 +119,7 @@ namespace CodeGenerator {
|
|||||||
$"DNA1: {_blendfile.SdnaStructs.Count} structures\n");
|
$"DNA1: {_blendfile.SdnaStructs.Count} structures\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int AddNormalField(DnaField field, ref CodeTypeDeclaration ctd, int index, int totalSize)
|
private static int AddNormalField(DnaField field, ref CodeTypeDeclaration ctd, int index, int totalSize) {
|
||||||
{
|
|
||||||
CodeMemberField cmf;
|
CodeMemberField cmf;
|
||||||
string name = field.Name;
|
string name = field.Name;
|
||||||
if (name.Contains("()")) return 0;
|
if (name.Contains("()")) return 0;
|
||||||
@@ -184,8 +187,7 @@ namespace CodeGenerator {
|
|||||||
if (IsClass(type)) {
|
if (IsClass(type)) {
|
||||||
Log($"Marking {type.Type} as class");
|
Log($"Marking {type.Type} as class");
|
||||||
ctd.IsClass = true;
|
ctd.IsClass = true;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
Log($"Marking {type.Type} as struct");
|
Log($"Marking {type.Type} as struct");
|
||||||
ctd.IsStruct = !ctd.IsClass;
|
ctd.IsStruct = !ctd.IsClass;
|
||||||
}
|
}
|
||||||
@@ -227,14 +229,17 @@ namespace CodeGenerator {
|
|||||||
//Retrieve the index of the list length field
|
//Retrieve the index of the list length field
|
||||||
int sizeIndex = type.Fields.IndexOf(listLength);
|
int sizeIndex = type.Fields.IndexOf(listLength);
|
||||||
|
|
||||||
totalSize += AddListField(ref ctd, totalSize, index, listLenghtOffset, listPointer, listLength, sizeIndex);
|
totalSize += AddListField(ref ctd, totalSize, index, listLenghtOffset, listPointer, listLength,
|
||||||
|
sizeIndex);
|
||||||
} else if (listFields.Select(f => f.Item2).Contains(field)) {
|
} else if (listFields.Select(f => f.Item2).Contains(field)) {
|
||||||
//update the size of the list attribute
|
//update the size of the list attribute
|
||||||
string fName = field.Name.ParseFName();
|
string fName = field.Name.ParseFName();
|
||||||
//retrieve the name of the list pointer
|
//retrieve the name of the list pointer
|
||||||
string listPointerName = listFields.First(f => f.Item2.Name.ParseFName() == fName).Item1.Name.ParseFName();
|
string listPointerName =
|
||||||
|
listFields.First(f => f.Item2.Name.ParseFName() == fName).Item1.Name.ParseFName();
|
||||||
//Try seeing if the list attribute is already present
|
//Try seeing if the list attribute is already present
|
||||||
var x = ctd.Members.OfType<CodeMemberField>().FirstOrDefault(member => member.Name.ParseFName() == listPointerName);
|
var x = ctd.Members.OfType<CodeMemberField>()
|
||||||
|
.FirstOrDefault(member => member.Name.ParseFName() == listPointerName);
|
||||||
|
|
||||||
if (x != null) //Update the existing list attribute
|
if (x != null) //Update the existing list attribute
|
||||||
x.CustomAttributes[0].Arguments[9] = new(new CodePrimitiveExpression(totalSize));
|
x.CustomAttributes[0].Arguments[9] = new(new CodePrimitiveExpression(totalSize));
|
||||||
@@ -299,7 +304,6 @@ namespace CodeGenerator {
|
|||||||
foreach (var field in dnaFields) {
|
foreach (var field in dnaFields) {
|
||||||
if (ListMarkerStr.Any(s => field.Name.Contains(s)) &&
|
if (ListMarkerStr.Any(s => field.Name.Contains(s)) &&
|
||||||
!ListLenghtStr.Any(s2 => field.Name.Contains(s2))) {
|
!ListLenghtStr.Any(s2 => field.Name.Contains(s2))) {
|
||||||
|
|
||||||
Log($"Found list field {field.Name}");
|
Log($"Found list field {field.Name}");
|
||||||
Log($"Searching for list length field");
|
Log($"Searching for list length field");
|
||||||
|
|
||||||
@@ -408,8 +412,7 @@ namespace CodeGenerator {
|
|||||||
size = body.Lengths[field.IdxType];
|
size = body.Lengths[field.IdxType];
|
||||||
string t = field.Type;
|
string t = field.Type;
|
||||||
|
|
||||||
if (field.Name.StartsWith('*'))
|
if (field.Name.StartsWith('*')) {
|
||||||
{
|
|
||||||
size = 8;
|
size = 8;
|
||||||
isPointer = true;
|
isPointer = true;
|
||||||
}
|
}
|
||||||
@@ -466,7 +469,6 @@ namespace CodeGenerator {
|
|||||||
|
|
||||||
private static CodeAttributeDeclaration GenerateDnaListAttribute(int listIndex, DnaField listField, int lenghtIndex,
|
private static CodeAttributeDeclaration GenerateDnaListAttribute(int listIndex, DnaField listField, int lenghtIndex,
|
||||||
DnaField lenghtField, int ptrOffset, int countOffset, out int size) {
|
DnaField lenghtField, int ptrOffset, int countOffset, out int size) {
|
||||||
|
|
||||||
size = 8;
|
size = 8;
|
||||||
var cad = new CodeAttributeDeclaration("DNAListAttribute");
|
var cad = new CodeAttributeDeclaration("DNAListAttribute");
|
||||||
cad.Arguments.AddRange(new CodeAttributeArgumentCollection() {
|
cad.Arguments.AddRange(new CodeAttributeArgumentCollection() {
|
||||||
@@ -532,10 +534,12 @@ namespace CodeGenerator {
|
|||||||
CodeTypeReference ctr = new(typeof(List<>));
|
CodeTypeReference ctr = new(typeof(List<>));
|
||||||
|
|
||||||
//Check if the type is a built-in type or a custom type
|
//Check if the type is a built-in type or a custom type
|
||||||
if (t != null) { //Built-in type
|
if (t != null) {
|
||||||
|
//Built-in type
|
||||||
ctr.TypeArguments.Add(t);
|
ctr.TypeArguments.Add(t);
|
||||||
cmf = new(ctr, field.Name.ParseFName());
|
cmf = new(ctr, field.Name.ParseFName());
|
||||||
} else { //Custom type
|
} else {
|
||||||
|
//Custom type
|
||||||
ctr.TypeArguments.Add(new CodeTypeReference(field.Type));
|
ctr.TypeArguments.Add(new CodeTypeReference(field.Type));
|
||||||
cmf = new(ctr, field.Name.ParseFName());
|
cmf = new(ctr, field.Name.ParseFName());
|
||||||
}
|
}
|
||||||
@@ -543,8 +547,7 @@ namespace CodeGenerator {
|
|||||||
return cmf;
|
return cmf;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<int> GetArrayDimensions(string name)
|
private static List<int> GetArrayDimensions(string name) {
|
||||||
{
|
|
||||||
var dimensions = new List<int>();
|
var dimensions = new List<int>();
|
||||||
int startIndex = 0;
|
int startIndex = 0;
|
||||||
// Get all array dimensions
|
// Get all array dimensions
|
||||||
|
|||||||
Reference in New Issue
Block a user