From d6678f0587fdc4ea6bcbae04b0409871a053cc19 Mon Sep 17 00:00:00 2001 From: the_fiddler Date: Fri, 21 Sep 2007 19:59:22 +0000 Subject: [PATCH] Enhanced BindStreamWriter.Indent() and Unindent() implementation (they now change a simple counter). Suppressed warning CS0649 (uninitialised field) in generated code for delegates. --- Source/Bind/BindStreamWriter.cs | 30 +++++++++++++++++++----------- Source/Bind/GL2/Generator.cs | 23 +++++++++++++---------- 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/Source/Bind/BindStreamWriter.cs b/Source/Bind/BindStreamWriter.cs index 0ad17268..61be32ad 100644 --- a/Source/Bind/BindStreamWriter.cs +++ b/Source/Bind/BindStreamWriter.cs @@ -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); } } } diff --git a/Source/Bind/GL2/Generator.cs b/Source/Bind/GL2/Generator.cs index 9b29d553..34ab240e 100644 --- a/Source/Bind/GL2/Generator.cs +++ b/Source/Bind/GL2/Generator.cs @@ -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 CSTypes) @@ -741,7 +744,7 @@ namespace Bind.GL2 } #endregion - + #region void WriteTypes public void WriteTypes(BindStreamWriter sw, Dictionary CSTypes)