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

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

Issue 1549203002: Switch to standard integer types in tools/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
« no previous file with comments | « tools/gn/parse_tree.h ('k') | tools/gn/parse_tree_unittest.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/parse_tree.h" 5 #include "tools/gn/parse_tree.h"
6 6
7 #include <stdint.h>
8
7 #include <string> 9 #include <string>
8 #include <tuple> 10 #include <tuple>
9 11
10 #include "base/stl_util.h" 12 #include "base/stl_util.h"
11 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
12 #include "tools/gn/functions.h" 14 #include "tools/gn/functions.h"
13 #include "tools/gn/operators.h" 15 #include "tools/gn/operators.h"
14 #include "tools/gn/scope.h" 16 #include "tools/gn/scope.h"
15 #include "tools/gn/string_utils.h" 17 #include "tools/gn/string_utils.h"
16 18
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 return Value(); 179 return Value();
178 180
179 const Value* base_value = scope->GetValue(base_.value(), true); 181 const Value* base_value = scope->GetValue(base_.value(), true);
180 if (!base_value) { 182 if (!base_value) {
181 *err = MakeErrorDescribing("Undefined identifier."); 183 *err = MakeErrorDescribing("Undefined identifier.");
182 return Value(); 184 return Value();
183 } 185 }
184 if (!base_value->VerifyTypeIs(Value::LIST, err)) 186 if (!base_value->VerifyTypeIs(Value::LIST, err))
185 return Value(); 187 return Value();
186 188
187 int64 index_int = index_value.int_value(); 189 int64_t index_int = index_value.int_value();
188 if (index_int < 0) { 190 if (index_int < 0) {
189 *err = Err(index_->GetRange(), "Negative array subscript.", 191 *err = Err(index_->GetRange(), "Negative array subscript.",
190 "You gave me " + base::Int64ToString(index_int) + "."); 192 "You gave me " + base::Int64ToString(index_int) + ".");
191 return Value(); 193 return Value();
192 } 194 }
193 size_t index_sizet = static_cast<size_t>(index_int); 195 size_t index_sizet = static_cast<size_t>(index_int);
194 if (index_sizet >= base_value->list_value().size()) { 196 if (index_sizet >= base_value->list_value().size()) {
195 *err = Err(index_->GetRange(), "Array subscript out of range.", 197 *err =
196 "You gave me " + base::Int64ToString(index_int) + 198 Err(index_->GetRange(), "Array subscript out of range.",
197 " but I was expecting something from 0 to " + 199 "You gave me " + base::Int64ToString(index_int) +
198 base::Int64ToString( 200 " but I was expecting something from 0 to " +
199 static_cast<int64>(base_value->list_value().size()) - 1) + 201 base::Int64ToString(
200 ", inclusive."); 202 static_cast<int64_t>(base_value->list_value().size()) - 1) +
203 ", inclusive.");
201 return Value(); 204 return Value();
202 } 205 }
203 206
204 // Doing this assumes that there's no way in the language to do anything 207 // Doing this assumes that there's no way in the language to do anything
205 // between the time the reference is created and the time that the reference 208 // between the time the reference is created and the time that the reference
206 // is used. If there is, this will crash! Currently, this is just used for 209 // is used. If there is, this will crash! Currently, this is just used for
207 // array accesses where this "shouldn't" happen. 210 // array accesses where this "shouldn't" happen.
208 return base_value->list_value()[index_sizet]; 211 return base_value->list_value()[index_sizet];
209 } 212 }
210 213
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 return Value(this, false); 700 return Value(this, false);
698 case Token::INTEGER: { 701 case Token::INTEGER: {
699 base::StringPiece s = value_.value(); 702 base::StringPiece s = value_.value();
700 if ((s.starts_with("0") && s.size() > 1) || s.starts_with("-0")) { 703 if ((s.starts_with("0") && s.size() > 1) || s.starts_with("-0")) {
701 if (s == "-0") 704 if (s == "-0")
702 *err = MakeErrorDescribing("Negative zero doesn't make sense"); 705 *err = MakeErrorDescribing("Negative zero doesn't make sense");
703 else 706 else
704 *err = MakeErrorDescribing("Leading zeros not allowed"); 707 *err = MakeErrorDescribing("Leading zeros not allowed");
705 return Value(); 708 return Value();
706 } 709 }
707 int64 result_int; 710 int64_t result_int;
708 if (!base::StringToInt64(s, &result_int)) { 711 if (!base::StringToInt64(s, &result_int)) {
709 *err = MakeErrorDescribing("This does not look like an integer"); 712 *err = MakeErrorDescribing("This does not look like an integer");
710 return Value(); 713 return Value();
711 } 714 }
712 return Value(this, result_int); 715 return Value(this, result_int);
713 } 716 }
714 case Token::STRING: { 717 case Token::STRING: {
715 Value v(this, Value::STRING); 718 Value v(this, Value::STRING);
716 ExpandStringLiteral(scope, value_, &v, err); 719 ExpandStringLiteral(scope, value_, &v, err);
717 return v; 720 return v;
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 831
829 Err EndNode::MakeErrorDescribing(const std::string& msg, 832 Err EndNode::MakeErrorDescribing(const std::string& msg,
830 const std::string& help) const { 833 const std::string& help) const {
831 return Err(value_, msg, help); 834 return Err(value_, msg, help);
832 } 835 }
833 836
834 void EndNode::Print(std::ostream& out, int indent) const { 837 void EndNode::Print(std::ostream& out, int indent) const {
835 out << IndentFor(indent) << "END(" << value_.value() << ")\n"; 838 out << IndentFor(indent) << "END(" << value_.value() << ")\n";
836 PrintComments(out, indent); 839 PrintComments(out, indent);
837 } 840 }
OLDNEW
« no previous file with comments | « tools/gn/parse_tree.h ('k') | tools/gn/parse_tree_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698