diff options
author | Christian Parpart <christian@ethereum.org> | 2018-11-15 00:11:55 +0800 |
---|---|---|
committer | Alex Beregszaszi <alex@rtfs.hu> | 2018-11-22 03:13:44 +0800 |
commit | d67322a1861d60a88151f7c25d6c3478a9a39acf (patch) | |
tree | af485e48c3436cd24e2db09a6a1bcf445605bae1 /liblangutil | |
parent | 80371e2d25ce3eb868d6f75b99a54af9dc6c1583 (diff) | |
download | dexon-solidity-d67322a1861d60a88151f7c25d6c3478a9a39acf.tar.gz dexon-solidity-d67322a1861d60a88151f7c25d6c3478a9a39acf.tar.zst dexon-solidity-d67322a1861d60a88151f7c25d6c3478a9a39acf.zip |
Introduce namespace `langutil` in liblangutil directory.
Also:
- Use {}-style list initialisation for SourceLocation construction
- Introduce new system includes
- Changes the API of the Scanner to take source as value (with move) as opposed to as a reference
Diffstat (limited to 'liblangutil')
-rw-r--r-- | liblangutil/CharStream.cpp | 11 | ||||
-rw-r--r-- | liblangutil/CharStream.h | 5 | ||||
-rw-r--r-- | liblangutil/ErrorReporter.cpp | 4 | ||||
-rw-r--r-- | liblangutil/ErrorReporter.h | 8 | ||||
-rw-r--r-- | liblangutil/Exceptions.cpp | 2 | ||||
-rw-r--r-- | liblangutil/Exceptions.h | 25 | ||||
-rw-r--r-- | liblangutil/ParserBase.cpp | 3 | ||||
-rw-r--r-- | liblangutil/ParserBase.h | 8 | ||||
-rw-r--r-- | liblangutil/Scanner.cpp | 16 | ||||
-rw-r--r-- | liblangutil/Scanner.h | 16 | ||||
-rw-r--r-- | liblangutil/SourceLocation.h | 4 | ||||
-rw-r--r-- | liblangutil/Token.cpp | 7 | ||||
-rw-r--r-- | liblangutil/Token.h | 8 |
13 files changed, 44 insertions, 73 deletions
diff --git a/liblangutil/CharStream.cpp b/liblangutil/CharStream.cpp index 04490fa6..aee7cb3e 100644 --- a/liblangutil/CharStream.cpp +++ b/liblangutil/CharStream.cpp @@ -52,15 +52,9 @@ #include <liblangutil/CharStream.h> #include <liblangutil/Exceptions.h> -#include <algorithm> -#include <tuple> using namespace std; - -namespace dev -{ -namespace solidity -{ +using namespace langutil; char CharStream::advanceAndGet(size_t _chars) { @@ -111,5 +105,4 @@ tuple<int, int> CharStream::translatePositionToLineColumn(int _position) const return tuple<int, int>(lineNumber, searchPosition - lineStart); } -} -} + diff --git a/liblangutil/CharStream.h b/liblangutil/CharStream.h index 7c5488a0..72aacacf 100644 --- a/liblangutil/CharStream.h +++ b/liblangutil/CharStream.h @@ -56,9 +56,7 @@ #include <string> #include <tuple> -namespace dev -{ -namespace solidity +namespace langutil { /** @@ -97,4 +95,3 @@ private: }; } -} diff --git a/liblangutil/ErrorReporter.cpp b/liblangutil/ErrorReporter.cpp index 5edb0eeb..5b6e0072 100644 --- a/liblangutil/ErrorReporter.cpp +++ b/liblangutil/ErrorReporter.cpp @@ -21,12 +21,12 @@ */ #include <liblangutil/ErrorReporter.h> -#include <libsolidity/ast/AST.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/liblangutil/ErrorReporter.h b/liblangutil/ErrorReporter.h index 72cf16a4..d90e652e 100644 --- a/liblangutil/ErrorReporter.h +++ b/liblangutil/ErrorReporter.h @@ -25,12 +25,8 @@ #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/liblangutil/Exceptions.cpp b/liblangutil/Exceptions.cpp index 069619dd..346313d5 100644 --- a/liblangutil/Exceptions.cpp +++ b/liblangutil/Exceptions.cpp @@ -24,7 +24,7 @@ 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/liblangutil/Exceptions.h b/liblangutil/Exceptions.h index 69efd6dd..5ad31ab2 100644 --- a/liblangutil/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 <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/liblangutil/ParserBase.cpp b/liblangutil/ParserBase.cpp index 197c2d65..8156f9b9 100644 --- a/liblangutil/ParserBase.cpp +++ b/liblangutil/ParserBase.cpp @@ -25,8 +25,7 @@ #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/liblangutil/ParserBase.h b/liblangutil/ParserBase.h index 0cd94eee..3ecabed5 100644 --- a/liblangutil/ParserBase.h +++ b/liblangutil/ParserBase.h @@ -22,12 +22,11 @@ #pragma once -#include <memory> #include <liblangutil/Token.h> +#include <memory> +#include <string> -namespace dev -{ -namespace solidity +namespace langutil { class ErrorReporter; @@ -90,4 +89,3 @@ protected: }; } -} diff --git a/liblangutil/Scanner.cpp b/liblangutil/Scanner.cpp index beb39a4f..3d7527d4 100644 --- a/liblangutil/Scanner.cpp +++ b/liblangutil/Scanner.cpp @@ -50,16 +50,14 @@ * Solidity scanner. */ -#include <algorithm> -#include <tuple> #include <liblangutil/Exceptions.h> #include <liblangutil/Scanner.h> +#include <algorithm> +#include <tuple> 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,5 +864,5 @@ tuple<Token, unsigned, unsigned> Scanner::scanIdentifierOrKeyword() return TokenTraits::fromIdentifierOrKeyword(m_nextToken.literal); } -} + } diff --git a/liblangutil/Scanner.h b/liblangutil/Scanner.h index 5e5ddfdd..da5e3dfb 100644 --- a/liblangutil/Scanner.h +++ b/liblangutil/Scanner.h @@ -52,15 +52,13 @@ #pragma once -#include <libdevcore/Common.h> -#include <libdevcore/CommonData.h> +#include <liblangutil/Token.h> #include <liblangutil/CharStream.h> #include <liblangutil/SourceLocation.h> -#include <liblangutil/Token.h> +#include <libdevcore/Common.h> +#include <libdevcore/CommonData.h> -namespace dev -{ -namespace solidity +namespace langutil { class AstRawString; @@ -71,13 +69,12 @@ 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(); @@ -216,4 +213,3 @@ private: }; } -} diff --git a/liblangutil/SourceLocation.h b/liblangutil/SourceLocation.h index b42c3aa9..eeb81e94 100644 --- a/liblangutil/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/liblangutil/Token.cpp b/liblangutil/Token.cpp index 2e754733..cbfd4a8c 100644 --- a/liblangutil/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 <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 index 89dd4c01..0b7d9f71 100644 --- a/liblangutil/Token.h +++ b/liblangutil/Token.h @@ -45,11 +45,12 @@ #include <libdevcore/Common.h> #include <liblangutil/Exceptions.h> #include <liblangutil/UndefMacros.h> + #include <iosfwd> +#include <string> +#include <tuple> -namespace dev -{ -namespace solidity +namespace langutil { // TOKEN_LIST takes a list of 3 macros M, all of which satisfy the @@ -375,4 +376,3 @@ private: }; } -} |