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

Side by Side Diff: pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart

Issue 917663003: Put IR builder visitors in a different library than IrBuilder. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 part of dart2js.ir_builder; 5 library dart2js.ir_builder_visitor;
asgerf 2015/02/11 10:51:14 Why rename the file to cps_ir_builder_task and the
Johnni Winther 2015/02/11 11:41:58 I started with the name _visitor but realized that
Johnni Winther 2015/03/05 11:05:53 Done.
6
7 import '../closure.dart' as closurelib;
8 import '../closure.dart' hide ClosureScope;
9 import '../constants/expressions.dart';
10 import '../dart_types.dart';
11 import '../dart2jslib.dart';
12 import '../elements/elements.dart';
13 import '../elements/modelx.dart' show SynthesizedConstructorElementX,
14 ConstructorBodyElementX, FunctionSignatureX;
15 import '../io/source_file.dart';
16 import '../js_backend/js_backend.dart' show JavaScriptBackend;
17 import '../scanner/scannerlib.dart' show Token, isUserDefinableOperator;
18 import '../tree/tree.dart' as ast;
19 import '../universe/universe.dart' show SelectorKind;
20 import 'cps_ir_nodes.dart' as ir;
21 import 'cps_ir_builder.dart';
6 22
7 /** 23 /**
8 * This task iterates through all resolved elements and builds [ir.Node]s. The 24 * This task iterates through all resolved elements and builds [ir.Node]s. The
9 * nodes are stored in the [nodes] map and accessible through [hasIr] and 25 * nodes are stored in the [nodes] map and accessible through [hasIr] and
10 * [getIr]. 26 * [getIr].
11 * 27 *
12 * The functionality of the IrNodes is added gradually, therefore elements might 28 * The functionality of the IrNodes is added gradually, therefore elements might
13 * have an IR or not, depending on the language features that are used. For 29 * have an IR or not, depending on the language features that are used. For
14 * elements that do have an IR, the tree [ast.Node]s and the [Token]s are not 30 * elements that do have an IR, the tree [ast.Node]s and the [Token]s are not
15 * used in the rest of the compilation. This is ensured by setting the element's 31 * used in the rest of the compilation. This is ensured by setting the element's
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 target: target); 348 target: target);
333 } 349 }
334 350
335 visitIf(ast.If node) { 351 visitIf(ast.If node) {
336 irBuilder.buildIf( 352 irBuilder.buildIf(
337 build(node.condition), 353 build(node.condition),
338 subbuild(node.thenPart), 354 subbuild(node.thenPart),
339 subbuild(node.elsePart)); 355 subbuild(node.elsePart));
340 } 356 }
341 357
342 ir.Primitive visitLabeledStatement(ast.LabeledStatement node) { 358 visitLabeledStatement(ast.LabeledStatement node) {
343 ast.Statement body = node.statement; 359 ast.Statement body = node.statement;
344 if (body is ast.Loop) return visit(body); 360 if (body is ast.Loop) {
345 JumpTarget target = elements.getTargetDefinition(body);
346 JumpCollector jumps = new JumpCollector(target);
347 irBuilder.state.breakCollectors.add(jumps);
348 IrBuilder innerBuilder = irBuilder.makeDelimitedBuilder();
349 withBuilder(innerBuilder, () {
350 visit(body); 361 visit(body);
351 });
352 irBuilder.state.breakCollectors.removeLast();
353 bool hasBreaks = !jumps.isEmpty;
354 ir.Continuation joinContinuation;
355 if (hasBreaks) {
356 if (innerBuilder.isOpen) {
357 jumps.addJump(innerBuilder);
358 }
359
360 // All jumps to the break continuation must be in the scope of the
361 // continuation's binding. The continuation is bound just outside the
362 // body to satisfy this property without extra analysis.
363 // As a consequence, the break continuation needs parameters for all
364 // local variables in scope at the exit from the body.
365 List<ir.Parameter> parameters =
366 new List<ir.Parameter>.generate(irBuilder.environment.length, (i) {
367 return new ir.Parameter(irBuilder.environment.index2variable[i]);
368 });
369 joinContinuation = new ir.Continuation(parameters);
370 irBuilder.invokeFullJoin(joinContinuation, jumps, recursive: false);
371 irBuilder.add(new ir.LetCont(joinContinuation,
372 innerBuilder._root));
373 for (int i = 0; i < irBuilder.environment.length; ++i) {
374 irBuilder.environment.index2value[i] = parameters[i];
375 }
376 } else { 362 } else {
377 if (innerBuilder._root != null) { 363 JumpTarget target = elements.getTargetDefinition(body);
378 irBuilder.add(innerBuilder._root); 364 irBuilder.buildLabeledStatement(
379 irBuilder._current = innerBuilder._current; 365 buildBody: subbuild(body),
380 irBuilder.environment = innerBuilder.environment; 366 target: target);
381 }
382 } 367 }
383 return null;
384 } 368 }
385 369
386 visitWhile(ast.While node) { 370 visitWhile(ast.While node) {
387 irBuilder.buildWhile( 371 irBuilder.buildWhile(
388 buildCondition: subbuild(node.condition), 372 buildCondition: subbuild(node.condition),
389 buildBody: subbuild(node.body), 373 buildBody: subbuild(node.body),
390 target: elements.getTargetDefinition(node), 374 target: elements.getTargetDefinition(node),
391 closureScope: getClosureScopeForNode(node)); 375 closureScope: getClosureScopeForNode(node));
392 } 376 }
393 377
(...skipping 1032 matching lines...) Expand 10 before | Expand all | Expand 10 after
1426 /// Defaults for optional arguments are evaluated in order to ensure 1410 /// Defaults for optional arguments are evaluated in order to ensure
1427 /// all parameters are available in the environment. 1411 /// all parameters are available in the environment.
1428 void loadArguments(FunctionElement target, 1412 void loadArguments(FunctionElement target,
1429 Selector selector, 1413 Selector selector,
1430 List<ir.Primitive> arguments) { 1414 List<ir.Primitive> arguments) {
1431 target = target.implementation; 1415 target = target.implementation;
1432 FunctionSignature signature = target.functionSignature; 1416 FunctionSignature signature = target.functionSignature;
1433 1417
1434 // Establish a scope in case parameters are captured. 1418 // Establish a scope in case parameters are captured.
1435 ClosureScope scope = getClosureScopeForFunction(target); 1419 ClosureScope scope = getClosureScopeForFunction(target);
1436 irBuilder._enterScope(scope); 1420 irBuilder.enterScope(scope);
1437 1421
1438 // Load required parameters 1422 // Load required parameters
1439 int index = 0; 1423 int index = 0;
1440 signature.forEachRequiredParameter((ParameterElement param) { 1424 signature.forEachRequiredParameter((ParameterElement param) {
1441 irBuilder.declareLocalVariable(param, initialValue: arguments[index]); 1425 irBuilder.declareLocalVariable(param, initialValue: arguments[index]);
1442 index++; 1426 index++;
1443 }); 1427 });
1444 1428
1445 // Load optional parameters, evaluating default values for omitted ones. 1429 // Load optional parameters, evaluating default values for omitted ones.
1446 signature.forEachOptionalParameter((ParameterElement param) { 1430 signature.forEachOptionalParameter((ParameterElement param) {
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
1655 for (String argName in selector.getOrderedNamedArguments()) { 1639 for (String argName in selector.getOrderedNamedArguments()) {
1656 int nameIndex = selector.namedArguments.indexOf(argName); 1640 int nameIndex = selector.namedArguments.indexOf(argName);
1657 int translatedIndex = selector.positionalArgumentCount + nameIndex; 1641 int translatedIndex = selector.positionalArgumentCount + nameIndex;
1658 result.add(arguments[translatedIndex]); 1642 result.add(arguments[translatedIndex]);
1659 } 1643 }
1660 return result; 1644 return result;
1661 } 1645 }
1662 1646
1663 } 1647 }
1664 1648
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698