| 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 "platform/utils.h" | 8 #include "platform/utils.h" |
| 9 #include "vm/ast_transformer.h" | 9 #include "vm/ast_transformer.h" |
| 10 #include "vm/bootstrap.h" | 10 #include "vm/bootstrap.h" |
| (...skipping 1414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1425 ASSERT(desc.Count() > 0); | 1425 ASSERT(desc.Count() > 0); |
| 1426 | 1426 |
| 1427 // Set up scope for this function. | 1427 // Set up scope for this function. |
| 1428 BuildDispatcherScope(func, desc, default_values); | 1428 BuildDispatcherScope(func, desc, default_values); |
| 1429 | 1429 |
| 1430 // Receiver is local 0. | 1430 // Receiver is local 0. |
| 1431 LocalScope* scope = current_block_->scope; | 1431 LocalScope* scope = current_block_->scope; |
| 1432 ArgumentListNode* no_args = new ArgumentListNode(token_pos); | 1432 ArgumentListNode* no_args = new ArgumentListNode(token_pos); |
| 1433 LoadLocalNode* receiver = new LoadLocalNode(token_pos, scope->VariableAt(0)); | 1433 LoadLocalNode* receiver = new LoadLocalNode(token_pos, scope->VariableAt(0)); |
| 1434 | 1434 |
| 1435 const Class& function_impl = Class::Handle(Type::Handle( |
| 1436 Isolate::Current()->object_store()->function_impl_type()).type_class()); |
| 1437 |
| 1435 const Class& owner = Class::Handle(Z, func.Owner()); | 1438 const Class& owner = Class::Handle(Z, func.Owner()); |
| 1436 ASSERT(!owner.IsNull()); | 1439 ASSERT(!owner.IsNull()); |
| 1437 const String& name = String::Handle(Z, func.name()); | 1440 const String& name = String::Handle(Z, func.name()); |
| 1438 AstNode* function_object = NULL; | 1441 AstNode* function_object = NULL; |
| 1439 if (owner.IsSignatureClass() && name.Equals(Symbols::Call())) { | 1442 if (owner.raw() == function_impl.raw() && name.Equals(Symbols::Call())) { |
| 1440 function_object = receiver; | 1443 function_object = receiver; |
| 1441 } else { | 1444 } else { |
| 1442 const String& getter_name = String::ZoneHandle(Z, | 1445 const String& getter_name = String::ZoneHandle(Z, |
| 1443 Symbols::New(String::Handle(Z, Field::GetterName(name)))); | 1446 Symbols::New(String::Handle(Z, Field::GetterName(name)))); |
| 1444 function_object = new(Z) InstanceCallNode( | 1447 function_object = new(Z) InstanceCallNode( |
| 1445 token_pos, receiver, getter_name, no_args); | 1448 token_pos, receiver, getter_name, no_args); |
| 1446 } | 1449 } |
| 1447 | 1450 |
| 1448 // Pass arguments 1..n to the closure call. | 1451 // Pass arguments 1..n to the closure call. |
| 1449 ArgumentListNode* args = new(Z) ArgumentListNode(token_pos); | 1452 ArgumentListNode* args = new(Z) ArgumentListNode(token_pos); |
| 1450 const Array& names = Array::Handle( | 1453 const Array& names = Array::Handle( |
| 1451 Z, Array::New(desc.NamedCount(), Heap::kOld)); | 1454 Z, Array::New(desc.NamedCount(), Heap::kOld)); |
| 1452 // Positional parameters. | 1455 // Positional parameters. |
| 1453 intptr_t i = 1; | 1456 intptr_t i = 1; |
| 1454 for (; i < desc.PositionalCount(); ++i) { | 1457 for (; i < desc.PositionalCount(); ++i) { |
| 1455 args->Add(new LoadLocalNode(token_pos, scope->VariableAt(i))); | 1458 args->Add(new LoadLocalNode(token_pos, scope->VariableAt(i))); |
| 1456 } | 1459 } |
| 1457 // Named parameters. | 1460 // Named parameters. |
| 1458 for (; i < desc.Count(); i++) { | 1461 for (; i < desc.Count(); i++) { |
| 1459 args->Add(new(Z) LoadLocalNode(token_pos, scope->VariableAt(i))); | 1462 args->Add(new(Z) LoadLocalNode(token_pos, scope->VariableAt(i))); |
| 1460 intptr_t index = i - desc.PositionalCount(); | 1463 intptr_t index = i - desc.PositionalCount(); |
| 1461 names.SetAt(index, String::Handle(Z, desc.NameAt(index))); | 1464 names.SetAt(index, String::Handle(Z, desc.NameAt(index))); |
| 1462 } | 1465 } |
| 1463 args->set_names(names); | 1466 args->set_names(names); |
| 1464 | 1467 |
| 1465 AstNode* result = NULL; | 1468 AstNode* result = NULL; |
| 1466 if (owner.IsSignatureClass() && name.Equals(Symbols::Call())) { | 1469 if (owner.raw() == function_impl.raw() && name.Equals(Symbols::Call())) { |
| 1467 result = new ClosureCallNode(token_pos, function_object, args); | 1470 result = new ClosureCallNode(token_pos, function_object, args); |
| 1468 } else { | 1471 } else { |
| 1469 result = BuildClosureCall(token_pos, function_object, args); | 1472 result = BuildClosureCall(token_pos, function_object, args); |
| 1470 } | 1473 } |
| 1471 | 1474 |
| 1472 ReturnNode* return_node = new ReturnNode(token_pos, result); | 1475 ReturnNode* return_node = new ReturnNode(token_pos, result); |
| 1473 current_block_->statements->Add(return_node); | 1476 current_block_->statements->Add(return_node); |
| 1474 return CloseBlock(); | 1477 return CloseBlock(); |
| 1475 } | 1478 } |
| 1476 | 1479 |
| (...skipping 10752 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12229 void Parser::SkipQualIdent() { | 12232 void Parser::SkipQualIdent() { |
| 12230 ASSERT(IsIdentifier()); | 12233 ASSERT(IsIdentifier()); |
| 12231 ConsumeToken(); | 12234 ConsumeToken(); |
| 12232 if (CurrentToken() == Token::kPERIOD) { | 12235 if (CurrentToken() == Token::kPERIOD) { |
| 12233 ConsumeToken(); // Consume the kPERIOD token. | 12236 ConsumeToken(); // Consume the kPERIOD token. |
| 12234 ExpectIdentifier("identifier expected after '.'"); | 12237 ExpectIdentifier("identifier expected after '.'"); |
| 12235 } | 12238 } |
| 12236 } | 12239 } |
| 12237 | 12240 |
| 12238 } // namespace dart | 12241 } // namespace dart |
| OLD | NEW |