diff --git a/gitgalaxy/core/detector.py b/gitgalaxy/core/detector.py index 5b12a3627..166ad6d66 100644 --- a/gitgalaxy/core/detector.py +++ b/gitgalaxy/core/detector.py @@ -4445,7 +4445,7 @@ def _extract_name(self, raw_match: str) -> str: # Group 1 now grabs the optional `(Ident::)+` chain immediately # before the `operator` keyword and it's prefixed back on below. op_match = re.search( - r"((?:[a-zA-Z_]\w*::)*)\b(operator\s*(?:\[\s*\]|\(\s*\)|[^a-zA-Z0-9_\s({]+|[a-zA-Z_]\w*(?:\s*\*+)?))", + r"((?:[a-zA-Z_]\w*::)*)\b(operator\s*(?:\[\s*\]|\(\s*\)|(?:::)?[a-zA-Z_]\w*(?:::[a-zA-Z_]\w*)*(?:\s*\*+)?|[^a-zA-Z0-9_\s({]+))", match_strip, ) if op_match: diff --git a/gitgalaxy/standards/language_standards.py b/gitgalaxy/standards/language_standards.py index 743f1a2a5..ba7a105eb 100644 --- a/gitgalaxy/standards/language_standards.py +++ b/gitgalaxy/standards/language_standards.py @@ -36,7 +36,7 @@ | -------- | ----------- | -------------- | ------------ | --------------- | | Apex | 100.0% | 95.0% | 100.0% | 100.0% | | C | 93.3% | 99.5% | 100.0% | 100.0% | -| Cpp | 92.3% | 96.2% | 98.6% | 92.6% | +| Cpp | 93.4% | 95.7% | 98.6% | 92.6% | | Csharp | 99.2% | 99.8% | 100.0% | 100.0% | | Css | 100.0% | 100.0% | N/A | N/A | | Dart | 96.0% | 97.8% | 100.0% | 100.0% | @@ -3011,7 +3011,7 @@ class PrismConfigSchema(TypedDict): # literal `[*&]`, the other forbids consuming past the first # non-whitespace char), so this doesn't reopen the Rule 14 # backtracking gap the surrounding bounds were built to close. - r"(?:(?![ \t]*#)[a-zA-Z_]\w*(?:::[a-zA-Z_]\w*)*" + r"(?:(?![ \t]*#)(?!(?:[a-zA-Z_]\w*::)*operator\b)[a-zA-Z_]\w*(?:::[a-zA-Z_]\w*)*" r"(?:<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>)?" r"(?:[ \t]{0,20}[*&]{1,5}[ \t\n]{0,200}|[ \t\n]{1,200})){0,5}" # 5. THE "NOT A FUNCTION" SHIELD @@ -3025,7 +3025,7 @@ class PrismConfigSchema(TypedDict): # `(?:[a-zA-Z_]\w*::)*`. Out-of-line operator overload definitions (defined in a # .cpp file, declared in the header) are mainstream, common C++ -- completely # invisible to func_start before this fix. - r"(?![ \t]*#)((?:[a-zA-Z_]\w*::)*[~a-zA-Z_]\w*|(?:[a-zA-Z_]\w*::)*operator[ \t]*[^a-zA-Z_\s(]+|(?:[a-zA-Z_]\w*::)*operator[ \t]+(?:new|delete)(?:\[\])?)" + r"(?![ \t]*#)((?:[a-zA-Z_]\w*::)*operator[ \t]*\(\)|(?:[a-zA-Z_]\w*::)*operator[ \t]+(?:::)?[a-zA-Z_]\w*(?:::[a-zA-Z_]\w*)*(?:[ \t]*[*&]+)?|(?:[a-zA-Z_]\w*::)*operator[ \t]*[^a-zA-Z_\s(]+|(?:[a-zA-Z_]\w*::)*operator[ \t]+(?:new|delete)(?:\[\])?|(?:[a-zA-Z_]\w*::)*[~a-zA-Z_]\w*)" # 7. THE PARAMETER BLOCK (Supports vertical gap) # [NESTED PARENTHESIS FIX]: Uses 1-Level Nesting Trick to swallow function pointers without ReDoS. r"[ \t\n]{0,200}(?:ARGS\d+\s*\([^)]*\)|\((?:[^)(]|\([^)]*\))*\)|NOARGS)" diff --git a/tests/extraction/languages/test_cpp.py b/tests/extraction/languages/test_cpp.py index e95bf7df9..09c03d9e9 100644 --- a/tests/extraction/languages/test_cpp.py +++ b/tests/extraction/languages/test_cpp.py @@ -60,6 +60,22 @@ "TargetClass& TargetClass::operator=(const TargetClass& other) {", "TargetClass::operator=", ), # out-of-line operator= -- was a real bug, now fixed + ( + "MyClass::operator()() const {", + "MyClass::operator()", + ), # functor operator() + ( + "MyClass::operator bool() const {", + "MyClass::operator bool", + ), # primitive type conversion operator + ( + "MyClass::operator std::string() const {", + "MyClass::operator std::string", + ), # namespace-qualified type conversion operator + ( + "MyClass::operator Foo() const {", + "MyClass::operator Foo", + ), # custom type conversion operator ( "MyClass::MyClass(int x) : field_(x), other_(0) {", "MyClass::MyClass", diff --git a/tests/tree_sitter_accuracy_baseline_cpp.json b/tests/tree_sitter_accuracy_baseline_cpp.json index 5117e554f..b0b916bb1 100644 --- a/tests/tree_sitter_accuracy_baseline_cpp.json +++ b/tests/tree_sitter_accuracy_baseline_cpp.json @@ -1,12 +1,12 @@ { - "args_comparable": 1376, - "args_exact_match": 1202, + "args_comparable": 1392, + "args_exact_match": 1207, "corpus_path": "language-crucible/data/cpp", "extra_classes": 11, - "extra_functions": 55, + "extra_functions": 62, "files_scanned": 29, "found_classes": 138, - "found_functions": 1376, + "found_functions": 1392, "real_classes": 140, "real_functions": 1491 }