Adds fmtlib as 3rdparty dependency for easier string composition.

This commit is contained in:
Christian Parpart 2021-04-20 14:12:07 +02:00
parent 16c4a889a6
commit 3f08b2269a
12 changed files with 64 additions and 24 deletions

View File

@ -41,6 +41,7 @@ include(EthCcache)
# Let's find our dependencies # Let's find our dependencies
include(EthDependencies) include(EthDependencies)
include(fmtlib)
include(jsoncpp) include(jsoncpp)
include(range-v3) include(range-v3)
include_directories(SYSTEM ${JSONCPP_INCLUDE_DIR}) include_directories(SYSTEM ${JSONCPP_INCLUDE_DIR})

20
cmake/fmtlib.cmake Normal file
View File

@ -0,0 +1,20 @@
include(FetchContent)
FetchContent_Declare(
fmtlib
PREFIX "${CMAKE_BINARY_DIR}/deps"
DOWNLOAD_DIR "${CMAKE_SOURCE_DIR}/deps/downloads"
DOWNLOAD_NAME fmt-8.0.1.tar.gz
URL https://github.com/fmtlib/fmt/archive/8.0.1.tar.gz
URL_HASH SHA256=b06ca3130158c625848f3fb7418f235155a4d389b2abc3a6245fb01cb0eb1e01
)
if (CMAKE_VERSION VERSION_LESS "3.14.0")
FetchContent_GetProperties(fmtlib)
if (NOT fmtlib_POPULATED)
FetchContent_Populate(fmtlib)
add_subdirectory(${fmtlib_SOURCE_DIR} ${fmtlib_BINARY_DIR})
endif()
else()
FetchContent_MakeAvailable(fmtlib)
endif()

View File

@ -38,4 +38,4 @@ set(sources
) )
add_library(evmasm ${sources}) add_library(evmasm ${sources})
target_link_libraries(evmasm PUBLIC solutil) target_link_libraries(evmasm PUBLIC solutil fmt::fmt-header-only)

View File

@ -29,4 +29,4 @@ set(sources
) )
add_library(langutil ${sources}) add_library(langutil ${sources})
target_link_libraries(langutil PUBLIC solutil) target_link_libraries(langutil PUBLIC solutil fmt::fmt-header-only)

View File

@ -159,4 +159,4 @@ set(sources
) )
add_library(solidity ${sources}) add_library(solidity ${sources})
target_link_libraries(solidity PUBLIC yul evmasm langutil smtutil solutil Boost::boost) target_link_libraries(solidity PUBLIC yul evmasm langutil smtutil solutil Boost::boost fmt::fmt-header-only)

View File

@ -37,6 +37,8 @@
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#include <fmt/format.h>
#include <memory> #include <memory>
#include <functional> #include <functional>
@ -643,7 +645,7 @@ void AsmAnalyzer::expectValidType(YulString _type, SourceLocation const& _locati
m_errorReporter.typeError( m_errorReporter.typeError(
5473_error, 5473_error,
_location, _location,
"\"" + _type.str() + "\" is not a valid type (user defined types are not yet supported)." fmt::format("\"{}\" is not a valid type (user defined types are not yet supported).", _type)
); );
} }
@ -653,11 +655,7 @@ void AsmAnalyzer::expectType(YulString _expectedType, YulString _givenType, Sour
m_errorReporter.typeError( m_errorReporter.typeError(
3781_error, 3781_error,
_location, _location,
"Expected a value of type \"" + fmt::format("Expected a value of type \"{}\" but got \"{}\".", _expectedType, _givenType)
_expectedType.str() +
"\" but got \"" +
_givenType.str() +
"\""
); );
} }
@ -689,14 +687,12 @@ bool AsmAnalyzer::validateInstructions(evmasm::Instruction _instr, SourceLocatio
m_errorReporter.typeError( m_errorReporter.typeError(
_errorId, _errorId,
_location, _location,
"The \"" + fmt::format(
boost::to_lower_copy(instructionInfo(_instr).name) "The \"{instruction}\" instruction is {kind} VMs (you are currently compiling for \"{version}\").",
+ "\" instruction is " + fmt::arg("instruction", boost::to_lower_copy(instructionInfo(_instr).name)),
vmKindMessage + fmt::arg("kind", vmKindMessage),
" VMs " + fmt::arg("version", m_evmVersion.name())
"(you are currently compiling for \"" + )
m_evmVersion.name() +
"\")."
); );
}; };

View File

@ -216,4 +216,4 @@ add_library(yul
optimiser/VarNameCleaner.h optimiser/VarNameCleaner.h
) )
target_link_libraries(yul PUBLIC evmasm solutil langutil smtutil) target_link_libraries(yul PUBLIC evmasm solutil langutil smtutil fmt::fmt-header-only)

View File

@ -21,6 +21,8 @@
#pragma once #pragma once
#include <fmt/format.h>
#include <unordered_map> #include <unordered_map>
#include <memory> #include <memory>
#include <vector> #include <vector>
@ -166,6 +168,26 @@ inline YulString operator "" _yulstring(char const* _string, std::size_t _size)
} }
} }
namespace fmt
{
template <>
struct formatter<solidity::yul::YulString>
{
template <typename ParseContext>
constexpr auto parse(ParseContext& _context)
{
return _context.begin();
}
template <typename FormatContext>
auto format(solidity::yul::YulString _value, FormatContext& _context)
{
return format_to(_context.out(), "{}", _value.str());
}
};
}
namespace std namespace std
{ {
template<> struct hash<solidity::yul::YulString> template<> struct hash<solidity::yul::YulString>

View File

@ -105,10 +105,11 @@ ppafilesurl=https://launchpad.net/~ethereum/+archive/ubuntu/${pparepo}/+files
git clone --depth 2 --recursive https://github.com/ethereum/solidity.git -b "$branch" git clone --depth 2 --recursive https://github.com/ethereum/solidity.git -b "$branch"
mv solidity solc mv solidity solc
# Fetch jsoncpp dependency # Fetch dependencies
mkdir -p ./solc/deps/downloads/ 2>/dev/null || true mkdir -p ./solc/deps/downloads/ 2>/dev/null || true
wget -O ./solc/deps/downloads/jsoncpp-1.9.3.tar.gz https://github.com/open-source-parsers/jsoncpp/archive/1.9.3.tar.gz wget -O ./solc/deps/downloads/jsoncpp-1.9.3.tar.gz https://github.com/open-source-parsers/jsoncpp/archive/1.9.3.tar.gz
wget -O ./solc/deps/downloads/range-v3-0.11.0.tar.gz https://github.com/ericniebler/range-v3/archive/0.11.0.tar.gz wget -O ./solc/deps/downloads/range-v3-0.11.0.tar.gz https://github.com/ericniebler/range-v3/archive/0.11.0.tar.gz
wget -O ./solc/deps/downloads/fmt-7.1.3.tar.gz https://github.com/fmtlib/fmt/archive/7.1.3.tar.gz
# Determine version # Determine version
cd solc cd solc

View File

@ -5,5 +5,5 @@
// ==== // ====
// dialect: evmTyped // dialect: evmTyped
// ---- // ----
// TypeError 3781: (24-38): Expected a value of type "u256" but got "invalidType" // TypeError 3781: (24-38): Expected a value of type "u256" but got "invalidType".
// TypeError 5473: (24-38): "invalidType" is not a valid type (user defined types are not yet supported). // TypeError 5473: (24-38): "invalidType" is not a valid type (user defined types are not yet supported).

View File

@ -6,5 +6,5 @@
// ==== // ====
// dialect: ewasm // dialect: ewasm
// ---- // ----
// TypeError 3781: (28-33): Expected a value of type "i32" but got "i64" // TypeError 3781: (28-33): Expected a value of type "i32" but got "i64".
// TypeError 3781: (46-51): Expected a value of type "i32" but got "i64" // TypeError 3781: (46-51): Expected a value of type "i32" but got "i64".

View File

@ -6,5 +6,5 @@
// ==== // ====
// dialect: evmTyped // dialect: evmTyped
// ---- // ----
// TypeError 3781: (24-33): Expected a value of type "u256" but got "bool" // TypeError 3781: (24-33): Expected a value of type "u256" but got "bool".
// TypeError 3781: (46-55): Expected a value of type "u256" but got "bool" // TypeError 3781: (46-55): Expected a value of type "u256" but got "bool".