mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #3373 from ethereum/sourceLocation
Reset source location after inline assembly and mechanism to update expectation in test.
This commit is contained in:
commit
ef356905ff
@ -347,6 +347,9 @@ void CompilerContext::appendInlineAssembly(
|
|||||||
|
|
||||||
solAssert(errorReporter.errors().empty(), "Failed to analyze inline assembly block.");
|
solAssert(errorReporter.errors().empty(), "Failed to analyze inline assembly block.");
|
||||||
assembly::CodeGenerator::assemble(*parserResult, analysisInfo, *m_asm, identifierAccess, _system);
|
assembly::CodeGenerator::assemble(*parserResult, analysisInfo, *m_asm, identifierAccess, _system);
|
||||||
|
|
||||||
|
// Reset the source location to the one of the node (instead of the CODEGEN source location)
|
||||||
|
updateSourceLocation();
|
||||||
}
|
}
|
||||||
|
|
||||||
FunctionDefinition const& CompilerContext::resolveVirtualFunction(
|
FunctionDefinition const& CompilerContext::resolveVirtualFunction(
|
||||||
|
@ -86,23 +86,59 @@ eth::AssemblyItems compileContract(const string& _sourceCode)
|
|||||||
return AssemblyItems();
|
return AssemblyItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void printAssemblyLocations(AssemblyItems const& _items)
|
||||||
|
{
|
||||||
|
auto printRepeated = [](SourceLocation const& _loc, size_t _repetitions)
|
||||||
|
{
|
||||||
|
cout <<
|
||||||
|
"\t\tvector<SourceLocation>(" <<
|
||||||
|
_repetitions <<
|
||||||
|
", SourceLocation(" <<
|
||||||
|
_loc.start <<
|
||||||
|
", " <<
|
||||||
|
_loc.end <<
|
||||||
|
", make_shared<string>(\"" <<
|
||||||
|
*_loc.sourceName <<
|
||||||
|
"\"))) +" << endl;
|
||||||
|
};
|
||||||
|
|
||||||
|
vector<SourceLocation> locations;
|
||||||
|
for (auto const& item: _items)
|
||||||
|
locations.push_back(item.location());
|
||||||
|
size_t repetitions = 0;
|
||||||
|
SourceLocation const* previousLoc = nullptr;
|
||||||
|
for (size_t i = 0; i < locations.size(); ++i)
|
||||||
|
{
|
||||||
|
SourceLocation& loc = locations[i];
|
||||||
|
if (previousLoc && *previousLoc == loc)
|
||||||
|
repetitions++;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (previousLoc)
|
||||||
|
printRepeated(*previousLoc, repetitions);
|
||||||
|
previousLoc = &loc;
|
||||||
|
repetitions = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (previousLoc)
|
||||||
|
printRepeated(*previousLoc, repetitions);
|
||||||
|
}
|
||||||
|
|
||||||
void checkAssemblyLocations(AssemblyItems const& _items, vector<SourceLocation> const& _locations)
|
void checkAssemblyLocations(AssemblyItems const& _items, vector<SourceLocation> const& _locations)
|
||||||
{
|
{
|
||||||
BOOST_CHECK_EQUAL(_items.size(), _locations.size());
|
BOOST_CHECK_EQUAL(_items.size(), _locations.size());
|
||||||
for (size_t i = 0; i < min(_items.size(), _locations.size()); ++i)
|
for (size_t i = 0; i < min(_items.size(), _locations.size()); ++i)
|
||||||
{
|
{
|
||||||
BOOST_CHECK_MESSAGE(
|
if (_items[i].location() != _locations[i])
|
||||||
_items[i].location() == _locations[i],
|
{
|
||||||
"Location mismatch for assembly item " + to_string(i) + ". Found: " +
|
BOOST_CHECK_MESSAGE(false, "Location mismatch for item " + to_string(i) + ". Found the following locations:");
|
||||||
(_items[i].location().sourceName ? *_items[i].location().sourceName + ":" : "(null source name)") +
|
printAssemblyLocations(_items);
|
||||||
to_string(_items[i].location().start) + "-" +
|
return;
|
||||||
to_string(_items[i].location().end) + ", expected: " +
|
}
|
||||||
(_locations[i].sourceName ? *_locations[i].sourceName + ":" : "(null source name)") +
|
|
||||||
to_string(_locations[i].start) + "-" +
|
|
||||||
to_string(_locations[i].end));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // end anonymous namespace
|
} // end anonymous namespace
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE(Assembly)
|
BOOST_AUTO_TEST_SUITE(Assembly)
|
||||||
|
Loading…
Reference in New Issue
Block a user