Remove TextGenerator class and re-use the one from CppSharp.
This commit is contained in:
Родитель
80279928ba
Коммит
378de9762c
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using CppSharp;
|
||||
using CppSharp.AST;
|
||||
using CppSharp.Generators;
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using CppSharp.AST;
|
||||
using CppSharp;
|
||||
using CppSharp.AST;
|
||||
using CppSharp.Generators;
|
||||
using System.Linq;
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using CppSharp.AST;
|
||||
using CppSharp;
|
||||
using CppSharp.AST;
|
||||
using CppSharp.AST.Extensions;
|
||||
using System.Linq;
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using CppSharp;
|
||||
using CppSharp.AST;
|
||||
using CppSharp.AST.Extensions;
|
||||
using CppSharp.Generators;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using CppSharp;
|
||||
using CppSharp.AST;
|
||||
using CppSharp.Generators;
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using CppSharp.AST;
|
||||
using CppSharp;
|
||||
using CppSharp.AST;
|
||||
using CppSharp.Generators;
|
||||
|
||||
namespace MonoEmbeddinator4000.Generators
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using CppSharp.AST;
|
||||
using CppSharp;
|
||||
using CppSharp.AST;
|
||||
using CppSharp.Generators;
|
||||
|
||||
namespace MonoEmbeddinator4000.Generators
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using CppSharp.AST;
|
||||
using CppSharp;
|
||||
using CppSharp.AST;
|
||||
using CppSharp.Generators;
|
||||
|
||||
namespace MonoEmbeddinator4000.Generators
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using CppSharp.AST;
|
||||
using CppSharp;
|
||||
using CppSharp.AST;
|
||||
using CppSharp.Generators;
|
||||
|
||||
namespace MonoEmbeddinator4000.Generators
|
||||
|
|
|
@ -1,147 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace MonoEmbeddinator4000
|
||||
{
|
||||
public interface ITextGenerator
|
||||
{
|
||||
uint Indent { get; }
|
||||
void Write(string msg, params object[] args);
|
||||
void WriteLine(string msg, params object[] args);
|
||||
void WriteLineIndent(string msg, params object[] args);
|
||||
void NewLine();
|
||||
void NewLineIfNeeded();
|
||||
void NeedNewLine();
|
||||
void ResetNewLine();
|
||||
void PushIndent(uint indent = TextGenerator.DefaultIndent);
|
||||
void PopIndent();
|
||||
void WriteStartBraceIndent();
|
||||
void WriteCloseBraceIndent();
|
||||
}
|
||||
|
||||
public class TextGenerator : ITextGenerator
|
||||
{
|
||||
public const uint DefaultIndent = 4;
|
||||
|
||||
public StringBuilder StringBuilder;
|
||||
protected bool IsStartOfLine;
|
||||
protected bool NeedsNewLine;
|
||||
protected readonly Stack<uint> CurrentIndent;
|
||||
|
||||
public uint Indent
|
||||
{
|
||||
get { return (uint)CurrentIndent.Sum(u => (int)u); }
|
||||
}
|
||||
|
||||
public TextGenerator()
|
||||
{
|
||||
StringBuilder = new StringBuilder();
|
||||
IsStartOfLine = false;
|
||||
CurrentIndent = new Stack<uint>();
|
||||
}
|
||||
|
||||
public TextGenerator(TextGenerator generator)
|
||||
{
|
||||
StringBuilder = new StringBuilder(generator);
|
||||
IsStartOfLine = generator.IsStartOfLine;
|
||||
NeedsNewLine = generator.NeedsNewLine;
|
||||
CurrentIndent = new Stack<uint>(generator.CurrentIndent);
|
||||
}
|
||||
|
||||
public TextGenerator Clone()
|
||||
{
|
||||
return new TextGenerator(this);
|
||||
}
|
||||
|
||||
public void Write(string msg, params object[] args)
|
||||
{
|
||||
if (string.IsNullOrEmpty(msg))
|
||||
return;
|
||||
|
||||
if (args.Length > 0)
|
||||
msg = string.Format(msg, args);
|
||||
|
||||
foreach (var line in msg.SplitAndKeep(Environment.NewLine))
|
||||
{
|
||||
if (IsStartOfLine && !string.IsNullOrWhiteSpace(line))
|
||||
StringBuilder.Append(new string(' ', (int)CurrentIndent.Sum(u => u)));
|
||||
|
||||
if (line.Length > 0)
|
||||
IsStartOfLine = line.EndsWith(Environment.NewLine);
|
||||
|
||||
StringBuilder.Append(line);
|
||||
}
|
||||
}
|
||||
|
||||
public void WriteLine(string msg, params object[] args)
|
||||
{
|
||||
Write(msg, args);
|
||||
NewLine();
|
||||
}
|
||||
|
||||
public void WriteLineIndent(string msg, params object[] args)
|
||||
{
|
||||
PushIndent();
|
||||
WriteLine(msg, args);
|
||||
PopIndent();
|
||||
}
|
||||
|
||||
public void NewLine()
|
||||
{
|
||||
StringBuilder.AppendLine(string.Empty);
|
||||
IsStartOfLine = true;
|
||||
}
|
||||
|
||||
public void NewLineIfNeeded()
|
||||
{
|
||||
if (!NeedsNewLine) return;
|
||||
|
||||
NewLine();
|
||||
NeedsNewLine = false;
|
||||
}
|
||||
|
||||
public void NeedNewLine()
|
||||
{
|
||||
NeedsNewLine = true;
|
||||
}
|
||||
|
||||
public void ResetNewLine()
|
||||
{
|
||||
NeedsNewLine = false;
|
||||
}
|
||||
|
||||
public void PushIndent(uint indent = DefaultIndent)
|
||||
{
|
||||
CurrentIndent.Push(indent);
|
||||
}
|
||||
|
||||
public void PopIndent()
|
||||
{
|
||||
CurrentIndent.Pop();
|
||||
}
|
||||
|
||||
public void WriteStartBraceIndent()
|
||||
{
|
||||
WriteLine("{");
|
||||
PushIndent();
|
||||
}
|
||||
|
||||
public void WriteCloseBraceIndent()
|
||||
{
|
||||
PopIndent();
|
||||
WriteLine("}");
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return StringBuilder.ToString();
|
||||
}
|
||||
|
||||
public static implicit operator string(TextGenerator tg)
|
||||
{
|
||||
return tg.ToString();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -140,9 +140,6 @@
|
|||
<Compile Include="../../binder/Utils/TargetFramework.cs">
|
||||
<Link>binder/Utils/TargetFramework.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="../../binder/Utils/TextGenerator.cs">
|
||||
<Link>binder/Utils/TextGenerator.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="../../binder/Utils/Utils.cs">
|
||||
<Link>binder/Utils/Utils.cs</Link>
|
||||
</Compile>
|
||||
|
|
Загрузка…
Ссылка в новой задаче