mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Some review fixes
This commit is contained in:
parent
b4f42f9b90
commit
513c34bafe
@ -32,7 +32,6 @@
|
|||||||
#include <liblangutil/SourceLocation.h>
|
#include <liblangutil/SourceLocation.h>
|
||||||
#include <libevmasm/Instruction.h>
|
#include <libevmasm/Instruction.h>
|
||||||
#include <libsolutil/FixedHash.h>
|
#include <libsolutil/FixedHash.h>
|
||||||
#include <libsolutil/JSON.h>
|
|
||||||
#include <libsolutil/LazyInit.h>
|
#include <libsolutil/LazyInit.h>
|
||||||
#include <libsolutil/Visitor.h>
|
#include <libsolutil/Visitor.h>
|
||||||
|
|
||||||
|
@ -74,6 +74,7 @@ map<string, ASTPointer<SourceUnit>> ASTJsonImporter::jsonToSourceUnit(map<string
|
|||||||
template <typename T, typename... Args>
|
template <typename T, typename... Args>
|
||||||
ASTPointer<T> ASTJsonImporter::createASTNode(Json const& _node, Args&&... _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.");
|
astAssert(member(_node, "id").is_number_integer(), "'id'-field must be 64bit integer.");
|
||||||
|
|
||||||
int64_t id = static_cast<Json::number_integer_t>(_node["id"]);
|
int64_t id = static_cast<Json::number_integer_t>(_node["id"]);
|
||||||
|
@ -388,7 +388,7 @@ Json collectEVMObject(
|
|||||||
function<bool(string)> const& _artifactRequested
|
function<bool(string)> const& _artifactRequested
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
Json output = Json::object();
|
Json output{Json::object()};
|
||||||
if (_artifactRequested("object"))
|
if (_artifactRequested("object"))
|
||||||
output["object"] = _object.toHex();
|
output["object"] = _object.toHex();
|
||||||
if (_artifactRequested("opcodes"))
|
if (_artifactRequested("opcodes"))
|
||||||
@ -1562,6 +1562,7 @@ Json StandardCompiler::formatFunctionDebugData(
|
|||||||
map<string, evmasm::LinkerObject::FunctionDebugData> const& _debugInfo
|
map<string, evmasm::LinkerObject::FunctionDebugData> const& _debugInfo
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
static_assert(is_same_v<Json::number_unsigned_t, uint64_t>);
|
||||||
Json ret{Json::object()};
|
Json ret{Json::object()};
|
||||||
for (auto const& [name, info]: _debugInfo)
|
for (auto const& [name, info]: _debugInfo)
|
||||||
{
|
{
|
||||||
|
@ -39,7 +39,7 @@ Json StorageLayout::generate(ContractDefinition const& _contractDef)
|
|||||||
for (auto [var, slot, offset]: contractType->stateVariables())
|
for (auto [var, slot, offset]: contractType->stateVariables())
|
||||||
variables.emplace_back(generate(*var, slot, offset));
|
variables.emplace_back(generate(*var, slot, offset));
|
||||||
|
|
||||||
Json layout;
|
Json layout(Json::object());
|
||||||
layout["storage"] = std::move(variables);
|
layout["storage"] = std::move(variables);
|
||||||
layout["types"] = std::move(m_types);
|
layout["types"] = std::move(m_types);
|
||||||
return layout;
|
return layout;
|
||||||
@ -47,7 +47,7 @@ Json StorageLayout::generate(ContractDefinition const& _contractDef)
|
|||||||
|
|
||||||
Json StorageLayout::generate(VariableDeclaration const& _var, u256 const& _slot, unsigned _offset)
|
Json StorageLayout::generate(VariableDeclaration const& _var, u256 const& _slot, unsigned _offset)
|
||||||
{
|
{
|
||||||
Json varEntry;
|
Json varEntry(Json::object());
|
||||||
Type const* varType = _var.type();
|
Type const* varType = _var.type();
|
||||||
|
|
||||||
varEntry["label"] = _var.name();
|
varEntry["label"] = _var.name();
|
||||||
|
@ -88,12 +88,12 @@ int toDiagnosticSeverity(Error::Type _errorType)
|
|||||||
|
|
||||||
Json semanticTokensLegend()
|
Json semanticTokensLegend()
|
||||||
{
|
{
|
||||||
Json legend = Json::object();
|
Json legend{Json::object()};
|
||||||
|
|
||||||
// NOTE! The (alphabetical) order and items must match exactly the items of
|
// NOTE! The (alphabetical) order and items must match exactly the items of
|
||||||
// their respective enum class members.
|
// their respective enum class members.
|
||||||
|
|
||||||
Json tokenTypes = Json::array();
|
Json tokenTypes{Json::array()};
|
||||||
tokenTypes.emplace_back("class");
|
tokenTypes.emplace_back("class");
|
||||||
tokenTypes.emplace_back("comment");
|
tokenTypes.emplace_back("comment");
|
||||||
tokenTypes.emplace_back("enum");
|
tokenTypes.emplace_back("enum");
|
||||||
@ -116,7 +116,7 @@ Json semanticTokensLegend()
|
|||||||
tokenTypes.emplace_back("variable");
|
tokenTypes.emplace_back("variable");
|
||||||
legend["tokenTypes"] = tokenTypes;
|
legend["tokenTypes"] = tokenTypes;
|
||||||
|
|
||||||
Json tokenModifiers = Json::array();
|
Json tokenModifiers{Json::array()};
|
||||||
tokenModifiers.emplace_back("abstract");
|
tokenModifiers.emplace_back("abstract");
|
||||||
tokenModifiers.emplace_back("declaration");
|
tokenModifiers.emplace_back("declaration");
|
||||||
tokenModifiers.emplace_back("definition");
|
tokenModifiers.emplace_back("definition");
|
||||||
@ -284,7 +284,7 @@ void LanguageServer::compileAndUpdateDiagnostics()
|
|||||||
// LSP only has diagnostics applied to individual files.
|
// LSP only has diagnostics applied to individual files.
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Json jsonDiag;
|
Json jsonDiag{Json::object()};
|
||||||
jsonDiag["source"] = "solc";
|
jsonDiag["source"] = "solc";
|
||||||
jsonDiag["severity"] = toDiagnosticSeverity(error->type());
|
jsonDiag["severity"] = toDiagnosticSeverity(error->type());
|
||||||
jsonDiag["code"] = Json{error->errorId().error};
|
jsonDiag["code"] = Json{error->errorId().error};
|
||||||
@ -297,7 +297,7 @@ void LanguageServer::compileAndUpdateDiagnostics()
|
|||||||
if (auto const* secondary = error->secondarySourceLocation())
|
if (auto const* secondary = error->secondarySourceLocation())
|
||||||
for (auto&& [secondaryMessage, secondaryLocation]: secondary->infos)
|
for (auto&& [secondaryMessage, secondaryLocation]: secondary->infos)
|
||||||
{
|
{
|
||||||
Json jsonRelated;
|
Json jsonRelated{Json::object()};
|
||||||
jsonRelated["message"] = secondaryMessage;
|
jsonRelated["message"] = secondaryMessage;
|
||||||
jsonRelated["location"] = toJson(secondaryLocation);
|
jsonRelated["location"] = toJson(secondaryLocation);
|
||||||
jsonDiag["relatedInformation"].emplace_back(jsonRelated);
|
jsonDiag["relatedInformation"].emplace_back(jsonRelated);
|
||||||
@ -308,7 +308,7 @@ void LanguageServer::compileAndUpdateDiagnostics()
|
|||||||
|
|
||||||
if (m_client.traceValue() != TraceValue::Off)
|
if (m_client.traceValue() != TraceValue::Off)
|
||||||
{
|
{
|
||||||
Json extra;
|
Json extra{Json::object()};
|
||||||
extra["openFileCount"] = Json{diagnosticsBySourceUnit.size()};
|
extra["openFileCount"] = Json{diagnosticsBySourceUnit.size()};
|
||||||
m_client.trace("Number of currently open files: " + to_string(diagnosticsBySourceUnit.size()), extra);
|
m_client.trace("Number of currently open files: " + to_string(diagnosticsBySourceUnit.size()), extra);
|
||||||
}
|
}
|
||||||
@ -316,7 +316,7 @@ void LanguageServer::compileAndUpdateDiagnostics()
|
|||||||
m_nonemptyDiagnostics.clear();
|
m_nonemptyDiagnostics.clear();
|
||||||
for (auto&& [sourceUnitName, diagnostics]: diagnosticsBySourceUnit)
|
for (auto&& [sourceUnitName, diagnostics]: diagnosticsBySourceUnit)
|
||||||
{
|
{
|
||||||
Json params;
|
Json params{Json::object()};
|
||||||
params["uri"] = m_fileRepository.sourceUnitNameToUri(sourceUnitName);
|
params["uri"] = m_fileRepository.sourceUnitNameToUri(sourceUnitName);
|
||||||
if (!diagnostics.empty())
|
if (!diagnostics.empty())
|
||||||
m_nonemptyDiagnostics.insert(sourceUnitName);
|
m_nonemptyDiagnostics.insert(sourceUnitName);
|
||||||
@ -408,7 +408,7 @@ void LanguageServer::handleInitialize(MessageID _id, Json const& _args)
|
|||||||
if (_args["initializationOptions"].is_object())
|
if (_args["initializationOptions"].is_object())
|
||||||
changeConfiguration(_args["initializationOptions"]);
|
changeConfiguration(_args["initializationOptions"]);
|
||||||
|
|
||||||
Json replyArgs;
|
Json replyArgs{Json::object()};
|
||||||
replyArgs["serverInfo"]["name"] = "solc";
|
replyArgs["serverInfo"]["name"] = "solc";
|
||||||
replyArgs["serverInfo"]["version"] = string(VersionNumber);
|
replyArgs["serverInfo"]["version"] = string(VersionNumber);
|
||||||
replyArgs["capabilities"]["definitionProvider"] = true;
|
replyArgs["capabilities"]["definitionProvider"] = true;
|
||||||
@ -441,7 +441,7 @@ void LanguageServer::semanticTokensFull(MessageID _id, Json const& _args)
|
|||||||
m_compilerStack.charStream(sourceName);
|
m_compilerStack.charStream(sourceName);
|
||||||
Json data = SemanticTokensBuilder().build(ast, m_compilerStack.charStream(sourceName));
|
Json data = SemanticTokensBuilder().build(ast, m_compilerStack.charStream(sourceName));
|
||||||
|
|
||||||
Json reply = Json::object();
|
Json reply{Json::object()};
|
||||||
reply["data"] = data;
|
reply["data"] = data;
|
||||||
|
|
||||||
m_client.reply(_id, std::move(reply));
|
m_client.reply(_id, std::move(reply));
|
||||||
|
@ -91,10 +91,10 @@ void RenameSymbol::operator()(MessageID _id, Json const& _args)
|
|||||||
// Apply changes in reverse order (will iterate in reverse)
|
// Apply changes in reverse order (will iterate in reverse)
|
||||||
sort(m_locations.begin(), m_locations.end());
|
sort(m_locations.begin(), m_locations.end());
|
||||||
|
|
||||||
Json reply = Json::object();
|
Json reply{Json::object()};
|
||||||
reply["changes"] = 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++)
|
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);
|
buffer.replace((size_t)i->start, (size_t)(i->end - i->start), newName);
|
||||||
fileRepository().setSourceByUri(uri, std::move(buffer));
|
fileRepository().setSourceByUri(uri, std::move(buffer));
|
||||||
|
|
||||||
Json edit = Json::object();
|
Json edit{Json::object()};
|
||||||
edit["range"] = toRange(*i);
|
edit["range"] = toRange(*i);
|
||||||
edit["newText"] = newName;
|
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)
|
if (i + 1 == m_locations.rend() || (i + 1)->sourceName != i->sourceName)
|
||||||
{
|
{
|
||||||
reply["changes"][uri] = edits;
|
reply["changes"][uri] = edits;
|
||||||
edits = Json::array();
|
edits = Json::array(); // Reset.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ optional<map<string, string>> Transport::parseHeaders()
|
|||||||
|
|
||||||
void Transport::notify(string _method, Json _message)
|
void Transport::notify(string _method, Json _message)
|
||||||
{
|
{
|
||||||
Json json;
|
Json json{Json::object()};
|
||||||
json["method"] = std::move(_method);
|
json["method"] = std::move(_method);
|
||||||
json["params"] = std::move(_message);
|
json["params"] = std::move(_message);
|
||||||
send(std::move(json));
|
send(std::move(json));
|
||||||
@ -114,14 +114,14 @@ void Transport::notify(string _method, Json _message)
|
|||||||
|
|
||||||
void Transport::reply(MessageID _id, Json _message)
|
void Transport::reply(MessageID _id, Json _message)
|
||||||
{
|
{
|
||||||
Json json;
|
Json json{Json::object()};
|
||||||
json["result"] = std::move(_message);
|
json["result"] = std::move(_message);
|
||||||
send(std::move(json), _id);
|
send(std::move(json), _id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Transport::error(MessageID _id, ErrorCode _code, string _message)
|
void Transport::error(MessageID _id, ErrorCode _code, string _message)
|
||||||
{
|
{
|
||||||
Json json;
|
Json json{Json::object()};
|
||||||
json["error"]["code"] = static_cast<int>(_code);
|
json["error"]["code"] = static_cast<int>(_code);
|
||||||
json["error"]["message"] = std::move(_message);
|
json["error"]["message"] = std::move(_message);
|
||||||
send(std::move(json), _id);
|
send(std::move(json), _id);
|
||||||
|
Loading…
Reference in New Issue
Block a user