Merge pull request #4753 from mattaereal/boost-to-string-patch

Replace boost:lexical_cast<std::string> for std::to_string.
This commit is contained in:
Alex Beregszaszi 2018-08-08 16:07:25 +01:00 committed by GitHub
commit 9062704054
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 32 additions and 36 deletions

View File

@ -17,8 +17,6 @@
#include <libdevcore/Exceptions.h> #include <libdevcore/Exceptions.h>
#include <boost/lexical_cast.hpp>
using namespace std; using namespace std;
using namespace dev; using namespace dev;
@ -43,7 +41,7 @@ string Exception::lineInfo() const
ret += *file; ret += *file;
ret += ':'; ret += ':';
if (line) if (line)
ret += boost::lexical_cast<string>(*line); ret += to_string(*line);
return ret; return ret;
} }

View File

@ -529,7 +529,7 @@ int CodeTransform::variableHeightDiff(solidity::assembly::Scope::Variable const&
if (heightDiff <= (_forSwap ? 1 : 0) || heightDiff > (_forSwap ? 17 : 16)) if (heightDiff <= (_forSwap ? 1 : 0) || heightDiff > (_forSwap ? 17 : 16))
{ {
solUnimplemented( solUnimplemented(
"Variable inaccessible, too deep inside stack (" + boost::lexical_cast<string>(heightDiff) + ")" "Variable inaccessible, too deep inside stack (" + to_string(heightDiff) + ")"
); );
return 0; return 0;
} }

View File

@ -31,7 +31,7 @@ string NameDispenser::newName(string const& _prefix)
while (name.empty() || m_usedNames.count(name)) while (name.empty() || m_usedNames.count(name))
{ {
suffix++; suffix++;
name = _prefix + "_" + std::to_string(suffix); name = _prefix + "_" + to_string(suffix);
} }
m_usedNames.insert(name); m_usedNames.insert(name);
return name; return name;

View File

@ -143,7 +143,7 @@ void dev::lll::parseTreeLLL(string const& _s, sp::utree& o_out)
catch (qi::expectation_failure<it> const& e) catch (qi::expectation_failure<it> const& e)
{ {
std::string fragment(e.first, e.last); std::string fragment(e.first, e.last);
std::string loc = std::to_string(std::distance(s.cbegin(), e.first) - 1); std::string loc = to_string(std::distance(s.cbegin(), e.first) - 1);
std::string reason("Lexer failure at " + loc + ": '" + fragment + "'"); std::string reason("Lexer failure at " + loc + ": '" + fragment + "'");
BOOST_THROW_EXCEPTION(ParserException() << errinfo_comment(reason)); BOOST_THROW_EXCEPTION(ParserException() << errinfo_comment(reason));
} }

View File

@ -126,7 +126,7 @@ string ASTJsonConverter::sourceLocationToString(SourceLocation const& _location)
int length = -1; int length = -1;
if (_location.start >= 0 && _location.end >= 0) if (_location.start >= 0 && _location.end >= 0)
length = _location.end - _location.start; length = _location.end - _location.start;
return std::to_string(_location.start) + ":" + std::to_string(length) + ":" + std::to_string(sourceIndex); return to_string(_location.start) + ":" + to_string(length) + ":" + to_string(sourceIndex);
} }
string ASTJsonConverter::namePathToString(std::vector<ASTString> const& _namePath) string ASTJsonConverter::namePathToString(std::vector<ASTString> const& _namePath)

View File

@ -478,7 +478,7 @@ string IntegerType::richIdentifier() const
if (isAddress()) if (isAddress())
return "t_address"; return "t_address";
else else
return "t_" + string(isSigned() ? "" : "u") + "int" + std::to_string(numBits()); return "t_" + string(isSigned() ? "" : "u") + "int" + to_string(numBits());
} }
bool IntegerType::isImplicitlyConvertibleTo(Type const& _convertTo) const bool IntegerType::isImplicitlyConvertibleTo(Type const& _convertTo) const
@ -644,7 +644,7 @@ FixedPointType::FixedPointType(unsigned _totalBits, unsigned _fractionalDigits,
string FixedPointType::richIdentifier() const string FixedPointType::richIdentifier() const
{ {
return "t_" + string(isSigned() ? "" : "u") + "fixed" + std::to_string(m_totalBits) + "x" + std::to_string(m_fractionalDigits); return "t_" + string(isSigned() ? "" : "u") + "fixed" + to_string(m_totalBits) + "x" + to_string(m_fractionalDigits);
} }
bool FixedPointType::isImplicitlyConvertibleTo(Type const& _convertTo) const bool FixedPointType::isImplicitlyConvertibleTo(Type const& _convertTo) const
@ -1390,7 +1390,7 @@ MemberList::MemberMap FixedBytesType::nativeMembers(const ContractDefinition*) c
string FixedBytesType::richIdentifier() const string FixedBytesType::richIdentifier() const
{ {
return "t_bytes" + std::to_string(m_bytes); return "t_bytes" + to_string(m_bytes);
} }
bool FixedBytesType::operator==(Type const& _other) const bool FixedBytesType::operator==(Type const& _other) const
@ -1833,7 +1833,7 @@ TypePointer ArrayType::copyForLocation(DataLocation _location, bool _isPointer)
string ContractType::richIdentifier() const string ContractType::richIdentifier() const
{ {
return (m_super ? "t_super" : "t_contract") + parenthesizeUserIdentifier(m_contract.name()) + std::to_string(m_contract.id()); return (m_super ? "t_super" : "t_contract") + parenthesizeUserIdentifier(m_contract.name()) + to_string(m_contract.id());
} }
bool ContractType::operator==(Type const& _other) const bool ContractType::operator==(Type const& _other) const
@ -1947,7 +1947,7 @@ bool StructType::isImplicitlyConvertibleTo(const Type& _convertTo) const
string StructType::richIdentifier() const string StructType::richIdentifier() const
{ {
return "t_struct" + parenthesizeUserIdentifier(m_struct.name()) + std::to_string(m_struct.id()) + identifierLocationSuffix(); return "t_struct" + parenthesizeUserIdentifier(m_struct.name()) + to_string(m_struct.id()) + identifierLocationSuffix();
} }
bool StructType::operator==(Type const& _other) const bool StructType::operator==(Type const& _other) const
@ -2173,7 +2173,7 @@ TypePointer EnumType::unaryOperatorResult(Token::Value _operator) const
string EnumType::richIdentifier() const string EnumType::richIdentifier() const
{ {
return "t_enum" + parenthesizeUserIdentifier(m_enum.name()) + std::to_string(m_enum.id()); return "t_enum" + parenthesizeUserIdentifier(m_enum.name()) + to_string(m_enum.id());
} }
bool EnumType::operator==(Type const& _other) const bool EnumType::operator==(Type const& _other) const
@ -3143,7 +3143,7 @@ string ModifierType::toString(bool _short) const
string ModuleType::richIdentifier() const string ModuleType::richIdentifier() const
{ {
return "t_module_" + std::to_string(m_sourceUnit.id()); return "t_module_" + to_string(m_sourceUnit.id());
} }
bool ModuleType::operator==(Type const& _other) const bool ModuleType::operator==(Type const& _other) const

View File

@ -50,7 +50,7 @@ class StackHeightChecker
public: public:
explicit StackHeightChecker(CompilerContext const& _context): explicit StackHeightChecker(CompilerContext const& _context):
m_context(_context), stackHeight(m_context.stackHeight()) {} m_context(_context), stackHeight(m_context.stackHeight()) {}
void check() { solAssert(m_context.stackHeight() == stackHeight, std::string("I sense a disturbance in the stack: ") + std::to_string(m_context.stackHeight()) + " vs " + std::to_string(stackHeight)); } void check() { solAssert(m_context.stackHeight() == stackHeight, std::string("I sense a disturbance in the stack: ") + to_string(m_context.stackHeight()) + " vs " + to_string(stackHeight)); }
private: private:
CompilerContext const& m_context; CompilerContext const& m_context;
unsigned stackHeight; unsigned stackHeight;

View File

@ -85,7 +85,7 @@ bool AsmAnalyzer::operator()(assembly::Literal const& _literal)
{ {
m_errorReporter.typeError( m_errorReporter.typeError(
_literal.location, _literal.location,
"String literal too long (" + boost::lexical_cast<std::string>(_literal.value.size()) + " > 32)" "String literal too long (" + to_string(_literal.value.size()) + " > 32)"
); );
return false; return false;
} }
@ -185,7 +185,7 @@ bool AsmAnalyzer::operator()(assembly::ExpressionStatement const& _statement)
Error::Type errorType = m_flavour == AsmFlavour::Loose ? *m_errorTypeForLoose : Error::Type::TypeError; Error::Type errorType = m_flavour == AsmFlavour::Loose ? *m_errorTypeForLoose : Error::Type::TypeError;
string msg = string msg =
"Top-level expressions are not supposed to return values (this expression returns " + "Top-level expressions are not supposed to return values (this expression returns " +
boost::lexical_cast<string>(m_stackHeight - initialStackHeight) + to_string(m_stackHeight - initialStackHeight) +
" value" + " value" +
(m_stackHeight - initialStackHeight == 1 ? "" : "s") + (m_stackHeight - initialStackHeight == 1 ? "" : "s") +
"). Use ``pop()`` or assign them."; "). Use ``pop()`` or assign them.";
@ -322,8 +322,8 @@ bool AsmAnalyzer::operator()(assembly::FunctionCall const& _funCall)
{ {
m_errorReporter.typeError( m_errorReporter.typeError(
_funCall.functionName.location, _funCall.functionName.location,
"Expected " + boost::lexical_cast<string>(arguments) + " arguments but got " + "Expected " + to_string(arguments) + " arguments but got " +
boost::lexical_cast<string>(_funCall.arguments.size()) + "." to_string(_funCall.arguments.size()) + "."
); );
success = false; success = false;
} }
@ -477,7 +477,7 @@ bool AsmAnalyzer::expectDeposit(int _deposit, int _oldHeight, SourceLocation con
m_errorReporter.typeError( m_errorReporter.typeError(
_location, _location,
"Expected expression to return one item to the stack, but did return " + "Expected expression to return one item to the stack, but did return " +
boost::lexical_cast<string>(m_stackHeight - _oldHeight) + to_string(m_stackHeight - _oldHeight) +
" items." " items."
); );
return false; return false;

View File

@ -279,7 +279,7 @@ assembly::Expression Parser::parseExpression()
"Expected '(' (instruction \"" + "Expected '(' (instruction \"" +
instructionNames().at(instr.instruction) + instructionNames().at(instr.instruction) +
"\" expects " + "\" expects " +
boost::lexical_cast<string>(args) + to_string(args) +
" arguments)" " arguments)"
)); ));
} }
@ -502,7 +502,7 @@ assembly::Expression Parser::parseCall(Parser::ElementaryOperation&& _initialOp)
"Expected expression (instruction \"" + "Expected expression (instruction \"" +
instructionNames().at(instr) + instructionNames().at(instr) +
"\" expects " + "\" expects " +
boost::lexical_cast<string>(args) + to_string(args) +
" arguments)" " arguments)"
)); ));
@ -514,7 +514,7 @@ assembly::Expression Parser::parseCall(Parser::ElementaryOperation&& _initialOp)
"Expected ',' (instruction \"" + "Expected ',' (instruction \"" +
instructionNames().at(instr) + instructionNames().at(instr) +
"\" expects " + "\" expects " +
boost::lexical_cast<string>(args) + to_string(args) +
" arguments)" " arguments)"
)); ));
else else
@ -527,7 +527,7 @@ assembly::Expression Parser::parseCall(Parser::ElementaryOperation&& _initialOp)
"Expected ')' (instruction \"" + "Expected ')' (instruction \"" +
instructionNames().at(instr) + instructionNames().at(instr) +
"\" expects " + "\" expects " +
boost::lexical_cast<string>(args) + to_string(args) +
" arguments)" " arguments)"
)); ));
expectToken(Token::RParen); expectToken(Token::RParen);

View File

@ -925,17 +925,17 @@ string CompilerStack::computeSourceMapping(eth::AssemblyItems const& _items) con
if (components-- > 0) if (components-- > 0)
{ {
if (location.start != prevStart) if (location.start != prevStart)
ret += std::to_string(location.start); ret += to_string(location.start);
if (components-- > 0) if (components-- > 0)
{ {
ret += ':'; ret += ':';
if (length != prevLength) if (length != prevLength)
ret += std::to_string(length); ret += to_string(length);
if (components-- > 0) if (components-- > 0)
{ {
ret += ':'; ret += ':';
if (sourceIndex != prevSourceIndex) if (sourceIndex != prevSourceIndex)
ret += std::to_string(sourceIndex); ret += to_string(sourceIndex);
if (components-- > 0) if (components-- > 0)
{ {
ret += ':'; ret += ':';

View File

@ -117,7 +117,7 @@ public:
if (occurrences > 32) if (occurrences > 32)
{ {
infos.resize(32); infos.resize(32);
_message += " Truncated from " + boost::lexical_cast<std::string>(occurrences) + " to the first 32 occurrences."; _message += " Truncated from " + std::to_string(occurrences) + " to the first 32 occurrences.";
} }
} }

View File

@ -30,7 +30,6 @@
#include <libevmasm/Assembly.h> #include <libevmasm/Assembly.h>
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>
#include <boost/lexical_cast.hpp>
#include <string> #include <string>
#include <tuple> #include <tuple>

View File

@ -130,17 +130,17 @@ BOOST_AUTO_TEST_CASE(switch_inconsistent_return_count)
BOOST_AUTO_TEST_CASE(disallowed_asm_instructions) BOOST_AUTO_TEST_CASE(disallowed_asm_instructions)
{ {
for (unsigned i = 1; i <= 32; i++) for (unsigned i = 1; i <= 32; i++)
BOOST_CHECK(!successCompile("(asm PUSH" + boost::lexical_cast<string>(i) + ")")); BOOST_CHECK(!successCompile("(asm PUSH" + to_string(i) + ")"));
} }
BOOST_AUTO_TEST_CASE(disallowed_functional_asm_instructions) BOOST_AUTO_TEST_CASE(disallowed_functional_asm_instructions)
{ {
for (unsigned i = 1; i <= 32; i++) for (unsigned i = 1; i <= 32; i++)
BOOST_CHECK(!successCompile("(PUSH" + boost::lexical_cast<string>(i) + ")")); BOOST_CHECK(!successCompile("(PUSH" + to_string(i) + ")"));
for (unsigned i = 1; i <= 16; i++) for (unsigned i = 1; i <= 16; i++)
BOOST_CHECK(!successCompile("(DUP" + boost::lexical_cast<string>(i) + ")")); BOOST_CHECK(!successCompile("(DUP" + to_string(i) + ")"));
for (unsigned i = 1; i <= 16; i++) for (unsigned i = 1; i <= 16; i++)
BOOST_CHECK(!successCompile("(SWAP" + boost::lexical_cast<string>(i) + ")")); BOOST_CHECK(!successCompile("(SWAP" + to_string(i) + ")"));
BOOST_CHECK(!successCompile("(JUMPDEST)")); BOOST_CHECK(!successCompile("(JUMPDEST)"));
} }

View File

@ -25,7 +25,6 @@
#include <libevmasm/Instruction.h> #include <libevmasm/Instruction.h>
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>
#include <boost/lexical_cast.hpp>
#include <chrono> #include <chrono>
#include <string> #include <string>
@ -82,8 +81,8 @@ public:
BOOST_CHECK_MESSAGE( BOOST_CHECK_MESSAGE(
_optimizeRuns < 50 || optimizedSize < nonOptimizedSize, _optimizeRuns < 50 || optimizedSize < nonOptimizedSize,
string("Optimizer did not reduce bytecode size. Non-optimized size: ") + string("Optimizer did not reduce bytecode size. Non-optimized size: ") +
std::to_string(nonOptimizedSize) + " - optimized size: " + to_string(nonOptimizedSize) + " - optimized size: " +
std::to_string(optimizedSize) to_string(optimizedSize)
); );
m_optimizedContract = m_contractAddress; m_optimizedContract = m_contractAddress;
} }