1

I am searching for a Cyclomatic Complexity Api in Delphi (2010). I need to create a program that will analize a source code and report the Cyclomatic Complexity of all methods in all classes (just like SourceMonitor does).
I cant use other softwares, I really need to build one.
Does anyone knows an API for delphi 2010 that does that?

Rafael Colucci
  • 6,018
  • 4
  • 52
  • 121
  • I'd have a look at Coco/R and its crossreferencing example. But there is still the problem of the missing grammar. (and specially if you aim recent subsets) – Marco van de Voort Dec 17 '10 at 20:30
  • 3
    Wait — a *library* that calculates the complexity is OK, but a *program* that does the same thing isn't? Why is that distinction so important? – Rob Kennedy Dec 17 '10 at 20:40

1 Answers1

3

You'll need a language parser from which you can generate a control flow graph. Then you need to calculate the CC using this formula.

I know of no library that will do this for you.

You may be able to use the free pascal source to generate the control flow graph (its a common technique used in compilers to eliminate unreachable code).

Unfortunately, Delphi hasn't shipped with a complete formal definition(bnf grammar) of the language in its documentation since Delphi 6 I believe. (even then it wasn't completely accurate) So all third party parsers are shooting in the dark.

Kenneth Cochran
  • 11,954
  • 3
  • 52
  • 117
  • Afaik the Delphi manual grammar never has been usable, and was for reference only. FPC doesn't have grammers either since it uses recursive descent parsers as customary with Wirthian languages. Even if you characterize Delphi manually (like FPC did), you will be forever in the dark about what is undefined behaviour (works but is coincidental), and what is intended – Marco van de Voort Dec 17 '10 at 20:29