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 "lib/invocation_mirror.h" | 7 #include "lib/invocation_mirror.h" |
8 #include "vm/bigint_operations.h" | 8 #include "vm/bigint_operations.h" |
9 #include "vm/bootstrap.h" | 9 #include "vm/bootstrap.h" |
10 #include "vm/class_finalizer.h" | 10 #include "vm/class_finalizer.h" |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 current_block_(NULL), | 248 current_block_(NULL), |
249 is_top_level_(false), | 249 is_top_level_(false), |
250 current_member_(NULL), | 250 current_member_(NULL), |
251 allow_function_literals_(true), | 251 allow_function_literals_(true), |
252 parsed_function_(NULL), | 252 parsed_function_(NULL), |
253 innermost_function_(Function::Handle(isolate_)), | 253 innermost_function_(Function::Handle(isolate_)), |
254 literal_token_(LiteralToken::Handle(isolate_)), | 254 literal_token_(LiteralToken::Handle(isolate_)), |
255 current_class_(Class::Handle(isolate_)), | 255 current_class_(Class::Handle(isolate_)), |
256 library_(Library::Handle(isolate_, library.raw())), | 256 library_(Library::Handle(isolate_, library.raw())), |
257 try_blocks_list_(NULL), | 257 try_blocks_list_(NULL), |
258 last_used_try_index_(CatchClauseNode::kInvalidTryIndex) { | 258 last_used_try_index_(CatchClauseNode::kInvalidTryIndex), |
| 259 unregister_pending_function_(false) { |
259 ASSERT(tokens_iterator_.IsValid()); | 260 ASSERT(tokens_iterator_.IsValid()); |
260 ASSERT(!library.IsNull()); | 261 ASSERT(!library.IsNull()); |
261 } | 262 } |
262 | 263 |
263 | 264 |
264 // For parsing a function. | 265 // For parsing a function. |
265 Parser::Parser(const Script& script, | 266 Parser::Parser(const Script& script, |
266 ParsedFunction* parsed_function, | 267 ParsedFunction* parsed_function, |
267 intptr_t token_position) | 268 intptr_t token_position) |
268 : isolate_(Isolate::Current()), | 269 : isolate_(Isolate::Current()), |
269 script_(Script::Handle(isolate_, script.raw())), | 270 script_(Script::Handle(isolate_, script.raw())), |
270 tokens_iterator_(TokenStream::Handle(isolate_, script.tokens()), | 271 tokens_iterator_(TokenStream::Handle(isolate_, script.tokens()), |
271 token_position), | 272 token_position), |
272 token_kind_(Token::kILLEGAL), | 273 token_kind_(Token::kILLEGAL), |
273 current_block_(NULL), | 274 current_block_(NULL), |
274 is_top_level_(false), | 275 is_top_level_(false), |
275 current_member_(NULL), | 276 current_member_(NULL), |
276 allow_function_literals_(true), | 277 allow_function_literals_(true), |
277 parsed_function_(parsed_function), | 278 parsed_function_(parsed_function), |
278 innermost_function_(Function::Handle(isolate_, | 279 innermost_function_(Function::Handle(isolate_, |
279 parsed_function->function().raw())), | 280 parsed_function->function().raw())), |
280 literal_token_(LiteralToken::Handle(isolate_)), | 281 literal_token_(LiteralToken::Handle(isolate_)), |
281 current_class_(Class::Handle(isolate_, | 282 current_class_(Class::Handle(isolate_, |
282 parsed_function->function().Owner())), | 283 parsed_function->function().Owner())), |
283 library_(Library::Handle(Class::Handle( | 284 library_(Library::Handle(Class::Handle( |
284 isolate_, | 285 isolate_, |
285 parsed_function->function().origin()).library())), | 286 parsed_function->function().origin()).library())), |
286 try_blocks_list_(NULL), | 287 try_blocks_list_(NULL), |
287 last_used_try_index_(CatchClauseNode::kInvalidTryIndex) { | 288 last_used_try_index_(CatchClauseNode::kInvalidTryIndex), |
| 289 unregister_pending_function_(false) { |
288 ASSERT(tokens_iterator_.IsValid()); | 290 ASSERT(tokens_iterator_.IsValid()); |
289 ASSERT(!current_function().IsNull()); | 291 ASSERT(!current_function().IsNull()); |
290 if (FLAG_enable_type_checks) { | 292 if (FLAG_enable_type_checks) { |
291 EnsureExpressionTemp(); | 293 EnsureExpressionTemp(); |
292 } | 294 } |
293 } | 295 } |
294 | 296 |
295 | 297 |
| 298 Parser::~Parser() { |
| 299 if (unregister_pending_function_) { |
| 300 const GrowableObjectArray& pending_functions = |
| 301 GrowableObjectArray::Handle( |
| 302 isolate()->object_store()->pending_functions()); |
| 303 ASSERT(pending_functions.Length() > 0); |
| 304 ASSERT(pending_functions.At(pending_functions.Length()-1) == |
| 305 current_function().raw()); |
| 306 pending_functions.RemoveLast(); |
| 307 } |
| 308 } |
| 309 |
| 310 |
296 void Parser::SetScript(const Script & script, intptr_t token_pos) { | 311 void Parser::SetScript(const Script & script, intptr_t token_pos) { |
297 script_ = script.raw(); | 312 script_ = script.raw(); |
298 tokens_iterator_.SetStream(TokenStream::Handle(script.tokens()), token_pos); | 313 tokens_iterator_.SetStream(TokenStream::Handle(script.tokens()), token_pos); |
299 token_kind_ = Token::kILLEGAL; | 314 token_kind_ = Token::kILLEGAL; |
300 } | 315 } |
301 | 316 |
302 | 317 |
303 bool Parser::SetAllowFunctionLiterals(bool value) { | 318 bool Parser::SetAllowFunctionLiterals(bool value) { |
304 bool current_value = allow_function_literals_; | 319 bool current_value = allow_function_literals_; |
305 allow_function_literals_ = value; | 320 allow_function_literals_ = value; |
(...skipping 2047 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2353 // Helper function to make the first num_variables variables in the | 2368 // Helper function to make the first num_variables variables in the |
2354 // given scope visible/invisible. | 2369 // given scope visible/invisible. |
2355 static void SetInvisible(LocalScope* scope, int num_variables, bool invisible) { | 2370 static void SetInvisible(LocalScope* scope, int num_variables, bool invisible) { |
2356 ASSERT(num_variables <= scope->num_variables()); | 2371 ASSERT(num_variables <= scope->num_variables()); |
2357 for (int i = 0; i < num_variables; i++) { | 2372 for (int i = 0; i < num_variables; i++) { |
2358 scope->VariableAt(i)->set_invisible(invisible); | 2373 scope->VariableAt(i)->set_invisible(invisible); |
2359 } | 2374 } |
2360 } | 2375 } |
2361 | 2376 |
2362 | 2377 |
| 2378 void Parser::CheckRecursiveInvocation() { |
| 2379 const GrowableObjectArray& pending_functions = |
| 2380 GrowableObjectArray::Handle( |
| 2381 isolate()->object_store()->pending_functions()); |
| 2382 for (int i = 0; i < pending_functions.Length(); i++) { |
| 2383 if (pending_functions.At(i) == current_function().raw()) { |
| 2384 const String& fname = |
| 2385 String::Handle(current_function().UserVisibleName()); |
| 2386 ErrorMsg("circular dependency for function %s", fname.ToCString()); |
| 2387 } |
| 2388 } |
| 2389 ASSERT(!unregister_pending_function_); |
| 2390 pending_functions.Add(current_function()); |
| 2391 unregister_pending_function_ = true; |
| 2392 } |
| 2393 |
| 2394 |
2363 // Parser is at the opening parenthesis of the formal parameter declaration | 2395 // Parser is at the opening parenthesis of the formal parameter declaration |
2364 // of function. Parse the formal parameters, initializers and code. | 2396 // of function. Parse the formal parameters, initializers and code. |
2365 SequenceNode* Parser::ParseConstructor(const Function& func, | 2397 SequenceNode* Parser::ParseConstructor(const Function& func, |
2366 Array& default_parameter_values) { | 2398 Array& default_parameter_values) { |
2367 TRACE_PARSER("ParseConstructor"); | 2399 TRACE_PARSER("ParseConstructor"); |
2368 ASSERT(func.IsConstructor()); | 2400 ASSERT(func.IsConstructor()); |
2369 ASSERT(!func.IsFactory()); | 2401 ASSERT(!func.IsFactory()); |
2370 ASSERT(!func.is_static()); | 2402 ASSERT(!func.is_static()); |
2371 ASSERT(!func.IsLocalFunction()); | 2403 ASSERT(!func.IsLocalFunction()); |
2372 const Class& cls = Class::Handle(func.Owner()); | 2404 const Class& cls = Class::Handle(func.Owner()); |
2373 ASSERT(!cls.IsNull()); | 2405 ASSERT(!cls.IsNull()); |
2374 | 2406 |
| 2407 CheckRecursiveInvocation(); |
| 2408 |
2375 if (func.IsImplicitConstructor()) { | 2409 if (func.IsImplicitConstructor()) { |
2376 // Special case: implicit constructor. | 2410 // Special case: implicit constructor. |
2377 // The parser adds an implicit default constructor when a class | 2411 // The parser adds an implicit default constructor when a class |
2378 // does not have any explicit constructor or factory (see | 2412 // does not have any explicit constructor or factory (see |
2379 // Parser::AddImplicitConstructor). | 2413 // Parser::AddImplicitConstructor). |
2380 // There is no source text to parse. We just build the | 2414 // There is no source text to parse. We just build the |
2381 // sequence node by hand. | 2415 // sequence node by hand. |
2382 return MakeImplicitConstructor(func); | 2416 return MakeImplicitConstructor(func); |
2383 } | 2417 } |
2384 | 2418 |
(...skipping 7944 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10329 void Parser::SkipQualIdent() { | 10363 void Parser::SkipQualIdent() { |
10330 ASSERT(IsIdentifier()); | 10364 ASSERT(IsIdentifier()); |
10331 ConsumeToken(); | 10365 ConsumeToken(); |
10332 if (CurrentToken() == Token::kPERIOD) { | 10366 if (CurrentToken() == Token::kPERIOD) { |
10333 ConsumeToken(); // Consume the kPERIOD token. | 10367 ConsumeToken(); // Consume the kPERIOD token. |
10334 ExpectIdentifier("identifier expected after '.'"); | 10368 ExpectIdentifier("identifier expected after '.'"); |
10335 } | 10369 } |
10336 } | 10370 } |
10337 | 10371 |
10338 } // namespace dart | 10372 } // namespace dart |
OLD | NEW |