Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 analyzer2dart.cps_generator; | 5 library analyzer2dart.cps_generator; |
| 6 | 6 |
| 7 import 'package:analyzer/analyzer.dart'; | 7 import 'package:analyzer/analyzer.dart'; |
| 8 | 8 |
| 9 import 'package:compiler/src/dart_types.dart' as dart2js; | 9 import 'package:compiler/src/dart_types.dart' as dart2js; |
| 10 import 'package:compiler/src/elements/elements.dart' as dart2js; | 10 import 'package:compiler/src/elements/elements.dart' as dart2js; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 final ElementConverter converter; | 28 final ElementConverter converter; |
| 29 | 29 |
| 30 CpsGeneratingVisitor(this.converter, this.element); | 30 CpsGeneratingVisitor(this.converter, this.element); |
| 31 | 31 |
| 32 Source get currentSource => element.source; | 32 Source get currentSource => element.source; |
| 33 | 33 |
| 34 analyzer.LibraryElement get currentLibrary => element.library; | 34 analyzer.LibraryElement get currentLibrary => element.library; |
| 35 | 35 |
| 36 ir.Node visit(AstNode node) => node.accept(this); | 36 ir.Node visit(AstNode node) => node.accept(this); |
| 37 | 37 |
| 38 @override | 38 ir.FieldDefinition handleFieldDeclaration( |
| 39 ir.Primitive visitFunctionExpression(FunctionExpression node) { | 39 analyzer.PropertyInducingElement field, VariableDeclaration node) { |
| 40 return irBuilder.buildFunctionExpression( | 40 dart2js.FieldElement element = converter.convertElement(field); |
| 41 handleFunctionDeclaration(node.element, node)); | 41 return withBuilder( |
| 42 new IrBuilder(DART_CONSTANT_SYSTEM, | |
| 43 element, | |
| 44 // TODO(johnniwinther): Supported closure variables. | |
| 45 const <dart2js.Local>[]), | |
| 46 () { | |
| 47 ir.Primitive initializer = build(node.initializer); | |
| 48 return irBuilder.makeFieldDefinition(initializer); | |
| 49 }); | |
| 42 } | 50 } |
| 43 | 51 |
| 44 ir.FunctionDefinition handleFunctionDeclaration( | 52 ir.FunctionDefinition handleFunctionDeclaration( |
| 45 analyzer.FunctionElement function, FunctionExpression node) { | 53 analyzer.FunctionElement function, FunctionExpression node) { |
| 46 dart2js.FunctionElement element = converter.convertElement(function); | 54 dart2js.FunctionElement element = converter.convertElement(function); |
| 47 return withBuilder( | 55 return withBuilder( |
| 48 new IrBuilder(DART_CONSTANT_SYSTEM, | 56 new IrBuilder(DART_CONSTANT_SYSTEM, |
| 49 element, | 57 element, |
| 50 // TODO(johnniwinther): Supported closure variables. | 58 // TODO(johnniwinther): Supported closure variables. |
| 51 const <dart2js.Local>[]), | 59 const <dart2js.Local>[]), |
| 52 () { | 60 () { |
| 53 function.parameters.forEach((analyzer.ParameterElement parameter) { | 61 function.parameters.forEach((analyzer.ParameterElement parameter) { |
| 54 // TODO(johnniwinther): Support "closure variables", that is variables | 62 // TODO(johnniwinther): Support "closure variables", that is variables |
| 55 // accessed from an inner function. | 63 // accessed from an inner function. |
| 56 irBuilder.createParameter(converter.convertElement(parameter)); | 64 irBuilder.createParameter(converter.convertElement(parameter)); |
| 57 }); | 65 }); |
| 58 // Visit the body directly to avoid processing the signature as | 66 // Visit the body directly to avoid processing the signature as |
| 59 // expressions. | 67 // expressions. |
| 60 visit(node.body); | 68 visit(node.body); |
| 61 return irBuilder.buildFunctionDefinition(const []); | 69 return irBuilder.makeFunctionDefinition(const []); |
| 62 }); | 70 }); |
| 63 } | 71 } |
| 64 | 72 |
| 65 @override | 73 @override |
| 74 ir.Primitive visitFunctionExpression(FunctionExpression node) { | |
| 75 return irBuilder.buildFunctionExpression( | |
| 76 handleFunctionDeclaration(node.element, node)); | |
| 77 } | |
| 78 | |
| 79 @override | |
| 66 ir.FunctionDefinition visitFunctionDeclaration(FunctionDeclaration node) { | 80 ir.FunctionDefinition visitFunctionDeclaration(FunctionDeclaration node) { |
| 67 return handleFunctionDeclaration(node.element, node.functionExpression); | 81 return handleFunctionDeclaration(node.element, node.functionExpression); |
| 68 } | 82 } |
| 69 | 83 |
| 70 @override | 84 @override |
| 71 visitFunctionDeclarationStatement(FunctionDeclarationStatement node) { | 85 visitFunctionDeclarationStatement(FunctionDeclarationStatement node) { |
| 72 FunctionDeclaration functionDeclaration = node.functionDeclaration; | 86 FunctionDeclaration functionDeclaration = node.functionDeclaration; |
| 73 analyzer.FunctionElement function = functionDeclaration.element; | 87 analyzer.FunctionElement function = functionDeclaration.element; |
| 74 dart2js.FunctionElement element = converter.convertElement(function); | 88 dart2js.FunctionElement element = converter.convertElement(function); |
| 75 ir.FunctionDefinition definition = handleFunctionDeclaration( | 89 ir.FunctionDefinition definition = handleFunctionDeclaration( |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 238 return handleLocalAccess(node, semantics); | 252 return handleLocalAccess(node, semantics); |
| 239 } | 253 } |
| 240 | 254 |
| 241 @override | 255 @override |
| 242 ir.Node visitParameterAccess(AstNode node, AccessSemantics semantics) { | 256 ir.Node visitParameterAccess(AstNode node, AccessSemantics semantics) { |
| 243 return handleLocalAccess(node, semantics); | 257 return handleLocalAccess(node, semantics); |
| 244 } | 258 } |
| 245 | 259 |
| 246 @override | 260 @override |
| 247 visitVariableDeclaration(VariableDeclaration node) { | 261 visitVariableDeclaration(VariableDeclaration node) { |
| 248 // TODO(johnniwinther): Handle constant local variables. | 262 if (hasIrBuilder) { |
|
sigurdm
2014/12/01 09:06:00
Perhaps make a getter encapsulating this check
Johnni Winther
2014/12/01 13:00:39
Done.
| |
| 249 ir.Node initialValue = build(node.initializer); | 263 // Local variable declaration. |
| 250 irBuilder.declareLocalVariable( | 264 // TODO(johnniwinther): Handle constant local variables. |
| 251 converter.convertElement(node.element), | 265 ir.Node initialValue = build(node.initializer); |
| 252 initialValue: initialValue); | 266 irBuilder.declareLocalVariable( |
| 267 converter.convertElement(node.element), | |
| 268 initialValue: initialValue); | |
| 269 } else { | |
| 270 // Field declaration. | |
| 271 return handleFieldDeclaration(node.element, node); | |
| 272 } | |
| 253 } | 273 } |
| 254 | 274 |
| 255 dart2js.Element getLocal(AstNode node, AccessSemantics semantics) { | 275 dart2js.Element getLocal(AstNode node, AccessSemantics semantics) { |
| 256 analyzer.Element element = semantics.element; | 276 analyzer.Element element = semantics.element; |
| 257 dart2js.Element target = converter.convertElement(element); | 277 dart2js.Element target = converter.convertElement(element); |
| 258 assert(invariant(node, target.isLocal, '$target expected to be local.')); | 278 assert(invariant(node, target.isLocal, '$target expected to be local.')); |
| 259 return target; | 279 return target; |
| 260 } | 280 } |
| 261 | 281 |
| 262 ir.Primitive handleLocalAccess(AstNode node, AccessSemantics semantics) { | 282 ir.Primitive handleLocalAccess(AstNode node, AccessSemantics semantics) { |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 285 return handleLocalAssignment(node, semantics); | 305 return handleLocalAssignment(node, semantics); |
| 286 } | 306 } |
| 287 | 307 |
| 288 @override | 308 @override |
| 289 ir.Node visitParameterAssignment(AssignmentExpression node, | 309 ir.Node visitParameterAssignment(AssignmentExpression node, |
| 290 AccessSemantics semantics) { | 310 AccessSemantics semantics) { |
| 291 return handleLocalAssignment(node, semantics); | 311 return handleLocalAssignment(node, semantics); |
| 292 } | 312 } |
| 293 | 313 |
| 294 @override | 314 @override |
| 315 ir.Node visitStaticFieldAssignment(AssignmentExpression node, | |
| 316 AccessSemantics semantics) { | |
| 317 if (node.operator.lexeme != '=') { | |
| 318 return giveUp(node, 'Assignment operator: ${node.operator.lexeme}'); | |
| 319 } | |
| 320 analyzer.Element element = semantics.element; | |
| 321 dart2js.Element target = converter.convertElement(element); | |
| 322 // TODO(johnniwinther): Selector information should be computed in the | |
| 323 // [TreeShaker] and shared with the [CpsGeneratingVisitor]. | |
| 324 assert(invariant(node, target.isTopLevel || target.isStatic, | |
| 325 '$target expected to be top-level or static.')); | |
| 326 return irBuilder.buildStaticSet( | |
| 327 target, | |
| 328 new Selector.setter(target.name, target.library), | |
| 329 build(node.rightHandSide)); | |
| 330 } | |
| 331 | |
| 332 @override | |
| 295 ir.Node visitDynamicAccess(AstNode node, AccessSemantics semantics) { | 333 ir.Node visitDynamicAccess(AstNode node, AccessSemantics semantics) { |
| 296 // TODO(johnniwinther): Handle implicit `this`. | 334 // TODO(johnniwinther): Handle implicit `this`. |
| 297 ir.Primitive receiver = build(semantics.target); | 335 ir.Primitive receiver = build(semantics.target); |
| 298 return irBuilder.buildDynamicGet(receiver, | 336 return irBuilder.buildDynamicGet(receiver, |
| 299 new Selector.getter(semantics.identifier.name, | 337 new Selector.getter(semantics.identifier.name, |
| 300 converter.convertElement(element.library))); | 338 converter.convertElement(element.library))); |
| 301 } | 339 } |
| 302 | 340 |
| 303 @override | 341 @override |
| 304 ir.Node visitStaticFieldAccess(AstNode node, AccessSemantics semantics) { | 342 ir.Node visitStaticFieldAccess(AstNode node, AccessSemantics semantics) { |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 456 } | 494 } |
| 457 | 495 |
| 458 @override | 496 @override |
| 459 ir.Primitive visitAsExpression(AsExpression node) { | 497 ir.Primitive visitAsExpression(AsExpression node) { |
| 460 return irBuilder.buildTypeOperator( | 498 return irBuilder.buildTypeOperator( |
| 461 visit(node.expression), | 499 visit(node.expression), |
| 462 converter.convertType(node.type.type), | 500 converter.convertType(node.type.type), |
| 463 isTypeTest: false); | 501 isTypeTest: false); |
| 464 } | 502 } |
| 465 } | 503 } |
| OLD | NEW |