From 4c8f8e949143d0c680a8257adbcc768d908fae9a Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Tue, 15 Jan 2019 13:40:10 +0100 Subject: Disallow mismatching types in switch cases and detect duplicates by value for number literals. --- libyul/optimiser/ExpressionJoiner.cpp | 2 +- libyul/optimiser/FullInliner.cpp | 2 +- libyul/optimiser/FunctionHoister.cpp | 2 +- .../InlinableExpressionFunctionFinder.cpp | 2 +- libyul/optimiser/OptimizerUtilities.cpp | 39 ++++++++++++++++++ libyul/optimiser/OptimizerUtilities.h | 32 +++++++++++++++ libyul/optimiser/SimplificationRules.cpp | 2 +- libyul/optimiser/StructuralSimplifier.cpp | 2 +- libyul/optimiser/UnusedPruner.cpp | 2 +- libyul/optimiser/Utilities.cpp | 48 ---------------------- libyul/optimiser/Utilities.h | 34 --------------- 11 files changed, 78 insertions(+), 89 deletions(-) create mode 100644 libyul/optimiser/OptimizerUtilities.cpp create mode 100644 libyul/optimiser/OptimizerUtilities.h delete mode 100644 libyul/optimiser/Utilities.cpp delete mode 100644 libyul/optimiser/Utilities.h (limited to 'libyul/optimiser') diff --git a/libyul/optimiser/ExpressionJoiner.cpp b/libyul/optimiser/ExpressionJoiner.cpp index de2b5d53..02ac4e45 100644 --- a/libyul/optimiser/ExpressionJoiner.cpp +++ b/libyul/optimiser/ExpressionJoiner.cpp @@ -22,7 +22,7 @@ #include #include -#include +#include #include #include diff --git a/libyul/optimiser/FullInliner.cpp b/libyul/optimiser/FullInliner.cpp index 1f267f96..dd969faf 100644 --- a/libyul/optimiser/FullInliner.cpp +++ b/libyul/optimiser/FullInliner.cpp @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/libyul/optimiser/FunctionHoister.cpp b/libyul/optimiser/FunctionHoister.cpp index bd1c781b..4863b94d 100644 --- a/libyul/optimiser/FunctionHoister.cpp +++ b/libyul/optimiser/FunctionHoister.cpp @@ -21,7 +21,7 @@ */ #include -#include +#include #include #include diff --git a/libyul/optimiser/InlinableExpressionFunctionFinder.cpp b/libyul/optimiser/InlinableExpressionFunctionFinder.cpp index 662cdf25..f57faa7c 100644 --- a/libyul/optimiser/InlinableExpressionFunctionFinder.cpp +++ b/libyul/optimiser/InlinableExpressionFunctionFinder.cpp @@ -20,7 +20,7 @@ #include -#include +#include #include using namespace std; diff --git a/libyul/optimiser/OptimizerUtilities.cpp b/libyul/optimiser/OptimizerUtilities.cpp new file mode 100644 index 00000000..f9571a4c --- /dev/null +++ b/libyul/optimiser/OptimizerUtilities.cpp @@ -0,0 +1,39 @@ +/* + 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 . +*/ +/** + * Some useful snippets for the optimiser. + */ + +#include + +#include + +#include + +#include + +using namespace std; +using namespace dev; +using namespace yul; + +void yul::removeEmptyBlocks(Block& _block) +{ + auto isEmptyBlock = [](Statement const& _st) -> bool { + return _st.type() == typeid(Block) && boost::get(_st).statements.empty(); + }; + boost::range::remove_erase_if(_block.statements, isEmptyBlock); +} diff --git a/libyul/optimiser/OptimizerUtilities.h b/libyul/optimiser/OptimizerUtilities.h new file mode 100644 index 00000000..449a1bc0 --- /dev/null +++ b/libyul/optimiser/OptimizerUtilities.h @@ -0,0 +1,32 @@ +/* + 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 . +*/ +/** + * Small useful snippets for the optimiser. + */ + +#pragma once + +#include +#include + +namespace yul +{ + +/// Removes statements that are just empty blocks (non-recursive). +void removeEmptyBlocks(Block& _block); + +} diff --git a/libyul/optimiser/SimplificationRules.cpp b/libyul/optimiser/SimplificationRules.cpp index da9c7d9d..037dad97 100644 --- a/libyul/optimiser/SimplificationRules.cpp +++ b/libyul/optimiser/SimplificationRules.cpp @@ -20,11 +20,11 @@ #include -#include #include #include #include #include +#include #include diff --git a/libyul/optimiser/StructuralSimplifier.cpp b/libyul/optimiser/StructuralSimplifier.cpp index bdf4cb2a..8d7dcd57 100644 --- a/libyul/optimiser/StructuralSimplifier.cpp +++ b/libyul/optimiser/StructuralSimplifier.cpp @@ -16,8 +16,8 @@ */ #include #include -#include #include +#include #include #include diff --git a/libyul/optimiser/UnusedPruner.cpp b/libyul/optimiser/UnusedPruner.cpp index 53c412e3..365b255c 100644 --- a/libyul/optimiser/UnusedPruner.cpp +++ b/libyul/optimiser/UnusedPruner.cpp @@ -22,7 +22,7 @@ #include #include -#include +#include #include #include diff --git a/libyul/optimiser/Utilities.cpp b/libyul/optimiser/Utilities.cpp deleted file mode 100644 index b3b580d5..00000000 --- a/libyul/optimiser/Utilities.cpp +++ /dev/null @@ -1,48 +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 . -*/ -/** - * Some useful snippets for the optimiser. - */ - -#include - -#include -#include - -#include - -#include - -using namespace std; -using namespace dev; -using namespace yul; - -void yul::removeEmptyBlocks(Block& _block) -{ - auto isEmptyBlock = [](Statement const& _st) -> bool { - return _st.type() == typeid(Block) && boost::get(_st).statements.empty(); - }; - boost::range::remove_erase_if(_block.statements, isEmptyBlock); -} - -u256 yul::valueOfNumberLiteral(Literal const& _literal) -{ - assertThrow(_literal.kind == LiteralKind::Number, OptimizerException, ""); - std::string const& literalString = _literal.value.str(); - assertThrow(isValidDecimal(literalString) || isValidHex(literalString), OptimizerException, ""); - return u256(literalString); -} diff --git a/libyul/optimiser/Utilities.h b/libyul/optimiser/Utilities.h deleted file mode 100644 index 1cfff62b..00000000 --- a/libyul/optimiser/Utilities.h +++ /dev/null @@ -1,34 +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 . -*/ -/** - * Small useful snippets for the optimiser. - */ - -#pragma once - -#include -#include - -namespace yul -{ - -/// Removes statements that are just empty blocks (non-recursive). -void removeEmptyBlocks(Block& _block); - -dev::u256 valueOfNumberLiteral(Literal const& _literal); - -} -- cgit v1.2.3