Fix substitution possible issues also improve code readability

This commit is contained in:
Thog 2018-05-12 11:09:39 +02:00
commit f6c53bda52
No known key found for this signature in database
GPG key ID: 0CD291558FAFDBC6

View file

@ -22,13 +22,13 @@ namespace Ryujinx.Core.OsHle.Diagnostics
{ "j", "unsigned int" }, { "j", "unsigned int" },
{ "l", "long" }, { "l", "long" },
{ "m", "unsigned long" }, { "m", "unsigned long" },
{ "x", "long long, __int64" }, { "x", "long long" },
{ "y", "unsigned long long, __int64" }, { "y", "unsigned long long" },
{ "n", "__int128" }, { "n", "__int128" },
{ "o", "unsigned __int128" }, { "o", "unsigned __int128" },
{ "f", "float" }, { "f", "float" },
{ "d", "double" }, { "d", "double" },
{ "e", "long double, __float80" }, { "e", "long double" },
{ "g", "__float128" }, { "g", "__float128" },
{ "z", "..." }, { "z", "..." },
{ "Dd", "__iec559_double" }, { "Dd", "__iec559_double" },
@ -75,15 +75,15 @@ namespace Ryujinx.Core.OsHle.Diagnostics
if (compressionData.Count == 0 || !compression.StartsWith("S")) if (compressionData.Count == 0 || !compression.StartsWith("S"))
return null; return null;
if (compression.Length > 2 && BuiltinTypes.TryGetValue(compression.Substring(0, 2), out string temp)) if (compression.Length >= 2 && SubstitutionExtra.TryGetValue(compression.Substring(0, 2), out string substitutionValue))
{ {
pos = 2; pos = 1;
res = temp; res = substitutionValue;
compression = compression.Substring(2); compression = compression.Substring(2);
} }
else if (compression.StartsWith("St")) else if (compression.StartsWith("St"))
{ {
pos = 2; pos = 1;
canHaveUnqualifiedName = true; canHaveUnqualifiedName = true;
res = "std"; res = "std";
compression = compression.Substring(2); compression = compression.Substring(2);
@ -117,11 +117,10 @@ namespace Ryujinx.Core.OsHle.Diagnostics
{ {
if (canHaveUnqualifiedName) if (canHaveUnqualifiedName)
{ {
int tempPos = -1; List<string> type = ReadName(compression, compressionData, out int endOfNameType);
List<string> type = ReadName(compression, compressionData, out tempPos); if (endOfNameType != -1 && type != null)
if (tempPos != -1 && type != null)
{ {
pos += tempPos; pos += endOfNameType;
res = res + "::" + type[type.Count - 1]; res = res + "::" + type[type.Count - 1];
} }
} }
@ -132,7 +131,7 @@ namespace Ryujinx.Core.OsHle.Diagnostics
private static List<string> ReadName(string mangled, List<string> compressionData, out int pos) private static List<string> ReadName(string mangled, List<string> compressionData, out int pos)
{ {
List<string> res = new List<string>(); List<string> res = new List<string>();
string charCountTemp = null; string charCountString = null;
int charCount = 0; int charCount = 0;
int i; int i;
@ -140,7 +139,7 @@ namespace Ryujinx.Core.OsHle.Diagnostics
for (i = 0; i < mangled.Length; i++) for (i = 0; i < mangled.Length; i++)
{ {
char chr = mangled[i]; char chr = mangled[i];
if (charCountTemp == null) if (charCountString == null)
{ {
if (ReadCVQualifiers(chr) != null) if (ReadCVQualifiers(chr) != null)
{ {
@ -158,7 +157,7 @@ namespace Ryujinx.Core.OsHle.Diagnostics
else else
res.Add(res[res.Count - 1] + "::" + data); res.Add(res[res.Count - 1] + "::" + data);
i += pos; i += pos;
if (mangled[i] == 'E') if (i < mangled.Length && mangled[i] == 'E')
{ {
break; break;
} }
@ -171,11 +170,11 @@ namespace Ryujinx.Core.OsHle.Diagnostics
} }
if (Char.IsDigit(chr)) if (Char.IsDigit(chr))
{ {
charCountTemp += chr; charCountString += chr;
} }
else else
{ {
if (!int.TryParse(charCountTemp, out charCount)) if (!int.TryParse(charCountString, out charCount))
{ {
return null; return null;
} }
@ -186,7 +185,7 @@ namespace Ryujinx.Core.OsHle.Diagnostics
res.Add(res[res.Count - 1] + "::" + demangledPart); res.Add(res[res.Count - 1] + "::" + demangledPart);
i = i + charCount - 1; i = i + charCount - 1;
charCount = 0; charCount = 0;
charCountTemp = null; charCountString = null;
} }
} }
if (res.Count == 0) if (res.Count == 0)
@ -200,19 +199,20 @@ namespace Ryujinx.Core.OsHle.Diagnostics
private static string ReadBuiltinType(string mangledType, out int pos) private static string ReadBuiltinType(string mangledType, out int pos)
{ {
string res = null; string res = null;
string temp; string possibleBuiltinType;
pos = -1; pos = -1;
temp = mangledType[0].ToString(); possibleBuiltinType = mangledType[0].ToString();
if (!BuiltinTypes.TryGetValue(temp, out res)) if (!BuiltinTypes.TryGetValue(possibleBuiltinType, out res))
{ {
if (mangledType.Length >= 2) if (mangledType.Length >= 2)
{ {
temp = mangledType.Substring(0, 2); // Try to match the first 2 chars if the first call failed
BuiltinTypes.TryGetValue(temp, out res); possibleBuiltinType = mangledType.Substring(0, 2);
BuiltinTypes.TryGetValue(possibleBuiltinType, out res);
} }
} }
if (res != null) if (res != null)
pos = temp.Length; pos = possibleBuiltinType.Length;
return res; return res;
} }
@ -257,38 +257,38 @@ namespace Ryujinx.Core.OsHle.Diagnostics
int i = 0; int i = 0;
pos = -1; pos = -1;
string temp = null; string typeBuffer = null;
string temp2 = null; string parsedTypePart = null;
for (i = 0; i < mangledParams.Length; i++) for (i = 0; i < mangledParams.Length; i++)
{ {
char chr = mangledParams[i]; char chr = mangledParams[i];
string part = mangledParams.Substring(i); string part = mangledParams.Substring(i);
// Try to read qualifiers // Try to read qualifiers
temp2 = ReadCVQualifiers(chr); parsedTypePart = ReadCVQualifiers(chr);
if (temp2 != null) if (parsedTypePart != null)
{ {
temp = temp2 + " " + temp; typeBuffer = parsedTypePart + " " + typeBuffer;
compressionData.Add(temp); compressionData.Add(typeBuffer);
// need more data // need more data
continue; continue;
} }
temp2 = ReadRefQualifiers(chr); parsedTypePart = ReadRefQualifiers(chr);
if (temp2 != null) if (parsedTypePart != null)
{ {
temp = temp + temp2; typeBuffer = typeBuffer + parsedTypePart;
compressionData.Add(temp); compressionData.Add(typeBuffer);
// need more data // need more data
continue; continue;
} }
temp2 = ReadSpecialQualifiers(chr); parsedTypePart = ReadSpecialQualifiers(chr);
if (temp2 != null) if (parsedTypePart != null)
{ {
temp = temp + temp2; typeBuffer = typeBuffer + parsedTypePart;
// need more data // need more data
continue; continue;
@ -298,14 +298,14 @@ namespace Ryujinx.Core.OsHle.Diagnostics
if (part.StartsWith("S")) if (part.StartsWith("S"))
{ {
temp2 = GetCompressedValue(part, compressionData, out pos); parsedTypePart = GetCompressedValue(part, compressionData, out pos);
if (pos != -1 && temp2 != null) if (pos != -1 && parsedTypePart != null)
{ {
i += pos; i += pos;
temp = temp2 + temp; typeBuffer = parsedTypePart + typeBuffer;
res.Add(temp); res.Add(typeBuffer);
compressionData.Add(temp); compressionData.Add(typeBuffer);
temp = null; typeBuffer = null;
continue; continue;
} }
pos = -1; pos = -1;
@ -318,27 +318,27 @@ namespace Ryujinx.Core.OsHle.Diagnostics
if (pos != -1 && name != null) if (pos != -1 && name != null)
{ {
i += pos + 1; i += pos + 1;
temp = name[name.Count - 1] + " " + temp; typeBuffer = name[name.Count - 1] + " " + typeBuffer;
res.Add(temp); res.Add(typeBuffer);
compressionData.Add(temp); compressionData.Add(typeBuffer);
temp = null; typeBuffer = null;
continue; continue;
} }
} }
// Try builting // Try builting
temp2 = ReadBuiltinType(part, out pos); parsedTypePart = ReadBuiltinType(part, out pos);
if (pos == -1) if (pos == -1)
{ {
return null; return null;
} }
if (temp != null) if (typeBuffer != null)
temp = temp2 + " " + temp; typeBuffer = parsedTypePart + " " + typeBuffer;
else else
temp = temp2; typeBuffer = parsedTypePart;
res.Add(temp); res.Add(typeBuffer);
compressionData.Add(temp); compressionData.Add(typeBuffer);
temp = null; typeBuffer = null;
i = i + pos -1; i = i + pos -1;
} }
pos = i; pos = i;