refactored GetArrayDimensions method, ParseFSize now returns null if not found
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace CodeGenerator {
|
||||
@@ -28,7 +29,7 @@ namespace CodeGenerator {
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static int ParseFSize(this string str) {
|
||||
public static int? ParseFSize(this string str) {
|
||||
return str switch {
|
||||
"char" => sizeof(sbyte),
|
||||
"short" => sizeof(short),
|
||||
@@ -40,8 +41,26 @@ namespace CodeGenerator {
|
||||
"int64_t" => sizeof(long),
|
||||
"int8_t" => sizeof(sbyte),
|
||||
"uint64_t" => sizeof(ulong),
|
||||
_ => throw new("Unknown type")
|
||||
_ => null
|
||||
};
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static List<int> GetArrayDimensions(this string name) {
|
||||
var dimensions = new List<int>();
|
||||
int startIndex = 0;
|
||||
// Get all array dimensions
|
||||
while ((startIndex = name.IndexOf('[', startIndex)) != -1) {
|
||||
int endIndex = name.IndexOf(']', startIndex);
|
||||
string sizeStr = name.Substring(startIndex + 1, endIndex - startIndex - 1);
|
||||
if (int.TryParse(sizeStr, out int size)) {
|
||||
dimensions.Add(size);
|
||||
}
|
||||
startIndex = endIndex + 1;
|
||||
}
|
||||
|
||||
return dimensions;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user