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

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

Issue 85813002: Revert "Revert "Build new IR for functions returning a constant."" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: feedback by kasper Created 7 years 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 dart2js.ir_type_inferrer;
6
7 import '../ir/ir_nodes.dart';
8 import 'inferrer_visitor.dart' show TypeSystem;
9 import 'simple_types_inferrer.dart' show InferrerEngine;
10 import '../elements/elements.dart' show
11 Element, FunctionElement, FunctionSignature;
12 import '../dart2jslib.dart' show Compiler, Constant, ConstantSystem;
13 import 'type_graph_inferrer.dart' show TypeInformation;
14
15 class IrTypeInferrerVisitor extends IrNodesVisitor {
16 final Compiler compiler;
17 final Element analyzedElement;
18 final TypeSystem<TypeInformation> types;
19 final InferrerEngine<TypeInformation, TypeSystem<TypeInformation>> inferrer;
20
21 IrTypeInferrerVisitor(this.compiler,
22 this.analyzedElement,
23 InferrerEngine<TypeInformation,
24 TypeSystem<TypeInformation>> inferrer)
25 : inferrer = inferrer,
26 types = inferrer.types;
27
28 final Map<IrNode, TypeInformation> analyzed = <IrNode, TypeInformation>{};
29
30 TypeInformation returnType;
31
32 TypeInformation run() {
33 if (analyzedElement.isField()) {
34 // TODO(lry): handle fields.
35 throw "Type infer from IR for field $analyzedElement";
36 }
37 FunctionElement function = analyzedElement;
38 FunctionSignature signature = function.computeSignature(compiler);
39 IrFunction node = compiler.irBuilder.getIr(function);
40 // TODO(lry): handle parameters.
41
42 if (function.isNative()) {
43 // TODO(lry): handle native.
44 throw "Type infer from IR for native $analyzedElement";
45 }
46
47 if (analyzedElement.isGenerativeConstructor()) {
48 // TODO(lry): handle constructors.
49 throw "Type infer from IR for constructor $analyzedElement";
50 }
51
52 if (analyzedElement.isSynthesized) {
53 // TODO(lry): handle synthethics.
54 throw "Type infer from IR for synthetic $analyzedElement";
55 }
56
57 visitAll(node.statements);
58 return returnType;
59 }
60
61 TypeInformation typeOfConstant(Constant constant) {
62 if (constant.isBool()) return types.boolType;
63 if (constant.isNum()) {
64 ConstantSystem constantSystem = compiler.backend.constantSystem;
65 // The JavaScript backend may turn this literal into a double at runtime.
66 if (constantSystem.isDouble(constant)) return types.doubleType;
67 return types.intType;
68 }
69 if (constant.isString()) return types.stringType;
70 if (constant.isNull()) return types.nullType;
71 compiler.internalError("Unexpected constant: $constant");
72 }
73
74 void visitIrConstant(IrConstant node) {
75 analyzed[node] = typeOfConstant(node.value);
76 }
77
78 void visitIrReturn(IrReturn node) {
79 TypeInformation type = analyzed[node.value];
80 returnType = inferrer.addReturnTypeFor(analyzedElement, returnType, type);
81 }
82
83 void visitNode(IrNode node) {
84 compiler.internalError('Unexpected IrNode $node');
85 }
86 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698