@@ -65,9 +65,8 @@ func (p *CTagsParser) prototypeAndCodeDontMatch(tag *types.CTag) bool {
65
65
66
66
code := removeSpacesAndTabs (tag .Code )
67
67
68
- // original code is multi-line, which tags doesn't have - could we find this code in the
69
- // original source file, for purposes of checking here?
70
68
if strings .Index (code , ")" ) == - 1 {
69
+ // Add to code non-whitespace non-comments tokens until we find a closing round bracket
71
70
file , err := os .Open (tag .Filename )
72
71
if err == nil {
73
72
defer file .Close ()
@@ -81,18 +80,19 @@ func (p *CTagsParser) prototypeAndCodeDontMatch(tag *types.CTag) bool {
81
80
}
82
81
83
82
// read up to 10 lines in search of a closing paren
84
- newcode := scanner .Text ()
85
- for scanner .Scan () && line < (tag .Line + 10 ) && strings .Index (newcode , ")" ) == - 1 {
86
- newcode += scanner .Text ()
87
- }
83
+ multilinecomment := false
84
+ temp := ""
88
85
89
- // don't bother replacing the code text if we haven't found a closing paren
90
- if strings .Index (newcode , ")" ) != - 1 {
91
- code = removeSpacesAndTabs (newcode )
86
+ code , multilinecomment = removeComments (scanner .Text (), multilinecomment )
87
+ for scanner .Scan () && line < (tag .Line + 10 ) && strings .Index (temp , ")" ) == - 1 {
88
+ temp , multilinecomment = removeComments (scanner .Text (), multilinecomment )
89
+ code += temp
92
90
}
93
91
}
94
92
}
95
93
94
+ code = removeSpacesAndTabs (code )
95
+
96
96
prototype := removeSpacesAndTabs (tag .Prototype )
97
97
prototype = removeTralingSemicolon (prototype )
98
98
@@ -150,30 +150,7 @@ func getFunctionProtoWithNPreviousCharacters(tag *types.CTag, code string, n int
150
150
line = line - 1
151
151
text := textBuffer [line ]
152
152
153
- // Remove C++ style comments
154
- if strings .Index (text , "//" ) != - 1 {
155
- text = text [0 :strings .Index (text , "//" )]
156
- }
157
-
158
- // Remove C style comments
159
- if strings .Index (text , "*/" ) != - 1 {
160
- if strings .Index (text , "/*" ) != - 1 {
161
- // C style comments on the same line
162
- text = text [0 :strings .Index (text , "/*" )] + text [strings .Index (text , "*/" )+ 1 :len (text )- 1 ]
163
- } else {
164
- text = text [strings .Index (text , "*/" )+ 1 : len (text )- 1 ]
165
- multilinecomment = true
166
- }
167
- }
168
-
169
- if multilinecomment {
170
- if strings .Index (text , "/*" ) != - 1 {
171
- text = text [0 :strings .Index (text , "/*" )]
172
- multilinecomment = false
173
- } else {
174
- text = ""
175
- }
176
- }
153
+ text , multilinecomment = removeComments (text , multilinecomment )
177
154
178
155
code = text + code
179
156
code = removeSpacesAndTabs (code )
@@ -182,6 +159,34 @@ func getFunctionProtoWithNPreviousCharacters(tag *types.CTag, code string, n int
182
159
return code
183
160
}
184
161
162
+ func removeComments (text string , multilinecomment bool ) (string , bool ) {
163
+ // Remove C++ style comments
164
+ if strings .Index (text , "//" ) != - 1 {
165
+ text = text [0 :strings .Index (text , "//" )]
166
+ }
167
+
168
+ // Remove C style comments
169
+ if strings .Index (text , "*/" ) != - 1 {
170
+ if strings .Index (text , "/*" ) != - 1 {
171
+ // C style comments on the same line
172
+ text = text [0 :strings .Index (text , "/*" )] + text [strings .Index (text , "*/" )+ 1 :len (text )- 1 ]
173
+ } else {
174
+ text = text [strings .Index (text , "*/" )+ 1 : len (text )- 1 ]
175
+ multilinecomment = true
176
+ }
177
+ }
178
+
179
+ if multilinecomment {
180
+ if strings .Index (text , "/*" ) != - 1 {
181
+ text = text [0 :strings .Index (text , "/*" )]
182
+ multilinecomment = false
183
+ } else {
184
+ text = ""
185
+ }
186
+ }
187
+ return text , multilinecomment
188
+ }
189
+
185
190
/* This function scans the source files searching for "extern C" context
186
191
* It save the line numbers in a map filename -> {lines...}
187
192
*/
0 commit comments