Skip to content

Commit

Permalink
Merge pull request #14493 from ethereum/purge-using-namespace-from-li…
Browse files Browse the repository at this point in the history
…bsolidity-lsp-parsing

Purge using namespace from libsolidity/lsp and parsing
  • Loading branch information
nikola-matic authored Aug 16, 2023
2 parents 8031be1 + f344dc1 commit 25fc3aa
Show file tree
Hide file tree
Showing 14 changed files with 210 additions and 220 deletions.
2 changes: 1 addition & 1 deletion libsolidity/interface/CompilerStack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1859,7 +1859,7 @@ Json::Value CompilerStack::gasEstimates(std::string const& _contractName) const
if (contract.fallbackFunction())
/// This needs to be set to an invalid signature in order to trigger the fallback,
/// without the shortcut (of CALLDATSIZE == 0), and therefore to receive the upper bound.
/// An empty std::string ("") would work to trigger the shortcut only.
/// An empty string ("") would work to trigger the shortcut only.
externalFunctions[""] = gasToJson(gasEstimator.functionalEstimation(*items, "INVALID"));

if (!externalFunctions.empty())
Expand Down
2 changes: 1 addition & 1 deletion libsolidity/interface/StandardCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ Json::Value formatLinkReferences(std::map<size_t, std::string> const& linkRefere
std::string const& fullname = ref.second;

// If the link reference does not contain a colon, assume that the file name is missing and
// the whole std::string represents the library name.
// the whole string represents the library name.
size_t colon = fullname.rfind(':');
std::string file = (colon != std::string::npos ? fullname.substr(0, colon) : "");
std::string name = (colon != std::string::npos ? fullname.substr(colon + 1) : fullname);
Expand Down
9 changes: 3 additions & 6 deletions libsolidity/lsp/DocumentHoverHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@

namespace solidity::lsp
{

using namespace std;

using namespace solidity::lsp;
using namespace solidity::langutil;
using namespace solidity::frontend;
Expand All @@ -35,16 +32,16 @@ namespace

struct MarkdownBuilder
{
stringstream result;
std::stringstream result;

MarkdownBuilder& solidityCode(string const& _code)
MarkdownBuilder& solidityCode(std::string const& _code)
{
auto constexpr SolidityLanguageId = "solidity";
result << "```" << SolidityLanguageId << '\n' << _code << "\n```\n\n";
return *this;
}

MarkdownBuilder& paragraph(string const& _text)
MarkdownBuilder& paragraph(std::string const& _text)
{
if (!_text.empty())
{
Expand Down
21 changes: 10 additions & 11 deletions libsolidity/lsp/FileRepository.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

#include <fmt/format.h>

using namespace std;
using namespace solidity;
using namespace solidity::lsp;
using namespace solidity::frontend;
Expand All @@ -54,11 +53,11 @@ void FileRepository::setIncludePaths(std::vector<boost::filesystem::path> _paths
m_includePaths = std::move(_paths);
}

string FileRepository::sourceUnitNameToUri(string const& _sourceUnitName) const
std::string FileRepository::sourceUnitNameToUri(std::string const& _sourceUnitName) const
{
regex const windowsDriveLetterPath("^[a-zA-Z]:/");
std::regex const windowsDriveLetterPath("^[a-zA-Z]:/");

auto const ensurePathIsUnixLike = [&](string inputPath) -> string {
auto const ensurePathIsUnixLike = [&](std::string inputPath) -> std::string {
if (!regex_search(inputPath, windowsDriveLetterPath))
return inputPath;
else
Expand Down Expand Up @@ -86,13 +85,13 @@ string FileRepository::sourceUnitNameToUri(string const& _sourceUnitName) const
return "file:///" + _sourceUnitName;
}

string FileRepository::uriToSourceUnitName(string const& _path) const
std::string FileRepository::uriToSourceUnitName(std::string const& _path) const
{
lspRequire(boost::algorithm::starts_with(_path, "file://"), ErrorCode::InternalError, "URI must start with file://");
return stripFileUriSchemePrefix(_path);
}

void FileRepository::setSourceByUri(string const& _uri, string _source)
void FileRepository::setSourceByUri(std::string const& _uri, std::string _source)
{
// This is needed for uris outside the base path. It can lead to collisions,
// but we need to mostly rewrite this in a future version anyway.
Expand All @@ -110,9 +109,9 @@ Result<boost::filesystem::path> FileRepository::tryResolvePath(std::string const
)
return boost::filesystem::path(_strippedSourceUnitName);

vector<boost::filesystem::path> candidates;
vector<reference_wrapper<boost::filesystem::path const>> prefixes = {m_basePath};
prefixes += (m_includePaths | ranges::to<vector<reference_wrapper<boost::filesystem::path const>>>);
std::vector<boost::filesystem::path> candidates;
std::vector<std::reference_wrapper<boost::filesystem::path const>> prefixes = {m_basePath};
prefixes += (m_includePaths | ranges::to<std::vector<std::reference_wrapper<boost::filesystem::path const>>>);
auto const defaultInclude = m_basePath / "node_modules";
if (m_includePaths.empty())
prefixes.emplace_back(defaultInclude);
Expand Down Expand Up @@ -148,7 +147,7 @@ Result<boost::filesystem::path> FileRepository::tryResolvePath(std::string const
return candidates[0];
}

frontend::ReadCallback::Result FileRepository::readFile(string const& _kind, string const& _sourceUnitName)
frontend::ReadCallback::Result FileRepository::readFile(std::string const& _kind, std::string const& _sourceUnitName)
{
solAssert(
_kind == ReadCallback::kindString(ReadCallback::Kind::ReadFile),
Expand All @@ -161,7 +160,7 @@ frontend::ReadCallback::Result FileRepository::readFile(string const& _kind, str
if (m_sourceCodes.count(_sourceUnitName))
return ReadCallback::Result{true, m_sourceCodes.at(_sourceUnitName)};

string const strippedSourceUnitName = stripFileUriSchemePrefix(_sourceUnitName);
std::string const strippedSourceUnitName = stripFileUriSchemePrefix(_sourceUnitName);
Result<boost::filesystem::path> const resolvedPath = tryResolvePath(strippedSourceUnitName);
if (!resolvedPath.message().empty())
return ReadCallback::Result{false, resolvedPath.message()};
Expand Down
5 changes: 2 additions & 3 deletions libsolidity/lsp/GotoDefinition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,14 @@
using namespace solidity::frontend;
using namespace solidity::langutil;
using namespace solidity::lsp;
using namespace std;

void GotoDefinition::operator()(MessageID _id, Json::Value const& _args)
{
auto const [sourceUnitName, lineColumn] = extractSourceUnitNameAndLineColumn(_args);

ASTNode const* sourceNode = m_server.astNodeAtSourceLocation(sourceUnitName, lineColumn);

vector<SourceLocation> locations;
std::vector<SourceLocation> locations;
if (auto const* expression = dynamic_cast<Expression const*>(sourceNode))
{
// Handles all expressions that can have one or more declaration annotation.
Expand All @@ -56,7 +55,7 @@ void GotoDefinition::operator()(MessageID _id, Json::Value const& _args)
{
auto const& path = *importDirective->annotation().absolutePath;
if (fileRepository().sourceUnits().count(path))
locations.emplace_back(SourceLocation{0, 0, make_shared<string const>(path)});
locations.emplace_back(SourceLocation{0, 0, std::make_shared<std::string const>(path)});
}

Json::Value reply = Json::arrayValue;
Expand Down
7 changes: 3 additions & 4 deletions libsolidity/lsp/HandlerBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
using namespace solidity::langutil;
using namespace solidity::lsp;
using namespace solidity::util;
using namespace std;

Json::Value HandlerBase::toRange(SourceLocation const& _location) const
{
Expand All @@ -52,10 +51,10 @@ Json::Value HandlerBase::toJson(SourceLocation const& _location) const
return item;
}

pair<string, LineColumn> HandlerBase::extractSourceUnitNameAndLineColumn(Json::Value const& _args) const
std::pair<std::string, LineColumn> HandlerBase::extractSourceUnitNameAndLineColumn(Json::Value const& _args) const
{
string const uri = _args["textDocument"]["uri"].asString();
string const sourceUnitName = fileRepository().uriToSourceUnitName(uri);
std::string const uri = _args["textDocument"]["uri"].asString();
std::string const sourceUnitName = fileRepository().uriToSourceUnitName(uri);
if (!fileRepository().sourceUnits().count(sourceUnitName))
BOOST_THROW_EXCEPTION(
RequestError(ErrorCode::RequestFailed) <<
Expand Down
Loading

0 comments on commit 25fc3aa

Please sign in to comment.