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

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

Issue 2980113002: fix #27320, better DDC temp generation (Closed)
Patch Set: rebase Created 3 years, 5 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 | « no previous file | pkg/dev_compiler/lib/src/compiler/js_metalet.dart » ('j') | 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 2634 matching lines...) Expand 10 before | Expand all | Expand 10 after
2645 return annotate(_toArrowFunction(fn), node); 2645 return annotate(_toArrowFunction(fn), node);
2646 } 2646 }
2647 2647
2648 JS.Fun _makeGenericFunction(JS.Fun fn) { 2648 JS.Fun _makeGenericFunction(JS.Fun fn) {
2649 if (fn.typeParams == null || fn.typeParams.isEmpty) return fn; 2649 if (fn.typeParams == null || fn.typeParams.isEmpty) return fn;
2650 2650
2651 return new JS.Fun( 2651 return new JS.Fun(
2652 fn.typeParams, 2652 fn.typeParams,
2653 new JS.Block([ 2653 new JS.Block([
2654 // Convert the function to an => function, to ensure `this` binding. 2654 // Convert the function to an => function, to ensure `this` binding.
2655 new JS.Return(_toArrowFunction(fn)) 2655 _toArrowFunction(fn).toReturn()
2656 ])); 2656 ]));
2657 } 2657 }
2658 2658
2659 JS.ArrowFun _toArrowFunction(JS.Fun f) { 2659 JS.ArrowFun _toArrowFunction(JS.Fun f) {
2660 JS.Node body = f.body; 2660 JS.Node body = f.body;
2661 2661
2662 // Simplify `=> { return e; }` to `=> e` 2662 // Simplify `=> { return e; }` to `=> e`
2663 if (body is JS.Block) { 2663 if (body is JS.Block) {
2664 JS.Block block = body; 2664 JS.Block block = body;
2665 if (block.statements.length == 1) { 2665 if (block.statements.length == 1) {
(...skipping 749 matching lines...) Expand 10 before | Expand all | Expand 10 after
3415 var body = js.call('# == null ? null : #', 3415 var body = js.call('# == null ? null : #',
3416 [_visit(left), _emitSet(_stripNullAwareOp(node, left), right)]); 3416 [_visit(left), _emitSet(_stripNullAwareOp(node, left), right)]);
3417 return new JS.MetaLet(vars, [body]); 3417 return new JS.MetaLet(vars, [body]);
3418 } 3418 }
3419 3419
3420 @override 3420 @override
3421 JS.Block visitExpressionFunctionBody(ExpressionFunctionBody node) { 3421 JS.Block visitExpressionFunctionBody(ExpressionFunctionBody node) {
3422 var savedFunction = _currentFunction; 3422 var savedFunction = _currentFunction;
3423 _currentFunction = node; 3423 _currentFunction = node;
3424 var initArgs = _emitArgumentInitializers(node.parent); 3424 var initArgs = _emitArgumentInitializers(node.parent);
3425 var ret = annotate(new JS.Return(_visit(node.expression)), node.expression); 3425 var ret = annotate(
3426 _visit<JS.Expression>(node.expression).toReturn(), node.expression);
3426 _currentFunction = savedFunction; 3427 _currentFunction = savedFunction;
3427 var _statements = initArgs != null ? [initArgs, ret] : [ret]; 3428 var _statements = initArgs != null ? [initArgs, ret] : [ret];
3428 var block = annotate(new JS.Block(_statements), node); 3429 var block = annotate(new JS.Block(_statements), node);
3429 return block; 3430 return block;
3430 } 3431 }
3431 3432
3432 @override 3433 @override
3433 JS.Block visitEmptyFunctionBody(EmptyFunctionBody node) => new JS.Block([]); 3434 JS.Block visitEmptyFunctionBody(EmptyFunctionBody node) => new JS.Block([]);
3434 3435
3435 @override 3436 @override
(...skipping 2543 matching lines...) Expand 10 before | Expand all | Expand 10 after
5979 if (targetIdentifier.staticElement is! PrefixElement) return false; 5980 if (targetIdentifier.staticElement is! PrefixElement) return false;
5980 var prefix = targetIdentifier.staticElement as PrefixElement; 5981 var prefix = targetIdentifier.staticElement as PrefixElement;
5981 5982
5982 // The library the prefix is referring to must come from a deferred import. 5983 // The library the prefix is referring to must come from a deferred import.
5983 var containingLibrary = resolutionMap 5984 var containingLibrary = resolutionMap
5984 .elementDeclaredByCompilationUnit(target.root as CompilationUnit) 5985 .elementDeclaredByCompilationUnit(target.root as CompilationUnit)
5985 .library; 5986 .library;
5986 var imports = containingLibrary.getImportsWithPrefix(prefix); 5987 var imports = containingLibrary.getImportsWithPrefix(prefix);
5987 return imports.length == 1 && imports[0].isDeferred; 5988 return imports.length == 1 && imports[0].isDeferred;
5988 } 5989 }
OLDNEW
« no previous file with comments | « no previous file | pkg/dev_compiler/lib/src/compiler/js_metalet.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698