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

Side by Side Diff: pkg/dev_compiler/lib/src/compiler/code_generator.dart

Issue 3009733002: fix how DDC finds its undefined constant (Closed)
Patch Set: rebase and rebuild JS files Created 3 years, 3 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
« no previous file with comments | « no previous file | pkg/dev_compiler/test/codegen_expected/BenchmarkBase.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 boolClass = _getLibrary(c, 'dart:core').getType('bool'), 221 boolClass = _getLibrary(c, 'dart:core').getType('bool'),
222 intClass = _getLibrary(c, 'dart:core').getType('int'), 222 intClass = _getLibrary(c, 'dart:core').getType('int'),
223 doubleClass = _getLibrary(c, 'dart:core').getType('double'), 223 doubleClass = _getLibrary(c, 'dart:core').getType('double'),
224 numClass = _getLibrary(c, 'dart:core').getType('num'), 224 numClass = _getLibrary(c, 'dart:core').getType('num'),
225 nullClass = _getLibrary(c, 'dart:core').getType('Null'), 225 nullClass = _getLibrary(c, 'dart:core').getType('Null'),
226 objectClass = _getLibrary(c, 'dart:core').getType('Object'), 226 objectClass = _getLibrary(c, 'dart:core').getType('Object'),
227 stringClass = _getLibrary(c, 'dart:core').getType('String'), 227 stringClass = _getLibrary(c, 'dart:core').getType('String'),
228 functionClass = _getLibrary(c, 'dart:core').getType('Function'), 228 functionClass = _getLibrary(c, 'dart:core').getType('Function'),
229 privateSymbolClass = 229 privateSymbolClass =
230 _getLibrary(c, 'dart:_internal').getType('PrivateSymbol'), 230 _getLibrary(c, 'dart:_internal').getType('PrivateSymbol'),
231 dartJSLibrary = _getLibrary(c, 'dart:js'), 231 dartJSLibrary = _getLibrary(c, 'dart:js') {
232 _undefinedConstant =
233 _getLibrary(c, 'dart:_runtime').publicNamespace.get('undefined') {
234 assert(_undefinedConstant != null);
235 typeRep = new JSTypeRep(rules, types); 232 typeRep = new JSTypeRep(rules, types);
236 } 233 }
237 234
238 Element get currentElement => _currentElements.last; 235 Element get currentElement => _currentElements.last;
239 236
240 LibraryElement get currentLibrary => currentElement.library; 237 LibraryElement get currentLibrary => currentElement.library;
241 238
242 /// The main entry point to JavaScript code generation. 239 /// The main entry point to JavaScript code generation.
243 /// 240 ///
244 /// Takes the metadata for the build unit, as well as resolved trees and 241 /// Takes the metadata for the build unit, as well as resolved trees and
(...skipping 2241 matching lines...) Expand 10 before | Expand all | Expand 10 after
2486 if (param is DefaultFormalParameter && param.defaultValue != null) { 2483 if (param is DefaultFormalParameter && param.defaultValue != null) {
2487 var defaultValue = param.defaultValue; 2484 var defaultValue = param.defaultValue;
2488 return _isJSUndefined(defaultValue) ? null : _visit(defaultValue); 2485 return _isJSUndefined(defaultValue) ? null : _visit(defaultValue);
2489 } else { 2486 } else {
2490 return new JS.LiteralNull(); 2487 return new JS.LiteralNull();
2491 } 2488 }
2492 } 2489 }
2493 2490
2494 bool _isJSUndefined(Expression expr) { 2491 bool _isJSUndefined(Expression expr) {
2495 expr = expr is AsExpression ? expr.expression : expr; 2492 expr = expr is AsExpression ? expr.expression : expr;
2496 return expr is Identifier && expr.staticElement == _undefinedConstant; 2493 if (expr is Identifier) {
2494 var element = expr.staticElement;
2495 return isSdkInternalRuntime(element.library) &&
2496 element.name == 'undefined';
2497 }
2498 return false;
2497 } 2499 }
2498 2500
2499 JS.Fun _emitNativeFunctionBody(MethodDeclaration node) { 2501 JS.Fun _emitNativeFunctionBody(MethodDeclaration node) {
2500 String name = 2502 String name =
2501 getAnnotationName(node.element, isJSAnnotation) ?? node.name.name; 2503 getAnnotationName(node.element, isJSAnnotation) ?? node.name.name;
2502 if (node.isGetter) { 2504 if (node.isGetter) {
2503 return new JS.Fun([], js.statement('{ return this.#; }', [name])); 2505 return new JS.Fun([], js.statement('{ return this.#; }', [name]));
2504 } else if (node.isSetter) { 2506 } else if (node.isSetter) {
2505 var params = 2507 var params =
2506 _emitFormalParameterList(node.parameters, destructure: false); 2508 _emitFormalParameterList(node.parameters, destructure: false);
(...skipping 1625 matching lines...) Expand 10 before | Expand all | Expand 10 after
4132 void _emitTopLevelFields(List<VariableDeclaration> fields) { 4134 void _emitTopLevelFields(List<VariableDeclaration> fields) {
4133 _moduleItems.add(_emitLazyFields(currentLibrary, fields)); 4135 _moduleItems.add(_emitLazyFields(currentLibrary, fields));
4134 } 4136 }
4135 4137
4136 /// Treat dart:_runtime fields as safe to eagerly evaluate. 4138 /// Treat dart:_runtime fields as safe to eagerly evaluate.
4137 // TODO(jmesserly): it'd be nice to avoid this special case. 4139 // TODO(jmesserly): it'd be nice to avoid this special case.
4138 void _emitInternalSdkFields(List<VariableDeclaration> fields) { 4140 void _emitInternalSdkFields(List<VariableDeclaration> fields) {
4139 for (var field in fields) { 4141 for (var field in fields) {
4140 // Skip our magic undefined constant. 4142 // Skip our magic undefined constant.
4141 var element = field.element as TopLevelVariableElement; 4143 var element = field.element as TopLevelVariableElement;
4142 if (element.getter == _undefinedConstant) continue; 4144 if (element.name == 'undefined') continue;
4143 _moduleItems.add(annotate( 4145 _moduleItems.add(annotate(
4144 js.statement('# = #;', 4146 js.statement('# = #;',
4145 [_emitTopLevelName(field.element), _visitInitializer(field)]), 4147 [_emitTopLevelName(field.element), _visitInitializer(field)]),
4146 field, 4148 field,
4147 field.element)); 4149 field.element));
4148 } 4150 }
4149 } 4151 }
4150 4152
4151 JS.Expression _visitInitializer(VariableDeclaration node) { 4153 JS.Expression _visitInitializer(VariableDeclaration node) {
4152 var value = _annotatedNullCheck(node.element) 4154 var value = _annotatedNullCheck(node.element)
(...skipping 1943 matching lines...) Expand 10 before | Expand all | Expand 10 after
6096 '~/': 'floorDivide', 6098 '~/': 'floorDivide',
6097 '*': 'times', 6099 '*': 'times',
6098 '%': 'modulo', 6100 '%': 'modulo',
6099 '|': 'bitOr', 6101 '|': 'bitOr',
6100 '^': 'bitXor', 6102 '^': 'bitXor',
6101 '&': 'bitAnd', 6103 '&': 'bitAnd',
6102 '<<': 'leftShift', 6104 '<<': 'leftShift',
6103 '>>': 'rightShift', 6105 '>>': 'rightShift',
6104 '~': 'bitNot' 6106 '~': 'bitNot'
6105 }; 6107 };
OLDNEW
« no previous file with comments | « no previous file | pkg/dev_compiler/test/codegen_expected/BenchmarkBase.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698