Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion liblangutil/ParserBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Token ParserBase::peekNextToken() const
return m_scanner->peekNextToken();
}

std::string ParserBase::currentLiteral() const
std::string_view ParserBase::currentLiteral() const
{
return m_scanner->currentLiteral();
}
Expand Down
3 changes: 2 additions & 1 deletion liblangutil/ParserBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ class ParserBase
Token currentToken() const;
Token peekNextToken() const;
std::string tokenName(Token _token);
std::string currentLiteral() const;
/// Points to the current literal. The string view invalidates when the parser advances.
std::string_view currentLiteral() const;
virtual Token advance();
///@}

Expand Down
2 changes: 1 addition & 1 deletion libsolutil/CommonData.h
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ inline std::string asString(bytesConstRef _b)
}

/// Converts a string to a byte array containing the string's (byte) data.
inline bytes asBytes(std::string const& _b)
inline bytes asBytes(std::string_view const _b)
{
return bytes((uint8_t const*)_b.data(), (uint8_t const*)(_b.data() + _b.size()));
}
Expand Down
4 changes: 2 additions & 2 deletions libyul/AsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ void Parser::checkBreakContinuePosition(std::string const& _which)
}
}

bool Parser::isValidNumberLiteral(std::string const& _literal)
bool Parser::isValidNumberLiteral(std::string_view const _literal)
{
try
{
Expand All @@ -793,7 +793,7 @@ bool Parser::isValidNumberLiteral(std::string const& _literal)
if (boost::starts_with(_literal, "0x"))
return true;
else
return _literal.find_first_not_of("0123456789") == std::string::npos;
return _literal.find_first_not_of("0123456789") == std::string_view::npos;
}

void Parser::raiseUnsupportedTypesError(SourceLocation const& _location) const
Expand Down
2 changes: 1 addition & 1 deletion libyul/AsmParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class Parser: public langutil::ParserBase
/// Reports an error if we are currently not inside the body part of a for loop.
void checkBreakContinuePosition(std::string const& _which);

static bool isValidNumberLiteral(std::string const& _literal);
static bool isValidNumberLiteral(std::string_view _literal);

private:
Dialect const& m_dialect;
Expand Down
2 changes: 1 addition & 1 deletion libyul/ObjectParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ void ObjectParser::parseData(Object& _containingObject)
std::string ObjectParser::parseUniqueName(Object const* _containingObject)
{
expectToken(Token::StringLiteral, false);
auto const name = currentLiteral();
std::string const name{currentLiteral()};
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here storing an explicit copy is required as we advance before returning from the function.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is an issue, it may be worthwhile to document the lifetime of the string_view in the header (i.e. state that advance invalidates it there)?

if (name.empty())
parserError(3287_error, "Object name cannot be empty.");
else if (_containingObject && _containingObject->name == name)
Expand Down