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

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: no nested functions in ir 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) :
ngeoffray 2013/11/21 15:02:05 Nit: ':' at the beginning of the line.
lukas 2013/11/21 17:14:27 Done.
25 inferrer = inferrer,
26 types = inferrer.types;
27
28 final Map<IrNode, T> analyzed = new Map<IrNode, T>();
29
30 T recordAnalyzed(IrNode node, T type) {
31 analyzed[node] = type;
ngeoffray 2013/11/21 15:02:05 Use '=>': => analyzed[node] = type;
lukas 2013/11/21 17:14:27 Done.
32 return type;
33 }
34
35 T run() {
36 if (analyzedElement.isField()) {
37 // TODO(lry): handle fields.
38 throw "Type infer from IR for field $analyzedElement";
39 }
40 FunctionElement function = analyzedElement;
41 FunctionSignature signature = function.computeSignature(compiler);
42 IrFunction node = function.irNode(compiler);
43 // TODO(lry): handle parameters.
44
45 if (function.isNative()) {
46 // TODO(lry): handle native.
47 throw "Type infer from IR for native $analyzedElement";
48 }
49
50 if (analyzedElement.isGenerativeConstructor()) {
51 // TODO(lry): handle constructors.
52 throw "Type infer from IR for constructor $analyzedElement";
53 }
54
55 if (analyzedElement.isSynthesized) {
56 // TODO(lry): handle synthethics.
57 throw "Type infer from IR for synthetic $analyzedElement";
58 }
59
60 visitAll(node.statements);
61 }
62
63 T typeOfConstant(Constant constant) {
64 if (constant.isBool()) return types.boolType;
65 if (constant.isNum()) {
66 ConstantSystem constantSystem = compiler.backend.constantSystem;
67 // The JavaScript backend may turn this literal into a double at runtime.
68 if (constantSystem.isDouble(constant)) return types.doubleType;
69 return types.intType;
70 }
71 if (constant.isString()) return types.stringType;
72 if (constant.isNull()) return types.nullType;
73 compiler.internalError("Unexpected constant: $constant");
74 }
75
76 T visitIrConstant(IrConstant node) {
77 return recordAnalyzed(node, typeOfConstant(node.value));
78 }
79
80 T visitIrReturn(IrReturn node) {
81 inferrer.addReturnTypeFor(analyzedElement, null, analyzed[node.value]);
82 }
83
84 T visitNode(IrNode node) {
85 compiler.internalError('Unexpected IrNode $node');
86 }
87 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698