Skip to content
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

sp_after_tparen_close doesn't work if function pointer is itself a function argument #3259

Open
alexhenrie opened this issue Aug 5, 2021 · 3 comments · May be fixed by #4290
Open

sp_after_tparen_close doesn't work if function pointer is itself a function argument #3259

alexhenrie opened this issue Aug 5, 2021 · 3 comments · May be fixed by #4290

Comments

@alexhenrie
Copy link
Collaborator

Config file:

sp_after_tparen_close = add

Test code (adapted from tests/input/c/i2c-core.c):

int (*found_proc)(struct i2c_adapter *, int, int);

static int i2c_probe_address(struct i2c_adapter *adapter, int addr, int kind,
			     int (*found_proc)(struct i2c_adapter *, int, int));

Expected output:

int (*found_proc) (struct i2c_adapter *, int, int);

static int i2c_probe_address(struct i2c_adapter *adapter, int addr, int kind,
                             int (*found_proc) (struct i2c_adapter *, int, int));

Actual output:

int (*found_proc) (struct i2c_adapter *, int, int);

static int i2c_probe_address(struct i2c_adapter *adapter, int addr, int kind,
                             int (*found_proc)(struct i2c_adapter *, int, int));

Debug output:

# Uncrustify_d-0.73.0-99-cbf8d8d4
sp_after_tparen_close           = add
# option(s) with 'not default' value: 1
#
# -=====-
# number of loops               = 0
# -=====-
# language                      = C-Header
# -=====-
# Line                Tag         Parent_type  Type of the parent         Columns Br/Lvl/pp      Flag   Nl  Text
#   1>               TYPE|           FUNC_VAR|     PARENT_NOT_SET[  1/  1/  4/  0][0/0/0][      c0000][0-0] int
#   1>        TPAREN_OPEN|           FUNC_VAR|     PARENT_NOT_SET[  5/  5/  6/  1][0/0/0][  203000000][0-0]     (
#   1>           PTR_TYPE|               NONE|     PARENT_NOT_SET[  6/  6/  7/  0][0/1/0][  200080000][0-0]      *
#   1>           FUNC_VAR|               NONE|     PARENT_NOT_SET[  7/  7/ 17/  0][0/1/0][    3080000][0-0]       found_proc
#   1>       TPAREN_CLOSE|           FUNC_VAR|     PARENT_NOT_SET[ 17/ 17/ 18/  0][0/0/0][  200000000][0-0]                 )
#   1>        FPAREN_OPEN|         FUNC_PROTO|     PARENT_NOT_SET[ 19/ 18/ 19/  0][0/0/0][  200000000][0-0]                   (
#   1>             STRUCT|               NONE|     PARENT_NOT_SET[ 20/ 19/ 25/  0][0/1/0][      a0000][0-0]                    struct
#   1>               TYPE|             STRUCT|     PARENT_NOT_SET[ 27/ 26/ 37/  1][0/1/0][     800000][0-0]                           i2c_adapter
#   1>           PTR_TYPE|             STRUCT|     PARENT_NOT_SET[ 39/ 38/ 39/  1][0/1/0][  200000000][0-0]                                       *
#   1>              COMMA|               NONE|     PARENT_NOT_SET[ 40/ 39/ 40/  0][0/1/0][  200000000][0-0]                                        ,
#   1>               WORD|               NONE|     PARENT_NOT_SET[ 42/ 41/ 44/  1][0/1/0][    3080000][0-0]                                          int
#   1>              COMMA|               NONE|     PARENT_NOT_SET[ 45/ 44/ 45/  0][0/1/0][  200000000][0-0]                                             ,
#   1>               WORD|               NONE|     PARENT_NOT_SET[ 47/ 46/ 49/  1][0/1/0][    1080000][0-0]                                               int
#   1>       FPAREN_CLOSE|         FUNC_PROTO|     PARENT_NOT_SET[ 50/ 49/ 50/  0][0/0/0][  200000000][0-0]                                                  )
#   1>          SEMICOLON|           FUNC_VAR|     PARENT_NOT_SET[ 51/ 50/ 51/  0][0/0/0][  200000000][0-0]                                                   ;
#   1>            NEWLINE|               NONE|     PARENT_NOT_SET[ 52/ 51/  1/  0][0/0/0][          0][2-0]
#   3>          QUALIFIER|               NONE|     PARENT_NOT_SET[  1/  1/  7/  0][0/0/0][      e0000][0-0] static
#   3>               TYPE|               NONE|     PARENT_NOT_SET[  8/  8/ 11/  1][0/0/0][      20000][0-0]        int
#   3>      FUNC_CTOR_VAR|               NONE|     PARENT_NOT_SET[ 12/ 12/ 29/  1][0/0/0][    3000000][0-0]            i2c_probe_address
#   3>        FPAREN_OPEN|      FUNC_CTOR_VAR|     PARENT_NOT_SET[ 29/ 29/ 30/  0][0/0/0][  200000000][0-0]                             (
#   3>             STRUCT|               NONE|     PARENT_NOT_SET[ 30/ 30/ 36/  0][0/1/0][400000a0000][0-0]                              struct
#   3>               WORD|               NONE|     PARENT_NOT_SET[ 37/ 37/ 48/  1][0/1/0][40000000000][0-0]                                     i2c_adapter
#   3>           PTR_TYPE|               NONE|     PARENT_NOT_SET[ 49/ 49/ 50/  1][0/1/0][40200000000][0-0]                                                 *
#   3>               WORD|               NONE|     PARENT_NOT_SET[ 50/ 50/ 57/  0][0/1/0][40000000000][0-0]                                                  adapter
#   3>              COMMA|               NONE|     PARENT_NOT_SET[ 57/ 57/ 58/  0][0/1/0][40200000000][0-0]                                                         ,
#   3>               WORD|               NONE|     PARENT_NOT_SET[ 59/ 59/ 62/  1][0/1/0][400000a0000][0-0]                                                           int
#   3>               WORD|               NONE|     PARENT_NOT_SET[ 63/ 63/ 67/  1][0/1/0][40000000000][0-0]                                                               addr
#   3>              COMMA|               NONE|     PARENT_NOT_SET[ 67/ 67/ 68/  0][0/1/0][40200000000][0-0]                                                                   ,
#   3>               WORD|               NONE|     PARENT_NOT_SET[ 69/ 69/ 72/  1][0/1/0][400000a0000][0-0]                                                                     int
#   3>               WORD|               NONE|     PARENT_NOT_SET[ 73/ 73/ 77/  1][0/1/0][40000000000][0-0]                                                                         kind
#   3>              COMMA|               NONE|     PARENT_NOT_SET[ 77/ 77/ 78/  0][0/1/0][40200000000][0-0]                                                                             ,
#   3>            NEWLINE|               NONE|     PARENT_NOT_SET[ 78/ 78/ 30/  0][0/1/0][40000000000][1-0]
#   4>    MACRO_FUNC_CALL|               NONE|     PARENT_NOT_SET[ 30/ 30/ 33/  0][0/1/0][40000080000][0-0]                              int
#   4>        FPAREN_OPEN|    MACRO_FUNC_CALL|     PARENT_NOT_SET[ 34/ 34/ 35/  1][0/1/0][40200000000][0-0]                                  (
#   4>              DEREF|               NONE|     PARENT_NOT_SET[ 35/ 35/ 36/  0][0/2/0][40200080000][0-0]                                   *
#   4>               WORD|               NONE|     PARENT_NOT_SET[ 36/ 36/ 46/  0][0/2/0][40000080000][0-0]                                    found_proc
#   4>       FPAREN_CLOSE|    MACRO_FUNC_CALL|     PARENT_NOT_SET[ 46/ 46/ 47/  0][0/1/0][40200000000][0-0]                                              )
#   4>        FPAREN_OPEN|          FUNC_CALL|     PARENT_NOT_SET[ 47/ 47/ 48/  0][0/1/0][40200000000][0-0]                                               (
#   4>             STRUCT|               NONE|     PARENT_NOT_SET[ 48/ 48/ 54/  0][0/2/0][400000a0000][0-0]                                                struct
#   4>               WORD|               NONE|     PARENT_NOT_SET[ 55/ 55/ 66/  1][0/2/0][40000000000][0-0]                                                       i2c_adapter
#   4>           PTR_TYPE|               NONE|     PARENT_NOT_SET[ 67/ 67/ 68/  1][0/2/0][40200000000][0-0]                                                                   *
#   4>              COMMA|               NONE|     PARENT_NOT_SET[ 68/ 68/ 69/  0][0/2/0][40200000000][0-0]                                                                    ,
#   4>               WORD|               NONE|     PARENT_NOT_SET[ 70/ 70/ 73/  1][0/2/0][40000080000][0-0]                                                                      int
#   4>              COMMA|               NONE|     PARENT_NOT_SET[ 73/ 73/ 74/  0][0/2/0][40200000000][0-0]                                                                         ,
#   4>               WORD|               NONE|     PARENT_NOT_SET[ 75/ 75/ 78/  1][0/2/0][40000080000][0-0]                                                                           int
#   4>       FPAREN_CLOSE|          FUNC_CALL|     PARENT_NOT_SET[ 78/ 78/ 79/  0][0/1/0][40200000000][0-0]                                                                              )
#   4>       FPAREN_CLOSE|      FUNC_CTOR_VAR|     PARENT_NOT_SET[ 79/ 79/ 80/  0][0/0/0][40200000000][0-0]                                                                               )
#   4>          SEMICOLON|      FUNC_CTOR_VAR|     PARENT_NOT_SET[ 80/ 80/ 81/  0][0/0/0][  200000000][0-0]                                                                                ;
#   4>            NEWLINE|               NONE|     PARENT_NOT_SET[ 81/ 81/  1/  0][0/0/0][          0][1-0]
# -=====-

Note that ordinarily, the first ) in the function pointer is correctly detected as a TPAREN_CLOSE, but if the function pointer is itself a function argument, it is detected as an FPAREN_CLOSE.

alexhenrie added a commit to alexhenrie/uncrustify that referenced this issue Aug 5, 2021
And also use it wherever Uncrustify is not able to correctly parse a
function pointer, providing a workaround for issue uncrustify#3259.
@gmaurel gmaurel closed this as completed Aug 6, 2021
@alexhenrie
Copy link
Collaborator Author

@gmaurel Please reopen this issue. #3257 was a workaround, not a proper fix.

@gmaurel gmaurel reopened this Aug 7, 2021
@gmaurel
Copy link
Collaborator

gmaurel commented Aug 7, 2021

re opened!

@guy-maurel
Copy link
Contributor

PR #4290 is a bug fix proposal.
Please test it and report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants