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

Side by Side Diff: pkg/compiler/lib/src/ssa/kernel_ast_adapter.dart

Issue 2918913003: Handle list and map literals (Closed)
Patch Set: Rebased Created 3 years, 6 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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 import 'package:js_runtime/shared/embedded_names.dart'; 5 import 'package:js_runtime/shared/embedded_names.dart';
6 import 'package:kernel/ast.dart' as ir; 6 import 'package:kernel/ast.dart' as ir;
7 7
8 import '../closure.dart'; 8 import '../closure.dart';
9 import '../common.dart'; 9 import '../common.dart';
10 import '../compiler.dart'; 10 import '../compiler.dart';
11 import '../constants/expressions.dart'; 11 import '../constants/expressions.dart';
12 import '../constants/values.dart'; 12 import '../constants/values.dart';
13 import '../common_elements.dart'; 13 import '../common_elements.dart';
14 import '../elements/resolution_types.dart';
15 import '../elements/elements.dart'; 14 import '../elements/elements.dart';
16 import '../elements/entities.dart'; 15 import '../elements/entities.dart';
17 import '../elements/modelx.dart'; 16 import '../elements/modelx.dart';
17 import '../elements/resolution_types.dart';
18 import '../elements/types.dart';
18 import '../js/js.dart' as js; 19 import '../js/js.dart' as js;
19 import '../js_backend/js_backend.dart'; 20 import '../js_backend/js_backend.dart';
20 import '../kernel/element_map.dart'; 21 import '../kernel/element_map.dart';
21 import '../kernel/kernel.dart'; 22 import '../kernel/kernel.dart';
22 import '../native/native.dart' as native; 23 import '../native/native.dart' as native;
23 import '../resolution/tree_elements.dart'; 24 import '../resolution/tree_elements.dart';
24 import '../tree/tree.dart' as ast; 25 import '../tree/tree.dart' as ast;
25 import '../types/masks.dart'; 26 import '../types/masks.dart';
26 import '../types/types.dart'; 27 import '../types/types.dart';
27 import '../universe/selector.dart'; 28 import '../universe/selector.dart';
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 assert(constant.fields.length == 1 || constant.fields.length == 2); 303 assert(constant.fields.length == 1 || constant.fields.length == 2);
303 ConstantValue indexConstant = constant.fields.values.first; 304 ConstantValue indexConstant = constant.fields.values.first;
304 if (indexConstant is IntConstantValue) { 305 if (indexConstant is IntConstantValue) {
305 return indexConstant.primitiveValue; 306 return indexConstant.primitiveValue;
306 } 307 }
307 } 308 }
308 } 309 }
309 return null; 310 return null;
310 } 311 }
311 312
312 ResolutionDartType getDartType(ir.DartType type) { 313 DartType getDartType(ir.DartType type) {
313 return _typeConverter.convert(type); 314 return _typeConverter.convert(type);
314 } 315 }
315 316
316 List<ResolutionDartType> getDartTypes(List<ir.DartType> types) { 317 List<DartType> getDartTypes(List<ir.DartType> types) {
317 return types.map(getDartType).toList(); 318 return types.map(getDartType).toList();
318 } 319 }
319 320
320 ResolutionInterfaceType getDartTypeOfListLiteral(ir.ListLiteral list) {
321 ast.Node node = getNodeOrNull(list);
322 if (node != null) return elements.getType(node);
323 assertNodeIsSynthetic(list);
324 return _compiler.commonElements.listType(getDartType(list.typeArgument));
325 }
326
327 ResolutionInterfaceType getDartTypeOfMapLiteral(ir.MapLiteral literal) {
328 ast.Node node = getNodeOrNull(literal);
329 if (node != null) return elements.getType(node);
330 assertNodeIsSynthetic(literal);
331 return _compiler.commonElements
332 .mapType(getDartType(literal.keyType), getDartType(literal.valueType));
333 }
334
335 /// Computes the function type corresponding the signature of [node]. 321 /// Computes the function type corresponding the signature of [node].
336 ResolutionFunctionType getFunctionType(ir.FunctionNode node) { 322 FunctionType getFunctionType(ir.FunctionNode node) {
337 ResolutionDartType returnType = getDartType(node.returnType); 323 ResolutionDartType returnType = getDartType(node.returnType);
338 List<ResolutionDartType> parameterTypes = <ResolutionDartType>[]; 324 List<ResolutionDartType> parameterTypes = <ResolutionDartType>[];
339 List<ResolutionDartType> optionalParameterTypes = <ResolutionDartType>[]; 325 List<ResolutionDartType> optionalParameterTypes = <ResolutionDartType>[];
340 for (ir.VariableDeclaration variable in node.positionalParameters) { 326 for (ir.VariableDeclaration variable in node.positionalParameters) {
341 if (parameterTypes.length == node.requiredParameterCount) { 327 if (parameterTypes.length == node.requiredParameterCount) {
342 optionalParameterTypes.add(getDartType(variable.type)); 328 optionalParameterTypes.add(getDartType(variable.type));
343 } else { 329 } else {
344 parameterTypes.add(getDartType(variable.type)); 330 parameterTypes.add(getDartType(variable.type));
345 } 331 }
346 } 332 }
347 List<String> namedParameters = <String>[]; 333 List<String> namedParameters = <String>[];
348 List<ResolutionDartType> namedParameterTypes = <ResolutionDartType>[]; 334 List<ResolutionDartType> namedParameterTypes = <ResolutionDartType>[];
349 List<ir.VariableDeclaration> sortedNamedParameters = 335 List<ir.VariableDeclaration> sortedNamedParameters =
350 node.namedParameters.toList()..sort((a, b) => a.name.compareTo(b.name)); 336 node.namedParameters.toList()..sort((a, b) => a.name.compareTo(b.name));
351 for (ir.VariableDeclaration variable in sortedNamedParameters) { 337 for (ir.VariableDeclaration variable in sortedNamedParameters) {
352 namedParameters.add(variable.name); 338 namedParameters.add(variable.name);
353 namedParameterTypes.add(getDartType(variable.type)); 339 namedParameterTypes.add(getDartType(variable.type));
354 } 340 }
355 return new ResolutionFunctionType.synthesized(returnType, parameterTypes, 341 return new ResolutionFunctionType.synthesized(returnType, parameterTypes,
356 optionalParameterTypes, namedParameters, namedParameterTypes); 342 optionalParameterTypes, namedParameters, namedParameterTypes);
357 } 343 }
358 344
359 ResolutionInterfaceType getInterfaceType(ir.InterfaceType type) => 345 InterfaceType getInterfaceType(ir.InterfaceType type) => getDartType(type);
360 getDartType(type);
361 346
362 ResolutionInterfaceType createInterfaceType( 347 InterfaceType createInterfaceType(
363 ir.Class cls, List<ir.DartType> typeArguments) { 348 ir.Class cls, List<ir.DartType> typeArguments) {
364 return new ResolutionInterfaceType( 349 return new ResolutionInterfaceType(
365 getClass(cls), getDartTypes(typeArguments)); 350 getClass(cls), getDartTypes(typeArguments));
366 } 351 }
367 352
368 MemberEntity getConstructorBodyEntity(ir.Constructor constructor) { 353 MemberEntity getConstructorBodyEntity(ir.Constructor constructor) {
369 AstElement element = getElement(constructor); 354 AstElement element = getElement(constructor);
370 MemberEntity constructorBody = 355 MemberEntity constructorBody =
371 ConstructorBodyElementX.createFromResolvedAst(element.resolvedAst); 356 ConstructorBodyElementX.createFromResolvedAst(element.resolvedAst);
372 assert(constructorBody != null); 357 assert(constructorBody != null);
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 TypeMask selectorTypeOf(Selector selector, TypeMask mask) { 670 TypeMask selectorTypeOf(Selector selector, TypeMask mask) {
686 return TypeMaskFactory.inferredTypeForSelector( 671 return TypeMaskFactory.inferredTypeForSelector(
687 selector, mask, _globalInferenceResults); 672 selector, mask, _globalInferenceResults);
688 } 673 }
689 674
690 TypeMask typeFromNativeBehavior( 675 TypeMask typeFromNativeBehavior(
691 native.NativeBehavior nativeBehavior, ClosedWorld closedWorld) { 676 native.NativeBehavior nativeBehavior, ClosedWorld closedWorld) {
692 return TypeMaskFactory.fromNativeBehavior(nativeBehavior, closedWorld); 677 return TypeMaskFactory.fromNativeBehavior(nativeBehavior, closedWorld);
693 } 678 }
694 } 679 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698