From becea47ac3066c7d8d448d0e428cd84d351061e3 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 16 Nov 2016 10:16:01 +0000 Subject: Use assertThrow where possible --- libdevcore/CommonIO.cpp | 7 +++---- libevmasm/Assembly.cpp | 13 +++++-------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/libdevcore/CommonIO.cpp b/libdevcore/CommonIO.cpp index 8dbcb00a..97505b54 100644 --- a/libdevcore/CommonIO.cpp +++ b/libdevcore/CommonIO.cpp @@ -30,11 +30,11 @@ #include #endif #include -#include "Exceptions.h" +#include "Assertions.h" + using namespace std; using namespace dev; - template inline _T contentsGeneric(std::string const& _file) { @@ -83,8 +83,7 @@ void dev::writeFile(std::string const& _file, bytesConstRef _data, bool _writeDe ofstream s(_file, ios::trunc | ios::binary); s.write(reinterpret_cast(_data.data()), _data.size()); - if (!s) - BOOST_THROW_EXCEPTION(FileError() << errinfo_comment("Could not write to file: " + _file)); + assertThrow(s, FileError, "Could not write to file: " + _file); DEV_IGNORE_EXCEPTIONS(fs::permissions(_file, fs::owner_read|fs::owner_write)); } } diff --git a/libevmasm/Assembly.cpp b/libevmasm/Assembly.cpp index 606714d2..27199b7b 100644 --- a/libevmasm/Assembly.cpp +++ b/libevmasm/Assembly.cpp @@ -59,14 +59,11 @@ void Assembly::append(Assembly const& _a) void Assembly::append(Assembly const& _a, int _deposit) { - if (_deposit > _a.m_deposit) - BOOST_THROW_EXCEPTION(InvalidDeposit()); - else - { - append(_a); - while (_deposit++ < _a.m_deposit) - append(Instruction::POP); - } + assertThrow(_deposit <= _a.m_deposit, InvalidDeposit, ""); + + append(_a); + while (_deposit++ < _a.m_deposit) + append(Instruction::POP); } unsigned Assembly::bytesRequired(unsigned subTagSize) const -- cgit v1.2.3 From a3bd670154da3c8cc153da4b2535cd3012d75885 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 21 Jun 2017 21:46:56 +0100 Subject: Remove obscure DEV_IGNORE_EXCEPTIONS macro --- libdevcore/Common.h | 2 -- libdevcore/CommonIO.cpp | 16 ++++++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/libdevcore/Common.h b/libdevcore/Common.h index dc981ff6..c5b09a80 100644 --- a/libdevcore/Common.h +++ b/libdevcore/Common.h @@ -76,8 +76,6 @@ using byte = uint8_t; #define DEV_QUOTED_HELPER(s) #s #define DEV_QUOTED(s) DEV_QUOTED_HELPER(s) -#define DEV_IGNORE_EXCEPTIONS(X) try { X; } catch (...) {} - namespace dev { diff --git a/libdevcore/CommonIO.cpp b/libdevcore/CommonIO.cpp index 97505b54..52829455 100644 --- a/libdevcore/CommonIO.cpp +++ b/libdevcore/CommonIO.cpp @@ -78,12 +78,24 @@ void dev::writeFile(std::string const& _file, bytesConstRef _data, bool _writeDe if (!fs::exists(p.parent_path())) { fs::create_directories(p.parent_path()); - DEV_IGNORE_EXCEPTIONS(fs::permissions(p.parent_path(), fs::owner_all)); + try + { + fs::permissions(p.parent_path(), fs::owner_all); + } + catch (...) + { + } } ofstream s(_file, ios::trunc | ios::binary); s.write(reinterpret_cast(_data.data()), _data.size()); assertThrow(s, FileError, "Could not write to file: " + _file); - DEV_IGNORE_EXCEPTIONS(fs::permissions(_file, fs::owner_read|fs::owner_write)); + try + { + fs::permissions(_file, fs::owner_read|fs::owner_write); + } + catch (...) + { + } } } -- cgit v1.2.3 From 09c548ec69478ee0fa1b1d017481c78d58662280 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 21 Jun 2017 21:50:05 +0100 Subject: Remove unused errinfo types --- libdevcore/Assertions.h | 2 -- libdevcore/Exceptions.h | 4 ---- 2 files changed, 6 deletions(-) diff --git a/libdevcore/Assertions.h b/libdevcore/Assertions.h index 0151cfc1..729ffb05 100644 --- a/libdevcore/Assertions.h +++ b/libdevcore/Assertions.h @@ -54,6 +54,4 @@ namespace dev } \ while (false) -using errinfo_comment = boost::error_info; - } diff --git a/libdevcore/Exceptions.h b/libdevcore/Exceptions.h index 37cdbed9..4817e9e3 100644 --- a/libdevcore/Exceptions.h +++ b/libdevcore/Exceptions.h @@ -56,9 +56,5 @@ DEV_SIMPLE_EXCEPTION(FileError); // error information to be added to exceptions using errinfo_invalidSymbol = boost::error_info; using errinfo_comment = boost::error_info; -using errinfo_required = boost::error_info; -using errinfo_got = boost::error_info; -using errinfo_required_h256 = boost::error_info; -using errinfo_got_h256 = boost::error_info; } -- cgit v1.2.3 From d5f8ce90c7a76870e5a9d0fe6f9fd709a7383572 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 21 Jun 2017 21:50:57 +0100 Subject: Merge interface/Exceptions and interface/Utils --- libjulia/backends/evm/EVMAssembly.cpp | 2 +- libjulia/backends/evm/EVMCodeTransform.cpp | 2 +- libsolidity/ast/AST.cpp | 2 -- libsolidity/ast/AST.h | 1 - libsolidity/ast/ASTJsonConverter.cpp | 1 - libsolidity/ast/ASTJsonConverter.h | 1 - libsolidity/ast/Types.cpp | 1 - libsolidity/codegen/ArrayUtils.cpp | 2 +- libsolidity/codegen/ExpressionCompiler.cpp | 1 + libsolidity/codegen/ExpressionCompiler.h | 2 +- libsolidity/inlineasm/AsmAnalysis.cpp | 1 - libsolidity/inlineasm/AsmPrinter.cpp | 2 +- libsolidity/inlineasm/AsmScopeFiller.cpp | 2 +- libsolidity/interface/Exceptions.cpp | 1 - libsolidity/interface/Exceptions.h | 11 ++++++++ libsolidity/interface/Utils.h | 45 ------------------------------ libsolidity/interface/Version.cpp | 2 +- libsolidity/parsing/DocStringParser.cpp | 2 +- libsolidity/parsing/Scanner.cpp | 2 +- libsolidity/parsing/Token.h | 1 - 20 files changed, 21 insertions(+), 63 deletions(-) delete mode 100644 libsolidity/interface/Utils.h diff --git a/libjulia/backends/evm/EVMAssembly.cpp b/libjulia/backends/evm/EVMAssembly.cpp index daca2393..7ec26957 100644 --- a/libjulia/backends/evm/EVMAssembly.cpp +++ b/libjulia/backends/evm/EVMAssembly.cpp @@ -22,7 +22,7 @@ #include -#include +#include using namespace std; using namespace dev; diff --git a/libjulia/backends/evm/EVMCodeTransform.cpp b/libjulia/backends/evm/EVMCodeTransform.cpp index b231ecec..8f12bc25 100644 --- a/libjulia/backends/evm/EVMCodeTransform.cpp +++ b/libjulia/backends/evm/EVMCodeTransform.cpp @@ -23,7 +23,7 @@ #include #include -#include +#include #include diff --git a/libsolidity/ast/AST.cpp b/libsolidity/ast/AST.cpp index 03112d2d..40dfa348 100644 --- a/libsolidity/ast/AST.cpp +++ b/libsolidity/ast/AST.cpp @@ -20,10 +20,8 @@ * Solidity abstract syntax tree. */ -#include #include #include -#include #include #include diff --git a/libsolidity/ast/AST.h b/libsolidity/ast/AST.h index ba1d0589..83572692 100644 --- a/libsolidity/ast/AST.h +++ b/libsolidity/ast/AST.h @@ -29,7 +29,6 @@ #include #include #include -#include #include #include #include diff --git a/libsolidity/ast/ASTJsonConverter.cpp b/libsolidity/ast/ASTJsonConverter.cpp index 4ad1f962..a90debb2 100644 --- a/libsolidity/ast/ASTJsonConverter.cpp +++ b/libsolidity/ast/ASTJsonConverter.cpp @@ -24,7 +24,6 @@ #include #include #include -#include #include #include diff --git a/libsolidity/ast/ASTJsonConverter.h b/libsolidity/ast/ASTJsonConverter.h index c2de5c48..27114c2a 100644 --- a/libsolidity/ast/ASTJsonConverter.h +++ b/libsolidity/ast/ASTJsonConverter.h @@ -26,7 +26,6 @@ #include #include #include -#include #include #include diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index cfee041e..bd3346f9 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -22,7 +22,6 @@ #include -#include #include #include diff --git a/libsolidity/codegen/ArrayUtils.cpp b/libsolidity/codegen/ArrayUtils.cpp index 6a641b02..67ca22f1 100644 --- a/libsolidity/codegen/ArrayUtils.cpp +++ b/libsolidity/codegen/ArrayUtils.cpp @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include using namespace std; diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp index 25154bc0..03bba80c 100644 --- a/libsolidity/codegen/ExpressionCompiler.cpp +++ b/libsolidity/codegen/ExpressionCompiler.cpp @@ -32,6 +32,7 @@ #include #include #include + using namespace std; namespace dev diff --git a/libsolidity/codegen/ExpressionCompiler.h b/libsolidity/codegen/ExpressionCompiler.h index d0a8ac15..3b8cf1c6 100644 --- a/libsolidity/codegen/ExpressionCompiler.h +++ b/libsolidity/codegen/ExpressionCompiler.h @@ -28,7 +28,7 @@ #include #include #include -#include +#include namespace dev { namespace eth diff --git a/libsolidity/inlineasm/AsmAnalysis.cpp b/libsolidity/inlineasm/AsmAnalysis.cpp index 2891ec95..b0d044ae 100644 --- a/libsolidity/inlineasm/AsmAnalysis.cpp +++ b/libsolidity/inlineasm/AsmAnalysis.cpp @@ -26,7 +26,6 @@ #include #include -#include #include #include diff --git a/libsolidity/inlineasm/AsmPrinter.cpp b/libsolidity/inlineasm/AsmPrinter.cpp index 0d06fedd..062ff453 100644 --- a/libsolidity/inlineasm/AsmPrinter.cpp +++ b/libsolidity/inlineasm/AsmPrinter.cpp @@ -22,7 +22,7 @@ #include #include -#include +#include #include #include diff --git a/libsolidity/inlineasm/AsmScopeFiller.cpp b/libsolidity/inlineasm/AsmScopeFiller.cpp index 3bef9cec..5b3174b8 100644 --- a/libsolidity/inlineasm/AsmScopeFiller.cpp +++ b/libsolidity/inlineasm/AsmScopeFiller.cpp @@ -25,7 +25,7 @@ #include #include -#include +#include #include diff --git a/libsolidity/interface/Exceptions.cpp b/libsolidity/interface/Exceptions.cpp index c09180de..deee92aa 100644 --- a/libsolidity/interface/Exceptions.cpp +++ b/libsolidity/interface/Exceptions.cpp @@ -21,7 +21,6 @@ */ #include -#include using namespace std; using namespace dev; diff --git a/libsolidity/interface/Exceptions.h b/libsolidity/interface/Exceptions.h index 0803d8cc..5fdb8f11 100644 --- a/libsolidity/interface/Exceptions.h +++ b/libsolidity/interface/Exceptions.h @@ -25,6 +25,7 @@ #include #include #include +#include #include namespace dev @@ -39,6 +40,16 @@ struct InternalCompilerError: virtual Exception {}; struct FatalError: virtual Exception {}; struct UnimplementedFeatureError: virtual Exception{}; +/// Assertion that throws an InternalCompilerError containing the given description if it is not met. +#define solAssert(CONDITION, DESCRIPTION) \ + assertThrow(CONDITION, ::dev::solidity::InternalCompilerError, DESCRIPTION) + +#define solUnimplementedAssert(CONDITION, DESCRIPTION) \ + assertThrow(CONDITION, ::dev::solidity::UnimplementedFeatureError, DESCRIPTION) + +#define solUnimplemented(DESCRIPTION) \ + solUnimplementedAssert(false, DESCRIPTION) + class Error: virtual public Exception { public: diff --git a/libsolidity/interface/Utils.h b/libsolidity/interface/Utils.h deleted file mode 100644 index 0027759c..00000000 --- a/libsolidity/interface/Utils.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - This file is part of solidity. - - solidity is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - solidity is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with solidity. If not, see . -*/ -/** - * @author Christian - * @date 2014 - * Solidity Utilities. - */ - -#pragma once - -#include -#include - -namespace dev -{ -namespace solidity -{ -struct InternalCompilerError; -struct UnimplementedFeatureError; -} -} - -/// Assertion that throws an InternalCompilerError containing the given description if it is not met. -#define solAssert(CONDITION, DESCRIPTION) \ - assertThrow(CONDITION, ::dev::solidity::InternalCompilerError, DESCRIPTION) - -#define solUnimplementedAssert(CONDITION, DESCRIPTION) \ - assertThrow(CONDITION, ::dev::solidity::UnimplementedFeatureError, DESCRIPTION) - -#define solUnimplemented(DESCRIPTION) \ - solUnimplementedAssert(false, DESCRIPTION) diff --git a/libsolidity/interface/Version.cpp b/libsolidity/interface/Version.cpp index 0d23f9c3..a35bfd29 100644 --- a/libsolidity/interface/Version.cpp +++ b/libsolidity/interface/Version.cpp @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include using namespace dev; diff --git a/libsolidity/parsing/DocStringParser.cpp b/libsolidity/parsing/DocStringParser.cpp index cd6c1d8a..0409de72 100644 --- a/libsolidity/parsing/DocStringParser.cpp +++ b/libsolidity/parsing/DocStringParser.cpp @@ -1,7 +1,7 @@ #include #include -#include +#include #include #include diff --git a/libsolidity/parsing/Scanner.cpp b/libsolidity/parsing/Scanner.cpp index 0e60fd0b..fdca23ea 100644 --- a/libsolidity/parsing/Scanner.cpp +++ b/libsolidity/parsing/Scanner.cpp @@ -52,7 +52,7 @@ #include #include -#include +#include #include using namespace std; diff --git a/libsolidity/parsing/Token.h b/libsolidity/parsing/Token.h index 9a557ebd..39c0eff9 100644 --- a/libsolidity/parsing/Token.h +++ b/libsolidity/parsing/Token.h @@ -43,7 +43,6 @@ #pragma once #include -#include #include #include -- cgit v1.2.3