universal-ctags / ctags

A maintained ctags implementation
https://ctags.io
GNU General Public License v2.0
6.57k stars 627 forks source link

d3d12.h not parsed correctly (_Field_size_full_) #3915

Closed kaloth closed 10 months ago

kaloth commented 10 months ago

( Thank you for contacting us.

If you are reporting an issue with the parsing output, please fill the following template. As your custom CTags configuration can affect results, please always use --options=NONE as the first option when running ctags.

Otherwise, delete the template and write your issue from scratch. Examples may help developers understanding your issue better.

Use GitHub web interface and markdown notation. Using mail results broken text rendering that makes the developers go crazy. )


The name of the parser: I'm not sure. C/C++?

The command line you used to run ctags:

$ ctags.exe --options=NONE -efhdrs\ctags-d3d12 "C:\Program Files (x86)\Windows Kits\10\Include\10.0.22593.0\um\d3d12.h"

The content of input file:

typedef struct D3D12_SHADER_BYTECODE
    {
    _Field_size_bytes_full_(BytecodeLength)  const void *pShaderBytecode;
    SIZE_T BytecodeLength;
    }   D3D12_SHADER_BYTECODE;

typedef struct D3D12_STREAM_OUTPUT_DESC
    {
    _Field_size_full_(NumEntries)  const D3D12_SO_DECLARATION_ENTRY *pSODeclaration;
    UINT NumEntries;
    _Field_size_full_(NumStrides)  const UINT *pBufferStrides;
    UINT NumStrides;
    UINT RasterizedStream;
    }   D3D12_STREAM_OUTPUT_DESC;

typedef struct D3D12_INPUT_LAYOUT_DESC
    {
    _Field_size_full_(NumElements)  const D3D12_INPUT_ELEMENT_DESC *pInputElementDescs;
    UINT NumElements;
    }   D3D12_INPUT_LAYOUT_DESC;

The tags output you are not satisfied with:

The following tags are missing: pShaderBytecode, pSODeclaration, pBufferStrides & pInputElementDescs.
...

The tags output you expect:

I'm not certain of the exact content but the above mentioned tags are missing.

The version of ctags:

$ ctags --version
Universal Ctags 6.1.0(v6.1.0), Copyright (C) 2015-2023 Universal Ctags Team
Universal Ctags is derived from Exuberant Ctags.
Exuberant Ctags 5.8, Copyright (C) 1996-2009 Darren Hiebert
  Compiled: Dec 29 2023, 08:24:13
  URL: https://ctags.io/
  Output version: 0.0
  Optional compiled features: +win32, +wildcards, +regex, +gnulib_regex, +internal-sort, +unix-path-separator, +iconv, +option-directory, +xpath, +json, +interactive, +yaml, +case-insensitive-filenames, +packcc, +optscript, +pcre2

How do you get ctags binary:

Downloaded from here: https://github.com/universal-ctags/ctags-win32/releases/download/v6.1.0/ctags-v6.1.0-x64.zip

k-takata commented 10 months ago

_Field_size_full_ is defined in sal.h. (Not sure if sal.h can be automatically parsed.)

How about using -D _Field_size_full_()=? E.g.:

ctags -D _Field_size_full_()= d3d12.h
kaloth commented 10 months ago

This was a great suggestion and it worked like a charm! I guess I'll leave it up to someone who knows ctags better to decide if ctags needs to support this usage properly or if the define stripping is the only viable workaround.

masatake commented 10 months ago

If the target source code includes sal.h and sal.h defines _Field_sizefull as a macro, ctags version 19.0 will expand the macro used in the target source code. This feature can be used with the -r option (semantic recursion).

However, the latest version is 6.1.0. -r option is not implemented yet as in 2024. The instruction that @k-takata wrote is solid.

If running ctags twice is allowed, you can expand macros automatically.

However, unlike imaginary option -r, the current version of ctags doesn't care #include and #ifdef/#elif/#else, ctags may expand macros unexpected places in the source tree.