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

Side by Side Diff: pkg/analyzer2dart/lib/src/cps_generator.dart

Issue 562123002: Support parameter access in analyzer2dart. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 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
« no previous file with comments | « no previous file | pkg/analyzer2dart/lib/src/element_converter.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) 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/implementation/elements/elements.dart' as dart2js; 9 import 'package:compiler/implementation/elements/elements.dart' as dart2js;
10 import 'package:analyzer/src/generated/element.dart' as analyzer; 10 import 'package:analyzer/src/generated/element.dart' as analyzer;
(...skipping 17 matching lines...) Expand all
28 28
29 @override 29 @override
30 ir.FunctionDefinition visitFunctionDeclaration(FunctionDeclaration node) { 30 ir.FunctionDefinition visitFunctionDeclaration(FunctionDeclaration node) {
31 analyzer.FunctionElement function = node.element; 31 analyzer.FunctionElement function = node.element;
32 function.parameters.forEach((analyzer.ParameterElement parameter) { 32 function.parameters.forEach((analyzer.ParameterElement parameter) {
33 // TODO(johnniwinther): Support "closure variables", that is variables 33 // TODO(johnniwinther): Support "closure variables", that is variables
34 // accessed from an inner function. 34 // accessed from an inner function.
35 irBuilder.createParameter(converter.convertElement(parameter), 35 irBuilder.createParameter(converter.convertElement(parameter),
36 isClosureVariable: false); 36 isClosureVariable: false);
37 }); 37 });
38 super.visitFunctionDeclaration(node); 38 // Visit the body directly to avoid processing the signature as expressions.
39 node.functionExpression.body.accept(this);
39 return irBuilder.buildFunctionDefinition( 40 return irBuilder.buildFunctionDefinition(
40 converter.convertElement(function), const [], const []); 41 converter.convertElement(function), const [], const []);
41 } 42 }
42 43 /*
sigurdm 2014/09/11 11:13:13 Why is this commented out?
Johnni Winther 2014/09/11 11:31:40 I thought I needed to process the function express
44 @override
45 visitFunctionExpression(FunctionExpression node) {
46 node.body
47 }
48 */
43 @override 49 @override
44 visitMethodInvocation(MethodInvocation node) { 50 visitMethodInvocation(MethodInvocation node) {
45 analyzer.Element staticElement = node.methodName.staticElement; 51 analyzer.Element staticElement = node.methodName.staticElement;
46 if (staticElement != null) { 52 if (staticElement != null) {
47 dart2js.Element element = converter.convertElement(staticElement); 53 dart2js.Element element = converter.convertElement(staticElement);
48 List<ir.Definition> arguments = <ir.Definition>[]; 54 List<ir.Definition> arguments = <ir.Definition>[];
49 for (Expression argument in node.argumentList.arguments) { 55 for (Expression argument in node.argumentList.arguments) {
50 arguments.add(argument.accept(this)); 56 ir.Definition value = argument.accept(this);
57 if (value == null) {
58 giveUp('Unsupported argument: $argument (${argument.runtimeType}).');
59 }
60 arguments.add(value);
51 } 61 }
52 return irBuilder.buildStaticInvocation( 62 return irBuilder.buildStaticInvocation(
53 element, createSelectorFromMethodInvocation(node), arguments); 63 element, createSelectorFromMethodInvocation(node), arguments);
54 } 64 }
55 } 65 }
56 66
57 @override 67 @override
58 ir.Constant visitNullLiteral(NullLiteral node) { 68 ir.Constant visitNullLiteral(NullLiteral node) {
59 return irBuilder.buildNullLiteral(); 69 return irBuilder.buildNullLiteral();
60 } 70 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 } 104 }
95 105
96 @override 106 @override
97 visitReturnStatement(ReturnStatement node) { 107 visitReturnStatement(ReturnStatement node) {
98 if (node.expression != null) { 108 if (node.expression != null) {
99 irBuilder.buildReturn(node.expression.accept(this)); 109 irBuilder.buildReturn(node.expression.accept(this));
100 } else { 110 } else {
101 irBuilder.buildReturn(); 111 irBuilder.buildReturn();
102 } 112 }
103 } 113 }
114
115 @override
116 visitSimpleIdentifier(SimpleIdentifier node) {
117 analyzer.Element element = node.staticElement;
118 if (element != null) {
119 dart2js.Element target = converter.convertElement(element);
120 if (dart2js.Elements.isLocal(target)) {
121 return irBuilder.buildGetLocal(target);
122 }
123 giveUp('Unhandled static reference: '
124 '$node -> $target (${target.runtimeType})');
125 }
126 giveUp('Unresolved identifier: $node.');
127 }
104 } 128 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer2dart/lib/src/element_converter.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698