+
Skip to content

Update gir files #1132

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

Merged
merged 5 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ext/gir-files
17 changes: 17 additions & 0 deletions src/Generation/Generator/Fixer/Record/DisableBrokenTypes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Generator.Model;

namespace Generator.Fixer.Record;

internal class DisableBrokenTypes : Fixer<GirModel.Record>
{
public void Fixup(GirModel.Record record)
{
switch (record.Name)
{
case "Win32NetworkMonitor":
case "Win32NetworkMonitorClass":
Type.Disable(record);
break;
}
}
}
7 changes: 4 additions & 3 deletions src/Generation/Generator/Fixer/Records.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ namespace Generator.Fixer;

public static class Records
{
private static readonly List<Fixer<GirModel.Record>> Fixers = new()
{
private static readonly List<Fixer<GirModel.Record>> Fixers =
[
new DisableBrokenTypes(),
new InternalMethodsNamedLikeRecordFixer(),
new MethodWithInOutInstanceParameterFixer(),
new PublicMethodsColldingWithFieldFixer(),
new RecordEqualsMethodCollidesWithGeneratedCode()
};
];

public static void Fixup(IEnumerable<GirModel.Record> records)
{
Expand Down
14 changes: 5 additions & 9 deletions src/Generation/Generator/Generator/Internal/TypedRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,16 @@

namespace Generator.Generator.Internal;

internal class TypedRecord : Generator<GirModel.Record>
internal class TypedRecord(Publisher publisher) : Generator<GirModel.Record>
{
private readonly Publisher _publisher;

public TypedRecord(Publisher publisher)
{
_publisher = publisher;
}

public void Generate(GirModel.Record obj)
{
if (!Record.IsTyped(obj))
return;

if (!Type.IsEnabled(obj))
return;

var source = Renderer.Internal.TypedRecord.Render(obj);
var codeUnit = new CodeUnit(
Project: Namespace.GetCanonicalName(obj.Namespace),
Expand All @@ -24,6 +20,6 @@ public void Generate(GirModel.Record obj)
IsInternal: true
);

_publisher.Publish(codeUnit);
publisher.Publish(codeUnit);
}
}
14 changes: 5 additions & 9 deletions src/Generation/Generator/Generator/Internal/TypedRecordData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,16 @@

namespace Generator.Generator.Internal;

internal class TypedRecordData : Generator<GirModel.Record>
internal class TypedRecordData(Publisher publisher) : Generator<GirModel.Record>
{
private readonly Publisher _publisher;

public TypedRecordData(Publisher publisher)
{
_publisher = publisher;
}

public void Generate(GirModel.Record obj)
{
if (!Record.IsTyped(obj))
return;

if (!Type.IsEnabled(obj))
return;

var source = Renderer.Internal.TypedRecordData.Render(obj);
var codeUnit = new CodeUnit(
Project: Namespace.GetCanonicalName(obj.Namespace),
Expand All @@ -24,6 +20,6 @@ public void Generate(GirModel.Record obj)
IsInternal: true
);

_publisher.Publish(codeUnit);
publisher.Publish(codeUnit);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,8 @@

namespace Generator.Generator.Internal;

internal class TypedRecordDelegates : Generator<GirModel.Record>
internal class TypedRecordDelegates(Publisher publisher) : Generator<GirModel.Record>
{
private readonly Publisher _publisher;

public TypedRecordDelegates(Publisher publisher)
{
_publisher = publisher;
}

public void Generate(GirModel.Record record)
{
if (!Record.IsTyped(record))
Expand All @@ -20,6 +13,9 @@ public void Generate(GirModel.Record record)
if (!record.Fields.Any(field => field.AnyTypeOrCallback.IsT1))
return;

if (!Type.IsEnabled(record))
return;

var source = Renderer.Internal.TypedRecordDelegates.Render(record);
var codeUnit = new CodeUnit(
Project: Namespace.GetCanonicalName(record.Namespace),
Expand All @@ -28,6 +24,6 @@ public void Generate(GirModel.Record record)
IsInternal: true
);

_publisher.Publish(codeUnit);
publisher.Publish(codeUnit);
}
}
14 changes: 5 additions & 9 deletions src/Generation/Generator/Generator/Internal/TypedRecordHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,16 @@

namespace Generator.Generator.Internal;

internal class TypedRecordHandle : Generator<GirModel.Record>
internal class TypedRecordHandle(Publisher publisher) : Generator<GirModel.Record>
{
private readonly Publisher _publisher;

public TypedRecordHandle(Publisher publisher)
{
_publisher = publisher;
}

public void Generate(GirModel.Record obj)
{
if (!Record.IsTyped(obj))
return;

if (!Type.IsEnabled(obj))
return;

var source = Renderer.Internal.TypedRecordHandle.Render(obj);
var codeUnit = new CodeUnit(
Project: Namespace.GetCanonicalName(obj.Namespace),
Expand All @@ -24,6 +20,6 @@ public void Generate(GirModel.Record obj)
IsInternal: true
);

_publisher.Publish(codeUnit);
publisher.Publish(codeUnit);
}
}
14 changes: 5 additions & 9 deletions src/Generation/Generator/Generator/Internal/UntypedRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,16 @@

namespace Generator.Generator.Internal;

internal class UntypedRecord : Generator<GirModel.Record>
internal class UntypedRecord(Publisher publisher) : Generator<GirModel.Record>
{
private readonly Publisher _publisher;

public UntypedRecord(Publisher publisher)
{
_publisher = publisher;
}

public void Generate(GirModel.Record obj)
{
if (!Record.IsUntyped(obj))
return;

if (!Type.IsEnabled(obj))
return;

var source = Renderer.Internal.UntypedRecord.Render(obj);
var codeUnit = new CodeUnit(
Project: Namespace.GetCanonicalName(obj.Namespace),
Expand All @@ -24,6 +20,6 @@ public void Generate(GirModel.Record obj)
IsInternal: true
);

_publisher.Publish(codeUnit);
publisher.Publish(codeUnit);
}
}
14 changes: 5 additions & 9 deletions src/Generation/Generator/Generator/Internal/UntypedRecordData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,16 @@

namespace Generator.Generator.Internal;

internal class UntypedRecordData : Generator<GirModel.Record>
internal class UntypedRecordData(Publisher publisher) : Generator<GirModel.Record>
{
private readonly Publisher _publisher;

public UntypedRecordData(Publisher publisher)
{
_publisher = publisher;
}

public void Generate(GirModel.Record obj)
{
if (!Record.IsUntyped(obj))
return;

if (!Type.IsEnabled(obj))
return;

var source = Renderer.Internal.UntypedRecordData.Render(obj);
var codeUnit = new CodeUnit(
Project: Namespace.GetCanonicalName(obj.Namespace),
Expand All @@ -24,6 +20,6 @@ public void Generate(GirModel.Record obj)
IsInternal: true
);

_publisher.Publish(codeUnit);
publisher.Publish(codeUnit);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,16 @@

namespace Generator.Generator.Internal;

internal class UntypedRecordHandle : Generator<GirModel.Record>
internal class UntypedRecordHandle(Publisher publisher) : Generator<GirModel.Record>
{
private readonly Publisher _publisher;

public UntypedRecordHandle(Publisher publisher)
{
_publisher = publisher;
}

public void Generate(GirModel.Record obj)
{
if (!Record.IsUntyped(obj))
return;

if (!Type.IsEnabled(obj))
return;

var source = Renderer.Internal.UntypedRecordHandle.Render(obj);
var codeUnit = new CodeUnit(
Project: Namespace.GetCanonicalName(obj.Namespace),
Expand All @@ -24,6 +20,6 @@ public void Generate(GirModel.Record obj)
IsInternal: true
);

_publisher.Publish(codeUnit);
publisher.Publish(codeUnit);
}
}
14 changes: 5 additions & 9 deletions src/Generation/Generator/Generator/Public/TypedRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,16 @@

namespace Generator.Generator.Public;

internal class TypedRecord : Generator<GirModel.Record>
internal class TypedRecord(Publisher publisher) : Generator<GirModel.Record>
{
private readonly Publisher _publisher;

public TypedRecord(Publisher publisher)
{
_publisher = publisher;
}

public void Generate(GirModel.Record record)
{
if (!Record.IsTyped(record))
return;

if (!Type.IsEnabled(record))
return;

var source = Renderer.Public.TypedRecord.Render(record);
var codeUnit = new CodeUnit(
Project: Namespace.GetCanonicalName(record.Namespace),
Expand All @@ -24,6 +20,6 @@ public void Generate(GirModel.Record record)
IsInternal: false
);

_publisher.Publish(codeUnit);
publisher.Publish(codeUnit);
}
}
14 changes: 5 additions & 9 deletions src/Generation/Generator/Generator/Public/UntypedRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,16 @@

namespace Generator.Generator.Public;

internal class UntypedRecord : Generator<GirModel.Record>
internal class UntypedRecord(Publisher publisher) : Generator<GirModel.Record>
{
private readonly Publisher _publisher;

public UntypedRecord(Publisher publisher)
{
_publisher = publisher;
}

public void Generate(GirModel.Record record)
{
if (!Record.IsUntyped(record))
return;

if (!Type.IsEnabled(record))
return;

var source = Renderer.Public.UntypedRecord.Render(record);
var codeUnit = new CodeUnit(
Project: Namespace.GetCanonicalName(record.Namespace),
Expand All @@ -24,6 +20,6 @@ public void Generate(GirModel.Record record)
IsInternal: false
);

_publisher.Publish(codeUnit);
publisher.Publish(codeUnit);
}
}
22 changes: 22 additions & 0 deletions src/Generation/Generator/Model/Type.Disable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Collections.Generic;

namespace Generator.Model;

internal static partial class Type
{
private static readonly HashSet<GirModel.Type> Disabled = new();

public static void Disable(GirModel.Type type)
{
lock (Disabled)
{
Disabled.Add(type);
}
}

public static bool IsEnabled(GirModel.Type type)
{
//Does not need a lock as it is called only after all insertions are done.
return !Disabled.Contains(type);
}
}
2 changes: 1 addition & 1 deletion src/Generation/Generator/Model/Type.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Generator.Model;

internal static class Type
internal static partial class Type
{
public const string Pointer = "IntPtr";
public const string PointerArray = "IntPtr[]";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private static string RenderContent(IEnumerable<ParameterToNativeData> parameter

private static string RenderCallStatement(GirModel.Constructor constructor, IEnumerable<ParameterToNativeData> parameters, Constructor.ConstructorData data)
{
var variableName = "handle";
var variableName = $"{constructor.Parent.Name.ToLower()}Handle";
var call = new StringBuilder();
call.Append($"var {variableName} = Internal.{constructor.Parent.Name}.{Model.Constructor.GetName(constructor)}(");
call.Append(string.Join(", ", parameters.Select(x => x.GetCallName())));
Expand Down
Loading
Loading
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载