Update .clang-format for my fickle tastes
This commit is contained in:
+13
-1
@@ -16,6 +16,9 @@ ColumnLimit: 0
|
|||||||
IndentWidth: 4
|
IndentWidth: 4
|
||||||
ConstructorInitializerIndentWidth: 4
|
ConstructorInitializerIndentWidth: 4
|
||||||
ContinuationIndentWidth: 4
|
ContinuationIndentWidth: 4
|
||||||
|
IndentGotoLabels: true
|
||||||
|
IndentPPDirectives: BeforeHash
|
||||||
|
IndentCaseLabels: false
|
||||||
|
|
||||||
# Alignment checks
|
# Alignment checks
|
||||||
AlignAfterOpenBracket: false
|
AlignAfterOpenBracket: false
|
||||||
@@ -70,6 +73,9 @@ BraceWrapping:
|
|||||||
|
|
||||||
# Don't break before ?:, it looks ugly
|
# Don't break before ?:, it looks ugly
|
||||||
BreakBeforeTernaryOperators: false
|
BreakBeforeTernaryOperators: false
|
||||||
|
BreakConstructorInitializers: AfterColon
|
||||||
|
BreakInheritanceList: AfterColon
|
||||||
|
BreakAfterAttributes: Leave
|
||||||
|
|
||||||
# Trim empty lines when there are more than 1
|
# Trim empty lines when there are more than 1
|
||||||
MaxEmptyLinesToKeep: 2
|
MaxEmptyLinesToKeep: 2
|
||||||
@@ -89,7 +95,12 @@ SpaceAfterTemplateKeyword: true
|
|||||||
# Put spaces before \.?\= operators, initializer {lists}, inline (parentheses), // comments.
|
# Put spaces before \.?\= operators, initializer {lists}, inline (parentheses), // comments.
|
||||||
SpaceBeforeAssignmentOperators: true
|
SpaceBeforeAssignmentOperators: true
|
||||||
SpaceBeforeCpp11BracedList: true
|
SpaceBeforeCpp11BracedList: true
|
||||||
SpaceBeforeParens: Always
|
SpaceBeforeParens: Custom
|
||||||
|
SpaceBeforeParensOptions:
|
||||||
|
AfterControlStatements: true
|
||||||
|
AfterFunctionDeclarationName: true
|
||||||
|
AfterFunctionDefinitionName: true
|
||||||
|
AfterOverloadedOperator: true
|
||||||
SpacesBeforeTrailingComments: 1
|
SpacesBeforeTrailingComments: 1
|
||||||
SpacesInLineCommentPrefix:
|
SpacesInLineCommentPrefix:
|
||||||
Minimum: 1
|
Minimum: 1
|
||||||
@@ -97,6 +108,7 @@ SpacesInLineCommentPrefix:
|
|||||||
# for (auto& loops : range), conditional ( statements ), ( parentheses ), [ brackets ]
|
# for (auto& loops : range), conditional ( statements ), ( parentheses ), [ brackets ]
|
||||||
SpaceBeforeCaseColon: false
|
SpaceBeforeCaseColon: false
|
||||||
SpaceBeforeInheritanceColon: false
|
SpaceBeforeInheritanceColon: false
|
||||||
|
SpaceBeforeCtorInitializerColon: false
|
||||||
SpaceBeforeRangeBasedForLoopColon: false
|
SpaceBeforeRangeBasedForLoopColon: false
|
||||||
SpacesInConditionalStatement: false
|
SpacesInConditionalStatement: false
|
||||||
SpacesInParentheses: false
|
SpacesInParentheses: false
|
||||||
|
|||||||
+10
-10
@@ -26,20 +26,20 @@
|
|||||||
#define RUSTPP_UNIQ(name) RUSTPP_UNIQ_(name, __LINE__)
|
#define RUSTPP_UNIQ(name) RUSTPP_UNIQ_(name, __LINE__)
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
||||||
#define rustpp_for(value, iter) \
|
#define rustpp_for(value, iter) \
|
||||||
if (auto RUSTPP_UNIQ (iterator) = iter.into_iter (); auto RUSTPP_UNIQ (opt) = RUSTPP_UNIQ (iterator).next ()) \
|
if (auto RUSTPP_UNIQ(iterator) = iter.into_iter(); auto RUSTPP_UNIQ(opt) = RUSTPP_UNIQ(iterator).next()) \
|
||||||
for (auto value = RUSTPP_UNIQ (opt).unwrap_unchecked (); \
|
for (auto value = RUSTPP_UNIQ(opt).unwrap_unchecked(); \
|
||||||
RUSTPP_UNIQ (opt).is_some (); \
|
RUSTPP_UNIQ(opt).is_some(); \
|
||||||
RUSTPP_UNIQ (opt) = RUSTPP_UNIQ (iterator).next (), value = RUSTPP_UNIQ (opt).unwrap_unchecked ())
|
RUSTPP_UNIQ(opt) = RUSTPP_UNIQ(iterator).next(), value = RUSTPP_UNIQ(opt).unwrap_unchecked())
|
||||||
|
|
||||||
|
|
||||||
#ifndef I_AM_RUSTPP_RUNTIME
|
#ifndef I_AM_RUSTPP_RUNTIME
|
||||||
|
|
||||||
#define main rustpp__main
|
#define main rustpp__main
|
||||||
#define new rustpp__new
|
#define new rustpp__new
|
||||||
|
|
||||||
#ifndef NO_RUSTPP_FOR
|
#ifndef NO_RUSTPP_FOR
|
||||||
#define for(...) rustpp_for (__VA_ARGS__)
|
#define for(...) rustpp_for(__VA_ARGS__)
|
||||||
#endif /* NO_RUSTPP_FOR */
|
#endif /* NO_RUSTPP_FOR */
|
||||||
|
|
||||||
#endif /* I_AM_RUSTPP_RUNTIME */
|
#endif /* I_AM_RUSTPP_RUNTIME */
|
||||||
|
|||||||
@@ -11,18 +11,19 @@ namespace panic {
|
|||||||
public:
|
public:
|
||||||
// std::stacktrace stack;
|
// std::stacktrace stack;
|
||||||
std::string message;
|
std::string message;
|
||||||
Panic (std::string message) : message (message) {
|
Panic (std::string message):
|
||||||
|
message(message) {
|
||||||
// stack = std::stacktrace::current();
|
// stack = std::stacktrace::current();
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr const char *what () {
|
constexpr const char *what () {
|
||||||
return message.c_str ();
|
return message.c_str();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} // namespace panic
|
} // namespace panic
|
||||||
|
|
||||||
|
|
||||||
#define panic(...) \
|
#define panic(...) \
|
||||||
do { \
|
do { \
|
||||||
throw panic::Panic { std::format (__VA_ARGS__) }; \
|
throw panic::Panic { std::format(__VA_ARGS__) }; \
|
||||||
} while (false)
|
} while (false)
|
||||||
|
|||||||
+67
-64
@@ -53,7 +53,7 @@ mod option {
|
|||||||
}
|
}
|
||||||
|
|
||||||
operator bool () {
|
operator bool () {
|
||||||
return this->is_some ();
|
return this->is_some();
|
||||||
}
|
}
|
||||||
|
|
||||||
operator i32 () {
|
operator i32 () {
|
||||||
@@ -65,17 +65,17 @@ mod option {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn unwrap () -> T {
|
fn unwrap () -> T {
|
||||||
match (variant) {
|
match(variant) {
|
||||||
arm (variant::Some, return value.Some);
|
arm(variant::Some, return value.Some);
|
||||||
arm (variant::None, panic ("Called Option::unwrap() on a None value"));
|
arm(variant::None, panic("Called Option::unwrap() on a None value"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename U>
|
template <typename U>
|
||||||
fn map (U (f) (T)) -> Option<U> {
|
fn map (U(f)(T)) -> Option<U> {
|
||||||
match (variant) {
|
match(variant) {
|
||||||
arm (variant::Some, return Some (f (value.Some)));
|
arm(variant::Some, return Some(f(value.Some)));
|
||||||
arm (variant::None, return None<U> ());
|
arm(variant::None, return None<U>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -84,14 +84,14 @@ mod option {
|
|||||||
///
|
///
|
||||||
/// Takes an optional (never-dereferenced) pointer argument, for type inference.
|
/// Takes an optional (never-dereferenced) pointer argument, for type inference.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
fn None (T *_type = (T *) (0)) -> Option<T> {
|
fn None(T *_type = (T *) (0)) -> Option<T> {
|
||||||
return Option<T>::None ();
|
return Option<T>::None();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Constructs an option with `variant` Some
|
/// Constructs an option with `variant` Some
|
||||||
template <typename T>
|
template <typename T>
|
||||||
fn Some (T value) -> Option<T> {
|
fn Some(T value) -> Option<T> {
|
||||||
return Option<T>::Some (value);
|
return Option<T>::Some(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,44 +139,44 @@ mod result {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn ok () -> option::Option<T> {
|
fn ok () -> option::Option<T> {
|
||||||
match (variant) {
|
match(variant) {
|
||||||
arm (variant::Ok, return option::Some (value.Ok));
|
arm(variant::Ok, return option::Some(value.Ok));
|
||||||
arm (variant::Err, return option::None<T> ());
|
arm(variant::Err, return option::None<T>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn err () -> option::Option<E> {
|
fn err () -> option::Option<E> {
|
||||||
match (variant) {
|
match(variant) {
|
||||||
arm (variant::Err, return option::Some (value.Err));
|
arm(variant::Err, return option::Some(value.Err));
|
||||||
arm (variant::Ok, return option::None<T> ());
|
arm(variant::Ok, return option::None<T>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn unwrap () -> T {
|
fn unwrap () -> T {
|
||||||
match (variant) {
|
match(variant) {
|
||||||
arm (variant::Ok, return value.Ok);
|
arm(variant::Ok, return value.Ok);
|
||||||
arm (variant::Err, panic ("Called Result::unwrap() on Err value"));
|
arm(variant::Err, panic("Called Result::unwrap() on Err value"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn unwrap_err () -> E {
|
fn unwrap_err () -> E {
|
||||||
match (variant) {
|
match(variant) {
|
||||||
arm (variant::Ok, panic ("Called Result::unwrap_err() on Ok value"));
|
arm(variant::Ok, panic("Called Result::unwrap_err() on Ok value"));
|
||||||
arm (variant::Err, return value.Err);
|
arm(variant::Err, return value.Err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Constructs a Result with variant Err and value `Err(value)`
|
/// Constructs a Result with variant Err and value `Err(value)`
|
||||||
template <typename T, typename E>
|
template <typename T, typename E>
|
||||||
fn Err (E error) -> Result<T, E> {
|
fn Err(E error) -> Result<T, E> {
|
||||||
return Result<T, E>::Err (error);
|
return Result<T, E>::Err(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Constructs a Result with variant Ok and value `Ok(value)`
|
/// Constructs a Result with variant Ok and value `Ok(value)`
|
||||||
template <typename T, typename E>
|
template <typename T, typename E>
|
||||||
fn Ok (T value) -> Result<T, E> {
|
fn Ok(T value) -> Result<T, E> {
|
||||||
return Result<T, E>::Ok (value);
|
return Result<T, E>::Ok(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,9 +188,9 @@ mod ptr {
|
|||||||
|
|
||||||
static fn rustpp__new (T *value) -> option::Option<Self> {
|
static fn rustpp__new (T *value) -> option::Option<Self> {
|
||||||
if (value) {
|
if (value) {
|
||||||
return option::Some ((Self) { value });
|
return option::Some((Self) { value });
|
||||||
} else {
|
} else {
|
||||||
return option::None<Self> ();
|
return option::None<Self>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,17 +200,17 @@ mod ptr {
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
fn nonnull (T * value) -> option::Option<Nonnull<T>> {
|
fn nonnull(T * value) -> option::Option<Nonnull<T>> {
|
||||||
switch (value) {
|
switch (value) {
|
||||||
case nullptr:
|
case nullptr:
|
||||||
return option::Some (value);
|
return option::Some(value);
|
||||||
default:
|
default:
|
||||||
return option::None (&value);
|
return option::None(&value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
fn nonnull_unchecked (T * value) -> Nonnull<T> {
|
fn nonnull_unchecked(T * value) -> Nonnull<T> {
|
||||||
return { value };
|
return { value };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -230,8 +230,9 @@ mod slice {
|
|||||||
T *head;
|
T *head;
|
||||||
T *tail;
|
T *tail;
|
||||||
|
|
||||||
Iter (T *head, T *tail) : head (head),
|
Iter (T *head, T *tail):
|
||||||
tail (tail) {}
|
head(head),
|
||||||
|
tail(tail) {}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
makeSelf (Iter<T>);
|
makeSelf (Iter<T>);
|
||||||
@@ -242,9 +243,9 @@ mod slice {
|
|||||||
|
|
||||||
fn next () -> option::Option<ptr::Nonnull<T>> override {
|
fn next () -> option::Option<ptr::Nonnull<T>> override {
|
||||||
if (head < tail)
|
if (head < tail)
|
||||||
return ptr::Nonnull<T>::rustpp__new (head++);
|
return ptr::Nonnull<T>::rustpp__new(head++);
|
||||||
else
|
else
|
||||||
return option::None<ptr::Nonnull<T>> ();
|
return option::None<ptr::Nonnull<T>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn into_iter () -> Self & {
|
fn into_iter () -> Self & {
|
||||||
@@ -259,7 +260,7 @@ mod slice {
|
|||||||
|
|
||||||
makeSelf (Slice<T>);
|
makeSelf (Slice<T>);
|
||||||
fn into_iter () -> Iter<T> {
|
fn into_iter () -> Iter<T> {
|
||||||
return Iter<T>::rustpp__new (self.ptr, self.len);
|
return Iter<T>::rustpp__new(self.ptr, self.len);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -273,26 +274,28 @@ mod vec {
|
|||||||
T *tail;
|
T *tail;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Drain () : allocation (nullptr),
|
Drain ():
|
||||||
head (nullptr),
|
allocation(nullptr),
|
||||||
tail (nullptr) {}
|
head(nullptr),
|
||||||
Drain (T *allocation, usize len) : allocation (allocation),
|
tail(nullptr) {}
|
||||||
head (allocation),
|
Drain (T *allocation, usize len):
|
||||||
tail (allocation + len) {}
|
allocation(allocation),
|
||||||
|
head(allocation),
|
||||||
|
tail(allocation + len) {}
|
||||||
~Drain () {
|
~Drain () {
|
||||||
free (allocation);
|
free(allocation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn next () -> option::Option<T> override {
|
fn next () -> option::Option<T> override {
|
||||||
if (head < tail) {
|
if (head < tail) {
|
||||||
return option::Some (*head++);
|
return option::Some(*head++);
|
||||||
}
|
}
|
||||||
if (allocation) {
|
if (allocation) {
|
||||||
free (allocation);
|
free(allocation);
|
||||||
allocation = nullptr;
|
allocation = nullptr;
|
||||||
}
|
}
|
||||||
return option::None<T> ();
|
return option::None<T>();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -310,9 +313,9 @@ mod vec {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn resize (usize cap) -> usize {
|
fn resize (usize cap) -> usize {
|
||||||
ptr = (T *) realloc ((void *) ptr, cap);
|
ptr = (T *) realloc((void *) ptr, cap);
|
||||||
if (!ptr) {
|
if (!ptr) {
|
||||||
panic ("Failed to resize Vec from {} to {}.", self.cap, cap);
|
panic("Failed to resize Vec from {} to {}.", self.cap, cap);
|
||||||
}
|
}
|
||||||
self.cap = cap;
|
self.cap = cap;
|
||||||
return self.cap;
|
return self.cap;
|
||||||
@@ -320,31 +323,31 @@ mod vec {
|
|||||||
|
|
||||||
fn _grow () -> usize {
|
fn _grow () -> usize {
|
||||||
switch (len) {
|
switch (len) {
|
||||||
case 0:
|
case 0:
|
||||||
return self.resize (8);
|
return self.resize(8);
|
||||||
default:
|
default:
|
||||||
return self.resize ((cap << 1) - cap);
|
return self.resize((cap << 1) - cap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn drop () {
|
fn drop () {
|
||||||
free (ptr);
|
free(ptr);
|
||||||
self = {};
|
self = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn push (T value) {
|
fn push (T value) {
|
||||||
self._grow ();
|
self._grow();
|
||||||
ptr[len++] = value;
|
ptr[len++] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pop () -> option::Option<T> {
|
fn pop () -> option::Option<T> {
|
||||||
use option::Some, option::None;
|
use option::Some, option::None;
|
||||||
if (len == 0) {
|
if (len == 0) {
|
||||||
return None (ptr);
|
return None(ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
let value = ptr[--len];
|
let value = ptr[--len];
|
||||||
return Some (value);
|
return Some(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn as_slice () -> slice::Slice<T> {
|
fn as_slice () -> slice::Slice<T> {
|
||||||
@@ -352,11 +355,11 @@ mod vec {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn iter () -> slice::Iter<T> {
|
fn iter () -> slice::Iter<T> {
|
||||||
return self.as_slice ().into_iter ();
|
return self.as_slice().into_iter();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn into_iter () -> Drain<T> {
|
fn into_iter () -> Drain<T> {
|
||||||
let drain = Drain<T> (self.ptr, self.len);
|
let drain = Drain<T>(self.ptr, self.len);
|
||||||
self = {};
|
self = {};
|
||||||
return drain;
|
return drain;
|
||||||
}
|
}
|
||||||
@@ -365,7 +368,7 @@ mod vec {
|
|||||||
|
|
||||||
mod env {
|
mod env {
|
||||||
/// Gets the environment variables
|
/// Gets the environment variables
|
||||||
fn args () -> slice::Slice<Cstr>;
|
fn args() -> slice::Slice<Cstr>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+9
-9
@@ -6,20 +6,20 @@
|
|||||||
fn main () -> i32 {
|
fn main () -> i32 {
|
||||||
let v = vec::Vec<i32>::new ();
|
let v = vec::Vec<i32>::new ();
|
||||||
|
|
||||||
v.push (10);
|
v.push(10);
|
||||||
v.push (20);
|
v.push(20);
|
||||||
v.push (30);
|
v.push(30);
|
||||||
|
|
||||||
std::println ("Printing contents of v by reference");
|
std::println("Printing contents of v by reference");
|
||||||
for (x, v.iter ()) {
|
for (x, v.iter()) {
|
||||||
std::println ("{}", *x);
|
std::println("{}", *x);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is okay, because the previous for loop borrowed v
|
// This is okay, because the previous for loop borrowed v
|
||||||
std::println ("Printing contents of v by value");
|
std::println("Printing contents of v by value");
|
||||||
for (x, v) {
|
for (x, v) {
|
||||||
std::println ("{}", x);
|
std::println("{}", x);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Err<int, const char *> ("Oops!");
|
return Err<int, const char *>("Oops!");
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -14,9 +14,9 @@ fn main (int argc, char **argv) -> int {
|
|||||||
int exitcode = 0;
|
int exitcode = 0;
|
||||||
program_args = { (Cstr *) argv, (usize) argc };
|
program_args = { (Cstr *) argv, (usize) argc };
|
||||||
try {
|
try {
|
||||||
exitcode = rustpp__main ();
|
exitcode = rustpp__main();
|
||||||
} catch (panic::Panic p) {
|
} catch (panic::Panic p) {
|
||||||
std::println ("Thread exited with explicit panic: {}", p.what ());
|
std::println("Thread exited with explicit panic: {}", p.what());
|
||||||
exitcode = -1;
|
exitcode = -1;
|
||||||
}
|
}
|
||||||
return exitcode;
|
return exitcode;
|
||||||
|
|||||||
Reference in New Issue
Block a user