Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem parsing structs with macro-ed function pointers #60

Open
tiennou opened this issue Jun 3, 2021 · 0 comments
Open

Problem parsing structs with macro-ed function pointers #60

tiennou opened this issue Jun 3, 2021 · 0 comments

Comments

@tiennou
Copy link
Contributor

tiennou commented Jun 3, 2021

I've been digging around parsing for some time, and I've discovered the following : clang seems to mishandle the following construct (test.txt, a reduced version of git2/sys/transport.h). If you use the following script, you'll get back the AST from clang. Notice that version gets its comment, as well as set_callbacks. But everything else does not. It seems the culprit is the GIT_CALLBACK macro, which seems to prevent clang (as it comes "first", before the actual documented identifier) from attaching the comment to where it belongs.

This should probably be filed upstream as well, but LLVM's bugzilla is under account spam lockdown, and I have a hunch comment parsing is pretty low-priority. For now, just document that this is the "expected" behavior (and publish the helpful script).

`-RecordDecl 0x7fe3dd07b8a8 prev 0x7fe3dd07ae58 <line:10:1, line:100:1> line:10:8 struct git_transport definition
  |-FullComment 0x7fe3dd0a2390 <line:9:4, col:12>
  | `-ParagraphComment 0x7fe3dd0a2360 <col:4, col:12>
  |   `-TextComment 0x7fe3dd0a2330 <col:4, col:12> Text="  BBlaah "
  |-FieldDecl 0x7fe3dd07b940 <line:11:5, col:18> col:18 version 'unsigned int'
  | `-FullComment 0x7fe3dd0a2460 <col:31, col:50>
  |   `-ParagraphComment 0x7fe3dd0a2430 <col:31, col:50>
  |     `-TextComment 0x7fe3dd0a2400 <col:31, col:50> Text=" The struct version "
  |-FieldDecl 0x7fe3dd0a02b8 <line:14:5, line:20:9> line:14:11 set_callbacks 'int (*)(git_transport *, git_transport_message_cb, git_transport_message_cb, git_transport_certificate_check_cb, void *)'
  | `-FullComment 0x7fe3dd0a2530 <line:13:8, col:41>
  |   `-ParagraphComment 0x7fe3dd0a2500 <col:8, col:41>
  |     `-TextComment 0x7fe3dd0a24d0 <col:8, col:41> Text=" Set progress and error callbacks "
  |-FieldDecl 0x7fe3dd0a05a0 <line:23:5, line:25:43> line:23:22 set_custom_headers 'int (*)(git_transport *, const int *)'
  |-FieldDecl 0x7fe3dd0a0b48 <line:31:5, line:38:18> line:31:22 connect 'int (*)(git_transport *, const char *, int, void *, const int *, int, int)'
  |-FieldDecl 0x7fe3dd0a0f28 <line:47:5, line:50:33> line:47:22 ls 'int (*)(const int ***, int *, git_transport *)'
  |-FieldDecl 0x7fe3df008878 <line:53:5, col:107> col:22 push 'int (*)(git_transport *, int *, const int *)'
  |-FieldDecl 0x7fe3df008ca0 <line:62:5, line:66:21> line:62:22 negotiate_fetch 'int (*)(git_transport *, int *, const int *const *, int)'
  |-FieldDecl 0x7fe3df009118 <line:74:5, line:79:31> line:74:22 download_pack 'int (*)(git_transport *, int *, int *, int, void *)'
  |-FieldDecl 0x7fe3df009338 <line:82:5, col:60> col:22 is_connected 'int (*)(git_transport *)'
  |-FieldDecl 0x7fe3df009600 <line:85:5, col:70> col:22 read_flags 'int (*)(git_transport *, int *)'
  |-FieldDecl 0x7fe3dd0a2038 <line:88:5, col:55> col:23 cancel 'void (*)(git_transport *)'
  |-FieldDecl 0x7fe3dd0a2170 <line:96:5, col:53> col:22 close 'int (*)(git_transport *)'
  `-FieldDecl 0x7fe3dd0a2298 <line:99:5, col:53> col:23 free 'void (*)(git_transport *)'
#!/usr/bin/env ruby -W

file = ARGV[0]

raise "Missing argument" if file.nil?
raise "File not found" unless File.exist?(file)

CLANG = "clang"

opts = %w(
	-Xclang
	-ast-dump
	-Wall
	-fsyntax-only
	-fno-color-diagnostics
	-fparse-all-comments
	-iquote include
)
system("#{CLANG} #{opts.join " "} #{file}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant