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

Side by Side Diff: pkg/compiler/lib/src/js_emitter/full_emitter/emitter.dart

Issue 2942863002: Compile and run Hello World! (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) 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 '../../../compiler_new.dart'; 14 import '../../../compiler_new.dart';
15 import '../../common.dart'; 15 import '../../common.dart';
16 import '../../compiler.dart' show Compiler; 16 import '../../compiler.dart' show Compiler;
17 import '../../constants/values.dart'; 17 import '../../constants/values.dart';
18 import '../../common_elements.dart' show CommonElements, ElementEnvironment; 18 import '../../common_elements.dart' show CommonElements, ElementEnvironment;
19 import '../../elements/resolution_types.dart' show ResolutionDartType; 19 import '../../elements/resolution_types.dart' show ResolutionDartType;
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 ClassElement, ConstructorBodyElement, LibraryElement, TypedefElement;
23 ClassElement,
24 ConstructorBodyElement,
25 FieldElement,
26 LibraryElement,
27 TypedefElement;
28 import '../../elements/entities.dart'; 23 import '../../elements/entities.dart';
29 import '../../elements/entity_utils.dart' as utils; 24 import '../../elements/entity_utils.dart' as utils;
30 import '../../elements/names.dart'; 25 import '../../elements/names.dart';
31 import '../../hash/sha1.dart' show Hasher; 26 import '../../hash/sha1.dart' show Hasher;
32 import '../../io/code_output.dart'; 27 import '../../io/code_output.dart';
33 import '../../io/location_provider.dart' show LocationCollector; 28 import '../../io/location_provider.dart' show LocationCollector;
34 import '../../io/source_map_builder.dart' show SourceMapBuilder; 29 import '../../io/source_map_builder.dart' show SourceMapBuilder;
35 import '../../js/js.dart' as jsAst; 30 import '../../js/js.dart' as jsAst;
36 import '../../js/js.dart' show js; 31 import '../../js/js.dart' show js;
37 import '../../js_backend/js_backend.dart' 32 import '../../js_backend/js_backend.dart'
38 show 33 show
39 ConstantEmitter, 34 ConstantEmitter,
40 JavaScriptBackend, 35 JavaScriptBackend,
41 JavaScriptConstantCompiler,
42 Namer, 36 Namer,
43 SetterName, 37 SetterName,
44 TypeVariableCodegenAnalysis; 38 TypeVariableCodegenAnalysis;
45 import '../../js_backend/native_data.dart'; 39 import '../../js_backend/native_data.dart';
46 import '../../universe/call_structure.dart' show CallStructure; 40 import '../../universe/call_structure.dart' show CallStructure;
47 import '../../universe/selector.dart' show Selector; 41 import '../../universe/selector.dart' show Selector;
48 import '../../universe/world_builder.dart' show CodegenWorldBuilder; 42 import '../../universe/world_builder.dart' show CodegenWorldBuilder;
49 import '../../util/uri_extras.dart' show relativize; 43 import '../../util/uri_extras.dart' show relativize;
50 import '../../world.dart' show ClosedWorld; 44 import '../../world.dart' show ClosedWorld;
51 import '../constant_ordering.dart' show deepCompareConstants; 45 import '../constant_ordering.dart' show deepCompareConstants;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 /// that is, some function was needed for reflection, had stubs, or had a 111 /// that is, some function was needed for reflection, had stubs, or had a
118 /// super alias. 112 /// super alias.
119 bool needsStructuredMemberInfo = false; 113 bool needsStructuredMemberInfo = false;
120 114
121 final Namer namer; 115 final Namer namer;
122 ConstantEmitter constantEmitter; 116 ConstantEmitter constantEmitter;
123 NativeEmitter get nativeEmitter => task.nativeEmitter; 117 NativeEmitter get nativeEmitter => task.nativeEmitter;
124 TypeTestRegistry get typeTestRegistry => task.typeTestRegistry; 118 TypeTestRegistry get typeTestRegistry => task.typeTestRegistry;
125 CommonElements get commonElements => _closedWorld.commonElements; 119 CommonElements get commonElements => _closedWorld.commonElements;
126 ElementEnvironment get _elementEnvironment => _closedWorld.elementEnvironment; 120 ElementEnvironment get _elementEnvironment => _closedWorld.elementEnvironment;
121 CodegenWorldBuilder get _worldBuilder => compiler.codegenWorldBuilder;
127 122
128 // The full code that is written to each hunk part-file. 123 // The full code that is written to each hunk part-file.
129 Map<OutputUnit, CodeOutput> outputBuffers = new Map<OutputUnit, CodeOutput>(); 124 Map<OutputUnit, CodeOutput> outputBuffers = new Map<OutputUnit, CodeOutput>();
130 125
131 String classesCollector; 126 String classesCollector;
132 final Map<jsAst.Name, String> mangledFieldNames = 127 final Map<jsAst.Name, String> mangledFieldNames =
133 new HashMap<jsAst.Name, String>(); 128 new HashMap<jsAst.Name, String>();
134 final Map<jsAst.Name, String> mangledGlobalFieldNames = 129 final Map<jsAst.Name, String> mangledGlobalFieldNames =
135 new HashMap<jsAst.Name, String>(); 130 new HashMap<jsAst.Name, String>();
136 final Set<jsAst.Name> recordedMangledNames = new Set<jsAst.Name>(); 131 final Set<jsAst.Name> recordedMangledNames = new Set<jsAst.Name>();
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 containerBuilder.addMemberMethod(method, builder); 621 containerBuilder.addMemberMethod(method, builder);
627 getStaticMethodDescriptor(element, fragment) 622 getStaticMethodDescriptor(element, fragment)
628 .properties 623 .properties
629 .addAll(builder.properties); 624 .addAll(builder.properties);
630 } 625 }
631 } 626 }
632 627
633 jsAst.Statement buildStaticNonFinalFieldInitializations( 628 jsAst.Statement buildStaticNonFinalFieldInitializations(
634 OutputUnit outputUnit) { 629 OutputUnit outputUnit) {
635 jsAst.Statement buildInitialization( 630 jsAst.Statement buildInitialization(
636 FieldElement element, jsAst.Expression initialValue) { 631 FieldEntity element, jsAst.Expression initialValue) {
637 return js.statement('${namer.staticStateHolder}.# = #', 632 return js.statement('${namer.staticStateHolder}.# = #',
638 [namer.globalPropertyNameForMember(element), initialValue]); 633 [namer.globalPropertyNameForMember(element), initialValue]);
639 } 634 }
640 635
641 bool inMainUnit = (outputUnit == compiler.deferredLoadTask.mainOutputUnit); 636 bool inMainUnit = (outputUnit == compiler.deferredLoadTask.mainOutputUnit);
642 JavaScriptConstantCompiler handler = backend.constants;
643 List<jsAst.Statement> parts = <jsAst.Statement>[]; 637 List<jsAst.Statement> parts = <jsAst.Statement>[];
644 638
645 Iterable<FieldEntity> fields = outputStaticNonFinalFieldLists[outputUnit]; 639 Iterable<FieldEntity> fields = outputStaticNonFinalFieldLists[outputUnit];
646 // If the outputUnit does not contain any static non-final fields, then 640 // If the outputUnit does not contain any static non-final fields, then
647 // [fields] is `null`. 641 // [fields] is `null`.
648 if (fields != null) { 642 if (fields != null) {
649 for (FieldElement element in fields) { 643 for (FieldEntity element in fields) {
650 reporter.withCurrentElement(element, () { 644 reporter.withCurrentElement(element, () {
651 ConstantValue constant = handler.getConstantValue(element.constant); 645 ConstantValue constant =
646 _worldBuilder.getConstantFieldInitializer(element);
652 parts.add(buildInitialization(element, constantReference(constant))); 647 parts.add(buildInitialization(element, constantReference(constant)));
653 }); 648 });
654 } 649 }
655 } 650 }
656 651
657 if (inMainUnit && outputStaticNonFinalFieldLists.length > 1) { 652 if (inMainUnit && outputStaticNonFinalFieldLists.length > 1) {
658 // In the main output-unit we output a stub initializer for deferred 653 // In the main output-unit we output a stub initializer for deferred
659 // variables, so that `isolateProperties` stays a fast object. 654 // variables, so that `isolateProperties` stays a fast object.
660 outputStaticNonFinalFieldLists 655 outputStaticNonFinalFieldLists
661 .forEach((OutputUnit fieldsOutputUnit, Iterable<FieldEntity> fields) { 656 .forEach((OutputUnit fieldsOutputUnit, Iterable<FieldEntity> fields) {
(...skipping 1310 matching lines...) Expand 10 before | Expand all | Expand 10 after
1972 // data. 1967 // data.
1973 mapping["_comment"] = "This mapping shows which compiled `.js` files are " 1968 mapping["_comment"] = "This mapping shows which compiled `.js` files are "
1974 "needed for a given deferred library import."; 1969 "needed for a given deferred library import.";
1975 mapping.addAll(compiler.deferredLoadTask.computeDeferredMap()); 1970 mapping.addAll(compiler.deferredLoadTask.computeDeferredMap());
1976 compiler.outputProvider( 1971 compiler.outputProvider(
1977 compiler.options.deferredMapUri.path, '', OutputType.info) 1972 compiler.options.deferredMapUri.path, '', OutputType.info)
1978 ..add(const JsonEncoder.withIndent(" ").convert(mapping)) 1973 ..add(const JsonEncoder.withIndent(" ").convert(mapping))
1979 ..close(); 1974 ..close();
1980 } 1975 }
1981 } 1976 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/js_backend/namer.dart ('k') | pkg/compiler/lib/src/js_emitter/program_builder/program_builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698