Chromium Code Reviews| Index: runtime/observatory/lib/src/service/object.dart |
| diff --git a/runtime/observatory/lib/src/service/object.dart b/runtime/observatory/lib/src/service/object.dart |
| index b0876e07cdae0a1cd2a86c092dc56b60cd5cc804..5369d6e0c5100882a9359588b9a0fee35d80ea4a 100644 |
| --- a/runtime/observatory/lib/src/service/object.dart |
| +++ b/runtime/observatory/lib/src/service/object.dart |
| @@ -1830,7 +1830,15 @@ class Instance extends ServiceObject { |
| _loaded = true; |
| } |
| - String get shortName => valueAsString != null ? valueAsString : 'a ${clazz.name}'; |
| + String get shortName { |
| + if (isClosure) { |
| + return closureFunc.qualifiedName; |
| + } |
| + if (valueAsString != null) { |
| + return valueAsString; |
| + } |
| + return 'a ${clazz.name}'; |
| + } |
| String toString() => 'Instance($shortName)'; |
| } |
| @@ -2068,6 +2076,8 @@ class ScriptLine extends Observable { |
| } |
| bool _isBlank; |
| + bool get isTrivialLine => !possibleBpt; |
| + |
| static bool _isTrivialToken(String token) { |
| if (token == 'else') { |
| return true; |
| @@ -2088,6 +2098,9 @@ class ScriptLine extends Observable { |
| } |
| static bool _isTrivialLine(String text) { |
| + if (text.trimLeft().startsWith('//')) { |
| + return true; |
| + } |
| var wsTokens = text.split(new RegExp(r"(\s)+")); |
| for (var wsToken in wsTokens) { |
| var tokens = wsToken.split(new RegExp(r"(\b)")); |
| @@ -2175,6 +2188,14 @@ class CallSiteEntry { |
| String toString() => "CallSiteEntry(${receiverContainer.name}, $count)"; |
| } |
| +/// The location of a local variable reference in a script. |
| +class LocalVarLocation { |
| + final int line; |
| + final int column; |
| + final int endColumn; |
| + LocalVarLocation(this.line, this.column, this.endColumn); |
| +} |
| + |
| class Script extends ServiceObject with Coverage { |
| Set<CallSite> callSites = new Set<CallSite>(); |
| final lines = new ObservableList<ScriptLine>(); |
| @@ -2331,6 +2352,108 @@ class Script extends ServiceObject with Coverage { |
| getLine(line).removeBreakpoint(bpt); |
| } |
| } |
| + |
| + List<LocalVarLocation> scanLineForLocalVariableLocationse(Pattern pattern, |
|
rmacnak
2015/05/11 17:59:36
Locationse -> Locations
|
| + String name, |
| + String lineContents, |
| + int lineNumber, |
| + int columnOffset) { |
| + var r = <LocalVarLocation>[]; |
| + |
| + pattern.allMatches(lineContents).forEach((Match match) { |
| + // We have a match but our regular expression may have matched extra |
| + // characters on either side of the name. Tighten the location. |
| + var nameStart = match.input.indexOf(name, match.start); |
| + var column = nameStart + columnOffset; |
| + var endColumn = column + name.length; |
| + var localVarLocation = new LocalVarLocation(lineNumber, |
| + column, |
| + endColumn); |
| + r.add(localVarLocation); |
| + }); |
| + |
| + return r; |
| + } |
| + |
| + List<LocalVarLocation> scanForLocalVariableLocations(String name, |
| + int tokenPos, |
| + int endTokenPos) { |
| + // A pattern that matches: |
| + // start of line OR non-(alpha numeric OR period) character followed by |
| + // name followed by |
| + // a non-alpha numerc character. |
| + // |
| + // NOTE: This pattern can over match on both ends. This is corrected for |
| + // [scanLineForLocalVariableLocationse]. |
|
rmacnak
2015/05/11 17:59:36
I was going to suggest match groups here. Then I s
Cutch
2015/05/12 02:41:21
Acknowledged.
|
| + var pattern = new RegExp("(^|[^A-Za-z0-9\.])$name[^A-Za-z0-9]"); |
| + |
| + // Limits. |
| + final lastLine = tokenToLine(endTokenPos); |
| + final lastColumn = tokenToCol(endTokenPos); |
| + |
| + // Current scan position. |
| + var line = tokenToLine(tokenPos); |
| + var column = tokenToCol(tokenPos); |
| + |
|
rmacnak
2015/05/11 17:59:36
Bail out if [last]line/column are null. See below.
Cutch
2015/05/12 02:41:21
Done.
|
| + // Move back by name length. |
| + // TODO(johnmccutchan): Fix LocalVarDescriptor to set column before the |
| + // identifier name. |
| + column = math.max(0, column - name.length); |
| + |
| + var lineContents; |
| + |
| + if (line == lastLine) { |
| + // Only one line. |
| + if (!getLine(line).isTrivialLine) { |
| + lineContents = getLine(line).text.substring(column, lastColumn - 1); |
| + return scanLineForLocalVariableLocationse(pattern, |
| + name, |
| + lineContents, |
| + line, |
| + column); |
| + } |
| + } |
| + |
| + // Result. |
| + var r = <LocalVarLocation>[]; |
| + |
| + // Scan first line. |
| + if (!getLine(line).isTrivialLine) { |
| + lineContents = getLine(line).text.substring(column); |
| + r.addAll(scanLineForLocalVariableLocationse(pattern, |
| + name, |
| + lineContents, |
| + line++, |
| + column)); |
| + } |
| + |
| + // Scan middle lines. |
| + while (line < (lastLine - 1)) { |
|
rmacnak
2015/05/11 17:59:36
line and lastLine can be null, so the subtraction
Cutch
2015/05/12 02:41:21
Acknowledged.
|
| + if (getLine(line).isTrivialLine) { |
| + line++; |
| + continue; |
| + } |
| + lineContents = getLine(line).text; |
| + r.addAll( |
| + scanLineForLocalVariableLocationse(pattern, |
| + name, |
| + lineContents, |
| + line++, |
| + 0)); |
| + } |
| + |
| + // Scan last line. |
| + if (!getLine(line).isTrivialLine) { |
| + lineContents = getLine(line).text.substring(0, lastColumn - 1); |
| + r.addAll( |
| + scanLineForLocalVariableLocationse(pattern, |
| + name, |
| + lineContents, |
| + line, |
| + 0)); |
| + } |
| + return r; |
| + } |
| } |
| class PcDescriptor extends Observable { |