From cb5e62a6a515237ac9981071b7150d31dbf29e49 Mon Sep 17 00:00:00 2001 From: Nikechukwu Okoronkwo Date: Tue, 17 Dec 2024 23:29:10 -0500 Subject: [PATCH 1/7] Added generics parsing for functions --- ...ration.dart => parse_function_declaration.dart} | 14 ++++++++++++++ .../declaration_parsers/parse_generics.dart | 0 .../lib/src/parser/parsers/parse_declarations.dart | 2 +- 3 files changed, 15 insertions(+), 1 deletion(-) rename pkgs/swift2objc/lib/src/parser/parsers/declaration_parsers/{pase_function_declaration.dart => parse_function_declaration.dart} (88%) create mode 100644 pkgs/swift2objc/lib/src/parser/parsers/declaration_parsers/parse_generics.dart diff --git a/pkgs/swift2objc/lib/src/parser/parsers/declaration_parsers/pase_function_declaration.dart b/pkgs/swift2objc/lib/src/parser/parsers/declaration_parsers/parse_function_declaration.dart similarity index 88% rename from pkgs/swift2objc/lib/src/parser/parsers/declaration_parsers/pase_function_declaration.dart rename to pkgs/swift2objc/lib/src/parser/parsers/declaration_parsers/parse_function_declaration.dart index bdff149925..1233e0c5da 100644 --- a/pkgs/swift2objc/lib/src/parser/parsers/declaration_parsers/pase_function_declaration.dart +++ b/pkgs/swift2objc/lib/src/parser/parsers/declaration_parsers/parse_function_declaration.dart @@ -24,6 +24,20 @@ GlobalFunctionDeclaration parseGlobalFunctionDeclaration( ); } +Iterable _parseGlobalFunctionTypeParams( + Json globalFunctionSymbolJson, + ParsedSymbolgraph symbolgraph, +) { + // get type params + final genericInfo = globalFunctionSymbolJson['swiftGenerics']; + + final parameters = genericInfo['parameters']; + + // how to make a good id for generic types + return parameters.map((e) => + GenericType(id: e['name'].get(), name: e['name'].get())); +} + MethodDeclaration parseMethodDeclaration( Json methodSymbolJson, ParsedSymbolgraph symbolgraph, { diff --git a/pkgs/swift2objc/lib/src/parser/parsers/declaration_parsers/parse_generics.dart b/pkgs/swift2objc/lib/src/parser/parsers/declaration_parsers/parse_generics.dart new file mode 100644 index 0000000000..e69de29bb2 diff --git a/pkgs/swift2objc/lib/src/parser/parsers/parse_declarations.dart b/pkgs/swift2objc/lib/src/parser/parsers/parse_declarations.dart index e3aa57322d..4bccc52d77 100644 --- a/pkgs/swift2objc/lib/src/parser/parsers/parse_declarations.dart +++ b/pkgs/swift2objc/lib/src/parser/parsers/parse_declarations.dart @@ -8,9 +8,9 @@ import '../../ast/_core/interfaces/declaration.dart'; import '../_core/parsed_symbolgraph.dart'; import '../_core/utils.dart'; import 'declaration_parsers/parse_compound_declaration.dart'; +import 'declaration_parsers/parse_function_declaration.dart'; import 'declaration_parsers/parse_initializer_declaration.dart'; import 'declaration_parsers/parse_variable_declaration.dart'; -import 'declaration_parsers/pase_function_declaration.dart'; List parseDeclarations(ParsedSymbolgraph symbolgraph) { final declarations = []; From 4a9274c3b50ee679bb374972c8d1bb82e7920dee Mon Sep 17 00:00:00 2001 From: Nikechukwu Okoronkwo Date: Tue, 17 Dec 2024 23:32:05 -0500 Subject: [PATCH 2/7] Added type constraints property on generic type --- .../lib/src/ast/_core/shared/referred_type.dart | 9 +++++---- .../parse_function_declaration.dart | 16 ++++++++++++++-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/pkgs/swift2objc/lib/src/ast/_core/shared/referred_type.dart b/pkgs/swift2objc/lib/src/ast/_core/shared/referred_type.dart index b9cf0bad1a..d4e7c91258 100644 --- a/pkgs/swift2objc/lib/src/ast/_core/shared/referred_type.dart +++ b/pkgs/swift2objc/lib/src/ast/_core/shared/referred_type.dart @@ -56,11 +56,12 @@ class GenericType implements ReferredType { @override final String name; + /// type constraints the generic type might have + final List constraints; + @override bool get isObjCRepresentable => false; - const GenericType({ - required this.id, - required this.name, - }); + const GenericType( + {required this.id, required this.name, this.constraints = const []}); } diff --git a/pkgs/swift2objc/lib/src/parser/parsers/declaration_parsers/parse_function_declaration.dart b/pkgs/swift2objc/lib/src/parser/parsers/declaration_parsers/parse_function_declaration.dart index 1233e0c5da..73112a8ee7 100644 --- a/pkgs/swift2objc/lib/src/parser/parsers/declaration_parsers/parse_function_declaration.dart +++ b/pkgs/swift2objc/lib/src/parser/parsers/declaration_parsers/parse_function_declaration.dart @@ -59,8 +59,20 @@ ReferredType? _parseFunctionReturnType( ) { final returnJson = methodSymbolJson['functionSignature']['returns'][0]; - // This means there's no return type - if (returnJson['spelling'].get() == '()') { + // if it is a type generic it may not even have a spelling + if (returnJson['spelling'].get() == null) { + // check if the item is a generic registered + try { + final type = returnJson['spelling'].get(); + final generics = methodSymbolJson['swiftGenerics']['parameters']; + if (generics.map((e) => e['name'].get()).contains(type)) { + // generic located + } + } on Exception catch (e) { + // continue + } + } else if (returnJson['spelling'].get() == '()') { + // This means there's no return type return null; } From 8a0e8ba12f7438a5a5b4ddfc16aca38c191dee7f Mon Sep 17 00:00:00 2001 From: Nikechukwu Okoronkwo Date: Wed, 18 Dec 2024 00:00:05 -0500 Subject: [PATCH 3/7] Written type parameter function for global functions --- .../src/ast/_core/shared/referred_type.dart | 2 +- .../built_in/built_in_declaration.dart | 1 + .../parse_function_declaration.dart | 53 +++++++++++++++---- 3 files changed, 46 insertions(+), 10 deletions(-) diff --git a/pkgs/swift2objc/lib/src/ast/_core/shared/referred_type.dart b/pkgs/swift2objc/lib/src/ast/_core/shared/referred_type.dart index d4e7c91258..3e0e15fb59 100644 --- a/pkgs/swift2objc/lib/src/ast/_core/shared/referred_type.dart +++ b/pkgs/swift2objc/lib/src/ast/_core/shared/referred_type.dart @@ -57,7 +57,7 @@ class GenericType implements ReferredType { final String name; /// type constraints the generic type might have - final List constraints; + final List> constraints; @override bool get isObjCRepresentable => false; diff --git a/pkgs/swift2objc/lib/src/ast/declarations/built_in/built_in_declaration.dart b/pkgs/swift2objc/lib/src/ast/declarations/built_in/built_in_declaration.dart index 6131549dff..98392427de 100644 --- a/pkgs/swift2objc/lib/src/ast/declarations/built_in/built_in_declaration.dart +++ b/pkgs/swift2objc/lib/src/ast/declarations/built_in/built_in_declaration.dart @@ -6,6 +6,7 @@ import '../../_core/interfaces/declaration.dart'; import '../../_core/interfaces/objc_annotatable.dart'; /// Describes a built-in Swift type (e.g Int, String, etc). +/// TODO: Include builtin protocols like "Hashable", "Numeric", etc enum BuiltInDeclaration implements Declaration, ObjCAnnotatable { swiftNSObject(id: 'c:objc(cs)NSObject', name: 'NSObject'), swiftString(id: 's:SS', name: 'String'), diff --git a/pkgs/swift2objc/lib/src/parser/parsers/declaration_parsers/parse_function_declaration.dart b/pkgs/swift2objc/lib/src/parser/parsers/declaration_parsers/parse_function_declaration.dart index 73112a8ee7..ae0c1601d1 100644 --- a/pkgs/swift2objc/lib/src/parser/parsers/declaration_parsers/parse_function_declaration.dart +++ b/pkgs/swift2objc/lib/src/parser/parsers/declaration_parsers/parse_function_declaration.dart @@ -2,6 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. +import '../../../ast/_core/interfaces/compound_declaration.dart'; import '../../../ast/_core/interfaces/declaration.dart'; import '../../../ast/_core/shared/parameter.dart'; import '../../../ast/_core/shared/referred_type.dart'; @@ -17,14 +18,16 @@ GlobalFunctionDeclaration parseGlobalFunctionDeclaration( ParsedSymbolgraph symbolgraph, ) { return GlobalFunctionDeclaration( - id: parseSymbolId(globalFunctionSymbolJson), - name: parseSymbolName(globalFunctionSymbolJson), - returnType: _parseFunctionReturnType(globalFunctionSymbolJson, symbolgraph), - params: _parseFunctionParams(globalFunctionSymbolJson, symbolgraph), - ); + id: parseSymbolId(globalFunctionSymbolJson), + name: parseSymbolName(globalFunctionSymbolJson), + returnType: + _parseFunctionReturnType(globalFunctionSymbolJson, symbolgraph), + params: _parseFunctionParams(globalFunctionSymbolJson, symbolgraph), + typeParams: _parseGlobalFunctionTypeParams( + globalFunctionSymbolJson, symbolgraph)); } -Iterable _parseGlobalFunctionTypeParams( +List _parseGlobalFunctionTypeParams( Json globalFunctionSymbolJson, ParsedSymbolgraph symbolgraph, ) { @@ -33,9 +36,41 @@ Iterable _parseGlobalFunctionTypeParams( final parameters = genericInfo['parameters']; - // how to make a good id for generic types - return parameters.map((e) => - GenericType(id: e['name'].get(), name: e['name'].get())); + if (genericInfo.jsonWithKeyExists('constraints')) { + return parameters.map((e) { + final constraintsDesc = genericInfo['constraints'].where( + (element) => element['lhs'].get() == e['name'].get()); + + return GenericType( + id: e['name'].get(), + name: e['name'].get(), + constraints: constraintsDesc.map((c) { + final constraintId = c['rhsPrecise'].get(); + + final constraintTypeSymbol = symbolgraph.symbols[constraintId]; + + if (constraintTypeSymbol == null) { + throw Exception( + 'The type constraint at path "${globalFunctionSymbolJson.path}"' + ' has a return type that does not exist among parsed symbols.', + ); + } + + final constraintDeclaration = parseDeclaration( + constraintTypeSymbol, + symbolgraph, + ) as CompoundDeclaration; + + return constraintDeclaration.asDeclaredType; + }).toList()); + }).toList(); + } else { + // how to make a good id for generic types + return parameters + .map((e) => GenericType( + id: e['name'].get(), name: e['name'].get())) + .toList(); + } } MethodDeclaration parseMethodDeclaration( From 070ebd906babd4488e43cc68e61de8273a967a7e Mon Sep 17 00:00:00 2001 From: Nikechukwu Okoronkwo Date: Wed, 18 Dec 2024 00:17:54 -0500 Subject: [PATCH 4/7] Implement parsing type params and some comments --- .../declaration_parsers/parse_function_declaration.dart | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pkgs/swift2objc/lib/src/parser/parsers/declaration_parsers/parse_function_declaration.dart b/pkgs/swift2objc/lib/src/parser/parsers/declaration_parsers/parse_function_declaration.dart index ae0c1601d1..43953642b2 100644 --- a/pkgs/swift2objc/lib/src/parser/parsers/declaration_parsers/parse_function_declaration.dart +++ b/pkgs/swift2objc/lib/src/parser/parsers/declaration_parsers/parse_function_declaration.dart @@ -23,11 +23,11 @@ GlobalFunctionDeclaration parseGlobalFunctionDeclaration( returnType: _parseFunctionReturnType(globalFunctionSymbolJson, symbolgraph), params: _parseFunctionParams(globalFunctionSymbolJson, symbolgraph), - typeParams: _parseGlobalFunctionTypeParams( - globalFunctionSymbolJson, symbolgraph)); + typeParams: + parseFunctionTypeParams(globalFunctionSymbolJson, symbolgraph)); } -List _parseGlobalFunctionTypeParams( +List parseFunctionTypeParams( Json globalFunctionSymbolJson, ParsedSymbolgraph symbolgraph, ) { @@ -84,6 +84,7 @@ MethodDeclaration parseMethodDeclaration( returnType: _parseFunctionReturnType(methodSymbolJson, symbolgraph), params: _parseFunctionParams(methodSymbolJson, symbolgraph), hasObjCAnnotation: parseSymbolHasObjcAnnotation(methodSymbolJson), + typeParams: parseFunctionTypeParams(methodSymbolJson, symbolgraph), isStatic: isStatic, ); } @@ -102,6 +103,7 @@ ReferredType? _parseFunctionReturnType( final generics = methodSymbolJson['swiftGenerics']['parameters']; if (generics.map((e) => e['name'].get()).contains(type)) { // generic located + // TODO: Parse return type generics } } on Exception catch (e) { // continue @@ -140,6 +142,7 @@ List _parseFunctionParams( return paramList .map( + // TODO: Add parameter type generic parsing (param) => Parameter( name: param['name'].get(), internalName: param['internalName'].get(), From bf069945be7deda4dd422100107300edc76a45c7 Mon Sep 17 00:00:00 2001 From: Nike Date: Wed, 18 Dec 2024 12:53:22 -0500 Subject: [PATCH 5/7] Added test for functions --- .../built_in/built_in_declaration.dart | 2 +- .../parse_function_declaration.dart | 81 +- .../parser/parsers/parse_declarations.dart | 1 + .../test/unit/parse_type_generics_test.dart | 31 + ...pegenerics_symbolgraph_module.symbols.json | 1212 +++++++++++++++++ 5 files changed, 1297 insertions(+), 30 deletions(-) create mode 100644 pkgs/swift2objc/test/unit/parse_type_generics_test.dart create mode 100644 pkgs/swift2objc/test/unit/typegenerics_symbolgraph_module.symbols.json diff --git a/pkgs/swift2objc/lib/src/ast/declarations/built_in/built_in_declaration.dart b/pkgs/swift2objc/lib/src/ast/declarations/built_in/built_in_declaration.dart index 98392427de..ee3786ffe0 100644 --- a/pkgs/swift2objc/lib/src/ast/declarations/built_in/built_in_declaration.dart +++ b/pkgs/swift2objc/lib/src/ast/declarations/built_in/built_in_declaration.dart @@ -6,7 +6,7 @@ import '../../_core/interfaces/declaration.dart'; import '../../_core/interfaces/objc_annotatable.dart'; /// Describes a built-in Swift type (e.g Int, String, etc). -/// TODO: Include builtin protocols like "Hashable", "Numeric", etc +/// TODO(https://github.com/dart-lang/native/issues/1827): Include builtin protocols like `Hashable`, `Numeric` enum BuiltInDeclaration implements Declaration, ObjCAnnotatable { swiftNSObject(id: 'c:objc(cs)NSObject', name: 'NSObject'), swiftString(id: 's:SS', name: 'String'), diff --git a/pkgs/swift2objc/lib/src/parser/parsers/declaration_parsers/parse_function_declaration.dart b/pkgs/swift2objc/lib/src/parser/parsers/declaration_parsers/parse_function_declaration.dart index 43953642b2..2ff9616f35 100644 --- a/pkgs/swift2objc/lib/src/parser/parsers/declaration_parsers/parse_function_declaration.dart +++ b/pkgs/swift2objc/lib/src/parser/parsers/declaration_parsers/parse_function_declaration.dart @@ -38,31 +38,8 @@ List parseFunctionTypeParams( if (genericInfo.jsonWithKeyExists('constraints')) { return parameters.map((e) { - final constraintsDesc = genericInfo['constraints'].where( - (element) => element['lhs'].get() == e['name'].get()); - - return GenericType( - id: e['name'].get(), - name: e['name'].get(), - constraints: constraintsDesc.map((c) { - final constraintId = c['rhsPrecise'].get(); - - final constraintTypeSymbol = symbolgraph.symbols[constraintId]; - - if (constraintTypeSymbol == null) { - throw Exception( - 'The type constraint at path "${globalFunctionSymbolJson.path}"' - ' has a return type that does not exist among parsed symbols.', - ); - } - - final constraintDeclaration = parseDeclaration( - constraintTypeSymbol, - symbolgraph, - ) as CompoundDeclaration; - - return constraintDeclaration.asDeclaredType; - }).toList()); + return parseFunctionGenericType(genericInfo, e['name'].get(), + symbolgraph, globalFunctionSymbolJson); }).toList(); } else { // how to make a good id for generic types @@ -73,6 +50,36 @@ List parseFunctionTypeParams( } } +GenericType parseFunctionGenericType(Json genericInfo, String name, + ParsedSymbolgraph symbolgraph, + Json functionSymbolJson, {String? id}) { + final constraintsDesc = genericInfo['constraints'].where( + (element) => element['lhs'].get() == name); + + return GenericType( + id: id ?? name, + name: name, + constraints: constraintsDesc.map((c) { + final constraintId = c['rhsPrecise'].get(); + + final constraintTypeSymbol = symbolgraph.symbols[constraintId]; + + if (constraintTypeSymbol == null) { + throw Exception( + 'The type constraint at path "${functionSymbolJson.path}"' + ' has a return type that does not exist among parsed symbols.', + ); + } + + final constraintDeclaration = parseDeclaration( + constraintTypeSymbol, + symbolgraph, + ) as CompoundDeclaration; + + return constraintDeclaration.asDeclaredType; + }).toList()); +} + MethodDeclaration parseMethodDeclaration( Json methodSymbolJson, ParsedSymbolgraph symbolgraph, { @@ -103,7 +110,8 @@ ReferredType? _parseFunctionReturnType( final generics = methodSymbolJson['swiftGenerics']['parameters']; if (generics.map((e) => e['name'].get()).contains(type)) { // generic located - // TODO: Parse return type generics + return parseFunctionGenericType(methodSymbolJson['swiftGenerics'], type, + symbolgraph, methodSymbolJson); } } on Exception catch (e) { // continue @@ -146,7 +154,7 @@ List _parseFunctionParams( (param) => Parameter( name: param['name'].get(), internalName: param['internalName'].get(), - type: _parseParamType(param, symbolgraph), + type: _parseParamType(param, symbolgraph, methodSymbolJson: methodSymbolJson), ), ) .toList(); @@ -155,11 +163,26 @@ List _parseFunctionParams( ReferredType _parseParamType( Json paramSymbolJson, ParsedSymbolgraph symbolgraph, + {Json? methodSymbolJson} ) { final fragments = paramSymbolJson['declarationFragments']; - final paramTypeId = fragments - .firstJsonWhereKey('kind', 'typeIdentifier')['preciseIdentifier'] + var typeDeclFragment = fragments + .firstJsonWhereKey('kind', 'typeIdentifier'); + + if (methodSymbolJson != null) { + if (methodSymbolJson['swiftGenerics'].get?>() != null) { + if (methodSymbolJson['swiftGenerics']['parameters'].map( + (e) => e['name'].get() + ).contains(typeDeclFragment['spelling'].get())) { + return parseFunctionGenericType(methodSymbolJson['swiftGenerics'], + typeDeclFragment['spelling'].get(), symbolgraph, + methodSymbolJson); + } + } + } + + final paramTypeId = typeDeclFragment['preciseIdentifier'] .get(); return parseTypeFromId(paramTypeId, symbolgraph); diff --git a/pkgs/swift2objc/lib/src/parser/parsers/parse_declarations.dart b/pkgs/swift2objc/lib/src/parser/parsers/parse_declarations.dart index 4bccc52d77..7624893ae3 100644 --- a/pkgs/swift2objc/lib/src/parser/parsers/parse_declarations.dart +++ b/pkgs/swift2objc/lib/src/parser/parsers/parse_declarations.dart @@ -37,6 +37,7 @@ Declaration parseDeclaration( final symbolType = symbolJson['kind']['identifier'].get(); + // TODO(https://github.com/dart-lang/native/issues/1828): Support protocols parsedSymbol.declaration = switch (symbolType) { 'swift.class' => parseClassDeclaration(parsedSymbol, symbolgraph), 'swift.struct' => parseStructDeclaration(parsedSymbol, symbolgraph), diff --git a/pkgs/swift2objc/test/unit/parse_type_generics_test.dart b/pkgs/swift2objc/test/unit/parse_type_generics_test.dart new file mode 100644 index 0000000000..ee8dbae861 --- /dev/null +++ b/pkgs/swift2objc/test/unit/parse_type_generics_test.dart @@ -0,0 +1,31 @@ +import 'package:path/path.dart' as p; +import 'package:swift2objc/src/ast/_core/interfaces/function_declaration.dart'; +import 'package:swift2objc/src/parser/_core/parsed_symbolgraph.dart'; +import 'package:swift2objc/src/parser/_core/utils.dart'; +import 'package:swift2objc/src/parser/parsers/parse_declarations.dart'; +import 'package:swift2objc/src/parser/parsers/parse_relations_map.dart'; +import 'package:swift2objc/src/parser/parsers/parse_symbols_map.dart'; +import 'package:test/test.dart'; + +void main() { + + group('General Test: Functions', () { + final inputFile = p.join(p.current, 'test', 'unit', + 'typegenerics_symbolgraph_module.symbols.json'); + final inputJson = readJsonFile(inputFile); + final symbolgraph = ParsedSymbolgraph( + parseSymbolsMap(inputJson), + parseRelationsMap(inputJson), + ); + final declarations = parseDeclarations(symbolgraph); + final functionDeclarations = declarations.whereType(); + + test('Basic Type Generics', () { + final firstTestDecl = functionDeclarations.firstWhere((d) => d.name == 'basicFunc'); + final secondTestDecl = functionDeclarations.firstWhere((d) => d.name == 'basicGenericFunc'); + + assert(firstTestDecl.typeParams.isEmpty); + assert(secondTestDecl.typeParams.isNotEmpty); + }); + }); +} \ No newline at end of file diff --git a/pkgs/swift2objc/test/unit/typegenerics_symbolgraph_module.symbols.json b/pkgs/swift2objc/test/unit/typegenerics_symbolgraph_module.symbols.json new file mode 100644 index 0000000000..c48d8553ec --- /dev/null +++ b/pkgs/swift2objc/test/unit/typegenerics_symbolgraph_module.symbols.json @@ -0,0 +1,1212 @@ +{ + "metadata": { + "formatVersion": { + "major": 0, + "minor": 6, + "patch": 0 + }, + "generator": "Apple Swift version 6.0.3 (swiftlang-6.0.3.1.10 clang-1600.0.30.1)" + }, + "module": { + "name": "primitive_symbolgraph_module", + "platform": { + "architecture": "arm64", + "vendor": "apple", + "operatingSystem": { + "name": "macosx", + "minimumVersion": { + "major": 15, + "minor": 0 + } + } + } + }, + "symbols": [ + { + "kind": { + "identifier": "swift.protocol", + "displayName": "Protocol" + }, + "identifier": { + "precise": "s:28primitive_symbolgraph_module1AP", + "interfaceLanguage": "swift" + }, + "pathComponents": [ + "A" + ], + "names": { + "title": "A", + "navigator": [ + { + "kind": "identifier", + "spelling": "A" + } + ], + "subHeading": [ + { + "kind": "keyword", + "spelling": "protocol" + }, + { + "kind": "text", + "spelling": " " + }, + { + "kind": "identifier", + "spelling": "A" + } + ] + }, + "declarationFragments": [ + { + "kind": "keyword", + "spelling": "protocol" + }, + { + "kind": "text", + "spelling": " " + }, + { + "kind": "identifier", + "spelling": "A" + } + ], + "accessLevel": "public", + "location": { + "uri": "file://types.swift", + "position": { + "line": 0, + "character": 16 + } + } + }, + { + "kind": { + "identifier": "swift.func", + "displayName": "Function" + }, + "identifier": { + "precise": "s:28primitive_symbolgraph_module7myFunc21myx_tAA1ARzlF", + "interfaceLanguage": "swift" + }, + "pathComponents": [ + "myFunc2(m:)" + ], + "names": { + "title": "myFunc2(m:)", + "subHeading": [ + { + "kind": "keyword", + "spelling": "func" + }, + { + "kind": "text", + "spelling": " " + }, + { + "kind": "identifier", + "spelling": "myFunc2" + }, + { + "kind": "text", + "spelling": "<" + }, + { + "kind": "genericParameter", + "spelling": "T" + }, + { + "kind": "text", + "spelling": ">(" + }, + { + "kind": "externalParam", + "spelling": "m" + }, + { + "kind": "text", + "spelling": ": " + }, + { + "kind": "typeIdentifier", + "spelling": "T", + "preciseIdentifier": "s:28primitive_symbolgraph_module7myFunc21myx_tAA1ARzlF1TL_xmfp" + }, + { + "kind": "text", + "spelling": ")" + } + ] + }, + "functionSignature": { + "parameters": [ + { + "name": "m", + "declarationFragments": [ + { + "kind": "identifier", + "spelling": "m" + }, + { + "kind": "text", + "spelling": ": " + }, + { + "kind": "typeIdentifier", + "spelling": "T", + "preciseIdentifier": "s:28primitive_symbolgraph_module7myFunc21myx_tAA1ARzlF1TL_xmfp" + } + ] + } + ], + "returns": [ + { + "kind": "text", + "spelling": "()" + } + ] + }, + "swiftGenerics": { + "parameters": [ + { + "name": "T", + "index": 0, + "depth": 0 + } + ], + "constraints": [ + { + "kind": "conformance", + "lhs": "T", + "rhs": "A", + "rhsPrecise": "s:28primitive_symbolgraph_module1AP" + } + ] + }, + "declarationFragments": [ + { + "kind": "keyword", + "spelling": "func" + }, + { + "kind": "text", + "spelling": " " + }, + { + "kind": "identifier", + "spelling": "myFunc2" + }, + { + "kind": "text", + "spelling": "<" + }, + { + "kind": "genericParameter", + "spelling": "T" + }, + { + "kind": "text", + "spelling": ">(" + }, + { + "kind": "externalParam", + "spelling": "m" + }, + { + "kind": "text", + "spelling": ": " + }, + { + "kind": "typeIdentifier", + "spelling": "T", + "preciseIdentifier": "s:28primitive_symbolgraph_module7myFunc21myx_tAA1ARzlF1TL_xmfp" + }, + { + "kind": "text", + "spelling": ") " + }, + { + "kind": "keyword", + "spelling": "where" + }, + { + "kind": "text", + "spelling": " " + }, + { + "kind": "typeIdentifier", + "spelling": "T" + }, + { + "kind": "text", + "spelling": " : " + }, + { + "kind": "typeIdentifier", + "spelling": "A", + "preciseIdentifier": "s:28primitive_symbolgraph_module1AP" + } + ], + "accessLevel": "public", + "location": { + "uri": "file://types.swift", + "position": { + "line": 15, + "character": 12 + } + } + }, + { + "kind": { + "identifier": "swift.func", + "displayName": "Function" + }, + "identifier": { + "precise": "s:28primitive_symbolgraph_module7myFunc31mq_x_tAA1ARzAaDR_r0_lF", + "interfaceLanguage": "swift" + }, + "pathComponents": [ + "myFunc3(m:)" + ], + "names": { + "title": "myFunc3(m:)", + "subHeading": [ + { + "kind": "keyword", + "spelling": "func" + }, + { + "kind": "text", + "spelling": " " + }, + { + "kind": "identifier", + "spelling": "myFunc3" + }, + { + "kind": "text", + "spelling": "<" + }, + { + "kind": "genericParameter", + "spelling": "T" + }, + { + "kind": "text", + "spelling": ", " + }, + { + "kind": "genericParameter", + "spelling": "U" + }, + { + "kind": "text", + "spelling": ">(" + }, + { + "kind": "externalParam", + "spelling": "m" + }, + { + "kind": "text", + "spelling": ": " + }, + { + "kind": "typeIdentifier", + "spelling": "T", + "preciseIdentifier": "s:28primitive_symbolgraph_module7myFunc31mq_x_tAA1ARzAaDR_r0_lF1TL_xmfp" + }, + { + "kind": "text", + "spelling": ") -> " + }, + { + "kind": "typeIdentifier", + "spelling": "U", + "preciseIdentifier": "s:28primitive_symbolgraph_module7myFunc31mq_x_tAA1ARzAaDR_r0_lF1UL_q_mfp" + } + ] + }, + "functionSignature": { + "parameters": [ + { + "name": "m", + "declarationFragments": [ + { + "kind": "identifier", + "spelling": "m" + }, + { + "kind": "text", + "spelling": ": " + }, + { + "kind": "typeIdentifier", + "spelling": "T", + "preciseIdentifier": "s:28primitive_symbolgraph_module7myFunc31mq_x_tAA1ARzAaDR_r0_lF1TL_xmfp" + } + ] + } + ], + "returns": [ + { + "kind": "typeIdentifier", + "spelling": "U" + } + ] + }, + "swiftGenerics": { + "parameters": [ + { + "name": "T", + "index": 0, + "depth": 0 + }, + { + "name": "U", + "index": 1, + "depth": 0 + } + ], + "constraints": [ + { + "kind": "conformance", + "lhs": "T", + "rhs": "A", + "rhsPrecise": "s:28primitive_symbolgraph_module1AP" + }, + { + "kind": "conformance", + "lhs": "U", + "rhs": "A", + "rhsPrecise": "s:28primitive_symbolgraph_module1AP" + } + ] + }, + "declarationFragments": [ + { + "kind": "keyword", + "spelling": "func" + }, + { + "kind": "text", + "spelling": " " + }, + { + "kind": "identifier", + "spelling": "myFunc3" + }, + { + "kind": "text", + "spelling": "<" + }, + { + "kind": "genericParameter", + "spelling": "T" + }, + { + "kind": "text", + "spelling": ", " + }, + { + "kind": "genericParameter", + "spelling": "U" + }, + { + "kind": "text", + "spelling": ">(" + }, + { + "kind": "externalParam", + "spelling": "m" + }, + { + "kind": "text", + "spelling": ": " + }, + { + "kind": "typeIdentifier", + "spelling": "T", + "preciseIdentifier": "s:28primitive_symbolgraph_module7myFunc31mq_x_tAA1ARzAaDR_r0_lF1TL_xmfp" + }, + { + "kind": "text", + "spelling": ") -> " + }, + { + "kind": "typeIdentifier", + "spelling": "U", + "preciseIdentifier": "s:28primitive_symbolgraph_module7myFunc31mq_x_tAA1ARzAaDR_r0_lF1UL_q_mfp" + }, + { + "kind": "text", + "spelling": " " + }, + { + "kind": "keyword", + "spelling": "where" + }, + { + "kind": "text", + "spelling": " " + }, + { + "kind": "typeIdentifier", + "spelling": "T" + }, + { + "kind": "text", + "spelling": " : " + }, + { + "kind": "typeIdentifier", + "spelling": "A", + "preciseIdentifier": "s:28primitive_symbolgraph_module1AP" + }, + { + "kind": "text", + "spelling": ", " + }, + { + "kind": "typeIdentifier", + "spelling": "U" + }, + { + "kind": "text", + "spelling": " : " + }, + { + "kind": "typeIdentifier", + "spelling": "A", + "preciseIdentifier": "s:28primitive_symbolgraph_module1AP" + } + ], + "accessLevel": "public", + "location": { + "uri": "file://types.swift", + "position": { + "line": 19, + "character": 12 + } + } + }, + { + "kind": { + "identifier": "swift.func", + "displayName": "Function" + }, + "identifier": { + "precise": "s:28primitive_symbolgraph_module16basicGenericFunc1myx_tlF", + "interfaceLanguage": "swift" + }, + "pathComponents": [ + "basicGenericFunc(m:)" + ], + "names": { + "title": "basicGenericFunc(m:)", + "subHeading": [ + { + "kind": "keyword", + "spelling": "func" + }, + { + "kind": "text", + "spelling": " " + }, + { + "kind": "identifier", + "spelling": "basicGenericFunc" + }, + { + "kind": "text", + "spelling": "<" + }, + { + "kind": "genericParameter", + "spelling": "U" + }, + { + "kind": "text", + "spelling": ">(" + }, + { + "kind": "externalParam", + "spelling": "m" + }, + { + "kind": "text", + "spelling": ": " + }, + { + "kind": "typeIdentifier", + "spelling": "U", + "preciseIdentifier": "s:28primitive_symbolgraph_module16basicGenericFunc1myx_tlF1UL_xmfp" + }, + { + "kind": "text", + "spelling": ")" + } + ] + }, + "functionSignature": { + "parameters": [ + { + "name": "m", + "declarationFragments": [ + { + "kind": "identifier", + "spelling": "m" + }, + { + "kind": "text", + "spelling": ": " + }, + { + "kind": "typeIdentifier", + "spelling": "U", + "preciseIdentifier": "s:28primitive_symbolgraph_module16basicGenericFunc1myx_tlF1UL_xmfp" + } + ] + } + ], + "returns": [ + { + "kind": "text", + "spelling": "()" + } + ] + }, + "swiftGenerics": { + "parameters": [ + { + "name": "U", + "index": 0, + "depth": 0 + } + ] + }, + "declarationFragments": [ + { + "kind": "keyword", + "spelling": "func" + }, + { + "kind": "text", + "spelling": " " + }, + { + "kind": "identifier", + "spelling": "basicGenericFunc" + }, + { + "kind": "text", + "spelling": "<" + }, + { + "kind": "genericParameter", + "spelling": "U" + }, + { + "kind": "text", + "spelling": ">(" + }, + { + "kind": "externalParam", + "spelling": "m" + }, + { + "kind": "text", + "spelling": ": " + }, + { + "kind": "typeIdentifier", + "spelling": "U", + "preciseIdentifier": "s:28primitive_symbolgraph_module16basicGenericFunc1myx_tlF1UL_xmfp" + }, + { + "kind": "text", + "spelling": ")" + } + ], + "accessLevel": "public", + "location": { + "uri": "file://types.swift", + "position": { + "line": 8, + "character": 12 + } + } + }, + { + "kind": { + "identifier": "swift.func", + "displayName": "Function" + }, + "identifier": { + "precise": "s:28primitive_symbolgraph_module6myFunc1myx_tAA1ARzlF", + "interfaceLanguage": "swift" + }, + "pathComponents": [ + "myFunc(m:)" + ], + "names": { + "title": "myFunc(m:)", + "subHeading": [ + { + "kind": "keyword", + "spelling": "func" + }, + { + "kind": "text", + "spelling": " " + }, + { + "kind": "identifier", + "spelling": "myFunc" + }, + { + "kind": "text", + "spelling": "<" + }, + { + "kind": "genericParameter", + "spelling": "T" + }, + { + "kind": "text", + "spelling": ">(" + }, + { + "kind": "externalParam", + "spelling": "m" + }, + { + "kind": "text", + "spelling": ": " + }, + { + "kind": "typeIdentifier", + "spelling": "T", + "preciseIdentifier": "s:28primitive_symbolgraph_module6myFunc1myx_tAA1ARzlF1TL_xmfp" + }, + { + "kind": "text", + "spelling": ")" + } + ] + }, + "functionSignature": { + "parameters": [ + { + "name": "m", + "declarationFragments": [ + { + "kind": "identifier", + "spelling": "m" + }, + { + "kind": "text", + "spelling": ": " + }, + { + "kind": "typeIdentifier", + "spelling": "T", + "preciseIdentifier": "s:28primitive_symbolgraph_module6myFunc1myx_tAA1ARzlF1TL_xmfp" + } + ] + } + ], + "returns": [ + { + "kind": "text", + "spelling": "()" + } + ] + }, + "swiftGenerics": { + "parameters": [ + { + "name": "T", + "index": 0, + "depth": 0 + } + ], + "constraints": [ + { + "kind": "conformance", + "lhs": "T", + "rhs": "A", + "rhsPrecise": "s:28primitive_symbolgraph_module1AP" + } + ] + }, + "declarationFragments": [ + { + "kind": "keyword", + "spelling": "func" + }, + { + "kind": "text", + "spelling": " " + }, + { + "kind": "identifier", + "spelling": "myFunc" + }, + { + "kind": "text", + "spelling": "<" + }, + { + "kind": "genericParameter", + "spelling": "T" + }, + { + "kind": "text", + "spelling": ">(" + }, + { + "kind": "externalParam", + "spelling": "m" + }, + { + "kind": "text", + "spelling": ": " + }, + { + "kind": "typeIdentifier", + "spelling": "T", + "preciseIdentifier": "s:28primitive_symbolgraph_module6myFunc1myx_tAA1ARzlF1TL_xmfp" + }, + { + "kind": "text", + "spelling": ") " + }, + { + "kind": "keyword", + "spelling": "where" + }, + { + "kind": "text", + "spelling": " " + }, + { + "kind": "typeIdentifier", + "spelling": "T" + }, + { + "kind": "text", + "spelling": " : " + }, + { + "kind": "typeIdentifier", + "spelling": "A", + "preciseIdentifier": "s:28primitive_symbolgraph_module1AP" + } + ], + "accessLevel": "public", + "location": { + "uri": "file://types.swift", + "position": { + "line": 12, + "character": 12 + } + } + }, + { + "kind": { + "identifier": "swift.func", + "displayName": "Function" + }, + "identifier": { + "precise": "s:28primitive_symbolgraph_module9basicFunc1mySS_tF", + "interfaceLanguage": "swift" + }, + "pathComponents": [ + "basicFunc(m:)" + ], + "names": { + "title": "basicFunc(m:)", + "subHeading": [ + { + "kind": "keyword", + "spelling": "func" + }, + { + "kind": "text", + "spelling": " " + }, + { + "kind": "identifier", + "spelling": "basicFunc" + }, + { + "kind": "text", + "spelling": "(" + }, + { + "kind": "externalParam", + "spelling": "m" + }, + { + "kind": "text", + "spelling": ": " + }, + { + "kind": "typeIdentifier", + "spelling": "String", + "preciseIdentifier": "s:SS" + }, + { + "kind": "text", + "spelling": ")" + } + ] + }, + "functionSignature": { + "parameters": [ + { + "name": "m", + "declarationFragments": [ + { + "kind": "identifier", + "spelling": "m" + }, + { + "kind": "text", + "spelling": ": " + }, + { + "kind": "typeIdentifier", + "spelling": "String", + "preciseIdentifier": "s:SS" + } + ] + } + ], + "returns": [ + { + "kind": "text", + "spelling": "()" + } + ] + }, + "declarationFragments": [ + { + "kind": "keyword", + "spelling": "func" + }, + { + "kind": "text", + "spelling": " " + }, + { + "kind": "identifier", + "spelling": "basicFunc" + }, + { + "kind": "text", + "spelling": "(" + }, + { + "kind": "externalParam", + "spelling": "m" + }, + { + "kind": "text", + "spelling": ": " + }, + { + "kind": "typeIdentifier", + "spelling": "String", + "preciseIdentifier": "s:SS" + }, + { + "kind": "text", + "spelling": ")" + } + ], + "accessLevel": "public", + "location": { + "uri": "file://types.swift", + "position": { + "line": 4, + "character": 12 + } + } + }, + { + "kind": { + "identifier": "swift.func", + "displayName": "Function" + }, + "identifier": { + "precise": "s:28primitive_symbolgraph_module7myFunc41m1uyx_q_tAA1ARzAaER_r0_lF", + "interfaceLanguage": "swift" + }, + "pathComponents": [ + "myFunc4(m:u:)" + ], + "names": { + "title": "myFunc4(m:u:)", + "subHeading": [ + { + "kind": "keyword", + "spelling": "func" + }, + { + "kind": "text", + "spelling": " " + }, + { + "kind": "identifier", + "spelling": "myFunc4" + }, + { + "kind": "text", + "spelling": "<" + }, + { + "kind": "genericParameter", + "spelling": "T" + }, + { + "kind": "text", + "spelling": ", " + }, + { + "kind": "genericParameter", + "spelling": "U" + }, + { + "kind": "text", + "spelling": ">(" + }, + { + "kind": "externalParam", + "spelling": "m" + }, + { + "kind": "text", + "spelling": ": " + }, + { + "kind": "typeIdentifier", + "spelling": "T", + "preciseIdentifier": "s:28primitive_symbolgraph_module7myFunc41m1uyx_q_tAA1ARzAaER_r0_lF1TL_xmfp" + }, + { + "kind": "text", + "spelling": ", " + }, + { + "kind": "externalParam", + "spelling": "u" + }, + { + "kind": "text", + "spelling": ": " + }, + { + "kind": "typeIdentifier", + "spelling": "U", + "preciseIdentifier": "s:28primitive_symbolgraph_module7myFunc41m1uyx_q_tAA1ARzAaER_r0_lF1UL_q_mfp" + }, + { + "kind": "text", + "spelling": ")" + } + ] + }, + "functionSignature": { + "parameters": [ + { + "name": "m", + "declarationFragments": [ + { + "kind": "identifier", + "spelling": "m" + }, + { + "kind": "text", + "spelling": ": " + }, + { + "kind": "typeIdentifier", + "spelling": "T", + "preciseIdentifier": "s:28primitive_symbolgraph_module7myFunc41m1uyx_q_tAA1ARzAaER_r0_lF1TL_xmfp" + } + ] + }, + { + "name": "u", + "declarationFragments": [ + { + "kind": "identifier", + "spelling": "u" + }, + { + "kind": "text", + "spelling": ": " + }, + { + "kind": "typeIdentifier", + "spelling": "U", + "preciseIdentifier": "s:28primitive_symbolgraph_module7myFunc41m1uyx_q_tAA1ARzAaER_r0_lF1UL_q_mfp" + } + ] + } + ], + "returns": [ + { + "kind": "text", + "spelling": "()" + } + ] + }, + "swiftGenerics": { + "parameters": [ + { + "name": "T", + "index": 0, + "depth": 0 + }, + { + "name": "U", + "index": 1, + "depth": 0 + } + ], + "constraints": [ + { + "kind": "conformance", + "lhs": "T", + "rhs": "A", + "rhsPrecise": "s:28primitive_symbolgraph_module1AP" + }, + { + "kind": "conformance", + "lhs": "U", + "rhs": "A", + "rhsPrecise": "s:28primitive_symbolgraph_module1AP" + } + ] + }, + "declarationFragments": [ + { + "kind": "keyword", + "spelling": "func" + }, + { + "kind": "text", + "spelling": " " + }, + { + "kind": "identifier", + "spelling": "myFunc4" + }, + { + "kind": "text", + "spelling": "<" + }, + { + "kind": "genericParameter", + "spelling": "T" + }, + { + "kind": "text", + "spelling": ", " + }, + { + "kind": "genericParameter", + "spelling": "U" + }, + { + "kind": "text", + "spelling": ">(" + }, + { + "kind": "externalParam", + "spelling": "m" + }, + { + "kind": "text", + "spelling": ": " + }, + { + "kind": "typeIdentifier", + "spelling": "T", + "preciseIdentifier": "s:28primitive_symbolgraph_module7myFunc41m1uyx_q_tAA1ARzAaER_r0_lF1TL_xmfp" + }, + { + "kind": "text", + "spelling": ", " + }, + { + "kind": "externalParam", + "spelling": "u" + }, + { + "kind": "text", + "spelling": ": " + }, + { + "kind": "typeIdentifier", + "spelling": "U", + "preciseIdentifier": "s:28primitive_symbolgraph_module7myFunc41m1uyx_q_tAA1ARzAaER_r0_lF1UL_q_mfp" + }, + { + "kind": "text", + "spelling": ") " + }, + { + "kind": "keyword", + "spelling": "where" + }, + { + "kind": "text", + "spelling": " " + }, + { + "kind": "typeIdentifier", + "spelling": "T" + }, + { + "kind": "text", + "spelling": " : " + }, + { + "kind": "typeIdentifier", + "spelling": "A", + "preciseIdentifier": "s:28primitive_symbolgraph_module1AP" + }, + { + "kind": "text", + "spelling": ", " + }, + { + "kind": "typeIdentifier", + "spelling": "U" + }, + { + "kind": "text", + "spelling": " : " + }, + { + "kind": "typeIdentifier", + "spelling": "A", + "preciseIdentifier": "s:28primitive_symbolgraph_module1AP" + } + ], + "accessLevel": "public", + "location": { + "uri": "file://types.swift", + "position": { + "line": 23, + "character": 12 + } + } + } + ], + "relationships": [] +} \ No newline at end of file From effe575bbe0b76de3b0871606af8dc0be8d6408d Mon Sep 17 00:00:00 2001 From: Nike Date: Wed, 18 Dec 2024 13:12:57 -0500 Subject: [PATCH 6/7] Implemented for compound declarations --- .../parse_compound_declaration.dart | 10 + .../parse_function_declaration.dart | 62 +- .../declaration_parsers/parse_generics.dart | 0 .../parse_variable_declaration.dart | 1 + .../parser/parsers/utils/parse_generics.dart | 60 + .../test/unit/parse_type_generics_test.dart | 28 +- .../unit/type_generics/compound.symbols.json | 1511 +++++++++++++++++ .../funcs.symbols.json} | 0 8 files changed, 1613 insertions(+), 59 deletions(-) delete mode 100644 pkgs/swift2objc/lib/src/parser/parsers/declaration_parsers/parse_generics.dart create mode 100644 pkgs/swift2objc/lib/src/parser/parsers/utils/parse_generics.dart create mode 100644 pkgs/swift2objc/test/unit/type_generics/compound.symbols.json rename pkgs/swift2objc/test/unit/{typegenerics_symbolgraph_module.symbols.json => type_generics/funcs.symbols.json} (100%) diff --git a/pkgs/swift2objc/lib/src/parser/parsers/declaration_parsers/parse_compound_declaration.dart b/pkgs/swift2objc/lib/src/parser/parsers/declaration_parsers/parse_compound_declaration.dart index 8b10ac69e1..9e9791ce8c 100644 --- a/pkgs/swift2objc/lib/src/parser/parsers/declaration_parsers/parse_compound_declaration.dart +++ b/pkgs/swift2objc/lib/src/parser/parsers/declaration_parsers/parse_compound_declaration.dart @@ -3,6 +3,7 @@ // BSD-style license that can be found in the LICENSE file. import '../../../ast/_core/interfaces/compound_declaration.dart'; +import '../../../ast/_core/shared/referred_type.dart'; import '../../../ast/declarations/compounds/class_declaration.dart'; import '../../../ast/declarations/compounds/members/initializer_declaration.dart'; import '../../../ast/declarations/compounds/members/method_declaration.dart'; @@ -12,6 +13,7 @@ import '../../_core/json.dart'; import '../../_core/parsed_symbolgraph.dart'; import '../../_core/utils.dart'; import '../parse_declarations.dart'; +import '../utils/parse_generics.dart'; typedef CompoundTearOff = T Function({ required String id, @@ -20,6 +22,7 @@ typedef CompoundTearOff = T Function({ required List properties, required List methods, required List initializers, + required List typeParams, }); T _parseCompoundDeclaration( @@ -38,10 +41,16 @@ T _parseCompoundDeclaration( methods: [], properties: [], initializers: [], + typeParams: [] ); compoundSymbol.declaration = compound; + final typeParams = parseTypeParams(compoundSymbol.json, symbolgraph); + compound.typeParams.addAll( + typeParams + ); + final memberDeclarations = compoundRelations .where( (relation) { @@ -72,6 +81,7 @@ T _parseCompoundDeclaration( compound.initializers.addAll( memberDeclarations.whereType(), ); + return compound; } diff --git a/pkgs/swift2objc/lib/src/parser/parsers/declaration_parsers/parse_function_declaration.dart b/pkgs/swift2objc/lib/src/parser/parsers/declaration_parsers/parse_function_declaration.dart index 2ff9616f35..3aaa594bbd 100644 --- a/pkgs/swift2objc/lib/src/parser/parsers/declaration_parsers/parse_function_declaration.dart +++ b/pkgs/swift2objc/lib/src/parser/parsers/declaration_parsers/parse_function_declaration.dart @@ -12,6 +12,7 @@ import '../../_core/json.dart'; import '../../_core/parsed_symbolgraph.dart'; import '../../_core/utils.dart'; import '../parse_declarations.dart'; +import '../utils/parse_generics.dart'; GlobalFunctionDeclaration parseGlobalFunctionDeclaration( Json globalFunctionSymbolJson, @@ -24,60 +25,7 @@ GlobalFunctionDeclaration parseGlobalFunctionDeclaration( _parseFunctionReturnType(globalFunctionSymbolJson, symbolgraph), params: _parseFunctionParams(globalFunctionSymbolJson, symbolgraph), typeParams: - parseFunctionTypeParams(globalFunctionSymbolJson, symbolgraph)); -} - -List parseFunctionTypeParams( - Json globalFunctionSymbolJson, - ParsedSymbolgraph symbolgraph, -) { - // get type params - final genericInfo = globalFunctionSymbolJson['swiftGenerics']; - - final parameters = genericInfo['parameters']; - - if (genericInfo.jsonWithKeyExists('constraints')) { - return parameters.map((e) { - return parseFunctionGenericType(genericInfo, e['name'].get(), - symbolgraph, globalFunctionSymbolJson); - }).toList(); - } else { - // how to make a good id for generic types - return parameters - .map((e) => GenericType( - id: e['name'].get(), name: e['name'].get())) - .toList(); - } -} - -GenericType parseFunctionGenericType(Json genericInfo, String name, - ParsedSymbolgraph symbolgraph, - Json functionSymbolJson, {String? id}) { - final constraintsDesc = genericInfo['constraints'].where( - (element) => element['lhs'].get() == name); - - return GenericType( - id: id ?? name, - name: name, - constraints: constraintsDesc.map((c) { - final constraintId = c['rhsPrecise'].get(); - - final constraintTypeSymbol = symbolgraph.symbols[constraintId]; - - if (constraintTypeSymbol == null) { - throw Exception( - 'The type constraint at path "${functionSymbolJson.path}"' - ' has a return type that does not exist among parsed symbols.', - ); - } - - final constraintDeclaration = parseDeclaration( - constraintTypeSymbol, - symbolgraph, - ) as CompoundDeclaration; - - return constraintDeclaration.asDeclaredType; - }).toList()); + parseTypeParams(globalFunctionSymbolJson, symbolgraph)); } MethodDeclaration parseMethodDeclaration( @@ -91,7 +39,7 @@ MethodDeclaration parseMethodDeclaration( returnType: _parseFunctionReturnType(methodSymbolJson, symbolgraph), params: _parseFunctionParams(methodSymbolJson, symbolgraph), hasObjCAnnotation: parseSymbolHasObjcAnnotation(methodSymbolJson), - typeParams: parseFunctionTypeParams(methodSymbolJson, symbolgraph), + typeParams: parseTypeParams(methodSymbolJson, symbolgraph), isStatic: isStatic, ); } @@ -110,7 +58,7 @@ ReferredType? _parseFunctionReturnType( final generics = methodSymbolJson['swiftGenerics']['parameters']; if (generics.map((e) => e['name'].get()).contains(type)) { // generic located - return parseFunctionGenericType(methodSymbolJson['swiftGenerics'], type, + return parseDeclGenericType(methodSymbolJson['swiftGenerics'], type, symbolgraph, methodSymbolJson); } } on Exception catch (e) { @@ -175,7 +123,7 @@ ReferredType _parseParamType( if (methodSymbolJson['swiftGenerics']['parameters'].map( (e) => e['name'].get() ).contains(typeDeclFragment['spelling'].get())) { - return parseFunctionGenericType(methodSymbolJson['swiftGenerics'], + return parseDeclGenericType(methodSymbolJson['swiftGenerics'], typeDeclFragment['spelling'].get(), symbolgraph, methodSymbolJson); } diff --git a/pkgs/swift2objc/lib/src/parser/parsers/declaration_parsers/parse_generics.dart b/pkgs/swift2objc/lib/src/parser/parsers/declaration_parsers/parse_generics.dart deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/pkgs/swift2objc/lib/src/parser/parsers/declaration_parsers/parse_variable_declaration.dart b/pkgs/swift2objc/lib/src/parser/parsers/declaration_parsers/parse_variable_declaration.dart index 783c6bb483..b430676323 100644 --- a/pkgs/swift2objc/lib/src/parser/parsers/declaration_parsers/parse_variable_declaration.dart +++ b/pkgs/swift2objc/lib/src/parser/parsers/declaration_parsers/parse_variable_declaration.dart @@ -7,6 +7,7 @@ import '../../_core/parsed_symbolgraph.dart'; import '../../_core/utils.dart'; import '../parse_declarations.dart'; +/// TODO: Support for generic types: Requires larger scope PropertyDeclaration parsePropertyDeclaration( Json propertySymbolJson, ParsedSymbolgraph symbolgraph, { diff --git a/pkgs/swift2objc/lib/src/parser/parsers/utils/parse_generics.dart b/pkgs/swift2objc/lib/src/parser/parsers/utils/parse_generics.dart new file mode 100644 index 0000000000..2b2ce76952 --- /dev/null +++ b/pkgs/swift2objc/lib/src/parser/parsers/utils/parse_generics.dart @@ -0,0 +1,60 @@ +import '../../../ast/_core/interfaces/compound_declaration.dart'; +import '../../../ast/_core/interfaces/declaration.dart'; +import '../../../ast/_core/shared/referred_type.dart'; +import '../../_core/json.dart'; +import '../../_core/parsed_symbolgraph.dart'; +import '../parse_declarations.dart'; + + +List parseTypeParams( + Json declarationSymbolJson, + ParsedSymbolgraph symbolgraph, +) { + // get type params + final genericInfo = declarationSymbolJson['swiftGenerics']; + + final parameters = genericInfo['parameters']; + + if (genericInfo.jsonWithKeyExists('constraints')) { + return parameters.map((e) { + return parseDeclGenericType(genericInfo, e['name'].get(), + symbolgraph, declarationSymbolJson); + }).toList(); + } else { + // how to make a good id for generic types + return parameters + .map((e) => GenericType( + id: e['name'].get(), name: e['name'].get())) + .toList(); + } +} + +GenericType parseDeclGenericType(Json genericInfo, String name, + ParsedSymbolgraph symbolgraph, + Json declSymbolJson, {String? id}) { + final constraintsDesc = genericInfo['constraints'].where( + (element) => element['lhs'].get() == name); + + return GenericType( + id: id ?? name, + name: name, + constraints: constraintsDesc.map((c) { + final constraintId = c['rhsPrecise'].get(); + + final constraintTypeSymbol = symbolgraph.symbols[constraintId]; + + if (constraintTypeSymbol == null) { + throw Exception( + 'The type constraint at path "${declSymbolJson.path}"' + ' has a return type that does not exist among parsed symbols.', + ); + } + + final constraintDeclaration = parseDeclaration( + constraintTypeSymbol, + symbolgraph, + ) as CompoundDeclaration; + + return constraintDeclaration.asDeclaredType; + }).toList()); +} diff --git a/pkgs/swift2objc/test/unit/parse_type_generics_test.dart b/pkgs/swift2objc/test/unit/parse_type_generics_test.dart index ee8dbae861..01aa006cd8 100644 --- a/pkgs/swift2objc/test/unit/parse_type_generics_test.dart +++ b/pkgs/swift2objc/test/unit/parse_type_generics_test.dart @@ -1,5 +1,7 @@ import 'package:path/path.dart' as p; +import 'package:swift2objc/src/ast/_core/interfaces/compound_declaration.dart'; import 'package:swift2objc/src/ast/_core/interfaces/function_declaration.dart'; +import 'package:swift2objc/src/ast/declarations/compounds/class_declaration.dart'; import 'package:swift2objc/src/parser/_core/parsed_symbolgraph.dart'; import 'package:swift2objc/src/parser/_core/utils.dart'; import 'package:swift2objc/src/parser/parsers/parse_declarations.dart'; @@ -10,8 +12,8 @@ import 'package:test/test.dart'; void main() { group('General Test: Functions', () { - final inputFile = p.join(p.current, 'test', 'unit', - 'typegenerics_symbolgraph_module.symbols.json'); + final inputFile = p.join(p.current, 'test', 'unit', 'type_generics', + 'funcs.symbols.json'); final inputJson = readJsonFile(inputFile); final symbolgraph = ParsedSymbolgraph( parseSymbolsMap(inputJson), @@ -28,4 +30,26 @@ void main() { assert(secondTestDecl.typeParams.isNotEmpty); }); }); + + + group('General Test: Compounds', () { + final inputFile = p.join(p.current, 'test', 'unit', 'type_generics', + 'compound.symbols.json'); + final inputJson = readJsonFile(inputFile); + final symbolgraph = ParsedSymbolgraph( + parseSymbolsMap(inputJson), + parseRelationsMap(inputJson), + ); + print(symbolgraph.symbols.values.map((m) => parseDeclaration(m, symbolgraph))); + final declarations = parseDeclarations(symbolgraph); + final compoundDeclarations = declarations.whereType(); + + test('Classes', () { + final classDeclarations = compoundDeclarations + .whereType(); + + final firstTest = classDeclarations.firstWhere((d) => d.name == 'A'); + assert(firstTest.typeParams.first.name == 'T'); + }); + }); } \ No newline at end of file diff --git a/pkgs/swift2objc/test/unit/type_generics/compound.symbols.json b/pkgs/swift2objc/test/unit/type_generics/compound.symbols.json new file mode 100644 index 0000000000..11cee9a7a0 --- /dev/null +++ b/pkgs/swift2objc/test/unit/type_generics/compound.symbols.json @@ -0,0 +1,1511 @@ +{ + "metadata": { + "formatVersion": { + "major": 0, + "minor": 6, + "patch": 0 + }, + "generator": "Apple Swift version 6.0.3 (swiftlang-6.0.3.1.10 clang-1600.0.30.1)" + }, + "module": { + "name": "funcs_symbolgraph_module", + "platform": { + "architecture": "arm64", + "vendor": "apple", + "operatingSystem": { + "name": "macosx", + "minimumVersion": { + "major": 15, + "minor": 0 + } + } + } + }, + "symbols": [ + { + "kind": { + "identifier": "swift.property", + "displayName": "Instance Property" + }, + "identifier": { + "precise": "s:24funcs_symbolgraph_module1CC1bxvp", + "interfaceLanguage": "swift" + }, + "pathComponents": [ + "C", + "b" + ], + "names": { + "title": "b", + "subHeading": [ + { + "kind": "keyword", + "spelling": "var" + }, + { + "kind": "text", + "spelling": " " + }, + { + "kind": "identifier", + "spelling": "b" + }, + { + "kind": "text", + "spelling": ": " + }, + { + "kind": "typeIdentifier", + "spelling": "T", + "preciseIdentifier": "s:24funcs_symbolgraph_module1CC1Txmfp" + } + ] + }, + "declarationFragments": [ + { + "kind": "keyword", + "spelling": "var" + }, + { + "kind": "text", + "spelling": " " + }, + { + "kind": "identifier", + "spelling": "b" + }, + { + "kind": "text", + "spelling": ": " + }, + { + "kind": "typeIdentifier", + "spelling": "T", + "preciseIdentifier": "s:24funcs_symbolgraph_module1CC1Txmfp" + } + ], + "accessLevel": "public", + "location": { + "uri": "file://funcs.swift", + "position": { + "line": 10, + "character": 15 + } + } + }, + { + "kind": { + "identifier": "swift.struct", + "displayName": "Structure" + }, + "identifier": { + "precise": "s:24funcs_symbolgraph_module1EV", + "interfaceLanguage": "swift" + }, + "pathComponents": [ + "E" + ], + "names": { + "title": "E", + "navigator": [ + { + "kind": "identifier", + "spelling": "E" + } + ], + "subHeading": [ + { + "kind": "keyword", + "spelling": "struct" + }, + { + "kind": "text", + "spelling": " " + }, + { + "kind": "identifier", + "spelling": "E" + } + ] + }, + "swiftGenerics": { + "parameters": [ + { + "name": "U", + "index": 0, + "depth": 0 + } + ] + }, + "declarationFragments": [ + { + "kind": "keyword", + "spelling": "struct" + }, + { + "kind": "text", + "spelling": " " + }, + { + "kind": "identifier", + "spelling": "E" + }, + { + "kind": "text", + "spelling": "<" + }, + { + "kind": "genericParameter", + "spelling": "U" + }, + { + "kind": "text", + "spelling": ">" + } + ], + "accessLevel": "public", + "location": { + "uri": "file://funcs.swift", + "position": { + "line": 21, + "character": 14 + } + } + }, + { + "kind": { + "identifier": "swift.class", + "displayName": "Class" + }, + "identifier": { + "precise": "s:24funcs_symbolgraph_module1CC", + "interfaceLanguage": "swift" + }, + "pathComponents": [ + "C" + ], + "names": { + "title": "C", + "navigator": [ + { + "kind": "identifier", + "spelling": "C" + } + ], + "subHeading": [ + { + "kind": "keyword", + "spelling": "class" + }, + { + "kind": "text", + "spelling": " " + }, + { + "kind": "identifier", + "spelling": "C" + } + ] + }, + "swiftGenerics": { + "parameters": [ + { + "name": "T", + "index": 0, + "depth": 0 + } + ], + "constraints": [ + { + "kind": "conformance", + "lhs": "T", + "rhs": "Hashable", + "rhsPrecise": "s:SH" + } + ] + }, + "declarationFragments": [ + { + "kind": "keyword", + "spelling": "class" + }, + { + "kind": "text", + "spelling": " " + }, + { + "kind": "identifier", + "spelling": "C" + }, + { + "kind": "text", + "spelling": "<" + }, + { + "kind": "genericParameter", + "spelling": "T" + }, + { + "kind": "text", + "spelling": "> " + }, + { + "kind": "keyword", + "spelling": "where" + }, + { + "kind": "text", + "spelling": " " + }, + { + "kind": "typeIdentifier", + "spelling": "T" + }, + { + "kind": "text", + "spelling": " : " + }, + { + "kind": "typeIdentifier", + "spelling": "Hashable", + "preciseIdentifier": "s:SH" + } + ], + "accessLevel": "public", + "location": { + "uri": "file://funcs.swift", + "position": { + "line": 8, + "character": 13 + } + } + }, + { + "kind": { + "identifier": "swift.method", + "displayName": "Instance Method" + }, + "identifier": { + "precise": "s:24funcs_symbolgraph_module1EV1e1m1nyx_qd__tlF", + "interfaceLanguage": "swift" + }, + "pathComponents": [ + "E", + "e(m:n:)" + ], + "names": { + "title": "e(m:n:)", + "subHeading": [ + { + "kind": "keyword", + "spelling": "func" + }, + { + "kind": "text", + "spelling": " " + }, + { + "kind": "identifier", + "spelling": "e" + }, + { + "kind": "text", + "spelling": "<" + }, + { + "kind": "genericParameter", + "spelling": "V" + }, + { + "kind": "text", + "spelling": ">(" + }, + { + "kind": "externalParam", + "spelling": "m" + }, + { + "kind": "text", + "spelling": ": " + }, + { + "kind": "typeIdentifier", + "spelling": "U", + "preciseIdentifier": "s:24funcs_symbolgraph_module1EV1Uxmfp" + }, + { + "kind": "text", + "spelling": ", " + }, + { + "kind": "externalParam", + "spelling": "n" + }, + { + "kind": "text", + "spelling": ": " + }, + { + "kind": "typeIdentifier", + "spelling": "V", + "preciseIdentifier": "s:24funcs_symbolgraph_module1EV1e1m1nyx_qd__tlF1VL_qd__mfp" + }, + { + "kind": "text", + "spelling": ")" + } + ] + }, + "functionSignature": { + "parameters": [ + { + "name": "m", + "declarationFragments": [ + { + "kind": "identifier", + "spelling": "m" + }, + { + "kind": "text", + "spelling": ": " + }, + { + "kind": "typeIdentifier", + "spelling": "U", + "preciseIdentifier": "s:24funcs_symbolgraph_module1EV1Uxmfp" + } + ] + }, + { + "name": "n", + "declarationFragments": [ + { + "kind": "identifier", + "spelling": "n" + }, + { + "kind": "text", + "spelling": ": " + }, + { + "kind": "typeIdentifier", + "spelling": "V", + "preciseIdentifier": "s:24funcs_symbolgraph_module1EV1e1m1nyx_qd__tlF1VL_qd__mfp" + } + ] + } + ], + "returns": [ + { + "kind": "text", + "spelling": "()" + } + ] + }, + "swiftGenerics": { + "parameters": [ + { + "name": "U", + "index": 0, + "depth": 0 + }, + { + "name": "V", + "index": 0, + "depth": 1 + } + ] + }, + "declarationFragments": [ + { + "kind": "keyword", + "spelling": "func" + }, + { + "kind": "text", + "spelling": " " + }, + { + "kind": "identifier", + "spelling": "e" + }, + { + "kind": "text", + "spelling": "<" + }, + { + "kind": "genericParameter", + "spelling": "V" + }, + { + "kind": "text", + "spelling": ">(" + }, + { + "kind": "externalParam", + "spelling": "m" + }, + { + "kind": "text", + "spelling": ": " + }, + { + "kind": "typeIdentifier", + "spelling": "U", + "preciseIdentifier": "s:24funcs_symbolgraph_module1EV1Uxmfp" + }, + { + "kind": "text", + "spelling": ", " + }, + { + "kind": "externalParam", + "spelling": "n" + }, + { + "kind": "text", + "spelling": ": " + }, + { + "kind": "typeIdentifier", + "spelling": "V", + "preciseIdentifier": "s:24funcs_symbolgraph_module1EV1e1m1nyx_qd__tlF1VL_qd__mfp" + }, + { + "kind": "text", + "spelling": ")" + } + ], + "accessLevel": "public", + "location": { + "uri": "file://funcs.swift", + "position": { + "line": 22, + "character": 16 + } + } + }, + { + "kind": { + "identifier": "swift.method", + "displayName": "Instance Method" + }, + "identifier": { + "precise": "s:24funcs_symbolgraph_module1CC1a1myx_tF", + "interfaceLanguage": "swift" + }, + "pathComponents": [ + "C", + "a(m:)" + ], + "names": { + "title": "a(m:)", + "subHeading": [ + { + "kind": "keyword", + "spelling": "func" + }, + { + "kind": "text", + "spelling": " " + }, + { + "kind": "identifier", + "spelling": "a" + }, + { + "kind": "text", + "spelling": "(" + }, + { + "kind": "externalParam", + "spelling": "m" + }, + { + "kind": "text", + "spelling": ": " + }, + { + "kind": "typeIdentifier", + "spelling": "T", + "preciseIdentifier": "s:24funcs_symbolgraph_module1CC1Txmfp" + }, + { + "kind": "text", + "spelling": ")" + } + ] + }, + "functionSignature": { + "parameters": [ + { + "name": "m", + "declarationFragments": [ + { + "kind": "identifier", + "spelling": "m" + }, + { + "kind": "text", + "spelling": ": " + }, + { + "kind": "typeIdentifier", + "spelling": "T", + "preciseIdentifier": "s:24funcs_symbolgraph_module1CC1Txmfp" + } + ] + } + ], + "returns": [ + { + "kind": "text", + "spelling": "()" + } + ] + }, + "swiftGenerics": { + "parameters": [ + { + "name": "T", + "index": 0, + "depth": 0 + } + ], + "constraints": [ + { + "kind": "conformance", + "lhs": "T", + "rhs": "Hashable", + "rhsPrecise": "s:SH" + } + ] + }, + "declarationFragments": [ + { + "kind": "keyword", + "spelling": "func" + }, + { + "kind": "text", + "spelling": " " + }, + { + "kind": "identifier", + "spelling": "a" + }, + { + "kind": "text", + "spelling": "(" + }, + { + "kind": "externalParam", + "spelling": "m" + }, + { + "kind": "text", + "spelling": ": " + }, + { + "kind": "typeIdentifier", + "spelling": "T", + "preciseIdentifier": "s:24funcs_symbolgraph_module1CC1Txmfp" + }, + { + "kind": "text", + "spelling": ")" + } + ], + "accessLevel": "public", + "location": { + "uri": "file://funcs.swift", + "position": { + "line": 9, + "character": 16 + } + } + }, + { + "kind": { + "identifier": "swift.init", + "displayName": "Initializer" + }, + "identifier": { + "precise": "s:24funcs_symbolgraph_module1CC1bACyxGx_tcfc", + "interfaceLanguage": "swift" + }, + "pathComponents": [ + "C", + "init(b:)" + ], + "names": { + "title": "init(b:)", + "subHeading": [ + { + "kind": "keyword", + "spelling": "init" + }, + { + "kind": "text", + "spelling": "(" + }, + { + "kind": "externalParam", + "spelling": "b" + }, + { + "kind": "text", + "spelling": ": " + }, + { + "kind": "typeIdentifier", + "spelling": "T", + "preciseIdentifier": "s:24funcs_symbolgraph_module1CC1Txmfp" + }, + { + "kind": "text", + "spelling": ")" + } + ] + }, + "functionSignature": { + "parameters": [ + { + "name": "b", + "declarationFragments": [ + { + "kind": "identifier", + "spelling": "b" + }, + { + "kind": "text", + "spelling": ": " + }, + { + "kind": "typeIdentifier", + "spelling": "T", + "preciseIdentifier": "s:24funcs_symbolgraph_module1CC1Txmfp" + } + ] + } + ] + }, + "swiftGenerics": { + "parameters": [ + { + "name": "T", + "index": 0, + "depth": 0 + } + ], + "constraints": [ + { + "kind": "conformance", + "lhs": "T", + "rhs": "Hashable", + "rhsPrecise": "s:SH" + } + ] + }, + "declarationFragments": [ + { + "kind": "keyword", + "spelling": "init" + }, + { + "kind": "text", + "spelling": "(" + }, + { + "kind": "externalParam", + "spelling": "b" + }, + { + "kind": "text", + "spelling": ": " + }, + { + "kind": "typeIdentifier", + "spelling": "T", + "preciseIdentifier": "s:24funcs_symbolgraph_module1CC1Txmfp" + }, + { + "kind": "text", + "spelling": ")" + } + ], + "accessLevel": "public", + "location": { + "uri": "file://funcs.swift", + "position": { + "line": 12, + "character": 11 + } + } + }, + { + "kind": { + "identifier": "swift.class", + "displayName": "Class" + }, + "identifier": { + "precise": "s:24funcs_symbolgraph_module1AC", + "interfaceLanguage": "swift" + }, + "pathComponents": [ + "A" + ], + "names": { + "title": "A", + "navigator": [ + { + "kind": "identifier", + "spelling": "A" + } + ], + "subHeading": [ + { + "kind": "keyword", + "spelling": "class" + }, + { + "kind": "text", + "spelling": " " + }, + { + "kind": "identifier", + "spelling": "A" + } + ] + }, + "swiftGenerics": { + "parameters": [ + { + "name": "T", + "index": 0, + "depth": 0 + } + ] + }, + "declarationFragments": [ + { + "kind": "keyword", + "spelling": "class" + }, + { + "kind": "text", + "spelling": " " + }, + { + "kind": "identifier", + "spelling": "A" + }, + { + "kind": "text", + "spelling": "<" + }, + { + "kind": "genericParameter", + "spelling": "T" + }, + { + "kind": "text", + "spelling": ">" + } + ], + "accessLevel": "public", + "location": { + "uri": "file://funcs.swift", + "position": { + "line": 0, + "character": 13 + } + } + }, + { + "kind": { + "identifier": "swift.method", + "displayName": "Instance Method" + }, + "identifier": { + "precise": "s:24funcs_symbolgraph_module1DCAASjRzSjR_rlE1e1m1n1oyx_q_qd__tSlRd__lF", + "interfaceLanguage": "swift" + }, + "pathComponents": [ + "D", + "e(m:n:o:)" + ], + "names": { + "title": "e(m:n:o:)", + "subHeading": [ + { + "kind": "keyword", + "spelling": "func" + }, + { + "kind": "text", + "spelling": " " + }, + { + "kind": "identifier", + "spelling": "e" + }, + { + "kind": "text", + "spelling": "<" + }, + { + "kind": "genericParameter", + "spelling": "V" + }, + { + "kind": "text", + "spelling": ">(" + }, + { + "kind": "externalParam", + "spelling": "m" + }, + { + "kind": "text", + "spelling": ": " + }, + { + "kind": "typeIdentifier", + "spelling": "T", + "preciseIdentifier": "s:24funcs_symbolgraph_module1DCAASjRzSjR_rlE1Txmfp" + }, + { + "kind": "text", + "spelling": ", " + }, + { + "kind": "externalParam", + "spelling": "n" + }, + { + "kind": "text", + "spelling": ": " + }, + { + "kind": "typeIdentifier", + "spelling": "U", + "preciseIdentifier": "s:24funcs_symbolgraph_module1DCAASjRzSjR_rlE1Uq_mfp" + }, + { + "kind": "text", + "spelling": ", " + }, + { + "kind": "externalParam", + "spelling": "o" + }, + { + "kind": "text", + "spelling": ": " + }, + { + "kind": "typeIdentifier", + "spelling": "V", + "preciseIdentifier": "s:24funcs_symbolgraph_module1DCAASjRzSjR_rlE1e1m1n1oyx_q_qd__tSlRd__lF1VL_qd__mfp" + }, + { + "kind": "text", + "spelling": ")" + } + ] + }, + "functionSignature": { + "parameters": [ + { + "name": "m", + "declarationFragments": [ + { + "kind": "identifier", + "spelling": "m" + }, + { + "kind": "text", + "spelling": ": " + }, + { + "kind": "typeIdentifier", + "spelling": "T", + "preciseIdentifier": "s:24funcs_symbolgraph_module1DCAASjRzSjR_rlE1Txmfp" + } + ] + }, + { + "name": "n", + "declarationFragments": [ + { + "kind": "identifier", + "spelling": "n" + }, + { + "kind": "text", + "spelling": ": " + }, + { + "kind": "typeIdentifier", + "spelling": "U", + "preciseIdentifier": "s:24funcs_symbolgraph_module1DCAASjRzSjR_rlE1Uq_mfp" + } + ] + }, + { + "name": "o", + "declarationFragments": [ + { + "kind": "identifier", + "spelling": "o" + }, + { + "kind": "text", + "spelling": ": " + }, + { + "kind": "typeIdentifier", + "spelling": "V", + "preciseIdentifier": "s:24funcs_symbolgraph_module1DCAASjRzSjR_rlE1e1m1n1oyx_q_qd__tSlRd__lF1VL_qd__mfp" + } + ] + } + ], + "returns": [ + { + "kind": "text", + "spelling": "()" + } + ] + }, + "swiftGenerics": { + "parameters": [ + { + "name": "T", + "index": 0, + "depth": 0 + }, + { + "name": "U", + "index": 1, + "depth": 0 + }, + { + "name": "V", + "index": 0, + "depth": 1 + } + ], + "constraints": [ + { + "kind": "conformance", + "lhs": "T", + "rhs": "Numeric", + "rhsPrecise": "s:Sj" + }, + { + "kind": "conformance", + "lhs": "U", + "rhs": "Numeric", + "rhsPrecise": "s:Sj" + }, + { + "kind": "conformance", + "lhs": "V", + "rhs": "Collection", + "rhsPrecise": "s:Sl" + } + ] + }, + "swiftExtension": { + "extendedModule": "funcs_symbolgraph_module", + "typeKind": "swift.class", + "constraints": [ + { + "kind": "conformance", + "lhs": "T", + "rhs": "Numeric", + "rhsPrecise": "s:Sj" + }, + { + "kind": "conformance", + "lhs": "U", + "rhs": "Numeric", + "rhsPrecise": "s:Sj" + } + ] + }, + "declarationFragments": [ + { + "kind": "keyword", + "spelling": "func" + }, + { + "kind": "text", + "spelling": " " + }, + { + "kind": "identifier", + "spelling": "e" + }, + { + "kind": "text", + "spelling": "<" + }, + { + "kind": "genericParameter", + "spelling": "V" + }, + { + "kind": "text", + "spelling": ">(" + }, + { + "kind": "externalParam", + "spelling": "m" + }, + { + "kind": "text", + "spelling": ": " + }, + { + "kind": "typeIdentifier", + "spelling": "T", + "preciseIdentifier": "s:24funcs_symbolgraph_module1DCAASjRzSjR_rlE1Txmfp" + }, + { + "kind": "text", + "spelling": ", " + }, + { + "kind": "externalParam", + "spelling": "n" + }, + { + "kind": "text", + "spelling": ": " + }, + { + "kind": "typeIdentifier", + "spelling": "U", + "preciseIdentifier": "s:24funcs_symbolgraph_module1DCAASjRzSjR_rlE1Uq_mfp" + }, + { + "kind": "text", + "spelling": ", " + }, + { + "kind": "externalParam", + "spelling": "o" + }, + { + "kind": "text", + "spelling": ": " + }, + { + "kind": "typeIdentifier", + "spelling": "V", + "preciseIdentifier": "s:24funcs_symbolgraph_module1DCAASjRzSjR_rlE1e1m1n1oyx_q_qd__tSlRd__lF1VL_qd__mfp" + }, + { + "kind": "text", + "spelling": ") " + }, + { + "kind": "keyword", + "spelling": "where" + }, + { + "kind": "text", + "spelling": " " + }, + { + "kind": "typeIdentifier", + "spelling": "V" + }, + { + "kind": "text", + "spelling": " : " + }, + { + "kind": "typeIdentifier", + "spelling": "Collection", + "preciseIdentifier": "s:Sl" + } + ], + "accessLevel": "public", + "location": { + "uri": "file://funcs.swift", + "position": { + "line": 30, + "character": 9 + } + } + }, + { + "kind": { + "identifier": "swift.class", + "displayName": "Class" + }, + "identifier": { + "precise": "s:24funcs_symbolgraph_module1DC", + "interfaceLanguage": "swift" + }, + "pathComponents": [ + "D" + ], + "names": { + "title": "D", + "navigator": [ + { + "kind": "identifier", + "spelling": "D" + } + ], + "subHeading": [ + { + "kind": "keyword", + "spelling": "class" + }, + { + "kind": "text", + "spelling": " " + }, + { + "kind": "identifier", + "spelling": "D" + } + ] + }, + "swiftGenerics": { + "parameters": [ + { + "name": "T", + "index": 0, + "depth": 0 + }, + { + "name": "U", + "index": 1, + "depth": 0 + } + ] + }, + "declarationFragments": [ + { + "kind": "keyword", + "spelling": "class" + }, + { + "kind": "text", + "spelling": " " + }, + { + "kind": "identifier", + "spelling": "D" + }, + { + "kind": "text", + "spelling": "<" + }, + { + "kind": "genericParameter", + "spelling": "T" + }, + { + "kind": "text", + "spelling": ", " + }, + { + "kind": "genericParameter", + "spelling": "U" + }, + { + "kind": "text", + "spelling": ">" + } + ], + "accessLevel": "public", + "location": { + "uri": "file://funcs.swift", + "position": { + "line": 17, + "character": 13 + } + } + }, + { + "kind": { + "identifier": "swift.method", + "displayName": "Instance Method" + }, + "identifier": { + "precise": "s:24funcs_symbolgraph_module1AC1a1myx_tF", + "interfaceLanguage": "swift" + }, + "pathComponents": [ + "A", + "a(m:)" + ], + "names": { + "title": "a(m:)", + "subHeading": [ + { + "kind": "keyword", + "spelling": "func" + }, + { + "kind": "text", + "spelling": " " + }, + { + "kind": "identifier", + "spelling": "a" + }, + { + "kind": "text", + "spelling": "(" + }, + { + "kind": "externalParam", + "spelling": "m" + }, + { + "kind": "text", + "spelling": ": " + }, + { + "kind": "typeIdentifier", + "spelling": "T", + "preciseIdentifier": "s:24funcs_symbolgraph_module1AC1Txmfp" + }, + { + "kind": "text", + "spelling": ")" + } + ] + }, + "functionSignature": { + "parameters": [ + { + "name": "m", + "declarationFragments": [ + { + "kind": "identifier", + "spelling": "m" + }, + { + "kind": "text", + "spelling": ": " + }, + { + "kind": "typeIdentifier", + "spelling": "T", + "preciseIdentifier": "s:24funcs_symbolgraph_module1AC1Txmfp" + } + ] + } + ], + "returns": [ + { + "kind": "text", + "spelling": "()" + } + ] + }, + "swiftGenerics": { + "parameters": [ + { + "name": "T", + "index": 0, + "depth": 0 + } + ] + }, + "declarationFragments": [ + { + "kind": "keyword", + "spelling": "func" + }, + { + "kind": "text", + "spelling": " " + }, + { + "kind": "identifier", + "spelling": "a" + }, + { + "kind": "text", + "spelling": "(" + }, + { + "kind": "externalParam", + "spelling": "m" + }, + { + "kind": "text", + "spelling": ": " + }, + { + "kind": "typeIdentifier", + "spelling": "T", + "preciseIdentifier": "s:24funcs_symbolgraph_module1AC1Txmfp" + }, + { + "kind": "text", + "spelling": ")" + } + ], + "accessLevel": "public", + "location": { + "uri": "file://funcs.swift", + "position": { + "line": 1, + "character": 16 + } + } + }, + { + "kind": { + "identifier": "swift.struct", + "displayName": "Structure" + }, + "identifier": { + "precise": "s:24funcs_symbolgraph_module1BV", + "interfaceLanguage": "swift" + }, + "pathComponents": [ + "B" + ], + "names": { + "title": "B", + "navigator": [ + { + "kind": "identifier", + "spelling": "B" + } + ], + "subHeading": [ + { + "kind": "keyword", + "spelling": "struct" + }, + { + "kind": "text", + "spelling": " " + }, + { + "kind": "identifier", + "spelling": "B" + } + ] + }, + "swiftGenerics": { + "parameters": [ + { + "name": "T", + "index": 0, + "depth": 0 + } + ], + "constraints": [ + { + "kind": "conformance", + "lhs": "T", + "rhs": "Hashable", + "rhsPrecise": "s:SH" + } + ] + }, + "declarationFragments": [ + { + "kind": "keyword", + "spelling": "struct" + }, + { + "kind": "text", + "spelling": " " + }, + { + "kind": "identifier", + "spelling": "B" + }, + { + "kind": "text", + "spelling": "<" + }, + { + "kind": "genericParameter", + "spelling": "T" + }, + { + "kind": "text", + "spelling": "> " + }, + { + "kind": "keyword", + "spelling": "where" + }, + { + "kind": "text", + "spelling": " " + }, + { + "kind": "typeIdentifier", + "spelling": "T" + }, + { + "kind": "text", + "spelling": " : " + }, + { + "kind": "typeIdentifier", + "spelling": "Hashable", + "preciseIdentifier": "s:SH" + } + ], + "accessLevel": "public", + "location": { + "uri": "file://funcs.swift", + "position": { + "line": 4, + "character": 14 + } + } + } + ], + "relationships": [ + { + "kind": "memberOf", + "source": "s:24funcs_symbolgraph_module1CC1a1myx_tF", + "target": "s:24funcs_symbolgraph_module1CC" + }, + { + "kind": "memberOf", + "source": "s:24funcs_symbolgraph_module1CC1bACyxGx_tcfc", + "target": "s:24funcs_symbolgraph_module1CC" + }, + { + "kind": "memberOf", + "source": "s:24funcs_symbolgraph_module1DCAASjRzSjR_rlE1e1m1n1oyx_q_qd__tSlRd__lF", + "target": "s:24funcs_symbolgraph_module1DC" + }, + { + "kind": "memberOf", + "source": "s:24funcs_symbolgraph_module1AC1a1myx_tF", + "target": "s:24funcs_symbolgraph_module1AC" + }, + { + "kind": "memberOf", + "source": "s:24funcs_symbolgraph_module1EV1e1m1nyx_qd__tlF", + "target": "s:24funcs_symbolgraph_module1EV" + }, + { + "kind": "memberOf", + "source": "s:24funcs_symbolgraph_module1CC1bxvp", + "target": "s:24funcs_symbolgraph_module1CC" + } + ] +} \ No newline at end of file diff --git a/pkgs/swift2objc/test/unit/typegenerics_symbolgraph_module.symbols.json b/pkgs/swift2objc/test/unit/type_generics/funcs.symbols.json similarity index 100% rename from pkgs/swift2objc/test/unit/typegenerics_symbolgraph_module.symbols.json rename to pkgs/swift2objc/test/unit/type_generics/funcs.symbols.json From dfec00a98daac6a2cd40626f0731aa0447734b70 Mon Sep 17 00:00:00 2001 From: Nike Okoronkwo Date: Sun, 26 Jan 2025 20:39:00 -0600 Subject: [PATCH 7/7] minor additions --- .../lib/src/ast/_core/shared/referred_type.dart | 1 + .../declaration_parsers/parse_compound_declaration.dart | 2 +- .../declaration_parsers/parse_function_declaration.dart | 8 ++++---- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/pkgs/swift2objc/lib/src/ast/_core/shared/referred_type.dart b/pkgs/swift2objc/lib/src/ast/_core/shared/referred_type.dart index ca2eea2f70..35e888ef29 100644 --- a/pkgs/swift2objc/lib/src/ast/_core/shared/referred_type.dart +++ b/pkgs/swift2objc/lib/src/ast/_core/shared/referred_type.dart @@ -2,6 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. +import '../interfaces/compound_declaration.dart'; import '../interfaces/declaration.dart'; import '../interfaces/nestable_declaration.dart'; import '../interfaces/objc_annotatable.dart'; diff --git a/pkgs/swift2objc/lib/src/parser/parsers/declaration_parsers/parse_compound_declaration.dart b/pkgs/swift2objc/lib/src/parser/parsers/declaration_parsers/parse_compound_declaration.dart index 6cb0d5d97e..8278daf7f0 100644 --- a/pkgs/swift2objc/lib/src/parser/parsers/declaration_parsers/parse_compound_declaration.dart +++ b/pkgs/swift2objc/lib/src/parser/parsers/declaration_parsers/parse_compound_declaration.dart @@ -40,7 +40,7 @@ T _parseCompoundDeclaration( methods: [], properties: [], initializers: [], - typeParams: [] + typeParams: [], nestedDeclarations: [], ); diff --git a/pkgs/swift2objc/lib/src/parser/parsers/declaration_parsers/parse_function_declaration.dart b/pkgs/swift2objc/lib/src/parser/parsers/declaration_parsers/parse_function_declaration.dart index feec8ba9f5..f6062b4240 100644 --- a/pkgs/swift2objc/lib/src/parser/parsers/declaration_parsers/parse_function_declaration.dart +++ b/pkgs/swift2objc/lib/src/parser/parsers/declaration_parsers/parse_function_declaration.dart @@ -26,10 +26,10 @@ GlobalFunctionDeclaration parseGlobalFunctionDeclaration( id: parseSymbolId(globalFunctionSymbolJson), name: parseSymbolName(globalFunctionSymbolJson), returnType: _parseFunctionReturnType(globalFunctionSymbolJson, symbolgraph), -// params: info.params, -// throws: info.throws, -// async: info.async, - params: _parseFunctionParams(globalFunctionSymbolJson symbolgraph) + // params: info.params, + // throws: info.throws, + // async: info.async, + params: _parseFunctionParams(globalFunctionSymbolJson, symbolgraph), typeParams: parseTypeParams(globalFunctionSymbolJson, symbolgraph) );