From 8b442eac0b767579d4d25c52f8f93e9713c54b95 Mon Sep 17 00:00:00 2001 From: caheckman <48068198+caheckman@users.noreply.github.com> Date: Thu, 5 Jan 2023 16:11:42 -0500 Subject: [PATCH] GP-2985 Remove "using namespace" directives --- .../src/decompile/cpp/architecture.cc | 1 + .../src/decompile/cpp/capability.hh | 3 +- .../src/decompile/cpp/consolemain.cc | 4 +++ .../Decompiler/src/decompile/cpp/error.hh | 30 +++++++++++++++++- .../src/decompile/cpp/filemanage.hh | 5 ++- .../Decompiler/src/decompile/cpp/float.cc | 26 +++++++++++----- .../src/decompile/cpp/ghidra_process.hh | 3 ++ .../Decompiler/src/decompile/cpp/interface.hh | 11 +++++-- .../Decompiler/src/decompile/cpp/marshal.hh | 3 +- .../Decompiler/src/decompile/cpp/opcodes.hh | 2 +- .../Decompiler/src/decompile/cpp/partmap.hh | 2 +- .../src/decompile/cpp/slgh_compile.hh | 4 +++ .../src/decompile/cpp/slghsymbol.cc | 1 + .../Decompiler/src/decompile/cpp/test.cc | 8 ++--- .../Decompiler/src/decompile/cpp/test.hh | 31 ++++++++++++------- .../src/decompile/cpp/testfunction.cc | 4 +-- .../src/decompile/cpp/testfunction.hh | 2 +- .../Decompiler/src/decompile/cpp/typeop.cc | 1 - .../Decompiler/src/decompile/cpp/xml.hh | 9 +++++- .../src/decompile/unittests/testfloatemu.cc | 19 +++++++----- 20 files changed, 127 insertions(+), 42 deletions(-) diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/architecture.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/architecture.cc index 2bd660889c..fdd607cc22 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/architecture.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/architecture.cc @@ -22,6 +22,7 @@ #endif #ifdef CPUI_STATISTICS #include +using std::sqrt; #endif vector ArchitectureCapability::thelist; diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/capability.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/capability.hh index 9ed07195d5..a4d58691d6 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/capability.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/capability.hh @@ -22,7 +22,8 @@ #include #include -using namespace std; +using std::vector; +using std::string; /// \brief Class for automatically registering extension points to the decompiler /// diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/consolemain.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/consolemain.cc index f40f3dd669..29d2bd63b7 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/consolemain.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/consolemain.cc @@ -16,6 +16,10 @@ #include #include +using std::cin; +using std::cout; +using std::cerr; + #include "libdecomp.hh" class IfcLoadFile : public IfaceDecompCommand { diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/error.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/error.hh index 788b2421d4..6cb1c11563 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/error.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/error.hh @@ -33,7 +33,35 @@ #include #include -using namespace std; +using std::string; +using std::map; +using std::set; +using std::list; +using std::vector; +using std::pair; +using std::make_pair; +using std::ostream; +using std::istream; +using std::ifstream; +using std::ofstream; +using std::istringstream; +using std::ostringstream; +using std::ios; +using std::dec; +using std::hex; +using std::oct; +using std::setfill; +using std::fixed; +using std::setprecision; +using std::setw; +using std::endl; +using std::ws; +using std::min; +using std::max; +using std::to_string; +using std::piecewise_construct; +using std::forward_as_tuple; + /// \brief The lowest level error generated by the decompiler /// diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/filemanage.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/filemanage.hh index 9cd6f4e8fa..9393802a48 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/filemanage.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/filemanage.hh @@ -24,7 +24,10 @@ #include #include -using namespace std; +using std::vector; +using std::string; +using std::ifstream; +using std::ostringstream; class FileManage { vector pathlist; // List of paths to search for files diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/float.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/float.cc index 068c7e991c..23bd6b385d 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/float.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/float.cc @@ -15,10 +15,20 @@ * limitations under the License. */ #include "float.hh" -#include -#include #include "address.hh" +#include +using std::ldexp; +using std::frexp; +using std::signbit; +using std::isnan; +using std::isinf; +using std::sqrt; +using std::floor; +using std::ceil; +using std::round; +using std::fabs; + /// Set format for a given encoding size according to IEEE 754 standards /// \param sz is the size of the encoding in bytes FloatFormat::FloatFormat(int4 sz) @@ -79,10 +89,10 @@ FloatFormat::floatclass FloatFormat::extractExpSig(double x,bool *sgn,uintb *sig { int4 e; - *sgn = std::signbit(x); + *sgn = signbit(x); if (x == 0.0) return zero; - if (std::isinf(x)) return infinity; - if (std::isnan(x)) return nan; + if (isinf(x)) return infinity; + if (isnan(x)) return nan; if (*sgn) x = -x; double norm = frexp(x,&e); // norm is between 1/2 and 1 @@ -232,11 +242,13 @@ double FloatFormat::getHostFloat(uintb encoding,floatclass *type) const else if (exp == maxexponent) { if ( frac == 0 ) { // Floating point infinity *type = infinity; - return sgn ? -INFINITY : +INFINITY; + double infinity = std::numeric_limits::infinity(); + return sgn ? -infinity : +infinity; } *type = nan; // encoding is "Not a Number" NaN - return sgn ? -NAN : +NAN; // Sign is usually ignored + double nan = std::numeric_limits::quiet_NaN(); + return sgn ? -nan : +nan; // Sign is usually ignored } else *type = normalized; diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/ghidra_process.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/ghidra_process.hh index 8c682d80dc..6ee255caa4 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/ghidra_process.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/ghidra_process.hh @@ -27,6 +27,9 @@ #include #include +using std::cin; +using std::cout; + class GhidraCommand; extern ElementId ELEM_DOC; ///< Marshaling element \ diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/interface.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/interface.hh index 0771e74289..03755410b7 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/interface.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/interface.hh @@ -20,14 +20,21 @@ #define __INTERFACE__ #include "capability.hh" -#include #include #include #include #include #include -using namespace std; +using std::map; +using std::istream; +using std::ostream; +using std::ifstream; +using std::ofstream; +using std::istringstream; +using std::endl; +using std::ws; +using std::ios_base; #ifdef __REMOTE_SOCKET__ diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/marshal.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/marshal.hh index a6cf0fb260..bdaa70e916 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/marshal.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/marshal.hh @@ -20,7 +20,8 @@ #include #include -using namespace std; +using std::list; +using std::unordered_map; /// \brief An annotation for a data element to being transferred to/from a stream /// diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/opcodes.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/opcodes.hh index 14ec997724..7c5cc64c54 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/opcodes.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/opcodes.hh @@ -21,7 +21,7 @@ #include -using namespace std; +using std::string; /// \brief The op-code defining a specific p-code operation (PcodeOp) /// diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/partmap.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/partmap.hh index 41abc55a0e..4573f4960a 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/partmap.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/partmap.hh @@ -199,7 +199,7 @@ template #if 0 #include -using namespace std; +using std::cout; int main(int argc,char **argv) diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/slgh_compile.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/slgh_compile.hh index e7ab191853..91e12244b4 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/slgh_compile.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/slgh_compile.hh @@ -22,6 +22,10 @@ #include #include +using std::cout; +using std::cerr; +using std::out_of_range; + /// \brief A helper class to associate a \e named Constructor section with its symbol scope /// /// A Constructor can contain multiple named sections of p-code. There is a \e main diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/slghsymbol.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/slghsymbol.cc index dbb8f9e51c..8516dbf107 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/slghsymbol.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/slghsymbol.cc @@ -16,6 +16,7 @@ #include "slghsymbol.hh" #include "sleighbase.hh" #include +using std::log; SleighSymbol *SymbolScope::addSymbol(SleighSymbol *a) diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/test.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/test.cc index 4d9b612d0e..e1b6a04c7e 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/test.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/test.cc @@ -32,17 +32,17 @@ int UnitTest::run(set &testNames) if (testNames.size() > 0 && testNames.find(t->name) == testNames.end()) { continue; } - std::cerr << "testing : " << t->name << " ..." << std::endl; + cerr << "testing : " << t->name << " ..." << endl; ++total; try { t->func(); ++passed; - std::cerr << " passed." << std::endl; + cerr << " passed." << endl; } catch(...) { } } - std::cerr << "==============================" << std::endl; - std::cerr << passed << "/" << total << " tests passed." << std::endl; + cerr << "==============================" << endl; + cerr << passed << "/" << total << " tests passed." << endl; return total - passed; } diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/test.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/test.hh index a138f511d0..b593db91fc 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/test.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/test.hh @@ -30,8 +30,17 @@ #include #include #include +#include #include +using std::vector; +using std::set; +using std::string; +using std::ostringstream; +using std::cout; +using std::cerr; +using std::endl; + typedef void (*testfunc_t)(); ///< A unit-test function /// \brief Simple unit test class @@ -40,21 +49,21 @@ typedef void (*testfunc_t)(); ///< A unit-test function /// The static run() method calls all the function pointers of all instantiated /// objects. struct UnitTest { - static std::vector tests; ///< The collection of test objects - std::string name; ///< Name of the test + static vector tests; ///< The collection of test objects + string name; ///< Name of the test testfunc_t func; ///< Call-back function executing the test /// \brief Constructor /// /// \param name is the identifier for the test /// \param func is a call-back function that executes the test - UnitTest(const std::string &name,testfunc_t func) : + UnitTest(const string &name,testfunc_t func) : name(name), func(func) { tests.push_back(this); } - static int run(std::set &testNames); ///< Run all the instantiated tests + static int run(set &testNames); ///< Run all the instantiated tests }; @@ -67,28 +76,28 @@ struct UnitTest { /// \brief Assert that a boolean is \b true for a unit test #define ASSERT(test) \ if (!(test)) { \ - std::cerr << " failed at " << __FILE__ << ":" << __LINE__ << " asserting \"" << #test << "\"." << std::endl; \ + cerr << " failed at " << __FILE__ << ":" << __LINE__ << " asserting \"" << #test << "\"." << endl; \ throw 0; \ } /// \brief Assert that two values are equal for a unit test #define ASSERT_EQUALS(a, b) \ if ((a) != (b)) { \ - std::stringstream ssa, ssb; \ + ostringstream ssa, ssb; \ ssa << (a); \ ssb << (b); \ - std::cerr << " failed at " << __FILE__ << ":" << __LINE__ << " asserting \"" << ssa.str() \ - << " == " << ssb.str() << "\"." << std::endl; \ + cerr << " failed at " << __FILE__ << ":" << __LINE__ << " asserting \"" << ssa.str() \ + << " == " << ssb.str() << "\"." << endl; \ throw 0; \ } /// \brief Assert that two values are not equal for a unit test #define ASSERT_NOT_EQUALS(a, b) \ if ((a) == (b)) { \ - std::stringstream ssa, ssb; \ + ostringstream ssa, ssb; \ ssa << (a); \ ssb << (b); \ - std::cerr << " failed at " << __FILE__ << ":" << __LINE__ << " asserting \"" << ssa.str() \ - << " != " << ssb.str() << "\"." << std::endl; \ + cerr << " failed at " << __FILE__ << ":" << __LINE__ << " asserting \"" << ssa.str() \ + << " != " << ssb.str() << "\"." << endl; \ throw 0; \ } diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/testfunction.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/testfunction.cc index 4f7110bb41..38137ffd43 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/testfunction.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/testfunction.cc @@ -24,7 +24,7 @@ void FunctionTestProperty::startTest(void) const void FunctionTestProperty::processLine(const string &line) const { - if (regex_search(line,pattern)) + if (std::regex_search(line,pattern)) count += 1; } @@ -42,7 +42,7 @@ void FunctionTestProperty::restoreXml(const Element *el) s1 >> minimumMatch; istringstream s2(el->getAttributeValue("max")); s2 >> maximumMatch; - pattern = regex(el->getContent()); + pattern = std::regex(el->getContent()); } void ConsoleCommands::readLine(string &line) diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/testfunction.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/testfunction.hh index 46abd6bce8..43801047a4 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/testfunction.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/testfunction.hh @@ -34,7 +34,7 @@ class FunctionTestProperty { int4 minimumMatch; ///< Minimum number of times property is expected to match int4 maximumMatch; ///< Maximum number of times property is expected to match string name; ///< Name of the test, to be printed in test summaries - regex pattern; ///< Regular expression to match against a line of output + std::regex pattern; ///< Regular expression to match against a line of output mutable uint4 count; ///< Number of times regular expression has been seen public: string getName(void) const { return name; } ///< Get the name of the property diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/typeop.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/typeop.cc index 0a00521f77..704950e036 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/typeop.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/typeop.cc @@ -15,7 +15,6 @@ */ #include "typeop.hh" #include "funcdata.hh" -#include /// \param inst will hold the array of TypeOp objects, indexed on op-code /// \param tlst is the corresponding TypeFactory for the Architecture diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/xml.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/xml.hh index a1c763a3e0..21884553cd 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/xml.hh +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/xml.hh @@ -25,7 +25,14 @@ #include #include -using namespace std; +using std::string; +using std::vector; +using std::map; +using std::istream; +using std::ostream; +using std::ifstream; +using std::dec; +using std::hex; /// \brief The \e attributes for a single XML element /// diff --git a/Ghidra/Features/Decompiler/src/decompile/unittests/testfloatemu.cc b/Ghidra/Features/Decompiler/src/decompile/unittests/testfloatemu.cc index ab99382a3c..f88b4d0002 100644 --- a/Ghidra/Features/Decompiler/src/decompile/unittests/testfloatemu.cc +++ b/Ghidra/Features/Decompiler/src/decompile/unittests/testfloatemu.cc @@ -25,7 +25,12 @@ #include #include -#include +using std::isnan; +using std::sqrt; +using std::floor; +using std::ceil; +using std::round; +using std::abs; // utility functions float floatFromRawBits(uintb e) { @@ -75,7 +80,7 @@ uintb doubleToRawBits(double f) { //// FloatFormat tests -static std::vector float_test_values{ +static vector float_test_values{ -0.0f, +0.0f, -1.0f, @@ -103,7 +108,7 @@ static std::vector float_test_values{ std::numeric_limits::infinity() }; -static std::vector int_test_values = { +static vector int_test_values = { 0, -1, 1, 1234, -1234, std::numeric_limits::min(), std::numeric_limits::max() }; @@ -256,7 +261,7 @@ TEST(float_opSqrt) { FloatFormat format(4); for(float f:float_test_values) { - uintb true_result = floatToRawBits(sqrtf(f)); + uintb true_result = floatToRawBits(sqrt(f)); uintb encoding = format.getEncoding(f); uintb result = format.opSqrt(encoding); @@ -269,7 +274,7 @@ TEST(float_opCeil) { FloatFormat format(4); for(float f:float_test_values) { - uintb true_result = floatToRawBits(ceilf(f)); + uintb true_result = floatToRawBits(ceil(f)); uintb encoding = format.getEncoding(f); uintb result = format.opCeil(encoding); @@ -282,7 +287,7 @@ TEST(float_opFloor) { FloatFormat format(4); for(float f:float_test_values) { - uintb true_result = floatToRawBits(floorf(f)); + uintb true_result = floatToRawBits(floor(f)); uintb encoding = format.getEncoding(f); uintb result = format.opFloor(encoding); @@ -295,7 +300,7 @@ TEST(float_opRound) { FloatFormat format(4); for(float f:float_test_values) { - uintb true_result = floatToRawBits(roundf(f)); + uintb true_result = floatToRawBits(round(f)); uintb encoding = format.getEncoding(f); uintb result = format.opRound(encoding);