-
Notifications
You must be signed in to change notification settings - Fork 75
[swift2objc] Support Protocols #1832
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nikeokoronkwo
wants to merge
18
commits into
dart-lang:main
Choose a base branch
from
nikeokoronkwo:swift2objc-protocols
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
b0c806f
Initial commit for branch
nikeokoronkwo 6f6d50f
implemented parsing basic protocols with inheritance (conformance)
nikeokoronkwo 2370826
Merge branch 'main' into swift2objc-protocols
nikeokoronkwo fa00ec4
added support for associated type
nikeokoronkwo be6b8c8
completed Protocol Declaration parsing
nikeokoronkwo 1e2f855
completed setting up tests
nikeokoronkwo c2c4c6d
removed redundant/completed TODO
nikeokoronkwo 354bb50
Added related issues for dangling TODOs
nikeokoronkwo d75dc8b
Search for superclass and inherit, fallback on NSObject if no superclass
nikeokoronkwo d441639
Added Protocol Transformation and Generation
nikeokoronkwo a312c76
Formatting and Fixing
nikeokoronkwo fae3b99
Merge branch 'main' into swift2objc-protocols
nikeokoronkwo 9b5c264
Removed dangling TODO
nikeokoronkwo e9c299e
Merge branch 'swift2objc-protocols' of https://github.com/nikeokoronk…
nikeokoronkwo ecd7bfd
Formatted files
nikeokoronkwo 4db39a7
Updated TODOs, referencing a pull request
nikeokoronkwo cb34323
Merge branch 'main' into swift2objc-protocols
nikeokoronkwo 478d543
Made changes to protocol
nikeokoronkwo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
pkgs/swift2objc/lib/src/ast/declarations/compounds/members/associated_type_declaration.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import '../../../_core/interfaces/declaration.dart'; | ||
import '../../../_core/shared/referred_type.dart'; | ||
import '../../../ast_node.dart'; | ||
import '../protocol_declaration.dart'; | ||
|
||
class AssociatedTypeDeclaration extends AstNode implements Declaration { | ||
@override | ||
String id; | ||
|
||
@override | ||
String name; | ||
|
||
List<DeclaredType<ProtocolDeclaration>> conformedProtocols; | ||
|
||
AssociatedTypeDeclaration( | ||
{required this.id, required this.name, required this.conformedProtocols}); | ||
} | ||
|
||
extension AsAssociatedType<T extends AssociatedTypeDeclaration> on T { | ||
AssociatedType asType() => AssociatedType( | ||
id: id, name: name, conformedProtocols: conformedProtocols); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...ft2objc/lib/src/parser/parsers/declaration_parsers/parse_associated_type_declaration.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file | ||
// 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/declaration.dart'; | ||
import '../../../ast/_core/shared/referred_type.dart'; | ||
import '../../../ast/declarations/compounds/members/associated_type_declaration.dart'; | ||
import '../../../ast/declarations/compounds/protocol_declaration.dart'; | ||
import '../../_core/json.dart'; | ||
import '../../_core/parsed_symbolgraph.dart'; | ||
import '../../_core/utils.dart'; | ||
import '../parse_declarations.dart'; | ||
|
||
AssociatedTypeDeclaration parseAssociatedTypeDeclaration( | ||
Json symbolJson, ParsedSymbolgraph symbolGraph) { | ||
final id = parseSymbolId(symbolJson); | ||
final name = parseSymbolName(symbolJson); | ||
|
||
final conformedProtocols = _parseConformedProtocols(symbolJson, symbolGraph); | ||
|
||
return AssociatedTypeDeclaration( | ||
id: id, name: name, conformedProtocols: conformedProtocols); | ||
} | ||
|
||
List<DeclaredType<ProtocolDeclaration>> _parseConformedProtocols( | ||
Json symbolJson, ParsedSymbolgraph symbolGraph) { | ||
final conformDecls = <DeclaredType<ProtocolDeclaration>>[]; | ||
|
||
final identifierIndex = symbolJson['declarationFragments'] | ||
.toList() | ||
.indexWhere((t) => | ||
t['kind'].get<String>() == 'identifier' && | ||
t['spelling'].get<String>() == 'Element'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Confused by this. Seems like this will only work for an associated type that is literally named |
||
|
||
if (symbolJson['declarationFragments'].length - 1 > identifierIndex && | ||
symbolJson['declarationFragments'][identifierIndex + 1]['spelling'] | ||
.get<String>() | ||
.trim() == | ||
':') { | ||
// the associated type contains | ||
final conformList = symbolJson['declarationFragments'] | ||
.toList() | ||
.sublist(identifierIndex + 2); | ||
conformList.removeWhere((t) => t['spelling'].get<String>().trim() == ','); | ||
|
||
// go through and find, then add | ||
for (final proto in conformList) { | ||
final protoId = proto['preciseIdentifier'].get<String>(); | ||
|
||
final protoSymbol = symbolGraph.symbols[protoId]; | ||
|
||
if (protoSymbol == null) { | ||
// return null; | ||
continue; | ||
} | ||
|
||
conformDecls.add( | ||
(tryParseDeclaration(protoSymbol, symbolGraph) as ProtocolDeclaration) | ||
.asDeclaredType); | ||
} | ||
} | ||
|
||
return conformDecls; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.