Change the way generatable validation works. Some generatable

properties can't be set until Validate-time (eg, Method.IsGetter),
	but it's annoying for every potential user of those properties to
	have to make sure it has Validated the generatable first. So now
	we add an explicit Validate() step after everything is loaded but
	before anything is Generated, so that at Generation time,
	everything can be assumed to have been Validated.

	* generator/IGeneratable.cs: add "bool Validate()"

	* generator/CodeGenerator.cs (Main): after loading all of the
	generatables, DeAlias the SymbolTable, Validate() all the
	generatables, and discard any invalid ones.

	* generator/*.cs: Implement Validate() trivially in generatables
	that didn't implement it before. Move Validate() calls from
	Generate() to Validate(). Remove non-hierarchical Validate()
	calls.

	* generator/SymbolTable.cs: GPtrArray is IntPtr, not IntPtr[]

svn path=/trunk/gtk-sharp/; revision=48046
This commit is contained in:
Dan Winship 2005-08-05 20:34:45 +00:00
parent a2b058160b
commit 85d88fe1ca
20 changed files with 237 additions and 162 deletions

View File

@ -1,3 +1,26 @@
2005-08-04 Dan Winship <danw@novell.com>
Change the way generatable validation works. Some generatable
properties can't be set until Validate-time (eg, Method.IsGetter),
but it's annoying for every potential user of those properties to
have to make sure it has Validated the generatable first. So now
we add an explicit Validate() step after everything is loaded but
before anything is Generated, so that at Generation time,
everything can be assumed to have been Validated.
* generator/IGeneratable.cs: add "bool Validate()"
* generator/CodeGenerator.cs (Main): after loading all of the
generatables, DeAlias the SymbolTable, Validate() all the
generatables, and discard any invalid ones.
* generator/*.cs: Implement Validate() trivially in generatables
that didn't implement it before. Move Validate() calls from
Generate() to Validate(). Remove non-hierarchical Validate()
calls.
* generator/SymbolTable.cs: GPtrArray is IntPtr, not IntPtr[]
2005-08-04 Dan Winship <danw@novell.com>
* gtk/TargetList.custom: add an operator for casting to

View File

@ -173,5 +173,17 @@
<since version="Gtk# 2.6" />
</Docs>
</Member>
<Member MemberName="Target">
<MemberSignature Language="C#" Value="public IntPtr Target { get; };" />
<MemberType>Property</MemberType>
<ReturnValue>
<ReturnType>System.IntPtr</ReturnType>
</ReturnValue>
<Docs>
<summary>To be added.</summary>
<value>To be added.</value>
<remarks>To be added.</remarks>
</Docs>
</Member>
</Members>
</Type>

View File

@ -1,19 +0,0 @@
<Type Name="SocketSetTimeoutFunc" FullName="Gnome.Vfs.SocketSetTimeoutFunc">
<TypeSignature Language="C#" Value="public delegate Gnome.Vfs.Result SocketSetTimeoutFunc();" />
<AssemblyInfo>
<AssemblyName>gnome-vfs-sharp</AssemblyName>
<AssemblyVersion>2.6.0.0</AssemblyVersion>
</AssemblyInfo>
<Base>
<BaseTypeName>System.Delegate</BaseTypeName>
</Base>
<Parameters />
<ReturnValue>
<ReturnType>Gnome.Vfs.Result</ReturnType>
</ReturnValue>
<Docs>
<summary>To be added.</summary>
<returns>To be added.</returns>
<remarks>To be added.</remarks>
</Docs>
</Type>

View File

@ -111,5 +111,14 @@
<AttributeName>System.Obsolete(Message=null, IsError=False)</AttributeName>
</Attribute>
</Attributes></Member>
<Member MemberName=".ctor">
<MemberSignature Language="C#" Value="protected ControlWidget ();" />
<MemberType>Constructor</MemberType>
<Parameters />
<Docs>
<summary>To be added.</summary>
<remarks>To be added.</remarks>
</Docs>
</Member>
</Members>
</Type>

View File

@ -1224,7 +1224,6 @@
<Type Name="XdgParentList" />
<Type Name="DNSSDBrowseCallback" />
<Type Name="DNSSDResolveCallback" />
<Type Name="SocketSetTimeoutFunc" />
<Type Name="XdgMimeCallback" />
<Type Name="XdgMimeDestroy" />
<Type Name="DNSSDServiceStatus" />

View File

@ -33,9 +33,6 @@ namespace GtkSharp.Generation {
{
gen_info.CurrentType = Name;
if (!Validate ())
return;
StreamWriter sw = gen_info.Writer = gen_info.OpenStream (Name);
base.Generate (gen_info);
sw.WriteLine ("\t\t[DllImport(\"glibsharpglue-2\")]");

View File

@ -39,6 +39,23 @@ namespace GtkSharp.Generation {
parms.HideData = true;
}
public override bool Validate ()
{
if (!retval.Validate ()) {
Console.WriteLine ("rettype: " + retval.CType + " in callback " + CName);
Statistics.ThrottledCount++;
return false;
}
if (!parms.Validate ()) {
Console.WriteLine (" in callback " + CName);
Statistics.ThrottledCount++;
return false;
}
return true;
}
public override string MarshalType {
get {
return NS + "Sharp." + Name + "Native";
@ -173,16 +190,6 @@ namespace GtkSharp.Generation {
public override void Generate (GenerationInfo gen_info)
{
gen_info.CurrentType = Name;
if (!retval.Validate ()) {
Console.WriteLine("rettype: " + retval.CType + " in callback " + CName);
Statistics.ThrottledCount++;
return;
}
if (!parms.Validate ()) {
Console.WriteLine(" in callback " + CName + " **** Stubbing it out ****");
Statistics.ThrottledCount++;
}
sig = new Signature (parms);

View File

@ -123,6 +123,77 @@ namespace GtkSharp.Generation {
}
}
public override bool Validate ()
{
if (Parent != null && !Parent.Validate ())
return false;
foreach (string iface in interfaces) {
IGeneratable gen = SymbolTable.Table[iface];
if (!(gen is InterfaceGen)) {
Console.WriteLine (QualifiedName + " implements unknown GInterface " + iface);
return false;
}
if (!gen.Validate ()) {
Console.WriteLine (QualifiedName + " implements invalid GInterface " + iface);
return false;
}
}
ArrayList invalids = new ArrayList ();
foreach (Property prop in props.Values) {
if (!prop.Validate ()) {
Console.WriteLine ("in type " + QualifiedName);
invalids.Add (prop);
}
}
foreach (Property prop in invalids)
props.Remove (prop.Name);
invalids.Clear ();
foreach (Signal sig in sigs.Values) {
if (!sig.Validate ()) {
Console.WriteLine ("in type " + QualifiedName);
invalids.Add (sig);
}
}
foreach (Signal sig in invalids)
sigs.Remove (sig.Name);
invalids.Clear ();
foreach (ObjectField field in fields.Values) {
if (!field.Validate ()) {
Console.WriteLine ("in type " + QualifiedName);
invalids.Add (field);
}
}
foreach (ObjectField field in invalids)
fields.Remove (field.Name);
invalids.Clear ();
foreach (Method method in methods.Values) {
if (!method.Validate ()) {
Console.WriteLine ("in type " + QualifiedName);
invalids.Add (method);
}
}
foreach (Method method in invalids)
methods.Remove (method.Name);
invalids.Clear ();
foreach (Ctor ctor in ctors) {
if (!ctor.Validate ()) {
Console.WriteLine ("in type " + QualifiedName);
invalids.Add (ctor);
}
}
foreach (Ctor ctor in invalids)
ctors.Remove (ctor);
invalids.Clear ();
return true;
}
public bool IsDeprecated {
get {
return deprecated;
@ -161,12 +232,8 @@ namespace GtkSharp.Generation {
if (props.Count == 0)
return;
foreach (Property prop in props.Values) {
if (prop.Validate ())
prop.Generate (gen_info, "\t\t", implementor);
else
Console.WriteLine("in Object " + QualifiedName);
}
foreach (Property prop in props.Values)
prop.Generate (gen_info, "\t\t", implementor);
}
public void GenSignals (GenerationInfo gen_info, ClassBase implementor)
@ -174,22 +241,14 @@ namespace GtkSharp.Generation {
if (sigs == null)
return;
foreach (Signal sig in sigs.Values) {
if (sig.Validate ())
sig.Generate (gen_info, implementor);
else
Console.WriteLine("in Object " + QualifiedName);
}
foreach (Signal sig in sigs.Values)
sig.Generate (gen_info, implementor);
}
protected void GenFields (GenerationInfo gen_info)
{
foreach (ObjectField field in fields.Values) {
if (field.Validate ())
field.Generate (gen_info, "\t\t");
else
Console.WriteLine("in Object " + QualifiedName);
}
foreach (ObjectField field in fields.Values)
field.Generate (gen_info, "\t\t");
}
private void ParseImplements (XmlElement member)
@ -222,25 +281,18 @@ namespace GtkSharp.Generation {
if (IgnoreMethod (method))
continue;
if (method.Validate ())
{
string oname = null, oprotection = null;
if (collisions != null && collisions.Contains (method.Name))
{
oname = method.Name;
oprotection = method.Protection;
method.Name = QualifiedName + "." + method.Name;
method.Protection = "";
}
method.Generate (gen_info, implementor);
if (oname != null)
{
method.Name = oname;
method.Protection = oprotection;
}
string oname = null, oprotection = null;
if (collisions != null && collisions.Contains (method.Name)) {
oname = method.Name;
oprotection = method.Protection;
method.Name = QualifiedName + "." + method.Name;
method.Protection = "";
}
method.Generate (gen_info, implementor);
if (oname != null) {
method.Name = oname;
method.Protection = oprotection;
}
else
Console.WriteLine("in Object " + QualifiedName);
}
}
@ -357,19 +409,16 @@ namespace GtkSharp.Generation {
clash_map = new Hashtable();
foreach (Ctor ctor in ctors) {
if (ctor.Validate ()) {
if (clash_map.Contains (ctor.Signature.Types)) {
Ctor clash = clash_map [ctor.Signature.Types] as Ctor;
Ctor alter = ctor.Preferred ? clash : ctor;
alter.IsStatic = true;
if (Parent != null && Parent.HasStaticCtor (alter.StaticName))
alter.Modifiers = "new ";
} else
clash_map [ctor.Signature.Types] = ctor;
valid_ctors.Add (ctor);
if (clash_map.Contains (ctor.Signature.Types)) {
Ctor clash = clash_map [ctor.Signature.Types] as Ctor;
Ctor alter = ctor.Preferred ? clash : ctor;
alter.IsStatic = true;
if (Parent != null && Parent.HasStaticCtor (alter.StaticName))
alter.Modifiers = "new ";
} else
Console.WriteLine("in Type " + QualifiedName);
clash_map [ctor.Signature.Types] = ctor;
valid_ctors.Add (ctor);
}
ctors = valid_ctors;

View File

@ -89,6 +89,16 @@ namespace GtkSharp.Generation {
gens.AddRange (curr_gens);
}
// Now that everything is loaded, validate all the to-be-
// generated generatables and then remove the invalid ones.
ArrayList invalids = new ArrayList ();
foreach (IGeneratable gen in gens) {
if (!gen.Validate ())
invalids.Add (gen);
}
foreach (IGeneratable gen in invalids)
gens.Remove (gen);
GenerationInfo gen_info = null;
if (dir != "" || assembly_name != "" || glue_filename != "" || glue_includes != "" || gluelib_name != "")
gen_info = new GenerationInfo (dir, custom_dir, assembly_name, glue_filename, glue_includes, gluelib_name);

View File

@ -50,7 +50,11 @@ namespace GtkSharp.Generation {
}
}
public override bool Validate ()
{
return true;
}
public override string MarshalType {
get {
return "int";

View File

@ -116,6 +116,8 @@ namespace GtkSharp.Generation {
return CallByName (var);
}
public abstract bool Validate ();
public void Generate ()
{
GenerationInfo geninfo = new GenerationInfo (ns);

View File

@ -56,6 +56,8 @@ namespace GtkSharp.Generation {
// Generates an expression to convert var to ToNativeReturnType
string ToNativeReturn (string var);
bool Validate ();
void Generate ();
void Generate (GenerationInfo gen_info);

View File

@ -171,11 +171,8 @@ namespace GtkSharp.Generation {
sw.WriteLine ();
sw.WriteLine ("\t\t// signals");
foreach (Signal sig in sigs.Values) {
if (sig.Validate ()) {
sig.GenerateDecl (sw);
sig.GenEventHandler (gen_info);
} else
Console.WriteLine ("of interface " + QualifiedName);
sig.GenerateDecl (sw);
sig.GenEventHandler (gen_info);
}
}
@ -204,17 +201,14 @@ namespace GtkSharp.Generation {
//if (IgnoreMethod (method))
//continue;
if (method.Validate ()) {
if (!vm_decls.Contains (method.Declaration) && method.Name != "GetGType") {
if (need_comment) {
sw.WriteLine ();
sw.WriteLine ("\t\t// non-virtual methods");
need_comment = false;
}
method.GenerateDecl (sw);
if (!vm_decls.Contains (method.Declaration) && method.Name != "GetGType") {
if (need_comment) {
sw.WriteLine ();
sw.WriteLine ("\t\t// non-virtual methods");
need_comment = false;
}
} else
Console.WriteLine ("of interface " + QualifiedName);
method.GenerateDecl (sw);
}
}
}
@ -271,28 +265,18 @@ namespace GtkSharp.Generation {
sw.WriteLine ();
foreach (Signal sig in sigs.Values) {
if (sig.Validate ()) {
sig.GenerateDecl (sw);
sig.GenEventHandler (gen_info);
} else
Console.WriteLine ("of interface " + QualifiedName);
sig.GenerateDecl (sw);
sig.GenEventHandler (gen_info);
}
foreach (Method method in methods.Values) {
if (method.Validate ()) {
if (IgnoreMethod (method))
continue;
method.GenerateDecl (sw);
} else
Console.WriteLine ("of interface " + QualifiedName);
if (IgnoreMethod (method))
continue;
method.GenerateDecl (sw);
}
foreach (Property prop in props.Values) {
if (prop.Validate ())
prop.GenerateDecl (sw, "\t\t");
else
Console.WriteLine ("of interface " + QualifiedName);
}
foreach (Property prop in props.Values)
prop.GenerateDecl (sw, "\t\t");
AppendCustom (sw, gen_info.CustomDir);

View File

@ -31,7 +31,6 @@ namespace GtkSharp.Generation {
private ReturnValue retval;
private bool initialized = false;
private string call;
private string name;
private string protection = "public";
@ -90,31 +89,19 @@ namespace GtkSharp.Generation {
}
}
private bool Initialize ()
public override bool Validate ()
{
if (initialized)
return true;
if (!retval.Validate () || !base.Validate ()) {
Console.Write(" in method " + Name + " ");
return false;
}
Parameters parms = Parameters;
is_get = ((((parms.IsAccessor && retval.IsVoid) || (parms.Count == 0 && !retval.IsVoid)) || (parms.Count == 0 && !retval.IsVoid)) && Name.Length > 3 && (Name.StartsWith ("Get") || Name.StartsWith ("Is") || Name.StartsWith ("Has")));
is_set = ((parms.IsAccessor || (parms.VisibleCount == 1 && retval.IsVoid)) && (Name.Length > 3 && Name.Substring(0, 3) == "Set"));
call = "(" + (IsStatic ? "" : container_type.CallByName () + (parms.Count > 0 ? ", " : "")) + Body.GetCallString (is_set) + ")";
initialized = true;
return true;
}
public override bool Validate ()
{
if (!base.Validate () || !Initialize ())
return false;
if (!retval.Validate ()) {
Console.Write(" in method " + Name + " ");
return false;
}
return true;
}
@ -150,7 +137,7 @@ namespace GtkSharp.Generation {
sw.Write("override ");
else if (Name == "GetGType" && container_type is ObjectGen)
sw.Write("new ");
else if (Modifiers == "new " || (dup != null && dup.Initialize () && ((dup.Signature != null && Signature != null && dup.Signature.ToString() == Signature.ToString()) || (dup.Signature == null && Signature == null))))
else if (Modifiers == "new " || (dup != null && ((dup.Signature != null && Signature != null && dup.Signature.ToString() == Signature.ToString()) || (dup.Signature == null && Signature == null))))
sw.Write("new ");
if (is_get || is_set) {
@ -173,16 +160,13 @@ namespace GtkSharp.Generation {
public void GenerateDecl (StreamWriter sw)
{
if (!Initialize ())
return;
if (IsStatic)
return;
if (is_get || is_set)
{
Method comp = GetComplement ();
if (comp != null && comp.Validate () && is_set)
if (comp != null && is_set)
return;
sw.Write("\t\t");
@ -225,9 +209,6 @@ namespace GtkSharp.Generation {
{
Method comp = null;
if (!Initialize ())
return;
gen_info.CurrentMember = Name;
if (implementor != null && IsStatic)
return;
@ -238,13 +219,14 @@ namespace GtkSharp.Generation {
if (Modifiers != "new " && container_type.GetPropertyRecursively (Name.Substring (3)) != null)
return;
comp = GetComplement ();
if (comp != null && comp.Validate () && is_set && Parameters.AccessorReturnType == comp.ReturnType)
return;
if (comp != null && is_set && Parameters.AccessorReturnType != comp.ReturnType)
{
is_set = false;
call = "(Handle, " + Body.GetCallString (false) + ")";
comp = null;
if (comp != null && is_set) {
if (Parameters.AccessorReturnType == comp.ReturnType)
return;
else {
is_set = false;
call = "(Handle, " + Body.GetCallString (false) + ")";
comp = null;
}
}
/* some setters take more than one arg */
if (comp != null && !comp.is_set)

View File

@ -71,6 +71,22 @@ namespace GtkSharp.Generation {
}
}
public override bool Validate ()
{
ArrayList invalids = new ArrayList ();
foreach (ChildProperty prop in childprops.Values) {
if (!prop.Validate ()) {
Console.WriteLine ("in Object " + QualifiedName);
invalids.Add (prop);
}
}
foreach (ChildProperty prop in invalids)
childprops.Remove (prop);
return base.Validate ();
}
private bool DisableVoidCtor {
get {
return Elem.HasAttribute ("disable_void_ctor");
@ -274,12 +290,8 @@ namespace GtkSharp.Generation {
sw.WriteLine ("\t\t\tprotected internal " + Name + "Child (Gtk.Container parent, Gtk.Widget child) : base (parent, child) {}");
sw.WriteLine ("");
foreach (ChildProperty prop in childprops.Values) {
if (prop.Validate ())
prop.Generate (gen_info, "\t\t\t", null);
else
Console.WriteLine("in Object " + QualifiedName);
}
foreach (ChildProperty prop in childprops.Values)
prop.Generate (gen_info, "\t\t\t", null);
sw.WriteLine ("\t\t}");
sw.WriteLine ("");

View File

@ -86,7 +86,7 @@ namespace GtkSharp.Generation {
if (getter == null) {
getter = container_type.GetMethod ("Get" + Name);
if (getter != null && getter.Name == "Get" + Name &&
getter.Validate () && getter.IsGetter)
getter.IsGetter)
cstype = getter.ReturnType;
else
getter = null;
@ -101,7 +101,7 @@ namespace GtkSharp.Generation {
if (setter == null) {
setter = container_type.GetMethod ("Set" + Name);
if (setter != null && setter.Name == "Set" + Name &&
setter.Validate () && setter.IsSetter)
setter.IsSetter)
cstype = setter.Signature.Types;
else
setter = null;

View File

@ -96,6 +96,11 @@ namespace GtkSharp.Generation {
return CallByName (var);
}
public bool Validate ()
{
return true;
}
public void Generate ()
{
}

View File

@ -131,7 +131,7 @@ namespace GtkSharp.Generation {
}
}
public bool Validate ()
public override bool Validate ()
{
foreach (StructField field in fields) {
if (!field.Validate ()) {
@ -141,7 +141,7 @@ namespace GtkSharp.Generation {
}
}
return true;
return base.Validate ();
}
public override void Generate (GenerationInfo gen_info)

View File

@ -33,9 +33,6 @@ namespace GtkSharp.Generation {
{
gen_info.CurrentType = Name;
if (!Validate ())
return;
StreamWriter sw = gen_info.Writer = gen_info.OpenStream (Name);
base.Generate (gen_info);
if (GetMethod ("GetType") == null && GetMethod ("GetGType") == null) {

View File

@ -111,7 +111,7 @@ namespace GtkSharp.Generation {
AddType (new SimpleGen ("GC", "IntPtr"));
AddType (new SimpleGen ("GError", "IntPtr"));
AddType (new SimpleGen ("GMemChunk", "IntPtr"));
AddType (new SimpleGen ("GPtrArray", "IntPtr[]"));
AddType (new SimpleGen ("GPtrArray", "IntPtr"));
AddType (new SimpleGen ("GTimeVal", "IntPtr"));
AddType (new SimpleGen ("GClosure", "IntPtr"));
AddType (new SimpleGen ("GArray", "IntPtr"));