@@ -99,19 +99,26 @@ func findLinesWithExternCScope(tag *types.CTag, ctx *types.Context) {
99
99
scanner := bufio .NewScanner (file )
100
100
101
101
inExternCNamespaceScope := false
102
+ decidingExternScope := false
102
103
indentLevels := 0
103
104
line := 0
104
105
for scanner .Scan () {
105
106
line ++
106
107
str := scanner .Text ()
107
- if strings .Contains (str , EXTERN ) {
108
+ if decidingExternScope == true && len (removeSpacesAndTabs (str )) > 0 {
109
+ decidingExternScope = false
110
+ }
111
+ if strings .Contains (removeSpacesAndTabs (str ), removeSpacesAndTabs (EXTERN )) {
108
112
inExternCNamespaceScope = true
113
+ if len (removeSpacesAndTabs (str )) == len (removeSpacesAndTabs (EXTERN )) {
114
+ decidingExternScope = true
115
+ }
109
116
}
110
117
if inExternCNamespaceScope == true {
111
118
ctx .LinesInExternCContext [tag .Filename ] = append (ctx .LinesInExternCContext [tag .Filename ], line )
112
119
}
113
120
indentLevels += strings .Count (str , "{" ) - strings .Count (str , "}" )
114
- if indentLevels == 0 {
121
+ if indentLevels == 0 && decidingExternScope == false {
115
122
inExternCNamespaceScope = false
116
123
}
117
124
}
@@ -247,7 +254,7 @@ func prototypeAndCodeDontMatch(tag *types.CTag) bool {
247
254
// what could possibly go wrong?
248
255
// definition is multiline
249
256
250
- // Phase 1: add to code n non-whitespace tokens before the code line
257
+ // Phase 1: add to code n non-whitespace non-comments tokens before the code line
251
258
code = removeEverythingAfterClosingPerentheses (code )
252
259
253
260
// is the code contained in the prototype?
@@ -269,22 +276,46 @@ func getFunctionPrototypWithNPreviousCharacter(tag *types.CTag, code string, n i
269
276
defer file .Close ()
270
277
271
278
scanner := bufio .NewScanner (file )
272
- line := 1
273
- iteration := 1
279
+ line := 0
280
+ multilinecomment := false
281
+ var textBuffer []string
274
282
275
- for len (code ) < expectedPrototypeLen {
283
+ // skip lines until we get to the start of this tag
284
+ for scanner .Scan () && line < (tag .Line - 1 ) {
285
+ line ++
286
+ text := scanner .Text ()
287
+ textBuffer = append (textBuffer , text )
288
+ }
276
289
277
- // skip lines until we get to the start of this tag
278
- for scanner .Scan () && line < (tag .Line - iteration ) {
279
- line ++
290
+ for line > 0 && len (code ) < expectedPrototypeLen {
291
+
292
+ line = line - 1
293
+ text := textBuffer [line ]
294
+
295
+ if strings .Index (text , "//" ) != - 1 {
296
+ text = text [0 :strings .Index (text , "//" )]
297
+ }
298
+
299
+ if strings .Index (text , "*/" ) != - 1 {
300
+ if strings .Index (text , "/*" ) != - 1 {
301
+ text = text [0 :strings .Index (text , "/*" )] + text [strings .Index (text , "*/" )+ 1 :len (text )- 1 ]
302
+ } else {
303
+ text = text [strings .Index (text , "*/" )+ 1 : len (text )- 1 ]
304
+ multilinecomment = true
305
+ }
306
+ }
307
+
308
+ if multilinecomment {
309
+ if strings .Index (text , "/*" ) != - 1 {
310
+ text = text [0 :strings .Index (text , "/*" )]
311
+ multilinecomment = false
312
+ } else {
313
+ text = ""
314
+ }
280
315
}
281
316
282
- code = scanner . Text () + code
317
+ code = text + code
283
318
code = removeSpacesAndTabs (code )
284
- iteration ++
285
- // rewind the file
286
- file .Seek (0 , 0 )
287
- line = 0
288
319
}
289
320
}
290
321
return code
0 commit comments