Browse Source

Factor common declaration and comment handling functionality to base code generator.

pull/778/head
Joao Matos 9 years ago
parent
commit
fa565a1e09
  1. 62
      src/Generator/Generators/CSharp/CSharpSources.cs
  2. 64
      src/Generator/Generators/CodeGenerator.cs

62
src/Generator/Generators/CSharp/CSharpSources.cs

@ -5,7 +5,6 @@ using System.IO; @@ -5,7 +5,6 @@ using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Web.Util;
using CppSharp.AST;
using CppSharp.AST.Extensions;
using CppSharp.Types;
@ -338,69 +337,14 @@ namespace CppSharp.Generators.CSharp @@ -338,69 +337,14 @@ namespace CppSharp.Generators.CSharp
}
}
public void GenerateDeclarationCommon(Declaration decl)
public override void GenerateDeclarationCommon(Declaration decl)
{
if (decl.Comment != null)
{
GenerateComment(decl.Comment);
GenerateDebug(decl);
}
base.GenerateDeclarationCommon(decl);
foreach (Attribute attribute in decl.Attributes)
WriteLine("[{0}({1})]", attribute.Type.FullName, attribute.Value);
}
public void GenerateDebug(Declaration decl)
{
if (Options.GenerateDebugOutput && !string.IsNullOrWhiteSpace(decl.DebugText))
WriteLine("// DEBUG: " + decl.DebugText);
}
public void GenerateComment(RawComment comment)
{
if (comment.FullComment != null)
{
PushBlock(BlockKind.BlockComment);
WriteLine(comment.FullComment.CommentToString(Options.CommentPrefix));
PopBlock();
return;
}
if (string.IsNullOrWhiteSpace(comment.BriefText))
return;
PushBlock(BlockKind.BlockComment);
WriteLine("{0} <summary>", Options.CommentPrefix);
foreach (string line in HtmlEncoder.HtmlEncode(comment.BriefText).Split(
Environment.NewLine.ToCharArray()))
WriteLine("{0} <para>{1}</para>", Options.CommentPrefix, line);
WriteLine("{0} </summary>", Options.CommentPrefix);
PopBlock();
}
public void GenerateInlineSummary(RawComment comment)
{
if (comment == null) return;
if (string.IsNullOrWhiteSpace(comment.BriefText))
return;
PushBlock(BlockKind.InlineComment);
if (comment.BriefText.Contains("\n"))
{
WriteLine("{0} <summary>", Options.CommentPrefix);
foreach (string line in HtmlEncoder.HtmlEncode(comment.BriefText).Split(
Environment.NewLine.ToCharArray()))
WriteLine("{0} <para>{1}</para>", Options.CommentPrefix, line);
WriteLine("{0} </summary>", Options.CommentPrefix);
}
else
{
WriteLine("{0} <summary>{1}</summary>", Options.CommentPrefix, comment.BriefText);
}
PopBlock();
}
#region Classes
public override bool VisitClassDecl(Class @class)
@ -3053,7 +2997,7 @@ namespace CppSharp.Generators.CSharp @@ -3053,7 +2997,7 @@ namespace CppSharp.Generators.CSharp
if (@enum.IsFlags)
WriteLine("[Flags]");
Write(Helpers.GetAccess(@enum.Access));
Write(Helpers.GetAccess(@enum.Access));
// internal P/Invoke declarations must see protected enums
if (@enum.Access == AccessSpecifier.Protected)
Write("internal ");

64
src/Generator/Generators/CodeGenerator.cs

@ -1,6 +1,8 @@ @@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.Web.Util;
using CppSharp.AST;
using CppSharp.Generators.CSharp;
namespace CppSharp.Generators
{
@ -40,7 +42,67 @@ namespace CppSharp.Generators @@ -40,7 +42,67 @@ namespace CppSharp.Generators
return base.Generate();
}
public void GenerateMultiLineComment(List<string> lines, CommentKind kind)
public virtual void GenerateDeclarationCommon(Declaration decl)
{
if (decl.Comment != null)
{
GenerateComment(decl.Comment);
GenerateDebug(decl);
}
}
public virtual void GenerateDebug(Declaration decl)
{
if (Options.GenerateDebugOutput && !string.IsNullOrWhiteSpace(decl.DebugText))
WriteLine("// DEBUG: " + decl.DebugText);
}
public void GenerateInlineSummary(RawComment comment)
{
if (comment == null) return;
if (string.IsNullOrWhiteSpace(comment.BriefText))
return;
PushBlock(BlockKind.InlineComment);
if (comment.BriefText.Contains("\n"))
{
WriteLine("{0} <summary>", Options.CommentPrefix);
foreach (string line in HtmlEncoder.HtmlEncode(comment.BriefText).Split(
Environment.NewLine.ToCharArray()))
WriteLine("{0} <para>{1}</para>", Options.CommentPrefix, line);
WriteLine("{0} </summary>", Options.CommentPrefix);
}
else
{
WriteLine("{0} <summary>{1}</summary>", Options.CommentPrefix, comment.BriefText);
}
PopBlock();
}
public virtual void GenerateComment(RawComment comment)
{
if (comment.FullComment != null)
{
PushBlock(BlockKind.BlockComment);
WriteLine(comment.FullComment.CommentToString(Options.CommentPrefix));
PopBlock();
return;
}
if (string.IsNullOrWhiteSpace(comment.BriefText))
return;
PushBlock(BlockKind.BlockComment);
WriteLine("{0} <summary>", Options.CommentPrefix);
foreach (string line in HtmlEncoder.HtmlEncode(comment.BriefText).Split(
Environment.NewLine.ToCharArray()))
WriteLine("{0} <para>{1}</para>", Options.CommentPrefix, line);
WriteLine("{0} </summary>", Options.CommentPrefix);
PopBlock();
}
public virtual void GenerateMultiLineComment(List<string> lines, CommentKind kind)
{
var lineCommentPrologue = Comment.GetLineCommentPrologue(kind);
if (!string.IsNullOrWhiteSpace(lineCommentPrologue))

Loading…
Cancel
Save