diff --git a/Misc/CoreUtils.cs b/Misc/CoreUtils.cs index f7fd0f5..1d73df1 100644 --- a/Misc/CoreUtils.cs +++ b/Misc/CoreUtils.cs @@ -731,9 +731,55 @@ public static string RustSimplifyStrToStr(string name) ); } - // NOTE: BNRustSimplifyStrToFQN uses sret (struct return) calling convention - // which makes the P/Invoke binding non-trivial. Use RustSimplifyStrToStr - // for simple string simplification instead. + /// + /// Simplifies a templated C++ name to a qualified name, mirroring Python + /// demangle.simplify_name_to_qualified_name (demangle.py:253). This can also tokenize a + /// string to a qualified name without simplifying. Returns null when the simplifier + /// yields no components. + /// + /// The name to simplify. + /// Whether to simplify the name; defaults to true. + /// The simplified qualified name, or null if the result is empty. + public static QualifiedName? SimplifyNameToQualifiedName(string inputName, bool simplify = true) + { + if (null == inputName) + { + throw new ArgumentNullException(nameof(inputName)); + } + + // BNRustSimplifyStrToFQN returns a BNQualifiedName by value. The struct is blittable + // (two IntPtrs + a ulong), so the P/Invoke marshaller handles the struct-return (sret) + // ABI directly -- the same pattern as BNTypeBuilderGetStructureName. TakeNative reads the + // components eagerly then frees the native array the core allocated. + QualifiedName result = QualifiedName.TakeNative( + NativeMethods.BNRustSimplifyStrToFQN(inputName, simplify) + ); + + if (0 == result.Name.Length) + { + return null; + } + + return result; + } + + /// + /// Simplifies an already-tokenized qualified name, mirroring Python + /// demangle.simplify_name_to_qualified_name for QualifiedName input + /// (demangle.py:267). Python forces simplification for qualified-name input, so + /// is always simplified. + /// + /// The qualified name to simplify. + /// The simplified qualified name, or null if the result is empty. + public static QualifiedName? SimplifyNameToQualifiedName(QualifiedName inputName) + { + if (null == inputName) + { + throw new ArgumentNullException(nameof(inputName)); + } + + return Core.SimplifyNameToQualifiedName(inputName.ToString(), true); + } /// /// Compute a fuzzy match score between a target string and a query. @@ -1170,10 +1216,6 @@ public static unsafe string[] ParseTypeParserOptionsText(string optionsText) // TODO: BNRenderLinesForData / BNGetLinesForData — complex callback-based renderer // with custom data renderer context callback parameters. - // TODO: BNRustSimplifyStrToFQN — uses sret ABI (struct return by hidden pointer). - // The BNQualifiedName return value is passed as a hidden first parameter; - // requires special P/Invoke marshalling or a C wrapper to implement correctly. - // TODO: BNAppendSymbolQueue / BNProcessSymbolQueue — internal callback-based // symbol resolution pipeline. Requires managed delegate infrastructure.