aboutsummaryrefslogtreecommitdiffstats
path: root/libjulia/optimiser/ASTCopier.h
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2017-11-28 19:45:37 +0800
committerchriseth <chris@ethereum.org>2017-12-05 19:09:52 +0800
commit861210f543cea615d7779fb7b1bc133349ae971a (patch)
treeaeee71e4ac8527221df8e10cd6241da406f2ca11 /libjulia/optimiser/ASTCopier.h
parent07101c13385dba6c103d9d0f51588638d94d5b81 (diff)
downloaddexon-solidity-861210f543cea615d7779fb7b1bc133349ae971a.tar.gz
dexon-solidity-861210f543cea615d7779fb7b1bc133349ae971a.tar.zst
dexon-solidity-861210f543cea615d7779fb7b1bc133349ae971a.zip
Disambiguator.
Diffstat (limited to 'libjulia/optimiser/ASTCopier.h')
-rw-r--r--libjulia/optimiser/ASTCopier.h101
1 files changed, 101 insertions, 0 deletions
diff --git a/libjulia/optimiser/ASTCopier.h b/libjulia/optimiser/ASTCopier.h
new file mode 100644
index 00000000..759dce31
--- /dev/null
+++ b/libjulia/optimiser/ASTCopier.h
@@ -0,0 +1,101 @@
+/*
+ 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 <http://www.gnu.org/licenses/>.
+*/
+/**
+ * Creates an independent copy of an AST, renaming identifiers to be unique.
+ */
+
+#pragma once
+
+#include <libjulia/ASTDataForward.h>
+
+#include <boost/variant.hpp>
+#include <boost/optional.hpp>
+
+#include <vector>
+#include <set>
+
+namespace dev
+{
+namespace julia
+{
+
+/**
+ * Creates a copy of a iulia AST potentially replacing identifier names.
+ * Base class to be extended.
+ */
+class ASTCopier: public boost::static_visitor<Statement>
+{
+public:
+ ASTCopier(Block const& _block):
+ m_block(_block)
+ {}
+
+ std::shared_ptr<Block> run();
+
+public:
+ Statement operator()(Literal const& _literal);
+ Statement operator()(Instruction const& _instruction);
+ Statement operator()(Identifier const& _identifier);
+ Statement operator()(FunctionalInstruction const& _instr);
+ Statement operator()(FunctionCall const&);
+ Statement operator()(Label const& _label);
+ Statement operator()(StackAssignment const& _assignment);
+ Statement operator()(Assignment const& _assignment);
+ Statement operator()(VariableDeclaration const& _varDecl);
+ Statement operator()(If const& _if);
+ Statement operator()(Switch const& _switch);
+ Statement operator()(FunctionDefinition const&);
+ Statement operator()(ForLoop const&);
+ Statement operator()(Block const& _block);
+
+protected:
+ template <typename T>
+ std::vector<T> translateVector(std::vector<T> const& _values);
+
+ template <typename T>
+ std::shared_ptr<T> translate(std::shared_ptr<T> const& _v)
+ {
+ return _v ? std::make_shared<T>(translate(*_v)) : nullptr;
+ }
+ Statement translate(Statement const& _statement);
+ Block translate(Block const& _block);
+ Case translate(Case const& _case);
+ Identifier translate(Identifier const& _identifier);
+ Literal translate(Literal const& _literal);
+ TypedName translate(TypedName const& _typedName);
+
+ virtual void enterScope(Block const& _block) = 0;
+ virtual void leaveScope(Block const& _block) = 0;
+ virtual void enterFunction(FunctionDefinition const& _function) = 0;
+ virtual void leaveFunction(FunctionDefinition const& _function) = 0;
+ virtual std::string translateIdentifier(std::string const& _name) { return _name; }
+
+ Block const& m_block;
+};
+
+template <typename T>
+std::vector<T> ASTCopier::translateVector(std::vector<T> const& _values)
+{
+ std::vector<T> translated;
+ for (auto const& v: _values)
+ translated.emplace_back(translate(v));
+ return translated;
+}
+
+
+}
+}