diff --git a/pkgs/ffigen/lib/src/code_generator/library.dart b/pkgs/ffigen/lib/src/code_generator/library.dart index f9e314235..ce89e9274 100644 --- a/pkgs/ffigen/lib/src/code_generator/library.dart +++ b/pkgs/ffigen/lib/src/code_generator/library.dart @@ -8,7 +8,7 @@ import 'package:yaml_edit/yaml_edit.dart'; import '../code_generator.dart'; import '../code_generator/utils.dart'; -import '../config_provider/config_types.dart'; +import '../config_provider/config.dart'; import '../context.dart'; import 'writer.dart'; @@ -27,15 +27,19 @@ class Library { required List bindings, required Context context, }) => Library( - description: context.config.wrapperDocComment, + description: switch (context.config.output.style) { + final DynamicLibraryBindings e => e.wrapperDocComment, + _ => null, + }, bindings: bindings, - header: context.config.preamble, + header: context.config.output.preamble, generateForPackageObjectiveC: // ignore: deprecated_member_use_from_same_package context.config.objectiveC?.generateForPackageObjectiveC ?? false, - libraryImports: context.config.libraryImports.values.toList(), + // ignore: deprecated_member_use_from_same_package + libraryImports: context.config.libraryImports, silenceEnumWarning: context.config.enums.silenceWarning, - nativeEntryPoints: context.config.entryPoints + nativeEntryPoints: context.config.headers.entryPoints .map((uri) => uri.toFilePath()) .toList(), context: context, @@ -54,13 +58,18 @@ class Library { // Seperate bindings which require lookup. final lookupBindings = []; final nativeBindings = []; - FfiNativeConfig? nativeConfig; + String? nativeAssetId; + + final outputStyle = context.config.output.style; + final outputStyleAssetId = outputStyle is NativeExternalBindings + ? outputStyle.assetId + : null; for (final binding in bindings.whereType()) { final loadFromNativeAsset = binding.loadFromNativeAsset; // At the moment, all bindings share their native config. - if (loadFromNativeAsset) nativeConfig = context.config.ffiNativeConfig; + if (loadFromNativeAsset) nativeAssetId = outputStyleAssetId; (loadFromNativeAsset ? nativeBindings : lookupBindings).add(binding); } @@ -69,7 +78,7 @@ class Library { final writer = Writer( lookUpBindings: lookupBindings, ffiNativeBindings: nativeBindings, - nativeAssetId: nativeConfig?.assetId, + nativeAssetId: nativeAssetId, noLookUpBindings: noLookUpBindings, classDocComment: description, header: header, diff --git a/pkgs/ffigen/lib/src/code_generator/objc_built_in_functions.dart b/pkgs/ffigen/lib/src/code_generator/objc_built_in_functions.dart index 2b0d7f724..9b63a89f2 100644 --- a/pkgs/ffigen/lib/src/code_generator/objc_built_in_functions.dart +++ b/pkgs/ffigen/lib/src/code_generator/objc_built_in_functions.dart @@ -220,9 +220,9 @@ class ObjCBuiltInFunctions { // a hash of parts of the config. static String _libraryIdFromConfigHash(Config config) => fnvHash32( [ - ...config.entryPoints, - config.output, - config.outputObjC, + ...config.headers.entryPoints, + config.output.dartFile, + config.output.objCFile, ].map((uri) => path.basename(uri.toFilePath())).join('\n'), ).toRadixString(36); } diff --git a/pkgs/ffigen/lib/src/config_provider/config.dart b/pkgs/ffigen/lib/src/config_provider/config.dart index 9cc8e564d..138f0280d 100644 --- a/pkgs/ffigen/lib/src/config_provider/config.dart +++ b/pkgs/ffigen/lib/src/config_provider/config.dart @@ -647,8 +647,7 @@ final class Output { /// The output Objective-C file for the generated Objective-C bindings. final Uri? objectiveCFile; - Uri get _objectiveCFile => - objectiveCFile ?? Uri.file('${dartFile.toFilePath()}.m'); + Uri get objCFile => objectiveCFile ?? Uri.file('${dartFile.toFilePath()}.m'); /// The config for the symbol file. final SymbolFile? symbolFile; @@ -717,74 +716,8 @@ final class DynamicLibraryBindings implements BindingStyle { } extension type Config(FfiGenerator ffiGen) implements FfiGenerator { - ObjectiveC get _objectiveC => ffiGen.objectiveC ?? const ObjectiveC(); - bool get includeTransitiveObjCInterfaces => - _objectiveC.interfaces.includeTransitive; - bool get includeTransitiveObjCProtocols => - _objectiveC.protocols.includeTransitive; - bool get includeTransitiveObjCCategories => - _objectiveC.categories.includeTransitive; - String? Function(Declaration declaration) get interfaceModule => - (declaration) => _objectiveC.interfaces.module(declaration); - String? Function(Declaration declaration) get protocolModule => - (declaration) => _objectiveC.protocols.module(declaration); - bool get generateForPackageObjectiveC => - // ignore: deprecated_member_use_from_same_package - _objectiveC.generateForPackageObjectiveC; - Categories get objcCategories => _objectiveC.categories; - Interfaces get objcInterfaces => _objectiveC.interfaces; - Protocols get objcProtocols => _objectiveC.protocols; - ExternalVersions get externalVersions => _objectiveC.externalVersions; // ignore: deprecated_member_use_from_same_package Map get importedTypesByUsr => ffiGen.importedTypesByUsr; - String get wrapperName => - (ffiGen.output.style as DynamicLibraryBindings).wrapperName; - - String? get wrapperDocComment => switch (ffiGen.output.style) { - final DynamicLibraryBindings e => e.wrapperDocComment, - _ => null, - }; - - FfiNativeConfig get ffiNativeConfig => FfiNativeConfig( - enabled: ffiGen.output.style is NativeExternalBindings, - assetId: switch (ffiGen.output.style) { - final NativeExternalBindings e => e.assetId, - _ => null, - }, - ); - - bool shouldIncludeHeader(Uri header) => ffiGen.headers.include(header); - - bool get ignoreSourceErrors => ffiGen.headers.ignoreSourceErrors; - - List? get compilerOpts => ffiGen.headers.compilerOptions; - - List get entryPoints => ffiGen.headers.entryPoints; - - Uri get output => ffiGen.output.dartFile; - - Uri get outputObjC => ffiGen.output._objectiveCFile; - - BindingStyle get outputStyle => ffiGen.output.style; - - SymbolFile? get symbolFile => ffiGen.output.symbolFile; - - bool get sort => ffiGen.output.sort; - - CommentType get commentType => ffiGen.output.commentType; - - String? get preamble => ffiGen.output.preamble; - - bool get formatOutput => ffiGen.output.format; - - // Override declarative user spec with what FFIgen internals expect. - Map get libraryImports => - Map.fromEntries( - // ignore: deprecated_member_use_from_same_package - ffiGen.libraryImports.map( - (import) => MapEntry(import.name, import), - ), - ); // Override declarative user spec with what FFIgen internals expect. Map get typedefTypeMappings => @@ -820,6 +753,4 @@ extension type Config(FfiGenerator ffiGen) implements FfiGenerator { (import) => MapEntry(import.nativeType, import), ), ); - - Language get language => objectiveC != null ? Language.objc : Language.c; } diff --git a/pkgs/ffigen/lib/src/context.dart b/pkgs/ffigen/lib/src/context.dart index 22d996f82..4b2eae002 100644 --- a/pkgs/ffigen/lib/src/context.dart +++ b/pkgs/ffigen/lib/src/context.dart @@ -26,7 +26,8 @@ class Context { bool hasSourceErrors = false; final reportedCommentRanges = <((String, int), (String, int))>{}; final libs = LibraryImports(); - late final compilerOpts = config.compilerOpts ?? defaultCompilerOpts(logger); + late final compilerOpts = + config.headers.compilerOptions ?? defaultCompilerOpts(logger); final Scope rootScope = Scope.createRoot('root'); final Scope rootObjCScope = Scope.createRoot('objc_root'); late final ExtraSymbols extraSymbols; diff --git a/pkgs/ffigen/lib/src/ffigen.dart b/pkgs/ffigen/lib/src/ffigen.dart index e2243d9e6..a637352e6 100644 --- a/pkgs/ffigen/lib/src/ffigen.dart +++ b/pkgs/ffigen/lib/src/ffigen.dart @@ -28,13 +28,13 @@ extension FfiGenGenerator on FfiGenerator { final library = parse(context); // Generate files for the parsed bindings. - final gen = File(config.output.toFilePath()); - library.generateFile(gen, format: config.formatOutput); + final gen = File(config.output.dartFile.toFilePath()); + library.generateFile(gen, format: config.ffiGen.output.format); logger.info( _successPen('Finished, Bindings generated in ${gen.absolute.path}'), ); - final objCGen = File(config.outputObjC.toFilePath()); + final objCGen = File(config.output.objCFile.toFilePath()); if (library.generateObjCFile(objCGen)) { logger.info( _successPen( @@ -44,11 +44,12 @@ extension FfiGenGenerator on FfiGenerator { ); } - if (config.symbolFile != null) { - final symbolFileGen = File(config.symbolFile!.output.toFilePath()); + final symbolFile = config.output.symbolFile; + if (symbolFile != null) { + final symbolFileGen = File(symbolFile.output.toFilePath()); library.generateSymbolOutputFile( symbolFileGen, - config.symbolFile!.importPath.toString(), + symbolFile.importPath.toString(), ); logger.info( _successPen( diff --git a/pkgs/ffigen/lib/src/header_parser/parser.dart b/pkgs/ffigen/lib/src/header_parser/parser.dart index 29c485094..f04c3d01a 100644 --- a/pkgs/ffigen/lib/src/header_parser/parser.dart +++ b/pkgs/ffigen/lib/src/header_parser/parser.dart @@ -50,12 +50,12 @@ List parseToBindings(Context context) { Pointer> clangCmdArgs = nullptr; final compilerOpts = [ // Add compiler opt for comment parsing for clang based on config. - if (config.commentType.length != CommentLength.none && - config.commentType.style == CommentStyle.any) + if (config.output.commentType.length != CommentLength.none && + config.output.commentType.style == CommentStyle.any) strings.fparseAllComments, // If the config targets Objective C, add a compiler opt for it. - if (config.language == Language.objc) ...[ + if (config.objectiveC != null) ...[ ...strings.clangLangObjC, ..._findObjectiveCSysroot(), ], @@ -72,12 +72,12 @@ List parseToBindings(Context context) { final bindings = {}; // Log all headers for user. - context.logger.info('Input Headers: ${config.entryPoints}'); + context.logger.info('Input Headers: ${config.headers.entryPoints}'); final tuList = >[]; // Parse all translation units from entry points. - for (final headerLocationUri in config.entryPoints) { + for (final headerLocationUri in config.headers.entryPoints) { final headerLocation = headerLocationUri.toFilePath(); context.logger.fine('Creating TranslationUnit for header: $headerLocation'); @@ -114,11 +114,11 @@ List parseToBindings(Context context) { 'The compiler found warnings/errors in source files.', ); context.logger.warning('This will likely generate invalid bindings.'); - if (config.ignoreSourceErrors) { + if (config.headers.ignoreSourceErrors) { context.logger.warning( 'Ignored source errors. (User supplied --ignore-source-errors)', ); - } else if (config.language == Language.objc) { + } else if (config.objectiveC != null) { context.logger.warning('Ignored source errors. (ObjC)'); } else { context.logger.severe( @@ -219,7 +219,7 @@ List transformBindings(List bindings, Context context) { /// Sort bindings. var finalBindingsList = finalBindings.toList(); - if (config.sort) { + if (config.output.sort) { finalBindingsList = visit( context, SorterVisitation(finalBindings, SorterVisitation.nameSortKey), @@ -283,7 +283,7 @@ void _nameAllSymbols(Context context, Set bindings) { } ExtraSymbols _createExtraSymbols(Context context) { - final bindingStyle = context.config.outputStyle; + final bindingStyle = context.config.output.style; Symbol? wrapperClassName; Symbol? lookupFuncName; if (bindingStyle is DynamicLibraryBindings) { diff --git a/pkgs/ffigen/lib/src/header_parser/sub_parsers/api_availability.dart b/pkgs/ffigen/lib/src/header_parser/sub_parsers/api_availability.dart index eb5e3a2b5..a5cdde0d7 100644 --- a/pkgs/ffigen/lib/src/header_parser/sub_parsers/api_availability.dart +++ b/pkgs/ffigen/lib/src/header_parser/sub_parsers/api_availability.dart @@ -27,7 +27,7 @@ class ApiAvailability { this.alwaysUnavailable = false, this.ios, this.macos, - required ExternalVersions externalVersions, + required ExternalVersions? externalVersions, }) { availability = _getAvailability(externalVersions); } @@ -88,7 +88,7 @@ class ApiAvailability { alwaysUnavailable: alwaysUnavailable.value != 0, ios: ios, macos: macos, - externalVersions: context.config.externalVersions, + externalVersions: context.config.objectiveC?.externalVersions, ); for (var i = 0; i < platformsLength; ++i) { @@ -101,9 +101,9 @@ class ApiAvailability { return api; } - Availability _getAvailability(ExternalVersions externalVersions) { - final macosVer = _normalizeVersions(externalVersions.macos); - final iosVer = _normalizeVersions(externalVersions.ios); + Availability _getAvailability(ExternalVersions? externalVersions) { + final macosVer = _normalizeVersions(externalVersions?.macos); + final iosVer = _normalizeVersions(externalVersions?.ios); // If no versions are specified, everything is available. if (iosVer == null && macosVer == null) { diff --git a/pkgs/ffigen/lib/src/header_parser/sub_parsers/functiondecl_parser.dart b/pkgs/ffigen/lib/src/header_parser/sub_parsers/functiondecl_parser.dart index 31ab4da42..71f0a23b3 100644 --- a/pkgs/ffigen/lib/src/header_parser/sub_parsers/functiondecl_parser.dart +++ b/pkgs/ffigen/lib/src/header_parser/sub_parsers/functiondecl_parser.dart @@ -3,6 +3,7 @@ // BSD-style license that can be found in the LICENSE file. import '../../code_generator.dart'; +import '../../config_provider/config.dart'; import '../../config_provider/config_types.dart'; import '../../context.dart'; import '../clang_bindings/clang_bindings.dart' as clang_types; @@ -151,7 +152,7 @@ List parseFunctionDeclaration( exposeFunctionTypedefs: config.functions.includeTypedef(decl), isLeaf: config.functions.isLeaf(decl), objCReturnsRetained: objCReturnsRetained, - loadFromNativeAsset: config.ffiNativeConfig.enabled, + loadFromNativeAsset: config.output.style is NativeExternalBindings, ), ); } diff --git a/pkgs/ffigen/lib/src/header_parser/sub_parsers/macro_parser.dart b/pkgs/ffigen/lib/src/header_parser/sub_parsers/macro_parser.dart index cf9583c24..5898b73ce 100644 --- a/pkgs/ffigen/lib/src/header_parser/sub_parsers/macro_parser.dart +++ b/pkgs/ffigen/lib/src/header_parser/sub_parsers/macro_parser.dart @@ -198,7 +198,7 @@ File createFileForMacros(Context context) { // Write file contents. final sb = StringBuffer(); - for (final h in context.config.entryPoints) { + for (final h in context.config.headers.entryPoints) { final fullHeaderPath = File(h.toFilePath()).absolute.path; sb.writeln('#include "$fullHeaderPath"'); } diff --git a/pkgs/ffigen/lib/src/header_parser/sub_parsers/objccategorydecl_parser.dart b/pkgs/ffigen/lib/src/header_parser/sub_parsers/objccategorydecl_parser.dart index a50204dca..73bfec155 100644 --- a/pkgs/ffigen/lib/src/header_parser/sub_parsers/objccategorydecl_parser.dart +++ b/pkgs/ffigen/lib/src/header_parser/sub_parsers/objccategorydecl_parser.dart @@ -15,7 +15,11 @@ ObjCCategory? parseObjCCategoryDeclaration( Context context, clang_types.CXCursor cursor, ) { - final config = context.config; + final objcCategories = context.config.objectiveC?.categories; + if (objcCategories == null) { + return null; + } + final logger = context.logger; final usr = cursor.usr(); final name = cursor.spelling(); @@ -58,7 +62,7 @@ ObjCCategory? parseObjCCategoryDeclaration( final category = ObjCCategory( usr: usr, originalName: name, - name: config.objcCategories.rename(decl), + name: objcCategories.rename(decl), parent: parentInterface, dartDoc: getCursorDocComment( context, @@ -84,7 +88,7 @@ ObjCCategory? parseObjCCategoryDeclaration( context, child, decl, - config.objcCategories, + objcCategories, ); category.addMethod(getter); category.addMethod(setter); @@ -92,7 +96,7 @@ ObjCCategory? parseObjCCategoryDeclaration( case clang_types.CXCursorKind.CXCursor_ObjCInstanceMethodDecl: case clang_types.CXCursorKind.CXCursor_ObjCClassMethodDecl: category.addMethod( - parseObjCMethod(context, child, decl, config.objcCategories), + parseObjCMethod(context, child, decl, objcCategories), ); break; } diff --git a/pkgs/ffigen/lib/src/header_parser/sub_parsers/objcinterfacedecl_parser.dart b/pkgs/ffigen/lib/src/header_parser/sub_parsers/objcinterfacedecl_parser.dart index 5e84322ce..dad0c90c5 100644 --- a/pkgs/ffigen/lib/src/header_parser/sub_parsers/objcinterfacedecl_parser.dart +++ b/pkgs/ffigen/lib/src/header_parser/sub_parsers/objcinterfacedecl_parser.dart @@ -23,18 +23,23 @@ Type? parseObjCInterfaceDeclaration( final decl = Declaration(usr: itfUsr, originalName: itfName); final apiAvailability = ApiAvailability.fromCursor(cursor, context); + final config = context.config; + final objcInterfaces = config.objectiveC?.interfaces; + if (objcInterfaces == null) { + return null; + } + context.logger.fine( '++++ Adding ObjC interface: ' 'Name: $itfName, ${cursor.completeStringRepr()}', ); - final config = context.config; return ObjCInterface( context: context, usr: itfUsr, originalName: itfName, - name: config.objcInterfaces.rename(decl), - lookupName: applyModulePrefix(itfName, config.interfaceModule(decl)), + name: objcInterfaces.rename(decl), + lookupName: applyModulePrefix(itfName, objcInterfaces.module(decl)), dartDoc: getCursorDocComment( context, cursor, @@ -59,6 +64,8 @@ void fillObjCInterfaceMethodsIfNeeded( if (itf.filled) return; itf.filled = true; // Break cycles. + final objcInterfaces = context.config.objectiveC!.interfaces; + context.logger.fine( '++++ Filling ObjC interface: ' 'Name: ${itf.originalName}, ${cursor.completeStringRepr()}', @@ -79,21 +86,14 @@ void fillObjCInterfaceMethodsIfNeeded( context, child, itfDecl, - context.config.objcInterfaces, + objcInterfaces, ); itf.addMethod(getter); itf.addMethod(setter); break; case clang_types.CXCursorKind.CXCursor_ObjCInstanceMethodDecl: case clang_types.CXCursorKind.CXCursor_ObjCClassMethodDecl: - itf.addMethod( - parseObjCMethod( - context, - child, - itfDecl, - context.config.objcInterfaces, - ), - ); + itf.addMethod(parseObjCMethod(context, child, itfDecl, objcInterfaces)); break; } }); diff --git a/pkgs/ffigen/lib/src/header_parser/sub_parsers/objcprotocoldecl_parser.dart b/pkgs/ffigen/lib/src/header_parser/sub_parsers/objcprotocoldecl_parser.dart index 195c74d8f..469ffc7f4 100644 --- a/pkgs/ffigen/lib/src/header_parser/sub_parsers/objcprotocoldecl_parser.dart +++ b/pkgs/ffigen/lib/src/header_parser/sub_parsers/objcprotocoldecl_parser.dart @@ -21,6 +21,11 @@ ObjCProtocol? parseObjCProtocolDeclaration( return null; } + final objcProtocols = config.objectiveC?.protocols; + if (objcProtocols == null) { + return null; + } + final usr = cursor.usr(); final name = cursor.spelling(); @@ -58,8 +63,8 @@ ObjCProtocol? parseObjCProtocolDeclaration( context: context, usr: usr, originalName: name, - name: config.objcProtocols.rename(decl), - lookupName: applyModulePrefix(name, config.protocolModule(decl)), + name: objcProtocols.rename(decl), + lookupName: applyModulePrefix(name, objcProtocols.module(decl)), dartDoc: getCursorDocComment( context, cursor, @@ -90,7 +95,7 @@ ObjCProtocol? parseObjCProtocolDeclaration( context, child, decl, - config.objcProtocols, + objcProtocols, ); protocol.addMethod(getter); protocol.addMethod(setter); @@ -98,7 +103,7 @@ ObjCProtocol? parseObjCProtocolDeclaration( case clang_types.CXCursorKind.CXCursor_ObjCInstanceMethodDecl: case clang_types.CXCursorKind.CXCursor_ObjCClassMethodDecl: protocol.addMethod( - parseObjCMethod(context, child, decl, config.objcProtocols), + parseObjCMethod(context, child, decl, objcProtocols), ); break; } diff --git a/pkgs/ffigen/lib/src/header_parser/sub_parsers/var_parser.dart b/pkgs/ffigen/lib/src/header_parser/sub_parsers/var_parser.dart index 41e0352aa..b9f6d4b53 100644 --- a/pkgs/ffigen/lib/src/header_parser/sub_parsers/var_parser.dart +++ b/pkgs/ffigen/lib/src/header_parser/sub_parsers/var_parser.dart @@ -3,6 +3,7 @@ // BSD-style license that can be found in the LICENSE file. import '../../code_generator.dart'; +import '../../config_provider/config.dart'; import '../../config_provider/config_types.dart'; import '../../context.dart'; import '../clang_bindings/clang_bindings.dart' as clang_types; @@ -12,6 +13,7 @@ import '../utils.dart'; Global? parseVarDeclaration(Context context, clang_types.CXCursor cursor) { final logger = context.logger; final config = context.config; + final nativeOutputStyle = config.output.style is NativeExternalBindings; final bindingsIndex = context.bindingsIndex; final name = cursor.spelling(); final usr = cursor.usr(); @@ -28,7 +30,7 @@ Global? parseVarDeclaration(Context context, clang_types.CXCursor cursor) { context, // Native fields can be arrays, but if we use the lookup based method of // reading fields there's no way to turn a Pointer into an array. - supportNonInlineArray: config.ffiNativeConfig.enabled, + supportNonInlineArray: nativeOutputStyle, ); if (type.baseType is UnimplementedType) { logger.fine( @@ -47,7 +49,7 @@ Global? parseVarDeclaration(Context context, clang_types.CXCursor cursor) { dartDoc: getCursorDocComment(context, cursor), exposeSymbolAddress: config.globals.includeSymbolAddress(decl), constant: cType.isConstQualified, - loadFromNativeAsset: config.ffiNativeConfig.enabled, + loadFromNativeAsset: nativeOutputStyle, ); bindingsIndex.addGlobalVarToSeen(usr, global); diff --git a/pkgs/ffigen/lib/src/header_parser/translation_unit_parser.dart b/pkgs/ffigen/lib/src/header_parser/translation_unit_parser.dart index 6e861cdf2..ce3eeac65 100644 --- a/pkgs/ffigen/lib/src/header_parser/translation_unit_parser.dart +++ b/pkgs/ffigen/lib/src/header_parser/translation_unit_parser.dart @@ -25,7 +25,7 @@ Set parseTranslationUnit( translationUnitCursor.visitChildren((cursor) { final file = cursor.sourceFileName(); if (file.isEmpty) return; - if (headers[file] ??= context.config.shouldIncludeHeader(Uri.file(file))) { + if (headers[file] ??= context.config.headers.include(Uri.file(file))) { try { logger.finest('rootCursorVisitor: ${cursor.completeStringRepr()}'); switch (clang.clang_getCursorKind(cursor)) { diff --git a/pkgs/ffigen/lib/src/header_parser/type_extractor/extractor.dart b/pkgs/ffigen/lib/src/header_parser/type_extractor/extractor.dart index 2c76840ac..1019c601a 100644 --- a/pkgs/ffigen/lib/src/header_parser/type_extractor/extractor.dart +++ b/pkgs/ffigen/lib/src/header_parser/type_extractor/extractor.dart @@ -6,7 +6,6 @@ library; import '../../code_generator.dart'; -import '../../config_provider/config_types.dart'; import '../../context.dart'; import '../../strings.dart' as strings; import '../clang_bindings/clang_bindings.dart' as clang_types; @@ -52,7 +51,7 @@ Type getCodeGenType( // These basic Objective C types skip the cache, and are conditional on the // language flag. - if (context.config.language == Language.objc) { + if (context.config.objectiveC != null) { switch (cxtype.kind) { case clang_types.CXTypeKind.CXType_ObjCObjectPointer: final pt = clang.clang_getPointeeType(cxtype); @@ -214,7 +213,7 @@ _CreateTypeFromCursorResult _createTypeFromCursor( switch (cxtype.kind) { case clang_types.CXTypeKind.CXType_Typedef: final spelling = clang.clang_getTypedefName(cxtype).toStringAndDispose(); - if (config.language == Language.objc && spelling == strings.objcBOOL) { + if (config.objectiveC != null && spelling == strings.objcBOOL) { // Objective C's BOOL type can be either bool or signed char, depending // on the platform. We want to present a consistent API to the user, and // those two types are ABI compatible, so just return bool regardless. diff --git a/pkgs/ffigen/lib/src/header_parser/utils.dart b/pkgs/ffigen/lib/src/header_parser/utils.dart index b69517e10..cfbb20130 100644 --- a/pkgs/ffigen/lib/src/header_parser/utils.dart +++ b/pkgs/ffigen/lib/src/header_parser/utils.dart @@ -296,7 +296,7 @@ String? getCursorDocComment( if (!context.reportedCommentRanges.add(currentCommentRange.toTuple())) { formattedDocComment = null; } else { - switch (context.config.commentType.length) { + switch (context.config.output.commentType.length) { case CommentLength.full: formattedDocComment = removeRawCommentMarkups( clang.clang_Cursor_getRawCommentText(cursor).toStringAndDispose(), diff --git a/pkgs/ffigen/lib/src/visitor/apply_config_filters.dart b/pkgs/ffigen/lib/src/visitor/apply_config_filters.dart index 870be2a36..3fe2bfbfe 100644 --- a/pkgs/ffigen/lib/src/visitor/apply_config_filters.dart +++ b/pkgs/ffigen/lib/src/visitor/apply_config_filters.dart @@ -39,11 +39,13 @@ class ApplyConfigFiltersVisitation extends Visitation { @override void visitObjCInterface(ObjCInterface node) { if (node.unavailable) return; + final objcInterfaces = config.objectiveC?.interfaces; + if (objcInterfaces == null) return; node.filterMethods( - (m) => config.objcInterfaces.includeMember(node, m.originalName), + (m) => objcInterfaces.includeMember(node, m.originalName), ); - _visitImpl(node, config.objcInterfaces); + _visitImpl(node, objcInterfaces); // If this node is included, include all its super types. if (directlyIncluded.contains(node)) { @@ -55,16 +57,20 @@ class ApplyConfigFiltersVisitation extends Visitation { @override void visitObjCCategory(ObjCCategory node) { + final objcCategories = config.objectiveC?.categories; + if (objcCategories == null) return; node.filterMethods((m) { if (node.shouldCopyMethodToInterface(m)) return false; - return config.objcCategories.includeMember(node, m.originalName); + return objcCategories.includeMember(node, m.originalName); }); - _visitImpl(node, config.objcCategories); + _visitImpl(node, objcCategories); } @override void visitObjCProtocol(ObjCProtocol node) { if (node.unavailable) return; + final objcProtocols = config.objectiveC?.protocols; + if (objcProtocols == null) return; node.filterMethods((m) { // TODO(https://github.com/dart-lang/native/issues/1149): Support class @@ -73,9 +79,9 @@ class ApplyConfigFiltersVisitation extends Visitation { // copied to any interfaces that implement the protocol. if (m.isClassMethod) return false; - return config.objcProtocols.includeMember(node, m.originalName); + return objcProtocols.includeMember(node, m.originalName); }); - _visitImpl(node, config.objcProtocols); + _visitImpl(node, objcProtocols); } @override diff --git a/pkgs/ffigen/lib/src/visitor/find_transitive_deps.dart b/pkgs/ffigen/lib/src/visitor/find_transitive_deps.dart index 8f5ff607b..9be48f552 100644 --- a/pkgs/ffigen/lib/src/visitor/find_transitive_deps.dart +++ b/pkgs/ffigen/lib/src/visitor/find_transitive_deps.dart @@ -40,7 +40,7 @@ class FindDirectTransitiveDepsVisitation extends Visitation { @override void visitObjCInterface(ObjCInterface node) { - _visitImpl(node, config.includeTransitiveObjCInterfaces); + _visitImpl(node, config.objectiveC?.interfaces.includeTransitive ?? false); // Always visit the super type, regardless of whether the node is directly // included. This ensures that super types of stubs are also stubs, rather @@ -59,7 +59,7 @@ class FindDirectTransitiveDepsVisitation extends Visitation { @override void visitObjCCategory(ObjCCategory node) { - _visitImpl(node, config.includeTransitiveObjCCategories); + _visitImpl(node, config.objectiveC?.categories.includeTransitive ?? false); // Same as visitObjCInterface's visit of superType. visitor.visit(node.parent); @@ -67,7 +67,7 @@ class FindDirectTransitiveDepsVisitation extends Visitation { @override void visitObjCProtocol(ObjCProtocol node) { - _visitImpl(node, config.includeTransitiveObjCInterfaces); + _visitImpl(node, config.objectiveC?.interfaces.includeTransitive ?? false); // Same as visitObjCInterface's visit of superType. visitor.visitAll(node.superProtocols); diff --git a/pkgs/ffigen/lib/src/visitor/list_bindings.dart b/pkgs/ffigen/lib/src/visitor/list_bindings.dart index 07fd21f01..5a9c0260a 100644 --- a/pkgs/ffigen/lib/src/visitor/list_bindings.dart +++ b/pkgs/ffigen/lib/src/visitor/list_bindings.dart @@ -4,7 +4,6 @@ import '../code_generator.dart'; import '../config_provider/config.dart' show Config; -import '../config_provider/config_types.dart' show Language; import '../strings.dart' as strings; import 'ast.dart'; @@ -67,7 +66,7 @@ class ListBindingsVisitation extends Visitation { node.unavailable || !_visitImpl( node, - config.includeTransitiveObjCInterfaces + config.objectiveC?.interfaces.includeTransitive ?? false ? _IncludeBehavior.configOrTransitive : _IncludeBehavior.configOnly, ); @@ -80,7 +79,7 @@ class ListBindingsVisitation extends Visitation { @override void visitObjCCategory(ObjCCategory node) => _visitImpl( node, - config.includeTransitiveObjCCategories + config.objectiveC?.categories.includeTransitive ?? false ? _IncludeBehavior.configOrDirectTransitive : _IncludeBehavior.configOnly, ); @@ -91,7 +90,7 @@ class ListBindingsVisitation extends Visitation { node.unavailable || !_visitImpl( node, - config.includeTransitiveObjCProtocols + config.objectiveC?.protocols.includeTransitive ?? false ? _IncludeBehavior.configOrTransitive : _IncludeBehavior.configOnly, ); @@ -111,7 +110,7 @@ class ListBindingsVisitation extends Visitation { ); // Objective C has some core typedefs that are important to keep. - if (config.language == Language.objc && + if (config.objectiveC != null && node.originalName == strings.objcInstanceType) { _add(node); }