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

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

Issue 23038010: Fix Function.end_token_pos() and implement MethodMirror.source getter (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 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 | Annotate | Revision Log
OLDNEW
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 2680 matching lines...) Expand 10 before | Expand all | Expand 10 after
2691 // instantiate types. 2691 // instantiate types.
2692 CaptureInstantiator(); 2692 CaptureInstantiator();
2693 } 2693 }
2694 } 2694 }
2695 2695
2696 OpenBlock(); // Open a nested scope for the outermost function block. 2696 OpenBlock(); // Open a nested scope for the outermost function block.
2697 if (CurrentToken() == Token::kLBRACE) { 2697 if (CurrentToken() == Token::kLBRACE) {
2698 ConsumeToken(); 2698 ConsumeToken();
2699 ParseStatementSequence(); 2699 ParseStatementSequence();
2700 ExpectToken(Token::kRBRACE); 2700 ExpectToken(Token::kRBRACE);
2701 func.set_end_token_pos(TokenPos() - 1);
hausner 2013/08/20 17:49:44 Read the closing brace after setting the end token
Michael Lippautz (Google) 2013/08/21 16:50:03 Done.
2701 } else if (CurrentToken() == Token::kARROW) { 2702 } else if (CurrentToken() == Token::kARROW) {
2702 ConsumeToken(); 2703 ConsumeToken();
2703 const intptr_t expr_pos = TokenPos(); 2704 const intptr_t expr_pos = TokenPos();
2704 AstNode* expr = ParseExpr(kAllowConst, kConsumeCascades); 2705 AstNode* expr = ParseExpr(kAllowConst, kConsumeCascades);
2705 ASSERT(expr != NULL); 2706 ASSERT(expr != NULL);
2706 current_block_->statements->Add(new ReturnNode(expr_pos, expr)); 2707 current_block_->statements->Add(new ReturnNode(expr_pos, expr));
2708 func.set_end_token_pos(TokenPos());
2707 } else if (IsLiteral("native")) { 2709 } else if (IsLiteral("native")) {
2708 ParseNativeFunctionBlock(&params, func); 2710 ParseNativeFunctionBlock(&params, func);
hausner 2013/08/20 17:49:44 Can you refactor the code so that ParseNativeFunct
Michael Lippautz (Google) 2013/08/21 16:50:03 Done.
2711 func.set_end_token_pos(TokenPos() - 1);
2709 } else if (func.is_external()) { 2712 } else if (func.is_external()) {
2710 // Body of an external method contains a single throw. 2713 // Body of an external method contains a single throw.
2711 const String& function_name = String::ZoneHandle(func.name()); 2714 const String& function_name = String::ZoneHandle(func.name());
2712 // TODO(regis): For an instance function, pass the receiver to 2715 // TODO(regis): For an instance function, pass the receiver to
2713 // NoSuchMethodError. 2716 // NoSuchMethodError.
2714 current_block_->statements->Add( 2717 current_block_->statements->Add(
2715 ThrowNoSuchMethodError(TokenPos(), 2718 ThrowNoSuchMethodError(TokenPos(),
2716 current_class(), 2719 current_class(),
2717 function_name, 2720 function_name,
2718 func.is_static() ? 2721 func.is_static() ?
2719 InvocationMirror::kStatic : 2722 InvocationMirror::kStatic :
2720 InvocationMirror::kDynamic, 2723 InvocationMirror::kDynamic,
2721 InvocationMirror::kMethod)); 2724 InvocationMirror::kMethod));
hausner 2013/08/20 17:49:44 For completeness, you should also set the end toke
Michael Lippautz (Google) 2013/08/21 16:50:03 Done.
2722 } else { 2725 } else {
2723 UnexpectedToken(); 2726 UnexpectedToken();
2724 } 2727 }
hausner 2013/08/20 17:49:44 It would be nice to assert here that if the functi
Michael Lippautz (Google) 2013/08/21 16:50:03 Added the assertion, which forced me to think abou
2725 SequenceNode* body = CloseBlock(); 2728 SequenceNode* body = CloseBlock();
2726 current_block_->statements->Add(body); 2729 current_block_->statements->Add(body);
2727 innermost_function_ = saved_innermost_function.raw(); 2730 innermost_function_ = saved_innermost_function.raw();
2728 return CloseBlock(); 2731 return CloseBlock();
2729 } 2732 }
2730 2733
2731 2734
2732 void Parser::SkipIf(Token::Kind token) { 2735 void Parser::SkipIf(Token::Kind token) {
2733 if (CurrentToken() == token) { 2736 if (CurrentToken() == token) {
2734 ConsumeToken(); 2737 ConsumeToken();
(...skipping 2566 matching lines...) Expand 10 before | Expand all | Expand 10 after
5301 "'%s' from outer scope has already been used, cannot redefine", 5304 "'%s' from outer scope has already been used, cannot redefine",
5302 function_variable->name().ToCString()); 5305 function_variable->name().ToCString());
5303 } 5306 }
5304 } 5307 }
5305 } 5308 }
5306 5309
5307 // Parse the local function. 5310 // Parse the local function.
5308 Array& default_parameter_values = Array::Handle(); 5311 Array& default_parameter_values = Array::Handle();
5309 SequenceNode* statements = Parser::ParseFunc(function, 5312 SequenceNode* statements = Parser::ParseFunc(function,
5310 default_parameter_values); 5313 default_parameter_values);
5311 ASSERT(is_new_closure || (function.end_token_pos() == (TokenPos() - 1)));
5312 function.set_end_token_pos(TokenPos() - 1);
5313 5314
5314 // Now that the local function has formal parameters, lookup the signature 5315 // Now that the local function has formal parameters, lookup the signature
5315 // class in the current library (but not in its imports) and only create a new 5316 // class in the current library (but not in its imports) and only create a new
5316 // canonical signature class if it does not exist yet. 5317 // canonical signature class if it does not exist yet.
5317 const String& signature = String::Handle(function.Signature()); 5318 const String& signature = String::Handle(function.Signature());
5318 Class& signature_class = Class::ZoneHandle(); 5319 Class& signature_class = Class::ZoneHandle();
5319 if (!is_new_closure) { 5320 if (!is_new_closure) {
5320 signature_class = function.signature_class(); 5321 signature_class = function.signature_class();
5321 } 5322 }
5322 if (signature_class.IsNull()) { 5323 if (signature_class.IsNull()) {
(...skipping 5004 matching lines...) Expand 10 before | Expand all | Expand 10 after
10327 void Parser::SkipQualIdent() { 10328 void Parser::SkipQualIdent() {
10328 ASSERT(IsIdentifier()); 10329 ASSERT(IsIdentifier());
10329 ConsumeToken(); 10330 ConsumeToken();
10330 if (CurrentToken() == Token::kPERIOD) { 10331 if (CurrentToken() == Token::kPERIOD) {
10331 ConsumeToken(); // Consume the kPERIOD token. 10332 ConsumeToken(); // Consume the kPERIOD token.
10332 ExpectIdentifier("identifier expected after '.'"); 10333 ExpectIdentifier("identifier expected after '.'");
10333 } 10334 }
10334 } 10335 }
10335 10336
10336 } // namespace dart 10337 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698