From d3c11a49e56b04e810ebc2f6c05a6fa9a929bb2d Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 8 Feb 2018 16:55:03 +0100 Subject: [PATCH] Move NameDispenser into its own file. --- libjulia/optimiser/FullInliner.cpp | 13 ---------- libjulia/optimiser/FullInliner.h | 8 +----- libjulia/optimiser/NameDispenser.cpp | 38 ++++++++++++++++++++++++++++ libjulia/optimiser/NameDispenser.h | 37 +++++++++++++++++++++++++++ 4 files changed, 76 insertions(+), 20 deletions(-) create mode 100644 libjulia/optimiser/NameDispenser.cpp create mode 100644 libjulia/optimiser/NameDispenser.h diff --git a/libjulia/optimiser/FullInliner.cpp b/libjulia/optimiser/FullInliner.cpp index 10955e940..30c537742 100644 --- a/libjulia/optimiser/FullInliner.cpp +++ b/libjulia/optimiser/FullInliner.cpp @@ -252,16 +252,3 @@ string BodyCopier::translateIdentifier(string const& _name) else return _name; } - -string NameDispenser::newName(string const& _prefix) -{ - string name = _prefix; - size_t suffix = 0; - while (name.empty() || m_usedNames.count(name)) - { - suffix++; - name = _prefix + "_" + std::to_string(suffix); - } - m_usedNames.insert(name); - return name; -} diff --git a/libjulia/optimiser/FullInliner.h b/libjulia/optimiser/FullInliner.h index d3dec3b20..d3628e1ac 100644 --- a/libjulia/optimiser/FullInliner.h +++ b/libjulia/optimiser/FullInliner.h @@ -23,6 +23,7 @@ #include #include +#include #include @@ -38,13 +39,6 @@ namespace julia class NameCollector; -struct NameDispenser -{ - std::string newName(std::string const& _prefix); - std::set m_usedNames; -}; - - /** * Optimiser component that modifies an AST in place, inlining arbitrary functions. diff --git a/libjulia/optimiser/NameDispenser.cpp b/libjulia/optimiser/NameDispenser.cpp new file mode 100644 index 000000000..e4f0e4f67 --- /dev/null +++ b/libjulia/optimiser/NameDispenser.cpp @@ -0,0 +1,38 @@ +/* + 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 . +*/ +/** + * Optimiser component that can create new unique names. + */ + +#include + +using namespace std; +using namespace dev; +using namespace dev::julia; + +string NameDispenser::newName(string const& _prefix) +{ + string name = _prefix; + size_t suffix = 0; + while (name.empty() || m_usedNames.count(name)) + { + suffix++; + name = _prefix + "_" + std::to_string(suffix); + } + m_usedNames.insert(name); + return name; +} diff --git a/libjulia/optimiser/NameDispenser.h b/libjulia/optimiser/NameDispenser.h new file mode 100644 index 000000000..91c43d549 --- /dev/null +++ b/libjulia/optimiser/NameDispenser.h @@ -0,0 +1,37 @@ +/* + 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 . +*/ +/** + * Optimiser component that can create new unique names. + */ +#pragma once + +#include +#include + +namespace dev +{ +namespace julia +{ + +struct NameDispenser +{ + std::string newName(std::string const& _prefix); + std::set m_usedNames; +}; + +} +}