Skip to content

frontend cpp limitations #1983

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

Open
DavidKorczynski opened this issue Jan 16, 2025 · 2 comments
Open

frontend cpp limitations #1983

DavidKorczynski opened this issue Jan 16, 2025 · 2 comments

Comments

@DavidKorczynski
Copy link
Contributor

Adding some code snippets that fail with the tree-sitter frontend

@DavidKorczynski
Copy link
Contributor Author

From: https://github.com/zeux/pugixml/blob/9d7fcbf7410e20720b093f9bb3d81dfe6500d30d/src/pugixml.cpp#L7746-L7751

PUGI_IMPL_FN xml_parse_result xml_document::load_buffer(const void* contents, size_t size, unsigned int options, xml_encoding encoding)
{
    reset();

    return impl::load_buffer_impl(static_cast<impl::xml_document_struct*>(_root), _root, const_cast<void*>(contents), size, options, encoding, false, false, &_buffer);
}

The tree looks like:

translation_unit [0, 0] - [6, 0]
  function_definition [0, 0] - [5, 1]
    type: type_identifier [0, 0] - [0, 12]
    declarator: function_declarator [0, 13] - [0, 135]
      declarator: qualified_identifier [0, 13] - [0, 55]
        scope: namespace_identifier [0, 13] - [0, 29]
        MISSING "::" [0, 29] - [0, 29]
        name: qualified_identifier [0, 30] - [0, 55]
          scope: namespace_identifier [0, 30] - [0, 42]
          name: identifier [0, 44] - [0, 55]
      parameters: parameter_list [0, 55] - [0, 135]
        parameter_declaration [0, 56] - [0, 76]
          type_qualifier [0, 56] - [0, 61]
...

The problem is that function_definition.type == PUGI_IMPL_FN and it analyses xml_parse_result as the initial scope. This is also why we have an error MISSING "::" which is because tree-sitter want's the function to be: PUGI_IMPL_FN xml_parse_result::xml_document::load_buffer

@DavidKorczynski
Copy link
Contributor Author

When macros are used in the code, we need to include everything

void f1() {
  #ifdef M1
    f1();
  #endif

  #ifdef M2
    f2();
  #endif
}

In this case, the executable depends on the way it's compiled, so we will include both f1 and f2 in the calltree.

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

No branches or pull requests

1 participant