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

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

Issue 1050723002: partially implement instance of checks and some codegen fixes (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 8 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 | « lib/runtime/dart_runtime.js ('k') | lib/src/js/nodes.dart » ('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 // 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; 7 import 'dart:collection' show HashSet, HashMap;
8 import 'dart:io' show Directory, File; 8 import 'dart:io' show Directory, File;
9 9
10 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; 10 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator;
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 defaultValue 138 defaultValue
139 ]) 139 ])
140 ]); 140 ]);
141 } 141 }
142 142
143 JS.Statement _initPrivateSymbol(String name) => js.statement( 143 JS.Statement _initPrivateSymbol(String name) => js.statement(
144 'let # = $_SYMBOL(#);', [new JSTemporary(name), js.string(name, "'")]); 144 'let # = $_SYMBOL(#);', [new JSTemporary(name), js.string(name, "'")]);
145 145
146 // TODO(jmesserly): this is a temporary workaround for `Symbol` in core, 146 // TODO(jmesserly): this is a temporary workaround for `Symbol` in core,
147 // until we have better name tracking. 147 // until we have better name tracking.
148 String get _SYMBOL => currentLibrary.isDartCore ? 'dart.JsSymbol' : 'Symbol'; 148 String get _SYMBOL {
149 var name = currentLibrary.name;
150 if (name == 'dart.core' || name == 'dart._internal') return 'dart.JsSymbol';
151 return 'Symbol';
152 }
149 153
150 @override 154 @override
151 JS.Statement visitCompilationUnit(CompilationUnit node) { 155 JS.Statement visitCompilationUnit(CompilationUnit node) {
152 var source = node.element.source; 156 var source = node.element.source;
153 157
154 _constEvaluator = new ConstantEvaluator(source, rules.provider); 158 _constEvaluator = new ConstantEvaluator(source, rules.provider);
155 _checkerReporter.enterSource(source); 159 _checkerReporter.enterSource(source);
156 160
157 // TODO(jmesserly): scriptTag, directives. 161 // TODO(jmesserly): scriptTag, directives.
158 var body = <JS.Statement>[]; 162 var body = <JS.Statement>[];
(...skipping 1188 matching lines...) Expand 10 before | Expand all | Expand 10 after
1347 _properties.clear(); 1351 _properties.clear();
1348 } 1352 }
1349 1353
1350 @override 1354 @override
1351 JS.Statement visitVariableDeclarationStatement( 1355 JS.Statement visitVariableDeclarationStatement(
1352 VariableDeclarationStatement node) => 1356 VariableDeclarationStatement node) =>
1353 _expressionStatement(_visit(node.variables)); 1357 _expressionStatement(_visit(node.variables));
1354 1358
1355 @override 1359 @override
1356 visitConstructorName(ConstructorName node) { 1360 visitConstructorName(ConstructorName node) {
1357 var typeName = _visit(node.type.name); 1361 var typeName = _visit(node.type);
1358 if (node.name != null) { 1362 if (node.name != null) {
1359 return js.call( 1363 return js.call(
1360 '#.#', [typeName, _jsMemberName(node.name.name, isStatic: true)]); 1364 '#.#', [typeName, _jsMemberName(node.name.name, isStatic: true)]);
1361 } 1365 }
1362 return typeName; 1366 return typeName;
1363 } 1367 }
1364 1368
1365 @override 1369 @override
1366 visitInstanceCreationExpression(InstanceCreationExpression node) { 1370 visitInstanceCreationExpression(InstanceCreationExpression node) {
1367 return js.call( 1371 return js.call(
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after
1863 _catchParameter = savedCatch; 1867 _catchParameter = savedCatch;
1864 return new JS.Catch(catchVarDecl, new JS.Block([catchBody])); 1868 return new JS.Catch(catchVarDecl, new JS.Block([catchBody]));
1865 } 1869 }
1866 1870
1867 JS.Statement _catchClauseGuard(CatchClause clause, JS.Statement otherwise) { 1871 JS.Statement _catchClauseGuard(CatchClause clause, JS.Statement otherwise) {
1868 var then = visitCatchClause(clause); 1872 var then = visitCatchClause(clause);
1869 1873
1870 // Discard following clauses, if any, as they are unreachable. 1874 // Discard following clauses, if any, as they are unreachable.
1871 if (clause.exceptionType == null) return then; 1875 if (clause.exceptionType == null) return then;
1872 1876
1877 // TODO(jmesserly): this is inconsistent with [visitIsExpression], which
1878 // has special case for typeof.
1873 return new JS.If(js.call('dart.is(#, #)', [ 1879 return new JS.If(js.call('dart.is(#, #)', [
1874 _visit(_catchParameter), 1880 _visit(_catchParameter),
1875 _emitTypeName(clause.exceptionType.type), 1881 _emitTypeName(clause.exceptionType.type),
1876 ]), then, otherwise); 1882 ]), then, otherwise);
1877 } 1883 }
1878 1884
1879 JS.Statement _statement(Iterable stmts) { 1885 JS.Statement _statement(Iterable stmts) {
1880 var s = stmts is List ? stmts : new List<JS.Statement>.from(stmts); 1886 var s = stmts is List ? stmts : new List<JS.Statement>.from(stmts);
1881 // TODO(jmesserly): empty block singleton? 1887 // TODO(jmesserly): empty block singleton?
1882 if (s.length == 0) return new JS.Block([]); 1888 if (s.length == 0) return new JS.Block([]);
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after
2378 2384
2379 // TODO(jmesserly): in many cases marking the end will be unncessary. 2385 // TODO(jmesserly): in many cases marking the end will be unncessary.
2380 printer.mark(_location(node.end)); 2386 printer.mark(_location(node.end));
2381 } 2387 }
2382 2388
2383 String _getIdentifier(AstNode node) { 2389 String _getIdentifier(AstNode node) {
2384 if (node is SimpleIdentifier) return node.name; 2390 if (node is SimpleIdentifier) return node.name;
2385 return null; 2391 return null;
2386 } 2392 }
2387 } 2393 }
OLDNEW
« no previous file with comments | « lib/runtime/dart_runtime.js ('k') | lib/src/js/nodes.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698