terryyin / lizard

A simple code complexity analyser without caring about the C/C++ header files or Java imports, supports most of the popular languages.
Other
1.85k stars 250 forks source link

Lizard not handling macros in C++ correctly #189

Closed etorlows closed 7 years ago

etorlows commented 7 years ago

With the following C++ code:

void myFunction()
{
    IGNORE_FLAGS("w-maybe")
    if(2+2==4)
    END_IGNORE_FLAGS("w-maybe")
    {
        mySecondFunction()
    }
}

int mySecondFunction()
{
    return 2;
}

Dox generates the following output: doxmacrobug

I've found that when the IGNORE_FLAGS and END_IGNORE_FLAGS macros are removed, the tool works without issue.

rakhimov commented 7 years ago

First, as the readme states, Lizard does not handle macros (code-gen) by its design. It tries to ignore them. Macros are evil; the code may end-up looking syntactically bogus for tools that don't do macro processing.

I don't see what the problem is when running from the command-line:

================================================
  NLOC    CCN   token  PARAM  length  location  
------------------------------------------------
       9      2     26      0       9 myFunction@1-9@code.cc
       4      1      8      0       4 mySecondFunction@11-14@code.cc
1 file analyzed.
==============================================================
NLOC    Avg.NLOC  AvgCCN  Avg.token  function_cnt    file
--------------------------------------------------------------
     13       6.5     1.5       17.0         2     code.cc

=============================================================================================
No thresholds exceeded (cyclomatic_complexity > 15 or length > 1000 or parameter_count > 100)
==========================================================================================
Total nloc   Avg.NLOC  AvgCCN  Avg.token   Fun Cnt  Warning cnt   Fun Rt   nloc Rt
------------------------------------------------------------------------------------------
        13       6.5     1.5       17.0        2            0      0.00    0.00
terryyin commented 7 years ago

The reason I created Lizard was because I wanted to ignore preprocessing when getting the complexity numbers. The downside is for some macros that breaks the syntax without expanding them lizard might not work.

I'm looking for a solution now but it'll take time:-)

terryyin commented 7 years ago

This is fixed now. Lizard and recognise both method, with the right measurement.

rakhimov commented 7 years ago

@terryyin Please reference your commits with issue numbers.

Transferring the discussion to appropriate thread from https://github.com/terryyin/lizard/issues/126#issuecomment-323616183

@rakhimov I removed two lines of nested_structure code to pass a test. Do you remember why they were there? e4c6898

git blame helps track down the reason:

commit fd44240fa4f4e7eccc36eb4a2dd76687479e5010
Author: rakhimov <...>
Date:   Fri Dec 30 13:24:05 2016 -0800

    Implement proper NS for paired structures

    Paired structures: try-catch, catch-catch, if-else, do-while.
    These structures keep the level from being decremented
    if they are declared right after each other.

    Fixes #157.

I need to look deeper to the recent changes and add more NS tests.