1 // Copyright 2022 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef V8_NUMBERS_INTEGER_LITERAL_INL_H_ 6 #define V8_NUMBERS_INTEGER_LITERAL_INL_H_ 7 8 #include "src/numbers/integer-literal.h" 9 10 namespace v8 { 11 namespace internal { 12 ToString()13inline std::string IntegerLiteral::ToString() const { 14 if (negative_) return std::string("-") + std::to_string(absolute_value_); 15 return std::to_string(absolute_value_); 16 } 17 18 inline IntegerLiteral operator<<(const IntegerLiteral& x, 19 const IntegerLiteral& y) { 20 DCHECK(!y.is_negative()); 21 DCHECK_LT(y.absolute_value(), sizeof(uint64_t) * kBitsPerByte); 22 return IntegerLiteral(x.is_negative(), x.absolute_value() 23 << y.absolute_value()); 24 } 25 26 inline IntegerLiteral operator+(const IntegerLiteral& x, 27 const IntegerLiteral& y) { 28 if (x.is_negative() == y.is_negative()) { 29 DCHECK_GE(x.absolute_value() + y.absolute_value(), x.absolute_value()); 30 return IntegerLiteral(x.is_negative(), 31 x.absolute_value() + y.absolute_value()); 32 } 33 if (x.absolute_value() >= y.absolute_value()) { 34 return IntegerLiteral(x.is_negative(), 35 x.absolute_value() - y.absolute_value()); 36 } 37 return IntegerLiteral(!x.is_negative(), 38 y.absolute_value() - x.absolute_value()); 39 } 40 41 } // namespace internal 42 } // namespace v8 43 #endif // V8_NUMBERS_INTEGER_LITERAL_INL_H_ 44