diff --git a/src/AST/Comment.cs b/src/AST/Comment.cs
index 578fab67..b654c97c 100644
--- a/src/AST/Comment.cs
+++ b/src/AST/Comment.cs
@@ -25,6 +25,25 @@ namespace CppSharp.AST
Merged
}
+ public enum CommentKind
+ {
+ FullComment,
+ BlockContentComment,
+ BlockCommandComment,
+ ParamCommandComment,
+ TParamCommandComment,
+ VerbatimBlockComment,
+ VerbatimLineComment,
+ ParagraphComment,
+ HTMLTagComment,
+ HTMLStartTagComment,
+ HTMLEndTagComment,
+ TextComment,
+ InlineContentComment,
+ InlineCommandComment,
+ VerbatimBlockLineComment,
+ }
+
///
/// Represents a raw C++ comment.
///
@@ -103,6 +122,8 @@ namespace CppSharp.AST
///
public abstract class Comment
{
+ public CommentKind Kind { get; set; }
+
public abstract void Visit(ICommentVisitor visitor);
}
@@ -157,6 +178,7 @@ namespace CppSharp.AST
public BlockCommandComment()
{
+ Kind = CommentKind.BlockCommandComment;
Arguments = new List();
}
@@ -174,6 +196,11 @@ namespace CppSharp.AST
public const uint InvalidParamIndex = ~0U;
public const uint VarArgParamIndex = ~0U/*InvalidParamIndex*/ - 1U;
+ public ParamCommandComment()
+ {
+ Kind = CommentKind.ParamCommandComment;
+ }
+
public enum PassDirection
{
In,
@@ -222,6 +249,7 @@ namespace CppSharp.AST
public TParamCommandComment()
{
+ Kind = CommentKind.TParamCommandComment;
Position = new List();
}
@@ -242,6 +270,7 @@ namespace CppSharp.AST
public VerbatimBlockComment()
{
+ Kind = CommentKind.VerbatimBlockComment;
Lines = new List();
}
@@ -260,6 +289,11 @@ namespace CppSharp.AST
{
public string Text;
+ public VerbatimLineComment()
+ {
+ Kind = CommentKind.VerbatimLineComment;
+ }
+
public override void Visit(ICommentVisitor visitor)
{
visitor.VisitVerbatimLine(this);
@@ -277,6 +311,7 @@ namespace CppSharp.AST
public ParagraphComment()
{
+ Kind = CommentKind.ParagraphComment;
Content = new List();
}
@@ -291,7 +326,10 @@ namespace CppSharp.AST
///
public abstract class InlineContentComment : Comment
{
-
+ protected InlineContentComment()
+ {
+ Kind = CommentKind.InlineContentComment;
+ }
}
///
@@ -302,6 +340,11 @@ namespace CppSharp.AST
public abstract class HTMLTagComment : InlineContentComment
{
public string TagName;
+
+ protected HTMLTagComment()
+ {
+ Kind = CommentKind.HTMLTagComment;
+ }
}
///
@@ -319,6 +362,7 @@ namespace CppSharp.AST
public HTMLStartTagComment()
{
+ Kind = CommentKind.HTMLStartTagComment;
Attributes = new List();
}
@@ -333,6 +377,11 @@ namespace CppSharp.AST
///
public class HTMLEndTagComment : HTMLTagComment
{
+ public HTMLEndTagComment()
+ {
+ Kind = CommentKind.HTMLEndTagComment;
+ }
+
public override void Visit(ICommentVisitor visitor)
{
visitor.VisitHTMLEndTag(this);
@@ -346,6 +395,11 @@ namespace CppSharp.AST
{
public string Text;
+ public TextComment()
+ {
+ Kind = CommentKind.TextComment;
+ }
+
public override void Visit(ICommentVisitor visitor)
{
visitor.VisitText(this);
@@ -370,12 +424,13 @@ namespace CppSharp.AST
RenderEmphasized
}
- public RenderKind Kind;
+ public RenderKind CommentRenderKind;
public List Arguments;
public InlineCommandComment()
{
+ Kind = CommentKind.InlineCommandComment;
Arguments = new List();
}
@@ -392,6 +447,11 @@ namespace CppSharp.AST
{
public string Text;
+ public VerbatimBlockLineComment()
+ {
+ Kind = CommentKind.VerbatimBlockLineComment;
+ }
+
public override void Visit(ICommentVisitor visitor)
{
visitor.VisitVerbatimBlockLine(this);
diff --git a/src/Generator/Generators/CSharp/CSharpCommentPrinter.cs b/src/Generator/Generators/CSharp/CSharpCommentPrinter.cs
new file mode 100644
index 00000000..1b1ba229
--- /dev/null
+++ b/src/Generator/Generators/CSharp/CSharpCommentPrinter.cs
@@ -0,0 +1,85 @@
+using System.Text;
+using System.Web.Util;
+using CppSharp.AST;
+
+namespace CppSharp.Generators.CSharp
+{
+ public static class CSharpCommentPrinter
+ {
+ public static string CommentToString(this Comment comment)
+ {
+ var summaryAdded = false;
+ var remarksAdded = false;
+ return CommentToString(comment, ref summaryAdded, ref remarksAdded).ToString();
+ }
+
+ private static StringBuilder CommentToString(Comment comment,
+ ref bool summaryAdded, ref bool remarksAdded)
+ {
+ var commentBuilder = new StringBuilder();
+ switch (comment.Kind)
+ {
+ case CommentKind.FullComment:
+ var fullComment = (FullComment) comment;
+ foreach (var block in fullComment.Blocks)
+ commentBuilder.Append(CommentToString(block,
+ ref summaryAdded, ref remarksAdded));
+ if (remarksAdded)
+ commentBuilder.Append("");
+ break;
+ case CommentKind.BlockCommandComment:
+ break;
+ case CommentKind.ParamCommandComment:
+ break;
+ case CommentKind.TParamCommandComment:
+ break;
+ case CommentKind.VerbatimBlockComment:
+ break;
+ case CommentKind.VerbatimLineComment:
+ break;
+ case CommentKind.ParagraphComment:
+ var paragraphComment = (ParagraphComment) comment;
+ foreach (var inlineContentComment in paragraphComment.Content)
+ commentBuilder.Append(CommentToString(inlineContentComment,
+ ref summaryAdded, ref remarksAdded));
+ break;
+ case CommentKind.HTMLTagComment:
+ break;
+ case CommentKind.HTMLStartTagComment:
+ break;
+ case CommentKind.HTMLEndTagComment:
+ break;
+ case CommentKind.TextComment:
+ if (!summaryAdded)
+ commentBuilder.AppendLine("");
+ if (summaryAdded && !remarksAdded)
+ {
+ commentBuilder.AppendLine("");
+ remarksAdded = true;
+ }
+ commentBuilder.Append("" + GetText(comment) + "").AppendLine();
+ if (!summaryAdded)
+ {
+ commentBuilder.AppendLine("");
+ summaryAdded = true;
+ }
+ break;
+ case CommentKind.InlineContentComment:
+ break;
+ case CommentKind.InlineCommandComment:
+ break;
+ case CommentKind.VerbatimBlockLineComment:
+ break;
+ }
+ return commentBuilder;
+ }
+
+ private static string GetText(Comment comment)
+ {
+ var textComment = ((TextComment) comment);
+ var text = textComment.Text;
+ return HtmlEncoder.HtmlEncode(
+ text.Length > 1 && text[0] == ' ' && text[1] != ' ' ? text.Substring(1) : text);
+ }
+ }
+}
diff --git a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs
index 51ad1ebb..b201e816 100644
--- a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs
+++ b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs
@@ -306,25 +306,25 @@ namespace CppSharp.Generators.CSharp
public void GenerateComment(RawComment comment)
{
- if (string.IsNullOrWhiteSpace(comment.BriefText))
- return;
-
- PushBlock(BlockKind.BlockComment);
- WriteLine("/// ");
- foreach (string line in HtmlEncoder.HtmlEncode(comment.BriefText).Split(
- Environment.NewLine.ToCharArray()))
- WriteLine("/// {0}", line);
- WriteLine("/// ");
-
- if (!string.IsNullOrWhiteSpace(comment.Text))
+ if (comment.FullComment != null)
{
- WriteLine("/// ");
- foreach (string line in HtmlEncoder.HtmlEncode(comment.Text).Split(
+ PushBlock(BlockKind.BlockComment);
+ WriteLine(comment.FullComment.CommentToString());
+ PopBlock();
+ }
+ else
+ {
+ if (string.IsNullOrWhiteSpace(comment.BriefText))
+ return;
+
+ PushBlock(BlockKind.BlockComment);
+ WriteLine("");
+ foreach (string line in HtmlEncoder.HtmlEncode(comment.BriefText).Split(
Environment.NewLine.ToCharArray()))
- WriteLine("/// {0}", line);
- WriteLine("/// ");
+ WriteLine("{0}", line);
+ WriteLine("");
+ PopBlock();
}
- PopBlock();
}
public void GenerateInlineSummary(RawComment comment)
@@ -337,15 +337,15 @@ namespace CppSharp.Generators.CSharp
PushBlock(BlockKind.InlineComment);
if (comment.BriefText.Contains("\n"))
{
- WriteLine("/// ");
+ WriteLine("{0} ", Options.CommentPrefix);
foreach (string line in HtmlEncoder.HtmlEncode(comment.BriefText).Split(
Environment.NewLine.ToCharArray()))
- WriteLine("/// {0}", line);
- WriteLine("/// ");
+ WriteLine("{0} {1}", Options.CommentPrefix, line);
+ WriteLine("{0} ", Options.CommentPrefix);
}
else
{
- WriteLine("/// {0}", comment.BriefText);
+ WriteLine("{0} {1}", Options.CommentPrefix, comment.BriefText);
}
PopBlock();
}
diff --git a/tests/Common/Common.h b/tests/Common/Common.h
index 3846d929..bfeeacc5 100644
--- a/tests/Common/Common.h
+++ b/tests/Common/Common.h
@@ -927,3 +927,9 @@ template
AbstractTemplate::AbstractTemplate()
{
}
+
+/// Hash set/map base class.
+/** Note that to prevent extra memory use due to vtable pointer, %HashBase intentionally does not declare a virtual destructor
+and therefore %HashBase pointers should never be used.
+*/
+class DLL_API TestComments {};