Skip to content

Add option for handling internals #364

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

Closed
wants to merge 10 commits into from
3 changes: 2 additions & 1 deletion src/CodeGenerator/CodeGenerator.csproj
Original file line number Diff line number Diff line change
@@ -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
@@ -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;
@@ -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; }
@@ -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 =>
@@ -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)
@@ -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);
@@ -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))
{
@@ -265,6 +277,7 @@ public EnumDefinition(string name, EnumMember[] elements)
{
_sanitizedNames.Add(el.Name, SanitizeMemberName(el.Name));
}
IsInternal = isInternal;
}

public string SanitizeNames(string text)
@@ -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;
}
}

@@ -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,
@@ -540,7 +556,8 @@ public OverloadDefinition(
string structName,
string comment,
bool isConstructor,
bool isDestructor)
bool isDestructor,
bool isInternal)
{
ExportedName = exportedName;
FriendlyName = friendlyName;
@@ -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

Unchanged files with check annotations Beta

namespace ImGuiNET
{
public delegate void Platform_CreateWindow(ImGuiViewportPtr vp); // Create a new platform window for the given viewport

Check warning on line 6 in src/ImGui.NET/Delegates.cs

GitHub Actions / Build_Windows

Missing XML comment for publicly visible type or member 'Platform_CreateWindow'
public delegate void Platform_DestroyWindow(ImGuiViewportPtr vp);

Check warning on line 7 in src/ImGui.NET/Delegates.cs

GitHub Actions / Build_Windows

Missing XML comment for publicly visible type or member 'Platform_DestroyWindow'
public delegate void Platform_ShowWindow(ImGuiViewportPtr vp); // Newly created windows are initially hidden so SetWindowPos/Size/Title can be called on them first

Check warning on line 8 in src/ImGui.NET/Delegates.cs

GitHub Actions / Build_Windows

Missing XML comment for publicly visible type or member 'Platform_ShowWindow'
public delegate void Platform_SetWindowPos(ImGuiViewportPtr vp, Vector2 pos);

Check warning on line 9 in src/ImGui.NET/Delegates.cs

GitHub Actions / Build_Windows

Missing XML comment for publicly visible type or member 'Platform_SetWindowPos'
public unsafe delegate void Platform_GetWindowPos(ImGuiViewportPtr vp, Vector2* outPos);

Check warning on line 10 in src/ImGui.NET/Delegates.cs

GitHub Actions / Build_Windows

Missing XML comment for publicly visible type or member 'Platform_GetWindowPos'
public delegate void Platform_SetWindowSize(ImGuiViewportPtr vp, Vector2 size);

Check warning on line 11 in src/ImGui.NET/Delegates.cs

GitHub Actions / Build_Windows

Missing XML comment for publicly visible type or member 'Platform_SetWindowSize'
public unsafe delegate void Platform_GetWindowSize(ImGuiViewportPtr vp, Vector2* outSize);

Check warning on line 12 in src/ImGui.NET/Delegates.cs

GitHub Actions / Build_Windows

Missing XML comment for publicly visible type or member 'Platform_GetWindowSize'
public delegate void Platform_SetWindowFocus(ImGuiViewportPtr vp); // Move window to front and set input focus

Check warning on line 13 in src/ImGui.NET/Delegates.cs

GitHub Actions / Build_Windows

Missing XML comment for publicly visible type or member 'Platform_SetWindowFocus'
public delegate byte Platform_GetWindowFocus(ImGuiViewportPtr vp);

Check warning on line 14 in src/ImGui.NET/Delegates.cs

GitHub Actions / Build_Windows

Missing XML comment for publicly visible type or member 'Platform_GetWindowFocus'
public delegate byte Platform_GetWindowMinimized(ImGuiViewportPtr vp);

Check warning on line 15 in src/ImGui.NET/Delegates.cs

GitHub Actions / Build_Windows

Missing XML comment for publicly visible type or member 'Platform_GetWindowMinimized'
public delegate void Platform_SetWindowTitle(ImGuiViewportPtr vp, IntPtr title);
}