rdmsr / cppdoc

C++ documentation generator
MIT License
47 stars 4 forks source link

unnamed field in struct #7

Closed db48x closed 1 week ago

db48x commented 1 week ago

Given the struct mvwzstr:

struct mvwzstr {
    int left = 0;
    nc_color color = c_unset;
    std::string txt;
    int sym = 0;
};

cppdoc outputs:

struct mvwzstr {
  int left;
  int color;
  int ;
  int sym;
  /* Full declaration omitted */ 
}

The types are not perfect either, but let’s start with the name.

db48x commented 1 week ago

I see that parser.rs:288 has c.get_name().unwrap_or_default(), so I guess that’s where the empty string is coming from. get_name() is a simple wrapper around clang_getCursorSpelling from libclang, so I guess we just get what we get.

rdmsr commented 1 week ago

I can't reproduce, this works fine in the example directory. Can you share your config file? This may be because you forgot to pass -x c++ to clang.

db48x commented 1 week ago
[input]
glob = "src/*.h"
compiler_arguments = ["-Isrc -isystem src/third-party -DGIT_VERSION -DTILES -DBACKTRACE -DLOCALIZE -Og -Werror -Wall -Wextra -Wformat-signedness -Wlogical-op -Wmissing-declarations -Wmissing-noreturn -Wnon-virtual-dtor -Wold-style-cast -Woverloaded-virtual -Wpedantic -Wsuggest-override -Wunused-macros -Wzero-as-null-pointer-constant -Wno-unknown-warning-option -Wno-dangling-reference -Wno-c++20-compat -Wredundant-decls -ggdb -g -fsigned-char -std=c++17 -I/usr/include/SDL2 -D_REENTRANT -I/usr/include/SDL2 -D_REENTRANT -DHWY_SHARED_DEFINE -DAVIF_DLL -I/usr/include/webp -I/usr/include/libpng16 -DWITH_GZFILEOP -I/usr/include/harfbuzz -I/usr/include/freetype2 -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/sysprof-6 -pthread -I/usr/include/freetype2 -I/usr/include/libpng16 -DWITH_GZFILEOP -I/usr/include/harfbuzz -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/sysprof-6 -pthread -I/usr/include/SDL2 -D_REENTRANT -DSDL_SOUND -MMD -MP"]
db48x commented 1 week ago

Adding -x c++ to compiler_arguments doesn’t change the result.

rdmsr commented 1 week ago

Try splitting your arguments, compiler_arguments is an array of arguments. So it should be ["-Isrc", "-isystem", ...]

db48x commented 1 week ago

I can do that, but is it really relevant? It just concatenates them back into a single string.

rdmsr commented 1 week ago

I can do that, but is it really relevant? It just concatenates them back into a single string.

Yes. It seems like libclang expects an array.

db48x commented 1 week ago

Yea, that does fix it. And I was misremembering; it’s compiler_invocation in the [doctests] section that is joined back into a single string.

Maybe it should print a warning if compiler_arguments looks suspiciously like a single string with spaces in it?

rdmsr commented 1 week ago

Yea, that does fix it. And I was misremembering; it’s compiler_invocation in the [doctests] section that is joined back into a single string.

Maybe it should print a warning if compiler_arguments looks suspiciously like a single string with spaces in it?

Yeah that is a good idea, I suppose I could also add some kind of fallback, like if there's only one element in the array and it is space-separated, split it into a proper array