2004-12-26 Mike Kestner <mkestner@novell.com>

* generator/Makefile.am : add new file.
	* generator/SimpleBase.cs : new class for non-generated type mappers.
	* generator/*Gen.cs : first refactoring of "Simple" generatable types.
	Derive them all from SimpleBase. More to come.

svn path=/trunk/gtk-sharp/; revision=38097
This commit is contained in:
Mike Kestner 2004-12-26 21:22:50 +00:00
parent 1c4b5f81ba
commit 1d72136dd8
11 changed files with 163 additions and 497 deletions

View File

@ -1,3 +1,10 @@
2004-12-26 Mike Kestner <mkestner@novell.com>
* generator/Makefile.am : add new file.
* generator/SimpleBase.cs : new class for non-generated type mappers.
* generator/*Gen.cs : first refactoring of "Simple" generatable types.
Derive them all from SimpleBase. More to come.
2004-12-26 Mike Kestner <mkestner@novell.com>
* generator/CustomMarshalerGen.cs : kill bad idea unused class.

View File

@ -1,8 +1,9 @@
// GtkSharp.Generation.ByRefGen.cs - The ByRef type Generatable.
//
// Author: Mike Kestner <mkestner@speakeasy.net>
// Author: Mike Kestner <mkestner@novell.com>
//
// Copyright (c) 2003 Mike Kestner
// Copyright (c) 2004 Novell, Inc.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of version 2 of the GNU General Public
@ -23,92 +24,37 @@ namespace GtkSharp.Generation {
using System;
public class ByRefGen : IGeneratable {
public class ByRefGen : SimpleBase {
string type;
string ctype;
string ns = "";
public ByRefGen (string ctype, string type)
{
string[] toks = type.Split('.');
this.ctype = ctype;
this.type = toks[toks.Length - 1];
if (toks.Length > 2)
this.ns = String.Join (".", toks, 0, toks.Length - 2);
else if (toks.Length == 2)
this.ns = toks[0];
}
public ByRefGen (string ctype, string type) : base (ctype, type) {}
public string CName {
get
{
return ctype;
}
}
public string Name {
get
{
return type;
}
}
public string QualifiedName {
get
{
return ns + "." + type;
}
}
public string MarshalType {
get
{
public override string MarshalType {
get {
return "ref " + QualifiedName;
}
}
public virtual string MarshalReturnType {
get
{
public override string MarshalReturnType {
get {
return QualifiedName;
}
}
public virtual string ToNativeReturnType {
get
{
public override string ToNativeReturnType {
get {
return QualifiedName;
}
}
public string CallByName (string var_name)
public override string CallByName (string var_name)
{
return "ref " + var_name;
}
public string FromNative(string var)
public override string ToNativeReturn(string var)
{
return var;
}
public virtual string FromNativeReturn(string var)
{
return var;
}
public virtual string ToNativeReturn(string var)
{
return var;
}
public void Generate ()
{
}
public void Generate (GenerationInfo gen_info)
{
}
}
}

View File

@ -1,6 +1,6 @@
// GtkSharp.Generation.GStringGen.cs - The GString type Generatable.
//
// Author: Mike Kestner <mkestner@ximian.com>
// Author: Mike Kestner <mkestner@novell.com>
//
// Copyright (c) 2004 Novell, Inc.
//
@ -23,71 +23,25 @@ namespace GtkSharp.Generation {
using System;
public class GStringGen : IGeneratable {
public class GStringGen : SimpleBase {
public string CName {
get {
return "GString";
}
}
public GStringGen () : base ("GString", "string") {}
public string Name {
get {
return "string";
}
}
public string QualifiedName {
get {
return "string";
}
}
public string MarshalType {
public override string MarshalType {
get {
return "IntPtr";
}
}
public string CallByName (string var_name)
public override string CallByName (string var_name)
{
return "(new GLib.GString (" + var_name + ")).Handle";
}
public string FromNative (string var)
public override string FromNative (string var)
{
return "GLib.GString.PtrToString (" + var + ")";
}
public string FromNativeReturn (string var)
{
return FromNative (var);
}
public string ToNativeReturn (string var)
{
return CallByName (var);
}
public string MarshalReturnType {
get {
return "IntPtr";
}
}
public string ToNativeReturnType {
get {
return "IntPtr";
}
}
public void Generate ()
{
}
public void Generate (GenerationInfo gen_info)
{
}
}
}

View File

@ -23,71 +23,25 @@ namespace GtkSharp.Generation {
using System;
public class GUnicharGen : IGeneratable {
public class GUnicharGen : SimpleBase {
public string CName {
get {
return "gunichar";
}
}
public GUnicharGen () : base ("gunichar", "char") {}
public string Name {
get {
return "char";
}
}
public string QualifiedName {
get {
return "char";
}
}
public string MarshalType {
public override string MarshalType {
get {
return "uint";
}
}
public string MarshalReturnType {
get {
return MarshalType;
}
}
public string ToNativeReturnType {
get {
return MarshalType;
}
}
public string CallByName (string var_name)
public override string CallByName (string var_name)
{
return "GLib.Marshaller.CharToGUnichar (" + var_name + ")";
}
public virtual string FromNative(string var)
public override string FromNative(string var)
{
return "GLib.Marshaller.GUnicharToChar (" + var + ")";
}
public virtual string FromNativeReturn(string var)
{
return FromNative (var);
}
public virtual string ToNativeReturn(string var)
{
return CallByName (var);
}
public void Generate ()
{
}
public void Generate (GenerationInfo gen_info)
{
}
}
}

View File

@ -23,78 +23,25 @@ namespace GtkSharp.Generation {
using System;
public class LPGen : IGeneratable {
public class LPGen : SimpleBase {
string ctype;
public LPGen (string ctype) : base (ctype, "long") {}
public LPGen (string ctype)
{
this.ctype = ctype;
}
public string CName {
get {
return ctype;
}
}
public string Name {
get {
return "long";
}
}
public string QualifiedName {
get {
return "long";
}
}
public string MarshalType {
public override string MarshalType {
get {
return "IntPtr";
}
}
public string MarshalReturnType {
get {
return MarshalType;
}
}
public string ToNativeReturnType {
get {
return MarshalType;
}
}
public string CallByName (string var_name)
public override string CallByName (string var_name)
{
return "new IntPtr (" + var_name + ")";
}
public virtual string FromNative(string var)
public override string FromNative(string var)
{
return "(long) " + var;
}
public virtual string FromNativeReturn(string var)
{
return FromNative (var);
}
public virtual string ToNativeReturn(string var)
{
return CallByName (var);
}
public void Generate ()
{
}
public void Generate (GenerationInfo gen_info)
{
}
}
}

View File

@ -23,80 +23,25 @@ namespace GtkSharp.Generation {
using System;
public class LPUGen : IGeneratable {
public class LPUGen : SimpleGen {
string ctype;
public LPUGen (string ctype) : base (ctype, "ulong") {}
public LPUGen (string ctype)
{
this.ctype = ctype;
}
public string CName {
get {
return ctype;
}
}
public string Name {
get {
return "ulong";
}
}
public string QualifiedName {
get {
return "ulong";
}
}
public string MarshalType {
public override string MarshalType {
get {
return "UIntPtr";
}
}
public string MarshalReturnType {
get
{
return MarshalType;
}
}
public string ToNativeReturnType {
get
{
return MarshalType;
}
}
public string CallByName (string var_name)
public override string CallByName (string var_name)
{
return "new UIntPtr (" + var_name + ")";
}
public virtual string FromNative(string var)
public override string FromNative(string var)
{
return "(ulong) " + var;
}
public virtual string FromNativeReturn(string var)
{
return FromNative (var);
}
public virtual string ToNativeReturn(string var)
{
return CallByName (var);
}
public void Generate ()
{
}
public void Generate (GenerationInfo gen_info)
{
}
}
}

View File

@ -42,6 +42,7 @@ sources = \
Signal.cs \
SignalHandler.cs \
Signature.cs \
SimpleBase.cs \
SimpleGen.cs \
Statistics.cs \
StringGen.cs \

View File

@ -23,96 +23,33 @@ namespace GtkSharp.Generation {
using System;
public class ManualGen : IGeneratable {
public class ManualGen : SimpleBase {
string handle;
string ctype;
string type;
string ns = "";
public ManualGen (string ctype, string type) : this (ctype, type, "Handle") {}
public ManualGen (string ctype, string type, string handle)
public ManualGen (string ctype, string type, string handle) : base (ctype, type)
{
string[] toks = type.Split('.');
this.handle = handle;
this.ctype = ctype;
this.type = toks[toks.Length - 1];
if (toks.Length > 2)
this.ns = String.Join (".", toks, 0, toks.Length - 2);
else if (toks.Length == 2)
this.ns = toks[0];
}
public string CName {
get
{
return ctype;
}
}
public string Name {
get
{
return type;
}
}
public string QualifiedName {
get
{
return ns + "." + type;
}
}
public string MarshalType {
public override string MarshalType {
get
{
return "IntPtr";
}
}
public string MarshalReturnType {
get
{
return "IntPtr";
}
}
public string ToNativeReturnType {
get
{
return "IntPtr";
}
}
public string CallByName (string var_name)
public override string CallByName (string var_name)
{
return var_name + "." + handle;
}
public virtual string FromNative(string var)
public override string FromNative(string var)
{
return "new " + QualifiedName + "(" + var + ")";
}
public virtual string FromNativeReturn(string var)
{
return FromNative (var);
}
public virtual string ToNativeReturn(string var)
{
return CallByName (var);
}
public void Generate ()
{
}
public void Generate (GenerationInfo gen_info)
{
}
}
}

108
generator/SimpleBase.cs Normal file
View File

@ -0,0 +1,108 @@
// GtkSharp.Generation.SimpleBase.cs - base class for marshaling non-generated types.
//
// Author: Mike Kestner <mkestner@novell.com>
//
// Copyright (c) 2004 Novell, Inc.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of version 2 of the GNU General Public
// License as published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public
// License along with this program; if not, write to the
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.
namespace GtkSharp.Generation {
using System;
public class SimpleBase : IGeneratable {
string type;
string ctype;
string ns = String.Empty;
public SimpleBase (string ctype, string type)
{
string[] toks = type.Split('.');
this.ctype = ctype;
this.type = toks[toks.Length - 1];
if (toks.Length > 2)
this.ns = String.Join (".", toks, 0, toks.Length - 2);
else if (toks.Length == 2)
this.ns = toks[0];
}
public string CName {
get {
return ctype;
}
}
public string Name {
get {
return type;
}
}
public string QualifiedName {
get {
return ns == String.Empty ? type : ns + "." + type;
}
}
public virtual string MarshalType {
get {
return QualifiedName;
}
}
public virtual string MarshalReturnType {
get {
return MarshalType;
}
}
public virtual string ToNativeReturnType {
get {
return MarshalType;
}
}
public virtual string CallByName (string var)
{
return var;
}
public virtual string FromNative(string var)
{
return var;
}
public virtual string FromNativeReturn(string var)
{
return FromNative (var);
}
public virtual string ToNativeReturn(string var)
{
return CallByName (var);
}
public void Generate ()
{
}
public void Generate (GenerationInfo gen_info)
{
}
}
}

View File

@ -23,85 +23,8 @@ namespace GtkSharp.Generation {
using System;
public class SimpleGen : IGeneratable {
string type;
string ctype;
public SimpleGen (string ctype, string type)
{
this.ctype = ctype;
this.type = type;
}
public string CName {
get
{
return ctype;
}
}
public string Name {
get
{
return type;
}
}
public string QualifiedName {
get
{
return type;
}
}
public string MarshalType {
get
{
return type;
}
}
public virtual string MarshalReturnType {
get
{
return type;
}
}
public virtual string ToNativeReturnType {
get
{
return type;
}
}
public string CallByName (string var_name)
{
return var_name;
}
public string FromNative(string var)
{
return var;
}
public virtual string FromNativeReturn(string var)
{
return var;
}
public virtual string ToNativeReturn(string var)
{
return var;
}
public void Generate ()
{
}
public void Generate (GenerationInfo gen_info)
{
}
public class SimpleGen : SimpleBase {
public SimpleGen (string ctype, string type) : base (ctype, type) {}
}
}

View File

@ -1,6 +1,6 @@
// GtkSharp.Generation.TimeTGen.cs - The time_t Generatable.
//
// Author: Mike Kestner <mkestner@speakeasy.net>
// Author: Mike Kestner <mkestner@novell.com>
//
// Copyright (c) 2003 Mike Kestner
// Copyright (c) 2004 Novell, Inc.
@ -24,81 +24,25 @@ namespace GtkSharp.Generation {
using System;
public class TimeTGen : IGeneratable {
public class TimeTGen : SimpleBase {
string ctype;
string type;
string ns = "";
public TimeTGen () : base ("time_t", "System.DateTime") {}
public string CName {
get
{
return "time_t";
}
}
public string Name {
get
{
return "DateTime";
}
}
public string QualifiedName {
get
{
return "System.DateTime";
}
}
public string MarshalType {
get
{
public override string MarshalType {
get {
return "IntPtr";
}
}
public string MarshalReturnType {
get
{
return "IntPtr";
}
}
public string ToNativeReturnType {
get
{
return "IntPtr";
}
}
public string CallByName (string var_name)
public override string CallByName (string var_name)
{
return "GLib.Marshaller.DateTimeTotime_t (" + var_name + ")";
}
public virtual string FromNative(string var)
public override string FromNative(string var)
{
return "GLib.Marshaller.time_tToDateTime (" + var + ")";
}
public virtual string FromNativeReturn(string var)
{
return FromNative (var);
}
public virtual string ToNativeReturn(string var)
{
return CallByName (var);
}
public void Generate ()
{
}
public void Generate (GenerationInfo gen_info)
{
}
}
}