mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
ASTJSON: Export evm version
This commit is contained in:
parent
d577a768ab
commit
adc4774d4a
@ -26,6 +26,8 @@
|
||||
#include <libyul/AsmJsonConverter.h>
|
||||
#include <libyul/AsmData.h>
|
||||
#include <libyul/AsmPrinter.h>
|
||||
#include <libyul/backends/evm/EVMDialect.h>
|
||||
|
||||
#include <libsolutil/JSON.h>
|
||||
#include <libsolutil/UTF8.h>
|
||||
|
||||
@ -492,13 +494,16 @@ bool ASTJsonConverter::visit(ArrayTypeName const& _node)
|
||||
bool ASTJsonConverter::visit(InlineAssembly const& _node)
|
||||
{
|
||||
vector<pair<string, Json::Value>> externalReferences;
|
||||
|
||||
for (auto const& it: _node.annotation().externalReferences)
|
||||
if (it.first)
|
||||
externalReferences.emplace_back(make_pair(
|
||||
it.first->name.str(),
|
||||
inlineAssemblyIdentifierToJson(it)
|
||||
));
|
||||
|
||||
Json::Value externalReferencesJson = Json::arrayValue;
|
||||
|
||||
for (auto&& it: boost::range::sort(externalReferences))
|
||||
externalReferencesJson.append(std::move(it.second));
|
||||
|
||||
@ -506,8 +511,10 @@ bool ASTJsonConverter::visit(InlineAssembly const& _node)
|
||||
m_legacy ?
|
||||
make_pair("operations", Json::Value(yul::AsmPrinter()(_node.operations()))) :
|
||||
make_pair("AST", Json::Value(yul::AsmJsonConverter(sourceIndexFromLocation(_node.location()))(_node.operations()))),
|
||||
make_pair("externalReferences", std::move(externalReferencesJson))
|
||||
make_pair("externalReferences", std::move(externalReferencesJson)),
|
||||
make_pair("evmVersion", dynamic_cast<solidity::yul::EVMDialect const&>(_node.dialect()).evmVersion().name())
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -124,6 +124,7 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"evmVersion": %EVMVERSION%,
|
||||
"externalReferences": [],
|
||||
"id": 3,
|
||||
"nodeType": "InlineAssembly",
|
||||
|
@ -89,6 +89,7 @@
|
||||
{
|
||||
"attributes":
|
||||
{
|
||||
"evmVersion": %EVMVERSION%,
|
||||
"externalReferences":
|
||||
[
|
||||
null
|
||||
|
@ -111,6 +111,7 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"evmVersion": %EVMVERSION%,
|
||||
"externalReferences": [],
|
||||
"id": 3,
|
||||
"nodeType": "InlineAssembly",
|
||||
|
@ -89,6 +89,7 @@
|
||||
{
|
||||
"attributes":
|
||||
{
|
||||
"evmVersion": %EVMVERSION%,
|
||||
"externalReferences":
|
||||
[
|
||||
null
|
||||
|
@ -61,6 +61,7 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"evmVersion": %EVMVERSION%,
|
||||
"externalReferences": [],
|
||||
"id": 3,
|
||||
"nodeType": "InlineAssembly",
|
||||
|
@ -89,6 +89,7 @@
|
||||
{
|
||||
"attributes":
|
||||
{
|
||||
"evmVersion": %EVMVERSION%,
|
||||
"externalReferences":
|
||||
[
|
||||
null
|
||||
|
@ -124,6 +124,7 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"evmVersion": %EVMVERSION%,
|
||||
"externalReferences": [],
|
||||
"id": 3,
|
||||
"nodeType": "InlineAssembly",
|
||||
|
@ -89,6 +89,7 @@
|
||||
{
|
||||
"attributes":
|
||||
{
|
||||
"evmVersion": %EVMVERSION%,
|
||||
"externalReferences":
|
||||
[
|
||||
null
|
||||
|
@ -176,6 +176,7 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"evmVersion": %EVMVERSION%,
|
||||
"externalReferences":
|
||||
[
|
||||
{
|
||||
|
@ -166,6 +166,7 @@
|
||||
{
|
||||
"attributes":
|
||||
{
|
||||
"evmVersion": %EVMVERSION%,
|
||||
"externalReferences":
|
||||
[
|
||||
{
|
||||
|
@ -65,6 +65,7 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"evmVersion": %EVMVERSION%,
|
||||
"externalReferences": [],
|
||||
"id": 3,
|
||||
"nodeType": "InlineAssembly",
|
||||
|
@ -89,6 +89,7 @@
|
||||
{
|
||||
"attributes":
|
||||
{
|
||||
"evmVersion": %EVMVERSION%,
|
||||
"externalReferences":
|
||||
[
|
||||
null
|
||||
|
@ -157,6 +157,7 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"evmVersion": %EVMVERSION%,
|
||||
"externalReferences": [],
|
||||
"id": 3,
|
||||
"nodeType": "InlineAssembly",
|
||||
|
@ -89,6 +89,7 @@
|
||||
{
|
||||
"attributes":
|
||||
{
|
||||
"evmVersion": %EVMVERSION%,
|
||||
"externalReferences":
|
||||
[
|
||||
null
|
||||
|
@ -107,6 +107,7 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"evmVersion": %EVMVERSION%,
|
||||
"externalReferences":
|
||||
[
|
||||
{
|
||||
|
@ -135,6 +135,7 @@
|
||||
{
|
||||
"attributes":
|
||||
{
|
||||
"evmVersion": %EVMVERSION%,
|
||||
"externalReferences":
|
||||
[
|
||||
{
|
||||
|
@ -15,6 +15,7 @@
|
||||
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <boost/algorithm/string/replace.hpp>
|
||||
#include <test/libsolidity/ASTJSONTest.h>
|
||||
#include <test/Options.h>
|
||||
#include <libsolutil/AnsiColorized.h>
|
||||
@ -38,6 +39,30 @@ using namespace std;
|
||||
namespace fs = boost::filesystem;
|
||||
using namespace boost::unit_test;
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
void replaceVersionWithTag(string& _input)
|
||||
{
|
||||
boost::algorithm::replace_all(
|
||||
_input,
|
||||
"\"" + solidity::test::Options::get().evmVersion().name() + "\"",
|
||||
"%EVMVERSION%"
|
||||
);
|
||||
}
|
||||
|
||||
void replaceTagWithVersion(string& _input)
|
||||
{
|
||||
boost::algorithm::replace_all(
|
||||
_input,
|
||||
"%EVMVERSION%",
|
||||
"\"" + solidity::test::Options::get().evmVersion().name() + "\""
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
ASTJSONTest::ASTJSONTest(string const& _filename)
|
||||
{
|
||||
if (!boost::algorithm::ends_with(_filename, ".sol"))
|
||||
@ -126,6 +151,8 @@ TestCase::TestResult ASTJSONTest::run(ostream& _stream, string const& _linePrefi
|
||||
|
||||
bool resultsMatch = true;
|
||||
|
||||
replaceTagWithVersion(m_expectation);
|
||||
|
||||
if (m_expectation != m_result)
|
||||
{
|
||||
string nextIndentLevel = _linePrefix + " ";
|
||||
@ -158,6 +185,8 @@ TestCase::TestResult ASTJSONTest::run(ostream& _stream, string const& _linePrefi
|
||||
m_resultLegacy += "\n";
|
||||
}
|
||||
|
||||
replaceTagWithVersion(m_expectationLegacy);
|
||||
|
||||
if (m_expectationLegacy != m_resultLegacy)
|
||||
{
|
||||
string nextIndentLevel = _linePrefix + " ";
|
||||
@ -202,12 +231,21 @@ void ASTJSONTest::printUpdatedExpectations(std::ostream&, std::string const&) co
|
||||
ofstream file(m_astFilename.c_str());
|
||||
if (!file) BOOST_THROW_EXCEPTION(runtime_error("Cannot write AST expectation to \"" + m_astFilename + "\"."));
|
||||
file.exceptions(ios::badbit);
|
||||
file << m_result;
|
||||
|
||||
string replacedResult = m_result;
|
||||
replaceVersionWithTag(replacedResult);
|
||||
|
||||
file << replacedResult;
|
||||
file.flush();
|
||||
file.close();
|
||||
|
||||
file.open(m_legacyAstFilename.c_str());
|
||||
if (!file) BOOST_THROW_EXCEPTION(runtime_error("Cannot write legacy AST expectation to \"" + m_legacyAstFilename + "\"."));
|
||||
file << m_resultLegacy;
|
||||
|
||||
string replacedResultLegacy = m_resultLegacy;
|
||||
replaceVersionWithTag(replacedResultLegacy);
|
||||
|
||||
file << replacedResultLegacy;
|
||||
file.flush();
|
||||
file.close();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user