// This file is distributed under the BSD License. // See "license.txt" for details. // Copyright 2009-2012, Jonathan Turner (jonathan@emptycrate.com) // Copyright 2009-2014, Jason Turner (jason@emptycrate.com) // http://www.chaiscript.com #include #include #include #include #include // MSVC doesn't like that we are using C++ return types from our C declared module // but this is the best way to do it for cross platform compatibility #ifdef CHAISCRIPT_MSVC #pragma warning(push) #pragma warning(disable : 4190) #endif bool has_parse_tree(const chaiscript::Const_Proxy_Function &t_pf) { std::shared_ptr pf = std::dynamic_pointer_cast(t_pf); if (pf) { if (pf->get_parse_tree()) { return true; } else { return false; } } else { return false; } } chaiscript::AST_NodePtr get_parse_tree(const chaiscript::Const_Proxy_Function &t_pf) { std::shared_ptr pf = std::dynamic_pointer_cast(t_pf); if (pf) { if (pf->get_parse_tree()) { return pf->get_parse_tree(); } else { throw std::runtime_error("Function does not have a parse tree"); } } else { throw std::runtime_error("Function does not have a parse tree"); } } #ifdef __llvm__ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wreturn-type-c-linkage" #endif CHAISCRIPT_MODULE_EXPORT chaiscript::ModulePtr create_chaiscript_module_reflection() { chaiscript::ModulePtr m(new chaiscript::Module()); m->add(chaiscript::fun(&has_parse_tree), "has_parse_tree"); m->add(chaiscript::fun(&get_parse_tree), "get_parse_tree"); m->add(chaiscript::base_class()); chaiscript::bootstrap::standard_library::vector_type > >("AST_NodeVector", m); using namespace chaiscript; chaiscript::utility::add_class(*m, "eval_error", { }, { {fun(&chaiscript::exception::eval_error::reason), "reason"}, {fun(&chaiscript::exception::eval_error::call_stack), "call_stack"} } ); chaiscript::utility::add_class(*m, "File_Position", { constructor(), constructor() }, { {fun(&File_Position::line), "line"}, {fun(&File_Position::column), "column"} } ); chaiscript::utility::add_class(*m, "AST_Node", { }, { {fun(&AST_Node::text), "text"}, {fun(&AST_Node::identifier), "identifier"}, {fun(&AST_Node::filename), "filename"}, {fun(&AST_Node::start), "start"}, {fun(&AST_Node::end), "end"}, {fun(&AST_Node::internal_to_string), "internal_to_string"}, {fun(&AST_Node::children), "children"}, {fun(&AST_Node::replace_child), "replace_child"} } ); chaiscript::utility::add_class(*m, "ChaiScript_Parser", { constructor() }, { {fun(&parser::ChaiScript_Parser::parse), "parse"}, {fun(&parser::ChaiScript_Parser::ast), "ast"} } ); return m; } #ifdef __llvm__ #pragma clang diagnostic pop #endif #ifdef CHAISCRIPT_MSVC #pragma warning(pop) #endif