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

UnqualifiedDesugaredType does not return an unqualified type #562

Open
nike4613 opened this issue Jul 16, 2024 · 2 comments
Open

UnqualifiedDesugaredType does not return an unqualified type #562

nike4613 opened this issue Jul 16, 2024 · 2 comments

Comments

@nike4613
Copy link

Example:

typedef int const* pcint;
pcint g();

Given the decl for g in variable gDecl, gDecl.ReturnType.CanonicalType.PointeeType.CanonicalType.UnqualifiedDesugaredType returns a BuiltinType that still represents const int.

Poking around in the sources suggests that the issue is in the fact that IsSugared returns false for qualified types. What I'd really like here is to be able to get a Type object for Handle.UnqualifiedType, which doesn't seem to exist at the moment.

@tannergooding
Copy link
Member

IsSugared is just calling Ty->isSugared():

unsigned clangsharp_Type_getIsSugared(CXType CT) {
QualType T = GetQualType(CT);
const Type* TP = T.getTypePtrOrNull();
#define ABSTRACT_TYPE(Class, Parent)
#define TYPE(Class, Parent) \
if (const Class##Type* Ty = dyn_cast<Class##Type>(TP)) { \
return Ty->isSugared(); \
}
#include "clang/AST/TypeNodes.inc"
return 0;
}

You'll note that UnqualifiedDesugaredType (https://source.clangsharp.dev/#ClangSharp/Types/Type.cs,2de64541a028759e) is itself just matching the behavior of Type::getUnqalifiedDesugaredType: https://clang.llvm.org/doxygen/Type_8cpp_source.html#l00605

In general ClangSharp tends to just mirror what Clang does and so you'll need to do whatever it is that Clang would expect you to do here.

@nike4613
Copy link
Author

I think the core issue here is that ClangSharp does not have a QualType equivalent; instead, a Type represents a full QualType, but only mirrors the API of Clang's Type*. As I mentioned, I think this is resolvable by simply exposing UnqualifiedType on Type.

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