mirror of
https://github.com/Ryujinx/GtkSharp.git
synced 2025-06-20 15:27:49 +00: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,24 +93,24 @@ namespace GtkSharp.Generation {
|
||||||
|
|
||||||
if (HasCB || HideData) {
|
if (HasCB || HideData) {
|
||||||
|
|
||||||
|
if (Parser.GetVersion (elem.OwnerDocument.DocumentElement) >= 3) {
|
||||||
foreach (Parameter param in param_list) {
|
foreach (Parameter param in param_list) {
|
||||||
if (param.Closure == idx)
|
if (param.Closure == idx)
|
||||||
return true;
|
return true;
|
||||||
else if (param.DestroyNotify == idx)
|
if (param.DestroyNotify == idx)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
if (p.IsUserData && (idx == Count - 1))
|
if (p.IsUserData && (idx == Count - 1))
|
||||||
return true;
|
return true;
|
||||||
if (p.IsUserData && (idx == Count - 2) && this [Count - 1] is ErrorParameter)
|
if (p.IsUserData && (idx == Count - 2) && this [Count - 1] is ErrorParameter)
|
||||||
return true;
|
return true;
|
||||||
if (p.IsUserData && idx > 0 &&
|
if (p.IsUserData && idx > 0 && this [idx - 1].Generatable is CallbackGen)
|
||||||
this [idx - 1].Generatable is CallbackGen)
|
|
||||||
return true;
|
return true;
|
||||||
if (p.IsDestroyNotify && (idx == Count - 1) &&
|
if (p.IsDestroyNotify && (idx == Count - 1) && this [idx - 1].IsUserData)
|
||||||
this [idx - 1].IsUserData)
|
|
||||||
return true;
|
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;
|
||||||
|
|
||||||
foreach (StructField field in fields) {
|
|
||||||
if (field.IsBitfield) {
|
|
||||||
if (need_field) {
|
|
||||||
StreamWriter sw = gen_info.Writer;
|
StreamWriter sw = gen_info.Writer;
|
||||||
|
|
||||||
|
foreach (StructField field in fields) {
|
||||||
|
if (Union)
|
||||||
|
sw.WriteLine ("\t\t[FieldOffset(0)]");
|
||||||
|
if (field.IsBitfield) {
|
||||||
|
if (need_field) {
|
||||||
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,6 +228,9 @@ 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]");
|
||||||
|
if (Union)
|
||||||
|
sw.WriteLine ("\t[StructLayout(LayoutKind.Explicit)]");
|
||||||
|
else
|
||||||
sw.WriteLine ("\t[StructLayout(LayoutKind.Sequential)]");
|
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);
|
||||||
|
|
|
@ -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") {
|
||||||
|
|
|
@ -293,6 +293,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)
|
||||||
{
|
{
|
||||||
if (this[c_type] is EnumGen)
|
if (this[c_type] is EnumGen)
|
||||||
|
|
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 a new issue