Browse Source

Added a new block policy to only generate a block if the following is not empty.

pull/155/head
triton 12 years ago
parent
commit
86c651625c
  1. 20
      src/Generator/Generators/Template.cs

20
src/Generator/Generators/Template.cs

@ -10,7 +10,8 @@ namespace CppSharp.Generators @@ -10,7 +10,8 @@ namespace CppSharp.Generators
{
Never,
Always,
BeforeNextBlock
BeforeNextBlock,
IfNotEmpty
}
public class BlockKind
@ -87,10 +88,27 @@ namespace CppSharp.Generators @@ -87,10 +88,27 @@ namespace CppSharp.Generators
uint totalIndent = 0;
Block previousBlock = null;
var blockIndex = 0;
foreach (var childBlock in Blocks)
{
var childText = childBlock.Generate(options);
var nextBlock = (++blockIndex < Blocks.Count)
? Blocks[blockIndex]
: null;
var skipBlock = false;
if (nextBlock != null)
{
var nextText = nextBlock.Generate(options);
if (string.IsNullOrEmpty(nextText) &&
childBlock.NewLineKind == NewLineKind.IfNotEmpty)
skipBlock = true;
}
if (skipBlock)
continue;
if (string.IsNullOrEmpty(childText))
continue;

Loading…
Cancel
Save