[foreign] RFR: improved macro parser

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Fri Jun 1 21:21:39 UTC 2018


Hi,
this webrev adds a new way of parsing object-like macros which relies on 
the jshell API; defined macros are turned into jshell var declaration - e.g.

#define FOO 12

is turned into

'var FOO = 12;'

All macros are entered into a jshell context, and this allows to 
'resolve' macro names so that we can handle common cases like:

#define MAX 43
#define MIN (-MAX)

Thanks to the jshell API the new code is not too complex, and it handles 
the vast majority of constant-like macros. Of course we need a more 
general fallback for macros (esp. function-like), e.g. I'm under no 
illusion that this will work in all cases, but this looks like a good 
improvement over the current strategy that blows up as soon as there are 
more than two tokens in the macro.

I tested with a bunch of system headers and results seemed significantly 
better than before.

Webrev:

http://cr.openjdk.java.net/~mcimadamore/panama/macro_parser/

Maurizio





More information about the panama-dev mailing list