Merge pull request #11729 from ethereum/build-speedups

header file cleanups
This commit is contained in:
chriseth 2021-08-03 16:44:54 +02:00 committed by GitHub
commit d7a40622e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 85 additions and 64 deletions

View File

@ -33,6 +33,7 @@ namespace solidity::langutil
class ErrorReporter; class ErrorReporter;
class Scanner; class Scanner;
struct SourceLocation;
struct ErrorId; struct ErrorId;
class ParserBase class ParserBase

View File

@ -55,8 +55,6 @@
#include <liblangutil/Token.h> #include <liblangutil/Token.h>
#include <liblangutil/CharStream.h> #include <liblangutil/CharStream.h>
#include <liblangutil/SourceLocation.h> #include <liblangutil/SourceLocation.h>
#include <libsolutil/Common.h>
#include <libsolutil/CommonData.h>
#include <optional> #include <optional>
#include <iosfwd> #include <iosfwd>

View File

@ -23,12 +23,20 @@
#include <liblangutil/SemVerHandler.h> #include <liblangutil/SemVerHandler.h>
#include <liblangutil/Exceptions.h>
#include <functional> #include <functional>
using namespace std; using namespace std;
using namespace solidity; using namespace solidity;
using namespace solidity::langutil; using namespace solidity::langutil;
SemVerMatchExpressionParser::SemVerMatchExpressionParser(vector<Token> _tokens, vector<string> _literals):
m_tokens(std::move(_tokens)), m_literals(std::move(_literals))
{
solAssert(m_tokens.size() == m_literals.size(), "");
}
SemVerVersion::SemVerVersion(string const& _versionString) SemVerVersion::SemVerVersion(string const& _versionString)
{ {
auto i = _versionString.begin(); auto i = _versionString.begin();

View File

@ -85,11 +85,7 @@ struct SemVerMatchExpression
class SemVerMatchExpressionParser class SemVerMatchExpressionParser
{ {
public: public:
SemVerMatchExpressionParser(std::vector<Token> _tokens, std::vector<std::string> _literals): SemVerMatchExpressionParser(std::vector<Token> _tokens, std::vector<std::string> _literals);
m_tokens(std::move(_tokens)), m_literals(std::move(_literals))
{
solAssert(m_tokens.size() == m_literals.size(), "");
}
/// Returns an expression if it was parseable, or nothing otherwise. /// Returns an expression if it was parseable, or nothing otherwise.
std::optional<SemVerMatchExpression> parse(); std::optional<SemVerMatchExpression> parse();

View File

@ -21,6 +21,8 @@
#include <boost/algorithm/string/split.hpp> #include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#include <iostream>
using namespace solidity; using namespace solidity;
using namespace solidity::langutil; using namespace solidity::langutil;
using namespace std; using namespace std;
@ -50,3 +52,16 @@ SourceLocation solidity::langutil::parseSourceLocation(string const& _input, vec
result.sourceName = _sourceNames.at(static_cast<size_t>(sourceIndex)); result.sourceName = _sourceNames.at(static_cast<size_t>(sourceIndex));
return result; 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;
}

View File

@ -23,16 +23,14 @@
#pragma once #pragma once
#include <libsolutil/Assertions.h> #include <iosfwd>
#include <libsolutil/Exceptions.h>
#include <limits>
#include <memory> #include <memory>
#include <string> #include <string>
#include <tuple>
#include <vector>
namespace solidity::langutil namespace solidity::langutil
{ {
struct SourceLocationError: virtual util::Exception {};
/** /**
* Representation of an interval of source positions. * Representation of an interval of source positions.
@ -112,17 +110,6 @@ SourceLocation parseSourceLocation(
); );
/// Stream output for Location (used e.g. in boost exceptions). /// Stream output for Location (used e.g. in boost exceptions).
inline std::ostream& operator<<(std::ostream& _out, SourceLocation const& _location) 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;
}
} }

View File

@ -21,6 +21,8 @@
#include <liblangutil/SourceReferenceFormatter.h> #include <liblangutil/SourceReferenceFormatter.h>
#include <liblangutil/Exceptions.h> #include <liblangutil/Exceptions.h>
#include <liblangutil/CharStream.h>
#include <liblangutil/CharStreamProvider.h>
#include <libsolutil/UTF8.h> #include <libsolutil/UTF8.h>
#include <iomanip> #include <iomanip>
#include <string_view> #include <string_view>
@ -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 AnsiColorized SourceReferenceFormatter::normalColored() const
{ {
return AnsiColorized(m_stream, m_colored, {WHITE}); return AnsiColorized(m_stream, m_colored, {WHITE});

View File

@ -23,7 +23,6 @@
#include <liblangutil/Exceptions.h> #include <liblangutil/Exceptions.h>
#include <liblangutil/SourceReferenceExtractor.h> #include <liblangutil/SourceReferenceExtractor.h>
#include <liblangutil/CharStreamProvider.h>
#include <libsolutil/AnsiColorized.h> #include <libsolutil/AnsiColorized.h>
@ -33,6 +32,9 @@
namespace solidity::langutil namespace solidity::langutil
{ {
class CharStream;
class CharStreamProvider;
struct SourceLocation; struct SourceLocation;
class SourceReferenceFormatter class SourceReferenceFormatter
@ -80,13 +82,7 @@ public:
); );
} }
static std::string formatErrorInformation(Error const& _error, CharStream const& _charStream) static std::string formatErrorInformation(Error const& _error, CharStream const& _charStream);
{
return formatErrorInformation(
_error,
SingletonCharStreamProvider(_charStream)
);
}
private: private:
util::AnsiColorized normalColored() const; util::AnsiColorized normalColored() const;

View File

@ -41,6 +41,7 @@
// along with solidity. If not, see <http://www.gnu.org/licenses/>. // along with solidity. If not, see <http://www.gnu.org/licenses/>.
#include <liblangutil/Token.h> #include <liblangutil/Token.h>
#include <liblangutil/Exceptions.h>
#include <map> #include <map>
using namespace std; using namespace std;
@ -48,6 +49,24 @@ using namespace std;
namespace solidity::langutil namespace solidity::langutil
{ {
Token TokenTraits::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)));
}
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) void ElementaryTypeNameToken::assertDetails(Token _baseType, unsigned const& _first, unsigned const& _second)
{ {
solAssert(TokenTraits::isElementaryTypeName(_baseType), "Expected elementary type name: " + string(TokenTraits::toString(_baseType))); solAssert(TokenTraits::isElementaryTypeName(_baseType), "Expected elementary type name: " + string(TokenTraits::toString(_baseType)));

View File

@ -42,8 +42,6 @@
#pragma once #pragma once
#include <libsolutil/Common.h>
#include <liblangutil/Exceptions.h>
#include <liblangutil/UndefMacros.h> #include <liblangutil/UndefMacros.h>
#include <iosfwd> #include <iosfwd>
@ -329,11 +327,7 @@ namespace TokenTraits
bool isYulKeyword(std::string const& _literal); bool isYulKeyword(std::string const& _literal);
inline Token AssignmentToBinaryOp(Token op) 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 // @returns the precedence > 0 for binary and compare
// operators; returns 0 otherwise. // operators; returns 0 otherwise.
@ -393,17 +387,7 @@ public:
Token token() const { return m_token; } Token token() const { return m_token; }
///if tokValue is set to true, then returns the actual token type name, otherwise, returns full type ///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 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: private:
Token m_token; Token m_token;

View File

@ -26,6 +26,7 @@
#include <libyul/AST.h> #include <libyul/AST.h>
#include <libyul/Exceptions.h> #include <libyul/Exceptions.h>
#include <liblangutil/Exceptions.h>
#include <liblangutil/Scanner.h> #include <liblangutil/Scanner.h>
#include <boost/algorithm/string/split.hpp> #include <boost/algorithm/string/split.hpp>

View File

@ -24,8 +24,9 @@
#include <libyul/AST.h> #include <libyul/AST.h>
#include <libyul/AsmParser.h> #include <libyul/AsmParser.h>
#include <libyul/Exceptions.h> #include <libyul/Exceptions.h>
#include <liblangutil/Scanner.h>
#include <liblangutil/ErrorReporter.h> #include <liblangutil/ErrorReporter.h>
#include <liblangutil/Exceptions.h>
#include <liblangutil/Scanner.h>
#include <libsolutil/Common.h> #include <libsolutil/Common.h>
#include <libsolutil/Visitor.h> #include <libsolutil/Visitor.h>
@ -70,6 +71,20 @@ optional<int> toInt(string const& _value)
} }
std::shared_ptr<DebugData const> 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<Block> Parser::parse(std::shared_ptr<Scanner> const& _scanner, bool _reuseScanner) unique_ptr<Block> Parser::parse(std::shared_ptr<Scanner> const& _scanner, bool _reuseScanner)
{ {
m_recursionDepth = 0; m_recursionDepth = 0;

View File

@ -31,6 +31,7 @@
#include <liblangutil/Scanner.h> #include <liblangutil/Scanner.h>
#include <liblangutil/ParserBase.h> #include <liblangutil/ParserBase.h>
#include <map>
#include <memory> #include <memory>
#include <variant> #include <variant>
#include <vector> #include <vector>
@ -103,19 +104,7 @@ protected:
void fetchSourceLocationFromComment(); void fetchSourceLocationFromComment();
/// Creates a DebugData object with the correct source location set. /// Creates a DebugData object with the correct source location set.
std::shared_ptr<DebugData const> createDebugData() const std::shared_ptr<DebugData const> 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, "");
}
/// Creates an inline assembly node with the current source location. /// Creates an inline assembly node with the current source location.
template <class T> T createWithLocation() const template <class T> T createWithLocation() const

View File

@ -27,6 +27,7 @@
#include <libyul/optimiser/ReasoningBasedSimplifier.h> #include <libyul/optimiser/ReasoningBasedSimplifier.h>
#include <libyul/AsmPrinter.h> #include <libyul/AsmPrinter.h>
#include <liblangutil/CharStreamProvider.h>
#include <liblangutil/SourceReferenceFormatter.h> #include <liblangutil/SourceReferenceFormatter.h>
#include <liblangutil/Scanner.h> #include <liblangutil/Scanner.h>

View File

@ -27,6 +27,7 @@
#include <tools/yulPhaser/SimulationRNG.h> #include <tools/yulPhaser/SimulationRNG.h>
#include <liblangutil/CharStream.h> #include <liblangutil/CharStream.h>
#include <liblangutil/CharStreamProvider.h>
#include <liblangutil/SourceReferenceFormatter.h> #include <liblangutil/SourceReferenceFormatter.h>
#include <liblangutil/Scanner.h> #include <liblangutil/Scanner.h>