| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 | 2 |
| 3 // for details. All rights reserved. Use of this source code is governed by a | 3 // for details. All rights reserved. Use of this source code is governed by a |
| 4 // BSD-style license that can be found in the LICENSE file. | 4 // BSD-style license that can be found in the LICENSE file. |
| 5 | 5 |
| 6 import 'dart:collection' show HashMap, HashSet; | 6 import 'dart:collection' show HashMap, HashSet; |
| 7 import 'dart:math' show min, max; | 7 import 'dart:math' show min, max; |
| 8 | 8 |
| 9 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; | 9 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; |
| 10 import 'package:analyzer/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 final ClassElement _jsArray; | 120 final ClassElement _jsArray; |
| 121 | 121 |
| 122 final ClassElement boolClass; | 122 final ClassElement boolClass; |
| 123 final ClassElement intClass; | 123 final ClassElement intClass; |
| 124 final ClassElement interceptorClass; | 124 final ClassElement interceptorClass; |
| 125 final ClassElement nullClass; | 125 final ClassElement nullClass; |
| 126 final ClassElement numClass; | 126 final ClassElement numClass; |
| 127 final ClassElement objectClass; | 127 final ClassElement objectClass; |
| 128 final ClassElement stringClass; | 128 final ClassElement stringClass; |
| 129 final ClassElement functionClass; | 129 final ClassElement functionClass; |
| 130 final ClassElement symbolClass; | 130 final ClassElement privateSymbolClass; |
| 131 | 131 |
| 132 ConstFieldVisitor _constants; | 132 ConstFieldVisitor _constants; |
| 133 | 133 |
| 134 /// The current function body being compiled. | 134 /// The current function body being compiled. |
| 135 FunctionBody _currentFunction; | 135 FunctionBody _currentFunction; |
| 136 | 136 |
| 137 /// Helper class for emitting elements in the proper order to allow | 137 /// Helper class for emitting elements in the proper order to allow |
| 138 /// JS to load the module. | 138 /// JS to load the module. |
| 139 ElementLoader _loader; | 139 ElementLoader _loader; |
| 140 | 140 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 167 interceptorClass = | 167 interceptorClass = |
| 168 _getLibrary(c, 'dart:_interceptors').getType('Interceptor'), | 168 _getLibrary(c, 'dart:_interceptors').getType('Interceptor'), |
| 169 dartCoreLibrary = _getLibrary(c, 'dart:core'), | 169 dartCoreLibrary = _getLibrary(c, 'dart:core'), |
| 170 boolClass = _getLibrary(c, 'dart:core').getType('bool'), | 170 boolClass = _getLibrary(c, 'dart:core').getType('bool'), |
| 171 intClass = _getLibrary(c, 'dart:core').getType('int'), | 171 intClass = _getLibrary(c, 'dart:core').getType('int'), |
| 172 numClass = _getLibrary(c, 'dart:core').getType('num'), | 172 numClass = _getLibrary(c, 'dart:core').getType('num'), |
| 173 nullClass = _getLibrary(c, 'dart:core').getType('Null'), | 173 nullClass = _getLibrary(c, 'dart:core').getType('Null'), |
| 174 objectClass = _getLibrary(c, 'dart:core').getType('Object'), | 174 objectClass = _getLibrary(c, 'dart:core').getType('Object'), |
| 175 stringClass = _getLibrary(c, 'dart:core').getType('String'), | 175 stringClass = _getLibrary(c, 'dart:core').getType('String'), |
| 176 functionClass = _getLibrary(c, 'dart:core').getType('Function'), | 176 functionClass = _getLibrary(c, 'dart:core').getType('Function'), |
| 177 symbolClass = _getLibrary(c, 'dart:_internal').getType('Symbol'), | 177 privateSymbolClass = |
| 178 _getLibrary(c, 'dart:_internal').getType('PrivateSymbol'), |
| 178 dartJSLibrary = _getLibrary(c, 'dart:js'); | 179 dartJSLibrary = _getLibrary(c, 'dart:js'); |
| 179 | 180 |
| 180 LibraryElement get currentLibrary => _loader.currentElement.library; | 181 LibraryElement get currentLibrary => _loader.currentElement.library; |
| 181 | 182 |
| 182 /// The main entry point to JavaScript code generation. | 183 /// The main entry point to JavaScript code generation. |
| 183 /// | 184 /// |
| 184 /// Takes the metadata for the build unit, as well as resolved trees and | 185 /// Takes the metadata for the build unit, as well as resolved trees and |
| 185 /// errors, and computes the output module code and optionally the source map. | 186 /// errors, and computes the output module code and optionally the source map. |
| 186 JSModuleFile compile(BuildUnit unit, List<CompilationUnit> compilationUnits, | 187 JSModuleFile compile(BuildUnit unit, List<CompilationUnit> compilationUnits, |
| 187 List<String> errors) { | 188 List<String> errors) { |
| (...skipping 2066 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2254 for (var p in ctor.parameters.parameters) { | 2255 for (var p in ctor.parameters.parameters) { |
| 2255 var element = p.element; | 2256 var element = p.element; |
| 2256 if (element is FieldFormalParameterElement) { | 2257 if (element is FieldFormalParameterElement) { |
| 2257 fields[element.field] = _emitSimpleIdentifier(p.identifier); | 2258 fields[element.field] = _emitSimpleIdentifier(p.identifier); |
| 2258 } | 2259 } |
| 2259 } | 2260 } |
| 2260 | 2261 |
| 2261 // Run constructor field initializers such as `: foo = bar.baz` | 2262 // Run constructor field initializers such as `: foo = bar.baz` |
| 2262 for (var init in ctor.initializers) { | 2263 for (var init in ctor.initializers) { |
| 2263 if (init is ConstructorFieldInitializer) { | 2264 if (init is ConstructorFieldInitializer) { |
| 2264 fields[init.fieldName.staticElement as FieldElement] = | 2265 var element = init.fieldName.staticElement as FieldElement; |
| 2265 _visit(init.expression); | 2266 fields[element] = _visit(init.expression); |
| 2266 } | 2267 } |
| 2267 } | 2268 } |
| 2268 } | 2269 } |
| 2269 | 2270 |
| 2270 for (var f in fields.keys) unsetFields.remove(f); | 2271 for (var f in fields.keys) unsetFields.remove(f); |
| 2271 | 2272 |
| 2272 // Initialize all remaining fields | 2273 // Initialize all remaining fields |
| 2273 unsetFields.forEach((element, fieldNode) { | 2274 unsetFields.forEach((element, fieldNode) { |
| 2274 JS.Expression value; | 2275 JS.Expression value; |
| 2275 if (fieldNode.initializer != null) { | 2276 if (fieldNode.initializer != null) { |
| (...skipping 3073 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5349 visitNullLiteral(NullLiteral node) => new JS.LiteralNull(); | 5350 visitNullLiteral(NullLiteral node) => new JS.LiteralNull(); |
| 5350 | 5351 |
| 5351 @override | 5352 @override |
| 5352 visitSymbolLiteral(SymbolLiteral node) { | 5353 visitSymbolLiteral(SymbolLiteral node) { |
| 5353 JS.Expression emitSymbol() { | 5354 JS.Expression emitSymbol() { |
| 5354 // TODO(vsm): Handle qualified symbols correctly. | 5355 // TODO(vsm): Handle qualified symbols correctly. |
| 5355 var last = node.components.last.toString(); | 5356 var last = node.components.last.toString(); |
| 5356 var name = js.string(node.components.join('.'), "'"); | 5357 var name = js.string(node.components.join('.'), "'"); |
| 5357 if (last.startsWith('_')) { | 5358 if (last.startsWith('_')) { |
| 5358 var nativeSymbol = _emitPrivateNameSymbol(currentLibrary, last); | 5359 var nativeSymbol = _emitPrivateNameSymbol(currentLibrary, last); |
| 5359 return js.call('new #.es6(#, #)', | 5360 return js.call('new #(#, #)', [ |
| 5360 [_emitConstructorAccess(symbolClass.type), name, nativeSymbol]); | 5361 _emitConstructorAccess(privateSymbolClass.type), |
| 5362 name, |
| 5363 nativeSymbol |
| 5364 ]); |
| 5361 } else { | 5365 } else { |
| 5362 return js | 5366 return js |
| 5363 .call('#.new(#)', [_emitConstructorAccess(types.symbolType), name]); | 5367 .call('#.new(#)', [_emitConstructorAccess(types.symbolType), name]); |
| 5364 } | 5368 } |
| 5365 } | 5369 } |
| 5366 | 5370 |
| 5367 return _emitConst(emitSymbol); | 5371 return _emitConst(emitSymbol); |
| 5368 } | 5372 } |
| 5369 | 5373 |
| 5370 @override | 5374 @override |
| (...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5890 if (targetIdentifier.staticElement is! PrefixElement) return false; | 5894 if (targetIdentifier.staticElement is! PrefixElement) return false; |
| 5891 var prefix = targetIdentifier.staticElement as PrefixElement; | 5895 var prefix = targetIdentifier.staticElement as PrefixElement; |
| 5892 | 5896 |
| 5893 // The library the prefix is referring to must come from a deferred import. | 5897 // The library the prefix is referring to must come from a deferred import. |
| 5894 var containingLibrary = resolutionMap | 5898 var containingLibrary = resolutionMap |
| 5895 .elementDeclaredByCompilationUnit(target.root as CompilationUnit) | 5899 .elementDeclaredByCompilationUnit(target.root as CompilationUnit) |
| 5896 .library; | 5900 .library; |
| 5897 var imports = containingLibrary.getImportsWithPrefix(prefix); | 5901 var imports = containingLibrary.getImportsWithPrefix(prefix); |
| 5898 return imports.length == 1 && imports[0].isDeferred; | 5902 return imports.length == 1 && imports[0].isDeferred; |
| 5899 } | 5903 } |
| OLD | NEW |