Skip to content

Commit

Permalink
fix: JSON library compilation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
abinavpp authored and antonbaliasnikov committed Jun 5, 2024
1 parent 9d9aa98 commit 905b735
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 23 deletions.
4 changes: 2 additions & 2 deletions libsolidity/codegen/Compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
29 changes: 15 additions & 14 deletions libsolidity/codegen/ExtraMetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}
Expand All @@ -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)
Expand All @@ -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<Json::number_integer_t>(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<Json::number_integer_t>(func.label));
record["totalParamSize"] = Json(static_cast<Json::number_integer_t>(func.ast->parameters.size()));
record["totalRetParamSize"]
= Json(static_cast<Json::number_integer_t>(func.ast->returnVariables.size()));
m_recFuncs.push_back(record);
}
}
}
Expand All @@ -92,25 +93,25 @@ 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;
else
func["runtimeTag"] = fn.tag;
func["totalParamSize"] = fn.ins;
func["totalRetParamSize"] = fn.outs;
recFuncs.append(func);
recFuncs.push_back(func);
}
};
recordRecursiveLowLevelFuncs(m_context);
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions libsolidity/codegen/ExtraMetadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <libsolidity/ast/ASTForward.h>
#include <libsolidity/codegen/CompilerContext.h>

#include <json/value.h>
#include <libsolutil/JSON.h>

#include <memory>

Expand All @@ -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)
Expand All @@ -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);
};

}
2 changes: 1 addition & 1 deletion libsolidity/interface/CompilerStack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions libsolidity/interface/CompilerStack.h
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
Expand Down Expand Up @@ -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<std::string const> metadata; ///< The metadata json that will be hashed into the chain.
util::LazyInit<Json const> abi;
util::LazyInit<Json const> storageLayout;
Expand Down
2 changes: 1 addition & 1 deletion libsolidity/interface/StandardCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 905b735

Please sign in to comment.