mirror of
https://github.com/Ryujinx/GtkSharp.git
synced 2024-09-09 00:13:20 +02:00
generator: Added conversion for unions
Also removed all assumptions for parameters when ParserVersion >= 3
This commit is contained in:
parent
fd2fb44f99
commit
747a4ad871
@ -64,6 +64,7 @@ sources = \
|
|||||||
StructField.cs \
|
StructField.cs \
|
||||||
StructGen.cs \
|
StructGen.cs \
|
||||||
SymbolTable.cs \
|
SymbolTable.cs \
|
||||||
|
UnionGen.cs \
|
||||||
VirtualMethod.cs \
|
VirtualMethod.cs \
|
||||||
VMSignature.cs \
|
VMSignature.cs \
|
||||||
XmlElementExtensions.cs
|
XmlElementExtensions.cs
|
||||||
|
@ -93,23 +93,23 @@ namespace GtkSharp.Generation {
|
|||||||
|
|
||||||
if (HasCB || HideData) {
|
if (HasCB || HideData) {
|
||||||
|
|
||||||
foreach (Parameter param in param_list) {
|
if (Parser.GetVersion (elem.OwnerDocument.DocumentElement) >= 3) {
|
||||||
if (param.Closure == idx)
|
foreach (Parameter param in param_list) {
|
||||||
|
if (param.Closure == idx)
|
||||||
|
return true;
|
||||||
|
if (param.DestroyNotify == idx)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (p.IsUserData && (idx == Count - 1))
|
||||||
return true;
|
return true;
|
||||||
else if (param.DestroyNotify == idx)
|
if (p.IsUserData && (idx == Count - 2) && this [Count - 1] is ErrorParameter)
|
||||||
|
return true;
|
||||||
|
if (p.IsUserData && idx > 0 && this [idx - 1].Generatable is CallbackGen)
|
||||||
|
return true;
|
||||||
|
if (p.IsDestroyNotify && (idx == Count - 1) && this [idx - 1].IsUserData)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p.IsUserData && (idx == Count - 1))
|
|
||||||
return true;
|
|
||||||
if (p.IsUserData && (idx == Count - 2) && this [Count - 1] is ErrorParameter)
|
|
||||||
return true;
|
|
||||||
if (p.IsUserData && idx > 0 &&
|
|
||||||
this [idx - 1].Generatable is CallbackGen)
|
|
||||||
return true;
|
|
||||||
if (p.IsDestroyNotify && (idx == Count - 1) &&
|
|
||||||
this [idx - 1].IsUserData)
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@ -234,7 +234,8 @@ namespace GtkSharp.Generation {
|
|||||||
param_list.Add (p);
|
param_list.Add (p);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (has_cb && Count > 2 && this [Count - 3].Generatable is CallbackGen && this [Count - 2].IsUserData && this [Count - 1].IsDestroyNotify)
|
if (Parser.GetVersion (elem.OwnerDocument.DocumentElement) < 3 &&
|
||||||
|
has_cb && Count > 2 && this [Count - 3].Generatable is CallbackGen && this [Count - 2].IsUserData && this [Count - 1].IsDestroyNotify)
|
||||||
this [Count - 3].Scope = "notified";
|
this [Count - 3].Scope = "notified";
|
||||||
|
|
||||||
valid = true;
|
valid = true;
|
||||||
|
@ -171,6 +171,9 @@ namespace GtkSharp.Generation {
|
|||||||
case "class":
|
case "class":
|
||||||
result.Add (new ClassGen (ns, elem));
|
result.Add (new ClassGen (ns, elem));
|
||||||
break;
|
break;
|
||||||
|
case "union":
|
||||||
|
result.Add (new UnionGen (ns, elem));
|
||||||
|
break;
|
||||||
case "struct":
|
case "struct":
|
||||||
if (is_opaque) {
|
if (is_opaque) {
|
||||||
result.Add (new OpaqueGen (ns, elem));
|
result.Add (new OpaqueGen (ns, elem));
|
||||||
|
@ -110,6 +110,12 @@ namespace GtkSharp.Generation {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual bool Union {
|
||||||
|
get {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected void GenEqualsAndHash (StreamWriter sw)
|
protected void GenEqualsAndHash (StreamWriter sw)
|
||||||
{
|
{
|
||||||
int bitfields = 0;
|
int bitfields = 0;
|
||||||
@ -172,12 +178,13 @@ namespace GtkSharp.Generation {
|
|||||||
{
|
{
|
||||||
int bitfields = 0;
|
int bitfields = 0;
|
||||||
bool need_field = true;
|
bool need_field = true;
|
||||||
|
StreamWriter sw = gen_info.Writer;
|
||||||
|
|
||||||
foreach (StructField field in fields) {
|
foreach (StructField field in fields) {
|
||||||
|
if (Union)
|
||||||
|
sw.WriteLine ("\t\t[FieldOffset(0)]");
|
||||||
if (field.IsBitfield) {
|
if (field.IsBitfield) {
|
||||||
if (need_field) {
|
if (need_field) {
|
||||||
StreamWriter sw = gen_info.Writer;
|
|
||||||
|
|
||||||
sw.WriteLine ("\t\tprivate uint _bitfield{0};\n", bitfields++);
|
sw.WriteLine ("\t\tprivate uint _bitfield{0};\n", bitfields++);
|
||||||
need_field = false;
|
need_field = false;
|
||||||
}
|
}
|
||||||
@ -221,7 +228,10 @@ namespace GtkSharp.Generation {
|
|||||||
sw.WriteLine ("#region Autogenerated code");
|
sw.WriteLine ("#region Autogenerated code");
|
||||||
if (IsDeprecated)
|
if (IsDeprecated)
|
||||||
sw.WriteLine ("\t[Obsolete]");
|
sw.WriteLine ("\t[Obsolete]");
|
||||||
sw.WriteLine ("\t[StructLayout(LayoutKind.Sequential)]");
|
if (Union)
|
||||||
|
sw.WriteLine ("\t[StructLayout(LayoutKind.Explicit)]");
|
||||||
|
else
|
||||||
|
sw.WriteLine ("\t[StructLayout(LayoutKind.Sequential)]");
|
||||||
string access = IsInternal ? "internal" : "public";
|
string access = IsInternal ? "internal" : "public";
|
||||||
sw.WriteLine ("\t" + access + " partial struct {0} : IEquatable<{0}> {{", Name);
|
sw.WriteLine ("\t" + access + " partial struct {0} : IEquatable<{0}> {{", Name);
|
||||||
sw.WriteLine ();
|
sw.WriteLine ();
|
||||||
|
@ -80,7 +80,7 @@ namespace GtkSharp.Generation {
|
|||||||
return StudlyName;
|
return StudlyName;
|
||||||
else if (IsBitfield)
|
else if (IsBitfield)
|
||||||
return Name;
|
return Name;
|
||||||
else if (IsPointer && (gen is StructGen || gen is BoxedGen))
|
else if (IsPointer && (gen is StructGen || gen is BoxedGen || gen is UnionGen))
|
||||||
return Access != "private" ? wrapped_name : Name;
|
return Access != "private" ? wrapped_name : Name;
|
||||||
else if (IsPointer && CSType != "string")
|
else if (IsPointer && CSType != "string")
|
||||||
return Name;
|
return Name;
|
||||||
@ -148,7 +148,7 @@ namespace GtkSharp.Generation {
|
|||||||
acc.WriteAccessors (sw, indent + "\t", Name);
|
acc.WriteAccessors (sw, indent + "\t", Name);
|
||||||
sw.WriteLine (indent + "}");
|
sw.WriteLine (indent + "}");
|
||||||
}
|
}
|
||||||
} else if (IsPointer && (gen is StructGen || gen is BoxedGen)) {
|
} else if (IsPointer && (gen is StructGen || gen is BoxedGen || gen is UnionGen)) {
|
||||||
sw.WriteLine (indent + "private {0} {1};", CSType, Name);
|
sw.WriteLine (indent + "private {0} {1};", CSType, Name);
|
||||||
sw.WriteLine ();
|
sw.WriteLine ();
|
||||||
if (Access != "private") {
|
if (Access != "private") {
|
||||||
|
@ -292,6 +292,13 @@ namespace GtkSharp.Generation {
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool IsUnion (string c_type)
|
||||||
|
{
|
||||||
|
if (this[c_type] is UnionGen)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public bool IsEnum(string c_type)
|
public bool IsEnum(string c_type)
|
||||||
{
|
{
|
||||||
|
18
generator/UnionGen.cs
Normal file
18
generator/UnionGen.cs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
|
||||||
|
using System.Xml;
|
||||||
|
|
||||||
|
namespace GtkSharp.Generation
|
||||||
|
{
|
||||||
|
public class UnionGen : StructBase {
|
||||||
|
|
||||||
|
public UnionGen (XmlElement ns, XmlElement elem) : base (ns, elem)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool Union {
|
||||||
|
get {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -92,6 +92,7 @@
|
|||||||
<Compile Include="ArrayParameter.cs" />
|
<Compile Include="ArrayParameter.cs" />
|
||||||
<Compile Include="Options.cs" />
|
<Compile Include="Options.cs" />
|
||||||
<Compile Include="Constant.cs" />
|
<Compile Include="Constant.cs" />
|
||||||
|
<Compile Include="UnionGen.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="DESIGN" />
|
<None Include="DESIGN" />
|
||||||
|
Loading…
Reference in New Issue
Block a user