OLD | NEW |
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/parse_tree.h" | 5 #include "tools/gn/parse_tree.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 return this; | 627 return this; |
628 } | 628 } |
629 | 629 |
630 Value LiteralNode::Execute(Scope* scope, Err* err) const { | 630 Value LiteralNode::Execute(Scope* scope, Err* err) const { |
631 switch (value_.type()) { | 631 switch (value_.type()) { |
632 case Token::TRUE_TOKEN: | 632 case Token::TRUE_TOKEN: |
633 return Value(this, true); | 633 return Value(this, true); |
634 case Token::FALSE_TOKEN: | 634 case Token::FALSE_TOKEN: |
635 return Value(this, false); | 635 return Value(this, false); |
636 case Token::INTEGER: { | 636 case Token::INTEGER: { |
| 637 base::StringPiece s = value_.value(); |
| 638 if ((s.starts_with("0") && s.size() > 1) || s.starts_with("-0")) { |
| 639 if (s == "-0") |
| 640 *err = MakeErrorDescribing("Negative zero doesn't make sense"); |
| 641 else |
| 642 *err = MakeErrorDescribing("Leading zeros not allowed"); |
| 643 return Value(); |
| 644 } |
637 int64 result_int; | 645 int64 result_int; |
638 if (!base::StringToInt64(value_.value(), &result_int)) { | 646 if (!base::StringToInt64(s, &result_int)) { |
639 *err = MakeErrorDescribing("This does not look like an integer"); | 647 *err = MakeErrorDescribing("This does not look like an integer"); |
640 return Value(); | 648 return Value(); |
641 } | 649 } |
642 return Value(this, result_int); | 650 return Value(this, result_int); |
643 } | 651 } |
644 case Token::STRING: { | 652 case Token::STRING: { |
645 Value v(this, Value::STRING); | 653 Value v(this, Value::STRING); |
646 ExpandStringLiteral(scope, value_, &v, err); | 654 ExpandStringLiteral(scope, value_, &v, err); |
647 return v; | 655 return v; |
648 } | 656 } |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
758 | 766 |
759 Err EndNode::MakeErrorDescribing(const std::string& msg, | 767 Err EndNode::MakeErrorDescribing(const std::string& msg, |
760 const std::string& help) const { | 768 const std::string& help) const { |
761 return Err(value_, msg, help); | 769 return Err(value_, msg, help); |
762 } | 770 } |
763 | 771 |
764 void EndNode::Print(std::ostream& out, int indent) const { | 772 void EndNode::Print(std::ostream& out, int indent) const { |
765 out << IndentFor(indent) << "END(" << value_.value() << ")\n"; | 773 out << IndentFor(indent) << "END(" << value_.value() << ")\n"; |
766 PrintComments(out, indent); | 774 PrintComments(out, indent); |
767 } | 775 } |
OLD | NEW |