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

a non-structural failure case in NS metric #157

Closed mehrdad89 closed 7 years ago

mehrdad89 commented 8 years ago

Hi,

I am currently running NS metric on my repository and faced a bug return statement. The following unit test clarifies my claim:

def test_non_structure_braces_with_return(self):
    """return statements in non-structural nesting level may confuse the nesting level."""
    result = process_cpp("""
    x c() {
        if (a)
            if (b)
                return false;

        if (c)
            if (d)
                return false;
    }
    """)
    self.assertEqual(3, result[0].max_nested_structures) # should be valued 2

commit: 23ec9e8e0091bf24a13d30b72fbe4df5b77b971a

Looking forward to hearing from you regarding this issue.

rakhimov commented 8 years ago

@mehrdad89 The problem seems to be general. It fails even if there's 'any statement' instead of the 'return statement'.

mehrdad89 commented 8 years ago

@rakhimov I kinda was hoping this is happening due to a minor case. I guess I should change the title of this issue too.

rakhimov commented 8 years ago

@mehrdad89 That would be great.

rakhimov commented 8 years ago

@mehrdad89 @terryyin I will be working on this bug over the weekend. The problem is that braceless control structures have the same nesting_level metric. It seems 'nesting_level' metric for tokens is unnecessarily complicated or even probably a wrong approach with my implementation. This looks to be one of those times when I look at my own months-old code and wonder: "WTF?" :-)

rakhimov commented 8 years ago

Hmm, the nesting structure determination extension is running before the assignment of the nestring_level to tokens. I thought it was the other way around.