| 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 2077 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2265 for (var p in ctor.parameters.parameters) { | 2266 for (var p in ctor.parameters.parameters) { |
| 2266 var element = p.element; | 2267 var element = p.element; |
| 2267 if (element is FieldFormalParameterElement) { | 2268 if (element is FieldFormalParameterElement) { |
| 2268 fields[element.field] = _emitSimpleIdentifier(p.identifier); | 2269 fields[element.field] = _emitSimpleIdentifier(p.identifier); |
| 2269 } | 2270 } |
| 2270 } | 2271 } |
| 2271 | 2272 |
| 2272 // Run constructor field initializers such as `: foo = bar.baz` | 2273 // Run constructor field initializers such as `: foo = bar.baz` |
| 2273 for (var init in ctor.initializers) { | 2274 for (var init in ctor.initializers) { |
| 2274 if (init is ConstructorFieldInitializer) { | 2275 if (init is ConstructorFieldInitializer) { |
| 2275 fields[init.fieldName.staticElement as FieldElement] = | 2276 var element = init.fieldName.staticElement as FieldElement; |
| 2276 _visit(init.expression); | 2277 fields[element] = _visit(init.expression); |
| 2277 } | 2278 } |
| 2278 } | 2279 } |
| 2279 } | 2280 } |
| 2280 | 2281 |
| 2281 for (var f in fields.keys) unsetFields.remove(f); | 2282 for (var f in fields.keys) unsetFields.remove(f); |
| 2282 | 2283 |
| 2283 // Initialize all remaining fields | 2284 // Initialize all remaining fields |
| 2284 unsetFields.forEach((element, fieldNode) { | 2285 unsetFields.forEach((element, fieldNode) { |
| 2285 JS.Expression value; | 2286 JS.Expression value; |
| 2286 if (fieldNode.initializer != null) { | 2287 if (fieldNode.initializer != null) { |
| (...skipping 3073 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5360 visitNullLiteral(NullLiteral node) => new JS.LiteralNull(); | 5361 visitNullLiteral(NullLiteral node) => new JS.LiteralNull(); |
| 5361 | 5362 |
| 5362 @override | 5363 @override |
| 5363 visitSymbolLiteral(SymbolLiteral node) { | 5364 visitSymbolLiteral(SymbolLiteral node) { |
| 5364 JS.Expression emitSymbol() { | 5365 JS.Expression emitSymbol() { |
| 5365 // TODO(vsm): Handle qualified symbols correctly. | 5366 // TODO(vsm): Handle qualified symbols correctly. |
| 5366 var last = node.components.last.toString(); | 5367 var last = node.components.last.toString(); |
| 5367 var name = js.string(node.components.join('.'), "'"); | 5368 var name = js.string(node.components.join('.'), "'"); |
| 5368 if (last.startsWith('_')) { | 5369 if (last.startsWith('_')) { |
| 5369 var nativeSymbol = _emitPrivateNameSymbol(currentLibrary, last); | 5370 var nativeSymbol = _emitPrivateNameSymbol(currentLibrary, last); |
| 5370 return js.call('new #.es6(#, #)', | 5371 return js.call('new #(#, #)', [ |
| 5371 [_emitConstructorAccess(symbolClass.type), name, nativeSymbol]); | 5372 _emitConstructorAccess(privateSymbolClass.type), |
| 5373 name, |
| 5374 nativeSymbol |
| 5375 ]); |
| 5372 } else { | 5376 } else { |
| 5373 return js | 5377 return js |
| 5374 .call('#.new(#)', [_emitConstructorAccess(types.symbolType), name]); | 5378 .call('#.new(#)', [_emitConstructorAccess(types.symbolType), name]); |
| 5375 } | 5379 } |
| 5376 } | 5380 } |
| 5377 | 5381 |
| 5378 return _emitConst(emitSymbol); | 5382 return _emitConst(emitSymbol); |
| 5379 } | 5383 } |
| 5380 | 5384 |
| 5381 @override | 5385 @override |
| (...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5901 if (targetIdentifier.staticElement is! PrefixElement) return false; | 5905 if (targetIdentifier.staticElement is! PrefixElement) return false; |
| 5902 var prefix = targetIdentifier.staticElement as PrefixElement; | 5906 var prefix = targetIdentifier.staticElement as PrefixElement; |
| 5903 | 5907 |
| 5904 // The library the prefix is referring to must come from a deferred import. | 5908 // The library the prefix is referring to must come from a deferred import. |
| 5905 var containingLibrary = resolutionMap | 5909 var containingLibrary = resolutionMap |
| 5906 .elementDeclaredByCompilationUnit(target.root as CompilationUnit) | 5910 .elementDeclaredByCompilationUnit(target.root as CompilationUnit) |
| 5907 .library; | 5911 .library; |
| 5908 var imports = containingLibrary.getImportsWithPrefix(prefix); | 5912 var imports = containingLibrary.getImportsWithPrefix(prefix); |
| 5909 return imports.length == 1 && imports[0].isDeferred; | 5913 return imports.length == 1 && imports[0].isDeferred; |
| 5910 } | 5914 } |
| OLD | NEW |