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:
parent
55a84c70c7
commit
d6678f0587
2 changed files with 32 additions and 21 deletions
|
@ -9,11 +9,15 @@ using System.Collections.Generic;
|
|||
using System.Text;
|
||||
using System.IO;
|
||||
using Bind.Structures;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Bind
|
||||
{
|
||||
class BindStreamWriter : StreamWriter
|
||||
{
|
||||
int indent_level = 0;
|
||||
Regex splitLines = new Regex(System.Environment.NewLine, RegexOptions.Compiled);
|
||||
|
||||
public BindStreamWriter(string file)
|
||||
: base(file)
|
||||
{
|
||||
|
@ -23,37 +27,41 @@ namespace Bind
|
|||
|
||||
public void Indent()
|
||||
{
|
||||
indent = " " + indent;
|
||||
++indent_level;
|
||||
}
|
||||
|
||||
public void Unindent()
|
||||
{
|
||||
if (!String.IsNullOrEmpty(indent))
|
||||
indent = indent.Substring(4);
|
||||
if (indent_level > 0)
|
||||
--indent_level;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
base.WriteLine(indent + value);
|
||||
for (int i = indent_level; i > 0; i--)
|
||||
base.Write(" ");
|
||||
|
||||
base.WriteLine(value);
|
||||
}
|
||||
|
||||
public void Write(Bind.Structures.Enum e)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder(e.ToString());
|
||||
sb.Replace(System.Environment.NewLine, System.Environment.NewLine + indent);
|
||||
Write(sb);
|
||||
foreach (string s in splitLines.Split(e.ToString()))
|
||||
WriteLine(s);
|
||||
}
|
||||
|
||||
public void Write(Bind.Structures.Function f)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder(f.ToString());
|
||||
sb.Replace(System.Environment.NewLine, System.Environment.NewLine + indent);
|
||||
Write(sb);
|
||||
foreach (string s in splitLines.Split(f.ToString()))
|
||||
WriteLine(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -562,14 +562,16 @@ namespace Bind.GL2
|
|||
{
|
||||
sw.WriteLine("namespace {0}", Settings.OutputNamespace);
|
||||
sw.WriteLine("{");
|
||||
|
||||
sw.Indent();
|
||||
//specWriter.WriteTypes(sw, Bind.Structures.Type.CSTypes);
|
||||
|
||||
sw.WriteLine("using System;");
|
||||
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("}");
|
||||
}
|
||||
using (BindStreamWriter sw = new BindStreamWriter(Path.Combine(Settings.OutputPath, importsFile)))
|
||||
|
@ -606,7 +608,7 @@ namespace Bind.GL2
|
|||
|
||||
#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));
|
||||
|
||||
|
@ -635,7 +637,7 @@ namespace Bind.GL2
|
|||
sw.WriteLine("internal {0};", d.ToString());
|
||||
// --- Workaround for mono gmcs 1.2.4 issue, where static initalization fails. ---
|
||||
sw.WriteLine(
|
||||
"internal {0}static {1} {2}{1} = null;",
|
||||
"internal {0}static {1} {2}{1};", // = null
|
||||
d.Unsafe ? "unsafe " : "",
|
||||
d.Name,
|
||||
Settings.FunctionPrefix);
|
||||
|
@ -643,12 +645,13 @@ namespace Bind.GL2
|
|||
}
|
||||
sw.Unindent();
|
||||
sw.WriteLine("}");
|
||||
|
||||
sw.Unindent();
|
||||
sw.WriteLine("}");
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region void WriteImports
|
||||
|
||||
public virtual void WriteImports(BindStreamWriter sw, DelegateCollection delegates)
|
||||
|
@ -687,7 +690,7 @@ namespace Bind.GL2
|
|||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region void WriteWrappers
|
||||
|
||||
public void WriteWrappers(BindStreamWriter sw, FunctionCollection wrappers, Dictionary<string, string> CSTypes)
|
||||
|
@ -741,7 +744,7 @@ namespace Bind.GL2
|
|||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region void WriteTypes
|
||||
|
||||
public void WriteTypes(BindStreamWriter sw, Dictionary<string, string> CSTypes)
|
||||
|
|
Loading…
Reference in a new issue