Code simplifications and spelling fixes found by clion

This commit is contained in:
Jason Turner
2015-04-27 08:09:31 -06:00
parent b2b604e2ad
commit 8889324b2d
12 changed files with 83 additions and 116 deletions

View File

@@ -229,8 +229,7 @@ namespace chaiscript
if (f)
{
std::shared_ptr<const dispatch::Dynamic_Proxy_Function> dynfunguard
= std::dynamic_pointer_cast<const dispatch::Dynamic_Proxy_Function>(f);
auto dynfunguard = std::dynamic_pointer_cast<const dispatch::Dynamic_Proxy_Function>(f);
if (dynfunguard)
{
retval += " : " + format_guard(dynfunguard->get_parse_tree());
@@ -486,8 +485,8 @@ namespace chaiscript
private:
// Copy and assignment explicitly unimplemented
AST_Node(const AST_Node &);
AST_Node& operator=(const AST_Node &);
AST_Node(const AST_Node &) = delete;
AST_Node& operator=(const AST_Node &) = delete;
};

View File

@@ -166,11 +166,11 @@ namespace chaiscript
static std::string get_error_message(DWORD t_err)
{
typedef LPTSTR StringType;
#if defined(_UNICODE) || defined(UNICODE)
typedef LPWSTR StringType;
std::wstring retval = L"Unknown Error";
#else
typedef LPSTR StringType;
std::string retval = "Unknown Error";
#endif
StringType lpMsgBuf = nullptr;
@@ -182,7 +182,7 @@ namespace chaiscript
NULL,
t_err,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(StringType)&lpMsgBuf,
reinterpret_cast<StringType>(&lpMsgBuf),
0, NULL ) != 0 && lpMsgBuf)
{
retval = lpMsgBuf;
@@ -264,8 +264,8 @@ namespace chaiscript
std::map<std::string, detail::Loadable_Module_Ptr> m_loaded_modules;
std::set<std::string> m_active_loaded_modules;
std::vector<std::string> m_modulepaths;
std::vector<std::string> m_usepaths;
std::vector<std::string> m_module_paths;
std::vector<std::string> m_use_paths;
chaiscript::detail::Dispatch_Engine m_engine;
@@ -299,7 +299,7 @@ namespace chaiscript
/// Evaluates the given file and looks in the 'use' paths
const Boxed_Value internal_eval_file(const std::string &t_filename) {
for (const auto &path : m_usepaths)
for (const auto &path : m_use_paths)
{
try {
const auto appendedpath = path + t_filename;
@@ -441,16 +441,16 @@ namespace chaiscript
ChaiScript(const ModulePtr &t_lib,
std::vector<std::string> t_modulepaths = std::vector<std::string>(),
std::vector<std::string> t_usepaths = std::vector<std::string>())
: m_modulepaths(std::move(t_modulepaths)), m_usepaths(std::move(t_usepaths))
: m_module_paths(std::move(t_modulepaths)), m_use_paths(std::move(t_usepaths))
{
if (m_modulepaths.empty())
if (m_module_paths.empty())
{
m_modulepaths.push_back("");
m_module_paths.push_back("");
}
if (m_usepaths.empty())
if (m_use_paths.empty())
{
m_usepaths.push_back("");
m_use_paths.push_back("");
}
build_eval_system(t_lib);
@@ -465,16 +465,16 @@ namespace chaiscript
/// \param[in] t_usepaths Vector of paths to search when attempting to "use" an included ChaiScript file
ChaiScript( std::vector<std::string> t_modulepaths = std::vector<std::string>(),
std::vector<std::string> t_usepaths = std::vector<std::string>())
: m_modulepaths(std::move(t_modulepaths)), m_usepaths(std::move(t_usepaths))
: m_module_paths(std::move(t_modulepaths)), m_use_paths(std::move(t_usepaths))
{
if (m_modulepaths.empty())
if (m_module_paths.empty())
{
m_modulepaths.push_back("");
m_module_paths.push_back("");
}
if (m_usepaths.empty())
if (m_use_paths.empty())
{
m_usepaths.push_back("");
m_use_paths.push_back("");
}
#if defined(_POSIX_VERSION) && !defined(__CYGWIN__)
@@ -507,7 +507,7 @@ namespace chaiscript
dllpath = std::string(&buf.front(), pathlen);
}
m_modulepaths.insert(m_modulepaths.begin(), dllpath+"/");
m_module_paths.insert(m_module_paths.begin(), dllpath+"/");
}
#endif
@@ -559,7 +559,7 @@ namespace chaiscript
/// \param[in] t_filename Filename to load and evaluate
Boxed_Value use(const std::string &t_filename)
{
for (const auto &path : m_usepaths)
for (const auto &path : m_use_paths)
{
try {
const auto appendedpath = path + t_filename;
@@ -758,7 +758,7 @@ namespace chaiscript
std::vector<std::string> postfixes{".dll", ".so", ".bundle", ""};
for (auto & elem : m_modulepaths)
for (auto & elem : m_module_paths)
{
for (auto & prefix : prefixes)
{

View File

@@ -1330,7 +1330,7 @@ namespace chaiscript
end_point = this->children.size() - 1;
}
for (size_t i = 1; i < end_point; ++i) {
chaiscript::eval::detail::Scope_Push_Pop catchscope(t_ss);
chaiscript::eval::detail::Scope_Push_Pop catch_scope(t_ss);
AST_NodePtr catch_block = this->children[i];
if (catch_block->children.size() == 1) {

View File

@@ -257,12 +257,12 @@ namespace chaiscript
for (auto &c : p->children)
{
if (c->identifier == AST_Node_Type::Def && c->children.size() > 0) {
auto &lastchild = c->children.back();
if (lastchild->identifier == AST_Node_Type::Block) {
auto &blocklastchild = lastchild->children.back();
if (blocklastchild->identifier == AST_Node_Type::Return) {
if (blocklastchild->children.size() == 1) {
blocklastchild = blocklastchild->children[0];
auto &last_child = c->children.back();
if (last_child->identifier == AST_Node_Type::Block) {
auto &block_last_child = last_child->children.back();
if (block_last_child->identifier == AST_Node_Type::Return) {
if (block_last_child->children.size() == 1) {
block_last_child = block_last_child->children[0];
}
}
}
@@ -789,30 +789,26 @@ namespace chaiscript
}
/// Reads (and potentially captures) an identifier from input
bool Id(const bool t_capture = false) {
bool Id() {
SkipWS();
if (!t_capture) {
return Id_();
const auto start = m_input_pos;
const auto prev_col = m_col;
const auto prev_line = m_line;
if (Id_()) {
m_match_stack.push_back(std::make_shared<eval::Id_AST_Node>(
[&]()->std::string{
if (*start == '`') {
//Id Literal
return std::string(start+1, m_input_pos-1);
} else {
return std::string(start, m_input_pos);
}
}(),
m_filename, prev_line, prev_col, m_line, m_col));
return true;
} else {
const auto start = m_input_pos;
const auto prev_col = m_col;
const auto prev_line = m_line;
if (Id_()) {
m_match_stack.push_back(std::make_shared<eval::Id_AST_Node>(
[&]()->std::string{
if (*start == '`') {
//Id Literal
return std::string(start+1, m_input_pos-1);
} else {
return std::string(start, m_input_pos);
}
}(),
m_filename, prev_line, prev_col, m_line, m_col));
return true;
} else {
return false;
}
return false;
}
}
@@ -821,14 +817,14 @@ namespace chaiscript
const auto prev_stack_top = m_match_stack.size();
SkipWS();
if (!Id(true)) {
if (!Id()) {
return false;
}
SkipWS();
if (t_type_allowed) {
Id(true);
Id();
}
build_match(std::make_shared<eval::Arg_AST_Node>(), prev_stack_top);
@@ -1426,7 +1422,7 @@ namespace chaiscript
if (Keyword("def")) {
retval = true;
if (!Id(true)) {
if (!Id()) {
throw exception::eval_error("Missing function name in definition", File_Position(m_line, m_col), *m_filename);
}
@@ -1436,7 +1432,7 @@ namespace chaiscript
//We're now a method
is_method = true;
if (!Id(true)) {
if (!Id()) {
throw exception::eval_error("Missing method name in definition", File_Position(m_line, m_col), *m_filename);
}
}
@@ -1609,7 +1605,7 @@ namespace chaiscript
if (Keyword("class")) {
retval = true;
if (!Id(true)) {
if (!Id()) {
throw exception::eval_error("Missing class name in definition", File_Position(m_line, m_col), *m_filename);
}
@@ -1890,7 +1886,7 @@ namespace chaiscript
const auto prev_stack_top = m_match_stack.size();
if (Lambda() || Num(true) || Quoted_String(true) || Single_Quoted_String(true) ||
Paren_Expression() || Inline_Container() || Id(true))
Paren_Expression() || Inline_Container() || Id())
{
retval = true;
bool has_more = true;
@@ -1931,7 +1927,7 @@ namespace chaiscript
}
else if (Symbol(".", true)) {
has_more = true;
if (!(Id(true))) {
if (!(Id())) {
throw exception::eval_error("Incomplete array access", File_Position(m_line, m_col), *m_filename);
}
@@ -1952,7 +1948,7 @@ namespace chaiscript
if (t_class_context && (Keyword("attr") || Keyword("auto") || Keyword("var"))) {
retval = true;
if (!Id(true)) {
if (!Id()) {
throw exception::eval_error("Incomplete attribute declaration", File_Position(m_line, m_col), *m_filename);
}
@@ -1960,7 +1956,7 @@ namespace chaiscript
} else if (Keyword("auto") || Keyword("var")) {
retval = true;
if (!(Reference() || Id(true))) {
if (!(Reference() || Id())) {
throw exception::eval_error("Incomplete variable declaration", File_Position(m_line, m_col), *m_filename);
}
@@ -1968,13 +1964,13 @@ namespace chaiscript
} else if (Keyword("attr")) {
retval = true;
if (!Id(true)) {
if (!Id()) {
throw exception::eval_error("Incomplete attribute declaration", File_Position(m_line, m_col), *m_filename);
}
if (!Symbol("::", false)) {
throw exception::eval_error("Incomplete attribute declaration", File_Position(m_line, m_col), *m_filename);
}
if (!Id(true)) {
if (!Id()) {
throw exception::eval_error("Missing attribute name in definition", File_Position(m_line, m_col), *m_filename);
}
@@ -2036,7 +2032,7 @@ namespace chaiscript
const auto prev_stack_top = m_match_stack.size();
if (Symbol("&", false)) {
if (!Id(true)) {
if (!Id()) {
throw exception::eval_error("Incomplete '&' expression", File_Position(m_line, m_col), *m_filename);
}
@@ -2071,11 +2067,7 @@ namespace chaiscript
/// Parses any of a group of 'value' style ast_node groups from input
bool Value() {
if (Var_Decl() || Dot_Fun_Array() || Prefix()) {
return true;
} else {
return false;
}
return Var_Decl() || Dot_Fun_Array() || Prefix();
}
bool Operator_Helper(const size_t t_precedence) {

View File

@@ -309,7 +309,7 @@ class Range
/// \brief Moves the front pointer forward one
///
/// \post front() returne the element at front() + 1;
/// \post front() returns the element at front() + 1;
void pop_front();
};
@@ -340,7 +340,7 @@ class Const_Range
/// \brief Moves the front pointer forward one
///
/// \post front() returne the element at front() + 1;
/// \post front() returns the element at front() + 1;
void pop_front();
};