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

Unified Diff: runtime/vm/parser.cc

Issue 11199002: Remove built-in identifier 'negate' from VM (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/parser.h ('k') | runtime/vm/token.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/parser.cc
===================================================================
--- runtime/vm/parser.cc (revision 13693)
+++ runtime/vm/parser.cc (working copy)
@@ -487,6 +487,7 @@
has_var = false;
has_factory = false;
has_operator = false;
+ operator_token = Token::kILLEGAL;
type = NULL;
name_pos = 0;
name = NULL;
@@ -518,6 +519,7 @@
bool has_var;
bool has_factory;
bool has_operator;
+ Token::Kind operator_token;
const AbstractType* type;
intptr_t name_pos;
String* name;
@@ -2445,12 +2447,15 @@
// Now that we know the parameter list, we can distinguish between the
// unary and binary operator -.
- if (method->has_operator &&
- method->name->Equals("-") &&
- (method->params.num_fixed_parameters == 1)) {
- // Patch up name for unary operator - so it does not clash with the
- // name for binary operator -.
- *method->name = Symbols::New("unary-");
+ if (method->has_operator) {
+ if ((method->operator_token == Token::kSUB) &&
+ (method->params.num_fixed_parameters == 1)) {
+ // Patch up name for unary operator - so it does not clash with the
+ // name for binary operator -.
+ method->operator_token = Token::kNEGATE;
+ *method->name = Symbols::New(Token::Str(Token::kNEGATE));
+ }
+ CheckOperatorArity(*method);
}
if (members->FunctionNameExists(*method->name, method->kind)) {
@@ -2811,19 +2816,12 @@
}
-void Parser::CheckOperatorArity(const MemberDesc& member,
- Token::Kind operator_token) {
+void Parser::CheckOperatorArity(const MemberDesc& member) {
intptr_t expected_num_parameters; // Includes receiver.
- if (operator_token == Token::kASSIGN_INDEX) {
+ Token::Kind op = member.operator_token;
+ if (op == Token::kASSIGN_INDEX) {
expected_num_parameters = 3;
- } else if (operator_token == Token::kSUB) {
- if (member.params.num_fixed_parameters == 1) {
- // Unary operator minus (i.e. negate).
- expected_num_parameters = 1;
- } else {
- expected_num_parameters = 2;
- }
- } else if (operator_token == Token::kBIT_NOT) {
+ } else if ((op == Token::kBIT_NOT) || (op == Token::kNEGATE)) {
expected_num_parameters = 1;
} else {
expected_num_parameters = 2;
@@ -2917,7 +2915,7 @@
}
}
}
- Token::Kind operator_token = Token::kILLEGAL;
+
// Optionally parse a (possibly named) constructor name or factory.
if (IsIdentifier() &&
(CurrentLiteral()->Equals(members->class_name()) || member.has_factory)) {
@@ -3014,12 +3012,12 @@
if (member.has_static) {
ErrorMsg("operator overloading functions cannot be static");
}
- operator_token = CurrentToken();
+ member.operator_token = CurrentToken();
member.has_operator = true;
member.kind = RawFunction::kRegularFunction;
member.name_pos = this->TokenPos();
member.name =
- &String::ZoneHandle(Symbols::New(Token::Str(operator_token)));
+ &String::ZoneHandle(Symbols::New(Token::Str(member.operator_token)));
ConsumeToken();
} else if (IsIdentifier()) {
member.name = CurrentLiteral();
@@ -3044,9 +3042,6 @@
}
ASSERT(member.IsFactory() == member.has_factory);
ParseMethodOrConstructor(members, &member);
- if (member.has_operator) {
- CheckOperatorArity(member, operator_token);
- }
} else if (CurrentToken() == Token::kSEMICOLON ||
CurrentToken() == Token::kCOMMA ||
CurrentToken() == Token::kASSIGN) {
@@ -6617,12 +6612,12 @@
}
-bool Parser::IsIncrementOperator(Token::Kind token) {
+static bool IsIncrementOperator(Token::Kind token) {
return token == Token::kINCR || token == Token::kDECR;
srdjan 2012/10/16 19:43:41 Does this belong into class Token with all the oth
hausner 2012/10/16 20:19:44 I prefer not to have these functions in class Toke
}
-bool Parser::IsPrefixOperator(Token::Kind token) {
+static bool IsPrefixOperator(Token::Kind token) {
return (token == Token::kTIGHTADD) || // Valid for literals only!
(token == Token::kSUB) ||
(token == Token::kNOT) ||
@@ -7095,6 +7090,9 @@
const intptr_t op_pos = TokenPos();
if (IsPrefixOperator(CurrentToken())) {
Token::Kind unary_op = CurrentToken();
+ if (unary_op == Token::kSUB) {
+ unary_op = Token::kNEGATE;
+ }
ConsumeToken();
expr = ParseUnaryExpr();
if (unary_op == Token::kTIGHTADD) {
« no previous file with comments | « runtime/vm/parser.h ('k') | runtime/vm/token.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698