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

c++11 fixed types not recognised as builtin types #98

Open
Firefly35 opened this issue Dec 11, 2019 · 6 comments
Open

c++11 fixed types not recognised as builtin types #98

Firefly35 opened this issue Dec 11, 2019 · 6 comments

Comments

@Firefly35
Copy link
Contributor

  • Platform : Mac OS Mojave
  • cppast version: latest
  • parser: libclang_parser
  • clang version: Apple clang version 11.0.0 (clang-1100.0.33.12)
    (but using llvm from brew version 7.0.1 to configure LLVM_CONFIG_BINARY for cppast build)

While parsing the following code, when iterating over member function parameters, parameter is considered as a "User defined type".

Input: class header file

#include <cstdint>

class X {
virtual void f(uint32_t parameter) = 0;
};

I then tried to retrieve the cpp_entity from the cpp_type using lookup in the cpp_entity_index

void parse_parameter(const cppast::cpp_entity_index& index, const cppast::cpp_type & p) {
auto & userType = static_cast<const cppast::cpp_user_defined_type&>(p);
        std::string derefTypeKind = "User defined type";
        if (userType.entity().no_overloaded().get() > 0) {
            auto ids = userType.entity().id();
            for (auto & id : ids) {
                if (index.lookup(id).has_value()) {
                    auto & entity = index.lookup(id).value();
                    if (entity.kind() == cppast::cpp_entity_kind::type_alias_t) {
                        std::cout<<"Entity "<<entity.name()<<" is a type alias"<<std::endl;
                    }
                }
            }
}

But there is no typedef matching uint32_t in the index, hence I can't consider uint32_t as a builtin type (except through basic string matching, but not the best way IMHO).

@foonathan
Copy link
Collaborator

The behavior is correct, uint32_t is not a builtin type, but a typedef in stddef.h. The typedef declaration is not in the index, because you didn't parse stddef.h.

@Firefly35
Copy link
Contributor Author

Firefly35 commented Dec 11, 2019 via email

@foonathan
Copy link
Collaborator

I believe stdint.h has been parsed : I use the compilation database
generated from Qt creator to parse the file, hence the stdint.h file must
be in the include paths.
I'll check if it's parsed.

It's in the include paths, yes, but the header file itself is not necessarily parsed by cppast (unless you've explicitly parsed it).

However, as I want to map the fixed width types towards protobuf fixed
width types, the typedef doesn't resolve the problem.

Hm, let me investigate a way to detect those types in an easier way.

@foonathan foonathan reopened this Dec 11, 2019
@Firefly35
Copy link
Contributor Author

Firefly35 commented Dec 11, 2019 via email

@Firefly35
Copy link
Contributor Author

Firefly35 commented Dec 16, 2019 via email

@Firefly35
Copy link
Contributor Author

Firefly35 commented Dec 16, 2019 via email

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

2 participants