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

Adding support for parsing expressions attached to EnumConstantDecl #45

Merged
merged 3 commits into from
May 11, 2019

Conversation

tannergooding
Copy link
Member

This just updates the binding generator to traverse expressions attached to enum constant declarations. This means that the generated code will more closely match the source files.

CXAvailability_Deprecated = 1,
CXAvailability_NotAvailable = 2,
CXAvailability_NotAccessible = 3,
CXAvailability_Available,
Copy link
Member Author

Choose a reason for hiding this comment

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

The header file doesn't explicitly set the values for most enums and we don't need to either.

@@ -13,7 +13,7 @@ public enum CXCallingConv
CXCallingConv_X86RegCall = 8,
CXCallingConv_IntelOclBicc = 9,
CXCallingConv_Win64 = 10,
CXCallingConv_X86_64Win64 = 10,
CXCallingConv_X86_64Win64 = CXCallingConv_Win64,
Copy link
Member Author

Choose a reason for hiding this comment

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

An example of traversing a declaration reference expression

CXCodeComplete_IncludeBriefComments = 4,
CXCodeComplete_SkipPreamble = 8,
CXCodeComplete_IncludeCompletionsWithFixIts = 16,
CXCodeComplete_IncludeMacros = 0x01,
Copy link
Member Author

Choose a reason for hiding this comment

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

An example of traversing an integer literal expression

CXCompletionContext_NaturalLanguage = 2097152,
CXCompletionContext_IncludedFile = 4194304,
CXCompletionContext_Unknown = 8388607,
CXCompletionContext_AnyType = 1 << 0,
Copy link
Member Author

Choose a reason for hiding this comment

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

An example of traversing a binary operator expression

Copy link
Contributor

Choose a reason for hiding this comment

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

Very nice!

CXCompletionContext_MacroName = 1 << 20,
CXCompletionContext_NaturalLanguage = 1 << 21,
CXCompletionContext_IncludedFile = 1 << 22,
CXCompletionContext_Unknown = ((1 << 23) - 1),
Copy link
Member Author

Choose a reason for hiding this comment

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

even works with parentheses

CXGlobalOpt_None = 0x0,
CXGlobalOpt_ThreadBackgroundPriorityForIndexing = 0x1,
CXGlobalOpt_ThreadBackgroundPriorityForEditing = 0x2,
CXGlobalOpt_ThreadBackgroundPriorityForAll = CXGlobalOpt_ThreadBackgroundPriorityForIndexing | CXGlobalOpt_ThreadBackgroundPriorityForEditing,
Copy link
Member Author

Choose a reason for hiding this comment

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

and combining multiple declaration references

@@ -3,8 +3,8 @@ namespace ClangSharp
public enum CXLanguageKind
{
CXLanguage_Invalid = 0,
Copy link
Member Author

Choose a reason for hiding this comment

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

An example of the native header explicitly setting the value for one entry, but not the subsequent declarations

@@ -89,12 +89,17 @@ public static int Run(InvocationContext context)
arr = arr.Concat(defines.Select(x => "-D" + x)).ToArray();
arr = arr.Concat(additionalArgs).ToArray();

var translationFlags = CXTranslationUnit_Flags.CXTranslationUnit_None;
Copy link
Member Author

Choose a reason for hiding this comment

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

Also updated this to start passing in some flags. Namely, not processing function bodies currently and including implicit attribute information (which ensures we aren't missing anything if the user specifies additional command line options).

@@ -258,7 +268,7 @@ public CXChildVisitResult VisitTranslationUnit(CXCursor cursor, CXCursor parent,
{
Debug.Assert(parent.Kind == CXCursorKind.CXCursor_TranslationUnit);

if (cursor.Location.IsInSystemHeader || !cursor.Location.IsFromMainFile)
if (!cursor.Location.IsFromMainFile)
Copy link
Member Author

Choose a reason for hiding this comment

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

Changed this to just check if we aren't in the main file; which ultimately allows users to generate bindings for system headers as well.

@mjsabby
Copy link
Contributor

mjsabby commented May 11, 2019

This is an exciting change! Thank you so much.

@tannergooding tannergooding merged commit 0d6204a into dotnet:master May 11, 2019
@tannergooding tannergooding deleted the enumconstantexpr branch May 11, 2019 23:41
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