Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option for handling internals #364

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
3 changes: 2 additions & 1 deletion src/CodeGenerator/CodeGenerator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
</ItemGroup>
</Project>
50 changes: 34 additions & 16 deletions src/CodeGenerator/ImguiDefinitions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ static int GetInt(JToken token, string key)
if (v == null) return 0;
return v.ToObject<int>();
}
public void LoadFrom(string directory)
public void LoadFrom(string directory, bool useInternals = false)
{

JObject typesJson;
Expand Down Expand Up @@ -66,23 +66,27 @@ public void LoadFrom(string directory)
{
JProperty jp = (JProperty)jt;
string name = jp.Name;
if (typeLocations?[jp.Name]?.Value<string>().Contains("internal") ?? false) {
bool isInternal = typeLocations?[jp.Name]?.Value<string>().Contains("internal") ?? false;

if (!useInternals && isInternal)
return null;
}

EnumMember[] elements = jp.Values().Select(v =>
{
return new EnumMember(v["name"].ToString(), v["calc_value"].ToString());
}).ToArray();
return new EnumDefinition(name, elements);
return new EnumDefinition(name, elements, isInternal);
}).Where(x => x != null).ToArray();

Types = typesJson["structs"].Select(jt =>
{
JProperty jp = (JProperty)jt;
string name = jp.Name;
if (typeLocations?[jp.Name]?.Value<string>().Contains("internal") ?? false) {
bool isInternal = typeLocations?[jp.Name]?.Value<string>().Contains("internal") ?? false;

if (!useInternals && isInternal)
return null;
}

TypeReference[] fields = jp.Values().Select(v =>
{
if (v["type"].ToString().Contains("static")) { return null; }
Expand All @@ -95,7 +99,7 @@ public void LoadFrom(string directory)
v["template_type"]?.ToString(),
Enums);
}).Where(tr => tr != null).ToArray();
return new TypeDefinition(name, fields);
return new TypeDefinition(name, fields, isInternal);
}).Where(x => x != null).ToArray();

Functions = functionsJson.Children().Select(jt =>
Expand All @@ -112,16 +116,22 @@ public void LoadFrom(string directory)
{
friendlyName = "Destroy";
}
//skip internal functions
// Hunt for internal and react
bool isInternal = val["location"]?.ToString().Contains("internal") ?? false;
var typename = val["stname"]?.ToString();
if (!string.IsNullOrEmpty(typename))
{
if (!Types.Any(x => x.Name == val["stname"]?.ToString())) {
TypeDefinition foundType = Types.FirstOrDefault(x => x.Name == val["stname"]?.ToString());

if (foundType != null)
isInternal = foundType.IsInternal;
else
return null;
}
}
if (friendlyName == null) { return null; }
if (val["location"]?.ToString().Contains("internal") ?? false) return null;

if (!useInternals && isInternal)
return null;

string exportedName = ov_cimguiname;
if (exportedName == null)
Expand Down Expand Up @@ -185,7 +195,8 @@ public void LoadFrom(string directory)
structName,
comment,
isConstructor,
isDestructor);
isDestructor,
isInternal);
}).Where(od => od != null).ToArray();
if(overloads.Length == 0) return null;
return new FunctionDefinition(name, overloads, Enums);
Expand Down Expand Up @@ -232,8 +243,9 @@ class EnumDefinition
public string[] Names { get; }
public string[] FriendlyNames { get; }
public EnumMember[] Members { get; }
public bool IsInternal { get; }

public EnumDefinition(string name, EnumMember[] elements)
public EnumDefinition(string name, EnumMember[] elements, bool isInternal)
{
if (TypeInfo.AlternateEnumPrefixes.TryGetValue(name, out string altName))
{
Expand Down Expand Up @@ -265,6 +277,7 @@ public EnumDefinition(string name, EnumMember[] elements)
{
_sanitizedNames.Add(el.Name, SanitizeMemberName(el.Name));
}
IsInternal = isInternal;
}

public string SanitizeNames(string text)
Expand Down Expand Up @@ -336,11 +349,13 @@ class TypeDefinition
{
public string Name { get; }
public TypeReference[] Fields { get; }
public bool IsInternal { get; }

public TypeDefinition(string name, TypeReference[] fields)
public TypeDefinition(string name, TypeReference[] fields, bool isInternal)
{
Name = name;
Fields = fields;
IsInternal = isInternal;
}
}

Expand Down Expand Up @@ -530,6 +545,7 @@ class OverloadDefinition
public string Comment { get; }
public bool IsConstructor { get; }
public bool IsDestructor { get; }
public bool IsInternal { get; }

public OverloadDefinition(
string exportedName,
Expand All @@ -540,7 +556,8 @@ public OverloadDefinition(
string structName,
string comment,
bool isConstructor,
bool isDestructor)
bool isDestructor,
bool isInternal)
{
ExportedName = exportedName;
FriendlyName = friendlyName;
Expand All @@ -552,11 +569,12 @@ public OverloadDefinition(
Comment = comment;
IsConstructor = isConstructor;
IsDestructor = isDestructor;
IsInternal = isInternal;
}

public OverloadDefinition WithParameters(TypeReference[] parameters)
{
return new OverloadDefinition(ExportedName, FriendlyName, parameters, DefaultValues, ReturnType, StructName, Comment, IsConstructor, IsDestructor);
return new OverloadDefinition(ExportedName, FriendlyName, parameters, DefaultValues, ReturnType, StructName, Comment, IsConstructor, IsDestructor, IsInternal);
}
}
}
Loading
Loading