From 905b735b62cba5956a2fa9d60ea56380850b9934 Mon Sep 17 00:00:00 2001 From: Abinav Puthan Purayil Date: Mon, 3 Jun 2024 00:10:57 +0200 Subject: [PATCH] fix: JSON library compilation errors --- libsolidity/codegen/Compiler.h | 4 +-- libsolidity/codegen/ExtraMetadata.cpp | 29 +++++++++++----------- libsolidity/codegen/ExtraMetadata.h | 6 ++--- libsolidity/interface/CompilerStack.cpp | 2 +- libsolidity/interface/CompilerStack.h | 4 +-- libsolidity/interface/StandardCompiler.cpp | 2 +- 6 files changed, 24 insertions(+), 23 deletions(-) diff --git a/libsolidity/codegen/Compiler.h b/libsolidity/codegen/Compiler.h index 4ddb037b8c..e2747991bd 100644 --- a/libsolidity/codegen/Compiler.h +++ b/libsolidity/codegen/Compiler.h @@ -61,10 +61,10 @@ class Compiler std::string generatedYulUtilityCode() const { return m_context.generatedYulUtilityCode(); } std::string runtimeGeneratedYulUtilityCode() const { return m_runtimeContext.generatedYulUtilityCode(); } - Json::Value extraMetadata() const { return m_extraMetadata; } + Json extraMetadata() const { return m_extraMetadata; } private: - Json::Value m_extraMetadata; + Json m_extraMetadata; OptimiserSettings const m_optimiserSettings; CompilerContext m_runtimeContext; size_t m_runtimeSub = size_t(-1); ///< Identifier of the runtime sub-assembly, if present. diff --git a/libsolidity/codegen/ExtraMetadata.cpp b/libsolidity/codegen/ExtraMetadata.cpp index ca05d1dca5..d114eaea8b 100644 --- a/libsolidity/codegen/ExtraMetadata.cpp +++ b/libsolidity/codegen/ExtraMetadata.cpp @@ -36,7 +36,7 @@ class InlineAsmRecursiveFuncRecorder: public ASTConstVisitor CallableDeclaration const& _func, CompilerContext const& _context, CompilerContext const& _runtimeContext, - Json::Value& _recFuncs) + Json& _recFuncs) : m_func(_func), m_context(_context), m_runtimeContext(_runtimeContext), m_recFuncs(_recFuncs) { } @@ -45,7 +45,7 @@ class InlineAsmRecursiveFuncRecorder: public ASTConstVisitor CallableDeclaration const& m_func; CompilerContext const& m_context; CompilerContext const& m_runtimeContext; - Json::Value& m_recFuncs; + Json& m_recFuncs; // Record recursions in @_asm for the extra metadata void record(InlineAssembly const& _p_asm, CompilerContext const& _context) @@ -72,15 +72,16 @@ class InlineAsmRecursiveFuncRecorder: public ASTConstVisitor continue; for (auto& func: findIt->second) { - Json::Value record(Json::objectValue); + Json record = Json::object(); record["name"] = recFunc.str(); if (_context.runtimeContext()) - record["creationTag"] = Json::Value(Json::LargestUInt(func.label)); + record["creationTag"] = Json(static_cast(func.label)); else - record["runtimeTag"] = Json::Value(Json::LargestUInt(func.label)); - record["totalParamSize"] = Json::Value(Json::LargestUInt(func.ast->parameters.size())); - record["totalRetParamSize"] = Json::Value(Json::LargestUInt(func.ast->returnVariables.size())); - m_recFuncs.append(record); + record["runtimeTag"] = Json(static_cast(func.label)); + record["totalParamSize"] = Json(static_cast(func.ast->parameters.size())); + record["totalRetParamSize"] + = Json(static_cast(func.ast->returnVariables.size())); + m_recFuncs.push_back(record); } } } @@ -92,17 +93,17 @@ class InlineAsmRecursiveFuncRecorder: public ASTConstVisitor } }; -Json::Value ExtraMetadataRecorder::run(ContractDefinition const& _contract) +Json ExtraMetadataRecorder::run(ContractDefinition const& _contract) { // Set "recursiveFunctions" - Json::Value recFuncs(Json::arrayValue); + Json recFuncs = Json::array(); // Record recursions in low level calls auto recordRecursiveLowLevelFuncs = [&](CompilerContext const& _context) { for (auto fn: _context.recursiveLowLevelFuncs()) { - Json::Value func(Json::objectValue); + Json func = Json::object(); func["name"] = fn.name; if (_context.runtimeContext()) func["creationTag"] = fn.tag; @@ -110,7 +111,7 @@ Json::Value ExtraMetadataRecorder::run(ContractDefinition const& _contract) func["runtimeTag"] = fn.tag; func["totalParamSize"] = fn.ins; func["totalRetParamSize"] = fn.outs; - recFuncs.append(func); + recFuncs.push_back(func); } }; recordRecursiveLowLevelFuncs(m_context); @@ -152,7 +153,7 @@ Json::Value ExtraMetadataRecorder::run(ContractDefinition const& _contract) if (tag == evmasm::AssemblyItem(evmasm::UndefinedItem)) continue; - Json::Value func(Json::objectValue); + Json func = Json::object(); func["name"] = fn->name(); // Assembly::new[Push]Tag() asserts that the tag is 32 bits @@ -170,7 +171,7 @@ Json::Value ExtraMetadataRecorder::run(ContractDefinition const& _contract) totalRetParamSize += param->type()->sizeOnStack(); func["totalRetParamSize"] = totalRetParamSize; - recFuncs.append(func); + recFuncs.push_back(func); } }; recordRecursiveSolFuncs(m_context); diff --git a/libsolidity/codegen/ExtraMetadata.h b/libsolidity/codegen/ExtraMetadata.h index 4536c5248e..e9598c1abe 100644 --- a/libsolidity/codegen/ExtraMetadata.h +++ b/libsolidity/codegen/ExtraMetadata.h @@ -22,7 +22,7 @@ #include #include -#include +#include #include @@ -38,7 +38,7 @@ class ExtraMetadataRecorder /// The root JSON value of the metadata /// Current mappings: /// - "recursiveFunctions": array of functions involved in recursion - Json::Value m_metadata; + Json m_metadata; public: ExtraMetadataRecorder(CompilerContext const& _context, CompilerContext const& _runtimeContext) @@ -47,7 +47,7 @@ class ExtraMetadataRecorder } /// Stores the extra metadata of @a _contract in `metadata` - Json::Value run(ContractDefinition const& _contract); + Json run(ContractDefinition const& _contract); }; } diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp index 5fb9f6ce3a..5c2188faab 100644 --- a/libsolidity/interface/CompilerStack.cpp +++ b/libsolidity/interface/CompilerStack.cpp @@ -1179,7 +1179,7 @@ std::string const& CompilerStack::metadata(Contract const& _contract) const return _contract.metadata.init([&]{ return createMetadata(_contract, m_viaIR); }); } -Json::Value const& CompilerStack::extraMetadata(std::string const& _contractName) const +Json const& CompilerStack::extraMetadata(std::string const& _contractName) const { Contract const& contr = contract(_contractName); if (m_stackState < AnalysisSuccessful) diff --git a/libsolidity/interface/CompilerStack.h b/libsolidity/interface/CompilerStack.h index 8040261797..c3dd93a428 100644 --- a/libsolidity/interface/CompilerStack.h +++ b/libsolidity/interface/CompilerStack.h @@ -341,7 +341,7 @@ class CompilerStack: public langutil::CharStreamProvider, public evmasm::Abstrac std::string const& metadata(std::string const& _contractName) const { return metadata(contract(_contractName)); } /// @returns the contract metadata containing miscellaneous information - Json::Value const& extraMetadata(std::string const& _contractName) const; + Json const& extraMetadata(std::string const& _contractName) const; /// @returns the CBOR-encoded metadata matching the pipeline selected using the viaIR setting. bytes cborMetadata(std::string const& _contractName) const { return cborMetadata(_contractName, m_viaIR); } @@ -394,7 +394,7 @@ class CompilerStack: public langutil::CharStreamProvider, public evmasm::Abstrac std::string yulIROptimized; ///< Optimized Yul IR code. Json yulIRAst; ///< JSON AST of Yul IR code. Json yulIROptimizedAst; ///< JSON AST of optimized Yul IR code. - Json::Value extraMetadata; ///< Misc metadata + Json extraMetadata; ///< Misc metadata util::LazyInit metadata; ///< The metadata json that will be hashed into the chain. util::LazyInit abi; util::LazyInit storageLayout; diff --git a/libsolidity/interface/StandardCompiler.cpp b/libsolidity/interface/StandardCompiler.cpp index 46000d8eb9..c32db29de3 100644 --- a/libsolidity/interface/StandardCompiler.cpp +++ b/libsolidity/interface/StandardCompiler.cpp @@ -1538,7 +1538,7 @@ Json StandardCompiler::compileSolidity(StandardCompiler::InputsAndSettings _inpu if (compilationSuccess && isArtifactRequested(_inputsAndSettings.outputSelection, file, name, "evm.gasEstimates", wildcardMatchesExperimental)) evmData["gasEstimates"] = compilerStack.gasEstimates(contractName); - Json::Value extraMetadata = compilerStack.extraMetadata(contractName); + Json extraMetadata = compilerStack.extraMetadata(contractName); if (compilationSuccess && !extraMetadata.empty()) evmData["extraMetadata"] = extraMetadata;