Skip to content

Commit

Permalink
Implicit supers
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanblake4 committed Nov 25, 2024
1 parent 46df712 commit 468e418
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 5 deletions.
4 changes: 3 additions & 1 deletion lib/src/eval/bindgen/bridge_declaration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ String? bindBridgeDeclaration(BindgenContext ctx, ClassElement element) {
}

var extendsStr = '';
if (element.supertype != null && !element.supertype!.isDartCoreObject) {
if (element.supertype != null &&
!element.supertype!.isDartCoreObject &&
!ctx.implicitSupers) {
extendsStr =
'\n\$extends: ${bridgeTypeRefFromType(ctx, element.supertype!)},';
}
Expand Down
5 changes: 3 additions & 2 deletions lib/src/eval/bindgen/parameters.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@ String _parameterFrom(BindgenContext ctx, ParameterElement parameter) {
''';
}

String argumentAccessors(BindgenContext ctx, List<ParameterElement> params) {
String argumentAccessors(BindgenContext ctx, List<ParameterElement> params,
{Map<String, String> paramMapping = const {}}) {
final paramBuffer = StringBuffer();
for (var i = 0; i < params.length; i++) {
final param = params[i];
if (param.isNamed) {
paramBuffer.write('${param.name}: ');
paramBuffer.write('${paramMapping[param.name] ?? param.name}: ');
}
final type = param.type;
if (type.isDartCoreFunction || type is FunctionType) {
Expand Down
17 changes: 17 additions & 0 deletions lib/src/eval/bindgen/statics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,23 @@ String _$constructor(
constructor.name.isNotEmpty ? '.${constructor.name}' : '';
final fullyQualifiedConstructorId = '${element.name}$namedConstructor';

final oConstructor = constructor;

final paramMapping = <String, String>{};
for (var i = 0; i < constructor.parameters.length; i++) {
final param = constructor.parameters[i];
paramMapping[param.name] = param.name;
}

while (constructor.redirectedConstructor != null) {
constructor = constructor.redirectedConstructor!;
for (var i = 0; i < constructor.parameters.length; i++) {
final param = constructor.parameters[i];
final oParam = oConstructor.parameters[i];
paramMapping[param.name] = oParam.name;
}
}

return '''
/// Wrapper for the [${element.name}.$name] constructor
static \$Value? \$$name(Runtime runtime, \$Value? thisValue, List<\$Value?> args) {
Expand Down
3 changes: 2 additions & 1 deletion lib/src/eval/bindgen/type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ String? wrapType(BindgenContext ctx, DartType type, String expr,
final typeEl = type.element;
if (typeEl is ClassElement &&
typeEl.metadata.any((e) => e.element?.displayName == 'Bind')) {
ctx.imports.add(typeEl.library.source.uri.toString());
ctx.imports.add(
typeEl.library.source.uri.toString().replaceAll('.dart', '.eval.dart'));
return '${unionStr}\$$name.wrap($expr)';
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/eval/cli/bind.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import 'package:pubspec_parse/pubspec_parse.dart';
const defaultImports = '''
// ignore_for_file: unused_import
// ignore_for_file: unnecessary_import
// ignore_for_file: no_leading_underscores_for_local_identifiers
import 'package:dart_eval/dart_eval.dart';
import 'package:dart_eval/dart_eval_bridge.dart';
Expand Down

0 comments on commit 468e418

Please sign in to comment.