26 #include "TClingUtils.h"
30 #include "cling/Interpreter/Interpreter.h"
31 #include "cling/Interpreter/LookupHelper.h"
32 #include "cling/Utils/AST.h"
34 #include "clang/AST/ASTContext.h"
35 #include "clang/AST/DeclCXX.h"
36 #include "clang/AST/Type.h"
37 #include "clang/AST/PrettyPrinter.h"
38 #include "clang/Frontend/CompilerInstance.h"
47 TClingTypeInfo::TClingTypeInfo(cling::Interpreter *interp,
const char *name)
55 void TClingTypeInfo::Init(
const char *name)
57 fQualType = clang::QualType();
60 "TClingTypeInfo::Init(name): looking up clang type: %s", name);
62 const cling::LookupHelper& lh = fInterp->getLookupHelper();
63 clang::QualType QT = lh.findType(name,
64 gDebug > 5 ? cling::LookupHelper::WithDiagnostics
65 : cling::LookupHelper::NoDiagnostics);
69 "TClingTypeInfo::Init(name): clang type not found: %s", name);
71 std::string buf = TClassEdit::InsertStd(name);
73 gDebug > 5 ? cling::LookupHelper::WithDiagnostics
74 : cling::LookupHelper::NoDiagnostics);
78 "TClingTypeInfo::Init(name): "
79 "clang type not found name: %s\n", buf.c_str());
86 "TClingTypeInfo::Init(name): found clang type name: %s\n",
95 "TClingTypeInfo::Init(name): clang type found: %s\n", name);
102 const char *TClingTypeInfo::Name()
const
108 TTHREAD_TLS_DECL( std::string, buf);
111 R__LOCKGUARD(gInterpreterMutex);
112 ROOT::TMetaUtils::GetFullyQualifiedTypeName(buf,fQualType,*fInterp);
118 long TClingTypeInfo::Property()
const
124 if (llvm::isa<clang::TypedefType>(*fQualType)) {
125 property |= kIsTypedef;
127 clang::QualType QT = fQualType.getCanonicalType();
128 if (QT.isConstQualified()) {
129 property |= kIsConstant;
132 if (QT->isArrayType()) {
133 QT = llvm::cast<clang::ArrayType>(QT)->getElementType();
136 else if (QT->isReferenceType()) {
137 property |= kIsReference;
138 QT = llvm::cast<clang::ReferenceType>(QT)->getPointeeType();
141 else if (QT->isPointerType()) {
142 property |= kIsPointer;
143 if (QT.isConstQualified()) {
144 property |= kIsConstPointer;
146 QT = llvm::cast<clang::PointerType>(QT)->getPointeeType();
149 else if (QT->isMemberPointerType()) {
150 QT = llvm::cast<clang::MemberPointerType>(QT)->getPointeeType();
155 if (QT->isBuiltinType()) {
156 property |= kIsFundamental;
158 if (QT.isConstQualified()) {
159 property |= kIsConstant;
161 const clang::TagType *tagQT = llvm::dyn_cast<clang::TagType>(QT.getTypePtr());
164 const clang::TagDecl *TD = llvm::dyn_cast<clang::TagDecl>(tagQT->getDecl());
169 const clang::CXXRecordDecl *CRD =
170 llvm::dyn_cast<clang::CXXRecordDecl>(TD);
171 if (CRD->isClass()) {
172 property |= kIsClass;
174 else if (CRD->isStruct()) {
175 property |= kIsStruct;
177 else if (CRD->isUnion()) {
178 property |= kIsUnion;
180 if (CRD->isThisDeclarationADefinition() && CRD->isAbstract()) {
181 property |= kIsAbstract;
190 int TClingTypeInfo::RefType()
const
197 clang::QualType QT = fQualType.getCanonicalType();
199 if (QT->isArrayType()) {
200 QT = llvm::cast<clang::ArrayType>(QT)->getElementType();
203 else if (QT->isReferenceType()) {
205 QT = llvm::cast<clang::ReferenceType>(QT)->getPointeeType();
208 else if (QT->isPointerType()) {
210 QT = llvm::cast<clang::PointerType>(QT)->getPointeeType();
213 else if (QT->isMemberPointerType()) {
214 QT = llvm::cast<clang::MemberPointerType>(QT)->getPointeeType();
225 val = kParaReference;
236 int TClingTypeInfo::Size()
const
241 if (fQualType->isDependentType()) {
245 if (
const clang::RecordType *RT = fQualType->getAs<clang::RecordType>()) {
246 if (!RT->getDecl()->getDefinition()) {
251 clang::ASTContext &Context = fInterp->getCI()->getASTContext();
253 clang::CharUnits::QuantityType Quantity =
254 Context.getTypeSizeInChars(fQualType).getQuantity();
255 return static_cast<int>(Quantity);
260 const char *TClingTypeInfo::StemName()
const
265 clang::QualType QT = fQualType.getCanonicalType();
267 if (QT->isArrayType()) {
268 QT = llvm::cast<clang::ArrayType>(QT)->getElementType();
271 else if (QT->isReferenceType()) {
272 QT = llvm::cast<clang::ReferenceType>(QT)->getPointeeType();
275 else if (QT->isPointerType()) {
276 QT = llvm::cast<clang::PointerType>(QT)->getPointeeType();
279 else if (QT->isMemberPointerType()) {
280 QT = llvm::cast<clang::MemberPointerType>(QT)->getPointeeType();
286 TTHREAD_TLS_DECL( std::string, buf);
288 clang::PrintingPolicy Policy(fInterp->getCI()->getASTContext().
289 getPrintingPolicy());
290 QT.getAsStringInternal(buf, Policy);
298 const char *TClingTypeInfo::TrueName(
const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt)
const
304 TTHREAD_TLS_DECL( std::string, buf);
307 ROOT::TMetaUtils::GetNormalizedName(buf,fQualType, *fInterp, normCtxt);
316 std::string TClingTypeInfo::NormalizedName(
const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt)
const
322 ROOT::TMetaUtils::GetNormalizedName(buf,fQualType, *fInterp, normCtxt);