Merge branch 'develop' into smaller_make_shared
And also apply cleanups suggested from resharper Conflicts: include/chaiscript/language/chaiscript_parser.hpp
This commit is contained in:
@@ -9,8 +9,6 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "../dispatchkit/dispatchkit.hpp"
|
||||
|
||||
namespace chaiscript
|
||||
{
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ namespace chaiscript
|
||||
{
|
||||
|
||||
/// Errors generated during parsing or evaluation
|
||||
struct eval_error : public std::runtime_error {
|
||||
struct eval_error : std::runtime_error {
|
||||
std::string reason;
|
||||
File_Position start_position;
|
||||
File_Position end_position;
|
||||
@@ -230,8 +230,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());
|
||||
@@ -393,7 +392,7 @@ namespace chaiscript
|
||||
|
||||
|
||||
/// Errors generated when loading a file
|
||||
struct file_not_found_error : public std::runtime_error {
|
||||
struct file_not_found_error : std::runtime_error {
|
||||
file_not_found_error(const std::string &t_filename) CHAISCRIPT_NOEXCEPT
|
||||
: std::runtime_error("File Not Found: " + t_filename)
|
||||
{ }
|
||||
@@ -488,8 +487,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;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
#define CHAISCRIPT_ENGINE_HPP_
|
||||
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
#include <algorithm>
|
||||
#include <exception>
|
||||
#include <fstream>
|
||||
#include <functional>
|
||||
@@ -18,7 +16,6 @@
|
||||
#include <mutex>
|
||||
#include <set>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "../chaiscript_defines.hpp"
|
||||
@@ -166,11 +163,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 +179,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 +261,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 +296,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;
|
||||
@@ -363,10 +360,10 @@ namespace chaiscript
|
||||
m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::function_exists, std::ref(m_engine)), "function_exists");
|
||||
m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::get_function_objects, std::ref(m_engine)), "get_functions");
|
||||
m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::get_scripting_objects, std::ref(m_engine)), "get_objects");
|
||||
m_engine.add(Proxy_Function(new dispatch::Dynamic_Proxy_Function(
|
||||
m_engine.add(chaiscript::make_shared<dispatch::Proxy_Function_Base, dispatch::Dynamic_Proxy_Function>(
|
||||
[this](const std::vector<Boxed_Value> &t_params) {
|
||||
return m_engine.call_exists(t_params);
|
||||
})), "call_exists");
|
||||
}), "call_exists");
|
||||
|
||||
// m_engine.add(fun<Boxed_Value (const dispatch::Proxy_Function_Base *, const std::vector<Boxed_Value> &)>(std::bind(&chaiscript::dispatch::Proxy_Function_Base::operator(), std::placeholders::_1, std::placeholders::_2, std::ref(m_engine.conversions()))), "call");
|
||||
//
|
||||
@@ -441,16 +438,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 +462,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 +504,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 +556,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 +755,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)
|
||||
{
|
||||
|
||||
@@ -7,8 +7,6 @@
|
||||
#ifndef CHAISCRIPT_EVAL_HPP_
|
||||
#define CHAISCRIPT_EVAL_HPP_
|
||||
|
||||
#include <assert.h>
|
||||
#include <cstdlib>
|
||||
#include <exception>
|
||||
#include <functional>
|
||||
#include <limits>
|
||||
@@ -21,7 +19,6 @@
|
||||
|
||||
#include "../chaiscript_defines.hpp"
|
||||
#include "../dispatchkit/boxed_cast.hpp"
|
||||
#include "../dispatchkit/boxed_cast_helper.hpp"
|
||||
#include "../dispatchkit/boxed_number.hpp"
|
||||
#include "../dispatchkit/boxed_value.hpp"
|
||||
#include "../dispatchkit/dispatchkit.hpp"
|
||||
@@ -821,12 +818,12 @@ namespace chaiscript
|
||||
|
||||
const auto &lambda_node = this->children.back();
|
||||
|
||||
return Boxed_Value(Proxy_Function(new dispatch::Dynamic_Proxy_Function(
|
||||
return Boxed_Value(chaiscript::make_shared<dispatch::Proxy_Function_Base, dispatch::Dynamic_Proxy_Function>(
|
||||
[&t_ss, lambda_node, param_names, captures](const std::vector<Boxed_Value> &t_params)
|
||||
{
|
||||
return detail::eval_function(t_ss, lambda_node, param_names, t_params, captures);
|
||||
},
|
||||
static_cast<int>(numparams), lambda_node, param_types)));
|
||||
static_cast<int>(numparams), lambda_node, param_types));
|
||||
}
|
||||
|
||||
|
||||
@@ -882,23 +879,23 @@ namespace chaiscript
|
||||
|
||||
std::shared_ptr<dispatch::Dynamic_Proxy_Function> guard;
|
||||
if (guardnode) {
|
||||
guard = std::shared_ptr<dispatch::Dynamic_Proxy_Function>
|
||||
(new dispatch::Dynamic_Proxy_Function([&t_ss, guardnode, t_param_names](const std::vector<Boxed_Value> &t_params)
|
||||
guard = std::make_shared<dispatch::Dynamic_Proxy_Function>
|
||||
([&t_ss, guardnode, t_param_names](const std::vector<Boxed_Value> &t_params)
|
||||
{
|
||||
return detail::eval_function(t_ss, guardnode, t_param_names, t_params);
|
||||
}, static_cast<int>(numparams), guardnode));
|
||||
}, static_cast<int>(numparams), guardnode);
|
||||
}
|
||||
|
||||
try {
|
||||
const std::string & l_function_name = this->children[0]->text;
|
||||
const std::string & l_annotation = this->annotation?this->annotation->text:"";
|
||||
const auto & func_node = this->children.back();
|
||||
t_ss.add(Proxy_Function
|
||||
(new dispatch::Dynamic_Proxy_Function([&t_ss, guardnode, func_node, t_param_names](const std::vector<Boxed_Value> &t_params)
|
||||
t_ss.add(chaiscript::make_shared<dispatch::Proxy_Function_Base, dispatch::Dynamic_Proxy_Function>
|
||||
([&t_ss, guardnode, func_node, t_param_names](const std::vector<Boxed_Value> &t_params)
|
||||
{
|
||||
return detail::eval_function(t_ss, func_node, t_param_names, t_params);
|
||||
}, static_cast<int>(numparams), this->children.back(),
|
||||
param_types, l_annotation, guard)), l_function_name);
|
||||
param_types, l_annotation, guard), l_function_name);
|
||||
}
|
||||
catch (const exception::reserved_word_error &e) {
|
||||
throw exception::eval_error("Reserved word used as function name '" + e.word() + "'");
|
||||
@@ -1330,7 +1327,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) {
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <exception>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
@@ -257,12 +256,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 +788,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(chaiscript::make_shared<AST_Node, 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(chaiscript::make_shared<AST_Node, 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 +816,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(chaiscript::make_shared<AST_Node, eval::Arg_AST_Node>(), prev_stack_top);
|
||||
@@ -1426,7 +1421,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 +1431,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 +1604,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 +1885,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 +1926,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 +1947,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 +1955,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 +1963,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 +2031,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 +2066,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) {
|
||||
|
||||
@@ -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();
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user