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