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

Side by Side Diff: pkg/compiler/lib/src/resolution/resolution_result.dart

Issue 1170673002: Begin to compute constant expressions in resolution. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Fix BinaryConstantExpression.getKnownType Created 5 years, 6 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of resolution; 5 part of resolution;
6 6
7 enum ResultKind {
8 NONE,
9 ELEMENT,
10 TYPE,
11 ASSERT,
12 CONSTANT,
13 }
14
7 /// The result of resolving a node. 15 /// The result of resolving a node.
8 abstract class ResolutionResult { 16 abstract class ResolutionResult {
9 Element get element; 17 const ResolutionResult();
18
19 // TODO(johnniwinther): Remove this factory constructor when `null` is never
20 // passed as an element result.
21 factory ResolutionResult.forElement(Element element) {
22 return element != null ? new ElementResult(element) : const NoneResult();
23 }
24
25 ResultKind get kind;
26 Element get element => null;
27 DartType get type => null;
28 ConstantExpression get constant => null;
29 bool get isConstant => false;
10 } 30 }
11 31
12 /// The result for the resolution of a node that points to an [Element]. 32 /// The result for the resolution of a node that points to an [Element].
13 class ElementResult implements ResolutionResult { 33 class ElementResult extends ResolutionResult {
14 final Element element; 34 final Element element;
15 35
16 // TODO(johnniwinther): Remove this factory constructor when `null` is never 36 ResultKind get kind => ResultKind.ELEMENT;
17 // passed as an element result.
18 factory ElementResult(Element element) {
19 return element != null ? new ElementResult.internal(element) : null;
20 }
21 37
22 ElementResult.internal(this.element); 38 ElementResult(this.element);
23 39
24 String toString() => 'ElementResult($element)'; 40 String toString() => 'ElementResult($element)';
25 } 41 }
26 42
27 /// The result for the resolution of a node that points to an [DartType]. 43 /// The result for the resolution of a node that points to an [DartType].
28 class TypeResult implements ResolutionResult { 44 class TypeResult extends ResolutionResult {
29 final DartType type; 45 final DartType type;
30 46
31 TypeResult(this.type) { 47 TypeResult(this.type) {
32 assert(type != null); 48 assert(type != null);
33 } 49 }
34 50
51 ResultKind get kind => ResultKind.TYPE;
52
35 Element get element => type.element; 53 Element get element => type.element;
36 54
37 String toString() => 'TypeResult($type)'; 55 String toString() => 'TypeResult($type)';
38 } 56 }
39 57
40 /// The result for the resolution of the `assert` method. 58 /// The result for the resolution of the `assert` method.
41 class AssertResult implements ResolutionResult { 59 class AssertResult extends ResolutionResult {
42 const AssertResult(); 60 const AssertResult();
43 61
44 Element get element => null; 62 ResultKind get kind => ResultKind.ASSERT;
45 63
46 String toString() => 'AssertResult()'; 64 String toString() => 'AssertResult()';
47 } 65 }
66
67 class ConstantResult extends ResolutionResult {
68 final Node node;
69 final ConstantExpression constant;
70
71 ConstantResult(this.node, this.constant);
72
73 bool get isConstant => true;
74
75 ResultKind get kind => ResultKind.CONSTANT;
76
77 String toString() => 'ConstantResult(${constant.getText()})';
78 }
79
80 class NoneResult extends ResolutionResult {
81 const NoneResult();
82
83 ResultKind get kind => ResultKind.NONE;
84
85 String toString() => 'NoneResult()';
86 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/resolution/resolution.dart ('k') | tests/compiler/dart2js/mock_compiler.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698