rdmsr / cppdoc

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

unnamed field in struct #7

Closed db48x closed 5 days ago

db48x commented 6 days 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 6 days 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 6 days 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 6 days 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 5 days ago

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

rdmsr commented 5 days ago

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

db48x commented 5 days ago

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

rdmsr commented 5 days 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 5 days 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 5 days 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

mnmnk43434 commented 5 days ago

Hello, we tried to solve the issue.

This is what we did:

Modified the Field struct to include a default_value field and updated the parse_record function to correctly parse default-initialized member variables. This change will allow cppdoc to properly display structs with default-initialized members.

You can review changes in this commit: https://github.com/mnmnk43434/rdmsr-cppdoc-7/commit/b525c929c11acb30edc0e6e8cda57221ec9f605e.

[!CAUTION] Disclaimer: The concept of solution was created by AI and you should never copy paste this code before you check the correctness of generated code. Solution might not be complete, you should use this code as an inspiration only.


If you no longer want Latta AI to attempt solving issues on your repository, you can block this account.