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

Unified Diff: sdk/lib/_internal/compiler/implementation/inferrer/ir_type_inferrer.dart

Issue 57873002: Build new IR for functions returning a constant (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: rename INode>IrNode. started working on inferencer Created 7 years, 1 month 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
Index: sdk/lib/_internal/compiler/implementation/inferrer/ir_type_inferrer.dart
diff --git a/sdk/lib/_internal/compiler/implementation/inferrer/ir_type_inferrer.dart b/sdk/lib/_internal/compiler/implementation/inferrer/ir_type_inferrer.dart
new file mode 100644
index 0000000000000000000000000000000000000000..3a2e83641220de90b8282df4e565ef1def3ed20d
--- /dev/null
+++ b/sdk/lib/_internal/compiler/implementation/inferrer/ir_type_inferrer.dart
@@ -0,0 +1,50 @@
+// Copyright (c) 2013, 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.
+
+library ir_type_inferrer;
+
+import '../ir/ir_nodes.dart';
+import 'inferrer_visitor.dart' show
+ TypeSystem;
+import 'simple_types_inferrer.dart' show
+ InferrerEngine;
+import '../elements/elements.dart' show
+ Element;
+import '../dart2jslib.dart' show
+ Compiler, Constant, ConstantSystem;
+
+class IrTypeInferrerVisitor<T> extends IrNodesVisitor<T> {
+ final Compiler compiler;
+ final Element analyzedElement;
+ final TypeSystem<T> types;
+ final InferrerEngine<T, TypeSystem<T>> inferrer;
+
+ IrTypeInferrerVisitor(
+ this.compiler, this.analyzedElement, this.types, this.inferrer);
+
+ T typeOfConstant(Constant constant) {
+ if (constant.isBool()) return types.boolType;
+ if (constant.isNum()) {
+ ConstantSystem constantSystem = compiler.backend.constantSystem;
+ // The JavaScript backend may turn this literal into a double at runtime.
+ if (constantSystem.isDouble(constant)) return types.doubleType;
+ return types.intType;
+ }
+ if (constant.isString()) return types.stringType;
+ if (constant.isNull()) return types.nullType;
+ compiler.internalError("Unexpected constant: $constant");
+ }
+
+ T visitIrConstant(IrConstant node) {
+ return typeOfConstant(node.value);
+ }
+
+ T visitIrFunction(IrFunction node) {
+ // TODO implement this method
+ }
+
+ T visitIrReturn(IrReturn node) {
+ inferrer.addReturnTypeFor(analyzedElement, null, node.value.accept(this));
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698