-
Notifications
You must be signed in to change notification settings - Fork 498
/
FixParameterUsageFromComments.cs
121 lines (95 loc) · 3.22 KB
/
FixParameterUsageFromComments.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
using CppSharp.AST;
using System;
namespace CppSharp.Passes
{
/// <summary>
/// This pass will look through semantic comments (Doxygen) in the source code
/// and fix the parameter usage (out or ref) if that information is available.
/// </summary>
public class FixParameterUsageFromComments : TranslationUnitPass, ICommentVisitor<bool>
{
Method currentMethod;
public override bool VisitMethodDecl(Method method)
{
if (method.Comment == null || method.Comment.FullComment == null)
return base.VisitMethodDecl(method);
Method previousMethod = currentMethod;
currentMethod = method;
var fullComment = method.Comment.FullComment;
VisitFull(fullComment);
currentMethod = previousMethod;
return base.VisitMethodDecl(method);
}
static ParameterUsage GetParameterUsageFromDirection(ParamCommandComment.PassDirection dir)
{
switch (dir)
{
case ParamCommandComment.PassDirection.In:
return ParameterUsage.In;
case ParamCommandComment.PassDirection.InOut:
return ParameterUsage.InOut;
case ParamCommandComment.PassDirection.Out:
return ParameterUsage.Out;
}
throw new NotSupportedException("Unknown parameter pass direction");
}
public bool VisitParamCommand(ParamCommandComment comment)
{
if (comment.Direction == ParamCommandComment.PassDirection.In)
return false;
if (!comment.IsParamIndexValid)
return false;
var parameter = currentMethod.Parameters[(int)comment.ParamIndex];
parameter.Usage = GetParameterUsageFromDirection(comment.Direction);
return true;
}
public bool VisitFull(FullComment comment)
{
foreach (var block in comment.Blocks)
block.Visit(this);
return true;
}
#region Comments visitor stubs
public bool VisitBlockCommand(BlockCommandComment comment)
{
return true;
}
public bool VisitParagraphCommand(ParagraphComment comment)
{
return true;
}
public bool VisitTParamCommand(TParamCommandComment comment)
{
return true;
}
public bool VisitVerbatimBlock(VerbatimBlockComment comment)
{
return true;
}
public bool VisitVerbatimLine(VerbatimLineComment comment)
{
return true;
}
public bool VisitHTMLStartTag(HTMLStartTagComment comment)
{
return true;
}
public bool VisitHTMLEndTag(HTMLEndTagComment comment)
{
return true;
}
public bool VisitText(TextComment comment)
{
return true;
}
public bool VisitInlineCommand(InlineCommandComment comment)
{
return true;
}
public bool VisitVerbatimBlockLine(VerbatimBlockLineComment comment)
{
return true;
}
#endregion
}
}