Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(209)

Side by Side Diff: pkg/dev_compiler/lib/src/compiler/code_generator.dart

Issue 2613383003: Add support for generic function type syntax, part 1 (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/dev_compiler/lib/src/compiler/ast_builder.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 2
3 // for details. All rights reserved. Use of this source code is governed by a 3 // for details. All rights reserved. Use of this source code is governed by a
4 // BSD-style license that can be found in the LICENSE file. 4 // BSD-style license that can be found in the LICENSE file.
5 5
6 import 'dart:collection' show HashMap, HashSet; 6 import 'dart:collection' show HashMap, HashSet;
7 import 'dart:math' show min, max; 7 import 'dart:math' show min, max;
8 8
9 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; 9 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator;
10 import 'package:analyzer/dart/ast/ast.dart'; 10 import 'package:analyzer/dart/ast/ast.dart';
(...skipping 3596 matching lines...) Expand 10 before | Expand all | Expand 10 after
3607 List<JS.Expression> _emitFunctionTypeArguments(DartType g, DartType f, 3607 List<JS.Expression> _emitFunctionTypeArguments(DartType g, DartType f,
3608 [TypeArgumentList typeArgs]) { 3608 [TypeArgumentList typeArgs]) {
3609 if (g is FunctionType && 3609 if (g is FunctionType &&
3610 g.typeFormals.isNotEmpty && 3610 g.typeFormals.isNotEmpty &&
3611 f is FunctionType && 3611 f is FunctionType &&
3612 f.typeFormals.isEmpty) { 3612 f.typeFormals.isEmpty) {
3613 return _recoverTypeArguments(g, f).map(_emitType).toList(growable: false); 3613 return _recoverTypeArguments(g, f).map(_emitType).toList(growable: false);
3614 } else if (typeArgs != null) { 3614 } else if (typeArgs != null) {
3615 // Dynamic calls may have type arguments, even though the function types 3615 // Dynamic calls may have type arguments, even though the function types
3616 // are not known. 3616 // are not known.
3617 return typeArgs.arguments.map(visitTypeName).toList(growable: false); 3617 return typeArgs.arguments.map((argument) {
3618 if (argument is TypeName) {
3619 return visitTypeName(argument);
3620 } else {
3621 // TODO(brianwilkerson) Implement support for GenericFunctionType.
3622 throw new StateError(
3623 'Cannot compile type argument of kind ${argument.runtimeType}');
3624 }
3625 }).toList(growable: false);
3618 } 3626 }
3619 return null; 3627 return null;
3620 } 3628 }
3621 3629
3622 /// Given a generic function type [g] and an instantiated function type [f], 3630 /// Given a generic function type [g] and an instantiated function type [f],
3623 /// find a list of type arguments TArgs such that `g<TArgs> == f`, 3631 /// find a list of type arguments TArgs such that `g<TArgs> == f`,
3624 /// and return TArgs. 3632 /// and return TArgs.
3625 /// 3633 ///
3626 /// This function must be called with type [f] that was instantiated from [g]. 3634 /// This function must be called with type [f] that was instantiated from [g].
3627 Iterable<DartType> _recoverTypeArguments(FunctionType g, FunctionType f) { 3635 Iterable<DartType> _recoverTypeArguments(FunctionType g, FunctionType f) {
(...skipping 2186 matching lines...) Expand 10 before | Expand all | Expand 10 after
5814 if (targetIdentifier.staticElement is! PrefixElement) return false; 5822 if (targetIdentifier.staticElement is! PrefixElement) return false;
5815 var prefix = targetIdentifier.staticElement as PrefixElement; 5823 var prefix = targetIdentifier.staticElement as PrefixElement;
5816 5824
5817 // The library the prefix is referring to must come from a deferred import. 5825 // The library the prefix is referring to must come from a deferred import.
5818 var containingLibrary = resolutionMap 5826 var containingLibrary = resolutionMap
5819 .elementDeclaredByCompilationUnit(target.root as CompilationUnit) 5827 .elementDeclaredByCompilationUnit(target.root as CompilationUnit)
5820 .library; 5828 .library;
5821 var imports = containingLibrary.getImportsWithPrefix(prefix); 5829 var imports = containingLibrary.getImportsWithPrefix(prefix);
5822 return imports.length == 1 && imports[0].isDeferred; 5830 return imports.length == 1 && imports[0].isDeferred;
5823 } 5831 }
OLDNEW
« no previous file with comments | « pkg/dev_compiler/lib/src/compiler/ast_builder.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698