-
-
Notifications
You must be signed in to change notification settings - Fork 8
C++ Demangler Rewrite #77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
notxvilka
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know it would be a lot of work, but I recommend splitting tests semantically rather than arbitrarily. Group them by the feature, for example. In the long run it will be much easier to add new tests and improve old ones whenever necessary.
|
Hi! Sorry for not being active for a long time. Last few (4-5) months have been a roller coaster ride for me. Thanks for picking up the PR. I just couldn't bring myself back at it again. During my process of writing this, I modified the grammar so it's compatible with the parsing method here. I see that I didn't keep the grammar file here also I don't have access to the system on which it is on at the moment. I'll get it soon and make it available here so it's easier to follow the decisions made. Sorry again 🙏 for keeping in the dark. RizinOrg is a lovely and welcoming community. |
Attachments4-final-almost-gnf-grammar.txt The above file contains the final grammar that I deduced after making multiple transformations to the original grammar. The following file contains all files that I created during the transformations iteratively. Most probably if you ever decide to use the grammar files, you'll mostly use the above, but if you need any answer to "why" then following zip file may help. How To Read The Grammar Files?Rules are written like this
Derivation ProcessThis is the general GNF derivation process.
This was done manually but I checked it manually more than hundred times so I believe this should be correct. |
|
@brightprogrammer I feel that implementing such a demangler using the C macro makes source-level debugging practically impossible. What was the original reasoning behind this approach? |
|
Code size reduced by a lot and I could compare code with grammar easily. Debugging does become harder, that is one of the reasons it too so much time to even get here. |
|
@b1llow The trace graph really helps here though. I found debugging using it quite helpful. Also because of the degeneracy of most of the code because of use of a select set of macros, only debugging of grammar rules is required, and some context information like substitutions and templates |
22e6b2e to
60a8e63
Compare
…ory management Enhance C++ demangling support with new rule declarations and macro improvements Add support for C++ type demangling in new test file Refactor macros to support positional tracking and improve clarity
60a8e63 to
6497e50
Compare
…andling in demangling
…-qualifier handling
…g type information
…types.h, and macros.h - Updated AST handling in ast.c (+29 lines) - Minor macro adjustments in macros.h - Refactored meta functions in meta.c (net -15 lines) - Modified type definitions in types.h (net -5 lines) - Small fixes in v2.c - Significant refactoring in v3.c (net -65 lines) Total: 83 insertions, 91 deletions across 6 files
- Refactor Meta struct to use DemAstNode for detected_types instead of Name - Change detected_types from Vec(Name) to Vec(DemAstNode) for consistency - Update meta_copy, meta_move, and meta_deinit functions accordingly - Change current_prefix from DemString to DemAstNode - Fix bugs in meta.c: - Remove duplicate 'is_const' assignment in meta_copy_scalars - Fix logic error in append_type (was checking !dem_string_empty, should be dem_string_empty) - Fix append_type to properly append NULL and copy node data - Fix indentation in append_tparam function - Update find_type_index and meta_substitute_type to work with DemAstNode - Simplify rule_prefix_tail in v3.c: - Replace complex backtracking logic with cleaner while-loop approach - Build fully qualified prefix incrementally - Properly update substitution table and current_prefix in each iteration - Fix minor issues: - Add missing semicolon in types.h function declaration - Fix const qualifier in cpdem_get_demangled return type (v2.c) - Fix formatting in v3.c (spacing around 'else') - Update trace_graph.c to use DemAstNode instead of Name - Add test timeout configuration in meson.build for slow tests (cxx_base) to handle large number of test cases with ASAN
…oved clarity and correctness
…le_name and rule_prefix_tail
…x construction in rule_type and rule_prefix_tail
…streamline type checks in rule_type
…and removing redundant conditions
…d improving node extraction logic
Removing complex prefix parsing rules Improving memory handling and node initialization Enhancing template and function pointer parsing capabilities Reducing code redundancy and improving maintainability 1. AST Node Constructor Refactoring (src/cplusplus/ast.c) Added DemAstNode_ctor_inplace() for in-place initialization Changed DemAstNode_ctor() signature to accept raw string parameters instead of struct pointers Enhanced DemAstNode_copy() to properly copy subtag and children fields 2. Type System Enhancements (src/cplusplus/types.h) Introduced subtag field for handling sub-type tags Added QUALIFIED_TYPE enum value Simplified type definitions 3. Macro Simplification (src/cplusplus/macros.h) Added CONSUME() macro Removed IS_CONST() / SET_CONST() / UNSET_CONST() macros Removed FORCE_APPEND_TYPE() and APPEND_TPARAM() macros Simplified append_type() calls (removed force parameter) 4. Metadata Handling Refactoring (src/cplusplus/meta.c) Added NodeList_copy(), NodeList_make(), NodeList_pop_trailing() helper functions Significantly simplified meta_copy_scalars() logic 5. Core Parsing Logic Overhaul (src/cplusplus/v3.c, ~500 lines reduced) Removed complex prefix rule functions: rule_prefix_suffix() rule_prefix_start() rule_prefix_tail() rule_prefix() rule_template_prefix() Improved nested name parsing Enhanced template argument handling Optimized function pointer handling logic Added debug trace toggle (m->trace)
…ing initialization
…ion and management
…roved readability
…TCH for improved clarity
…PNodeList and enhancing initialization
…PNodeList and enhancing initialization
…non-empty children
…to prevent pointer overflow and ensure valid terminators
…tion in DemAstNode and Meta structures
Parse std:: qualified templates correctly by detecting St<digit> pattern and parsing the identifier after the std substitution. Key changes: - Detect when St substitution is followed by a digit (identifier) - Append :: and parse the source name to form std::<identifier> - Add qualified name to substitution table BEFORE parsing template args to ensure correct back-reference resolution This fixes parsing of std::function<T>, std::char_traits<T>, and other std-qualified templates that were being split incorrectly. Test results: All 1003 tests in cxx.00 now pass (was 10 failures)
This is the 3nd attempt to rewrite old C++ demangler GPL code.
New features:
C++20 name mangling support
Resources :
Old PR: