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

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: Add import to a2d. Created 5 years, 9 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_task;
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 '../io/source_information.dart';
17 import '../js_backend/js_backend.dart' show JavaScriptBackend;
18 import '../scanner/scannerlib.dart' show Token, isUserDefinableOperator;
19 import '../tree/tree.dart' as ast;
20 import '../universe/universe.dart' show SelectorKind;
21 import 'cps_ir_nodes.dart' as ir;
22 import 'cps_ir_builder.dart';
6 23
7 /** 24 /**
8 * This task iterates through all resolved elements and builds [ir.Node]s. The 25 * 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 26 * nodes are stored in the [nodes] map and accessible through [hasIr] and
10 * [getIr]. 27 * [getIr].
11 * 28 *
12 * The functionality of the IrNodes is added gradually, therefore elements might 29 * 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 30 * 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 31 * 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 32 * used in the rest of the compilation. This is ensured by setting the element's
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 target: target); 355 target: target);
339 } 356 }
340 357
341 visitIf(ast.If node) { 358 visitIf(ast.If node) {
342 irBuilder.buildIf( 359 irBuilder.buildIf(
343 build(node.condition), 360 build(node.condition),
344 subbuild(node.thenPart), 361 subbuild(node.thenPart),
345 subbuild(node.elsePart)); 362 subbuild(node.elsePart));
346 } 363 }
347 364
348 ir.Primitive visitLabeledStatement(ast.LabeledStatement node) { 365 visitLabeledStatement(ast.LabeledStatement node) {
349 ast.Statement body = node.statement; 366 ast.Statement body = node.statement;
350 if (body is ast.Loop) return visit(body); 367 if (body is ast.Loop) {
351 JumpTarget target = elements.getTargetDefinition(body);
352 JumpCollector jumps = new JumpCollector(target);
353 irBuilder.state.breakCollectors.add(jumps);
354 IrBuilder innerBuilder = irBuilder.makeDelimitedBuilder();
355 withBuilder(innerBuilder, () {
356 visit(body); 368 visit(body);
357 });
358 irBuilder.state.breakCollectors.removeLast();
359 bool hasBreaks = !jumps.isEmpty;
360 ir.Continuation joinContinuation;
361 if (hasBreaks) {
362 if (innerBuilder.isOpen) {
363 jumps.addJump(innerBuilder);
364 }
365
366 // All jumps to the break continuation must be in the scope of the
367 // continuation's binding. The continuation is bound just outside the
368 // body to satisfy this property without extra analysis.
369 // As a consequence, the break continuation needs parameters for all
370 // local variables in scope at the exit from the body.
371 List<ir.Parameter> parameters =
372 new List<ir.Parameter>.generate(irBuilder.environment.length, (i) {
373 return new ir.Parameter(irBuilder.environment.index2variable[i]);
374 });
375 joinContinuation = new ir.Continuation(parameters);
376 irBuilder.invokeFullJoin(joinContinuation, jumps, recursive: false);
377 irBuilder.add(new ir.LetCont(joinContinuation,
378 innerBuilder._root));
379 for (int i = 0; i < irBuilder.environment.length; ++i) {
380 irBuilder.environment.index2value[i] = parameters[i];
381 }
382 } else { 369 } else {
383 if (innerBuilder._root != null) { 370 JumpTarget target = elements.getTargetDefinition(body);
384 irBuilder.add(innerBuilder._root); 371 irBuilder.buildLabeledStatement(
385 irBuilder._current = innerBuilder._current; 372 buildBody: subbuild(body),
386 irBuilder.environment = innerBuilder.environment; 373 target: target);
387 }
388 } 374 }
389 return null;
390 } 375 }
391 376
392 visitWhile(ast.While node) { 377 visitWhile(ast.While node) {
393 irBuilder.buildWhile( 378 irBuilder.buildWhile(
394 buildCondition: subbuild(node.condition), 379 buildCondition: subbuild(node.condition),
395 buildBody: subbuild(node.body), 380 buildBody: subbuild(node.body),
396 target: elements.getTargetDefinition(node), 381 target: elements.getTargetDefinition(node),
397 closureScope: getClosureScopeForNode(node)); 382 closureScope: getClosureScopeForNode(node));
398 } 383 }
399 384
(...skipping 1170 matching lines...) Expand 10 before | Expand all | Expand 10 after
1570 /// Defaults for optional arguments are evaluated in order to ensure 1555 /// Defaults for optional arguments are evaluated in order to ensure
1571 /// all parameters are available in the environment. 1556 /// all parameters are available in the environment.
1572 void loadArguments(FunctionElement target, 1557 void loadArguments(FunctionElement target,
1573 Selector selector, 1558 Selector selector,
1574 List<ir.Primitive> arguments) { 1559 List<ir.Primitive> arguments) {
1575 target = target.implementation; 1560 target = target.implementation;
1576 FunctionSignature signature = target.functionSignature; 1561 FunctionSignature signature = target.functionSignature;
1577 1562
1578 // Establish a scope in case parameters are captured. 1563 // Establish a scope in case parameters are captured.
1579 ClosureScope scope = getClosureScopeForFunction(target); 1564 ClosureScope scope = getClosureScopeForFunction(target);
1580 irBuilder._enterScope(scope); 1565 irBuilder.enterScope(scope);
1581 1566
1582 // Load required parameters 1567 // Load required parameters
1583 int index = 0; 1568 int index = 0;
1584 signature.forEachRequiredParameter((ParameterElement param) { 1569 signature.forEachRequiredParameter((ParameterElement param) {
1585 irBuilder.declareLocalVariable(param, initialValue: arguments[index]); 1570 irBuilder.declareLocalVariable(param, initialValue: arguments[index]);
1586 index++; 1571 index++;
1587 }); 1572 });
1588 1573
1589 // Load optional parameters, evaluating default values for omitted ones. 1574 // Load optional parameters, evaluating default values for omitted ones.
1590 signature.forEachOptionalParameter((ParameterElement param) { 1575 signature.forEachOptionalParameter((ParameterElement param) {
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
1838 SourceInformation buildCall(ast.Node node) { 1823 SourceInformation buildCall(ast.Node node) {
1839 return new PositionSourceInformation( 1824 return new PositionSourceInformation(
1840 new TokenSourceLocation(sourceFile, node.getBeginToken(), name)); 1825 new TokenSourceLocation(sourceFile, node.getBeginToken(), name));
1841 } 1826 }
1842 1827
1843 @override 1828 @override
1844 SourceInformationBuilder forContext(AstElement element) { 1829 SourceInformationBuilder forContext(AstElement element) {
1845 return new PositionSourceInformationBuilder(element); 1830 return new PositionSourceInformationBuilder(element);
1846 } 1831 }
1847 } 1832 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/cps_ir/cps_ir_builder.dart ('k') | pkg/compiler/lib/src/cps_ir/cps_ir_builder_visitor.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698