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

Side by Side Diff: pkg/compiler/lib/src/js_emitter/full_emitter/emitter.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) 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 dart2js.js_emitter.full_emitter; 5 library dart2js.js_emitter.full_emitter;
6 6
7 import 'dart:collection' show HashMap; 7 import 'dart:collection' show HashMap;
8 import 'dart:convert'; 8 import 'dart:convert';
9 9
10 import 'package:js_runtime/shared/embedded_names.dart' as embeddedNames; 10 import 'package:js_runtime/shared/embedded_names.dart' as embeddedNames;
11 import 'package:js_runtime/shared/embedded_names.dart' 11 import 'package:js_runtime/shared/embedded_names.dart'
12 show JsBuiltin, JsGetName; 12 show JsBuiltin, JsGetName;
13 13
14 import '../../common.dart'; 14 import '../../common.dart';
15 import '../../common/names.dart' show Names; 15 import '../../common/names.dart' show Names;
16 import '../../compiler.dart' show Compiler; 16 import '../../compiler.dart' show Compiler;
17 import '../../constants/values.dart'; 17 import '../../constants/values.dart';
18 import '../../core_types.dart' show CoreClasses; 18 import '../../core_types.dart' show CommonElements;
19 import '../../dart_types.dart' show DartType; 19 import '../../dart_types.dart' show DartType;
20 import '../../deferred_load.dart' show OutputUnit; 20 import '../../deferred_load.dart' show OutputUnit;
21 import '../../elements/elements.dart' 21 import '../../elements/elements.dart'
22 show 22 show
23 ClassElement, 23 ClassElement,
24 Element, 24 Element,
25 Elements, 25 Elements,
26 FieldElement, 26 FieldElement,
27 FunctionElement, 27 FunctionElement,
28 FunctionSignature, 28 FunctionSignature,
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 120
121 /// True if [ContainerBuilder.addMemberMethodFromInfo] used "structured info", 121 /// True if [ContainerBuilder.addMemberMethodFromInfo] used "structured info",
122 /// that is, some function was needed for reflection, had stubs, or had a 122 /// that is, some function was needed for reflection, had stubs, or had a
123 /// super alias. 123 /// super alias.
124 bool needsStructuredMemberInfo = false; 124 bool needsStructuredMemberInfo = false;
125 125
126 final Namer namer; 126 final Namer namer;
127 ConstantEmitter constantEmitter; 127 ConstantEmitter constantEmitter;
128 NativeEmitter get nativeEmitter => task.nativeEmitter; 128 NativeEmitter get nativeEmitter => task.nativeEmitter;
129 TypeTestRegistry get typeTestRegistry => task.typeTestRegistry; 129 TypeTestRegistry get typeTestRegistry => task.typeTestRegistry;
130 CoreClasses get coreClasses => compiler.coreClasses; 130 CommonElements get commonElements => compiler.commonElements;
131 131
132 // The full code that is written to each hunk part-file. 132 // The full code that is written to each hunk part-file.
133 Map<OutputUnit, CodeOutput> outputBuffers = new Map<OutputUnit, CodeOutput>(); 133 Map<OutputUnit, CodeOutput> outputBuffers = new Map<OutputUnit, CodeOutput>();
134 134
135 String classesCollector; 135 String classesCollector;
136 final Map<jsAst.Name, String> mangledFieldNames = 136 final Map<jsAst.Name, String> mangledFieldNames =
137 new HashMap<jsAst.Name, String>(); 137 new HashMap<jsAst.Name, String>();
138 final Map<jsAst.Name, String> mangledGlobalFieldNames = 138 final Map<jsAst.Name, String> mangledGlobalFieldNames =
139 new HashMap<jsAst.Name, String>(); 139 new HashMap<jsAst.Name, String>();
140 final Set<jsAst.Name> recordedMangledNames = new Set<jsAst.Name>(); 140 final Set<jsAst.Name> recordedMangledNames = new Set<jsAst.Name>();
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 @override 360 @override
361 jsAst.PropertyAccess typeAccess(Element element) { 361 jsAst.PropertyAccess typeAccess(Element element) {
362 return globalPropertyAccess(element); 362 return globalPropertyAccess(element);
363 } 363 }
364 364
365 @override 365 @override
366 jsAst.Template templateForBuiltin(JsBuiltin builtin) { 366 jsAst.Template templateForBuiltin(JsBuiltin builtin) {
367 switch (builtin) { 367 switch (builtin) {
368 case JsBuiltin.dartObjectConstructor: 368 case JsBuiltin.dartObjectConstructor:
369 return jsAst.js 369 return jsAst.js
370 .expressionTemplateYielding(typeAccess(coreClasses.objectClass)); 370 .expressionTemplateYielding(typeAccess(commonElements.objectClass));
371 371
372 case JsBuiltin.isCheckPropertyToJsConstructorName: 372 case JsBuiltin.isCheckPropertyToJsConstructorName:
373 int isPrefixLength = namer.operatorIsPrefix.length; 373 int isPrefixLength = namer.operatorIsPrefix.length;
374 return jsAst.js.expressionTemplateFor('#.substring($isPrefixLength)'); 374 return jsAst.js.expressionTemplateFor('#.substring($isPrefixLength)');
375 375
376 case JsBuiltin.isFunctionType: 376 case JsBuiltin.isFunctionType:
377 return backend.rtiEncoder.templateForIsFunctionType; 377 return backend.rtiEncoder.templateForIsFunctionType;
378 378
379 case JsBuiltin.rawRtiToJsConstructorName: 379 case JsBuiltin.rawRtiToJsConstructorName:
380 return jsAst.js.expressionTemplateFor("#.$typeNameProperty"); 380 return jsAst.js.expressionTemplateFor("#.$typeNameProperty");
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 subclassReadGenerator, interceptorsByTagAccess, leafTagsAccess); 433 subclassReadGenerator, interceptorsByTagAccess, leafTagsAccess);
434 } 434 }
435 435
436 jsAst.ObjectInitializer generateInterceptedNamesSet() { 436 jsAst.ObjectInitializer generateInterceptedNamesSet() {
437 return interceptorEmitter.generateInterceptedNamesSet(); 437 return interceptorEmitter.generateInterceptedNamesSet();
438 } 438 }
439 439
440 /// In minified mode we want to keep the name for the most common core types. 440 /// In minified mode we want to keep the name for the most common core types.
441 bool _isNativeTypeNeedingReflectionName(Element element) { 441 bool _isNativeTypeNeedingReflectionName(Element element) {
442 if (!element.isClass) return false; 442 if (!element.isClass) return false;
443 return (element == coreClasses.intClass || 443 return (element == commonElements.intClass ||
444 element == coreClasses.doubleClass || 444 element == commonElements.doubleClass ||
445 element == coreClasses.numClass || 445 element == commonElements.numClass ||
446 element == coreClasses.stringClass || 446 element == commonElements.stringClass ||
447 element == coreClasses.boolClass || 447 element == commonElements.boolClass ||
448 element == coreClasses.nullClass || 448 element == commonElements.nullClass ||
449 element == coreClasses.listClass); 449 element == commonElements.listClass);
450 } 450 }
451 451
452 /// Returns the "reflection name" of an [Element] or [Selector]. 452 /// Returns the "reflection name" of an [Element] or [Selector].
453 /// The reflection name of a getter 'foo' is 'foo'. 453 /// The reflection name of a getter 'foo' is 'foo'.
454 /// The reflection name of a setter 'foo' is 'foo='. 454 /// The reflection name of a setter 'foo' is 'foo='.
455 /// The reflection name of a method 'foo' is 'foo:N:M:O', where N is the 455 /// The reflection name of a method 'foo' is 'foo:N:M:O', where N is the
456 /// number of required arguments, M is the number of optional arguments, and 456 /// number of required arguments, M is the number of optional arguments, and
457 /// O is the named arguments. 457 /// O is the named arguments.
458 /// The reflection name of a constructor is similar to a regular method but 458 /// The reflection name of a constructor is similar to a regular method but
459 /// starts with 'new '. 459 /// starts with 'new '.
(...skipping 770 matching lines...) Expand 10 before | Expand all | Expand 10 after
1230 task.metadataCollector.reifyType(type, ignoreTypeVariables: true); 1230 task.metadataCollector.reifyType(type, ignoreTypeVariables: true);
1231 ClassBuilder builder = new ClassBuilder.forStatics(typedef, namer); 1231 ClassBuilder builder = new ClassBuilder.forStatics(typedef, namer);
1232 builder.addPropertyByName( 1232 builder.addPropertyByName(
1233 embeddedNames.TYPEDEF_TYPE_PROPERTY_NAME, typeIndex); 1233 embeddedNames.TYPEDEF_TYPE_PROPERTY_NAME, typeIndex);
1234 builder.addPropertyByName( 1234 builder.addPropertyByName(
1235 embeddedNames.TYPEDEF_PREDICATE_PROPERTY_NAME, js.boolean(true)); 1235 embeddedNames.TYPEDEF_PREDICATE_PROPERTY_NAME, js.boolean(true));
1236 1236
1237 // We can be pretty sure that the objectClass is initialized, since 1237 // We can be pretty sure that the objectClass is initialized, since
1238 // typedefs are only emitted with reflection, which requires lots of 1238 // typedefs are only emitted with reflection, which requires lots of
1239 // classes. 1239 // classes.
1240 assert(coreClasses.objectClass != null); 1240 assert(commonElements.objectClass != null);
1241 builder.superName = namer.className(coreClasses.objectClass); 1241 builder.superName = namer.className(commonElements.objectClass);
1242 jsAst.Node declaration = builder.toObjectInitializer(); 1242 jsAst.Node declaration = builder.toObjectInitializer();
1243 jsAst.Name mangledName = namer.globalPropertyName(typedef); 1243 jsAst.Name mangledName = namer.globalPropertyName(typedef);
1244 String reflectionName = getReflectionName(typedef, mangledName); 1244 String reflectionName = getReflectionName(typedef, mangledName);
1245 getElementDescriptor(library, mainFragment) 1245 getElementDescriptor(library, mainFragment)
1246 ..addProperty(mangledName, declaration) 1246 ..addProperty(mangledName, declaration)
1247 ..addPropertyByName("+$reflectionName", js.string('')); 1247 ..addPropertyByName("+$reflectionName", js.string(''));
1248 // Also emit a trivial constructor for CSP mode. 1248 // Also emit a trivial constructor for CSP mode.
1249 jsAst.Name constructorName = mangledName; 1249 jsAst.Name constructorName = mangledName;
1250 jsAst.Expression constructorAst = js('function() {}'); 1250 jsAst.Expression constructorAst = js('function() {}');
1251 List<jsAst.Name> fieldNames = []; 1251 List<jsAst.Name> fieldNames = [];
(...skipping 927 matching lines...) Expand 10 before | Expand all | Expand 10 after
2179 if (cachedElements.isEmpty) return; 2179 if (cachedElements.isEmpty) return;
2180 for (Element element in backend.codegenEnqueuer.newlyEnqueuedElements) { 2180 for (Element element in backend.codegenEnqueuer.newlyEnqueuedElements) {
2181 if (element.isInstanceMember) { 2181 if (element.isInstanceMember) {
2182 cachedClassBuilders.remove(element.enclosingClass); 2182 cachedClassBuilders.remove(element.enclosingClass);
2183 2183
2184 nativeEmitter.cachedBuilders.remove(element.enclosingClass); 2184 nativeEmitter.cachedBuilders.remove(element.enclosingClass);
2185 } 2185 }
2186 } 2186 }
2187 } 2187 }
2188 } 2188 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/js_backend/runtime_types.dart ('k') | pkg/compiler/lib/src/js_emitter/full_emitter/nsm_emitter.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698