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

Side by Side Diff: lib/src/codegen/js_codegen.dart

Issue 1172453002: fixes #209, remove tree mutation from CodeChecker (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 6 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
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 // 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 dev_compiler.src.codegen.js_codegen; 5 library dev_compiler.src.codegen.js_codegen;
6 6
7 import 'dart:collection' show HashSet, HashMap, SplayTreeSet; 7 import 'dart:collection' show HashSet, HashMap, SplayTreeSet;
8 8
9 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; 9 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator;
10 import 'package:analyzer/src/generated/ast.dart' hide ConstantEvaluator; 10 import 'package:analyzer/src/generated/ast.dart' hide ConstantEvaluator;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 // dart_runtime.js file and comments. 42 // dart_runtime.js file and comments.
43 // TODO(jmesserly): ideally we'd have a "dynamic call" dart library we can 43 // TODO(jmesserly): ideally we'd have a "dynamic call" dart library we can
44 // import and generate calls to, rather than dart_runtime.js 44 // import and generate calls to, rather than dart_runtime.js
45 const DPUT = 'dput'; 45 const DPUT = 'dput';
46 const DLOAD = 'dload'; 46 const DLOAD = 'dload';
47 const DINDEX = 'dindex'; 47 const DINDEX = 'dindex';
48 const DSETINDEX = 'dsetindex'; 48 const DSETINDEX = 'dsetindex';
49 const DCALL = 'dcall'; 49 const DCALL = 'dcall';
50 const DSEND = 'dsend'; 50 const DSEND = 'dsend';
51 51
52 class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor { 52 class JSCodegenVisitor extends GeneralizingAstVisitor {
53 final AbstractCompiler compiler; 53 final AbstractCompiler compiler;
54 final CompilerOptions options; 54 final CompilerOptions options;
55 final TypeRules rules; 55 final TypeRules rules;
56 final LibraryInfo libraryInfo; 56 final LibraryInfo libraryInfo;
57 57
58 /// Entry point uri 58 /// Entry point uri
59 final Uri root; 59 final Uri root;
60 60
61 /// The global extension type table. 61 /// The global extension type table.
62 final HashSet<ClassElement> _extensionTypes; 62 final HashSet<ClassElement> _extensionTypes;
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 // TODO(jmesserly): this is a temporary workaround for `Symbol` in core, 226 // TODO(jmesserly): this is a temporary workaround for `Symbol` in core,
227 // until we have better name tracking. 227 // until we have better name tracking.
228 String get _SYMBOL { 228 String get _SYMBOL {
229 var name = currentLibrary.name; 229 var name = currentLibrary.name;
230 if (name == 'dart.core' || name == 'dart._internal') return 'dart.JsSymbol'; 230 if (name == 'dart.core' || name == 'dart._internal') return 'dart.JsSymbol';
231 return 'Symbol'; 231 return 'Symbol';
232 } 232 }
233 233
234 bool isPublic(String name) => !name.startsWith('_'); 234 bool isPublic(String name) => !name.startsWith('_');
235 235
236 /// Conversions that we don't handle end up here.
237 @override
238 visitConversion(Conversion node) {
239 throw 'Unlowered conversion ${node.runtimeType}: $node';
240 }
241
242 @override 236 @override
243 visitAsExpression(AsExpression node) { 237 visitAsExpression(AsExpression node) {
244 var from = getStaticType(node.expression); 238 var from = getStaticType(node.expression);
245 var to = node.type.type; 239 var to = node.type.type;
246 240
247 // All Dart number types map to a JS double. 241 // All Dart number types map to a JS double.
248 if (rules.isNumType(from) && 242 if (rules.isNumType(from) &&
249 (rules.isIntType(to) || rules.isDoubleType(to))) { 243 (rules.isIntType(to) || rules.isDoubleType(to))) {
250 // TODO(jmesserly): a lot of these checks are meaningless, as people use 244 // TODO(jmesserly): a lot of these checks are meaningless, as people use
251 // `num` to mean "any kind of number" rather than "could be null". 245 // `num` to mean "any kind of number" rather than "could be null".
(...skipping 1560 matching lines...) Expand 10 before | Expand all | Expand 10 after
1812 // TODO(vsm): Revisit whether we really need this when we get 1806 // TODO(vsm): Revisit whether we really need this when we get
1813 // better non-nullability in the type system. 1807 // better non-nullability in the type system.
1814 1808
1815 if (expr is Literal && expr is! NullLiteral) return true; 1809 if (expr is Literal && expr is! NullLiteral) return true;
1816 if (expr is IsExpression) return true; 1810 if (expr is IsExpression) return true;
1817 if (expr is ThisExpression) return true; 1811 if (expr is ThisExpression) return true;
1818 if (expr is SuperExpression) return true; 1812 if (expr is SuperExpression) return true;
1819 if (expr is ParenthesizedExpression) { 1813 if (expr is ParenthesizedExpression) {
1820 return _isNonNullableExpression(expr.expression); 1814 return _isNonNullableExpression(expr.expression);
1821 } 1815 }
1822 if (expr is Conversion) {
1823 return _isNonNullableExpression(expr.expression);
1824 }
1825 if (expr is SimpleIdentifier) { 1816 if (expr is SimpleIdentifier) {
1826 // Type literals are not null. 1817 // Type literals are not null.
1827 Element e = expr.staticElement; 1818 Element e = expr.staticElement;
1828 if (e is ClassElement || e is FunctionTypeAliasElement) return true; 1819 if (e is ClassElement || e is FunctionTypeAliasElement) return true;
1829 } 1820 }
1830 DartType type = null; 1821 DartType type = null;
1831 if (expr is BinaryExpression) { 1822 if (expr is BinaryExpression) {
1832 switch (expr.operator.type) { 1823 switch (expr.operator.type) {
1833 case TokenType.EQ_EQ: 1824 case TokenType.EQ_EQ:
1834 case TokenType.BANG_EQ: 1825 case TokenType.BANG_EQ:
(...skipping 916 matching lines...) Expand 10 before | Expand all | Expand 10 after
2751 2742
2752 /// A special kind of element created by the compiler, signifying a temporary 2743 /// A special kind of element created by the compiler, signifying a temporary
2753 /// variable. These objects use instance equality, and should be shared 2744 /// variable. These objects use instance equality, and should be shared
2754 /// everywhere in the tree where they are treated as the same variable. 2745 /// everywhere in the tree where they are treated as the same variable.
2755 class TemporaryVariableElement extends LocalVariableElementImpl { 2746 class TemporaryVariableElement extends LocalVariableElementImpl {
2756 TemporaryVariableElement.forNode(Identifier name) : super.forNode(name); 2747 TemporaryVariableElement.forNode(Identifier name) : super.forNode(name);
2757 2748
2758 int get hashCode => identityHashCode(this); 2749 int get hashCode => identityHashCode(this);
2759 bool operator ==(Object other) => identical(this, other); 2750 bool operator ==(Object other) => identical(this, other);
2760 } 2751 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698