Skip to content

Commit

Permalink
Modernize language parser
Browse files Browse the repository at this point in the history
  • Loading branch information
xPaw committed Nov 16, 2023
1 parent c919ff6 commit ae8eac7
Show file tree
Hide file tree
Showing 7 changed files with 287 additions and 287 deletions.
4 changes: 4 additions & 0 deletions Resources/SteamLanguageParser/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
root = true

[*.cs]
indent_style = space
40 changes: 28 additions & 12 deletions Resources/SteamLanguageParser/CodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public TypeInfo(int size)
}
}

private static string defaultType = "uint";
private static Dictionary<String, TypeInfo> weakTypeMap = new Dictionary<String, TypeInfo>
private static readonly string defaultType = "uint";
private static readonly Dictionary<string, TypeInfo> weakTypeMap = new()
{
{"byte", new TypeInfo(1)},
{"short", new TypeInfo(2)},
Expand All @@ -51,8 +51,10 @@ public TypeInfo(int size)

public static string GetUnsignedType(string type)
{
if (weakTypeMap.ContainsKey(type) && !weakTypeMap[type].Signed)
return weakTypeMap[type].SignedType;
if (weakTypeMap.TryGetValue(type, out var value) && !value.Signed)
{
return value.SignedType;
}

return type;
}
Expand All @@ -64,11 +66,17 @@ public static string GetTypeOfSize(int size, bool unsigned)
if (weakTypeMap[key].Size == size)
{
if (unsigned && weakTypeMap[key].Signed == false)
{
return key;
}
else if (weakTypeMap[key].Signed)
{
return key;
}
else if (!weakTypeMap[key].Signed)
{
return weakTypeMap[key].SignedType;
}
}
}

Expand All @@ -95,9 +103,9 @@ public static int GetTypeSize(PropNode prop)
key = defaultType;
}

if (!String.IsNullOrEmpty(prop.FlagsOpt))
if (!string.IsNullOrEmpty(prop.FlagsOpt))
{
return Int32.Parse(prop.FlagsOpt);
return int.Parse(prop.FlagsOpt);
}

return weakTypeMap[key].Size;
Expand All @@ -110,28 +118,36 @@ public static int GetTypeSize(PropNode prop)
{
EnumNode enode = ssym.Class as EnumNode;

if (enode.Type is WeakSymbol)
return weakTypeMap[((WeakSymbol)enode.Type).Identifier].Size;
if (enode.Type is WeakSymbol weakSymbol)
{
return weakTypeMap[weakSymbol.Identifier].Size;
}
else
{
return weakTypeMap[defaultType].Size;
}
}
}

return 0;
}

public static void EmitCode(Node root, ICodeGen gen, StringBuilder sb, string nspace, bool supportsGC, bool internalFile )
public static void EmitCode(Node root, ICodeGen gen, StringBuilder sb, string nspace, bool supportsGC, bool internalFile)
{
gen.EmitNamespace(sb, false, nspace);

int level = 0;
if (gen.SupportsNamespace())
{
level = 1;
}

if ( internalFile )
gen.EmitSerialBase( sb, level, supportsGC );
if (internalFile)
{
gen.EmitSerialBase(sb, level, supportsGC);
}

foreach (Node n in root.childNodes)
foreach (Node n in root.ChildNodes)
{
gen.EmitNode(n, sb, level);
}
Expand Down
Loading

0 comments on commit ae8eac7

Please sign in to comment.