| OLD | NEW |
| 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.compiler_base; | 5 library dart2js.compiler_base; |
| 6 | 6 |
| 7 import 'dart:async' show EventSink, Future; | 7 import 'dart:async' show EventSink, Future; |
| 8 | 8 |
| 9 import '../compiler_new.dart' as api; | 9 import '../compiler_new.dart' as api; |
| 10 import 'closure.dart' as closureMapping show ClosureTask; | 10 import 'closure.dart' as closureMapping show ClosureTask; |
| 11 import 'common/names.dart' show Selectors; | 11 import 'common/names.dart' show Selectors; |
| 12 import 'common/names.dart' show Identifiers, Uris; | 12 import 'common/names.dart' show Identifiers, Uris; |
| 13 import 'common/resolution.dart' | 13 import 'common/resolution.dart' |
| 14 show | 14 show |
| 15 ParsingContext, | 15 ParsingContext, |
| 16 Resolution, | 16 Resolution, |
| 17 ResolutionWorkItem, | 17 ResolutionWorkItem, |
| 18 ResolutionImpact, | 18 ResolutionImpact, |
| 19 Target; | 19 Target; |
| 20 import 'common/tasks.dart' show CompilerTask, GenericTask, Measurer; | 20 import 'common/tasks.dart' show CompilerTask, GenericTask, Measurer; |
| 21 import 'common/work.dart' show WorkItem; | 21 import 'common/work.dart' show WorkItem; |
| 22 import 'common.dart'; | 22 import 'common.dart'; |
| 23 import 'compile_time_constants.dart'; | 23 import 'compile_time_constants.dart'; |
| 24 import 'constants/values.dart'; | 24 import 'constants/values.dart'; |
| 25 import 'common_elements.dart' | 25 import 'common_elements.dart' |
| 26 show CommonElements, CommonElementsMixin, ElementEnvironment; | 26 show CommonElements, CommonElementsImpl, ElementEnvironment; |
| 27 import 'deferred_load.dart' show DeferredLoadTask; | 27 import 'deferred_load.dart' show DeferredLoadTask; |
| 28 import 'diagnostics/code_location.dart'; | 28 import 'diagnostics/code_location.dart'; |
| 29 import 'diagnostics/diagnostic_listener.dart' show DiagnosticReporter; | 29 import 'diagnostics/diagnostic_listener.dart' show DiagnosticReporter; |
| 30 import 'diagnostics/invariant.dart' show REPORT_EXCESS_RESOLUTION; | 30 import 'diagnostics/invariant.dart' show REPORT_EXCESS_RESOLUTION; |
| 31 import 'diagnostics/messages.dart' show Message, MessageTemplate; | 31 import 'diagnostics/messages.dart' show Message, MessageTemplate; |
| 32 import 'dump_info.dart' show DumpInfoTask; | 32 import 'dump_info.dart' show DumpInfoTask; |
| 33 import 'elements/elements.dart'; | 33 import 'elements/elements.dart'; |
| 34 import 'elements/entities.dart'; | 34 import 'elements/entities.dart'; |
| 35 import 'elements/modelx.dart' show ErroneousElementX; | 35 import 'elements/modelx.dart' show ErroneousElementX; |
| 36 import 'elements/resolution_types.dart' | 36 import 'elements/resolution_types.dart' |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 import 'world.dart' show ClosedWorld, ClosedWorldRefiner, ClosedWorldImpl; | 81 import 'world.dart' show ClosedWorld, ClosedWorldRefiner, ClosedWorldImpl; |
| 82 | 82 |
| 83 typedef CompilerDiagnosticReporter MakeReporterFunction( | 83 typedef CompilerDiagnosticReporter MakeReporterFunction( |
| 84 Compiler compiler, CompilerOptions options); | 84 Compiler compiler, CompilerOptions options); |
| 85 | 85 |
| 86 abstract class Compiler { | 86 abstract class Compiler { |
| 87 Measurer get measurer; | 87 Measurer get measurer; |
| 88 | 88 |
| 89 final IdGenerator idGenerator = new IdGenerator(); | 89 final IdGenerator idGenerator = new IdGenerator(); |
| 90 Types types; | 90 Types types; |
| 91 _CompilerCommonElements _commonElements; | 91 CommonElementsImpl _commonElements; |
| 92 _CompilerElementEnvironment _elementEnvironment; | 92 _CompilerElementEnvironment _elementEnvironment; |
| 93 CompilerDiagnosticReporter _reporter; | 93 CompilerDiagnosticReporter _reporter; |
| 94 CompilerResolution _resolution; | 94 CompilerResolution _resolution; |
| 95 ParsingContext _parsingContext; | 95 ParsingContext _parsingContext; |
| 96 | 96 |
| 97 ImpactStrategy impactStrategy = const ImpactStrategy(); | 97 ImpactStrategy impactStrategy = const ImpactStrategy(); |
| 98 | 98 |
| 99 /** | 99 /** |
| 100 * Map from token to the first preceding comment token. | 100 * Map from token to the first preceding comment token. |
| 101 */ | 101 */ |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 this.userOutputProvider = outputProvider == null | 190 this.userOutputProvider = outputProvider == null |
| 191 ? const NullCompilerOutput() | 191 ? const NullCompilerOutput() |
| 192 : outputProvider { | 192 : outputProvider { |
| 193 if (makeReporter != null) { | 193 if (makeReporter != null) { |
| 194 _reporter = makeReporter(this, options); | 194 _reporter = makeReporter(this, options); |
| 195 } else { | 195 } else { |
| 196 _reporter = new CompilerDiagnosticReporter(this, options); | 196 _reporter = new CompilerDiagnosticReporter(this, options); |
| 197 } | 197 } |
| 198 _resolution = createResolution(); | 198 _resolution = createResolution(); |
| 199 _elementEnvironment = new _CompilerElementEnvironment(this); | 199 _elementEnvironment = new _CompilerElementEnvironment(this); |
| 200 _commonElements = | 200 _commonElements = new CommonElementsImpl(_elementEnvironment); |
| 201 new _CompilerCommonElements(_elementEnvironment, _resolution, reporter); | |
| 202 types = new Types(_resolution); | 201 types = new Types(_resolution); |
| 203 | 202 |
| 204 if (options.verbose) { | 203 if (options.verbose) { |
| 205 progress = new Stopwatch()..start(); | 204 progress = new Stopwatch()..start(); |
| 206 } | 205 } |
| 207 | 206 |
| 208 backend = createBackend(); | 207 backend = createBackend(); |
| 209 enqueuer = backend.makeEnqueuer(); | 208 enqueuer = backend.makeEnqueuer(); |
| 210 | 209 |
| 211 tasks = [ | 210 tasks = [ |
| (...skipping 868 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1080 return userOutputProvider.createOutputSink(name, extension, type); | 1079 return userOutputProvider.createOutputSink(name, extension, type); |
| 1081 } | 1080 } |
| 1082 } | 1081 } |
| 1083 | 1082 |
| 1084 /// Information about suppressed warnings and hints for a given library. | 1083 /// Information about suppressed warnings and hints for a given library. |
| 1085 class SuppressionInfo { | 1084 class SuppressionInfo { |
| 1086 int warnings = 0; | 1085 int warnings = 0; |
| 1087 int hints = 0; | 1086 int hints = 0; |
| 1088 } | 1087 } |
| 1089 | 1088 |
| 1090 class _CompilerCommonElements extends CommonElementsMixin { | |
| 1091 final Resolution resolution; | |
| 1092 final DiagnosticReporter reporter; | |
| 1093 | |
| 1094 final ElementEnvironment environment; | |
| 1095 | |
| 1096 _CompilerCommonElements(this.environment, this.resolution, this.reporter); | |
| 1097 | |
| 1098 @override | |
| 1099 ResolutionDynamicType get dynamicType => const ResolutionDynamicType(); | |
| 1100 | |
| 1101 LibraryEntity _coreLibrary; | |
| 1102 LibraryEntity get coreLibrary => | |
| 1103 _coreLibrary ??= environment.lookupLibrary(Uris.dart_core); | |
| 1104 | |
| 1105 LibraryEntity _typedDataLibrary; | |
| 1106 LibraryEntity get typedDataLibrary => _typedDataLibrary ??= | |
| 1107 environment.lookupLibrary(Uris.dart__native_typed_data); | |
| 1108 | |
| 1109 LibraryEntity _mirrorsLibrary; | |
| 1110 LibraryEntity get mirrorsLibrary => | |
| 1111 _mirrorsLibrary ??= environment.lookupLibrary(Uris.dart_mirrors); | |
| 1112 | |
| 1113 LibraryEntity _asyncLibrary; | |
| 1114 LibraryEntity get asyncLibrary => | |
| 1115 _asyncLibrary ??= environment.lookupLibrary(Uris.dart_async); | |
| 1116 | |
| 1117 @override | |
| 1118 MemberElement findLibraryMember(LibraryElement library, String name, | |
| 1119 {bool setter: false, bool required: true}) { | |
| 1120 Element member = _findLibraryMember(library, name, required: required); | |
| 1121 if (member != null && member.isAbstractField) { | |
| 1122 AbstractFieldElement abstractField = member; | |
| 1123 if (setter) { | |
| 1124 member = abstractField.setter; | |
| 1125 } else { | |
| 1126 member = abstractField.getter; | |
| 1127 } | |
| 1128 if (member == null && required) { | |
| 1129 reporter.internalError( | |
| 1130 library, | |
| 1131 "The library '${library.canonicalUri}' does not contain required " | |
| 1132 "${setter ? 'setter' : 'getter'}: '$name'."); | |
| 1133 } | |
| 1134 } | |
| 1135 return member; | |
| 1136 } | |
| 1137 | |
| 1138 @override | |
| 1139 MemberElement findClassMember(ClassElement cls, String name, | |
| 1140 {bool setter: false, bool required: true}) { | |
| 1141 cls.ensureResolved(resolution); | |
| 1142 Element member = cls.lookupLocalMember(name); | |
| 1143 if (member != null && member.isAbstractField) { | |
| 1144 AbstractFieldElement abstractField = member; | |
| 1145 if (setter) { | |
| 1146 member = abstractField.setter; | |
| 1147 } else { | |
| 1148 member = abstractField.getter; | |
| 1149 } | |
| 1150 } | |
| 1151 if (member == null && required) { | |
| 1152 reporter.internalError( | |
| 1153 cls, | |
| 1154 "The class '${cls}' in '${cls.library.canonicalUri}' does not " | |
| 1155 "contain required member: '$name'."); | |
| 1156 } | |
| 1157 return member; | |
| 1158 } | |
| 1159 | |
| 1160 @override | |
| 1161 ConstructorElement findConstructor(ClassElement cls, String name, | |
| 1162 {bool required: true}) { | |
| 1163 cls.ensureResolved(resolution); | |
| 1164 ConstructorElement constructor = cls.lookupConstructor(name); | |
| 1165 if (constructor == null && required) { | |
| 1166 reporter.internalError( | |
| 1167 cls, | |
| 1168 "The class '${cls}' in '${cls.library.canonicalUri}' does not " | |
| 1169 "contain required constructor: '$name'."); | |
| 1170 } | |
| 1171 return constructor; | |
| 1172 } | |
| 1173 | |
| 1174 @override | |
| 1175 ClassElement findClass(LibraryElement library, String name, | |
| 1176 {bool required: true}) { | |
| 1177 return _findLibraryMember(library, name, required: required); | |
| 1178 } | |
| 1179 | |
| 1180 Element _findLibraryMember(LibraryElement library, String name, | |
| 1181 {bool required: true}) { | |
| 1182 // If the script of the library is synthesized, the library does not exist | |
| 1183 // and we do not try to load the helpers. | |
| 1184 // | |
| 1185 // This could for example happen if dart:async is disabled, then loading it | |
| 1186 // should not try to find the given element. | |
| 1187 if (library == null || library.isSynthesized) return null; | |
| 1188 | |
| 1189 Element element = library.find(name); | |
| 1190 if (element == null && required) { | |
| 1191 reporter.internalError( | |
| 1192 library, | |
| 1193 "The library '${library.canonicalUri}' does not contain required " | |
| 1194 "element: '$name'."); | |
| 1195 } | |
| 1196 return element; | |
| 1197 } | |
| 1198 } | |
| 1199 | |
| 1200 class CompilerDiagnosticReporter extends DiagnosticReporter { | 1089 class CompilerDiagnosticReporter extends DiagnosticReporter { |
| 1201 final Compiler compiler; | 1090 final Compiler compiler; |
| 1202 final DiagnosticOptions options; | 1091 final DiagnosticOptions options; |
| 1203 | 1092 |
| 1204 Element _currentElement; | 1093 Element _currentElement; |
| 1205 bool hasCrashed = false; | 1094 bool hasCrashed = false; |
| 1206 | 1095 |
| 1207 /// `true` if the last diagnostic was filtered, in which case the | 1096 /// `true` if the last diagnostic was filtered, in which case the |
| 1208 /// accompanying info message should be filtered as well. | 1097 /// accompanying info message should be filtered as well. |
| 1209 bool lastDiagnosticWasFiltered = false; | 1098 bool lastDiagnosticWasFiltered = false; |
| (...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1917 | 1806 |
| 1918 /// An element environment base on a [Compiler]. | 1807 /// An element environment base on a [Compiler]. |
| 1919 class _CompilerElementEnvironment implements ElementEnvironment { | 1808 class _CompilerElementEnvironment implements ElementEnvironment { |
| 1920 final Compiler _compiler; | 1809 final Compiler _compiler; |
| 1921 | 1810 |
| 1922 _CompilerElementEnvironment(this._compiler); | 1811 _CompilerElementEnvironment(this._compiler); |
| 1923 | 1812 |
| 1924 LibraryProvider get _libraryProvider => _compiler.libraryLoader; | 1813 LibraryProvider get _libraryProvider => _compiler.libraryLoader; |
| 1925 Resolution get _resolution => _compiler.resolution; | 1814 Resolution get _resolution => _compiler.resolution; |
| 1926 | 1815 |
| 1816 ResolutionDynamicType get dynamicType => const ResolutionDynamicType(); |
| 1817 |
| 1927 @override | 1818 @override |
| 1928 LibraryEntity get mainLibrary => _compiler.mainApp; | 1819 LibraryEntity get mainLibrary => _compiler.mainApp; |
| 1929 | 1820 |
| 1930 @override | 1821 @override |
| 1931 FunctionEntity get mainFunction => _compiler.mainFunction; | 1822 FunctionEntity get mainFunction => _compiler.mainFunction; |
| 1932 | 1823 |
| 1933 @override | 1824 @override |
| 1934 ResolutionInterfaceType getThisType(ClassElement cls) { | 1825 ResolutionInterfaceType getThisType(ClassElement cls) { |
| 1935 cls.ensureResolved(_resolution); | 1826 cls.ensureResolved(_resolution); |
| 1936 return cls.thisType; | 1827 return cls.thisType; |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2027 cls, | 1918 cls, |
| 2028 "The library '${library.libraryName}' does not " | 1919 "The library '${library.libraryName}' does not " |
| 2029 "contain required class: '$name'."); | 1920 "contain required class: '$name'."); |
| 2030 } | 1921 } |
| 2031 return cls?.declaration; | 1922 return cls?.declaration; |
| 2032 } | 1923 } |
| 2033 | 1924 |
| 2034 @override | 1925 @override |
| 2035 LibraryElement lookupLibrary(Uri uri, {bool required: false}) { | 1926 LibraryElement lookupLibrary(Uri uri, {bool required: false}) { |
| 2036 LibraryElement library = _libraryProvider.lookupLibrary(uri); | 1927 LibraryElement library = _libraryProvider.lookupLibrary(uri); |
| 1928 // If the script of the library is synthesized, the library does not exist |
| 1929 // and we do not try to load the helpers. |
| 1930 // |
| 1931 // This could for example happen if dart:async is disabled, then loading it |
| 1932 // should not try to find the given element. |
| 2037 if (library != null && library.isSynthesized) { | 1933 if (library != null && library.isSynthesized) { |
| 2038 return null; | 1934 return null; |
| 2039 } | 1935 } |
| 2040 if (library == null && required) { | 1936 if (library == null && required) { |
| 2041 throw new SpannableAssertionFailure( | 1937 throw new SpannableAssertionFailure( |
| 2042 library, "The library '${uri}' was not found."); | 1938 library, "The library '${uri}' was not found."); |
| 2043 } | 1939 } |
| 2044 return library; | 1940 return library; |
| 2045 } | 1941 } |
| 2046 } | 1942 } |
| OLD | NEW |