Menu

#124 Miscount of C++ comments

v1.63
pending
nobody
None
1
2015-12-06
2014-10-31
tksh
No

Hi, cloc (v1.60, 1.62) seems to miscount C++ comments in some case.

1) For attached sample.cpp,
the expected is blank:2, comment:16, code:2,
but the result is blank:2, comment:11, code:7 .

2) When we change the filter order in the language definition file as follows:

C++
    filter call_regexp_common C
    filter remove_matches ^\s*//
    filter remove_inline //.*$

then the result is blank:2, comment:15,code:3 .

3) When we change the filter as follows:

C++
    filter call_regexp_common C++

then the result is blank:2, comment:17,code:1 .
(line 11 and 12 are combined into one line "code1code2")

Is there some workaround for this problem ?

Thank you,
tksh

1 Attachments

Discussion

  • tksh

    tksh - 2014-10-31

    As far as I investigated the code,
    only one filter "call_regexp_common C++" as in 3) should work well
    because Regexp::Common supports both of inline "//" and multi-line "/ /" comments.

    The problem is probably that Regexp::Common removes "\n" from an inline comment line.
    The modification below seems to work well.

    # sub to_eol  ($)  {"(?k:(?k:$_[0])(?k:[^\\n]*)(?k:\\n))"}
    sub to_eol  ($)  {"(?k:(?k:$_[0])(?k:[^\\n]*))"}
    
     

    Last edit: tksh 2014-10-31
  • Al Danial

    Al Danial - 2014-11-01

    I tested your mod to sub to_eol() from Regexp::Common and simplified the language filter to just use Regexp::Common's C++ but that still returned blank:2, comment:17, code:1.
    The lines are still joined into a single "code1code2". This is with Perl 5.18.0. Still scratching my head on this one.

     
  • tksh

    tksh - 2014-11-04

    Did you confirm that $HAVE_Rexexp_Common = 0 ?

    Attached is my test.

     
  • Al Danial

    Al Danial - 2015-12-06

    Sorry for the delay, but I've just now gotten around to fixing this. As the code now lives on github, you can test the change by grabbing the code from https://github.com/AlDanial/cloc/blob/dev/cloc.

     
  • Al Danial

    Al Danial - 2015-12-06
    • status: open --> pending
     

Anonymous
Anonymous

Add attachments
Cancel