From 611aa35750a2be6ae8f3c9e3680e48ae9cec5d73 Mon Sep 17 00:00:00 2001 From: Joao Matos Date: Thu, 23 Feb 2017 18:09:33 +0000 Subject: [PATCH] Added a generation method for multi-line comments. --- src/AST/Comment.cs | 58 ++++++++++++++++++++++- src/Generator/Generators/CodeGenerator.cs | 15 ++++++ 2 files changed, 72 insertions(+), 1 deletion(-) diff --git a/src/AST/Comment.cs b/src/AST/Comment.cs index fd53245f..933052b6 100644 --- a/src/AST/Comment.cs +++ b/src/AST/Comment.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; namespace CppSharp.AST { @@ -125,6 +126,61 @@ namespace CppSharp.AST public CommentKind Kind { get; set; } public abstract void Visit(ICommentVisitor 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 diff --git a/src/Generator/Generators/CodeGenerator.cs b/src/Generator/Generators/CodeGenerator.cs index f9835cf3..bb16b535 100644 --- a/src/Generator/Generators/CodeGenerator.cs +++ b/src/Generator/Generators/CodeGenerator.cs @@ -40,6 +40,21 @@ namespace CppSharp.Generators return base.Generate(); } + public void GenerateMultiLineComment(List 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);