mirror of
https://github.com/Ryujinx/GtkSharp.git
synced 2024-09-18 20:29:46 +02:00
2003-10-06 Mike Kestner <mkestner@ximian.com>
* generator/CodeGenerator.cs (Main): use new ObjectGen.GenerateMappers. * generator/GenerationInfo.cs (Ctor): new (dir, assembly) ctor * generator/ObjectGen.cs : move hash management to Generate from Ctor, index it on dir, and make it hold new DirectoryInfo refs. Refactor GenerateMapper. The object mappers are now assembly based instead of namespace based. svn path=/trunk/gtk-sharp/; revision=18681
This commit is contained in:
parent
1c7dfb776c
commit
06a02e97b4
@ -1,3 +1,12 @@
|
|||||||
|
2003-10-06 Mike Kestner <mkestner@ximian.com>
|
||||||
|
|
||||||
|
* generator/CodeGenerator.cs (Main): use new ObjectGen.GenerateMappers.
|
||||||
|
* generator/GenerationInfo.cs (Ctor): new (dir, assembly) ctor
|
||||||
|
* generator/ObjectGen.cs : move hash management to Generate from Ctor,
|
||||||
|
index it on dir, and make it hold new DirectoryInfo refs. Refactor
|
||||||
|
GenerateMapper. The object mappers are now assembly based instead of
|
||||||
|
namespace based.
|
||||||
|
|
||||||
2003-10-06 Mike Kestner <mkestner@ximian.com>
|
2003-10-06 Mike Kestner <mkestner@ximian.com>
|
||||||
|
|
||||||
* generator/Signal.cs (Generate): pass gen_info to sighdnlr.Generate.
|
* generator/Signal.cs (Generate): pass gen_info to sighdnlr.Generate.
|
||||||
|
@ -46,7 +46,7 @@ namespace GtkSharp.Generation {
|
|||||||
gen.Generate ();
|
gen.Generate ();
|
||||||
}
|
}
|
||||||
|
|
||||||
ObjectGen.GenerateMapper ();
|
ObjectGen.GenerateMappers ();
|
||||||
|
|
||||||
Statistics.Report();
|
Statistics.Report();
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -27,6 +27,13 @@ namespace GtkSharp.Generation {
|
|||||||
assembly_name = ns_name.ToLower () + "-sharp";
|
assembly_name = ns_name.ToLower () + "-sharp";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GenerationInfo (string dir, string assembly_name)
|
||||||
|
{
|
||||||
|
this.dir = dir;
|
||||||
|
custom_dir = dir;
|
||||||
|
this.assembly_name = assembly_name;
|
||||||
|
}
|
||||||
|
|
||||||
public string AssemblyName {
|
public string AssemblyName {
|
||||||
get {
|
get {
|
||||||
return assembly_name;
|
return assembly_name;
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
//
|
//
|
||||||
// Author: Mike Kestner <mkestner@speakeasy.net>
|
// Author: Mike Kestner <mkestner@speakeasy.net>
|
||||||
//
|
//
|
||||||
// (c) 2001-2002 Mike Kestner
|
// (c) 2001-2003 Mike Kestner and Ximian Inc.
|
||||||
|
|
||||||
namespace GtkSharp.Generation {
|
namespace GtkSharp.Generation {
|
||||||
|
|
||||||
@ -15,19 +15,10 @@ namespace GtkSharp.Generation {
|
|||||||
public class ObjectGen : ClassBase, IGeneratable {
|
public class ObjectGen : ClassBase, IGeneratable {
|
||||||
|
|
||||||
private ArrayList strings = new ArrayList();
|
private ArrayList strings = new ArrayList();
|
||||||
private static Hashtable namespaces = new Hashtable ();
|
private static Hashtable dirs = new Hashtable ();
|
||||||
|
|
||||||
public ObjectGen (XmlElement ns, XmlElement elem) : base (ns, elem)
|
public ObjectGen (XmlElement ns, XmlElement elem) : base (ns, elem)
|
||||||
{
|
{
|
||||||
Hashtable objs;
|
|
||||||
if (namespaces.ContainsKey (NS))
|
|
||||||
objs = (Hashtable) namespaces[NS];
|
|
||||||
else {
|
|
||||||
objs = new Hashtable();
|
|
||||||
namespaces.Add (NS, objs);
|
|
||||||
}
|
|
||||||
objs.Add (CName, QualifiedName + "," + NS.ToLower() + "-sharp");
|
|
||||||
|
|
||||||
foreach (XmlNode node in elem.ChildNodes) {
|
foreach (XmlNode node in elem.ChildNodes) {
|
||||||
|
|
||||||
if (!(node is XmlElement)) continue;
|
if (!(node is XmlElement)) continue;
|
||||||
@ -51,6 +42,36 @@ namespace GtkSharp.Generation {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class DirectoryInfo {
|
||||||
|
public string assembly_name;
|
||||||
|
public Hashtable objects;
|
||||||
|
|
||||||
|
public DirectoryInfo (string assembly_name) {
|
||||||
|
this.assembly_name = assembly_name;
|
||||||
|
objects = new Hashtable ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static DirectoryInfo GetDirectoryInfo (string dir, string assembly_name)
|
||||||
|
{
|
||||||
|
DirectoryInfo result;
|
||||||
|
|
||||||
|
if (dirs.ContainsKey (dir)) {
|
||||||
|
result = dirs [dir] as DirectoryInfo;
|
||||||
|
if (result.assembly_name != assembly_name) {
|
||||||
|
Console.WriteLine ("Can't put multiple assemblies in one directory.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
result = new DirectoryInfo (assembly_name);
|
||||||
|
dirs.Add (dir, result);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public void Generate ()
|
public void Generate ()
|
||||||
{
|
{
|
||||||
GenerationInfo gen_info = new GenerationInfo (NSElem);
|
GenerationInfo gen_info = new GenerationInfo (NSElem);
|
||||||
@ -59,6 +80,9 @@ namespace GtkSharp.Generation {
|
|||||||
|
|
||||||
public void Generate (GenerationInfo gen_info)
|
public void Generate (GenerationInfo gen_info)
|
||||||
{
|
{
|
||||||
|
DirectoryInfo di = GetDirectoryInfo (gen_info.Dir, gen_info.AssemblyName);
|
||||||
|
di.objects.Add (CName, QualifiedName);
|
||||||
|
|
||||||
StreamWriter sw = gen_info.Writer = gen_info.OpenStream (Name);
|
StreamWriter sw = gen_info.Writer = gen_info.OpenStream (Name);
|
||||||
|
|
||||||
sw.WriteLine ("namespace " + NS + " {");
|
sw.WriteLine ("namespace " + NS + " {");
|
||||||
@ -163,7 +187,7 @@ namespace GtkSharp.Generation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Keep this in sync with the one in glib/ObjectManager.cs */
|
/* Keep this in sync with the one in glib/ObjectManager.cs */
|
||||||
static string GetExpected (string cname)
|
private static string GetExpected (string cname)
|
||||||
{
|
{
|
||||||
StringBuilder expected = new StringBuilder ();
|
StringBuilder expected = new StringBuilder ();
|
||||||
string ns = "";
|
string ns = "";
|
||||||
@ -177,43 +201,49 @@ namespace GtkSharp.Generation {
|
|||||||
}
|
}
|
||||||
expected.Append (cname[i]);
|
expected.Append (cname[i]);
|
||||||
}
|
}
|
||||||
expected.AppendFormat (",{0}-sharp", ns);
|
|
||||||
return expected.ToString ();
|
return expected.ToString ();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GenerateMapper ()
|
private static bool NeedsMap (Hashtable objs)
|
||||||
{
|
{
|
||||||
foreach (string ns in namespaces.Keys) {
|
foreach (string key in objs.Keys)
|
||||||
Hashtable objs = (Hashtable) namespaces[ns];
|
if (GetExpected (key) != ((string) objs[key]))
|
||||||
bool needs_map = false;
|
return true;
|
||||||
foreach (string key in objs.Keys) {
|
|
||||||
string expected = GetExpected (key);
|
return false;
|
||||||
if (expected != ((string) objs[key])) {
|
|
||||||
needs_map = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!needs_map)
|
private static string Studlify (string name)
|
||||||
|
{
|
||||||
|
string result = "";
|
||||||
|
|
||||||
|
string[] subs = name.Split ('-');
|
||||||
|
foreach (string sub in subs)
|
||||||
|
result += Char.ToUpper (sub[0]) + sub.Substring (1);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void GenerateMappers ()
|
||||||
|
{
|
||||||
|
foreach (string dir in dirs.Keys) {
|
||||||
|
|
||||||
|
DirectoryInfo di = dirs[dir] as DirectoryInfo;
|
||||||
|
|
||||||
|
if (!NeedsMap (di.objects))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
char sep = Path.DirectorySeparatorChar;
|
GenerationInfo gen_info = new GenerationInfo (dir, di.assembly_name);
|
||||||
string dir = ".." + sep + ns.ToLower () + sep + "generated";
|
|
||||||
if (!Directory.Exists(dir)) {
|
GenerateMapper (di, gen_info);
|
||||||
Console.WriteLine ("creating " + dir);
|
}
|
||||||
Directory.CreateDirectory(dir);
|
|
||||||
}
|
}
|
||||||
String filename = dir + sep + "ObjectManager.cs";
|
|
||||||
|
|
||||||
FileStream stream = new FileStream (filename, FileMode.Create, FileAccess.Write);
|
private static void GenerateMapper (DirectoryInfo dir_info, GenerationInfo gen_info)
|
||||||
StreamWriter sw = new StreamWriter (stream);
|
{
|
||||||
|
StreamWriter sw = gen_info.OpenStream ("ObjectManager");
|
||||||
|
|
||||||
sw.WriteLine ("// Generated File. Do not modify.");
|
sw.WriteLine ("namespace GtkSharp." + Studlify (dir_info.assembly_name) + " {");
|
||||||
sw.WriteLine ("// <c> 2001-2002 Mike Kestner");
|
|
||||||
sw.WriteLine ();
|
|
||||||
|
|
||||||
sw.WriteLine ("namespace GtkSharp {");
|
|
||||||
sw.WriteLine ();
|
|
||||||
sw.WriteLine ("\tnamespace " + ns + " {");
|
|
||||||
sw.WriteLine ();
|
sw.WriteLine ();
|
||||||
sw.WriteLine ("\tpublic class ObjectManager {");
|
sw.WriteLine ("\tpublic class ObjectManager {");
|
||||||
sw.WriteLine ();
|
sw.WriteLine ();
|
||||||
@ -221,21 +251,15 @@ namespace GtkSharp.Generation {
|
|||||||
sw.WriteLine ("\t\tpublic static void Initialize ()");
|
sw.WriteLine ("\t\tpublic static void Initialize ()");
|
||||||
sw.WriteLine ("\t\t{");
|
sw.WriteLine ("\t\t{");
|
||||||
|
|
||||||
foreach (string key in objs.Keys) {
|
foreach (string key in dir_info.objects.Keys)
|
||||||
string expected = GetExpected (key);
|
if (GetExpected(key) != ((string) dir_info.objects[key]))
|
||||||
if (expected != ((string) objs[key])) {
|
sw.WriteLine ("\t\t\tGtkSharp.ObjectManager.RegisterType(\"" + key + "\", \"" + dir_info.objects [key] + "," + dir_info.assembly_name + "\");");
|
||||||
sw.WriteLine ("\t\t\tGtkSharp.ObjectManager.RegisterType(\"" + key + "\", \"" + objs[key] + "\");");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sw.WriteLine ("\t\t}");
|
sw.WriteLine ("\t\t}");
|
||||||
sw.WriteLine ("\t}");
|
sw.WriteLine ("\t}");
|
||||||
sw.WriteLine ("}");
|
sw.WriteLine ("}");
|
||||||
sw.WriteLine ("}");
|
|
||||||
sw.Flush ();
|
|
||||||
sw.Close ();
|
sw.Close ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user