Merge pull request #12746 from tfire/fix/remove-namespace-ast-annotations

Remove use of `using namespace` in header file
This commit is contained in:
Daniel Kirchner
2022-03-11 12:49:13 +01:00
committed by GitHub
39 changed files with 123 additions and 121 deletions
+16 -18
View File
@@ -42,11 +42,10 @@ namespace
int parseUnsignedInteger(string::iterator& _it, string::iterator _end)
{
auto isDigit = [](char _c) -> bool {return isdigit(_c, std::locale::classic());};
if (_it == _end || !isDigit(*_it))
if (_it == _end || !util::isDigit(*_it))
BOOST_THROW_EXCEPTION(runtime_error("Invalid test expectation. Source location expected."));
int result = 0;
while (_it != _end && isDigit(*_it))
while (_it != _end && util::isDigit(*_it))
{
result *= 10;
result += *_it - '0';
@@ -84,9 +83,9 @@ TestCase::TestResult CommonSyntaxTest::conclude(ostream& _stream, string const&
void CommonSyntaxTest::printExpectationAndError(ostream& _stream, string const& _linePrefix, bool _formatted)
{
string nextIndentLevel = _linePrefix + " ";
AnsiColorized(_stream, _formatted, {BOLD, CYAN}) << _linePrefix << "Expected result:" << endl;
util::AnsiColorized(_stream, _formatted, {BOLD, CYAN}) << _linePrefix << "Expected result:" << endl;
printErrorList(_stream, m_expectations, nextIndentLevel, _formatted);
AnsiColorized(_stream, _formatted, {BOLD, CYAN}) << _linePrefix << "Obtained result:" << endl;
util::AnsiColorized(_stream, _formatted, {BOLD, CYAN}) << _linePrefix << "Obtained result:" << endl;
printErrorList(_stream, m_errorList, nextIndentLevel, _formatted);
}
@@ -105,8 +104,8 @@ void CommonSyntaxTest::printSource(ostream& _stream, string const& _linePrefix,
continue;
if (outputSourceNames)
_stream << _linePrefix << formatting::CYAN << "==== Source: " << name << " ====" << formatting::RESET << endl;
vector<char const*> sourceFormatting(source.length(), formatting::RESET);
_stream << _linePrefix << util::formatting::CYAN << "==== Source: " << name << " ====" << util::formatting::RESET << endl;
vector<char const*> sourceFormatting(source.length(), util::formatting::RESET);
for (auto const& error: m_errorList)
if (error.sourceName == name && error.locationStart >= 0 && error.locationEnd >= 0)
{
@@ -116,11 +115,11 @@ void CommonSyntaxTest::printSource(ostream& _stream, string const& _linePrefix,
for (int i = error.locationStart; i < error.locationEnd; i++)
if (isWarning)
{
if (sourceFormatting[static_cast<size_t>(i)] == formatting::RESET)
sourceFormatting[static_cast<size_t>(i)] = formatting::ORANGE_BACKGROUND_256;
if (sourceFormatting[static_cast<size_t>(i)] == util::formatting::RESET)
sourceFormatting[static_cast<size_t>(i)] = util::formatting::ORANGE_BACKGROUND_256;
}
else
sourceFormatting[static_cast<size_t>(i)] = formatting::RED_BACKGROUND;
sourceFormatting[static_cast<size_t>(i)] = util::formatting::RED_BACKGROUND;
}
_stream << _linePrefix << sourceFormatting.front() << source.front();
@@ -132,12 +131,12 @@ void CommonSyntaxTest::printSource(ostream& _stream, string const& _linePrefix,
_stream << source[i];
else
{
_stream << formatting::RESET << endl;
_stream << util::formatting::RESET << endl;
if (i + 1 < source.length())
_stream << _linePrefix << sourceFormatting[i];
}
}
_stream << formatting::RESET;
_stream << util::formatting::RESET;
}
else
{
@@ -158,12 +157,12 @@ void CommonSyntaxTest::printErrorList(
)
{
if (_errorList.empty())
AnsiColorized(_stream, _formatted, {BOLD, GREEN}) << _linePrefix << "Success" << endl;
util::AnsiColorized(_stream, _formatted, {BOLD, GREEN}) << _linePrefix << "Success" << endl;
else
for (auto const& error: _errorList)
{
{
AnsiColorized scope(_stream, _formatted, {BOLD, (error.type == "Warning") ? YELLOW : RED});
util::AnsiColorized scope(_stream, _formatted, {BOLD, (error.type == "Warning") ? YELLOW : RED});
_stream << _linePrefix << error.type;
if (error.errorId.has_value())
_stream << ' ' << error.errorId->error;
@@ -185,7 +184,7 @@ void CommonSyntaxTest::printErrorList(
}
}
string CommonSyntaxTest::errorMessage(Exception const& _e)
string CommonSyntaxTest::errorMessage(util::Exception const& _e)
{
if (_e.comment() && !_e.comment()->empty())
return boost::replace_all_copy(*_e.comment(), "\n", "\\n");
@@ -195,7 +194,6 @@ string CommonSyntaxTest::errorMessage(Exception const& _e)
vector<SyntaxTestError> CommonSyntaxTest::parseExpectations(istream& _stream)
{
auto isDigit = [](char _c) -> bool {return isdigit(_c, std::locale::classic());};
vector<SyntaxTestError> expectations;
string line;
while (getline(_stream, line))
@@ -215,7 +213,7 @@ vector<SyntaxTestError> CommonSyntaxTest::parseExpectations(istream& _stream)
skipWhitespace(it, line.end());
optional<ErrorId> errorId;
if (it != line.end() && isDigit(*it))
if (it != line.end() && util::isDigit(*it))
errorId = ErrorId{static_cast<unsigned long long>(parseUnsignedInteger(it, line.end()))};
expect(it, line.end(), ':');
@@ -228,7 +226,7 @@ vector<SyntaxTestError> CommonSyntaxTest::parseExpectations(istream& _stream)
if (it != line.end() && *it == '(')
{
++it;
if (it != line.end() && !isDigit(*it))
if (it != line.end() && !util::isDigit(*it))
{
auto sourceNameStart = it;
while (it != line.end() && *it != ':')
+4 -4
View File
@@ -70,10 +70,10 @@ SemanticTest::SemanticTest(
static set<string> const legacyRunTriggers{"also", "false", "default"};
string compileViaYul = m_reader.stringSetting("compileViaYul", "default");
if (!contains(compileViaYulAllowedValues, compileViaYul))
if (!util::contains(compileViaYulAllowedValues, compileViaYul))
BOOST_THROW_EXCEPTION(runtime_error("Invalid compileViaYul value: " + compileViaYul + "."));
m_testCaseWantsYulRun = contains(yulRunTriggers, compileViaYul);
m_testCaseWantsLegacyRun = contains(legacyRunTriggers, compileViaYul);
m_testCaseWantsYulRun = util::contains(yulRunTriggers, compileViaYul);
m_testCaseWantsLegacyRun = util::contains(legacyRunTriggers, compileViaYul);
// Do not enforce via yul and ewasm, if via yul was explicitly denied.
if (compileViaYul == "false")
@@ -189,7 +189,7 @@ vector<SideEffectHook> SemanticTest::makeSideEffectHooks() const
{
vector<string> result;
for (auto const& argument: _call.arguments.parameters)
result.emplace_back(toHex(argument.rawBytes));
result.emplace_back(util::toHex(argument.rawBytes));
return result;
}
return {};
+2 -2
View File
@@ -4102,12 +4102,12 @@ BOOST_AUTO_TEST_CASE(strip_reason_strings)
m_optimiserSettings == OptimiserSettings::none()
)
// check that the reason string IS part of the binary.
BOOST_CHECK(toHex(m_output).find("736f6d6520726561736f6e") != std::string::npos);
BOOST_CHECK(util::toHex(m_output).find("736f6d6520726561736f6e") != std::string::npos);
m_revertStrings = RevertStrings::Strip;
compileAndRun(sourceCode, 0, "C");
// check that the reason string is NOT part of the binary.
BOOST_CHECK(toHex(m_output).find("736f6d6520726561736f6e") == std::string::npos);
BOOST_CHECK(util::toHex(m_output).find("736f6d6520726561736f6e") == std::string::npos);
ABI_CHECK(callContractFunction("f(bool)", true), encodeArgs(7));
ABI_CHECK(callContractFunction("f(bool)", false), encodeArgs());
@@ -350,7 +350,7 @@ BOOST_AUTO_TEST_CASE(arithmetic)
uint8_t(Instruction::JUMPDEST),
uint8_t(Instruction::PUSH32)
} +
fromHex("4E487B7100000000000000000000000000000000000000000000000000000000") +
util::fromHex("4E487B7100000000000000000000000000000000000000000000000000000000") +
bytes{
uint8_t(Instruction::PUSH1), 0x0,
uint8_t(Instruction::MSTORE),
+2 -2
View File
@@ -98,8 +98,8 @@ public:
BOOST_CHECK_MESSAGE(!optimizedOutput.empty(), "No optimized output for " + _sig);
BOOST_CHECK_MESSAGE(!nonOptimizedOutput.empty(), "No un-optimized output for " + _sig);
BOOST_CHECK_MESSAGE(nonOptimizedOutput == optimizedOutput, "Computed values do not match."
"\nNon-Optimized: " + toHex(nonOptimizedOutput) +
"\nOptimized: " + toHex(optimizedOutput));
"\nNon-Optimized: " + util::toHex(nonOptimizedOutput) +
"\nOptimized: " + util::toHex(optimizedOutput));
}
/// @returns the number of instructions in the given bytecode, not taking the metadata hash
@@ -47,6 +47,7 @@
#include <vector>
using namespace std;
using namespace solidity::util;
using namespace solidity::langutil;
using namespace solidity::frontend;
+1 -1
View File
@@ -220,7 +220,7 @@ string BytesUtils::formatString(bytes const& _bytes, size_t _cutOff)
if (isPrint(static_cast<char>(v)))
os << v;
else
os << "\\x" << toHex(v, HexCase::Lower);
os << "\\x" << util::toHex(v, HexCase::Lower);
}
}
os << "\"";
+4 -1
View File
@@ -16,6 +16,9 @@
*/
// SPDX-License-Identifier: GPL-3.0
#include <libsolutil/StringUtils.h>
#include <test/libsolidity/util/TestFileParser.h>
#include <test/libsolidity/util/BytesUtils.h>
@@ -34,6 +37,7 @@
#include <stdexcept>
using namespace solidity;
using namespace solidity::util;
using namespace solidity::frontend;
using namespace solidity::frontend::test;
using namespace std;
@@ -763,7 +767,6 @@ string TestFileParser::Scanner::scanString()
char TestFileParser::Scanner::scanHexPart()
{
auto toLower = [](char _c) -> char { return tolower(_c, locale::classic()); };
auto isDigit = [](char _c) -> bool { return isdigit(_c, locale::classic()); };
advance(); // skip 'x'
+1 -1
View File
@@ -324,7 +324,7 @@ string TestFunctionCall::formatRawParameters(
for (auto const c: param.rawString)
// NOTE: Even though we have a toHex() overload specifically for uint8_t, the compiler
// chooses the one for bytes if the second argument is omitted.
os << (c >= ' ' ? string(1, c) : "\\x" + toHex(static_cast<uint8_t>(c), HexCase::Lower));
os << (c >= ' ' ? string(1, c) : "\\x" + util::toHex(static_cast<uint8_t>(c), HexCase::Lower));
if (&param != &_params.back())
os << ", ";
}
+1
View File
@@ -43,6 +43,7 @@
using namespace std;
using namespace solidity::frontend;
using namespace solidity::test;
using namespace solidity::util;
using PathSet = set<boost::filesystem::path>;