Skip to content

feat: complete c parser #13

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

Merged
merged 8 commits into from
May 28, 2025
Merged

feat: complete c parser #13

merged 8 commits into from
May 28, 2025

Conversation

Hoblovski
Copy link
Collaborator

What type of PR is this?

实现 C parser 到 AST。
考虑到 C 语言无模块,所以只有一个模块。

Check the PR title.

  • This PR title match the format: <type>(optional scope): <description>
  • The description of this PR title is user-oriented and clear enough for others to understand.
  • Attach the PR updating the user documentation if the current PR requires user awareness at the usage level. User docs repo

(Optional) Translate the PR title into Chinese.

(Optional) More detailed description for this PR(en: English/zh: Chinese).

en:
zh(optional):

(Optional) Which issue(s) this PR fixes:

(optional) The PR that updates user documentation:

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

license-eye has totally checked 53 files.

Valid Invalid Ignored Fixed
51 2 0 0
Click to see the invalid file list
  • src/lang/cxx/lib.go
  • src/lang/cxx/spec.go

@AsterDY
Copy link
Collaborator

AsterDY commented Apr 22, 2025

resolve the conflicts first @Hoblovski

@CLAassistant
Copy link

CLAassistant commented Apr 26, 2025

CLA assistant check
All committers have signed the CLA.

@HeyJavaBean
Copy link
Member

@AsterDY

1. Since clangd does not support semanticTokens/range method, use
  semanticTokens/full + filtering to emulate.
2. Since the concept of package and module does not apply to C/C++,
  treat the whole repo as a single package/module.
Hoblovski and others added 4 commits May 9, 2025 18:14
C allows symbols with the same name in a single module, provided either:
* One is a weak symbol (decl) and one is a strong symbol (def)
* They are both strong symbols, but never linked together.

The first one works fine, but more changes are needed for the second
one.

testdata/cxxsimple illustrates the first scenario. Two instances of
`myself` are present, one (weak) in `pair.h` and one (strong) in `pair.c`.
The dependency is well defined in this scneario:
1. `pair.c:myself` depends on `pair.h:myself`
2. any other function using `myself` depends on both.
To verify, run `./abcoder parse cxx testdata/cxxsimple > cxxsimple.json`.

testdata/cxxduplicate is the second scenario. Two strong instances of
`add` are present, each used in a different executable. clangd handles
this with compile_commands.json. If clangd is invoked as below, the
`main->add` dependency shall point to the `add` in `d1/add.c`.

	mkdir build && cd build && cmake ..
	bear -- make prog1 # generate compile_commands.json
	cd testdata/cduplicate && clangd-18

While clangd does the right job, the current implementation of scanning
during collection does not take into account which files are included in
a compilation (as specified in compile_commands.json). So
`Collector.Collect` will incorrectly include `d2/add.c` even if it is
not used, and mess up with dependencies. That is to say, even for the
compilation `prog1 <- main.c, d1/add.c`, a dependency
`main->d2/add.c:add` will be present.
@AsterDY AsterDY merged commit aaa32a8 into main May 28, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants