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

Side by Side Diff: pkg/analyzer/lib/src/summary/resynthesize.dart

Issue 1649873002: Resynthesize binary and prefix expressions. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 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
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 library summary_resynthesizer; 5 library summary_resynthesizer;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/element/element.dart'; 10 import 'package:analyzer/dart/element/element.dart';
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 int doublePtr = 0; 256 int doublePtr = 0;
257 int stringPtr = 0; 257 int stringPtr = 0;
258 int refPtr = 0; 258 int refPtr = 0;
259 final List<Expression> stack = <Expression>[]; 259 final List<Expression> stack = <Expression>[];
260 260
261 _ConstExprBuilder(this.resynthesizer, this.uc); 261 _ConstExprBuilder(this.resynthesizer, this.uc);
262 262
263 Expression get expr => stack.single; 263 Expression get expr => stack.single;
264 264
265 Expression build() { 265 Expression build() {
266 // TODO(scheglov) complete implementation
267 for (UnlinkedConstOperation operation in uc.operations) { 266 for (UnlinkedConstOperation operation in uc.operations) {
268 switch (operation) { 267 switch (operation) {
269 case UnlinkedConstOperation.pushNull: 268 case UnlinkedConstOperation.pushNull:
270 stack.add(AstFactory.nullLiteral()); 269 _push(AstFactory.nullLiteral());
271 break; 270 break;
271 // bool
272 case UnlinkedConstOperation.pushFalse: 272 case UnlinkedConstOperation.pushFalse:
273 stack.add(AstFactory.booleanLiteral(false)); 273 _push(AstFactory.booleanLiteral(false));
274 break; 274 break;
275 case UnlinkedConstOperation.pushTrue: 275 case UnlinkedConstOperation.pushTrue:
276 stack.add(AstFactory.booleanLiteral(true)); 276 _push(AstFactory.booleanLiteral(true));
277 break; 277 break;
278 // literals
278 case UnlinkedConstOperation.pushInt: 279 case UnlinkedConstOperation.pushInt:
279 int value = uc.ints[intPtr++]; 280 int value = uc.ints[intPtr++];
280 stack.add(AstFactory.integer(value)); 281 _push(AstFactory.integer(value));
282 break;
283 case UnlinkedConstOperation.shiftOr:
284 int top = (_pop() as IntegerLiteral).value;
285 int value = uc.ints[intPtr++];
286 _push(AstFactory.integer(top << 32 | value));
281 break; 287 break;
282 case UnlinkedConstOperation.pushDouble: 288 case UnlinkedConstOperation.pushDouble:
283 double value = uc.doubles[doublePtr++]; 289 double value = uc.doubles[doublePtr++];
284 stack.add(AstFactory.doubleLiteral(value)); 290 _push(AstFactory.doubleLiteral(value));
285 break; 291 break;
292 case UnlinkedConstOperation.makeSymbol:
293 SimpleStringLiteral literal = _pop();
294 _push(AstFactory.symbolLiteral([literal.value]));
295 break;
296 // String
286 case UnlinkedConstOperation.pushString: 297 case UnlinkedConstOperation.pushString:
287 String value = uc.strings[stringPtr++]; 298 String value = uc.strings[stringPtr++];
288 stack.add(AstFactory.string2(value)); 299 _push(AstFactory.string2(value));
289 break; 300 break;
290 case UnlinkedConstOperation.concatenate: 301 case UnlinkedConstOperation.concatenate:
291 int count = uc.ints[intPtr++]; 302 int count = uc.ints[intPtr++];
292 List<InterpolationElement> elements = <InterpolationElement>[]; 303 List<InterpolationElement> elements = <InterpolationElement>[];
293 for (int i = 0; i < count; i++) { 304 for (int i = 0; i < count; i++) {
294 Expression expr = stack.removeLast(); 305 Expression expr = _pop();
295 InterpolationElement element = _newInterpolationElement(expr); 306 InterpolationElement element = _newInterpolationElement(expr);
296 elements.insert(0, element); 307 elements.insert(0, element);
297 } 308 }
298 stack.add(AstFactory.string(elements)); 309 _push(AstFactory.string(elements));
299 break; 310 break;
300 default: 311 // binary
312 case UnlinkedConstOperation.equal:
313 _pushBinary(TokenType.EQ_EQ);
314 break;
315 case UnlinkedConstOperation.and:
316 _pushBinary(TokenType.AMPERSAND_AMPERSAND);
317 break;
318 case UnlinkedConstOperation.or:
319 _pushBinary(TokenType.BAR_BAR);
320 break;
321 case UnlinkedConstOperation.bitXor:
322 _pushBinary(TokenType.CARET);
323 break;
324 case UnlinkedConstOperation.bitAnd:
325 _pushBinary(TokenType.AMPERSAND);
326 break;
327 case UnlinkedConstOperation.bitOr:
328 _pushBinary(TokenType.BAR);
329 break;
330 case UnlinkedConstOperation.bitShiftLeft:
331 _pushBinary(TokenType.LT_LT);
332 break;
333 case UnlinkedConstOperation.bitShiftRight:
334 _pushBinary(TokenType.GT_GT);
335 break;
336 case UnlinkedConstOperation.add:
337 _pushBinary(TokenType.PLUS);
338 break;
339 case UnlinkedConstOperation.subtract:
340 _pushBinary(TokenType.MINUS);
341 break;
342 case UnlinkedConstOperation.multiply:
343 _pushBinary(TokenType.STAR);
344 break;
345 case UnlinkedConstOperation.divide:
346 _pushBinary(TokenType.SLASH);
347 break;
348 case UnlinkedConstOperation.floorDivide:
349 _pushBinary(TokenType.TILDE_SLASH);
350 break;
351 case UnlinkedConstOperation.modulo:
352 _pushBinary(TokenType.PERCENT);
353 break;
354 case UnlinkedConstOperation.greater:
355 _pushBinary(TokenType.GT);
356 break;
357 case UnlinkedConstOperation.greaterEqual:
358 _pushBinary(TokenType.GT_EQ);
359 break;
360 case UnlinkedConstOperation.less:
361 _pushBinary(TokenType.LT);
362 break;
363 case UnlinkedConstOperation.lessEqual:
364 _pushBinary(TokenType.LT_EQ);
365 break;
366 // prefix
367 case UnlinkedConstOperation.complement:
368 _pushPrefix(TokenType.TILDE);
369 break;
370 case UnlinkedConstOperation.negate:
371 _pushPrefix(TokenType.MINUS);
372 break;
373 case UnlinkedConstOperation.not:
374 _pushPrefix(TokenType.BANG);
375 break;
376 // conditional
377 case UnlinkedConstOperation.conditional:
378 Expression elseExpr = _pop();
379 Expression thenExpr = _pop();
380 Expression condition = _pop();
381 _push(
382 AstFactory.conditionalExpression(condition, thenExpr, elseExpr));
383 break;
384 // identical
385 case UnlinkedConstOperation.identical:
386 Expression second = _pop();
387 Expression first = _pop();
388 _push(AstFactory.methodInvocation(
389 null, 'identical', <Expression>[first, second]));
390 break;
391 // TODO(scheglov) complete implementation
392 case UnlinkedConstOperation.makeUntypedList:
393 case UnlinkedConstOperation.makeTypedList:
394 case UnlinkedConstOperation.makeUntypedMap:
395 case UnlinkedConstOperation.makeTypedMap:
396 case UnlinkedConstOperation.pushReference:
397 case UnlinkedConstOperation.invokeConstructor:
398 case UnlinkedConstOperation.length:
301 return AstFactory.nullLiteral(); 399 return AstFactory.nullLiteral();
302 // throw new StateError('Unsupported constant operation $operation'); 400 // throw new StateError('Unsupported constant operation $operation');
303 } 401 }
304 } 402 }
305 return stack.single; 403 return stack.single;
306 } 404 }
307 405
308 InterpolationElement _newInterpolationElement(Expression expr) { 406 InterpolationElement _newInterpolationElement(Expression expr) {
309 if (expr is SimpleStringLiteral) { 407 if (expr is SimpleStringLiteral) {
310 return new InterpolationString(expr.literal, expr.value); 408 return new InterpolationString(expr.literal, expr.value);
311 } else { 409 } else {
312 return new InterpolationExpression( 410 return new InterpolationExpression(
313 TokenFactory.tokenFromType(TokenType.STRING_INTERPOLATION_EXPRESSION), 411 TokenFactory.tokenFromType(TokenType.STRING_INTERPOLATION_EXPRESSION),
314 expr, 412 expr,
315 TokenFactory.tokenFromType(TokenType.CLOSE_CURLY_BRACKET)); 413 TokenFactory.tokenFromType(TokenType.CLOSE_CURLY_BRACKET));
316 } 414 }
317 } 415 }
416
417 Expression _pop() => stack.removeLast();
418
419 void _push(Expression expr) {
420 stack.add(expr);
421 }
422
423 void _pushBinary(TokenType operator) {
424 Expression right = _pop();
425 Expression left = _pop();
426 _push(AstFactory.binaryExpression(left, operator, right));
427 }
428
429 void _pushPrefix(TokenType operator) {
430 Expression operand = _pop();
431 _push(AstFactory.prefixExpression(operator, operand));
432 }
318 } 433 }
319 434
320 /** 435 /**
321 * A single constant variable for which the constant value should be computed. 436 * A single constant variable for which the constant value should be computed.
322 * 437 *
323 * TODO(scheglov) we will probably need to add dependency list 438 * TODO(scheglov) we will probably need to add dependency list
324 */ 439 */
325 class _ConstVariable { 440 class _ConstVariable {
326 final ConstVariableElement element; 441 final ConstVariableElement element;
327 442
(...skipping 1033 matching lines...) Expand 10 before | Expand all | Expand 10 after
1361 for (PropertyAccessorElementImpl accessor in unit.accessors) { 1476 for (PropertyAccessorElementImpl accessor in unit.accessors) {
1362 elementMap[accessor.identifier] = accessor; 1477 elementMap[accessor.identifier] = accessor;
1363 } 1478 }
1364 resummarizedElements[absoluteUri] = elementMap; 1479 resummarizedElements[absoluteUri] = elementMap;
1365 unitHolder = null; 1480 unitHolder = null;
1366 linkedUnit = null; 1481 linkedUnit = null;
1367 unlinkedUnit = null; 1482 unlinkedUnit = null;
1368 linkedTypeMap = null; 1483 linkedTypeMap = null;
1369 } 1484 }
1370 } 1485 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/format.dart ('k') | pkg/analyzer/test/src/summary/resynthesize_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698