Improve position information.

R=paulberry@google.com

Review-Url: https://codereview.chromium.org/2915123002 .
This commit is contained in:
Peter von der Ahé 2017-06-02 15:14:52 +02:00
parent cbcb7d4885
commit a79a59d19c
6 changed files with 44 additions and 27 deletions

View file

@ -15,8 +15,12 @@ class PrefixBuilder extends Builder {
final bool deferred;
@override
final int charOffset;
PrefixBuilder(this.name, this.deferred, LibraryBuilder parent, int charOffset)
: parent = parent,
charOffset = charOffset,
super(parent, charOffset, parent.fileUri);
Builder lookup(String name, int charOffset, Uri fileUri) {

View file

@ -579,7 +579,8 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper {
arguments[i] = new NamedExpression(
"#$i",
buildCompileTimeError(
"Expected named argument.", arguments[i].fileOffset));
"Expected named argument.", arguments[i].fileOffset))
..fileOffset = beginToken.charOffset;
}
}
}
@ -588,9 +589,10 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper {
arguments.getRange(0, firstNamedArgumentIndex));
List<NamedExpression> named = new List<NamedExpression>.from(
arguments.getRange(firstNamedArgumentIndex, arguments.length));
push(new KernelArguments(positional, named: named));
push(new KernelArguments(positional, named: named)
..fileOffset = beginToken.charOffset);
} else {
push(new KernelArguments(arguments));
push(new KernelArguments(arguments)..fileOffset = beginToken.charOffset);
}
}
@ -740,14 +742,14 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper {
/// Handle `a?.b(...)`.
void doIfNotNull(Token token) {
IncompleteSend send = pop();
push(send.withReceiver(pop(), isNullAware: true));
push(send.withReceiver(pop(), token.charOffset, isNullAware: true));
}
void doDotOrCascadeExpression(Token token) {
// TODO(ahe): Handle null-aware.
IncompleteSend send = pop();
Object receiver = optional(".", token) ? pop() : popForValue();
push(send.withReceiver(receiver));
push(send.withReceiver(receiver, token.charOffset));
}
@override
@ -757,9 +759,12 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper {
if (target is Procedure) {
if (!target.isAccessor) {
if (areArgumentsCompatible(target.function, node.arguments)) {
// TODO(ahe): Use [DirectMethodInvocation] when possible.
Expression result = new KernelDirectMethodInvocation(
new ThisExpression(), target, node.arguments);
new ThisExpression()..fileOffset = node.fileOffset,
target,
node.arguments);
// TODO(ahe): Use [DirectMethodInvocation] when possible, that is,
// remove the next line:
result =
new KernelSuperMethodInvocation(node.name, node.arguments, null);
return result;
@ -773,9 +778,10 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper {
node.name.name, node.arguments, node.fileOffset,
isSuper: true);
}
// TODO(ahe): Use [DirectPropertyGet] when possible.
Expression receiver =
new KernelDirectPropertyGet(new ThisExpression(), target);
Expression receiver = new KernelDirectPropertyGet(
new ThisExpression()..fileOffset = node.fileOffset, target);
// TODO(ahe): Use [DirectPropertyGet] when possible, that is, remove the
// next line:
receiver = new KernelSuperPropertyGet(node.name, target);
return buildMethodInvocation(
receiver, callName, node.arguments, node.fileOffset);
@ -2103,7 +2109,8 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper {
debugEvent("NamedArgument");
Expression value = popForValue();
Identifier identifier = pop();
push(new NamedExpression(identifier.name, value));
push(new NamedExpression(identifier.name, value)
..fileOffset = offsetForToken(identifier.token));
}
@override

View file

@ -147,7 +147,7 @@ abstract class FastaAccessor implements Accessor {
int offset, Arguments arguments);
/* Expression | FastaAccessor */ buildPropertyAccess(
IncompleteSend send, bool isNullAware) {
IncompleteSend send, int operatorOffset, bool isNullAware) {
if (send is SendAccessor) {
return helper.buildMethodInvocation(buildSimpleRead(), send.name,
send.arguments, offsetForToken(send.token),
@ -189,7 +189,7 @@ abstract class ErrorAccessor implements FastaAccessor {
@override
String get plainNameForRead => name.name;
withReceiver(Object receiver, {bool isNullAware}) => this;
withReceiver(Object receiver, int operatorOffset, {bool isNullAware}) => this;
@override
Initializer buildFieldInitializer(
@ -204,7 +204,10 @@ abstract class ErrorAccessor implements FastaAccessor {
}
@override
buildPropertyAccess(IncompleteSend send, bool isNullAware) => this;
buildPropertyAccess(
IncompleteSend send, int operatorOffset, bool isNullAware) {
return this;
}
@override
buildThrowNoSuchMethodError(Arguments arguments,
@ -300,7 +303,8 @@ class ThisAccessor extends FastaAccessor {
offset);
}
buildPropertyAccess(IncompleteSend send, bool isNullAware) {
buildPropertyAccess(
IncompleteSend send, int operatorOffset, bool isNullAware) {
if (isInitializer && send is SendAccessor) {
return buildConstructorInitializer(
offsetForToken(send.token), send.name, send.arguments);
@ -405,7 +409,7 @@ abstract class IncompleteSend extends FastaAccessor {
IncompleteSend(this.helper, this.token, this.name);
withReceiver(Object receiver, {bool isNullAware});
withReceiver(Object receiver, int operatorOffset, {bool isNullAware});
Arguments get arguments => null;
}
@ -446,9 +450,9 @@ class SendAccessor extends IncompleteSend {
return internalError("Unhandled");
}
withReceiver(Object receiver, {bool isNullAware: false}) {
withReceiver(Object receiver, int operatorOffset, {bool isNullAware: false}) {
if (receiver is FastaAccessor) {
return receiver.buildPropertyAccess(this, isNullAware);
return receiver.buildPropertyAccess(this, operatorOffset, isNullAware);
}
if (receiver is PrefixBuilder) {
PrefixBuilder prefix = receiver;
@ -503,9 +507,9 @@ class IncompletePropertyAccessor extends IncompleteSend {
return internalError("Unhandled");
}
withReceiver(Object receiver, {bool isNullAware: false}) {
withReceiver(Object receiver, int operatorOffset, {bool isNullAware: false}) {
if (receiver is FastaAccessor) {
return receiver.buildPropertyAccess(this, isNullAware);
return receiver.buildPropertyAccess(this, operatorOffset, isNullAware);
}
if (receiver is PrefixBuilder) {
PrefixBuilder prefix = receiver;
@ -852,7 +856,8 @@ class TypeDeclarationAccessor extends ReadOnlyAccessor {
}
@override
buildPropertyAccess(IncompleteSend send, bool isNullAware) {
buildPropertyAccess(
IncompleteSend send, int operatorOffset, bool isNullAware) {
// `SomeType?.toString` is the same as `SomeType.toString`, not
// `(SomeType).toString`.
isNullAware = false;
@ -888,7 +893,7 @@ class TypeDeclarationAccessor extends ReadOnlyAccessor {
? accessor
: accessor.doInvocation(offsetForToken(send.token), arguments);
} else {
return super.buildPropertyAccess(send, isNullAware);
return super.buildPropertyAccess(send, operatorOffset, isNullAware);
}
}

View file

@ -160,7 +160,7 @@ String unescape(String string, Quote quote) {
? string
: unescapeCodeUnits(string.codeUnits, true);
}
return internalError("Unhandled string quote: $quote");
return internalError("Internal error: Unexpected quote: $quote.");
}
const String incompleteSequence = "Incomplete escape sequence.";

View file

@ -159,11 +159,11 @@ class OutlineBuilder extends UnhandledListener {
@override
void endPart(Token partKeyword, Token semicolon) {
debugEvent("Part");
popCharOffset();
int charOffset = popCharOffset();
String uri = pop();
List<MetadataBuilder> metadata = pop();
if (uri != null) {
library.addPart(metadata, uri);
library.addPart(metadata, uri, charOffset);
}
checkEmpty(partKeyword.charOffset);
}
@ -395,7 +395,8 @@ class OutlineBuilder extends UnhandledListener {
debugEvent("MixinApplication");
List<TypeBuilder> mixins = pop();
TypeBuilder supertype = pop();
push(library.addMixinApplication(supertype, mixins, -1));
push(
library.addMixinApplication(supertype, mixins, withKeyword.charOffset));
}
@override

View file

@ -149,7 +149,7 @@ abstract class SourceLibraryBuilder<T extends TypeBuilder, R>
prefixCharOffset));
}
void addPart(List<MetadataBuilder> metadata, String path) {
void addPart(List<MetadataBuilder> metadata, String path, int charOffset) {
Uri resolvedUri;
Uri newFileUri;
if (uri.scheme == "dart") {