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

Unified Diff: pkg/compiler/lib/src/io/start_end_information.dart

Issue 1902363002: Derive source information from ResolvedAst. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/compiler/lib/src/io/source_information.dart ('k') | pkg/compiler/lib/src/js_backend/codegen/task.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/io/start_end_information.dart
diff --git a/pkg/compiler/lib/src/io/start_end_information.dart b/pkg/compiler/lib/src/io/start_end_information.dart
index b1553cd0271345eed91032a376e03fa67bd03157..b749d8a1cdcb46ddb540802113f80a1dcc132223 100644
--- a/pkg/compiler/lib/src/io/start_end_information.dart
+++ b/pkg/compiler/lib/src/io/start_end_information.dart
@@ -9,7 +9,7 @@ library dart2js.source_information.start_end;
import '../common.dart';
import '../diagnostics/messages.dart' show MessageTemplate;
-import '../elements/elements.dart' show AstElement;
+import '../elements/elements.dart' show AstElement, ResolvedAst, ResolvedAstKind;
import '../js/js.dart' as js;
import '../js/js_source_mapping.dart';
import '../tokens/token.dart' show Token;
@@ -60,30 +60,31 @@ class StartEndSourceInformation extends SourceInformation {
// TODO(johnniwinther): Inline this in
// [StartEndSourceInformationBuilder.buildDeclaration].
static StartEndSourceInformation _computeSourceInformation(
- AstElement element) {
- AstElement implementation = element.implementation;
- SourceFile sourceFile = implementation.compilationUnit.script.file;
- String name = computeElementNameForSourceMaps(element);
- Node node = implementation.node;
- Token beginToken;
- Token endToken;
- if (node == null) {
+ ResolvedAst resolvedAst) {
+ String name = computeElementNameForSourceMaps(resolvedAst.element);
+ SourceFile sourceFile;
+ int begin;
+ int end;
+ if (resolvedAst.kind != ResolvedAstKind.PARSED) {
// Synthesized node. Use the enclosing element for the location.
- beginToken = endToken = element.position;
+ sourceFile = resolvedAst.element.compilationUnit.script.file;
+ begin = end = resolvedAst.element.sourcePosition.begin;
} else {
- beginToken = node.getBeginToken();
- endToken = node.getEndToken();
+ AstElement implementation = resolvedAst.element.implementation;
+ sourceFile = implementation.compilationUnit.script.file;
+ Node node = resolvedAst.node;
+ begin = node.getBeginToken().charOffset;
+ end = node.getEndToken().charOffset;
}
// TODO(johnniwinther): find the right sourceFile here and remove offset
// checks below.
SourceLocation sourcePosition, endSourcePosition;
- if (beginToken.charOffset < sourceFile.length) {
+ if (begin < sourceFile.length) {
sourcePosition =
- new OffsetSourceLocation(sourceFile, beginToken.charOffset, name);
+ new OffsetSourceLocation(sourceFile, begin, name);
}
- if (endToken.charOffset < sourceFile.length) {
- endSourcePosition =
- new OffsetSourceLocation(sourceFile, endToken.charOffset, name);
+ if (end < sourceFile.length) {
+ endSourcePosition = new OffsetSourceLocation(sourceFile, end, name);
}
return new StartEndSourceInformation(sourcePosition, endSourcePosition);
}
@@ -161,8 +162,8 @@ class StartEndSourceInformationBuilder extends SourceInformationBuilder {
: sourceFile = element.compilationUnit.script.file,
name = computeElementNameForSourceMaps(element);
- SourceInformation buildDeclaration(AstElement element) {
- return StartEndSourceInformation._computeSourceInformation(element);
+ SourceInformation buildDeclaration(ResolvedAst resolvedAst) {
+ return StartEndSourceInformation._computeSourceInformation(resolvedAst);
}
SourceLocation sourceFileLocationForToken(Token token) {
« no previous file with comments | « pkg/compiler/lib/src/io/source_information.dart ('k') | pkg/compiler/lib/src/js_backend/codegen/task.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698