Some review fixes

This commit is contained in:
Alex Beregszaszi 2022-09-27 02:05:23 +02:00
parent b4f42f9b90
commit 513c34bafe
7 changed files with 21 additions and 20 deletions

View File

@ -32,7 +32,6 @@
#include <liblangutil/SourceLocation.h>
#include <libevmasm/Instruction.h>
#include <libsolutil/FixedHash.h>
#include <libsolutil/JSON.h>
#include <libsolutil/LazyInit.h>
#include <libsolutil/Visitor.h>

View File

@ -74,6 +74,7 @@ map<string, ASTPointer<SourceUnit>> ASTJsonImporter::jsonToSourceUnit(map<string
template <typename T, typename... Args>
ASTPointer<T> ASTJsonImporter::createASTNode(Json const& _node, Args&&... _args)
{
static_assert(sizeof(Json::number_integer_t) == sizeof(uint64_t));
astAssert(member(_node, "id").is_number_integer(), "'id'-field must be 64bit integer.");
int64_t id = static_cast<Json::number_integer_t>(_node["id"]);

View File

@ -388,7 +388,7 @@ Json collectEVMObject(
function<bool(string)> const& _artifactRequested
)
{
Json output = Json::object();
Json output{Json::object()};
if (_artifactRequested("object"))
output["object"] = _object.toHex();
if (_artifactRequested("opcodes"))
@ -1562,6 +1562,7 @@ Json StandardCompiler::formatFunctionDebugData(
map<string, evmasm::LinkerObject::FunctionDebugData> const& _debugInfo
)
{
static_assert(is_same_v<Json::number_unsigned_t, uint64_t>);
Json ret{Json::object()};
for (auto const& [name, info]: _debugInfo)
{

View File

@ -39,7 +39,7 @@ Json StorageLayout::generate(ContractDefinition const& _contractDef)
for (auto [var, slot, offset]: contractType->stateVariables())
variables.emplace_back(generate(*var, slot, offset));
Json layout;
Json layout(Json::object());
layout["storage"] = std::move(variables);
layout["types"] = std::move(m_types);
return layout;
@ -47,7 +47,7 @@ Json StorageLayout::generate(ContractDefinition const& _contractDef)
Json StorageLayout::generate(VariableDeclaration const& _var, u256 const& _slot, unsigned _offset)
{
Json varEntry;
Json varEntry(Json::object());
Type const* varType = _var.type();
varEntry["label"] = _var.name();

View File

@ -88,12 +88,12 @@ int toDiagnosticSeverity(Error::Type _errorType)
Json semanticTokensLegend()
{
Json legend = Json::object();
Json legend{Json::object()};
// NOTE! The (alphabetical) order and items must match exactly the items of
// their respective enum class members.
Json tokenTypes = Json::array();
Json tokenTypes{Json::array()};
tokenTypes.emplace_back("class");
tokenTypes.emplace_back("comment");
tokenTypes.emplace_back("enum");
@ -116,7 +116,7 @@ Json semanticTokensLegend()
tokenTypes.emplace_back("variable");
legend["tokenTypes"] = tokenTypes;
Json tokenModifiers = Json::array();
Json tokenModifiers{Json::array()};
tokenModifiers.emplace_back("abstract");
tokenModifiers.emplace_back("declaration");
tokenModifiers.emplace_back("definition");
@ -284,7 +284,7 @@ void LanguageServer::compileAndUpdateDiagnostics()
// LSP only has diagnostics applied to individual files.
continue;
Json jsonDiag;
Json jsonDiag{Json::object()};
jsonDiag["source"] = "solc";
jsonDiag["severity"] = toDiagnosticSeverity(error->type());
jsonDiag["code"] = Json{error->errorId().error};
@ -297,7 +297,7 @@ void LanguageServer::compileAndUpdateDiagnostics()
if (auto const* secondary = error->secondarySourceLocation())
for (auto&& [secondaryMessage, secondaryLocation]: secondary->infos)
{
Json jsonRelated;
Json jsonRelated{Json::object()};
jsonRelated["message"] = secondaryMessage;
jsonRelated["location"] = toJson(secondaryLocation);
jsonDiag["relatedInformation"].emplace_back(jsonRelated);
@ -308,7 +308,7 @@ void LanguageServer::compileAndUpdateDiagnostics()
if (m_client.traceValue() != TraceValue::Off)
{
Json extra;
Json extra{Json::object()};
extra["openFileCount"] = Json{diagnosticsBySourceUnit.size()};
m_client.trace("Number of currently open files: " + to_string(diagnosticsBySourceUnit.size()), extra);
}
@ -316,7 +316,7 @@ void LanguageServer::compileAndUpdateDiagnostics()
m_nonemptyDiagnostics.clear();
for (auto&& [sourceUnitName, diagnostics]: diagnosticsBySourceUnit)
{
Json params;
Json params{Json::object()};
params["uri"] = m_fileRepository.sourceUnitNameToUri(sourceUnitName);
if (!diagnostics.empty())
m_nonemptyDiagnostics.insert(sourceUnitName);
@ -408,7 +408,7 @@ void LanguageServer::handleInitialize(MessageID _id, Json const& _args)
if (_args["initializationOptions"].is_object())
changeConfiguration(_args["initializationOptions"]);
Json replyArgs;
Json replyArgs{Json::object()};
replyArgs["serverInfo"]["name"] = "solc";
replyArgs["serverInfo"]["version"] = string(VersionNumber);
replyArgs["capabilities"]["definitionProvider"] = true;
@ -441,7 +441,7 @@ void LanguageServer::semanticTokensFull(MessageID _id, Json const& _args)
m_compilerStack.charStream(sourceName);
Json data = SemanticTokensBuilder().build(ast, m_compilerStack.charStream(sourceName));
Json reply = Json::object();
Json reply{Json::object()};
reply["data"] = data;
m_client.reply(_id, std::move(reply));

View File

@ -91,10 +91,10 @@ void RenameSymbol::operator()(MessageID _id, Json const& _args)
// Apply changes in reverse order (will iterate in reverse)
sort(m_locations.begin(), m_locations.end());
Json reply = Json::object();
Json reply{Json::object()};
reply["changes"] = Json::object();
Json edits = Json::array();
Json edits{Json::array()};
for (auto i = m_locations.rbegin(); i != m_locations.rend(); i++)
{
@ -106,7 +106,7 @@ void RenameSymbol::operator()(MessageID _id, Json const& _args)
buffer.replace((size_t)i->start, (size_t)(i->end - i->start), newName);
fileRepository().setSourceByUri(uri, std::move(buffer));
Json edit = Json::object();
Json edit{Json::object()};
edit["range"] = toRange(*i);
edit["newText"] = newName;
@ -115,7 +115,7 @@ void RenameSymbol::operator()(MessageID _id, Json const& _args)
if (i + 1 == m_locations.rend() || (i + 1)->sourceName != i->sourceName)
{
reply["changes"][uri] = edits;
edits = Json::array();
edits = Json::array(); // Reset.
}
}

View File

@ -106,7 +106,7 @@ optional<map<string, string>> Transport::parseHeaders()
void Transport::notify(string _method, Json _message)
{
Json json;
Json json{Json::object()};
json["method"] = std::move(_method);
json["params"] = std::move(_message);
send(std::move(json));
@ -114,14 +114,14 @@ void Transport::notify(string _method, Json _message)
void Transport::reply(MessageID _id, Json _message)
{
Json json;
Json json{Json::object()};
json["result"] = std::move(_message);
send(std::move(json), _id);
}
void Transport::error(MessageID _id, ErrorCode _code, string _message)
{
Json json;
Json json{Json::object()};
json["error"]["code"] = static_cast<int>(_code);
json["error"]["message"] = std::move(_message);
send(std::move(json), _id);