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

Side by Side Diff: pkg/analyzer/lib/src/dart/constant/evaluation.dart

Issue 2624283003: Revert "Add support for generic function type syntax, part 1" (TBR) (Closed)
Patch Set: Created 3 years, 11 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) 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 library analyzer.src.dart.constant.evaluation; 5 library analyzer.src.dart.constant.evaluation;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/context/declared_variables.dart'; 9 import 'package:analyzer/context/declared_variables.dart';
10 import 'package:analyzer/dart/ast/ast.dart'; 10 import 'package:analyzer/dart/ast/ast.dart';
(...skipping 1340 matching lines...) Expand 10 before | Expand all | Expand 10 after
1351 if (elementResult == null) { 1351 if (elementResult == null) {
1352 errorOccurred = true; 1352 errorOccurred = true;
1353 } else { 1353 } else {
1354 elements.add(elementResult); 1354 elements.add(elementResult);
1355 } 1355 }
1356 } 1356 }
1357 if (errorOccurred) { 1357 if (errorOccurred) {
1358 return null; 1358 return null;
1359 } 1359 }
1360 DartType elementType = _typeProvider.dynamicType; 1360 DartType elementType = _typeProvider.dynamicType;
1361 NodeList<TypeAnnotation> typeArgs = node.typeArguments?.arguments; 1361 NodeList<TypeName> typeArgs = node.typeArguments?.arguments;
1362 if (typeArgs?.length == 1) { 1362 if (typeArgs?.length == 1) {
1363 DartType type = visitTypeAnnotation(typeArgs[0])?.toTypeValue(); 1363 DartType type = visitTypeName(typeArgs[0])?.toTypeValue();
1364 if (type != null) { 1364 if (type != null) {
1365 elementType = type; 1365 elementType = type;
1366 } 1366 }
1367 } 1367 }
1368 InterfaceType listType = _typeProvider.listType.instantiate([elementType]); 1368 InterfaceType listType = _typeProvider.listType.instantiate([elementType]);
1369 return new DartObjectImpl(listType, new ListState(elements)); 1369 return new DartObjectImpl(listType, new ListState(elements));
1370 } 1370 }
1371 1371
1372 @override 1372 @override
1373 DartObjectImpl visitMapLiteral(MapLiteral node) { 1373 DartObjectImpl visitMapLiteral(MapLiteral node) {
(...skipping 12 matching lines...) Expand all
1386 errorOccurred = true; 1386 errorOccurred = true;
1387 } else { 1387 } else {
1388 map[keyResult] = valueResult; 1388 map[keyResult] = valueResult;
1389 } 1389 }
1390 } 1390 }
1391 if (errorOccurred) { 1391 if (errorOccurred) {
1392 return null; 1392 return null;
1393 } 1393 }
1394 DartType keyType = _typeProvider.dynamicType; 1394 DartType keyType = _typeProvider.dynamicType;
1395 DartType valueType = _typeProvider.dynamicType; 1395 DartType valueType = _typeProvider.dynamicType;
1396 NodeList<TypeAnnotation> typeArgs = node.typeArguments?.arguments; 1396 NodeList<TypeName> typeArgs = node.typeArguments?.arguments;
1397 if (typeArgs?.length == 2) { 1397 if (typeArgs?.length == 2) {
1398 DartType keyTypeCandidate = 1398 DartType keyTypeCandidate = visitTypeName(typeArgs[0])?.toTypeValue();
1399 visitTypeAnnotation(typeArgs[0])?.toTypeValue();
1400 if (keyTypeCandidate != null) { 1399 if (keyTypeCandidate != null) {
1401 keyType = keyTypeCandidate; 1400 keyType = keyTypeCandidate;
1402 } 1401 }
1403 DartType valueTypeCandidate = 1402 DartType valueTypeCandidate = visitTypeName(typeArgs[1])?.toTypeValue();
1404 visitTypeAnnotation(typeArgs[1])?.toTypeValue();
1405 if (valueTypeCandidate != null) { 1403 if (valueTypeCandidate != null) {
1406 valueType = valueTypeCandidate; 1404 valueType = valueTypeCandidate;
1407 } 1405 }
1408 } 1406 }
1409 InterfaceType mapType = 1407 InterfaceType mapType =
1410 _typeProvider.mapType.instantiate([keyType, valueType]); 1408 _typeProvider.mapType.instantiate([keyType, valueType]);
1411 return new DartObjectImpl(mapType, new MapState(map)); 1409 return new DartObjectImpl(mapType, new MapState(map));
1412 } 1410 }
1413 1411
1414 @override 1412 @override
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
1544 for (int i = 0; i < components.length; i++) { 1542 for (int i = 0; i < components.length; i++) {
1545 if (i > 0) { 1543 if (i > 0) {
1546 buffer.writeCharCode(0x2E); 1544 buffer.writeCharCode(0x2E);
1547 } 1545 }
1548 buffer.write(components[i].lexeme); 1546 buffer.write(components[i].lexeme);
1549 } 1547 }
1550 return new DartObjectImpl( 1548 return new DartObjectImpl(
1551 _typeProvider.symbolType, new SymbolState(buffer.toString())); 1549 _typeProvider.symbolType, new SymbolState(buffer.toString()));
1552 } 1550 }
1553 1551
1554 DartObjectImpl visitTypeAnnotation(TypeAnnotation node) { 1552 @override
1553 DartObjectImpl visitTypeName(TypeName node) {
1555 DartType type = evaluateType(node.type); 1554 DartType type = evaluateType(node.type);
1556 if (type == null) { 1555 if (type == null) {
1557 return super.visitTypeName(node); 1556 return super.visitTypeName(node);
1558 } 1557 }
1559 return typeConstant(type); 1558 return typeConstant(type);
1560 } 1559 }
1561 1560
1562 @override
1563 DartObjectImpl visitTypeName(TypeName node) => visitTypeAnnotation(node);
1564
1565 /** 1561 /**
1566 * Create an error associated with the given [node]. The error will have the 1562 * Create an error associated with the given [node]. The error will have the
1567 * given error [code]. 1563 * given error [code].
1568 */ 1564 */
1569 void _error(AstNode node, ErrorCode code) { 1565 void _error(AstNode node, ErrorCode code) {
1570 _errorReporter.reportErrorForNode( 1566 _errorReporter.reportErrorForNode(
1571 code ?? CompileTimeErrorCode.INVALID_CONSTANT, node); 1567 code ?? CompileTimeErrorCode.INVALID_CONSTANT, node);
1572 } 1568 }
1573 1569
1574 /** 1570 /**
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
2084 } 2080 }
2085 2081
2086 @override 2082 @override
2087 String toString() { 2083 String toString() {
2088 if (value == null) { 2084 if (value == null) {
2089 return "error"; 2085 return "error";
2090 } 2086 }
2091 return value.toString(); 2087 return value.toString();
2092 } 2088 }
2093 } 2089 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/dart/ast/utilities.dart ('k') | pkg/analyzer/lib/src/generated/element_resolver.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698