Skip to content

Commit

Permalink
Basic support for reading documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
qmfrederik committed May 18, 2018
1 parent 38ef66d commit 2eaa12e
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 0 deletions.
80 changes: 80 additions & 0 deletions Core.Clang/Comment.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using System;

namespace Core.Clang
{
public sealed unsafe class Comment
{
internal CXComment Struct { get; }

private Comment(CXComment cxComment)
{
Struct = cxComment;
}

internal static Comment Create(CXComment cxComment)
{
return new Comment(cxComment);
}

public CommentKind Kind
{
get
{
return (CommentKind)NativeMethods.clang_Comment_getKind(Struct);
}
}

public int GetNumChildren()
{
return (int)NativeMethods.clang_Comment_getNumChildren(Struct);
}

public Comment GetChild(int index)
{
CXComment cxComment = NativeMethods.clang_Comment_getChild(Struct, (uint)index);
return Create(cxComment);
}

public string GetText()
{
if (this.Kind != CommentKind.Text)
{
throw new InvalidOperationException();
}

CXString cxString = NativeMethods.clang_TextComment_getText(Struct);
using (var str = new String(cxString))
{
return str.ToString();
}
}

public string GetParamName()
{
if (this.Kind != CommentKind.ParamCommand)
{
throw new InvalidOperationException();
}

CXString cxString = NativeMethods.clang_ParamCommandComment_getParamName(Struct);
using (var str = new String(cxString))
{
return str.ToString();
}
}

public string GetCommandName()
{
if(this.Kind != CommentKind.BlockCommand)
{
throw new InvalidOperationException();
}

CXString cxString = NativeMethods.clang_BlockCommandComment_getCommandName(Struct);
using (var str = new String(cxString))
{
return str.ToString();
}
}
}
}
20 changes: 20 additions & 0 deletions Core.Clang/CommentKind.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace Core.Clang
{
[EnumMapping(typeof(CXCommentKind), Prefix = "CXComment_")]
public enum CommentKind
{
Null,
Text,
InlineCommand,
HTMLStartTag,
HTMLEndTag,
Paragraph,
BlockCommand,
ParamCommand,
TParamCommand,
VerbatimBlockCommand,
VerbatimBlockLine,
VerbatimLine,
FullComment,
}
}
8 changes: 8 additions & 0 deletions Core.Clang/Cursor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1340,6 +1340,14 @@ public Cursor GetSpecializedTemplate()
return Create(cxCursor, TranslationUnit);
}

public Comment GetParsedComment()
{
ThrowIfDisposed();

var cxComment = NativeMethods.clang_Cursor_getParsedComment(Struct);
return Comment.Create(cxComment);
}

/// <summary>
/// For a cursor that references something else, return the source range covering that
/// reference.
Expand Down

0 comments on commit 2eaa12e

Please sign in to comment.