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

Seems 'function_definition' not parsed correctly when putting 'else-if' in '#ifndef' #76

Open
Ps7ch3 opened this issue Aug 6, 2021 · 0 comments

Comments

@Ps7ch3
Copy link

Ps7ch3 commented Aug 6, 2021

I'm trying to extract all the function_definition in C files but seems there's a false positive for 'function_definition' query.

Minimal repro:

int foo(int a)
{
    if (0)
        return 0;
    #ifndef XXX
    else if (1){
    	return 0;
    }
    #endif
}
translation_unit [0, 0] - [11, 0]
  function_definition [0, 0] - [9, 1]
    type: primitive_type [0, 0] - [0, 3]
    declarator: function_declarator [0, 4] - [0, 14]
      declarator: identifier [0, 4] - [0, 7]
      parameters: parameter_list [0, 7] - [0, 14]
        parameter_declaration [0, 8] - [0, 13]
          type: primitive_type [0, 8] - [0, 11]
          declarator: identifier [0, 12] - [0, 13]
    body: compound_statement [1, 0] - [9, 1]
      if_statement [2, 4] - [3, 17]
        condition: parenthesized_expression [2, 7] - [2, 10]
          number_literal [2, 8] - [2, 9]
        consequence: return_statement [3, 8] - [3, 17]
          number_literal [3, 15] - [3, 16]
      preproc_ifdef [4, 4] - [8, 10]
        name: identifier [4, 12] - [4, 15]
        function_definition [5, 4] - [7, 5]  -------------------- strange result as function_definition
          type: type_identifier [5, 4] - [5, 8]
          declarator: function_declarator [5, 9] - [5, 15]
            declarator: identifier [5, 9] - [5, 11]
            parameters: parameter_list [5, 12] - [5, 15]
              ERROR [5, 13] - [5, 14]
                number_literal [5, 13] - [5, 14]
          body: compound_statement [5, 15] - [7, 5]
            return_statement [6, 5] - [6, 14]
              number_literal [6, 12] - [6, 13]

query:
(function_definition (function_declarator (identifier) (parameter_list) @params) @decl)

image

I'm not sure if this behavior is expected, but what should I do to avoid this?

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

Successfully merging a pull request may close this issue.

1 participant