@@ -65,9 +65,8 @@ func (p *CTagsParser) prototypeAndCodeDontMatch(tag *types.CTag) bool {
6565
6666 code := removeSpacesAndTabs (tag .Code )
6767
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?
7068 if strings .Index (code , ")" ) == - 1 {
69+ // Add to code non-whitespace non-comments tokens until we find a closing round bracket
7170 file , err := os .Open (tag .Filename )
7271 if err == nil {
7372 defer file .Close ()
@@ -81,18 +80,19 @@ func (p *CTagsParser) prototypeAndCodeDontMatch(tag *types.CTag) bool {
8180 }
8281
8382 // 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 := ""
8885
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
9290 }
9391 }
9492 }
9593
94+ code = removeSpacesAndTabs (code )
95+
9696 prototype := removeSpacesAndTabs (tag .Prototype )
9797 prototype = removeTralingSemicolon (prototype )
9898
@@ -150,30 +150,7 @@ func getFunctionProtoWithNPreviousCharacters(tag *types.CTag, code string, n int
150150 line = line - 1
151151 text := textBuffer [line ]
152152
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 )
177154
178155 code = text + code
179156 code = removeSpacesAndTabs (code )
@@ -182,6 +159,34 @@ func getFunctionProtoWithNPreviousCharacters(tag *types.CTag, code string, n int
182159 return code
183160}
184161
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+
185190/* This function scans the source files searching for "extern C" context
186191 * It save the line numbers in a map filename -> {lines...}
187192 */
0 commit comments