Skip to content

Commit 7ecc6cd

Browse files
UvuvDevclaude
andcommitted
Move Function::GetComplexity implementation into the core, add Rust bindings
Function::GetComplexity/GetComplexityMetricNames now call through new BNGetFunctionComplexity/BNGetFunctionComplexityMetricNames C API functions instead of each language binding reimplementing the metric engine independently - the core is now the single canonical C/C++ implementation. Also adds "code_references" (count of code cross-references to a function - the complement of fan_out) to the core implementation, and adds Rust bindings (Function::complexity/complexity_metric_names) that go through the same C API. The standalone complexity.cpp in this repo is removed since its logic moved into the core; the C++ wrapper in function.cpp now validates the metric name client-side before calling into the core, since the C ABI boundary can't let an unrecognized-metric exception cross into other language bindings (notably Rust). Validated directly: a full incremental build of the real Binary Ninja core links successfully with the new BNGetFunctionComplexity/ BNGetFunctionComplexityMetricNames symbols correctly exported: nm confirms both. The updated C++ wrapper in function.cpp syntax-checks cleanly against the new declarations, and `cargo check` on the Rust crate passes with bindgen picking up the new C API automatically. Corresponding core changes (core/complexity.cpp, a small addition to core/function.h) live in the separate, private binaryninja core repo and aren't part of this PR - flagging here since this PR's C++/Rust code won't link without them. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
1 parent 8662f74 commit 7ecc6cd

4 files changed

Lines changed: 79 additions & 490 deletions

File tree

‎binaryninjacore.h‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6025,6 +6025,17 @@ extern "C"
60256025
BINARYNINJACOREAPI BNLanguageRepresentationFunction* BNGetFunctionLanguageRepresentationIfAvailable(
60266026
BNFunction* func, const char* language);
60276027

6028+
// Computes a code complexity score for `func` using the named metric (e.g. "composite",
6029+
// "cyclomatic", "transitive", ...) - see BNGetFunctionComplexityMetricNames for the full,
6030+
// current list. Returns 0.0 (and logs) for an unrecognized metric name rather than raising
6031+
// across the C ABI boundary; callers are expected to validate `metric` against
6032+
// BNGetFunctionComplexityMetricNames themselves first if they want to surface that as their
6033+
// own idiomatic error.
6034+
BINARYNINJACOREAPI double BNGetFunctionComplexity(BNFunction* func, const char* metric);
6035+
// Names accepted by BNGetFunctionComplexity's `metric` parameter. Free the result with
6036+
// BNFreeStringList.
6037+
BINARYNINJACOREAPI char** BNGetFunctionComplexityMetricNames(size_t* count);
6038+
60286039
BINARYNINJACOREAPI BNDataBuffer* BNGetConstantData(BNFunction* func, BNRegisterValueType state, uint64_t value,
60296040
size_t size, BNBuiltinType* builtin);
60306041

0 commit comments

Comments
 (0)