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

Fix incorrect tag generation for enum classes #1900

Merged
merged 1 commit into from
Feb 8, 2025

Conversation

duckdoom5
Copy link
Contributor

Currently invalid source is generated for scoped enums (enum class).

This patch will resolve this issue by adding class when it is a scoped enum.

I've also added an early out to skip printing the tag is the class isn't incomplete, since that shouldn't be necessary in those cases. (Though maybe we should add this as an option so you'd still be able to force print it. Eg. new method PrintTagIfNeeded?)

@duckdoom5 duckdoom5 mentioned this pull request Feb 3, 2025
5 tasks
@tritao
Copy link
Collaborator

tritao commented Feb 3, 2025

@duckdoom5
Copy link
Contributor Author

Hm, interesting.. I guess it's not enough to know if it's incomplete or not. Might look into it a bit tomorrow or just remove the early out for now

@duckdoom5
Copy link
Contributor Author

duckdoom5 commented Feb 4, 2025

@tritao
Okay, so I've been looking into this and it seems relatively easy to fix. I just need to check if there is an ambiguous name within the current namespace. So, I've added that function.

I'm just running into an issue:
image

Can you tell me why the stdlib.h functions are not included in the ASTContext?

@tritao
Copy link
Collaborator

tritao commented Feb 4, 2025

@tritao Okay, so I've been looking into this and it seems relatively easy to fix. I just need to check if there is an ambiguous name within the current namespace. So, I've added that function.

I'm just running into an issue: image

Can you tell me why the stdlib.h functions are not included in the ASTContext?

I think it's because of this: https://github.com/mono/CppSharp/blob/main/src/CppParser/Parser.cpp#L1025

e965803

Basically it's almost rarely needed for binding purposes and makes a difference when it comes to performance.

I am guessing it's causing issues in this new approach for this PR?

@duckdoom5
Copy link
Contributor Author

Ah yeah, that makes total sense.
I'll convert that into an option and default it to skip like it is now. That should resolve this issue

@duckdoom5
Copy link
Contributor Author

duckdoom5 commented Feb 5, 2025

@tritao So ran into a couple of issues again which I resolved today. I'll make more PR's for those in a bit.

Last issue I'm dealing with now, is that if I enable parsing of the system headers, the generated Std-Symbols.cpp file adds the following invalid declaration:
template __declspec(dllexport) std::char_traits<char>& std::char_traits<char>::operator=(std::char_traits<char>&&);

1 error generated.
\CppSharp\build\gen\Common\Std-symbols.cpp(7,80): error: explicit instantiation refers to member function 'std::char_traits::operator=' that is not an instantiation
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.42.34433\include__msvc_string_view.hpp(465,8): note: explicit instantiation refers here

Any ideas? (I should also note that it now adds way more declarations then before)

@tritao
Copy link
Collaborator

tritao commented Feb 6, 2025

Kinda hard to say why, but if it's getting generated then presumably CppSharp think it's needed when it shouldn't, so maybe we should just ignore such std::char_traits from consideration. If more stuff is getting generated, then I guess we need to be way more agressive in general in pruning system things from being generated.

It could be we're missing some check in those passes to skip system headers.

@duckdoom5
Copy link
Contributor Author

Hm, yeah I noticed some other things as well, but I'll leave that discussion for later. Want to get this fixed first and maybe then ask some questions about how some things are designed currently cus I'm a little confused about translations units atm.

@duckdoom5 duckdoom5 force-pushed the fix/invalid-scoped-enum-tag branch from 00b8109 to 030e0cf Compare February 8, 2025 08:53
@tritao tritao merged commit 7fd8727 into mono:main Feb 8, 2025
7 checks passed
@duckdoom5 duckdoom5 deleted the fix/invalid-scoped-enum-tag branch February 8, 2025 14:55
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