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 'cache_strategy.dart' show CacheStrategy; | 10 import 'cache_strategy.dart' show CacheStrategy; |
(...skipping 1152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1163 _doubleClass ??= _findRequired(coreLibrary, 'double'); | 1163 _doubleClass ??= _findRequired(coreLibrary, 'double'); |
1164 | 1164 |
1165 ClassElement _stringClass; | 1165 ClassElement _stringClass; |
1166 ClassElement get stringClass => | 1166 ClassElement get stringClass => |
1167 _stringClass ??= _findRequired(coreLibrary, 'String'); | 1167 _stringClass ??= _findRequired(coreLibrary, 'String'); |
1168 | 1168 |
1169 ClassElement _functionClass; | 1169 ClassElement _functionClass; |
1170 ClassElement get functionClass => | 1170 ClassElement get functionClass => |
1171 _functionClass ??= _findRequired(coreLibrary, 'Function'); | 1171 _functionClass ??= _findRequired(coreLibrary, 'Function'); |
1172 | 1172 |
1173 Element _functionApplyMethod; | 1173 MethodElement _functionApplyMethod; |
1174 Element get functionApplyMethod { | 1174 MethodElement get functionApplyMethod { |
1175 if (_functionApplyMethod == null) { | 1175 if (_functionApplyMethod == null) { |
1176 functionClass.ensureResolved(resolution); | 1176 functionClass.ensureResolved(resolution); |
1177 _functionApplyMethod = functionClass.lookupLocalMember('apply'); | 1177 _functionApplyMethod = functionClass.lookupLocalMember('apply'); |
1178 assert(invariant(functionClass, _functionApplyMethod != null, | 1178 assert(invariant(functionClass, _functionApplyMethod != null, |
1179 message: "Member `apply` not found in ${functionClass}.")); | 1179 message: "Member `apply` not found in ${functionClass}.")); |
1180 } | 1180 } |
1181 return _functionApplyMethod; | 1181 return _functionApplyMethod; |
1182 } | 1182 } |
1183 | 1183 |
1184 bool isFunctionApplyMethod(Element element) => | 1184 bool isFunctionApplyMethod(MemberElement element) => |
1185 element.name == 'apply' && element.enclosingClass == functionClass; | 1185 element.name == 'apply' && element.enclosingClass == functionClass; |
1186 | 1186 |
1187 ClassElement _nullClass; | 1187 ClassElement _nullClass; |
1188 ClassElement get nullClass => | 1188 ClassElement get nullClass => |
1189 _nullClass ??= _findRequired(coreLibrary, 'Null'); | 1189 _nullClass ??= _findRequired(coreLibrary, 'Null'); |
1190 | 1190 |
1191 ClassElement _listClass; | 1191 ClassElement _listClass; |
1192 ClassElement get listClass => | 1192 ClassElement get listClass => |
1193 _listClass ??= _findRequired(coreLibrary, 'List'); | 1193 _listClass ??= _findRequired(coreLibrary, 'List'); |
1194 | 1194 |
(...skipping 27 matching lines...) Expand all Loading... |
1222 _stackTraceClass ??= _findRequired(coreLibrary, 'StackTrace'); | 1222 _stackTraceClass ??= _findRequired(coreLibrary, 'StackTrace'); |
1223 | 1223 |
1224 ClassElement _iterableClass; | 1224 ClassElement _iterableClass; |
1225 ClassElement get iterableClass => | 1225 ClassElement get iterableClass => |
1226 _iterableClass ??= _findRequired(coreLibrary, 'Iterable'); | 1226 _iterableClass ??= _findRequired(coreLibrary, 'Iterable'); |
1227 | 1227 |
1228 ClassElement _resourceClass; | 1228 ClassElement _resourceClass; |
1229 ClassElement get resourceClass => | 1229 ClassElement get resourceClass => |
1230 _resourceClass ??= _findRequired(coreLibrary, 'Resource'); | 1230 _resourceClass ??= _findRequired(coreLibrary, 'Resource'); |
1231 | 1231 |
1232 Element _identicalFunction; | 1232 MethodElement _identicalFunction; |
1233 Element get identicalFunction => | 1233 MethodElement get identicalFunction => |
1234 _identicalFunction ??= coreLibrary.find('identical'); | 1234 _identicalFunction ??= coreLibrary.find('identical'); |
1235 | 1235 |
1236 // From dart:async | 1236 // From dart:async |
1237 | 1237 |
1238 ClassElement _futureClass; | 1238 ClassElement _futureClass; |
1239 ClassElement get futureClass => | 1239 ClassElement get futureClass => |
1240 _futureClass ??= _findRequired(asyncLibrary, 'Future'); | 1240 _futureClass ??= _findRequired(asyncLibrary, 'Future'); |
1241 | 1241 |
1242 ClassElement _streamClass; | 1242 ClassElement _streamClass; |
1243 ClassElement get streamClass => | 1243 ClassElement get streamClass => |
1244 _streamClass ??= _findRequired(asyncLibrary, 'Stream'); | 1244 _streamClass ??= _findRequired(asyncLibrary, 'Stream'); |
1245 | 1245 |
1246 ClassElement _deferredLibraryClass; | 1246 ClassElement _deferredLibraryClass; |
1247 ClassElement get deferredLibraryClass => | 1247 ClassElement get deferredLibraryClass => |
1248 _deferredLibraryClass ??= _findRequired(asyncLibrary, "DeferredLibrary"); | 1248 _deferredLibraryClass ??= _findRequired(asyncLibrary, "DeferredLibrary"); |
1249 | 1249 |
1250 // From dart:mirrors | 1250 // From dart:mirrors |
1251 | 1251 |
1252 ClassElement _mirrorSystemClass; | 1252 ClassElement _mirrorSystemClass; |
1253 ClassElement get mirrorSystemClass => | 1253 ClassElement get mirrorSystemClass => |
1254 _mirrorSystemClass ??= _findRequired(mirrorsLibrary, 'MirrorSystem'); | 1254 _mirrorSystemClass ??= _findRequired(mirrorsLibrary, 'MirrorSystem'); |
1255 | 1255 |
1256 FunctionElement _mirrorSystemGetNameFunction; | 1256 FunctionElement _mirrorSystemGetNameFunction; |
1257 bool isMirrorSystemGetNameFunction(Element element) { | 1257 bool isMirrorSystemGetNameFunction(MemberElement element) { |
1258 if (_mirrorSystemGetNameFunction == null) { | 1258 if (_mirrorSystemGetNameFunction == null) { |
1259 if (!element.isFunction || mirrorsLibrary == null) return false; | 1259 if (!element.isFunction || mirrorsLibrary == null) return false; |
1260 ClassElement cls = mirrorSystemClass; | 1260 ClassElement cls = mirrorSystemClass; |
1261 if (element.enclosingClass != cls) return false; | 1261 if (element.enclosingClass != cls) return false; |
1262 if (cls != null) { | 1262 if (cls != null) { |
1263 cls.ensureResolved(resolution); | 1263 cls.ensureResolved(resolution); |
1264 _mirrorSystemGetNameFunction = cls.lookupLocalMember('getName'); | 1264 _mirrorSystemGetNameFunction = cls.lookupLocalMember('getName'); |
1265 } | 1265 } |
1266 } | 1266 } |
1267 return element == _mirrorSystemGetNameFunction; | 1267 return element == _mirrorSystemGetNameFunction; |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1472 ConstructorElement _unnamedListConstructor; | 1472 ConstructorElement _unnamedListConstructor; |
1473 ConstructorElement get unnamedListConstructor => | 1473 ConstructorElement get unnamedListConstructor => |
1474 _unnamedListConstructor ??= listClass.lookupDefaultConstructor(); | 1474 _unnamedListConstructor ??= listClass.lookupDefaultConstructor(); |
1475 | 1475 |
1476 ConstructorElement _filledListConstructor; | 1476 ConstructorElement _filledListConstructor; |
1477 ConstructorElement get filledListConstructor => | 1477 ConstructorElement get filledListConstructor => |
1478 _filledListConstructor ??= listClass.lookupConstructor("filled"); | 1478 _filledListConstructor ??= listClass.lookupConstructor("filled"); |
1479 | 1479 |
1480 // TODO(johnniwinther): Change types to `ClassElement` when these are not | 1480 // TODO(johnniwinther): Change types to `ClassElement` when these are not |
1481 // called with unrelated elements. | 1481 // called with unrelated elements. |
1482 bool isNumberOrStringSupertype(/*Class*/ Element element) { | 1482 bool isNumberOrStringSupertype(/*Class*/ Entity element) { |
1483 return element == coreLibrary.find('Comparable'); | 1483 return element == coreLibrary.find('Comparable'); |
1484 } | 1484 } |
1485 | 1485 |
1486 bool isStringOnlySupertype(/*Class*/ Element element) { | 1486 bool isStringOnlySupertype(/*Class*/ Entity element) { |
1487 return element == coreLibrary.find('Pattern'); | 1487 return element == coreLibrary.find('Pattern'); |
1488 } | 1488 } |
1489 | 1489 |
1490 bool isListSupertype(/*Class*/ Element element) => element == iterableClass; | 1490 bool isListSupertype(/*Class*/ Entity element) => element == iterableClass; |
1491 } | 1491 } |
1492 | 1492 |
1493 class CompilerDiagnosticReporter extends DiagnosticReporter { | 1493 class CompilerDiagnosticReporter extends DiagnosticReporter { |
1494 final Compiler compiler; | 1494 final Compiler compiler; |
1495 final DiagnosticOptions options; | 1495 final DiagnosticOptions options; |
1496 | 1496 |
1497 Element _currentElement; | 1497 Element _currentElement; |
1498 bool hasCrashed = false; | 1498 bool hasCrashed = false; |
1499 | 1499 |
1500 /// `true` if the last diagnostic was filtered, in which case the | 1500 /// `true` if the last diagnostic was filtered, in which case the |
(...skipping 726 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2227 _ElementScanner(this.scanner); | 2227 _ElementScanner(this.scanner); |
2228 void scanLibrary(LibraryElement library) => scanner.scanLibrary(library); | 2228 void scanLibrary(LibraryElement library) => scanner.scanLibrary(library); |
2229 void scanUnit(CompilationUnitElement unit) => scanner.scan(unit); | 2229 void scanUnit(CompilationUnitElement unit) => scanner.scan(unit); |
2230 } | 2230 } |
2231 | 2231 |
2232 class _EmptyEnvironment implements Environment { | 2232 class _EmptyEnvironment implements Environment { |
2233 const _EmptyEnvironment(); | 2233 const _EmptyEnvironment(); |
2234 | 2234 |
2235 String valueOf(String key) => null; | 2235 String valueOf(String key) => null; |
2236 } | 2236 } |
OLD | NEW |