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

Unified Diff: pkg/compiler/lib/src/js_backend/codegen/type_test_emitter.dart

Issue 1110813005: cps-ir: Implement type tests for interface types without type arguments. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/compiler/lib/src/js_backend/codegen/glue.dart ('k') | tests/language/language_dart2js.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/js_backend/codegen/type_test_emitter.dart
diff --git a/pkg/compiler/lib/src/js_backend/codegen/type_test_emitter.dart b/pkg/compiler/lib/src/js_backend/codegen/type_test_emitter.dart
new file mode 100644
index 0000000000000000000000000000000000000000..49b28e6caa8a505879994f44c4f38aa0a1b46939
--- /dev/null
+++ b/pkg/compiler/lib/src/js_backend/codegen/type_test_emitter.dart
@@ -0,0 +1,63 @@
+// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+part of code_generator;
+
+abstract class TypeTestEmitter {
+ giveup(node, reason);
+ Glue get glue;
+
+ js.Expression emitSubtypeTest(tree_ir.Node node,
+ js.Expression value,
+ DartType type) {
+ return glue.isNativePrimitiveType(type)
+ ? emitNativeSubtypeTest(node, value, type.element)
+ : emitGeneralSubtypeTest(node, value, type);
+ }
+
+ js.Expression emitNativeSubtypeTest(tree_ir.Node node,
+ js.Expression value,
+ ClassElement cls) {
+ if (glue.isIntClass(cls)) {
+ return _emitIntCheck(value);
+ } else if (glue.isStringClass(cls)) {
+ return _emitTypeofCheck(value, 'string');
+ } else if (glue.isBoolClass(cls)) {
+ return _emitTypeofCheck(value, 'boolean');
+ } else if (glue.isNumClass(cls) || glue.isDoubleClass(cls)) {
+ return _emitNumCheck(value);
+ } else {
+ return giveup(value, 'type check unimplemented for ${cls.name}.');
+ }
+ }
+
+ js.Expression emitGeneralSubtypeTest(tree_ir.Node node,
+ js.Expression value,
+ InterfaceType type) {
+ return new js.Binary('&&',
+ new js.Prefix('!!', value),
+ new js.Prefix('!!',
+ new js.PropertyAccess.field(value, glue.getTypeTestTag(type))));
+ }
+
+ js.Expression _emitNumCheck(js.Expression value) {
+ return _emitTypeofCheck(value, 'number');
+ }
+
+ js.Expression _emitBigIntCheck(js.Expression value) {
+ return js.js('Math.floor(#) === #', [value, value]);
+ }
+
+ js.Expression _emitIntCheck(js.Expression value) {
+ return new js.Binary('&&',
+ _emitNumCheck(value),
+ _emitBigIntCheck(value));
+ }
+
+ js.Expression _emitTypeofCheck(js.Expression value, String type) {
+ return new js.Binary('===',
+ new js.Prefix("typeof", value),
+ js.string(type));
+ }
+}
« no previous file with comments | « pkg/compiler/lib/src/js_backend/codegen/glue.dart ('k') | tests/language/language_dart2js.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698