Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 part of service; | 5 part of service; |
| 6 | 6 |
| 7 /// A [ServiceObject] is an object known to the VM service and is tied | 7 /// A [ServiceObject] is an object known to the VM service and is tied |
| 8 /// to an owning [Isolate]. | 8 /// to an owning [Isolate]. |
| 9 abstract class ServiceObject extends Observable { | 9 abstract class ServiceObject extends Observable { |
| 10 /// The owner of this [ServiceObject]. This can be an [Isolate], a | 10 /// The owner of this [ServiceObject]. This can be an [Isolate], a |
| (...skipping 1085 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1096 void update(List stats) { | 1096 void update(List stats) { |
| 1097 accumulated.instances = stats[ACCUMULATED]; | 1097 accumulated.instances = stats[ACCUMULATED]; |
| 1098 accumulated.bytes = stats[ACCUMULATED_SIZE]; | 1098 accumulated.bytes = stats[ACCUMULATED_SIZE]; |
| 1099 current.instances = stats[LIVE_AFTER_GC] + stats[ALLOCATED_SINCE_GC]; | 1099 current.instances = stats[LIVE_AFTER_GC] + stats[ALLOCATED_SINCE_GC]; |
| 1100 current.bytes = stats[LIVE_AFTER_GC_SIZE] + stats[ALLOCATED_SINCE_GC_SIZE]; | 1100 current.bytes = stats[LIVE_AFTER_GC_SIZE] + stats[ALLOCATED_SINCE_GC_SIZE]; |
| 1101 } | 1101 } |
| 1102 | 1102 |
| 1103 bool get empty => accumulated.empty && current.empty; | 1103 bool get empty => accumulated.empty && current.empty; |
| 1104 } | 1104 } |
| 1105 | 1105 |
| 1106 class ClassParser { | |
|
hausner
2014/07/01 23:49:07
When we spoke offline I was under the impression t
| |
| 1107 List<ScriptLine> _source; | |
| 1108 int _offset; | |
| 1109 | |
| 1110 ClassParser(this._source) { | |
| 1111 assert(_source != null && _source.length > 0); | |
| 1112 _offset = this._source.first.line; | |
| 1113 } | |
| 1114 | |
| 1115 // Internal state for parsing the class. | |
| 1116 var _line; | |
| 1117 var _col; | |
| 1118 int _currentToken; | |
| 1119 | |
| 1120 int _char(String str) => str.codeUnitAt(0); | |
| 1121 | |
| 1122 void _initTokens() { | |
| 1123 _line = 0; | |
| 1124 _col = 0; | |
| 1125 _currentToken = _source[_line].text.codeUnitAt(_col); | |
| 1126 } | |
| 1127 | |
| 1128 int _advanceToken([int num, stripWhite=true]) { | |
| 1129 _col++; | |
| 1130 if (_col >= _source[_line].text.codeUnits.length) { | |
| 1131 var col = _col; | |
| 1132 _col = 0; | |
| 1133 _line++; | |
| 1134 if (_line == _source.length) { | |
| 1135 _line--; | |
| 1136 _col = col; | |
| 1137 _currentToken = 0; | |
| 1138 return 0; | |
| 1139 } | |
| 1140 } | |
| 1141 | |
| 1142 while (_source[_line].text.length == 0) { _line++; } | |
| 1143 _currentToken = _source[_line].text.codeUnitAt(_col); | |
| 1144 if (stripWhite && _currentToken == _char(' ')) { | |
| 1145 _advanceToken(); | |
| 1146 } | |
| 1147 if (num != null) { | |
| 1148 for (int i = 1; i < num; i++) { | |
| 1149 _advanceToken(); | |
| 1150 } | |
| 1151 } | |
| 1152 return _currentToken; | |
| 1153 } | |
| 1154 | |
| 1155 int _peek(int len, [stripWhite=true]) { | |
| 1156 int saved_line = _line; | |
| 1157 int saved_col = _col; | |
| 1158 int c = _advanceToken(len,stripWhite); | |
| 1159 _line = saved_line; | |
| 1160 _col = saved_col; | |
| 1161 return c; | |
| 1162 } | |
| 1163 | |
| 1164 void _consumeMultilineString(int quote) { | |
| 1165 _advanceToken(3); | |
| 1166 for (int c = _currentToken; c != 0; c = _advanceToken()) { | |
| 1167 if (c == quote && _peek(1) == quote && _peek(2) == quote) { | |
| 1168 _advanceToken(3); | |
| 1169 break; | |
| 1170 } | |
| 1171 } | |
| 1172 } | |
| 1173 | |
| 1174 void _consumeString(int quote) { | |
| 1175 _advanceToken(); | |
| 1176 for (int c = _currentToken; c != 0; c = _advanceToken()) { | |
| 1177 if (c == _char('\\')) { | |
| 1178 _advanceToken(); | |
| 1179 } | |
| 1180 if (c == quote) { | |
| 1181 _advanceToken(); | |
| 1182 break; | |
| 1183 } | |
| 1184 } | |
| 1185 } | |
| 1186 | |
| 1187 void _consumeComment() { | |
| 1188 _col = _source[_line].text.codeUnits.length; | |
| 1189 } | |
| 1190 | |
| 1191 void _consumeMultilineComment() { | |
| 1192 _advanceToken(2); | |
| 1193 int commentLevel = 1; | |
| 1194 for (int c = _currentToken; c != 0; c = _advanceToken()) { | |
| 1195 if (c == _char('/') && _peek(1, false) == _char('*')) { | |
| 1196 commentLevel++; | |
| 1197 _advanceToken(); | |
| 1198 } else if (c == _char('*') && _peek(1, false) == _char('/')) { | |
| 1199 commentLevel--; | |
| 1200 _advanceToken(); | |
| 1201 if (commentLevel == 0) { | |
| 1202 _advanceToken(); | |
| 1203 break; | |
| 1204 } | |
| 1205 } | |
| 1206 } | |
| 1207 } | |
| 1208 | |
| 1209 /// Finds the end position, i.e., the closing curly brackets of the given | |
| 1210 /// class. | |
| 1211 /// Returns a tuple [line, col]. | |
| 1212 List findEndPos() { | |
| 1213 int level = 0; | |
| 1214 _initTokens(); | |
| 1215 for (int c = _currentToken; c != 0; c=_currentToken) { | |
| 1216 if ((c == _char("'") && | |
| 1217 _peek(1) == _char("'") && | |
| 1218 _peek(2) == _char("'")) || | |
| 1219 (c == _char('"') && | |
| 1220 _peek(1) == _char('"') && | |
| 1221 _peek(2) == _char('"'))) { | |
| 1222 _consumeMultilineString(c); | |
| 1223 continue; | |
| 1224 } else if (c == _char("'") || c == _char('"')) { | |
| 1225 _consumeString(c); | |
| 1226 continue; | |
| 1227 } else if (c == _char('/') && _peek(1, false) == _char('/')) { | |
| 1228 _consumeComment(); | |
| 1229 continue; | |
| 1230 } else if (c == _char('/') && _peek(1, false) == _char('*')) { | |
| 1231 _consumeMultilineComment(); | |
| 1232 continue; | |
| 1233 } else if (c == _char('{')) { | |
| 1234 level++; | |
| 1235 } else if (c == _char('}')) { | |
| 1236 if (--level == 0) { | |
| 1237 break; | |
| 1238 } | |
| 1239 } | |
| 1240 c = _advanceToken(); | |
| 1241 } | |
| 1242 return [_line + _offset, _col + 1]; | |
| 1243 } | |
| 1244 } | |
| 1245 | |
| 1106 class Class extends ServiceObject with Coverage { | 1246 class Class extends ServiceObject with Coverage { |
| 1107 @observable Library library; | 1247 @observable Library library; |
| 1108 @observable Script script; | 1248 @observable Script script; |
| 1109 @observable Class superClass; | 1249 @observable Class superClass; |
| 1110 | 1250 |
| 1111 @observable bool isAbstract; | 1251 @observable bool isAbstract; |
| 1112 @observable bool isConst; | 1252 @observable bool isConst; |
| 1113 @observable bool isFinalized; | 1253 @observable bool isFinalized; |
| 1114 @observable bool isPatch; | 1254 @observable bool isPatch; |
| 1115 @observable bool isImplemented; | 1255 @observable bool isImplemented; |
| 1116 | 1256 |
| 1117 @observable int tokenPos; | 1257 @observable int tokenPos; |
| 1118 | 1258 |
| 1259 int _endTokenPos = null; | |
| 1260 @observable int get endTokenPos { | |
| 1261 if (_endTokenPos == null) { | |
| 1262 _computeEndTokenPos(); | |
| 1263 } | |
| 1264 return _endTokenPos; | |
| 1265 } | |
| 1266 | |
| 1119 @observable ServiceMap error; | 1267 @observable ServiceMap error; |
| 1120 | 1268 |
| 1121 final Allocations newSpace = new Allocations(); | 1269 final Allocations newSpace = new Allocations(); |
| 1122 final Allocations oldSpace = new Allocations(); | 1270 final Allocations oldSpace = new Allocations(); |
| 1123 | 1271 |
| 1124 bool get hasNoAllocations => newSpace.empty && oldSpace.empty; | 1272 bool get hasNoAllocations => newSpace.empty && oldSpace.empty; |
| 1125 | 1273 |
| 1126 @reflectable final children = new ObservableList<Class>(); | 1274 @reflectable final children = new ObservableList<Class>(); |
| 1127 @reflectable final subClasses = new ObservableList<Class>(); | 1275 @reflectable final subClasses = new ObservableList<Class>(); |
| 1128 @reflectable final fields = new ObservableList<ServiceMap>(); | 1276 @reflectable final fields = new ObservableList<ServiceMap>(); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1194 void _addToChildren(Class cls) { | 1342 void _addToChildren(Class cls) { |
| 1195 if (children.contains(cls)) { | 1343 if (children.contains(cls)) { |
| 1196 return; | 1344 return; |
| 1197 } | 1345 } |
| 1198 children.add(cls); | 1346 children.add(cls); |
| 1199 } | 1347 } |
| 1200 | 1348 |
| 1201 Future<ServiceObject> get(String command) { | 1349 Future<ServiceObject> get(String command) { |
| 1202 return isolate.get(id + "/$command"); | 1350 return isolate.get(id + "/$command"); |
| 1203 } | 1351 } |
| 1352 | |
| 1353 void _computeEndTokenPos() { | |
| 1354 script.load().whenComplete(() { | |
| 1355 int line = script.tokenToLine(tokenPos); // Lines are 1-based. | |
| 1356 ClassParser clsp = new ClassParser(script.lines.sublist(line - 1)); | |
| 1357 List posTuple = clsp.findEndPos(); | |
| 1358 // Search for the token one this line and column. | |
| 1359 List tokenCandidates = []; | |
| 1360 script._tokenToLine.forEach((k,v) { | |
| 1361 if (script._tokenToLine[k] == posTuple[0]) { | |
| 1362 tokenCandidates.add(k); | |
| 1363 } | |
| 1364 }); | |
| 1365 Iterable tokenIndex = | |
| 1366 tokenCandidates.where((e) => script._tokenToCol[e] == posTuple[1]); | |
| 1367 assert(tokenIndex.length == 1); | |
| 1368 _endTokenPos = tokenIndex.first; | |
| 1369 notifyPropertyChange(#endTokenPos, null, _endTokenPos); | |
| 1370 }); | |
| 1371 } | |
| 1204 } | 1372 } |
| 1205 | 1373 |
| 1206 class ScriptLine extends Observable { | 1374 class ScriptLine extends Observable { |
| 1207 final int line; | 1375 final int line; |
| 1208 final String text; | 1376 final String text; |
| 1209 @observable int hits; | 1377 @observable int hits; |
| 1210 ScriptLine(this.line, this.text); | 1378 ScriptLine(this.line, this.text); |
| 1211 } | 1379 } |
| 1212 | 1380 |
| 1213 class Script extends ServiceObject with Coverage { | 1381 class Script extends ServiceObject with Coverage { |
| (...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1902 var v = list[i]; | 2070 var v = list[i]; |
| 1903 if ((v is ObservableMap) && _isServiceMap(v)) { | 2071 if ((v is ObservableMap) && _isServiceMap(v)) { |
| 1904 list[i] = owner.getFromMap(v); | 2072 list[i] = owner.getFromMap(v); |
| 1905 } else if (v is ObservableList) { | 2073 } else if (v is ObservableList) { |
| 1906 _upgradeObservableList(v, owner); | 2074 _upgradeObservableList(v, owner); |
| 1907 } else if (v is ObservableMap) { | 2075 } else if (v is ObservableMap) { |
| 1908 _upgradeObservableMap(v, owner); | 2076 _upgradeObservableMap(v, owner); |
| 1909 } | 2077 } |
| 1910 } | 2078 } |
| 1911 } | 2079 } |
| OLD | NEW |