issue with getTypeClass when CXXRecord is declared in an include file

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

issue with getTypeClass when CXXRecord is declared in an include file

Louis Dionne via cfe-dev
Hello,
With the below case I don't have the expected type :

main file (input file of the tool) tests.h :

#include "external_lib.h" namespace Test { void fnc(const external_lib::MyClass& a); }








external_lib.h (in include path):

namespace external_lib { class MyClass { }; }






My code which returns a wrong result: 

void GetSourceRange(const clang::QualType& qualType, clang::SourceRange& srcLoc) { clang::Decl* decl = nullptr; switch (qualType->getTypeClass()) { case clang::Type::Pointer: { auto pointee_type = qualType->getPointeeType(); GetSourceRange(pointee_type, srcLoc); break; } case clang::Type::Elaborated: { auto ET = qualType->getAs<clang::ElaboratedType>(); GetSourceRange(ET->getNamedType(), srcLoc); break; } case clang::Type::RValueReference: case clang::Type::LValueReference: { auto dref = qualType.getNonReferenceType(); GetSourceRange(dref, srcLoc); break; } case clang::Type::Record: { srcLoc = qualType->getAs<clang::RecordType>()->getDecl()->getSourceRange(); decl = qualType->getAs<clang::RecordType>()->getDecl(); break; } case clang::Type::Enum: { srcLoc = qualType->getAs<clang::EnumType>()->getDecl()->getSourceRange(); decl = qualType->getAs<clang::EnumType>()->getDecl(); break; } case clang::Type::Typedef: { srcLoc = qualType->getAs<clang::TypedefType>()->getDecl()->getSourceRange(); decl = qualType->getAs<clang::TypedefType>()->getDecl(); break; } default: { break; } } }















































Firtsly the code execute the L/RVAlueReference's case, but at the second call with type returned by getNonReferenceType() the line qualType->getTypeClass() returns clang::Type::Builtin instead of Elaborated.
What's wrong with this case?

I haven't the issue if MyClass is declared in main file.


Many thanks for helps.


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: issue with getTypeClass when CXXRecord is declared in an include file

Louis Dionne via cfe-dev
On 2 April 2018 at 05:58, ogzu rasa via cfe-dev <[hidden email]> wrote:
Hello,
With the below case I don't have the expected type :

main file (input file of the tool) tests.h :

#include "external_lib.h" namespace Test { void fnc(const external_lib::MyClass& a); }








external_lib.h (in include path):

namespace external_lib { class MyClass { }; }






My code which returns a wrong result: 

void GetSourceRange(const clang::QualType& qualType, clang::SourceRange& srcLoc) { clang::Decl* decl = nullptr; switch (qualType->getTypeClass()) { case clang::Type::Pointer: { auto pointee_type = qualType->getPointeeType(); GetSourceRange(pointee_type, srcLoc); break; } case clang::Type::Elaborated: { auto ET = qualType->getAs<clang::ElaboratedType>(); GetSourceRange(ET->getNamedType(), srcLoc); break; } case clang::Type::RValueReference: case clang::Type::LValueReference: { auto dref = qualType.getNonReferenceType(); GetSourceRange(dref, srcLoc); break; } case clang::Type::Record: { srcLoc = qualType->getAs<clang::RecordType>()->getDecl()->getSourceRange(); decl = qualType->getAs<clang::RecordType>()->getDecl(); break; } case clang::Type::Enum: { srcLoc = qualType->getAs<clang::EnumType>()->getDecl()->getSourceRange(); decl = qualType->getAs<clang::EnumType>()->getDecl(); break; } case clang::Type::Typedef: { srcLoc = qualType->getAs<clang::TypedefType>()->getDecl()->getSourceRange(); decl = qualType->getAs<clang::TypedefType>()->getDecl(); break; } default: { break; } } }















































Firtsly the code execute the L/RVAlueReference's case, but at the second call with type returned by getNonReferenceType() the line qualType->getTypeClass() returns clang::Type::Builtin instead of Elaborated.
What's wrong with this case?

I haven't the issue if MyClass is declared in main file.

My guess would be that your include paths are not configured correctly (so that external_lib.h is not being found, or perhaps the wrong version of that file is found), and you don't have a diagnostics renderer hooked up, so the error message for "external_lib::MyClass" being unknown is not printed anywhere; the BuiltinType you're seeing is probably being created by error recovery. You can call qualType.dump() to check what type you were given.
 
Many thanks for helps.


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev



_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev