From 8719140d39047033b96b2b2053a0dfdd69d1dcf2 Mon Sep 17 00:00:00 2001 From: Levi Lesches Date: Mon, 10 Jun 2024 16:55:29 -0400 Subject: [PATCH 01/16] Enums as return types now work --- .../lib/src/code_generator/enum_class.dart | 17 ++++++++++++++++- pkgs/ffigen/lib/src/code_generator/func.dart | 17 +++++++++++------ 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/pkgs/ffigen/lib/src/code_generator/enum_class.dart b/pkgs/ffigen/lib/src/code_generator/enum_class.dart index 02e1bfc00d..1775cb3bce 100644 --- a/pkgs/ffigen/lib/src/code_generator/enum_class.dart +++ b/pkgs/ffigen/lib/src/code_generator/enum_class.dart @@ -192,6 +192,16 @@ class EnumClass extends BindingType { s.write("sealed class $name { }\n"); } + void writeFromValue(StringBuffer s) { + s.write("${depth}static $name fromValue(int value) => switch (value) {\n"); + for (final member in uniqueMembers) { + final memberName = enumNames[member]!; + s.write("$depth$depth${member.value} => $memberName,\n"); + } + s.write('$depth${depth}_ => throw ArgumentError("Invalid value for $name: \$value"),\n'); + s.write("$depth};"); + } + @override BindingString toBindingString(Writer w) { final s = StringBuffer(); @@ -208,6 +218,8 @@ class EnumClass extends BindingType { s.write("\n"); writeConstructor(s); s.write("\n"); + writeFromValue(s); + s.write("\n"); writeToStringOverride(s); s.write('}\n\n'); } @@ -230,11 +242,14 @@ class EnumClass extends BindingType { @override String getFfiDartType(Writer w) => nativeType.getFfiDartType(w); + @override + String getDartType(Writer w) => name; + @override bool get sameFfiDartAndCType => nativeType.sameFfiDartAndCType; @override - bool get sameDartAndCType => nativeType.sameDartAndCType; + bool get sameDartAndCType => false; @override String? getDefaultValue(Writer w) => '0'; diff --git a/pkgs/ffigen/lib/src/code_generator/func.dart b/pkgs/ffigen/lib/src/code_generator/func.dart index 05d67d40c2..6e5e8a3ec5 100644 --- a/pkgs/ffigen/lib/src/code_generator/func.dart +++ b/pkgs/ffigen/lib/src/code_generator/func.dart @@ -110,6 +110,7 @@ class Func extends LookUpBinding { final dartType = _exposedFunctionTypealias?.getFfiDartType(w) ?? functionType.getFfiDartType(w, writeArgumentNames: false); final needsWrapper = !functionType.sameDartAndFfiDartType && !isInternal; + final returnsEnum = functionType.returnType is EnumClass; final funcVarName = w.wrapperLevelUniqueNamer.makeUnique('_$name'); final ffiReturnType = functionType.returnType.getFfiDartType(w); @@ -176,12 +177,16 @@ $dartReturnType $enclosingFuncName($dartArgDeclString) => $funcImplCall; final isLeafString = isLeaf ? 'isLeaf:true' : ''; // Write enclosing function. - s.write(''' -$dartReturnType $enclosingFuncName($dartArgDeclString) { - return $funcImplCall; -} - -'''); + if (returnsEnum) { + final enumName = functionType.returnType.getDartType(w); + s.write("\n$enumName $enclosingFuncName($dartArgDeclString) {\n"); + s.write("return $enumName.fromValue($funcImplCall);\n"); + s.write("}\n"); + } else { + s.write("\n$dartReturnType $enclosingFuncName($dartArgDeclString) {\n"); + s.write("return $funcImplCall;\n"); + s.write("}\n"); + } if (exposeSymbolAddress) { // Add to SymbolAddress in writer. From ee664492370f3987aec8f730b1a512d46d1a6fba Mon Sep 17 00:00:00 2001 From: Levi Lesches Date: Mon, 10 Jun 2024 17:05:26 -0400 Subject: [PATCH 02/16] Enum values in args and return types are real enums not ints --- .../lib/src/code_generator/enum_class.dart | 19 +++++++++++++++++-- pkgs/ffigen/lib/src/code_generator/func.dart | 14 +++----------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/pkgs/ffigen/lib/src/code_generator/enum_class.dart b/pkgs/ffigen/lib/src/code_generator/enum_class.dart index 1775cb3bce..ea574ac61b 100644 --- a/pkgs/ffigen/lib/src/code_generator/enum_class.dart +++ b/pkgs/ffigen/lib/src/code_generator/enum_class.dart @@ -246,13 +246,28 @@ class EnumClass extends BindingType { String getDartType(Writer w) => name; @override - bool get sameFfiDartAndCType => nativeType.sameFfiDartAndCType; + bool get sameFfiDartAndCType => false; @override - bool get sameDartAndCType => false; + bool get sameDartAndFfiDartType => false; @override String? getDefaultValue(Writer w) => '0'; + + @override + String convertDartTypeToFfiDartType( + Writer w, + String value, { + required bool objCRetain, + }) => "$value.value"; + + @override + String convertFfiDartTypeToDartType( + Writer w, + String value, { + required bool objCRetain, + String? objCEnclosingClass, + }) => "$name.fromValue($value)"; } /// Represents a single value in an enum. diff --git a/pkgs/ffigen/lib/src/code_generator/func.dart b/pkgs/ffigen/lib/src/code_generator/func.dart index 6e5e8a3ec5..33bbc91464 100644 --- a/pkgs/ffigen/lib/src/code_generator/func.dart +++ b/pkgs/ffigen/lib/src/code_generator/func.dart @@ -110,7 +110,6 @@ class Func extends LookUpBinding { final dartType = _exposedFunctionTypealias?.getFfiDartType(w) ?? functionType.getFfiDartType(w, writeArgumentNames: false); final needsWrapper = !functionType.sameDartAndFfiDartType && !isInternal; - final returnsEnum = functionType.returnType is EnumClass; final funcVarName = w.wrapperLevelUniqueNamer.makeUnique('_$name'); final ffiReturnType = functionType.returnType.getFfiDartType(w); @@ -177,16 +176,9 @@ $dartReturnType $enclosingFuncName($dartArgDeclString) => $funcImplCall; final isLeafString = isLeaf ? 'isLeaf:true' : ''; // Write enclosing function. - if (returnsEnum) { - final enumName = functionType.returnType.getDartType(w); - s.write("\n$enumName $enclosingFuncName($dartArgDeclString) {\n"); - s.write("return $enumName.fromValue($funcImplCall);\n"); - s.write("}\n"); - } else { - s.write("\n$dartReturnType $enclosingFuncName($dartArgDeclString) {\n"); - s.write("return $funcImplCall;\n"); - s.write("}\n"); - } + s.write("\n$dartReturnType $enclosingFuncName($dartArgDeclString) {\n"); + s.write("return $funcImplCall;\n"); + s.write("}\n"); if (exposeSymbolAddress) { // Add to SymbolAddress in writer. From d30ee0adc65dc85cdbaf65f012b3e30402cb01ac Mon Sep 17 00:00:00 2001 From: Levi Lesches Date: Mon, 10 Jun 2024 17:14:11 -0400 Subject: [PATCH 03/16] Documented --- pkgs/ffigen/lib/src/code_generator/enum_class.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/pkgs/ffigen/lib/src/code_generator/enum_class.dart b/pkgs/ffigen/lib/src/code_generator/enum_class.dart index ea574ac61b..1fc82353dc 100644 --- a/pkgs/ffigen/lib/src/code_generator/enum_class.dart +++ b/pkgs/ffigen/lib/src/code_generator/enum_class.dart @@ -192,6 +192,7 @@ class EnumClass extends BindingType { s.write("sealed class $name { }\n"); } + /// Writes a static function that maps integers to enum values. void writeFromValue(StringBuffer s) { s.write("${depth}static $name fromValue(int value) => switch (value) {\n"); for (final member in uniqueMembers) { From 24cff464659c67ce689aa044f150a21cc9182fed Mon Sep 17 00:00:00 2001 From: Levi Lesches Date: Mon, 10 Jun 2024 17:14:55 -0400 Subject: [PATCH 04/16] Formatted --- pkgs/ffigen/lib/src/code_generator/enum_class.dart | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pkgs/ffigen/lib/src/code_generator/enum_class.dart b/pkgs/ffigen/lib/src/code_generator/enum_class.dart index 1fc82353dc..834b18d735 100644 --- a/pkgs/ffigen/lib/src/code_generator/enum_class.dart +++ b/pkgs/ffigen/lib/src/code_generator/enum_class.dart @@ -199,7 +199,10 @@ class EnumClass extends BindingType { final memberName = enumNames[member]!; s.write("$depth$depth${member.value} => $memberName,\n"); } - s.write('$depth${depth}_ => throw ArgumentError("Invalid value for $name: \$value"),\n'); + s.write( + '$depth${depth}_ => ' + 'throw ArgumentError("Invalid value for $name: \$value"),\n', + ); s.write("$depth};"); } @@ -260,7 +263,8 @@ class EnumClass extends BindingType { Writer w, String value, { required bool objCRetain, - }) => "$value.value"; + }) => + "$value.value"; @override String convertFfiDartTypeToDartType( @@ -268,7 +272,8 @@ class EnumClass extends BindingType { String value, { required bool objCRetain, String? objCEnclosingClass, - }) => "$name.fromValue($value)"; + }) => + "$name.fromValue($value)"; } /// Represents a single value in an enum. From cb55149aa9cb81df710c56272715168298a8ce54 Mon Sep 17 00:00:00 2001 From: Levi Lesches Date: Mon, 10 Jun 2024 17:19:37 -0400 Subject: [PATCH 05/16] Updated Changelog --- pkgs/ffigen/CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkgs/ffigen/CHANGELOG.md b/pkgs/ffigen/CHANGELOG.md index 5ba93e159f..bb4078513f 100644 --- a/pkgs/ffigen/CHANGELOG.md +++ b/pkgs/ffigen/CHANGELOG.md @@ -7,6 +7,9 @@ abstract classes. Since Dart enums cannot be empty, empty native enums are generated as empty sealed classes. Native enum members with duplicate integer values are handled properly, and are equal to each other in Dart as well. +- __Breaking change__: ffigen now emits code that uses the Dart enums in return + types and argument types, allowing you to use them as normal Dart enums without + converting to and from their integer values. - Rename ObjC interface methods that clash with type names. Fixes https://github.com/dart-lang/native/issues/1007. From 7cd729da01b9dd5d58f691a7a7acba70c1e41567 Mon Sep 17 00:00:00 2001 From: Levi Lesches Date: Mon, 10 Jun 2024 18:07:00 -0400 Subject: [PATCH 06/16] All tests are passing --- .../libclang-example/generated_bindings.dart | 931 ++++++++++++-- .../shared_bindings/lib/generated/a_gen.dart | 6 + .../lib/generated/a_shared_b_gen.dart | 6 + .../lib/src/code_generator/enum_class.dart | 2 +- pkgs/ffigen/lib/src/code_generator/func.dart | 4 +- .../_expected_enumclass_bindings.dart | 6 + ...xpected_enumclass_duplicates_bindings.dart | 6 + .../_expected_forward_decl_bindings.dart | 10 +- .../_expected_typedef_bindings.dart | 12 + .../_expected_libclang_bindings.dart | 1140 +++++++++++++++-- 10 files changed, 1892 insertions(+), 231 deletions(-) diff --git a/pkgs/ffigen/example/libclang-example/generated_bindings.dart b/pkgs/ffigen/example/libclang-example/generated_bindings.dart index ecc179953d..636cc9aa62 100644 --- a/pkgs/ffigen/example/libclang-example/generated_bindings.dart +++ b/pkgs/ffigen/example/libclang-example/generated_bindings.dart @@ -1051,12 +1051,12 @@ class LibClang { .asFunction(); /// Determine the severity of the given diagnostic. - int clang_getDiagnosticSeverity( + CXDiagnosticSeverity clang_getDiagnosticSeverity( CXDiagnostic arg0, ) { - return _clang_getDiagnosticSeverity( + return CXDiagnosticSeverity.fromValue(_clang_getDiagnosticSeverity( arg0, - ); + )); } late final _clang_getDiagnosticSeverityPtr = @@ -1392,16 +1392,16 @@ class LibClang { /// \c CXTranslationUnit. /// /// \returns Zero on success, otherwise returns an error code. - int clang_createTranslationUnit2( + CXErrorCode clang_createTranslationUnit2( CXIndex CIdx, ffi.Pointer ast_filename, ffi.Pointer out_TU, ) { - return _clang_createTranslationUnit2( + return CXErrorCode.fromValue(_clang_createTranslationUnit2( CIdx, ast_filename, out_TU, - ); + )); } late final _clang_createTranslationUnit2Ptr = @@ -1503,7 +1503,7 @@ class LibClang { /// diagnostics produced by the compiler. /// /// \returns Zero on success, otherwise returns an error code. - int clang_parseTranslationUnit2( + CXErrorCode clang_parseTranslationUnit2( CXIndex CIdx, ffi.Pointer source_filename, ffi.Pointer> command_line_args, @@ -1513,7 +1513,7 @@ class LibClang { int options, ffi.Pointer out_TU, ) { - return _clang_parseTranslationUnit2( + return CXErrorCode.fromValue(_clang_parseTranslationUnit2( CIdx, source_filename, command_line_args, @@ -1522,7 +1522,7 @@ class LibClang { num_unsaved_files, options, out_TU, - ); + )); } late final _clang_parseTranslationUnit2Ptr = @@ -1534,7 +1534,7 @@ class LibClang { /// Same as clang_parseTranslationUnit2 but requires a full command line /// for \c command_line_args including argv[0]. This is useful if the standard /// library paths are relative to the binary. - int clang_parseTranslationUnit2FullArgv( + CXErrorCode clang_parseTranslationUnit2FullArgv( CXIndex CIdx, ffi.Pointer source_filename, ffi.Pointer> command_line_args, @@ -1544,7 +1544,7 @@ class LibClang { int options, ffi.Pointer out_TU, ) { - return _clang_parseTranslationUnit2FullArgv( + return CXErrorCode.fromValue(_clang_parseTranslationUnit2FullArgv( CIdx, source_filename, command_line_args, @@ -1553,7 +1553,7 @@ class LibClang { num_unsaved_files, options, out_TU, - ); + )); } late final _clang_parseTranslationUnit2FullArgvPtr = @@ -1739,10 +1739,10 @@ class LibClang { /// Returns the human-readable null-terminated C string that represents /// the name of the memory category. This string should never be freed. ffi.Pointer clang_getTUResourceUsageName( - int kind, + CXTUResourceUsageKind kind, ) { return _clang_getTUResourceUsageName( - kind, + kind.value, ); } @@ -1928,12 +1928,12 @@ class LibClang { _clang_hashCursorPtr.asFunction(); /// Retrieve the kind of the given cursor. - int clang_getCursorKind( + CXCursorKind clang_getCursorKind( CXCursor arg0, ) { - return _clang_getCursorKind( + return CXCursorKind.fromValue(_clang_getCursorKind( arg0, - ); + )); } late final _clang_getCursorKindPtr = @@ -1944,10 +1944,10 @@ class LibClang { /// Determine whether the given cursor kind represents a declaration. int clang_isDeclaration( - int arg0, + CXCursorKind arg0, ) { return _clang_isDeclaration( - arg0, + arg0.value, ); } @@ -1984,10 +1984,10 @@ class LibClang { /// other cursors. Use clang_getCursorReferenced() to determine whether a /// particular cursor refers to another entity. int clang_isReference( - int arg0, + CXCursorKind arg0, ) { return _clang_isReference( - arg0, + arg0.value, ); } @@ -1998,10 +1998,10 @@ class LibClang { /// Determine whether the given cursor kind represents an expression. int clang_isExpression( - int arg0, + CXCursorKind arg0, ) { return _clang_isExpression( - arg0, + arg0.value, ); } @@ -2013,10 +2013,10 @@ class LibClang { /// Determine whether the given cursor kind represents a statement. int clang_isStatement( - int arg0, + CXCursorKind arg0, ) { return _clang_isStatement( - arg0, + arg0.value, ); } @@ -2027,10 +2027,10 @@ class LibClang { /// Determine whether the given cursor kind represents an attribute. int clang_isAttribute( - int arg0, + CXCursorKind arg0, ) { return _clang_isAttribute( - arg0, + arg0.value, ); } @@ -2057,10 +2057,10 @@ class LibClang { /// Determine whether the given cursor kind represents an invalid /// cursor. int clang_isInvalid( - int arg0, + CXCursorKind arg0, ) { return _clang_isInvalid( - arg0, + arg0.value, ); } @@ -2072,10 +2072,10 @@ class LibClang { /// Determine whether the given cursor kind represents a translation /// unit. int clang_isTranslationUnit( - int arg0, + CXCursorKind arg0, ) { return _clang_isTranslationUnit( - arg0, + arg0.value, ); } @@ -2088,10 +2088,10 @@ class LibClang { /// Determine whether the given cursor represents a preprocessing /// element, such as a preprocessor directive or macro instantiation. int clang_isPreprocessing( - int arg0, + CXCursorKind arg0, ) { return _clang_isPreprocessing( - arg0, + arg0.value, ); } @@ -2104,10 +2104,10 @@ class LibClang { /// Determine whether the given cursor represents a currently /// unexposed piece of the AST (e.g., CXCursor_UnexposedStmt). int clang_isUnexposed( - int arg0, + CXCursorKind arg0, ) { return _clang_isUnexposed( - arg0, + arg0.value, ); } @@ -2117,12 +2117,12 @@ class LibClang { _clang_isUnexposedPtr.asFunction(); /// Determine the linkage of the entity referred to by a given cursor. - int clang_getCursorLinkage( + CXLinkageKind clang_getCursorLinkage( CXCursor cursor, ) { - return _clang_getCursorLinkage( + return CXLinkageKind.fromValue(_clang_getCursorLinkage( cursor, - ); + )); } late final _clang_getCursorLinkagePtr = @@ -2140,12 +2140,12 @@ class LibClang { /// \param cursor The cursor to query. /// /// \returns The visibility of the cursor. - int clang_getCursorVisibility( + CXVisibilityKind clang_getCursorVisibility( CXCursor cursor, ) { - return _clang_getCursorVisibility( + return CXVisibilityKind.fromValue(_clang_getCursorVisibility( cursor, - ); + )); } late final _clang_getCursorVisibilityPtr = @@ -2160,12 +2160,12 @@ class LibClang { /// \param cursor The cursor to query. /// /// \returns The availability of the cursor. - int clang_getCursorAvailability( + CXAvailabilityKind clang_getCursorAvailability( CXCursor cursor, ) { - return _clang_getCursorAvailability( + return CXAvailabilityKind.fromValue(_clang_getCursorAvailability( cursor, - ); + )); } late final _clang_getCursorAvailabilityPtr = @@ -2252,12 +2252,12 @@ class LibClang { .asFunction(); /// Determine the "language" of the entity referred to by a given cursor. - int clang_getCursorLanguage( + CXLanguageKind clang_getCursorLanguage( CXCursor cursor, ) { - return _clang_getCursorLanguage( + return CXLanguageKind.fromValue(_clang_getCursorLanguage( cursor, - ); + )); } late final _clang_getCursorLanguagePtr = @@ -2268,12 +2268,12 @@ class LibClang { /// Determine the "thread-local storage (TLS) kind" of the declaration /// referred to by a cursor. - int clang_getCursorTLSKind( + CXTLSKind clang_getCursorTLSKind( CXCursor cursor, ) { - return _clang_getCursorTLSKind( + return CXTLSKind.fromValue(_clang_getCursorTLSKind( cursor, - ); + )); } late final _clang_getCursorTLSKindPtr = @@ -2830,14 +2830,15 @@ class LibClang { /// /// For I = 0, 1, and 2, Type, Integral, and Integral will be returned, /// respectively. - int clang_Cursor_getTemplateArgumentKind( + CXTemplateArgumentKind clang_Cursor_getTemplateArgumentKind( CXCursor C, int I, ) { - return _clang_Cursor_getTemplateArgumentKind( + return CXTemplateArgumentKind.fromValue( + _clang_Cursor_getTemplateArgumentKind( C, I, - ); + )); } late final _clang_Cursor_getTemplateArgumentKindPtr = @@ -3177,10 +3178,10 @@ class LibClang { /// Retrieve the spelling of a given CXTypeKind. CXString clang_getTypeKindSpelling( - int K, + CXTypeKind K, ) { return _clang_getTypeKindSpelling( - K, + K.value, ); } @@ -3193,12 +3194,12 @@ class LibClang { /// Retrieve the calling convention associated with a function type. /// /// If a non-function type is passed in, CXCallingConv_Invalid is returned. - int clang_getFunctionTypeCallingConv( + CXCallingConv clang_getFunctionTypeCallingConv( CXType T, ) { - return _clang_getFunctionTypeCallingConv( + return CXCallingConv.fromValue(_clang_getFunctionTypeCallingConv( T, - ); + )); } late final _clang_getFunctionTypeCallingConvPtr = @@ -3550,12 +3551,12 @@ class LibClang { .asFunction(); /// Retrieve the nullability kind of a pointer type. - int clang_Type_getNullability( + CXTypeNullabilityKind clang_Type_getNullability( CXType T, ) { - return _clang_Type_getNullability( + return CXTypeNullabilityKind.fromValue(_clang_Type_getNullability( T, - ); + )); } late final _clang_Type_getNullabilityPtr = @@ -3788,12 +3789,12 @@ class LibClang { /// /// The ref-qualifier is returned for C++ functions or methods. For other types /// or non-C++ declarations, CXRefQualifier_None is returned. - int clang_Type_getCXXRefQualifier( + CXRefQualifierKind clang_Type_getCXXRefQualifier( CXType T, ) { - return _clang_Type_getCXXRefQualifier( + return CXRefQualifierKind.fromValue(_clang_Type_getCXXRefQualifier( T, - ); + )); } late final _clang_Type_getCXXRefQualifierPtr = @@ -3839,12 +3840,12 @@ class LibClang { /// If the cursor refers to a C++ declaration, its access control level within its /// parent scope is returned. Otherwise, if the cursor refers to a base specifier or /// access specifier, the specifier itself is returned. - int clang_getCXXAccessSpecifier( + CX_CXXAccessSpecifier clang_getCXXAccessSpecifier( CXCursor arg0, ) { - return _clang_getCXXAccessSpecifier( + return CX_CXXAccessSpecifier.fromValue(_clang_getCXXAccessSpecifier( arg0, - ); + )); } late final _clang_getCXXAccessSpecifierPtr = @@ -3857,12 +3858,12 @@ class LibClang { /// /// If the passed in Cursor is not a function or variable declaration, /// CX_SC_Invalid is returned else the storage class. - int clang_Cursor_getStorageClass( + CX_StorageClass clang_Cursor_getStorageClass( CXCursor arg0, ) { - return _clang_Cursor_getStorageClass( + return CX_StorageClass.fromValue(_clang_Cursor_getStorageClass( arg0, - ); + )); } late final _clang_Cursor_getStorageClassPtr = @@ -4148,11 +4149,11 @@ class LibClang { /// Get a property value for the given printing policy. int clang_PrintingPolicy_getProperty( CXPrintingPolicy Policy, - int Property, + CXPrintingPolicyProperty Property, ) { return _clang_PrintingPolicy_getProperty( Policy, - Property, + Property.value, ); } @@ -4166,12 +4167,12 @@ class LibClang { /// Set a property value for the given printing policy. void clang_PrintingPolicy_setProperty( CXPrintingPolicy Policy, - int Property, + CXPrintingPolicyProperty Property, int Value, ) { return _clang_PrintingPolicy_setProperty( Policy, - Property, + Property.value, Value, ); } @@ -5045,12 +5046,12 @@ class LibClang { /// \returns The cursor kind of the specializations that would be generated /// by instantiating the template \p C. If \p C is not a template, returns /// \c CXCursor_NoDeclFound. - int clang_getTemplateCursorKind( + CXCursorKind clang_getTemplateCursorKind( CXCursor C, ) { - return _clang_getTemplateCursorKind( + return CXCursorKind.fromValue(_clang_getTemplateCursorKind( C, - ); + )); } late final _clang_getTemplateCursorKindPtr = @@ -5160,12 +5161,12 @@ class LibClang { _clang_getTokenPtr.asFunction(); /// Determine the kind of the given token. - int clang_getTokenKind( + CXTokenKind clang_getTokenKind( CXToken arg0, ) { - return _clang_getTokenKind( + return CXTokenKind.fromValue(_clang_getTokenKind( arg0, - ); + )); } late final _clang_getTokenKindPtr = @@ -5335,10 +5336,10 @@ class LibClang { /// /// @{ CXString clang_getCursorKindSpelling( - int Kind, + CXCursorKind Kind, ) { return _clang_getCursorKindSpelling( - Kind, + Kind.value, ); } @@ -5411,14 +5412,14 @@ class LibClang { /// \param chunk_number the 0-based index of the chunk in the completion string. /// /// \returns the kind of the chunk at the index \c chunk_number. - int clang_getCompletionChunkKind( + CXCompletionChunkKind clang_getCompletionChunkKind( CXCompletionString completion_string, int chunk_number, ) { - return _clang_getCompletionChunkKind( + return CXCompletionChunkKind.fromValue(_clang_getCompletionChunkKind( completion_string, chunk_number, - ); + )); } late final _clang_getCompletionChunkKindPtr = @@ -5522,12 +5523,12 @@ class LibClang { /// \param completion_string The completion string to query. /// /// \returns The availability of the completion string. - int clang_getCompletionAvailability( + CXAvailabilityKind clang_getCompletionAvailability( CXCompletionString completion_string, ) { - return _clang_getCompletionAvailability( + return CXAvailabilityKind.fromValue(_clang_getCompletionAvailability( completion_string, - ); + )); } late final _clang_getCompletionAvailabilityPtr = @@ -5960,14 +5961,14 @@ class LibClang { /// /// \returns the container kind, or CXCursor_InvalidCode if there is not a /// container - int clang_codeCompleteGetContainerKind( + CXCursorKind clang_codeCompleteGetContainerKind( ffi.Pointer Results, ffi.Pointer IsIncomplete, ) { - return _clang_codeCompleteGetContainerKind( + return CXCursorKind.fromValue(_clang_codeCompleteGetContainerKind( Results, IsIncomplete, - ); + )); } late final _clang_codeCompleteGetContainerKindPtr = @@ -6093,12 +6094,12 @@ class LibClang { _clang_Cursor_EvaluatePtr.asFunction(); /// Returns the kind of the evaluated result. - int clang_EvalResult_getKind( + CXEvalResultKind clang_EvalResult_getKind( CXEvalResult E, ) { - return _clang_EvalResult_getKind( + return CXEvalResultKind.fromValue(_clang_EvalResult_getKind( E, - ); + )); } late final _clang_EvalResult_getKindPtr = @@ -6337,16 +6338,16 @@ class LibClang { /// a macro (and not a macro argument) the CXSourceRange will be invalid. /// /// \returns one of the CXResult enumerators. - int clang_findReferencesInFile( + CXResult clang_findReferencesInFile( CXCursor cursor, CXFile file, CXCursorAndRangeVisitor visitor, ) { - return _clang_findReferencesInFile( + return CXResult.fromValue(_clang_findReferencesInFile( cursor, file, visitor, - ); + )); } late final _clang_findReferencesInFilePtr = @@ -6365,16 +6366,16 @@ class LibClang { /// each directive found. /// /// \returns one of the CXResult enumerators. - int clang_findIncludesInFile( + CXResult clang_findIncludesInFile( CXTranslationUnit TU, CXFile file, CXCursorAndRangeVisitor visitor, ) { - return _clang_findIncludesInFile( + return CXResult.fromValue(_clang_findIncludesInFile( TU, file, visitor, - ); + )); } late final _clang_findIncludesInFilePtr = @@ -6384,10 +6385,10 @@ class LibClang { _clang_findIncludesInFilePtr.asFunction(); int clang_index_isEntityObjCContainerKind( - int arg0, + CXIdxEntityKind arg0, ) { return _clang_index_isEntityObjCContainerKind( - arg0, + arg0.value, ); } @@ -7748,6 +7749,14 @@ enum CXGlobalOptFlags { final int value; const CXGlobalOptFlags(this.value); + + static CXGlobalOptFlags fromValue(int value) => switch (value) { + 0 => CXGlobalOpt_None, + 1 => CXGlobalOpt_ThreadBackgroundPriorityForIndexing, + 2 => CXGlobalOpt_ThreadBackgroundPriorityForEditing, + 3 => CXGlobalOpt_ThreadBackgroundPriorityForAll, + _ => throw ArgumentError("Invalid value for CXGlobalOptFlags: $value"), + }; } typedef NativeClang_CXIndex_setGlobalOptions = ffi.Void Function( @@ -7988,6 +7997,14 @@ enum CXLoadDiag_Error { final int value; const CXLoadDiag_Error(this.value); + + static CXLoadDiag_Error fromValue(int value) => switch (value) { + 0 => CXLoadDiag_None, + 1 => CXLoadDiag_Unknown, + 2 => CXLoadDiag_CannotLoad, + 3 => CXLoadDiag_InvalidFile, + _ => throw ArgumentError("Invalid value for CXLoadDiag_Error: $value"), + }; } typedef NativeClang_loadDiagnostics = CXDiagnosticSet Function( @@ -8051,6 +8068,16 @@ enum CXDiagnosticSeverity { final int value; const CXDiagnosticSeverity(this.value); + + static CXDiagnosticSeverity fromValue(int value) => switch (value) { + 0 => CXDiagnostic_Ignored, + 1 => CXDiagnostic_Note, + 2 => CXDiagnostic_Warning, + 3 => CXDiagnostic_Error, + 4 => CXDiagnostic_Fatal, + _ => + throw ArgumentError("Invalid value for CXDiagnosticSeverity: $value"), + }; } typedef NativeClang_getDiagnosticSeverity = ffi.Int32 Function( @@ -8147,6 +8174,15 @@ enum CXErrorCode { final int value; const CXErrorCode(this.value); + + static CXErrorCode fromValue(int value) => switch (value) { + 0 => CXError_Success, + 1 => CXError_Failure, + 2 => CXError_Crashed, + 3 => CXError_InvalidArguments, + 4 => CXError_ASTReadError, + _ => throw ArgumentError("Invalid value for CXErrorCode: $value"), + }; } typedef NativeClang_createTranslationUnit2 = ffi.Int32 Function(CXIndex CIdx, @@ -8263,6 +8299,25 @@ enum CXTUResourceUsageKind { final int value; const CXTUResourceUsageKind(this.value); + static CXTUResourceUsageKind fromValue(int value) => switch (value) { + 1 => CXTUResourceUsage_AST, + 2 => CXTUResourceUsage_Identifiers, + 3 => CXTUResourceUsage_Selectors, + 4 => CXTUResourceUsage_GlobalCompletionResults, + 5 => CXTUResourceUsage_SourceManagerContentCache, + 6 => CXTUResourceUsage_AST_SideTables, + 7 => CXTUResourceUsage_SourceManager_Membuffer_Malloc, + 8 => CXTUResourceUsage_SourceManager_Membuffer_MMap, + 9 => CXTUResourceUsage_ExternalASTSource_Membuffer_Malloc, + 10 => CXTUResourceUsage_ExternalASTSource_Membuffer_MMap, + 11 => CXTUResourceUsage_Preprocessor, + 12 => CXTUResourceUsage_PreprocessingRecord, + 13 => CXTUResourceUsage_SourceManager_DataStructures, + 14 => CXTUResourceUsage_Preprocessor_HeaderSearch, + _ => throw ArgumentError( + "Invalid value for CXTUResourceUsageKind: $value"), + }; + @override String toString() { if (this == CXTUResourceUsage_AST) @@ -9135,6 +9190,252 @@ enum CXCursorKind { final int value; const CXCursorKind(this.value); + static CXCursorKind fromValue(int value) => switch (value) { + 1 => CXCursor_UnexposedDecl, + 2 => CXCursor_StructDecl, + 3 => CXCursor_UnionDecl, + 4 => CXCursor_ClassDecl, + 5 => CXCursor_EnumDecl, + 6 => CXCursor_FieldDecl, + 7 => CXCursor_EnumConstantDecl, + 8 => CXCursor_FunctionDecl, + 9 => CXCursor_VarDecl, + 10 => CXCursor_ParmDecl, + 11 => CXCursor_ObjCInterfaceDecl, + 12 => CXCursor_ObjCCategoryDecl, + 13 => CXCursor_ObjCProtocolDecl, + 14 => CXCursor_ObjCPropertyDecl, + 15 => CXCursor_ObjCIvarDecl, + 16 => CXCursor_ObjCInstanceMethodDecl, + 17 => CXCursor_ObjCClassMethodDecl, + 18 => CXCursor_ObjCImplementationDecl, + 19 => CXCursor_ObjCCategoryImplDecl, + 20 => CXCursor_TypedefDecl, + 21 => CXCursor_CXXMethod, + 22 => CXCursor_Namespace, + 23 => CXCursor_LinkageSpec, + 24 => CXCursor_Constructor, + 25 => CXCursor_Destructor, + 26 => CXCursor_ConversionFunction, + 27 => CXCursor_TemplateTypeParameter, + 28 => CXCursor_NonTypeTemplateParameter, + 29 => CXCursor_TemplateTemplateParameter, + 30 => CXCursor_FunctionTemplate, + 31 => CXCursor_ClassTemplate, + 32 => CXCursor_ClassTemplatePartialSpecialization, + 33 => CXCursor_NamespaceAlias, + 34 => CXCursor_UsingDirective, + 35 => CXCursor_UsingDeclaration, + 36 => CXCursor_TypeAliasDecl, + 37 => CXCursor_ObjCSynthesizeDecl, + 38 => CXCursor_ObjCDynamicDecl, + 39 => CXCursor_CXXAccessSpecifier, + 40 => CXCursor_FirstRef, + 41 => CXCursor_ObjCProtocolRef, + 42 => CXCursor_ObjCClassRef, + 43 => CXCursor_TypeRef, + 44 => CXCursor_CXXBaseSpecifier, + 45 => CXCursor_TemplateRef, + 46 => CXCursor_NamespaceRef, + 47 => CXCursor_MemberRef, + 48 => CXCursor_LabelRef, + 49 => CXCursor_OverloadedDeclRef, + 50 => CXCursor_VariableRef, + 70 => CXCursor_FirstInvalid, + 71 => CXCursor_NoDeclFound, + 72 => CXCursor_NotImplemented, + 73 => CXCursor_InvalidCode, + 100 => CXCursor_FirstExpr, + 101 => CXCursor_DeclRefExpr, + 102 => CXCursor_MemberRefExpr, + 103 => CXCursor_CallExpr, + 104 => CXCursor_ObjCMessageExpr, + 105 => CXCursor_BlockExpr, + 106 => CXCursor_IntegerLiteral, + 107 => CXCursor_FloatingLiteral, + 108 => CXCursor_ImaginaryLiteral, + 109 => CXCursor_StringLiteral, + 110 => CXCursor_CharacterLiteral, + 111 => CXCursor_ParenExpr, + 112 => CXCursor_UnaryOperator, + 113 => CXCursor_ArraySubscriptExpr, + 114 => CXCursor_BinaryOperator, + 115 => CXCursor_CompoundAssignOperator, + 116 => CXCursor_ConditionalOperator, + 117 => CXCursor_CStyleCastExpr, + 118 => CXCursor_CompoundLiteralExpr, + 119 => CXCursor_InitListExpr, + 120 => CXCursor_AddrLabelExpr, + 121 => CXCursor_StmtExpr, + 122 => CXCursor_GenericSelectionExpr, + 123 => CXCursor_GNUNullExpr, + 124 => CXCursor_CXXStaticCastExpr, + 125 => CXCursor_CXXDynamicCastExpr, + 126 => CXCursor_CXXReinterpretCastExpr, + 127 => CXCursor_CXXConstCastExpr, + 128 => CXCursor_CXXFunctionalCastExpr, + 129 => CXCursor_CXXTypeidExpr, + 130 => CXCursor_CXXBoolLiteralExpr, + 131 => CXCursor_CXXNullPtrLiteralExpr, + 132 => CXCursor_CXXThisExpr, + 133 => CXCursor_CXXThrowExpr, + 134 => CXCursor_CXXNewExpr, + 135 => CXCursor_CXXDeleteExpr, + 136 => CXCursor_UnaryExpr, + 137 => CXCursor_ObjCStringLiteral, + 138 => CXCursor_ObjCEncodeExpr, + 139 => CXCursor_ObjCSelectorExpr, + 140 => CXCursor_ObjCProtocolExpr, + 141 => CXCursor_ObjCBridgedCastExpr, + 142 => CXCursor_PackExpansionExpr, + 143 => CXCursor_SizeOfPackExpr, + 144 => CXCursor_LambdaExpr, + 145 => CXCursor_ObjCBoolLiteralExpr, + 146 => CXCursor_ObjCSelfExpr, + 147 => CXCursor_OMPArraySectionExpr, + 148 => CXCursor_ObjCAvailabilityCheckExpr, + 149 => CXCursor_FixedPointLiteral, + 200 => CXCursor_FirstStmt, + 201 => CXCursor_LabelStmt, + 202 => CXCursor_CompoundStmt, + 203 => CXCursor_CaseStmt, + 204 => CXCursor_DefaultStmt, + 205 => CXCursor_IfStmt, + 206 => CXCursor_SwitchStmt, + 207 => CXCursor_WhileStmt, + 208 => CXCursor_DoStmt, + 209 => CXCursor_ForStmt, + 210 => CXCursor_GotoStmt, + 211 => CXCursor_IndirectGotoStmt, + 212 => CXCursor_ContinueStmt, + 213 => CXCursor_BreakStmt, + 214 => CXCursor_ReturnStmt, + 215 => CXCursor_GCCAsmStmt, + 216 => CXCursor_ObjCAtTryStmt, + 217 => CXCursor_ObjCAtCatchStmt, + 218 => CXCursor_ObjCAtFinallyStmt, + 219 => CXCursor_ObjCAtThrowStmt, + 220 => CXCursor_ObjCAtSynchronizedStmt, + 221 => CXCursor_ObjCAutoreleasePoolStmt, + 222 => CXCursor_ObjCForCollectionStmt, + 223 => CXCursor_CXXCatchStmt, + 224 => CXCursor_CXXTryStmt, + 225 => CXCursor_CXXForRangeStmt, + 226 => CXCursor_SEHTryStmt, + 227 => CXCursor_SEHExceptStmt, + 228 => CXCursor_SEHFinallyStmt, + 229 => CXCursor_MSAsmStmt, + 230 => CXCursor_NullStmt, + 231 => CXCursor_DeclStmt, + 232 => CXCursor_OMPParallelDirective, + 233 => CXCursor_OMPSimdDirective, + 234 => CXCursor_OMPForDirective, + 235 => CXCursor_OMPSectionsDirective, + 236 => CXCursor_OMPSectionDirective, + 237 => CXCursor_OMPSingleDirective, + 238 => CXCursor_OMPParallelForDirective, + 239 => CXCursor_OMPParallelSectionsDirective, + 240 => CXCursor_OMPTaskDirective, + 241 => CXCursor_OMPMasterDirective, + 242 => CXCursor_OMPCriticalDirective, + 243 => CXCursor_OMPTaskyieldDirective, + 244 => CXCursor_OMPBarrierDirective, + 245 => CXCursor_OMPTaskwaitDirective, + 246 => CXCursor_OMPFlushDirective, + 247 => CXCursor_SEHLeaveStmt, + 248 => CXCursor_OMPOrderedDirective, + 249 => CXCursor_OMPAtomicDirective, + 250 => CXCursor_OMPForSimdDirective, + 251 => CXCursor_OMPParallelForSimdDirective, + 252 => CXCursor_OMPTargetDirective, + 253 => CXCursor_OMPTeamsDirective, + 254 => CXCursor_OMPTaskgroupDirective, + 255 => CXCursor_OMPCancellationPointDirective, + 256 => CXCursor_OMPCancelDirective, + 257 => CXCursor_OMPTargetDataDirective, + 258 => CXCursor_OMPTaskLoopDirective, + 259 => CXCursor_OMPTaskLoopSimdDirective, + 260 => CXCursor_OMPDistributeDirective, + 261 => CXCursor_OMPTargetEnterDataDirective, + 262 => CXCursor_OMPTargetExitDataDirective, + 263 => CXCursor_OMPTargetParallelDirective, + 264 => CXCursor_OMPTargetParallelForDirective, + 265 => CXCursor_OMPTargetUpdateDirective, + 266 => CXCursor_OMPDistributeParallelForDirective, + 267 => CXCursor_OMPDistributeParallelForSimdDirective, + 268 => CXCursor_OMPDistributeSimdDirective, + 269 => CXCursor_OMPTargetParallelForSimdDirective, + 270 => CXCursor_OMPTargetSimdDirective, + 271 => CXCursor_OMPTeamsDistributeDirective, + 272 => CXCursor_OMPTeamsDistributeSimdDirective, + 273 => CXCursor_OMPTeamsDistributeParallelForSimdDirective, + 274 => CXCursor_OMPTeamsDistributeParallelForDirective, + 275 => CXCursor_OMPTargetTeamsDirective, + 276 => CXCursor_OMPTargetTeamsDistributeDirective, + 277 => CXCursor_OMPTargetTeamsDistributeParallelForDirective, + 278 => CXCursor_OMPTargetTeamsDistributeParallelForSimdDirective, + 279 => CXCursor_OMPTargetTeamsDistributeSimdDirective, + 280 => CXCursor_BuiltinBitCastExpr, + 281 => CXCursor_OMPMasterTaskLoopDirective, + 282 => CXCursor_OMPParallelMasterTaskLoopDirective, + 283 => CXCursor_OMPMasterTaskLoopSimdDirective, + 284 => CXCursor_OMPParallelMasterTaskLoopSimdDirective, + 285 => CXCursor_OMPParallelMasterDirective, + 300 => CXCursor_TranslationUnit, + 400 => CXCursor_FirstAttr, + 401 => CXCursor_IBActionAttr, + 402 => CXCursor_IBOutletAttr, + 403 => CXCursor_IBOutletCollectionAttr, + 404 => CXCursor_CXXFinalAttr, + 405 => CXCursor_CXXOverrideAttr, + 406 => CXCursor_AnnotateAttr, + 407 => CXCursor_AsmLabelAttr, + 408 => CXCursor_PackedAttr, + 409 => CXCursor_PureAttr, + 410 => CXCursor_ConstAttr, + 411 => CXCursor_NoDuplicateAttr, + 412 => CXCursor_CUDAConstantAttr, + 413 => CXCursor_CUDADeviceAttr, + 414 => CXCursor_CUDAGlobalAttr, + 415 => CXCursor_CUDAHostAttr, + 416 => CXCursor_CUDASharedAttr, + 417 => CXCursor_VisibilityAttr, + 418 => CXCursor_DLLExport, + 419 => CXCursor_DLLImport, + 420 => CXCursor_NSReturnsRetained, + 421 => CXCursor_NSReturnsNotRetained, + 422 => CXCursor_NSReturnsAutoreleased, + 423 => CXCursor_NSConsumesSelf, + 424 => CXCursor_NSConsumed, + 425 => CXCursor_ObjCException, + 426 => CXCursor_ObjCNSObject, + 427 => CXCursor_ObjCIndependentClass, + 428 => CXCursor_ObjCPreciseLifetime, + 429 => CXCursor_ObjCReturnsInnerPointer, + 430 => CXCursor_ObjCRequiresSuper, + 431 => CXCursor_ObjCRootClass, + 432 => CXCursor_ObjCSubclassingRestricted, + 433 => CXCursor_ObjCExplicitProtocolImpl, + 434 => CXCursor_ObjCDesignatedInitializer, + 435 => CXCursor_ObjCRuntimeVisible, + 436 => CXCursor_ObjCBoxable, + 437 => CXCursor_FlagEnum, + 438 => CXCursor_ConvergentAttr, + 439 => CXCursor_WarnUnusedAttr, + 440 => CXCursor_WarnUnusedResultAttr, + 441 => CXCursor_AlignedAttr, + 500 => CXCursor_PreprocessingDirective, + 501 => CXCursor_MacroDefinition, + 502 => CXCursor_MacroExpansion, + 503 => CXCursor_InclusionDirective, + 600 => CXCursor_ModuleImportDecl, + 601 => CXCursor_TypeAliasTemplateDecl, + 602 => CXCursor_StaticAssert, + 603 => CXCursor_FriendDecl, + 700 => CXCursor_OverloadCandidate, + _ => throw ArgumentError("Invalid value for CXCursorKind: $value"), + }; + @override String toString() { if (this == CXCursor_UnexposedDecl) @@ -9239,6 +9540,15 @@ enum CXLinkageKind { final int value; const CXLinkageKind(this.value); + + static CXLinkageKind fromValue(int value) => switch (value) { + 0 => CXLinkage_Invalid, + 1 => CXLinkage_NoLinkage, + 2 => CXLinkage_Internal, + 3 => CXLinkage_UniqueExternal, + 4 => CXLinkage_External, + _ => throw ArgumentError("Invalid value for CXLinkageKind: $value"), + }; } typedef NativeClang_getCursorLinkage = ffi.Int32 Function(CXCursor cursor); @@ -9260,6 +9570,14 @@ enum CXVisibilityKind { final int value; const CXVisibilityKind(this.value); + + static CXVisibilityKind fromValue(int value) => switch (value) { + 0 => CXVisibility_Invalid, + 1 => CXVisibility_Hidden, + 2 => CXVisibility_Protected, + 3 => CXVisibility_Default, + _ => throw ArgumentError("Invalid value for CXVisibilityKind: $value"), + }; } typedef NativeClang_getCursorVisibility = ffi.Int32 Function(CXCursor cursor); @@ -9285,6 +9603,15 @@ enum CXAvailabilityKind { final int value; const CXAvailabilityKind(this.value); + + static CXAvailabilityKind fromValue(int value) => switch (value) { + 0 => CXAvailability_Available, + 1 => CXAvailability_Deprecated, + 2 => CXAvailability_NotAvailable, + 3 => CXAvailability_NotAccessible, + _ => + throw ArgumentError("Invalid value for CXAvailabilityKind: $value"), + }; } typedef NativeClang_getCursorAvailability = ffi.Int32 Function(CXCursor cursor); @@ -9349,6 +9676,14 @@ enum CXLanguageKind { final int value; const CXLanguageKind(this.value); + + static CXLanguageKind fromValue(int value) => switch (value) { + 0 => CXLanguage_Invalid, + 1 => CXLanguage_C, + 2 => CXLanguage_ObjC, + 3 => CXLanguage_CPlusPlus, + _ => throw ArgumentError("Invalid value for CXLanguageKind: $value"), + }; } typedef NativeClang_getCursorLanguage = ffi.Int32 Function(CXCursor cursor); @@ -9363,6 +9698,13 @@ enum CXTLSKind { final int value; const CXTLSKind(this.value); + + static CXTLSKind fromValue(int value) => switch (value) { + 0 => CXTLS_None, + 1 => CXTLS_Dynamic, + 2 => CXTLS_Static, + _ => throw ArgumentError("Invalid value for CXTLSKind: $value"), + }; } typedef NativeClang_getCursorTLSKind = ffi.Int32 Function(CXCursor cursor); @@ -9548,6 +9890,126 @@ enum CXTypeKind { final int value; const CXTypeKind(this.value); + static CXTypeKind fromValue(int value) => switch (value) { + 0 => CXType_Invalid, + 1 => CXType_Unexposed, + 2 => CXType_Void, + 3 => CXType_Bool, + 4 => CXType_Char_U, + 5 => CXType_UChar, + 6 => CXType_Char16, + 7 => CXType_Char32, + 8 => CXType_UShort, + 9 => CXType_UInt, + 10 => CXType_ULong, + 11 => CXType_ULongLong, + 12 => CXType_UInt128, + 13 => CXType_Char_S, + 14 => CXType_SChar, + 15 => CXType_WChar, + 16 => CXType_Short, + 17 => CXType_Int, + 18 => CXType_Long, + 19 => CXType_LongLong, + 20 => CXType_Int128, + 21 => CXType_Float, + 22 => CXType_Double, + 23 => CXType_LongDouble, + 24 => CXType_NullPtr, + 25 => CXType_Overload, + 26 => CXType_Dependent, + 27 => CXType_ObjCId, + 28 => CXType_ObjCClass, + 29 => CXType_ObjCSel, + 30 => CXType_Float128, + 31 => CXType_Half, + 32 => CXType_Float16, + 33 => CXType_ShortAccum, + 34 => CXType_Accum, + 35 => CXType_LongAccum, + 36 => CXType_UShortAccum, + 37 => CXType_UAccum, + 38 => CXType_ULongAccum, + 100 => CXType_Complex, + 101 => CXType_Pointer, + 102 => CXType_BlockPointer, + 103 => CXType_LValueReference, + 104 => CXType_RValueReference, + 105 => CXType_Record, + 106 => CXType_Enum, + 107 => CXType_Typedef, + 108 => CXType_ObjCInterface, + 109 => CXType_ObjCObjectPointer, + 110 => CXType_FunctionNoProto, + 111 => CXType_FunctionProto, + 112 => CXType_ConstantArray, + 113 => CXType_Vector, + 114 => CXType_IncompleteArray, + 115 => CXType_VariableArray, + 116 => CXType_DependentSizedArray, + 117 => CXType_MemberPointer, + 118 => CXType_Auto, + 119 => CXType_Elaborated, + 120 => CXType_Pipe, + 121 => CXType_OCLImage1dRO, + 122 => CXType_OCLImage1dArrayRO, + 123 => CXType_OCLImage1dBufferRO, + 124 => CXType_OCLImage2dRO, + 125 => CXType_OCLImage2dArrayRO, + 126 => CXType_OCLImage2dDepthRO, + 127 => CXType_OCLImage2dArrayDepthRO, + 128 => CXType_OCLImage2dMSAARO, + 129 => CXType_OCLImage2dArrayMSAARO, + 130 => CXType_OCLImage2dMSAADepthRO, + 131 => CXType_OCLImage2dArrayMSAADepthRO, + 132 => CXType_OCLImage3dRO, + 133 => CXType_OCLImage1dWO, + 134 => CXType_OCLImage1dArrayWO, + 135 => CXType_OCLImage1dBufferWO, + 136 => CXType_OCLImage2dWO, + 137 => CXType_OCLImage2dArrayWO, + 138 => CXType_OCLImage2dDepthWO, + 139 => CXType_OCLImage2dArrayDepthWO, + 140 => CXType_OCLImage2dMSAAWO, + 141 => CXType_OCLImage2dArrayMSAAWO, + 142 => CXType_OCLImage2dMSAADepthWO, + 143 => CXType_OCLImage2dArrayMSAADepthWO, + 144 => CXType_OCLImage3dWO, + 145 => CXType_OCLImage1dRW, + 146 => CXType_OCLImage1dArrayRW, + 147 => CXType_OCLImage1dBufferRW, + 148 => CXType_OCLImage2dRW, + 149 => CXType_OCLImage2dArrayRW, + 150 => CXType_OCLImage2dDepthRW, + 151 => CXType_OCLImage2dArrayDepthRW, + 152 => CXType_OCLImage2dMSAARW, + 153 => CXType_OCLImage2dArrayMSAARW, + 154 => CXType_OCLImage2dMSAADepthRW, + 155 => CXType_OCLImage2dArrayMSAADepthRW, + 156 => CXType_OCLImage3dRW, + 157 => CXType_OCLSampler, + 158 => CXType_OCLEvent, + 159 => CXType_OCLQueue, + 160 => CXType_OCLReserveID, + 161 => CXType_ObjCObject, + 162 => CXType_ObjCTypeParam, + 163 => CXType_Attributed, + 164 => CXType_OCLIntelSubgroupAVCMcePayload, + 165 => CXType_OCLIntelSubgroupAVCImePayload, + 166 => CXType_OCLIntelSubgroupAVCRefPayload, + 167 => CXType_OCLIntelSubgroupAVCSicPayload, + 168 => CXType_OCLIntelSubgroupAVCMceResult, + 169 => CXType_OCLIntelSubgroupAVCImeResult, + 170 => CXType_OCLIntelSubgroupAVCRefResult, + 171 => CXType_OCLIntelSubgroupAVCSicResult, + 172 => CXType_OCLIntelSubgroupAVCImeResultSingleRefStreamout, + 173 => CXType_OCLIntelSubgroupAVCImeResultDualRefStreamout, + 174 => CXType_OCLIntelSubgroupAVCImeSingleRefStreamin, + 175 => CXType_OCLIntelSubgroupAVCImeDualRefStreamin, + 176 => CXType_ExtVector, + _ => throw ArgumentError("Invalid value for CXTypeKind: $value"), + }; + @override String toString() { if (this == CXType_Void) @@ -9610,6 +10072,21 @@ enum CXTemplateArgumentKind { final int value; const CXTemplateArgumentKind(this.value); + + static CXTemplateArgumentKind fromValue(int value) => switch (value) { + 0 => CXTemplateArgumentKind_Null, + 1 => CXTemplateArgumentKind_Type, + 2 => CXTemplateArgumentKind_Declaration, + 3 => CXTemplateArgumentKind_NullPtr, + 4 => CXTemplateArgumentKind_Integral, + 5 => CXTemplateArgumentKind_Template, + 6 => CXTemplateArgumentKind_TemplateExpansion, + 7 => CXTemplateArgumentKind_Expression, + 8 => CXTemplateArgumentKind_Pack, + 9 => CXTemplateArgumentKind_Invalid, + _ => throw ArgumentError( + "Invalid value for CXTemplateArgumentKind: $value"), + }; } typedef NativeClang_Cursor_getTemplateArgumentKind = ffi.Int32 Function( @@ -9691,6 +10168,29 @@ enum CXCallingConv { final int value; const CXCallingConv(this.value); + static CXCallingConv fromValue(int value) => switch (value) { + 0 => CXCallingConv_Default, + 1 => CXCallingConv_C, + 2 => CXCallingConv_X86StdCall, + 3 => CXCallingConv_X86FastCall, + 4 => CXCallingConv_X86ThisCall, + 5 => CXCallingConv_X86Pascal, + 6 => CXCallingConv_AAPCS, + 7 => CXCallingConv_AAPCS_VFP, + 8 => CXCallingConv_X86RegCall, + 9 => CXCallingConv_IntelOclBicc, + 10 => CXCallingConv_Win64, + 11 => CXCallingConv_X86_64SysV, + 12 => CXCallingConv_X86VectorCall, + 13 => CXCallingConv_Swift, + 14 => CXCallingConv_PreserveMost, + 15 => CXCallingConv_PreserveAll, + 16 => CXCallingConv_AArch64VectorCall, + 100 => CXCallingConv_Invalid, + 200 => CXCallingConv_Unexposed, + _ => throw ArgumentError("Invalid value for CXCallingConv: $value"), + }; + @override String toString() { if (this == CXCallingConv_Win64) @@ -9765,6 +10265,15 @@ enum CXTypeNullabilityKind { final int value; const CXTypeNullabilityKind(this.value); + + static CXTypeNullabilityKind fromValue(int value) => switch (value) { + 0 => CXTypeNullability_NonNull, + 1 => CXTypeNullability_Nullable, + 2 => CXTypeNullability_Unspecified, + 3 => CXTypeNullability_Invalid, + _ => throw ArgumentError( + "Invalid value for CXTypeNullabilityKind: $value"), + }; } typedef NativeClang_Type_getNullability = ffi.Int32 Function(CXType T); @@ -9810,6 +10319,14 @@ enum CXRefQualifierKind { final int value; const CXRefQualifierKind(this.value); + + static CXRefQualifierKind fromValue(int value) => switch (value) { + 0 => CXRefQualifier_None, + 1 => CXRefQualifier_LValue, + 2 => CXRefQualifier_RValue, + _ => + throw ArgumentError("Invalid value for CXRefQualifierKind: $value"), + }; } typedef NativeClang_Type_getCXXRefQualifier = ffi.Int32 Function(CXType T); @@ -9829,6 +10346,15 @@ enum CX_CXXAccessSpecifier { final int value; const CX_CXXAccessSpecifier(this.value); + + static CX_CXXAccessSpecifier fromValue(int value) => switch (value) { + 0 => CX_CXXInvalidAccessSpecifier, + 1 => CX_CXXPublic, + 2 => CX_CXXProtected, + 3 => CX_CXXPrivate, + _ => throw ArgumentError( + "Invalid value for CX_CXXAccessSpecifier: $value"), + }; } typedef NativeClang_getCXXAccessSpecifier = ffi.Int32 Function(CXCursor arg0); @@ -9848,6 +10374,18 @@ enum CX_StorageClass { final int value; const CX_StorageClass(this.value); + + static CX_StorageClass fromValue(int value) => switch (value) { + 0 => CX_SC_Invalid, + 1 => CX_SC_None, + 2 => CX_SC_Extern, + 3 => CX_SC_Static, + 4 => CX_SC_PrivateExtern, + 5 => CX_SC_OpenCLWorkGroupLocal, + 6 => CX_SC_Auto, + 7 => CX_SC_Register, + _ => throw ArgumentError("Invalid value for CX_StorageClass: $value"), + }; } typedef NativeClang_Cursor_getStorageClass = ffi.Int32 Function(CXCursor arg0); @@ -9876,7 +10414,7 @@ typedef CXCursorVisitor = ffi.Pointer>; typedef CXCursorVisitorFunction = ffi.Int32 Function( CXCursor cursor, CXCursor parent, CXClientData client_data); -typedef DartCXCursorVisitorFunction = int Function( +typedef DartCXCursorVisitorFunction = CXChildVisitResult Function( CXCursor cursor, CXCursor parent, CXClientData client_data); /// Describes how the traversal of the children of a particular @@ -9898,6 +10436,14 @@ enum CXChildVisitResult { final int value; const CXChildVisitResult(this.value); + + static CXChildVisitResult fromValue(int value) => switch (value) { + 0 => CXChildVisit_Break, + 1 => CXChildVisit_Continue, + 2 => CXChildVisit_Recurse, + _ => + throw ArgumentError("Invalid value for CXChildVisitResult: $value"), + }; } /// Opaque pointer representing client data that will be passed through @@ -9983,6 +10529,37 @@ enum CXPrintingPolicyProperty { final int value; const CXPrintingPolicyProperty(this.value); + static CXPrintingPolicyProperty fromValue(int value) => switch (value) { + 0 => CXPrintingPolicy_Indentation, + 1 => CXPrintingPolicy_SuppressSpecifiers, + 2 => CXPrintingPolicy_SuppressTagKeyword, + 3 => CXPrintingPolicy_IncludeTagDefinition, + 4 => CXPrintingPolicy_SuppressScope, + 5 => CXPrintingPolicy_SuppressUnwrittenScope, + 6 => CXPrintingPolicy_SuppressInitializers, + 7 => CXPrintingPolicy_ConstantArraySizeAsWritten, + 8 => CXPrintingPolicy_AnonymousTagLocations, + 9 => CXPrintingPolicy_SuppressStrongLifetime, + 10 => CXPrintingPolicy_SuppressLifetimeQualifiers, + 11 => CXPrintingPolicy_SuppressTemplateArgsInCXXConstructors, + 12 => CXPrintingPolicy_Bool, + 13 => CXPrintingPolicy_Restrict, + 14 => CXPrintingPolicy_Alignof, + 15 => CXPrintingPolicy_UnderscoreAlignof, + 16 => CXPrintingPolicy_UseVoidForZeroParams, + 17 => CXPrintingPolicy_TerseOutput, + 18 => CXPrintingPolicy_PolishForDeclaration, + 19 => CXPrintingPolicy_Half, + 20 => CXPrintingPolicy_MSWChar, + 21 => CXPrintingPolicy_IncludeNewlines, + 22 => CXPrintingPolicy_MSVCFormatting, + 23 => CXPrintingPolicy_ConstantsAsWritten, + 24 => CXPrintingPolicy_SuppressImplicitBase, + 25 => CXPrintingPolicy_FullyQualifiedName, + _ => throw ArgumentError( + "Invalid value for CXPrintingPolicyProperty: $value"), + }; + @override String toString() { if (this == CXPrintingPolicy_FullyQualifiedName) @@ -10180,6 +10757,15 @@ enum CXTokenKind { final int value; const CXTokenKind(this.value); + + static CXTokenKind fromValue(int value) => switch (value) { + 0 => CXToken_Punctuation, + 1 => CXToken_Keyword, + 2 => CXToken_Identifier, + 3 => CXToken_Literal, + 4 => CXToken_Comment, + _ => throw ArgumentError("Invalid value for CXTokenKind: $value"), + }; } typedef NativeClang_getTokenKind = ffi.Int32 Function(CXToken arg0); @@ -10427,6 +11013,32 @@ enum CXCompletionChunkKind { final int value; const CXCompletionChunkKind(this.value); + + static CXCompletionChunkKind fromValue(int value) => switch (value) { + 0 => CXCompletionChunk_Optional, + 1 => CXCompletionChunk_TypedText, + 2 => CXCompletionChunk_Text, + 3 => CXCompletionChunk_Placeholder, + 4 => CXCompletionChunk_Informative, + 5 => CXCompletionChunk_CurrentParameter, + 6 => CXCompletionChunk_LeftParen, + 7 => CXCompletionChunk_RightParen, + 8 => CXCompletionChunk_LeftBracket, + 9 => CXCompletionChunk_RightBracket, + 10 => CXCompletionChunk_LeftBrace, + 11 => CXCompletionChunk_RightBrace, + 12 => CXCompletionChunk_LeftAngle, + 13 => CXCompletionChunk_RightAngle, + 14 => CXCompletionChunk_Comma, + 15 => CXCompletionChunk_ResultType, + 16 => CXCompletionChunk_Colon, + 17 => CXCompletionChunk_SemiColon, + 18 => CXCompletionChunk_Equal, + 19 => CXCompletionChunk_HorizontalSpace, + 20 => CXCompletionChunk_VerticalSpace, + _ => throw ArgumentError( + "Invalid value for CXCompletionChunkKind: $value"), + }; } typedef NativeClang_getCompletionChunkKind = ffi.Int32 Function( @@ -10606,6 +11218,17 @@ enum CXEvalResultKind { final int value; const CXEvalResultKind(this.value); + + static CXEvalResultKind fromValue(int value) => switch (value) { + 1 => CXEval_Int, + 2 => CXEval_Float, + 3 => CXEval_ObjCStrLiteral, + 4 => CXEval_StrLiteral, + 5 => CXEval_CFStr, + 6 => CXEval_Other, + 0 => CXEval_UnExposed, + _ => throw ArgumentError("Invalid value for CXEvalResultKind: $value"), + }; } typedef NativeClang_EvalResult_getKind = ffi.Int32 Function(CXEvalResult E); @@ -10675,6 +11298,12 @@ enum CXVisitorResult { final int value; const CXVisitorResult(this.value); + + static CXVisitorResult fromValue(int value) => switch (value) { + 0 => CXVisit_Break, + 1 => CXVisit_Continue, + _ => throw ArgumentError("Invalid value for CXVisitorResult: $value"), + }; } enum CXResult { @@ -10690,6 +11319,13 @@ enum CXResult { final int value; const CXResult(this.value); + + static CXResult fromValue(int value) => switch (value) { + 0 => CXResult_Success, + 1 => CXResult_Invalid, + 2 => CXResult_VisitBreak, + _ => throw ArgumentError("Invalid value for CXResult: $value"), + }; } typedef NativeClang_findReferencesInFile = ffi.Int32 Function( @@ -10767,6 +11403,14 @@ enum CXIdxAttrKind { final int value; const CXIdxAttrKind(this.value); + + static CXIdxAttrKind fromValue(int value) => switch (value) { + 0 => CXIdxAttr_Unexposed, + 1 => CXIdxAttr_IBAction, + 2 => CXIdxAttr_IBOutlet, + 3 => CXIdxAttr_IBOutletCollection, + _ => throw ArgumentError("Invalid value for CXIdxAttrKind: $value"), + }; } final class CXIdxEntityInfo extends ffi.Struct { @@ -10822,6 +11466,37 @@ enum CXIdxEntityKind { final int value; const CXIdxEntityKind(this.value); + + static CXIdxEntityKind fromValue(int value) => switch (value) { + 0 => CXIdxEntity_Unexposed, + 1 => CXIdxEntity_Typedef, + 2 => CXIdxEntity_Function, + 3 => CXIdxEntity_Variable, + 4 => CXIdxEntity_Field, + 5 => CXIdxEntity_EnumConstant, + 6 => CXIdxEntity_ObjCClass, + 7 => CXIdxEntity_ObjCProtocol, + 8 => CXIdxEntity_ObjCCategory, + 9 => CXIdxEntity_ObjCInstanceMethod, + 10 => CXIdxEntity_ObjCClassMethod, + 11 => CXIdxEntity_ObjCProperty, + 12 => CXIdxEntity_ObjCIvar, + 13 => CXIdxEntity_Enum, + 14 => CXIdxEntity_Struct, + 15 => CXIdxEntity_Union, + 16 => CXIdxEntity_CXXClass, + 17 => CXIdxEntity_CXXNamespace, + 18 => CXIdxEntity_CXXNamespaceAlias, + 19 => CXIdxEntity_CXXStaticVariable, + 20 => CXIdxEntity_CXXStaticMethod, + 21 => CXIdxEntity_CXXInstanceMethod, + 22 => CXIdxEntity_CXXConstructor, + 23 => CXIdxEntity_CXXDestructor, + 24 => CXIdxEntity_CXXConversionFunction, + 25 => CXIdxEntity_CXXTypeAlias, + 26 => CXIdxEntity_CXXInterface, + _ => throw ArgumentError("Invalid value for CXIdxEntityKind: $value"), + }; } /// Extra C++ template information for an entity. This can apply to: @@ -10840,6 +11515,15 @@ enum CXIdxEntityCXXTemplateKind { final int value; const CXIdxEntityCXXTemplateKind(this.value); + + static CXIdxEntityCXXTemplateKind fromValue(int value) => switch (value) { + 0 => CXIdxEntity_NonTemplate, + 1 => CXIdxEntity_Template, + 2 => CXIdxEntity_TemplatePartialSpecialization, + 3 => CXIdxEntity_TemplateSpecialization, + _ => throw ArgumentError( + "Invalid value for CXIdxEntityCXXTemplateKind: $value"), + }; } enum CXIdxEntityLanguage { @@ -10851,6 +11535,16 @@ enum CXIdxEntityLanguage { final int value; const CXIdxEntityLanguage(this.value); + + static CXIdxEntityLanguage fromValue(int value) => switch (value) { + 0 => CXIdxEntityLang_None, + 1 => CXIdxEntityLang_C, + 2 => CXIdxEntityLang_ObjC, + 3 => CXIdxEntityLang_CXX, + 4 => CXIdxEntityLang_Swift, + _ => + throw ArgumentError("Invalid value for CXIdxEntityLanguage: $value"), + }; } final class CXIdxContainerInfo extends ffi.Struct { @@ -10919,6 +11613,14 @@ enum CXIdxObjCContainerKind { final int value; const CXIdxObjCContainerKind(this.value); + + static CXIdxObjCContainerKind fromValue(int value) => switch (value) { + 0 => CXIdxObjCContainer_ForwardRef, + 1 => CXIdxObjCContainer_Interface, + 2 => CXIdxObjCContainer_Implementation, + _ => throw ArgumentError( + "Invalid value for CXIdxObjCContainerKind: $value"), + }; } final class CXIdxBaseClassInfo extends ffi.Struct { @@ -11027,6 +11729,13 @@ enum CXIdxEntityRefKind { final int value; const CXIdxEntityRefKind(this.value); + + static CXIdxEntityRefKind fromValue(int value) => switch (value) { + 1 => CXIdxEntityRef_Direct, + 2 => CXIdxEntityRef_Implicit, + _ => + throw ArgumentError("Invalid value for CXIdxEntityRefKind: $value"), + }; } /// Roles that are attributed to symbol occurrences. @@ -11047,6 +11756,20 @@ enum CXSymbolRole { final int value; const CXSymbolRole(this.value); + + static CXSymbolRole fromValue(int value) => switch (value) { + 0 => CXSymbolRole_None, + 1 => CXSymbolRole_Declaration, + 2 => CXSymbolRole_Definition, + 4 => CXSymbolRole_Reference, + 8 => CXSymbolRole_Read, + 16 => CXSymbolRole_Write, + 32 => CXSymbolRole_Call, + 64 => CXSymbolRole_Dynamic, + 128 => CXSymbolRole_AddressOf, + 256 => CXSymbolRole_Implicit, + _ => throw ArgumentError("Invalid value for CXSymbolRole: $value"), + }; } typedef NativeClang_index_isEntityObjCContainerKind = ffi.Int Function( @@ -11290,7 +12013,7 @@ typedef CXFieldVisitor = ffi.Pointer>; typedef CXFieldVisitorFunction = ffi.Int32 Function( CXCursor C, CXClientData client_data); -typedef DartCXFieldVisitorFunction = int Function( +typedef DartCXFieldVisitorFunction = CXVisitorResult Function( CXCursor C, CXClientData client_data); typedef NativeClang_Type_visitFields = ffi.UnsignedInt Function( CXType T, CXFieldVisitor visitor, CXClientData client_data); diff --git a/pkgs/ffigen/example/shared_bindings/lib/generated/a_gen.dart b/pkgs/ffigen/example/shared_bindings/lib/generated/a_gen.dart index 32dd7ac82c..40b50ba765 100644 --- a/pkgs/ffigen/example/shared_bindings/lib/generated/a_gen.dart +++ b/pkgs/ffigen/example/shared_bindings/lib/generated/a_gen.dart @@ -112,6 +112,12 @@ enum A_Enum { final int value; const A_Enum(this.value); + + static A_Enum fromValue(int value) => switch (value) { + 0 => A_ENUM_1, + 1 => A_ENUM_2, + _ => throw ArgumentError("Invalid value for A_Enum: $value"), + }; } const int BASE_MACRO_1 = 1; diff --git a/pkgs/ffigen/example/shared_bindings/lib/generated/a_shared_b_gen.dart b/pkgs/ffigen/example/shared_bindings/lib/generated/a_shared_b_gen.dart index df3963569e..262713f943 100644 --- a/pkgs/ffigen/example/shared_bindings/lib/generated/a_shared_b_gen.dart +++ b/pkgs/ffigen/example/shared_bindings/lib/generated/a_shared_b_gen.dart @@ -67,6 +67,12 @@ enum A_Enum { final int value; const A_Enum(this.value); + + static A_Enum fromValue(int value) => switch (value) { + 0 => A_ENUM_1, + 1 => A_ENUM_2, + _ => throw ArgumentError("Invalid value for A_Enum: $value"), + }; } const int BASE_MACRO_1 = 1; diff --git a/pkgs/ffigen/lib/src/code_generator/enum_class.dart b/pkgs/ffigen/lib/src/code_generator/enum_class.dart index 834b18d735..28b3a63fdd 100644 --- a/pkgs/ffigen/lib/src/code_generator/enum_class.dart +++ b/pkgs/ffigen/lib/src/code_generator/enum_class.dart @@ -203,7 +203,7 @@ class EnumClass extends BindingType { '$depth${depth}_ => ' 'throw ArgumentError("Invalid value for $name: \$value"),\n', ); - s.write("$depth};"); + s.write("$depth};\n"); } @override diff --git a/pkgs/ffigen/lib/src/code_generator/func.dart b/pkgs/ffigen/lib/src/code_generator/func.dart index 33bbc91464..b830cd1e8e 100644 --- a/pkgs/ffigen/lib/src/code_generator/func.dart +++ b/pkgs/ffigen/lib/src/code_generator/func.dart @@ -176,9 +176,9 @@ $dartReturnType $enclosingFuncName($dartArgDeclString) => $funcImplCall; final isLeafString = isLeaf ? 'isLeaf:true' : ''; // Write enclosing function. - s.write("\n$dartReturnType $enclosingFuncName($dartArgDeclString) {\n"); + s.write("$dartReturnType $enclosingFuncName($dartArgDeclString) {\n"); s.write("return $funcImplCall;\n"); - s.write("}\n"); + s.write("}\n\n"); if (exposeSymbolAddress) { // Add to SymbolAddress in writer. diff --git a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_enumclass_bindings.dart b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_enumclass_bindings.dart index f1ef6aa7c1..c9a459c13b 100644 --- a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_enumclass_bindings.dart +++ b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_enumclass_bindings.dart @@ -18,4 +18,10 @@ enum Constants { final int value; const Constants(this.value); + + static Constants fromValue(int value) => switch (value) { + 10 => a, + -1 => b, + _ => throw ArgumentError("Invalid value for Constants: $value"), + }; } diff --git a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_enumclass_duplicates_bindings.dart b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_enumclass_duplicates_bindings.dart index 3eedd8f622..3d76be254b 100644 --- a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_enumclass_duplicates_bindings.dart +++ b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_enumclass_duplicates_bindings.dart @@ -23,6 +23,12 @@ enum Duplicates { final int value; const Duplicates(this.value); + static Duplicates fromValue(int value) => switch (value) { + 0 => a, + 1 => b, + _ => throw ArgumentError("Invalid value for Duplicates: $value"), + }; + @override String toString() { if (this == b) return "Duplicates.b, Duplicates.c"; diff --git a/pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_forward_decl_bindings.dart b/pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_forward_decl_bindings.dart index 6b337dc31d..2ae77afe89 100644 --- a/pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_forward_decl_bindings.dart +++ b/pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_forward_decl_bindings.dart @@ -22,11 +22,11 @@ class NativeLibrary { void func( ffi.Pointer a, - int b, + B b, ) { return _func( a, - b, + b.value, ); } @@ -50,4 +50,10 @@ enum B { final int value; const B(this.value); + + static B fromValue(int value) => switch (value) { + 0 => a, + 1 => b, + _ => throw ArgumentError("Invalid value for B: $value"), + }; } diff --git a/pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_typedef_bindings.dart b/pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_typedef_bindings.dart index 2b1083e16d..c74b399926 100644 --- a/pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_typedef_bindings.dart +++ b/pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_typedef_bindings.dart @@ -110,6 +110,12 @@ enum AnonymousEnumInTypedef { final int value; const AnonymousEnumInTypedef(this.value); + + static AnonymousEnumInTypedef fromValue(int value) => switch (value) { + 0 => a, + _ => throw ArgumentError( + "Invalid value for AnonymousEnumInTypedef: $value"), + }; } enum _NamedEnumInTypedef { @@ -117,6 +123,12 @@ enum _NamedEnumInTypedef { final int value; const _NamedEnumInTypedef(this.value); + + static _NamedEnumInTypedef fromValue(int value) => switch (value) { + 0 => b, + _ => + throw ArgumentError("Invalid value for _NamedEnumInTypedef: $value"), + }; } typedef NestingASpecifiedType = ffi.IntPtr; diff --git a/pkgs/ffigen/test/large_integration_tests/_expected_libclang_bindings.dart b/pkgs/ffigen/test/large_integration_tests/_expected_libclang_bindings.dart index a6cc81404c..5119399336 100644 --- a/pkgs/ffigen/test/large_integration_tests/_expected_libclang_bindings.dart +++ b/pkgs/ffigen/test/large_integration_tests/_expected_libclang_bindings.dart @@ -97,16 +97,16 @@ class LibClang { /// Map an absolute virtual file path to an absolute real one. The virtual /// path must be canonicalized (not contain "."/".."). - int clang_VirtualFileOverlay_addFileMapping( + CXErrorCode clang_VirtualFileOverlay_addFileMapping( CXVirtualFileOverlay arg0, ffi.Pointer virtualPath, ffi.Pointer realPath, ) { - return _clang_VirtualFileOverlay_addFileMapping( + return CXErrorCode.fromValue(_clang_VirtualFileOverlay_addFileMapping( arg0, virtualPath, realPath, - ); + )); } late final _clang_VirtualFileOverlay_addFileMappingPtr = _lookup< @@ -122,14 +122,14 @@ class LibClang { /// Set the case sensitivity for the CXVirtualFileOverlay object. The /// CXVirtualFileOverlay object is case-sensitive by default, this option can /// be used to override the default. - int clang_VirtualFileOverlay_setCaseSensitivity( + CXErrorCode clang_VirtualFileOverlay_setCaseSensitivity( CXVirtualFileOverlay arg0, int caseSensitive, ) { - return _clang_VirtualFileOverlay_setCaseSensitivity( + return CXErrorCode.fromValue(_clang_VirtualFileOverlay_setCaseSensitivity( arg0, caseSensitive, - ); + )); } late final _clang_VirtualFileOverlay_setCaseSensitivityPtr = _lookup< @@ -141,18 +141,18 @@ class LibClang { .asFunction(); /// Write out the CXVirtualFileOverlay object to a char buffer. - int clang_VirtualFileOverlay_writeToBuffer( + CXErrorCode clang_VirtualFileOverlay_writeToBuffer( CXVirtualFileOverlay arg0, int options, ffi.Pointer> out_buffer_ptr, ffi.Pointer out_buffer_size, ) { - return _clang_VirtualFileOverlay_writeToBuffer( + return CXErrorCode.fromValue(_clang_VirtualFileOverlay_writeToBuffer( arg0, options, out_buffer_ptr, out_buffer_size, - ); + )); } late final _clang_VirtualFileOverlay_writeToBufferPtr = _lookup< @@ -221,14 +221,15 @@ class LibClang { .asFunction(); /// Sets the framework module name that the module.map describes. - int clang_ModuleMapDescriptor_setFrameworkModuleName( + CXErrorCode clang_ModuleMapDescriptor_setFrameworkModuleName( CXModuleMapDescriptor arg0, ffi.Pointer name, ) { - return _clang_ModuleMapDescriptor_setFrameworkModuleName( + return CXErrorCode.fromValue( + _clang_ModuleMapDescriptor_setFrameworkModuleName( arg0, name, - ); + )); } late final _clang_ModuleMapDescriptor_setFrameworkModuleNamePtr = _lookup< @@ -241,14 +242,14 @@ class LibClang { int Function(CXModuleMapDescriptor, ffi.Pointer)>(); /// Sets the umbrealla header name that the module.map describes. - int clang_ModuleMapDescriptor_setUmbrellaHeader( + CXErrorCode clang_ModuleMapDescriptor_setUmbrellaHeader( CXModuleMapDescriptor arg0, ffi.Pointer name, ) { - return _clang_ModuleMapDescriptor_setUmbrellaHeader( + return CXErrorCode.fromValue(_clang_ModuleMapDescriptor_setUmbrellaHeader( arg0, name, - ); + )); } late final _clang_ModuleMapDescriptor_setUmbrellaHeaderPtr = _lookup< @@ -261,18 +262,18 @@ class LibClang { int Function(CXModuleMapDescriptor, ffi.Pointer)>(); /// Write out the CXModuleMapDescriptor object to a char buffer. - int clang_ModuleMapDescriptor_writeToBuffer( + CXErrorCode clang_ModuleMapDescriptor_writeToBuffer( CXModuleMapDescriptor arg0, int options, ffi.Pointer> out_buffer_ptr, ffi.Pointer out_buffer_size, ) { - return _clang_ModuleMapDescriptor_writeToBuffer( + return CXErrorCode.fromValue(_clang_ModuleMapDescriptor_writeToBuffer( arg0, options, out_buffer_ptr, out_buffer_size, - ); + )); } late final _clang_ModuleMapDescriptor_writeToBufferPtr = _lookup< @@ -1130,12 +1131,12 @@ class LibClang { _clang_defaultDiagnosticDisplayOptionsPtr.asFunction(); /// Determine the severity of the given diagnostic. - int clang_getDiagnosticSeverity( + CXDiagnosticSeverity clang_getDiagnosticSeverity( CXDiagnostic arg0, ) { - return _clang_getDiagnosticSeverity( + return CXDiagnosticSeverity.fromValue(_clang_getDiagnosticSeverity( arg0, - ); + )); } late final _clang_getDiagnosticSeverityPtr = @@ -1386,16 +1387,16 @@ class LibClang { .asFunction)>(); /// Create a translation unit from an AST file ( -emit-ast). - int clang_createTranslationUnit2( + CXErrorCode clang_createTranslationUnit2( CXIndex CIdx, ffi.Pointer ast_filename, ffi.Pointer out_TU, ) { - return _clang_createTranslationUnit2( + return CXErrorCode.fromValue(_clang_createTranslationUnit2( CIdx, ast_filename, out_TU, - ); + )); } late final _clang_createTranslationUnit2Ptr = _lookup< @@ -1466,7 +1467,7 @@ class LibClang { /// Parse the given source file and the translation unit corresponding to that /// file. - int clang_parseTranslationUnit2( + CXErrorCode clang_parseTranslationUnit2( CXIndex CIdx, ffi.Pointer source_filename, ffi.Pointer> command_line_args, @@ -1476,7 +1477,7 @@ class LibClang { int options, ffi.Pointer out_TU, ) { - return _clang_parseTranslationUnit2( + return CXErrorCode.fromValue(_clang_parseTranslationUnit2( CIdx, source_filename, command_line_args, @@ -1485,7 +1486,7 @@ class LibClang { num_unsaved_files, options, out_TU, - ); + )); } late final _clang_parseTranslationUnit2Ptr = _lookup< @@ -1514,7 +1515,7 @@ class LibClang { /// Same as clang_parseTranslationUnit2 but requires a full command line for /// command_line_args including argv[0]. This is useful if the standard /// library paths are relative to the binary. - int clang_parseTranslationUnit2FullArgv( + CXErrorCode clang_parseTranslationUnit2FullArgv( CXIndex CIdx, ffi.Pointer source_filename, ffi.Pointer> command_line_args, @@ -1524,7 +1525,7 @@ class LibClang { int options, ffi.Pointer out_TU, ) { - return _clang_parseTranslationUnit2FullArgv( + return CXErrorCode.fromValue(_clang_parseTranslationUnit2FullArgv( CIdx, source_filename, command_line_args, @@ -1533,7 +1534,7 @@ class LibClang { num_unsaved_files, options, out_TU, - ); + )); } late final _clang_parseTranslationUnit2FullArgvPtr = _lookup< @@ -1673,10 +1674,10 @@ class LibClang { /// Returns the human-readable null-terminated C string that represents the /// name of the memory category. This string should never be freed. ffi.Pointer clang_getTUResourceUsageName( - int kind, + CXTUResourceUsageKind kind, ) { return _clang_getTUResourceUsageName( - kind, + kind.value, ); } @@ -1853,12 +1854,12 @@ class LibClang { _clang_hashCursorPtr.asFunction(); /// Retrieve the kind of the given cursor. - int clang_getCursorKind( + CXCursorKind clang_getCursorKind( CXCursor arg0, ) { - return _clang_getCursorKind( + return CXCursorKind.fromValue(_clang_getCursorKind( arg0, - ); + )); } late final _clang_getCursorKindPtr = @@ -1869,10 +1870,10 @@ class LibClang { /// Determine whether the given cursor kind represents a declaration. int clang_isDeclaration( - int arg0, + CXCursorKind arg0, ) { return _clang_isDeclaration( - arg0, + arg0.value, ); } @@ -1899,10 +1900,10 @@ class LibClang { /// Determine whether the given cursor kind represents a simple reference. int clang_isReference( - int arg0, + CXCursorKind arg0, ) { return _clang_isReference( - arg0, + arg0.value, ); } @@ -1914,10 +1915,10 @@ class LibClang { /// Determine whether the given cursor kind represents an expression. int clang_isExpression( - int arg0, + CXCursorKind arg0, ) { return _clang_isExpression( - arg0, + arg0.value, ); } @@ -1929,10 +1930,10 @@ class LibClang { /// Determine whether the given cursor kind represents a statement. int clang_isStatement( - int arg0, + CXCursorKind arg0, ) { return _clang_isStatement( - arg0, + arg0.value, ); } @@ -1944,10 +1945,10 @@ class LibClang { /// Determine whether the given cursor kind represents an attribute. int clang_isAttribute( - int arg0, + CXCursorKind arg0, ) { return _clang_isAttribute( - arg0, + arg0.value, ); } @@ -1974,10 +1975,10 @@ class LibClang { /// Determine whether the given cursor kind represents an invalid cursor. int clang_isInvalid( - int arg0, + CXCursorKind arg0, ) { return _clang_isInvalid( - arg0, + arg0.value, ); } @@ -1989,10 +1990,10 @@ class LibClang { /// Determine whether the given cursor kind represents a translation unit. int clang_isTranslationUnit( - int arg0, + CXCursorKind arg0, ) { return _clang_isTranslationUnit( - arg0, + arg0.value, ); } @@ -2005,10 +2006,10 @@ class LibClang { /// * Determine whether the given cursor represents a preprocessing element, /// such as a preprocessor directive or macro instantiation. int clang_isPreprocessing( - int arg0, + CXCursorKind arg0, ) { return _clang_isPreprocessing( - arg0, + arg0.value, ); } @@ -2021,10 +2022,10 @@ class LibClang { /// * Determine whether the given cursor represents a currently unexposed /// piece of the AST (e.g., CXCursor_UnexposedStmt). int clang_isUnexposed( - int arg0, + CXCursorKind arg0, ) { return _clang_isUnexposed( - arg0, + arg0.value, ); } @@ -2035,12 +2036,12 @@ class LibClang { _clang_isUnexposedPtr.asFunction(); /// Determine the linkage of the entity referred to by a given cursor. - int clang_getCursorLinkage( + CXLinkageKind clang_getCursorLinkage( CXCursor cursor, ) { - return _clang_getCursorLinkage( + return CXLinkageKind.fromValue(_clang_getCursorLinkage( cursor, - ); + )); } late final _clang_getCursorLinkagePtr = @@ -2050,12 +2051,12 @@ class LibClang { _clang_getCursorLinkagePtr.asFunction(); /// Describe the visibility of the entity referred to by a cursor. - int clang_getCursorVisibility( + CXVisibilityKind clang_getCursorVisibility( CXCursor cursor, ) { - return _clang_getCursorVisibility( + return CXVisibilityKind.fromValue(_clang_getCursorVisibility( cursor, - ); + )); } late final _clang_getCursorVisibilityPtr = @@ -2066,12 +2067,12 @@ class LibClang { /// Determine the availability of the entity that this cursor refers to, /// taking the current target platform into account. - int clang_getCursorAvailability( + CXAvailabilityKind clang_getCursorAvailability( CXCursor cursor, ) { - return _clang_getCursorAvailability( + return CXAvailabilityKind.fromValue(_clang_getCursorAvailability( cursor, - ); + )); } late final _clang_getCursorAvailabilityPtr = @@ -2141,12 +2142,12 @@ class LibClang { .asFunction)>(); /// Determine the "language" of the entity referred to by a given cursor. - int clang_getCursorLanguage( + CXLanguageKind clang_getCursorLanguage( CXCursor cursor, ) { - return _clang_getCursorLanguage( + return CXLanguageKind.fromValue(_clang_getCursorLanguage( cursor, - ); + )); } late final _clang_getCursorLanguagePtr = @@ -2157,12 +2158,12 @@ class LibClang { /// Determine the "thread-local storage (TLS) kind" of the declaration /// referred to by a cursor. - int clang_getCursorTLSKind( + CXTLSKind clang_getCursorTLSKind( CXCursor cursor, ) { - return _clang_getCursorTLSKind( + return CXTLSKind.fromValue(_clang_getCursorTLSKind( cursor, - ); + )); } late final _clang_getCursorTLSKindPtr = @@ -2544,14 +2545,15 @@ class LibClang { .asFunction(); /// Retrieve the kind of the I'th template argument of the CXCursor C. - int clang_Cursor_getTemplateArgumentKind( + CXTemplateArgumentKind clang_Cursor_getTemplateArgumentKind( CXCursor C, int I, ) { - return _clang_Cursor_getTemplateArgumentKind( + return CXTemplateArgumentKind.fromValue( + _clang_Cursor_getTemplateArgumentKind( C, I, - ); + )); } late final _clang_Cursor_getTemplateArgumentKindPtr = _lookup< @@ -2839,10 +2841,10 @@ class LibClang { /// Retrieve the spelling of a given CXTypeKind. CXString clang_getTypeKindSpelling( - int K, + CXTypeKind K, ) { return _clang_getTypeKindSpelling( - K, + K.value, ); } @@ -2853,12 +2855,12 @@ class LibClang { _clang_getTypeKindSpellingPtr.asFunction(); /// Retrieve the calling convention associated with a function type. - int clang_getFunctionTypeCallingConv( + CXCallingConv clang_getFunctionTypeCallingConv( CXType T, ) { - return _clang_getFunctionTypeCallingConv( + return CXCallingConv.fromValue(_clang_getFunctionTypeCallingConv( T, - ); + )); } late final _clang_getFunctionTypeCallingConvPtr = @@ -3167,12 +3169,12 @@ class LibClang { _clang_Type_isTransparentTagTypedefPtr.asFunction(); /// Retrieve the nullability kind of a pointer type. - int clang_Type_getNullability( + CXTypeNullabilityKind clang_Type_getNullability( CXType T, ) { - return _clang_Type_getNullability( + return CXTypeNullabilityKind.fromValue(_clang_Type_getNullability( T, - ); + )); } late final _clang_Type_getNullabilityPtr = @@ -3360,12 +3362,12 @@ class LibClang { .asFunction(); /// Retrieve the ref-qualifier kind of a function or method. - int clang_Type_getCXXRefQualifier( + CXRefQualifierKind clang_Type_getCXXRefQualifier( CXType T, ) { - return _clang_Type_getCXXRefQualifier( + return CXRefQualifierKind.fromValue(_clang_Type_getCXXRefQualifier( T, - ); + )); } late final _clang_Type_getCXXRefQualifierPtr = @@ -3407,12 +3409,12 @@ class LibClang { _clang_isVirtualBasePtr.asFunction(); /// Returns the access control level for the referenced object. - int clang_getCXXAccessSpecifier( + CX_CXXAccessSpecifier clang_getCXXAccessSpecifier( CXCursor arg0, ) { - return _clang_getCXXAccessSpecifier( + return CX_CXXAccessSpecifier.fromValue(_clang_getCXXAccessSpecifier( arg0, - ); + )); } late final _clang_getCXXAccessSpecifierPtr = @@ -3422,12 +3424,12 @@ class LibClang { _clang_getCXXAccessSpecifierPtr.asFunction(); /// Returns the storage class for a function or variable declaration. - int clang_Cursor_getStorageClass( + CX_StorageClass clang_Cursor_getStorageClass( CXCursor arg0, ) { - return _clang_Cursor_getStorageClass( + return CX_StorageClass.fromValue(_clang_Cursor_getStorageClass( arg0, - ); + )); } late final _clang_Cursor_getStorageClassPtr = @@ -3675,11 +3677,11 @@ class LibClang { /// Get a property value for the given printing policy. int clang_PrintingPolicy_getProperty( CXPrintingPolicy Policy, - int Property, + CXPrintingPolicyProperty Property, ) { return _clang_PrintingPolicy_getProperty( Policy, - Property, + Property.value, ); } @@ -3694,12 +3696,12 @@ class LibClang { /// Set a property value for the given printing policy. void clang_PrintingPolicy_setProperty( CXPrintingPolicy Policy, - int Property, + CXPrintingPolicyProperty Property, int Value, ) { return _clang_PrintingPolicy_setProperty( Policy, - Property, + Property.value, Value, ); } @@ -4461,12 +4463,12 @@ class LibClang { /// Given a cursor that represents a template, determine the cursor kind of /// the specializations would be generated by instantiating the template. - int clang_getTemplateCursorKind( + CXCursorKind clang_getTemplateCursorKind( CXCursor C, ) { - return _clang_getTemplateCursorKind( + return CXCursorKind.fromValue(_clang_getTemplateCursorKind( C, - ); + )); } late final _clang_getTemplateCursorKindPtr = @@ -4534,12 +4536,12 @@ class LibClang { ffi.Pointer Function(CXTranslationUnit, CXSourceLocation)>(); /// Determine the kind of the given token. - int clang_getTokenKind( + CXTokenKind clang_getTokenKind( CXToken arg0, ) { - return _clang_getTokenKind( + return CXTokenKind.fromValue(_clang_getTokenKind( arg0, - ); + )); } late final _clang_getTokenKindPtr = @@ -4675,10 +4677,10 @@ class LibClang { /// These routines are used for testing and debugging, only, and should not be /// relied upon. CXString clang_getCursorKindSpelling( - int Kind, + CXCursorKind Kind, ) { return _clang_getCursorKindSpelling( - Kind, + Kind.value, ); } @@ -4768,14 +4770,14 @@ class LibClang { int)>(); /// Determine the kind of a particular chunk within a completion string. - int clang_getCompletionChunkKind( + CXCompletionChunkKind clang_getCompletionChunkKind( CXCompletionString completion_string, int chunk_number, ) { - return _clang_getCompletionChunkKind( + return CXCompletionChunkKind.fromValue(_clang_getCompletionChunkKind( completion_string, chunk_number, - ); + )); } late final _clang_getCompletionChunkKindPtr = _lookup< @@ -4856,12 +4858,12 @@ class LibClang { /// Determine the availability of the entity that this code-completion string /// refers to. - int clang_getCompletionAvailability( + CXAvailabilityKind clang_getCompletionAvailability( CXCompletionString completion_string, ) { - return _clang_getCompletionAvailability( + return CXAvailabilityKind.fromValue(_clang_getCompletionAvailability( completion_string, - ); + )); } late final _clang_getCompletionAvailabilityPtr = @@ -5153,14 +5155,14 @@ class LibClang { /// context. The container is only guaranteed to be set for contexts where a /// container exists (i.e. member accesses or Objective-C message sends); if /// there is not a container, this function will return CXCursor_InvalidCode. - int clang_codeCompleteGetContainerKind( + CXCursorKind clang_codeCompleteGetContainerKind( ffi.Pointer Results, ffi.Pointer IsIncomplete, ) { - return _clang_codeCompleteGetContainerKind( + return CXCursorKind.fromValue(_clang_codeCompleteGetContainerKind( Results, IsIncomplete, - ); + )); } late final _clang_codeCompleteGetContainerKindPtr = _lookup< @@ -5279,12 +5281,12 @@ class LibClang { _clang_Cursor_EvaluatePtr.asFunction(); /// Returns the kind of the evaluated result. - int clang_EvalResult_getKind( + CXEvalResultKind clang_EvalResult_getKind( CXEvalResult E, ) { - return _clang_EvalResult_getKind( + return CXEvalResultKind.fromValue(_clang_EvalResult_getKind( E, - ); + )); } late final _clang_EvalResult_getKindPtr = @@ -5497,16 +5499,16 @@ class LibClang { _clang_remap_disposePtr.asFunction(); /// Find references of a declaration in a specific file. - int clang_findReferencesInFile( + CXResult clang_findReferencesInFile( CXCursor cursor, CXFile file, CXCursorAndRangeVisitor visitor, ) { - return _clang_findReferencesInFile( + return CXResult.fromValue(_clang_findReferencesInFile( cursor, file, visitor, - ); + )); } late final _clang_findReferencesInFilePtr = _lookup< @@ -5517,16 +5519,16 @@ class LibClang { .asFunction(); /// Find #import/#include directives in a specific file. - int clang_findIncludesInFile( + CXResult clang_findIncludesInFile( CXTranslationUnit TU, CXFile file, CXCursorAndRangeVisitor visitor, ) { - return _clang_findIncludesInFile( + return CXResult.fromValue(_clang_findIncludesInFile( TU, file, visitor, - ); + )); } late final _clang_findIncludesInFilePtr = _lookup< @@ -5538,10 +5540,10 @@ class LibClang { int Function(CXTranslationUnit, CXFile, CXCursorAndRangeVisitor)>(); int clang_index_isEntityObjCContainerKind( - int arg0, + CXIdxEntityKind arg0, ) { return _clang_index_isEntityObjCContainerKind( - arg0, + arg0.value, ); } @@ -6036,6 +6038,15 @@ enum CXErrorCode { final int value; const CXErrorCode(this.value); + + static CXErrorCode fromValue(int value) => switch (value) { + 0 => CXError_Success, + 1 => CXError_Failure, + 2 => CXError_Crashed, + 3 => CXError_InvalidArguments, + 4 => CXError_ASTReadError, + _ => throw ArgumentError("Invalid value for CXErrorCode: $value"), + }; } /// A character string. @@ -6101,6 +6112,15 @@ enum CXAvailabilityKind { final int value; const CXAvailabilityKind(this.value); + + static CXAvailabilityKind fromValue(int value) => switch (value) { + 0 => CXAvailability_Available, + 1 => CXAvailability_Deprecated, + 2 => CXAvailability_NotAvailable, + 3 => CXAvailability_NotAccessible, + _ => + throw ArgumentError("Invalid value for CXAvailabilityKind: $value"), + }; } /// Describes a version number of the form major.minor.subminor. @@ -6156,6 +6176,22 @@ enum CXCursor_ExceptionSpecificationKind { final int value; const CXCursor_ExceptionSpecificationKind(this.value); + + static CXCursor_ExceptionSpecificationKind fromValue(int value) => + switch (value) { + 0 => CXCursor_ExceptionSpecificationKind_None, + 1 => CXCursor_ExceptionSpecificationKind_DynamicNone, + 2 => CXCursor_ExceptionSpecificationKind_Dynamic, + 3 => CXCursor_ExceptionSpecificationKind_MSAny, + 4 => CXCursor_ExceptionSpecificationKind_BasicNoexcept, + 5 => CXCursor_ExceptionSpecificationKind_ComputedNoexcept, + 6 => CXCursor_ExceptionSpecificationKind_Unevaluated, + 7 => CXCursor_ExceptionSpecificationKind_Uninstantiated, + 8 => CXCursor_ExceptionSpecificationKind_Unparsed, + 9 => CXCursor_ExceptionSpecificationKind_NoThrow, + _ => throw ArgumentError( + "Invalid value for CXCursor_ExceptionSpecificationKind: $value"), + }; } /// An "index" that consists of a set of translation units that would typically @@ -6180,6 +6216,14 @@ enum CXGlobalOptFlags { final int value; const CXGlobalOptFlags(this.value); + + static CXGlobalOptFlags fromValue(int value) => switch (value) { + 0 => CXGlobalOpt_None, + 1 => CXGlobalOpt_ThreadBackgroundPriorityForIndexing, + 2 => CXGlobalOpt_ThreadBackgroundPriorityForEditing, + 3 => CXGlobalOpt_ThreadBackgroundPriorityForAll, + _ => throw ArgumentError("Invalid value for CXGlobalOptFlags: $value"), + }; } /// A particular source file that is part of a translation unit. @@ -6247,6 +6291,16 @@ enum CXDiagnosticSeverity { final int value; const CXDiagnosticSeverity(this.value); + + static CXDiagnosticSeverity fromValue(int value) => switch (value) { + 0 => CXDiagnostic_Ignored, + 1 => CXDiagnostic_Note, + 2 => CXDiagnostic_Warning, + 3 => CXDiagnostic_Error, + 4 => CXDiagnostic_Fatal, + _ => + throw ArgumentError("Invalid value for CXDiagnosticSeverity: $value"), + }; } /// A group of CXDiagnostics. @@ -6275,6 +6329,14 @@ enum CXLoadDiag_Error { final int value; const CXLoadDiag_Error(this.value); + + static CXLoadDiag_Error fromValue(int value) => switch (value) { + 0 => CXLoadDiag_None, + 1 => CXLoadDiag_Unknown, + 2 => CXLoadDiag_CannotLoad, + 3 => CXLoadDiag_InvalidFile, + _ => throw ArgumentError("Invalid value for CXLoadDiag_Error: $value"), + }; } /// Options to control the display of diagnostics. @@ -6301,6 +6363,17 @@ enum CXDiagnosticDisplayOptions { final int value; const CXDiagnosticDisplayOptions(this.value); + + static CXDiagnosticDisplayOptions fromValue(int value) => switch (value) { + 1 => CXDiagnostic_DisplaySourceLocation, + 2 => CXDiagnostic_DisplayColumn, + 4 => CXDiagnostic_DisplaySourceRanges, + 8 => CXDiagnostic_DisplayOption, + 16 => CXDiagnostic_DisplayCategoryId, + 32 => CXDiagnostic_DisplayCategoryName, + _ => throw ArgumentError( + "Invalid value for CXDiagnosticDisplayOptions: $value"), + }; } /// Flags that control the creation of translation units. @@ -6368,6 +6441,28 @@ enum CXTranslationUnit_Flags { final int value; const CXTranslationUnit_Flags(this.value); + + static CXTranslationUnit_Flags fromValue(int value) => switch (value) { + 0 => CXTranslationUnit_None, + 1 => CXTranslationUnit_DetailedPreprocessingRecord, + 2 => CXTranslationUnit_Incomplete, + 4 => CXTranslationUnit_PrecompiledPreamble, + 8 => CXTranslationUnit_CacheCompletionResults, + 16 => CXTranslationUnit_ForSerialization, + 32 => CXTranslationUnit_CXXChainedPCH, + 64 => CXTranslationUnit_SkipFunctionBodies, + 128 => CXTranslationUnit_IncludeBriefCommentsInCodeCompletion, + 256 => CXTranslationUnit_CreatePreambleOnFirstParse, + 512 => CXTranslationUnit_KeepGoing, + 1024 => CXTranslationUnit_SingleFileParse, + 2048 => CXTranslationUnit_LimitSkipFunctionBodiesToPreamble, + 4096 => CXTranslationUnit_IncludeAttributedTypes, + 8192 => CXTranslationUnit_VisitImplicitAttributes, + 16384 => CXTranslationUnit_IgnoreNonErrorsFromIncludedFiles, + 32768 => CXTranslationUnit_RetainExcludedConditionalBlocks, + _ => throw ArgumentError( + "Invalid value for CXTranslationUnit_Flags: $value"), + }; } /// Flags that control how translation units are saved. @@ -6377,6 +6472,12 @@ enum CXSaveTranslationUnit_Flags { final int value; const CXSaveTranslationUnit_Flags(this.value); + + static CXSaveTranslationUnit_Flags fromValue(int value) => switch (value) { + 0 => CXSaveTranslationUnit_None, + _ => throw ArgumentError( + "Invalid value for CXSaveTranslationUnit_Flags: $value"), + }; } /// Describes the kind of error that occurred (if any) in a call to @@ -6399,6 +6500,14 @@ enum CXSaveError { final int value; const CXSaveError(this.value); + + static CXSaveError fromValue(int value) => switch (value) { + 0 => CXSaveError_None, + 1 => CXSaveError_Unknown, + 2 => CXSaveError_TranslationErrors, + 3 => CXSaveError_InvalidTU, + _ => throw ArgumentError("Invalid value for CXSaveError: $value"), + }; } /// Flags that control the reparsing of translation units. @@ -6408,6 +6517,11 @@ enum CXReparse_Flags { final int value; const CXReparse_Flags(this.value); + + static CXReparse_Flags fromValue(int value) => switch (value) { + 0 => CXReparse_None, + _ => throw ArgumentError("Invalid value for CXReparse_Flags: $value"), + }; } /// Categorizes how memory is being used by a translation unit. @@ -6437,6 +6551,25 @@ enum CXTUResourceUsageKind { final int value; const CXTUResourceUsageKind(this.value); + static CXTUResourceUsageKind fromValue(int value) => switch (value) { + 1 => CXTUResourceUsage_AST, + 2 => CXTUResourceUsage_Identifiers, + 3 => CXTUResourceUsage_Selectors, + 4 => CXTUResourceUsage_GlobalCompletionResults, + 5 => CXTUResourceUsage_SourceManagerContentCache, + 6 => CXTUResourceUsage_AST_SideTables, + 7 => CXTUResourceUsage_SourceManager_Membuffer_Malloc, + 8 => CXTUResourceUsage_SourceManager_Membuffer_MMap, + 9 => CXTUResourceUsage_ExternalASTSource_Membuffer_Malloc, + 10 => CXTUResourceUsage_ExternalASTSource_Membuffer_MMap, + 11 => CXTUResourceUsage_Preprocessor, + 12 => CXTUResourceUsage_PreprocessingRecord, + 13 => CXTUResourceUsage_SourceManager_DataStructures, + 14 => CXTUResourceUsage_Preprocessor_HeaderSearch, + _ => throw ArgumentError( + "Invalid value for CXTUResourceUsageKind: $value"), + }; + @override String toString() { if (this == CXTUResourceUsage_AST) @@ -7122,6 +7255,252 @@ enum CXCursorKind { final int value; const CXCursorKind(this.value); + static CXCursorKind fromValue(int value) => switch (value) { + 1 => CXCursor_UnexposedDecl, + 2 => CXCursor_StructDecl, + 3 => CXCursor_UnionDecl, + 4 => CXCursor_ClassDecl, + 5 => CXCursor_EnumDecl, + 6 => CXCursor_FieldDecl, + 7 => CXCursor_EnumConstantDecl, + 8 => CXCursor_FunctionDecl, + 9 => CXCursor_VarDecl, + 10 => CXCursor_ParmDecl, + 11 => CXCursor_ObjCInterfaceDecl, + 12 => CXCursor_ObjCCategoryDecl, + 13 => CXCursor_ObjCProtocolDecl, + 14 => CXCursor_ObjCPropertyDecl, + 15 => CXCursor_ObjCIvarDecl, + 16 => CXCursor_ObjCInstanceMethodDecl, + 17 => CXCursor_ObjCClassMethodDecl, + 18 => CXCursor_ObjCImplementationDecl, + 19 => CXCursor_ObjCCategoryImplDecl, + 20 => CXCursor_TypedefDecl, + 21 => CXCursor_CXXMethod, + 22 => CXCursor_Namespace, + 23 => CXCursor_LinkageSpec, + 24 => CXCursor_Constructor, + 25 => CXCursor_Destructor, + 26 => CXCursor_ConversionFunction, + 27 => CXCursor_TemplateTypeParameter, + 28 => CXCursor_NonTypeTemplateParameter, + 29 => CXCursor_TemplateTemplateParameter, + 30 => CXCursor_FunctionTemplate, + 31 => CXCursor_ClassTemplate, + 32 => CXCursor_ClassTemplatePartialSpecialization, + 33 => CXCursor_NamespaceAlias, + 34 => CXCursor_UsingDirective, + 35 => CXCursor_UsingDeclaration, + 36 => CXCursor_TypeAliasDecl, + 37 => CXCursor_ObjCSynthesizeDecl, + 38 => CXCursor_ObjCDynamicDecl, + 39 => CXCursor_CXXAccessSpecifier, + 40 => CXCursor_FirstRef, + 41 => CXCursor_ObjCProtocolRef, + 42 => CXCursor_ObjCClassRef, + 43 => CXCursor_TypeRef, + 44 => CXCursor_CXXBaseSpecifier, + 45 => CXCursor_TemplateRef, + 46 => CXCursor_NamespaceRef, + 47 => CXCursor_MemberRef, + 48 => CXCursor_LabelRef, + 49 => CXCursor_OverloadedDeclRef, + 50 => CXCursor_VariableRef, + 70 => CXCursor_FirstInvalid, + 71 => CXCursor_NoDeclFound, + 72 => CXCursor_NotImplemented, + 73 => CXCursor_InvalidCode, + 100 => CXCursor_FirstExpr, + 101 => CXCursor_DeclRefExpr, + 102 => CXCursor_MemberRefExpr, + 103 => CXCursor_CallExpr, + 104 => CXCursor_ObjCMessageExpr, + 105 => CXCursor_BlockExpr, + 106 => CXCursor_IntegerLiteral, + 107 => CXCursor_FloatingLiteral, + 108 => CXCursor_ImaginaryLiteral, + 109 => CXCursor_StringLiteral, + 110 => CXCursor_CharacterLiteral, + 111 => CXCursor_ParenExpr, + 112 => CXCursor_UnaryOperator, + 113 => CXCursor_ArraySubscriptExpr, + 114 => CXCursor_BinaryOperator, + 115 => CXCursor_CompoundAssignOperator, + 116 => CXCursor_ConditionalOperator, + 117 => CXCursor_CStyleCastExpr, + 118 => CXCursor_CompoundLiteralExpr, + 119 => CXCursor_InitListExpr, + 120 => CXCursor_AddrLabelExpr, + 121 => CXCursor_StmtExpr, + 122 => CXCursor_GenericSelectionExpr, + 123 => CXCursor_GNUNullExpr, + 124 => CXCursor_CXXStaticCastExpr, + 125 => CXCursor_CXXDynamicCastExpr, + 126 => CXCursor_CXXReinterpretCastExpr, + 127 => CXCursor_CXXConstCastExpr, + 128 => CXCursor_CXXFunctionalCastExpr, + 129 => CXCursor_CXXTypeidExpr, + 130 => CXCursor_CXXBoolLiteralExpr, + 131 => CXCursor_CXXNullPtrLiteralExpr, + 132 => CXCursor_CXXThisExpr, + 133 => CXCursor_CXXThrowExpr, + 134 => CXCursor_CXXNewExpr, + 135 => CXCursor_CXXDeleteExpr, + 136 => CXCursor_UnaryExpr, + 137 => CXCursor_ObjCStringLiteral, + 138 => CXCursor_ObjCEncodeExpr, + 139 => CXCursor_ObjCSelectorExpr, + 140 => CXCursor_ObjCProtocolExpr, + 141 => CXCursor_ObjCBridgedCastExpr, + 142 => CXCursor_PackExpansionExpr, + 143 => CXCursor_SizeOfPackExpr, + 144 => CXCursor_LambdaExpr, + 145 => CXCursor_ObjCBoolLiteralExpr, + 146 => CXCursor_ObjCSelfExpr, + 147 => CXCursor_OMPArraySectionExpr, + 148 => CXCursor_ObjCAvailabilityCheckExpr, + 149 => CXCursor_FixedPointLiteral, + 200 => CXCursor_FirstStmt, + 201 => CXCursor_LabelStmt, + 202 => CXCursor_CompoundStmt, + 203 => CXCursor_CaseStmt, + 204 => CXCursor_DefaultStmt, + 205 => CXCursor_IfStmt, + 206 => CXCursor_SwitchStmt, + 207 => CXCursor_WhileStmt, + 208 => CXCursor_DoStmt, + 209 => CXCursor_ForStmt, + 210 => CXCursor_GotoStmt, + 211 => CXCursor_IndirectGotoStmt, + 212 => CXCursor_ContinueStmt, + 213 => CXCursor_BreakStmt, + 214 => CXCursor_ReturnStmt, + 215 => CXCursor_GCCAsmStmt, + 216 => CXCursor_ObjCAtTryStmt, + 217 => CXCursor_ObjCAtCatchStmt, + 218 => CXCursor_ObjCAtFinallyStmt, + 219 => CXCursor_ObjCAtThrowStmt, + 220 => CXCursor_ObjCAtSynchronizedStmt, + 221 => CXCursor_ObjCAutoreleasePoolStmt, + 222 => CXCursor_ObjCForCollectionStmt, + 223 => CXCursor_CXXCatchStmt, + 224 => CXCursor_CXXTryStmt, + 225 => CXCursor_CXXForRangeStmt, + 226 => CXCursor_SEHTryStmt, + 227 => CXCursor_SEHExceptStmt, + 228 => CXCursor_SEHFinallyStmt, + 229 => CXCursor_MSAsmStmt, + 230 => CXCursor_NullStmt, + 231 => CXCursor_DeclStmt, + 232 => CXCursor_OMPParallelDirective, + 233 => CXCursor_OMPSimdDirective, + 234 => CXCursor_OMPForDirective, + 235 => CXCursor_OMPSectionsDirective, + 236 => CXCursor_OMPSectionDirective, + 237 => CXCursor_OMPSingleDirective, + 238 => CXCursor_OMPParallelForDirective, + 239 => CXCursor_OMPParallelSectionsDirective, + 240 => CXCursor_OMPTaskDirective, + 241 => CXCursor_OMPMasterDirective, + 242 => CXCursor_OMPCriticalDirective, + 243 => CXCursor_OMPTaskyieldDirective, + 244 => CXCursor_OMPBarrierDirective, + 245 => CXCursor_OMPTaskwaitDirective, + 246 => CXCursor_OMPFlushDirective, + 247 => CXCursor_SEHLeaveStmt, + 248 => CXCursor_OMPOrderedDirective, + 249 => CXCursor_OMPAtomicDirective, + 250 => CXCursor_OMPForSimdDirective, + 251 => CXCursor_OMPParallelForSimdDirective, + 252 => CXCursor_OMPTargetDirective, + 253 => CXCursor_OMPTeamsDirective, + 254 => CXCursor_OMPTaskgroupDirective, + 255 => CXCursor_OMPCancellationPointDirective, + 256 => CXCursor_OMPCancelDirective, + 257 => CXCursor_OMPTargetDataDirective, + 258 => CXCursor_OMPTaskLoopDirective, + 259 => CXCursor_OMPTaskLoopSimdDirective, + 260 => CXCursor_OMPDistributeDirective, + 261 => CXCursor_OMPTargetEnterDataDirective, + 262 => CXCursor_OMPTargetExitDataDirective, + 263 => CXCursor_OMPTargetParallelDirective, + 264 => CXCursor_OMPTargetParallelForDirective, + 265 => CXCursor_OMPTargetUpdateDirective, + 266 => CXCursor_OMPDistributeParallelForDirective, + 267 => CXCursor_OMPDistributeParallelForSimdDirective, + 268 => CXCursor_OMPDistributeSimdDirective, + 269 => CXCursor_OMPTargetParallelForSimdDirective, + 270 => CXCursor_OMPTargetSimdDirective, + 271 => CXCursor_OMPTeamsDistributeDirective, + 272 => CXCursor_OMPTeamsDistributeSimdDirective, + 273 => CXCursor_OMPTeamsDistributeParallelForSimdDirective, + 274 => CXCursor_OMPTeamsDistributeParallelForDirective, + 275 => CXCursor_OMPTargetTeamsDirective, + 276 => CXCursor_OMPTargetTeamsDistributeDirective, + 277 => CXCursor_OMPTargetTeamsDistributeParallelForDirective, + 278 => CXCursor_OMPTargetTeamsDistributeParallelForSimdDirective, + 279 => CXCursor_OMPTargetTeamsDistributeSimdDirective, + 280 => CXCursor_BuiltinBitCastExpr, + 281 => CXCursor_OMPMasterTaskLoopDirective, + 282 => CXCursor_OMPParallelMasterTaskLoopDirective, + 283 => CXCursor_OMPMasterTaskLoopSimdDirective, + 284 => CXCursor_OMPParallelMasterTaskLoopSimdDirective, + 285 => CXCursor_OMPParallelMasterDirective, + 300 => CXCursor_TranslationUnit, + 400 => CXCursor_FirstAttr, + 401 => CXCursor_IBActionAttr, + 402 => CXCursor_IBOutletAttr, + 403 => CXCursor_IBOutletCollectionAttr, + 404 => CXCursor_CXXFinalAttr, + 405 => CXCursor_CXXOverrideAttr, + 406 => CXCursor_AnnotateAttr, + 407 => CXCursor_AsmLabelAttr, + 408 => CXCursor_PackedAttr, + 409 => CXCursor_PureAttr, + 410 => CXCursor_ConstAttr, + 411 => CXCursor_NoDuplicateAttr, + 412 => CXCursor_CUDAConstantAttr, + 413 => CXCursor_CUDADeviceAttr, + 414 => CXCursor_CUDAGlobalAttr, + 415 => CXCursor_CUDAHostAttr, + 416 => CXCursor_CUDASharedAttr, + 417 => CXCursor_VisibilityAttr, + 418 => CXCursor_DLLExport, + 419 => CXCursor_DLLImport, + 420 => CXCursor_NSReturnsRetained, + 421 => CXCursor_NSReturnsNotRetained, + 422 => CXCursor_NSReturnsAutoreleased, + 423 => CXCursor_NSConsumesSelf, + 424 => CXCursor_NSConsumed, + 425 => CXCursor_ObjCException, + 426 => CXCursor_ObjCNSObject, + 427 => CXCursor_ObjCIndependentClass, + 428 => CXCursor_ObjCPreciseLifetime, + 429 => CXCursor_ObjCReturnsInnerPointer, + 430 => CXCursor_ObjCRequiresSuper, + 431 => CXCursor_ObjCRootClass, + 432 => CXCursor_ObjCSubclassingRestricted, + 433 => CXCursor_ObjCExplicitProtocolImpl, + 434 => CXCursor_ObjCDesignatedInitializer, + 435 => CXCursor_ObjCRuntimeVisible, + 436 => CXCursor_ObjCBoxable, + 437 => CXCursor_FlagEnum, + 438 => CXCursor_ConvergentAttr, + 439 => CXCursor_WarnUnusedAttr, + 440 => CXCursor_WarnUnusedResultAttr, + 441 => CXCursor_AlignedAttr, + 500 => CXCursor_PreprocessingDirective, + 501 => CXCursor_MacroDefinition, + 502 => CXCursor_MacroExpansion, + 503 => CXCursor_InclusionDirective, + 600 => CXCursor_ModuleImportDecl, + 601 => CXCursor_TypeAliasTemplateDecl, + 602 => CXCursor_StaticAssert, + 603 => CXCursor_FriendDecl, + 700 => CXCursor_OverloadCandidate, + _ => throw ArgumentError("Invalid value for CXCursorKind: $value"), + }; + @override String toString() { if (this == CXCursor_UnexposedDecl) @@ -7199,6 +7578,15 @@ enum CXLinkageKind { final int value; const CXLinkageKind(this.value); + + static CXLinkageKind fromValue(int value) => switch (value) { + 0 => CXLinkage_Invalid, + 1 => CXLinkage_NoLinkage, + 2 => CXLinkage_Internal, + 3 => CXLinkage_UniqueExternal, + 4 => CXLinkage_External, + _ => throw ArgumentError("Invalid value for CXLinkageKind: $value"), + }; } enum CXVisibilityKind { @@ -7217,6 +7605,14 @@ enum CXVisibilityKind { final int value; const CXVisibilityKind(this.value); + + static CXVisibilityKind fromValue(int value) => switch (value) { + 0 => CXVisibility_Invalid, + 1 => CXVisibility_Hidden, + 2 => CXVisibility_Protected, + 3 => CXVisibility_Default, + _ => throw ArgumentError("Invalid value for CXVisibilityKind: $value"), + }; } /// Describes the availability of a given entity on a particular platform, e.g., @@ -7255,6 +7651,14 @@ enum CXLanguageKind { final int value; const CXLanguageKind(this.value); + + static CXLanguageKind fromValue(int value) => switch (value) { + 0 => CXLanguage_Invalid, + 1 => CXLanguage_C, + 2 => CXLanguage_ObjC, + 3 => CXLanguage_CPlusPlus, + _ => throw ArgumentError("Invalid value for CXLanguageKind: $value"), + }; } /// Describe the "thread-local storage (TLS) kind" of the declaration referred @@ -7266,6 +7670,13 @@ enum CXTLSKind { final int value; const CXTLSKind(this.value); + + static CXTLSKind fromValue(int value) => switch (value) { + 0 => CXTLS_None, + 1 => CXTLS_Dynamic, + 2 => CXTLS_Static, + _ => throw ArgumentError("Invalid value for CXTLSKind: $value"), + }; } final class CXCursorSetImpl extends ffi.Opaque {} @@ -7403,6 +7814,126 @@ enum CXTypeKind { final int value; const CXTypeKind(this.value); + static CXTypeKind fromValue(int value) => switch (value) { + 0 => CXType_Invalid, + 1 => CXType_Unexposed, + 2 => CXType_Void, + 3 => CXType_Bool, + 4 => CXType_Char_U, + 5 => CXType_UChar, + 6 => CXType_Char16, + 7 => CXType_Char32, + 8 => CXType_UShort, + 9 => CXType_UInt, + 10 => CXType_ULong, + 11 => CXType_ULongLong, + 12 => CXType_UInt128, + 13 => CXType_Char_S, + 14 => CXType_SChar, + 15 => CXType_WChar, + 16 => CXType_Short, + 17 => CXType_Int, + 18 => CXType_Long, + 19 => CXType_LongLong, + 20 => CXType_Int128, + 21 => CXType_Float, + 22 => CXType_Double, + 23 => CXType_LongDouble, + 24 => CXType_NullPtr, + 25 => CXType_Overload, + 26 => CXType_Dependent, + 27 => CXType_ObjCId, + 28 => CXType_ObjCClass, + 29 => CXType_ObjCSel, + 30 => CXType_Float128, + 31 => CXType_Half, + 32 => CXType_Float16, + 33 => CXType_ShortAccum, + 34 => CXType_Accum, + 35 => CXType_LongAccum, + 36 => CXType_UShortAccum, + 37 => CXType_UAccum, + 38 => CXType_ULongAccum, + 100 => CXType_Complex, + 101 => CXType_Pointer, + 102 => CXType_BlockPointer, + 103 => CXType_LValueReference, + 104 => CXType_RValueReference, + 105 => CXType_Record, + 106 => CXType_Enum, + 107 => CXType_Typedef, + 108 => CXType_ObjCInterface, + 109 => CXType_ObjCObjectPointer, + 110 => CXType_FunctionNoProto, + 111 => CXType_FunctionProto, + 112 => CXType_ConstantArray, + 113 => CXType_Vector, + 114 => CXType_IncompleteArray, + 115 => CXType_VariableArray, + 116 => CXType_DependentSizedArray, + 117 => CXType_MemberPointer, + 118 => CXType_Auto, + 119 => CXType_Elaborated, + 120 => CXType_Pipe, + 121 => CXType_OCLImage1dRO, + 122 => CXType_OCLImage1dArrayRO, + 123 => CXType_OCLImage1dBufferRO, + 124 => CXType_OCLImage2dRO, + 125 => CXType_OCLImage2dArrayRO, + 126 => CXType_OCLImage2dDepthRO, + 127 => CXType_OCLImage2dArrayDepthRO, + 128 => CXType_OCLImage2dMSAARO, + 129 => CXType_OCLImage2dArrayMSAARO, + 130 => CXType_OCLImage2dMSAADepthRO, + 131 => CXType_OCLImage2dArrayMSAADepthRO, + 132 => CXType_OCLImage3dRO, + 133 => CXType_OCLImage1dWO, + 134 => CXType_OCLImage1dArrayWO, + 135 => CXType_OCLImage1dBufferWO, + 136 => CXType_OCLImage2dWO, + 137 => CXType_OCLImage2dArrayWO, + 138 => CXType_OCLImage2dDepthWO, + 139 => CXType_OCLImage2dArrayDepthWO, + 140 => CXType_OCLImage2dMSAAWO, + 141 => CXType_OCLImage2dArrayMSAAWO, + 142 => CXType_OCLImage2dMSAADepthWO, + 143 => CXType_OCLImage2dArrayMSAADepthWO, + 144 => CXType_OCLImage3dWO, + 145 => CXType_OCLImage1dRW, + 146 => CXType_OCLImage1dArrayRW, + 147 => CXType_OCLImage1dBufferRW, + 148 => CXType_OCLImage2dRW, + 149 => CXType_OCLImage2dArrayRW, + 150 => CXType_OCLImage2dDepthRW, + 151 => CXType_OCLImage2dArrayDepthRW, + 152 => CXType_OCLImage2dMSAARW, + 153 => CXType_OCLImage2dArrayMSAARW, + 154 => CXType_OCLImage2dMSAADepthRW, + 155 => CXType_OCLImage2dArrayMSAADepthRW, + 156 => CXType_OCLImage3dRW, + 157 => CXType_OCLSampler, + 158 => CXType_OCLEvent, + 159 => CXType_OCLQueue, + 160 => CXType_OCLReserveID, + 161 => CXType_ObjCObject, + 162 => CXType_ObjCTypeParam, + 163 => CXType_Attributed, + 164 => CXType_OCLIntelSubgroupAVCMcePayload, + 165 => CXType_OCLIntelSubgroupAVCImePayload, + 166 => CXType_OCLIntelSubgroupAVCRefPayload, + 167 => CXType_OCLIntelSubgroupAVCSicPayload, + 168 => CXType_OCLIntelSubgroupAVCMceResult, + 169 => CXType_OCLIntelSubgroupAVCImeResult, + 170 => CXType_OCLIntelSubgroupAVCRefResult, + 171 => CXType_OCLIntelSubgroupAVCSicResult, + 172 => CXType_OCLIntelSubgroupAVCImeResultSingleRefStreamout, + 173 => CXType_OCLIntelSubgroupAVCImeResultDualRefStreamout, + 174 => CXType_OCLIntelSubgroupAVCImeSingleRefStreamin, + 175 => CXType_OCLIntelSubgroupAVCImeDualRefStreamin, + 176 => CXType_ExtVector, + _ => throw ArgumentError("Invalid value for CXTypeKind: $value"), + }; + @override String toString() { if (this == CXType_Void) @@ -7440,6 +7971,29 @@ enum CXCallingConv { final int value; const CXCallingConv(this.value); + static CXCallingConv fromValue(int value) => switch (value) { + 0 => CXCallingConv_Default, + 1 => CXCallingConv_C, + 2 => CXCallingConv_X86StdCall, + 3 => CXCallingConv_X86FastCall, + 4 => CXCallingConv_X86ThisCall, + 5 => CXCallingConv_X86Pascal, + 6 => CXCallingConv_AAPCS, + 7 => CXCallingConv_AAPCS_VFP, + 8 => CXCallingConv_X86RegCall, + 9 => CXCallingConv_IntelOclBicc, + 10 => CXCallingConv_Win64, + 11 => CXCallingConv_X86_64SysV, + 12 => CXCallingConv_X86VectorCall, + 13 => CXCallingConv_Swift, + 14 => CXCallingConv_PreserveMost, + 15 => CXCallingConv_PreserveAll, + 16 => CXCallingConv_AArch64VectorCall, + 100 => CXCallingConv_Invalid, + 200 => CXCallingConv_Unexposed, + _ => throw ArgumentError("Invalid value for CXCallingConv: $value"), + }; + @override String toString() { if (this == CXCallingConv_Win64) @@ -7472,6 +8026,21 @@ enum CXTemplateArgumentKind { final int value; const CXTemplateArgumentKind(this.value); + + static CXTemplateArgumentKind fromValue(int value) => switch (value) { + 0 => CXTemplateArgumentKind_Null, + 1 => CXTemplateArgumentKind_Type, + 2 => CXTemplateArgumentKind_Declaration, + 3 => CXTemplateArgumentKind_NullPtr, + 4 => CXTemplateArgumentKind_Integral, + 5 => CXTemplateArgumentKind_Template, + 6 => CXTemplateArgumentKind_TemplateExpansion, + 7 => CXTemplateArgumentKind_Expression, + 8 => CXTemplateArgumentKind_Pack, + 9 => CXTemplateArgumentKind_Invalid, + _ => throw ArgumentError( + "Invalid value for CXTemplateArgumentKind: $value"), + }; } enum CXTypeNullabilityKind { @@ -7491,6 +8060,15 @@ enum CXTypeNullabilityKind { final int value; const CXTypeNullabilityKind(this.value); + + static CXTypeNullabilityKind fromValue(int value) => switch (value) { + 0 => CXTypeNullability_NonNull, + 1 => CXTypeNullability_Nullable, + 2 => CXTypeNullability_Unspecified, + 3 => CXTypeNullability_Invalid, + _ => throw ArgumentError( + "Invalid value for CXTypeNullabilityKind: $value"), + }; } /// List the possible error codes for clang_Type_getSizeOf, @@ -7516,6 +8094,16 @@ enum CXTypeLayoutError { final int value; const CXTypeLayoutError(this.value); + + static CXTypeLayoutError fromValue(int value) => switch (value) { + -1 => CXTypeLayoutError_Invalid, + -2 => CXTypeLayoutError_Incomplete, + -3 => CXTypeLayoutError_Dependent, + -4 => CXTypeLayoutError_NotConstantSize, + -5 => CXTypeLayoutError_InvalidFieldName, + -6 => CXTypeLayoutError_Undeduced, + _ => throw ArgumentError("Invalid value for CXTypeLayoutError: $value"), + }; } enum CXRefQualifierKind { @@ -7530,6 +8118,14 @@ enum CXRefQualifierKind { final int value; const CXRefQualifierKind(this.value); + + static CXRefQualifierKind fromValue(int value) => switch (value) { + 0 => CXRefQualifier_None, + 1 => CXRefQualifier_LValue, + 2 => CXRefQualifier_RValue, + _ => + throw ArgumentError("Invalid value for CXRefQualifierKind: $value"), + }; } /// Represents the C++ access control level to a base class for a cursor with @@ -7542,6 +8138,15 @@ enum CX_CXXAccessSpecifier { final int value; const CX_CXXAccessSpecifier(this.value); + + static CX_CXXAccessSpecifier fromValue(int value) => switch (value) { + 0 => CX_CXXInvalidAccessSpecifier, + 1 => CX_CXXPublic, + 2 => CX_CXXProtected, + 3 => CX_CXXPrivate, + _ => throw ArgumentError( + "Invalid value for CX_CXXAccessSpecifier: $value"), + }; } /// Represents the storage classes as declared in the source. CX_SC_Invalid was @@ -7558,6 +8163,18 @@ enum CX_StorageClass { final int value; const CX_StorageClass(this.value); + + static CX_StorageClass fromValue(int value) => switch (value) { + 0 => CX_SC_Invalid, + 1 => CX_SC_None, + 2 => CX_SC_Extern, + 3 => CX_SC_Static, + 4 => CX_SC_PrivateExtern, + 5 => CX_SC_OpenCLWorkGroupLocal, + 6 => CX_SC_Auto, + 7 => CX_SC_Register, + _ => throw ArgumentError("Invalid value for CX_StorageClass: $value"), + }; } /// Describes how the traversal of the children of a particular cursor should @@ -7576,6 +8193,14 @@ enum CXChildVisitResult { final int value; const CXChildVisitResult(this.value); + + static CXChildVisitResult fromValue(int value) => switch (value) { + 0 => CXChildVisit_Break, + 1 => CXChildVisit_Continue, + 2 => CXChildVisit_Recurse, + _ => + throw ArgumentError("Invalid value for CXChildVisitResult: $value"), + }; } /// Visitor invoked for each cursor found by a traversal. @@ -7583,7 +8208,7 @@ typedef CXCursorVisitor = ffi.Pointer>; typedef CXCursorVisitorFunction = ffi.Int32 Function( CXCursor cursor, CXCursor parent, CXClientData client_data); -typedef DartCXCursorVisitorFunction = int Function( +typedef DartCXCursorVisitorFunction = CXChildVisitResult Function( CXCursor cursor, CXCursor parent, CXClientData client_data); /// Opaque pointer representing client data that will be passed through to @@ -7625,6 +8250,37 @@ enum CXPrintingPolicyProperty { final int value; const CXPrintingPolicyProperty(this.value); + static CXPrintingPolicyProperty fromValue(int value) => switch (value) { + 0 => CXPrintingPolicy_Indentation, + 1 => CXPrintingPolicy_SuppressSpecifiers, + 2 => CXPrintingPolicy_SuppressTagKeyword, + 3 => CXPrintingPolicy_IncludeTagDefinition, + 4 => CXPrintingPolicy_SuppressScope, + 5 => CXPrintingPolicy_SuppressUnwrittenScope, + 6 => CXPrintingPolicy_SuppressInitializers, + 7 => CXPrintingPolicy_ConstantArraySizeAsWritten, + 8 => CXPrintingPolicy_AnonymousTagLocations, + 9 => CXPrintingPolicy_SuppressStrongLifetime, + 10 => CXPrintingPolicy_SuppressLifetimeQualifiers, + 11 => CXPrintingPolicy_SuppressTemplateArgsInCXXConstructors, + 12 => CXPrintingPolicy_Bool, + 13 => CXPrintingPolicy_Restrict, + 14 => CXPrintingPolicy_Alignof, + 15 => CXPrintingPolicy_UnderscoreAlignof, + 16 => CXPrintingPolicy_UseVoidForZeroParams, + 17 => CXPrintingPolicy_TerseOutput, + 18 => CXPrintingPolicy_PolishForDeclaration, + 19 => CXPrintingPolicy_Half, + 20 => CXPrintingPolicy_MSWChar, + 21 => CXPrintingPolicy_IncludeNewlines, + 22 => CXPrintingPolicy_MSVCFormatting, + 23 => CXPrintingPolicy_ConstantsAsWritten, + 24 => CXPrintingPolicy_SuppressImplicitBase, + 25 => CXPrintingPolicy_FullyQualifiedName, + _ => throw ArgumentError( + "Invalid value for CXPrintingPolicyProperty: $value"), + }; + @override String toString() { if (this == CXPrintingPolicy_FullyQualifiedName) @@ -7656,6 +8312,25 @@ enum CXObjCPropertyAttrKind { final int value; const CXObjCPropertyAttrKind(this.value); + + static CXObjCPropertyAttrKind fromValue(int value) => switch (value) { + 0 => CXObjCPropertyAttr_noattr, + 1 => CXObjCPropertyAttr_readonly, + 2 => CXObjCPropertyAttr_getter, + 4 => CXObjCPropertyAttr_assign, + 8 => CXObjCPropertyAttr_readwrite, + 16 => CXObjCPropertyAttr_retain, + 32 => CXObjCPropertyAttr_copy, + 64 => CXObjCPropertyAttr_nonatomic, + 128 => CXObjCPropertyAttr_setter, + 256 => CXObjCPropertyAttr_atomic, + 512 => CXObjCPropertyAttr_weak, + 1024 => CXObjCPropertyAttr_strong, + 2048 => CXObjCPropertyAttr_unsafe_unretained, + 4096 => CXObjCPropertyAttr_class, + _ => throw ArgumentError( + "Invalid value for CXObjCPropertyAttrKind: $value"), + }; } /// 'Qualifiers' written next to the return and parameter types in Objective-C @@ -7671,6 +8346,18 @@ enum CXObjCDeclQualifierKind { final int value; const CXObjCDeclQualifierKind(this.value); + + static CXObjCDeclQualifierKind fromValue(int value) => switch (value) { + 0 => CXObjCDeclQualifier_None, + 1 => CXObjCDeclQualifier_In, + 2 => CXObjCDeclQualifier_Inout, + 4 => CXObjCDeclQualifier_Out, + 8 => CXObjCDeclQualifier_Bycopy, + 16 => CXObjCDeclQualifier_Byref, + 32 => CXObjCDeclQualifier_Oneway, + _ => throw ArgumentError( + "Invalid value for CXObjCDeclQualifierKind: $value"), + }; } /// The functions in this group provide access to information about modules. @@ -7689,6 +8376,13 @@ enum CXNameRefFlags { final int value; const CXNameRefFlags(this.value); + + static CXNameRefFlags fromValue(int value) => switch (value) { + 1 => CXNameRange_WantQualifier, + 2 => CXNameRange_WantTemplateArgs, + 4 => CXNameRange_WantSinglePiece, + _ => throw ArgumentError("Invalid value for CXNameRefFlags: $value"), + }; } /// Describes a kind of token. @@ -7710,6 +8404,15 @@ enum CXTokenKind { final int value; const CXTokenKind(this.value); + + static CXTokenKind fromValue(int value) => switch (value) { + 0 => CXToken_Punctuation, + 1 => CXToken_Keyword, + 2 => CXToken_Identifier, + 3 => CXToken_Literal, + 4 => CXToken_Comment, + _ => throw ArgumentError("Invalid value for CXTokenKind: $value"), + }; } /// Describes a single preprocessing token. @@ -7808,6 +8511,32 @@ enum CXCompletionChunkKind { final int value; const CXCompletionChunkKind(this.value); + + static CXCompletionChunkKind fromValue(int value) => switch (value) { + 0 => CXCompletionChunk_Optional, + 1 => CXCompletionChunk_TypedText, + 2 => CXCompletionChunk_Text, + 3 => CXCompletionChunk_Placeholder, + 4 => CXCompletionChunk_Informative, + 5 => CXCompletionChunk_CurrentParameter, + 6 => CXCompletionChunk_LeftParen, + 7 => CXCompletionChunk_RightParen, + 8 => CXCompletionChunk_LeftBracket, + 9 => CXCompletionChunk_RightBracket, + 10 => CXCompletionChunk_LeftBrace, + 11 => CXCompletionChunk_RightBrace, + 12 => CXCompletionChunk_LeftAngle, + 13 => CXCompletionChunk_RightAngle, + 14 => CXCompletionChunk_Comma, + 15 => CXCompletionChunk_ResultType, + 16 => CXCompletionChunk_Colon, + 17 => CXCompletionChunk_SemiColon, + 18 => CXCompletionChunk_Equal, + 19 => CXCompletionChunk_HorizontalSpace, + 20 => CXCompletionChunk_VerticalSpace, + _ => throw ArgumentError( + "Invalid value for CXCompletionChunkKind: $value"), + }; } /// Contains the results of code-completion. @@ -7845,6 +8574,16 @@ enum CXCodeComplete_Flags { final int value; const CXCodeComplete_Flags(this.value); + + static CXCodeComplete_Flags fromValue(int value) => switch (value) { + 1 => CXCodeComplete_IncludeMacros, + 2 => CXCodeComplete_IncludeCodePatterns, + 4 => CXCodeComplete_IncludeBriefComments, + 8 => CXCodeComplete_SkipPreamble, + 16 => CXCodeComplete_IncludeCompletionsWithFixIts, + _ => + throw ArgumentError("Invalid value for CXCodeComplete_Flags: $value"), + }; } /// Bits that represent the context under which completion is occurring. @@ -7941,6 +8680,36 @@ enum CXCompletionContext { final int value; const CXCompletionContext(this.value); + + static CXCompletionContext fromValue(int value) => switch (value) { + 0 => CXCompletionContext_Unexposed, + 1 => CXCompletionContext_AnyType, + 2 => CXCompletionContext_AnyValue, + 4 => CXCompletionContext_ObjCObjectValue, + 8 => CXCompletionContext_ObjCSelectorValue, + 16 => CXCompletionContext_CXXClassTypeValue, + 32 => CXCompletionContext_DotMemberAccess, + 64 => CXCompletionContext_ArrowMemberAccess, + 128 => CXCompletionContext_ObjCPropertyAccess, + 256 => CXCompletionContext_EnumTag, + 512 => CXCompletionContext_UnionTag, + 1024 => CXCompletionContext_StructTag, + 2048 => CXCompletionContext_ClassTag, + 4096 => CXCompletionContext_Namespace, + 8192 => CXCompletionContext_NestedNameSpecifier, + 16384 => CXCompletionContext_ObjCInterface, + 32768 => CXCompletionContext_ObjCProtocol, + 65536 => CXCompletionContext_ObjCCategory, + 131072 => CXCompletionContext_ObjCInstanceMessage, + 262144 => CXCompletionContext_ObjCClassMessage, + 524288 => CXCompletionContext_ObjCSelectorName, + 1048576 => CXCompletionContext_MacroName, + 2097152 => CXCompletionContext_NaturalLanguage, + 4194304 => CXCompletionContext_IncludedFile, + 8388607 => CXCompletionContext_Unknown, + _ => + throw ArgumentError("Invalid value for CXCompletionContext: $value"), + }; } /// Visitor invoked for each file in a translation unit (used with @@ -7969,6 +8738,17 @@ enum CXEvalResultKind { final int value; const CXEvalResultKind(this.value); + + static CXEvalResultKind fromValue(int value) => switch (value) { + 1 => CXEval_Int, + 2 => CXEval_Float, + 3 => CXEval_ObjCStrLiteral, + 4 => CXEval_StrLiteral, + 5 => CXEval_CFStr, + 6 => CXEval_Other, + 0 => CXEval_UnExposed, + _ => throw ArgumentError("Invalid value for CXEvalResultKind: $value"), + }; } /// Evaluation result of a cursor @@ -7984,6 +8764,12 @@ enum CXVisitorResult { final int value; const CXVisitorResult(this.value); + + static CXVisitorResult fromValue(int value) => switch (value) { + 0 => CXVisit_Break, + 1 => CXVisit_Continue, + _ => throw ArgumentError("Invalid value for CXVisitorResult: $value"), + }; } final class CXCursorAndRangeVisitor extends ffi.Struct { @@ -8007,6 +8793,13 @@ enum CXResult { final int value; const CXResult(this.value); + + static CXResult fromValue(int value) => switch (value) { + 0 => CXResult_Success, + 1 => CXResult_Invalid, + 2 => CXResult_VisitBreak, + _ => throw ArgumentError("Invalid value for CXResult: $value"), + }; } /// Source location passed to index callbacks. @@ -8088,6 +8881,37 @@ enum CXIdxEntityKind { final int value; const CXIdxEntityKind(this.value); + + static CXIdxEntityKind fromValue(int value) => switch (value) { + 0 => CXIdxEntity_Unexposed, + 1 => CXIdxEntity_Typedef, + 2 => CXIdxEntity_Function, + 3 => CXIdxEntity_Variable, + 4 => CXIdxEntity_Field, + 5 => CXIdxEntity_EnumConstant, + 6 => CXIdxEntity_ObjCClass, + 7 => CXIdxEntity_ObjCProtocol, + 8 => CXIdxEntity_ObjCCategory, + 9 => CXIdxEntity_ObjCInstanceMethod, + 10 => CXIdxEntity_ObjCClassMethod, + 11 => CXIdxEntity_ObjCProperty, + 12 => CXIdxEntity_ObjCIvar, + 13 => CXIdxEntity_Enum, + 14 => CXIdxEntity_Struct, + 15 => CXIdxEntity_Union, + 16 => CXIdxEntity_CXXClass, + 17 => CXIdxEntity_CXXNamespace, + 18 => CXIdxEntity_CXXNamespaceAlias, + 19 => CXIdxEntity_CXXStaticVariable, + 20 => CXIdxEntity_CXXStaticMethod, + 21 => CXIdxEntity_CXXInstanceMethod, + 22 => CXIdxEntity_CXXConstructor, + 23 => CXIdxEntity_CXXDestructor, + 24 => CXIdxEntity_CXXConversionFunction, + 25 => CXIdxEntity_CXXTypeAlias, + 26 => CXIdxEntity_CXXInterface, + _ => throw ArgumentError("Invalid value for CXIdxEntityKind: $value"), + }; } enum CXIdxEntityLanguage { @@ -8099,6 +8923,16 @@ enum CXIdxEntityLanguage { final int value; const CXIdxEntityLanguage(this.value); + + static CXIdxEntityLanguage fromValue(int value) => switch (value) { + 0 => CXIdxEntityLang_None, + 1 => CXIdxEntityLang_C, + 2 => CXIdxEntityLang_ObjC, + 3 => CXIdxEntityLang_CXX, + 4 => CXIdxEntityLang_Swift, + _ => + throw ArgumentError("Invalid value for CXIdxEntityLanguage: $value"), + }; } /// Extra C++ template information for an entity. This can apply to: @@ -8113,6 +8947,15 @@ enum CXIdxEntityCXXTemplateKind { final int value; const CXIdxEntityCXXTemplateKind(this.value); + + static CXIdxEntityCXXTemplateKind fromValue(int value) => switch (value) { + 0 => CXIdxEntity_NonTemplate, + 1 => CXIdxEntity_Template, + 2 => CXIdxEntity_TemplatePartialSpecialization, + 3 => CXIdxEntity_TemplateSpecialization, + _ => throw ArgumentError( + "Invalid value for CXIdxEntityCXXTemplateKind: $value"), + }; } enum CXIdxAttrKind { @@ -8123,6 +8966,14 @@ enum CXIdxAttrKind { final int value; const CXIdxAttrKind(this.value); + + static CXIdxAttrKind fromValue(int value) => switch (value) { + 0 => CXIdxAttr_Unexposed, + 1 => CXIdxAttr_IBAction, + 2 => CXIdxAttr_IBOutlet, + 3 => CXIdxAttr_IBOutletCollection, + _ => throw ArgumentError("Invalid value for CXIdxAttrKind: $value"), + }; } final class CXIdxAttrInfo extends ffi.Struct { @@ -8175,6 +9026,12 @@ enum CXIdxDeclInfoFlags { final int value; const CXIdxDeclInfoFlags(this.value); + + static CXIdxDeclInfoFlags fromValue(int value) => switch (value) { + 1 => CXIdxDeclFlag_Skipped, + _ => + throw ArgumentError("Invalid value for CXIdxDeclInfoFlags: $value"), + }; } final class CXIdxDeclInfo extends ffi.Struct { @@ -8222,6 +9079,14 @@ enum CXIdxObjCContainerKind { final int value; const CXIdxObjCContainerKind(this.value); + + static CXIdxObjCContainerKind fromValue(int value) => switch (value) { + 0 => CXIdxObjCContainer_ForwardRef, + 1 => CXIdxObjCContainer_Interface, + 2 => CXIdxObjCContainer_Implementation, + _ => throw ArgumentError( + "Invalid value for CXIdxObjCContainerKind: $value"), + }; } final class CXIdxObjCContainerDeclInfo extends ffi.Struct { @@ -8302,6 +9167,13 @@ enum CXIdxEntityRefKind { final int value; const CXIdxEntityRefKind(this.value); + + static CXIdxEntityRefKind fromValue(int value) => switch (value) { + 1 => CXIdxEntityRef_Direct, + 2 => CXIdxEntityRef_Implicit, + _ => + throw ArgumentError("Invalid value for CXIdxEntityRefKind: $value"), + }; } /// Roles that are attributed to symbol occurrences. @@ -8319,6 +9191,20 @@ enum CXSymbolRole { final int value; const CXSymbolRole(this.value); + + static CXSymbolRole fromValue(int value) => switch (value) { + 0 => CXSymbolRole_None, + 1 => CXSymbolRole_Declaration, + 2 => CXSymbolRole_Definition, + 4 => CXSymbolRole_Reference, + 8 => CXSymbolRole_Read, + 16 => CXSymbolRole_Write, + 32 => CXSymbolRole_Call, + 64 => CXSymbolRole_Dynamic, + 128 => CXSymbolRole_AddressOf, + 256 => CXSymbolRole_Implicit, + _ => throw ArgumentError("Invalid value for CXSymbolRole: $value"), + }; } /// Data for IndexerCallbacks#indexEntityReference. @@ -8446,6 +9332,16 @@ enum CXIndexOptFlags { final int value; const CXIndexOptFlags(this.value); + + static CXIndexOptFlags fromValue(int value) => switch (value) { + 0 => CXIndexOpt_None, + 1 => CXIndexOpt_SuppressRedundantRefs, + 2 => CXIndexOpt_IndexFunctionLocalSymbols, + 4 => CXIndexOpt_IndexImplicitTemplateInstantiations, + 8 => CXIndexOpt_SuppressWarnings, + 16 => CXIndexOpt_SkipParsedBodiesInSession, + _ => throw ArgumentError("Invalid value for CXIndexOptFlags: $value"), + }; } /// Visitor invoked for each field found by a traversal. @@ -8453,7 +9349,7 @@ typedef CXFieldVisitor = ffi.Pointer>; typedef CXFieldVisitorFunction = ffi.Int32 Function( CXCursor C, CXClientData client_data); -typedef DartCXFieldVisitorFunction = int Function( +typedef DartCXFieldVisitorFunction = CXVisitorResult Function( CXCursor C, CXClientData client_data); const int CINDEX_VERSION_MAJOR = 0; From 58f416f448a493fa26cd4387b80703e59cbbaca0 Mon Sep 17 00:00:00 2001 From: Levi Lesches Date: Mon, 10 Jun 2024 18:23:47 -0400 Subject: [PATCH 07/16] Reverted EnumClass.sameFfiDartAndCType --- pkgs/ffigen/lib/src/code_generator/enum_class.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/ffigen/lib/src/code_generator/enum_class.dart b/pkgs/ffigen/lib/src/code_generator/enum_class.dart index 28b3a63fdd..7d9a6a6249 100644 --- a/pkgs/ffigen/lib/src/code_generator/enum_class.dart +++ b/pkgs/ffigen/lib/src/code_generator/enum_class.dart @@ -250,7 +250,7 @@ class EnumClass extends BindingType { String getDartType(Writer w) => name; @override - bool get sameFfiDartAndCType => false; + bool get sameFfiDartAndCType => nativeType.sameFfiDartAndCType; @override bool get sameDartAndFfiDartType => false; From df7ba4eebe12ad3a3434298384ae9b446cd98e3b Mon Sep 17 00:00:00 2001 From: Levi Lesches Date: Fri, 14 Jun 2024 10:10:03 -0400 Subject: [PATCH 08/16] Updated Changelog --- pkgs/ffigen/CHANGELOG.md | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/pkgs/ffigen/CHANGELOG.md b/pkgs/ffigen/CHANGELOG.md index ce01154341..29cd32b09c 100644 --- a/pkgs/ffigen/CHANGELOG.md +++ b/pkgs/ffigen/CHANGELOG.md @@ -3,13 +3,11 @@ - __Breaking change__: Code-gen the ObjC `id` type to `ObjCObjectBase` rather than `NSObject`, since not all ObjC classes inherit from `NSObject`. Eg `NSProxy`. -- __Breaking change__: Enums are now generated as real Dart enums, instead of - abstract classes. Since Dart enums cannot be empty, empty native enums are - generated as empty sealed classes. Native enum members with duplicate integer - values are handled properly, and are equal to each other in Dart as well. -- __Breaking change__: ffigen now emits code that uses the Dart enums in return - types and argument types, allowing you to use them as normal Dart enums without - converting to and from their integer values. +- __Breaking change__: Native enums are now generated as real Dart enums, instead + of abstract classes with integer constants. Native enum members with the same + integer values are handled properly on the Dart side, and native functions + that use enums in their signatures now accept the generated enums on the Dart + side, instead of integer values. - Rename ObjC interface methods that clash with type names. Fixes https://github.com/dart-lang/native/issues/1007. - __Breaking change__: Enum integer types are implementation-defined and not From f32ed7ef47427891a0a5ef7488a07fd897b1f4fe Mon Sep 17 00:00:00 2001 From: Levi Lesches Date: Fri, 14 Jun 2024 10:21:21 -0400 Subject: [PATCH 09/16] Reverted to multiline string --- pkgs/ffigen/lib/src/code_generator/func.dart | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pkgs/ffigen/lib/src/code_generator/func.dart b/pkgs/ffigen/lib/src/code_generator/func.dart index b830cd1e8e..05d67d40c2 100644 --- a/pkgs/ffigen/lib/src/code_generator/func.dart +++ b/pkgs/ffigen/lib/src/code_generator/func.dart @@ -176,9 +176,12 @@ $dartReturnType $enclosingFuncName($dartArgDeclString) => $funcImplCall; final isLeafString = isLeaf ? 'isLeaf:true' : ''; // Write enclosing function. - s.write("$dartReturnType $enclosingFuncName($dartArgDeclString) {\n"); - s.write("return $funcImplCall;\n"); - s.write("}\n\n"); + s.write(''' +$dartReturnType $enclosingFuncName($dartArgDeclString) { + return $funcImplCall; +} + +'''); if (exposeSymbolAddress) { // Add to SymbolAddress in writer. From c180a162ae57ad8d9c3a200712a678c739decb6d Mon Sep 17 00:00:00 2001 From: Levi Lesches Date: Fri, 14 Jun 2024 10:29:09 -0400 Subject: [PATCH 10/16] Replaced 'Invalid value' for 'Unknown value' --- .../libclang-example/generated_bindings.dart | 48 +++++++------- .../shared_bindings/lib/generated/a_gen.dart | 2 +- .../lib/generated/a_shared_b_gen.dart | 2 +- .../lib/src/code_generator/enum_class.dart | 2 +- .../_expected_enumclass_bindings.dart | 2 +- ...xpected_enumclass_duplicates_bindings.dart | 2 +- .../_expected_forward_decl_bindings.dart | 2 +- .../_expected_typedef_bindings.dart | 2 +- .../_expected_libclang_bindings.dart | 64 +++++++++---------- 9 files changed, 63 insertions(+), 63 deletions(-) diff --git a/pkgs/ffigen/example/libclang-example/generated_bindings.dart b/pkgs/ffigen/example/libclang-example/generated_bindings.dart index 8c5c5e78a7..2c953c6d8f 100644 --- a/pkgs/ffigen/example/libclang-example/generated_bindings.dart +++ b/pkgs/ffigen/example/libclang-example/generated_bindings.dart @@ -7755,7 +7755,7 @@ enum CXGlobalOptFlags { 1 => CXGlobalOpt_ThreadBackgroundPriorityForIndexing, 2 => CXGlobalOpt_ThreadBackgroundPriorityForEditing, 3 => CXGlobalOpt_ThreadBackgroundPriorityForAll, - _ => throw ArgumentError("Invalid value for CXGlobalOptFlags: $value"), + _ => throw ArgumentError("Unknown value for CXGlobalOptFlags: $value"), }; } @@ -8003,7 +8003,7 @@ enum CXLoadDiag_Error { 1 => CXLoadDiag_Unknown, 2 => CXLoadDiag_CannotLoad, 3 => CXLoadDiag_InvalidFile, - _ => throw ArgumentError("Invalid value for CXLoadDiag_Error: $value"), + _ => throw ArgumentError("Unknown value for CXLoadDiag_Error: $value"), }; } @@ -8076,7 +8076,7 @@ enum CXDiagnosticSeverity { 3 => CXDiagnostic_Error, 4 => CXDiagnostic_Fatal, _ => - throw ArgumentError("Invalid value for CXDiagnosticSeverity: $value"), + throw ArgumentError("Unknown value for CXDiagnosticSeverity: $value"), }; } @@ -8181,7 +8181,7 @@ enum CXErrorCode { 2 => CXError_Crashed, 3 => CXError_InvalidArguments, 4 => CXError_ASTReadError, - _ => throw ArgumentError("Invalid value for CXErrorCode: $value"), + _ => throw ArgumentError("Unknown value for CXErrorCode: $value"), }; } @@ -9435,7 +9435,7 @@ enum CXCursorKind { 602 => CXCursor_StaticAssert, 603 => CXCursor_FriendDecl, 700 => CXCursor_OverloadCandidate, - _ => throw ArgumentError("Invalid value for CXCursorKind: $value"), + _ => throw ArgumentError("Unknown value for CXCursorKind: $value"), }; @override @@ -9556,7 +9556,7 @@ enum CXLinkageKind { 2 => CXLinkage_Internal, 3 => CXLinkage_UniqueExternal, 4 => CXLinkage_External, - _ => throw ArgumentError("Invalid value for CXLinkageKind: $value"), + _ => throw ArgumentError("Unknown value for CXLinkageKind: $value"), }; } @@ -9586,7 +9586,7 @@ enum CXVisibilityKind { 1 => CXVisibility_Hidden, 2 => CXVisibility_Protected, 3 => CXVisibility_Default, - _ => throw ArgumentError("Invalid value for CXVisibilityKind: $value"), + _ => throw ArgumentError("Unknown value for CXVisibilityKind: $value"), }; } @@ -9621,7 +9621,7 @@ enum CXAvailabilityKind { 2 => CXAvailability_NotAvailable, 3 => CXAvailability_NotAccessible, _ => - throw ArgumentError("Invalid value for CXAvailabilityKind: $value"), + throw ArgumentError("Unknown value for CXAvailabilityKind: $value"), }; } @@ -9694,7 +9694,7 @@ enum CXLanguageKind { 1 => CXLanguage_C, 2 => CXLanguage_ObjC, 3 => CXLanguage_CPlusPlus, - _ => throw ArgumentError("Invalid value for CXLanguageKind: $value"), + _ => throw ArgumentError("Unknown value for CXLanguageKind: $value"), }; } @@ -9716,7 +9716,7 @@ enum CXTLSKind { 0 => CXTLS_None, 1 => CXTLS_Dynamic, 2 => CXTLS_Static, - _ => throw ArgumentError("Invalid value for CXTLSKind: $value"), + _ => throw ArgumentError("Unknown value for CXTLSKind: $value"), }; } @@ -10021,7 +10021,7 @@ enum CXTypeKind { 174 => CXType_OCLIntelSubgroupAVCImeSingleRefStreamin, 175 => CXType_OCLIntelSubgroupAVCImeDualRefStreamin, 176 => CXType_ExtVector, - _ => throw ArgumentError("Invalid value for CXTypeKind: $value"), + _ => throw ArgumentError("Unknown value for CXTypeKind: $value"), }; @override @@ -10202,7 +10202,7 @@ enum CXCallingConv { 16 => CXCallingConv_AArch64VectorCall, 100 => CXCallingConv_Invalid, 200 => CXCallingConv_Unexposed, - _ => throw ArgumentError("Invalid value for CXCallingConv: $value"), + _ => throw ArgumentError("Unknown value for CXCallingConv: $value"), }; @override @@ -10340,7 +10340,7 @@ enum CXRefQualifierKind { 1 => CXRefQualifier_LValue, 2 => CXRefQualifier_RValue, _ => - throw ArgumentError("Invalid value for CXRefQualifierKind: $value"), + throw ArgumentError("Unknown value for CXRefQualifierKind: $value"), }; } @@ -10401,7 +10401,7 @@ enum CX_StorageClass { 5 => CX_SC_OpenCLWorkGroupLocal, 6 => CX_SC_Auto, 7 => CX_SC_Register, - _ => throw ArgumentError("Invalid value for CX_StorageClass: $value"), + _ => throw ArgumentError("Unknown value for CX_StorageClass: $value"), }; } @@ -10460,7 +10460,7 @@ enum CXChildVisitResult { 1 => CXChildVisit_Continue, 2 => CXChildVisit_Recurse, _ => - throw ArgumentError("Invalid value for CXChildVisitResult: $value"), + throw ArgumentError("Unknown value for CXChildVisitResult: $value"), }; } @@ -10783,7 +10783,7 @@ enum CXTokenKind { 2 => CXToken_Identifier, 3 => CXToken_Literal, 4 => CXToken_Comment, - _ => throw ArgumentError("Invalid value for CXTokenKind: $value"), + _ => throw ArgumentError("Unknown value for CXTokenKind: $value"), }; } @@ -11247,7 +11247,7 @@ enum CXEvalResultKind { 5 => CXEval_CFStr, 6 => CXEval_Other, 0 => CXEval_UnExposed, - _ => throw ArgumentError("Invalid value for CXEvalResultKind: $value"), + _ => throw ArgumentError("Unknown value for CXEvalResultKind: $value"), }; } @@ -11323,7 +11323,7 @@ enum CXVisitorResult { static CXVisitorResult fromValue(int value) => switch (value) { 0 => CXVisit_Break, 1 => CXVisit_Continue, - _ => throw ArgumentError("Invalid value for CXVisitorResult: $value"), + _ => throw ArgumentError("Unknown value for CXVisitorResult: $value"), }; } @@ -11345,7 +11345,7 @@ enum CXResult { 0 => CXResult_Success, 1 => CXResult_Invalid, 2 => CXResult_VisitBreak, - _ => throw ArgumentError("Invalid value for CXResult: $value"), + _ => throw ArgumentError("Unknown value for CXResult: $value"), }; } @@ -11430,7 +11430,7 @@ enum CXIdxAttrKind { 1 => CXIdxAttr_IBAction, 2 => CXIdxAttr_IBOutlet, 3 => CXIdxAttr_IBOutletCollection, - _ => throw ArgumentError("Invalid value for CXIdxAttrKind: $value"), + _ => throw ArgumentError("Unknown value for CXIdxAttrKind: $value"), }; } @@ -11516,7 +11516,7 @@ enum CXIdxEntityKind { 24 => CXIdxEntity_CXXConversionFunction, 25 => CXIdxEntity_CXXTypeAlias, 26 => CXIdxEntity_CXXInterface, - _ => throw ArgumentError("Invalid value for CXIdxEntityKind: $value"), + _ => throw ArgumentError("Unknown value for CXIdxEntityKind: $value"), }; } @@ -11564,7 +11564,7 @@ enum CXIdxEntityLanguage { 3 => CXIdxEntityLang_CXX, 4 => CXIdxEntityLang_Swift, _ => - throw ArgumentError("Invalid value for CXIdxEntityLanguage: $value"), + throw ArgumentError("Unknown value for CXIdxEntityLanguage: $value"), }; } @@ -11755,7 +11755,7 @@ enum CXIdxEntityRefKind { 1 => CXIdxEntityRef_Direct, 2 => CXIdxEntityRef_Implicit, _ => - throw ArgumentError("Invalid value for CXIdxEntityRefKind: $value"), + throw ArgumentError("Unknown value for CXIdxEntityRefKind: $value"), }; } @@ -11789,7 +11789,7 @@ enum CXSymbolRole { 64 => CXSymbolRole_Dynamic, 128 => CXSymbolRole_AddressOf, 256 => CXSymbolRole_Implicit, - _ => throw ArgumentError("Invalid value for CXSymbolRole: $value"), + _ => throw ArgumentError("Unknown value for CXSymbolRole: $value"), }; } diff --git a/pkgs/ffigen/example/shared_bindings/lib/generated/a_gen.dart b/pkgs/ffigen/example/shared_bindings/lib/generated/a_gen.dart index 40b50ba765..8f92d2216c 100644 --- a/pkgs/ffigen/example/shared_bindings/lib/generated/a_gen.dart +++ b/pkgs/ffigen/example/shared_bindings/lib/generated/a_gen.dart @@ -116,7 +116,7 @@ enum A_Enum { static A_Enum fromValue(int value) => switch (value) { 0 => A_ENUM_1, 1 => A_ENUM_2, - _ => throw ArgumentError("Invalid value for A_Enum: $value"), + _ => throw ArgumentError("Unknown value for A_Enum: $value"), }; } diff --git a/pkgs/ffigen/example/shared_bindings/lib/generated/a_shared_b_gen.dart b/pkgs/ffigen/example/shared_bindings/lib/generated/a_shared_b_gen.dart index 262713f943..c220cab4f3 100644 --- a/pkgs/ffigen/example/shared_bindings/lib/generated/a_shared_b_gen.dart +++ b/pkgs/ffigen/example/shared_bindings/lib/generated/a_shared_b_gen.dart @@ -71,7 +71,7 @@ enum A_Enum { static A_Enum fromValue(int value) => switch (value) { 0 => A_ENUM_1, 1 => A_ENUM_2, - _ => throw ArgumentError("Invalid value for A_Enum: $value"), + _ => throw ArgumentError("Unknown value for A_Enum: $value"), }; } diff --git a/pkgs/ffigen/lib/src/code_generator/enum_class.dart b/pkgs/ffigen/lib/src/code_generator/enum_class.dart index 6a46be9682..ed544c4045 100644 --- a/pkgs/ffigen/lib/src/code_generator/enum_class.dart +++ b/pkgs/ffigen/lib/src/code_generator/enum_class.dart @@ -204,7 +204,7 @@ class EnumClass extends BindingType { } s.write( '$depth${depth}_ => ' - 'throw ArgumentError("Invalid value for $name: \$value"),\n', + 'throw ArgumentError("Unknown value for $name: \$value"),\n', ); s.write("$depth};\n"); } diff --git a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_enumclass_bindings.dart b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_enumclass_bindings.dart index c9a459c13b..d294f60467 100644 --- a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_enumclass_bindings.dart +++ b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_enumclass_bindings.dart @@ -22,6 +22,6 @@ enum Constants { static Constants fromValue(int value) => switch (value) { 10 => a, -1 => b, - _ => throw ArgumentError("Invalid value for Constants: $value"), + _ => throw ArgumentError("Unknown value for Constants: $value"), }; } diff --git a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_enumclass_duplicates_bindings.dart b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_enumclass_duplicates_bindings.dart index 3d76be254b..8bb1376641 100644 --- a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_enumclass_duplicates_bindings.dart +++ b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_enumclass_duplicates_bindings.dart @@ -26,7 +26,7 @@ enum Duplicates { static Duplicates fromValue(int value) => switch (value) { 0 => a, 1 => b, - _ => throw ArgumentError("Invalid value for Duplicates: $value"), + _ => throw ArgumentError("Unknown value for Duplicates: $value"), }; @override diff --git a/pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_forward_decl_bindings.dart b/pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_forward_decl_bindings.dart index d261bcfe7b..63551d7fb0 100644 --- a/pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_forward_decl_bindings.dart +++ b/pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_forward_decl_bindings.dart @@ -54,6 +54,6 @@ enum B { static B fromValue(int value) => switch (value) { 0 => a, 1 => b, - _ => throw ArgumentError("Invalid value for B: $value"), + _ => throw ArgumentError("Unknown value for B: $value"), }; } diff --git a/pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_typedef_bindings.dart b/pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_typedef_bindings.dart index c74b399926..a40f0cc31a 100644 --- a/pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_typedef_bindings.dart +++ b/pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_typedef_bindings.dart @@ -127,7 +127,7 @@ enum _NamedEnumInTypedef { static _NamedEnumInTypedef fromValue(int value) => switch (value) { 0 => b, _ => - throw ArgumentError("Invalid value for _NamedEnumInTypedef: $value"), + throw ArgumentError("Unknown value for _NamedEnumInTypedef: $value"), }; } diff --git a/pkgs/ffigen/test/large_integration_tests/_expected_libclang_bindings.dart b/pkgs/ffigen/test/large_integration_tests/_expected_libclang_bindings.dart index 365a573cad..80eb0ac46c 100644 --- a/pkgs/ffigen/test/large_integration_tests/_expected_libclang_bindings.dart +++ b/pkgs/ffigen/test/large_integration_tests/_expected_libclang_bindings.dart @@ -6047,7 +6047,7 @@ enum CXErrorCode { 2 => CXError_Crashed, 3 => CXError_InvalidArguments, 4 => CXError_ASTReadError, - _ => throw ArgumentError("Invalid value for CXErrorCode: $value"), + _ => throw ArgumentError("Unknown value for CXErrorCode: $value"), }; } @@ -6121,7 +6121,7 @@ enum CXAvailabilityKind { 2 => CXAvailability_NotAvailable, 3 => CXAvailability_NotAccessible, _ => - throw ArgumentError("Invalid value for CXAvailabilityKind: $value"), + throw ArgumentError("Unknown value for CXAvailabilityKind: $value"), }; } @@ -6224,7 +6224,7 @@ enum CXGlobalOptFlags { 1 => CXGlobalOpt_ThreadBackgroundPriorityForIndexing, 2 => CXGlobalOpt_ThreadBackgroundPriorityForEditing, 3 => CXGlobalOpt_ThreadBackgroundPriorityForAll, - _ => throw ArgumentError("Invalid value for CXGlobalOptFlags: $value"), + _ => throw ArgumentError("Unknown value for CXGlobalOptFlags: $value"), }; } @@ -6301,7 +6301,7 @@ enum CXDiagnosticSeverity { 3 => CXDiagnostic_Error, 4 => CXDiagnostic_Fatal, _ => - throw ArgumentError("Invalid value for CXDiagnosticSeverity: $value"), + throw ArgumentError("Unknown value for CXDiagnosticSeverity: $value"), }; } @@ -6337,7 +6337,7 @@ enum CXLoadDiag_Error { 1 => CXLoadDiag_Unknown, 2 => CXLoadDiag_CannotLoad, 3 => CXLoadDiag_InvalidFile, - _ => throw ArgumentError("Invalid value for CXLoadDiag_Error: $value"), + _ => throw ArgumentError("Unknown value for CXLoadDiag_Error: $value"), }; } @@ -6508,7 +6508,7 @@ enum CXSaveError { 1 => CXSaveError_Unknown, 2 => CXSaveError_TranslationErrors, 3 => CXSaveError_InvalidTU, - _ => throw ArgumentError("Invalid value for CXSaveError: $value"), + _ => throw ArgumentError("Unknown value for CXSaveError: $value"), }; } @@ -6522,7 +6522,7 @@ enum CXReparse_Flags { static CXReparse_Flags fromValue(int value) => switch (value) { 0 => CXReparse_None, - _ => throw ArgumentError("Invalid value for CXReparse_Flags: $value"), + _ => throw ArgumentError("Unknown value for CXReparse_Flags: $value"), }; } @@ -7500,7 +7500,7 @@ enum CXCursorKind { 602 => CXCursor_StaticAssert, 603 => CXCursor_FriendDecl, 700 => CXCursor_OverloadCandidate, - _ => throw ArgumentError("Invalid value for CXCursorKind: $value"), + _ => throw ArgumentError("Unknown value for CXCursorKind: $value"), }; @override @@ -7587,7 +7587,7 @@ enum CXLinkageKind { 2 => CXLinkage_Internal, 3 => CXLinkage_UniqueExternal, 4 => CXLinkage_External, - _ => throw ArgumentError("Invalid value for CXLinkageKind: $value"), + _ => throw ArgumentError("Unknown value for CXLinkageKind: $value"), }; } @@ -7613,7 +7613,7 @@ enum CXVisibilityKind { 1 => CXVisibility_Hidden, 2 => CXVisibility_Protected, 3 => CXVisibility_Default, - _ => throw ArgumentError("Invalid value for CXVisibilityKind: $value"), + _ => throw ArgumentError("Unknown value for CXVisibilityKind: $value"), }; } @@ -7659,7 +7659,7 @@ enum CXLanguageKind { 1 => CXLanguage_C, 2 => CXLanguage_ObjC, 3 => CXLanguage_CPlusPlus, - _ => throw ArgumentError("Invalid value for CXLanguageKind: $value"), + _ => throw ArgumentError("Unknown value for CXLanguageKind: $value"), }; } @@ -7677,7 +7677,7 @@ enum CXTLSKind { 0 => CXTLS_None, 1 => CXTLS_Dynamic, 2 => CXTLS_Static, - _ => throw ArgumentError("Invalid value for CXTLSKind: $value"), + _ => throw ArgumentError("Unknown value for CXTLSKind: $value"), }; } @@ -7933,7 +7933,7 @@ enum CXTypeKind { 174 => CXType_OCLIntelSubgroupAVCImeSingleRefStreamin, 175 => CXType_OCLIntelSubgroupAVCImeDualRefStreamin, 176 => CXType_ExtVector, - _ => throw ArgumentError("Invalid value for CXTypeKind: $value"), + _ => throw ArgumentError("Unknown value for CXTypeKind: $value"), }; @override @@ -7993,7 +7993,7 @@ enum CXCallingConv { 16 => CXCallingConv_AArch64VectorCall, 100 => CXCallingConv_Invalid, 200 => CXCallingConv_Unexposed, - _ => throw ArgumentError("Invalid value for CXCallingConv: $value"), + _ => throw ArgumentError("Unknown value for CXCallingConv: $value"), }; @override @@ -8104,7 +8104,7 @@ enum CXTypeLayoutError { -4 => CXTypeLayoutError_NotConstantSize, -5 => CXTypeLayoutError_InvalidFieldName, -6 => CXTypeLayoutError_Undeduced, - _ => throw ArgumentError("Invalid value for CXTypeLayoutError: $value"), + _ => throw ArgumentError("Unknown value for CXTypeLayoutError: $value"), }; } @@ -8126,7 +8126,7 @@ enum CXRefQualifierKind { 1 => CXRefQualifier_LValue, 2 => CXRefQualifier_RValue, _ => - throw ArgumentError("Invalid value for CXRefQualifierKind: $value"), + throw ArgumentError("Unknown value for CXRefQualifierKind: $value"), }; } @@ -8175,7 +8175,7 @@ enum CX_StorageClass { 5 => CX_SC_OpenCLWorkGroupLocal, 6 => CX_SC_Auto, 7 => CX_SC_Register, - _ => throw ArgumentError("Invalid value for CX_StorageClass: $value"), + _ => throw ArgumentError("Unknown value for CX_StorageClass: $value"), }; } @@ -8201,7 +8201,7 @@ enum CXChildVisitResult { 1 => CXChildVisit_Continue, 2 => CXChildVisit_Recurse, _ => - throw ArgumentError("Invalid value for CXChildVisitResult: $value"), + throw ArgumentError("Unknown value for CXChildVisitResult: $value"), }; } @@ -8383,7 +8383,7 @@ enum CXNameRefFlags { 1 => CXNameRange_WantQualifier, 2 => CXNameRange_WantTemplateArgs, 4 => CXNameRange_WantSinglePiece, - _ => throw ArgumentError("Invalid value for CXNameRefFlags: $value"), + _ => throw ArgumentError("Unknown value for CXNameRefFlags: $value"), }; } @@ -8413,7 +8413,7 @@ enum CXTokenKind { 2 => CXToken_Identifier, 3 => CXToken_Literal, 4 => CXToken_Comment, - _ => throw ArgumentError("Invalid value for CXTokenKind: $value"), + _ => throw ArgumentError("Unknown value for CXTokenKind: $value"), }; } @@ -8584,7 +8584,7 @@ enum CXCodeComplete_Flags { 8 => CXCodeComplete_SkipPreamble, 16 => CXCodeComplete_IncludeCompletionsWithFixIts, _ => - throw ArgumentError("Invalid value for CXCodeComplete_Flags: $value"), + throw ArgumentError("Unknown value for CXCodeComplete_Flags: $value"), }; } @@ -8710,7 +8710,7 @@ enum CXCompletionContext { 4194304 => CXCompletionContext_IncludedFile, 8388607 => CXCompletionContext_Unknown, _ => - throw ArgumentError("Invalid value for CXCompletionContext: $value"), + throw ArgumentError("Unknown value for CXCompletionContext: $value"), }; } @@ -8749,7 +8749,7 @@ enum CXEvalResultKind { 5 => CXEval_CFStr, 6 => CXEval_Other, 0 => CXEval_UnExposed, - _ => throw ArgumentError("Invalid value for CXEvalResultKind: $value"), + _ => throw ArgumentError("Unknown value for CXEvalResultKind: $value"), }; } @@ -8770,7 +8770,7 @@ enum CXVisitorResult { static CXVisitorResult fromValue(int value) => switch (value) { 0 => CXVisit_Break, 1 => CXVisit_Continue, - _ => throw ArgumentError("Invalid value for CXVisitorResult: $value"), + _ => throw ArgumentError("Unknown value for CXVisitorResult: $value"), }; } @@ -8800,7 +8800,7 @@ enum CXResult { 0 => CXResult_Success, 1 => CXResult_Invalid, 2 => CXResult_VisitBreak, - _ => throw ArgumentError("Invalid value for CXResult: $value"), + _ => throw ArgumentError("Unknown value for CXResult: $value"), }; } @@ -8912,7 +8912,7 @@ enum CXIdxEntityKind { 24 => CXIdxEntity_CXXConversionFunction, 25 => CXIdxEntity_CXXTypeAlias, 26 => CXIdxEntity_CXXInterface, - _ => throw ArgumentError("Invalid value for CXIdxEntityKind: $value"), + _ => throw ArgumentError("Unknown value for CXIdxEntityKind: $value"), }; } @@ -8933,7 +8933,7 @@ enum CXIdxEntityLanguage { 3 => CXIdxEntityLang_CXX, 4 => CXIdxEntityLang_Swift, _ => - throw ArgumentError("Invalid value for CXIdxEntityLanguage: $value"), + throw ArgumentError("Unknown value for CXIdxEntityLanguage: $value"), }; } @@ -8974,7 +8974,7 @@ enum CXIdxAttrKind { 1 => CXIdxAttr_IBAction, 2 => CXIdxAttr_IBOutlet, 3 => CXIdxAttr_IBOutletCollection, - _ => throw ArgumentError("Invalid value for CXIdxAttrKind: $value"), + _ => throw ArgumentError("Unknown value for CXIdxAttrKind: $value"), }; } @@ -9032,7 +9032,7 @@ enum CXIdxDeclInfoFlags { static CXIdxDeclInfoFlags fromValue(int value) => switch (value) { 1 => CXIdxDeclFlag_Skipped, _ => - throw ArgumentError("Invalid value for CXIdxDeclInfoFlags: $value"), + throw ArgumentError("Unknown value for CXIdxDeclInfoFlags: $value"), }; } @@ -9174,7 +9174,7 @@ enum CXIdxEntityRefKind { 1 => CXIdxEntityRef_Direct, 2 => CXIdxEntityRef_Implicit, _ => - throw ArgumentError("Invalid value for CXIdxEntityRefKind: $value"), + throw ArgumentError("Unknown value for CXIdxEntityRefKind: $value"), }; } @@ -9205,7 +9205,7 @@ enum CXSymbolRole { 64 => CXSymbolRole_Dynamic, 128 => CXSymbolRole_AddressOf, 256 => CXSymbolRole_Implicit, - _ => throw ArgumentError("Invalid value for CXSymbolRole: $value"), + _ => throw ArgumentError("Unknown value for CXSymbolRole: $value"), }; } @@ -9342,7 +9342,7 @@ enum CXIndexOptFlags { 4 => CXIndexOpt_IndexImplicitTemplateInstantiations, 8 => CXIndexOpt_SuppressWarnings, 16 => CXIndexOpt_SkipParsedBodiesInSession, - _ => throw ArgumentError("Invalid value for CXIndexOptFlags: $value"), + _ => throw ArgumentError("Unknown value for CXIndexOptFlags: $value"), }; } From 5f44f6764c2acac54c59452ecafaa73fda214e80 Mon Sep 17 00:00:00 2001 From: Levi Lesches Date: Fri, 14 Jun 2024 10:36:33 -0400 Subject: [PATCH 11/16] Fixed enum mimic test --- .../_expected_enum_int_mimic_bindings.dart | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_enum_int_mimic_bindings.dart b/pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_enum_int_mimic_bindings.dart index 42a21fd68a..2f5c7b9bfc 100644 --- a/pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_enum_int_mimic_bindings.dart +++ b/pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_enum_int_mimic_bindings.dart @@ -9,6 +9,11 @@ enum Simple { final int value; const Simple(this.value); + + static Simple fromValue(int value) => switch (value) { + 0 => A0, + _ => throw ArgumentError("Unknown value for Simple: $value"), + }; } enum SimpleWithNegative { @@ -17,6 +22,13 @@ enum SimpleWithNegative { final int value; const SimpleWithNegative(this.value); + + static SimpleWithNegative fromValue(int value) => switch (value) { + 0 => B0, + -1000 => B1, + _ => + throw ArgumentError("Unknown value for SimpleWithNegative: $value"), + }; } enum PositiveIntOverflow { @@ -24,6 +36,12 @@ enum PositiveIntOverflow { final int value; const PositiveIntOverflow(this.value); + + static PositiveIntOverflow fromValue(int value) => switch (value) { + -2147483607 => C0, + _ => + throw ArgumentError("Unknown value for PositiveIntOverflow: $value"), + }; } enum ExplicitType { @@ -32,6 +50,12 @@ enum ExplicitType { final int value; const ExplicitType(this.value); + + static ExplicitType fromValue(int value) => switch (value) { + 0 => E0, + 1 => E1, + _ => throw ArgumentError("Unknown value for ExplicitType: $value"), + }; } enum ExplicitTypeWithOverflow { @@ -40,6 +64,13 @@ enum ExplicitTypeWithOverflow { final int value; const ExplicitTypeWithOverflow(this.value); + + static ExplicitTypeWithOverflow fromValue(int value) => switch (value) { + 0 => F0, + -32727 => F1, + _ => throw ArgumentError( + "Unknown value for ExplicitTypeWithOverflow: $value"), + }; } final class Test extends ffi.Struct { From 94c5badae8851e4115d2de5d346cb00318e6005a Mon Sep 17 00:00:00 2001 From: Levi Lesches Date: Fri, 14 Jun 2024 10:40:03 -0400 Subject: [PATCH 12/16] Fixed more tests --- .../libclang-example/generated_bindings.dart | 16 +++++------ .../_expected_typedef_bindings.dart | 2 +- .../_expected_libclang_bindings.dart | 28 +++++++++---------- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/pkgs/ffigen/example/libclang-example/generated_bindings.dart b/pkgs/ffigen/example/libclang-example/generated_bindings.dart index 2c953c6d8f..01add6dcfc 100644 --- a/pkgs/ffigen/example/libclang-example/generated_bindings.dart +++ b/pkgs/ffigen/example/libclang-example/generated_bindings.dart @@ -8317,7 +8317,7 @@ enum CXTUResourceUsageKind { 13 => CXTUResourceUsage_SourceManager_DataStructures, 14 => CXTUResourceUsage_Preprocessor_HeaderSearch, _ => throw ArgumentError( - "Invalid value for CXTUResourceUsageKind: $value"), + "Unknown value for CXTUResourceUsageKind: $value"), }; @override @@ -10099,7 +10099,7 @@ enum CXTemplateArgumentKind { 8 => CXTemplateArgumentKind_Pack, 9 => CXTemplateArgumentKind_Invalid, _ => throw ArgumentError( - "Invalid value for CXTemplateArgumentKind: $value"), + "Unknown value for CXTemplateArgumentKind: $value"), }; } @@ -10287,7 +10287,7 @@ enum CXTypeNullabilityKind { 2 => CXTypeNullability_Unspecified, 3 => CXTypeNullability_Invalid, _ => throw ArgumentError( - "Invalid value for CXTypeNullabilityKind: $value"), + "Unknown value for CXTypeNullabilityKind: $value"), }; } @@ -10369,7 +10369,7 @@ enum CX_CXXAccessSpecifier { 2 => CX_CXXProtected, 3 => CX_CXXPrivate, _ => throw ArgumentError( - "Invalid value for CX_CXXAccessSpecifier: $value"), + "Unknown value for CX_CXXAccessSpecifier: $value"), }; } @@ -10575,7 +10575,7 @@ enum CXPrintingPolicyProperty { 24 => CXPrintingPolicy_SuppressImplicitBase, 25 => CXPrintingPolicy_FullyQualifiedName, _ => throw ArgumentError( - "Invalid value for CXPrintingPolicyProperty: $value"), + "Unknown value for CXPrintingPolicyProperty: $value"), }; @override @@ -11057,7 +11057,7 @@ enum CXCompletionChunkKind { 19 => CXCompletionChunk_HorizontalSpace, 20 => CXCompletionChunk_VerticalSpace, _ => throw ArgumentError( - "Invalid value for CXCompletionChunkKind: $value"), + "Unknown value for CXCompletionChunkKind: $value"), }; } @@ -11543,7 +11543,7 @@ enum CXIdxEntityCXXTemplateKind { 2 => CXIdxEntity_TemplatePartialSpecialization, 3 => CXIdxEntity_TemplateSpecialization, _ => throw ArgumentError( - "Invalid value for CXIdxEntityCXXTemplateKind: $value"), + "Unknown value for CXIdxEntityCXXTemplateKind: $value"), }; } @@ -11640,7 +11640,7 @@ enum CXIdxObjCContainerKind { 1 => CXIdxObjCContainer_Interface, 2 => CXIdxObjCContainer_Implementation, _ => throw ArgumentError( - "Invalid value for CXIdxObjCContainerKind: $value"), + "Unknown value for CXIdxObjCContainerKind: $value"), }; } diff --git a/pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_typedef_bindings.dart b/pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_typedef_bindings.dart index a40f0cc31a..d5da7f3ebf 100644 --- a/pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_typedef_bindings.dart +++ b/pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_typedef_bindings.dart @@ -114,7 +114,7 @@ enum AnonymousEnumInTypedef { static AnonymousEnumInTypedef fromValue(int value) => switch (value) { 0 => a, _ => throw ArgumentError( - "Invalid value for AnonymousEnumInTypedef: $value"), + "Unknown value for AnonymousEnumInTypedef: $value"), }; } diff --git a/pkgs/ffigen/test/large_integration_tests/_expected_libclang_bindings.dart b/pkgs/ffigen/test/large_integration_tests/_expected_libclang_bindings.dart index 80eb0ac46c..9a7d6cf685 100644 --- a/pkgs/ffigen/test/large_integration_tests/_expected_libclang_bindings.dart +++ b/pkgs/ffigen/test/large_integration_tests/_expected_libclang_bindings.dart @@ -6192,7 +6192,7 @@ enum CXCursor_ExceptionSpecificationKind { 8 => CXCursor_ExceptionSpecificationKind_Unparsed, 9 => CXCursor_ExceptionSpecificationKind_NoThrow, _ => throw ArgumentError( - "Invalid value for CXCursor_ExceptionSpecificationKind: $value"), + "Unknown value for CXCursor_ExceptionSpecificationKind: $value"), }; } @@ -6374,7 +6374,7 @@ enum CXDiagnosticDisplayOptions { 16 => CXDiagnostic_DisplayCategoryId, 32 => CXDiagnostic_DisplayCategoryName, _ => throw ArgumentError( - "Invalid value for CXDiagnosticDisplayOptions: $value"), + "Unknown value for CXDiagnosticDisplayOptions: $value"), }; } @@ -6463,7 +6463,7 @@ enum CXTranslationUnit_Flags { 16384 => CXTranslationUnit_IgnoreNonErrorsFromIncludedFiles, 32768 => CXTranslationUnit_RetainExcludedConditionalBlocks, _ => throw ArgumentError( - "Invalid value for CXTranslationUnit_Flags: $value"), + "Unknown value for CXTranslationUnit_Flags: $value"), }; } @@ -6478,7 +6478,7 @@ enum CXSaveTranslationUnit_Flags { static CXSaveTranslationUnit_Flags fromValue(int value) => switch (value) { 0 => CXSaveTranslationUnit_None, _ => throw ArgumentError( - "Invalid value for CXSaveTranslationUnit_Flags: $value"), + "Unknown value for CXSaveTranslationUnit_Flags: $value"), }; } @@ -6569,7 +6569,7 @@ enum CXTUResourceUsageKind { 13 => CXTUResourceUsage_SourceManager_DataStructures, 14 => CXTUResourceUsage_Preprocessor_HeaderSearch, _ => throw ArgumentError( - "Invalid value for CXTUResourceUsageKind: $value"), + "Unknown value for CXTUResourceUsageKind: $value"), }; @override @@ -8041,7 +8041,7 @@ enum CXTemplateArgumentKind { 8 => CXTemplateArgumentKind_Pack, 9 => CXTemplateArgumentKind_Invalid, _ => throw ArgumentError( - "Invalid value for CXTemplateArgumentKind: $value"), + "Unknown value for CXTemplateArgumentKind: $value"), }; } @@ -8069,7 +8069,7 @@ enum CXTypeNullabilityKind { 2 => CXTypeNullability_Unspecified, 3 => CXTypeNullability_Invalid, _ => throw ArgumentError( - "Invalid value for CXTypeNullabilityKind: $value"), + "Unknown value for CXTypeNullabilityKind: $value"), }; } @@ -8147,7 +8147,7 @@ enum CX_CXXAccessSpecifier { 2 => CX_CXXProtected, 3 => CX_CXXPrivate, _ => throw ArgumentError( - "Invalid value for CX_CXXAccessSpecifier: $value"), + "Unknown value for CX_CXXAccessSpecifier: $value"), }; } @@ -8280,7 +8280,7 @@ enum CXPrintingPolicyProperty { 24 => CXPrintingPolicy_SuppressImplicitBase, 25 => CXPrintingPolicy_FullyQualifiedName, _ => throw ArgumentError( - "Invalid value for CXPrintingPolicyProperty: $value"), + "Unknown value for CXPrintingPolicyProperty: $value"), }; @override @@ -8331,7 +8331,7 @@ enum CXObjCPropertyAttrKind { 2048 => CXObjCPropertyAttr_unsafe_unretained, 4096 => CXObjCPropertyAttr_class, _ => throw ArgumentError( - "Invalid value for CXObjCPropertyAttrKind: $value"), + "Unknown value for CXObjCPropertyAttrKind: $value"), }; } @@ -8358,7 +8358,7 @@ enum CXObjCDeclQualifierKind { 16 => CXObjCDeclQualifier_Byref, 32 => CXObjCDeclQualifier_Oneway, _ => throw ArgumentError( - "Invalid value for CXObjCDeclQualifierKind: $value"), + "Unknown value for CXObjCDeclQualifierKind: $value"), }; } @@ -8537,7 +8537,7 @@ enum CXCompletionChunkKind { 19 => CXCompletionChunk_HorizontalSpace, 20 => CXCompletionChunk_VerticalSpace, _ => throw ArgumentError( - "Invalid value for CXCompletionChunkKind: $value"), + "Unknown value for CXCompletionChunkKind: $value"), }; } @@ -8956,7 +8956,7 @@ enum CXIdxEntityCXXTemplateKind { 2 => CXIdxEntity_TemplatePartialSpecialization, 3 => CXIdxEntity_TemplateSpecialization, _ => throw ArgumentError( - "Invalid value for CXIdxEntityCXXTemplateKind: $value"), + "Unknown value for CXIdxEntityCXXTemplateKind: $value"), }; } @@ -9087,7 +9087,7 @@ enum CXIdxObjCContainerKind { 1 => CXIdxObjCContainer_Interface, 2 => CXIdxObjCContainer_Implementation, _ => throw ArgumentError( - "Invalid value for CXIdxObjCContainerKind: $value"), + "Unknown value for CXIdxObjCContainerKind: $value"), }; } From 71b073889bdb063d4ff7f247647aee744d21808a Mon Sep 17 00:00:00 2001 From: Levi Lesches Date: Fri, 14 Jun 2024 10:54:17 -0400 Subject: [PATCH 13/16] Replaced ObjCInterface._needsConvertings with sameDartAndFfiDartType --- .../lib/src/code_generator/objc_interface.dart | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/pkgs/ffigen/lib/src/code_generator/objc_interface.dart b/pkgs/ffigen/lib/src/code_generator/objc_interface.dart index 6293493ce1..4d99f1aeb0 100644 --- a/pkgs/ffigen/lib/src/code_generator/objc_interface.dart +++ b/pkgs/ffigen/lib/src/code_generator/objc_interface.dart @@ -190,8 +190,8 @@ class $name extends ${superType?.getDartType(w) ?? wrapObjType} { s.write(' {\n'); // Implementation. - final convertReturn = m.kind != ObjCMethodKind.propertySetter && - _needsConverting(returnType); + final convertReturn = + m.kind != ObjCMethodKind.propertySetter && sameDartAndFfiDartType; if (returnType != voidType) { s.write(' ${convertReturn ? 'final _ret = ' : 'return '}'); @@ -394,17 +394,6 @@ class $name extends ${superType?.getDartType(w) ?? wrapObjType} { return '$className.castFromPointer($value, $ownershipFlags)'; } - // Utils for converting between the internal types passed to native code, and - // the external types visible to the user. For example, ObjCInterfaces are - // passed to native as Pointer, but the user sees the Dart wrapper - // class. These methods need to be kept in sync. - bool _needsConverting(Type type) => - type is ObjCInstanceType || - type.typealiasType is ObjCInterface || - type.typealiasType is ObjCBlock || - type.typealiasType is ObjCObjectPointer || - type.typealiasType is ObjCNullable; - String _getConvertedType(Type type, Writer w, String enclosingClass) { if (type is ObjCInstanceType) return enclosingClass; final baseType = type.typealiasType; From 11c3ddd4d8b4fbcd08feeaa95f5ae550bfa221e8 Mon Sep 17 00:00:00 2001 From: Levi Lesches Date: Fri, 14 Jun 2024 11:01:07 -0400 Subject: [PATCH 14/16] Negated sameDartAndFfiDartType condition for ObjC --- pkgs/ffigen/lib/src/code_generator/objc_interface.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/ffigen/lib/src/code_generator/objc_interface.dart b/pkgs/ffigen/lib/src/code_generator/objc_interface.dart index 4d99f1aeb0..3ac1ae1558 100644 --- a/pkgs/ffigen/lib/src/code_generator/objc_interface.dart +++ b/pkgs/ffigen/lib/src/code_generator/objc_interface.dart @@ -191,7 +191,7 @@ class $name extends ${superType?.getDartType(w) ?? wrapObjType} { // Implementation. final convertReturn = - m.kind != ObjCMethodKind.propertySetter && sameDartAndFfiDartType; + m.kind != ObjCMethodKind.propertySetter && !sameDartAndFfiDartType; if (returnType != voidType) { s.write(' ${convertReturn ? 'final _ret = ' : 'return '}'); From ce57dafc70c58024000098b4fb877c4e98c439ec Mon Sep 17 00:00:00 2001 From: Levi Lesches Date: Fri, 14 Jun 2024 11:14:56 -0400 Subject: [PATCH 15/16] Use return type for ObjC check --- pkgs/ffigen/lib/src/code_generator/objc_interface.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/ffigen/lib/src/code_generator/objc_interface.dart b/pkgs/ffigen/lib/src/code_generator/objc_interface.dart index 3ac1ae1558..f6c2e31eea 100644 --- a/pkgs/ffigen/lib/src/code_generator/objc_interface.dart +++ b/pkgs/ffigen/lib/src/code_generator/objc_interface.dart @@ -191,7 +191,7 @@ class $name extends ${superType?.getDartType(w) ?? wrapObjType} { // Implementation. final convertReturn = - m.kind != ObjCMethodKind.propertySetter && !sameDartAndFfiDartType; + m.kind != ObjCMethodKind.propertySetter && !returnType.sameDartAndFfiDartType; if (returnType != voidType) { s.write(' ${convertReturn ? 'final _ret = ' : 'return '}'); From e78f5cfe7da0f5d99d1c766553e1d690b1d7a3de Mon Sep 17 00:00:00 2001 From: Levi Lesches Date: Fri, 14 Jun 2024 11:25:40 -0400 Subject: [PATCH 16/16] Formatting --- pkgs/ffigen/lib/src/code_generator/objc_interface.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/ffigen/lib/src/code_generator/objc_interface.dart b/pkgs/ffigen/lib/src/code_generator/objc_interface.dart index f6c2e31eea..cabf9ccaf4 100644 --- a/pkgs/ffigen/lib/src/code_generator/objc_interface.dart +++ b/pkgs/ffigen/lib/src/code_generator/objc_interface.dart @@ -190,8 +190,8 @@ class $name extends ${superType?.getDartType(w) ?? wrapObjType} { s.write(' {\n'); // Implementation. - final convertReturn = - m.kind != ObjCMethodKind.propertySetter && !returnType.sameDartAndFfiDartType; + final convertReturn = m.kind != ObjCMethodKind.propertySetter && + !returnType.sameDartAndFfiDartType; if (returnType != voidType) { s.write(' ${convertReturn ? 'final _ret = ' : 'return '}');