I’ve tried a few tools like cloc to count the lines of code within my cpp project.

However, they are pretty surface level and just count the lines.

Is there anything that is able to show how many lines are for classe, imports, simple aliases, typedefs, and more detailed info like that.

My codebase is using C++ 20 modules and a lot of it is just imports and namespace aliases, so just counting the lines is pretty inaccurate. A lot of the files are simply just 10-20 lines at the header for imports, etc, and then just a small child class with constructors.

Which is to say that it’s >50% “filler” in a lot of files.

If anyone knows any tools for this, ideally FOSS, please let me know. Thanks!

  • lambalicious
    link
    fedilink
    English
    arrow-up
    7
    ·
    9 days ago

    I’m unsure if that’s even possible in C++ for a “normal program” instead of requiring a full-fledged compiler and even maybe a linker, as C++ syntax is completely context-dependent. There’s no way to tell if i+=b; increments a value or is actually a dynamic hierarchy cast that prints a message to screen and invokes a vector copy with data downloaded from the internet.

    I’d venture there’s something in Clang that does this? (clang-tidy, clang-format, who knows), since they implement the syntax tree parser thing.

      • lambalicious
        link
        fedilink
        English
        arrow-up
        1
        ·
        7 days ago

        Yeah basically C++ is fun (or “fun”) in that in order to try and get what code does or what it means you have pretty much no other alternative than trying to compile it.

        There are a number of terms that have only one meaning and can appear in only one “semantic place”, such as namespace, return and… I think that’s it? Maybe (maaaaybe) .*. So it’s little enough that doesn’t give you that much good information if you try and hand-parse them out from the code you have.

    • Emperor@reddthat.comOP
      link
      fedilink
      English
      arrow-up
      2
      ·
      9 days ago

      This is a lot more complicated than I first anticipated. I guess its probably not a common tool then 😅

      • lambalicious
        link
        fedilink
        English
        arrow-up
        2
        ·
        7 days ago

        Whch is why the cool thing™ nowadays is to use an IDE that has Clang integration, and let the compiler that already compiles your code anyway, do all that sweet statistics job for you.

    • Emperor@reddthat.comOP
      link
      fedilink
      English
      arrow-up
      1
      ·
      9 days ago

      That would only tell me how large each object/asm file is, its not really indicative of the lines of code as it could expand to quite a large size once compiled.

      I’m looking for more of an analysis of what has been written and its ratio to the line count.

      Thanks for suggesting this, but its not quite what I’m looking for.

  • BB_C@programming.dev
    link
    fedilink
    arrow-up
    3
    ·
    8 days ago

    tokei is the tool that came to mind reading your title.

    Getting fancier info depends on the fanciness of the tokenizer used. Maximum fanciness probably requires a full language parser. Info beyond code/tokens requires more than just a parser (language server territory).