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

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: 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 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
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;
503 504
504 SourcePositionKind sourcePositionKind = SourcePositionKind.START; 505 void registerPosition(SourcePositionKind sourcePositionKind) {
506 int codeLocation = offset.subexpressionOffset;
Siggi Cherem (dart-lang) 2016/03/07 18:12:49 consider moving this out to the beginning of onSte
Johnni Winther 2016/03/08 09:39:23 Done.
507 SourceLocation sourceLocation =
508 getSourceLocation(sourceInformation, sourcePositionKind);
509 if (codeLocation != null && sourceLocation != null) {
510 sourceMapper.register(node, codeLocation, sourceLocation);
511 }
512 }
513
505 switch (kind) { 514 switch (kind) {
506 case StepKind.FUN: 515 case StepKind.FUN_ENTRY:
507 sourcePositionKind = SourcePositionKind.INNER; 516 // TODO(johnniwinther): Remove this when fully transitioned to the
517 // new source info system.
518 registerPosition(SourcePositionKind.START);
519 break;
520 case StepKind.FUN_EXIT:
521 registerPosition(SourcePositionKind.INNER);
508 break; 522 break;
509 case StepKind.CALL: 523 case StepKind.CALL:
510 CallPosition callPosition = 524 CallPosition callPosition =
511 CallPosition.getSemanticPositionForCall(node); 525 CallPosition.getSemanticPositionForCall(node);
512 sourcePositionKind = callPosition.sourcePositionKind; 526 registerPosition(callPosition.sourcePositionKind);
513 break; 527 break;
514 case StepKind.NEW: 528 case StepKind.NEW:
515 case StepKind.RETURN: 529 case StepKind.RETURN:
516 case StepKind.BREAK: 530 case StepKind.BREAK:
517 case StepKind.CONTINUE: 531 case StepKind.CONTINUE:
518 case StepKind.THROW: 532 case StepKind.THROW:
519 case StepKind.EXPRESSION_STATEMENT: 533 case StepKind.EXPRESSION_STATEMENT:
520 case StepKind.IF_CONDITION: 534 case StepKind.IF_CONDITION:
521 case StepKind.FOR_INITIALIZER: 535 case StepKind.FOR_INITIALIZER:
522 case StepKind.FOR_CONDITION: 536 case StepKind.FOR_CONDITION:
523 case StepKind.FOR_UPDATE: 537 case StepKind.FOR_UPDATE:
524 case StepKind.WHILE_CONDITION: 538 case StepKind.WHILE_CONDITION:
525 case StepKind.DO_CONDITION: 539 case StepKind.DO_CONDITION:
526 case StepKind.SWITCH_EXPRESSION: 540 case StepKind.SWITCH_EXPRESSION:
541 registerPosition(SourcePositionKind.START);
527 break; 542 break;
528 } 543 }
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 } 544 }
536 } 545 }
537 546
538 /// The position of a [js.Call] node. 547 /// The position of a [js.Call] node.
539 class CallPosition { 548 class CallPosition {
540 final js.Node node; 549 final js.Node node;
541 final CodePositionKind codePositionKind; 550 final CodePositionKind codePositionKind;
542 final SourcePositionKind sourcePositionKind; 551 final SourcePositionKind sourcePositionKind;
543 552
544 CallPosition(this.node, this.codePositionKind, this.sourcePositionKind); 553 CallPosition(this.node, this.codePositionKind, this.sourcePositionKind);
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 674
666 enum BranchKind { 675 enum BranchKind {
667 CONDITION, 676 CONDITION,
668 LOOP, 677 LOOP,
669 CATCH, 678 CATCH,
670 FINALLY, 679 FINALLY,
671 CASE, 680 CASE,
672 } 681 }
673 682
674 enum StepKind { 683 enum StepKind {
675 FUN, 684 FUN_ENTRY,
685 FUN_EXIT,
676 CALL, 686 CALL,
677 NEW, 687 NEW,
678 RETURN, 688 RETURN,
679 BREAK, 689 BREAK,
680 CONTINUE, 690 CONTINUE,
681 THROW, 691 THROW,
682 EXPRESSION_STATEMENT, 692 EXPRESSION_STATEMENT,
683 IF_CONDITION, 693 IF_CONDITION,
684 FOR_INITIALIZER, 694 FOR_INITIALIZER,
685 FOR_CONDITION, 695 FOR_CONDITION,
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
790 } 800 }
791 } 801 }
792 } 802 }
793 803
794 @override 804 @override
795 visitFun(js.Fun node) { 805 visitFun(js.Fun node) {
796 bool activeBefore = active; 806 bool activeBefore = active;
797 if (!active) { 807 if (!active) {
798 active = node.sourceInformation != null; 808 active = node.sourceInformation != null;
799 } 809 }
810 leftToRightOffset = statementOffset =
811 getSyntaxOffset(node, kind: CodePositionKind.START);
812 Offset entryOffset = getOffsetForNode(node, statementOffset);
813 notifyStep(node, entryOffset, StepKind.FUN_ENTRY);
814
800 visit(node.body); 815 visit(node.body);
816
801 leftToRightOffset = statementOffset = 817 leftToRightOffset = statementOffset =
802 getSyntaxOffset(node, kind: CodePositionKind.CLOSING); 818 getSyntaxOffset(node, kind: CodePositionKind.CLOSING);
803 Offset offset = getOffsetForNode(node, statementOffset); 819 Offset exitOffset = getOffsetForNode(node, statementOffset);
804 notifyStep(node, offset, StepKind.FUN); 820 notifyStep(node, exitOffset, StepKind.FUN_EXIT);
805 active = activeBefore; 821 active = activeBefore;
806 } 822 }
807 823
808 @override 824 @override
809 visitBlock(js.Block node) { 825 visitBlock(js.Block node) {
810 for (js.Statement statement in node.statements) { 826 for (js.Statement statement in node.statements) {
811 visit(statement); 827 visit(statement);
812 } 828 }
813 } 829 }
814 830
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
1267 1283
1268 @override 1284 @override
1269 CodePosition operator [](js.Node node) { 1285 CodePosition operator [](js.Node node) {
1270 CodePosition codePosition = codePositions[node]; 1286 CodePosition codePosition = codePositions[node];
1271 if (codePosition == null) { 1287 if (codePosition == null) {
1272 coverage.registerNodesWithoutOffset(node); 1288 coverage.registerNodesWithoutOffset(node);
1273 } 1289 }
1274 return codePosition; 1290 return codePosition;
1275 } 1291 }
1276 } 1292 }
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