@@ -99,19 +99,26 @@ func findLinesWithExternCScope(tag *types.CTag, ctx *types.Context) {
9999 scanner := bufio .NewScanner (file )
100100
101101 inExternCNamespaceScope := false
102+ decidingExternScope := false
102103 indentLevels := 0
103104 line := 0
104105 for scanner .Scan () {
105106 line ++
106107 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 )) {
108112 inExternCNamespaceScope = true
113+ if len (removeSpacesAndTabs (str )) == len (removeSpacesAndTabs (EXTERN )) {
114+ decidingExternScope = true
115+ }
109116 }
110117 if inExternCNamespaceScope == true {
111118 ctx .LinesInExternCContext [tag .Filename ] = append (ctx .LinesInExternCContext [tag .Filename ], line )
112119 }
113120 indentLevels += strings .Count (str , "{" ) - strings .Count (str , "}" )
114- if indentLevels == 0 {
121+ if indentLevels == 0 && decidingExternScope == false {
115122 inExternCNamespaceScope = false
116123 }
117124 }
@@ -247,7 +254,7 @@ func prototypeAndCodeDontMatch(tag *types.CTag) bool {
247254 // what could possibly go wrong?
248255 // definition is multiline
249256
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
251258 code = removeEverythingAfterClosingPerentheses (code )
252259
253260 // is the code contained in the prototype?
@@ -269,22 +276,46 @@ func getFunctionPrototypWithNPreviousCharacter(tag *types.CTag, code string, n i
269276 defer file .Close ()
270277
271278 scanner := bufio .NewScanner (file )
272- line := 1
273- iteration := 1
279+ line := 0
280+ multilinecomment := false
281+ var textBuffer []string
274282
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+ }
276289
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+ }
280315 }
281316
282- code = scanner . Text () + code
317+ code = text + code
283318 code = removeSpacesAndTabs (code )
284- iteration ++
285- // rewind the file
286- file .Seek (0 , 0 )
287- line = 0
288319 }
289320 }
290321 return code
0 commit comments