diff options
author | chriseth <chris@ethereum.org> | 2018-11-22 07:31:01 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-22 07:31:01 +0800 |
commit | b5acc630089ba0e4c41cfb8548c82f157f9be6fc (patch) | |
tree | 9f95cd156ce58213c7412597568d096635c7d868 | |
parent | 7d8c1fc53b1eb318bb0eb0896dfd6ab77a11eb6e (diff) | |
parent | d67322a1861d60a88151f7c25d6c3478a9a39acf (diff) | |
download | dexon-solidity-b5acc630089ba0e4c41cfb8548c82f157f9be6fc.tar dexon-solidity-b5acc630089ba0e4c41cfb8548c82f157f9be6fc.tar.gz dexon-solidity-b5acc630089ba0e4c41cfb8548c82f157f9be6fc.tar.bz2 dexon-solidity-b5acc630089ba0e4c41cfb8548c82f157f9be6fc.tar.lz dexon-solidity-b5acc630089ba0e4c41cfb8548c82f157f9be6fc.tar.xz dexon-solidity-b5acc630089ba0e4c41cfb8548c82f157f9be6fc.tar.zst dexon-solidity-b5acc630089ba0e4c41cfb8548c82f157f9be6fc.zip |
Merge pull request #5427 from ethereum/liblangutil
Factor out langutil, a new static library that is shared between libyul/libsolidity
155 files changed, 1163 insertions, 829 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 86769672..ed51e5a7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,6 +45,7 @@ include(EthOptions) configure_project(TESTS) add_subdirectory(libdevcore) +add_subdirectory(liblangutil) add_subdirectory(libevmasm) add_subdirectory(libsolidity) add_subdirectory(libsolc) diff --git a/libevmasm/Assembly.cpp b/libevmasm/Assembly.cpp index e63194a0..d80f97c4 100644 --- a/libevmasm/Assembly.cpp +++ b/libevmasm/Assembly.cpp @@ -35,6 +35,7 @@ using namespace std; using namespace dev; using namespace dev::eth; +using namespace langutil; void Assembly::append(Assembly const& _a) { diff --git a/libevmasm/Assembly.h b/libevmasm/Assembly.h index 8ef36923..d846b475 100644 --- a/libevmasm/Assembly.h +++ b/libevmasm/Assembly.h @@ -18,12 +18,12 @@ #pragma once #include <libevmasm/Instruction.h> -#include <libevmasm/SourceLocation.h> +#include <liblangutil/SourceLocation.h> #include <libevmasm/AssemblyItem.h> #include <libevmasm/LinkerObject.h> #include <libevmasm/Exceptions.h> -#include <libsolidity/interface/EVMVersion.h> +#include <liblangutil/EVMVersion.h> #include <libdevcore/Common.h> #include <libdevcore/Assertions.h> @@ -93,7 +93,7 @@ public: void setDeposit(int _deposit) { m_deposit = _deposit; assertThrow(m_deposit >= 0, InvalidDeposit, ""); } /// Changes the source location used for each appended item. - void setSourceLocation(SourceLocation const& _location) { m_currentSourceLocation = _location; } + void setSourceLocation(langutil::SourceLocation const& _location) { m_currentSourceLocation = _location; } /// Assembles the assembly into bytecode. The assembly should not be modified after this call, since the assembled version is cached. LinkerObject const& assemble() const; @@ -178,7 +178,7 @@ protected: int m_deposit = 0; - SourceLocation m_currentSourceLocation; + langutil::SourceLocation m_currentSourceLocation; }; inline std::ostream& operator<<(std::ostream& _out, Assembly const& _a) diff --git a/libevmasm/AssemblyItem.h b/libevmasm/AssemblyItem.h index 6187e18f..a7875171 100644 --- a/libevmasm/AssemblyItem.h +++ b/libevmasm/AssemblyItem.h @@ -26,7 +26,7 @@ #include <libdevcore/Common.h> #include <libdevcore/Assertions.h> #include <libevmasm/Instruction.h> -#include <libevmasm/SourceLocation.h> +#include <liblangutil/SourceLocation.h> #include "Exceptions.h" using namespace dev::solidity; @@ -57,14 +57,14 @@ class AssemblyItem public: enum class JumpType { Ordinary, IntoFunction, OutOfFunction }; - AssemblyItem(u256 _push, SourceLocation const& _location = SourceLocation()): + AssemblyItem(u256 _push, langutil::SourceLocation const& _location = langutil::SourceLocation()): AssemblyItem(Push, _push, _location) { } - AssemblyItem(solidity::Instruction _i, SourceLocation const& _location = SourceLocation()): + AssemblyItem(solidity::Instruction _i, langutil::SourceLocation const& _location = langutil::SourceLocation()): m_type(Operation), m_instruction(_i), m_location(_location) {} - AssemblyItem(AssemblyItemType _type, u256 _data = 0, SourceLocation const& _location = SourceLocation()): + AssemblyItem(AssemblyItemType _type, u256 _data = 0, langutil::SourceLocation const& _location = langutil::SourceLocation()): m_type(_type), m_location(_location) { @@ -124,8 +124,8 @@ public: /// @returns true if the assembly item can be used in a functional context. bool canBeFunctional() const; - void setLocation(SourceLocation const& _location) { m_location = _location; } - SourceLocation const& location() const { return m_location; } + void setLocation(langutil::SourceLocation const& _location) { m_location = _location; } + langutil::SourceLocation const& location() const { return m_location; } void setJumpType(JumpType _jumpType) { m_jumpType = _jumpType; } JumpType getJumpType() const { return m_jumpType; } @@ -140,7 +140,7 @@ private: AssemblyItemType m_type; Instruction m_instruction; ///< Only valid if m_type == Operation std::shared_ptr<u256> m_data; ///< Only valid if m_type != Operation - SourceLocation m_location; + langutil::SourceLocation m_location; JumpType m_jumpType = JumpType::Ordinary; /// Pushed value for operations with data to be determined during assembly stage, /// e.g. PushSubSize, PushTag, PushSub, etc. diff --git a/libevmasm/CommonSubexpressionEliminator.cpp b/libevmasm/CommonSubexpressionEliminator.cpp index 04926986..949d2c75 100644 --- a/libevmasm/CommonSubexpressionEliminator.cpp +++ b/libevmasm/CommonSubexpressionEliminator.cpp @@ -30,6 +30,7 @@ using namespace std; using namespace dev; using namespace dev::eth; +using namespace langutil; vector<AssemblyItem> CommonSubexpressionEliminator::getOptimizedItems() { diff --git a/libevmasm/CommonSubexpressionEliminator.h b/libevmasm/CommonSubexpressionEliminator.h index b20de246..eba25db0 100644 --- a/libevmasm/CommonSubexpressionEliminator.h +++ b/libevmasm/CommonSubexpressionEliminator.h @@ -34,6 +34,11 @@ #include <libevmasm/SemanticInformation.h> #include <libevmasm/KnownState.h> +namespace langutil +{ +struct SourceLocation; +} + namespace dev { namespace eth @@ -137,10 +142,10 @@ private: bool removeStackTopIfPossible(); /// Appends a dup instruction to m_generatedItems to retrieve the element at the given stack position. - void appendDup(int _fromPosition, SourceLocation const& _location); + void appendDup(int _fromPosition, langutil::SourceLocation const& _location); /// Appends a swap instruction to m_generatedItems to retrieve the element at the given stack position. /// @note this might also remove the last item if it exactly the same swap instruction. - void appendOrRemoveSwap(int _fromPosition, SourceLocation const& _location); + void appendOrRemoveSwap(int _fromPosition, langutil::SourceLocation const& _location); /// Appends the given assembly item. void appendItem(AssemblyItem const& _item); diff --git a/libevmasm/ConstantOptimiser.h b/libevmasm/ConstantOptimiser.h index 2c2b87a0..04c43c5d 100644 --- a/libevmasm/ConstantOptimiser.h +++ b/libevmasm/ConstantOptimiser.h @@ -23,7 +23,7 @@ #include <libevmasm/Exceptions.h> -#include <libsolidity/interface/EVMVersion.h> +#include <liblangutil/EVMVersion.h> #include <libdevcore/Assertions.h> #include <libdevcore/CommonData.h> diff --git a/libevmasm/ControlFlowGraph.cpp b/libevmasm/ControlFlowGraph.cpp index 86f16d48..d62f5436 100644 --- a/libevmasm/ControlFlowGraph.cpp +++ b/libevmasm/ControlFlowGraph.cpp @@ -275,7 +275,7 @@ void ControlFlowGraph::gatherKnowledge() //@todo in the case of JUMPI, add knowledge about the condition to the state // (for both values of the condition) set<u256> tags = state->tagsInExpression( - state->stackElement(state->stackHeight(), SourceLocation()) + state->stackElement(state->stackHeight(), langutil::SourceLocation{}) ); state->feedItem(m_items.at(pc++)); diff --git a/libevmasm/ExpressionClasses.cpp b/libevmasm/ExpressionClasses.cpp index 42a1819a..abbbbc2c 100644 --- a/libevmasm/ExpressionClasses.cpp +++ b/libevmasm/ExpressionClasses.cpp @@ -34,7 +34,7 @@ using namespace std; using namespace dev; using namespace dev::eth; - +using namespace langutil; bool ExpressionClasses::Expression::operator<(ExpressionClasses::Expression const& _other) const { diff --git a/libevmasm/ExpressionClasses.h b/libevmasm/ExpressionClasses.h index df8082f9..a34844c5 100644 --- a/libevmasm/ExpressionClasses.h +++ b/libevmasm/ExpressionClasses.h @@ -31,6 +31,11 @@ #include <memory> #include <set> +namespace langutil +{ +struct SourceLocation; +} + namespace dev { namespace eth @@ -82,7 +87,7 @@ public: void forceEqual(Id _id, AssemblyItem const& _item, Ids const& _arguments, bool _copyItem = true); /// @returns the id of a new class which is different to all other classes. - Id newClass(SourceLocation const& _location); + Id newClass(langutil::SourceLocation const& _location); /// @returns true if the values of the given classes are known to be different (on every input). /// @note that this function might still return false for some different inputs. diff --git a/libevmasm/GasMeter.h b/libevmasm/GasMeter.h index da90b028..e3909e86 100644 --- a/libevmasm/GasMeter.h +++ b/libevmasm/GasMeter.h @@ -24,7 +24,7 @@ #include <libevmasm/ExpressionClasses.h> #include <libevmasm/AssemblyItem.h> -#include <libsolidity/interface/EVMVersion.h> +#include <liblangutil/EVMVersion.h> #include <ostream> #include <tuple> diff --git a/libevmasm/KnownState.cpp b/libevmasm/KnownState.cpp index b6c1bcc9..a5546e61 100644 --- a/libevmasm/KnownState.cpp +++ b/libevmasm/KnownState.cpp @@ -29,6 +29,7 @@ using namespace std; using namespace dev; using namespace dev::eth; +using namespace langutil; ostream& KnownState::stream(ostream& _out) const { diff --git a/libevmasm/KnownState.h b/libevmasm/KnownState.h index cd50550e..3ab1c4b1 100644 --- a/libevmasm/KnownState.h +++ b/libevmasm/KnownState.h @@ -46,6 +46,11 @@ #include <libevmasm/ExpressionClasses.h> #include <libevmasm/SemanticInformation.h> +namespace langutil +{ +struct SourceLocation; +} + namespace dev { namespace eth @@ -121,9 +126,9 @@ public: /// Retrieves the current equivalence class fo the given stack element (or generates a new /// one if it does not exist yet). - Id stackElement(int _stackHeight, SourceLocation const& _location); + Id stackElement(int _stackHeight, langutil::SourceLocation const& _location); /// @returns the stackElement relative to the current stack height. - Id relativeStackElement(int _stackOffset, SourceLocation const& _location = SourceLocation()); + Id relativeStackElement(int _stackOffset, langutil::SourceLocation const& _location = {}); /// @returns its set of tags if the given expression class is a known tag union; returns a set /// containing the tag if it is a PushTag expression and the empty set otherwise. @@ -142,22 +147,22 @@ private: /// Assigns a new equivalence class to the next sequence number of the given stack element. void setStackElement(int _stackHeight, Id _class); /// Swaps the given stack elements in their next sequence number. - void swapStackElements(int _stackHeightA, int _stackHeightB, SourceLocation const& _location); + void swapStackElements(int _stackHeightA, int _stackHeightB, langutil::SourceLocation const& _location); /// Increments the sequence number, deletes all storage information that might be overwritten /// and stores the new value at the given slot. /// @returns the store operation, which might be invalid if storage was not modified - StoreOperation storeInStorage(Id _slot, Id _value, SourceLocation const& _location); + StoreOperation storeInStorage(Id _slot, Id _value, langutil::SourceLocation const& _location); /// Retrieves the current value at the given slot in storage or creates a new special sload class. - Id loadFromStorage(Id _slot, SourceLocation const& _location); + Id loadFromStorage(Id _slot, langutil::SourceLocation const& _location); /// Increments the sequence number, deletes all memory information that might be overwritten /// and stores the new value at the given slot. /// @returns the store operation, which might be invalid if memory was not modified - StoreOperation storeInMemory(Id _slot, Id _value, SourceLocation const& _location); + StoreOperation storeInMemory(Id _slot, Id _value, langutil::SourceLocation const& _location); /// Retrieves the current value at the given slot in memory or creates a new special mload class. - Id loadFromMemory(Id _slot, SourceLocation const& _location); + Id loadFromMemory(Id _slot, langutil::SourceLocation const& _location); /// Finds or creates a new expression that applies the Keccak-256 hash function to the contents in memory. - Id applyKeccak256(Id _start, Id _length, SourceLocation const& _location); + Id applyKeccak256(Id _start, Id _length, langutil::SourceLocation const& _location); /// @returns a new or already used Id representing the given set of tags. Id tagUnion(std::set<u256> _tags); diff --git a/libevmasm/PathGasMeter.h b/libevmasm/PathGasMeter.h index fb821684..772df484 100644 --- a/libevmasm/PathGasMeter.h +++ b/libevmasm/PathGasMeter.h @@ -23,7 +23,7 @@ #include <libevmasm/GasMeter.h> -#include <libsolidity/interface/EVMVersion.h> +#include <liblangutil/EVMVersion.h> #include <set> #include <vector> diff --git a/libevmasm/SimplificationRules.cpp b/libevmasm/SimplificationRules.cpp index 120d1787..1dce5f1e 100644 --- a/libevmasm/SimplificationRules.cpp +++ b/libevmasm/SimplificationRules.cpp @@ -38,7 +38,7 @@ using namespace std; using namespace dev; using namespace dev::eth; - +using namespace langutil; SimplificationRule<Pattern> const* Rules::findFirstMatch( Expression const& _expr, diff --git a/libevmasm/SimplificationRules.h b/libevmasm/SimplificationRules.h index fbe5a2b0..fc45a46c 100644 --- a/libevmasm/SimplificationRules.h +++ b/libevmasm/SimplificationRules.h @@ -31,6 +31,11 @@ #include <functional> #include <vector> +namespace langutil +{ +struct SourceLocation; +} + namespace dev { namespace eth @@ -97,7 +102,7 @@ public: unsigned matchGroup() const { return m_matchGroup; } bool matches(Expression const& _expr, ExpressionClasses const& _classes) const; - AssemblyItem toAssemblyItem(SourceLocation const& _location) const; + AssemblyItem toAssemblyItem(langutil::SourceLocation const& _location) const; std::vector<Pattern> arguments() const { return m_arguments; } /// @returns the id of the matched expression if this pattern is part of a match group. @@ -135,7 +140,7 @@ struct ExpressionTemplate { using Expression = ExpressionClasses::Expression; using Id = ExpressionClasses::Id; - explicit ExpressionTemplate(Pattern const& _pattern, SourceLocation const& _location); + explicit ExpressionTemplate(Pattern const& _pattern, langutil::SourceLocation const& _location); std::string toString() const; bool hasId = false; /// Id of the matched expression, if available. diff --git a/liblangutil/CMakeLists.txt b/liblangutil/CMakeLists.txt new file mode 100644 index 00000000..722ca840 --- /dev/null +++ b/liblangutil/CMakeLists.txt @@ -0,0 +1,6 @@ +# Solidity Commons Library (Solidity related sharing bits between libsolidity and libyul) +file(GLOB sources "*.cpp") +file(GLOB headers "*.h") + +add_library(langutil ${sources} ${headers}) +target_link_libraries(langutil PUBLIC devcore) diff --git a/liblangutil/CharStream.cpp b/liblangutil/CharStream.cpp new file mode 100644 index 00000000..aee7cb3e --- /dev/null +++ b/liblangutil/CharStream.cpp @@ -0,0 +1,108 @@ +/* + 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/>. + + This file is derived from the file "scanner.cc", which was part of the + V8 project. The original copyright header follows: + + Copyright 2006-2012, the V8 project authors. All rights reserved. + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + * Neither the name of Google Inc. nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/** + * @author Christian <c@ethdev.com> + * @date 2014 + * Solidity scanner. + */ + +#include <liblangutil/CharStream.h> +#include <liblangutil/Exceptions.h> + +using namespace std; +using namespace langutil; + +char CharStream::advanceAndGet(size_t _chars) +{ + if (isPastEndOfInput()) + return 0; + m_position += _chars; + if (isPastEndOfInput()) + return 0; + return m_source[m_position]; +} + +char CharStream::rollback(size_t _amount) +{ + solAssert(m_position >= _amount, ""); + m_position -= _amount; + return get(); +} + +string CharStream::lineAtPosition(int _position) const +{ + // if _position points to \n, it returns the line before the \n + using size_type = string::size_type; + size_type searchStart = min<size_type>(m_source.size(), _position); + if (searchStart > 0) + searchStart--; + size_type lineStart = m_source.rfind('\n', searchStart); + if (lineStart == string::npos) + lineStart = 0; + else + lineStart++; + return m_source.substr(lineStart, min(m_source.find('\n', lineStart), + m_source.size()) - lineStart); +} + +tuple<int, int> CharStream::translatePositionToLineColumn(int _position) const +{ + using size_type = string::size_type; + size_type searchPosition = min<size_type>(m_source.size(), _position); + int lineNumber = count(m_source.begin(), m_source.begin() + searchPosition, '\n'); + size_type lineStart; + if (searchPosition == 0) + lineStart = 0; + else + { + lineStart = m_source.rfind('\n', searchPosition - 1); + lineStart = lineStart == string::npos ? 0 : lineStart + 1; + } + return tuple<int, int>(lineNumber, searchPosition - lineStart); +} + + diff --git a/liblangutil/CharStream.h b/liblangutil/CharStream.h new file mode 100644 index 00000000..72aacacf --- /dev/null +++ b/liblangutil/CharStream.h @@ -0,0 +1,97 @@ +/* + 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/>. + + This file is derived from the file "scanner.h", which was part of the + V8 project. The original copyright header follows: + + Copyright 2006-2012, the V8 project authors. All rights reserved. + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + * Neither the name of Google Inc. nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/** + * @author Christian <c@ethdev.com> + * @date 2014 + * Solidity scanner. + */ + +#pragma once + +#include <cstdint> +#include <string> +#include <tuple> + +namespace langutil +{ + +/** + * Bidirectional stream of characters. + * + * This CharStream is used by lexical analyzers as the source. + */ +class CharStream +{ +public: + CharStream(): m_position(0) {} + explicit CharStream(std::string const& _source): m_source(_source), m_position(0) {} + + int position() const { return m_position; } + bool isPastEndOfInput(size_t _charsForward = 0) const { return (m_position + _charsForward) >= m_source.size(); } + + char get(size_t _charsForward = 0) const { return m_source[m_position + _charsForward]; } + char advanceAndGet(size_t _chars = 1); + char rollback(size_t _amount); + + void reset() { m_position = 0; } + + std::string const& source() const { return m_source; } + + ///@{ + ///@name Error printing helper functions + /// Functions that help pretty-printing parse errors + /// Do only use in error cases, they are quite expensive. + std::string lineAtPosition(int _position) const; + std::tuple<int, int> translatePositionToLineColumn(int _position) const; + ///@} + +private: + std::string m_source; + size_t m_position; +}; + +} diff --git a/libsolidity/interface/EVMVersion.h b/liblangutil/EVMVersion.h index 657727ac..657727ac 100644 --- a/libsolidity/interface/EVMVersion.h +++ b/liblangutil/EVMVersion.h diff --git a/libsolidity/interface/ErrorReporter.cpp b/liblangutil/ErrorReporter.cpp index 368e25e0..5b6e0072 100644 --- a/libsolidity/interface/ErrorReporter.cpp +++ b/liblangutil/ErrorReporter.cpp @@ -20,13 +20,13 @@ * Error helper class. */ -#include <libsolidity/interface/ErrorReporter.h> -#include <libsolidity/ast/AST.h> +#include <liblangutil/ErrorReporter.h> +#include <liblangutil/SourceLocation.h> #include <memory> using namespace std; using namespace dev; -using namespace dev::solidity; +using namespace langutil; ErrorReporter& ErrorReporter::operator=(ErrorReporter const& _errorReporter) { diff --git a/libsolidity/interface/ErrorReporter.h b/liblangutil/ErrorReporter.h index fd53587a..d90e652e 100644 --- a/libsolidity/interface/ErrorReporter.h +++ b/liblangutil/ErrorReporter.h @@ -22,15 +22,11 @@ #pragma once -#include <libsolidity/interface/Exceptions.h> -#include <libevmasm/SourceLocation.h> +#include <liblangutil/Exceptions.h> +#include <liblangutil/SourceLocation.h> -namespace dev +namespace langutil { -namespace solidity -{ - -class ASTNode; class ErrorReporter { @@ -120,7 +116,5 @@ private: const unsigned c_maxErrorsAllowed = 256; }; - -} } diff --git a/libsolidity/interface/Exceptions.cpp b/liblangutil/Exceptions.cpp index ecadd0b7..346313d5 100644 --- a/libsolidity/interface/Exceptions.cpp +++ b/liblangutil/Exceptions.cpp @@ -20,11 +20,11 @@ * Solidity exception hierarchy. */ -#include <libsolidity/interface/Exceptions.h> +#include <liblangutil/Exceptions.h> using namespace std; using namespace dev; -using namespace dev::solidity; +using namespace langutil; Error::Error(Type _type, SourceLocation const& _location, string const& _description): m_type(_type) diff --git a/libsolidity/interface/Exceptions.h b/liblangutil/Exceptions.h index 629b8f3f..5ad31ab2 100644 --- a/libsolidity/interface/Exceptions.h +++ b/liblangutil/Exceptions.h @@ -24,33 +24,33 @@ #include <string> #include <utility> +#include <vector> +#include <memory> #include <libdevcore/Exceptions.h> #include <libdevcore/Assertions.h> -#include <libevmasm/SourceLocation.h> +#include <liblangutil/SourceLocation.h> -namespace dev -{ -namespace solidity +namespace langutil { class Error; using ErrorList = std::vector<std::shared_ptr<Error const>>; -struct CompilerError: virtual Exception {}; -struct InternalCompilerError: virtual Exception {}; -struct FatalError: virtual Exception {}; -struct UnimplementedFeatureError: virtual Exception{}; +struct CompilerError: virtual dev::Exception {}; +struct InternalCompilerError: virtual dev::Exception {}; +struct FatalError: virtual dev::Exception {}; +struct UnimplementedFeatureError: virtual dev::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) + assertThrow(CONDITION, ::langutil::InternalCompilerError, DESCRIPTION) #define solUnimplementedAssert(CONDITION, DESCRIPTION) \ - assertThrow(CONDITION, ::dev::solidity::UnimplementedFeatureError, DESCRIPTION) + assertThrow(CONDITION, ::langutil::UnimplementedFeatureError, DESCRIPTION) #define solUnimplemented(DESCRIPTION) \ solUnimplementedAssert(false, DESCRIPTION) -class Error: virtual public Exception +class Error: virtual public dev::Exception { public: enum class Type @@ -98,7 +98,6 @@ private: std::string m_typeName; }; - using errorSourceLocationInfo = std::pair<std::string, SourceLocation>; class SecondarySourceLocation @@ -109,6 +108,7 @@ public: infos.push_back(std::make_pair(_errMsg, _sourceLocation)); return *this; } + /// Limits the number of secondary source locations to 32 and appends a notice to the /// error message. void limitSize(std::string& _message) @@ -124,9 +124,8 @@ public: std::vector<errorSourceLocationInfo> infos; }; - using errinfo_sourceLocation = boost::error_info<struct tag_sourceLocation, SourceLocation>; using errinfo_secondarySourceLocation = boost::error_info<struct tag_secondarySourceLocation, SecondarySourceLocation>; -} + } diff --git a/libsolidity/parsing/ParserBase.cpp b/liblangutil/ParserBase.cpp index 1d4cb1e2..8156f9b9 100644 --- a/libsolidity/parsing/ParserBase.cpp +++ b/liblangutil/ParserBase.cpp @@ -20,13 +20,12 @@ * Solidity parser shared functionality. */ -#include <libsolidity/parsing/ParserBase.h> -#include <libsolidity/parsing/Scanner.h> -#include <libsolidity/interface/ErrorReporter.h> +#include <liblangutil/ParserBase.h> +#include <liblangutil/Scanner.h> +#include <liblangutil/ErrorReporter.h> using namespace std; -using namespace dev; -using namespace dev::solidity; +using namespace langutil; std::shared_ptr<string const> const& ParserBase::sourceName() const { diff --git a/libsolidity/parsing/ParserBase.h b/liblangutil/ParserBase.h index e01f37d8..3ecabed5 100644 --- a/libsolidity/parsing/ParserBase.h +++ b/liblangutil/ParserBase.h @@ -22,12 +22,11 @@ #pragma once +#include <liblangutil/Token.h> #include <memory> -#include <libsolidity/parsing/Token.h> +#include <string> -namespace dev -{ -namespace solidity +namespace langutil { class ErrorReporter; @@ -90,4 +89,3 @@ protected: }; } -} diff --git a/libsolidity/parsing/Scanner.cpp b/liblangutil/Scanner.cpp index e9dad2ad..3d7527d4 100644 --- a/libsolidity/parsing/Scanner.cpp +++ b/liblangutil/Scanner.cpp @@ -50,16 +50,14 @@ * Solidity scanner. */ +#include <liblangutil/Exceptions.h> +#include <liblangutil/Scanner.h> #include <algorithm> #include <tuple> -#include <libsolidity/interface/Exceptions.h> -#include <libsolidity/parsing/Scanner.h> using namespace std; -namespace dev -{ -namespace solidity +namespace langutil { namespace @@ -143,10 +141,10 @@ private: }; // end of LiteralScope class -void Scanner::reset(CharStream const& _source, string const& _sourceName) +void Scanner::reset(CharStream _source, string _sourceName) { - m_source = _source; - m_sourceName = make_shared<string const>(_sourceName); + m_source = std::move(_source); + m_sourceName = make_shared<string const>(std::move(_sourceName)); reset(); } @@ -866,55 +864,5 @@ tuple<Token, unsigned, unsigned> Scanner::scanIdentifierOrKeyword() return TokenTraits::fromIdentifierOrKeyword(m_nextToken.literal); } -char CharStream::advanceAndGet(size_t _chars) -{ - if (isPastEndOfInput()) - return 0; - m_position += _chars; - if (isPastEndOfInput()) - return 0; - return m_source[m_position]; -} - -char CharStream::rollback(size_t _amount) -{ - solAssert(m_position >= _amount, ""); - m_position -= _amount; - return get(); -} - -string CharStream::lineAtPosition(int _position) const -{ - // if _position points to \n, it returns the line before the \n - using size_type = string::size_type; - size_type searchStart = min<size_type>(m_source.size(), _position); - if (searchStart > 0) - searchStart--; - size_type lineStart = m_source.rfind('\n', searchStart); - if (lineStart == string::npos) - lineStart = 0; - else - lineStart++; - return m_source.substr(lineStart, min(m_source.find('\n', lineStart), - m_source.size()) - lineStart); -} - -tuple<int, int> CharStream::translatePositionToLineColumn(int _position) const -{ - using size_type = string::size_type; - size_type searchPosition = min<size_type>(m_source.size(), _position); - int lineNumber = count(m_source.begin(), m_source.begin() + searchPosition, '\n'); - size_type lineStart; - if (searchPosition == 0) - lineStart = 0; - else - { - lineStart = m_source.rfind('\n', searchPosition - 1); - lineStart = lineStart == string::npos ? 0 : lineStart + 1; - } - return tuple<int, int>(lineNumber, searchPosition - lineStart); -} - -} } diff --git a/libsolidity/parsing/Scanner.h b/liblangutil/Scanner.h index 14eeb66e..da5e3dfb 100644 --- a/libsolidity/parsing/Scanner.h +++ b/liblangutil/Scanner.h @@ -52,62 +52,29 @@ #pragma once +#include <liblangutil/Token.h> +#include <liblangutil/CharStream.h> +#include <liblangutil/SourceLocation.h> #include <libdevcore/Common.h> #include <libdevcore/CommonData.h> -#include <libevmasm/SourceLocation.h> -#include <libsolidity/parsing/Token.h> -namespace dev +namespace langutil { -namespace solidity -{ - class AstRawString; class AstValueFactory; class ParserRecorder; -class CharStream -{ -public: - CharStream(): m_position(0) {} - explicit CharStream(std::string const& _source): m_source(_source), m_position(0) {} - int position() const { return m_position; } - bool isPastEndOfInput(size_t _charsForward = 0) const { return (m_position + _charsForward) >= m_source.size(); } - char get(size_t _charsForward = 0) const { return m_source[m_position + _charsForward]; } - char advanceAndGet(size_t _chars = 1); - char rollback(size_t _amount); - - void reset() { m_position = 0; } - - std::string const& source() const { return m_source; } - - ///@{ - ///@name Error printing helper functions - /// Functions that help pretty-printing parse errors - /// Do only use in error cases, they are quite expensive. - std::string lineAtPosition(int _position) const; - std::tuple<int, int> translatePositionToLineColumn(int _position) const; - ///@} - -private: - std::string m_source; - size_t m_position; -}; - - - class Scanner { friend class LiteralScope; public: - - explicit Scanner(CharStream const& _source = CharStream(), std::string const& _sourceName = "") { reset(_source, _sourceName); } + explicit Scanner(CharStream _source = CharStream(), std::string _sourceName = "") { reset(std::move(_source), std::move(_sourceName)); } std::string source() const { return m_source.source(); } /// Resets the scanner as if newly constructed with _source and _sourceName as input. - void reset(CharStream const& _source, std::string const& _sourceName); + void reset(CharStream _source, std::string _sourceName); /// Resets scanner to the start of input. void reset(); @@ -246,4 +213,3 @@ private: }; } -} diff --git a/libevmasm/SourceLocation.h b/liblangutil/SourceLocation.h index b42c3aa9..eeb81e94 100644 --- a/libevmasm/SourceLocation.h +++ b/liblangutil/SourceLocation.h @@ -22,13 +22,13 @@ #pragma once +#include <libdevcore/Common.h> // defines noexcept macro for MSVC #include <memory> #include <string> #include <ostream> #include <tuple> -#include <libdevcore/Common.h> // defines noexcept macro for MSVC -namespace dev +namespace langutil { /** diff --git a/libsolidity/parsing/Token.cpp b/liblangutil/Token.cpp index dccd9037..cbfd4a8c 100644 --- a/libsolidity/parsing/Token.cpp +++ b/liblangutil/Token.cpp @@ -40,15 +40,13 @@ // You should have received a copy of the GNU General Public License // along with solidity. If not, see <http://www.gnu.org/licenses/>. -#include <map> -#include <libsolidity/parsing/Token.h> +#include <liblangutil/Token.h> #include <boost/range/iterator_range.hpp> +#include <map> using namespace std; -namespace dev -{ -namespace solidity +namespace langutil { void ElementaryTypeNameToken::assertDetails(Token _baseType, unsigned const& _first, unsigned const& _second) @@ -204,4 +202,3 @@ tuple<Token, unsigned int, unsigned int> fromIdentifierOrKeyword(string const& _ } } -} diff --git a/liblangutil/Token.h b/liblangutil/Token.h new file mode 100644 index 00000000..0b7d9f71 --- /dev/null +++ b/liblangutil/Token.h @@ -0,0 +1,378 @@ +// Copyright 2006-2012, the V8 project authors. All rights reserved. +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following +// disclaimer in the documentation and/or other materials provided +// with the distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Modifications as part of solidity under the following license: +// +// 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/>. + +#pragma once + +#include <libdevcore/Common.h> +#include <liblangutil/Exceptions.h> +#include <liblangutil/UndefMacros.h> + +#include <iosfwd> +#include <string> +#include <tuple> + +namespace langutil +{ + +// TOKEN_LIST takes a list of 3 macros M, all of which satisfy the +// same signature M(name, string, precedence), where name is the +// symbolic token name, string is the corresponding syntactic symbol +// (or NULL, for literals), and precedence is the precedence (or 0). +// The parameters are invoked for token categories as follows: +// +// T: Non-keyword tokens +// K: Keyword tokens + +// IGNORE_TOKEN is a convenience macro that can be supplied as +// an argument (at any position) for a TOKEN_LIST call. It does +// nothing with tokens belonging to the respective category. + +#define IGNORE_TOKEN(name, string, precedence) + +#define TOKEN_LIST(T, K) \ + /* End of source indicator. */ \ + T(EOS, "EOS", 0) \ + \ + /* Punctuators (ECMA-262, section 7.7, page 15). */ \ + T(LParen, "(", 0) \ + T(RParen, ")", 0) \ + T(LBrack, "[", 0) \ + T(RBrack, "]", 0) \ + T(LBrace, "{", 0) \ + T(RBrace, "}", 0) \ + T(Colon, ":", 0) \ + T(Semicolon, ";", 0) \ + T(Period, ".", 0) \ + T(Conditional, "?", 3) \ + T(Arrow, "=>", 0) \ + \ + /* Assignment operators. */ \ + /* IsAssignmentOp() relies on this block of enum values being */ \ + /* contiguous and sorted in the same order!*/ \ + T(Assign, "=", 2) \ + /* The following have to be in exactly the same order as the simple binary operators*/ \ + T(AssignBitOr, "|=", 2) \ + T(AssignBitXor, "^=", 2) \ + T(AssignBitAnd, "&=", 2) \ + T(AssignShl, "<<=", 2) \ + T(AssignSar, ">>=", 2) \ + T(AssignShr, ">>>=", 2) \ + T(AssignAdd, "+=", 2) \ + T(AssignSub, "-=", 2) \ + T(AssignMul, "*=", 2) \ + T(AssignDiv, "/=", 2) \ + T(AssignMod, "%=", 2) \ + \ + /* Binary operators sorted by precedence. */ \ + /* IsBinaryOp() relies on this block of enum values */ \ + /* being contiguous and sorted in the same order! */ \ + T(Comma, ",", 1) \ + T(Or, "||", 4) \ + T(And, "&&", 5) \ + T(BitOr, "|", 8) \ + T(BitXor, "^", 9) \ + T(BitAnd, "&", 10) \ + T(SHL, "<<", 11) \ + T(SAR, ">>", 11) \ + T(SHR, ">>>", 11) \ + T(Add, "+", 12) \ + T(Sub, "-", 12) \ + T(Mul, "*", 13) \ + T(Div, "/", 13) \ + T(Mod, "%", 13) \ + T(Exp, "**", 14) \ + \ + /* Compare operators sorted by precedence. */ \ + /* IsCompareOp() relies on this block of enum values */ \ + /* being contiguous and sorted in the same order! */ \ + T(Equal, "==", 6) \ + T(NotEqual, "!=", 6) \ + T(LessThan, "<", 7) \ + T(GreaterThan, ">", 7) \ + T(LessThanOrEqual, "<=", 7) \ + T(GreaterThanOrEqual, ">=", 7) \ + \ + /* Unary operators. */ \ + /* IsUnaryOp() relies on this block of enum values */ \ + /* being contiguous and sorted in the same order! */ \ + T(Not, "!", 0) \ + T(BitNot, "~", 0) \ + T(Inc, "++", 0) \ + T(Dec, "--", 0) \ + K(Delete, "delete", 0) \ + \ + /* Keywords */ \ + K(Anonymous, "anonymous", 0) \ + K(As, "as", 0) \ + K(Assembly, "assembly", 0) \ + K(Break, "break", 0) \ + K(Constant, "constant", 0) \ + K(Constructor, "constructor", 0) \ + K(Continue, "continue", 0) \ + K(Contract, "contract", 0) \ + K(Do, "do", 0) \ + K(Else, "else", 0) \ + K(Enum, "enum", 0) \ + K(Emit, "emit", 0) \ + K(Event, "event", 0) \ + K(External, "external", 0) \ + K(For, "for", 0) \ + K(Function, "function", 0) \ + K(Hex, "hex", 0) \ + K(If, "if", 0) \ + K(Indexed, "indexed", 0) \ + K(Interface, "interface", 0) \ + K(Internal, "internal", 0) \ + K(Import, "import", 0) \ + K(Is, "is", 0) \ + K(Library, "library", 0) \ + K(Mapping, "mapping", 0) \ + K(Memory, "memory", 0) \ + K(Modifier, "modifier", 0) \ + K(New, "new", 0) \ + K(Payable, "payable", 0) \ + K(Public, "public", 0) \ + K(Pragma, "pragma", 0) \ + K(Private, "private", 0) \ + K(Pure, "pure", 0) \ + K(Return, "return", 0) \ + K(Returns, "returns", 0) \ + K(Storage, "storage", 0) \ + K(CallData, "calldata", 0) \ + K(Struct, "struct", 0) \ + K(Throw, "throw", 0) \ + K(Using, "using", 0) \ + K(Var, "var", 0) \ + K(View, "view", 0) \ + K(While, "while", 0) \ + \ + /* Ether subdenominations */ \ + K(SubWei, "wei", 0) \ + K(SubSzabo, "szabo", 0) \ + K(SubFinney, "finney", 0) \ + K(SubEther, "ether", 0) \ + K(SubSecond, "seconds", 0) \ + K(SubMinute, "minutes", 0) \ + K(SubHour, "hours", 0) \ + K(SubDay, "days", 0) \ + K(SubWeek, "weeks", 0) \ + K(SubYear, "years", 0) \ + /* type keywords*/ \ + K(Int, "int", 0) \ + K(UInt, "uint", 0) \ + K(Bytes, "bytes", 0) \ + K(Byte, "byte", 0) \ + K(String, "string", 0) \ + K(Address, "address", 0) \ + K(Bool, "bool", 0) \ + K(Fixed, "fixed", 0) \ + K(UFixed, "ufixed", 0) \ + T(IntM, "intM", 0) \ + T(UIntM, "uintM", 0) \ + T(BytesM, "bytesM", 0) \ + T(FixedMxN, "fixedMxN", 0) \ + T(UFixedMxN, "ufixedMxN", 0) \ + T(TypesEnd, NULL, 0) /* used as type enum end marker */ \ + \ + /* Literals */ \ + K(TrueLiteral, "true", 0) \ + K(FalseLiteral, "false", 0) \ + T(Number, NULL, 0) \ + T(StringLiteral, NULL, 0) \ + T(CommentLiteral, NULL, 0) \ + \ + /* Identifiers (not keywords or future reserved words). */ \ + T(Identifier, NULL, 0) \ + \ + /* Keywords reserved for future use. */ \ + K(Abstract, "abstract", 0) \ + K(After, "after", 0) \ + K(Alias, "alias", 0) \ + K(Apply, "apply", 0) \ + K(Auto, "auto", 0) \ + K(Case, "case", 0) \ + K(Catch, "catch", 0) \ + K(CopyOf, "copyof", 0) \ + K(Default, "default", 0) \ + K(Define, "define", 0) \ + K(Final, "final", 0) \ + K(Immutable, "immutable", 0) \ + K(Implements, "implements", 0) \ + K(In, "in", 0) \ + K(Inline, "inline", 0) \ + K(Let, "let", 0) \ + K(Macro, "macro", 0) \ + K(Match, "match", 0) \ + K(Mutable, "mutable", 0) \ + K(NullLiteral, "null", 0) \ + K(Of, "of", 0) \ + K(Override, "override", 0) \ + K(Partial, "partial", 0) \ + K(Promise, "promise", 0) \ + K(Reference, "reference", 0) \ + K(Relocatable, "relocatable", 0) \ + K(Sealed, "sealed", 0) \ + K(Sizeof, "sizeof", 0) \ + K(Static, "static", 0) \ + K(Supports, "supports", 0) \ + K(Switch, "switch", 0) \ + K(Try, "try", 0) \ + K(Type, "type", 0) \ + K(Typedef, "typedef", 0) \ + K(TypeOf, "typeof", 0) \ + K(Unchecked, "unchecked", 0) \ + \ + /* Illegal token - not able to scan. */ \ + T(Illegal, "ILLEGAL", 0) \ + /* Illegal hex token */ \ + T(IllegalHex, "ILLEGAL_HEX", 0) \ + \ + /* Scanner-internal use only. */ \ + T(Whitespace, NULL, 0) + +// All token values. +// attention! msvc issue: +// http://stackoverflow.com/questions/9567868/compile-errors-after-adding-v8-to-my-project-c2143-c2059 +// @todo: avoid TOKEN_LIST macro +enum class Token : unsigned int { +#define T(name, string, precedence) name, + TOKEN_LIST(T, T) + NUM_TOKENS +#undef T +}; + +namespace TokenTraits +{ + constexpr size_t count() { return static_cast<size_t>(Token::NUM_TOKENS); } + + // Predicates + constexpr bool isElementaryTypeName(Token tok) { return Token::Int <= tok && tok < Token::TypesEnd; } + constexpr bool isAssignmentOp(Token tok) { return Token::Assign <= tok && tok <= Token::AssignMod; } + constexpr bool isBinaryOp(Token op) { return Token::Comma <= op && op <= Token::Exp; } + constexpr bool isCommutativeOp(Token op) { return op == Token::BitOr || op == Token::BitXor || op == Token::BitAnd || + op == Token::Add || op == Token::Mul || op == Token::Equal || op == Token::NotEqual; } + constexpr bool isArithmeticOp(Token op) { return Token::Add <= op && op <= Token::Exp; } + constexpr bool isCompareOp(Token op) { return Token::Equal <= op && op <= Token::GreaterThanOrEqual; } + + constexpr bool isBitOp(Token op) { return (Token::BitOr <= op && op <= Token::BitAnd) || op == Token::BitNot; } + constexpr bool isBooleanOp(Token op) { return (Token::Or <= op && op <= Token::And) || op == Token::Not; } + constexpr bool isUnaryOp(Token op) { return (Token::Not <= op && op <= Token::Delete) || op == Token::Add || op == Token::Sub; } + constexpr bool isCountOp(Token op) { return op == Token::Inc || op == Token::Dec; } + constexpr bool isShiftOp(Token op) { return (Token::SHL <= op) && (op <= Token::SHR); } + constexpr bool isVariableVisibilitySpecifier(Token op) { return op == Token::Public || op == Token::Private || op == Token::Internal; } + constexpr bool isVisibilitySpecifier(Token op) { return isVariableVisibilitySpecifier(op) || op == Token::External; } + constexpr bool isLocationSpecifier(Token op) { return op == Token::Memory || op == Token::Storage || op == Token::CallData; } + + constexpr bool isStateMutabilitySpecifier(Token op, bool _allowConstant = true) + { + return (op == Token::Constant && _allowConstant) + || op == Token::Pure || op == Token::View || op == Token::Payable; + } + + constexpr bool isEtherSubdenomination(Token op) { return op == Token::SubWei || op == Token::SubSzabo || op == Token::SubFinney || op == Token::SubEther; } + constexpr bool isTimeSubdenomination(Token op) { return op == Token::SubSecond || op == Token::SubMinute || op == Token::SubHour || op == Token::SubDay || op == Token::SubWeek || op == Token::SubYear; } + constexpr bool isReservedKeyword(Token op) { return (Token::Abstract <= op && op <= Token::Unchecked); } + + inline Token AssignmentToBinaryOp(Token op) + { + solAssert(isAssignmentOp(op) && op != Token::Assign, ""); + return static_cast<Token>(static_cast<int>(op) + (static_cast<int>(Token::BitOr) - static_cast<int>(Token::AssignBitOr))); + } + + // @returns the precedence > 0 for binary and compare + // operators; returns 0 otherwise. + int precedence(Token tok); + + std::tuple<Token, unsigned int, unsigned int> fromIdentifierOrKeyword(std::string const& _literal); + + // @returns a string corresponding to the C++ token name + // (e.g. "LT" for the token LT). + char const* name(Token tok); + + // @returns a string corresponding to the JS token string + // (.e., "<" for the token LT) or NULL if the token doesn't + // have a (unique) string (e.g. an IDENTIFIER). + char const* toString(Token tok); + + std::string friendlyName(Token tok); +} + +inline std::ostream& operator<<(std::ostream& os, Token token) +{ + os << TokenTraits::friendlyName(token); + return os; +} + +class ElementaryTypeNameToken +{ +public: + ElementaryTypeNameToken(Token _token, unsigned const& _firstNumber, unsigned const& _secondNumber) + { + assertDetails(_token, _firstNumber, _secondNumber); + } + + unsigned int firstNumber() const { return m_firstNumber; } + unsigned int secondNumber() const { return m_secondNumber; } + Token token() const { return m_token; } + + ///if tokValue is set to true, then returns the actual token type name, otherwise, returns full type + std::string toString(bool const& tokenValue = false) const + { + std::string name = TokenTraits::toString(m_token); + if (tokenValue || (firstNumber() == 0 && secondNumber() == 0)) + return name; + solAssert(name.size() >= 3, "Token name size should be greater than 3. Should not reach here."); + if (m_token == Token::FixedMxN || m_token == Token::UFixedMxN) + return name.substr(0, name.size() - 3) + std::to_string(m_firstNumber) + "x" + std::to_string(m_secondNumber); + else + return name.substr(0, name.size() - 1) + std::to_string(m_firstNumber); + } + +private: + Token m_token; + unsigned int m_firstNumber; + unsigned int m_secondNumber; + /// throws if type is not properly sized + void assertDetails(Token _baseType, unsigned const& _first, unsigned const& _second); +}; + +} diff --git a/libsolidity/parsing/UndefMacros.h b/liblangutil/UndefMacros.h index d96e242e..d96e242e 100644 --- a/libsolidity/parsing/UndefMacros.h +++ b/liblangutil/UndefMacros.h diff --git a/liblll/Compiler.h b/liblll/Compiler.h index 1ff7d5f8..93235cdd 100644 --- a/liblll/Compiler.h +++ b/liblll/Compiler.h @@ -23,7 +23,7 @@ #include <libdevcore/Common.h> -#include <libsolidity/interface/EVMVersion.h> +#include <liblangutil/EVMVersion.h> #include <string> #include <vector> diff --git a/libsolidity/CMakeLists.txt b/libsolidity/CMakeLists.txt index 136d39b1..c57fca16 100644 --- a/libsolidity/CMakeLists.txt +++ b/libsolidity/CMakeLists.txt @@ -26,7 +26,7 @@ if (NOT (${Z3_FOUND} OR ${CVC4_FOUND})) endif() add_library(solidity ${sources} ${headers}) -target_link_libraries(solidity PUBLIC evmasm devcore ${Boost_FILESYSTEM_LIBRARY} ${Boost_SYSTEM_LIBRARY}) +target_link_libraries(solidity PUBLIC evmasm langutil devcore ${Boost_FILESYSTEM_LIBRARY} ${Boost_SYSTEM_LIBRARY}) if (${Z3_FOUND}) target_link_libraries(solidity PUBLIC ${Z3_LIBRARY}) diff --git a/libsolidity/analysis/ConstantEvaluator.cpp b/libsolidity/analysis/ConstantEvaluator.cpp index f9b00927..9d041ce5 100644 --- a/libsolidity/analysis/ConstantEvaluator.cpp +++ b/libsolidity/analysis/ConstantEvaluator.cpp @@ -22,7 +22,7 @@ #include <libsolidity/analysis/ConstantEvaluator.h> #include <libsolidity/ast/AST.h> -#include <libsolidity/interface/ErrorReporter.h> +#include <liblangutil/ErrorReporter.h> using namespace std; using namespace dev; diff --git a/libsolidity/analysis/ConstantEvaluator.h b/libsolidity/analysis/ConstantEvaluator.h index ac3a24a1..23ca3628 100644 --- a/libsolidity/analysis/ConstantEvaluator.h +++ b/libsolidity/analysis/ConstantEvaluator.h @@ -24,12 +24,16 @@ #include <libsolidity/ast/ASTVisitor.h> +namespace langutil +{ +class ErrorReporter; +} + namespace dev { namespace solidity { -class ErrorReporter; class TypeChecker; /** @@ -39,7 +43,7 @@ class ConstantEvaluator: private ASTConstVisitor { public: ConstantEvaluator( - ErrorReporter& _errorReporter, + langutil::ErrorReporter& _errorReporter, size_t _newDepth = 0, std::shared_ptr<std::map<ASTNode const*, TypePointer>> _types = std::make_shared<std::map<ASTNode const*, TypePointer>>() ): @@ -61,7 +65,7 @@ private: void setType(ASTNode const& _node, TypePointer const& _type); TypePointer type(ASTNode const& _node); - ErrorReporter& m_errorReporter; + langutil::ErrorReporter& m_errorReporter; /// Current recursion depth. size_t m_depth = 0; std::shared_ptr<std::map<ASTNode const*, TypePointer>> m_types; diff --git a/libsolidity/analysis/ControlFlowAnalyzer.cpp b/libsolidity/analysis/ControlFlowAnalyzer.cpp index 8a608552..fe58f0aa 100644 --- a/libsolidity/analysis/ControlFlowAnalyzer.cpp +++ b/libsolidity/analysis/ControlFlowAnalyzer.cpp @@ -16,8 +16,10 @@ */ #include <libsolidity/analysis/ControlFlowAnalyzer.h> +#include <liblangutil/SourceLocation.h> using namespace std; +using namespace langutil; using namespace dev::solidity; bool ControlFlowAnalyzer::analyze(ASTNode const& _astRoot) diff --git a/libsolidity/analysis/ControlFlowAnalyzer.h b/libsolidity/analysis/ControlFlowAnalyzer.h index aaaf1bff..411d57ff 100644 --- a/libsolidity/analysis/ControlFlowAnalyzer.h +++ b/libsolidity/analysis/ControlFlowAnalyzer.h @@ -29,7 +29,7 @@ namespace solidity class ControlFlowAnalyzer: private ASTConstVisitor { public: - explicit ControlFlowAnalyzer(CFG const& _cfg, ErrorReporter& _errorReporter): + explicit ControlFlowAnalyzer(CFG const& _cfg, langutil::ErrorReporter& _errorReporter): m_cfg(_cfg), m_errorReporter(_errorReporter) {} bool analyze(ASTNode const& _astRoot); @@ -45,7 +45,7 @@ private: ) const; CFG const& m_cfg; - ErrorReporter& m_errorReporter; + langutil::ErrorReporter& m_errorReporter; }; } diff --git a/libsolidity/analysis/ControlFlowGraph.cpp b/libsolidity/analysis/ControlFlowGraph.cpp index 9b3da0eb..b8860158 100644 --- a/libsolidity/analysis/ControlFlowGraph.cpp +++ b/libsolidity/analysis/ControlFlowGraph.cpp @@ -23,6 +23,7 @@ #include <algorithm> using namespace std; +using namespace langutil; using namespace dev::solidity; bool CFG::constructFlow(ASTNode const& _astRoot) @@ -133,4 +134,4 @@ void CFG::applyModifierFlowToFunctionFlow( _functionFlow->entry = copySrcToCopyDst[_modifierFlow.entry]; _functionFlow->exit = copySrcToCopyDst[_modifierFlow.exit]; -}
\ No newline at end of file +} diff --git a/libsolidity/analysis/ControlFlowGraph.h b/libsolidity/analysis/ControlFlowGraph.h index 3f4820b8..8fe9fe8e 100644 --- a/libsolidity/analysis/ControlFlowGraph.h +++ b/libsolidity/analysis/ControlFlowGraph.h @@ -19,7 +19,7 @@ #include <libsolidity/ast/AST.h> #include <libsolidity/ast/ASTVisitor.h> -#include <libsolidity/interface/ErrorReporter.h> +#include <liblangutil/ErrorReporter.h> #include <map> #include <memory> @@ -101,7 +101,7 @@ struct ModifierFlow: FunctionFlow class CFG: private ASTConstVisitor { public: - explicit CFG(ErrorReporter& _errorReporter): m_errorReporter(_errorReporter) {} + explicit CFG(langutil::ErrorReporter& _errorReporter): m_errorReporter(_errorReporter) {} bool constructFlow(ASTNode const& _astRoot); @@ -133,7 +133,7 @@ private: FunctionFlow* _functionFlow ); - ErrorReporter& m_errorReporter; + langutil::ErrorReporter& m_errorReporter; /// Node container. /// All nodes allocated during the construction of the control flow graph diff --git a/libsolidity/analysis/DocStringAnalyser.cpp b/libsolidity/analysis/DocStringAnalyser.cpp index c1b97def..69a7a43c 100644 --- a/libsolidity/analysis/DocStringAnalyser.cpp +++ b/libsolidity/analysis/DocStringAnalyser.cpp @@ -23,11 +23,12 @@ #include <libsolidity/analysis/DocStringAnalyser.h> #include <libsolidity/ast/AST.h> -#include <libsolidity/interface/ErrorReporter.h> +#include <liblangutil/ErrorReporter.h> #include <libsolidity/parsing/DocStringParser.h> using namespace std; using namespace dev; +using namespace langutil; using namespace dev::solidity; bool DocStringAnalyser::analyseDocStrings(SourceUnit const& _sourceUnit) diff --git a/libsolidity/analysis/DocStringAnalyser.h b/libsolidity/analysis/DocStringAnalyser.h index 82746207..f6b236db 100644 --- a/libsolidity/analysis/DocStringAnalyser.h +++ b/libsolidity/analysis/DocStringAnalyser.h @@ -25,13 +25,16 @@ #include <libsolidity/ast/ASTVisitor.h> +namespace langutil +{ +class ErrorReporter; +} + namespace dev { namespace solidity { -class ErrorReporter; - /** * Parses and analyses the doc strings. * Stores the parsing results in the AST annotations and reports errors. @@ -39,7 +42,7 @@ class ErrorReporter; class DocStringAnalyser: private ASTConstVisitor { public: - DocStringAnalyser(ErrorReporter& _errorReporter): m_errorReporter(_errorReporter) {} + DocStringAnalyser(langutil::ErrorReporter& _errorReporter): m_errorReporter(_errorReporter) {} bool analyseDocStrings(SourceUnit const& _sourceUnit); private: @@ -75,7 +78,7 @@ private: void appendError(std::string const& _description); bool m_errorOccured = false; - ErrorReporter& m_errorReporter; + langutil::ErrorReporter& m_errorReporter; }; } diff --git a/libsolidity/analysis/NameAndTypeResolver.cpp b/libsolidity/analysis/NameAndTypeResolver.cpp index b452a49a..e40a2c97 100644 --- a/libsolidity/analysis/NameAndTypeResolver.cpp +++ b/libsolidity/analysis/NameAndTypeResolver.cpp @@ -24,12 +24,13 @@ #include <libsolidity/ast/AST.h> #include <libsolidity/analysis/TypeChecker.h> -#include <libsolidity/interface/ErrorReporter.h> +#include <liblangutil/ErrorReporter.h> #include <libdevcore/StringUtils.h> #include <boost/algorithm/string.hpp> using namespace std; +using namespace langutil; namespace dev { @@ -59,7 +60,7 @@ bool NameAndTypeResolver::registerDeclarations(SourceUnit& _sourceUnit, ASTNode { DeclarationRegistrationHelper registrar(m_scopes, _sourceUnit, m_errorReporter, _currentScope); } - catch (FatalError const&) + catch (langutil::FatalError const&) { if (m_errorReporter.errors().empty()) throw; // Something is weird here, rather throw again. @@ -129,7 +130,7 @@ bool NameAndTypeResolver::resolveNamesAndTypes(ASTNode& _node, bool _resolveInsi { return resolveNamesAndTypesInternal(_node, _resolveInsideCode); } - catch (FatalError const&) + catch (langutil::FatalError const&) { if (m_errorReporter.errors().empty()) throw; // Something is weird here, rather throw again. @@ -144,7 +145,7 @@ bool NameAndTypeResolver::updateDeclaration(Declaration const& _declaration) m_scopes[nullptr]->registerDeclaration(_declaration, nullptr, false, true); solAssert(_declaration.scope() == nullptr, "Updated declaration outside global scope."); } - catch (FatalError const&) + catch (langutil::FatalError const&) { if (m_errorReporter.errors().empty()) throw; // Something is weird here, rather throw again. diff --git a/libsolidity/analysis/NameAndTypeResolver.h b/libsolidity/analysis/NameAndTypeResolver.h index a72c21e3..1b034ef4 100644 --- a/libsolidity/analysis/NameAndTypeResolver.h +++ b/libsolidity/analysis/NameAndTypeResolver.h @@ -30,13 +30,16 @@ #include <libsolidity/ast/ASTVisitor.h> #include <libsolidity/ast/ASTAnnotations.h> +namespace langutil +{ +class ErrorReporter; +} + namespace dev { namespace solidity { -class ErrorReporter; - /** * Resolves name references, typenames and sets the (explicitly given) types for all variable * declarations. @@ -50,7 +53,7 @@ public: NameAndTypeResolver( std::vector<Declaration const*> const& _globals, std::map<ASTNode const*, std::shared_ptr<DeclarationContainer>>& _scopes, - ErrorReporter& _errorReporter + langutil::ErrorReporter& _errorReporter ); /// Registers all declarations found in the AST node, usually a source unit. /// @returns false in case of error. @@ -125,7 +128,7 @@ private: std::map<ASTNode const*, std::shared_ptr<DeclarationContainer>>& m_scopes; DeclarationContainer* m_currentScope = nullptr; - ErrorReporter& m_errorReporter; + langutil::ErrorReporter& m_errorReporter; }; /** @@ -142,7 +145,7 @@ public: DeclarationRegistrationHelper( std::map<ASTNode const*, std::shared_ptr<DeclarationContainer>>& _scopes, ASTNode& _astRoot, - ErrorReporter& _errorReporter, + langutil::ErrorReporter& _errorReporter, ASTNode const* _currentScope = nullptr ); @@ -150,10 +153,10 @@ public: DeclarationContainer& _container, Declaration const& _declaration, std::string const* _name, - SourceLocation const* _errorLocation, + langutil::SourceLocation const* _errorLocation, bool _warnOnShadow, bool _inactive, - ErrorReporter& _errorReporter + langutil::ErrorReporter& _errorReporter ); private: @@ -194,7 +197,7 @@ private: std::map<ASTNode const*, std::shared_ptr<DeclarationContainer>>& m_scopes; ASTNode const* m_currentScope = nullptr; VariableScope* m_currentFunction = nullptr; - ErrorReporter& m_errorReporter; + langutil::ErrorReporter& m_errorReporter; }; } diff --git a/libsolidity/analysis/PostTypeChecker.cpp b/libsolidity/analysis/PostTypeChecker.cpp index 240d7973..27cbcd45 100644 --- a/libsolidity/analysis/PostTypeChecker.cpp +++ b/libsolidity/analysis/PostTypeChecker.cpp @@ -18,7 +18,7 @@ #include <libsolidity/analysis/PostTypeChecker.h> #include <libsolidity/ast/AST.h> #include <libsolidity/analysis/SemVerHandler.h> -#include <libsolidity/interface/ErrorReporter.h> +#include <liblangutil/ErrorReporter.h> #include <libsolidity/interface/Version.h> #include <libdevcore/Algorithms.h> @@ -29,6 +29,7 @@ using namespace std; using namespace dev; +using namespace langutil; using namespace dev::solidity; diff --git a/libsolidity/analysis/PostTypeChecker.h b/libsolidity/analysis/PostTypeChecker.h index 8382948a..e428b81a 100644 --- a/libsolidity/analysis/PostTypeChecker.h +++ b/libsolidity/analysis/PostTypeChecker.h @@ -23,13 +23,17 @@ #include <libsolidity/ast/ASTForward.h> #include <libsolidity/ast/ASTVisitor.h> +namespace langutil +{ +class ErrorReporter; +struct SourceLocation; +} + namespace dev { namespace solidity { -class ErrorReporter; - /** * This module performs analyses on the AST that are done after type checking and assignments of types: * - whether there are circular references in constant state variables @@ -39,13 +43,13 @@ class PostTypeChecker: private ASTConstVisitor { public: /// @param _errorReporter provides the error logging functionality. - PostTypeChecker(ErrorReporter& _errorReporter): m_errorReporter(_errorReporter) {} + PostTypeChecker(langutil::ErrorReporter& _errorReporter): m_errorReporter(_errorReporter) {} bool check(ASTNode const& _astRoot); private: /// Adds a new error to the list of errors. - void typeError(SourceLocation const& _location, std::string const& _description); + void typeError(langutil::SourceLocation const& _location, std::string const& _description); bool visit(ContractDefinition const& _contract) override; void endVisit(ContractDefinition const& _contract) override; @@ -57,7 +61,7 @@ private: VariableDeclaration const* findCycle(VariableDeclaration const& _startingFrom); - ErrorReporter& m_errorReporter; + langutil::ErrorReporter& m_errorReporter; VariableDeclaration const* m_currentConstVariable = nullptr; std::vector<VariableDeclaration const*> m_constVariables; ///< Required for determinism. diff --git a/libsolidity/analysis/ReferencesResolver.cpp b/libsolidity/analysis/ReferencesResolver.cpp index 2adc8e77..7ac3ceff 100644 --- a/libsolidity/analysis/ReferencesResolver.cpp +++ b/libsolidity/analysis/ReferencesResolver.cpp @@ -23,12 +23,12 @@ #include <libsolidity/analysis/ReferencesResolver.h> #include <libsolidity/ast/AST.h> #include <libsolidity/analysis/NameAndTypeResolver.h> -#include <libsolidity/interface/Exceptions.h> +#include <liblangutil/Exceptions.h> #include <libsolidity/analysis/ConstantEvaluator.h> #include <libsolidity/inlineasm/AsmAnalysis.h> #include <libsolidity/inlineasm/AsmAnalysisInfo.h> #include <libsolidity/inlineasm/AsmData.h> -#include <libsolidity/interface/ErrorReporter.h> +#include <liblangutil/ErrorReporter.h> #include <libdevcore/StringUtils.h> @@ -36,9 +36,12 @@ #include <boost/range/adaptor/transformed.hpp> using namespace std; -using namespace dev; -using namespace dev::solidity; +using namespace langutil; +namespace dev +{ +namespace solidity +{ bool ReferencesResolver::resolve(ASTNode const& _root) { @@ -454,3 +457,6 @@ void ReferencesResolver::fatalDeclarationError(SourceLocation const& _location, m_errorOccurred = true; m_errorReporter.fatalDeclarationError(_location, _description); } + +} +} diff --git a/libsolidity/analysis/ReferencesResolver.h b/libsolidity/analysis/ReferencesResolver.h index 34dbca96..32c0553f 100644 --- a/libsolidity/analysis/ReferencesResolver.h +++ b/libsolidity/analysis/ReferencesResolver.h @@ -28,12 +28,17 @@ #include <libsolidity/ast/ASTVisitor.h> #include <libsolidity/ast/ASTAnnotations.h> +namespace langutil +{ +class ErrorReporter; +struct SourceLocation; +} + namespace dev { namespace solidity { -class ErrorReporter; class NameAndTypeResolver; /** @@ -44,7 +49,7 @@ class ReferencesResolver: private ASTConstVisitor { public: ReferencesResolver( - ErrorReporter& _errorReporter, + langutil::ErrorReporter& _errorReporter, NameAndTypeResolver& _resolver, bool _resolveInsideCode = false ): @@ -77,18 +82,18 @@ private: void endVisit(VariableDeclaration const& _variable) override; /// Adds a new error to the list of errors. - void typeError(SourceLocation const& _location, std::string const& _description); + void typeError(langutil::SourceLocation const& _location, std::string const& _description); /// Adds a new error to the list of errors and throws to abort reference resolving. - void fatalTypeError(SourceLocation const& _location, std::string const& _description); + void fatalTypeError(langutil::SourceLocation const& _location, std::string const& _description); /// Adds a new error to the list of errors. - void declarationError(SourceLocation const& _location, std::string const& _description); + void declarationError(langutil::SourceLocation const& _location, std::string const& _description); /// Adds a new error to the list of errors and throws to abort reference resolving. - void fatalDeclarationError(SourceLocation const& _location, std::string const& _description); + void fatalDeclarationError(langutil::SourceLocation const& _location, std::string const& _description); - ErrorReporter& m_errorReporter; + langutil::ErrorReporter& m_errorReporter; NameAndTypeResolver& m_resolver; /// Stack of return parameters. std::vector<ParameterList const*> m_returnParameters; diff --git a/libsolidity/analysis/SemVerHandler.h b/libsolidity/analysis/SemVerHandler.h index 03a557c5..80185612 100644 --- a/libsolidity/analysis/SemVerHandler.h +++ b/libsolidity/analysis/SemVerHandler.h @@ -22,8 +22,9 @@ #pragma once -#include <vector> #include <libsolidity/parsing/Token.h> +#include <string> +#include <vector> namespace dev { diff --git a/libsolidity/analysis/StaticAnalyzer.cpp b/libsolidity/analysis/StaticAnalyzer.cpp index 487a5cca..38391841 100644 --- a/libsolidity/analysis/StaticAnalyzer.cpp +++ b/libsolidity/analysis/StaticAnalyzer.cpp @@ -23,11 +23,12 @@ #include <libsolidity/analysis/StaticAnalyzer.h> #include <libsolidity/analysis/ConstantEvaluator.h> #include <libsolidity/ast/AST.h> -#include <libsolidity/interface/ErrorReporter.h> +#include <liblangutil/ErrorReporter.h> #include <memory> using namespace std; using namespace dev; +using namespace langutil; using namespace dev::solidity; bool StaticAnalyzer::analyze(SourceUnit const& _sourceUnit) diff --git a/libsolidity/analysis/StaticAnalyzer.h b/libsolidity/analysis/StaticAnalyzer.h index f5f3dbce..ff33fa3a 100644 --- a/libsolidity/analysis/StaticAnalyzer.h +++ b/libsolidity/analysis/StaticAnalyzer.h @@ -28,6 +28,11 @@ #include <libsolidity/ast/ASTForward.h> #include <libsolidity/ast/ASTVisitor.h> +namespace langutil +{ +class ErrorReporter; +} + namespace dev { namespace solidity @@ -44,7 +49,7 @@ class StaticAnalyzer: private ASTConstVisitor { public: /// @param _errorReporter provides the error logging functionality. - explicit StaticAnalyzer(ErrorReporter& _errorReporter): m_errorReporter(_errorReporter) {} + explicit StaticAnalyzer(langutil::ErrorReporter& _errorReporter): m_errorReporter(_errorReporter) {} /// Performs static analysis on the given source unit and all of its sub-nodes. /// @returns true iff all checks passed. Note even if all checks passed, errors() can still contain warnings @@ -70,7 +75,7 @@ private: /// @returns the size of this type in storage, including all sub-types. static bigint structureSizeEstimate(Type const& _type, std::set<StructDefinition const*>& _structsSeen); - ErrorReporter& m_errorReporter; + langutil::ErrorReporter& m_errorReporter; /// Flag that indicates whether the current contract definition is a library. bool m_library = false; diff --git a/libsolidity/analysis/SyntaxChecker.cpp b/libsolidity/analysis/SyntaxChecker.cpp index 3f9f8373..a73d7e5c 100644 --- a/libsolidity/analysis/SyntaxChecker.cpp +++ b/libsolidity/analysis/SyntaxChecker.cpp @@ -20,7 +20,7 @@ #include <libsolidity/ast/AST.h> #include <libsolidity/ast/ExperimentalFeatures.h> #include <libsolidity/analysis/SemVerHandler.h> -#include <libsolidity/interface/ErrorReporter.h> +#include <liblangutil/ErrorReporter.h> #include <libsolidity/interface/Version.h> #include <boost/algorithm/cxx11/all_of.hpp> @@ -29,6 +29,7 @@ using namespace std; using namespace dev; +using namespace langutil; using namespace dev::solidity; diff --git a/libsolidity/analysis/SyntaxChecker.h b/libsolidity/analysis/SyntaxChecker.h index 9e3c4652..c2463955 100644 --- a/libsolidity/analysis/SyntaxChecker.h +++ b/libsolidity/analysis/SyntaxChecker.h @@ -23,6 +23,11 @@ #include <libsolidity/ast/ASTForward.h> #include <libsolidity/ast/ASTVisitor.h> +namespace langutil +{ +class ErrorReporter; +} + namespace dev { namespace solidity @@ -39,7 +44,7 @@ class SyntaxChecker: private ASTConstVisitor { public: /// @param _errorReporter provides the error logging functionality. - SyntaxChecker(ErrorReporter& _errorReporter): m_errorReporter(_errorReporter) {} + SyntaxChecker(langutil::ErrorReporter& _errorReporter): m_errorReporter(_errorReporter) {} bool checkSyntax(ASTNode const& _astRoot); @@ -81,7 +86,7 @@ private: bool visit(StructDefinition const& _struct) override; bool visit(Literal const& _literal) override; - ErrorReporter& m_errorReporter; + langutil::ErrorReporter& m_errorReporter; /// Flag that indicates whether a function modifier actually contains '_'. bool m_placeholderFound = false; diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index c5e6488b..69de9f12 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -30,11 +30,12 @@ #include <libsolidity/inlineasm/AsmAnalysis.h> #include <libsolidity/inlineasm/AsmAnalysisInfo.h> #include <libsolidity/inlineasm/AsmData.h> -#include <libsolidity/interface/ErrorReporter.h> +#include <liblangutil/ErrorReporter.h> #include <libdevcore/Algorithms.h> using namespace std; using namespace dev; +using namespace langutil; using namespace dev::solidity; namespace diff --git a/libsolidity/analysis/TypeChecker.h b/libsolidity/analysis/TypeChecker.h index ae3ebc52..c98a4c7f 100644 --- a/libsolidity/analysis/TypeChecker.h +++ b/libsolidity/analysis/TypeChecker.h @@ -22,20 +22,23 @@ #pragma once -#include <libsolidity/interface/EVMVersion.h> +#include <liblangutil/EVMVersion.h> #include <libsolidity/ast/Types.h> #include <libsolidity/ast/ASTAnnotations.h> #include <libsolidity/ast/ASTForward.h> #include <libsolidity/ast/ASTVisitor.h> +namespace langutil +{ +class ErrorReporter; +} + namespace dev { namespace solidity { -class ErrorReporter; - /** * The module that performs type analysis on the AST, checks the applicability of operations on * those types and stores errors for invalid operations. @@ -45,7 +48,7 @@ class TypeChecker: private ASTConstVisitor { public: /// @param _errorReporter provides the error logging functionality. - TypeChecker(EVMVersion _evmVersion, ErrorReporter& _errorReporter): + TypeChecker(EVMVersion _evmVersion, langutil::ErrorReporter& _errorReporter): m_evmVersion(_evmVersion), m_errorReporter(_errorReporter) {} @@ -183,7 +186,7 @@ private: /// Flag indicating whether we are currently inside a StructDefinition. bool m_insideStruct = false; - ErrorReporter& m_errorReporter; + langutil::ErrorReporter& m_errorReporter; }; } diff --git a/libsolidity/analysis/ViewPureChecker.cpp b/libsolidity/analysis/ViewPureChecker.cpp index b0cacc43..3fb4c026 100644 --- a/libsolidity/analysis/ViewPureChecker.cpp +++ b/libsolidity/analysis/ViewPureChecker.cpp @@ -22,10 +22,13 @@ #include <libsolidity/inlineasm/AsmData.h> #include <libsolidity/ast/ExperimentalFeatures.h> +#include <liblangutil/ErrorReporter.h> + #include <functional> using namespace std; using namespace dev; +using namespace langutil; using namespace dev::solidity; namespace diff --git a/libsolidity/analysis/ViewPureChecker.h b/libsolidity/analysis/ViewPureChecker.h index 1109ad76..fd2432a7 100644 --- a/libsolidity/analysis/ViewPureChecker.h +++ b/libsolidity/analysis/ViewPureChecker.h @@ -21,11 +21,15 @@ #include <libsolidity/ast/ASTForward.h> #include <libsolidity/ast/ASTVisitor.h> -#include <libsolidity/interface/ErrorReporter.h> - #include <map> #include <memory> +namespace langutil +{ +class ErrorReporter; +struct SourceLocation; +} + namespace dev { namespace solidity @@ -34,7 +38,7 @@ namespace solidity class ViewPureChecker: private ASTConstVisitor { public: - ViewPureChecker(std::vector<std::shared_ptr<ASTNode>> const& _ast, ErrorReporter& _errorReporter): + ViewPureChecker(std::vector<std::shared_ptr<ASTNode>> const& _ast, langutil::ErrorReporter& _errorReporter): m_ast(_ast), m_errorReporter(_errorReporter) {} bool check(); @@ -43,7 +47,7 @@ private: struct MutabilityAndLocation { StateMutability mutability; - SourceLocation location; + langutil::SourceLocation location; }; bool visit(FunctionDefinition const& _funDef) override; @@ -62,15 +66,15 @@ private: /// Creates appropriate warnings and errors and sets @a m_currentBestMutability. void reportMutability( StateMutability _mutability, - SourceLocation const& _location, - boost::optional<SourceLocation> const& _nestedLocation = {} + langutil::SourceLocation const& _location, + boost::optional<langutil::SourceLocation> const& _nestedLocation = {} ); std::vector<std::shared_ptr<ASTNode>> const& m_ast; - ErrorReporter& m_errorReporter; + langutil::ErrorReporter& m_errorReporter; bool m_errors = false; - MutabilityAndLocation m_bestMutabilityAndLocation = MutabilityAndLocation{StateMutability::Payable, SourceLocation()}; + MutabilityAndLocation m_bestMutabilityAndLocation = MutabilityAndLocation{StateMutability::Payable, langutil::SourceLocation()}; FunctionDefinition const* m_currentFunction = nullptr; std::map<ModifierDefinition const*, MutabilityAndLocation> m_inferredMutability; }; diff --git a/libsolidity/ast/AST.h b/libsolidity/ast/AST.h index 23a6078b..d23562ad 100644 --- a/libsolidity/ast/AST.h +++ b/libsolidity/ast/AST.h @@ -23,13 +23,13 @@ #pragma once -#include <libsolidity/ast/ASTForward.h> #include <libsolidity/parsing/Token.h> +#include <libsolidity/ast/ASTForward.h> #include <libsolidity/ast/Types.h> #include <libsolidity/ast/ASTAnnotations.h> #include <libsolidity/ast/ASTEnums.h> -#include <libevmasm/SourceLocation.h> +#include <liblangutil/SourceLocation.h> #include <libevmasm/Instruction.h> #include <libdevcore/FixedHash.h> @@ -58,6 +58,8 @@ class ASTConstVisitor; class ASTNode: private boost::noncopyable { public: + using SourceLocation = langutil::SourceLocation; + explicit ASTNode(SourceLocation const& _location); virtual ~ASTNode(); diff --git a/libsolidity/ast/ASTEnums.h b/libsolidity/ast/ASTEnums.h index 5ba21907..d47a5f05 100644 --- a/libsolidity/ast/ASTEnums.h +++ b/libsolidity/ast/ASTEnums.h @@ -21,7 +21,7 @@ #pragma once -#include <libsolidity/interface/Exceptions.h> +#include <liblangutil/Exceptions.h> #include <string> diff --git a/libsolidity/ast/ASTJsonConverter.cpp b/libsolidity/ast/ASTJsonConverter.cpp index 2d26ce8a..6b9f7227 100644 --- a/libsolidity/ast/ASTJsonConverter.cpp +++ b/libsolidity/ast/ASTJsonConverter.cpp @@ -27,6 +27,7 @@ #include <libsolidity/inlineasm/AsmPrinter.h> using namespace std; +using namespace langutil; namespace dev { diff --git a/libsolidity/ast/ASTJsonConverter.h b/libsolidity/ast/ASTJsonConverter.h index 8429708c..dec3ac96 100644 --- a/libsolidity/ast/ASTJsonConverter.h +++ b/libsolidity/ast/ASTJsonConverter.h @@ -25,10 +25,15 @@ #include <ostream> #include <stack> #include <libsolidity/ast/ASTVisitor.h> -#include <libsolidity/interface/Exceptions.h> +#include <liblangutil/Exceptions.h> #include <libsolidity/ast/ASTAnnotations.h> #include <json/json.h> +namespace langutil +{ +struct SourceLocation; +} + namespace dev { namespace solidity @@ -120,7 +125,7 @@ private: std::string const& _nodeName, std::vector<std::pair<std::string, Json::Value>>&& _attributes ); - std::string sourceLocationToString(SourceLocation const& _location) const; + std::string sourceLocationToString(langutil::SourceLocation const& _location) const; static std::string namePathToString(std::vector<ASTString> const& _namePath); static Json::Value idOrNull(ASTNode const* _pt) { diff --git a/libsolidity/ast/ASTPrinter.cpp b/libsolidity/ast/ASTPrinter.cpp index 255cb9be..cdc6ae7d 100644 --- a/libsolidity/ast/ASTPrinter.cpp +++ b/libsolidity/ast/ASTPrinter.cpp @@ -28,6 +28,7 @@ #include <boost/algorithm/string/join.hpp> using namespace std; +using namespace langutil; namespace dev { diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index 4b31d2e8..0eab75aa 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -45,6 +45,7 @@ using namespace std; using namespace dev; +using namespace langutil; using namespace dev::solidity; namespace diff --git a/libsolidity/ast/Types.h b/libsolidity/ast/Types.h index fbf11f49..482d6735 100644 --- a/libsolidity/ast/Types.h +++ b/libsolidity/ast/Types.h @@ -22,7 +22,7 @@ #pragma once -#include <libsolidity/interface/Exceptions.h> +#include <liblangutil/Exceptions.h> #include <libsolidity/ast/ASTForward.h> #include <libsolidity/ast/ASTEnums.h> #include <libsolidity/parsing/Token.h> diff --git a/libsolidity/codegen/ABIFunctions.h b/libsolidity/codegen/ABIFunctions.h index e9ffe4fb..d2132258 100644 --- a/libsolidity/codegen/ABIFunctions.h +++ b/libsolidity/codegen/ABIFunctions.h @@ -22,7 +22,7 @@ #pragma once -#include <libsolidity/interface/EVMVersion.h> +#include <liblangutil/EVMVersion.h> #include <libsolidity/ast/ASTForward.h> diff --git a/libsolidity/codegen/ArrayUtils.cpp b/libsolidity/codegen/ArrayUtils.cpp index d33f749c..4878f9f3 100644 --- a/libsolidity/codegen/ArrayUtils.cpp +++ b/libsolidity/codegen/ArrayUtils.cpp @@ -25,11 +25,12 @@ #include <libsolidity/codegen/CompilerContext.h> #include <libsolidity/codegen/CompilerUtils.h> #include <libsolidity/ast/Types.h> -#include <libsolidity/interface/Exceptions.h> +#include <liblangutil/Exceptions.h> #include <libsolidity/codegen/LValue.h> using namespace std; using namespace dev; +using namespace langutil; using namespace solidity; void ArrayUtils::copyArrayToStorage(ArrayType const& _targetType, ArrayType const& _sourceType) const diff --git a/libsolidity/codegen/Compiler.h b/libsolidity/codegen/Compiler.h index 4028ae63..48d9e9d6 100644 --- a/libsolidity/codegen/Compiler.h +++ b/libsolidity/codegen/Compiler.h @@ -23,7 +23,7 @@ #pragma once #include <libsolidity/codegen/CompilerContext.h> -#include <libsolidity/interface/EVMVersion.h> +#include <liblangutil/EVMVersion.h> #include <libevmasm/Assembly.h> diff --git a/libsolidity/codegen/CompilerContext.cpp b/libsolidity/codegen/CompilerContext.cpp index 6e14d68a..9e4f2882 100644 --- a/libsolidity/codegen/CompilerContext.cpp +++ b/libsolidity/codegen/CompilerContext.cpp @@ -25,9 +25,10 @@ #include <libsolidity/ast/AST.h> #include <libsolidity/codegen/Compiler.h> #include <libsolidity/interface/Version.h> -#include <libsolidity/interface/ErrorReporter.h> +#include <liblangutil/ErrorReporter.h> +#include <liblangutil/Scanner.h> #include <libsolidity/interface/SourceReferenceFormatter.h> -#include <libsolidity/parsing/Scanner.h> +#include <liblangutil/Scanner.h> #include <libsolidity/inlineasm/AsmParser.h> #include <libsolidity/inlineasm/AsmCodeGen.h> #include <libsolidity/inlineasm/AsmAnalysis.h> @@ -47,6 +48,7 @@ using namespace std; +using namespace langutil; namespace dev { @@ -359,7 +361,7 @@ void CompilerContext::appendInlineAssembly( ErrorList errors; ErrorReporter errorReporter(errors); - auto scanner = make_shared<Scanner>(CharStream(_assembly), "--CODEGEN--"); + auto scanner = make_shared<langutil::Scanner>(langutil::CharStream(_assembly), "--CODEGEN--"); auto parserResult = assembly::Parser(errorReporter, assembly::AsmFlavour::Strict).parse(scanner, false); #ifdef SOL_OUTPUT_ASM cout << assembly::AsmPrinter()(*parserResult) << endl; diff --git a/libsolidity/codegen/CompilerContext.h b/libsolidity/codegen/CompilerContext.h index 5bdc1d19..63365175 100644 --- a/libsolidity/codegen/CompilerContext.h +++ b/libsolidity/codegen/CompilerContext.h @@ -24,7 +24,7 @@ #include <libsolidity/codegen/ABIFunctions.h> -#include <libsolidity/interface/EVMVersion.h> +#include <liblangutil/EVMVersion.h> #include <libsolidity/ast/ASTForward.h> #include <libsolidity/ast/Types.h> diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp index a0d11017..93c8cc77 100644 --- a/libsolidity/codegen/CompilerUtils.cpp +++ b/libsolidity/codegen/CompilerUtils.cpp @@ -32,6 +32,7 @@ #include <libdevcore/Whiskers.h> using namespace std; +using namespace langutil; namespace dev { diff --git a/libsolidity/codegen/ContractCompiler.cpp b/libsolidity/codegen/ContractCompiler.cpp index 1fdf3483..7a1dcd70 100644 --- a/libsolidity/codegen/ContractCompiler.cpp +++ b/libsolidity/codegen/ContractCompiler.cpp @@ -23,7 +23,7 @@ #include <libsolidity/codegen/ContractCompiler.h> #include <libsolidity/inlineasm/AsmCodeGen.h> #include <libsolidity/ast/AST.h> -#include <libsolidity/interface/ErrorReporter.h> +#include <liblangutil/ErrorReporter.h> #include <libsolidity/codegen/ExpressionCompiler.h> #include <libsolidity/codegen/CompilerUtils.h> @@ -37,6 +37,7 @@ using namespace std; using namespace dev; +using namespace langutil; using namespace dev::solidity; namespace diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp index bdf91fbf..57b513d2 100644 --- a/libsolidity/codegen/ExpressionCompiler.cpp +++ b/libsolidity/codegen/ExpressionCompiler.cpp @@ -36,6 +36,7 @@ #include <libdevcore/Whiskers.h> using namespace std; +using namespace langutil; namespace dev { diff --git a/libsolidity/codegen/ExpressionCompiler.h b/libsolidity/codegen/ExpressionCompiler.h index 9a695b4c..2bfaab43 100644 --- a/libsolidity/codegen/ExpressionCompiler.h +++ b/libsolidity/codegen/ExpressionCompiler.h @@ -25,10 +25,10 @@ #include <memory> #include <boost/noncopyable.hpp> #include <libdevcore/Common.h> -#include <libevmasm/SourceLocation.h> +#include <liblangutil/SourceLocation.h> #include <libsolidity/ast/ASTVisitor.h> #include <libsolidity/codegen/LValue.h> -#include <libsolidity/interface/Exceptions.h> +#include <liblangutil/Exceptions.h> namespace dev { namespace eth diff --git a/libsolidity/codegen/LValue.cpp b/libsolidity/codegen/LValue.cpp index 790ab309..6d71d36f 100644 --- a/libsolidity/codegen/LValue.cpp +++ b/libsolidity/codegen/LValue.cpp @@ -28,6 +28,7 @@ using namespace std; using namespace dev; +using namespace langutil; using namespace solidity; diff --git a/libsolidity/codegen/LValue.h b/libsolidity/codegen/LValue.h index 6054af28..d854857b 100644 --- a/libsolidity/codegen/LValue.h +++ b/libsolidity/codegen/LValue.h @@ -24,7 +24,7 @@ #include <memory> #include <vector> -#include <libevmasm/SourceLocation.h> +#include <liblangutil/SourceLocation.h> #include <libsolidity/codegen/ArrayUtils.h> namespace dev @@ -55,17 +55,17 @@ public: /// Copies the value of the current lvalue to the top of the stack and, if @a _remove is true, /// also removes the reference from the stack. /// @a _location source location of the current expression, used for error reporting. - virtual void retrieveValue(SourceLocation const& _location, bool _remove = false) const = 0; + virtual void retrieveValue(langutil::SourceLocation const& _location, bool _remove = false) const = 0; /// Moves a value from the stack to the lvalue. Removes the value if @a _move is true. /// @a _location is the source location of the expression that caused this operation. /// Stack pre: value [lvalue_ref] /// Stack post: if !_move: value_of(lvalue_ref) virtual void storeValue(Type const& _sourceType, - SourceLocation const& _location = SourceLocation(), bool _move = false) const = 0; + langutil::SourceLocation const& _location = {}, bool _move = false) const = 0; /// Stores zero in the lvalue. Removes the reference from the stack if @a _removeReference is true. /// @a _location is the source location of the requested operation virtual void setToZero( - SourceLocation const& _location = SourceLocation(), + langutil::SourceLocation const& _location = {}, bool _removeReference = true ) const = 0; @@ -83,14 +83,14 @@ public: StackVariable(CompilerContext& _compilerContext, VariableDeclaration const& _declaration); unsigned sizeOnStack() const override { return 0; } - void retrieveValue(SourceLocation const& _location, bool _remove = false) const override; + void retrieveValue(langutil::SourceLocation const& _location, bool _remove = false) const override; virtual void storeValue( Type const& _sourceType, - SourceLocation const& _location = SourceLocation(), + langutil::SourceLocation const& _location = {}, bool _move = false ) const override; virtual void setToZero( - SourceLocation const& _location = SourceLocation(), + langutil::SourceLocation const& _location = {}, bool _removeReference = true ) const override; @@ -109,14 +109,14 @@ class MemoryItem: public LValue public: MemoryItem(CompilerContext& _compilerContext, Type const& _type, bool _padded = true); unsigned sizeOnStack() const override { return 1; } - void retrieveValue(SourceLocation const& _location, bool _remove = false) const override; + void retrieveValue(langutil::SourceLocation const& _location, bool _remove = false) const override; virtual void storeValue( Type const& _sourceType, - SourceLocation const& _location = SourceLocation(), + langutil::SourceLocation const& _location = {}, bool _move = false ) const override; virtual void setToZero( - SourceLocation const& _location = SourceLocation(), + langutil::SourceLocation const& _location = {}, bool _removeReference = true ) const override; private: @@ -137,14 +137,14 @@ public: /// Constructs the LValue and assumes that the storage reference is already on the stack. StorageItem(CompilerContext& _compilerContext, Type const& _type); unsigned sizeOnStack() const override { return 2; } - void retrieveValue(SourceLocation const& _location, bool _remove = false) const override; + void retrieveValue(langutil::SourceLocation const& _location, bool _remove = false) const override; virtual void storeValue( Type const& _sourceType, - SourceLocation const& _location = SourceLocation(), + langutil::SourceLocation const& _location = {}, bool _move = false ) const override; virtual void setToZero( - SourceLocation const& _location = SourceLocation(), + langutil::SourceLocation const& _location = {}, bool _removeReference = true ) const override; }; @@ -159,14 +159,14 @@ public: /// Constructs the LValue and assumes that the storage reference is already on the stack. StorageByteArrayElement(CompilerContext& _compilerContext); unsigned sizeOnStack() const override { return 2; } - void retrieveValue(SourceLocation const& _location, bool _remove = false) const override; + void retrieveValue(langutil::SourceLocation const& _location, bool _remove = false) const override; virtual void storeValue( Type const& _sourceType, - SourceLocation const& _location = SourceLocation(), + langutil::SourceLocation const& _location = {}, bool _move = false ) const override; virtual void setToZero( - SourceLocation const& _location = SourceLocation(), + langutil::SourceLocation const& _location = {}, bool _removeReference = true ) const override; }; @@ -181,14 +181,14 @@ class StorageArrayLength: public LValue public: /// Constructs the LValue, assumes that the reference to the array head is already on the stack. StorageArrayLength(CompilerContext& _compilerContext, ArrayType const& _arrayType); - void retrieveValue(SourceLocation const& _location, bool _remove = false) const override; + void retrieveValue(langutil::SourceLocation const& _location, bool _remove = false) const override; virtual void storeValue( Type const& _sourceType, - SourceLocation const& _location = SourceLocation(), + langutil::SourceLocation const& _location = {}, bool _move = false ) const override; virtual void setToZero( - SourceLocation const& _location = SourceLocation(), + langutil::SourceLocation const& _location = {}, bool _removeReference = true ) const override; @@ -206,14 +206,14 @@ public: /// Empty unique_ptrs are possible if e.g. some values should be ignored during assignment. TupleObject(CompilerContext& _compilerContext, std::vector<std::unique_ptr<LValue>>&& _lvalues); unsigned sizeOnStack() const override; - void retrieveValue(SourceLocation const& _location, bool _remove = false) const override; + void retrieveValue(langutil::SourceLocation const& _location, bool _remove = false) const override; virtual void storeValue( Type const& _sourceType, - SourceLocation const& _location = SourceLocation(), + langutil::SourceLocation const& _location = {}, bool _move = false ) const override; virtual void setToZero( - SourceLocation const& _location = SourceLocation(), + langutil::SourceLocation const& _location = {}, bool _removeReference = true ) const override; diff --git a/libsolidity/formal/CVC4Interface.cpp b/libsolidity/formal/CVC4Interface.cpp index 6e17eef1..8952665f 100644 --- a/libsolidity/formal/CVC4Interface.cpp +++ b/libsolidity/formal/CVC4Interface.cpp @@ -17,7 +17,7 @@ #include <libsolidity/formal/CVC4Interface.h> -#include <libsolidity/interface/Exceptions.h> +#include <liblangutil/Exceptions.h> #include <libdevcore/CommonIO.h> diff --git a/libsolidity/formal/SMTChecker.cpp b/libsolidity/formal/SMTChecker.cpp index 0a581fc0..7e75df87 100644 --- a/libsolidity/formal/SMTChecker.cpp +++ b/libsolidity/formal/SMTChecker.cpp @@ -22,13 +22,14 @@ #include <libsolidity/formal/VariableUsage.h> #include <libsolidity/formal/SymbolicTypes.h> -#include <libsolidity/interface/ErrorReporter.h> +#include <liblangutil/ErrorReporter.h> #include <boost/range/adaptor/map.hpp> #include <boost/algorithm/string/replace.hpp> using namespace std; using namespace dev; +using namespace langutil; using namespace dev::solidity; SMTChecker::SMTChecker(ErrorReporter& _errorReporter, ReadCallback::Callback const& _readFileCallback): diff --git a/libsolidity/formal/SMTChecker.h b/libsolidity/formal/SMTChecker.h index 3bf84ac9..d7f86cbc 100644 --- a/libsolidity/formal/SMTChecker.h +++ b/libsolidity/formal/SMTChecker.h @@ -25,26 +25,31 @@ #include <libsolidity/interface/ReadFile.h> -#include <libsolidity/parsing/Scanner.h> +#include <liblangutil/Scanner.h> #include <unordered_map> #include <string> #include <vector> +namespace langutil +{ +class ErrorReporter; +struct SourceLocation; +} + namespace dev { namespace solidity { class VariableUsage; -class ErrorReporter; class SMTChecker: private ASTConstVisitor { public: - SMTChecker(ErrorReporter& _errorReporter, ReadCallback::Callback const& _readCallback); + SMTChecker(langutil::ErrorReporter& _errorReporter, ReadCallback::Callback const& _readCallback); - void analyze(SourceUnit const& _sources, std::shared_ptr<Scanner> const& _scanner); + void analyze(SourceUnit const& _sources, std::shared_ptr<langutil::Scanner> const& _scanner); private: // TODO: Check that we do not have concurrent reads and writes to a variable, @@ -89,8 +94,8 @@ private: /// of rounding for signed division. smt::Expression division(smt::Expression _left, smt::Expression _right, IntegerType const& _type); - void assignment(VariableDeclaration const& _variable, Expression const& _value, SourceLocation const& _location); - void assignment(VariableDeclaration const& _variable, smt::Expression const& _value, SourceLocation const& _location); + void assignment(VariableDeclaration const& _variable, Expression const& _value, langutil::SourceLocation const& _location); + void assignment(VariableDeclaration const& _variable, smt::Expression const& _value, langutil::SourceLocation const& _location); /// Maps a variable to an SSA index. using VariableIndices = std::unordered_map<VariableDeclaration const*, int>; @@ -104,7 +109,7 @@ private: /// Check that a condition can be satisfied. void checkCondition( smt::Expression _condition, - SourceLocation const& _location, + langutil::SourceLocation const& _location, std::string const& _description, std::string const& _additionalValueName = "", smt::Expression* _additionalValue = nullptr @@ -117,7 +122,7 @@ private: std::string const& _description ); /// Checks that the value is in the range given by the type. - void checkUnderOverflow(smt::Expression _value, IntegerType const& _Type, SourceLocation const& _location); + void checkUnderOverflow(smt::Expression _value, IntegerType const& _Type, langutil::SourceLocation const& _location); std::pair<smt::CheckResult, std::vector<std::string>> @@ -200,8 +205,8 @@ private: /// Used to retrieve models. std::vector<Expression const*> m_uninterpretedTerms; std::vector<smt::Expression> m_pathConditions; - ErrorReporter& m_errorReporter; - std::shared_ptr<Scanner> m_scanner; + langutil::ErrorReporter& m_errorReporter; + std::shared_ptr<langutil::Scanner> m_scanner; /// Stores the current path of function calls. std::vector<FunctionDefinition const*> m_functionPath; diff --git a/libsolidity/formal/SMTLib2Interface.cpp b/libsolidity/formal/SMTLib2Interface.cpp index 01386dda..7a6b558b 100644 --- a/libsolidity/formal/SMTLib2Interface.cpp +++ b/libsolidity/formal/SMTLib2Interface.cpp @@ -17,7 +17,7 @@ #include <libsolidity/formal/SMTLib2Interface.h> -#include <libsolidity/interface/Exceptions.h> +#include <liblangutil/Exceptions.h> #include <libsolidity/interface/ReadFile.h> #include <boost/algorithm/string/predicate.hpp> diff --git a/libsolidity/formal/SMTLib2Interface.h b/libsolidity/formal/SMTLib2Interface.h index b140f555..f3c58d6b 100644 --- a/libsolidity/formal/SMTLib2Interface.h +++ b/libsolidity/formal/SMTLib2Interface.h @@ -19,7 +19,7 @@ #include <libsolidity/formal/SolverInterface.h> -#include <libsolidity/interface/Exceptions.h> +#include <liblangutil/Exceptions.h> #include <libsolidity/interface/ReadFile.h> #include <libdevcore/Common.h> diff --git a/libsolidity/formal/SolverInterface.h b/libsolidity/formal/SolverInterface.h index 55c0a563..df036190 100644 --- a/libsolidity/formal/SolverInterface.h +++ b/libsolidity/formal/SolverInterface.h @@ -17,7 +17,7 @@ #pragma once -#include <libsolidity/interface/Exceptions.h> +#include <liblangutil/Exceptions.h> #include <libsolidity/interface/ReadFile.h> #include <libdevcore/Common.h> diff --git a/libsolidity/formal/Z3Interface.cpp b/libsolidity/formal/Z3Interface.cpp index 09696aeb..ac6fbd54 100644 --- a/libsolidity/formal/Z3Interface.cpp +++ b/libsolidity/formal/Z3Interface.cpp @@ -17,7 +17,7 @@ #include <libsolidity/formal/Z3Interface.h> -#include <libsolidity/interface/Exceptions.h> +#include <liblangutil/Exceptions.h> #include <libdevcore/CommonIO.h> diff --git a/libsolidity/inlineasm/AsmAnalysis.cpp b/libsolidity/inlineasm/AsmAnalysis.cpp index ac019c06..fb96f73c 100644 --- a/libsolidity/inlineasm/AsmAnalysis.cpp +++ b/libsolidity/inlineasm/AsmAnalysis.cpp @@ -25,7 +25,7 @@ #include <libsolidity/inlineasm/AsmScope.h> #include <libsolidity/inlineasm/AsmAnalysisInfo.h> -#include <libsolidity/interface/ErrorReporter.h> +#include <liblangutil/ErrorReporter.h> #include <boost/range/adaptor/reversed.hpp> #include <boost/algorithm/string.hpp> @@ -35,6 +35,7 @@ using namespace std; using namespace dev; +using namespace langutil; using namespace dev::solidity; using namespace dev::solidity::assembly; diff --git a/libsolidity/inlineasm/AsmAnalysis.h b/libsolidity/inlineasm/AsmAnalysis.h index a8673efa..194f736e 100644 --- a/libsolidity/inlineasm/AsmAnalysis.h +++ b/libsolidity/inlineasm/AsmAnalysis.h @@ -20,8 +20,8 @@ #pragma once -#include <libsolidity/interface/Exceptions.h> -#include <libsolidity/interface/EVMVersion.h> +#include <liblangutil/Exceptions.h> +#include <liblangutil/EVMVersion.h> #include <libsolidity/inlineasm/AsmScope.h> @@ -35,11 +35,16 @@ #include <functional> #include <memory> +namespace langutil +{ +class ErrorReporter; +struct SourceLocation; +} + namespace dev { namespace solidity { -class ErrorReporter; namespace assembly { @@ -55,9 +60,9 @@ class AsmAnalyzer: public boost::static_visitor<bool> public: explicit AsmAnalyzer( AsmAnalysisInfo& _analysisInfo, - ErrorReporter& _errorReporter, + langutil::ErrorReporter& _errorReporter, EVMVersion _evmVersion, - boost::optional<Error::Type> _errorTypeForLoose, + boost::optional<langutil::Error::Type> _errorTypeForLoose, AsmFlavour _flavour = AsmFlavour::Loose, yul::ExternalIdentifierAccess::Resolver const& _resolver = yul::ExternalIdentifierAccess::Resolver() ): @@ -90,20 +95,20 @@ public: private: /// Visits the statement and expects it to deposit one item onto the stack. bool expectExpression(Expression const& _expr); - bool expectDeposit(int _deposit, int _oldHeight, SourceLocation const& _location); + bool expectDeposit(int _deposit, int _oldHeight, langutil::SourceLocation const& _location); /// Verifies that a variable to be assigned to exists and has the same size /// as the value, @a _valueSize, unless that is equal to -1. bool checkAssignment(assembly::Identifier const& _assignment, size_t _valueSize = size_t(-1)); Scope& scope(assembly::Block const* _block); - void expectValidType(std::string const& type, SourceLocation const& _location); - void warnOnInstructions(solidity::Instruction _instr, SourceLocation const& _location); + void expectValidType(std::string const& type, langutil::SourceLocation const& _location); + void warnOnInstructions(solidity::Instruction _instr, langutil::SourceLocation const& _location); /// Depending on @a m_flavour and @a m_errorTypeForLoose, throws an internal compiler /// exception (if the flavour is not Loose), reports an error/warning /// (if m_errorTypeForLoose is set) or does nothing. - void checkLooseFeature(SourceLocation const& _location, std::string const& _description); + void checkLooseFeature(langutil::SourceLocation const& _location, std::string const& _description); int m_stackHeight = 0; yul::ExternalIdentifierAccess::Resolver m_resolver; @@ -112,10 +117,10 @@ private: /// "part of the scope but not yet declared") std::set<Scope::Variable const*> m_activeVariables; AsmAnalysisInfo& m_info; - ErrorReporter& m_errorReporter; + langutil::ErrorReporter& m_errorReporter; EVMVersion m_evmVersion; AsmFlavour m_flavour = AsmFlavour::Loose; - boost::optional<Error::Type> m_errorTypeForLoose; + boost::optional<langutil::Error::Type> m_errorTypeForLoose; }; } diff --git a/libsolidity/inlineasm/AsmCodeGen.cpp b/libsolidity/inlineasm/AsmCodeGen.cpp index 3a62b232..2800cc7b 100644 --- a/libsolidity/inlineasm/AsmCodeGen.cpp +++ b/libsolidity/inlineasm/AsmCodeGen.cpp @@ -29,7 +29,7 @@ #include <libsolidity/inlineasm/AsmAnalysisInfo.h> #include <libevmasm/Assembly.h> -#include <libevmasm/SourceLocation.h> +#include <liblangutil/SourceLocation.h> #include <libevmasm/Instruction.h> #include <libyul/backends/evm/AbstractAssembly.h> @@ -46,6 +46,7 @@ using namespace std; using namespace dev; +using namespace langutil; using namespace dev::solidity; using namespace dev::solidity::assembly; diff --git a/libsolidity/inlineasm/AsmData.h b/libsolidity/inlineasm/AsmData.h index a8d5e327..23a9db75 100644 --- a/libsolidity/inlineasm/AsmData.h +++ b/libsolidity/inlineasm/AsmData.h @@ -25,7 +25,7 @@ #include <libsolidity/inlineasm/AsmDataForward.h> #include <libevmasm/Instruction.h> -#include <libevmasm/SourceLocation.h> +#include <liblangutil/SourceLocation.h> #include <libyul/YulString.h> @@ -45,56 +45,56 @@ namespace assembly using YulString = dev::yul::YulString; using Type = YulString; -struct TypedName { SourceLocation location; YulString name; Type type; }; +struct TypedName { langutil::SourceLocation location; YulString name; Type type; }; using TypedNameList = std::vector<TypedName>; /// Direct EVM instruction (except PUSHi and JUMPDEST) -struct Instruction { SourceLocation location; solidity::Instruction instruction; }; +struct Instruction { langutil::SourceLocation location; solidity::Instruction instruction; }; /// Literal number or string (up to 32 bytes) enum class LiteralKind { Number, Boolean, String }; -struct Literal { SourceLocation location; LiteralKind kind; YulString value; Type type; }; +struct Literal { langutil::SourceLocation location; LiteralKind kind; YulString value; Type type; }; /// External / internal identifier or label reference -struct Identifier { SourceLocation location; YulString name; }; +struct Identifier { langutil::SourceLocation location; YulString name; }; /// Jump label ("name:") -struct Label { SourceLocation location; YulString name; }; +struct Label { langutil::SourceLocation location; YulString name; }; /// Assignment from stack (":= x", moves stack top into x, potentially multiple slots) -struct StackAssignment { SourceLocation location; Identifier variableName; }; +struct StackAssignment { langutil::SourceLocation location; Identifier variableName; }; /// Assignment ("x := mload(20:u256)", expects push-1-expression on the right hand /// side and requires x to occupy exactly one stack slot. /// /// Multiple assignment ("x, y := f()"), where the left hand side variables each occupy /// a single stack slot and expects a single expression on the right hand returning /// the same amount of items as the number of variables. -struct Assignment { SourceLocation location; std::vector<Identifier> variableNames; std::shared_ptr<Expression> value; }; +struct Assignment { langutil::SourceLocation location; std::vector<Identifier> variableNames; std::shared_ptr<Expression> value; }; /// Functional instruction, e.g. "mul(mload(20:u256), add(2:u256, x))" -struct FunctionalInstruction { SourceLocation location; solidity::Instruction instruction; std::vector<Expression> arguments; }; -struct FunctionCall { SourceLocation location; Identifier functionName; std::vector<Expression> arguments; }; +struct FunctionalInstruction { langutil::SourceLocation location; solidity::Instruction instruction; std::vector<Expression> arguments; }; +struct FunctionCall { langutil::SourceLocation location; Identifier functionName; std::vector<Expression> arguments; }; /// Statement that contains only a single expression -struct ExpressionStatement { SourceLocation location; Expression expression; }; +struct ExpressionStatement { langutil::SourceLocation location; Expression expression; }; /// Block-scope variable declaration ("let x:u256 := mload(20:u256)"), non-hoisted -struct VariableDeclaration { SourceLocation location; TypedNameList variables; std::shared_ptr<Expression> value; }; +struct VariableDeclaration { langutil::SourceLocation location; TypedNameList variables; std::shared_ptr<Expression> value; }; /// Block that creates a scope (frees declared stack variables) -struct Block { SourceLocation location; std::vector<Statement> statements; }; +struct Block { langutil::SourceLocation location; std::vector<Statement> statements; }; /// Function definition ("function f(a, b) -> (d, e) { ... }") -struct FunctionDefinition { SourceLocation location; YulString name; TypedNameList parameters; TypedNameList returnVariables; Block body; }; +struct FunctionDefinition { langutil::SourceLocation location; YulString name; TypedNameList parameters; TypedNameList returnVariables; Block body; }; /// Conditional execution without "else" part. -struct If { SourceLocation location; std::shared_ptr<Expression> condition; Block body; }; +struct If { langutil::SourceLocation location; std::shared_ptr<Expression> condition; Block body; }; /// Switch case or default case -struct Case { SourceLocation location; std::shared_ptr<Literal> value; Block body; }; +struct Case { langutil::SourceLocation location; std::shared_ptr<Literal> value; Block body; }; /// Switch statement -struct Switch { SourceLocation location; std::shared_ptr<Expression> expression; std::vector<Case> cases; }; -struct ForLoop { SourceLocation location; Block pre; std::shared_ptr<Expression> condition; Block post; Block body; }; +struct Switch { langutil::SourceLocation location; std::shared_ptr<Expression> expression; std::vector<Case> cases; }; +struct ForLoop { langutil::SourceLocation location; Block pre; std::shared_ptr<Expression> condition; Block post; Block body; }; -struct LocationExtractor: boost::static_visitor<SourceLocation> +struct LocationExtractor: boost::static_visitor<langutil::SourceLocation> { - template <class T> SourceLocation operator()(T const& _node) const + template <class T> langutil::SourceLocation operator()(T const& _node) const { return _node.location; } }; /// Extracts the source location from an inline assembly node. -template <class T> inline SourceLocation locationOf(T const& _node) +template <class T> inline langutil::SourceLocation locationOf(T const& _node) { return boost::apply_visitor(LocationExtractor(), _node); } diff --git a/libsolidity/inlineasm/AsmParser.cpp b/libsolidity/inlineasm/AsmParser.cpp index 1f399edc..b11f70e0 100644 --- a/libsolidity/inlineasm/AsmParser.cpp +++ b/libsolidity/inlineasm/AsmParser.cpp @@ -21,8 +21,8 @@ */ #include <libsolidity/inlineasm/AsmParser.h> -#include <libsolidity/parsing/Scanner.h> -#include <libsolidity/interface/ErrorReporter.h> +#include <liblangutil/Scanner.h> +#include <liblangutil/ErrorReporter.h> #include <boost/algorithm/string.hpp> @@ -31,6 +31,7 @@ using namespace std; using namespace dev; +using namespace langutil; using namespace dev::solidity; using namespace dev::solidity::assembly; diff --git a/libsolidity/inlineasm/AsmParser.h b/libsolidity/inlineasm/AsmParser.h index 41117228..9e13799a 100644 --- a/libsolidity/inlineasm/AsmParser.h +++ b/libsolidity/inlineasm/AsmParser.h @@ -25,7 +25,9 @@ #include <memory> #include <vector> #include <libsolidity/inlineasm/AsmData.h> -#include <libsolidity/parsing/ParserBase.h> +#include <liblangutil/SourceLocation.h> +#include <liblangutil/Scanner.h> +#include <liblangutil/ParserBase.h> namespace dev { @@ -34,22 +36,22 @@ namespace solidity namespace assembly { -class Parser: public ParserBase +class Parser: public langutil::ParserBase { public: - explicit Parser(ErrorReporter& _errorReporter, AsmFlavour _flavour = AsmFlavour::Loose): + explicit Parser(langutil::ErrorReporter& _errorReporter, AsmFlavour _flavour = AsmFlavour::Loose): ParserBase(_errorReporter), m_flavour(_flavour) {} /// Parses an inline assembly block starting with `{` and ending with `}`. /// @param _reuseScanner if true, do check for end of input after the `}`. /// @returns an empty shared pointer on error. - std::shared_ptr<Block> parse(std::shared_ptr<Scanner> const& _scanner, bool _reuseScanner); + std::shared_ptr<Block> parse(std::shared_ptr<langutil::Scanner> const& _scanner, bool _reuseScanner); protected: using ElementaryOperation = boost::variant<assembly::Instruction, assembly::Literal, assembly::Identifier>; /// Creates an inline assembly node with the given source location. - template <class T> T createWithLocation(SourceLocation const& _loc = SourceLocation()) const + template <class T> T createWithLocation(langutil::SourceLocation const& _loc = {}) const { T r; r.location = _loc; @@ -62,7 +64,7 @@ protected: r.location.sourceName = sourceName(); return r; } - SourceLocation location() const { return SourceLocation(position(), endPosition(), sourceName()); } + langutil::SourceLocation location() const { return {position(), endPosition(), sourceName()}; } Block parseBlock(); Statement parseStatement(); diff --git a/libsolidity/inlineasm/AsmPrinter.cpp b/libsolidity/inlineasm/AsmPrinter.cpp index ae0bd1eb..7151fcfa 100644 --- a/libsolidity/inlineasm/AsmPrinter.cpp +++ b/libsolidity/inlineasm/AsmPrinter.cpp @@ -22,7 +22,7 @@ #include <libsolidity/inlineasm/AsmPrinter.h> #include <libsolidity/inlineasm/AsmData.h> -#include <libsolidity/interface/Exceptions.h> +#include <liblangutil/Exceptions.h> #include <libdevcore/CommonData.h> diff --git a/libsolidity/inlineasm/AsmScope.h b/libsolidity/inlineasm/AsmScope.h index 65848018..12c05716 100644 --- a/libsolidity/inlineasm/AsmScope.h +++ b/libsolidity/inlineasm/AsmScope.h @@ -20,7 +20,7 @@ #pragma once -#include <libsolidity/interface/Exceptions.h> +#include <liblangutil/Exceptions.h> #include <libyul/YulString.h> diff --git a/libsolidity/inlineasm/AsmScopeFiller.cpp b/libsolidity/inlineasm/AsmScopeFiller.cpp index d1f98083..09934bd8 100644 --- a/libsolidity/inlineasm/AsmScopeFiller.cpp +++ b/libsolidity/inlineasm/AsmScopeFiller.cpp @@ -24,8 +24,8 @@ #include <libsolidity/inlineasm/AsmScope.h> #include <libsolidity/inlineasm/AsmAnalysisInfo.h> -#include <libsolidity/interface/ErrorReporter.h> -#include <libsolidity/interface/Exceptions.h> +#include <liblangutil/ErrorReporter.h> +#include <liblangutil/Exceptions.h> #include <libdevcore/CommonData.h> @@ -36,6 +36,7 @@ using namespace std; using namespace dev; +using namespace langutil; using namespace dev::solidity; using namespace dev::solidity::assembly; diff --git a/libsolidity/inlineasm/AsmScopeFiller.h b/libsolidity/inlineasm/AsmScopeFiller.h index bb023f61..7454fd6c 100644 --- a/libsolidity/inlineasm/AsmScopeFiller.h +++ b/libsolidity/inlineasm/AsmScopeFiller.h @@ -27,12 +27,16 @@ #include <functional> #include <memory> -namespace dev +namespace langutil { +class ErrorReporter; struct SourceLocation; +} + +namespace dev +{ namespace solidity { -class ErrorReporter; namespace assembly { @@ -47,7 +51,7 @@ struct AsmAnalysisInfo; class ScopeFiller: public boost::static_visitor<bool> { public: - ScopeFiller(AsmAnalysisInfo& _info, ErrorReporter& _errorReporter); + ScopeFiller(AsmAnalysisInfo& _info, langutil::ErrorReporter& _errorReporter); bool operator()(assembly::Instruction const&) { return true; } bool operator()(assembly::Literal const&) { return true; } @@ -68,7 +72,7 @@ public: private: bool registerVariable( TypedName const& _name, - SourceLocation const& _location, + langutil::SourceLocation const& _location, Scope& _scope ); @@ -76,7 +80,7 @@ private: Scope* m_currentScope = nullptr; AsmAnalysisInfo& m_info; - ErrorReporter& m_errorReporter; + langutil::ErrorReporter& m_errorReporter; }; } diff --git a/libsolidity/interface/AssemblyStack.cpp b/libsolidity/interface/AssemblyStack.cpp index 26496de7..5b6b1113 100644 --- a/libsolidity/interface/AssemblyStack.cpp +++ b/libsolidity/interface/AssemblyStack.cpp @@ -22,7 +22,7 @@ #include <libsolidity/interface/AssemblyStack.h> -#include <libsolidity/parsing/Scanner.h> +#include <liblangutil/Scanner.h> #include <libsolidity/inlineasm/AsmPrinter.h> #include <libsolidity/inlineasm/AsmParser.h> #include <libsolidity/inlineasm/AsmAnalysis.h> @@ -36,6 +36,7 @@ using namespace std; using namespace dev; +using namespace langutil; using namespace dev::solidity; namespace diff --git a/libsolidity/interface/AssemblyStack.h b/libsolidity/interface/AssemblyStack.h index 8132ce63..d6ee33cf 100644 --- a/libsolidity/interface/AssemblyStack.h +++ b/libsolidity/interface/AssemblyStack.h @@ -21,19 +21,23 @@ #pragma once -#include <libsolidity/interface/ErrorReporter.h> -#include <libsolidity/interface/EVMVersion.h> +#include <liblangutil/ErrorReporter.h> +#include <liblangutil/EVMVersion.h> #include <libevmasm/LinkerObject.h> #include <string> #include <memory> +namespace langutil +{ +class Scanner; +} + namespace dev { namespace solidity { -class Scanner; namespace assembly { struct AsmAnalysisInfo; @@ -61,7 +65,7 @@ public: {} /// @returns the scanner used during parsing - Scanner const& scanner() const; + langutil::Scanner const& scanner() const; /// Runs parsing and analysis steps, returns false if input cannot be assembled. /// Multiple calls overwrite the previous state. @@ -69,13 +73,13 @@ public: /// Runs analysis step on the supplied block, returns false if input cannot be assembled. /// Multiple calls overwrite the previous state. - bool analyze(assembly::Block const& _block, Scanner const* _scanner = nullptr); + bool analyze(assembly::Block const& _block, langutil::Scanner const* _scanner = nullptr); /// Run the assembly step (should only be called after parseAndAnalyze). MachineAssemblyObject assemble(Machine _machine) const; /// @returns the errors generated during parsing, analysis (and potentially assembly). - ErrorList const& errors() const { return m_errors; } + langutil::ErrorList const& errors() const { return m_errors; } /// Pretty-print the input after having parsed it. std::string print() const; @@ -86,13 +90,13 @@ private: Language m_language = Language::Assembly; EVMVersion m_evmVersion; - std::shared_ptr<Scanner> m_scanner; + std::shared_ptr<langutil::Scanner> m_scanner; bool m_analysisSuccessful = false; std::shared_ptr<assembly::Block> m_parserResult; std::shared_ptr<assembly::AsmAnalysisInfo> m_analysisInfo; - ErrorList m_errors; - ErrorReporter m_errorReporter; + langutil::ErrorList m_errors; + langutil::ErrorReporter m_errorReporter; }; } diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp index d6a63f1d..a5674705 100644 --- a/libsolidity/interface/CompilerStack.cpp +++ b/libsolidity/interface/CompilerStack.cpp @@ -27,7 +27,7 @@ #include <libsolidity/interface/Version.h> #include <libsolidity/analysis/SemVerHandler.h> #include <libsolidity/ast/AST.h> -#include <libsolidity/parsing/Scanner.h> +#include <liblangutil/Scanner.h> #include <libsolidity/parsing/Parser.h> #include <libsolidity/analysis/ControlFlowAnalyzer.h> #include <libsolidity/analysis/ControlFlowGraph.h> @@ -58,6 +58,7 @@ using namespace std; using namespace dev; +using namespace langutil; using namespace dev::solidity; boost::optional<CompilerStack::Remapping> CompilerStack::parseRemapping(string const& _remapping) diff --git a/libsolidity/interface/CompilerStack.h b/libsolidity/interface/CompilerStack.h index 9a15fbf0..8c50266e 100644 --- a/libsolidity/interface/CompilerStack.h +++ b/libsolidity/interface/CompilerStack.h @@ -23,11 +23,12 @@ #pragma once -#include <libsolidity/interface/ErrorReporter.h> #include <libsolidity/interface/ReadFile.h> -#include <libsolidity/interface/EVMVersion.h> -#include <libevmasm/SourceLocation.h> +#include <liblangutil/ErrorReporter.h> +#include <liblangutil/EVMVersion.h> +#include <liblangutil/SourceLocation.h> + #include <libevmasm/LinkerObject.h> #include <libdevcore/Common.h> @@ -43,6 +44,11 @@ #include <vector> #include <functional> +namespace langutil +{ +class Scanner; +} + namespace dev { @@ -57,7 +63,6 @@ namespace solidity { // forward declarations -class Scanner; class ASTNode; class ContractDefinition; class FunctionDefinition; @@ -65,7 +70,6 @@ class SourceUnit; class Compiler; class GlobalContext; class Natspec; -class Error; class DeclarationContainer; /** @@ -100,7 +104,7 @@ public: m_errorReporter(m_errorList) {} /// @returns the list of errors that occurred during parsing and type checking. - ErrorList const& errors() const { return m_errorReporter.errors(); } + langutil::ErrorList const& errors() const { return m_errorReporter.errors(); } /// @returns the current state. State state() const { return m_stackState; } @@ -174,7 +178,7 @@ public: std::map<std::string, unsigned> sourceIndices() const; /// @returns the previously used scanner, useful for counting lines during error reporting. - Scanner const& scanner(std::string const& _sourceName) const; + langutil::Scanner const& scanner(std::string const& _sourceName) const; /// @returns the parsed source unit with the supplied name. SourceUnit const& ast(std::string const& _sourceName) const; @@ -182,7 +186,7 @@ public: /// Helper function for logs printing. Do only use in error cases, it's quite expensive. /// line and columns are numbered starting from 1 with following order: /// start line, start column, end line, end column - std::tuple<int, int, int, int> positionFromSourceLocation(SourceLocation const& _sourceLocation) const; + std::tuple<int, int, int, int> positionFromSourceLocation(langutil::SourceLocation const& _sourceLocation) const; /// @returns a list of the contract names in the sources. std::vector<std::string> contractNames() const; @@ -248,7 +252,7 @@ private: /// The state per source unit. Filled gradually during parsing. struct Source { - std::shared_ptr<Scanner> scanner; + std::shared_ptr<langutil::Scanner> scanner; std::shared_ptr<SourceUnit> ast; bool isLibrary = false; void reset() { scanner.reset(); ast.reset(); } @@ -345,8 +349,8 @@ private: /// This is updated during compilation. std::map<ASTNode const*, std::shared_ptr<DeclarationContainer>> m_scopes; std::map<std::string const, Contract> m_contracts; - ErrorList m_errorList; - ErrorReporter m_errorReporter; + langutil::ErrorList m_errorList; + langutil::ErrorReporter m_errorReporter; bool m_metadataLiteralSources = false; State m_stackState = Empty; }; diff --git a/libsolidity/interface/GasEstimator.cpp b/libsolidity/interface/GasEstimator.cpp index 1f20366e..de6b2ce5 100644 --- a/libsolidity/interface/GasEstimator.cpp +++ b/libsolidity/interface/GasEstimator.cpp @@ -35,6 +35,7 @@ using namespace std; using namespace dev; using namespace dev::eth; +using namespace langutil; using namespace dev::solidity; GasEstimator::ASTGasConsumptionSelfAccumulated GasEstimator::structuralEstimation( diff --git a/libsolidity/interface/GasEstimator.h b/libsolidity/interface/GasEstimator.h index ea94d988..214a3e58 100644 --- a/libsolidity/interface/GasEstimator.h +++ b/libsolidity/interface/GasEstimator.h @@ -22,7 +22,7 @@ #pragma once -#include <libsolidity/interface/EVMVersion.h> +#include <liblangutil/EVMVersion.h> #include <libevmasm/GasMeter.h> #include <libevmasm/Assembly.h> diff --git a/libsolidity/interface/SourceReferenceFormatter.cpp b/libsolidity/interface/SourceReferenceFormatter.cpp index 865907e2..d727afbe 100644 --- a/libsolidity/interface/SourceReferenceFormatter.cpp +++ b/libsolidity/interface/SourceReferenceFormatter.cpp @@ -21,10 +21,11 @@ */ #include <libsolidity/interface/SourceReferenceFormatter.h> -#include <libsolidity/parsing/Scanner.h> -#include <libsolidity/interface/Exceptions.h> +#include <liblangutil/Scanner.h> +#include <liblangutil/Exceptions.h> using namespace std; +using namespace langutil; namespace dev { diff --git a/libsolidity/interface/SourceReferenceFormatter.h b/libsolidity/interface/SourceReferenceFormatter.h index a32babdc..7dea5254 100644 --- a/libsolidity/interface/SourceReferenceFormatter.h +++ b/libsolidity/interface/SourceReferenceFormatter.h @@ -25,7 +25,12 @@ #include <ostream> #include <sstream> #include <functional> -#include <libevmasm/SourceLocation.h> + +namespace langutil +{ +struct SourceLocation; +class Scanner; +} namespace dev { @@ -35,13 +40,12 @@ struct Exception; // forward namespace solidity { -class Scanner; // forward class CompilerStack; // forward class SourceReferenceFormatter { public: - using ScannerFromSourceNameFun = std::function<Scanner const&(std::string const&)>; + using ScannerFromSourceNameFun = std::function<langutil::Scanner const&(std::string const&)>; explicit SourceReferenceFormatter( std::ostream& _stream, @@ -52,7 +56,7 @@ public: {} /// Prints source location if it is given. - void printSourceLocation(SourceLocation const* _location); + void printSourceLocation(langutil::SourceLocation const* _location); void printExceptionInformation(Exception const& _exception, std::string const& _name); static std::string formatExceptionInformation( @@ -69,7 +73,7 @@ public: } private: /// Prints source name if location is given. - void printSourceName(SourceLocation const* _location); + void printSourceName(langutil::SourceLocation const* _location); std::ostream& m_stream; ScannerFromSourceNameFun m_scannerFromSourceName; diff --git a/libsolidity/interface/StandardCompiler.cpp b/libsolidity/interface/StandardCompiler.cpp index c8b03a94..291a1071 100644 --- a/libsolidity/interface/StandardCompiler.cpp +++ b/libsolidity/interface/StandardCompiler.cpp @@ -31,6 +31,7 @@ using namespace std; using namespace dev; +using namespace langutil; using namespace dev::solidity; namespace { @@ -411,7 +412,7 @@ Json::Value StandardCompiler::compileInternal(Json::Value const& _input) Json::Value outputSelection = settings.get("outputSelection", Json::Value()); m_compilerStack.setRequestedContractNames(requestedContractNames(outputSelection)); - auto scannerFromSourceName = [&](string const& _sourceName) -> solidity::Scanner const& { return m_compilerStack.scanner(_sourceName); }; + auto scannerFromSourceName = [&](string const& _sourceName) -> Scanner const& { return m_compilerStack.scanner(_sourceName); }; try { diff --git a/libsolidity/interface/Version.cpp b/libsolidity/interface/Version.cpp index b5f68ce8..b785d557 100644 --- a/libsolidity/interface/Version.cpp +++ b/libsolidity/interface/Version.cpp @@ -24,7 +24,7 @@ #include <string> #include <libdevcore/CommonData.h> #include <libdevcore/Common.h> -#include <libsolidity/interface/Exceptions.h> +#include <liblangutil/Exceptions.h> #include <solidity/BuildInfo.h> using namespace dev; diff --git a/libsolidity/parsing/DocStringParser.cpp b/libsolidity/parsing/DocStringParser.cpp index d9588e5c..d8927fea 100644 --- a/libsolidity/parsing/DocStringParser.cpp +++ b/libsolidity/parsing/DocStringParser.cpp @@ -1,13 +1,14 @@ #include <libsolidity/parsing/DocStringParser.h> -#include <libsolidity/interface/ErrorReporter.h> -#include <libsolidity/interface/Exceptions.h> +#include <liblangutil/ErrorReporter.h> +#include <liblangutil/Exceptions.h> #include <boost/range/irange.hpp> #include <boost/range/algorithm.hpp> using namespace std; using namespace dev; +using namespace langutil; using namespace dev::solidity; diff --git a/libsolidity/parsing/DocStringParser.h b/libsolidity/parsing/DocStringParser.h index 5f2819cc..c83b416d 100644 --- a/libsolidity/parsing/DocStringParser.h +++ b/libsolidity/parsing/DocStringParser.h @@ -25,19 +25,22 @@ #include <string> #include <libsolidity/ast/ASTAnnotations.h> +namespace langutil +{ +class ErrorReporter; +} + namespace dev { namespace solidity { -class ErrorReporter; - class DocStringParser { public: /// Parse the given @a _docString and stores the parsed components internally. /// @returns false on error and appends the error to @a _errors. - bool parse(std::string const& _docString, ErrorReporter& _errorReporter); + bool parse(std::string const& _docString, langutil::ErrorReporter& _errorReporter); std::multimap<std::string, DocTag> const& tags() const { return m_docTags; } @@ -63,7 +66,7 @@ private: /// Mapping tag name -> content. std::multimap<std::string, DocTag> m_docTags; DocTag* m_lastTag = nullptr; - ErrorReporter* m_errorReporter = nullptr; + langutil::ErrorReporter* m_errorReporter = nullptr; bool m_errorsOccurred = false; }; diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp index b17dad9a..de5293b4 100644 --- a/libsolidity/parsing/Parser.cpp +++ b/libsolidity/parsing/Parser.cpp @@ -22,13 +22,14 @@ #include <cctype> #include <vector> -#include <libevmasm/SourceLocation.h> +#include <liblangutil/SourceLocation.h> #include <libsolidity/parsing/Parser.h> -#include <libsolidity/parsing/Scanner.h> +#include <liblangutil/Scanner.h> #include <libsolidity/inlineasm/AsmParser.h> -#include <libsolidity/interface/ErrorReporter.h> +#include <liblangutil/ErrorReporter.h> using namespace std; +using namespace langutil; namespace dev { diff --git a/libsolidity/parsing/Parser.h b/libsolidity/parsing/Parser.h index fa974171..15852096 100644 --- a/libsolidity/parsing/Parser.h +++ b/libsolidity/parsing/Parser.h @@ -23,21 +23,24 @@ #pragma once #include <libsolidity/ast/AST.h> -#include <libsolidity/parsing/ParserBase.h> +#include <liblangutil/ParserBase.h> + +namespace langutil +{ +class Scanner; +} namespace dev { namespace solidity { -class Scanner; - -class Parser: public ParserBase +class Parser: public langutil::ParserBase { public: - explicit Parser(ErrorReporter& _errorReporter): ParserBase(_errorReporter) {} + explicit Parser(langutil::ErrorReporter& _errorReporter): ParserBase(_errorReporter) {} - ASTPointer<SourceUnit> parse(std::shared_ptr<Scanner> const& _scanner); + ASTPointer<SourceUnit> parse(std::shared_ptr<langutil::Scanner> const& _scanner); private: class ASTNodeFactory; @@ -146,7 +149,7 @@ private: struct IndexAccessedPath { std::vector<ASTPointer<PrimaryExpression>> path; - std::vector<std::pair<ASTPointer<Expression>, SourceLocation>> indices; + std::vector<std::pair<ASTPointer<Expression>, langutil::SourceLocation>> indices; bool empty() const; }; diff --git a/libsolidity/parsing/Token.h b/libsolidity/parsing/Token.h index 81e8dd98..d61aefb6 100644 --- a/libsolidity/parsing/Token.h +++ b/libsolidity/parsing/Token.h @@ -1,378 +1,36 @@ -// Copyright 2006-2012, the V8 project authors. All rights reserved. -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following -// disclaimer in the documentation and/or other materials provided -// with the distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived -// from this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Modifications as part of solidity under the following license: -// -// 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/>. - +/* + 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/>. +*/ +/** + * Solidity and Yul both share the same Token (and Scanner) API. + * + * This may (or may not) change in the future. But for the time being, we've put both + * at a shared place, and *just* import them. +*/ #pragma once -#include <libdevcore/Common.h> -#include <libsolidity/interface/Exceptions.h> -#include <libsolidity/parsing/UndefMacros.h> -#include <iosfwd> +#include <liblangutil/Token.h> namespace dev { namespace solidity { +namespace TokenTraits = ::langutil::TokenTraits; -// TOKEN_LIST takes a list of 3 macros M, all of which satisfy the -// same signature M(name, string, precedence), where name is the -// symbolic token name, string is the corresponding syntactic symbol -// (or NULL, for literals), and precedence is the precedence (or 0). -// The parameters are invoked for token categories as follows: -// -// T: Non-keyword tokens -// K: Keyword tokens - -// IGNORE_TOKEN is a convenience macro that can be supplied as -// an argument (at any position) for a TOKEN_LIST call. It does -// nothing with tokens belonging to the respective category. - -#define IGNORE_TOKEN(name, string, precedence) - -#define TOKEN_LIST(T, K) \ - /* End of source indicator. */ \ - T(EOS, "EOS", 0) \ - \ - /* Punctuators (ECMA-262, section 7.7, page 15). */ \ - T(LParen, "(", 0) \ - T(RParen, ")", 0) \ - T(LBrack, "[", 0) \ - T(RBrack, "]", 0) \ - T(LBrace, "{", 0) \ - T(RBrace, "}", 0) \ - T(Colon, ":", 0) \ - T(Semicolon, ";", 0) \ - T(Period, ".", 0) \ - T(Conditional, "?", 3) \ - T(Arrow, "=>", 0) \ - \ - /* Assignment operators. */ \ - /* IsAssignmentOp() relies on this block of enum values being */ \ - /* contiguous and sorted in the same order!*/ \ - T(Assign, "=", 2) \ - /* The following have to be in exactly the same order as the simple binary operators*/ \ - T(AssignBitOr, "|=", 2) \ - T(AssignBitXor, "^=", 2) \ - T(AssignBitAnd, "&=", 2) \ - T(AssignShl, "<<=", 2) \ - T(AssignSar, ">>=", 2) \ - T(AssignShr, ">>>=", 2) \ - T(AssignAdd, "+=", 2) \ - T(AssignSub, "-=", 2) \ - T(AssignMul, "*=", 2) \ - T(AssignDiv, "/=", 2) \ - T(AssignMod, "%=", 2) \ - \ - /* Binary operators sorted by precedence. */ \ - /* IsBinaryOp() relies on this block of enum values */ \ - /* being contiguous and sorted in the same order! */ \ - T(Comma, ",", 1) \ - T(Or, "||", 4) \ - T(And, "&&", 5) \ - T(BitOr, "|", 8) \ - T(BitXor, "^", 9) \ - T(BitAnd, "&", 10) \ - T(SHL, "<<", 11) \ - T(SAR, ">>", 11) \ - T(SHR, ">>>", 11) \ - T(Add, "+", 12) \ - T(Sub, "-", 12) \ - T(Mul, "*", 13) \ - T(Div, "/", 13) \ - T(Mod, "%", 13) \ - T(Exp, "**", 14) \ - \ - /* Compare operators sorted by precedence. */ \ - /* IsCompareOp() relies on this block of enum values */ \ - /* being contiguous and sorted in the same order! */ \ - T(Equal, "==", 6) \ - T(NotEqual, "!=", 6) \ - T(LessThan, "<", 7) \ - T(GreaterThan, ">", 7) \ - T(LessThanOrEqual, "<=", 7) \ - T(GreaterThanOrEqual, ">=", 7) \ - \ - /* Unary operators. */ \ - /* IsUnaryOp() relies on this block of enum values */ \ - /* being contiguous and sorted in the same order! */ \ - T(Not, "!", 0) \ - T(BitNot, "~", 0) \ - T(Inc, "++", 0) \ - T(Dec, "--", 0) \ - K(Delete, "delete", 0) \ - \ - /* Keywords */ \ - K(Anonymous, "anonymous", 0) \ - K(As, "as", 0) \ - K(Assembly, "assembly", 0) \ - K(Break, "break", 0) \ - K(Constant, "constant", 0) \ - K(Constructor, "constructor", 0) \ - K(Continue, "continue", 0) \ - K(Contract, "contract", 0) \ - K(Do, "do", 0) \ - K(Else, "else", 0) \ - K(Enum, "enum", 0) \ - K(Emit, "emit", 0) \ - K(Event, "event", 0) \ - K(External, "external", 0) \ - K(For, "for", 0) \ - K(Function, "function", 0) \ - K(Hex, "hex", 0) \ - K(If, "if", 0) \ - K(Indexed, "indexed", 0) \ - K(Interface, "interface", 0) \ - K(Internal, "internal", 0) \ - K(Import, "import", 0) \ - K(Is, "is", 0) \ - K(Library, "library", 0) \ - K(Mapping, "mapping", 0) \ - K(Memory, "memory", 0) \ - K(Modifier, "modifier", 0) \ - K(New, "new", 0) \ - K(Payable, "payable", 0) \ - K(Public, "public", 0) \ - K(Pragma, "pragma", 0) \ - K(Private, "private", 0) \ - K(Pure, "pure", 0) \ - K(Return, "return", 0) \ - K(Returns, "returns", 0) \ - K(Storage, "storage", 0) \ - K(CallData, "calldata", 0) \ - K(Struct, "struct", 0) \ - K(Throw, "throw", 0) \ - K(Using, "using", 0) \ - K(Var, "var", 0) \ - K(View, "view", 0) \ - K(While, "while", 0) \ - \ - /* Ether subdenominations */ \ - K(SubWei, "wei", 0) \ - K(SubSzabo, "szabo", 0) \ - K(SubFinney, "finney", 0) \ - K(SubEther, "ether", 0) \ - K(SubSecond, "seconds", 0) \ - K(SubMinute, "minutes", 0) \ - K(SubHour, "hours", 0) \ - K(SubDay, "days", 0) \ - K(SubWeek, "weeks", 0) \ - K(SubYear, "years", 0) \ - /* type keywords*/ \ - K(Int, "int", 0) \ - K(UInt, "uint", 0) \ - K(Bytes, "bytes", 0) \ - K(Byte, "byte", 0) \ - K(String, "string", 0) \ - K(Address, "address", 0) \ - K(Bool, "bool", 0) \ - K(Fixed, "fixed", 0) \ - K(UFixed, "ufixed", 0) \ - T(IntM, "intM", 0) \ - T(UIntM, "uintM", 0) \ - T(BytesM, "bytesM", 0) \ - T(FixedMxN, "fixedMxN", 0) \ - T(UFixedMxN, "ufixedMxN", 0) \ - T(TypesEnd, NULL, 0) /* used as type enum end marker */ \ - \ - /* Literals */ \ - K(TrueLiteral, "true", 0) \ - K(FalseLiteral, "false", 0) \ - T(Number, NULL, 0) \ - T(StringLiteral, NULL, 0) \ - T(CommentLiteral, NULL, 0) \ - \ - /* Identifiers (not keywords or future reserved words). */ \ - T(Identifier, NULL, 0) \ - \ - /* Keywords reserved for future use. */ \ - K(Abstract, "abstract", 0) \ - K(After, "after", 0) \ - K(Alias, "alias", 0) \ - K(Apply, "apply", 0) \ - K(Auto, "auto", 0) \ - K(Case, "case", 0) \ - K(Catch, "catch", 0) \ - K(CopyOf, "copyof", 0) \ - K(Default, "default", 0) \ - K(Define, "define", 0) \ - K(Final, "final", 0) \ - K(Immutable, "immutable", 0) \ - K(Implements, "implements", 0) \ - K(In, "in", 0) \ - K(Inline, "inline", 0) \ - K(Let, "let", 0) \ - K(Macro, "macro", 0) \ - K(Match, "match", 0) \ - K(Mutable, "mutable", 0) \ - K(NullLiteral, "null", 0) \ - K(Of, "of", 0) \ - K(Override, "override", 0) \ - K(Partial, "partial", 0) \ - K(Promise, "promise", 0) \ - K(Reference, "reference", 0) \ - K(Relocatable, "relocatable", 0) \ - K(Sealed, "sealed", 0) \ - K(Sizeof, "sizeof", 0) \ - K(Static, "static", 0) \ - K(Supports, "supports", 0) \ - K(Switch, "switch", 0) \ - K(Try, "try", 0) \ - K(Type, "type", 0) \ - K(Typedef, "typedef", 0) \ - K(TypeOf, "typeof", 0) \ - K(Unchecked, "unchecked", 0) \ - \ - /* Illegal token - not able to scan. */ \ - T(Illegal, "ILLEGAL", 0) \ - /* Illegal hex token */ \ - T(IllegalHex, "ILLEGAL_HEX", 0) \ - \ - /* Scanner-internal use only. */ \ - T(Whitespace, NULL, 0) - -// All token values. -// attention! msvc issue: -// http://stackoverflow.com/questions/9567868/compile-errors-after-adding-v8-to-my-project-c2143-c2059 -// @todo: avoid TOKEN_LIST macro -enum class Token : unsigned int { -#define T(name, string, precedence) name, - TOKEN_LIST(T, T) - NUM_TOKENS -#undef T -}; - -namespace TokenTraits -{ - constexpr size_t count() { return static_cast<size_t>(Token::NUM_TOKENS); } - - // Predicates - constexpr bool isElementaryTypeName(Token tok) { return Token::Int <= tok && tok < Token::TypesEnd; } - constexpr bool isAssignmentOp(Token tok) { return Token::Assign <= tok && tok <= Token::AssignMod; } - constexpr bool isBinaryOp(Token op) { return Token::Comma <= op && op <= Token::Exp; } - constexpr bool isCommutativeOp(Token op) { return op == Token::BitOr || op == Token::BitXor || op == Token::BitAnd || - op == Token::Add || op == Token::Mul || op == Token::Equal || op == Token::NotEqual; } - constexpr bool isArithmeticOp(Token op) { return Token::Add <= op && op <= Token::Exp; } - constexpr bool isCompareOp(Token op) { return Token::Equal <= op && op <= Token::GreaterThanOrEqual; } - - constexpr bool isBitOp(Token op) { return (Token::BitOr <= op && op <= Token::BitAnd) || op == Token::BitNot; } - constexpr bool isBooleanOp(Token op) { return (Token::Or <= op && op <= Token::And) || op == Token::Not; } - constexpr bool isUnaryOp(Token op) { return (Token::Not <= op && op <= Token::Delete) || op == Token::Add || op == Token::Sub; } - constexpr bool isCountOp(Token op) { return op == Token::Inc || op == Token::Dec; } - constexpr bool isShiftOp(Token op) { return (Token::SHL <= op) && (op <= Token::SHR); } - constexpr bool isVariableVisibilitySpecifier(Token op) { return op == Token::Public || op == Token::Private || op == Token::Internal; } - constexpr bool isVisibilitySpecifier(Token op) { return isVariableVisibilitySpecifier(op) || op == Token::External; } - constexpr bool isLocationSpecifier(Token op) { return op == Token::Memory || op == Token::Storage || op == Token::CallData; } - - constexpr bool isStateMutabilitySpecifier(Token op, bool _allowConstant = true) - { - return (op == Token::Constant && _allowConstant) - || op == Token::Pure || op == Token::View || op == Token::Payable; - } - - constexpr bool isEtherSubdenomination(Token op) { return op == Token::SubWei || op == Token::SubSzabo || op == Token::SubFinney || op == Token::SubEther; } - constexpr bool isTimeSubdenomination(Token op) { return op == Token::SubSecond || op == Token::SubMinute || op == Token::SubHour || op == Token::SubDay || op == Token::SubWeek || op == Token::SubYear; } - constexpr bool isReservedKeyword(Token op) { return (Token::Abstract <= op && op <= Token::Unchecked); } - - inline Token AssignmentToBinaryOp(Token op) - { - solAssert(isAssignmentOp(op) && op != Token::Assign, ""); - return static_cast<Token>(static_cast<int>(op) + (static_cast<int>(Token::BitOr) - static_cast<int>(Token::AssignBitOr))); - } - - // @returns the precedence > 0 for binary and compare - // operators; returns 0 otherwise. - int precedence(Token tok); - - std::tuple<Token, unsigned int, unsigned int> fromIdentifierOrKeyword(std::string const& _literal); - - // @returns a string corresponding to the C++ token name - // (e.g. "LT" for the token LT). - char const* name(Token tok); - - // @returns a string corresponding to the JS token string - // (.e., "<" for the token LT) or NULL if the token doesn't - // have a (unique) string (e.g. an IDENTIFIER). - char const* toString(Token tok); - - std::string friendlyName(Token tok); -} - -inline std::ostream& operator<<(std::ostream& os, Token token) -{ - os << TokenTraits::friendlyName(token); - return os; -} - -class ElementaryTypeNameToken -{ -public: - ElementaryTypeNameToken(Token _token, unsigned const& _firstNumber, unsigned const& _secondNumber) - { - assertDetails(_token, _firstNumber, _secondNumber); - } - - unsigned int firstNumber() const { return m_firstNumber; } - unsigned int secondNumber() const { return m_secondNumber; } - Token token() const { return m_token; } - - ///if tokValue is set to true, then returns the actual token type name, otherwise, returns full type - std::string toString(bool const& tokenValue = false) const - { - std::string name = TokenTraits::toString(m_token); - if (tokenValue || (firstNumber() == 0 && secondNumber() == 0)) - return name; - solAssert(name.size() >= 3, "Token name size should be greater than 3. Should not reach here."); - if (m_token == Token::FixedMxN || m_token == Token::UFixedMxN) - return name.substr(0, name.size() - 3) + std::to_string(m_firstNumber) + "x" + std::to_string(m_secondNumber); - else - return name.substr(0, name.size() - 1) + std::to_string(m_firstNumber); - } - -private: - Token m_token; - unsigned int m_firstNumber; - unsigned int m_secondNumber; - /// throws if type is not properly sized - void assertDetails(Token _baseType, unsigned const& _first, unsigned const& _second); -}; - +using ::langutil::Token; +using ::langutil::ElementaryTypeNameToken; } } diff --git a/libyul/backends/evm/AbstractAssembly.h b/libyul/backends/evm/AbstractAssembly.h index d75058f7..5a1140cb 100644 --- a/libyul/backends/evm/AbstractAssembly.h +++ b/libyul/backends/evm/AbstractAssembly.h @@ -26,9 +26,13 @@ #include <functional> -namespace dev +namespace langutil { struct SourceLocation; +} + +namespace dev +{ namespace solidity { enum class Instruction: uint8_t; @@ -52,7 +56,7 @@ public: virtual ~AbstractAssembly() {} /// Set a new source location valid starting from the next instruction. - virtual void setSourceLocation(SourceLocation const& _location) = 0; + virtual void setSourceLocation(langutil::SourceLocation const& _location) = 0; /// Retrieve the current height of the stack. This does not have to be zero /// at the beginning. virtual int stackHeight() const = 0; diff --git a/libyul/backends/evm/EVMAssembly.cpp b/libyul/backends/evm/EVMAssembly.cpp index b37a3231..791b6226 100644 --- a/libyul/backends/evm/EVMAssembly.cpp +++ b/libyul/backends/evm/EVMAssembly.cpp @@ -22,10 +22,11 @@ #include <libevmasm/Instruction.h> -#include <libsolidity/interface/Exceptions.h> +#include <liblangutil/Exceptions.h> using namespace std; using namespace dev; +using namespace langutil; using namespace dev::yul; namespace diff --git a/libyul/backends/evm/EVMAssembly.h b/libyul/backends/evm/EVMAssembly.h index 8f92b6e7..c9190634 100644 --- a/libyul/backends/evm/EVMAssembly.h +++ b/libyul/backends/evm/EVMAssembly.h @@ -26,6 +26,11 @@ #include <map> +namespace langutil +{ +struct SourceLocation; +} + namespace dev { namespace yul @@ -38,7 +43,7 @@ public: virtual ~EVMAssembly() {} /// Set a new source location valid starting from the next instruction. - void setSourceLocation(SourceLocation const& _location) override; + void setSourceLocation(langutil::SourceLocation const& _location) override; /// Retrieve the current height of the stack. This does not have to be zero /// at the beginning. int stackHeight() const override { return m_stackHeight; } diff --git a/libyul/backends/evm/EVMCodeTransform.cpp b/libyul/backends/evm/EVMCodeTransform.cpp index 650a8c0a..23e09756 100644 --- a/libyul/backends/evm/EVMCodeTransform.cpp +++ b/libyul/backends/evm/EVMCodeTransform.cpp @@ -23,7 +23,7 @@ #include <libsolidity/inlineasm/AsmAnalysisInfo.h> #include <libsolidity/inlineasm/AsmData.h> -#include <libsolidity/interface/Exceptions.h> +#include <liblangutil/Exceptions.h> #include <boost/range/adaptor/reversed.hpp> diff --git a/libyul/optimiser/ExpressionSplitter.cpp b/libyul/optimiser/ExpressionSplitter.cpp index a4b7a909..42730864 100644 --- a/libyul/optimiser/ExpressionSplitter.cpp +++ b/libyul/optimiser/ExpressionSplitter.cpp @@ -31,6 +31,7 @@ using namespace std; using namespace dev; +using namespace langutil; using namespace dev::yul; using namespace dev::solidity; diff --git a/libyul/optimiser/FullInliner.h b/libyul/optimiser/FullInliner.h index 8243160d..5ebb3bf6 100644 --- a/libyul/optimiser/FullInliner.h +++ b/libyul/optimiser/FullInliner.h @@ -26,7 +26,7 @@ #include <libyul/optimiser/NameDispenser.h> #include <libyul/Exceptions.h> -#include <libevmasm/SourceLocation.h> +#include <liblangutil/SourceLocation.h> #include <boost/variant.hpp> #include <boost/optional.hpp> diff --git a/libyul/optimiser/SSATransform.cpp b/libyul/optimiser/SSATransform.cpp index f209ee7b..6fb4b08d 100644 --- a/libyul/optimiser/SSATransform.cpp +++ b/libyul/optimiser/SSATransform.cpp @@ -31,6 +31,7 @@ using namespace std; using namespace dev; +using namespace langutil; using namespace dev::yul; using namespace dev::solidity; diff --git a/libyul/optimiser/SimplificationRules.cpp b/libyul/optimiser/SimplificationRules.cpp index 5721042f..a15ed391 100644 --- a/libyul/optimiser/SimplificationRules.cpp +++ b/libyul/optimiser/SimplificationRules.cpp @@ -31,6 +31,7 @@ using namespace std; using namespace dev; +using namespace langutil; using namespace dev::yul; diff --git a/libyul/optimiser/SimplificationRules.h b/libyul/optimiser/SimplificationRules.h index b608ca91..bd6aa4de 100644 --- a/libyul/optimiser/SimplificationRules.h +++ b/libyul/optimiser/SimplificationRules.h @@ -107,7 +107,7 @@ public: /// Turns this pattern into an actual expression. Should only be called /// for patterns resulting from an action, i.e. with match groups assigned. - Expression toExpression(SourceLocation const& _location) const; + Expression toExpression(langutil::SourceLocation const& _location) const; private: Expression const& matchGroupValue() const; diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index 844cef90..b9f0bf79 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -26,12 +26,12 @@ #include "license.h" #include <libsolidity/interface/Version.h> -#include <libsolidity/parsing/Scanner.h> +#include <liblangutil/Scanner.h> #include <libsolidity/parsing/Parser.h> #include <libsolidity/ast/ASTPrinter.h> #include <libsolidity/ast/ASTJsonConverter.h> #include <libsolidity/analysis/NameAndTypeResolver.h> -#include <libsolidity/interface/Exceptions.h> +#include <liblangutil/Exceptions.h> #include <libsolidity/interface/CompilerStack.h> #include <libsolidity/interface/StandardCompiler.h> #include <libsolidity/interface/SourceReferenceFormatter.h> @@ -62,6 +62,7 @@ #include <fstream> using namespace std; +using namespace langutil; namespace po = boost::program_options; namespace dev @@ -827,7 +828,7 @@ bool CommandLineInterface::processInput() m_compiler.reset(new CompilerStack(fileReader)); - auto scannerFromSourceName = [&](string const& _sourceName) -> solidity::Scanner const& { return m_compiler->scanner(_sourceName); }; + auto scannerFromSourceName = [&](string const& _sourceName) -> Scanner const& { return m_compiler->scanner(_sourceName); }; SourceReferenceFormatter formatter(cerr, scannerFromSourceName); try diff --git a/solc/CommandLineInterface.h b/solc/CommandLineInterface.h index aa49383a..8dc00370 100644 --- a/solc/CommandLineInterface.h +++ b/solc/CommandLineInterface.h @@ -23,7 +23,7 @@ #include <libsolidity/interface/CompilerStack.h> #include <libsolidity/interface/AssemblyStack.h> -#include <libsolidity/interface/EVMVersion.h> +#include <liblangutil/EVMVersion.h> #include <boost/program_options.hpp> #include <boost/filesystem/path.hpp> diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 3b674502..acfc7d00 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -5,6 +5,8 @@ file(GLOB contracts_sources "contracts/*.cpp") file(GLOB contracts_headers "contracts/*.h") file(GLOB libdevcore_sources "libdevcore/*.cpp") file(GLOB libdevcore_headers "libdevcore/*.h") +file(GLOB liblangutil_sources "liblangutil/*.cpp") +file(GLOB liblangutil_headers "liblangutil/*.h") file(GLOB libevmasm_sources "libevmasm/*.cpp") file(GLOB libevmasm_headers "libevmasm/*.h") file(GLOB libyul_sources "libyul/*.cpp") @@ -19,6 +21,7 @@ file(GLOB libsolidity_headers "libsolidity/*.h") add_executable(soltest ${sources} ${headers} ${contracts_sources} ${contracts_headers} ${libdevcore_sources} ${libdevcore_headers} + ${liblangutil_sources} ${liblangutil_headers} ${libevmasm_sources} ${libevmasm_headers} ${libyul_sources} ${libyul_headers} ${liblll_sources} ${liblll_headers} diff --git a/test/ExecutionFramework.h b/test/ExecutionFramework.h index d6de95a3..86c1bcca 100644 --- a/test/ExecutionFramework.h +++ b/test/ExecutionFramework.h @@ -25,7 +25,7 @@ #include <test/Options.h> #include <test/RPCSession.h> -#include <libsolidity/interface/EVMVersion.h> +#include <liblangutil/EVMVersion.h> #include <libdevcore/FixedHash.h> #include <libdevcore/Keccak256.h> diff --git a/test/Options.cpp b/test/Options.cpp index da08eb37..9f0d6752 100644 --- a/test/Options.cpp +++ b/test/Options.cpp @@ -23,8 +23,8 @@ #include <test/Common.h> -#include <libsolidity/interface/EVMVersion.h> -#include <libsolidity/interface/Exceptions.h> +#include <liblangutil/EVMVersion.h> +#include <liblangutil/Exceptions.h> #include <boost/test/framework.hpp> #include <boost/filesystem.hpp> diff --git a/test/Options.h b/test/Options.h index 0e8a51da..af6f06ee 100644 --- a/test/Options.h +++ b/test/Options.h @@ -19,7 +19,7 @@ #pragma once -#include <libsolidity/interface/EVMVersion.h> +#include <liblangutil/EVMVersion.h> #include <boost/test/unit_test.hpp> #include <boost/filesystem.hpp> diff --git a/test/RPCSession.cpp b/test/RPCSession.cpp index 9ac24972..0aae21a7 100644 --- a/test/RPCSession.cpp +++ b/test/RPCSession.cpp @@ -23,7 +23,7 @@ #include <test/Options.h> -#include <libsolidity/interface/EVMVersion.h> +#include <liblangutil/EVMVersion.h> #include <libdevcore/CommonData.h> diff --git a/test/libevmasm/Assembler.cpp b/test/libevmasm/Assembler.cpp index 1c041596..5ad01594 100644 --- a/test/libevmasm/Assembler.cpp +++ b/test/libevmasm/Assembler.cpp @@ -30,6 +30,7 @@ #include <memory> using namespace std; +using namespace langutil; using namespace dev::eth; namespace dev diff --git a/test/libevmasm/Optimiser.cpp b/test/libevmasm/Optimiser.cpp index c01e8758..c061b783 100644 --- a/test/libevmasm/Optimiser.cpp +++ b/test/libevmasm/Optimiser.cpp @@ -36,6 +36,7 @@ #include <memory> using namespace std; +using namespace langutil; using namespace dev::eth; namespace dev diff --git a/test/libevmasm/SourceLocation.cpp b/test/liblangutil/SourceLocation.cpp index 764da3cd..ac7a2173 100644 --- a/test/libevmasm/SourceLocation.cpp +++ b/test/liblangutil/SourceLocation.cpp @@ -20,13 +20,11 @@ * Unit tests for the SourceLocation class. */ -#include <libevmasm/SourceLocation.h> +#include <liblangutil/SourceLocation.h> #include <test/Options.h> -namespace dev -{ -namespace solidity +namespace langutil { namespace test { @@ -46,5 +44,4 @@ BOOST_AUTO_TEST_CASE(test_fail) BOOST_AUTO_TEST_SUITE_END() } -} } // end namespaces diff --git a/test/libsolidity/ABIDecoderTests.cpp b/test/libsolidity/ABIDecoderTests.cpp index 94319985..291ed15a 100644 --- a/test/libsolidity/ABIDecoderTests.cpp +++ b/test/libsolidity/ABIDecoderTests.cpp @@ -22,7 +22,7 @@ #include <string> #include <tuple> #include <boost/test/unit_test.hpp> -#include <libsolidity/interface/Exceptions.h> +#include <liblangutil/Exceptions.h> #include <test/libsolidity/SolidityExecutionFramework.h> #include <test/libsolidity/ABITestsCommon.h> diff --git a/test/libsolidity/ABIEncoderTests.cpp b/test/libsolidity/ABIEncoderTests.cpp index d2125cc7..b6e6cedd 100644 --- a/test/libsolidity/ABIEncoderTests.cpp +++ b/test/libsolidity/ABIEncoderTests.cpp @@ -22,7 +22,7 @@ #include <string> #include <tuple> #include <boost/test/unit_test.hpp> -#include <libsolidity/interface/Exceptions.h> +#include <liblangutil/Exceptions.h> #include <test/libsolidity/SolidityExecutionFramework.h> #include <test/libsolidity/ABITestsCommon.h> diff --git a/test/libsolidity/AnalysisFramework.cpp b/test/libsolidity/AnalysisFramework.cpp index ec98026c..12d63cb7 100644 --- a/test/libsolidity/AnalysisFramework.cpp +++ b/test/libsolidity/AnalysisFramework.cpp @@ -27,7 +27,7 @@ #include <libsolidity/ast/AST.h> -#include <libsolidity/parsing/Scanner.h> +#include <liblangutil/Scanner.h> #include <libdevcore/Keccak256.h> @@ -35,6 +35,7 @@ using namespace std; using namespace dev; +using namespace langutil; using namespace dev::solidity; using namespace dev::solidity::test; @@ -127,7 +128,7 @@ string AnalysisFramework::formatError(Error const& _error) const return SourceReferenceFormatter::formatExceptionInformation( _error, (_error.type() == Error::Type::Warning) ? "Warning" : "Error", - [&](std::string const& _sourceName) -> solidity::Scanner const& { return m_compiler.scanner(_sourceName); } + [&](std::string const& _sourceName) -> Scanner const& { return m_compiler.scanner(_sourceName); } ); } diff --git a/test/libsolidity/AnalysisFramework.h b/test/libsolidity/AnalysisFramework.h index a904617d..391a21da 100644 --- a/test/libsolidity/AnalysisFramework.h +++ b/test/libsolidity/AnalysisFramework.h @@ -45,7 +45,7 @@ class AnalysisFramework { protected: - virtual std::pair<SourceUnit const*, ErrorList> + virtual std::pair<SourceUnit const*, langutil::ErrorList> parseAnalyseAndReturnError( std::string const& _source, bool _reportWarnings = false, @@ -56,10 +56,10 @@ protected: SourceUnit const* parseAndAnalyse(std::string const& _source); bool success(std::string const& _source); - ErrorList expectError(std::string const& _source, bool _warning = false, bool _allowMultiple = false); + langutil::ErrorList expectError(std::string const& _source, bool _warning = false, bool _allowMultiple = false); std::string formatErrors() const; - std::string formatError(Error const& _error) const; + std::string formatError(langutil::Error const& _error) const; static ContractDefinition const* retrieveContractByName(SourceUnit const& _source, std::string const& _name); static FunctionTypePointer retrieveFunctionBySignature( @@ -68,7 +68,7 @@ protected: ); // filter out the warnings in m_warningsToFilter or all warnings if _includeWarnings is false - ErrorList filterErrors(ErrorList const& _errorList, bool _includeWarnings) const; + langutil::ErrorList filterErrors(langutil::ErrorList const& _errorList, bool _includeWarnings) const; std::vector<std::string> m_warningsToFilter = {"This is a pre-release compiler version"}; dev::solidity::CompilerStack m_compiler; diff --git a/test/libsolidity/Assembly.cpp b/test/libsolidity/Assembly.cpp index 5e157678..926e29fe 100644 --- a/test/libsolidity/Assembly.cpp +++ b/test/libsolidity/Assembly.cpp @@ -22,16 +22,16 @@ #include <test/Options.h> -#include <libevmasm/SourceLocation.h> +#include <liblangutil/SourceLocation.h> #include <libevmasm/Assembly.h> -#include <libsolidity/parsing/Scanner.h> +#include <liblangutil/Scanner.h> #include <libsolidity/parsing/Parser.h> #include <libsolidity/analysis/NameAndTypeResolver.h> #include <libsolidity/codegen/Compiler.h> #include <libsolidity/ast/AST.h> #include <libsolidity/analysis/TypeChecker.h> -#include <libsolidity/interface/ErrorReporter.h> +#include <liblangutil/ErrorReporter.h> #include <boost/test/unit_test.hpp> @@ -39,6 +39,7 @@ #include <iostream> using namespace std; +using namespace langutil; using namespace dev::eth; namespace dev diff --git a/test/libsolidity/ErrorCheck.cpp b/test/libsolidity/ErrorCheck.cpp index fba2c897..e1f48fb2 100644 --- a/test/libsolidity/ErrorCheck.cpp +++ b/test/libsolidity/ErrorCheck.cpp @@ -27,6 +27,7 @@ using namespace std; using namespace dev; +using namespace langutil; using namespace dev::solidity; namespace diff --git a/test/libsolidity/ErrorCheck.h b/test/libsolidity/ErrorCheck.h index 8ad81f85..c3a2f522 100644 --- a/test/libsolidity/ErrorCheck.h +++ b/test/libsolidity/ErrorCheck.h @@ -21,7 +21,7 @@ #pragma once -#include <libsolidity/interface/Exceptions.h> +#include <liblangutil/Exceptions.h> #include <vector> #include <tuple> @@ -30,10 +30,10 @@ namespace dev { namespace solidity { -bool searchErrorMessage(Error const& _err, std::string const& _substr); +bool searchErrorMessage(langutil::Error const& _err, std::string const& _substr); /// Checks that all provided errors are of the given type and have a given substring in their /// description. /// If the expectations are not met, returns a nonempty description, otherwise an empty string. -std::string searchErrors(ErrorList const& _errors, std::vector<std::pair<Error::Type, std::string>> const& _expectations); +std::string searchErrors(langutil::ErrorList const& _errors, std::vector<std::pair<langutil::Error::Type, std::string>> const& _expectations); } } diff --git a/test/libsolidity/GasMeter.cpp b/test/libsolidity/GasMeter.cpp index 4887dd5b..61f16c0f 100644 --- a/test/libsolidity/GasMeter.cpp +++ b/test/libsolidity/GasMeter.cpp @@ -29,6 +29,7 @@ #include <libsolidity/interface/SourceReferenceFormatter.h> using namespace std; +using namespace langutil; using namespace dev::eth; using namespace dev::solidity; using namespace dev::test; diff --git a/test/libsolidity/Imports.cpp b/test/libsolidity/Imports.cpp index dc33d577..abd659b6 100644 --- a/test/libsolidity/Imports.cpp +++ b/test/libsolidity/Imports.cpp @@ -23,7 +23,7 @@ #include <test/libsolidity/ErrorCheck.h> #include <test/Options.h> -#include <libsolidity/interface/Exceptions.h> +#include <liblangutil/Exceptions.h> #include <libsolidity/interface/CompilerStack.h> #include <boost/test/unit_test.hpp> diff --git a/test/libsolidity/InlineAssembly.cpp b/test/libsolidity/InlineAssembly.cpp index a9ce6e49..31d21490 100644 --- a/test/libsolidity/InlineAssembly.cpp +++ b/test/libsolidity/InlineAssembly.cpp @@ -23,8 +23,8 @@ #include <test/Options.h> #include <libsolidity/interface/AssemblyStack.h> -#include <libsolidity/parsing/Scanner.h> -#include <libsolidity/interface/Exceptions.h> +#include <liblangutil/Scanner.h> +#include <liblangutil/Exceptions.h> #include <libsolidity/ast/AST.h> #include <test/libsolidity/ErrorCheck.h> #include <libevmasm/Assembly.h> @@ -36,6 +36,7 @@ #include <memory> using namespace std; +using namespace langutil; namespace dev { diff --git a/test/libsolidity/SMTChecker.cpp b/test/libsolidity/SMTChecker.cpp index 195004cb..13fcc5b4 100644 --- a/test/libsolidity/SMTChecker.cpp +++ b/test/libsolidity/SMTChecker.cpp @@ -25,6 +25,7 @@ #include <string> using namespace std; +using namespace langutil; namespace dev { diff --git a/test/libsolidity/SemVerMatcher.cpp b/test/libsolidity/SemVerMatcher.cpp index 43951f73..2e147847 100644 --- a/test/libsolidity/SemVerMatcher.cpp +++ b/test/libsolidity/SemVerMatcher.cpp @@ -23,11 +23,12 @@ #include <string> #include <vector> #include <tuple> -#include <libsolidity/parsing/Scanner.h> +#include <liblangutil/Scanner.h> #include <libsolidity/analysis/SemVerHandler.h> #include <test/Options.h> using namespace std; +using namespace langutil; namespace dev { diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 87646737..041f29a8 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -25,8 +25,8 @@ #include <test/Options.h> -#include <libsolidity/interface/Exceptions.h> -#include <libsolidity/interface/EVMVersion.h> +#include <liblangutil/Exceptions.h> +#include <liblangutil/EVMVersion.h> #include <libevmasm/Assembly.h> diff --git a/test/libsolidity/SolidityExecutionFramework.h b/test/libsolidity/SolidityExecutionFramework.h index 12687dd1..d43e994d 100644 --- a/test/libsolidity/SolidityExecutionFramework.h +++ b/test/libsolidity/SolidityExecutionFramework.h @@ -27,7 +27,7 @@ #include <test/ExecutionFramework.h> #include <libsolidity/interface/CompilerStack.h> -#include <libsolidity/interface/Exceptions.h> +#include <liblangutil/Exceptions.h> #include <libsolidity/interface/SourceReferenceFormatter.h> namespace dev @@ -72,13 +72,13 @@ public: m_compiler.setOptimiserSettings(m_optimize, m_optimizeRuns); if (!m_compiler.compile()) { - auto scannerFromSourceName = [&](std::string const& _sourceName) -> solidity::Scanner const& { return m_compiler.scanner(_sourceName); }; + auto scannerFromSourceName = [&](std::string const& _sourceName) -> langutil::Scanner const& { return m_compiler.scanner(_sourceName); }; SourceReferenceFormatter formatter(std::cerr, scannerFromSourceName); for (auto const& error: m_compiler.errors()) formatter.printExceptionInformation( *error, - (error->type() == Error::Type::Warning) ? "Warning" : "Error" + (error->type() == langutil::Error::Type::Warning) ? "Warning" : "Error" ); BOOST_ERROR("Compiling contract failed"); } diff --git a/test/libsolidity/SolidityExpressionCompiler.cpp b/test/libsolidity/SolidityExpressionCompiler.cpp index 309cbf0b..a68eb3df 100644 --- a/test/libsolidity/SolidityExpressionCompiler.cpp +++ b/test/libsolidity/SolidityExpressionCompiler.cpp @@ -22,17 +22,18 @@ #include <string> -#include <libsolidity/parsing/Scanner.h> +#include <liblangutil/Scanner.h> #include <libsolidity/parsing/Parser.h> #include <libsolidity/analysis/NameAndTypeResolver.h> #include <libsolidity/codegen/CompilerContext.h> #include <libsolidity/codegen/ExpressionCompiler.h> #include <libsolidity/ast/AST.h> #include <libsolidity/analysis/TypeChecker.h> -#include <libsolidity/interface/ErrorReporter.h> +#include <liblangutil/ErrorReporter.h> #include <test/Options.h> using namespace std; +using namespace langutil; namespace dev { diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index 5ec010c7..75726027 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -33,6 +33,7 @@ #include <string> using namespace std; +using namespace langutil; namespace dev { diff --git a/test/libsolidity/SolidityNatspecJSON.cpp b/test/libsolidity/SolidityNatspecJSON.cpp index d77050cb..d930f697 100644 --- a/test/libsolidity/SolidityNatspecJSON.cpp +++ b/test/libsolidity/SolidityNatspecJSON.cpp @@ -24,9 +24,11 @@ #include <string> #include <libdevcore/JSON.h> #include <libsolidity/interface/CompilerStack.h> -#include <libsolidity/interface/Exceptions.h> +#include <liblangutil/Exceptions.h> #include <libdevcore/Exceptions.h> +using namespace langutil; + namespace dev { namespace solidity diff --git a/test/libsolidity/SolidityParser.cpp b/test/libsolidity/SolidityParser.cpp index 5432e9b5..3534dd5b 100644 --- a/test/libsolidity/SolidityParser.cpp +++ b/test/libsolidity/SolidityParser.cpp @@ -22,13 +22,14 @@ #include <string> #include <memory> -#include <libsolidity/parsing/Scanner.h> +#include <liblangutil/Scanner.h> #include <libsolidity/parsing/Parser.h> -#include <libsolidity/interface/ErrorReporter.h> +#include <liblangutil/ErrorReporter.h> #include <test/Options.h> #include <test/libsolidity/ErrorCheck.h> using namespace std; +using namespace langutil; namespace dev { diff --git a/test/libsolidity/SolidityScanner.cpp b/test/libsolidity/SolidityScanner.cpp index 6965d886..2d164ae3 100644 --- a/test/libsolidity/SolidityScanner.cpp +++ b/test/libsolidity/SolidityScanner.cpp @@ -20,10 +20,11 @@ * Unit tests for the solidity scanner. */ -#include <libsolidity/parsing/Scanner.h> +#include <liblangutil/Scanner.h> #include <boost/test/unit_test.hpp> using namespace std; +using namespace langutil; namespace dev { diff --git a/test/libsolidity/SolidityTypes.cpp b/test/libsolidity/SolidityTypes.cpp index 6f9d4ce8..c839afd4 100644 --- a/test/libsolidity/SolidityTypes.cpp +++ b/test/libsolidity/SolidityTypes.cpp @@ -26,6 +26,7 @@ #include <boost/test/unit_test.hpp> using namespace std; +using namespace langutil; namespace dev { diff --git a/test/libsolidity/SyntaxTest.cpp b/test/libsolidity/SyntaxTest.cpp index 91d1681f..45d32b55 100644 --- a/test/libsolidity/SyntaxTest.cpp +++ b/test/libsolidity/SyntaxTest.cpp @@ -25,6 +25,7 @@ #include <stdexcept> using namespace dev; +using namespace langutil; using namespace solidity; using namespace dev::solidity::test; using namespace dev::solidity::test::formatting; diff --git a/test/libsolidity/SyntaxTest.h b/test/libsolidity/SyntaxTest.h index 654ce4a0..0f151e66 100644 --- a/test/libsolidity/SyntaxTest.h +++ b/test/libsolidity/SyntaxTest.h @@ -20,7 +20,7 @@ #include <test/libsolidity/AnalysisFramework.h> #include <test/libsolidity/FormattedScope.h> #include <test/libsolidity/TestCase.h> -#include <libsolidity/interface/Exceptions.h> +#include <liblangutil/Exceptions.h> #include <iosfwd> #include <string> diff --git a/test/libsolidity/ViewPureChecker.cpp b/test/libsolidity/ViewPureChecker.cpp index b7ea1efc..64e52604 100644 --- a/test/libsolidity/ViewPureChecker.cpp +++ b/test/libsolidity/ViewPureChecker.cpp @@ -28,6 +28,7 @@ #include <tuple> using namespace std; +using namespace langutil; namespace dev { diff --git a/test/libyul/Common.cpp b/test/libyul/Common.cpp index d224bdcd..8913483f 100644 --- a/test/libyul/Common.cpp +++ b/test/libyul/Common.cpp @@ -25,18 +25,19 @@ #include <libyul/optimiser/Disambiguator.h> -#include <libsolidity/parsing/Scanner.h> +#include <liblangutil/Scanner.h> #include <libsolidity/inlineasm/AsmParser.h> #include <libsolidity/inlineasm/AsmAnalysis.h> #include <libsolidity/inlineasm/AsmPrinter.h> #include <libsolidity/interface/SourceReferenceFormatter.h> -#include <libsolidity/interface/ErrorReporter.h> +#include <liblangutil/ErrorReporter.h> #include <boost/test/unit_test.hpp> using namespace std; +using namespace langutil; using namespace dev::yul; using namespace dev::solidity; diff --git a/test/libyul/Common.h b/test/libyul/Common.h index ee191494..390e214f 100644 --- a/test/libyul/Common.h +++ b/test/libyul/Common.h @@ -27,13 +27,17 @@ #include <vector> #include <memory> -namespace dev -{ -namespace solidity +namespace langutil { class Scanner; class Error; using ErrorList = std::vector<std::shared_ptr<Error const>>; +} + +namespace dev +{ +namespace solidity +{ namespace assembly { struct AsmAnalysisInfo; @@ -44,7 +48,7 @@ namespace yul namespace test { -void printErrors(solidity::ErrorList const& _errors, solidity::Scanner const& _scanner); +void printErrors(langutil::ErrorList const& _errors, langutil::Scanner const& _scanner); std::pair<std::shared_ptr<solidity::assembly::Block>, std::shared_ptr<solidity::assembly::AsmAnalysisInfo>> parse(std::string const& _source, bool _yul = true); solidity::assembly::Block disambiguate(std::string const& _source, bool _yul = true); diff --git a/test/libyul/Parser.cpp b/test/libyul/Parser.cpp index 3f329d28..4aa3dd5c 100644 --- a/test/libyul/Parser.cpp +++ b/test/libyul/Parser.cpp @@ -26,8 +26,8 @@ #include <libsolidity/inlineasm/AsmParser.h> #include <libsolidity/inlineasm/AsmAnalysis.h> #include <libsolidity/inlineasm/AsmAnalysisInfo.h> -#include <libsolidity/parsing/Scanner.h> -#include <libsolidity/interface/ErrorReporter.h> +#include <liblangutil/Scanner.h> +#include <liblangutil/ErrorReporter.h> #include <boost/optional.hpp> #include <boost/algorithm/string/replace.hpp> @@ -36,6 +36,7 @@ #include <memory> using namespace std; +using namespace langutil; namespace dev { diff --git a/test/libyul/YulOptimizerTest.cpp b/test/libyul/YulOptimizerTest.cpp index 9e257717..6b2b81c3 100644 --- a/test/libyul/YulOptimizerTest.cpp +++ b/test/libyul/YulOptimizerTest.cpp @@ -21,6 +21,9 @@ #include <test/Options.h> +#include <liblangutil/ErrorReporter.h> +#include <liblangutil/Scanner.h> + #include <libyul/optimiser/BlockFlattener.h> #include <libyul/optimiser/VarDeclPropagator.h> #include <libyul/optimiser/Disambiguator.h> @@ -41,12 +44,10 @@ #include <libyul/optimiser/RedundantAssignEliminator.h> #include <libyul/optimiser/Suite.h> -#include <libsolidity/parsing/Scanner.h> #include <libsolidity/inlineasm/AsmPrinter.h> #include <libsolidity/inlineasm/AsmParser.h> #include <libsolidity/inlineasm/AsmAnalysis.h> #include <libsolidity/interface/SourceReferenceFormatter.h> -#include <libsolidity/interface/ErrorReporter.h> #include <boost/test/unit_test.hpp> #include <boost/algorithm/string.hpp> @@ -54,6 +55,7 @@ #include <fstream> using namespace dev; +using namespace langutil; using namespace dev::yul; using namespace dev::yul::test; using namespace dev::solidity; diff --git a/test/libyul/YulOptimizerTest.h b/test/libyul/YulOptimizerTest.h index 7db17ceb..d11ff8fb 100644 --- a/test/libyul/YulOptimizerTest.h +++ b/test/libyul/YulOptimizerTest.h @@ -19,14 +19,17 @@ #include <test/libsolidity/TestCase.h> +namespace langutil +{ +class Scanner; +class Error; +using ErrorList = std::vector<std::shared_ptr<Error const>>; +} namespace dev { namespace solidity { -class Scanner; -class Error; -using ErrorList = std::vector<std::shared_ptr<Error const>>; namespace assembly { struct AsmAnalysisInfo; @@ -58,7 +61,7 @@ private: bool parse(std::ostream& _stream, std::string const& _linePrefix, bool const _formatted); void disambiguate(); - static void printErrors(std::ostream& _stream, solidity::ErrorList const& _errors, solidity::Scanner const& _scanner); + static void printErrors(std::ostream& _stream, langutil::ErrorList const& _errors, langutil::Scanner const& _scanner); std::string m_source; bool m_yul = false; diff --git a/test/tools/yulopti.cpp b/test/tools/yulopti.cpp index 3e96ef35..8bc807d4 100644 --- a/test/tools/yulopti.cpp +++ b/test/tools/yulopti.cpp @@ -19,15 +19,15 @@ */ #include <libdevcore/CommonIO.h> +#include <liblangutil/ErrorReporter.h> +#include <liblangutil/Scanner.h> #include <libsolidity/inlineasm/AsmAnalysis.h> #include <libsolidity/inlineasm/AsmAnalysisInfo.h> -#include <libsolidity/parsing/Scanner.h> #include <libsolidity/parsing/Parser.h> #include <libsolidity/inlineasm/AsmData.h> #include <libsolidity/inlineasm/AsmParser.h> #include <libsolidity/inlineasm/AsmPrinter.h> #include <libsolidity/interface/SourceReferenceFormatter.h> -#include <libsolidity/interface/ErrorReporter.h> #include <libyul/optimiser/BlockFlattener.h> #include <libyul/optimiser/Disambiguator.h> @@ -58,6 +58,7 @@ using namespace std; using namespace dev; +using namespace langutil; using namespace dev::solidity; using namespace dev::solidity::assembly; using namespace dev::yul; |