mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Adds line numbers to parser errors in isoltest.
This commit is contained in:
@@ -43,7 +43,8 @@ SemanticTest::SemanticTest(string const& _filename, string const& _ipcPath, lang
|
||||
soltestAssert(file, "Cannot open test contract: \"" + _filename + "\".");
|
||||
file.exceptions(ios::badbit);
|
||||
|
||||
m_source = parseSourceAndSettings(file);
|
||||
std::tie(m_source, m_lineOffset) = parseSourceAndSettingsWithLineNumbers(file);
|
||||
|
||||
if (m_settings.count("compileViaYul"))
|
||||
{
|
||||
if (m_settings["compileViaYul"] == "also")
|
||||
@@ -163,7 +164,7 @@ void SemanticTest::printUpdatedExpectations(ostream& _stream, string const&) con
|
||||
void SemanticTest::parseExpectations(istream& _stream)
|
||||
{
|
||||
TestFileParser parser{_stream};
|
||||
auto functionCalls = parser.parseFunctionCalls();
|
||||
auto functionCalls = parser.parseFunctionCalls(m_lineOffset);
|
||||
std::move(functionCalls.begin(), functionCalls.end(), back_inserter(m_tests));
|
||||
}
|
||||
|
||||
|
||||
@@ -64,6 +64,7 @@ public:
|
||||
|
||||
private:
|
||||
std::string m_source;
|
||||
std::size_t m_lineOffset;
|
||||
std::vector<TestFunctionCall> m_tests;
|
||||
bool m_runWithYul = false;
|
||||
bool m_runWithoutYul = true;
|
||||
|
||||
@@ -48,7 +48,7 @@ char TestFileParser::Scanner::peek() const noexcept
|
||||
return *next;
|
||||
}
|
||||
|
||||
vector<dev::solidity::test::FunctionCall> TestFileParser::parseFunctionCalls()
|
||||
vector<dev::solidity::test::FunctionCall> TestFileParser::parseFunctionCalls(size_t _lineOffset)
|
||||
{
|
||||
vector<FunctionCall> calls;
|
||||
if (!accept(Token::EOS))
|
||||
@@ -70,32 +70,47 @@ vector<dev::solidity::test::FunctionCall> TestFileParser::parseFunctionCalls()
|
||||
if (calls.empty())
|
||||
expect(Token::Newline);
|
||||
else
|
||||
accept(Token::Newline, true);
|
||||
if (accept(Token::Newline, true))
|
||||
m_lineNumber++;
|
||||
|
||||
call.signature = parseFunctionSignature();
|
||||
if (accept(Token::Comma, true))
|
||||
call.value = parseFunctionCallValue();
|
||||
if (accept(Token::Colon, true))
|
||||
call.arguments = parseFunctionCallArguments();
|
||||
try
|
||||
{
|
||||
call.signature = parseFunctionSignature();
|
||||
if (accept(Token::Comma, true))
|
||||
call.value = parseFunctionCallValue();
|
||||
if (accept(Token::Colon, true))
|
||||
call.arguments = parseFunctionCallArguments();
|
||||
|
||||
if (accept(Token::Newline, true))
|
||||
call.displayMode = FunctionCall::DisplayMode::MultiLine;
|
||||
if (accept(Token::Newline, true))
|
||||
{
|
||||
call.displayMode = FunctionCall::DisplayMode::MultiLine;
|
||||
m_lineNumber++;
|
||||
}
|
||||
|
||||
call.arguments.comment = parseComment();
|
||||
call.arguments.comment = parseComment();
|
||||
|
||||
if (accept(Token::Newline, true))
|
||||
call.displayMode = FunctionCall::DisplayMode::MultiLine;
|
||||
if (accept(Token::Newline, true))
|
||||
{
|
||||
call.displayMode = FunctionCall::DisplayMode::MultiLine;
|
||||
m_lineNumber++;
|
||||
}
|
||||
|
||||
expect(Token::Arrow);
|
||||
call.expectations = parseFunctionCallExpectations();
|
||||
expect(Token::Arrow);
|
||||
call.expectations = parseFunctionCallExpectations();
|
||||
|
||||
accept(Token::Newline, true);
|
||||
call.expectations.comment = parseComment();
|
||||
if (accept(Token::Newline, true))
|
||||
m_lineNumber++;
|
||||
call.expectations.comment = parseComment();
|
||||
|
||||
if (call.signature == "constructor()")
|
||||
call.isConstructor = true;
|
||||
if (call.signature == "constructor()")
|
||||
call.isConstructor = true;
|
||||
|
||||
calls.emplace_back(std::move(call));
|
||||
calls.emplace_back(std::move(call));
|
||||
}
|
||||
catch (Error const& _e)
|
||||
{
|
||||
throw Error{_e.type(), "Line " + to_string(_lineOffset + m_lineNumber) + ": " + _e.what()};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -207,7 +222,10 @@ Parameter TestFileParser::parseParameter()
|
||||
{
|
||||
Parameter parameter;
|
||||
if (accept(Token::Newline, true))
|
||||
{
|
||||
parameter.format.newline = true;
|
||||
m_lineNumber++;
|
||||
}
|
||||
|
||||
bool isSigned = false;
|
||||
|
||||
|
||||
@@ -59,7 +59,9 @@ public:
|
||||
/// Throws an exception if a function call cannot be parsed because of its
|
||||
/// incorrect structure, an invalid or unsupported encoding
|
||||
/// of its arguments or expected results.
|
||||
std::vector<FunctionCall> parseFunctionCalls();
|
||||
/// Passes the source line offset, such that parsing errors can be enhanced
|
||||
/// with a line number it occurred in.
|
||||
std::vector<FunctionCall> parseFunctionCalls(std::size_t _lineOffset);
|
||||
|
||||
private:
|
||||
using Token = soltest::Token;
|
||||
@@ -179,6 +181,10 @@ private:
|
||||
|
||||
/// A scanner instance
|
||||
Scanner m_scanner;
|
||||
|
||||
/// The current line number. Incremented when Token::Newline (//) is found and
|
||||
/// used to enhance parser error messages.
|
||||
size_t m_lineNumber = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ vector<FunctionCall> parse(string const& _source)
|
||||
{
|
||||
istringstream stream{_source, ios_base::out};
|
||||
TestFileParser parser{stream};
|
||||
return parser.parseFunctionCalls();
|
||||
return parser.parseFunctionCalls(0);
|
||||
}
|
||||
|
||||
void testFunctionCall(
|
||||
|
||||
Reference in New Issue
Block a user