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

Side by Side Diff: tools/gn/operators.cc

Issue 115323009: Fix help and error messages. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 6 years, 11 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 | « tools/gn/functions_target.cc ('k') | tools/gn/parse_tree.cc » ('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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "tools/gn/operators.h" 5 #include "tools/gn/operators.h"
6 6
7 #include "base/strings/string_number_conversions.h" 7 #include "base/strings/string_number_conversions.h"
8 #include "tools/gn/err.h" 8 #include "tools/gn/err.h"
9 #include "tools/gn/parse_tree.h" 9 #include "tools/gn/parse_tree.h"
10 #include "tools/gn/scope.h" 10 #include "tools/gn/scope.h"
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 286
287 // Left-hand-side list. 287 // Left-hand-side list.
288 case Value::LIST: 288 case Value::LIST:
289 RemoveMatchesFromList(op_node, left, right, err); 289 RemoveMatchesFromList(op_node, left, right, err);
290 return; 290 return;
291 291
292 default: 292 default:
293 break; 293 break;
294 } 294 }
295 295
296 *err = Err(op_node->op(), "Incompatible types to add.", 296 *err = Err(op_node->op(), "Incompatible types to subtract.",
297 std::string("I see a ") + Value::DescribeType(left->type()) + " and a " + 297 std::string("I see a ") + Value::DescribeType(left->type()) + " and a " +
298 Value::DescribeType(right.type()) + "."); 298 Value::DescribeType(right.type()) + ".");
299 } 299 }
300 300
301 Value ExecuteMinusEquals(Scope* scope, 301 Value ExecuteMinusEquals(Scope* scope,
302 const BinaryOpNode* op_node, 302 const BinaryOpNode* op_node,
303 const Token& left, 303 const Token& left,
304 const Value& right, 304 const Value& right,
305 Err* err) { 305 Err* err) {
306 Value* left_value = 306 Value* left_value =
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 const ParseNode* right, 507 const ParseNode* right,
508 Err* err) { 508 Err* err) {
509 const Token& op = op_node->op(); 509 const Token& op = op_node->op();
510 510
511 // First handle the ones that take an lvalue. 511 // First handle the ones that take an lvalue.
512 if (op.type() == Token::EQUAL || 512 if (op.type() == Token::EQUAL ||
513 op.type() == Token::PLUS_EQUALS || 513 op.type() == Token::PLUS_EQUALS ||
514 op.type() == Token::MINUS_EQUALS) { 514 op.type() == Token::MINUS_EQUALS) {
515 const IdentifierNode* left_id = left->AsIdentifier(); 515 const IdentifierNode* left_id = left->AsIdentifier();
516 if (!left_id) { 516 if (!left_id) {
517 *err = Err(op, "Operator requires an lvalue.", 517 *err = Err(op, "Operator requires a lvalue.",
518 "This thing on the left is not an idenfitier."); 518 "This thing on the left is not an identifier.");
519 err->AppendRange(left->GetRange()); 519 err->AppendRange(left->GetRange());
520 return Value(); 520 return Value();
521 } 521 }
522 const Token& dest = left_id->value(); 522 const Token& dest = left_id->value();
523 523
524 Value right_value = right->Execute(scope, err); 524 Value right_value = right->Execute(scope, err);
525 if (err->has_error()) 525 if (err->has_error())
526 return Value(); 526 return Value();
527 if (right_value.type() == Value::NONE) { 527 if (right_value.type() == Value::NONE) {
528 *err = Err(op, "Operator requires an rvalue.", 528 *err = Err(op, "Operator requires a rvalue.",
529 "This thing on the right does not evaluate to a value."); 529 "This thing on the right does not evaluate to a value.");
530 err->AppendRange(right->GetRange()); 530 err->AppendRange(right->GetRange());
531 return Value(); 531 return Value();
532 } 532 }
533 533
534 if (op.type() == Token::EQUAL) 534 if (op.type() == Token::EQUAL)
535 return ExecuteEquals(scope, op_node, dest, right_value, err); 535 return ExecuteEquals(scope, op_node, dest, right_value, err);
536 if (op.type() == Token::PLUS_EQUALS) 536 if (op.type() == Token::PLUS_EQUALS)
537 return ExecutePlusEquals(scope, op_node, dest, right_value, err); 537 return ExecutePlusEquals(scope, op_node, dest, right_value, err);
538 if (op.type() == Token::MINUS_EQUALS) 538 if (op.type() == Token::MINUS_EQUALS)
539 return ExecuteMinusEquals(scope, op_node, dest, right_value, err); 539 return ExecuteMinusEquals(scope, op_node, dest, right_value, err);
540 NOTREACHED(); 540 NOTREACHED();
541 return Value(); 541 return Value();
542 } 542 }
543 543
544 // Left value. 544 // Left value.
545 Value left_value = left->Execute(scope, err); 545 Value left_value = left->Execute(scope, err);
546 if (err->has_error()) 546 if (err->has_error())
547 return Value(); 547 return Value();
548 if (left_value.type() == Value::NONE) { 548 if (left_value.type() == Value::NONE) {
549 *err = Err(op, "Operator requires an value.", 549 *err = Err(op, "Operator requires a value.",
550 "This thing on the left does not evaluate to a value."); 550 "This thing on the left does not evaluate to a value.");
551 err->AppendRange(left->GetRange()); 551 err->AppendRange(left->GetRange());
552 return Value(); 552 return Value();
553 } 553 }
554 554
555 // Right value. Note: don't move this above to share code with the lvalue 555 // Right value. Note: don't move this above to share code with the lvalue
556 // version since in this case we want to execute the left side first. 556 // version since in this case we want to execute the left side first.
557 Value right_value = right->Execute(scope, err); 557 Value right_value = right->Execute(scope, err);
558 if (err->has_error()) 558 if (err->has_error())
559 return Value(); 559 return Value();
560 if (right_value.type() == Value::NONE) { 560 if (right_value.type() == Value::NONE) {
561 *err = Err(op, "Operator requires an value.", 561 *err = Err(op, "Operator requires a value.",
562 "This thing on the right does not evaluate to a value."); 562 "This thing on the right does not evaluate to a value.");
563 err->AppendRange(right->GetRange()); 563 err->AppendRange(right->GetRange());
564 return Value(); 564 return Value();
565 } 565 }
566 566
567 // +, -. 567 // +, -.
568 if (op.type() == Token::MINUS) 568 if (op.type() == Token::MINUS)
569 return ExecuteMinus(scope, op_node, left_value, right_value, err); 569 return ExecuteMinus(scope, op_node, left_value, right_value, err);
570 if (op.type() == Token::PLUS) 570 if (op.type() == Token::PLUS)
571 return ExecutePlus(scope, op_node, left_value, right_value, err); 571 return ExecutePlus(scope, op_node, left_value, right_value, err);
(...skipping 13 matching lines...) Expand all
585 return ExecuteLess(scope, op_node, left_value, right_value, err); 585 return ExecuteLess(scope, op_node, left_value, right_value, err);
586 586
587 // ||, &&. 587 // ||, &&.
588 if (op.type() == Token::BOOLEAN_OR) 588 if (op.type() == Token::BOOLEAN_OR)
589 return ExecuteOr(scope, op_node, left_value, right_value, err); 589 return ExecuteOr(scope, op_node, left_value, right_value, err);
590 if (op.type() == Token::BOOLEAN_AND) 590 if (op.type() == Token::BOOLEAN_AND)
591 return ExecuteAnd(scope, op_node, left_value, right_value, err); 591 return ExecuteAnd(scope, op_node, left_value, right_value, err);
592 592
593 return Value(); 593 return Value();
594 } 594 }
OLDNEW
« no previous file with comments | « tools/gn/functions_target.cc ('k') | tools/gn/parse_tree.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698