From 63a083b47b887a2e1ef9eb69f3fff04301830dd1 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Thu, 13 Nov 2014 10:13:51 -0700 Subject: [PATCH] Remove uses of std::endl, which imply a flush --- include/chaiscript/dispatchkit/bootstrap.hpp | 2 +- include/chaiscript/dispatchkit/boxed_cast.hpp | 4 +- .../chaiscript/dispatchkit/dispatchkit.hpp | 14 +++---- .../dispatchkit/type_conversions.hpp | 4 -- .../chaiscript/language/chaiscript_common.hpp | 16 +++---- .../chaiscript/language/chaiscript_engine.hpp | 4 +- .../chaiscript/language/chaiscript_parser.hpp | 2 +- samples/example.cpp | 16 +++---- samples/memory_leak_test.cpp | 2 +- src/main.cpp | 42 +++++++++---------- unittests/boxed_cast_test.cpp | 16 +++---- unittests/dynamic_object_test.cpp | 2 +- unittests/eval_catch_exception_test.cpp | 26 ++++++------ unittests/integer_literal_test.cpp | 2 +- unittests/type_info_test.cpp | 2 +- 15 files changed, 75 insertions(+), 79 deletions(-) diff --git a/include/chaiscript/dispatchkit/bootstrap.hpp b/include/chaiscript/dispatchkit/bootstrap.hpp index 98648da..55e0271 100644 --- a/include/chaiscript/dispatchkit/bootstrap.hpp +++ b/include/chaiscript/dispatchkit/bootstrap.hpp @@ -207,7 +207,7 @@ namespace chaiscript static void println(const std::string &s) { - std::cout << s << std::endl; + std::cout << s << '\n'; } diff --git a/include/chaiscript/dispatchkit/boxed_cast.hpp b/include/chaiscript/dispatchkit/boxed_cast.hpp index 1fc5755..1d11d6e 100644 --- a/include/chaiscript/dispatchkit/boxed_cast.hpp +++ b/include/chaiscript/dispatchkit/boxed_cast.hpp @@ -89,13 +89,13 @@ namespace chaiscript if (t_conversions && t_conversions->convertable_type()) { try { - // std::cout << "trying an up conversion " << typeid(Type).name() << std::endl; + // std::cout << "trying an up conversion " << typeid(Type).name() << '\n'; // We will not catch any bad_boxed_dynamic_cast that is thrown, let the user get it // either way, we are not responsible if it doesn't work return detail::Cast_Helper::cast(t_conversions->boxed_type_conversion(bv), t_conversions); } catch (...) { try { - // std::cout << "trying a down conversion " << typeid(Type).name() << std::endl; + // std::cout << "trying a down conversion " << typeid(Type).name() << '\n'; // try going the other way - down the inheritance graph return detail::Cast_Helper::cast(t_conversions->boxed_type_down_conversion(bv), t_conversions); } catch (const chaiscript::detail::exception::bad_any_cast &) { diff --git a/include/chaiscript/dispatchkit/dispatchkit.hpp b/include/chaiscript/dispatchkit/dispatchkit.hpp index 9d78507..6428677 100644 --- a/include/chaiscript/dispatchkit/dispatchkit.hpp +++ b/include/chaiscript/dispatchkit/dispatchkit.hpp @@ -796,7 +796,7 @@ namespace chaiscript /// Dump object info to stdout void dump_object(const Boxed_Value &o) const { - std::cout << (o.is_const()?"const ":"") << type_name(o) << std::endl; + std::cout << (o.is_const()?"const ":"") << type_name(o) << '\n'; } /// Dump type info to stdout @@ -830,7 +830,7 @@ namespace chaiscript } } - std::cout << ") " << std::endl; + std::cout << ") \n"; } /// Returns true if a call can be made that consists of the first parameter @@ -850,7 +850,7 @@ namespace chaiscript /// Dump all system info to stdout void dump_system() const { - std::cout << "Registered Types: " << std::endl; + std::cout << "Registered Types: \n"; std::vector > types = get_types(); for (std::vector >::const_iterator itr = types.begin(); itr != types.end(); @@ -858,20 +858,20 @@ namespace chaiscript { std::cout << itr->first << ": "; std::cout << itr->second.bare_name(); - std::cout << std::endl; + std::cout << '\n'; } - std::cout << std::endl; + std::cout << '\n'; std::vector > funcs = get_functions(); - std::cout << "Functions: " << std::endl; + std::cout << "Functions: \n"; for (std::vector >::const_iterator itr = funcs.begin(); itr != funcs.end(); ++itr) { dump_function(*itr); } - std::cout << std::endl; + std::cout << '\n'; } /// return true if the Boxed_Value matches the registered type by name diff --git a/include/chaiscript/dispatchkit/type_conversions.hpp b/include/chaiscript/dispatchkit/type_conversions.hpp index b238b97..59ad5e3 100644 --- a/include/chaiscript/dispatchkit/type_conversions.hpp +++ b/include/chaiscript/dispatchkit/type_conversions.hpp @@ -429,11 +429,7 @@ namespace chaiscript static_assert(std::is_convertible::value, "Types are not automatically convertible"); auto func = [](const Boxed_Value &t_bv) -> Boxed_Value { // not even attempting to call boxed_cast so that we don't get caught in some call recursion - std::cout << " Type conversion to : " << typeid(To).name() << " from " << typeid(From).name() << std::endl; auto &&from = detail::Cast_Helper::cast(t_bv, nullptr); - std::cout << "Ptr" << static_cast(from) << std::endl; - std::cout << "Ptr" << from << std::endl; - To to(from); return chaiscript::Boxed_Value(to); }; diff --git a/include/chaiscript/language/chaiscript_common.hpp b/include/chaiscript/language/chaiscript_common.hpp index d15c2d9..393c248 100644 --- a/include/chaiscript/language/chaiscript_common.hpp +++ b/include/chaiscript/language/chaiscript_common.hpp @@ -118,19 +118,19 @@ namespace chaiscript ss << what(); if (call_stack.size() > 0) { - ss << "during evaluation at (" << fname(call_stack[0]) << " " << startpos(call_stack[0]) << ")" << std::endl; - ss << std::endl << detail << std::endl; + ss << "during evaluation at (" << fname(call_stack[0]) << " " << startpos(call_stack[0]) << ")\n"; + ss << '\n' << detail << '\n'; ss << " " << fname(call_stack[0]) << " (" << startpos(call_stack[0]) << ") '" << pretty(call_stack[0]) << "'"; for (size_t j = 1; j < call_stack.size(); ++j) { if (id(call_stack[j]) != chaiscript::AST_Node_Type::Block && id(call_stack[j]) != chaiscript::AST_Node_Type::File) { - ss << std::endl; + ss << '\n'; ss << " from " << fname(call_stack[j]) << " (" << startpos(call_stack[j]) << ") '" << pretty(call_stack[j]) << "'"; } } } - ss << std::endl; + ss << '\n'; return ss.str(); } @@ -264,13 +264,13 @@ namespace chaiscript std::stringstream ss; if (t_functions.size() == 1) { - ss << " Expected: " << format_types(t_functions[0], t_dot_notation, t_ss) << std::endl; + ss << " Expected: " << format_types(t_functions[0], t_dot_notation, t_ss) << '\n'; } else { - ss << " " << t_functions.size() << " overloads available:" << std::endl; + ss << " " << t_functions.size() << " overloads available:\n"; for (const auto & t_function : t_functions) { - ss << " " << format_types((t_function), t_dot_notation, t_ss) << std::endl; + ss << " " << format_types((t_function), t_dot_notation, t_ss) << '\n'; } } @@ -430,7 +430,7 @@ namespace chaiscript std::ostringstream oss; oss << t_prepend << "(" << ast_node_type_to_string(this->identifier) << ") " - << this->text << " : " << this->start.line << ", " << this->start.column << std::endl; + << this->text << " : " << this->start.line << ", " << this->start.column << '\n'; for (size_t j = 0; j < this->children.size(); ++j) { oss << this->children[j]->to_string(t_prepend + " "); diff --git a/include/chaiscript/language/chaiscript_engine.hpp b/include/chaiscript/language/chaiscript_engine.hpp index b5393c5..523f49f 100644 --- a/include/chaiscript/language/chaiscript_engine.hpp +++ b/include/chaiscript/language/chaiscript_engine.hpp @@ -735,11 +735,11 @@ namespace chaiscript { try { const auto name = elem + prefix + t_module_name + postfix; - // std::cerr << "trying location: " << name << std::endl; + // std::cerr << "trying location: " << name << '\n'; load_module(version_stripped_name, name); return name; } catch (const chaiscript::exception::load_module_error &e) { - // std::cerr << "error: " << e.what() << std::endl; + // std::cerr << "error: " << e.what() << '\n'; errors.push_back(e); // Try next set } diff --git a/include/chaiscript/language/chaiscript_parser.hpp b/include/chaiscript/language/chaiscript_parser.hpp index 482d653..f61d624 100644 --- a/include/chaiscript/language/chaiscript_parser.hpp +++ b/include/chaiscript/language/chaiscript_parser.hpp @@ -171,7 +171,7 @@ namespace chaiscript /// Prints the parsed ast_nodes as a tree /* void debug_print(AST_NodePtr t, std::string prepend = "") { - std::cout << prepend << "(" << ast_node_type_to_string(t->identifier) << ") " << t->text << " : " << t->start.line << ", " << t->start.column << std::endl; + std::cout << prepend << "(" << ast_node_type_to_string(t->identifier) << ") " << t->text << " : " << t->start.line << ", " << t->start.column << '\n'; for (unsigned int j = 0; j < t->children.size(); ++j) { debug_print(t->children[j], prepend + " "); } diff --git a/samples/example.cpp b/samples/example.cpp index 797a5ee..6fc73db 100644 --- a/samples/example.cpp +++ b/samples/example.cpp @@ -13,12 +13,12 @@ void log(const std::string &msg) { - std::cout << "[" << time(nullptr) << "] " << msg << std::endl; + std::cout << "[" << time(nullptr) << "] " << msg << '\n'; } void log(const std::string &module, const std::string &msg) { - std::cout << "[" << time(nullptr) << "] <" << module << "> " << msg << std::endl; + std::cout << "[" << time(nullptr) << "] <" << module << "> " << msg << '\n'; } void bound_log(const std::string &msg) @@ -28,12 +28,12 @@ void bound_log(const std::string &msg) void hello_world(const chaiscript::Boxed_Value & /*o*/) { - std::cout << "Hello World" << std::endl; + std::cout << "Hello World\n"; } void hello_constructor(const chaiscript::Boxed_Value & /*o*/) { - std::cout << "Hello Constructor" << std::endl; + std::cout << "Hello Constructor\n"; } @@ -62,7 +62,7 @@ struct System void take_shared_ptr(const std::shared_ptr &p) { - std::cout << *p << std::endl; + std::cout << *p << '\n'; } int main(int /*argc*/, char * /*argv*/[]) { @@ -122,7 +122,7 @@ int main(int /*argc*/, char * /*argv*/[]) { //the templated version of eval: int i = chai.eval("5+5"); - std::cout << "5+5: " << i << std::endl; + std::cout << "5+5: " << i << '\n'; //Add a new variable chai("var scripti = 15"); @@ -130,9 +130,9 @@ int main(int /*argc*/, char * /*argv*/[]) { //We can even get a handle to the variables in the system int &scripti = chai.eval("scripti"); - std::cout << "scripti: " << scripti << std::endl; + std::cout << "scripti: " << scripti << '\n'; scripti *= 2; - std::cout << "scripti (updated): " << scripti << std::endl; + std::cout << "scripti (updated): " << scripti << '\n'; chai("print(\"Scripti from chai: \" + to_string(scripti))"); //To do: Add examples of handling Boxed_Values directly when needed diff --git a/samples/memory_leak_test.cpp b/samples/memory_leak_test.cpp index fb58003..13afbb4 100644 --- a/samples/memory_leak_test.cpp +++ b/samples/memory_leak_test.cpp @@ -54,7 +54,7 @@ class test chaiscript::Boxed_Value val = chai.eval_file(sFile); } catch (std::exception &e) { - std::cout << e.what() << std::endl; + std::cout << e.what() << '\n'; } } diff --git a/src/main.cpp b/src/main.cpp index a3735f8..dead221 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -136,24 +136,24 @@ std::vector default_search_paths() void help(int n) { if ( n >= 0 ) { - std::cout << "ChaiScript evaluator. To evaluate an expression, type it and press ." << std::endl; - std::cout << "Additionally, you can inspect the runtime system using:" << std::endl; - std::cout << " dump_system() - outputs all functions registered to the system" << std::endl; - std::cout << " dump_object(x) - dumps information about the given symbol" << std::endl; + std::cout << "ChaiScript evaluator. To evaluate an expression, type it and press .\n"; + std::cout << "Additionally, you can inspect the runtime system using:\n"; + std::cout << " dump_system() - outputs all functions registered to the system\n"; + std::cout << " dump_object(x) - dumps information about the given symbol\n"; } else { - std::cout << "usage : chai [option]+" << std::endl; - std::cout << "option:" << std::endl; - std::cout << " -h | --help" << std::endl; - std::cout << " -i | --interactive" << std::endl; - std::cout << " -c | --command cmd" << std::endl; - std::cout << " -v | --version" << std::endl; - std::cout << " - --stdin" << std::endl; - std::cout << " filepath" << std::endl; + std::cout << "usage : chai [option]+\n"; + std::cout << "option:" << '\n'; + std::cout << " -h | --help" << '\n'; + std::cout << " -i | --interactive" << '\n'; + std::cout << " -c | --command cmd" << '\n'; + std::cout << " -v | --version" << '\n'; + std::cout << " - --stdin" << '\n'; + std::cout << " filepath" << '\n'; } } void version(int){ - std::cout << "chai: compiled " << __TIME__ << " " << __DATE__ << std::endl; + std::cout << "chai: compiled " << __TIME__ << " " << __DATE__ << '\n'; } bool throws_exception(const std::function &f) @@ -231,7 +231,7 @@ void interactive(chaiscript::ChaiScript& chai) //Then, we try to print the result of the evaluation to the user if (!val.get_type_info().bare_equal(chaiscript::user_type())) { try { - std::cout << chai.eval >("to_string")(val) << std::endl; + std::cout << chai.eval >("to_string")(val) << '\n'; } catch (...) {} //If we can't, do nothing } @@ -241,11 +241,11 @@ void interactive(chaiscript::ChaiScript& chai) if (ee.call_stack.size() > 0) { std::cout << "during evaluation at (" << ee.call_stack[0]->start.line << ", " << ee.call_stack[0]->start.column << ")"; } - std::cout << std::endl; + std::cout << '\n'; } catch (const std::exception &e) { std::cout << e.what(); - std::cout << std::endl; + std::cout << '\n'; } } } @@ -305,7 +305,7 @@ int main(int argc, char *argv[]) if ( arg == "-c" || arg == "--command" ) { if ( (i+1) >= argc ) { - std::cout << "insufficient input following " << arg << std::endl; + std::cout << "insufficient input following " << arg << '\n'; return EXIT_FAILURE; } else { arg = argv[++i]; @@ -323,7 +323,7 @@ int main(int argc, char *argv[]) } else if ( arg == "-i" || arg == "--interactive" ) { mode = eInteractive ; } else if ( arg.find('-') == 0 ) { - std::cout << "unrecognised argument " << arg << std::endl; + std::cout << "unrecognised argument " << arg << '\n'; return EXIT_FAILURE; } else { mode = eFile; @@ -335,16 +335,16 @@ int main(int argc, char *argv[]) case eInteractive : interactive(chai); break; case eCommand : val = chai.eval(arg); break; case eFile : val = chai.eval_file(arg); break; - default : std::cout << "Unrecognized execution mode" << std::endl; return EXIT_FAILURE; + default : std::cout << "Unrecognized execution mode\n"; return EXIT_FAILURE; } } catch (const chaiscript::exception::eval_error &ee) { std::cout << ee.pretty_print(); - std::cout << std::endl; + std::cout << '\n'; return EXIT_FAILURE; } catch (std::exception &e) { - std::cout << e.what() << std::endl; + std::cout << e.what() << '\n'; return EXIT_FAILURE; } } diff --git a/unittests/boxed_cast_test.cpp b/unittests/boxed_cast_test.cpp index c398b7b..4e94471 100644 --- a/unittests/boxed_cast_test.cpp +++ b/unittests/boxed_cast_test.cpp @@ -15,16 +15,16 @@ bool run_test_type_conversion(const Boxed_Value &bv, bool expectedpass) use(ret); } catch (const chaiscript::exception::bad_boxed_cast &/*e*/) { if (expectedpass) { -// std::cerr << "Failure in run_test_type_conversion: " << e.what() << std::endl; +// std::cerr << "Failure in run_test_type_conversion: " << e.what() << '\n'; return false; } else { return true; } } catch (const std::exception &e) { - std::cerr << "Unexpected standard exception when attempting cast_conversion: " << e.what() << std::endl; + std::cerr << "Unexpected standard exception when attempting cast_conversion: " << e.what() << '\n'; return false; } catch (...) { - std::cerr << "Unexpected unknown exception when attempting cast_conversion." << std::endl; + std::cerr << "Unexpected unknown exception when attempting cast_conversion.\n"; return false; } @@ -47,7 +47,7 @@ bool test_type_conversion(const Boxed_Value &bv, bool expectedpass) << (bv.is_const()?(std::string("const ")):(std::string())) << bv.get_type_info().name() << " To: " << (std::is_const::value?(std::string("const ")):(std::string())) << typeid(To).name() - << " test was expected to " << ((expectedpass)?(std::string("succeed")):(std::string("fail"))) << " but did not" << std::endl; + << " test was expected to " << ((expectedpass)?(std::string("succeed")):(std::string("fail"))) << " but did not\n"; } return ret; @@ -264,21 +264,21 @@ bool pointer_test(const T& default_value, const T& new_value) if (p != (*result) ) { - std::cerr << "Pointer passed in different than one returned" << std::endl; + std::cerr << "Pointer passed in different than one returned\n"; return false; } if (*p != *(*result) ) { - std::cerr << "Somehow dereferenced pointer values are not the same?" << std::endl; + std::cerr << "Somehow dereferenced pointer values are not the same?\n"; return false; } return true; } catch (const exception::bad_boxed_cast &) { - std::cerr << "Bad boxed cast performing ** to ** test" << std::endl; + std::cerr << "Bad boxed cast performing ** to ** test\n"; return false; } catch (...) { - std::cerr << "Unknown exception performing ** to ** test" << std::endl; + std::cerr << "Unknown exception performing ** to ** test\n"; return false; } diff --git a/unittests/dynamic_object_test.cpp b/unittests/dynamic_object_test.cpp index 3e09ef6..85f868a 100644 --- a/unittests/dynamic_object_test.cpp +++ b/unittests/dynamic_object_test.cpp @@ -8,7 +8,7 @@ void assert_equal(const LHS &lhs, const RHS &rhs) { return; } else { - std::cout << "Got: " << lhs << " expected " << rhs << std::endl; + std::cout << "Got: " << lhs << " expected " << rhs << '\n'; exit(EXIT_FAILURE); } } diff --git a/unittests/eval_catch_exception_test.cpp b/unittests/eval_catch_exception_test.cpp index 8cde186..0433839 100644 --- a/unittests/eval_catch_exception_test.cpp +++ b/unittests/eval_catch_exception_test.cpp @@ -16,7 +16,7 @@ int test_generic() } } - std::cout << "test_generic failed" << std::endl; + std::cout << "test_generic failed\n"; return EXIT_FAILURE; } @@ -33,7 +33,7 @@ int test_1() } } - std::cout << "test_1 failed" << std::endl; + std::cout << "test_1 failed\n"; return EXIT_FAILURE; } @@ -50,7 +50,7 @@ int test_2() } } - std::cout << "test_2 failed" << std::endl; + std::cout << "test_2 failed\n"; return EXIT_FAILURE; } @@ -61,22 +61,22 @@ int test_5() try { chai.eval("throw(runtime_error(\"error\"))", chaiscript::exception_specification()); } catch (const double) { - std::cout << "test_5 failed with double" << std::endl; + std::cout << "test_5 failed with double\n"; return EXIT_FAILURE; } catch (int) { - std::cout << "test_5 failed with int" << std::endl; + std::cout << "test_5 failed with int\n"; return EXIT_FAILURE; } catch (float) { - std::cout << "test_5 failed with float" << std::endl; + std::cout << "test_5 failed with float\n"; return EXIT_FAILURE; } catch (const std::string &) { - std::cout << "test_5 failed with string" << std::endl; + std::cout << "test_5 failed with string\n"; return EXIT_FAILURE; } catch (const std::exception &) { return EXIT_SUCCESS; } - std::cout << "test_5 failed" << std::endl; + std::cout << "test_5 failed\n"; return EXIT_FAILURE; } @@ -87,22 +87,22 @@ int test_unhandled() try { chai.eval("throw(\"error\")", chaiscript::exception_specification()); } catch (double) { - std::cout << "test_unhandled failed with double" << std::endl; + std::cout << "test_unhandled failed with double\n"; return EXIT_FAILURE; } catch (int) { - std::cout << "test_unhandled failed with int" << std::endl; + std::cout << "test_unhandled failed with int\n"; return EXIT_FAILURE; } catch (float) { - std::cout << "test_unhandled failed with float" << std::endl; + std::cout << "test_unhandled failed with float\n"; return EXIT_FAILURE; } catch (const std::exception &) { - std::cout << "test_unhandled failed with std::exception" << std::endl; + std::cout << "test_unhandled failed with std::exception\n"; return EXIT_FAILURE; } catch (const chaiscript::Boxed_Value &) { return EXIT_SUCCESS; } - std::cout << "test_unhandled failed" << std::endl; + std::cout << "test_unhandled failed\n"; return EXIT_FAILURE; } diff --git a/unittests/integer_literal_test.cpp b/unittests/integer_literal_test.cpp index b446d3d..ecaff8a 100644 --- a/unittests/integer_literal_test.cpp +++ b/unittests/integer_literal_test.cpp @@ -7,7 +7,7 @@ bool test_literal(T val, const std::string &str) { chaiscript::ChaiScript chai; T val2 = chai.eval(str); - std::cout << "Comparing : " << val << " " << val2 << std::endl; + std::cout << "Comparing : " << val << " " << val2 << '\n'; return val == val2; } diff --git a/unittests/type_info_test.cpp b/unittests/type_info_test.cpp index e41f111..5e16581 100644 --- a/unittests/type_info_test.cpp +++ b/unittests/type_info_test.cpp @@ -31,7 +31,7 @@ int main() test_type(chaiscript::user_type(), true, true, false, false, false); test_type(chaiscript::Type_Info(), false, false, false, false, true); - std::cout << "Size of Type_Info " << sizeof(chaiscript::Type_Info) << std::endl; + std::cout << "Size of Type_Info " << sizeof(chaiscript::Type_Info) << '\n'; return EXIT_SUCCESS; }