Skip to content

Commit d7a4062

Browse files
authored
Merge pull request #11729 from ethereum/build-speedups
header file cleanups
2 parents ffd66a5 + af18b8a commit d7a4062

15 files changed

+85
-64
lines changed

liblangutil/ParserBase.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ namespace solidity::langutil
3333

3434
class ErrorReporter;
3535
class Scanner;
36+
struct SourceLocation;
3637
struct ErrorId;
3738

3839
class ParserBase

liblangutil/Scanner.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@
5555
#include <liblangutil/Token.h>
5656
#include <liblangutil/CharStream.h>
5757
#include <liblangutil/SourceLocation.h>
58-
#include <libsolutil/Common.h>
59-
#include <libsolutil/CommonData.h>
6058

6159
#include <optional>
6260
#include <iosfwd>

liblangutil/SemVerHandler.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,20 @@
2323

2424
#include <liblangutil/SemVerHandler.h>
2525

26+
#include <liblangutil/Exceptions.h>
27+
2628
#include <functional>
2729

2830
using namespace std;
2931
using namespace solidity;
3032
using namespace solidity::langutil;
3133

34+
SemVerMatchExpressionParser::SemVerMatchExpressionParser(vector<Token> _tokens, vector<string> _literals):
35+
m_tokens(std::move(_tokens)), m_literals(std::move(_literals))
36+
{
37+
solAssert(m_tokens.size() == m_literals.size(), "");
38+
}
39+
3240
SemVerVersion::SemVerVersion(string const& _versionString)
3341
{
3442
auto i = _versionString.begin();

liblangutil/SemVerHandler.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,7 @@ struct SemVerMatchExpression
8585
class SemVerMatchExpressionParser
8686
{
8787
public:
88-
SemVerMatchExpressionParser(std::vector<Token> _tokens, std::vector<std::string> _literals):
89-
m_tokens(std::move(_tokens)), m_literals(std::move(_literals))
90-
{
91-
solAssert(m_tokens.size() == m_literals.size(), "");
92-
}
88+
SemVerMatchExpressionParser(std::vector<Token> _tokens, std::vector<std::string> _literals);
9389

9490
/// Returns an expression if it was parseable, or nothing otherwise.
9591
std::optional<SemVerMatchExpression> parse();

liblangutil/SourceLocation.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include <boost/algorithm/string/split.hpp>
2222
#include <boost/algorithm/string.hpp>
2323

24+
#include <iostream>
25+
2426
using namespace solidity;
2527
using namespace solidity::langutil;
2628
using namespace std;
@@ -50,3 +52,16 @@ SourceLocation solidity::langutil::parseSourceLocation(string const& _input, vec
5052
result.sourceName = _sourceNames.at(static_cast<size_t>(sourceIndex));
5153
return result;
5254
}
55+
56+
std::ostream& solidity::langutil::operator<<(std::ostream& _out, SourceLocation const& _location)
57+
{
58+
if (!_location.isValid())
59+
return _out << "NO_LOCATION_SPECIFIED";
60+
61+
if (_location.sourceName)
62+
_out << *_location.sourceName;
63+
64+
_out << "[" << _location.start << "," << _location.end << "]";
65+
66+
return _out;
67+
}

liblangutil/SourceLocation.h

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,14 @@
2323

2424
#pragma once
2525

26-
#include <libsolutil/Assertions.h>
27-
#include <libsolutil/Exceptions.h>
28-
29-
#include <limits>
26+
#include <iosfwd>
3027
#include <memory>
3128
#include <string>
29+
#include <tuple>
30+
#include <vector>
3231

3332
namespace solidity::langutil
3433
{
35-
struct SourceLocationError: virtual util::Exception {};
3634

3735
/**
3836
* Representation of an interval of source positions.
@@ -112,17 +110,6 @@ SourceLocation parseSourceLocation(
112110
);
113111

114112
/// Stream output for Location (used e.g. in boost exceptions).
115-
inline std::ostream& operator<<(std::ostream& _out, SourceLocation const& _location)
116-
{
117-
if (!_location.isValid())
118-
return _out << "NO_LOCATION_SPECIFIED";
119-
120-
if (_location.sourceName)
121-
_out << *_location.sourceName;
122-
123-
_out << "[" << _location.start << "," << _location.end << "]";
124-
125-
return _out;
126-
}
113+
std::ostream& operator<<(std::ostream& _out, SourceLocation const& _location);
127114

128115
}

liblangutil/SourceReferenceFormatter.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
#include <liblangutil/SourceReferenceFormatter.h>
2323
#include <liblangutil/Exceptions.h>
24+
#include <liblangutil/CharStream.h>
25+
#include <liblangutil/CharStreamProvider.h>
2426
#include <libsolutil/UTF8.h>
2527
#include <iomanip>
2628
#include <string_view>
@@ -45,6 +47,14 @@ std::string replaceNonTabs(std::string_view _utf8Input, char _filler)
4547

4648
}
4749

50+
std::string SourceReferenceFormatter::formatErrorInformation(Error const& _error, CharStream const& _charStream)
51+
{
52+
return formatErrorInformation(
53+
_error,
54+
SingletonCharStreamProvider(_charStream)
55+
);
56+
}
57+
4858
AnsiColorized SourceReferenceFormatter::normalColored() const
4959
{
5060
return AnsiColorized(m_stream, m_colored, {WHITE});

liblangutil/SourceReferenceFormatter.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
#include <liblangutil/Exceptions.h>
2525
#include <liblangutil/SourceReferenceExtractor.h>
26-
#include <liblangutil/CharStreamProvider.h>
2726

2827
#include <libsolutil/AnsiColorized.h>
2928

@@ -33,6 +32,9 @@
3332

3433
namespace solidity::langutil
3534
{
35+
36+
class CharStream;
37+
class CharStreamProvider;
3638
struct SourceLocation;
3739

3840
class SourceReferenceFormatter
@@ -80,13 +82,7 @@ class SourceReferenceFormatter
8082
);
8183
}
8284

83-
static std::string formatErrorInformation(Error const& _error, CharStream const& _charStream)
84-
{
85-
return formatErrorInformation(
86-
_error,
87-
SingletonCharStreamProvider(_charStream)
88-
);
89-
}
85+
static std::string formatErrorInformation(Error const& _error, CharStream const& _charStream);
9086

9187
private:
9288
util::AnsiColorized normalColored() const;

liblangutil/Token.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,32 @@
4141
// along with solidity. If not, see <http://www.gnu.org/licenses/>.
4242

4343
#include <liblangutil/Token.h>
44+
#include <liblangutil/Exceptions.h>
4445
#include <map>
4546

4647
using namespace std;
4748

4849
namespace solidity::langutil
4950
{
5051

52+
Token TokenTraits::AssignmentToBinaryOp(Token op)
53+
{
54+
solAssert(isAssignmentOp(op) && op != Token::Assign, "");
55+
return static_cast<Token>(static_cast<int>(op) + (static_cast<int>(Token::BitOr) - static_cast<int>(Token::AssignBitOr)));
56+
}
57+
58+
std::string ElementaryTypeNameToken::toString(bool const& tokenValue) const
59+
{
60+
std::string name = TokenTraits::toString(m_token);
61+
if (tokenValue || (firstNumber() == 0 && secondNumber() == 0))
62+
return name;
63+
solAssert(name.size() >= 3, "Token name size should be greater than 3. Should not reach here.");
64+
if (m_token == Token::FixedMxN || m_token == Token::UFixedMxN)
65+
return name.substr(0, name.size() - 3) + std::to_string(m_firstNumber) + "x" + std::to_string(m_secondNumber);
66+
else
67+
return name.substr(0, name.size() - 1) + std::to_string(m_firstNumber);
68+
}
69+
5170
void ElementaryTypeNameToken::assertDetails(Token _baseType, unsigned const& _first, unsigned const& _second)
5271
{
5372
solAssert(TokenTraits::isElementaryTypeName(_baseType), "Expected elementary type name: " + string(TokenTraits::toString(_baseType)));

liblangutil/Token.h

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@
4242

4343
#pragma once
4444

45-
#include <libsolutil/Common.h>
46-
#include <liblangutil/Exceptions.h>
4745
#include <liblangutil/UndefMacros.h>
4846

4947
#include <iosfwd>
@@ -329,11 +327,7 @@ namespace TokenTraits
329327

330328
bool isYulKeyword(std::string const& _literal);
331329

332-
inline Token AssignmentToBinaryOp(Token op)
333-
{
334-
solAssert(isAssignmentOp(op) && op != Token::Assign, "");
335-
return static_cast<Token>(static_cast<int>(op) + (static_cast<int>(Token::BitOr) - static_cast<int>(Token::AssignBitOr)));
336-
}
330+
Token AssignmentToBinaryOp(Token op);
337331

338332
// @returns the precedence > 0 for binary and compare
339333
// operators; returns 0 otherwise.
@@ -393,17 +387,7 @@ class ElementaryTypeNameToken
393387
Token token() const { return m_token; }
394388

395389
///if tokValue is set to true, then returns the actual token type name, otherwise, returns full type
396-
std::string toString(bool const& tokenValue = false) const
397-
{
398-
std::string name = TokenTraits::toString(m_token);
399-
if (tokenValue || (firstNumber() == 0 && secondNumber() == 0))
400-
return name;
401-
solAssert(name.size() >= 3, "Token name size should be greater than 3. Should not reach here.");
402-
if (m_token == Token::FixedMxN || m_token == Token::UFixedMxN)
403-
return name.substr(0, name.size() - 3) + std::to_string(m_firstNumber) + "x" + std::to_string(m_secondNumber);
404-
else
405-
return name.substr(0, name.size() - 1) + std::to_string(m_firstNumber);
406-
}
390+
std::string toString(bool const& tokenValue = false) const;
407391

408392
private:
409393
Token m_token;

0 commit comments

Comments
 (0)