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

Side by Side Diff: pkg/compiler/lib/src/io/position_information.dart

Issue 1773553002: Add source location to function declarations. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Updated cf. comments. Created 4 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
« no previous file with comments | « no previous file | tests/compiler/dart2js/sourcemaps/js_tracer.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 /// Source information system mapping that attempts a semantic mapping between 5 /// Source information system mapping that attempts a semantic mapping between
6 /// offsets of JavaScript code points to offsets of Dart code points. 6 /// offsets of JavaScript code points to offsets of Dart code points.
7 7
8 library dart2js.source_information.position; 8 library dart2js.source_information.position;
9 9
10 import '../common.dart'; 10 import '../common.dart';
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 sourceFile = element.implementation.compilationUnit.script.file, 156 sourceFile = element.implementation.compilationUnit.script.file,
157 name = computeElementNameForSourceMaps(element); 157 name = computeElementNameForSourceMaps(element);
158 158
159 SourceInformation buildDeclaration(AstElement element) { 159 SourceInformation buildDeclaration(AstElement element) {
160 if (element.isSynthesized) { 160 if (element.isSynthesized) {
161 return new PositionSourceInformation( 161 return new PositionSourceInformation(
162 new OffsetSourceLocation( 162 new OffsetSourceLocation(
163 sourceFile, element.position.charOffset, name)); 163 sourceFile, element.position.charOffset, name));
164 } else { 164 } else {
165 return new PositionSourceInformation( 165 return new PositionSourceInformation(
166 null, 166 new OffsetSourceLocation(sourceFile,
167 element.resolvedAst.node.getBeginToken().charOffset, name),
167 new OffsetSourceLocation(sourceFile, 168 new OffsetSourceLocation(sourceFile,
168 element.resolvedAst.node.getEndToken().charOffset, name)); 169 element.resolvedAst.node.getEndToken().charOffset, name));
169 } 170 }
170 } 171 }
171 172
172 /// Builds a source information object pointing the start position of [node]. 173 /// Builds a source information object pointing the start position of [node].
173 SourceInformation buildBegin(Node node) { 174 SourceInformation buildBegin(Node node) {
174 return new PositionSourceInformation(new OffsetSourceLocation( 175 return new PositionSourceInformation(new OffsetSourceLocation(
175 sourceFile, node.getBeginToken().charOffset, name)); 176 sourceFile, node.getBeginToken().charOffset, name));
176 } 177 }
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 class PositionTraceListener extends TraceListener with 494 class PositionTraceListener extends TraceListener with
494 NodeToSourceInformationMixin { 495 NodeToSourceInformationMixin {
495 final SourceMapper sourceMapper; 496 final SourceMapper sourceMapper;
496 497
497 PositionTraceListener(this.sourceMapper); 498 PositionTraceListener(this.sourceMapper);
498 499
499 @override 500 @override
500 void onStep(js.Node node, Offset offset, StepKind kind) { 501 void onStep(js.Node node, Offset offset, StepKind kind) {
501 SourceInformation sourceInformation = computeSourceInformation(node); 502 SourceInformation sourceInformation = computeSourceInformation(node);
502 if (sourceInformation == null) return; 503 if (sourceInformation == null) return;
504 int codeLocation = offset.subexpressionOffset;
505 if (codeLocation == null) return;
503 506
504 SourcePositionKind sourcePositionKind = SourcePositionKind.START; 507 void registerPosition(SourcePositionKind sourcePositionKind) {
508 SourceLocation sourceLocation =
509 getSourceLocation(sourceInformation, sourcePositionKind);
510 if (sourceLocation != null) {
511 sourceMapper.register(node, codeLocation, sourceLocation);
512 }
513 }
514
505 switch (kind) { 515 switch (kind) {
506 case StepKind.FUN: 516 case StepKind.FUN_ENTRY:
507 sourcePositionKind = SourcePositionKind.INNER; 517 // TODO(johnniwinther): Remove this when fully transitioned to the
518 // new source info system.
519 registerPosition(SourcePositionKind.START);
520 break;
521 case StepKind.FUN_EXIT:
522 registerPosition(SourcePositionKind.INNER);
508 break; 523 break;
509 case StepKind.CALL: 524 case StepKind.CALL:
510 CallPosition callPosition = 525 CallPosition callPosition =
511 CallPosition.getSemanticPositionForCall(node); 526 CallPosition.getSemanticPositionForCall(node);
512 sourcePositionKind = callPosition.sourcePositionKind; 527 registerPosition(callPosition.sourcePositionKind);
513 break; 528 break;
514 case StepKind.NEW: 529 case StepKind.NEW:
515 case StepKind.RETURN: 530 case StepKind.RETURN:
516 case StepKind.BREAK: 531 case StepKind.BREAK:
517 case StepKind.CONTINUE: 532 case StepKind.CONTINUE:
518 case StepKind.THROW: 533 case StepKind.THROW:
519 case StepKind.EXPRESSION_STATEMENT: 534 case StepKind.EXPRESSION_STATEMENT:
520 case StepKind.IF_CONDITION: 535 case StepKind.IF_CONDITION:
521 case StepKind.FOR_INITIALIZER: 536 case StepKind.FOR_INITIALIZER:
522 case StepKind.FOR_CONDITION: 537 case StepKind.FOR_CONDITION:
523 case StepKind.FOR_UPDATE: 538 case StepKind.FOR_UPDATE:
524 case StepKind.WHILE_CONDITION: 539 case StepKind.WHILE_CONDITION:
525 case StepKind.DO_CONDITION: 540 case StepKind.DO_CONDITION:
526 case StepKind.SWITCH_EXPRESSION: 541 case StepKind.SWITCH_EXPRESSION:
542 registerPosition(SourcePositionKind.START);
527 break; 543 break;
528 } 544 }
529 int codeLocation = offset.subexpressionOffset;
530 SourceLocation sourceLocation =
531 getSourceLocation(sourceInformation, sourcePositionKind);
532 if (codeLocation != null && sourceLocation != null) {
533 sourceMapper.register(node, codeLocation, sourceLocation);
534 }
535 } 545 }
536 } 546 }
537 547
538 /// The position of a [js.Call] node. 548 /// The position of a [js.Call] node.
539 class CallPosition { 549 class CallPosition {
540 final js.Node node; 550 final js.Node node;
541 final CodePositionKind codePositionKind; 551 final CodePositionKind codePositionKind;
542 final SourcePositionKind sourcePositionKind; 552 final SourcePositionKind sourcePositionKind;
543 553
544 CallPosition(this.node, this.codePositionKind, this.sourcePositionKind); 554 CallPosition(this.node, this.codePositionKind, this.sourcePositionKind);
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 675
666 enum BranchKind { 676 enum BranchKind {
667 CONDITION, 677 CONDITION,
668 LOOP, 678 LOOP,
669 CATCH, 679 CATCH,
670 FINALLY, 680 FINALLY,
671 CASE, 681 CASE,
672 } 682 }
673 683
674 enum StepKind { 684 enum StepKind {
675 FUN, 685 FUN_ENTRY,
686 FUN_EXIT,
676 CALL, 687 CALL,
677 NEW, 688 NEW,
678 RETURN, 689 RETURN,
679 BREAK, 690 BREAK,
680 CONTINUE, 691 CONTINUE,
681 THROW, 692 THROW,
682 EXPRESSION_STATEMENT, 693 EXPRESSION_STATEMENT,
683 IF_CONDITION, 694 IF_CONDITION,
684 FOR_INITIALIZER, 695 FOR_INITIALIZER,
685 FOR_CONDITION, 696 FOR_CONDITION,
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
790 } 801 }
791 } 802 }
792 } 803 }
793 804
794 @override 805 @override
795 visitFun(js.Fun node) { 806 visitFun(js.Fun node) {
796 bool activeBefore = active; 807 bool activeBefore = active;
797 if (!active) { 808 if (!active) {
798 active = node.sourceInformation != null; 809 active = node.sourceInformation != null;
799 } 810 }
811 leftToRightOffset = statementOffset =
812 getSyntaxOffset(node, kind: CodePositionKind.START);
813 Offset entryOffset = getOffsetForNode(node, statementOffset);
814 notifyStep(node, entryOffset, StepKind.FUN_ENTRY);
815
800 visit(node.body); 816 visit(node.body);
817
801 leftToRightOffset = statementOffset = 818 leftToRightOffset = statementOffset =
802 getSyntaxOffset(node, kind: CodePositionKind.CLOSING); 819 getSyntaxOffset(node, kind: CodePositionKind.CLOSING);
803 Offset offset = getOffsetForNode(node, statementOffset); 820 Offset exitOffset = getOffsetForNode(node, statementOffset);
804 notifyStep(node, offset, StepKind.FUN); 821 notifyStep(node, exitOffset, StepKind.FUN_EXIT);
805 active = activeBefore; 822 active = activeBefore;
806 } 823 }
807 824
808 @override 825 @override
809 visitBlock(js.Block node) { 826 visitBlock(js.Block node) {
810 for (js.Statement statement in node.statements) { 827 for (js.Statement statement in node.statements) {
811 visit(statement); 828 visit(statement);
812 } 829 }
813 } 830 }
814 831
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
1267 1284
1268 @override 1285 @override
1269 CodePosition operator [](js.Node node) { 1286 CodePosition operator [](js.Node node) {
1270 CodePosition codePosition = codePositions[node]; 1287 CodePosition codePosition = codePositions[node];
1271 if (codePosition == null) { 1288 if (codePosition == null) {
1272 coverage.registerNodesWithoutOffset(node); 1289 coverage.registerNodesWithoutOffset(node);
1273 } 1290 }
1274 return codePosition; 1291 return codePosition;
1275 } 1292 }
1276 } 1293 }
OLDNEW
« no previous file with comments | « no previous file | tests/compiler/dart2js/sourcemaps/js_tracer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698