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

Side by Side Diff: src/parser.cc

Issue 6879081: Added type recording for unary minus and unary bitwise negation. Note that the (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Incorporated Florian's suggested changes Created 9 years, 8 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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 2466 matching lines...) Expand 10 before | Expand all | Expand 10 after
2477 // We have a comparison. 2477 // We have a comparison.
2478 Token::Value cmp = op; 2478 Token::Value cmp = op;
2479 switch (op) { 2479 switch (op) {
2480 case Token::NE: cmp = Token::EQ; break; 2480 case Token::NE: cmp = Token::EQ; break;
2481 case Token::NE_STRICT: cmp = Token::EQ_STRICT; break; 2481 case Token::NE_STRICT: cmp = Token::EQ_STRICT; break;
2482 default: break; 2482 default: break;
2483 } 2483 }
2484 x = NewCompareNode(cmp, x, y, position); 2484 x = NewCompareNode(cmp, x, y, position);
2485 if (cmp != op) { 2485 if (cmp != op) {
2486 // The comparison was negated - add a NOT. 2486 // The comparison was negated - add a NOT.
2487 x = new(zone()) UnaryOperation(Token::NOT, x); 2487 x = new(zone()) UnaryOperation(Token::NOT, x, position);
2488 } 2488 }
2489 2489
2490 } else { 2490 } else {
2491 // We have a "normal" binary operation. 2491 // We have a "normal" binary operation.
2492 x = new(zone()) BinaryOperation(op, x, y, position); 2492 x = new(zone()) BinaryOperation(op, x, y, position);
2493 } 2493 }
2494 } 2494 }
2495 } 2495 }
2496 return x; 2496 return x;
2497 } 2497 }
(...skipping 29 matching lines...) Expand all
2527 // '++' UnaryExpression 2527 // '++' UnaryExpression
2528 // '--' UnaryExpression 2528 // '--' UnaryExpression
2529 // '+' UnaryExpression 2529 // '+' UnaryExpression
2530 // '-' UnaryExpression 2530 // '-' UnaryExpression
2531 // '~' UnaryExpression 2531 // '~' UnaryExpression
2532 // '!' UnaryExpression 2532 // '!' UnaryExpression
2533 2533
2534 Token::Value op = peek(); 2534 Token::Value op = peek();
2535 if (Token::IsUnaryOp(op)) { 2535 if (Token::IsUnaryOp(op)) {
2536 op = Next(); 2536 op = Next();
2537 int position = scanner().location().beg_pos;
2537 Expression* expression = ParseUnaryExpression(CHECK_OK); 2538 Expression* expression = ParseUnaryExpression(CHECK_OK);
2538 2539
2539 // Compute some expressions involving only number literals. 2540 // Compute some expressions involving only number literals.
2540 if (expression != NULL && expression->AsLiteral() && 2541 if (expression != NULL && expression->AsLiteral() &&
2541 expression->AsLiteral()->handle()->IsNumber()) { 2542 expression->AsLiteral()->handle()->IsNumber()) {
2542 double value = expression->AsLiteral()->handle()->Number(); 2543 double value = expression->AsLiteral()->handle()->Number();
2543 switch (op) { 2544 switch (op) {
2544 case Token::ADD: 2545 case Token::ADD:
2545 return expression; 2546 return expression;
2546 case Token::SUB: 2547 case Token::SUB:
2547 return NewNumberLiteral(-value); 2548 return NewNumberLiteral(-value);
2548 case Token::BIT_NOT: 2549 case Token::BIT_NOT:
2549 return NewNumberLiteral(~DoubleToInt32(value)); 2550 return NewNumberLiteral(~DoubleToInt32(value));
2550 default: break; 2551 default: break;
2551 } 2552 }
2552 } 2553 }
2553 2554
2554 // "delete identifier" is a syntax error in strict mode. 2555 // "delete identifier" is a syntax error in strict mode.
2555 if (op == Token::DELETE && top_scope_->is_strict_mode()) { 2556 if (op == Token::DELETE && top_scope_->is_strict_mode()) {
2556 VariableProxy* operand = expression->AsVariableProxy(); 2557 VariableProxy* operand = expression->AsVariableProxy();
2557 if (operand != NULL && !operand->is_this()) { 2558 if (operand != NULL && !operand->is_this()) {
2558 ReportMessage("strict_delete", Vector<const char*>::empty()); 2559 ReportMessage("strict_delete", Vector<const char*>::empty());
2559 *ok = false; 2560 *ok = false;
2560 return NULL; 2561 return NULL;
2561 } 2562 }
2562 } 2563 }
2563 2564
2564 return new(zone()) UnaryOperation(op, expression); 2565 return new(zone()) UnaryOperation(op, expression, position);
2565 2566
2566 } else if (Token::IsCountOp(op)) { 2567 } else if (Token::IsCountOp(op)) {
2567 op = Next(); 2568 op = Next();
2568 Expression* expression = ParseUnaryExpression(CHECK_OK); 2569 Expression* expression = ParseUnaryExpression(CHECK_OK);
2569 // Signal a reference error if the expression is an invalid 2570 // Signal a reference error if the expression is an invalid
2570 // left-hand side expression. We could report this as a syntax 2571 // left-hand side expression. We could report this as a syntax
2571 // error here but for compatibility with JSC we choose to report the 2572 // error here but for compatibility with JSC we choose to report the
2572 // error at runtime. 2573 // error at runtime.
2573 if (expression == NULL || !expression->IsValidLeftHandSide()) { 2574 if (expression == NULL || !expression->IsValidLeftHandSide()) {
2574 Handle<String> type = 2575 Handle<String> type =
(...skipping 2576 matching lines...) Expand 10 before | Expand all | Expand 10 after
5151 info->is_global(), 5152 info->is_global(),
5152 info->StrictMode()); 5153 info->StrictMode());
5153 } 5154 }
5154 } 5155 }
5155 5156
5156 info->SetFunction(result); 5157 info->SetFunction(result);
5157 return (result != NULL); 5158 return (result != NULL);
5158 } 5159 }
5159 5160
5160 } } // namespace v8::internal 5161 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698