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

Introduce clang_getCursorKind #150

Merged
merged 2 commits into from
Sep 4, 2024
Merged

Introduce clang_getCursorKind #150

merged 2 commits into from
Sep 4, 2024

Conversation

edsko
Copy link
Collaborator

@edsko edsko commented Sep 4, 2024

We were using clang_getCursorType to determine what kind of AST element we were dealing with, but that's not quite right; we should instead be using clang_getCursorKind. For example, this tells us that we are dealing with an enum declaration (which happens to be reported as type enum); this matters in some cases, for example, a macro definition does not have any associated type (reported as "invalid"), but is reported as cursor kind "macro definition".

We were using `clang_getCursorType` to determine what kind of AST element we
were dealing with, but that's not quite right; we should instead be using
`clang_getCursorKind`. For example, this tells us that we are dealing with an
enum declaration (which happens to be reported as type enum); this matters in
some cases, for example, a macro definition does not have any associated type
(reported as "invalid"), but is reported as cursor kind "macro definition".
@edsko edsko force-pushed the edsko/cursor-kind branch from 70ef943 to eb7cf43 Compare September 4, 2024 13:52
"PACKED_C" :: "Int"
"macro definition" "ENUMS_H" :: "Invalid"
"EnumDecl" "first" :: "Enum"
"EnumConstantDecl" "FIRST1" :: "Int"
Copy link
Collaborator

Choose a reason for hiding this comment

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

does this mean that we don't need to check parent when getting enum value, checking the kind of the cursor is enough?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah, yes, well-spotted. Will fix.

In order to do the error check we need to check the cursor kind; previously we
were (incorrectly?) looking at the _type_ kind, which for an enum member will
just report `Int`, which isn't particularly informative. We therefore looked at
the type kind of the _parent_, but instead we should just look at the kind of
the _cursor_ (which will be `EnumConstantDecl`).
@edsko edsko merged commit 00969e0 into main Sep 4, 2024
7 checks passed
@edsko edsko deleted the edsko/cursor-kind branch September 4, 2024 14:05
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

Successfully merging this pull request may close these issues.

2 participants