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

Side by Side Diff: dart/lib/compiler/implementation/ssa/builder.dart

Issue 10823184: Basic type inference skeleton (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Address review comments Created 8 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 class Interceptors { 5 class Interceptors {
6 Compiler compiler; 6 Compiler compiler;
7 Interceptors(Compiler this.compiler); 7 Interceptors(Compiler this.compiler);
8 8
9 SourceString mapOperatorToMethodName(Operator op) { 9 SourceString mapOperatorToMethodName(Operator op) {
10 String name = op.source.stringValue; 10 String name = op.source.stringValue;
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 */ 210 */
211 Map<Element, HInstruction> directLocals; 211 Map<Element, HInstruction> directLocals;
212 Map<Element, Element> redirectionMapping; 212 Map<Element, Element> redirectionMapping;
213 SsaBuilder builder; 213 SsaBuilder builder;
214 ClosureData closureData; 214 ClosureData closureData;
215 215
216 LocalsHandler(this.builder) 216 LocalsHandler(this.builder)
217 : directLocals = new Map<Element, HInstruction>(), 217 : directLocals = new Map<Element, HInstruction>(),
218 redirectionMapping = new Map<Element, Element>(); 218 redirectionMapping = new Map<Element, Element>();
219 219
220 get typesTask() => builder.compiler.typesTask;
221
220 /** 222 /**
221 * Creates a new [LocalsHandler] based on [other]. We only need to 223 * Creates a new [LocalsHandler] based on [other]. We only need to
222 * copy the [directLocals], since the other fields can be shared 224 * copy the [directLocals], since the other fields can be shared
223 * throughout the AST visit. 225 * throughout the AST visit.
224 */ 226 */
225 LocalsHandler.from(LocalsHandler other) 227 LocalsHandler.from(LocalsHandler other)
226 : directLocals = new Map<Element, HInstruction>.from(other.directLocals), 228 : directLocals = new Map<Element, HInstruction>.from(other.directLocals),
227 redirectionMapping = other.redirectionMapping, 229 redirectionMapping = other.redirectionMapping,
228 builder = other.builder, 230 builder = other.builder,
229 closureData = other.closureData; 231 closureData = other.closureData;
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 310
309 ClosureTranslator translator = new ClosureTranslator(builder); 311 ClosureTranslator translator = new ClosureTranslator(builder);
310 closureData = translator.translate(node); 312 closureData = translator.translate(node);
311 313
312 FunctionSignature signature = function.computeSignature(builder.compiler); 314 FunctionSignature signature = function.computeSignature(builder.compiler);
313 signature.forEachParameter((Element element) { 315 signature.forEachParameter((Element element) {
314 HInstruction parameter = new HParameterValue(element); 316 HInstruction parameter = new HParameterValue(element);
315 builder.add(parameter); 317 builder.add(parameter);
316 builder.parameters[element] = parameter; 318 builder.parameters[element] = parameter;
317 directLocals[element] = parameter; 319 directLocals[element] = parameter;
320 parameter.guaranteedType =
321 builder.mapInferredType(typesTask.getGuaranteedTypeOfElement(element));
318 }); 322 });
319 323
320 enterScope(node); 324 enterScope(node);
321 325
322 // If the freeVariableMapping is not empty, then this function was a 326 // If the freeVariableMapping is not empty, then this function was a
323 // nested closure that captures variables. Redirect the captured 327 // nested closure that captures variables. Redirect the captured
324 // variables to fields in the closure. 328 // variables to fields in the closure.
325 closureData.freeVariableMapping.forEach((Element from, Element to) { 329 closureData.freeVariableMapping.forEach((Element from, Element to) {
326 redirectElement(from, to); 330 redirectElement(from, to);
327 }); 331 });
(...skipping 2956 matching lines...) Expand 10 before | Expand all | Expand 10 after
3284 } 3288 }
3285 3289
3286 visitTypedef(Typedef node) { 3290 visitTypedef(Typedef node) {
3287 compiler.unimplemented('SsaBuilder.visitTypedef', node: node); 3291 compiler.unimplemented('SsaBuilder.visitTypedef', node: node);
3288 } 3292 }
3289 3293
3290 visitTypeVariable(TypeVariable node) { 3294 visitTypeVariable(TypeVariable node) {
3291 compiler.internalError('SsaBuilder.visitTypeVariable'); 3295 compiler.internalError('SsaBuilder.visitTypeVariable');
3292 } 3296 }
3293 3297
3298 HType mapInferredType(Element element) {
3299 if (element === builder.compiler.boolClass) return HType.BOOLEAN;
ngeoffray 2012/08/16 12:53:10 Should those be BOOLEAN_OR_NULL, ... ?
ahe 2012/08/16 17:26:54 No. It has been inferred that it must be a bool. T
3300 if (element === builder.compiler.doubleClass) return HType.DOUBLE;
3301 if (element === builder.compiler.intClass) return HType.INTEGER;
3302 // TODO(ahe): How to map listClass to HType?
ngeoffray 2012/08/16 12:53:10 new HBoundedPotentialPrimitiveArray(element.comput
ahe 2012/08/16 17:26:54 It can't be null and it will be a primitive array.
3303 if (element === builder.compiler.listClass) return HType.UNKNOWN;
3304 if (element === builder.compiler.nullClass) return HType.NULL;
3305 if (element === builder.compiler.stringClass) return HType.STRING;
3306 return HType.UNKNOWN;
3307 }
3308
3294 /** HACK HACK HACK */ 3309 /** HACK HACK HACK */
3295 void hackAroundPossiblyAbortingBody(Node statement, void body()) { 3310 void hackAroundPossiblyAbortingBody(Node statement, void body()) {
3296 visitCondition() { 3311 visitCondition() {
3297 stack.add(graph.addConstantBool(true)); 3312 stack.add(graph.addConstantBool(true));
3298 } 3313 }
3299 buildBody() { 3314 buildBody() {
3300 // TODO(lrn): Make sure to take continue into account. 3315 // TODO(lrn): Make sure to take continue into account.
3301 body(); 3316 body();
3302 } 3317 }
3303 handleIf(statement, visitCondition, buildBody, null); 3318 handleIf(statement, visitCondition, buildBody, null);
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
3585 new HSubGraphBlockInformation(elseBranch.graph)); 3600 new HSubGraphBlockInformation(elseBranch.graph));
3586 3601
3587 HBasicBlock conditionStartBlock = conditionBranch.block; 3602 HBasicBlock conditionStartBlock = conditionBranch.block;
3588 conditionStartBlock.setBlockFlow(info, joinBlock); 3603 conditionStartBlock.setBlockFlow(info, joinBlock);
3589 SubGraph conditionGraph = conditionBranch.graph; 3604 SubGraph conditionGraph = conditionBranch.graph;
3590 HIf branch = conditionGraph.end.last; 3605 HIf branch = conditionGraph.end.last;
3591 assert(branch is HIf); 3606 assert(branch is HIf);
3592 branch.blockInformation = conditionStartBlock.blockFlow; 3607 branch.blockInformation = conditionStartBlock.blockFlow;
3593 } 3608 }
3594 } 3609 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698