Skip to content

Commit 8035a84

Browse files
committed
clang-format codebase
1 parent 802b838 commit 8035a84

File tree

4 files changed

+371
-455
lines changed

4 files changed

+371
-455
lines changed

.clang-format

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
AccessModifierOffset: -4
3+
AlignAfterOpenBracket: 'AlwaysBreak'
4+
AllowAllParametersOfDeclarationOnNextLine: 'false'
5+
AllowShortFunctionsOnASingleLine: 'true'
6+
AllowShortCaseLabelsOnASingleLine: 'true'
7+
AlwaysBreakBeforeMultilineStrings: 'true'
8+
AlwaysBreakTemplateDeclarations: 'true'
9+
BinPackArguments: 'false'
10+
BinPackParameters: 'false'
11+
BraceWrapping: {
12+
AfterClass: 'true'
13+
AfterControlStatement: 'true'
14+
AfterEnum: 'true'
15+
AfterFunction: 'true'
16+
AfterNamespace: 'true'
17+
AfterStruct: 'true'
18+
AfterUnion: 'true'
19+
BeforeCatch: 'true'
20+
BeforeElse: 'true'
21+
IndentBraces: 'false'
22+
}
23+
BreakBeforeBraces: Custom
24+
BreakConstructorInitializers: BeforeColon
25+
ColumnLimit: 100
26+
ConstructorInitializerAllOnOneLineOrOnePerLine: 'true'
27+
ConstructorInitializerIndentWidth: 4
28+
Cpp11BracedListStyle: 'true'
29+
DerivePointerAlignment: 'false'
30+
IndentCaseLabels: 'false'
31+
IndentWidth: 4
32+
PenaltyExcessCharacter: 100000000
33+
PenaltyReturnTypeOnItsOwnLine: 100000000
34+
PointerAlignment: Left
35+
PointerBindsToType: 'true'
36+
SortIncludes: 'false'
37+
SpaceAfterTemplateKeyword: 'false'
38+
SpaceBeforeAssignmentOperators: 'true'
39+
SpaceBeforeParens: ControlStatements
40+
Standard: Cpp11
41+
TabWidth: 4
42+
UseTab: Never

Wren++.cpp

+62-109
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
#include "Wren++.h"
2-
#include <cstdlib> // for malloc
3-
#include <cstring> // for strcmp, memcpy
2+
#include <cstdlib> // for malloc
3+
#include <cstring> // for strcmp, memcpy
44
#include <cassert>
55
#include <iostream>
66

77
namespace
88
{
9-
109
struct BoundState
1110
{
12-
std::unordered_map< std::size_t, WrenForeignMethodFn > methods{};
13-
std::unordered_map< std::size_t, WrenForeignClassMethods > classes{};
11+
std::unordered_map<std::size_t, WrenForeignMethodFn> methods{};
12+
std::unordered_map<std::size_t, WrenForeignClassMethods> classes{};
1413
};
1514

16-
WrenForeignMethodFn foreignMethodProvider(WrenVM* vm,
15+
WrenForeignMethodFn foreignMethodProvider(
16+
WrenVM* vm,
1717
const char* module,
1818
const char* className,
1919
bool isStatic,
2020
const char* signature)
2121
{
2222
auto* boundState = (BoundState*)wrenGetUserData(vm);
23-
auto it = boundState->methods.find(wrenpp::detail::hashMethodSignature(module, className, isStatic, signature));
23+
auto it = boundState->methods.find(
24+
wrenpp::detail::hashMethodSignature(module, className, isStatic, signature));
2425
if (it == boundState->methods.end())
2526
{
2627
return NULL;
@@ -35,7 +36,7 @@ WrenForeignClassMethods foreignClassProvider(WrenVM* vm, const char* m, const ch
3536
auto it = boundState->classes.find(wrenpp::detail::hashClassSignature(m, c));
3637
if (it == boundState->classes.end())
3738
{
38-
return WrenForeignClassMethods{ nullptr, nullptr };
39+
return WrenForeignClassMethods{nullptr, nullptr};
3940
}
4041

4142
return it->second;
@@ -45,22 +46,16 @@ inline const char* errorTypeToString(WrenErrorType type)
4546
{
4647
switch (type)
4748
{
48-
case WREN_ERROR_COMPILE: return "WREN_ERROR_COMPILE";
49-
case WREN_ERROR_RUNTIME: return "WREN_ERROR_RUNTIME";
50-
case WREN_ERROR_STACK_TRACE: return "WREN_ERROR_STACK_TRACE";
51-
default: assert(false); return "";
49+
case WREN_ERROR_COMPILE: return "WREN_ERROR_COMPILE";
50+
case WREN_ERROR_RUNTIME: return "WREN_ERROR_RUNTIME";
51+
case WREN_ERROR_STACK_TRACE: return "WREN_ERROR_STACK_TRACE";
52+
default: assert(false); return "";
5253
}
5354
}
5455

55-
char* loadModuleFnWrapper(WrenVM* vm, const char* mod)
56-
{
57-
return wrenpp::VM::loadModuleFn(mod);
58-
}
56+
char* loadModuleFnWrapper(WrenVM* vm, const char* mod) { return wrenpp::VM::loadModuleFn(mod); }
5957

60-
void writeFnWrapper(WrenVM* vm, const char* text)
61-
{
62-
wrenpp::VM::writeFn(text);
63-
}
58+
void writeFnWrapper(WrenVM* vm, const char* text) { wrenpp::VM::writeFn(text); }
6459

6560
void errorFnWrapper(WrenVM*, WrenErrorType type, const char* module, int line, const char* message)
6661
{
@@ -71,64 +66,51 @@ void* reallocateFnWrapper(void* memory, std::size_t newSize)
7166
{
7267
return wrenpp::VM::reallocateFn(memory, newSize);
7368
}
74-
75-
}
69+
} // namespace
7670

7771
namespace wrenpp
7872
{
79-
8073
namespace detail
8174
{
82-
void registerFunction(WrenVM* vm, const std::string& mod, const std::string& cName, bool isStatic, std::string sig, WrenForeignMethodFn function)
75+
void registerFunction(
76+
WrenVM* vm,
77+
const std::string& mod,
78+
const std::string& cName,
79+
bool isStatic,
80+
std::string sig,
81+
WrenForeignMethodFn function)
8382
{
8483
BoundState* boundState = (BoundState*)wrenGetUserData(vm);
85-
std::size_t hash = detail::hashMethodSignature(mod.c_str(), cName.c_str(), isStatic, sig.c_str());
84+
std::size_t hash =
85+
detail::hashMethodSignature(mod.c_str(), cName.c_str(), isStatic, sig.c_str());
8686
boundState->methods.insert(std::make_pair(hash, function));
8787
}
8888

89-
void registerClass(WrenVM* vm, const std::string& mod, std::string cName, WrenForeignClassMethods methods)
89+
void registerClass(
90+
WrenVM* vm,
91+
const std::string& mod,
92+
std::string cName,
93+
WrenForeignClassMethods methods)
9094
{
9195
BoundState* boundState = (BoundState*)wrenGetUserData(vm);
9296
std::size_t hash = detail::hashClassSignature(mod.c_str(), cName.c_str());
9397
boundState->classes.insert(std::make_pair(hash, methods));
9498
}
95-
96-
}
99+
} // namespace detail
97100

98101
Value null = Value();
99102

100-
Value::Value(bool val)
101-
: type_{ WREN_TYPE_BOOL }, string_{ nullptr }
102-
{
103-
set(val);
104-
}
103+
Value::Value(bool val) : type_{WREN_TYPE_BOOL}, string_{nullptr} { set(val); }
105104

106-
Value::Value(float val)
107-
: type_{ WREN_TYPE_NUM }, string_{ nullptr }
108-
{
109-
set(val);
110-
}
105+
Value::Value(float val) : type_{WREN_TYPE_NUM}, string_{nullptr} { set(val); }
111106

112-
Value::Value(double val)
113-
: type_{ WREN_TYPE_NUM }, string_{ nullptr }
114-
{
115-
set(val);
116-
}
107+
Value::Value(double val) : type_{WREN_TYPE_NUM}, string_{nullptr} { set(val); }
117108

118-
Value::Value(int val)
119-
: type_{ WREN_TYPE_NUM }, string_{ nullptr }
120-
{
121-
set(val);
122-
}
109+
Value::Value(int val) : type_{WREN_TYPE_NUM}, string_{nullptr} { set(val); }
123110

124-
Value::Value(unsigned int val)
125-
: type_{ WREN_TYPE_NUM }, string_{ nullptr }
126-
{
127-
set(val);
128-
}
111+
Value::Value(unsigned int val) : type_{WREN_TYPE_NUM}, string_{nullptr} { set(val); }
129112

130-
Value::Value(const char* str)
131-
: type_{ WREN_TYPE_STRING }, string_{ nullptr }
113+
Value::Value(const char* str) : type_{WREN_TYPE_STRING}, string_{nullptr}
132114
{
133115
string_ = (char*)VM::reallocateFn(nullptr, std::strlen(str) + 1);
134116
std::strcpy(string_, str);
@@ -143,15 +125,11 @@ Value::~Value()
143125
}
144126

145127
Method::Method(VM* vm, WrenHandle* variable, WrenHandle* method)
146-
: vm_(vm),
147-
method_(method),
148-
variable_(variable)
149-
{}
150-
151-
Method::Method(Method&& other)
152-
: vm_(other.vm_),
153-
method_(other.method_),
154-
variable_(other.variable_)
128+
: vm_(vm), method_(method), variable_(variable)
129+
{
130+
}
131+
132+
Method::Method(Method&& other) : vm_(other.vm_), method_(other.method_), variable_(other.variable_)
155133
{
156134
other.vm_ = nullptr;
157135
other.method_ = nullptr;
@@ -179,28 +157,22 @@ Method& Method::operator=(Method&& rhs)
179157
rhs.method_ = nullptr;
180158
rhs.variable_ = nullptr;
181159
}
182-
160+
183161
return *this;
184162
}
185163

186-
ClassContext ModuleContext::beginClass(std::string c)
187-
{
188-
return ClassContext(c, *this);
189-
}
164+
ClassContext ModuleContext::beginClass(std::string c) { return ClassContext(c, *this); }
190165

191166
void ModuleContext::endModule() {}
192167

193-
ModuleContext& ClassContext::endClass()
194-
{
195-
return module_;
196-
}
168+
ModuleContext& ClassContext::endClass() { return module_; }
197169

198-
ClassContext::ClassContext(std::string c, ModuleContext& mod)
199-
: module_(mod),
200-
class_(c)
201-
{}
170+
ClassContext::ClassContext(std::string c, ModuleContext& mod) : module_(mod), class_(c) {}
202171

203-
ClassContext& ClassContext::bindCFunction(bool isStatic, std::string signature, WrenForeignMethodFn function)
172+
ClassContext& ClassContext::bindCFunction(
173+
bool isStatic,
174+
std::string signature,
175+
WrenForeignMethodFn function)
204176
{
205177
detail::registerFunction(module_.vm_, module_.name_, class_, isStatic, signature, function);
206178
return *this;
@@ -211,8 +183,7 @@ ClassContext& ClassContext::bindCFunction(bool isStatic, std::string signature,
211183
* Uses malloc, because our reallocateFn is set to default:
212184
* it uses malloc, realloc and free.
213185
* */
214-
LoadModuleFn VM::loadModuleFn = [](const char* mod) -> char*
215-
{
186+
LoadModuleFn VM::loadModuleFn = [](const char* mod) -> char* {
216187
std::string path(mod);
217188
path += ".wren";
218189
std::string source;
@@ -230,17 +201,15 @@ LoadModuleFn VM::loadModuleFn = [](const char* mod) -> char*
230201
return buffer;
231202
};
232203

233-
WriteFn VM::writeFn = [](const char* text) -> void
234-
{
235-
std::cout << text;
236-
};
204+
WriteFn VM::writeFn = [](const char* text) -> void { std::cout << text; };
237205

238-
ErrorFn VM::errorFn = [](WrenErrorType type, const char* module_name, int line, const char* message) -> void
239-
{
206+
ErrorFn VM::errorFn =
207+
[](WrenErrorType type, const char* module_name, int line, const char* message) -> void {
240208
const char* typeStr = errorTypeToString(type);
241209
if (module_name)
242210
{
243-
std::cout << typeStr << " in " << module_name << ":" << line << "> " << message << std::endl;
211+
std::cout << typeStr << " in " << module_name << ":" << line << "> " << message
212+
<< std::endl;
244213
}
245214
else
246215
{
@@ -258,8 +227,7 @@ int VM::heapGrowthPercent = 50;
258227

259228
std::size_t VM::chunkSize = 0x500000u;
260229

261-
VM::VM()
262-
: vm_{ nullptr }
230+
VM::VM() : vm_{nullptr}
263231
{
264232
WrenConfiguration configuration{};
265233
wrenInitConfiguration(&configuration);
@@ -277,11 +245,7 @@ VM::VM()
277245
vm_ = wrenNewVM(&configuration);
278246
}
279247

280-
VM::VM(VM&& other)
281-
: vm_{ other.vm_ }
282-
{
283-
other.vm_ = nullptr;
284-
}
248+
VM::VM(VM&& other) : vm_{other.vm_} { other.vm_ = nullptr; }
285249

286250
VM& VM::operator=(VM&& rhs)
287251
{
@@ -337,16 +301,9 @@ Result VM::executeString(const std::string& code)
337301
return Result::Success;
338302
}
339303

340-
void VM::collectGarbage()
341-
{
342-
wrenCollectGarbage(vm_);
343-
}
304+
void VM::collectGarbage() { wrenCollectGarbage(vm_); }
344305

345-
Method VM::method(
346-
const std::string& mod,
347-
const std::string& var,
348-
const std::string& sig
349-
)
306+
Method VM::method(const std::string& mod, const std::string& var, const std::string& sig)
350307
{
351308
wrenEnsureSlots(vm_, 1);
352309
wrenGetVariable(vm_, mod.c_str(), var.c_str(), 0);
@@ -355,9 +312,5 @@ Method VM::method(
355312
return Method(this, variable, handle);
356313
}
357314

358-
ModuleContext VM::beginModule(std::string name)
359-
{
360-
return ModuleContext(vm_, name);
361-
}
362-
363-
}
315+
ModuleContext VM::beginModule(std::string name) { return ModuleContext(vm_, name); }
316+
} // namespace wrenpp

0 commit comments

Comments
 (0)