Embrace Whitespace
Icy lets you skip closing braces and semicolons by applying indentation based deduction rules. Therefore letting you write:
void BFCAllocator::SetSafeFrontier(uint64 count) {
uint64 current = safe_frontier_.load(std::memory_order_relaxed)
while (count > current) {
if (safe_frontier_.compare_exchange_strong(current, count)) {
retry_helper_.NotifyDealloc()
return
else {
current = safe_frontier_.load(std::memory_order_relaxed)
instead of:
void BFCAllocator::SetSafeFrontier(uint64 count) {
uint64 current = safe_frontier_.load(std::memory_order_relaxed);
while (count > current) {
if (safe_frontier_.compare_exchange_strong(current, count)) {
retry_helper_.NotifyDealloc();
return;
} else {
current = safe_frontier_.load(std::memory_order_relaxed);
}
}
}
- Strings, comments, trailing whitespace and empty lines are ignored.
- If next line has higher indentation, both lines are treated as same logical line.
-
ScopeExitGuard(const bool callOnScopeExit_, F &&onScopeExit_, m_callOnScopeExit(callOnScopeExit_), m_onScopeExit(std::forward<F>(onScopeExit_))
-
- If a line ends with an opening brace and next line has exactly one level higher indentation, it marks the start of a block.
-
namespace guard { // Not a block. Must close manually if (m_callOnScopeExit) { // Block m_onScopeExit() std::cout << "Enter" // Block closed
-
- The line after the next logical line having indentation equal or lower than the block's start, marks the end of the block.
-
ScopeExitGuard(ScopeExitGuard<G> &&other) : m_callOnScopeExit(true) { // Block start at logical line's indent 0 other.m_callOnScopeExit = false ~ScopeExitGuard() { // Previous block ends if (m_callOnScopeExit) { m_onScopeExit()
-
- If a logical line has indentation equal or greater than the next line, it is treated as a statement and appended with a semi-colon.
- The line must not end with
{ ; , : < ( [ =
. - Exception for isolated template declarations.
-
template <typename G> // Not a statement ScopeExitGuard(ScopeExitGuard<G> &&other) : m_callOnScopeExit(true) { other.m_callOnScopeExit = false // Statement std::cout << "Exit" // Statement auto flags = {1, 2, 3}
-
- The line must not end with
- Icy can seamlessly integrated with existing C++ tooling since the brace and semi-colon addition is done only on the line ends which preserves line and column numbers. TODO: Extensions for popular editors. Should be trivial.
- Decompilation with
icyd
involves clang-format with following configuration.Closing braces and semi-colons are removed if Icy compilerLambdaBodyIndentation: Signature IndentGotoLabels: true IndentExternBlock: Indent BreakBeforeBraces: Attach AllowAllArgumentsOnNextLine: false Cpp11BracedListStyle: false IndentRequires: true IndentWrappedFunctionNames: true NamespaceIndentation: All UseTab: Never CompactNamespaces: false
icyc
can deduce them from the indentation of formatted code.
There have been a few attempts at trimming the C++ syntax but have ended up being too disruptive.