Skip to content

Commit

Permalink
Use single 64-bit bindings + reduce bindings via whitelist functions
Browse files Browse the repository at this point in the history
  • Loading branch information
lithiumtoast committed Oct 30, 2021
1 parent c54e1b9 commit e6ee5c7
Show file tree
Hide file tree
Showing 18 changed files with 1,314 additions and 145,552 deletions.
176 changes: 1 addition & 175 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -64,178 +64,4 @@ end_of_line = lf

# Makefiles
[Makefile]
indent_style = tab

##########################################
# Default .NET Code Style Severities
# https://docs.microsoft.com/dotnet/fundamentals/code-analysis/configuration-options#scope
##########################################

[*.{cs,csx,cake,vb,vbx}]
# Default Severity for all .NET Code Style rules below
dotnet_analyzer_diagnostic.severity = error

##########################################
# .NET Language Conventions
# https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions
##########################################

# .NET Code Style Settings
# https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#net-code-style-settings
[*.{cs,csx,cake,vb,vbx}]
# "this." and "Me." qualifiers
# https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#this-and-me
dotnet_style_qualification_for_field = false:error
dotnet_style_qualification_for_property = false:error
dotnet_style_qualification_for_method = false:error
dotnet_style_qualification_for_event = false:error
# Language keywords instead of framework type names for type references
# https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#language-keywords
dotnet_style_predefined_type_for_locals_parameters_members = true:error
dotnet_style_predefined_type_for_member_access = true:error
# Modifier preferences
# https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#normalize-modifiers
dotnet_style_require_accessibility_modifiers = always:error
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:error
visual_basic_preferred_modifier_order = Partial,Default,Private,Protected,Public,Friend,NotOverridable,Overridable,MustOverride,Overloads,Overrides,MustInherit,NotInheritable,Static,Shared,Shadows,ReadOnly,WriteOnly,Dim,Const,WithEvents,Widening,Narrowing,Custom,Async:error
dotnet_style_readonly_field = true:error
# Parentheses preferences
# https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#parentheses-preferences
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:error
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:error
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:error
dotnet_style_parentheses_in_other_operators = always_for_clarity:error
# Expression-level preferences
# https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#expression-level-preferences
dotnet_style_object_initializer = true:error
dotnet_style_collection_initializer = true:error
dotnet_style_explicit_tuple_names = true:error
dotnet_style_prefer_inferred_tuple_names = true:error
dotnet_style_prefer_inferred_anonymous_type_member_names = true:error
dotnet_style_prefer_auto_properties = true:error
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:error
dotnet_style_prefer_conditional_expression_over_assignment = false:error
dotnet_diagnostic.IDE0045.severity = error
dotnet_style_prefer_conditional_expression_over_return = false:error
dotnet_diagnostic.IDE0046.severity = error
dotnet_style_prefer_compound_assignment = true:error
# Null-checking preferences
# https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#null-checking-preferences
dotnet_style_coalesce_expression = true:error
dotnet_style_null_propagation = true:error
# Parameter preferences
# https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#parameter-preferences
dotnet_code_quality_unused_parameters = all:error
# More style options (Undocumented)
# https://github.com/MicrosoftDocs/visualstudio-docs/issues/3641
dotnet_style_operator_placement_when_wrapping = end_of_line:error
# https://github.com/dotnet/roslyn/pull/40070
dotnet_style_prefer_simplified_interpolation = true:error

# C# Code Style Settings
# https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#c-code-style-settings
[*.{cs,csx,cake}]
# Implicit and explicit types
# https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#implicit-and-explicit-types
csharp_style_var_for_built_in_types = true:error
csharp_style_var_when_type_is_apparent = true:error
csharp_style_var_elsewhere = true:error
# Expression-bodied members
# https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#expression-bodied-members
csharp_style_expression_bodied_methods = false:error
csharp_style_expression_bodied_constructors = false:error
csharp_style_expression_bodied_operators = true:error
csharp_style_expression_bodied_properties = true:error
csharp_style_expression_bodied_indexers = true:error
csharp_style_expression_bodied_accessors = true:error
csharp_style_expression_bodied_lambdas = true:error
csharp_style_expression_bodied_local_functions = true:error
# Pattern matching
# https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#pattern-matching
csharp_style_pattern_matching_over_is_with_cast_check = true:error
csharp_style_pattern_matching_over_as_with_null_check = true:error
# Inlined variable declarations
# https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#inlined-variable-declarations
csharp_style_inlined_variable_declaration = true:error
# Expression-level preferences
# https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#expression-level-preferences
csharp_prefer_simple_default_expression = true:error
# "Null" checking preferences
# https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#c-null-checking-preferences
csharp_style_throw_expression = true:error
csharp_style_conditional_delegate_call = true:error
# Code block preferences
# https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#code-block-preferences
csharp_prefer_braces = when_multiline:error
csharp_prefer_simple_using_statement = false:error
# Unused value preferences
# https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#unused-value-preferences
csharp_style_unused_value_expression_statement_preference = discard_variable:error
dotnet_diagnostic.IDE0058.severity = error
csharp_style_unused_value_assignment_preference = discard_variable:error
dotnet_diagnostic.IDE0059.severity = error
# Index and range preferences
# https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#index-and-range-preferences
csharp_style_prefer_index_operator = true:error
csharp_style_prefer_range_operator = true:error
# Miscellaneous preferences
# https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#miscellaneous-preferences
csharp_style_deconstructed_variable_declaration = true:error
csharp_style_pattern_local_over_anonymous_function = true:error
csharp_using_directive_placement = outside_namespace:error
csharp_prefer_static_local_function = true:error
dotnet_diagnostic.IDE0063.severity = error

##########################################
# .NET Formatting Conventions
# https://docs.microsoft.com/visualstudio/ide/editorconfig-code-style-settings-reference#formatting-conventions
##########################################

# Organize usings
# https://docs.microsoft.com/visualstudio/ide/editorconfig-formatting-conventions#organize-using-directives
dotnet_sort_system_directives_first = true
# Newline options
# https://docs.microsoft.com/visualstudio/ide/editorconfig-formatting-conventions#new-line-options
csharp_new_line_before_open_brace = all
csharp_new_line_before_else = true
csharp_new_line_before_catch = true
csharp_new_line_before_finally = true
csharp_new_line_before_members_in_object_initializers = true
csharp_new_line_before_members_in_anonymous_types = true
csharp_new_line_between_query_expression_clauses = true
# Indentation options
# https://docs.microsoft.com/visualstudio/ide/editorconfig-formatting-conventions#indentation-options
csharp_indent_case_contents = true
csharp_indent_switch_labels = true
csharp_indent_labels = no_change
csharp_indent_block_contents = true
csharp_indent_braces = false
csharp_indent_case_contents_when_block = false
# Spacing options
# https://docs.microsoft.com/visualstudio/ide/editorconfig-formatting-conventions#spacing-options
csharp_space_after_cast = false
csharp_space_after_keywords_in_control_flow_statements = true
csharp_space_between_parentheses = false
csharp_space_before_colon_in_inheritance_clause = true
csharp_space_after_colon_in_inheritance_clause = true
csharp_space_around_binary_operators = before_and_after
csharp_space_between_method_declaration_parameter_list_parentheses = false
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
csharp_space_between_method_declaration_name_and_open_parenthesis = false
csharp_space_between_method_call_parameter_list_parentheses = false
csharp_space_between_method_call_empty_parameter_list_parentheses = false
csharp_space_between_method_call_name_and_opening_parenthesis = false
csharp_space_after_comma = true
csharp_space_before_comma = false
csharp_space_after_dot = false
csharp_space_before_dot = false
csharp_space_after_semicolon_in_for_statement = true
csharp_space_before_semicolon_in_for_statement = false
csharp_space_around_declaration_statements = false
csharp_space_before_open_square_brackets = false
csharp_space_between_empty_square_brackets = false
csharp_space_between_square_brackets = false
# Wrapping options
# https://docs.microsoft.com/visualstudio/ide/editorconfig-formatting-conventions#wrap-options
csharp_preserve_single_line_statements = false
csharp_preserve_single_line_blocks = true
indent_style = tab
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,8 @@ lib/
*.dylib
*.so

# C2CS artifacts
ast/

# macOS
.DS_Store
38 changes: 10 additions & 28 deletions src/cs/production/clang-c/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,6 @@ internal static class Program
{
private static void Main()
{
var runtimeIdentifierOperatingSystem = string.Empty;
if (OperatingSystem.IsWindows())
{
runtimeIdentifierOperatingSystem = "win";
}
else if (OperatingSystem.IsMacOS())
{
runtimeIdentifierOperatingSystem = "osx";
}
else if (OperatingSystem.IsLinux())
{
runtimeIdentifierOperatingSystem = "linux";
}

var runtimeIdentifier32Bits = runtimeIdentifierOperatingSystem + "32";
var runtimeIdentifier64Bits = runtimeIdentifierOperatingSystem + "64";

var searchDirectory = Path.TrimEndingDirectorySeparator(AppContext.BaseDirectory);
var directoryName = searchDirectory[(searchDirectory.LastIndexOf(Path.DirectorySeparatorChar) + 1)..];
while (directoryName != "bin")
Expand All @@ -35,40 +18,39 @@ private static void Main()
}

var rootDirectory = Path.GetFullPath(Path.Combine(searchDirectory, ".."));
GenerateAbstractSyntaxTree(rootDirectory, runtimeIdentifier64Bits);
GenerateAbstractSyntaxTree(rootDirectory, runtimeIdentifier32Bits);
GenerateBindingsCSharp(rootDirectory, runtimeIdentifier64Bits);
GenerateBindingsCSharp(rootDirectory, runtimeIdentifier32Bits);
GenerateCAbstractSyntaxTree(rootDirectory);
GenerateCSharpBindings(rootDirectory);
}

private static void GenerateAbstractSyntaxTree(string rootDirectory, string runtimeIdentifier)
private static void GenerateCAbstractSyntaxTree(string rootDirectory)
{
var bitness = runtimeIdentifier.EndsWith("64", StringComparison.InvariantCulture) ? "64" : "32";

const string bitness = "64";
var arguments = @$"
ast
-i
{rootDirectory}/ext/clang/include/clang-c/Index.h
-s
{rootDirectory}/ext/clang/include
-o
{rootDirectory}/src/cs/production/clang-c/ast.{runtimeIdentifier}.json
{rootDirectory}/src/cs/production/clang-c/ast/clang.json
-b
{bitness}
-w
{rootDirectory}/src/cs/production/clang-c/api.txt
";
var argumentsArray =
arguments.Split(new[] { "\n", "\r" }, StringSplitOptions.RemoveEmptyEntries);
C2CS.Program.Main(argumentsArray);
}

private static void GenerateBindingsCSharp(string rootDirectory, string runtimeIdentifier)
private static void GenerateCSharpBindings(string rootDirectory)
{
var arguments = @$"
cs
-i
{rootDirectory}/src/cs/production/clang-c/ast.{runtimeIdentifier}.json
{rootDirectory}/src/cs/production/clang-c/ast/clang.json
-o
{rootDirectory}/src/cs/production/clang-cs/clang.{runtimeIdentifier}.cs
{rootDirectory}/src/cs/production/clang-cs/clang.cs
-l
libclang
";
Expand Down
46 changes: 46 additions & 0 deletions src/cs/production/clang-c/api.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
clang_Cursor_getOffsetOfField
clang_Cursor_getTranslationUnit
clang_Cursor_isAnonymous
clang_Cursor_isMacroBuiltin
clang_Cursor_isMacroFunctionLike
clang_Location_isInSystemHeader
clang_Type_getAlignOf
clang_Type_getModifiedType
clang_Type_getNamedType
clang_Type_getSizeOf
clang_createIndex
clang_defaultDiagnosticDisplayOptions
clang_disposeTokens
clang_disposeTokens
clang_formatDiagnostic
clang_getArrayElementType
clang_getArrayElementType
clang_getArraySize
clang_getCString
clang_getCString
clang_getCursorExtent
clang_getCursorKind
clang_getCursorLinkage
clang_getCursorLocation
clang_getCursorResultType
clang_getCursorSpelling
clang_getCursorType
clang_getDiagnostic
clang_getDiagnosticSeverity
clang_getElementType
clang_getEnumConstantDeclValue
clang_getEnumDeclIntegerType
clang_getFileLocation
clang_getFileName
clang_getFunctionTypeCallingConv
clang_getNumDiagnostics
clang_getPointeeType
clang_getResultType
clang_getTokenSpelling
clang_getTranslationUnitCursor
clang_getTypeDeclaration
clang_getTypeSpelling
clang_getTypedefDeclUnderlyingType
clang_parseTranslationUnit2
clang_tokenize
clang_visitChildren
Loading

0 comments on commit e6ee5c7

Please sign in to comment.