Menu

#216 [cffi] Fix CFFI conversion of constant expressions

None
wont-fix
None
5
2019-02-05
2008-09-02
No

CFFI converts constant expressions in #define'd constants and in enumeration items into equivalent lisp expressions. This patch (hopefully) fixes this conversion.
This patch implements a simple naive parser for constant expressions (replacing even more naive approach with a more correct one), memoization of previously met constant values (so that code like
enum { A = 123, B = A + 10 };
would translate into correct lisp expression). Still broken things are: not supporting ternary operator, somewhat wrong operators precedence order and associativity, but fixing those would require a full parser.
Also, one small fix goes into SWIG's parser: it would incorrectly parse character constant expressions in enumeration items: in
enum { A = '1' };
for '1' it would get node with enumvalue="1", type="int" instead of enumvalue="'1'", type="int", which makes correct parsing of such expressions impossible. Not fixed is parsing of expressions like
enum { A = '1' + 1 };
which would parse into enumvalue="1+1", type="int" instead of enumvalue="'1'+1", type="int" (again, which makes correct generation of lisp-side code impossible).

Discussion

  • Dmitry Kalyanov

    Dmitry Kalyanov - 2008-09-07

    Logged In: YES
    user_id=2201504
    Originator: YES

    Attaching a better variant of patch.
    Changes:
    1) Using custom macro define-constant instead of cl:defconstant (see http://www.sbcl.org/manual/Defining-Constants.html\)
    2) Better handling of character constants and arithemitcs with them
    3) Better handling of escape sequences in characters and strings;
    4) Safe way of specifying string literals with non-ascii characters.
    5) Change to c parser to retain the single quotes in character constants. This probably fixes some problems not only with cffi, but with some other modules.
    File Added: swig-full.patch

     
  • Dmitry Kalyanov

    Dmitry Kalyanov - 2008-09-07

    Version 2 of the patch

     
  • Olly Betts

    Olly Betts - 2008-09-17

    I don't have the time to check right now, but the fix for character constants sounds like this bug:

    http://sourceforge.net/tracker2/?func=detail&aid=1474463&group_id=1645&atid=101645

    I applied a fix for that but had to revert it. I forget the exact details, but it was discussed on swig-dev at the time.

    Anyway, this patch could well fix that bug. Or it could have the same flaw my fix did (I've checked and it isn't the same change I made).

     
  • William Fulton

    William Fulton - 2019-02-05
    • status: open --> closed
    • assigned_to: William Fulton
    • Group: -->
     
  • William Fulton

    William Fulton - 2019-02-05

    Closing all open CFFI issues as CFFI has been disabled, please see https://github.com/swig/swig/issues/1447

     
  • William Fulton

    William Fulton - 2019-02-05
    • status: closed --> wont-fix
     
  • William Fulton

    William Fulton - 2019-02-05

    Closing all open CFFI issues as CFFI has been disabled, please see https://github.com/swig/swig/issues/1447

     

Log in to post a comment.