decomp-permuter icon indicating copy to clipboard operation
decomp-permuter copied to clipboard

Macro preserval shouldn't depend on the order of macros

Open simonlindholm opened this issue 1 year ago • 0 comments

#define A B 
#define B C 
A

with import.py --preserve-macros=A will at the start of preprocess_c_with_macros create the temporary file

_permuter define A B 
#define B C 
A

and run cpp on that in order to expand macros in the definition of A before turning it back into a #define, but this fails because the define for B comes after that of A. When you compile the file normally it works, however, because macro expansion is lazy.

Should probably fix this by first stripping comments, and then moving all macro definitions to the top.

If there are #undefs that makes things harder; in principle unfixable if there are macros that get undef'd and redefined and are referenced from a macro that changes meaning over time (not that we care about that case).

simonlindholm avatar Jan 18 '23 17:01 simonlindholm