mirror of
https://github.com/ChaiScript/ChaiScript.git
synced 2026-04-30 19:09:26 +08:00
* Fix #690: Apply clang-format consistently with CI Applied clang-format-19 to all source files to enforce consistent formatting according to the existing .clang-format configuration. Added auto-clang-format GitHub Actions workflow (from cpp-best-practices/cmake_template) that runs on pull requests to automatically format and commit any style violations going forward. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
1cbbba38f9
commit
9680c93bd1
@ -1,10 +1,14 @@
|
||||
# clang-format: 11
|
||||
# clang-format: 19
|
||||
AccessModifierOffset: -2
|
||||
AlignAfterOpenBracket: Align
|
||||
AlignConsecutiveBitFields: false
|
||||
AllowShortBlocksOnASingleLine: false
|
||||
AllowShortBlocksOnASingleLine: Always
|
||||
AllowShortCaseLabelsOnASingleLine: true
|
||||
AllowShortEnumsOnASingleLine: true
|
||||
AllowShortFunctionsOnASingleLine: Inline
|
||||
AllowShortIfStatementsOnASingleLine: AllIfsAndElse
|
||||
AllowShortLambdasOnASingleLine: All
|
||||
AllowShortLoopsOnASingleLine: true
|
||||
AlwaysBreakTemplateDeclarations: true
|
||||
BasedOnStyle: WebKit
|
||||
BinPackArguments: true
|
||||
@ -13,12 +17,14 @@ BreakBeforeBraces: Attach
|
||||
ColumnLimit: 0
|
||||
Cpp11BracedListStyle: true
|
||||
FixNamespaceComments: true
|
||||
IfMacros: ['SECTION']
|
||||
IncludeBlocks: Preserve
|
||||
IndentCaseLabels: true
|
||||
IndentPPDirectives: None
|
||||
IndentWidth: 2
|
||||
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||
NamespaceIndentation: All
|
||||
PackConstructorInitializers: CurrentLine
|
||||
PenaltyBreakBeforeFirstCallParameter: 200
|
||||
PenaltyBreakComment: 5
|
||||
PenaltyBreakFirstLessLess: 50
|
||||
@ -27,6 +33,10 @@ PointerAlignment: Right
|
||||
SortIncludes: true
|
||||
SpaceAfterTemplateKeyword: false
|
||||
SpaceBeforeCpp11BracedList: false
|
||||
SpaceBeforeParens: Custom
|
||||
SpaceBeforeParensOptions:
|
||||
AfterControlStatements: true
|
||||
AfterIfMacros: false
|
||||
SpaceInEmptyBlock: false
|
||||
Standard: Latest
|
||||
TabWidth: 2
|
||||
|
||||
27
.github/workflows/auto-clang-format.yml
vendored
Normal file
27
.github/workflows/auto-clang-format.yml
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
name: auto-clang-format
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- develop
|
||||
- master
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
- uses: DoozyX/clang-format-lint-action@v0.20
|
||||
with:
|
||||
source: '.'
|
||||
exclude: './third_party ./external ./unittests/catch.hpp'
|
||||
extensions: 'h,cpp,hpp'
|
||||
clangFormatVersion: 19
|
||||
inplace: True
|
||||
- uses: EndBug/add-and-commit@v9
|
||||
with:
|
||||
author_name: Clang Robot
|
||||
author_email: robot@example.com
|
||||
message: ':art: Committing clang-format changes'
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
@ -11,14 +11,14 @@
|
||||
#ifndef CHAISCRIPT_EMSCRIPTEN_EVAL_HPP_
|
||||
#define CHAISCRIPT_EMSCRIPTEN_EVAL_HPP_
|
||||
|
||||
#include <string>
|
||||
#include <chaiscript/chaiscript.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace detail {
|
||||
inline chaiscript::ChaiScript &get_chai_instance() {
|
||||
inline chaiscript::ChaiScript &get_chai_instance() {
|
||||
static chaiscript::ChaiScript chai;
|
||||
return chai;
|
||||
}
|
||||
}
|
||||
} // namespace detail
|
||||
|
||||
inline void chaiscript_eval(const std::string &input) {
|
||||
|
||||
@ -18,11 +18,11 @@
|
||||
|
||||
#include "dispatchkit/function_call.hpp"
|
||||
|
||||
//#include "dispatchkit/dispatchkit.hpp"
|
||||
// #include "dispatchkit/dispatchkit.hpp"
|
||||
#include "dispatchkit/bootstrap.hpp"
|
||||
#include "dispatchkit/bootstrap_stl.hpp"
|
||||
#include "dispatchkit/operators.hpp"
|
||||
//#include "dispatchkit/boxed_value.hpp"
|
||||
// #include "dispatchkit/boxed_value.hpp"
|
||||
#include "dispatchkit/register_function.hpp"
|
||||
#include "language/chaiscript_prelude.hpp"
|
||||
#include "utility/json_wrap.hpp"
|
||||
|
||||
@ -65,7 +65,6 @@ namespace chaiscript {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool is_explicit() const noexcept { return m_option_explicit; }
|
||||
|
||||
void set_explicit(const bool t_explicit) noexcept { m_option_explicit = t_explicit; }
|
||||
|
||||
@ -64,7 +64,7 @@ namespace chaiscript::dispatch::detail {
|
||||
Function_Signature(Ret (Class::*f)(Param...) volatile &) -> Function_Signature<Ret, Function_Params<volatile Class &, Param...>, false, true>;
|
||||
|
||||
template<typename Ret, typename Class, typename... Param>
|
||||
Function_Signature(Ret (Class::*f)(Param...) volatile &noexcept)
|
||||
Function_Signature(Ret (Class::*f)(Param...) volatile & noexcept)
|
||||
-> Function_Signature<Ret, Function_Params<volatile Class &, Param...>, true, true>;
|
||||
|
||||
template<typename Ret, typename Class, typename... Param>
|
||||
@ -72,20 +72,20 @@ namespace chaiscript::dispatch::detail {
|
||||
-> Function_Signature<Ret, Function_Params<volatile const Class &, Param...>, false, true>;
|
||||
|
||||
template<typename Ret, typename Class, typename... Param>
|
||||
Function_Signature(Ret (Class::*f)(Param...) volatile const &noexcept)
|
||||
Function_Signature(Ret (Class::*f)(Param...) volatile const & noexcept)
|
||||
-> Function_Signature<Ret, Function_Params<volatile const Class &, Param...>, true, true>;
|
||||
|
||||
template<typename Ret, typename Class, typename... Param>
|
||||
Function_Signature(Ret (Class::*f)(Param...) &) -> Function_Signature<Ret, Function_Params<Class &, Param...>, false, true>;
|
||||
|
||||
template<typename Ret, typename Class, typename... Param>
|
||||
Function_Signature(Ret (Class::*f)(Param...) &noexcept) -> Function_Signature<Ret, Function_Params<Class &, Param...>, true, true>;
|
||||
Function_Signature(Ret (Class::*f)(Param...) & noexcept) -> Function_Signature<Ret, Function_Params<Class &, Param...>, true, true>;
|
||||
|
||||
template<typename Ret, typename Class, typename... Param>
|
||||
Function_Signature(Ret (Class::*f)(Param...) const &) -> Function_Signature<Ret, Function_Params<const Class &, Param...>, false, true>;
|
||||
|
||||
template<typename Ret, typename Class, typename... Param>
|
||||
Function_Signature(Ret (Class::*f)(Param...) const &noexcept) -> Function_Signature<Ret, Function_Params<const Class &, Param...>, true, true>;
|
||||
Function_Signature(Ret (Class::*f)(Param...) const & noexcept) -> Function_Signature<Ret, Function_Params<const Class &, Param...>, true, true>;
|
||||
|
||||
// && reference specifier
|
||||
|
||||
@ -93,7 +93,7 @@ namespace chaiscript::dispatch::detail {
|
||||
Function_Signature(Ret (Class::*f)(Param...) volatile &&) -> Function_Signature<Ret, Function_Params<volatile Class &&, Param...>, false, true>;
|
||||
|
||||
template<typename Ret, typename Class, typename... Param>
|
||||
Function_Signature(Ret (Class::*f)(Param...) volatile &&noexcept)
|
||||
Function_Signature(Ret (Class::*f)(Param...) volatile && noexcept)
|
||||
-> Function_Signature<Ret, Function_Params<volatile Class &&, Param...>, true, true>;
|
||||
|
||||
template<typename Ret, typename Class, typename... Param>
|
||||
@ -101,20 +101,20 @@ namespace chaiscript::dispatch::detail {
|
||||
-> Function_Signature<Ret, Function_Params<volatile const Class &&, Param...>, false, true>;
|
||||
|
||||
template<typename Ret, typename Class, typename... Param>
|
||||
Function_Signature(Ret (Class::*f)(Param...) volatile const &&noexcept)
|
||||
Function_Signature(Ret (Class::*f)(Param...) volatile const && noexcept)
|
||||
-> Function_Signature<Ret, Function_Params<volatile const Class &&, Param...>, true, true>;
|
||||
|
||||
template<typename Ret, typename Class, typename... Param>
|
||||
Function_Signature(Ret (Class::*f)(Param...) &&) -> Function_Signature<Ret, Function_Params<Class &&, Param...>, false, true>;
|
||||
|
||||
template<typename Ret, typename Class, typename... Param>
|
||||
Function_Signature(Ret (Class::*f)(Param...) &&noexcept) -> Function_Signature<Ret, Function_Params<Class &&, Param...>, true, true>;
|
||||
Function_Signature(Ret (Class::*f)(Param...) && noexcept) -> Function_Signature<Ret, Function_Params<Class &&, Param...>, true, true>;
|
||||
|
||||
template<typename Ret, typename Class, typename... Param>
|
||||
Function_Signature(Ret (Class::*f)(Param...) const &&) -> Function_Signature<Ret, Function_Params<const Class &&, Param...>, false, true>;
|
||||
|
||||
template<typename Ret, typename Class, typename... Param>
|
||||
Function_Signature(Ret (Class::*f)(Param...) const &&noexcept)
|
||||
Function_Signature(Ret (Class::*f)(Param...) const && noexcept)
|
||||
-> Function_Signature<Ret, Function_Params<const Class &&, Param...>, true, true>;
|
||||
|
||||
template<typename Ret, typename Class>
|
||||
|
||||
@ -543,8 +543,7 @@ namespace chaiscript {
|
||||
|
||||
auto pair = std::make_pair(
|
||||
detail::Cast_Helper<Left>::cast(from_pair.first, nullptr),
|
||||
detail::Cast_Helper<Right>::cast(from_pair.second, nullptr)
|
||||
);
|
||||
detail::Cast_Helper<Right>::cast(from_pair.second, nullptr));
|
||||
|
||||
return Boxed_Value(std::move(pair));
|
||||
};
|
||||
|
||||
@ -593,7 +593,7 @@ namespace chaiscript {
|
||||
|
||||
} // namespace exception
|
||||
|
||||
//static
|
||||
// static
|
||||
bool AST_Node::get_bool_condition(const Boxed_Value &t_bv, const chaiscript::detail::Dispatch_State &t_ss) {
|
||||
try {
|
||||
return t_ss->boxed_cast<bool>(t_bv);
|
||||
|
||||
@ -138,7 +138,8 @@ namespace chaiscript {
|
||||
|
||||
m_engine.add(fun([this](const std::function<void(const std::string &)> &t_handler) {
|
||||
m_print_handler = t_handler;
|
||||
}), "set_print_handler");
|
||||
}),
|
||||
"set_print_handler");
|
||||
|
||||
m_engine.add(fun([this](const std::function<std::string(const std::string &)> &t_reader) {
|
||||
m_file_reader = t_reader;
|
||||
@ -291,7 +292,6 @@ namespace chaiscript {
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
/// \brief Set a custom handler for print output, used by both print_string and println_string
|
||||
/// \param[in] t_handler Function to call with the string to print
|
||||
void set_print_handler(std::function<void(const std::string &)> t_handler) {
|
||||
|
||||
@ -10,13 +10,13 @@
|
||||
#ifndef CHAISCRIPT_EVAL_HPP_
|
||||
#define CHAISCRIPT_EVAL_HPP_
|
||||
|
||||
#include <algorithm>
|
||||
#include <exception>
|
||||
#include <functional>
|
||||
#include <limits>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <ostream>
|
||||
#include <algorithm>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@ -1271,8 +1271,7 @@ namespace chaiscript {
|
||||
const auto process_statement = [&](const AST_Node_Impl<T> &stmt) {
|
||||
if (stmt.identifier == AST_Node_Type::Def) {
|
||||
const auto &def_node = static_cast<const Def_AST_Node<T> &>(stmt);
|
||||
target_ns[def_node.children[0]->text] =
|
||||
Boxed_Value(Def_AST_Node<T>::make_proxy_function(def_node, t_ss));
|
||||
target_ns[def_node.children[0]->text] = Boxed_Value(Def_AST_Node<T>::make_proxy_function(def_node, t_ss));
|
||||
} else if (stmt.identifier == AST_Node_Type::Assign_Decl
|
||||
|| stmt.identifier == AST_Node_Type::Const_Assign_Decl) {
|
||||
const auto &var_name = stmt.children[0]->text;
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
#ifndef CHAISCRIPT_SIMPLEJSON_WRAP_HPP
|
||||
#define CHAISCRIPT_SIMPLEJSON_WRAP_HPP
|
||||
|
||||
#include "json.hpp"
|
||||
#include "../dispatchkit/dynamic_object.hpp"
|
||||
#include "json.hpp"
|
||||
|
||||
namespace chaiscript {
|
||||
class json_wrap {
|
||||
|
||||
@ -605,7 +605,9 @@ TEST_CASE("Utility_Test utility class wrapper for enum") {
|
||||
}
|
||||
|
||||
// Issue #601: add_class for enums should work directly with ChaiScript reference
|
||||
enum class Issue601_EnumClass { Apple, Banana, Pear };
|
||||
enum class Issue601_EnumClass { Apple,
|
||||
Banana,
|
||||
Pear };
|
||||
|
||||
TEST_CASE("Issue 601: add_class enum with ChaiScript reference directly") {
|
||||
chaiscript::ChaiScript_Basic chai(create_chaiscript_stdlib(), create_chaiscript_parser());
|
||||
@ -626,7 +628,9 @@ TEST_CASE("Issue 601: add_class enum with ChaiScript reference directly") {
|
||||
}
|
||||
|
||||
// Also test non-scoped enum directly with ChaiScript reference
|
||||
enum Issue601_PlainEnum { Issue601_Red = 0, Issue601_Green = 1, Issue601_Blue = 2 };
|
||||
enum Issue601_PlainEnum { Issue601_Red = 0,
|
||||
Issue601_Green = 1,
|
||||
Issue601_Blue = 2 };
|
||||
|
||||
TEST_CASE("Issue 601: add_class plain enum with ChaiScript reference directly") {
|
||||
chaiscript::ChaiScript_Basic chai(create_chaiscript_stdlib(), create_chaiscript_parser());
|
||||
@ -952,7 +956,7 @@ TEST_CASE("Pair conversions") {
|
||||
const auto p = chai.eval<std::pair<std::string, std::string>>(R"cs(
|
||||
Pair("chai", "script");
|
||||
)cs");
|
||||
CHECK(p.first == std::string{ "chai" });
|
||||
CHECK(p.first == std::string{"chai"});
|
||||
CHECK(p.second == "script");
|
||||
}
|
||||
{
|
||||
@ -1532,7 +1536,8 @@ TEST_CASE("ChaiScript default has all functions") {
|
||||
TEST_CASE("Issue #421 - Switch with type_conversion does not compare destroyed objects") {
|
||||
struct MyType {
|
||||
int value;
|
||||
explicit MyType(int v) : value(v) {}
|
||||
explicit MyType(int v)
|
||||
: value(v) {}
|
||||
};
|
||||
|
||||
chaiscript::ChaiScript_Basic chai(create_chaiscript_stdlib(), create_chaiscript_parser());
|
||||
@ -1761,45 +1766,44 @@ TEST_CASE("push_back on script vector with vector_conversion") {
|
||||
result += s;
|
||||
}
|
||||
return result;
|
||||
}), "join_strings");
|
||||
}),
|
||||
"join_strings");
|
||||
|
||||
// push_back on an empty script-created vector must be visible
|
||||
CHECK(chai.eval<bool>(
|
||||
"auto x = [];"
|
||||
"x.push_back(\"Hello\");"
|
||||
"x.size() == 1"
|
||||
));
|
||||
"x.size() == 1"));
|
||||
|
||||
// push_back on a vector with initial elements must grow correctly
|
||||
CHECK(chai.eval<bool>(
|
||||
"auto y = [\"a\", \"b\"];"
|
||||
"y.push_back(\"c\");"
|
||||
"y.push_back(\"d\");"
|
||||
"y.size() == 4"
|
||||
));
|
||||
"y.size() == 4"));
|
||||
|
||||
// Verify the actual content is preserved after push_back
|
||||
CHECK(chai.eval<std::string>(
|
||||
"auto z = [];"
|
||||
"z.push_back(\"World\");"
|
||||
"z[0]"
|
||||
) == "World");
|
||||
"z[0]")
|
||||
== "World");
|
||||
|
||||
// Round-trip: build a vector in script, push_back elements, then pass it
|
||||
// to a C++ function via vector_conversion and verify the contents
|
||||
CHECK(chai.eval<std::string>(
|
||||
"auto v = [\"one\", \"two\"];"
|
||||
"v.push_back(\"three\");"
|
||||
"join_strings(v)"
|
||||
) == "one,two,three");
|
||||
"join_strings(v)")
|
||||
== "one,two,three");
|
||||
|
||||
// Verify conversion works on a freshly created vector too
|
||||
CHECK(chai.eval<std::string>(
|
||||
"auto w = [];"
|
||||
"w.push_back(\"hello\");"
|
||||
"w.push_back(\"world\");"
|
||||
"join_strings(w)"
|
||||
) == "hello,world");
|
||||
"join_strings(w)")
|
||||
== "hello,world");
|
||||
}
|
||||
|
||||
// Regression test for issue #607: AST_Node_Trace must be a complete type
|
||||
@ -1962,20 +1966,23 @@ TEST_CASE("Namespace block rejects non-declaration statements") {
|
||||
namespace bad {
|
||||
1 + 2
|
||||
}
|
||||
)"), chaiscript::exception::eval_error);
|
||||
)"),
|
||||
chaiscript::exception::eval_error);
|
||||
|
||||
CHECK_THROWS_AS(chai.eval(R"(
|
||||
namespace bad {
|
||||
print("hello")
|
||||
}
|
||||
)"), chaiscript::exception::eval_error);
|
||||
)"),
|
||||
chaiscript::exception::eval_error);
|
||||
|
||||
CHECK_THROWS_AS(chai.eval(R"(
|
||||
var x = 5
|
||||
namespace bad {
|
||||
x = 10
|
||||
}
|
||||
)"), chaiscript::exception::eval_error);
|
||||
)"),
|
||||
chaiscript::exception::eval_error);
|
||||
}
|
||||
|
||||
TEST_CASE("C++ runtime_error thrown from registered function is catchable in ChaiScript") {
|
||||
@ -2061,7 +2068,8 @@ TEST_CASE("Typed catch with no match propagates exception") {
|
||||
catch(string e) {
|
||||
// wrong type, should not match
|
||||
}
|
||||
)"), chaiscript::Boxed_Value);
|
||||
)"),
|
||||
chaiscript::Boxed_Value);
|
||||
}
|
||||
|
||||
TEST_CASE("Typed catch with no match still runs finally block") {
|
||||
@ -2078,7 +2086,8 @@ TEST_CASE("Typed catch with no match still runs finally block") {
|
||||
finally {
|
||||
finally_ran = true
|
||||
}
|
||||
)"), chaiscript::Boxed_Value);
|
||||
)"),
|
||||
chaiscript::Boxed_Value);
|
||||
|
||||
CHECK(chai.eval<bool>("finally_ran") == true);
|
||||
}
|
||||
@ -2093,7 +2102,8 @@ TEST_CASE("Multiple C++ exception types from registered functions") {
|
||||
case 2: throw std::logic_error("logic");
|
||||
default: return which;
|
||||
}
|
||||
}), "cpp_multi_throw");
|
||||
}),
|
||||
"cpp_multi_throw");
|
||||
|
||||
CHECK(chai.eval<int>(R"(
|
||||
var catch_count = 0
|
||||
@ -2122,7 +2132,8 @@ TEST_CASE("Exception from C++ binary operator is catchable in ChaiScript") {
|
||||
chai.add(chaiscript::constructor<ThrowingType(int)>(), "ThrowingType");
|
||||
chai.add(chaiscript::fun([](const ThrowingType &, const ThrowingType &) -> ThrowingType {
|
||||
throw std::runtime_error("cpp operator+ threw");
|
||||
}), "+");
|
||||
}),
|
||||
"+");
|
||||
|
||||
CHECK(chai.eval<bool>(R"(
|
||||
var caught = false
|
||||
@ -2150,7 +2161,8 @@ TEST_CASE("Exception from C++ [] operator is catchable in ChaiScript") {
|
||||
chai.add(chaiscript::fun([](const IndexableType &, int idx) -> int {
|
||||
if (idx < 0) { throw std::out_of_range("negative index"); }
|
||||
return idx;
|
||||
}), "[]");
|
||||
}),
|
||||
"[]");
|
||||
|
||||
CHECK(chai.eval<int>("var obj = IndexableType(0); obj[5]") == 5);
|
||||
|
||||
|
||||
@ -9,9 +9,9 @@
|
||||
#define CHAISCRIPT_NO_DYNLOAD
|
||||
#endif
|
||||
|
||||
#include <chaiscript/chaiscript.hpp>
|
||||
#include "../emscripten/chaiscript_eval.hpp"
|
||||
#include <cassert>
|
||||
#include <chaiscript/chaiscript.hpp>
|
||||
#include <cmath>
|
||||
#include <string>
|
||||
|
||||
|
||||
@ -10,9 +10,9 @@
|
||||
#define CHAISCRIPT_NO_DYNLOAD
|
||||
#endif
|
||||
|
||||
#include <chaiscript/chaiscript.hpp>
|
||||
#include "../emscripten/chaiscript_eval.hpp"
|
||||
#include <cassert>
|
||||
#include <chaiscript/chaiscript.hpp>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user