Skip to content

C#: Stub generator improvements. #10003

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 14 commits into from
Aug 15, 2022
Merged

Conversation

michaelnebel
Copy link
Contributor

@michaelnebel michaelnebel commented Aug 10, 2022

In this PR we introduce the following improvements to the the stub generator.

  • Enums are now explicitly typed and enum values are assigned.
  • Support for function pointers types.

This brings the stub generator in state where we almost can generate stubs for the ASP.NET Core and .NET Core frameworks without making manual changes to the generated code.
The only part that is now missing are some unsafe keywords (whether this is due to extraction errors or issues with the stub generator is unknown).

Furthermore, the subs for ASP.NET Core and .NET Core has been regenerated based on the newest version of the stub generator.

Closes https://github.com/github/codeql-csharp-team/issues/260

@github-actions github-actions bot added the C# label Aug 10, 2022
@michaelnebel michaelnebel marked this pull request as ready for review August 10, 2022 09:01
@michaelnebel michaelnebel requested a review from a team as a code owner August 10, 2022 09:01
@michaelnebel michaelnebel added the no-change-note-required This PR does not need a change note label Aug 10, 2022
hvitved
hvitved previously approved these changes Aug 10, 2022
@michaelnebel michaelnebel changed the title C#: Stub generator C#: Stub generator improvements. Aug 12, 2022
@@ -513,12 +513,30 @@ private string stubClassName(Type t) {
stubClassName(element), "," order by i
) + ")"
else
if t instanceof ValueOrRefType
if t instanceof FunctionPointerType
Copy link
Contributor

Choose a reason for hiding this comment

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

You can remove this if, and instead replace the matching else with or not t instanceof FunctionPointerType and

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure - we can do it like that instead - I just continued the pattern that was already there.
However, it might make things slightly more complicated, when adding new cases 😄

stubQualifiedNamePrefix(t) + t.getUndecoratedName() +
stubGenericArguments(t)
else result = "<error>"
exists(CallingConvention callconvention, string calltext |
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps add FunctionPointerType fpt, assign fpt = this, and replace the three t.(FunctionPointerType) with fpt.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I thought about that as well, but decided against it because last time I did it, the review comment recommend to do it the other way around 😄 But on the other hand, here we already have an exists, so it will make it nicer 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

It makes sense to introduce a new variable (either with exists or any) when there are multiple identical casts, as in this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great - that is the rule of 👍 I needed 😸

@@ -134,6 +134,34 @@ public class Nested : Class9

public Class9.Nested NestedInstance { get; } = new Class9.Nested(1);
}

public enum Enum1
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a test case with non-int enum?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, definitely yes!
and also a testcase for function pointers!

@michaelnebel michaelnebel merged commit 79a7164 into github:main Aug 15, 2022
@michaelnebel michaelnebel deleted the csharp/stubsenum branch August 15, 2022 10:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C# no-change-note-required This PR does not need a change note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants