Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #include "vm/parser.h" | 5 #include "vm/parser.h" |
| 6 | 6 |
| 7 #include "vm/bigint_operations.h" | 7 #include "vm/bigint_operations.h" |
| 8 #include "vm/class_finalizer.h" | 8 #include "vm/class_finalizer.h" |
| 9 #include "vm/compiler.h" | 9 #include "vm/compiler.h" |
| 10 #include "vm/compiler_stats.h" | 10 #include "vm/compiler_stats.h" |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 247 Parser::Parser(const Script& script, | 247 Parser::Parser(const Script& script, |
| 248 const Library& library) | 248 const Library& library) |
| 249 : script_(script), | 249 : script_(script), |
| 250 tokens_(TokenStream::Handle(script.tokens())), | 250 tokens_(TokenStream::Handle(script.tokens())), |
| 251 token_index_(0), | 251 token_index_(0), |
| 252 current_block_(NULL), | 252 current_block_(NULL), |
| 253 is_top_level_(false), | 253 is_top_level_(false), |
| 254 current_member_(NULL), | 254 current_member_(NULL), |
| 255 allow_function_literals_(true), | 255 allow_function_literals_(true), |
| 256 current_function_(Function::Handle()), | 256 current_function_(Function::Handle()), |
| 257 innermost_function_(Function::Handle()), | |
| 257 current_class_(Class::Handle()), | 258 current_class_(Class::Handle()), |
| 258 library_(library), | 259 library_(library), |
| 259 try_blocks_list_(NULL), | 260 try_blocks_list_(NULL), |
| 260 expression_temp_(NULL) { | 261 expression_temp_(NULL) { |
| 261 ASSERT(!tokens_.IsNull()); | 262 ASSERT(!tokens_.IsNull()); |
| 262 ASSERT(!library.IsNull()); | 263 ASSERT(!library.IsNull()); |
| 263 SetPosition(0); | 264 SetPosition(0); |
| 264 } | 265 } |
| 265 | 266 |
| 266 | 267 |
| 267 // For parsing a function. | 268 // For parsing a function. |
| 268 Parser::Parser(const Script& script, | 269 Parser::Parser(const Script& script, |
| 269 const Function& function, | 270 const Function& function, |
| 270 intptr_t token_index) | 271 intptr_t token_index) |
| 271 : script_(script), | 272 : script_(script), |
| 272 tokens_(TokenStream::Handle(script.tokens())), | 273 tokens_(TokenStream::Handle(script.tokens())), |
| 273 token_index_(0), | 274 token_index_(0), |
| 274 current_block_(NULL), | 275 current_block_(NULL), |
| 275 is_top_level_(false), | 276 is_top_level_(false), |
| 276 current_member_(NULL), | 277 current_member_(NULL), |
| 277 allow_function_literals_(true), | 278 allow_function_literals_(true), |
| 278 current_function_(function), | 279 current_function_(function), |
| 280 innermost_function_(Function::Handle(function.raw())), | |
| 279 current_class_(Class::Handle(current_function_.owner())), | 281 current_class_(Class::Handle(current_function_.owner())), |
| 280 library_(Library::Handle(current_class_.library())), | 282 library_(Library::Handle(current_class_.library())), |
| 281 try_blocks_list_(NULL), | 283 try_blocks_list_(NULL), |
| 282 expression_temp_(NULL) { | 284 expression_temp_(NULL) { |
| 283 ASSERT(!tokens_.IsNull()); | 285 ASSERT(!tokens_.IsNull()); |
| 284 ASSERT(!function.IsNull()); | 286 ASSERT(!function.IsNull()); |
| 285 SetPosition(token_index); | 287 SetPosition(token_index); |
| 286 if (FLAG_enable_type_checks) { | 288 if (FLAG_enable_type_checks) { |
| 287 EnsureExpressionTemp(); | 289 EnsureExpressionTemp(); |
| 288 } | 290 } |
| 289 } | 291 } |
| 290 | 292 |
| 291 | 293 |
| 292 bool Parser::SetAllowFunctionLiterals(bool value) { | 294 bool Parser::SetAllowFunctionLiterals(bool value) { |
| 293 bool current_value = allow_function_literals_; | 295 bool current_value = allow_function_literals_; |
| 294 allow_function_literals_ = value; | 296 allow_function_literals_ = value; |
| 295 return current_value; | 297 return current_value; |
| 296 } | 298 } |
| 297 | 299 |
| 298 | 300 |
| 299 const Function& Parser::current_function() const { | 301 const Function& Parser::current_function() const { |
| 300 return current_function_; | 302 return current_function_; |
| 301 } | 303 } |
| 302 | 304 |
| 303 | 305 |
| 306 const Function& Parser::innermost_function() const { | |
| 307 return innermost_function_; | |
| 308 } | |
| 309 | |
| 310 | |
| 304 const Class& Parser::current_class() const { | 311 const Class& Parser::current_class() const { |
| 305 return current_class_; | 312 return current_class_; |
| 306 } | 313 } |
| 307 | 314 |
| 308 | 315 |
| 309 void Parser::set_current_class(const Class& value) { | 316 void Parser::set_current_class(const Class& value) { |
| 310 current_class_ = value.raw(); | 317 current_class_ = value.raw(); |
| 311 } | 318 } |
| 312 | 319 |
| 313 | 320 |
| (...skipping 1754 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2068 return statements; | 2075 return statements; |
| 2069 } | 2076 } |
| 2070 | 2077 |
| 2071 | 2078 |
| 2072 // Parser is at the opening parenthesis of the formal parameter | 2079 // Parser is at the opening parenthesis of the formal parameter |
| 2073 // declaration of the function or constructor. | 2080 // declaration of the function or constructor. |
| 2074 // Parse the formal parameters and code. | 2081 // Parse the formal parameters and code. |
| 2075 SequenceNode* Parser::ParseFunc(const Function& func, | 2082 SequenceNode* Parser::ParseFunc(const Function& func, |
| 2076 Array& default_parameter_values) { | 2083 Array& default_parameter_values) { |
| 2077 TRACE_PARSER("ParseFunc"); | 2084 TRACE_PARSER("ParseFunc"); |
| 2085 innermost_function_ = func.raw(); | |
|
regis
2012/06/22 23:58:32
You should assert that func.parent() == innermost_
hausner
2012/06/23 00:15:04
Good catch!
Actually, I initialize innermost_func
| |
| 2086 | |
| 2078 if (func.IsConstructor()) { | 2087 if (func.IsConstructor()) { |
| 2079 return ParseConstructor(func, default_parameter_values); | 2088 return ParseConstructor(func, default_parameter_values); |
| 2080 } | 2089 } |
| 2081 | 2090 |
| 2082 ASSERT(!func.IsConstructor()); | 2091 ASSERT(!func.IsConstructor()); |
| 2083 OpenFunctionBlock(func); // Build local scope for function. | 2092 OpenFunctionBlock(func); // Build local scope for function. |
| 2084 | 2093 |
| 2085 ParamList params; | 2094 ParamList params; |
| 2086 // Static functions do not have a receiver. | 2095 // Static functions do not have a receiver. |
| 2087 // An instance closure may capture and access the receiver, but via the | 2096 // An instance closure may capture and access the receiver, but via the |
| (...skipping 2102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4190 // and register it in the current class. | 4199 // and register it in the current class. |
| 4191 // Note that we cannot share the same closure function between the closurized | 4200 // Note that we cannot share the same closure function between the closurized |
| 4192 // and non-closurized versions of the same parent function. | 4201 // and non-closurized versions of the same parent function. |
| 4193 Function& function = Function::ZoneHandle(); | 4202 Function& function = Function::ZoneHandle(); |
| 4194 bool is_new_closure = false; | 4203 bool is_new_closure = false; |
| 4195 // TODO(hausner): There could be two different closures at the given | 4204 // TODO(hausner): There could be two different closures at the given |
| 4196 // function_pos, one enclosed in a closurized function and one enclosed in the | 4205 // function_pos, one enclosed in a closurized function and one enclosed in the |
| 4197 // non-closurized version of this same function. | 4206 // non-closurized version of this same function. |
| 4198 function = current_class().LookupClosureFunction(function_pos); | 4207 function = current_class().LookupClosureFunction(function_pos); |
| 4199 if (function.IsNull() || (function.token_index() != function_pos) || | 4208 if (function.IsNull() || (function.token_index() != function_pos) || |
| 4200 (function.parent_function() != current_function().raw())) { | 4209 (function.parent_function() != innermost_function().raw())) { |
| 4201 is_new_closure = true; | 4210 is_new_closure = true; |
| 4202 function = Function::NewClosureFunction(*function_name, | 4211 function = Function::NewClosureFunction(*function_name, |
| 4203 current_function(), | 4212 innermost_function(), |
| 4204 function_pos); | 4213 function_pos); |
| 4205 function.set_result_type(result_type); | 4214 function.set_result_type(result_type); |
| 4206 current_class().AddClosureFunction(function); | 4215 current_class().AddClosureFunction(function); |
| 4207 } | 4216 } |
| 4208 | 4217 |
| 4209 // The function type does not need to be determined at compile time, unless | 4218 // The function type does not need to be determined at compile time, unless |
| 4210 // the closure is assigned to a function variable and type checks are enabled. | 4219 // the closure is assigned to a function variable and type checks are enabled. |
| 4211 // At run time, the function type is derived from the signature class of the | 4220 // At run time, the function type is derived from the signature class of the |
| 4212 // closure function and from the type arguments of the instantiator. | 4221 // closure function and from the type arguments of the instantiator. |
| 4213 | 4222 |
| (...skipping 1165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5379 | 5388 |
| 5380 // Add this individual catch handler to the catch handlers list. | 5389 // Add this individual catch handler to the catch handlers list. |
| 5381 current_block_->statements->Add(catch_clause); | 5390 current_block_->statements->Add(catch_clause); |
| 5382 } | 5391 } |
| 5383 catch_handler_list = CloseBlock(); | 5392 catch_handler_list = CloseBlock(); |
| 5384 TryBlocks* inner_try_block = PopTryBlock(); | 5393 TryBlocks* inner_try_block = PopTryBlock(); |
| 5385 | 5394 |
| 5386 // Finally parse the 'finally' block. | 5395 // Finally parse the 'finally' block. |
| 5387 SequenceNode* finally_block = NULL; | 5396 SequenceNode* finally_block = NULL; |
| 5388 if (CurrentToken() == Token::kFINALLY) { | 5397 if (CurrentToken() == Token::kFINALLY) { |
| 5389 current_function_.set_is_optimizable(false); | 5398 current_function().set_is_optimizable(false); |
| 5390 ConsumeToken(); // Consume the 'finally'. | 5399 ConsumeToken(); // Consume the 'finally'. |
| 5391 const intptr_t finally_pos = token_index_; | 5400 const intptr_t finally_pos = token_index_; |
| 5392 // Add the finally block to the exit points recorded so far. | 5401 // Add the finally block to the exit points recorded so far. |
| 5393 intptr_t node_index = 0; | 5402 intptr_t node_index = 0; |
| 5394 AstNode* node_to_inline = | 5403 AstNode* node_to_inline = |
| 5395 inner_try_block->GetNodeToInlineFinally(node_index); | 5404 inner_try_block->GetNodeToInlineFinally(node_index); |
| 5396 while (node_to_inline != NULL) { | 5405 while (node_to_inline != NULL) { |
| 5397 finally_block = ParseFinallyBlock(); | 5406 finally_block = ParseFinallyBlock(); |
| 5398 InlinedFinallyNode* node = new InlinedFinallyNode(finally_pos, | 5407 InlinedFinallyNode* node = new InlinedFinallyNode(finally_pos, |
| 5399 finally_block, | 5408 finally_block, |
| (...skipping 3187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8587 void Parser::SkipQualIdent() { | 8596 void Parser::SkipQualIdent() { |
| 8588 ASSERT(IsIdentifier()); | 8597 ASSERT(IsIdentifier()); |
| 8589 ConsumeToken(); | 8598 ConsumeToken(); |
| 8590 if (CurrentToken() == Token::kPERIOD) { | 8599 if (CurrentToken() == Token::kPERIOD) { |
| 8591 ConsumeToken(); // Consume the kPERIOD token. | 8600 ConsumeToken(); // Consume the kPERIOD token. |
| 8592 ExpectIdentifier("identifier expected after '.'"); | 8601 ExpectIdentifier("identifier expected after '.'"); |
| 8593 } | 8602 } |
| 8594 } | 8603 } |
| 8595 | 8604 |
| 8596 } // namespace dart | 8605 } // namespace dart |
| OLD | NEW |