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

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

Issue 8222015: Implement super operator calls (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 9 years, 2 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 | « runtime/vm/parser.h ('k') | tests/language/language.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 1010 matching lines...) Expand 10 before | Expand all | Expand 10 after
1021 if (super_function.IsNull()) { 1021 if (super_function.IsNull()) {
1022 ErrorMsg(supercall_pos, 1022 ErrorMsg(supercall_pos,
1023 "function '%s' not found in super class", 1023 "function '%s' not found in super class",
1024 function_name.ToCString()); 1024 function_name.ToCString());
1025 } 1025 }
1026 CheckFunctionIsCallable(supercall_pos, super_function); 1026 CheckFunctionIsCallable(supercall_pos, super_function);
1027 return new StaticCallNode(supercall_pos, super_function, arguments); 1027 return new StaticCallNode(supercall_pos, super_function, arguments);
1028 } 1028 }
1029 1029
1030 1030
1031 AstNode* Parser::ParseSuperOperator() {
1032 AstNode* super_op = NULL;
1033 const intptr_t operator_pos = token_index_;
1034 const Class& super_class = Class::Handle(current_class().SuperClass());
1035 if (super_class.IsNull()) {
1036 ErrorMsg(operator_pos, "class '%s' does not have a superclass",
1037 String::Handle(current_class().Name()).ToCString());
1038 }
1039
1040 if (CurrentToken() == Token::kLBRACK) {
1041 Unimplemented("Not yet implemented: super[expr]");
1042 } else if (Token::CanBeOverloaded(CurrentToken())) {
1043 Token::Kind op = CurrentToken();
1044 ConsumeToken();
1045
1046 // Resolve the operator function in the superclass.
1047 const String& operator_function_name =
1048 String::ZoneHandle(String::NewSymbol(Token::Str(op)));
1049 const Function& super_operator = Function::ZoneHandle(
1050 ResolveDynamicFunction(super_class, operator_function_name));
1051 if (super_operator.IsNull()) {
1052 ErrorMsg(operator_pos, "operator '%s' not found in super class",
1053 Token::Str(op));
1054 }
1055
1056 ASSERT(Token::Precedence(op) >= Token::Precedence(Token::kBIT_OR));
1057 AstNode* other_operand = ParseBinaryExpr(Token::Precedence(op) + 1);
1058
1059 ArgumentListNode* op_arguments = new ArgumentListNode(operator_pos);
1060 AstNode* receiver = LoadReceiver(operator_pos);
1061 op_arguments->Add(receiver);
1062 op_arguments->Add(other_operand);
1063
1064 CheckFunctionIsCallable(operator_pos, super_operator);
1065 super_op = new StaticCallNode(operator_pos, super_operator, op_arguments);
1066 }
1067 return super_op;
1068 }
1069
1070
1031 AstNode* Parser::CreateImplicitClosureNode(const Function& func, 1071 AstNode* Parser::CreateImplicitClosureNode(const Function& func,
1032 intptr_t token_pos, 1072 intptr_t token_pos,
1033 AstNode* receiver) { 1073 AstNode* receiver) {
1034 Function& implicit_closure_function = 1074 Function& implicit_closure_function =
1035 Function::ZoneHandle(func.ImplicitClosureFunction()); 1075 Function::ZoneHandle(func.ImplicitClosureFunction());
1036 ASSERT(!implicit_closure_function.IsNull()); 1076 ASSERT(!implicit_closure_function.IsNull());
1037 ASSERT(implicit_closure_function.is_static()); // TODO(regis): For now. 1077 ASSERT(implicit_closure_function.is_static()); // TODO(regis): For now.
1038 AstNode* node; 1078 AstNode* node;
1039 if (receiver == NULL) { 1079 if (receiver == NULL) {
1040 ASSERT(func.is_static()); 1080 ASSERT(func.is_static());
(...skipping 5577 matching lines...) Expand 10 before | Expand all | Expand 10 after
6618 } 6658 }
6619 ConsumeToken(); 6659 ConsumeToken();
6620 if (CurrentToken() == Token::kPERIOD) { 6660 if (CurrentToken() == Token::kPERIOD) {
6621 ConsumeToken(); 6661 ConsumeToken();
6622 const String& ident = *ExpectIdentifier("identifier expected"); 6662 const String& ident = *ExpectIdentifier("identifier expected");
6623 if (CurrentToken() == Token::kLPAREN) { 6663 if (CurrentToken() == Token::kLPAREN) {
6624 primary = ParseSuperCall(ident); 6664 primary = ParseSuperCall(ident);
6625 } else { 6665 } else {
6626 primary = ParseSuperFieldAccess(ident); 6666 primary = ParseSuperFieldAccess(ident);
6627 } 6667 }
6628 } else if (CurrentToken() == Token::kLBRACK) { 6668 } else if (Token::CanBeOverloaded(CurrentToken())) {
6629 Unimplemented("Don't know yet how to interpret super[expr]"); 6669 primary = ParseSuperOperator();
6630 } else { 6670 } else {
6631 ErrorMsg("Expected '.' or '[' after super"); 6671 ErrorMsg("Illegal super call");
6632 } 6672 }
6633 } else { 6673 } else {
6634 UnexpectedToken(); 6674 UnexpectedToken();
6635 } 6675 }
6636 return primary; 6676 return primary;
6637 } 6677 }
6638 6678
6639 6679
6640 // Evaluate expression in expr and return the value. The expression must 6680 // Evaluate expression in expr and return the value. The expression must
6641 // be a compile time constant. 6681 // be a compile time constant.
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
6889 } 6929 }
6890 6930
6891 6931
6892 void Parser::SkipNestedExpr() { 6932 void Parser::SkipNestedExpr() {
6893 const bool saved_mode = SetAllowFunctionLiterals(true); 6933 const bool saved_mode = SetAllowFunctionLiterals(true);
6894 SkipExpr(); 6934 SkipExpr();
6895 SetAllowFunctionLiterals(saved_mode); 6935 SetAllowFunctionLiterals(saved_mode);
6896 } 6936 }
6897 6937
6898 } // namespace dart 6938 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/parser.h ('k') | tests/language/language.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698