2002-01-05 13:45:55 +01:00
|
|
|
// GtkSharp.Generation.SymbolTable.cs - The Symbol Table Class.
|
|
|
|
//
|
|
|
|
// Author: Mike Kestner <mkestner@speakeasy.net>
|
|
|
|
//
|
|
|
|
// (c) 2001 Mike Kestner
|
|
|
|
|
|
|
|
namespace GtkSharp.Generation {
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
|
|
|
|
public class SymbolTable {
|
|
|
|
|
|
|
|
private Hashtable complex_types = new Hashtable ();
|
|
|
|
private Hashtable simple_types;
|
2002-01-17 Mike Kestner <mkestner@speakeasy.net>
* generator/BoxedGen.cs : Removed Name, CName, and QualifiedName.
* generator/ObjectGen.cs : Removed Name, CName, and QualifiedName.
* generator/StructBase.cs : Add Name, CName, and QualifiedName. Add
GenCtor method. Stub GetCallString, GetImportSig, and GetSignature
methods.
* generator/StructGen.cs : Removed Name, CName, and QualifiedName.
* generator/SymbolTable.cs : Add GetDllName method.
* parser/gapi2xml.pl : Fix a couple <parameters> bugs.
svn path=/trunk/gtk-sharp/; revision=2030
2002-01-18 00:44:56 +01:00
|
|
|
private Hashtable dlls;
|
2002-01-05 13:45:55 +01:00
|
|
|
|
2002-01-05 14:24:13 +01:00
|
|
|
public SymbolTable ()
|
|
|
|
{
|
|
|
|
simple_types = new Hashtable ();
|
2002-02-09 00:56:27 +01:00
|
|
|
simple_types.Add ("void", "void");
|
2002-01-05 14:24:13 +01:00
|
|
|
simple_types.Add ("gboolean", "bool");
|
|
|
|
simple_types.Add ("gint", "int");
|
|
|
|
simple_types.Add ("guint", "uint");
|
|
|
|
simple_types.Add ("glong", "long");
|
2002-01-06 14:33:25 +01:00
|
|
|
simple_types.Add ("gshort", "short");
|
2002-01-05 14:24:13 +01:00
|
|
|
simple_types.Add ("guint32", "uint");
|
|
|
|
simple_types.Add ("const-gchar", "String");
|
|
|
|
simple_types.Add ("gchar", "String");
|
|
|
|
simple_types.Add ("GObject", "GLib.Object");
|
|
|
|
simple_types.Add ("gfloat", "float");
|
|
|
|
simple_types.Add ("gdouble", "double");
|
|
|
|
simple_types.Add ("gint8", "byte");
|
|
|
|
simple_types.Add ("guint8", "byte");
|
|
|
|
simple_types.Add ("gint16", "short");
|
2002-01-06 14:33:25 +01:00
|
|
|
simple_types.Add ("gint32", "int");
|
|
|
|
simple_types.Add ("guint16", "ushort");
|
2002-01-05 14:24:13 +01:00
|
|
|
simple_types.Add ("guint1", "bool");
|
2002-01-06 14:33:25 +01:00
|
|
|
simple_types.Add ("gpointer", "IntPtr");
|
2002-01-05 14:24:13 +01:00
|
|
|
simple_types.Add ("guchar", "byte");
|
|
|
|
simple_types.Add ("GValue", "GLib.Value");
|
|
|
|
simple_types.Add ("GtkType", "int");
|
|
|
|
simple_types.Add ("long", "long");
|
|
|
|
simple_types.Add ("gulong", "ulong");
|
|
|
|
simple_types.Add ("GQuark", "int");
|
|
|
|
simple_types.Add ("int", "int");
|
2002-01-06 14:33:25 +01:00
|
|
|
simple_types.Add ("char", "char");
|
2002-01-05 14:24:13 +01:00
|
|
|
simple_types.Add ("double", "double");
|
2002-01-12 03:08:16 +01:00
|
|
|
simple_types.Add ("float", "float");
|
2002-01-05 14:24:13 +01:00
|
|
|
simple_types.Add ("gunichar", "String");
|
|
|
|
simple_types.Add ("uint1", "bool");
|
2002-01-08 21:05:47 +01:00
|
|
|
simple_types.Add ("GPtrArray", "IntPtr[]");
|
|
|
|
simple_types.Add ("GType", "int");
|
2002-01-05 14:24:13 +01:00
|
|
|
|
|
|
|
// FIXME: These ought to be handled properly.
|
2002-01-06 14:33:25 +01:00
|
|
|
simple_types.Add ("GList", "IntPtr");
|
2002-01-08 21:05:47 +01:00
|
|
|
simple_types.Add ("GMemChunk", "IntPtr");
|
|
|
|
simple_types.Add ("GTimeVal", "IntPtr");
|
|
|
|
simple_types.Add ("GClosure", "IntPtr");
|
|
|
|
simple_types.Add ("GArray", "IntPtr");
|
|
|
|
simple_types.Add ("GData", "IntPtr");
|
2002-01-10 16:01:31 +01:00
|
|
|
simple_types.Add ("GTypeModule", "GLib.Object");
|
2002-02-03 04:44:10 +01:00
|
|
|
simple_types.Add ("GSList", "GLib.SList");
|
2002-01-06 14:33:25 +01:00
|
|
|
simple_types.Add ("GHashTable", "IntPtr");
|
2002-01-05 14:24:13 +01:00
|
|
|
simple_types.Add ("va_list", "IntPtr");
|
|
|
|
simple_types.Add ("GParamSpec", "IntPtr");
|
2002-01-17 Mike Kestner <mkestner@speakeasy.net>
* generator/BoxedGen.cs : Removed Name, CName, and QualifiedName.
* generator/ObjectGen.cs : Removed Name, CName, and QualifiedName.
* generator/StructBase.cs : Add Name, CName, and QualifiedName. Add
GenCtor method. Stub GetCallString, GetImportSig, and GetSignature
methods.
* generator/StructGen.cs : Removed Name, CName, and QualifiedName.
* generator/SymbolTable.cs : Add GetDllName method.
* parser/gapi2xml.pl : Fix a couple <parameters> bugs.
svn path=/trunk/gtk-sharp/; revision=2030
2002-01-18 00:44:56 +01:00
|
|
|
|
|
|
|
dlls = new Hashtable();
|
2002-03-28 22:16:43 +01:00
|
|
|
dlls.Add("Pango", "pango-1.0");
|
|
|
|
dlls.Add("Atk", "atk-1.0");
|
|
|
|
dlls.Add("Gdk", "gdk-x11-2.0");
|
|
|
|
dlls.Add("Gtk", "gtk-x11-2.0");
|
2002-01-05 14:24:13 +01:00
|
|
|
}
|
|
|
|
|
2002-01-05 13:45:55 +01:00
|
|
|
public void AddType (IGeneratable gen)
|
|
|
|
{
|
|
|
|
complex_types [gen.CName] = gen;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int Count {
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return complex_types.Count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-03-08 23:40:00 +01:00
|
|
|
public IEnumerable Generatables {
|
|
|
|
get {
|
|
|
|
return complex_types.Values;
|
|
|
|
}
|
2002-01-05 13:45:55 +01:00
|
|
|
}
|
|
|
|
|
2002-02-03 04:44:10 +01:00
|
|
|
private String Trim(String type)
|
|
|
|
{
|
2002-03-29 18:55:46 +01:00
|
|
|
String trim_type = type.TrimEnd('*');
|
2002-02-18 20:26:33 +01:00
|
|
|
if (trim_type.StartsWith("const-")) return trim_type.Substring(6);
|
2002-02-03 04:44:10 +01:00
|
|
|
return trim_type;
|
|
|
|
}
|
|
|
|
|
2002-02-09 00:56:27 +01:00
|
|
|
public String FromNative(String c_type, String val)
|
|
|
|
{
|
|
|
|
c_type = Trim(c_type);
|
|
|
|
if (simple_types.ContainsKey(c_type)) {
|
|
|
|
return val;
|
|
|
|
} else if (complex_types.ContainsKey(c_type)) {
|
|
|
|
IGeneratable gen = (IGeneratable) complex_types[c_type];
|
|
|
|
return gen.FromNative(val);
|
|
|
|
} else {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-01-12 03:08:16 +01:00
|
|
|
public String GetCSType(String c_type)
|
2002-01-05 13:45:55 +01:00
|
|
|
{
|
2002-02-03 04:44:10 +01:00
|
|
|
c_type = Trim(c_type);
|
2002-01-05 14:24:13 +01:00
|
|
|
if (simple_types.ContainsKey(c_type)) {
|
2002-01-12 03:08:16 +01:00
|
|
|
return (String) simple_types[c_type];
|
2002-01-05 14:24:13 +01:00
|
|
|
} else if (complex_types.ContainsKey(c_type)) {
|
|
|
|
IGeneratable gen = (IGeneratable) complex_types[c_type];
|
|
|
|
return gen.QualifiedName;
|
|
|
|
} else {
|
|
|
|
return "";
|
|
|
|
}
|
2002-01-05 13:45:55 +01:00
|
|
|
}
|
|
|
|
|
2002-02-15 02:08:57 +01:00
|
|
|
public String GetName(String c_type)
|
|
|
|
{
|
|
|
|
c_type = Trim(c_type);
|
|
|
|
if (simple_types.ContainsKey(c_type)) {
|
|
|
|
String stype = (String) simple_types[c_type];
|
|
|
|
int dotidx = stype.IndexOf(".");
|
|
|
|
if (dotidx == -1) {
|
|
|
|
return stype;
|
|
|
|
} else {
|
|
|
|
return stype.Substring(dotidx+1);
|
|
|
|
}
|
|
|
|
} else if (complex_types.ContainsKey(c_type)) {
|
|
|
|
IGeneratable gen = (IGeneratable) complex_types[c_type];
|
|
|
|
return gen.Name;
|
|
|
|
} else {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-01-17 Mike Kestner <mkestner@speakeasy.net>
* generator/BoxedGen.cs : Removed Name, CName, and QualifiedName.
* generator/ObjectGen.cs : Removed Name, CName, and QualifiedName.
* generator/StructBase.cs : Add Name, CName, and QualifiedName. Add
GenCtor method. Stub GetCallString, GetImportSig, and GetSignature
methods.
* generator/StructGen.cs : Removed Name, CName, and QualifiedName.
* generator/SymbolTable.cs : Add GetDllName method.
* parser/gapi2xml.pl : Fix a couple <parameters> bugs.
svn path=/trunk/gtk-sharp/; revision=2030
2002-01-18 00:44:56 +01:00
|
|
|
public String GetDllName(String ns)
|
|
|
|
{
|
|
|
|
return (String) dlls[ns];
|
|
|
|
}
|
|
|
|
|
2002-01-12 03:08:16 +01:00
|
|
|
public String GetMarshalType(String c_type)
|
|
|
|
{
|
2002-02-06 21:09:14 +01:00
|
|
|
c_type = Trim(c_type);
|
2002-01-12 03:08:16 +01:00
|
|
|
if (simple_types.ContainsKey(c_type)) {
|
|
|
|
return (String) simple_types[c_type];
|
|
|
|
} else if (complex_types.ContainsKey(c_type)) {
|
|
|
|
IGeneratable gen = (IGeneratable) complex_types[c_type];
|
|
|
|
return gen.MarshalType;
|
|
|
|
} else {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-02-06 21:09:14 +01:00
|
|
|
public String CallByName(String c_type, String var_name)
|
|
|
|
{
|
|
|
|
c_type = Trim(c_type);
|
|
|
|
if (simple_types.ContainsKey(c_type)) {
|
|
|
|
return var_name;
|
|
|
|
} else if (complex_types.ContainsKey(c_type)) {
|
|
|
|
IGeneratable gen = (IGeneratable) complex_types[c_type];
|
|
|
|
return gen.CallByName(var_name);
|
|
|
|
} else {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-01-17 01:26:46 +01:00
|
|
|
public bool IsBoxed(String c_type)
|
|
|
|
{
|
2002-02-15 02:08:57 +01:00
|
|
|
c_type = Trim(c_type);
|
2002-01-17 01:26:46 +01:00
|
|
|
if (complex_types.ContainsKey(c_type)) {
|
|
|
|
IGeneratable gen = (IGeneratable) complex_types[c_type];
|
|
|
|
if (gen is BoxedGen) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool IsInterface(String c_type)
|
|
|
|
{
|
2002-02-15 02:08:57 +01:00
|
|
|
c_type = Trim(c_type);
|
2002-01-17 01:26:46 +01:00
|
|
|
if (complex_types.ContainsKey(c_type)) {
|
|
|
|
IGeneratable gen = (IGeneratable) complex_types[c_type];
|
|
|
|
if (gen is InterfaceGen) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2002-01-12 03:08:16 +01:00
|
|
|
public bool IsObject(String c_type)
|
|
|
|
{
|
2002-02-15 02:08:57 +01:00
|
|
|
c_type = Trim(c_type);
|
2002-01-12 03:08:16 +01:00
|
|
|
if (complex_types.ContainsKey(c_type)) {
|
|
|
|
IGeneratable gen = (IGeneratable) complex_types[c_type];
|
|
|
|
if (gen is ObjectGen) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2002-01-05 13:45:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|