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

Side by Side Diff: runtime/vm/ast_transformer.cc

Issue 868913002: Add Zone-based handle allocation interface and reduce use of Isolate-based interfaces. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 5 years, 11 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 | runtime/vm/bit_vector.h » ('j') | runtime/vm/constant_propagator.cc » ('J')
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 #include "vm/ast_transformer.h" 5 #include "vm/ast_transformer.h"
6 6
7 #include "vm/object_store.h" 7 #include "vm/object_store.h"
8 #include "vm/parser.h" 8 #include "vm/parser.h"
9 #include "vm/thread.h" 9 #include "vm/thread.h"
10 10
11 namespace dart { 11 namespace dart {
12 12
13 // Quick access to the current isolate and zone. 13 // Quick access to the current zone.
14 #define I (thread()->isolate())
15 #define Z (thread()->zone()) 14 #define Z (thread()->zone())
16 15
17 // Nodes that are unreachable from already parsed expressions. 16 // Nodes that are unreachable from already parsed expressions.
18 #define FOR_EACH_UNREACHABLE_NODE(V) \ 17 #define FOR_EACH_UNREACHABLE_NODE(V) \
19 V(AwaitMarker) \ 18 V(AwaitMarker) \
20 V(Case) \ 19 V(Case) \
21 V(CatchClause) \ 20 V(CatchClause) \
22 V(CloneContext) \ 21 V(CloneContext) \
23 V(ClosureCall) \ 22 V(ClosureCall) \
24 V(DoWhile) \ 23 V(DoWhile) \
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 58
60 AstNode* AwaitTransformer::Transform(AstNode* expr) { 59 AstNode* AwaitTransformer::Transform(AstNode* expr) {
61 expr->Visit(this); 60 expr->Visit(this);
62 return result_; 61 return result_;
63 } 62 }
64 63
65 64
66 LocalVariable* AwaitTransformer::EnsureCurrentTempVar() { 65 LocalVariable* AwaitTransformer::EnsureCurrentTempVar() {
67 const char* await_temp_prefix = ":await_temp_var_"; 66 const char* await_temp_prefix = ":await_temp_var_";
68 const String& cnt_str = String::ZoneHandle( 67 const String& cnt_str = String::ZoneHandle(
69 I, String::NewFormatted("%s%d", await_temp_prefix, temp_cnt_)); 68 Z, String::NewFormatted("%s%d", await_temp_prefix, temp_cnt_));
70 const String& symbol = String::ZoneHandle(I, Symbols::New(cnt_str)); 69 const String& symbol = String::ZoneHandle(Z, Symbols::New(cnt_str));
71 ASSERT(!symbol.IsNull()); 70 ASSERT(!symbol.IsNull());
72 // Look up the variable through the preamble scope. 71 // Look up the variable through the preamble scope.
73 LocalVariable* await_tmp = preamble_->scope()->LookupVariable(symbol, false); 72 LocalVariable* await_tmp = preamble_->scope()->LookupVariable(symbol, false);
74 if (await_tmp == NULL) { 73 if (await_tmp == NULL) {
75 // If we need a new temp variable, we add it to the function's top scope. 74 // If we need a new temp variable, we add it to the function's top scope.
76 await_tmp = new (Z) LocalVariable( 75 await_tmp = new (Z) LocalVariable(
77 Scanner::kNoSourcePos, symbol, Type::ZoneHandle(Type::DynamicType())); 76 Scanner::kNoSourcePos, symbol, Type::ZoneHandle(Type::DynamicType()));
78 function_top_->AddVariable(await_tmp); 77 function_top_->AddVariable(await_tmp);
79 // After adding it to the top scope, we can look it up from the preamble. 78 // After adding it to the top scope, we can look it up from the preamble.
80 // The following call includes an ASSERT check. 79 // The following call includes an ASSERT check.
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 preamble_->scope(), Symbols::AsyncOperationErrorParam()); 133 preamble_->scope(), Symbols::AsyncOperationErrorParam());
135 134
136 AstNode* transformed_expr = Transform(node->expr()); 135 AstNode* transformed_expr = Transform(node->expr());
137 preamble_->Add(new(Z) StoreLocalNode( 136 preamble_->Add(new(Z) StoreLocalNode(
138 Scanner::kNoSourcePos, result_param, transformed_expr)); 137 Scanner::kNoSourcePos, result_param, transformed_expr));
139 138
140 LoadLocalNode* load_result_param = new(Z) LoadLocalNode( 139 LoadLocalNode* load_result_param = new(Z) LoadLocalNode(
141 Scanner::kNoSourcePos, result_param); 140 Scanner::kNoSourcePos, result_param);
142 141
143 const Class& future_cls = 142 const Class& future_cls =
144 Class::ZoneHandle(I, I->object_store()->future_class()); 143 Class::ZoneHandle(Z, thread()->isolate()->object_store()->future_class());
Ivan Posva 2015/01/23 04:53:04 Was wondering whether it makes sense to keep I def
koda 2015/01/23 14:29:31 Acknowledged.
145 ASSERT(!future_cls.IsNull()); 144 ASSERT(!future_cls.IsNull());
146 const AbstractType& future_type = 145 const AbstractType& future_type =
147 AbstractType::ZoneHandle(I, future_cls.RareType()); 146 AbstractType::ZoneHandle(Z, future_cls.RareType());
148 ASSERT(!future_type.IsNull()); 147 ASSERT(!future_type.IsNull());
149 148
150 LocalScope* is_not_future_scope = ChainNewScope(preamble_->scope()); 149 LocalScope* is_not_future_scope = ChainNewScope(preamble_->scope());
151 SequenceNode* is_not_future_branch = 150 SequenceNode* is_not_future_branch =
152 new (Z) SequenceNode(Scanner::kNoSourcePos, is_not_future_scope); 151 new (Z) SequenceNode(Scanner::kNoSourcePos, is_not_future_scope);
153 152
154 // if (:result_param is !Future) { 153 // if (:result_param is !Future) {
155 // :result_param = Future.value(:result_param); 154 // :result_param = Future.value(:result_param);
156 // } 155 // }
157 const Function& value_ctor = Function::ZoneHandle( 156 const Function& value_ctor = Function::ZoneHandle(
158 I, future_cls.LookupFunction(Symbols::FutureValue())); 157 Z, future_cls.LookupFunction(Symbols::FutureValue()));
159 ASSERT(!value_ctor.IsNull()); 158 ASSERT(!value_ctor.IsNull());
160 ArgumentListNode* ctor_args = new (Z) ArgumentListNode(Scanner::kNoSourcePos); 159 ArgumentListNode* ctor_args = new (Z) ArgumentListNode(Scanner::kNoSourcePos);
161 ctor_args->Add(new (Z) LoadLocalNode(Scanner::kNoSourcePos, result_param)); 160 ctor_args->Add(new (Z) LoadLocalNode(Scanner::kNoSourcePos, result_param));
162 ConstructorCallNode* ctor_call = 161 ConstructorCallNode* ctor_call =
163 new (Z) ConstructorCallNode(Scanner::kNoSourcePos, 162 new (Z) ConstructorCallNode(Scanner::kNoSourcePos,
164 TypeArguments::ZoneHandle(I), 163 TypeArguments::ZoneHandle(Z),
165 value_ctor, 164 value_ctor,
166 ctor_args); 165 ctor_args);
167 is_not_future_branch->Add(new (Z) StoreLocalNode( 166 is_not_future_branch->Add(new (Z) StoreLocalNode(
168 Scanner::kNoSourcePos, result_param, ctor_call)); 167 Scanner::kNoSourcePos, result_param, ctor_call));
169 AstNode* is_not_future_test = new (Z) ComparisonNode( 168 AstNode* is_not_future_test = new (Z) ComparisonNode(
170 Scanner::kNoSourcePos, 169 Scanner::kNoSourcePos,
171 Token::kISNOT, 170 Token::kISNOT,
172 load_result_param, 171 load_result_param,
173 new (Z) TypeNode(Scanner::kNoSourcePos, future_type)); 172 new (Z) TypeNode(Scanner::kNoSourcePos, future_type));
174 preamble_->Add(new(Z) IfNode(Scanner::kNoSourcePos, 173 preamble_->Add(new(Z) IfNode(Scanner::kNoSourcePos,
175 is_not_future_test, 174 is_not_future_test,
176 is_not_future_branch, 175 is_not_future_branch,
177 NULL)); 176 NULL));
178 177
179 AwaitMarkerNode* await_marker = new (Z) AwaitMarkerNode(); 178 AwaitMarkerNode* await_marker = new (Z) AwaitMarkerNode();
180 await_marker->set_scope(preamble_->scope()); 179 await_marker->set_scope(preamble_->scope());
181 preamble_->Add(await_marker); 180 preamble_->Add(await_marker);
182 ArgumentListNode* args = new(Z) ArgumentListNode(Scanner::kNoSourcePos); 181 ArgumentListNode* args = new(Z) ArgumentListNode(Scanner::kNoSourcePos);
183 182
184 args->Add(new(Z) LoadLocalNode(Scanner::kNoSourcePos, async_op)); 183 args->Add(new(Z) LoadLocalNode(Scanner::kNoSourcePos, async_op));
185 preamble_->Add(new (Z) StoreLocalNode( 184 preamble_->Add(new (Z) StoreLocalNode(
186 Scanner::kNoSourcePos, 185 Scanner::kNoSourcePos,
187 result_param, 186 result_param,
188 new(Z) InstanceCallNode(Scanner::kNoSourcePos, 187 new(Z) InstanceCallNode(Scanner::kNoSourcePos,
189 load_result_param, 188 load_result_param,
190 Symbols::FutureThen(), 189 Symbols::FutureThen(),
191 args))); 190 args)));
192 const Library& core_lib = Library::Handle(Library::CoreLibrary()); 191 const Library& core_lib = Library::Handle(Library::CoreLibrary());
193 const Function& async_catch_helper = Function::ZoneHandle( 192 const Function& async_catch_helper = Function::ZoneHandle(
194 I, core_lib.LookupFunctionAllowPrivate(Symbols::AsyncCatchHelper())); 193 Z, core_lib.LookupFunctionAllowPrivate(Symbols::AsyncCatchHelper()));
195 ASSERT(!async_catch_helper.IsNull()); 194 ASSERT(!async_catch_helper.IsNull());
196 ArgumentListNode* catch_helper_args = new (Z) ArgumentListNode( 195 ArgumentListNode* catch_helper_args = new (Z) ArgumentListNode(
197 Scanner::kNoSourcePos); 196 Scanner::kNoSourcePos);
198 InstanceGetterNode* catch_error_getter = new (Z) InstanceGetterNode( 197 InstanceGetterNode* catch_error_getter = new (Z) InstanceGetterNode(
199 Scanner::kNoSourcePos, 198 Scanner::kNoSourcePos,
200 load_result_param, 199 load_result_param,
201 Symbols::FutureCatchError()); 200 Symbols::FutureCatchError());
202 catch_helper_args->Add(catch_error_getter); 201 catch_helper_args->Add(catch_error_getter);
203 catch_helper_args->Add(new (Z) LoadLocalNode( 202 catch_helper_args->Add(new (Z) LoadLocalNode(
204 Scanner::kNoSourcePos, async_op)); 203 Scanner::kNoSourcePos, async_op));
205 preamble_->Add(new (Z) StaticCallNode( 204 preamble_->Add(new (Z) StaticCallNode(
206 Scanner::kNoSourcePos, 205 Scanner::kNoSourcePos,
207 async_catch_helper, 206 async_catch_helper,
208 catch_helper_args)); 207 catch_helper_args));
209 ReturnNode* continuation_return = new(Z) ReturnNode(Scanner::kNoSourcePos); 208 ReturnNode* continuation_return = new(Z) ReturnNode(Scanner::kNoSourcePos);
210 continuation_return->set_return_type(ReturnNode::kContinuationTarget); 209 continuation_return->set_return_type(ReturnNode::kContinuationTarget);
211 preamble_->Add(continuation_return); 210 preamble_->Add(continuation_return);
212 211
213 // If this expression is part of a try block, also append the code for 212 // If this expression is part of a try block, also append the code for
214 // restoring the saved try context that lives on the stack. 213 // restoring the saved try context that lives on the stack.
215 const String& async_saved_try_ctx_name = 214 const String& async_saved_try_ctx_name =
216 String::Handle(I, parsed_function_->async_saved_try_ctx_name()); 215 String::Handle(Z, parsed_function_->async_saved_try_ctx_name());
217 if (!async_saved_try_ctx_name.IsNull()) { 216 if (!async_saved_try_ctx_name.IsNull()) {
218 LocalVariable* async_saved_try_ctx = 217 LocalVariable* async_saved_try_ctx =
219 GetVariableInScope(preamble_->scope(), async_saved_try_ctx_name); 218 GetVariableInScope(preamble_->scope(), async_saved_try_ctx_name);
220 preamble_->Add(new (Z) StoreLocalNode( 219 preamble_->Add(new (Z) StoreLocalNode(
221 Scanner::kNoSourcePos, 220 Scanner::kNoSourcePos,
222 parsed_function_->saved_try_ctx(), 221 parsed_function_->saved_try_ctx(),
223 new (Z) LoadLocalNode(Scanner::kNoSourcePos, async_saved_try_ctx))); 222 new (Z) LoadLocalNode(Scanner::kNoSourcePos, async_saved_try_ctx)));
224 } 223 }
225 224
226 LoadLocalNode* load_error_param = new (Z) LoadLocalNode( 225 LoadLocalNode* load_error_param = new (Z) LoadLocalNode(
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 void AwaitTransformer::VisitThrowNode(ThrowNode* node) { 595 void AwaitTransformer::VisitThrowNode(ThrowNode* node) {
597 // TODO(mlippautz): Check if relevant. 596 // TODO(mlippautz): Check if relevant.
598 AstNode* new_exception = Transform(node->exception()); 597 AstNode* new_exception = Transform(node->exception());
599 AstNode* new_stacktrace = Transform(node->stacktrace()); 598 AstNode* new_stacktrace = Transform(node->stacktrace());
600 result_ = new(Z) ThrowNode(node->token_pos(), 599 result_ = new(Z) ThrowNode(node->token_pos(),
601 new_exception, 600 new_exception,
602 new_stacktrace); 601 new_stacktrace);
603 } 602 }
604 603
605 } // namespace dart 604 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/bit_vector.h » ('j') | runtime/vm/constant_propagator.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698