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

underestimating max depth when statements are found in the if block #254

Closed elmotec closed 5 years ago

elmotec commented 5 years ago

Hello,

I see an issue with max_nested_depth that I reproduced in the following test case:

def test_one_function_nd_with_addl_statement_in_if(self):
        result = get_cpp_with_nestdepth("""
        int fun() {
            if(a) {
                b;
                if (c) {
                    d;
                }
            }
        }""")
        self.assertEqual(2, result[0].max_nesting_depth)

result[0].max_nesting_depth is 1 instead of 2 so this test should fail if you add it to testNestingDepth.py.

Note that without the b; statement, I get max_nesting_depth 2 which I is correct but I don't believe b; should impact the nesting depth.

terryyin commented 5 years ago

hmm, thanks for the re part and test. I will look into it. The nested structure implementation is mostly from a pull request and right now not functioning as expected.

elmotec commented 5 years ago

I think I have an angle on it, I should have a fix today.

The only thing is that right now, I break the "ignoring explicit forever loop" which is illustrated by the following test case:

    def test_one_function_nd_ignoring_explicit_forever_loop(self):
        result = get_cpp_with_nestdepth("""
        x a() {
          for(;;) {  // <-- explicit forever loop
            if(a != 0){
                a = b;
            }
          }
        }
        x b() {
          while(1) {
            if(a != 0){
                a = b;
            }
          }
        }
        x c() {
          while(true) {
            if(a != 0){
                a = b;
            }
          }
        }
        """)
        self.assertEqual(1, result[0].max_nesting_depth)
        self.assertEqual(2, result[1].max_nesting_depth)
        self.assertEqual(2, result[2].max_nesting_depth)

I am not sure why for (;;) deserves a special treatment. What's your take on it?

elmotec commented 5 years ago

@terryyin, just realized that the PR #257 had not been merged. Only the fixes to the test suite. What's the next move?

terryyin commented 5 years ago

Just merged it. Sorry for the delay.

On 9 Mar 2019, at 8:35 AM, elmotec notifications@github.com wrote:

@terryyin https://github.com/terryyin, just realized that the PR #257 https://github.com/terryyin/lizard/pull/257 had not been merged. Only the fixes to the test suite. What's the next move?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/terryyin/lizard/issues/254#issuecomment-471125338, or mute the thread https://github.com/notifications/unsubscribe-auth/AAwJYpJRggdPMczelo0hWMu9Ml67M25qks5vUwHFgaJpZM4a_URY.

elmotec commented 5 years ago

No worries. Thank you for Lizard!