diff --git a/liblangutil/ParserBase.h b/liblangutil/ParserBase.h index 098826f1c..d75a97707 100644 --- a/liblangutil/ParserBase.h +++ b/liblangutil/ParserBase.h @@ -33,6 +33,7 @@ namespace solidity::langutil class ErrorReporter; class Scanner; +struct SourceLocation; struct ErrorId; class ParserBase diff --git a/liblangutil/Scanner.h b/liblangutil/Scanner.h index ef12703ef..347c75779 100644 --- a/liblangutil/Scanner.h +++ b/liblangutil/Scanner.h @@ -55,8 +55,6 @@ #include #include #include -#include -#include #include #include diff --git a/liblangutil/SemVerHandler.cpp b/liblangutil/SemVerHandler.cpp index af408789c..ede1cd7be 100644 --- a/liblangutil/SemVerHandler.cpp +++ b/liblangutil/SemVerHandler.cpp @@ -23,12 +23,20 @@ #include +#include + #include using namespace std; using namespace solidity; using namespace solidity::langutil; +SemVerMatchExpressionParser::SemVerMatchExpressionParser(vector _tokens, vector _literals): + m_tokens(std::move(_tokens)), m_literals(std::move(_literals)) +{ + solAssert(m_tokens.size() == m_literals.size(), ""); +} + SemVerVersion::SemVerVersion(string const& _versionString) { auto i = _versionString.begin(); diff --git a/liblangutil/SemVerHandler.h b/liblangutil/SemVerHandler.h index 0c4f57a03..bce4d736b 100644 --- a/liblangutil/SemVerHandler.h +++ b/liblangutil/SemVerHandler.h @@ -85,11 +85,7 @@ struct SemVerMatchExpression class SemVerMatchExpressionParser { public: - SemVerMatchExpressionParser(std::vector _tokens, std::vector _literals): - m_tokens(std::move(_tokens)), m_literals(std::move(_literals)) - { - solAssert(m_tokens.size() == m_literals.size(), ""); - } + SemVerMatchExpressionParser(std::vector _tokens, std::vector _literals); /// Returns an expression if it was parseable, or nothing otherwise. std::optional parse(); diff --git a/liblangutil/SourceLocation.cpp b/liblangutil/SourceLocation.cpp index 058cc6b57..72f2506e8 100644 --- a/liblangutil/SourceLocation.cpp +++ b/liblangutil/SourceLocation.cpp @@ -21,6 +21,8 @@ #include #include +#include + using namespace solidity; using namespace solidity::langutil; using namespace std; @@ -50,3 +52,16 @@ SourceLocation solidity::langutil::parseSourceLocation(string const& _input, vec result.sourceName = _sourceNames.at(static_cast(sourceIndex)); return result; } + +std::ostream& solidity::langutil::operator<<(std::ostream& _out, SourceLocation const& _location) +{ + if (!_location.isValid()) + return _out << "NO_LOCATION_SPECIFIED"; + + if (_location.sourceName) + _out << *_location.sourceName; + + _out << "[" << _location.start << "," << _location.end << "]"; + + return _out; +} diff --git a/liblangutil/SourceLocation.h b/liblangutil/SourceLocation.h index 845b269ca..66cef52fb 100644 --- a/liblangutil/SourceLocation.h +++ b/liblangutil/SourceLocation.h @@ -23,16 +23,14 @@ #pragma once -#include -#include - -#include +#include #include #include +#include +#include namespace solidity::langutil { -struct SourceLocationError: virtual util::Exception {}; /** * Representation of an interval of source positions. @@ -112,17 +110,6 @@ SourceLocation parseSourceLocation( ); /// Stream output for Location (used e.g. in boost exceptions). -inline std::ostream& operator<<(std::ostream& _out, SourceLocation const& _location) -{ - if (!_location.isValid()) - return _out << "NO_LOCATION_SPECIFIED"; - - if (_location.sourceName) - _out << *_location.sourceName; - - _out << "[" << _location.start << "," << _location.end << "]"; - - return _out; -} +std::ostream& operator<<(std::ostream& _out, SourceLocation const& _location); } diff --git a/liblangutil/SourceReferenceFormatter.cpp b/liblangutil/SourceReferenceFormatter.cpp index 2a0799036..20d0f3306 100644 --- a/liblangutil/SourceReferenceFormatter.cpp +++ b/liblangutil/SourceReferenceFormatter.cpp @@ -21,6 +21,8 @@ #include #include +#include +#include #include #include #include @@ -45,6 +47,14 @@ std::string replaceNonTabs(std::string_view _utf8Input, char _filler) } +std::string SourceReferenceFormatter::formatErrorInformation(Error const& _error, CharStream const& _charStream) +{ + return formatErrorInformation( + _error, + SingletonCharStreamProvider(_charStream) + ); +} + AnsiColorized SourceReferenceFormatter::normalColored() const { return AnsiColorized(m_stream, m_colored, {WHITE}); diff --git a/liblangutil/SourceReferenceFormatter.h b/liblangutil/SourceReferenceFormatter.h index 630f00de5..fc1f418a2 100644 --- a/liblangutil/SourceReferenceFormatter.h +++ b/liblangutil/SourceReferenceFormatter.h @@ -23,7 +23,6 @@ #include #include -#include #include @@ -33,6 +32,9 @@ namespace solidity::langutil { + +class CharStream; +class CharStreamProvider; struct SourceLocation; class SourceReferenceFormatter @@ -80,13 +82,7 @@ public: ); } - static std::string formatErrorInformation(Error const& _error, CharStream const& _charStream) - { - return formatErrorInformation( - _error, - SingletonCharStreamProvider(_charStream) - ); - } + static std::string formatErrorInformation(Error const& _error, CharStream const& _charStream); private: util::AnsiColorized normalColored() const; diff --git a/liblangutil/Token.cpp b/liblangutil/Token.cpp index b6cb1e0ed..8bdaff1fd 100644 --- a/liblangutil/Token.cpp +++ b/liblangutil/Token.cpp @@ -41,6 +41,7 @@ // along with solidity. If not, see . #include +#include #include using namespace std; @@ -48,6 +49,24 @@ using namespace std; namespace solidity::langutil { +Token TokenTraits::AssignmentToBinaryOp(Token op) +{ + solAssert(isAssignmentOp(op) && op != Token::Assign, ""); + return static_cast(static_cast(op) + (static_cast(Token::BitOr) - static_cast(Token::AssignBitOr))); +} + +std::string ElementaryTypeNameToken::toString(bool const& tokenValue) 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); +} + void ElementaryTypeNameToken::assertDetails(Token _baseType, unsigned const& _first, unsigned const& _second) { solAssert(TokenTraits::isElementaryTypeName(_baseType), "Expected elementary type name: " + string(TokenTraits::toString(_baseType))); diff --git a/liblangutil/Token.h b/liblangutil/Token.h index 13f836589..eb8015f4d 100644 --- a/liblangutil/Token.h +++ b/liblangutil/Token.h @@ -42,8 +42,6 @@ #pragma once -#include -#include #include #include @@ -329,11 +327,7 @@ namespace TokenTraits bool isYulKeyword(std::string const& _literal); - inline Token AssignmentToBinaryOp(Token op) - { - solAssert(isAssignmentOp(op) && op != Token::Assign, ""); - return static_cast(static_cast(op) + (static_cast(Token::BitOr) - static_cast(Token::AssignBitOr))); - } + Token AssignmentToBinaryOp(Token op); // @returns the precedence > 0 for binary and compare // operators; returns 0 otherwise. @@ -393,17 +387,7 @@ public: 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); - } + std::string toString(bool const& tokenValue = false) const; private: Token m_token; diff --git a/libyul/AsmJsonImporter.cpp b/libyul/AsmJsonImporter.cpp index 87ce31497..0c4273aa7 100644 --- a/libyul/AsmJsonImporter.cpp +++ b/libyul/AsmJsonImporter.cpp @@ -26,6 +26,7 @@ #include #include +#include #include #include diff --git a/libyul/AsmParser.cpp b/libyul/AsmParser.cpp index e8f5b3e4e..b5e542926 100644 --- a/libyul/AsmParser.cpp +++ b/libyul/AsmParser.cpp @@ -24,8 +24,9 @@ #include #include #include -#include #include +#include +#include #include #include @@ -70,6 +71,20 @@ optional toInt(string const& _value) } +std::shared_ptr Parser::createDebugData() const +{ + switch (m_useSourceLocationFrom) + { + case UseSourceLocationFrom::Scanner: + return DebugData::create(ParserBase::currentLocation()); + case UseSourceLocationFrom::LocationOverride: + return DebugData::create(m_locationOverride); + case UseSourceLocationFrom::Comments: + return m_debugDataOverride; + } + solAssert(false, ""); +} + unique_ptr Parser::parse(std::shared_ptr const& _scanner, bool _reuseScanner) { m_recursionDepth = 0; diff --git a/libyul/AsmParser.h b/libyul/AsmParser.h index 23ee935e5..3f1f30963 100644 --- a/libyul/AsmParser.h +++ b/libyul/AsmParser.h @@ -31,6 +31,7 @@ #include #include +#include #include #include #include @@ -103,19 +104,7 @@ protected: void fetchSourceLocationFromComment(); /// Creates a DebugData object with the correct source location set. - std::shared_ptr createDebugData() const - { - switch (m_useSourceLocationFrom) - { - case UseSourceLocationFrom::Scanner: - return DebugData::create(ParserBase::currentLocation()); - case UseSourceLocationFrom::LocationOverride: - return DebugData::create(m_locationOverride); - case UseSourceLocationFrom::Comments: - return m_debugDataOverride; - } - solAssert(false, ""); - } + std::shared_ptr createDebugData() const; /// Creates an inline assembly node with the current source location. template T createWithLocation() const diff --git a/test/libyul/YulOptimizerTest.cpp b/test/libyul/YulOptimizerTest.cpp index 3454f09ac..ada942152 100644 --- a/test/libyul/YulOptimizerTest.cpp +++ b/test/libyul/YulOptimizerTest.cpp @@ -27,6 +27,7 @@ #include #include +#include #include #include diff --git a/tools/yulPhaser/Phaser.cpp b/tools/yulPhaser/Phaser.cpp index db7d79c31..30d3b8876 100644 --- a/tools/yulPhaser/Phaser.cpp +++ b/tools/yulPhaser/Phaser.cpp @@ -27,6 +27,7 @@ #include #include +#include #include #include