Skip to content

Commit eaed3cd

Browse files
committed
Merge origin/main into fix/objectscript-empty-deserialize
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
2 parents cd368ce + a74d528 commit eaed3cd

16 files changed

Lines changed: 1266 additions & 151 deletions

‎Makefile.cbm‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1386,6 +1386,7 @@ LLVM_BIN := $(shell brew --prefix llvm 2>/dev/null)/bin
13861386
CLANG_TIDY ?= $(shell [ -x "$(LLVM_BIN)/clang-tidy" ] && echo "$(LLVM_BIN)/clang-tidy" || echo clang-tidy)
13871387
CLANG_FORMAT ?= $(shell [ -x "$(LLVM_BIN)/clang-format" ] && echo "$(LLVM_BIN)/clang-format" || echo clang-format)
13881388
CPPCHECK ?= cppcheck
1389+
CPPCHECK_JOBS ?= 2
13891390

13901391
# macOS SDK sysroot (needed for Homebrew LLVM to find system headers)
13911392
SYSROOT = $(shell xcrun --show-sdk-path 2>/dev/null)
@@ -1410,10 +1411,16 @@ lint-tidy:
14101411
lint-tidy-diff:
14111412
@scripts/lint-tidy-diff.sh "$(CLANG_TIDY)" $(LINT_SRCS) -- $(CFLAGS_COMMON) $(SYSROOT_FLAG)
14121413

1413-
# cppcheck: complementary analysis (config in .cppcheck)
1414+
# cppcheck: complementary analysis (config in .cppcheck). A build directory
1415+
# retains whole-program analysis with parallel workers; each run owns its state.
14141416
lint-cppcheck:
14151417
@echo "=== cppcheck ==="
1416-
@$(CPPCHECK) --enable=warning,style,performance,portability \
1418+
@set -e; \
1419+
cppcheck_dir=$$(mktemp -d "$${TMPDIR:-/tmp}/cbm-cppcheck.XXXXXX"); \
1420+
trap 'status=$$?; rm -rf "$$cppcheck_dir" || :; exit "$$status"' EXIT; \
1421+
trap 'exit 129' HUP; trap 'exit 130' INT; trap 'exit 143' TERM; \
1422+
$(CPPCHECK) -j$(CPPCHECK_JOBS) --cppcheck-build-dir="$$cppcheck_dir" \
1423+
--enable=warning,style,performance,portability \
14171424
--std=c11 --language=c \
14181425
--suppressions-list=.cppcheck \
14191426
--error-exitcode=1 \

‎internal/cbm/extract_defs.c‎

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8923,6 +8923,68 @@ static void extract_objc_impl_methods(CBMExtractCtx *ctx, TSNode impl_node, cons
89238923
}
89248924
}
89258925

8926+
/* True for a C# 14 extension block. The vendored tree-sitter-c-sharp has no
8927+
* `extension` production, so `extension(string text) { ... }` parses as a
8928+
* constructor_declaration named `extension` and nothing flags it: has_error
8929+
* stays 0. A constructor carries its own type's name, so this shape can only be
8930+
* a genuine constructor inside a type literally called `extension` (#2071). */
8931+
static bool csharp_is_extension_block(TSNode node, TSNode class_node, const char *source) {
8932+
if (strcmp(ts_node_type(node), "constructor_declaration") != 0) {
8933+
return false;
8934+
}
8935+
TSNode name = resolve_method_name(node, CBM_LANG_CSHARP);
8936+
if (ts_node_is_null(name)) {
8937+
return false;
8938+
}
8939+
const size_t kw_len = sizeof("extension") - 1;
8940+
uint32_t len = ts_node_end_byte(name) - ts_node_start_byte(name);
8941+
if (len != kw_len || strncmp(source + ts_node_start_byte(name), "extension", kw_len) != 0) {
8942+
return false;
8943+
}
8944+
TSNode type_name = ts_node_child_by_field_name(class_node, TS_FIELD("name"));
8945+
if (!ts_node_is_null(type_name)) {
8946+
const char *type_text = source + ts_node_start_byte(type_name);
8947+
uint32_t tlen = ts_node_end_byte(type_name) - ts_node_start_byte(type_name);
8948+
/* A verbatim identifier names the same type: class @extension may
8949+
* declare a genuine constructor spelled extension(). */
8950+
if (tlen > 0 && type_text[0] == '@') {
8951+
type_text++;
8952+
tlen--;
8953+
}
8954+
if (tlen == kw_len && strncmp(type_text, "extension", kw_len) == 0) {
8955+
return false;
8956+
}
8957+
}
8958+
return true;
8959+
}
8960+
8961+
/* Lift the members of a misparsed C# 14 extension block onto the enclosing
8962+
* type. They sit in the block the grammar took for a constructor body, which
8963+
* nothing recurses into, so every one of them was dropped. Methods land there
8964+
* as local_function_statement; a property in the block parses as ERROR and is
8965+
* beyond recovery without a grammar that knows the construct (#2071). */
8966+
static void extract_csharp_extension_members(CBMExtractCtx *ctx, TSNode ext_node, TSNode class_node,
8967+
const char *class_qn, const CBMLangSpec *spec) {
8968+
TSNode body = cbm_find_child_by_kind(ext_node, "block");
8969+
if (ts_node_is_null(body)) {
8970+
return;
8971+
}
8972+
member_iter_t it;
8973+
member_iter_init(&it, body, ctx->language, false);
8974+
TSNode member;
8975+
while (member_iter_next(&it, &member)) {
8976+
if (strcmp(ts_node_type(member), "local_function_statement") != 0) {
8977+
continue;
8978+
}
8979+
TSNode name = resolve_method_name(member, ctx->language);
8980+
if (ts_node_is_null(name)) {
8981+
continue;
8982+
}
8983+
push_method_def(ctx, member, class_node, class_qn, spec, name);
8984+
}
8985+
member_iter_done(&it);
8986+
}
8987+
89268988
// Extract methods inside a class body
89278989
static void extract_class_methods(CBMExtractCtx *ctx, TSNode class_node, const char *class_qn,
89288990
const CBMLangSpec *spec) {
@@ -8936,6 +8998,15 @@ static void extract_class_methods(CBMExtractCtx *ctx, TSNode class_node, const c
89368998
TSNode child;
89378999
while (member_iter_next(&it, &child)) {
89389000

9001+
/* C# 14 extension block: emit the members it holds as methods of the
9002+
* enclosing type, rather than the block itself as a constructor named
9003+
* `extension` with its members buried in the body (#2071). */
9004+
if (ctx->language == CBM_LANG_CSHARP &&
9005+
csharp_is_extension_block(child, class_node, ctx->source)) {
9006+
extract_csharp_extension_members(ctx, child, class_node, class_qn, spec);
9007+
continue;
9008+
}
9009+
89399010
if (ctx->language == CBM_LANG_OBJC &&
89409011
strcmp(ts_node_type(child), "implementation_definition") == 0) {
89419012
extract_objc_impl_methods(ctx, child, class_qn, spec);

0 commit comments

Comments
 (0)