Coder Social home page Coder Social logo

terryyin / lizard Goto Github PK

View Code? Open in Web Editor NEW
1.8K 55.0 246.0 2.6 MB

A simple code complexity analyser without caring about the C/C++ header files or Java imports, supports most of the popular languages.

License: Other

Makefile 0.13% Python 53.36% XSLT 0.28% C 0.01% HTML 12.98% CSS 0.51% Shell 0.06% PHP 0.58% JavaScript 9.80% Hack 0.04% Nix 0.12% Less 22.12%

lizard's Issues

Rename hfcca

Hfcca has already got a little user base. But the hfcca is hard to pronounce (even I don't know how to pronounce it.)

So better use a different name.

IndexError: pop from empty list errors

I ran lizard on various projects and got a bunch of pop from empty list errors. Here are some samples
https://www.dropbox.com/s/h43p1b4uozqly59/vgabios.c from qemu
https://www.dropbox.com/s/bpib35xzrq3hik3/arg9.C from gcc
https://www.dropbox.com/s/u5o94tbgn7do6d6/temp_arg_nontype.cpp from llvm
https://www.dropbox.com/s/k49d5ywfav58im0/johab.c from glibc
https://www.dropbox.com/s/slnz4uhxv8mul0h/common.h from tcmalloc

Traceback (most recent call last):
  File "/home/cocobo/repository/lizard/lizard", line 6, in <module>
    lizard_main(sys.argv)
  File "/home/cocobo/repository/lizard/lizard.py", line 944, in lizard_main
    printer(result, options)
  File "/home/cocobo/repository/lizard/lizard.py", line 821, in print_result
    code_infos, option.extensions, scheme)
  File "/home/cocobo/repository/lizard/lizard.py", line 789, in print_and_save_modules
    for module_info in all_modules:
  File "/home/cocobo/repository/lizard/lizard.py", line 644, in __call__
    filename, open(filename, 'rU').read())
  File "/home/cocobo/repository/lizard/lizard.py", line 656, in analyze_source_code
    for _ in tokens:
  File "/home/cocobo/repository/lizard/lizard.py", line 631, in token_processor_for_function
    reader.state(token)
  File "/home/cocobo/repository/lizard/lizard.py", line 323, in state
    self._state(token)
  File "/home/cocobo/repository/lizard/lizard.py", line 457, in _state_template_in_name
    if self.bracket_stack.pop() != "<":
IndexError: pop from empty list

Wrong CCN of Python file

Hi!

I stumbled upon a Python file at work for which lizard calculates a wrong CCN.

# code somewhat simplified
def method1(self):
    pass

class Class1(object):
    def method2(self):

        if True:
            pass
        if True:
            pass

        def method1(param):
            for x in (1,2):
                pass

        if True:
            pass

        if True:
            pass

        while True:
            if True:
                pass

            for x in (1,2):
                True

    def method3(self):
        if True:
            for x in (1,2):
                if True:
                    pass
                else:
                    pass
        if True:
            pass
        else:
            pass

    def method4(self):
        if True:
            pass

        if True:
            pass

        if True:
            if True
                pass

        if True:
            if True:
                pass

        if True:
            pass
        else:
            pass

def memoize(obj):
    obj.cache = {}

Lizard tells me that method1() ranges from line 1 to line 62 and has a CCN of 20. If I remove the last two lines (memoize()), it works as expected.

Bye, Robert

Btw: lizard is a great tool and I use it every day.

Inifinite loop on python2.6

Greetings,
I tried to run hfcca.py on python2.6 and it enters an infinite loop, unfortunately i was unable to gather much info on where to start debugging.

Currently, when i try leave the process by CTRL+C, I only get ^C on the screen. Only killing python gives the prompt back.

I get no error message nor anything except the following lines:

NLOC CCN token param function@line@file

Unfortunatelly the machines where i need to run hfcca are debian 6 (python 2.6 by default) and it's out of the question install 2.7.4 on each one.

Thanks for any info

Support for #elif

Hi,

please check the example:

int main(){

ifdef A

#define C

elif (defined E)

#define D

endif

return 0;

}

breaking the lizard. Thank you.

Hang on some python files

Lizard gets stuck on some python files. Sample
https://www.dropbox.com/s/wjl70kodhb3qtlu/cp037.py

$ ~/repository/lizard/lizard cp037.py 
========================================
  NLOC    CCN   token  PARAM  location  
----------------------------------------
^C
Traceback (most recent call last):
  File "/home/cocobo/repository/lizard/lizard", line 6, in <module>
    lizard_main(sys.argv)
  File "/home/cocobo/repository/lizard/lizard.py", line 944, in lizard_main
    printer(result, options)
  File "/home/cocobo/repository/lizard/lizard.py", line 821, in print_result
    code_infos, option.extensions, scheme)
  File "/home/cocobo/repository/lizard/lizard.py", line 789, in print_and_save_modules
    for module_info in all_modules:
  File "/home/cocobo/repository/lizard/lizard.py", line 644, in __call__
    filename, open(filename, 'rU').read())
  File "/home/cocobo/repository/lizard/lizard.py", line 653, in analyze_source_code
    tokens = reader.generate_tokens(code)
  File "/home/cocobo/repository/lizard/lizard_ext/python.py", line 23, in generate_tokens
    r"|\'\'\'.*?\'\'\'" + r'|\"\"\".*?\"\"\"')
  File "/home/cocobo/repository/lizard/lizard.py", line 367, in generate_tokens
    return [t for t in _generate_tokens(source_code, addition)]
  File "/home/cocobo/repository/lizard/lizard.py", line 352, in _generate_tokens
    for token in token_pattern.findall(source_code):
KeyboardInterrupt

Crash when parsing Linux kernel

Parsing the Linux kernel will crash with an error like this:

Traceback (most recent call last):
  File "/home/cocobo/repository/lizard/lizard", line 6, in <module>
    lizard_main(sys.argv)
  File "/home/cocobo/repository/lizard/lizard.py", line 923, in lizard_main
    printer(result, options)
  File "/home/cocobo/repository/lizard/lizard.py", line 800, in print_result
    code_infos, option.extensions, scheme)
  File "/home/cocobo/repository/lizard/lizard.py", line 768, in print_and_save_modules
    for module_info in all_modules:
  File "/home/cocobo/repository/lizard/lizard.py", line 624, in __call__
    filename, open(filename, 'rU').read())
  File "/home/cocobo/repository/lizard/lizard.py", line 635, in analyze_source_code
    for _ in tokens:
  File "/home/cocobo/repository/lizard/lizard.py", line 611, in token_processor_for_function
    reader.state(token)
  File "/home/cocobo/repository/lizard/lizard.py", line 323, in state
    self._state(token)
  File "/home/cocobo/repository/lizard/lizard.py", line 437, in _state_template_in_name
    if self.bracket_stack.pop() != "<":
IndexError: pop from empty list

The problem is in the file drivers/isdn/hardware/avm/avmcard.h
Here is a small cutout

#define SEND_POLL       0x72    /*
                     * after load <- RECEIVE_POLL
                     */
#define SEND_INIT       0x11    /*
                     * first message <- RECEIVE_INIT
                     * int32 NumApplications  int32
                     * NumNCCIs int32 BoardNumber
                     */
#define RECEIVE_POLL        0x32    /*
                     * <- after SEND_POLL
                     */
#define RECEIVE_INIT        0x27    /*
                     * <- after SEND_INIT int32 length
                     * byte total length b1struct board
                     * driver revision b1struct card
                     * type b1struct reserved b1struct
                     * serial number b1struct driver
                     * capability b1struct d-channel
                     * protocol b1struct CAPI-2.0
                     * profile b1struct capi version
                     */
#define RECEIVE_MESSAGE     0x21    /*
                     * <- after SEND_MESSAGE int32
                     * AppllID int32 Length capi-data
                     * ....
                     */
static inline void b1_put_word(unsigned int base, unsigned int val)
{
    b1_put_byte(base, val & 0xff);
    b1_put_byte(base, (val >> 8) & 0xff);
    b1_put_byte(base, (val >> 16) & 0xff);
    b1_put_byte(base, (val >> 24) & 0xff);
}

The crash seems to be caused by those <- in the comment sections.

add support for `--version` option

Please add support to trace the current version number and exit when invoked with --version, e.g.:

$ ./hfcca.py --version
hfcca 1.6.0

Don't print result status when everything is ok

Hello,
I am using lizard as part of a larger code checking framework at work and therefore need to parse its output (great tool that works without much fiddling, by the way). In case no problems are found, a "No warning found. Excellent!" message is printed. I believe the more unix-oid way would be to print nothing and just quit quietly (that would also make parsing more straightforward). Do you think you could change this for the default settings or add a "--quiet" option or show it only for "--verbose"?
Thanks and best regards

#ifndef in c++

Hi,

first of all: great tool :) I have found out that is not dealing correctly with 'ugly' ifdefs in C++.

int main(){

ifndef NORBUS

if(true){
    return 1;

else

if(false){
    return 0;

endif

}
    return 1;

}

Could you please look at this ?

Thanks,
Norbert

Lizard failing on char sequence

Lizard fails to parse a file when (a form of) the following sequence is encounterd (in regex) [a-zA-Z]<.*>>
So the following sequence is a failing sequence: a<>>

I encounterd the bug when trying to parse a java file with the following line of code:
private static final Map<String, Map<Byte, String>> VAR_NAME = ImmutableMap.<String, Map<Byte, String>> builder()
Although this is really ugly, it is valid java.

I worked around the problem by adding a space between ">>"

RuntimeError: maximum recursion depth exceeded error

Some files cause a maximum recursion depth exceeded error. Sample
https://www.dropbox.com/s/0pg9cwnkdoevy03/fp_and_simd.c from valgrind

Traceback (most recent call last):
  File "/home/cocobo/repository/lizard/lizard", line 6, in <module>
    lizard_main(sys.argv)
  File "/home/cocobo/repository/lizard/lizard.py", line 944, in lizard_main
    printer(result, options)
  File "/home/cocobo/repository/lizard/lizard.py", line 821, in print_result
    code_infos, option.extensions, scheme)
  File "/home/cocobo/repository/lizard/lizard.py", line 789, in print_and_save_modules
    for module_info in all_modules:
  File "/home/cocobo/repository/lizard/lizard.py", line 644, in __call__
    filename, open(filename, 'rU').read())
  File "/home/cocobo/repository/lizard/lizard.py", line 656, in analyze_source_code
    for _ in tokens:
  File "/home/cocobo/repository/lizard/lizard.py", line 631, in token_processor_for_function
    reader.state(token)
  File "/home/cocobo/repository/lizard/lizard.py", line 323, in state
    self._state(token)
  File "/home/cocobo/repository/lizard/lizard.py", line 528, in _state_old_c_params
    self._state(token)
  File "/home/cocobo/repository/lizard/lizard.py", line 528, in _state_old_c_params
    self._state(token)
...
  File "/home/cocobo/repository/lizard/lizard.py", line 528, in _state_old_c_params
    self._state(token)
  File "/home/cocobo/repository/lizard/lizard.py", line 428, in _state_global
    self.context.start_new_function(token)
  File "/home/cocobo/repository/lizard/lizard.py", line 216, in start_new_function
    self.current_line)
RuntimeError: maximum recursion depth exceeded

#ifndef in c++

Hi,

please check the example:

class Constructor{
int m_timer;

public:
Constructor::Constructor()

ifdef MAGIC

:
m_timer(5)

endif

{
int a = 0;
}
};

it doesn't work correctly even when i use -P flag.

Sorry for so strange examples :) and I think your tool is great. Such a code should be avoided.

map function iterates indefinitely

The third argument in the following map function repeats indefinitely (both with preprocessor set and unset (true or false)). It worrks if the third argument is removed.
r = map(analyze_source_file, files, itertools.repeat(options.use_preprocessor))

This appends None objects to the filename list and the file open function will fail.

From "map()" Python Documentation:
"If additional iterable arguments are passed, function must take that many arguments and is applied to the items from all iterables in parallel. If one iterable is shorter than another it is assumed to be extended with None items."

Error message:

f = open(filename)
TypeError: coercing to Unicode: need string or buffer, NoneType found

Running Ubuntu 12.04

br
Simon

Set whitelist via flag

I have the white list for Lizard stored in a different directory than where I run Lizard from (due to build automation).
I would like to see an option to pass a white-list to Lizard via a special command line flag.

CPP, problem introduced in lizard

Hi,

I am using my forked version of you repo (https://github.com/norkos/lizard.git) which is quite old one. While changing to new version I have met problem in files like:

include

class Timer{

ifndef TEST

Timer(int j);

else

Timer();

endif

};

ifndef TEST

Timer::Timer(int j)
{

else

Timer::Timer()
{

endif

for (int i = 0; i < 10; i++)
{
}

ifndef TEST

std::cout << "Branch";

endif

}

int main(){
return 0;
}

No function is find in this file.

NLOC Avg.NLOC AvgCCN Avg.ttoken function_cnt file

 17      0    0.0         0         0     check.cpp

Previously I had:

nloc CCN token param function@line@file

10      3     32      1    Timer::Timer@[email protected]
 1      1      3      0    main@[email protected]

Could you please help me ? Thank you in advance.

btw. I am aware that this code is tricky ...

Preprocessing counting.

I am not getting the right numbers for cyclomatic_complexity for C preprocessing that is done outside of methods (i.e. it is done in the header of the file).

Is this a known issue or is there any fix for this?

headers in cpp

Hi,

as c/c++ files we use (c|C|cpp|CPP|CC|cc|mm). Unfortunately it can happen that someone will put inline functions into headers.

Could you extend this pattern for headers file ? Complexity for function declarations already works fine.

Swift langage support

We are using lizard on objc project (thanks you for this nice tool that improve xcode using a simple script), is there any chances that brand new Swift language will be supported ?

I have no idea on how to add support for it, maybe some indication will help to support it.

about filename in whitelizard.txt

Actually, it's path not filename.
You have to type the path instead of only filename.
I think the explanation in readme is too vague

#ifndef in c++

Hi,

first of all: great tool :) I have found out that is not dealing correctly with 'ugly' ifdefs in C++.

int main(){

ifndef NORBUS

if(true){
return 1;

else

if(false){
return 0;

endif

}
return 1;

}

Could you please look at this ?

Thanks,
Norbert

support js

Hi

so could lizard support JS?

thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.