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

Side by Side Diff: frog/leg/elements/elements.dart

Issue 8888010: First instantiations of objects. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Added comment. Created 9 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
« no previous file with comments | « no previous file | frog/leg/emitter.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 #library('elements'); 5 #library('elements');
6 6
7 #import('../tree/tree.dart'); 7 #import('../tree/tree.dart');
8 #import('../scanner/scannerlib.dart'); 8 #import('../scanner/scannerlib.dart');
9 #import('../leg.dart'); // TODO(karlklose): we only need type. 9 #import('../leg.dart'); // TODO(karlklose): we only need type.
10 #import('../util/util.dart'); 10 #import('../util/util.dart');
(...skipping 12 matching lines...) Expand all
23 final String id; 23 final String id;
24 24
25 const ElementKind(String this.id); 25 const ElementKind(String this.id);
26 26
27 static final ElementKind VARIABLE = const ElementKind('variable'); 27 static final ElementKind VARIABLE = const ElementKind('variable');
28 static final ElementKind PARAMETER = const ElementKind('parameter'); 28 static final ElementKind PARAMETER = const ElementKind('parameter');
29 static final ElementKind FUNCTION = const ElementKind('function'); 29 static final ElementKind FUNCTION = const ElementKind('function');
30 static final ElementKind CLASS = const ElementKind('class'); 30 static final ElementKind CLASS = const ElementKind('class');
31 static final ElementKind FOREIGN = const ElementKind('foreign'); 31 static final ElementKind FOREIGN = const ElementKind('foreign');
32 static final ElementKind CONSTRUCTOR = const ElementKind('constructor'); 32 static final ElementKind CONSTRUCTOR = const ElementKind('constructor');
33 static final ElementKind CONSTRUCTOR_BODY =
34 const ElementKind('constructor_body');
33 35
34 toString() => id; 36 toString() => id;
35 } 37 }
36 38
37 class Element implements Hashable { 39 class Element implements Hashable {
38 final SourceString name; 40 final SourceString name;
39 final ElementKind kind; 41 final ElementKind kind;
40 final Element enclosingElement; 42 final Element enclosingElement;
41 abstract Node parseNode(Canceler canceler, Logger logger); 43 abstract Node parseNode(Canceler canceler, Logger logger);
42 abstract Type computeType(Compiler compiler, Types types); 44 abstract Type computeType(Compiler compiler, Types types);
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 for (Link<Element> link = parameters; !link.isEmpty(); link = link.tail) { 132 for (Link<Element> link = parameters; !link.isEmpty(); link = link.tail) {
131 parameterTypes.addLast(link.head.computeType(compiler, types)); 133 parameterTypes.addLast(link.head.computeType(compiler, types));
132 } 134 }
133 type = new FunctionType(returnType, parameterTypes.toLink(), this); 135 type = new FunctionType(returnType, parameterTypes.toLink(), this);
134 return type; 136 return type;
135 } 137 }
136 138
137 Node parseNode(Canceler canceler, Logger logger) => node; 139 Node parseNode(Canceler canceler, Logger logger) => node;
138 } 140 }
139 141
142 class ConstructorBodyElement extends FunctionElement {
143 FunctionElement constructor;
144
145 ConstructorBodyElement(FunctionElement constructor)
146 : this.constructor = constructor,
147 super(constructor.name,
148 ElementKind.CONSTRUCTOR_BODY,
149 constructor.enclosingElement) {
150 assert(constructor.node !== null);
151 }
152
153 Link<Element> get parameters() => constructor.parameters;
154 FunctionExpression get node() => constructor.node;
155 Type get type() => constructor.type;
156 bool isStatic() => false;
157
158 FunctionType computeType(Compiler compiler, types) { unreachable(); }
159 Node parseNode(Canceler canceler, Logger logger) { unreachable(); }
160 }
161
140 class SynthesizedConstructorElement extends FunctionElement { 162 class SynthesizedConstructorElement extends FunctionElement {
141 SynthesizedConstructorElement(Element enclosing) 163 SynthesizedConstructorElement(Element enclosing)
142 : super(const SourceString(''), ElementKind.CONSTRUCTOR, enclosing) { 164 : super(const SourceString(''), ElementKind.CONSTRUCTOR, enclosing) {
143 parameters = const EmptyLink<Element>(); 165 parameters = const EmptyLink<Element>();
144 } 166 }
145 167
146 FunctionType computeType(Compiler compiler, types) { 168 FunctionType computeType(Compiler compiler, types) {
147 if (type != null) return type; 169 if (type != null) return type;
148 type = new FunctionType(types.voidType, const EmptyLink<Type>(), this); 170 type = new FunctionType(types.voidType, const EmptyLink<Type>(), this);
149 return type; 171 return type;
150 } 172 }
151 173
152 Node parseNode(Canceler canceler, Logger logger) { 174 Node parseNode(Canceler canceler, Logger logger) {
153 if (node != null) return node; 175 if (node != null) return node;
154 node = new FunctionExpression( 176 node = new FunctionExpression(
155 new Identifier.synthetic(''), 177 new Identifier.synthetic(''),
156 new NodeList.empty(), 178 new NodeList.empty(),
157 new Block(new NodeList.empty())); 179 new Block(new NodeList.empty()));
158 return node; 180 return node;
159 } 181 }
160 } 182 }
161 183
162 class ClassElement extends Element { 184 class ClassElement extends Element {
163 Type type; 185 Type type;
164 Type supertype; 186 Type supertype;
165 Link<Element> members; 187 Link<Element> members;
166 Link<Type> interfaces = const EmptyLink<Type>(); 188 Link<Type> interfaces = const EmptyLink<Type>();
167 bool isResolved = false; 189 bool isResolved = false;
168 ClassNode node; 190 ClassNode node;
191 // backendMembers are members that have been added by the backend to simplify
192 // compilation. They don't have any user-side counter-part.
193 Link<Element> backendMembers;
169 SynthesizedConstructorElement synthesizedConstructor; 194 SynthesizedConstructorElement synthesizedConstructor;
170 195
171 ClassElement(SourceString name) : super(name, ElementKind.CLASS, null); 196 ClassElement(SourceString name)
197 : backendMembers = const EmptyLink(),
198 super(name, ElementKind.CLASS, null);
172 199
173 Type computeType(compiler, types) { 200 Type computeType(compiler, types) {
174 if (type === null) { 201 if (type === null) {
175 type = new SimpleType(name, this); 202 type = new SimpleType(name, this);
176 } 203 }
177 return type; 204 return type;
178 } 205 }
179 206
180 void resolve(Compiler compiler) { 207 void resolve(Compiler compiler) {
181 if (isResolved) return; 208 if (isResolved) return;
(...skipping 14 matching lines...) Expand all
196 // TODO(ngeoffray): Implement these. 223 // TODO(ngeoffray): Implement these.
197 bool canHaveDefaultConstructor() => true; 224 bool canHaveDefaultConstructor() => true;
198 225
199 SynthesizedConstructorElement getSynthesizedConstructor() { 226 SynthesizedConstructorElement getSynthesizedConstructor() {
200 if (synthesizedConstructor === null && canHaveDefaultConstructor()) { 227 if (synthesizedConstructor === null && canHaveDefaultConstructor()) {
201 synthesizedConstructor = new SynthesizedConstructorElement(this); 228 synthesizedConstructor = new SynthesizedConstructorElement(this);
202 } 229 }
203 return synthesizedConstructor; 230 return synthesizedConstructor;
204 } 231 }
205 } 232 }
OLDNEW
« no previous file with comments | « no previous file | frog/leg/emitter.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698