private static Symbol SymbolFromClangCursor(ClangCursor cursor)
{
var result = new Symbol();
switch (cursor.Kind)
{
case NClang.CursorKind.CXXAccessSpecifier:
result.Name = "(Access Specifier) " + cursor.CxxAccessSpecifier;
break;
default:
result.Name = cursor.Spelling;
break;
}
result.Kind = (CursorKind)cursor.Kind;
result.BriefComment = cursor.BriefCommentText;
result.TypeDescription = cursor.CursorType?.Spelling;
result.EnumDescription = cursor.EnumConstantDeclValue.ToString();
result.Definition = cursor.Definition.DisplayName;
result.Linkage = (LinkageKind)cursor.Linkage;
result.IsBuiltInType = IsBuiltInType(cursor.CursorType);
result.SymbolType = cursor.CursorType?.Spelling.Replace(" &", "&").Replace(" *", "*") + " ";
result.ResultType = cursor.ResultType?.Spelling;
result.Arguments = new List<ParameterSymbol>();
result.Access = (AccessType)cursor.CxxAccessSpecifier;
result.IsVariadic = cursor.IsVariadic;
switch (result.Kind)
{
case CursorKind.FunctionDeclaration:
case CursorKind.CXXMethod:
case CursorKind.Constructor:
case CursorKind.Destructor:
for (var i = 0; i < cursor.ArgumentCount; i++)
{
var argument = cursor.GetArgument(i);
var arg = new ParameterSymbol();
arg.IsBuiltInType = IsBuiltInType(argument.CursorType);
arg.Name = argument.Spelling;
arg.TypeDescription = argument.CursorType.Spelling;
result.Arguments.Add(arg);
}
if (cursor.IsVariadic)
{
result.Arguments.Last().Name += ", ";
result.Arguments.Add(new ParameterSymbol { Name = "... variadic" });
}
if (cursor.ParsedComment.FullCommentAsXml != null)
{
var documentation = XDocument.Parse(cursor.ParsedComment.FullCommentAsXml);
var function = documentation.Element("Function");
var parameters = function.Element("Parameters");
if (parameters != null)
{
var arguments = parameters.Elements("Parameter");
foreach (var argument in arguments)
{
var isVarArgs = argument.Element("IsVarArg");
var discussion = argument.Element("Discussion");
var paragraph = discussion.Element("Para");
if (isVarArgs != null)
{
result.Arguments.Last().Comment = paragraph.Value;
}
else
{
var inx = argument.Element("Index");
if (inx != null) // This happens when documentation for an argument was left in, but the argument no longer exists.
{
var index = int.Parse(inx.Value);
result.Arguments[index].Comment = paragraph.Value;
}
}
}
}
}
if (result.Arguments.Count == 0)
{
result.Arguments.Add(new ParameterSymbol { Name = "void" });
}
break;
}
return result;
}