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

Side by Side Diff: pkg/compiler/lib/src/js_backend/constant_system_javascript.dart

Issue 2595493002: Merge CoreTypes and CoreClasses into CommonElements. (Closed)
Patch Set: Updated cf. comment Created 3 years, 12 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 dart2js.constant_system.js; 5 library dart2js.constant_system.js;
6 6
7 import '../compiler.dart' show Compiler; 7 import '../compiler.dart' show Compiler;
8 import '../constant_system_dart.dart'; 8 import '../constant_system_dart.dart';
9 import '../constants/constant_system.dart'; 9 import '../constants/constant_system.dart';
10 import '../constants/values.dart'; 10 import '../constants/values.dart';
11 import '../core_types.dart' show CoreTypes; 11 import '../core_types.dart' show CommonElements;
12 import '../dart_types.dart'; 12 import '../dart_types.dart';
13 import '../elements/elements.dart' show ClassElement, FieldElement; 13 import '../elements/elements.dart' show ClassElement, FieldElement;
14 import '../tree/dartstring.dart' show DartString, LiteralDartString; 14 import '../tree/dartstring.dart' show DartString, LiteralDartString;
15 import 'js_backend.dart'; 15 import 'js_backend.dart';
16 16
17 const JAVA_SCRIPT_CONSTANT_SYSTEM = const JavaScriptConstantSystem(); 17 const JAVA_SCRIPT_CONSTANT_SYSTEM = const JavaScriptConstantSystem();
18 18
19 class JavaScriptBitNotOperation extends BitNotOperation { 19 class JavaScriptBitNotOperation extends BitNotOperation {
20 const JavaScriptBitNotOperation(); 20 const JavaScriptBitNotOperation();
21 21
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 constant.isDouble && !constant.isMinusZero; 327 constant.isDouble && !constant.isMinusZero;
328 bool isString(ConstantValue constant) => constant.isString; 328 bool isString(ConstantValue constant) => constant.isString;
329 bool isBool(ConstantValue constant) => constant.isBool; 329 bool isBool(ConstantValue constant) => constant.isBool;
330 bool isNull(ConstantValue constant) => constant.isNull; 330 bool isNull(ConstantValue constant) => constant.isNull;
331 331
332 bool isSubtype(DartTypes types, DartType s, DartType t) { 332 bool isSubtype(DartTypes types, DartType s, DartType t) {
333 // At runtime, an integer is both an integer and a double: the 333 // At runtime, an integer is both an integer and a double: the
334 // integer type check is Math.floor, which will return true only 334 // integer type check is Math.floor, which will return true only
335 // for real integers, and our double type check is 'typeof number' 335 // for real integers, and our double type check is 'typeof number'
336 // which will return true for both integers and doubles. 336 // which will return true for both integers and doubles.
337 if (s == types.coreTypes.intType && t == types.coreTypes.doubleType) { 337 if (s == types.commonElements.intType &&
338 t == types.commonElements.doubleType) {
338 return true; 339 return true;
339 } 340 }
340 return types.isSubtype(s, t); 341 return types.isSubtype(s, t);
341 } 342 }
342 343
343 MapConstantValue createMap(Compiler compiler, InterfaceType sourceType, 344 MapConstantValue createMap(Compiler compiler, InterfaceType sourceType,
344 List<ConstantValue> keys, List<ConstantValue> values) { 345 List<ConstantValue> keys, List<ConstantValue> values) {
345 JavaScriptBackend backend = compiler.backend; 346 JavaScriptBackend backend = compiler.backend;
346 CoreTypes coreTypes = compiler.coreTypes; 347 CommonElements commonElements = compiler.commonElements;
347 348
348 bool onlyStringKeys = true; 349 bool onlyStringKeys = true;
349 ConstantValue protoValue = null; 350 ConstantValue protoValue = null;
350 for (int i = 0; i < keys.length; i++) { 351 for (int i = 0; i < keys.length; i++) {
351 var key = keys[i]; 352 var key = keys[i];
352 if (key.isString) { 353 if (key.isString) {
353 if (key.primitiveValue == JavaScriptMapConstant.PROTO_PROPERTY) { 354 if (key.primitiveValue == JavaScriptMapConstant.PROTO_PROPERTY) {
354 protoValue = values[i]; 355 protoValue = values[i];
355 } 356 }
356 } else { 357 } else {
357 onlyStringKeys = false; 358 onlyStringKeys = false;
358 // Don't handle __proto__ values specially in the general map case. 359 // Don't handle __proto__ values specially in the general map case.
359 protoValue = null; 360 protoValue = null;
360 break; 361 break;
361 } 362 }
362 } 363 }
363 364
364 bool hasProtoKey = (protoValue != null); 365 bool hasProtoKey = (protoValue != null);
365 DartType keysType; 366 DartType keysType;
366 if (sourceType.treatAsRaw) { 367 if (sourceType.treatAsRaw) {
367 keysType = coreTypes.listType(); 368 keysType = commonElements.listType();
368 } else { 369 } else {
369 keysType = coreTypes.listType(sourceType.typeArguments.first); 370 keysType = commonElements.listType(sourceType.typeArguments.first);
370 } 371 }
371 ListConstantValue keysList = new ListConstantValue(keysType, keys); 372 ListConstantValue keysList = new ListConstantValue(keysType, keys);
372 String className = onlyStringKeys 373 String className = onlyStringKeys
373 ? (hasProtoKey 374 ? (hasProtoKey
374 ? JavaScriptMapConstant.DART_PROTO_CLASS 375 ? JavaScriptMapConstant.DART_PROTO_CLASS
375 : JavaScriptMapConstant.DART_STRING_CLASS) 376 : JavaScriptMapConstant.DART_STRING_CLASS)
376 : JavaScriptMapConstant.DART_GENERAL_CLASS; 377 : JavaScriptMapConstant.DART_GENERAL_CLASS;
377 ClassElement classElement = backend.helpers.jsHelperLibrary.find(className); 378 ClassElement classElement = backend.helpers.jsHelperLibrary.find(className);
378 classElement.ensureResolved(compiler.resolution); 379 classElement.ensureResolved(compiler.resolution);
379 List<DartType> typeArgument = sourceType.typeArguments; 380 List<DartType> typeArgument = sourceType.typeArguments;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 result.add(keyList); 440 result.add(keyList);
440 } else { 441 } else {
441 // Add the keys individually to avoid generating an unused list constant 442 // Add the keys individually to avoid generating an unused list constant
442 // for the keys. 443 // for the keys.
443 result.addAll(keys); 444 result.addAll(keys);
444 } 445 }
445 result.addAll(values); 446 result.addAll(values);
446 return result; 447 return result;
447 } 448 }
448 } 449 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/js_backend/backend_impact.dart ('k') | pkg/compiler/lib/src/js_backend/namer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698