Browse Source

Optimised code generation when the option for auto-compilation is used.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/593/head
Dimitar Dobrev 10 years ago
parent
commit
c8397166ed
  1. 51
      src/Generator/Generators/Template.cs

51
src/Generator/Generators/Template.cs

@ -161,6 +161,55 @@ namespace CppSharp.Generators
return builder.ToString(); return builder.ToString();
} }
public StringBuilder GenerateUnformatted(DriverOptions options)
{
if (CheckGenerate != null && !CheckGenerate())
return new StringBuilder(0);
if (Blocks.Count == 0)
return Text.StringBuilder;
var builder = new StringBuilder();
Block previousBlock = null;
var blockIndex = 0;
foreach (var childBlock in Blocks)
{
var childText = childBlock.GenerateUnformatted(options);
var nextBlock = (++blockIndex < Blocks.Count)
? Blocks[blockIndex]
: null;
if (nextBlock != null)
{
var nextText = nextBlock.GenerateUnformatted(options);
if (nextText.Length == 0 &&
childBlock.NewLineKind == NewLineKind.IfNotEmpty)
continue;
}
if (childText.Length == 0)
continue;
if (previousBlock != null &&
previousBlock.NewLineKind == NewLineKind.BeforeNextBlock)
builder.AppendLine();
builder.Append(childText);
if (childBlock.NewLineKind == NewLineKind.Always)
builder.AppendLine();
previousBlock = childBlock;
}
if (Text.StringBuilder.Length != 0)
builder.Append(Text.StringBuilder);
return builder;
}
public bool IsEmpty public bool IsEmpty
{ {
get get
@ -267,6 +316,8 @@ namespace CppSharp.Generators
public string Generate() public string Generate()
{ {
if (Options.IsCSharpGenerator && Options.CompileCode)
return RootBlock.GenerateUnformatted(Options).ToString();
return RootBlock.Generate(Options); return RootBlock.Generate(Options);
} }

Loading…
Cancel
Save