From 3f08b2269aae767df5dbf13d40f6900e3585fdd3 Mon Sep 17 00:00:00 2001 From: Christian Parpart Date: Tue, 20 Apr 2021 14:12:07 +0200 Subject: [PATCH] Adds fmtlib as 3rdparty dependency for easier string composition. --- CMakeLists.txt | 1 + cmake/fmtlib.cmake | 20 ++++++++++++++++ libevmasm/CMakeLists.txt | 2 +- liblangutil/CMakeLists.txt | 2 +- libsolidity/CMakeLists.txt | 2 +- libyul/AsmAnalysis.cpp | 24 ++++++++----------- libyul/CMakeLists.txt | 2 +- libyul/YulString.h | 22 +++++++++++++++++ scripts/release_ppa.sh | 3 ++- test/libyul/yulSyntaxTests/invalid_type4.yul | 2 +- .../yulSyntaxTests/type_check_cases_fail.yul | 4 ++-- .../type_check_cases_fail_evmtyped.yul | 4 ++-- 12 files changed, 64 insertions(+), 24 deletions(-) create mode 100644 cmake/fmtlib.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 6014cc6fa..23c2f0e42 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,6 +41,7 @@ include(EthCcache) # Let's find our dependencies include(EthDependencies) +include(fmtlib) include(jsoncpp) include(range-v3) include_directories(SYSTEM ${JSONCPP_INCLUDE_DIR}) diff --git a/cmake/fmtlib.cmake b/cmake/fmtlib.cmake new file mode 100644 index 000000000..5ed196cea --- /dev/null +++ b/cmake/fmtlib.cmake @@ -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() diff --git a/libevmasm/CMakeLists.txt b/libevmasm/CMakeLists.txt index 5b3afcdb6..4e392aadd 100644 --- a/libevmasm/CMakeLists.txt +++ b/libevmasm/CMakeLists.txt @@ -38,4 +38,4 @@ set(sources ) add_library(evmasm ${sources}) -target_link_libraries(evmasm PUBLIC solutil) +target_link_libraries(evmasm PUBLIC solutil fmt::fmt-header-only) diff --git a/liblangutil/CMakeLists.txt b/liblangutil/CMakeLists.txt index 96f2a23d8..28216207c 100644 --- a/liblangutil/CMakeLists.txt +++ b/liblangutil/CMakeLists.txt @@ -29,4 +29,4 @@ set(sources ) add_library(langutil ${sources}) -target_link_libraries(langutil PUBLIC solutil) +target_link_libraries(langutil PUBLIC solutil fmt::fmt-header-only) diff --git a/libsolidity/CMakeLists.txt b/libsolidity/CMakeLists.txt index 24b7d2d85..a1cb68c35 100644 --- a/libsolidity/CMakeLists.txt +++ b/libsolidity/CMakeLists.txt @@ -159,4 +159,4 @@ set(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) diff --git a/libyul/AsmAnalysis.cpp b/libyul/AsmAnalysis.cpp index aae1c97e1..d19aa1a4e 100644 --- a/libyul/AsmAnalysis.cpp +++ b/libyul/AsmAnalysis.cpp @@ -37,6 +37,8 @@ #include +#include + #include #include @@ -643,7 +645,7 @@ void AsmAnalyzer::expectValidType(YulString _type, SourceLocation const& _locati m_errorReporter.typeError( 5473_error, _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( 3781_error, _location, - "Expected a value of type \"" + - _expectedType.str() + - "\" but got \"" + - _givenType.str() + - "\"" + fmt::format("Expected a value of type \"{}\" but got \"{}\".", _expectedType, _givenType) ); } @@ -689,14 +687,12 @@ bool AsmAnalyzer::validateInstructions(evmasm::Instruction _instr, SourceLocatio m_errorReporter.typeError( _errorId, _location, - "The \"" + - boost::to_lower_copy(instructionInfo(_instr).name) - + "\" instruction is " + - vmKindMessage + - " VMs " + - "(you are currently compiling for \"" + - m_evmVersion.name() + - "\")." + fmt::format( + "The \"{instruction}\" instruction is {kind} VMs (you are currently compiling for \"{version}\").", + fmt::arg("instruction", boost::to_lower_copy(instructionInfo(_instr).name)), + fmt::arg("kind", vmKindMessage), + fmt::arg("version", m_evmVersion.name()) + ) ); }; diff --git a/libyul/CMakeLists.txt b/libyul/CMakeLists.txt index 2cc5578e8..0ddb9c64a 100644 --- a/libyul/CMakeLists.txt +++ b/libyul/CMakeLists.txt @@ -216,4 +216,4 @@ add_library(yul 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) diff --git a/libyul/YulString.h b/libyul/YulString.h index fc3dedfd4..5522e3484 100644 --- a/libyul/YulString.h +++ b/libyul/YulString.h @@ -21,6 +21,8 @@ #pragma once +#include + #include #include #include @@ -166,6 +168,26 @@ inline YulString operator "" _yulstring(char const* _string, std::size_t _size) } } + +namespace fmt +{ +template <> +struct formatter +{ + template + constexpr auto parse(ParseContext& _context) + { + return _context.begin(); + } + + template + auto format(solidity::yul::YulString _value, FormatContext& _context) + { + return format_to(_context.out(), "{}", _value.str()); + } +}; +} + namespace std { template<> struct hash diff --git a/scripts/release_ppa.sh b/scripts/release_ppa.sh index a798b96a5..a06a779d6 100755 --- a/scripts/release_ppa.sh +++ b/scripts/release_ppa.sh @@ -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" mv solidity solc -# Fetch jsoncpp dependency +# Fetch dependencies 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/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 cd solc diff --git a/test/libyul/yulSyntaxTests/invalid_type4.yul b/test/libyul/yulSyntaxTests/invalid_type4.yul index 0c588a831..8195fcf90 100644 --- a/test/libyul/yulSyntaxTests/invalid_type4.yul +++ b/test/libyul/yulSyntaxTests/invalid_type4.yul @@ -5,5 +5,5 @@ // ==== // 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). diff --git a/test/libyul/yulSyntaxTests/type_check_cases_fail.yul b/test/libyul/yulSyntaxTests/type_check_cases_fail.yul index 1b3f779d1..d9b4c0204 100644 --- a/test/libyul/yulSyntaxTests/type_check_cases_fail.yul +++ b/test/libyul/yulSyntaxTests/type_check_cases_fail.yul @@ -6,5 +6,5 @@ // ==== // dialect: ewasm // ---- -// 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: (28-33): Expected a value of type "i32" but got "i64". +// TypeError 3781: (46-51): Expected a value of type "i32" but got "i64". diff --git a/test/libyul/yulSyntaxTests/type_check_cases_fail_evmtyped.yul b/test/libyul/yulSyntaxTests/type_check_cases_fail_evmtyped.yul index 458372fe9..35926ccb2 100644 --- a/test/libyul/yulSyntaxTests/type_check_cases_fail_evmtyped.yul +++ b/test/libyul/yulSyntaxTests/type_check_cases_fail_evmtyped.yul @@ -6,5 +6,5 @@ // ==== // dialect: evmTyped // ---- -// 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: (24-33): Expected a value of type "u256" but got "bool". +// TypeError 3781: (46-55): Expected a value of type "u256" but got "bool".