Ryujinx-GtkSharp/generator/SymbolTable.cs
Mike Kestner 6d30cf0c3e refactoring to remove substantial code duplication thoughout the generator
2002-05-23  Mike Kestner <mkestner@speakeasy.net>

	* generator/BoxedGen.cs : Update for Static SymbolTable
	* generator/CallbackGen.cs : Use GenBase and Parameters classes
	* generator/CodeGenerator.cs : Update for Static SymbolTable
	* generator/Ctor.cs : code from StructBase using Parameters class
	* generator/EnumGen.cs : Use GenBase
	* generator/GenBase.cs : Abstract Stream Writer creation, stream
	  boilerplate, and common *Name properties
	* generator/IGeneratable.cs : Update for Static SymbolTable
	* generator/InterfaceGen.cs : Use GenBase
	* generator/Method.cs : code from StructBase using Parameters class
	* generator/ObjectGen.cs : Major refactoring. Use GenBase. Build
	  tables of Member generatables at construct time to facilitate
	  future name collision resolution logic.
	* generator/Parameters.cs : new generatable to abstract duplicated
	  parameter parsing logic.
	* generator/Parser.cs : Update for Static SymbolTable
	* generator/Property.cs : code from ObjectGen
	* generator/Signal.cs : code from ObjectGen
	* generator/SignalHandler.cs : Update for Static SymbolTable
	* generator/StructBase.cs : Update for Static SymbolTable
	* generator/StructGen.cs : Update for Static SymbolTable
	* generator/SymbolTable.cs : Make all methods and private members
	  static.  There is no reason to ever have multiple tables.

svn path=/trunk/gtk-sharp/; revision=4895
2002-05-23 23:43:25 +00:00

235 lines
6.3 KiB
C#

// GtkSharp.Generation.SymbolTable.cs - The Symbol Table Class.
//
// Author: Mike Kestner <mkestner@speakeasy.net>
//
// (c) 2001-2002 Mike Kestner
namespace GtkSharp.Generation {
using System;
using System.Collections;
public class SymbolTable {
private static Hashtable complex_types = new Hashtable ();
private static Hashtable simple_types;
private static Hashtable dlls;
static SymbolTable ()
{
simple_types = new Hashtable ();
simple_types.Add ("void", "void");
simple_types.Add ("gboolean", "bool");
simple_types.Add ("gint", "int");
simple_types.Add ("guint", "uint");
simple_types.Add ("glong", "long");
simple_types.Add ("gshort", "short");
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");
simple_types.Add ("gint32", "int");
simple_types.Add ("guint16", "ushort");
simple_types.Add ("guint1", "bool");
simple_types.Add ("gpointer", "System.IntPtr");
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");
simple_types.Add ("char", "string");
simple_types.Add ("double", "double");
simple_types.Add ("float", "float");
simple_types.Add ("gunichar", "string");
simple_types.Add ("uint1", "bool");
simple_types.Add ("GPtrArray", "System.IntPtr[]");
simple_types.Add ("GType", "int");
// FIXME: These ought to be handled properly.
simple_types.Add ("GList", "System.IntPtr");
simple_types.Add ("GMemChunk", "System.IntPtr");
simple_types.Add ("GTimeVal", "System.IntPtr");
simple_types.Add ("GClosure", "System.IntPtr");
simple_types.Add ("GArray", "System.IntPtr");
simple_types.Add ("GData", "System.IntPtr");
simple_types.Add ("GTypeModule", "GLib.Object");
simple_types.Add ("GSList", "GLib.SList");
simple_types.Add ("GHashTable", "System.IntPtr");
simple_types.Add ("va_list", "System.IntPtr");
simple_types.Add ("GParamSpec", "System.IntPtr");
dlls = new Hashtable();
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");
}
public static void AddType (IGeneratable gen)
{
complex_types [gen.CName] = gen;
}
public static int Count {
get
{
return complex_types.Count;
}
}
public static IEnumerable Generatables {
get {
return complex_types.Values;
}
}
private static string Trim(string type)
{
string trim_type = type.TrimEnd('*');
if (trim_type.StartsWith("const-")) return trim_type.Substring(6);
return trim_type;
}
public static 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 "";
}
}
public static string GetCSType(string c_type)
{
c_type = Trim(c_type);
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.QualifiedName;
} else {
return "";
}
}
public static 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 "";
}
}
public static string GetDllName(string ns)
{
return (string) dlls[ns];
}
public static string GetMarshalType(string c_type)
{
c_type = Trim(c_type);
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 "";
}
}
public static 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 "";
}
}
public static bool IsBoxed(string c_type)
{
c_type = Trim(c_type);
if (complex_types.ContainsKey(c_type)) {
IGeneratable gen = (IGeneratable) complex_types[c_type];
if (gen is BoxedGen) {
return true;
}
}
return false;
}
public static bool IsEnum(string c_type)
{
c_type = Trim(c_type);
if (complex_types.ContainsKey(c_type)) {
IGeneratable gen = (IGeneratable) complex_types[c_type];
if (gen is EnumGen) {
return true;
}
}
return false;
}
public static bool IsInterface(string c_type)
{
c_type = Trim(c_type);
if (complex_types.ContainsKey(c_type)) {
IGeneratable gen = (IGeneratable) complex_types[c_type];
if (gen is InterfaceGen) {
return true;
}
}
return false;
}
public static ObjectGen GetObjectGen(string c_type)
{
c_type = Trim(c_type);
if (IsObject(c_type)) {
return (ObjectGen) complex_types[c_type];
}
return null;
}
public static bool IsObject(string c_type)
{
c_type = Trim(c_type);
if (complex_types.ContainsKey(c_type)) {
IGeneratable gen = (IGeneratable) complex_types[c_type];
if (gen is ObjectGen) {
return true;
}
}
return false;
}
}
}