Browse Source

Added a generation method for multi-line comments.

pull/769/head
Joao Matos 9 years ago
parent
commit
611aa35750
  1. 58
      src/AST/Comment.cs
  2. 15
      src/Generator/Generators/CodeGenerator.cs

58
src/AST/Comment.cs

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
namespace CppSharp.AST
{
@ -125,6 +126,61 @@ namespace CppSharp.AST @@ -125,6 +126,61 @@ namespace CppSharp.AST
public CommentKind Kind { get; set; }
public abstract void Visit<T>(ICommentVisitor<T> visitor);
public static string GetMultiLineCommentPrologue(RawCommentKind kind)
{
switch (kind)
{
case RawCommentKind.OrdinaryBCPL:
case RawCommentKind.BCPLExcl:
return "//";
case RawCommentKind.OrdinaryC:
case RawCommentKind.JavaDoc:
case RawCommentKind.Qt:
return " *";
case RawCommentKind.BCPLSlash:
return "///";
default:
throw new ArgumentOutOfRangeException();
}
}
public static string GetLineCommentPrologue(RawCommentKind kind)
{
switch (kind)
{
case RawCommentKind.OrdinaryBCPL:
case RawCommentKind.BCPLSlash:
return string.Empty;
case RawCommentKind.OrdinaryC:
return "/*";
case RawCommentKind.BCPLExcl:
return "//!";
case RawCommentKind.JavaDoc:
return "/**";
case RawCommentKind.Qt:
return "/*!";
default:
throw new ArgumentOutOfRangeException();
}
}
public static string GetLineCommentEpilogue(RawCommentKind kind)
{
switch (kind)
{
case RawCommentKind.OrdinaryBCPL:
case RawCommentKind.BCPLSlash:
case RawCommentKind.BCPLExcl:
return string.Empty;
case RawCommentKind.OrdinaryC:
case RawCommentKind.JavaDoc:
case RawCommentKind.Qt:
return " */";
default:
throw new ArgumentOutOfRangeException();
}
}
}
#region Comments

15
src/Generator/Generators/CodeGenerator.cs

@ -40,6 +40,21 @@ namespace CppSharp.Generators @@ -40,6 +40,21 @@ namespace CppSharp.Generators
return base.Generate();
}
public void GenerateMultiLineComment(List<string> lines, RawCommentKind kind)
{
var lineCommentPrologue = Comment.GetLineCommentPrologue(kind);
if (!string.IsNullOrWhiteSpace(lineCommentPrologue))
WriteLine("{0}", lineCommentPrologue);
var multiLineCommentPrologue = Comment.GetMultiLineCommentPrologue(kind);
foreach (var line in lines)
WriteLine("{0} {1}", multiLineCommentPrologue, line);
var lineCommentEpilogue = Comment.GetLineCommentEpilogue(kind);
if (!string.IsNullOrWhiteSpace(lineCommentEpilogue))
WriteLine("{0}", lineCommentEpilogue);
}
public virtual void GenerateFilePreamble()
{
PushBlock(BlockKind.Header);

Loading…
Cancel
Save