Enhanced BindStreamWriter.Indent() and Unindent() implementation (they now change a simple counter).

Suppressed warning CS0649 (uninitialised field) in generated code for delegates.
This commit is contained in:
the_fiddler 2007-09-21 19:59:22 +00:00
parent 55a84c70c7
commit d6678f0587
2 changed files with 32 additions and 21 deletions

View file

@ -9,11 +9,15 @@ using System.Collections.Generic;
using System.Text; using System.Text;
using System.IO; using System.IO;
using Bind.Structures; using Bind.Structures;
using System.Text.RegularExpressions;
namespace Bind namespace Bind
{ {
class BindStreamWriter : StreamWriter class BindStreamWriter : StreamWriter
{ {
int indent_level = 0;
Regex splitLines = new Regex(System.Environment.NewLine, RegexOptions.Compiled);
public BindStreamWriter(string file) public BindStreamWriter(string file)
: base(file) : base(file)
{ {
@ -23,37 +27,41 @@ namespace Bind
public void Indent() public void Indent()
{ {
indent = " " + indent; ++indent_level;
} }
public void Unindent() public void Unindent()
{ {
if (!String.IsNullOrEmpty(indent)) if (indent_level > 0)
indent = indent.Substring(4); --indent_level;
} }
public override void Write(string value) public override void Write(string value)
{ {
base.Write(indent + value); for (int i = indent_level; i > 0; i--)
base.Write(" ");
base.Write(value);
} }
public override void WriteLine(string value) public override void WriteLine(string value)
{ {
base.WriteLine(indent + value); for (int i = indent_level; i > 0; i--)
base.Write(" ");
base.WriteLine(value);
} }
public void Write(Bind.Structures.Enum e) public void Write(Bind.Structures.Enum e)
{ {
StringBuilder sb = new StringBuilder(e.ToString()); foreach (string s in splitLines.Split(e.ToString()))
sb.Replace(System.Environment.NewLine, System.Environment.NewLine + indent); WriteLine(s);
Write(sb);
} }
public void Write(Bind.Structures.Function f) public void Write(Bind.Structures.Function f)
{ {
StringBuilder sb = new StringBuilder(f.ToString()); foreach (string s in splitLines.Split(f.ToString()))
sb.Replace(System.Environment.NewLine, System.Environment.NewLine + indent); WriteLine(s);
Write(sb);
} }
} }
} }

View file

@ -562,14 +562,16 @@ namespace Bind.GL2
{ {
sw.WriteLine("namespace {0}", Settings.OutputNamespace); sw.WriteLine("namespace {0}", Settings.OutputNamespace);
sw.WriteLine("{"); sw.WriteLine("{");
sw.Indent(); sw.Indent();
//specWriter.WriteTypes(sw, Bind.Structures.Type.CSTypes);
sw.WriteLine("using System;"); sw.WriteLine("using System;");
sw.WriteLine("using System.Runtime.InteropServices;"); sw.WriteLine("using System.Runtime.InteropServices;");
WriteDelegates(sw, Bind.Structures.Delegate.Delegates);
sw.Unindent();
sw.WriteLine("#pragma warning disable 0649");
WriteDelegates(sw, Bind.Structures.Delegate.Delegates);
sw.WriteLine("#pragma warning restore 0649");
sw.Unindent();
sw.WriteLine("}"); sw.WriteLine("}");
} }
using (BindStreamWriter sw = new BindStreamWriter(Path.Combine(Settings.OutputPath, importsFile))) using (BindStreamWriter sw = new BindStreamWriter(Path.Combine(Settings.OutputPath, importsFile)))
@ -606,7 +608,7 @@ namespace Bind.GL2
#region void WriteDelegates #region void WriteDelegates
public void WriteDelegates(BindStreamWriter sw, DelegateCollection delegates) public virtual void WriteDelegates(BindStreamWriter sw, DelegateCollection delegates)
{ {
Trace.WriteLine(String.Format("Writing delegates to {0}.{1}", Settings.OutputNamespace, Settings.DelegatesClass)); Trace.WriteLine(String.Format("Writing delegates to {0}.{1}", Settings.OutputNamespace, Settings.DelegatesClass));
@ -635,7 +637,7 @@ namespace Bind.GL2
sw.WriteLine("internal {0};", d.ToString()); sw.WriteLine("internal {0};", d.ToString());
// --- Workaround for mono gmcs 1.2.4 issue, where static initalization fails. --- // --- Workaround for mono gmcs 1.2.4 issue, where static initalization fails. ---
sw.WriteLine( sw.WriteLine(
"internal {0}static {1} {2}{1} = null;", "internal {0}static {1} {2}{1};", // = null
d.Unsafe ? "unsafe " : "", d.Unsafe ? "unsafe " : "",
d.Name, d.Name,
Settings.FunctionPrefix); Settings.FunctionPrefix);
@ -643,6 +645,7 @@ namespace Bind.GL2
} }
sw.Unindent(); sw.Unindent();
sw.WriteLine("}"); sw.WriteLine("}");
sw.Unindent(); sw.Unindent();
sw.WriteLine("}"); sw.WriteLine("}");
} }