-
-
Notifications
You must be signed in to change notification settings - Fork 10
Rewrite Of C++ Demanglers #69
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
54 commits
Select commit
Hold shift + click to select a range
102446e
Seven (7/347) Tests Pass GNU v2 Rewrite
brightprogrammer 4ff587b
(31/349) Function Param Type Demangling
brightprogrammer 078a388
Update CI Without `with_gpl` Meson Option
brightprogrammer 6847f23
(74/348) Demangling of Refs & Ptrs In Function Params
brightprogrammer ea348f0
Remove `r-value` Reference Demangle Check
brightprogrammer d2c70c7
Update Reuse Config & Remove GPL License File
brightprogrammer 30b2d0f
Added Operators, Now Total 159 Tests Pass
brightprogrammer a338379
Refactor Function Params To A Vector
brightprogrammer 9529a03
(242) Template Parameters Added
brightprogrammer b762255
(252) Template Parameters : Some Working, Some Need Fixing
brightprogrammer b3bc0e2
(269) Template Classes Working
brightprogrammer 364b4e9
(323) Function Pointers & Virtual Tables Remain
brightprogrammer 0f70055
(343) Just Two Test Cases Remain To Pass
brightprogrammer 8e22ad4
(344) Complete GNU v2
brightprogrammer ac42199
First Run Itanium ABI (GPL v3)
brightprogrammer 41269bb
Fix Recursion Problems
brightprogrammer 150707b
V3 Progress & Some Tests Fix
brightprogrammer 2e9e1ca
Improve Substitution
brightprogrammer 5e12019
Remove Match & Do & Improve Optional Matches
brightprogrammer 6905fe8
Many Tests Passing, Some Tests Just Need Readjustment To Pass, Templa…
brightprogrammer 793d3d9
Test File Split. Lots Of Tests Passing. Templates, Ctors & Dtors Remain
brightprogrammer 72de14d
Better Substitutable Type Detection
brightprogrammer b3db303
Templates Working, Some Substitution Detection Bug Exist
brightprogrammer a63a044
Branch From Actual Grammar & Many Many Tests Pass
brightprogrammer fcc7d24
Better Substitutions
brightprogrammer 11d5a47
Std Namespace Use Correctly
brightprogrammer 6175e0b
Detecting Functors & Better Type Detection & Substitution
brightprogrammer 9132efa
Template Ctor & Dtor
brightprogrammer bcc72eb
Template Params (`T[N]_`)
brightprogrammer 94a0de8
Substitution Bugs Exist. Pointer To Member Type Demangling Works.
brightprogrammer 597e260
Constructors With Template Arguments
brightprogrammer 861dc9d
Inline Rewrite Of Boolean Values
brightprogrammer d270403
Better Const Propagation
brightprogrammer e477ba3
Test Fix
brightprogrammer e44a39e
Substution Improvements & Test Fixes
brightprogrammer 7c182cd
Template Param Detection Bug
brightprogrammer c966d9c
Fix Detected Types In `RULE(prefix)`
brightprogrammer 8b9b656
Expr Primary Fix
brightprogrammer 9a60257
Test Fixes & Prefix Bug Fix
brightprogrammer baaa269
Append Type Only When `const` is Added In `RULE(name)`
brightprogrammer bacc6ea
Force Append Type On Template Substitution
brightprogrammer 3350f93
More Green, More Tests Pass
brightprogrammer d0cfdff
Detect Names Before Templates Are Parsed As Well
brightprogrammer b64090c
Better Template Detection
brightprogrammer bee9a05
More Tests Pass Less Failures Remain
brightprogrammer 2949402
Test Fixes
brightprogrammer aa10fa1
Template Param Substitutions Must Be Forcefully Appended To Detected …
brightprogrammer b3dd702
Toplevel Template Parameters Reset
brightprogrammer 1b1cfd5
Apply @wargio's suggestions
brightprogrammer 65b71c2
Template Params Are Always Added, Without Maintaining Uniqueness
brightprogrammer 076970e
Array Type Parsing
brightprogrammer 4c2258f
Correct Rule Use
brightprogrammer d2914ad
save_work
brightprogrammer 21bdf09
To GNF
brightprogrammer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| #include "cp/common.h" | ||
|
|
||
| CpDem* cpdem_init (CpDem* dem, const char* mangled, CpDemOptions opts) { | ||
| if (!dem || !mangled) { | ||
| return NULL; | ||
| } | ||
|
|
||
| memset (dem, 0, sizeof (CpDem)); | ||
| dem->original = | ||
| ((StrIter) {.beg = mangled, .end = mangled + strlen (mangled) + 1, .cur = mangled}); | ||
| dem->opts = opts; | ||
| dem_string_init (&dem->base_name); | ||
| dem_string_init (&dem->suffix); | ||
| dem_string_init (&dem->prefix); | ||
| param_vec_init (&dem->func_params); | ||
| return dem; | ||
| } | ||
|
|
||
| CpDem* cpdem_deinit (CpDem* dem) { | ||
| if (!dem) { | ||
| return NULL; | ||
| } | ||
|
|
||
| /* free all demstring and deinit qualifiers vector */ | ||
| vec_foreach_ptr (&dem->qualifiers, q, { dem_string_deinit (q); }); | ||
| vec_deinit (&dem->qualifiers); | ||
|
|
||
| // deinit all func params first | ||
| param_vec_deinit (&dem->func_params); | ||
|
|
||
| dem_string_deinit (&dem->base_name); | ||
| dem_string_deinit (&dem->prefix); | ||
| dem_string_deinit (&dem->suffix); | ||
| dem_string_deinit (&dem->custom_operator); | ||
|
|
||
| memset (dem, 0, sizeof (CpDem)); | ||
| return dem; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,156 @@ | ||
| // SPDX-FileCopyrightText: 2025 RizinOrg <info@rizin.re> | ||
| // SPDX-FileCopyrightText: 2025 Siddharth Mishra <admin@brightprogrammer.in> | ||
| // SPDX-License-Identifier: LGPL-3.0-only | ||
|
|
||
| #ifndef CPDEM_COMMON_H | ||
| #define CPDEM_COMMON_H | ||
|
|
||
| #include "cp/demangle.h" | ||
| #include "cp/param.h" | ||
| #include "cp/vec.h" | ||
| #include "demangler_util.h" | ||
|
|
||
| /** | ||
| * \b String iterator | ||
| **/ | ||
| typedef struct StrIter { | ||
| const char* beg; /**< \b Beginning position of string. */ | ||
| const char* end; /**< \b Ending of string (usually points to the null-terminator char). */ | ||
| const char* cur; /**< \b Current read position. */ | ||
| } StrIter; | ||
|
|
||
| typedef Vec (DemString) ClassNameVec; | ||
|
|
||
| typedef struct { | ||
| StrIter original; | ||
| CpDemOptions opts; // TODO: use options to simplify output while demangling | ||
|
|
||
| ClassNameVec qualifiers; | ||
| DemString base_name; // Used to identify base type in list of function params | ||
| ParamVec func_params; // Names of all function params | ||
| bool has_params; // There are cases where control never reaches `cpdem_func_params` | ||
|
|
||
| DemString suffix; // anything that is to be put at the very end of demangled output | ||
| DemString prefix; // a return type, or another keyword to be put before name | ||
| DemString custom_operator; // A special case of operator "__op<L><TYPE>" | ||
|
|
||
| bool has_global_name; /* __vt or _GLOBAL$I/D$, etc... */ | ||
| bool is_ctor; | ||
| bool is_dtor; | ||
| ut8 operator_type; // 0 if not an operator, otherwise a positive value | ||
| } CpDem; | ||
|
|
||
| CpDem* cpdem_init (CpDem* dem, const char* mangled, CpDemOptions opts); | ||
| CpDem* cpdem_deinit (CpDem* dem); | ||
|
|
||
| /** | ||
| * \b Give current read position. | ||
| * | ||
| * \return const char pointer to current read position. | ||
| */ | ||
| #define CUR() (dem->original.cur) | ||
|
|
||
| /** | ||
| * \b Give position where string begins. | ||
| * | ||
| * \return const char pointer to beginning of mangled string. | ||
| */ | ||
| #define BEG() (dem->original.beg) | ||
|
|
||
| /** | ||
| * \b Give position of NULL terminator. | ||
| * | ||
| * \return const char pointer to end of mangled string. | ||
| */ | ||
| #define END() (dem->original.end) | ||
|
|
||
| /** | ||
| * \b Check whether the provided position is in range of readable address. | ||
| * | ||
| * \p read_pos : char pointer to check for range. | ||
| * | ||
| * \return 1 if in range. | ||
| * \return 0 otherwise. | ||
| */ | ||
| #define IN_RANGE(read_pos) ((read_pos) >= BEG() ? ((read_pos) < END() ? 1 : 0) : 0) | ||
|
|
||
| /** | ||
| * \b Seek to given read position if it's in range. This will change the current | ||
| * read position to given target_read_pos. | ||
| * | ||
| * \p target_read_pos : char pointer specifying the target read position to seek to. | ||
| * | ||
| * \return target_read_pos on success. | ||
| * \return CUR() otherwise. | ||
| */ | ||
| #define SEEK_TO(target_read_pos) \ | ||
| (dem->original.cur = IN_RANGE (target_read_pos) ? (target_read_pos) : CUR()) | ||
|
|
||
| /** | ||
| * Peek one character from current read position in demangling context. | ||
| * This will NOT advance, unlike READ(). | ||
| * | ||
| * \return char on success. | ||
| * \return 0 if no more characters left | ||
| */ | ||
| #define PEEK() (IN_RANGE (CUR()) ? *dem->original.cur : 0) | ||
|
|
||
| /** | ||
| * \b Read one character from current read position in demangling context | ||
| * and then advance by one position. | ||
| * | ||
| * \return char on success. | ||
| * \return 0 if no more characters left | ||
| */ | ||
| #define READ(ch) (IN_RANGE (CUR()) ? ((*dem->original.cur == ch) ? (ADV(), 1) : 0) : 0) | ||
|
|
||
| /** | ||
| * \b Advance current read position by one character, if this next | ||
| * position is in range, otherwise stay at current read position. | ||
| * | ||
| * \return updated read position on success. | ||
| * \return NULL otherwise. | ||
| */ | ||
| #define ADV() (IN_RANGE (CUR() + 1) ? dem->original.cur++ : NULL) | ||
|
|
||
| /** | ||
| * \b Advance current read position by "n" characters, if this next | ||
| * position is in range, otherwise stay at current read position. | ||
| * | ||
| * \return updated read position on success. | ||
| * \return NULL otherwise. | ||
| */ | ||
| #define ADV_BY(n) (IN_RANGE (CUR() + n) ? (dem->original.cur = dem->original.cur + (n)) : NULL) | ||
|
|
||
| /** | ||
| * \b Save current read position in demangling context to restore it later. | ||
| * This is used when we know that while matching a rule we might fail, and we'll | ||
| * need to backtrack. For this we must remember the initial trial start pos. | ||
| */ | ||
| #define SAVE_POS() const char* _____trial_start_pos = CUR(); | ||
|
|
||
| /** | ||
| * \b Restore saved position | ||
| */ | ||
| #define RESTORE_POS() \ | ||
| do { \ | ||
| SEEK_TO (_____trial_start_pos); \ | ||
| } while (0) | ||
|
|
||
| /** | ||
| * Reads a number from current demangling position to provided "var" variable. | ||
| * Automatically will adjust next read position if numbe read is successful, otherwise, will | ||
| * set var to -1 | ||
| */ | ||
| #define READ_NUMBER(var) \ | ||
| do { \ | ||
| char* end = NULL; \ | ||
| (var) = strtoll (CUR(), &end, 10); \ | ||
| if (!end) { \ | ||
| (var) = -1; \ | ||
| break; \ | ||
| } \ | ||
| SEEK_TO (end); \ | ||
| } while (0) | ||
|
|
||
| #endif // CPDEM_COMMON_H | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.