-
-
Notifications
You must be signed in to change notification settings - Fork 41
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
Incomplete macro reolving #71
Comments
Confirmed with this repro:
Thanks for the bug report! |
@ned14 I distilled the repro further and tried it in pdb. By now I am convinced that the issue is the two levels of pasting tokens Distilled version: #define fCAST4_8s(A) A
#define SECOND_LVL_CONCAT(SRC, REGSTYPE) fCAST##REGSTYPE(SRC)
#define FIRST_LVL_CONCAT(SRC, REGSTYPE) SECOND_LVL_CONCAT(SRC, REGSTYPE##s)
FIRST_LVL_CONCAT(src,4_8) I renamed the function-style macros for brevity. When I run the C/C++ preprocessor on my system against it I get (the
and pcpp gives:
So we arrive at the name
... and only then do we see that |
Alright, in pdb I can see that when we are in
I think in particular the assessment of the lexer that Currently I think that this may cause the And a short test confirms that this suspicion may indeed be true. Replacing Temporary repro (to force the lexer to give us a single token): #define fCASTr_8s(A) A
#define SECOND_LVL_CONCAT(SRC, REGSTYPE) fCAST##REGSTYPE(SRC)
#define FIRST_LVL_CONCAT(SRC, REGSTYPE) SECOND_LVL_CONCAT(SRC, REGSTYPE##s)
FIRST_LVL_CONCAT(src,r_8) Output for
Unfortunately the
Anyway, pdb to the rescue. This looks a lot better already (
So the For reference this is the conditional breakpoint at preprocess.py:558 I set:
|
Side note: Looking at
can be vastly simplified and at the same time expanded to support
We only appear to use a single capture group, so make the two remaining groups non-capturing. Also set mode to case-insensitive (works both on Python 2.7 and 3.x). What do you think, @ned14? |
Seems plausible. The hard part is coming up with a fix which doesn't break other things and is maintainable. |
Indeed, which is the reason why I didn't rush to fixing it. The code I saw during debugging has to sink in first and I need to get more acquainted with the code in general. Also I think it helps to aim for highest possible test coverage before attempting to tackle this (which is why I did this tox thingamy). |
FYI: The latest repro from this comment gets properly resolved with the changes from PR #80. |
In the following example not all macros get resolved:
Running
pcpp test.h
returns:Note that the
fCAST4_8s
macro was not resolved.It seems to be a problem with the
##
operator.If
fCAST##REGSTYPE
is replaced withfCAST4_8s
in macrofBIDIR_SHIFTR
it works fine.pcpp version: 1.30
The text was updated successfully, but these errors were encountered: