standardese/cppast

c++11 fixed types not recognised as builtin types

Firefly35 opened this issue · 6 comments

  • 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).

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.

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.