24 #include <unordered_set>
26 #include "RConfigure.h"
29 #include "compiledata.h"
33 #include "clang/AST/ASTContext.h"
34 #include "clang/AST/Attr.h"
35 #include "clang/AST/CXXInheritance.h"
36 #include "clang/AST/Decl.h"
37 #include "clang/AST/DeclTemplate.h"
38 #include "clang/AST/Type.h"
39 #include "clang/AST/TypeVisitor.h"
40 #include "clang/Frontend/CompilerInstance.h"
41 #include "clang/Lex/HeaderSearch.h"
42 #include "clang/Lex/ModuleMap.h"
43 #include "clang/Lex/Preprocessor.h"
45 #include "clang/Sema/Sema.h"
47 #include "cling/Interpreter/LookupHelper.h"
48 #include "cling/Interpreter/Transaction.h"
49 #include "cling/Interpreter/Interpreter.h"
50 #include "cling/Utils/AST.h"
52 #include "llvm/Support/Path.h"
53 #include "llvm/Support/FileSystem.h"
56 #include "../../../interpreter/llvm/src/tools/clang/lib/Sema/HackForDefaultTemplateArg.h"
65 namespace TMetaUtils {
72 class TNormalizedCtxtImpl {
73 using DeclsCont_t = TNormalizedCtxt::Config_t::SkipCollection;
79 TypesCont_t fTypeWithAlternative;
80 static TemplPtrIntMap_t fTemplatePtrArgsToKeepMap;
82 TNormalizedCtxtImpl(
const cling::LookupHelper &lh);
84 const Config_t &GetConfig()
const {
return fConfig; }
85 const TypesCont_t &GetTypeWithAlternative()
const {
return fTypeWithAlternative; }
86 void AddTemplAndNargsToKeep(
const clang::ClassTemplateDecl* templ,
unsigned int i);
87 int GetNargsToKeep(
const clang::ClassTemplateDecl* templ)
const;
88 const TemplPtrIntMap_t GetTemplNargsToKeepMap()
const {
return fTemplatePtrArgsToKeepMap; }
89 void keepTypedef(
const cling::LookupHelper &lh,
const char* name,
90 bool replace =
false);
100 static clang::NestedNameSpecifier* AddDefaultParametersNNS(
const clang::ASTContext& Ctx,
101 clang::NestedNameSpecifier* scope,
102 const cling::Interpreter &interpreter,
104 if (!scope)
return 0;
106 const clang::Type* scope_type = scope->getAsType();
109 clang::NestedNameSpecifier* outer_scope = scope->getPrefix();
111 outer_scope = AddDefaultParametersNNS(Ctx, outer_scope, interpreter, normCtxt);
114 clang::QualType addDefault =
117 if (addDefault.getTypePtr() != scope_type)
118 return clang::NestedNameSpecifier::Create(Ctx,outer_scope,
120 addDefault.getTypePtr());
127 static bool CheckDefinition(
const clang::CXXRecordDecl *cl,
const clang::CXXRecordDecl *context)
129 if (!cl->hasDefinition()) {
132 "Missing definition for class %s, please #include its header in the header of %s\n",
133 cl->getName().str().c_str(), context->getName().str().c_str());
136 "Missing definition for class %s\n",
137 cl->getName().str().c_str());
149 static clang::NestedNameSpecifier* ReSubstTemplateArgNNS(
const clang::ASTContext &Ctxt,
150 clang::NestedNameSpecifier *scope,
153 if (!scope)
return 0;
155 const clang::Type* scope_type = scope->getAsType();
157 clang::NestedNameSpecifier* outer_scope = scope->getPrefix();
159 outer_scope = ReSubstTemplateArgNNS(Ctxt, outer_scope, instance);
161 clang::QualType substScope =
164 scope = clang::NestedNameSpecifier::Create(Ctxt,outer_scope,
166 substScope.getTypePtr());
175 const clang::BuiltinType * builtin = llvm::dyn_cast<clang::BuiltinType>(type->getCanonicalTypeInternal().getTypePtr());
177 return builtin->isInteger();
185 static bool IsFieldDeclInt(
const clang::FieldDecl *field)
187 return IsTypeInt(field->getType().getTypePtr());
193 static const clang::FieldDecl *GetDataMemberFromAll(
const clang::CXXRecordDecl &cl, llvm::StringRef what)
195 for(clang::RecordDecl::field_iterator field_iter = cl.field_begin(), end = cl.field_end();
198 if (field_iter->getName() ==
what) {
208 static bool CXXRecordDecl__FindOrdinaryMember(
const clang::CXXBaseSpecifier *Specifier,
209 clang::CXXBasePath &Path,
213 clang::RecordDecl *BaseRecord = Specifier->getType()->getAs<clang::RecordType>()->getDecl();
215 const clang::CXXRecordDecl *clxx = llvm::dyn_cast<clang::CXXRecordDecl>(BaseRecord);
216 if (clxx == 0)
return false;
218 const clang::FieldDecl *found = GetDataMemberFromAll(*clxx,(
const char*)Name);
222 clang::NamedDecl* NonConstFD =
const_cast<clang::FieldDecl*
>(found);
223 clang::NamedDecl** BaseSpecFirstHack
224 =
reinterpret_cast<clang::NamedDecl**
>(NonConstFD);
225 Path.Decls = clang::DeclContextLookupResult(BaseSpecFirstHack, 1);
250 static const clang::FieldDecl *GetDataMemberFromAllParents(
const clang::CXXRecordDecl &cl,
const char *what)
252 clang::CXXBasePaths Paths;
253 Paths.setOrigin(const_cast<clang::CXXRecordDecl*>(&cl));
254 if (cl.lookupInBases(&CXXRecordDecl__FindOrdinaryMember,
255 (
void*) const_cast<char*>(what),
258 clang::CXXBasePaths::paths_iterator
iter = Paths.begin();
259 if (iter != Paths.end()) {
261 const clang::FieldDecl *found = (clang::FieldDecl *)iter->Decls.data();
269 cling::LookupHelper::DiagSetting ToLHDS(
bool wantDiags) {
271 ? cling::LookupHelper::WithDiagnostics
272 : cling::LookupHelper::NoDiagnostics;
279 namespace TMetaUtils {
285 void TNormalizedCtxtImpl::AddTemplAndNargsToKeep(
const clang::ClassTemplateDecl* templ,
288 Error(
"TNormalizedCtxt::AddTemplAndNargsToKeep",
289 "Tring to specify a number of template arguments to keep for a null pointer. Exiting without assigning any value.\n");
293 const clang::ClassTemplateDecl* canTempl = templ->getCanonicalDecl();
295 if(fTemplatePtrArgsToKeepMap.count(canTempl)==1 &&
296 fTemplatePtrArgsToKeepMap[canTempl]!=(int)i){
297 const std::string templateName (canTempl->getNameAsString());
298 const std::string i_str (std::to_string(i));
299 const std::string previousArgsToKeep(std::to_string(fTemplatePtrArgsToKeepMap[canTempl]));
300 Error(
"TNormalizedCtxt::AddTemplAndNargsToKeep",
301 "Tring to specify for template %s %s arguments to keep, while before this number was %s\n",
302 canTempl->getNameAsString().c_str(),
304 previousArgsToKeep.c_str());
307 fTemplatePtrArgsToKeepMap[canTempl]=i;
314 int TNormalizedCtxtImpl::GetNargsToKeep(
const clang::ClassTemplateDecl* templ)
const{
315 const clang::ClassTemplateDecl* constTempl = templ->getCanonicalDecl();
316 auto thePairPtr = fTemplatePtrArgsToKeepMap.find(constTempl);
317 int nArgsToKeep = (thePairPtr != fTemplatePtrArgsToKeepMap.end() ) ? thePairPtr->second : -1;
325 fImpl(new TNormalizedCtxtImpl(lh))
329 fImpl(new TNormalizedCtxtImpl(*other.fImpl))
336 return fImpl->GetConfig();
339 return fImpl->GetTypeWithAlternative();
343 return fImpl->AddTemplAndNargsToKeep(templ, i);
347 return fImpl->GetNargsToKeep(templ);
350 return fImpl->GetTemplNargsToKeepMap();
355 return fImpl->keepTypedef(lh, name, replace);
365 const clang::RecordDecl *decl,
368 bool rRequestNoInputOperator,
369 bool rRequestOnlyTClass,
370 int rRequestedVersionNumber,
371 const cling::Interpreter &interpreter,
373 fRuleIndex(index), fDecl(decl), fRequestStreamerInfo(rStreamerInfo), fRequestNoStreamer(rNoStreamer),
374 fRequestNoInputOperator(rRequestNoInputOperator), fRequestOnlyTClass(rRequestOnlyTClass), fRequestedVersionNumber(rRequestedVersionNumber)
385 const clang::RecordDecl *decl,
386 const char *requestName,
387 unsigned int nTemplateArgsToSkip,
390 bool rRequestNoInputOperator,
391 bool rRequestOnlyTClass,
392 int rRequestVersionNumber,
393 const cling::Interpreter &interpreter,
395 fRuleIndex(index), fDecl(decl), fRequestedName(
""), fRequestStreamerInfo(rStreamerInfo), fRequestNoStreamer(rNoStreamer),
396 fRequestNoInputOperator(rRequestNoInputOperator), fRequestOnlyTClass(rRequestOnlyTClass), fRequestedVersionNumber(rRequestVersionNumber)
405 "Could not remove the requested template arguments.\n");
414 const clang::RecordDecl *decl,
415 const char *requestName,
418 bool rRequestNoInputOperator,
419 bool rRequestOnlyTClass,
420 int rRequestVersionNumber,
421 const cling::Interpreter &interpreter,
423 fRuleIndex(index), fDecl(decl), fRequestedName(
""), fRequestStreamerInfo(rStreamerInfo), fRequestNoStreamer(rNoStreamer),
424 fRequestNoInputOperator(rRequestNoInputOperator), fRequestOnlyTClass(rRequestOnlyTClass), fRequestedVersionNumber(rRequestVersionNumber)
437 const clang::RecordDecl *decl,
438 const char *requestName,
441 bool rRequestNoInputOperator,
442 bool rRequestOnlyTClass,
443 int rRequestVersionNumber,
444 const cling::Interpreter &interpreter,
446 fRuleIndex(index), fDecl(decl), fRequestedName(
""), fRequestStreamerInfo(rStreamerInfo), fRequestNoStreamer(rNoStreamer), fRequestNoInputOperator(rRequestNoInputOperator), fRequestOnlyTClass(rRequestOnlyTClass), fRequestedVersionNumber(rRequestVersionNumber)
455 if (requestName && requestName[0]) {
471 ExistingTypeCheck_t existingTypeCheck,
472 AutoParse_t autoParse,
473 const int* pgDebug ):
474 fInterpreter(&interpreter),fNormalizedCtxt(&normCtxt),
475 fExistingTypeCheck(existingTypeCheck),
476 fAutoParse(autoParse), fPDebug(pgDebug)
487 if (tname.empty())
return false;
497 const cling::LookupHelper& lh =
fInterpreter->getLookupHelper();
498 clang::QualType t = lh.findType(nameLong, ToLHDS(
WantDiags()));
501 if (!dest.isNull() && (dest != t)) {
504 dest.getAsStringInternal(nameLong,
fInterpreter->getCI()->getASTContext().getPrintingPolicy());
512 const std::string &nameLong)
514 const cling::LookupHelper& lh =
fInterpreter->getLookupHelper();
515 clang::QualType t = lh.findType(nondef.c_str(), ToLHDS(
WantDiags()));
518 if (!dest.isNull() && (dest != t) &&
519 nameLong == t.getAsString(
fInterpreter->getCI()->getASTContext().getPrintingPolicy()))
529 const cling::LookupHelper& lh =
fInterpreter->getLookupHelper();
530 const clang::Decl *scope = lh.findScope(base.c_str(), ToLHDS(
WantDiags()), 0);
537 const clang::NamespaceDecl *nsdecl = llvm::dyn_cast<clang::NamespaceDecl>(scope);
538 isInlined = nsdecl && nsdecl->isInline();
549 if (tname.empty())
return false;
557 return ! result.empty();
566 const cling::LookupHelper& lh =
fInterpreter->getLookupHelper();
567 clang::QualType t = lh.findType(tname.c_str(), ToLHDS(
WantDiags()));
574 if (!dest.isNull() && dest != t) {
578 clang::PrintingPolicy policy(
fInterpreter->getCI()->getASTContext().getPrintingPolicy());
579 policy.SuppressTagKeyword =
true;
580 policy.SuppressScope =
true;
586 dest.getAsStringInternal(result, policy);
588 unsigned long offset = 0;
589 if (strncmp(result.c_str(),
"const ", 6) == 0) {
592 if (strncmp(result.c_str()+offset,
"std::", 5) == 0) {
593 result.erase(offset,5);
595 for(
unsigned int i = 1; i<result.length(); ++i) {
596 if (result[i]==
's') {
597 if (result[i-1]==
'<' || result[i-1]==
',' || result[i-1]==
' ') {
598 if (result.compare(i,5,
"std::",5) == 0) {
603 if (result[i]==
' ') {
604 if (result[i-1] ==
',') {
607 }
else if ( (i+1) < result.length() &&
608 (result[i+1]==
'*' || result[i+1]==
'&' || result[i+1]==
'[') ) {
633 void ROOT::TMetaUtils::TNormalizedCtxtImpl::keepTypedef(
const cling::LookupHelper &lh,
636 clang::QualType toSkip = lh.findType(name, cling::LookupHelper::WithDiagnostics);
638 const clang::TypedefType *tt = llvm::dyn_cast<clang::TypedefType>(
T);
640 clang::Decl* D = tt->getDecl();
641 fConfig.m_toSkip.insert(D);
643 clang::QualType canon = toSkip->getCanonicalTypeInternal();
644 fConfig.m_toReplace.insert(std::make_pair(canon.getTypePtr(),
T));
646 fTypeWithAlternative.insert(
T);
657 ROOT::TMetaUtils::TNormalizedCtxtImpl::TNormalizedCtxtImpl(
const cling::LookupHelper &lh)
659 keepTypedef(lh,
"Double32_t");
660 keepTypedef(lh,
"Float16_t");
661 keepTypedef(lh,
"Long64_t",
true);
662 keepTypedef(lh,
"ULong64_t",
true);
664 clang::QualType toSkip = lh.findType(
"string", cling::LookupHelper::WithDiagnostics);
665 if (
const clang::TypedefType* TT
666 = llvm::dyn_cast_or_null<clang::TypedefType>(toSkip.getTypePtr()))
667 fConfig.m_toSkip.insert(TT->getDecl());
669 toSkip = lh.findType(
"std::string", cling::LookupHelper::WithDiagnostics);
670 if (!toSkip.isNull()) {
671 if (
const clang::TypedefType* TT
672 = llvm::dyn_cast_or_null<clang::TypedefType>(toSkip.getTypePtr()))
673 fConfig.m_toSkip.insert(TT->getDecl());
675 clang::QualType canon = toSkip->getCanonicalTypeInternal();
676 fConfig.m_toReplace.insert(std::make_pair(canon.getTypePtr(),toSkip.getTypePtr()));
681 TNCtxtFullQual::TemplPtrIntMap_t TNCtxtFullQual::fTemplatePtrArgsToKeepMap=TNCtxtFullQual::TemplPtrIntMap_t{};
689 return (cl.getKind() == clang::Decl::ClassTemplatePartialSpecialization
690 || cl.getKind() == clang::Decl::ClassTemplateSpecialization);
697 const cling::Interpreter& interp)
699 clang::Sema*
S = &interp.getSema();
700 const clang::NamedDecl* ND = cling::utils::Lookup::Named(S, name, cl);
701 if (ND == (clang::NamedDecl*)-1)
702 return (clang::FunctionDecl*)-1;
703 return llvm::dyn_cast_or_null<clang::FunctionDecl>(ND);
709 const clang::CXXRecordDecl *
713 const cling::LookupHelper& lh = interp.getLookupHelper();
716 const clang::CXXRecordDecl *
result
717 = llvm::dyn_cast_or_null<clang::CXXRecordDecl>
718 (lh.findScope(name, cling::LookupHelper::NoDiagnostics, resultType));
720 std::string std_name(
"std::");
724 result = llvm::dyn_cast_or_null<clang::CXXRecordDecl>
725 (lh.findScope(std_name, cling::LookupHelper::NoDiagnostics, resultType));
735 clang::QualType qType(cl->getTypeForDecl(),0);
743 clang::Sema&
S = interp.getCI()->getSema();
746 cling::Interpreter::PushTransactionRAII RAII(const_cast<cling::Interpreter*>(&interp));
747 return S.RequireCompleteType( Loc, Type , 0);
753 const clang::CXXRecordDecl *context,
const cling::Interpreter &interp)
759 if (!cl->getDefinition() || !cl->isCompleteDefinition()) {
763 if (!CheckDefinition(cl, context) || !CheckDefinition(base, context)) {
767 if (!base->hasDefinition()) {
771 return cl->isDerivedFrom(base);
783 const clang::NamedDecl *base
787 return IsBase(CRD, llvm::dyn_cast<clang::CXXRecordDecl>( base ),
788 llvm::dyn_cast<clang::CXXRecordDecl>(m.getDeclContext()),interp);
796 const clang::NamedDecl &forcontext,
797 const clang::QualType &qti,
798 const char *R__t,
int rwmode,
799 const cling::Interpreter &interp,
802 static const clang::CXXRecordDecl *TObject_decl
805 kBIT_ISTOBJECT = 0x10000000,
806 kBIT_HASSTREAMER = 0x20000000,
807 kBIT_ISSTRING = 0x40000000,
809 kBIT_ISPOINTER = 0x00001000,
810 kBIT_ISFUNDAMENTAL = 0x00000020,
811 kBIT_ISENUM = 0x00000008
824 clang::CXXRecordDecl *cxxtype = rawtype->getAsCXXRecordDecl() ;
826 int isTObj = cxxtype && (
IsBase(cxxtype,TObject_decl,
nullptr,interp) || rawname ==
"TObject");
830 if (ti.isPointerType()) kase |= kBIT_ISPOINTER;
831 if (rawtype->isFundamentalType()) kase |= kBIT_ISFUNDAMENTAL;
832 if (rawtype->isEnumeralType()) kase |= kBIT_ISENUM;
835 if (isTObj) kase |= kBIT_ISTOBJECT;
836 if (isStre) kase |= kBIT_HASSTREAMER;
837 if (tiName ==
"string") kase |= kBIT_ISSTRING;
838 if (tiName ==
"string*") kase |= kBIT_ISSTRING;
842 tcl =
" internal error in rootcling ";
848 if (R__t) finalString <<
" " << tiName <<
" " << R__t <<
";" << std::endl;
851 case kBIT_ISFUNDAMENTAL:
853 finalString <<
" R__b >> " << R__t <<
";" << std::endl;
856 case kBIT_ISPOINTER|kBIT_ISTOBJECT|kBIT_HASSTREAMER:
858 finalString <<
" " << R__t <<
" = (" << tiName <<
")R__b.ReadObjectAny(" << tcl <<
");" << std::endl;
867 finalString <<
" Int_t readtemp;" << std::endl
868 <<
" R__b >> readtemp;" << std::endl
869 <<
" " << R__t <<
" = static_cast<" << tiName <<
">(readtemp);" << std::endl;
872 case kBIT_HASSTREAMER:
873 case kBIT_HASSTREAMER|kBIT_ISTOBJECT:
875 finalString <<
" " << R__t <<
".Streamer(R__b);" << std::endl;
878 case kBIT_HASSTREAMER|kBIT_ISPOINTER:
881 finalString <<
" if (R__b.GetInfo() && R__b.GetInfo()->GetOldVersion()<=3) {" << std::endl;
882 if (cxxtype && cxxtype->isAbstract()) {
883 finalString <<
" R__ASSERT(0);// " << objType <<
" is abstract. We assume that older file could not be produced using this streaming method." << std::endl;
885 finalString <<
" " << R__t <<
" = new " << objType <<
";" << std::endl
886 <<
" " << R__t <<
"->Streamer(R__b);" << std::endl;
888 finalString <<
" } else {" << std::endl
889 <<
" " << R__t <<
" = (" << tiName <<
")R__b.ReadObjectAny(" << tcl <<
");" << std::endl
890 <<
" }" << std::endl;
895 finalString <<
" {TString R__str;" << std::endl
896 <<
" R__str.Streamer(R__b);" << std::endl
897 <<
" " << R__t <<
" = R__str.Data();}" << std::endl;
900 case kBIT_ISSTRING|kBIT_ISPOINTER:
902 finalString <<
" {TString R__str;" << std::endl
903 <<
" R__str.Streamer(R__b);" << std::endl
904 <<
" " << R__t <<
" = new string(R__str.Data());}" << std::endl;
909 finalString <<
" " << R__t <<
" = (" << tiName <<
")R__b.ReadObjectAny(" << tcl <<
");" << std::endl;
914 finalString <<
" R__b.StreamObject(&" << R__t <<
"," << tcl <<
");" << std::endl;
922 case kBIT_ISFUNDAMENTAL:
923 case kBIT_ISPOINTER|kBIT_ISTOBJECT|kBIT_HASSTREAMER:
925 finalString <<
" R__b << " << R__t <<
";" << std::endl;
930 finalString <<
" { void *ptr_enum = (void*)&" << R__t <<
";\n";
931 finalString <<
" R__b >> *reinterpret_cast<Int_t*>(ptr_enum); }" << std::endl;
934 case kBIT_HASSTREAMER:
935 case kBIT_HASSTREAMER|kBIT_ISTOBJECT:
937 finalString <<
" ((" << objType <<
"&)" << R__t <<
").Streamer(R__b);" << std::endl;
940 case kBIT_HASSTREAMER|kBIT_ISPOINTER:
942 finalString <<
" R__b.WriteObjectAny(" << R__t <<
"," << tcl <<
");" << std::endl;
947 finalString <<
" {TString R__str(" << R__t <<
".c_str());" << std::endl
948 <<
" R__str.Streamer(R__b);};" << std::endl;
951 case kBIT_ISSTRING|kBIT_ISPOINTER:
953 finalString <<
" {TString R__str(" << R__t <<
"->c_str());" << std::endl
954 <<
" R__str.Streamer(R__b);}" << std::endl;
959 finalString <<
" R__b.WriteObjectAny(" << R__t <<
"," << tcl <<
");" << std::endl;
964 finalString <<
" R__b.StreamObject((" << objType <<
"*)&" << R__t <<
"," << tcl <<
");" << std::endl;
975 const cling::Interpreter& interpreter)
977 const char *arg = ioctortype.
GetName();
979 if (ioctortype.
GetType() ==0 && (arg == 0 || arg[0] ==
'\0')) {
981 clang::CXXRecordDecl* ncCl =
const_cast<clang::CXXRecordDecl*
>(cl);
984 cling::Interpreter::PushTransactionRAII clingRAII(const_cast<cling::Interpreter*>(&interpreter));
986 if (
auto* Ctor = interpreter.getCI()->getSema().LookupDefaultConstructor(ncCl)) {
987 if (Ctor->getAccess() == clang::AS_public) {
991 return EIOCtorCategory::kAbsent;
994 for (clang::CXXRecordDecl::ctor_iterator
iter = cl->ctor_begin(), end = cl->ctor_end();
998 if (
iter->getAccess() != clang::AS_public)
1002 if (
iter->getNumParams() == 1) {
1003 clang::QualType argType( (*
iter->param_begin())->getType() );
1004 argType = argType.getDesugaredType(cl->getASTContext());
1006 auto ioCtorCategory = EIOCtorCategory::kAbsent;
1007 if (argType->isPointerType()) {
1008 ioCtorCategory = EIOCtorCategory::kIOPtrType;
1009 argType = argType->getPointeeType();
1010 }
else if (argType->isReferenceType()){
1011 ioCtorCategory = EIOCtorCategory::kIORefType;
1012 argType = argType.getNonReferenceType();
1014 if (ioCtorCategory != EIOCtorCategory::kAbsent) {
1015 argType = argType.getDesugaredType(cl->getASTContext());
1016 const clang::CXXRecordDecl *argDecl = argType->getAsCXXRecordDecl();
1017 if (argDecl && ioctortype.
GetType()) {
1018 if (argDecl->getCanonicalDecl() == ioctortype.
GetType()->getCanonicalDecl()) {
1019 return ioCtorCategory;
1022 std::string realArg = argType.getAsString();
1023 std::string clarg(
"class ");
1025 if (realArg == clarg) {
1026 return ioCtorCategory;
1034 return EIOCtorCategory::kAbsent;
1041 const char *method,
const char *proto,
1042 const cling::Interpreter &interp,
1045 const clang::FunctionDecl* funcD
1046 = interp.getLookupHelper().findFunctionProto(cinfo, method, proto,
1047 diagnose ? cling::LookupHelper::WithDiagnostics
1048 : cling::LookupHelper::NoDiagnostics);
1050 return llvm::dyn_cast<
const clang::CXXMethodDecl>(funcD);
1059 namespace TMetaUtils {
1062 const cling::LookupHelper& lh = interp.getLookupHelper();
1065 clang::QualType instanceType = lh.findType(type_of_arg, cling::LookupHelper::WithDiagnostics);
1066 if (!instanceType.isNull())
1067 fArgType = instanceType->getAsCXXRecordDecl();
1081 const cling::Interpreter &interp)
1083 if (cl->isAbstract())
return false;
1085 for (RConstructorTypes::const_iterator ctorTypeIt = ctorTypes.begin();
1086 ctorTypeIt!=ctorTypes.end(); ++ctorTypeIt) {
1090 if (EIOCtorCategory::kAbsent == ioCtorCat)
1093 std::string proto( ctorTypeIt->GetName() );
1094 bool defaultCtor = proto.empty();
1100 if (EIOCtorCategory::kIOPtrType == ioCtorCat){
1102 }
else if (EIOCtorCategory::kIORefType == ioCtorCat) {
1106 arg +=
")nullptr )";
1109 const clang::CXXMethodDecl *method
1111 cling::LookupHelper::NoDiagnostics);
1112 if (method && method->getAccess() != clang::AS_public) {
1127 if (!cl)
return false;
1129 if (cl->hasUserDeclaredDestructor()) {
1131 clang::CXXDestructorDecl *
dest = cl->getDestructor();
1133 return (dest->getAccess() == clang::AS_public);
1145 const char *methodname,
1147 const cling::Interpreter &interp,
1150 const clang::CXXMethodDecl *method
1152 diagnose ? cling::LookupHelper::WithDiagnostics
1153 : cling::LookupHelper::NoDiagnostics);
1154 return (method && method->getAccess() == clang::AS_public);
1165 const char *proto =
"TDirectory*";
1166 const char *name =
"DirectoryAutoAdd";
1180 const char *proto =
"TCollection*,TFileMergeInfo*";
1181 const char *name =
"Merge";
1194 const char *proto =
"TCollection*";
1195 const char *name =
"Merge";
1210 const char *proto =
"TFileMergeInfo*";
1211 const char *name =
"ResetAfterMerge";
1221 const clang::CXXRecordDecl* clxx,
1222 const cling::Interpreter &interp,
1225 static const char *proto =
"TBuffer&";
1227 const clang::CXXMethodDecl *method
1229 cling::LookupHelper::NoDiagnostics);
1230 const clang::DeclContext *clxx_as_context = llvm::dyn_cast<clang::DeclContext>(clxx);
1232 return (method && method->getDeclContext() == clxx_as_context
1240 const clang::CXXRecordDecl* clxx,
1241 const cling::Interpreter &interp,
1244 static const char *proto =
"TBuffer&,TClass*";
1246 const clang::CXXMethodDecl *method
1248 cling::LookupHelper::NoDiagnostics);
1249 const clang::DeclContext *clxx_as_context = llvm::dyn_cast<clang::DeclContext>(clxx);
1251 return (method && method->getDeclContext() == clxx_as_context
1281 clang::QualType qualType(&type,0);
1313 llvm::raw_string_ostream stream(qual_name);
1314 clang::PrintingPolicy policy( cl.getASTContext().getPrintingPolicy() );
1315 policy.SuppressTagKeyword =
true;
1316 policy.SuppressUnwrittenScope =
true;
1318 cl.getNameForDiagnostic(stream,policy,
true);
1321 if ( qual_name ==
"(anonymous " ) {
1322 size_t pos = qual_name.find(
':');
1323 qual_name.erase(0,pos+2);
1339 const clang::Type* declType ( recordDecl.getTypeForDecl() );
1340 clang::QualType qualType(declType,0);
1374 std::stringstream dims;
1375 std::string typenameStr;
1377 const clang::ASTContext& astContext = cl.getASTContext();
1380 for(clang::RecordDecl::field_iterator field_iter = cl.field_begin(), end = cl.field_end();
1388 typenameStr.clear();
1392 clang::QualType fieldType(field_iter->getType());
1393 if (fieldType->isConstantArrayType()) {
1394 const clang::ConstantArrayType *arrayType = llvm::dyn_cast<clang::ConstantArrayType>(fieldType.getTypePtr());
1396 dims <<
"[" << arrayType->getSize().getLimitedValue() <<
"]";
1397 fieldType = arrayType->getElementType();
1398 arrayType = llvm::dyn_cast<clang::ConstantArrayType>(arrayType->getArrayElementTypeNoTypeQual());
1408 for(clang::CXXRecordDecl::base_class_const_iterator
iter = cl.bases_begin(), end = cl.bases_end();
1411 std::string basename(
iter->getType()->getAsCXXRecordDecl()->getNameAsString() );
1421 const cling::Interpreter &interp,
1424 return interp.getLookupHelper().findFunctionProto(cinfo, method, proto,
1425 diagnose ? cling::LookupHelper::WithDiagnostics
1426 : cling::LookupHelper::NoDiagnostics);
1460 clang::SourceLocation sourceLocation = decl->getLocation();
1461 clang::SourceManager& sourceManager = decl->getASTContext().getSourceManager();
1463 if (!sourceLocation.isValid() ) {
1467 if (!sourceLocation.isFileID()) {
1468 sourceLocation = sourceManager.getExpansionRange(sourceLocation).second;
1471 if (sourceLocation.isValid() && sourceLocation.isFileID()) {
1472 return sourceManager.getLineNumber(sourceManager.getFileID(sourceLocation),sourceManager.getFileOffset(sourceLocation));
1485 while (llvm::isa<clang::PointerType>(instanceType.getTypePtr())
1486 || llvm::isa<clang::ReferenceType>(instanceType.getTypePtr()))
1488 instanceType = instanceType->getPointeeType();
1491 const clang::ElaboratedType* etype
1492 = llvm::dyn_cast<clang::ElaboratedType>(instanceType.getTypePtr());
1494 instanceType = clang::QualType(etype->getNamedType().getTypePtr(),0);
1507 const clang::CXXRecordDecl* clxx = instanceType->getAsCXXRecordDecl();
1508 if (clxx && clxx->getTemplateSpecializationKind() != clang::TSK_Undeclared) {
1510 const clang::TemplateSpecializationType* TST
1511 = llvm::dyn_cast<
const clang::TemplateSpecializationType>(instanceType.getTypePtr());
1518 for(clang::TemplateSpecializationType::iterator
1519 I = TST->begin(),
E = TST->end();
1537 const cling::Interpreter &interp,
1540 const clang::CXXRecordDecl* clxx = llvm::dyn_cast<clang::CXXRecordDecl>(cl.
GetRecordDecl());
1541 if (clxx->getTemplateSpecializationKind() == clang::TSK_Undeclared)
return 0;
1543 clang::QualType instanceType = interp.getLookupHelper().findType(cl.
GetNormalizedName(),
1544 cling::LookupHelper::WithDiagnostics);
1545 if (instanceType.isNull()) {
1558 clang::AnnotateAttr* annAttr = clang::dyn_cast<clang::AnnotateAttr>(attribute);
1563 attrString = annAttr->getAnnotation();
1573 if (substrFound==std::string::npos) {
1578 attrName = attributeStr.substr(0, EndPart1);
1580 attrValue = attributeStr.substr(EndPart1 + separatorLength);
1588 std::string attrString;
1590 if (0!=ret)
return ret;
1598 const std::string& propName,
1599 std::string& propValue)
1601 for (clang::Decl::attr_iterator attrIt = decl.attr_begin();
1602 attrIt!=decl.attr_end();++attrIt){
1603 clang::AnnotateAttr* annAttr = clang::dyn_cast<clang::AnnotateAttr>(*attrIt);
1604 if (!annAttr)
continue;
1606 llvm::StringRef attribute = annAttr->getAnnotation();
1608 if (split.first != propName.c_str())
continue;
1610 propValue = split.second;
1621 const std::string& propName,
1624 for (clang::Decl::attr_iterator attrIt = decl.attr_begin();
1625 attrIt!=decl.attr_end();++attrIt){
1626 clang::AnnotateAttr* annAttr = clang::dyn_cast<clang::AnnotateAttr>(*attrIt);
1627 if (!annAttr)
continue;
1629 llvm::StringRef attribute = annAttr->getAnnotation();
1631 if (split.first != propName.c_str())
continue;
1633 return split.second.getAsInteger(10,propValue);
1644 const clang::CXXRecordDecl *decl,
1645 const cling::Interpreter &interp,
1648 bool& needCollectionProxy)
1652 std::string mappedname;
1654 std::string csymbol = classname;
1662 csymbol.insert(0,
"::");
1669 const cling::LookupHelper& lh = interp.getLookupHelper();
1672 bool isStdNotString = isStd && !isString;
1674 finalString <<
"namespace ROOT {" <<
"\n";
1678 finalString <<
" static TClass *" << mappedname.c_str() <<
"_Dictionary();\n"
1679 <<
" static void " << mappedname.c_str() <<
"_TClassManip(TClass*);\n";
1685 finalString <<
" static void *new_" << mappedname.c_str() <<
"(void *p = 0);" <<
"\n";
1689 finalString <<
" static void *newArray_";
1690 finalString << mappedname.c_str();
1691 finalString <<
"(Long_t size, void *p);";
1692 finalString <<
"\n";
1697 finalString <<
" static void delete_" << mappedname.c_str() <<
"(void *p);" <<
"\n" <<
" static void deleteArray_" << mappedname.c_str() <<
"(void *p);" <<
"\n" <<
" static void destruct_" << mappedname.c_str() <<
"(void *p);" <<
"\n";
1700 finalString <<
" static void directoryAutoAdd_" << mappedname.c_str() <<
"(void *obj, TDirectory *dir);" <<
"\n";
1703 finalString <<
" static void streamer_" << mappedname.c_str() <<
"(TBuffer &buf, void *obj);" <<
"\n";
1706 finalString <<
" static void conv_streamer_" << mappedname.c_str() <<
"(TBuffer &buf, void *obj, const TClass*);" <<
"\n";
1709 finalString <<
" static Long64_t merge_" << mappedname.c_str() <<
"(void *obj, TCollection *coll,TFileMergeInfo *info);" <<
"\n";
1712 finalString <<
" static void reset_" << mappedname.c_str() <<
"(void *obj, TFileMergeInfo *info);" <<
"\n";
1719 std::string declName;
1721 ROOT::SchemaRuleClassMap_t::iterator rulesIt1 =
ROOT::gReadRules.find( declName.c_str() );
1722 ROOT::SchemaRuleClassMap_t::iterator rulesIt2 =
ROOT::gReadRawRules.find( declName.c_str() );
1733 finalString <<
"\n // Schema evolution read functions\n";
1734 std::list<ROOT::SchemaRuleMap_t>::iterator rIt = rulesIt1->second.begin();
1735 while( rIt != rulesIt1->second.end() ) {
1742 rIt = rulesIt1->second.erase(rIt);
1750 if( rIt->find(
"code" ) != rIt->end() ) {
1766 finalString <<
"\n // Schema evolution read raw functions\n";
1767 std::list<ROOT::SchemaRuleMap_t>::iterator rIt = rulesIt2->second.begin();
1768 while( rIt != rulesIt2->second.end() ) {
1775 rIt = rulesIt2->second.erase(rIt);
1783 if( rIt->find(
"code" ) == rIt->end() )
1791 finalString <<
"\n" <<
" // Function generating the singleton type initializer" <<
"\n";
1793 finalString <<
" static TGenericClassInfo *GenerateInitInstanceLocal(const " << csymbol <<
"*)" <<
"\n" <<
" {" <<
"\n";
1795 finalString <<
" " << csymbol <<
" *ptr = 0;" <<
"\n";
1799 finalString <<
" static ::TVirtualIsAProxy* isa_proxy = new ::TInstrumentedIsAProxy< " << csymbol <<
" >(0);" <<
"\n";
1802 finalString <<
" static ::TVirtualIsAProxy* isa_proxy = new ::TIsAProxy(typeid(" << csymbol <<
"));" <<
"\n";
1804 finalString <<
" static ::ROOT::TGenericClassInfo " <<
"\n" <<
" instance(\"" << classname.c_str() <<
"\", ";
1807 finalString << csymbol <<
"::Class_Version(), ";
1809 finalString <<
"2, ";
1811 finalString <<
"-2, ";
1817 static const char *versionFunc =
"GetClassVersion";
1821 std::string proto = classname +
"*";
1822 const clang::Decl* ctxt = llvm::dyn_cast<clang::Decl>((*cl).getDeclContext());
1823 const clang::FunctionDecl *methodinfo
1825 interp, cling::LookupHelper::NoDiagnostics);
1833 finalString <<
"GetClassVersion< ";
1834 finalString << classname.c_str();
1835 finalString <<
" >(), ";
1843 if (filename.length() > 0) {
1844 for (
unsigned int i=0; i<filename.length(); i++) {
1845 if (filename[i]==
'\\') filename[i]=
'/';
1849 <<
"," <<
"\n" <<
" typeid(" << csymbol
1850 <<
"), ::ROOT::Internal::DefineBehavior(ptr, ptr)," <<
"\n" <<
" ";
1853 finalString <<
"&" << csymbol <<
"::Dictionary, ";
1855 finalString <<
"&" << mappedname <<
"_Dictionary, ";
1859 TClassTable__kHasCustomStreamerMember = 0x10
1864 rootflag = rootflag | TClassTable__kHasCustomStreamerMember;
1866 finalString <<
"isa_proxy, " << rootflag <<
"," <<
"\n" <<
" sizeof(" << csymbol <<
") );" <<
"\n";
1868 finalString <<
" instance.SetNew(&new_" << mappedname.c_str() <<
");" <<
"\n";
1870 finalString <<
" instance.SetNewArray(&newArray_" << mappedname.c_str() <<
");" <<
"\n";
1873 finalString <<
" instance.SetDelete(&delete_" << mappedname.c_str() <<
");" <<
"\n" <<
" instance.SetDeleteArray(&deleteArray_" << mappedname.c_str() <<
");" <<
"\n" <<
" instance.SetDestructor(&destruct_" << mappedname.c_str() <<
");" <<
"\n";
1876 finalString <<
" instance.SetDirectoryAutoAdd(&directoryAutoAdd_" << mappedname.c_str() <<
");" <<
"\n";
1880 finalString <<
" instance.SetStreamerFunc(&streamer_" << mappedname.c_str() <<
");" <<
"\n";
1884 finalString <<
" instance.SetConvStreamerFunc(&conv_streamer_" << mappedname.c_str() <<
");" <<
"\n";
1887 finalString <<
" instance.SetMerge(&merge_" << mappedname.c_str() <<
");" <<
"\n";
1890 finalString <<
" instance.SetResetAfterMerge(&reset_" << mappedname.c_str() <<
");" <<
"\n";
1893 finalString <<
" instance.AdoptCollectionProxyInfo(TCollectionProxyInfo::Generate(TCollectionProxyInfo::" <<
"Pushback" <<
"<Internal::TStdBitsetHelper< " << classname.c_str() <<
" > >()));" <<
"\n";
1895 needCollectionProxy =
true;
1896 }
else if (stl != 0 &&
1899 int idx = classname.find(
"<");
1900 int stlType = (idx!=(int)std::string::npos) ?
TClassEdit::STLKind(classname.substr(0,idx).c_str()) : 0;
1901 const char* methodTCP=0;
1906 methodTCP=
"Pushback";
1909 methodTCP=
"Pushfront";
1915 methodTCP=
"MapInsert";
1924 finalString <<
" instance.AdoptCollectionProxyInfo(TCollectionProxyInfo::Generate(TCollectionProxyInfo::" << methodTCP <<
"< " << classname.c_str() <<
" >()));" <<
"\n";
1926 needCollectionProxy =
true;
1934 finalString <<
"\n" <<
" ::ROOT::AddClassAlternate(\""
1943 finalString <<
"\n" <<
" ROOT::Internal::TSchemaHelper* rule;" <<
"\n";
1947 finalString <<
"\n" <<
" // the io read rules" <<
"\n" <<
" std::vector<ROOT::Internal::TSchemaHelper> readrules(" << rulesIt1->second.size() <<
");" <<
"\n";
1949 finalString <<
" instance.SetReadRules( readrules );" <<
"\n";
1953 finalString <<
"\n" <<
" // the io read raw rules" <<
"\n" <<
" std::vector<ROOT::Internal::TSchemaHelper> readrawrules(" << rulesIt2->second.size() <<
");" <<
"\n";
1955 finalString <<
" instance.SetReadRawRules( readrawrules );" <<
"\n";
1958 finalString <<
" return &instance;" <<
"\n" <<
" }" <<
"\n";
1962 finalString <<
" TGenericClassInfo *GenerateInitInstance(const " << csymbol <<
"*)" <<
"\n" <<
" {\n return GenerateInitInstanceLocal((" << csymbol <<
"*)0);\n }" <<
"\n";
1965 finalString <<
" // Static variable to force the class initialization" <<
"\n";
1969 finalString <<
" static ::ROOT::TGenericClassInfo *_R__UNIQUE_(Init) = GenerateInitInstanceLocal((const " << csymbol <<
"*)0x0); R__UseDummy(_R__UNIQUE_(Init));" <<
"\n";
1972 finalString <<
"\n" <<
" // Dictionary for non-ClassDef classes" <<
"\n"
1973 <<
" static TClass *" << mappedname <<
"_Dictionary() {\n"
1974 <<
" TClass* theClass ="
1975 <<
"::ROOT::GenerateInitInstanceLocal((const " << csymbol <<
"*)0x0)->GetClass();\n"
1976 <<
" " << mappedname <<
"_TClassManip(theClass);\n";
1977 finalString <<
" return theClass;\n";
1978 finalString <<
" }\n\n";
1982 std::string manipString;
1983 std::string attribute_s;
1984 std::string attrName, attrValue;
1986 bool attrMapExtracted =
false;
1987 if (decl->hasAttrs()){
1989 for (clang::Decl::attr_iterator attrIt = decl->attr_begin();
1990 attrIt!=decl->attr_end();++attrIt){
1997 if (attrName ==
"name" ||
1998 attrName ==
"pattern" ||
1999 attrName ==
"rootmap")
continue;
2005 if (!attrMapExtracted){
2006 manipString+=
" theClass->CreateAttributeMap();\n";
2007 manipString+=
" TDictAttributeMap* attrMap( theClass->GetAttributeMap() );\n";
2008 attrMapExtracted=
true;
2010 manipString+=
" attrMap->AddProperty(\""+attrName +
"\",\""+attrValue+
"\");\n";
2016 for(clang::CXXRecordDecl::decl_iterator internalDeclIt = decl->decls_begin();
2017 internalDeclIt != decl->decls_end(); ++internalDeclIt){
2018 if (!(!(*internalDeclIt)->isImplicit()
2019 && (clang::isa<clang::FieldDecl>(*internalDeclIt) ||
2020 clang::isa<clang::VarDecl>(*internalDeclIt))))
continue;
2023 if (!internalDeclIt->hasAttrs())
continue;
2025 attrMapExtracted =
false;
2026 bool memberPtrCreated =
false;
2028 for (clang::Decl::attr_iterator attrIt = internalDeclIt->attr_begin();
2029 attrIt!=internalDeclIt->attr_end();++attrIt){
2037 clang::NamedDecl* namedInternalDecl = clang::dyn_cast<clang::NamedDecl> (*internalDeclIt);
2038 if (!namedInternalDecl) {
2042 const std::string memberName(namedInternalDecl->getName());
2043 const std::string cppMemberName=
"theMember_"+memberName;
2046 const std::string dataMemberCreation=
" TDataMember* "+cppMemberName+
" = theClass->GetDataMember(\""+memberName+
"\");\n";
2059 if (!memberPtrCreated){
2060 manipString+=dataMemberCreation;
2061 memberPtrCreated=
true;
2064 if (!attrMapExtracted){
2065 manipString+=
" "+cppMemberName+
"->CreateAttributeMap();\n";
2066 manipString+=
" TDictAttributeMap* memberAttrMap_"+memberName+
"( theMember_"+memberName+
"->GetAttributeMap() );\n";
2067 attrMapExtracted=
true;
2070 manipString+=
" memberAttrMap_"+memberName+
"->AddProperty(\""+attrName +
"\",\""+attrValue+
"\");\n";
2077 finalString <<
" static void " << mappedname <<
"_TClassManip(TClass* " << (manipString.empty() ?
"":
"theClass") <<
"){\n"
2082 finalString <<
"} // end of namespace ROOT" <<
"\n" <<
"\n";
2092 std::string &clsname,
2093 std::string &nsname,
2094 const clang::CXXRecordDecl *cl)
2104 auto ctxt = cl->getEnclosingNamespaceContext();
2105 while(ctxt && ctxt!=cl && ctxt->isInlineNamespace()) {
2106 ctxt = ctxt->getParent();
2109 const clang::NamedDecl *namedCtxt = llvm::dyn_cast<clang::NamedDecl>(ctxt);
2110 if (namedCtxt && namedCtxt!=cl) {
2111 const clang::NamespaceDecl *nsdecl = llvm::dyn_cast<clang::NamespaceDecl>(namedCtxt);
2112 if (nsdecl != 0 && !nsdecl->isAnonymousNamespace()) {
2114 clsname.erase (0, nsname.size() + 2);
2126 const clang::DeclContext *ctxt = cl.getDeclContext();
2127 while(ctxt && !ctxt->isNamespace()) {
2128 ctxt = ctxt->getParent();
2142 int closing_brackets = 0;
2146 if (ctxt && ctxt->isNamespace()) {
2151 const clang::NamespaceDecl *ns = llvm::dyn_cast<clang::NamespaceDecl>(ctxt);
2154 out <<
"namespace " << ns->getNameAsString() <<
" {" << std::endl;
2158 return closing_brackets;
2172 clang::TemplateSpecializationKind kind = cl->getTemplateSpecializationKind();
2173 if (kind == clang::TSK_Undeclared ) {
2176 }
else if (kind == clang::TSK_ExplicitSpecialization) {
2190 const char *name = which;
2191 const char *proto =
"size_t";
2192 const char *protoPlacement =
"size_t,void*";
2195 const clang::FunctionDecl *operatornew
2197 name, proto, interp,
2198 cling::LookupHelper::NoDiagnostics);
2199 const clang::FunctionDecl *operatornewPlacement
2201 name, protoPlacement, interp,
2202 cling::LookupHelper::NoDiagnostics);
2204 const clang::DeclContext *ctxtnew = 0;
2205 const clang::DeclContext *ctxtnewPlacement = 0;
2208 ctxtnew = operatornew->getParent();
2210 if (operatornewPlacement) {
2211 ctxtnewPlacement = operatornewPlacement->getParent();
2217 operatornewPlacement
2222 ctxtnew = operatornew->getParent();
2224 if (operatornewPlacement) {
2225 ctxtnewPlacement = operatornewPlacement->getParent();
2228 if (ctxtnewPlacement == 0) {
2236 if (ctxtnew == ctxtnewPlacement) {
2240 const clang::CXXRecordDecl* clnew = llvm::dyn_cast<clang::CXXRecordDecl>(ctxtnew);
2241 const clang::CXXRecordDecl* clnewPlacement = llvm::dyn_cast<clang::CXXRecordDecl>(ctxtnewPlacement);
2242 if (clnew == 0 && clnewPlacement == 0) {
2248 if (clnew != 0 && clnewPlacement == 0) {
2252 if (clnew == 0 && clnewPlacement != 0) {
2257 if (clnew->isDerivedFrom(clnewPlacement)) {
2287 const clang::CXXRecordDecl *decl,
2288 const cling::Interpreter &interp,
2294 std::string mappedname;
2312 classname.insert(0,
"::");
2315 finalString <<
"namespace ROOT {" <<
"\n";
2320 finalString <<
" // Wrappers around operator new" <<
"\n";
2321 finalString <<
" static void *new_" << mappedname.c_str() <<
"(void *p) {" <<
"\n" <<
" return p ? ";
2323 finalString <<
"new(p) ";
2324 finalString << classname.c_str();
2325 finalString << args;
2326 finalString <<
" : ";
2328 finalString <<
"::new((::ROOT::Internal::TOperatorNewHelper*)p) ";
2329 finalString << classname.c_str();
2330 finalString << args;
2331 finalString <<
" : ";
2333 finalString <<
"new " << classname.c_str() << args <<
";" <<
"\n";
2334 finalString <<
" }" <<
"\n";
2338 finalString <<
" static void *newArray_";
2339 finalString << mappedname.c_str();
2340 finalString <<
"(Long_t nElements, void *p) {";
2341 finalString <<
"\n";
2342 finalString <<
" return p ? ";
2344 finalString <<
"new(p) ";
2345 finalString << classname.c_str();
2346 finalString <<
"[nElements] : ";
2348 finalString <<
"::new((::ROOT::Internal::TOperatorNewHelper*)p) ";
2349 finalString << classname.c_str();
2350 finalString <<
"[nElements] : ";
2352 finalString <<
"new ";
2353 finalString << classname.c_str();
2354 finalString <<
"[nElements];";
2355 finalString <<
"\n";
2356 finalString <<
" }";
2357 finalString <<
"\n";
2362 finalString <<
" // Wrapper around operator delete" <<
"\n" <<
" static void delete_" << mappedname.c_str() <<
"(void *p) {" <<
"\n" <<
" delete ((" << classname.c_str() <<
"*)p);" <<
"\n" <<
" }" <<
"\n" <<
" static void deleteArray_" << mappedname.c_str() <<
"(void *p) {" <<
"\n" <<
" delete [] ((" << classname.c_str() <<
"*)p);" <<
"\n" <<
" }" <<
"\n" <<
" static void destruct_" << mappedname.c_str() <<
"(void *p) {" <<
"\n" <<
" typedef " << classname.c_str() <<
" current_t;" <<
"\n" <<
" ((current_t*)p)->~current_t();" <<
"\n" <<
" }" <<
"\n";
2366 finalString <<
" // Wrapper around the directory auto add." <<
"\n" <<
" static void directoryAutoAdd_" << mappedname.c_str() <<
"(void *p, TDirectory *dir) {" <<
"\n" <<
" ((" << classname.c_str() <<
"*)p)->DirectoryAutoAdd(dir);" <<
"\n" <<
" }" <<
"\n";
2370 finalString <<
" // Wrapper around a custom streamer member function." <<
"\n" <<
" static void streamer_" << mappedname.c_str() <<
"(TBuffer &buf, void *obj) {" <<
"\n" <<
" ((" << classname.c_str() <<
"*)obj)->" << classname.c_str() <<
"::Streamer(buf);" <<
"\n" <<
" }" <<
"\n";
2374 finalString <<
" // Wrapper around a custom streamer member function." <<
"\n" <<
" static void conv_streamer_" << mappedname.c_str() <<
"(TBuffer &buf, void *obj, const TClass *onfile_class) {" <<
"\n" <<
" ((" << classname.c_str() <<
"*)obj)->" << classname.c_str() <<
"::Streamer(buf,onfile_class);" <<
"\n" <<
" }" <<
"\n";
2378 finalString <<
" // Wrapper around the merge function." <<
"\n" <<
" static Long64_t merge_" << mappedname.c_str() <<
"(void *obj,TCollection *coll,TFileMergeInfo *info) {" <<
"\n" <<
" return ((" << classname.c_str() <<
"*)obj)->Merge(coll,info);" <<
"\n" <<
" }" <<
"\n";
2380 finalString <<
" // Wrapper around the merge function." <<
"\n" <<
" static Long64_t merge_" << mappedname.c_str() <<
"(void *obj,TCollection *coll,TFileMergeInfo *) {" <<
"\n" <<
" return ((" << classname.c_str() <<
"*)obj)->Merge(coll);" <<
"\n" <<
" }" <<
"\n";
2384 finalString <<
" // Wrapper around the Reset function." <<
"\n" <<
" static void reset_" << mappedname.c_str() <<
"(void *obj,TFileMergeInfo *info) {" <<
"\n" <<
" ((" << classname.c_str() <<
"*)obj)->ResetAfterMerge(info);" <<
"\n" <<
" }" <<
"\n";
2386 finalString <<
"} // end of namespace ROOT for class " << classname.c_str() <<
"\n" <<
"\n";
2393 const cling::Interpreter &interp,
2400 if (version == 0)
return;
2404 const clang::CXXRecordDecl *clxx = llvm::dyn_cast<clang::CXXRecordDecl>(cl.
GetRecordDecl());
2405 if (clxx == 0)
return;
2408 for(clang::CXXRecordDecl::base_class_const_iterator
iter = clxx->bases_begin(), end = clxx->bases_end();
2414 Internal::RStl::Instance().GenerateTClassFor(
iter->getType(), interp, normCtxt);
2419 for(clang::RecordDecl::field_iterator field_iter = clxx->field_begin(), end = clxx->field_end();
2423 std::string mTypename;
2429 if (!strcmp(shortTypeName,
"string")) {
2441 Internal::RStl::Instance().GenerateTClassFor(utype, interp, normCtxt);
2451 const clang::Type *rawtype = m.getType()->getCanonicalTypeInternal().getTypePtr();
2452 if (rawtype->isArrayType()) {
2453 rawtype = rawtype->getBaseElementTypeUnsafe ();
2467 const clang::CXXRecordDecl* CRD = llvm::dyn_cast<clang::CXXRecordDecl>(cl);
2475 if (!funcCV)
return -1;
2477 if (funcCV == (clang::FunctionDecl*)-1)
return 1;
2479 const clang::CompoundStmt* FuncBody
2480 = llvm::dyn_cast_or_null<clang::CompoundStmt>(funcCV->getBody());
2481 if (!FuncBody)
return -1;
2482 if (FuncBody->size() != 1) {
2488 const clang::ReturnStmt* RetStmt
2489 = llvm::dyn_cast<clang::ReturnStmt>(FuncBody->body_back());
2490 if (!RetStmt)
return -1;
2491 const clang::Expr* RetExpr = RetStmt->getRetValue();
2497 llvm::APSInt RetRes;
2498 if (!RetExpr->isIntegerConstantExpr(RetRes, funcCV->getASTContext()))
2500 if (RetRes.isSigned()) {
2501 return (
Version_t)RetRes.getSExtValue();
2504 return (
Version_t)RetRes.getZExtValue();
2520 clang::QualType type = m.getType();
2532 clang::QualType type = base.getType();
2547 static char t[4096];
2548 static const char* constwd =
"const ";
2549 static const char* constwdend =
"const";
2554 for (s=typeDesc;*s;s++) {
2557 if (lev==0 && *s==
'*')
continue;
2558 if (lev==0 && (strncmp(constwd,s,strlen(constwd))==0
2559 ||strcmp(constwdend,s)==0 ) ) {
2560 s+=strlen(constwd)-1;
2563 if (lev==0 && *s==
' ' && *(s+1)!=
'*') { p = t;
continue;}
2564 if (p - t > (
long)
sizeof(t)) {
2565 printf(
"ERROR (rootcling): type name too long for StortTypeName: %s\n",
2578 const cling::Interpreter& interp)
2583 if (comment[0] ==
'!')
return false;
2585 clang::QualType type = m.getType();
2587 if (type->isReferenceType()) {
2592 std::string mTypeName = type.getAsString(m.getASTContext().getPrintingPolicy());
2593 if (!strcmp(mTypeName.c_str(),
"string") || !strcmp(mTypeName.c_str(),
"string*")) {
2596 if (!strcmp(mTypeName.c_str(),
"std::string") || !strcmp(mTypeName.c_str(),
"std::string*")) {
2604 const clang::Type *rawtype = type.getTypePtr()->getBaseElementTypeUnsafe ();
2606 if (rawtype->isPointerType()) {
2608 clang::QualType pointee;
2609 while ( (pointee = rawtype->getPointeeType()) , pointee.getTypePtrOrNull() && pointee.getTypePtr() != rawtype)
2611 rawtype = pointee.getTypePtr();
2615 if (rawtype->isFundamentalType() || rawtype->isEnumeralType()) {
2620 const clang::CXXRecordDecl *cxxdecl = rawtype->getAsCXXRecordDecl();
2624 if (version > 0)
return true;
2637 const clang::Type *rawtype = m.getType().getTypePtr();
2640 clang::QualType pointee;
2641 while ( rawtype->isPointerType() && ((pointee = rawtype->getPointeeType()) , pointee.getTypePtrOrNull()) && pointee.getTypePtr() != rawtype)
2643 rawtype = pointee.getTypePtr();
2657 if (rawtype->isFundamentalType() || rawtype->isEnumeralType()) {
2661 return rawtype->getAsCXXRecordDecl();
2670 const cling::Interpreter &interp,
2672 std::ostream& dictStream,
2674 bool isGenreflex=
false)
2676 const clang::CXXRecordDecl* decl = llvm::dyn_cast<clang::CXXRecordDecl>(cl.
GetRecordDecl());
2678 if (!decl || !decl->isCompleteDefinition()) {
2682 std::string fullname;
2685 Internal::RStl::Instance().GenerateTClassFor(cl.
GetNormalizedName(), llvm::dyn_cast<clang::CXXRecordDecl>(cl.
GetRecordDecl()), interp, normCtxt);
2692 (*WriteStreamerFunc)(cl, interp, normCtxt, dictStream, isGenreflex || cl.RequestStreamerInfo());
2694 ROOT::TMetaUtils::Info(0,
"Class %s: Do not generate Streamer() [*** custom streamer ***]\n",fullname.c_str());
2707 if (level < ROOT::TMetaUtils::gErrorIgnoreLevel)
2710 const char *type = 0;
2725 if (!location || !location[0]) {
2726 if (prefix) fprintf(stderr,
"%s: ", type);
2727 vfprintf(stderr, (
const char*)
va_(fmt), ap);
2729 if (prefix) fprintf(stderr,
"%s in <%s>: ", type, location);
2730 else fprintf(stderr,
"In <%s>: ", location);
2731 vfprintf(stderr, (
const char*)
va_(fmt), ap);
2738 gNumberOfWarningsAndErrors++;
2749 va_start(ap,
va_(fmt));
2760 va_start(ap,
va_(fmt));
2771 va_start(ap,
va_(fmt));
2782 va_start(ap,
va_(fmt));
2793 va_start(ap,
va_(fmt));
2810 const cling::Interpreter &interpreter,
2813 const clang::ASTContext& Ctx = interpreter.getCI()->getASTContext();
2815 clang::QualType originalType = instanceType;
2819 if (llvm::isa<clang::PointerType>(instanceType.getTypePtr())) {
2821 clang::Qualifiers quals = instanceType.getQualifiers();
2822 clang::QualType newPointee =
AddDefaultParameters(instanceType->getPointeeType(), interpreter, normCtxt);
2823 if (newPointee != instanceType->getPointeeType()) {
2824 instanceType = Ctx.getPointerType(newPointee);
2826 instanceType = Ctx.getQualifiedType(instanceType, quals);
2828 return instanceType;
2833 if (llvm::isa<clang::ReferenceType>(instanceType.getTypePtr())) {
2835 bool isLValueRefTy = llvm::isa<clang::LValueReferenceType>(instanceType.getTypePtr());
2836 clang::Qualifiers quals = instanceType.getQualifiers();
2837 clang::QualType newPointee =
AddDefaultParameters(instanceType->getPointeeType(), interpreter, normCtxt);
2839 if (newPointee != instanceType->getPointeeType()) {
2842 instanceType = Ctx.getLValueReferenceType(newPointee);
2844 instanceType = Ctx.getRValueReferenceType(newPointee);
2846 instanceType = Ctx.getQualifiedType(instanceType, quals);
2848 return instanceType;
2852 bool prefix_changed =
false;
2853 clang::NestedNameSpecifier* prefix = 0;
2854 clang::Qualifiers prefix_qualifiers = instanceType.getLocalQualifiers();
2855 const clang::ElaboratedType* etype
2856 = llvm::dyn_cast<clang::ElaboratedType>(instanceType.getTypePtr());
2859 prefix = AddDefaultParametersNNS(Ctx, etype->getQualifier(), interpreter, normCtxt);
2860 prefix_changed = prefix != etype->getQualifier();
2861 instanceType = clang::QualType(etype->getNamedType().getTypePtr(),0);
2867 const clang::TemplateSpecializationType* TST
2868 = llvm::dyn_cast<
const clang::TemplateSpecializationType>(instanceType.getTypePtr());
2870 const clang::ClassTemplateSpecializationDecl* TSTdecl
2871 = llvm::dyn_cast_or_null<const clang::ClassTemplateSpecializationDecl>(instanceType.getTypePtr()->getAsCXXRecordDecl());
2883 bool mightHaveChanged =
false;
2884 if (TST && TSTdecl) {
2886 clang::Sema&
S = interpreter.getCI()->getSema();
2887 clang::TemplateDecl *Template = TSTdecl->getSpecializedTemplate()->getMostRecentDecl();
2888 clang::TemplateParameterList *Params = Template->getTemplateParameters();
2889 clang::TemplateParameterList::iterator Param = Params->begin();
2893 unsigned int dropDefault = normCtxt.
GetConfig().DropDefaultArg(*Template);
2895 llvm::SmallVector<clang::TemplateArgument, 4> desArgs;
2896 unsigned int Idecl = 0, Edecl = TSTdecl->getTemplateArgs().size();
2897 unsigned int maxAddArg = TSTdecl->getTemplateArgs().size() - dropDefault;
2898 for(clang::TemplateSpecializationType::iterator
2899 I = TST->begin(),
E = TST->end();
2901 I!=
E ? ++
I : 0, ++Idecl, ++Param) {
2905 if (
I->getKind() == clang::TemplateArgument::Template) {
2906 clang::TemplateName templateName =
I->getAsTemplate();
2907 clang::TemplateDecl* templateDecl = templateName.getAsTemplateDecl();
2909 clang::DeclContext* declCtxt = templateDecl->getDeclContext();
2911 if (declCtxt && !templateName.getAsQualifiedTemplateName()){
2912 clang::NamespaceDecl* ns = clang::dyn_cast<clang::NamespaceDecl>(declCtxt);
2913 clang::NestedNameSpecifier* nns;
2915 nns = cling::utils::TypeName::CreateNestedNameSpecifier(Ctx, ns);
2916 }
else if (clang::TagDecl* TD = llvm::dyn_cast<clang::TagDecl>(declCtxt)) {
2917 nns = cling::utils::TypeName::CreateNestedNameSpecifier(Ctx,TD,
false );
2920 desArgs.push_back(*
I);
2923 clang::TemplateName templateNameWithNSS ( Ctx.getQualifiedTemplateName(nns,
false, templateDecl) );
2924 desArgs.push_back(clang::TemplateArgument(templateNameWithNSS));
2925 mightHaveChanged =
true;
2932 desArgs.push_back(*
I);
2936 clang::QualType SubTy =
I->getAsType();
2945 if (SubTy != newSubTy) {
2946 mightHaveChanged =
true;
2947 desArgs.push_back(clang::TemplateArgument(newSubTy));
2949 desArgs.push_back(*
I);
2952 }
else if (!isStdDropDefault && Idecl < maxAddArg) {
2954 mightHaveChanged =
true;
2956 const clang::TemplateArgument& templateArg
2957 = TSTdecl->getTemplateArgs().get(Idecl);
2959 desArgs.push_back(templateArg);
2962 clang::QualType SubTy = templateArg.getAsType();
2964 clang::SourceLocation TemplateLoc = Template->getSourceRange ().getBegin();
2965 clang::SourceLocation RAngleLoc = TSTdecl->getSourceRange().getBegin();
2967 clang::TemplateTypeParmDecl *TTP = llvm::dyn_cast<clang::TemplateTypeParmDecl>(*Param);
2970 cling::Interpreter::PushTransactionRAII clingRAII(const_cast<cling::Interpreter*>(&interpreter));
2971 clang::sema::HackForDefaultTemplateArg raii;
2972 bool HasDefaultArgs;
2973 clang::TemplateArgumentLoc ArgType = S.SubstDefaultTemplateArgumentIfAvailable(
2982 if (ArgType.getArgument().isNull()
2985 "Template parameter substitution failed for %s around %s",
2986 instanceType.getAsString().c_str(),
2987 SubTy.getAsString().c_str()
2991 clang::QualType BetterSubTy = ArgType.getArgument().getAsType();
2992 SubTy = cling::utils::Transform::GetPartiallyDesugaredType(Ctx,BetterSubTy,normCtxt.
GetConfig(),
true);
2995 desArgs.push_back(clang::TemplateArgument(SubTy));
3004 if (mightHaveChanged) {
3005 instanceType = Ctx.getTemplateSpecializationType(TST->getTemplateName(),
3008 TST->getCanonicalTypeInternal());
3012 if (!prefix_changed && !mightHaveChanged)
return originalType;
3014 instanceType = Ctx.getElaboratedType(clang::ETK_None,prefix,instanceType);
3015 instanceType = Ctx.getQualifiedType(instanceType,prefix_qualifiers);
3017 return instanceType;
3037 llvm::StringRef title;
3040 if (clang::AnnotateAttr *
A = m.getAttr<clang::AnnotateAttr>())
3041 title =
A->getAnnotation();
3053 if (errnum) *errnum =
VALID;
3055 if (title.size() == 0 || (title[0] !=
'['))
return llvm::StringRef();
3056 size_t rightbracket = title.find(
']');
3057 if (rightbracket == llvm::StringRef::npos)
return llvm::StringRef();
3059 std::string working;
3060 llvm::StringRef indexvar(title.data()+1,rightbracket-1);
3067 size_t indexvarlen = indexvar.size();
3068 for ( i=0; i<indexvarlen; i++) {
3069 if (!isspace(indexvar[i])) {
3070 working += indexvar[i];
3075 const char *tokenlist =
"*+-";
3076 char *current =
const_cast<char*
>(working.c_str());
3077 current = strtok(current,tokenlist);
3079 while (current!=0) {
3081 if (isdigit(current[0])) {
3082 for(i=0;i<strlen(current);i++) {
3083 if (!isdigit(current[0])) {
3088 if (errstr) *errstr = current;
3089 if (errnum) *errnum =
NOT_INT;
3090 return llvm::StringRef();
3096 const clang::CXXRecordDecl *parent_clxx = llvm::dyn_cast<clang::CXXRecordDecl>(m.getDeclContext());
3097 const clang::FieldDecl *index1 = 0;
3099 index1 = GetDataMemberFromAll(*parent_clxx, current );
3101 if ( IsFieldDeclInt(index1) ) {
3107 for(clang::RecordDecl::field_iterator field_iter = parent_clxx->field_begin(), end = parent_clxx->field_end();
3111 if ( field_iter->getNameAsString() == m.getNameAsString() ) {
3117 if (errstr) *errstr = current;
3118 if (errnum) *errnum =
NOT_DEF;
3119 return llvm::StringRef();
3121 if ( field_iter->getNameAsString() == index1->getNameAsString() ) {
3129 if (errstr) *errstr = current;
3130 if (errnum) *errnum =
NOT_INT;
3131 return llvm::StringRef();
3136 index1 = GetDataMemberFromAllParents( *parent_clxx, current );
3138 if ( IsFieldDeclInt(index1) ) {
3145 if (errnum) *errnum =
NOT_INT;
3146 if (errstr) *errstr = current;
3150 if (errnum) *errnum =
NOT_INT;
3151 if (errstr) *errstr = current;
3152 return llvm::StringRef();
3154 if ( found && (index1->getAccess() == clang::AS_private) ) {
3157 if (errstr) *errstr = current;
3159 return llvm::StringRef();
3166 if (errstr) *errstr = indexvar;
3167 if (errnum) *errnum =
UNKNOWN;
3168 return llvm::StringRef();
3173 current = strtok(0,tokenlist);
3186 out.resize(strlen(in)*2);
3187 unsigned int i=0,j=0,
c;
3189 if (out.capacity() < (j+3)) {
3193 case '+': strcpy(const_cast<char*>(out.data())+j,
"pL"); j+=2;
break;
3194 case '-': strcpy(const_cast<char*>(out.data())+j,
"mI"); j+=2;
break;
3195 case '*': strcpy(const_cast<char*>(out.data())+j,
"mU"); j+=2;
break;
3196 case '/': strcpy(const_cast<char*>(out.data())+j,
"dI"); j+=2;
break;
3197 case '&': strcpy(const_cast<char*>(out.data())+j,
"aN"); j+=2;
break;
3198 case '%': strcpy(const_cast<char*>(out.data())+j,
"pE"); j+=2;
break;
3199 case '|': strcpy(const_cast<char*>(out.data())+j,
"oR"); j+=2;
break;
3200 case '^': strcpy(const_cast<char*>(out.data())+j,
"hA"); j+=2;
break;
3201 case '>': strcpy(const_cast<char*>(out.data())+j,
"gR"); j+=2;
break;
3202 case '<': strcpy(const_cast<char*>(out.data())+j,
"lE"); j+=2;
break;
3203 case '=': strcpy(const_cast<char*>(out.data())+j,
"eQ"); j+=2;
break;
3204 case '~': strcpy(const_cast<char*>(out.data())+j,
"wA"); j+=2;
break;
3205 case '.': strcpy(const_cast<char*>(out.data())+j,
"dO"); j+=2;
break;
3206 case '(': strcpy(const_cast<char*>(out.data())+j,
"oP"); j+=2;
break;
3207 case ')': strcpy(const_cast<char*>(out.data())+j,
"cP"); j+=2;
break;
3208 case '[': strcpy(const_cast<char*>(out.data())+j,
"oB"); j+=2;
break;
3209 case ']': strcpy(const_cast<char*>(out.data())+j,
"cB"); j+=2;
break;
3210 case '!': strcpy(const_cast<char*>(out.data())+j,
"nO"); j+=2;
break;
3211 case ',': strcpy(const_cast<char*>(out.data())+j,
"cO"); j+=2;
break;
3212 case '$': strcpy(const_cast<char*>(out.data())+j,
"dA"); j+=2;
break;
3213 case ' ': strcpy(const_cast<char*>(out.data())+j,
"sP"); j+=2;
break;
3214 case ':': strcpy(const_cast<char*>(out.data())+j,
"cL"); j+=2;
break;
3215 case '"': strcpy(const_cast<char*>(out.data())+j,
"dQ"); j+=2;
break;
3216 case '@': strcpy(const_cast<char*>(out.data())+j,
"aT"); j+=2;
break;
3217 case '\'': strcpy(const_cast<char*>(out.data())+j,
"sQ"); j+=2;
break;
3218 case '\\': strcpy(const_cast<char*>(out.data())+j,
"fI"); j+=2;
break;
3219 default: out[j++]=
c;
break;
3226 std::size_t firstNonNumber = out.find_first_not_of(
"0123456789");
3227 out.replace(0,firstNonNumber,
"");
3232 static clang::SourceLocation
3234 clang::SourceLocation sourceLoc) {
3236 if (!sourceLoc.isFileID()) {
3237 return sourceManager.getExpansionRange(sourceLoc).second;
3246 const cling::Interpreter& interp)
3276 using namespace clang;
3277 SourceLocation headerLoc = decl.getLocation();
3279 static const char invalidFilename[] =
"invalid";
3280 if (!headerLoc.isValid())
return invalidFilename;
3282 HeaderSearch& HdrSearch = interp.getCI()->getPreprocessor().getHeaderSearchInfo();
3284 SourceManager& sourceManager = decl.getASTContext().getSourceManager();
3286 FileID headerFID = sourceManager.getFileID(headerLoc);
3287 SourceLocation includeLoc
3289 sourceManager.getIncludeLoc(headerFID));
3291 const FileEntry *headerFE = sourceManager.getFileEntryForID(headerFID);
3292 while (includeLoc.isValid() && sourceManager.isInSystemHeader(includeLoc)) {
3293 const DirectoryLookup *foundDir = 0;
3296 const FileEntry *FEhdr
3300 ArrayRef<std::pair<const FileEntry *, const DirectoryEntry *>>(),
3305 headerFID = sourceManager.getFileID(includeLoc);
3306 headerFE = sourceManager.getFileEntryForID(headerFID);
3308 sourceManager.getIncludeLoc(headerFID));
3311 if (!headerFE)
return invalidFilename;
3312 llvm::StringRef headerFileName = headerFE->getName();
3323 bool isAbsolute = llvm::sys::path::is_absolute(headerFileName);
3324 const FileEntry* FELong = 0;
3326 for (llvm::sys::path::const_iterator
3327 IDir = llvm::sys::path::begin(headerFileName),
3328 EDir = llvm::sys::path::end(headerFileName);
3329 !FELong && IDir != EDir; ++IDir) {
3335 size_t lenTrailing = headerFileName.size() - (IDir->data() - headerFileName.data());
3336 llvm::StringRef trailingPart(IDir->data(), lenTrailing);
3337 assert(trailingPart.data() + trailingPart.size()
3338 == headerFileName.data() + headerFileName.size()
3339 &&
"Mismatched partitioning of file name!");
3340 const DirectoryLookup* FoundDir = 0;
3341 FELong = HdrSearch.LookupFile(trailingPart, SourceLocation(),
3343 ArrayRef<std::pair<const FileEntry *, const DirectoryEntry *>>(),
3350 return invalidFilename;
3354 for (llvm::sys::path::reverse_iterator
3355 IDir = llvm::sys::path::rbegin(headerFileName),
3356 EDir = llvm::sys::path::rend(headerFileName);
3357 IDir != EDir; ++IDir) {
3358 size_t lenTrailing = headerFileName.size() - (IDir->data() - headerFileName.data());
3359 llvm::StringRef trailingPart(IDir->data(), lenTrailing);
3360 assert(trailingPart.data() + trailingPart.size()
3361 == headerFileName.data() + headerFileName.size()
3362 &&
"Mismatched partitioning of file name!");
3363 const DirectoryLookup* FoundDir = 0;
3366 if (HdrSearch.LookupFile(trailingPart, SourceLocation(),
3368 ArrayRef<std::pair<const FileEntry *, const DirectoryEntry *>>(),
3371 return trailingPart;
3375 return invalidFilename;
3381 const clang::QualType &qtype,
3382 const clang::ASTContext &astContext)
3384 std::string fqname = cling::utils::TypeName::GetFullyQualifiedName(qtype, astContext);
3393 const clang::QualType &qtype,
3394 const cling::Interpreter &interpreter)
3398 interpreter.getCI()->getASTContext());
3410 const char* rootsys = getenv(
"ROOTSYS");
3412 Error(0,
"Environment variable ROOTSYS not set!");
3415 return std::string(
"-I") + rootsys +
"/etc";
3418 return std::string(
"-I") + ROOTETCDIR;
3427 #ifdef R__EXTERN_LLVMDIR
3428 return R__EXTERN_LLVMDIR;
3431 .substr(2, std::string::npos) +
"/cling";
3440 clang::ClassTemplateDecl*& ctd,
3441 clang::ClassTemplateSpecializationDecl*& ctsd)
3443 using namespace clang;
3444 const Type* theType = qt.getTypePtr();
3451 if (theType->isPointerType()) {
3455 if (
const RecordType* rType = llvm::dyn_cast<RecordType>(theType)) {
3456 ctsd = llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(rType->getDecl());
3458 ctd = ctsd->getSpecializedTemplate();
3463 if (
const SubstTemplateTypeParmType* sttpType = llvm::dyn_cast<SubstTemplateTypeParmType>(theType)){
3468 ctsd = llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(qt->getAsCXXRecordDecl());
3470 ctd = ctsd->getSpecializedTemplate();
3485 using namespace clang;
3486 ClassTemplateSpecializationDecl* ctsd;
3487 ClassTemplateDecl* ctd;
3501 using namespace clang;
3502 TemplateName theTemplateName;
3504 const Type* theType = qt.getTypePtr();
3506 if (
const TemplateSpecializationType* tst = llvm::dyn_cast_or_null<const TemplateSpecializationType>(theType)) {
3507 theTemplateName = tst->getTemplateName();
3510 theTemplateName = TemplateName(ctd);
3513 return theTemplateName;
3519 llvm::SmallVectorImpl<clang::TemplateArgument>& preceedingTArgs,
3520 const clang::NamedDecl& tPar,
3521 const cling::Interpreter& interp,
3525 using namespace clang;
3528 TemplateTypeParmDecl* ttpdPtr =
const_cast<TemplateTypeParmDecl*
>(llvm::dyn_cast<TemplateTypeParmDecl>(&tPar));
3529 if (!ttpdPtr)
return false;
3530 if (!ttpdPtr->hasDefaultArgument())
return false;
3533 QualType tParQualType = ttpdPtr->getDefaultArgument();
3534 const QualType tArgQualType = tArg.getAsType();
3541 if (tParQualType.getTypePtr() == tArgQualType.getTypePtr())
return true;
3552 const clang::ElaboratedType* etype
3553 = llvm::dyn_cast<clang::ElaboratedType>(tParQualType.getTypePtr());
3555 tParQualType = clang::QualType(etype->getNamedType().getTypePtr(),0);
3556 etype = llvm::dyn_cast<clang::ElaboratedType>(tParQualType.getTypePtr());
3559 const TemplateSpecializationType* tst =
3560 llvm::dyn_cast<TemplateSpecializationType>(tParQualType.getTypePtr());
3565 ClassTemplateSpecializationDecl* TSTdecl
3566 = llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(tArgQualType->getAsCXXRecordDecl());
3571 TemplateDecl *Template = tst->getTemplateName().getAsTemplateDecl();
3574 SourceLocation TemplateLoc = Template->getSourceRange ().getBegin();
3577 SourceLocation LAngleLoc = TSTdecl->getSourceRange().getBegin();
3582 TemplateArgument newArg = tArg;
3584 clang::Sema&
S = interp.getCI()->getSema();
3585 cling::Interpreter::PushTransactionRAII clingRAII(const_cast<cling::Interpreter*>(&interp));
3586 clang::sema::HackForDefaultTemplateArg raii;
3587 bool HasDefaultArgs;
3588 TemplateArgumentLoc defTArgLoc = S.SubstDefaultTemplateArgumentIfAvailable(Template,
3596 newArg = defTArgLoc.getArgument();
3597 if (newArg.isNull() ||
3600 "Template parameter substitution failed!");
3603 ClassTemplateSpecializationDecl* nTSTdecl
3604 = llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(newArg.getAsType()->getAsCXXRecordDecl());
3607 isEqual = nTSTdecl->getMostRecentDecl() == TSTdecl->getMostRecentDecl() ||
3608 tParQualType.getTypePtr() == newArg.getAsType().getTypePtr();
3620 const clang::NamedDecl& tPar)
3622 using namespace clang;
3623 const NonTypeTemplateParmDecl* nttpdPtr = llvm::dyn_cast<NonTypeTemplateParmDecl>(&tPar);
3624 if (!nttpdPtr)
return false;
3625 const NonTypeTemplateParmDecl& nttpd = *nttpdPtr;
3627 if (!nttpd.hasDefaultArgument())
3631 llvm::APSInt defaultValueAPSInt(64,
false);
3632 if (Expr* defArgExpr = nttpd.getDefaultArgument()) {
3633 const ASTContext& astCtxt = nttpdPtr->getASTContext();
3634 defArgExpr->isIntegerConstantExpr(defaultValueAPSInt, astCtxt);
3637 const int value = tArg.getAsIntegral().getLimitedValue();
3640 return value == defaultValueAPSInt;
3650 using namespace clang;
3651 if (!nDecl)
return false;
3652 if (
const TemplateTypeParmDecl* ttpd = llvm::dyn_cast<TemplateTypeParmDecl>(nDecl))
3653 return ttpd->hasDefaultArgument();
3654 if (
const NonTypeTemplateParmDecl* nttpd = llvm::dyn_cast<NonTypeTemplateParmDecl>(nDecl))
3655 return nttpd->hasDefaultArgument();
3665 const clang::QualType& vanillaType,
3666 const cling::Interpreter& interp,
3670 using namespace clang;
3674 ClassTemplateSpecializationDecl* ctsd;
3675 ClassTemplateDecl* ctd;
3682 QualType originalNormalizedType = normalizedType;
3684 const ASTContext& astCtxt = ctsd->getASTContext();
3689 if (llvm::isa<clang::PointerType>(normalizedType.getTypePtr())) {
3691 clang::Qualifiers quals = normalizedType.getQualifiers();
3692 auto valNormalizedType = normalizedType->getPointeeType();
3693 KeepNParams(valNormalizedType,vanillaType, interp, normCtxt);
3694 normalizedType = astCtxt.getPointerType(valNormalizedType);
3696 normalizedType = astCtxt.getQualifiedType(normalizedType, quals);
3702 if (llvm::isa<clang::ReferenceType>(normalizedType.getTypePtr())) {
3704 bool isLValueRefTy = llvm::isa<clang::LValueReferenceType>(normalizedType.getTypePtr());
3705 clang::Qualifiers quals = normalizedType.getQualifiers();
3706 auto valNormType = normalizedType->getPointeeType();
3707 KeepNParams(valNormType, vanillaType, interp, normCtxt);
3711 normalizedType = astCtxt.getLValueReferenceType(valNormType);
3713 normalizedType = astCtxt.getRValueReferenceType(valNormType);
3715 normalizedType = astCtxt.getQualifiedType(normalizedType, quals);
3720 bool prefix_changed =
false;
3721 clang::NestedNameSpecifier* prefix =
nullptr;
3722 clang::Qualifiers prefix_qualifiers = normalizedType.getLocalQualifiers();
3723 const clang::ElaboratedType* etype
3724 = llvm::dyn_cast<clang::ElaboratedType>(normalizedType.getTypePtr());
3728 prefix = AddDefaultParametersNNS(astCtxt, etype->getQualifier(), interp, normCtxt);
3729 prefix_changed = prefix != etype->getQualifier();
3730 normalizedType = clang::QualType(etype->getNamedType().getTypePtr(),0);
3736 const clang::ClassTemplateDecl* ctdWithDefaultArgs = ctd;
3737 for (
const RedeclarableTemplateDecl* rd: ctdWithDefaultArgs->redecls()) {
3738 clang::TemplateParameterList* tpl = rd->getTemplateParameters();
3739 if (tpl->getMinRequiredArguments () < tpl->size())
3740 ctdWithDefaultArgs = llvm::dyn_cast<clang::ClassTemplateDecl>(rd);
3742 TemplateParameterList* tParsPtr = ctdWithDefaultArgs->getTemplateParameters();
3743 const TemplateParameterList& tPars = *tParsPtr;
3744 const TemplateArgumentList& tArgs = ctsd->getTemplateArgs();
3748 if (theTemplateName.isNull()) {
3749 normalizedType=originalNormalizedType;
3753 const TemplateSpecializationType* normalizedTst =
3754 llvm::dyn_cast<TemplateSpecializationType>(normalizedType.getTypePtr());
3755 if (!normalizedTst) {
3756 normalizedType=originalNormalizedType;
3760 const clang::ClassTemplateSpecializationDecl* TSTdecl
3761 = llvm::dyn_cast_or_null<const clang::ClassTemplateSpecializationDecl>(normalizedType.getTypePtr()->getAsCXXRecordDecl());
3769 llvm::SmallVector<TemplateArgument, 4> argsToKeep;
3771 const int nArgs = tArgs.size();
3772 const int nNormArgs = normalizedTst->getNumArgs();
3774 bool mightHaveChanged =
false;
3777 for (
int index = 0; index != nArgs; ++index) {
3778 const NamedDecl* tParPtr = tPars.getParam(index);
3779 if (!tParPtr)
Error(
"KeepNParams",
3780 "The parameter number %s is null.\n",
3783 const TemplateArgument& tArg = tArgs.get(index);
3787 if (index == nNormArgs)
break;
3789 TemplateArgument NormTArg(normalizedTst->getArgs()[index]);
3791 bool shouldKeepArg = nArgsToKeep < 0 || index <
nArgsToKeep;
3792 if (isStdDropDefault) shouldKeepArg =
false;
3804 QualType thisNormQualType = NormTArg.getAsType();
3805 QualType thisArgQualType = tArg.getAsType();
3810 mightHaveChanged |= (thisNormQualType != thisArgQualType);
3811 NormTArg = TemplateArgument(thisNormQualType);
3813 argsToKeep.push_back(NormTArg);
3816 if (!isStdDropDefault) {
3818 mightHaveChanged =
true;
3828 auto argKind = tArg.getKind();
3831 equal =
areEqualTypes(tArg, argsToKeep, *tParPtr, interp, normCtxt);
3832 }
else if (argKind == clang::TemplateArgument::Integral){
3836 argsToKeep.push_back(NormTArg);
3838 mightHaveChanged =
true;
3844 if (!prefix_changed && !mightHaveChanged) {
3845 normalizedType = originalNormalizedType;
3850 if (mightHaveChanged) {
3851 Qualifiers qualifiers = normalizedType.getLocalQualifiers();
3852 normalizedType = astCtxt.getTemplateSpecializationType(theTemplateName,
3855 normalizedType.getTypePtr()->getCanonicalTypeInternal());
3856 normalizedType = astCtxt.getQualifiedType(normalizedType, qualifiers);
3862 normalizedType = astCtxt.getElaboratedType(clang::ETK_None,prefix,normalizedType);
3863 normalizedType = astCtxt.getQualifiedType(normalizedType,prefix_qualifiers);
3877 clang::ASTContext &ctxt = interpreter.getCI()->getASTContext();
3879 clang::QualType normalizedType = cling::utils::Transform::GetPartiallyDesugaredType(ctxt, type, normCtxt.
GetConfig(),
true );
3885 KeepNParams(normalizedType,type,interpreter,normCtxt);
3887 return normalizedType;
3901 if (type.isNull()) {
3908 clang::ASTContext &ctxt = interpreter.getCI()->getASTContext();
3909 clang::PrintingPolicy policy(ctxt.getPrintingPolicy());
3910 policy.SuppressTagKeyword =
true;
3911 policy.SuppressScope =
true;
3912 policy.AnonymousTagLocations =
false;
3917 std::string normalizedNameStep1;
3918 normalizedType.getAsStringInternal(normalizedNameStep1,policy);
3928 if (norm_name.length()>2 && norm_name[0]==
':' && norm_name[1]==
':') {
3929 norm_name.erase(0,2);
3937 const clang::TypeDecl* typeDecl,
3938 const cling::Interpreter &interpreter)
3941 const clang::Sema &sema = interpreter.getSema();
3942 clang::ASTContext& astCtxt = sema.getASTContext();
3943 clang::QualType qualType = astCtxt.getTypeDeclType(typeDecl);
3955 const std::string defaultInclude (
"include");
3958 const char* rootSysContent = getenv(
"ROOTSYS");
3959 if (rootSysContent) {
3960 std::string incl_rootsys (rootSysContent);
3961 return incl_rootsys +
"/" + defaultInclude;
3963 Error(0,
"Environment variable ROOTSYS not set");
3964 return defaultInclude;
3971 return defaultInclude;
3979 std::string dictFileName(moduleName);
3980 dictFileName +=
"_rdict.pcm";
3981 return dictFileName;
3988 const char* moduleFileName,
3989 const char* headers[])
3991 clang::Preprocessor& PP = CI->getPreprocessor();
3992 clang::ModuleMap& ModuleMap = PP.getHeaderSearchInfo().getModuleMap();
3995 clang::HeaderSearch& HS = CI->getPreprocessor().getHeaderSearchInfo();
3996 HS.setModuleCachePath(llvm::sys::path::parent_path(moduleFileName));
3999 moduleName = llvm::sys::path::stem(moduleName);
4001 std::pair<clang::Module*, bool> modCreation;
4004 = ModuleMap.findOrCreateModule(moduleName.str(),
4007 if (!modCreation.second && !strstr(moduleFileName,
"/allDict_rdict.pcm")) {
4008 std::cerr <<
"TMetaUtils::declareModuleMap: "
4009 "Duplicate definition of dictionary module "
4010 << moduleFileName << std::endl;
4015 clang::HeaderSearch& HdrSearch = PP.getHeaderSearchInfo();
4016 for (
const char** hdr = headers; hdr && *hdr; ++hdr) {
4017 const clang::DirectoryLookup* CurDir;
4018 const clang::FileEntry* hdrFileEntry
4019 = HdrSearch.LookupFile(*hdr, clang::SourceLocation(),
4021 llvm::ArrayRef<std::pair<
const clang::FileEntry *,
4022 const clang::DirectoryEntry *>>(),
4026 if (!hdrFileEntry) {
4027 std::cerr <<
"TMetaUtils::declareModuleMap: "
4028 "Cannot find header file " << *hdr
4029 <<
" included in dictionary module "
4031 <<
" in include search path!";
4032 hdrFileEntry = PP.getFileManager().getFile(*hdr,
false,
4034 }
else if (getenv(
"ROOT_MODULES")) {
4036 llvm::StringRef srHdrDir(hdrFileEntry->getName());
4037 srHdrDir = llvm::sys::path::parent_path(srHdrDir);
4038 const clang::DirectoryEntry* Dir
4039 = PP.getFileManager().getDirectory(srHdrDir);
4041 HdrSearch.setDirectoryHasModuleMap(Dir);
4045 ModuleMap.addHeader(modCreation.first,
4046 clang::Module::Header{*hdr,hdrFileEntry},
4047 clang::ModuleMap::NormalHeader);
4049 return modCreation.first;
4053 llvm::errs() << llvm::StringRef(commentStart, 80) <<
'\n';
4079 clang::SourceManager& sourceManager = decl.getASTContext().getSourceManager();
4080 clang::SourceLocation sourceLocation = decl.getLocEnd();
4083 sourceLocation = sourceManager.getExpansionRange(sourceLocation).second;
4084 if (sourceManager.isLoadedSourceLocation(sourceLocation)) {
4090 const char *commentStart = sourceManager.getCharacterData(sourceLocation, &invalid);
4094 bool skipToSemi =
true;
4095 if (
const clang::FunctionDecl* FD = clang::dyn_cast<clang::FunctionDecl>(&decl)) {
4096 if (FD->isImplicit()) {
4100 if (FD->isExplicitlyDefaulted() || FD->isDeletedAsWritten()) {
4104 }
else if (FD->doesThisDeclarationHaveABody()) {
4107 assert((decl.getLocEnd() != sourceLocation || *commentStart ==
'}'
4109 &&
"Expected macro or end of body at '}'");
4110 if (*commentStart) ++commentStart;
4113 while (*commentStart && isspace(*commentStart)
4114 && *commentStart !=
'\n' && *commentStart !=
'\r') {
4117 if (*commentStart ==
';') ++commentStart;
4121 }
else if (
const clang::EnumConstantDecl* ECD
4122 = clang::dyn_cast<clang::EnumConstantDecl>(&decl)) {
4124 if (ECD->getNextDeclInContext())
4125 while (*commentStart && *commentStart !=
',' && *commentStart !=
'\r' && *commentStart !=
'\n')
4133 while (*commentStart && *commentStart !=
';' && *commentStart !=
'\r' && *commentStart !=
'\n')
4135 if (*commentStart ==
';') ++commentStart;
4139 while ( *commentStart && isspace(*commentStart)
4140 && *commentStart !=
'\n' && *commentStart !=
'\r') {
4144 if (commentStart[0] !=
'/' ||
4145 (commentStart[1] !=
'/' && commentStart[1] !=
'*')) {
4155 unsigned int skipChars = 2;
4156 if (commentStart[0] ==
'/' &&
4157 commentStart[1] ==
'/' &&
4158 (commentStart[2] ==
'/' || commentStart[2] ==
'!') &&
4159 commentStart[3] ==
'<') {
4161 }
else if (commentStart[0] ==
'/' &&
4162 commentStart[1] ==
'*' &&
4163 (commentStart[2] ==
'*' || commentStart[2] ==
'!') &&
4164 commentStart[3] ==
'<') {
4168 commentStart += skipChars;
4171 while ( *commentStart && isspace(*commentStart)
4172 && *commentStart !=
'\n' && *commentStart !=
'\r') {
4175 const char* commentEnd = commentStart;
4177 while (*commentEnd && *commentEnd !=
'\n' && *commentEnd !=
'\r') {
4183 while (commentEnd > commentStart && isspace(commentEnd[-1])) {
4189 unsigned offset = commentStart - sourceManager.getCharacterData(sourceLocation);
4190 *loc = sourceLocation.getLocWithOffset(offset - 1);
4193 return llvm::StringRef(commentStart, commentEnd - commentStart);
4204 clang::SourceLocation *loc,
4205 const cling::Interpreter &interpreter)
4207 using namespace clang;
4208 SourceLocation commentSLoc;
4211 Sema& sema = interpreter.getCI()->getSema();
4213 const Decl* DeclFileLineDecl
4214 = interpreter.getLookupHelper().findFunctionProto(&decl,
"DeclFileLine",
"",
4215 cling::LookupHelper::NoDiagnostics);
4216 if (!DeclFileLineDecl)
return llvm::StringRef();
4219 SourceLocation maybeMacroLoc = DeclFileLineDecl->getLocation();
4220 bool isClassDefMacro = maybeMacroLoc.isMacroID() && sema.findMacroSpelling(maybeMacroLoc,
"ClassDef");
4221 if (isClassDefMacro) {
4223 if (comment.size()) {
4230 return llvm::StringRef();
4242 if (rawtype->isElaboratedTypeSpecifier() ) {
4243 rawtype = rawtype->getCanonicalTypeInternal().getTypePtr();
4245 if (rawtype->isArrayType()) {
4246 rawtype = type.getTypePtr()->getBaseElementTypeUnsafe ();
4248 if (rawtype->isPointerType() || rawtype->isReferenceType() ) {
4250 clang::QualType pointee;
4251 while ( (pointee = rawtype->getPointeeType()) , pointee.getTypePtrOrNull() && pointee.getTypePtr() != rawtype)
4253 rawtype = pointee.getTypePtr();
4255 if (rawtype->isElaboratedTypeSpecifier() ) {
4256 rawtype = rawtype->getCanonicalTypeInternal().getTypePtr();
4258 if (rawtype->isArrayType()) {
4259 rawtype = rawtype->getBaseElementTypeUnsafe ();
4263 if (rawtype->isArrayType()) {
4264 rawtype = rawtype->getBaseElementTypeUnsafe ();
4285 static const char *names[] =
4286 {
"shared_ptr",
"__shared_ptr",
4287 "vector",
"list",
"deque",
"map",
"multimap",
"set",
"multiset",
"bitset"};
4288 llvm::StringRef clname(cl.getName());
4289 for(
auto &&name : names) {
4290 if (clname == name)
return true;
4300 const clang::CXXRecordDecl ¤tCl)
4303 if (&cl == ¤tCl)
return true;
4305 const clang::CXXRecordDecl* previous = currentCl.getPreviousDecl();
4308 if (
NULL == previous){
4327 const clang::CXXRecordDecl *thisDecl =
4328 llvm::dyn_cast_or_null<clang::CXXRecordDecl>(lh.findScope(typ, cling::LookupHelper::WithDiagnostics));
4332 Error(
"IsOfType",
"Record decl of type %s not found in the AST.", typ.c_str());
4337 const clang::CXXRecordDecl *mostRecentDecl = thisDecl->getMostRecentDecl();
4370 using namespace clang;
4371 struct SearchTypedef:
public TypeVisitor<SearchTypedef, bool> {
4372 bool VisitTypedefType(
const TypedefType* TD) {
4375 bool VisitArrayType(
const ArrayType* AT) {
4376 return Visit(AT->getElementType().getTypePtr());
4378 bool VisitDecltypeType(
const DecltypeType* DT) {
4379 return Visit(DT->getUnderlyingType().getTypePtr());
4381 bool VisitPointerType(
const PointerType* PT) {
4382 return Visit(PT->getPointeeType().getTypePtr());
4384 bool VisitReferenceType(
const ReferenceType* RT) {
4385 return Visit(RT->getPointeeType().getTypePtr());
4387 bool VisitSubstTemplateTypeParmType(
const SubstTemplateTypeParmType* STST) {
4388 return Visit(STST->getReplacementType().getTypePtr());
4390 bool VisitTemplateSpecializationType(
const TemplateSpecializationType* TST) {
4391 for (
int I = 0,
N = TST->getNumArgs();
I <
N; ++
I) {
4392 const TemplateArgument& TA = TST->getArg(
I);
4394 && Visit(TA.getAsType().getTypePtr()))
4399 bool VisitTemplateTypeParmType(
const TemplateTypeParmType* TTPT) {
4402 bool VisitTypeOfType(
const TypeOfType* TOT) {
4403 return TOT->getUnderlyingType().getTypePtr();
4405 bool VisitElaboratedType(
const ElaboratedType* ET) {
4406 NestedNameSpecifier* NNS = ET->getQualifier();
4408 if (NNS->getKind() == NestedNameSpecifier::TypeSpec) {
4409 if (Visit(NNS->getAsType()))
4412 NNS = NNS->getPrefix();
4414 return Visit(ET->getNamedType().getTypePtr());
4429 if (!instance)
return input;
4435 using namespace llvm;
4436 using namespace clang;
4437 const clang::ASTContext &Ctxt = instance->getAsCXXRecordDecl()->getASTContext();
4440 const clang::ElaboratedType* etype
4441 = llvm::dyn_cast<clang::ElaboratedType>(input.getTypePtr());
4445 clang::Qualifiers scope_qualifiers = input.getLocalQualifiers();
4446 assert(instance->getAsCXXRecordDecl()!=0 &&
"ReSubstTemplateArg only makes sense with a type representing a class.");
4448 clang::NestedNameSpecifier *scope = ReSubstTemplateArgNNS(Ctxt,etype->getQualifier(),instance);
4449 clang::QualType subTy =
ReSubstTemplateArg(clang::QualType(etype->getNamedType().getTypePtr(),0),instance);
4451 if (scope) subTy = Ctxt.getElaboratedType(clang::ETK_None,scope,subTy);
4452 subTy = Ctxt.getQualifiedType(subTy,scope_qualifiers);
4456 QualType QT = input;
4460 if (isa<clang::PointerType>(QT.getTypePtr())) {
4462 Qualifiers quals = QT.getQualifiers();
4465 if (nQT == QT->getPointeeType())
return QT;
4467 QT = Ctxt.getPointerType(nQT);
4469 QT = Ctxt.getQualifiedType(QT, quals);
4475 if (isa<ReferenceType>(QT.getTypePtr())) {
4477 bool isLValueRefTy = isa<LValueReferenceType>(QT.getTypePtr());
4478 Qualifiers quals = QT.getQualifiers();
4481 if (nQT == QT->getPointeeType())
return QT;
4485 QT = Ctxt.getLValueReferenceType(nQT);
4487 QT = Ctxt.getRValueReferenceType(nQT);
4489 QT = Ctxt.getQualifiedType(QT, quals);
4495 if (isa<clang::ArrayType>(QT.getTypePtr())) {
4497 Qualifiers quals = QT.getQualifiers();
4499 if (isa<ConstantArrayType>(QT.getTypePtr())) {
4500 const ConstantArrayType *arr = dyn_cast<ConstantArrayType>(QT.getTypePtr());
4504 if (newQT == arr->getElementType())
return QT;
4505 QT = Ctxt.getConstantArrayType (newQT,
4507 arr->getSizeModifier(),
4508 arr->getIndexTypeCVRQualifiers());
4510 }
else if (isa<DependentSizedArrayType>(QT.getTypePtr())) {
4511 const DependentSizedArrayType *arr = dyn_cast<DependentSizedArrayType>(QT.getTypePtr());
4515 if (newQT == QT)
return QT;
4516 QT = Ctxt.getDependentSizedArrayType (newQT,
4518 arr->getSizeModifier(),
4519 arr->getIndexTypeCVRQualifiers(),
4520 arr->getBracketsRange());
4522 }
else if (isa<IncompleteArrayType>(QT.getTypePtr())) {
4523 const IncompleteArrayType *arr
4524 = dyn_cast<IncompleteArrayType>(QT.getTypePtr());
4528 if (newQT == arr->getElementType())
return QT;
4529 QT = Ctxt.getIncompleteArrayType (newQT,
4530 arr->getSizeModifier(),
4531 arr->getIndexTypeCVRQualifiers());
4533 }
else if (isa<VariableArrayType>(QT.getTypePtr())) {
4534 const VariableArrayType *arr
4535 = dyn_cast<VariableArrayType>(QT.getTypePtr());
4539 if (newQT == arr->getElementType())
return QT;
4540 QT = Ctxt.getVariableArrayType (newQT,
4542 arr->getSizeModifier(),
4543 arr->getIndexTypeCVRQualifiers(),
4544 arr->getBracketsRange());
4548 QT = Ctxt.getQualifiedType(QT, quals);
4553 etype = llvm::dyn_cast<clang::ElaboratedType>(instance);
4555 instance = etype->getNamedType().getTypePtr();
4556 if (!instance)
return input;
4559 const clang::TemplateSpecializationType* TST
4560 = llvm::dyn_cast<
const clang::TemplateSpecializationType>(instance);
4562 if (!TST)
return input;
4564 const clang::ClassTemplateSpecializationDecl* TSTdecl
4565 = llvm::dyn_cast_or_null<const clang::ClassTemplateSpecializationDecl>(instance->getAsCXXRecordDecl());
4567 const clang::SubstTemplateTypeParmType *substType
4568 = llvm::dyn_cast<clang::SubstTemplateTypeParmType>(input.getTypePtr());
4572 const clang::ClassTemplateDecl *replacedCtxt = 0;
4574 const clang::DeclContext *replacedDeclCtxt = substType->getReplacedParameter()->getDecl()->getDeclContext();
4575 const clang::CXXRecordDecl *decl = llvm::dyn_cast<clang::CXXRecordDecl>(replacedDeclCtxt);
4576 unsigned int index = substType->getReplacedParameter()->getIndex();
4579 if (decl->getKind() == clang::Decl::ClassTemplatePartialSpecialization) {
4580 const clang::ClassTemplatePartialSpecializationDecl *spec = llvm::dyn_cast<clang::ClassTemplatePartialSpecializationDecl>(decl);
4582 unsigned int depth = substType->getReplacedParameter()->getDepth();
4584 const TemplateArgument *instanceArgs = spec->getTemplateArgs().data();
4585 unsigned int instanceNArgs = spec->getTemplateArgs().size();
4589 for(
unsigned int A = 0;
A < instanceNArgs; ++
A) {
4591 clang::QualType argQualType = instanceArgs[
A].getAsType();
4593 const clang::TemplateTypeParmType *replacementType;
4595 replacementType = llvm::dyn_cast<clang::TemplateTypeParmType>(argQualType);
4597 if (!replacementType) {
4598 const clang::SubstTemplateTypeParmType *argType
4599 = llvm::dyn_cast<clang::SubstTemplateTypeParmType>(argQualType);
4601 clang::QualType replacementQT = argType->getReplacementType();
4602 replacementType = llvm::dyn_cast<clang::TemplateTypeParmType>(replacementQT);
4605 if (replacementType &&
4606 depth == replacementType->getDepth() &&
4607 index == replacementType->getIndex() )
4614 replacedCtxt = spec->getSpecializedTemplate();
4616 replacedCtxt = decl->getDescribedClassTemplate();
4619 replacedCtxt = llvm::dyn_cast<clang::ClassTemplateDecl>(replacedDeclCtxt);
4622 if (replacedCtxt->getCanonicalDecl() == TSTdecl->getSpecializedTemplate()->getCanonicalDecl()
4624 substType->getReplacedParameter()->getDecl()
4625 == TSTdecl->getSpecializedTemplate ()->getTemplateParameters()->getParam(index))
4627 if ( index >= TST->getNumArgs() ) {
4634 return TST->getArg(index).getAsType();
4639 const clang::TemplateSpecializationType* inputTST
4640 = llvm::dyn_cast<
const clang::TemplateSpecializationType>(input.getTypePtr());
4641 const clang::ASTContext& astCtxt = TSTdecl->getASTContext();
4644 bool mightHaveChanged =
false;
4645 llvm::SmallVector<clang::TemplateArgument, 4> desArgs;
4646 for(clang::TemplateSpecializationType::iterator
I = inputTST->begin(),
E = inputTST->end();
4649 desArgs.push_back(*
I);
4653 clang::QualType SubTy =
I->getAsType();
4655 if (llvm::isa<clang::SubstTemplateTypeParmType>(SubTy)
4656 || llvm::isa<clang::TemplateSpecializationType>(SubTy)) {
4658 mightHaveChanged = SubTy != newSubTy;
4659 if (!newSubTy.isNull()) {
4660 desArgs.push_back(clang::TemplateArgument(newSubTy));
4663 desArgs.push_back(*
I);
4667 if (mightHaveChanged) {
4668 clang::Qualifiers qualifiers = input.getLocalQualifiers();
4669 input = astCtxt.getTemplateSpecializationType(inputTST->getTemplateName(),
4672 inputTST->getCanonicalTypeInternal());
4673 input = astCtxt.getQualifiedType(input, qualifiers);
4685 if ( nArgsToRemove == 0 || name ==
"")
4690 const unsigned int length = name.length();
4692 unsigned int nArgsRemoved=0;
4693 unsigned int nBraces=0;
4695 while (nArgsRemoved!=nArgsToRemove && cur<length){
4697 if (c ==
'<') nBraces++;
4698 if (c ==
'>') nBraces--;
4699 if (c ==
',' && nBraces==1 ) nArgsRemoved++;
4703 name = name.substr(0,cur)+
">";
4713 static const char *stls[] =
4714 {
"any",
"vector",
"list",
"deque",
"map",
"multimap",
"set",
"multiset",
"bitset",
4715 "forward_list",
"unordered_set",
"unordered_multiset",
"unordered_map",
"unordered_multimap",0};
4728 for(
int k=1;stls[k];k++) {
if (type.equals(stls[k]))
return values[k];}
4739 TND = TND->getMostRecentDecl();
4740 while (TND && !(TND->hasAttrs()))
4741 TND = TND->getPreviousDecl();
4753 TD = TD->getMostRecentDecl();
4754 while (TD && !(TD->hasAttrs() && TD->isThisDeclarationADefinition()))
4755 TD = TD->getPreviousDecl();
4764 std::list<std::pair<std::string,bool> >& enclosingNamespaces)
4766 const clang::DeclContext* enclosingNamespaceDeclCtxt = decl.getDeclContext();
4767 if (!enclosingNamespaceDeclCtxt)
return;
4769 const clang::NamespaceDecl* enclosingNamespace =
4770 clang::dyn_cast<clang::NamespaceDecl>(enclosingNamespaceDeclCtxt);
4771 if (!enclosingNamespace)
return;
4773 enclosingNamespaces.push_back(std::make_pair(enclosingNamespace->getNameAsString(),
4774 enclosingNamespace->isInline()));
4784 std::list<std::pair<std::string,bool> >& enclosingNamespaces)
4786 const clang::DeclContext* enclosingNamespaceDeclCtxt = ctxt.getParent ();
4789 if (!enclosingNamespaceDeclCtxt) {
4795 const clang::NamespaceDecl* enclosingNamespace = clang::dyn_cast<clang::NamespaceDecl>(enclosingNamespaceDeclCtxt);
4796 if (!enclosingNamespace)
return;
4799 enclosingNamespaces.push_back(std::make_pair(enclosingNamespace->getNameAsString(),
4800 enclosingNamespace->isInline()));
4811 std::list<std::pair<std::string,unsigned int> >& enclosingSc)
4813 const clang::DeclContext* enclosingDeclCtxt = decl.getDeclContext();
4814 if (!enclosingDeclCtxt)
return 0;
4816 unsigned int scopeType;
4818 if (
auto enclosingNamespacePtr =
4819 clang::dyn_cast<clang::NamespaceDecl>(enclosingDeclCtxt)){
4820 scopeType= enclosingNamespacePtr->isInline() ? 1 : 0;
4821 enclosingSc.push_back(std::make_pair(enclosingNamespacePtr->getNameAsString(),scopeType));
4825 if (
auto enclosingClassPtr =
4826 clang::dyn_cast<clang::RecordDecl>(enclosingDeclCtxt)){
4827 return enclosingClassPtr;
4840 std::string::size_type beginVar = 0;
4841 std::string::size_type endVar = 0;
4842 while ((beginVar = txt.find(
'$', beginVar)) != std::string::npos
4843 && beginVar + 1 < txt.length()) {
4844 std::string::size_type beginVarName = beginVar + 1;
4845 std::string::size_type endVarName = std::string::npos;
4846 if (txt[beginVarName] ==
'(') {
4848 endVarName = txt.find(
')', beginVarName);
4850 if (endVarName == std::string::npos) {
4852 varname, txt.c_str() + beginVar);
4855 endVar = endVarName + 1;
4858 beginVarName = beginVar + 1;
4859 endVarName = beginVarName;
4860 while (isalnum(txt[endVarName]) || txt[endVarName] ==
'_')
4862 endVar = endVarName;
4865 const char* val = getenv(txt.substr(beginVarName,
4866 endVarName - beginVarName).c_str());
4869 txt.replace(beginVar, endVar - beginVar, val);
4870 int lenval = strlen(val);
4871 int delta = lenval - (endVar - beginVar);
4875 beginVar = endVar + 1;
4887 const char* envInclPath = getenv(
"ROOT_INCLUDE_PATH");
4891 std::istringstream envInclPathsStream(envInclPath);
4892 std::string inclPath;
4893 while (std::getline(envInclPathsStream, inclPath,
':')) {
4896 if (!inclPath.empty()) {
4897 clingArgs.push_back(
"-I");
4898 clingArgs.push_back(inclPath);
4909 size_t start_pos = 0;
4914 while((start_pos = str.find(from, start_pos)) != std::string::npos) {
4915 str.replace(start_pos, from.length(), to);
4916 start_pos += to.length();
4917 if (recurse) changed =
true;
4930 static const std::string gPathSeparator (
"\\");
4932 static const std::string gPathSeparator (
"/");
4934 return gPathSeparator;
4941 if (theString.size() < theSubstring.size())
return false;
4942 const unsigned int theSubstringSize = theSubstring.size();
4943 return 0 == theString.compare(theString.size() - theSubstringSize,
4952 if (theString.size() < theSubstring.size())
return false;
4953 const unsigned int theSubstringSize = theSubstring.size();
4954 return 0 == theString.compare(0,
4964 clang::Sema &sema = interp.getSema();
4965 cling::Transaction theTransaction(sema);
4966 std::set<clang::Decl *> addedDecls;
4967 for (
auto decl : decls) {
4969 clang::Decl *ncDecl =
const_cast<clang::Decl *
>(decl);
4970 theTransaction.append(ncDecl);
4972 std::string newFwdDecl;
4973 llvm::raw_string_ostream llvmOstr(newFwdDecl);
4974 interp.forwardDeclare(theTransaction, sema, llvmOstr,
true,
nullptr, ignoreFiles);
4987 std::string& defString)
4999 std::string& defString)
5001 std::list<std::pair<std::string,unsigned int> > enclosingNamespaces;
5004 if (rcdPtr)
return rcdPtr;
5007 static const std::string scopeType [] = {
"namespace ",
"inline namespace ",
"class "};
5009 std::string scopeName;
5010 std::string scopeContent;
5011 unsigned int scopeIndex;
5012 for (
auto const & encScope : enclosingNamespaces){
5013 scopeIndex = encScope.second;
5014 scopeName = encScope.first;
5015 scopeContent =
" { " + defString +
" }";
5016 defString = scopeType[scopeIndex] +
5038 const clang::TemplateParameterList& tmplParamList,
5039 const cling::Interpreter& interpreter)
5041 static const char* paramPackWarning=
"Template parameter pack found: autoload of variadic templates is not supported yet.\n";
5044 for (
auto prmIt = tmplParamList.begin();
5045 prmIt != tmplParamList.end(); prmIt++){
5047 if (prmIt != tmplParamList.begin())
5048 templateArgs +=
", ";
5050 auto nDecl = *prmIt;
5051 std::string typeName;
5053 if(nDecl->isParameterPack ()){
5059 if (llvm::isa<clang::TemplateTypeParmDecl>(nDecl)){
5060 typeName =
"typename " + (*prmIt)->getNameAsString();
5063 else if (
auto nttpd = llvm::dyn_cast<clang::NonTypeTemplateParmDecl>(nDecl)){
5064 auto theType = nttpd->getType();
5067 if (theType.getAsString().find(
"enum") != std::string::npos){
5068 std::string astDump;
5069 llvm::raw_string_ostream ostream(astDump);
5070 nttpd->dump(ostream);
5072 ROOT::TMetaUtils::Warning(0,
"Forward declarations of templates with enums as template parameters. The responsible class is: %s\n", astDump.c_str());
5081 else if (
auto ttpd = llvm::dyn_cast<clang::TemplateTemplateParmDecl>(nDecl)){
5084 std::string astDump;
5085 llvm::raw_string_ostream ostream(astDump);
5086 ttpd->dump(ostream);
5088 ROOT::TMetaUtils::Error(0,
"Cannot reconstruct template template parameter forward declaration for %s\n", astDump.c_str());
5093 templateArgs += typeName;
5104 const cling::Interpreter& interpreter,
5105 std::string& defString)
5107 std::string templatePrefixString;
5108 auto tmplParamList= templDecl.getTemplateParameters();
5109 if (!tmplParamList){
5111 "Cannot extract template parameter list for %s",
5112 templDecl.getNameAsString().c_str());
5119 "Problems with arguments for forward declaration of class %s\n",
5120 templDecl.getNameAsString().c_str());
5123 templatePrefixString =
"template " + templatePrefixString +
" ";
5125 defString = templatePrefixString +
"class " + templDecl.getNameAsString();
5126 if (llvm::isa<clang::TemplateTemplateParmDecl>(&templDecl)) {
5140 std::string& argFwdDecl,
5141 const cling::Interpreter& interpreter,
5142 bool acceptStl=
false)
5150 auto argQualType = arg.getAsType();
5153 while (llvm::isa<clang::PointerType>(argQualType.getTypePtr())) argQualType = argQualType->getPointeeType();
5155 auto argTypePtr = argQualType.getTypePtr();
5158 if (llvm::isa<clang::EnumType>(argTypePtr)){
5163 if (llvm::isa<clang::BuiltinType>(argTypePtr)){
5168 if (llvm::isa<clang::TypedefType>(argTypePtr)){
5169 auto tdTypePtr = llvm::dyn_cast<clang::TypedefType>(argTypePtr);
5174 if (llvm::isa<clang::RecordType>(argQualType)){
5176 auto argRecTypePtr = llvm::cast<clang::RecordType>(argTypePtr);
5177 if (
auto argRecDeclPtr = argRecTypePtr->getDecl()){
5192 const cling::Interpreter& interpreter,
5193 std::string& defString,
5201 if (!recordDecl.getIdentifier())
5205 std::string argsFwdDecl;
5207 if (
auto tmplSpecDeclPtr = llvm::dyn_cast<clang::ClassTemplateSpecializationDecl>(&recordDecl)){
5208 std::string argFwdDecl;
5210 std::cout <<
"Class " << recordDecl.getNameAsString()
5211 <<
" is a template specialisation. Treating its arguments.\n";
5212 for(
auto arg : tmplSpecDeclPtr->getTemplateArgs().asArray()){
5215 std::cout <<
" o Template argument ";
5217 std::cout <<
"successfully treated. Arg fwd decl: " << argFwdDecl << std::endl;
5219 std::cout <<
"could not be treated. Abort fwd declaration generation.\n";
5226 argsFwdDecl+=argFwdDecl;
5230 defString=argsFwdDecl;
5235 if (
auto tmplDeclPtr = tmplSpecDeclPtr->getSpecializedTemplate()){
5238 defString = argsFwdDecl +
"\n" + defString;
5243 defString =
"class " + recordDecl.getNameAsString() +
";";
5244 const clang::RecordDecl* rcd =
EncloseInScopes(recordDecl, defString);
5252 defString = argsFwdDecl +
"\n" + defString;
5263 const cling::Interpreter& interpreter,
5264 std::string& fwdDeclString,
5265 std::unordered_set<std::string>* fwdDeclSetPtr)
5267 std::string buffer = tdnDecl.getNameAsString();
5268 std::string underlyingName;
5269 auto underlyingType = tdnDecl.getUnderlyingType().getCanonicalType();
5270 if (
const clang::TagType* TT
5271 = llvm::dyn_cast<clang::TagType>(underlyingType.getTypePtr())) {
5272 if (clang::NamedDecl* ND = TT->getDecl()) {
5273 if (!ND->getIdentifier()) {
5287 if (underlyingName.find(
">::") != std::string::npos)
5290 buffer=
"typedef "+underlyingName+
" "+buffer+
";";
5302 auto& ctxt = tdnDecl.getASTContext();
5303 auto immediatelyUnderlyingType = underlyingType.getSingleStepDesugaredType(ctxt);
5305 if (
auto underlyingTdnTypePtr = llvm::dyn_cast<clang::TypedefType>(immediatelyUnderlyingType.getTypePtr())){
5306 std::string tdnFwdDecl;
5307 auto underlyingTdnDeclPtr = underlyingTdnTypePtr->getDecl();
5312 if (!fwdDeclSetPtr || fwdDeclSetPtr->insert(tdnFwdDecl).second)
5313 fwdDeclString+=tdnFwdDecl;
5314 }
else if (
auto CXXRcdDeclPtr = immediatelyUnderlyingType->getAsCXXRecordDecl()){
5315 std::string classFwdDecl;
5317 std::cout <<
"Typedef " << tdnDecl.getNameAsString() <<
" hides a class: "
5318 << CXXRcdDeclPtr->getNameAsString() << std::endl;
5327 if (!fwdDeclSetPtr || fwdDeclSetPtr->insert(classFwdDecl).second)
5328 fwdDeclString+=classFwdDecl;
5331 fwdDeclString+=buffer;
5343 std::string& valAsString,
5344 const clang::PrintingPolicy& ppolicy)
5346 auto defArgExprPtr = par.getDefaultArg();
5347 auto& ctxt = par.getASTContext();
5348 if(!defArgExprPtr->isEvaluatable(ctxt)){
5352 auto defArgType = par.getType();
5355 if (defArgType->isBooleanType()){
5357 defArgExprPtr->EvaluateAsBooleanCondition (result,ctxt);
5358 valAsString=std::to_string(result);
5363 if (defArgType->isIntegerType()){
5365 defArgExprPtr->EvaluateAsInt(result,ctxt);
5366 auto uintVal = *result.getRawData();
5367 if (result.isNegative()){
5368 long long int intVal=uintVal*-1;
5369 valAsString=std::to_string(intVal);
5371 valAsString=std::to_string(uintVal);
5378 llvm::raw_string_ostream rso(valAsString);
5379 defArgExprPtr->printPretty(rso,
nullptr,ppolicy);
5380 valAsString = rso.str();
void WriteReadRawRuleFunc(SchemaRuleMap_t &rule, int index, std::string &mappedName, MembersTypeMap_t &members, std::ostream &output)
Write the conversion function for ReadRaw rule, the function name is being written to rule["funcname"...
ROOT::ESTLType IsSTLCont(std::string_view type)
type : type name: vector,allocator> result: 0 : not stl container code of cont...
ClassImp(TAlienJobStatusList) void TAlienJobStatusList TString split(jobstatus->GetKey("split"))
Print information about jobs.
Namespace for new ROOT classes and functions.
bool equal(double d1, double d2, double stol=10000)
void WriteSchemaList(std::list< SchemaRuleMap_t > &rules, const std::string &listName, std::ostream &output)
Write schema rules.
static const char * filename()
std::map< std::string, ROOT::Internal::TSchemaType > MembersTypeMap_t
bool IsSTLBitset(const char *type)
Return true is the name is std::bitset or bitset
void ShortType(std::string &answer, int mode)
Return the absolute type of typeDesc into the string answ.
std::map< std::string, std::string >::const_iterator iter
ROOT::ESTLType STLKind(std::string_view type)
Converts STL container name to number.
std::string GetLong64_Name(const char *original)
Replace 'long long' and 'unsigned long long' by 'Long64_t' and 'ULong64_t'.
void Error(const char *location, const char *msgfmt,...)
SchemaRuleClassMap_t gReadRules
Double_t length(const TVector2 &v)
static void indent(ostringstream &buf, int indent_level)
bool IsStdClass(const char *type)
return true if the class belongs to the std namespace
Type
enumeration specifying the integration types.
void WriteReadRuleFunc(SchemaRuleMap_t &rule, int index, std::string &mappedName, MembersTypeMap_t &members, std::ostream &output)
Write the conversion function for Read rule, the function name is being written to rule["funcname"]...
SchemaRuleClassMap_t gReadRawRules
ClassImp(TMCParticle) void TMCParticle printf(": p=(%7.3f,%7.3f,%9.3f) ;", fPx, fPy, fPz)
bool HasValidDataMembers(SchemaRuleMap_t &rule, MembersTypeMap_t &members)
Check if given rule contains references to valid data members.
#define dest(otri, vertexptr)