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

Side by Side 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: type inference and inlining for new ir nodes 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
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.
4
5 library ir_type_inferrer;
6
7 import '../ir/ir_nodes.dart';
8 import 'inferrer_visitor.dart' show
9 TypeSystem;
10 import 'simple_types_inferrer.dart' show
11 InferrerEngine;
12 import '../elements/elements.dart' show
13 Element, FunctionElement, FunctionSignature;
14 import '../dart2jslib.dart' show
15 Compiler, Constant, ConstantSystem;
16
17 class IrTypeInferrerVisitor<T> extends IrNodesVisitor<T> {
18 final Compiler compiler;
19 final Element analyzedElement;
20 final TypeSystem<T> types;
21 final InferrerEngine<T, TypeSystem<T>> inferrer;
22
23 IrTypeInferrerVisitor(this.compiler, this.analyzedElement,
24 InferrerEngine<T, TypeSystem<T>> inferrer) :
25 inferrer = inferrer,
26 types = inferrer.types;
27
28 T returnType;
ngeoffray 2013/11/20 14:55:27 Not used.
lukas 2013/11/21 12:20:21 Done.
29
30 T run() {
31 if (analyzedElement.isField()) {
32 // TODO(lry): handle fields.
33 throw "Type infer from IR for field $analyzedElement";
34 }
35 FunctionElement function = analyzedElement;
36 FunctionSignature signature = function.computeSignature(compiler);
37 IrFunction node = function.irNode(compiler);
38 // TODO(lry): handle parameters.
39
40 if (function.isNative()) {
41 // TODO(lry): handle native.
42 throw "Type infer from IR for natvie $analyzedElement";
ngeoffray 2013/11/20 14:55:27 natvie -> native
lukas 2013/11/21 12:20:21 Done.
43 }
44
45 if (analyzedElement.isGenerativeConstructor()) {
46 // TODO(lry): handle constructors.
47 throw "Type infer from IR for constructor $analyzedElement";
48 }
49
50 if (analyzedElement.isSynthesized) {
51 // TODO(lry): handle synthethics.
52 throw "Type infer from IR for synthetic $analyzedElement";
53 }
54
55 visitAll(node.statements);
56 }
57
58 T typeOfConstant(Constant constant) {
59 if (constant.isBool()) return types.boolType;
60 if (constant.isNum()) {
61 ConstantSystem constantSystem = compiler.backend.constantSystem;
62 // The JavaScript backend may turn this literal into a double at runtime.
63 if (constantSystem.isDouble(constant)) return types.doubleType;
64 return types.intType;
65 }
66 if (constant.isString()) return types.stringType;
67 if (constant.isNull()) return types.nullType;
68 compiler.internalError("Unexpected constant: $constant");
69 }
70
71 T visitIrConstant(IrConstant node) {
72 return typeOfConstant(node.value);
73 }
74
75 T visitIrReturn(IrReturn node) {
76 inferrer.addReturnTypeFor(analyzedElement, null, node.value.accept(this));
ngeoffray 2013/11/20 14:55:27 Hasn't the node been visited already?
lukas 2013/11/21 12:20:21 Done.
77 }
78
79 T visitNode(IrNode node) {
80 compiler.internalError('Unexpected IrNode $node');
81 }
82 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698