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

Side by Side Diff: pkg/kernel/lib/transformations/closure/rewriter.dart

Issue 2998803002: [kernel] Support for top-level generic functions. (Closed)
Patch Set: Review comments. Created 3 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
OLDNEW
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, 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 kernel.transformations.closure.rewriter; 5 library kernel.transformations.closure.rewriter;
6 6
7 import '../../ast.dart'; 7 import '../../ast.dart';
8 import 'converter.dart' show ClosureConverter; 8 import 'converter.dart' show ClosureConverter;
9 9
10 /// Used by the [Context] to initialize and update the context variable 10 /// Used by the [Context] to initialize and update the context variable
(...skipping 12 matching lines...) Expand all
23 /// Inserts an allocation of a context and initializes [contextDeclaration] 23 /// Inserts an allocation of a context and initializes [contextDeclaration]
24 /// and [vectorCreation]. 24 /// and [vectorCreation].
25 void insertContextDeclaration(Expression accessParent); 25 void insertContextDeclaration(Expression accessParent);
26 26
27 /// Inserts an expression or statement that extends the context. 27 /// Inserts an expression or statement that extends the context.
28 void insertExtendContext(VectorSet extender); 28 void insertExtendContext(VectorSet extender);
29 29
30 void _createDeclaration() { 30 void _createDeclaration() {
31 assert(contextDeclaration == null && vectorCreation == null); 31 assert(contextDeclaration == null && vectorCreation == null);
32 32
33 // Context size is set to 1 initially, because the 0-th element of it works 33 // Context size is set to 2 initially, because the 0-th element of it holds
34 // as a link to the parent context. 34 // the vector of type arguments that the VM creates, and the 1-st element
35 vectorCreation = new VectorCreation(1); 35 // works as a link to the parent context.
36 vectorCreation = new VectorCreation(2);
36 contextDeclaration = new VariableDeclaration.forValue(vectorCreation, 37 contextDeclaration = new VariableDeclaration.forValue(vectorCreation,
37 type: new VectorType()); 38 type: new VectorType());
38 contextDeclaration.name = "#context"; 39 contextDeclaration.name = "#context";
39 } 40 }
40 } 41 }
41 42
42 /// Adds a local variable for the context and adds update [Statement]s to the 43 /// Adds a local variable for the context and adds update [Statement]s to the
43 /// current block. 44 /// current block.
44 class BlockRewriter extends AstRewriter { 45 class BlockRewriter extends AstRewriter {
45 Block _currentBlock; 46 Block _currentBlock;
(...skipping 21 matching lines...) Expand all
67 68
68 void _insertStatement(Statement statement) { 69 void _insertStatement(Statement statement) {
69 _currentBlock.statements.insert(_insertionIndex++, statement); 70 _currentBlock.statements.insert(_insertionIndex++, statement);
70 statement.parent = _currentBlock; 71 statement.parent = _currentBlock;
71 } 72 }
72 73
73 void insertContextDeclaration(Expression accessParent) { 74 void insertContextDeclaration(Expression accessParent) {
74 _createDeclaration(); 75 _createDeclaration();
75 _insertStatement(contextDeclaration); 76 _insertStatement(contextDeclaration);
76 if (accessParent is! NullLiteral) { 77 if (accessParent is! NullLiteral) {
77 // Index 0 of a context always points to the parent. 78 // Index 1 of a context always points to the parent.
78 _insertStatement(new ExpressionStatement( 79 _insertStatement(new ExpressionStatement(
79 new VectorSet(new VariableGet(contextDeclaration), 0, accessParent))); 80 new VectorSet(new VariableGet(contextDeclaration), 1, accessParent)));
80 } 81 }
81 } 82 }
82 83
83 void insertExtendContext(VectorSet extender) { 84 void insertExtendContext(VectorSet extender) {
84 _insertStatement(new ExpressionStatement(extender)); 85 _insertStatement(new ExpressionStatement(extender));
85 } 86 }
86 } 87 }
87 88
88 class InitializerListRewriter extends AstRewriter { 89 class InitializerListRewriter extends AstRewriter {
89 final Constructor parentConstructor; 90 final Constructor parentConstructor;
(...skipping 15 matching lines...) Expand all
105 } 106 }
106 107
107 @override 108 @override
108 void insertExtendContext(VectorSet extender) { 109 void insertExtendContext(VectorSet extender) {
109 var init = new LocalInitializer( 110 var init = new LocalInitializer(
110 new VariableDeclaration(null, initializer: extender)); 111 new VariableDeclaration(null, initializer: extender));
111 init.parent = parentConstructor; 112 init.parent = parentConstructor;
112 prefix.add(init); 113 prefix.add(init);
113 } 114 }
114 } 115 }
OLDNEW
« no previous file with comments | « pkg/kernel/lib/transformations/closure/converter.dart ('k') | pkg/kernel/test/closures/closures.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698