Skip to content

Commit 5aa1e30

Browse files
committedFeb 20, 2025
fixed wrong formatting ((char*)self)+Some.sizeof
1 parent 32b8153 commit 5aa1e30

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed
 

‎lib/c3tools/codefmt/_resolvers.c3

+11-5
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,8 @@ fn bool CodeFmt._resolve__prev_is_binexp(&self) @private
561561
bool has_type = false;
562562
bool has_idents = false;
563563
bool has_expr = false;
564+
bool has_typeof = false;
565+
bool has_vars = false;
564566

565567
TokenType rhs_token = INVALID_TOKEN;
566568

@@ -618,16 +620,19 @@ fn bool CodeFmt._resolve__prev_is_binexp(&self) @private
618620
case QUESTION: // for ternary
619621
if (scope == 0) break LOOP;
620622
has_expr = true;
621-
case INTEGER:
622623
case IDENT:
623624
case HASH_IDENT:
625+
has_vars = true;
626+
nextcase;
627+
case INTEGER:
624628
// is a binary expression sign
625629
// ident &
626630
// ident *
627631
// ident ^
628632
// ident + foo
629633
// ident - foo
630634
// indent[i]
635+
// ((char*)indent)
631636
switch (rhs_token) {
632637
case PLUS:
633638
case MINUS:
@@ -640,9 +645,11 @@ fn bool CodeFmt._resolve__prev_is_binexp(&self) @private
640645
break;
641646
}
642647
has_idents = true;
648+
case CT_TYPEOF:
649+
has_typeof = true;
650+
nextcase;
643651
case TYPE_IDENT:
644652
case CT_TYPE_IDENT:
645-
case CT_TYPEOF:
646653
has_type = true;
647654
case LVEC:
648655
case RVEC:
@@ -697,8 +704,7 @@ fn bool CodeFmt._resolve__prev_is_binexp(&self) @private
697704
// simple cast (void*)
698705
// generic cast (Foo(<void>)*) / array cast (char[8]*)
699706
if (has_type) {
700-
// return !has_idents || has_brackets;
701-
is_cast = true;
707+
if(has_typeof || !has_vars) is_cast = true;
702708
break;
703709
} else {
704710
break;
@@ -717,7 +723,7 @@ fn bool CodeFmt._resolve__prev_is_binexp(&self) @private
717723
}
718724
}
719725

720-
if (!has_parens && !has_type && !has_brackets && !has_idents) {
726+
if (!has_parens && !has_type && !has_brackets && (has_typeof || !has_idents)) {
721727
is_cast = true;
722728
}
723729
};

‎lib/c3tools/lsp/_symbols.c3

+7-6
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ struct SymbolItem @align(32)
4040
{
4141
uint name_offset : 0..31; // from the beginning of SymbolCache.data
4242
SymbolKind kind : 32..39; // kind of the symbol
43-
bool is_private: 40..40; // symbol contains @private attribute
44-
bool is_conditional: 41..41; // symbol contains @if() attribute
43+
bool is_private : 40..40; // symbol contains @private attribute
44+
bool is_conditional : 41..41; // symbol contains @if() attribute
4545
}
4646

4747
union ptr
@@ -113,6 +113,7 @@ macro SymbolItem* SymbolCache.first(&self, name_or_hash)
113113

114114
<*
115115
Returns next item with hash collision (if any)
116+
116117
@param [in] item "Item returned by previous SymbolCache.find()"
117118
@return "next item or null if not exist"
118119
@require item != null
@@ -239,8 +240,9 @@ struct SymbolItemIterator
239240
uint cursor;
240241
uint next_idx;
241242
}
242-
macro SymbolNameIterator SymbolCache.iter_names(&self) => SymbolNameIterator {.cache = self};
243-
macro SymbolItemIterator SymbolCache.iter_items(&self) => SymbolItemIterator {.cache = self};
243+
244+
macro SymbolNameIterator SymbolCache.iter_names(&self) => SymbolNameIterator { .cache = self };
245+
macro SymbolItemIterator SymbolCache.iter_items(&self) => SymbolItemIterator { .cache = self };
244246

245247
macro usz SymbolNameIterator.len(self) @operator(len) => self.cache.names_cnt;
246248
macro usz SymbolItemIterator.len(self) @operator(len) => self.cache.items_len;
@@ -254,7 +256,7 @@ macro String SymbolNameIterator.get(&self, usz idx) @operator([])
254256
uint cnt = names[i];
255257

256258
assert(cnt, "expected string len > 0");
257-
assert(names[i+1+cnt] == '\0', "no null terminator");
259+
assert(names[i + 1 + cnt] == '\0', "no null terminator");
258260

259261
self.cursor += cnt + 2; // 2 extra bytes for len and \0
260262
self.next_idx++;
@@ -269,7 +271,6 @@ macro SymbolItem* SymbolItemIterator.get(&self, usz idx) @operator(&[])
269271
return &items[idx];
270272
}
271273

272-
273274
<*
274275
Checks if SymbolCache has space for adding a new symbol
275276
*>

‎project.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"sources": [ "lib/**" ],
99
"test-sources": [ "test/**" ],
1010
"output": "build",
11-
//"exec": ["c3c compile-run c3fmt_gentests.c3 ../lib/**"],
11+
"exec": ["c3c compile-run c3fmt_gentests.c3 ../lib/**"],
1212
"targets": {
1313
"c3fmt": {
1414
"type": "executable",

0 commit comments

Comments
 (0)
Please sign in to comment.