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

Side by Side Diff: lib/src/compiler/js_metalet.dart

Issue 2016483002: Enable strong mode in DDC, fix all warnings/errors (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 4 years, 6 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 | « lib/src/compiler/element_helpers.dart ('k') | lib/src/compiler/module_builder.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 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 // TODO(jmesserly): import from its own package 5 // TODO(jmesserly): import from its own package
6 import '../js_ast/js_ast.dart'; 6 import '../js_ast/js_ast.dart';
7 import '../js_ast/precedence.dart'; 7 import '../js_ast/precedence.dart';
8 8
9 import 'js_names.dart' show TemporaryId; 9 import 'js_names.dart' show TemporaryId;
10 10
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 int get precedenceLevel => variables.isEmpty ? EXPRESSION : CALL; 146 int get precedenceLevel => variables.isEmpty ? EXPRESSION : CALL;
147 147
148 /// Patch to pretend [Template] supports visitMetaLet. 148 /// Patch to pretend [Template] supports visitMetaLet.
149 Instantiator _templateVisitMetaLet(InstantiatorGeneratorVisitor visitor) { 149 Instantiator _templateVisitMetaLet(InstantiatorGeneratorVisitor visitor) {
150 var valueInstantiators = variables.values.map(visitor.visit); 150 var valueInstantiators = variables.values.map(visitor.visit);
151 var bodyInstantiators = body.map(visitor.visit); 151 var bodyInstantiators = body.map(visitor.visit);
152 152
153 return (args) => new MetaLet( 153 return (args) => new MetaLet(
154 new Map.fromIterables( 154 new Map.fromIterables(
155 variables.keys, valueInstantiators.map((i) => i(args))), 155 variables.keys, valueInstantiators.map((i) => i(args))),
156 bodyInstantiators.map((i) => i(args)).toList(), 156 bodyInstantiators.map((i) => i(args) as Expression).toList(),
157 statelessResult: statelessResult); 157 statelessResult: statelessResult);
158 } 158 }
159 159
160 Expression _toInvokedFunction(Statement block) { 160 Expression _toInvokedFunction(Statement block) {
161 var finder = new _YieldFinder(); 161 var finder = new _YieldFinder();
162 block.accept(finder); 162 block.accept(finder);
163 if (!finder.hasYield) { 163 if (!finder.hasYield) {
164 return new Call(new ArrowFun([], block), []); 164 return new Call(new ArrowFun([], block), []);
165 } 165 }
166 // If we have a yield, it's more tricky. We'll create a `function*`, which 166 // If we have a yield, it's more tricky. We'll create a `function*`, which
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 if (isDeclaration) { 248 if (isDeclaration) {
249 // Technically, putting one of these in a comma expression is not 249 // Technically, putting one of these in a comma expression is not
250 // legal. However when isDeclaration is true, toStatement will be 250 // legal. However when isDeclaration is true, toStatement will be
251 // called immediately on the MetaLet, which results in legal JS. 251 // called immediately on the MetaLet, which results in legal JS.
252 assign = new VariableDeclarationList( 252 assign = new VariableDeclarationList(
253 'let', [new VariableInitialization(left, value)]); 253 'let', [new VariableInitialization(left, value)]);
254 } else { 254 } else {
255 assign = value.toAssignExpression(left); 255 assign = value.toAssignExpression(left);
256 } 256 }
257 257
258 var newBody = new Expression.binary([assign]..addAll(body), ','); 258 assert(body.isNotEmpty);
259 Binary newBody = new Expression.binary([assign]..addAll(body), ',');
259 newBody = _substitute(newBody, {result: left}); 260 newBody = _substitute(newBody, {result: left});
260 return new MetaLet(vars, newBody.commaToExpressionList(), 261 return new MetaLet(vars, newBody.commaToExpressionList(),
261 statelessResult: statelessResult); 262 statelessResult: statelessResult);
262 } 263 }
263 } 264 }
264 265
265 /// Similar to [Template.instantiate] but works with free variables. 266 /// Similar to [Template.instantiate] but works with free variables.
266 Node _substitute(Node tree, Map<MetaLetVariable, Expression> substitutions) { 267 Node _substitute(Node tree, Map<MetaLetVariable, Expression> substitutions) {
267 var generator = new InstantiatorGeneratorVisitor(/*forceCopy:*/ false); 268 var generator = new InstantiatorGeneratorVisitor(/*forceCopy:*/ false);
268 var instantiator = generator.compile(tree); 269 var instantiator = generator.compile(tree);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 @override 349 @override
349 visitYield(Yield node) { 350 visitYield(Yield node) {
350 if (!_nestedFunction) hasYield = true; 351 if (!_nestedFunction) hasYield = true;
351 } 352 }
352 353
353 @override 354 @override
354 visitNode(Node node) { 355 visitNode(Node node) {
355 if (!hasYield) super.visitNode(node); 356 if (!hasYield) super.visitNode(node);
356 } 357 }
357 } 358 }
OLDNEW
« no previous file with comments | « lib/src/compiler/element_helpers.dart ('k') | lib/src/compiler/module_builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698