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))
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,
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,
437 const clang::RecordDecl *decl,
438 const char *requestName,
441 bool rRequestNoInputOperator,
442 bool rRequestOnlyTClass,
443 int rRequestVersionNumber,
444 const cling::Interpreter &interpreter,
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) {
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());
1007 if (argType->isPointerType()) {
1009 argType = argType->getPointeeType();
1010 }
else if (argType->isReferenceType()){
1012 argType = argType.getNonReferenceType();
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;
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) {
1093 std::string proto( ctorTypeIt->GetName() );
1094 bool defaultCtor = proto.empty();
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();
2419 for(clang::RecordDecl::field_iterator field_iter = clxx->field_begin(), end = clxx->field_end();
2423 std::string mTypename;
2429 if (!strcmp(shortTypeName,
"string")) {
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;
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) {
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());
3406 clang::ClassTemplateDecl*& ctd,
3407 clang::ClassTemplateSpecializationDecl*& ctsd)
3409 using namespace clang;
3410 const Type* theType = qt.getTypePtr();
3417 if (theType->isPointerType()) {
3421 if (
const RecordType* rType = llvm::dyn_cast<RecordType>(theType)) {
3422 ctsd = llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(rType->getDecl());
3424 ctd = ctsd->getSpecializedTemplate();
3429 if (
const SubstTemplateTypeParmType* sttpType = llvm::dyn_cast<SubstTemplateTypeParmType>(theType)){
3434 ctsd = llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(qt->getAsCXXRecordDecl());
3436 ctd = ctsd->getSpecializedTemplate();
3451 using namespace clang;
3452 ClassTemplateSpecializationDecl* ctsd;
3453 ClassTemplateDecl* ctd;
3467 using namespace clang;
3468 TemplateName theTemplateName;
3470 const Type* theType = qt.getTypePtr();
3472 if (
const TemplateSpecializationType* tst = llvm::dyn_cast_or_null<const TemplateSpecializationType>(theType)) {
3473 theTemplateName = tst->getTemplateName();
3476 theTemplateName = TemplateName(ctd);
3479 return theTemplateName;
3485 llvm::SmallVectorImpl<clang::TemplateArgument>& preceedingTArgs,
3486 const clang::NamedDecl& tPar,
3487 const cling::Interpreter& interp,
3491 using namespace clang;
3494 TemplateTypeParmDecl* ttpdPtr =
const_cast<TemplateTypeParmDecl*
>(llvm::dyn_cast<TemplateTypeParmDecl>(&tPar));
3495 if (!ttpdPtr)
return false;
3496 if (!ttpdPtr->hasDefaultArgument())
return false;
3499 QualType tParQualType = ttpdPtr->getDefaultArgument();
3500 const QualType tArgQualType = tArg.getAsType();
3507 if (tParQualType.getTypePtr() == tArgQualType.getTypePtr())
return true;
3518 const clang::ElaboratedType* etype
3519 = llvm::dyn_cast<clang::ElaboratedType>(tParQualType.getTypePtr());
3521 tParQualType = clang::QualType(etype->getNamedType().getTypePtr(),0);
3522 etype = llvm::dyn_cast<clang::ElaboratedType>(tParQualType.getTypePtr());
3525 const TemplateSpecializationType* tst =
3526 llvm::dyn_cast<TemplateSpecializationType>(tParQualType.getTypePtr());
3531 ClassTemplateSpecializationDecl* TSTdecl
3532 = llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(tArgQualType->getAsCXXRecordDecl());
3537 TemplateDecl *
Template = tst->getTemplateName().getAsTemplateDecl();
3540 SourceLocation TemplateLoc = Template->getSourceRange ().getBegin();
3543 SourceLocation LAngleLoc = TSTdecl->getSourceRange().getBegin();
3548 TemplateArgument newArg = tArg;
3550 clang::Sema&
S = interp.getCI()->getSema();
3551 cling::Interpreter::PushTransactionRAII clingRAII(const_cast<cling::Interpreter*>(&interp));
3552 clang::sema::HackForDefaultTemplateArg raii;
3553 bool HasDefaultArgs;
3554 TemplateArgumentLoc defTArgLoc = S.SubstDefaultTemplateArgumentIfAvailable(Template,
3562 newArg = defTArgLoc.getArgument();
3563 if (newArg.isNull() ||
3566 "Template parameter substitution failed!");
3569 ClassTemplateSpecializationDecl* nTSTdecl
3570 = llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(newArg.getAsType()->getAsCXXRecordDecl());
3573 isEqual = nTSTdecl->getMostRecentDecl() == TSTdecl->getMostRecentDecl() ||
3574 tParQualType.getTypePtr() == newArg.getAsType().getTypePtr();
3586 const clang::NamedDecl& tPar)
3588 using namespace clang;
3589 const NonTypeTemplateParmDecl* nttpdPtr = llvm::dyn_cast<NonTypeTemplateParmDecl>(&tPar);
3590 if (!nttpdPtr)
return false;
3591 const NonTypeTemplateParmDecl& nttpd = *nttpdPtr;
3593 if (!nttpd.hasDefaultArgument())
3597 llvm::APSInt defaultValueAPSInt(64,
false);
3598 if (Expr* defArgExpr = nttpd.getDefaultArgument()) {
3599 const ASTContext& astCtxt = nttpdPtr->getASTContext();
3600 defArgExpr->isIntegerConstantExpr(defaultValueAPSInt, astCtxt);
3603 const int value = tArg.getAsIntegral().getLimitedValue();
3606 return value == defaultValueAPSInt;
3616 using namespace clang;
3617 if (!nDecl)
return false;
3618 if (
const TemplateTypeParmDecl* ttpd = llvm::dyn_cast<TemplateTypeParmDecl>(nDecl))
3619 return ttpd->hasDefaultArgument();
3620 if (
const NonTypeTemplateParmDecl* nttpd = llvm::dyn_cast<NonTypeTemplateParmDecl>(nDecl))
3621 return nttpd->hasDefaultArgument();
3631 const clang::QualType& vanillaType,
3632 const cling::Interpreter& interp,
3636 using namespace clang;
3640 ClassTemplateSpecializationDecl* ctsd;
3641 ClassTemplateDecl* ctd;
3648 QualType originalNormalizedType = normalizedType;
3650 const ASTContext& astCtxt = ctsd->getASTContext();
3655 if (llvm::isa<clang::PointerType>(normalizedType.getTypePtr())) {
3657 clang::Qualifiers quals = normalizedType.getQualifiers();
3658 auto valNormalizedType = normalizedType->getPointeeType();
3659 KeepNParams(valNormalizedType,vanillaType, interp, normCtxt);
3660 normalizedType = astCtxt.getPointerType(valNormalizedType);
3662 normalizedType = astCtxt.getQualifiedType(normalizedType, quals);
3668 if (llvm::isa<clang::ReferenceType>(normalizedType.getTypePtr())) {
3670 bool isLValueRefTy = llvm::isa<clang::LValueReferenceType>(normalizedType.getTypePtr());
3671 clang::Qualifiers quals = normalizedType.getQualifiers();
3672 auto valNormType = normalizedType->getPointeeType();
3673 KeepNParams(valNormType, vanillaType, interp, normCtxt);
3677 normalizedType = astCtxt.getLValueReferenceType(valNormType);
3679 normalizedType = astCtxt.getRValueReferenceType(valNormType);
3681 normalizedType = astCtxt.getQualifiedType(normalizedType, quals);
3686 bool prefix_changed =
false;
3687 clang::NestedNameSpecifier* prefix =
nullptr;
3688 clang::Qualifiers prefix_qualifiers = normalizedType.getLocalQualifiers();
3689 const clang::ElaboratedType* etype
3690 = llvm::dyn_cast<clang::ElaboratedType>(normalizedType.getTypePtr());
3694 prefix = AddDefaultParametersNNS(astCtxt, etype->getQualifier(), interp, normCtxt);
3695 prefix_changed = prefix != etype->getQualifier();
3696 normalizedType = clang::QualType(etype->getNamedType().getTypePtr(),0);
3702 const clang::ClassTemplateDecl* ctdWithDefaultArgs = ctd;
3703 for (
const RedeclarableTemplateDecl* rd: ctdWithDefaultArgs->redecls()) {
3704 clang::TemplateParameterList* tpl = rd->getTemplateParameters();
3705 if (tpl->getMinRequiredArguments () < tpl->size())
3706 ctdWithDefaultArgs = llvm::dyn_cast<clang::ClassTemplateDecl>(rd);
3708 TemplateParameterList* tParsPtr = ctdWithDefaultArgs->getTemplateParameters();
3709 const TemplateParameterList& tPars = *tParsPtr;
3710 const TemplateArgumentList& tArgs = ctsd->getTemplateArgs();
3714 if (theTemplateName.isNull()) {
3715 normalizedType=originalNormalizedType;
3719 const TemplateSpecializationType* normalizedTst =
3720 llvm::dyn_cast<TemplateSpecializationType>(normalizedType.getTypePtr());
3721 if (!normalizedTst) {
3722 normalizedType=originalNormalizedType;
3726 const clang::ClassTemplateSpecializationDecl* TSTdecl
3727 = llvm::dyn_cast_or_null<const clang::ClassTemplateSpecializationDecl>(normalizedType.getTypePtr()->getAsCXXRecordDecl());
3735 llvm::SmallVector<TemplateArgument, 4> argsToKeep;
3737 const int nArgs = tArgs.size();
3738 const int nNormArgs = normalizedTst->getNumArgs();
3740 bool mightHaveChanged =
false;
3743 for (
int index = 0; index != nArgs; ++index) {
3744 const NamedDecl* tParPtr = tPars.getParam(index);
3745 if (!tParPtr)
Error(
"KeepNParams",
3746 "The parameter number %s is null.\n",
3749 const TemplateArgument& tArg = tArgs.get(index);
3753 if (index == nNormArgs)
break;
3755 TemplateArgument NormTArg(normalizedTst->getArgs()[index]);
3757 bool shouldKeepArg = nArgsToKeep < 0 || index <
nArgsToKeep;
3758 if (isStdDropDefault) shouldKeepArg =
false;
3770 QualType thisNormQualType = NormTArg.getAsType();
3771 QualType thisArgQualType = tArg.getAsType();
3776 mightHaveChanged |= (thisNormQualType != thisArgQualType);
3777 NormTArg = TemplateArgument(thisNormQualType);
3779 argsToKeep.push_back(NormTArg);
3782 if (!isStdDropDefault) {
3784 mightHaveChanged =
true;
3794 auto argKind = tArg.getKind();
3797 equal =
areEqualTypes(tArg, argsToKeep, *tParPtr, interp, normCtxt);
3798 }
else if (argKind == clang::TemplateArgument::Integral){
3802 argsToKeep.push_back(NormTArg);
3804 mightHaveChanged =
true;
3810 if (!prefix_changed && !mightHaveChanged) {
3811 normalizedType = originalNormalizedType;
3816 if (mightHaveChanged) {
3817 Qualifiers qualifiers = normalizedType.getLocalQualifiers();
3818 normalizedType = astCtxt.getTemplateSpecializationType(theTemplateName,
3821 normalizedType.getTypePtr()->getCanonicalTypeInternal());
3822 normalizedType = astCtxt.getQualifiedType(normalizedType, qualifiers);
3828 normalizedType = astCtxt.getElaboratedType(clang::ETK_None,prefix,normalizedType);
3829 normalizedType = astCtxt.getQualifiedType(normalizedType,prefix_qualifiers);
3843 clang::ASTContext &ctxt = interpreter.getCI()->getASTContext();
3845 clang::QualType normalizedType = cling::utils::Transform::GetPartiallyDesugaredType(ctxt, type, normCtxt.
GetConfig(),
true );
3851 KeepNParams(normalizedType,type,interpreter,normCtxt);
3853 return normalizedType;
3867 if (type.isNull()) {
3874 clang::ASTContext &ctxt = interpreter.getCI()->getASTContext();
3875 clang::PrintingPolicy policy(ctxt.getPrintingPolicy());
3876 policy.SuppressTagKeyword =
true;
3877 policy.SuppressScope =
true;
3878 policy.AnonymousTagLocations =
false;
3883 std::string normalizedNameStep1;
3884 normalizedType.getAsStringInternal(normalizedNameStep1,policy);
3894 if (norm_name.length()>2 && norm_name[0]==
':' && norm_name[1]==
':') {
3895 norm_name.erase(0,2);
3903 const clang::TypeDecl* typeDecl,
3904 const cling::Interpreter &interpreter)
3907 const clang::Sema &sema = interpreter.getSema();
3908 clang::ASTContext& astCtxt = sema.getASTContext();
3909 clang::QualType qualType = astCtxt.getTypeDeclType(typeDecl);
3922 std::string dictFileName(moduleName);
3923 dictFileName +=
"_rdict.pcm";
3924 return dictFileName;
3931 const char* moduleFileName,
3932 const char* headers[])
3934 clang::Preprocessor& PP = CI->getPreprocessor();
3935 clang::ModuleMap& ModuleMap = PP.getHeaderSearchInfo().getModuleMap();
3938 clang::HeaderSearch& HS = CI->getPreprocessor().getHeaderSearchInfo();
3939 HS.setModuleCachePath(llvm::sys::path::parent_path(moduleFileName));
3942 moduleName = llvm::sys::path::stem(moduleName);
3944 std::pair<clang::Module*, bool> modCreation;
3947 = ModuleMap.findOrCreateModule(moduleName.str(),
3950 if (!modCreation.second && !strstr(moduleFileName,
"/allDict_rdict.pcm")) {
3951 std::cerr <<
"TMetaUtils::declareModuleMap: " 3952 "Duplicate definition of dictionary module " 3953 << moduleFileName << std::endl;
3958 clang::HeaderSearch& HdrSearch = PP.getHeaderSearchInfo();
3959 for (
const char** hdr = headers; hdr && *hdr; ++hdr) {
3960 const clang::DirectoryLookup* CurDir;
3961 const clang::FileEntry* hdrFileEntry
3962 = HdrSearch.LookupFile(*hdr, clang::SourceLocation(),
3964 llvm::ArrayRef<std::pair<
const clang::FileEntry *,
3965 const clang::DirectoryEntry *>>(),
3969 if (!hdrFileEntry) {
3970 std::cerr <<
"TMetaUtils::declareModuleMap: " 3971 "Cannot find header file " << *hdr
3972 <<
" included in dictionary module " 3974 <<
" in include search path!";
3975 hdrFileEntry = PP.getFileManager().getFile(*hdr,
false,
3977 }
else if (getenv(
"ROOT_MODULES")) {
3979 llvm::StringRef srHdrDir(hdrFileEntry->getName());
3980 srHdrDir = llvm::sys::path::parent_path(srHdrDir);
3981 const clang::DirectoryEntry* Dir
3982 = PP.getFileManager().getDirectory(srHdrDir);
3984 HdrSearch.setDirectoryHasModuleMap(Dir);
3988 ModuleMap.addHeader(modCreation.first,
3989 clang::Module::Header{*hdr,hdrFileEntry},
3990 clang::ModuleMap::NormalHeader);
3992 return modCreation.first;
3996 llvm::errs() << llvm::StringRef(commentStart, 80) <<
'\n';
4022 clang::SourceManager& sourceManager = decl.getASTContext().getSourceManager();
4023 clang::SourceLocation sourceLocation = decl.getLocEnd();
4026 sourceLocation = sourceManager.getExpansionRange(sourceLocation).second;
4027 if (sourceManager.isLoadedSourceLocation(sourceLocation)) {
4033 const char *commentStart = sourceManager.getCharacterData(sourceLocation, &invalid);
4037 bool skipToSemi =
true;
4038 if (
const clang::FunctionDecl* FD = clang::dyn_cast<clang::FunctionDecl>(&decl)) {
4039 if (FD->isImplicit()) {
4043 if (FD->isExplicitlyDefaulted() || FD->isDeletedAsWritten()) {
4047 }
else if (FD->doesThisDeclarationHaveABody()) {
4050 assert((decl.getLocEnd() != sourceLocation || *commentStart ==
'}' 4052 &&
"Expected macro or end of body at '}'");
4053 if (*commentStart) ++commentStart;
4056 while (*commentStart && isspace(*commentStart)
4057 && *commentStart !=
'\n' && *commentStart !=
'\r') {
4060 if (*commentStart ==
';') ++commentStart;
4064 }
else if (
const clang::EnumConstantDecl* ECD
4065 = clang::dyn_cast<clang::EnumConstantDecl>(&decl)) {
4067 if (ECD->getNextDeclInContext())
4068 while (*commentStart && *commentStart !=
',' && *commentStart !=
'\r' && *commentStart !=
'\n')
4076 while (*commentStart && *commentStart !=
';' && *commentStart !=
'\r' && *commentStart !=
'\n')
4078 if (*commentStart ==
';') ++commentStart;
4082 while ( *commentStart && isspace(*commentStart)
4083 && *commentStart !=
'\n' && *commentStart !=
'\r') {
4087 if (commentStart[0] !=
'/' ||
4088 (commentStart[1] !=
'/' && commentStart[1] !=
'*')) {
4098 unsigned int skipChars = 2;
4099 if (commentStart[0] ==
'/' &&
4100 commentStart[1] ==
'/' &&
4101 (commentStart[2] ==
'/' || commentStart[2] ==
'!') &&
4102 commentStart[3] ==
'<') {
4104 }
else if (commentStart[0] ==
'/' &&
4105 commentStart[1] ==
'*' &&
4106 (commentStart[2] ==
'*' || commentStart[2] ==
'!') &&
4107 commentStart[3] ==
'<') {
4111 commentStart += skipChars;
4114 while ( *commentStart && isspace(*commentStart)
4115 && *commentStart !=
'\n' && *commentStart !=
'\r') {
4118 const char* commentEnd = commentStart;
4120 while (*commentEnd && *commentEnd !=
'\n' && *commentEnd !=
'\r') {
4126 while (commentEnd > commentStart && isspace(commentEnd[-1])) {
4132 unsigned offset = commentStart - sourceManager.getCharacterData(sourceLocation);
4133 *loc = sourceLocation.getLocWithOffset(offset - 1);
4136 return llvm::StringRef(commentStart, commentEnd - commentStart);
4147 clang::SourceLocation *loc,
4148 const cling::Interpreter &interpreter)
4150 using namespace clang;
4151 SourceLocation commentSLoc;
4154 Sema& sema = interpreter.getCI()->getSema();
4156 const Decl* DeclFileLineDecl
4157 = interpreter.getLookupHelper().findFunctionProto(&decl,
"DeclFileLine",
"",
4158 cling::LookupHelper::NoDiagnostics);
4159 if (!DeclFileLineDecl)
return llvm::StringRef();
4162 SourceLocation maybeMacroLoc = DeclFileLineDecl->getLocation();
4163 bool isClassDefMacro = maybeMacroLoc.isMacroID() && sema.findMacroSpelling(maybeMacroLoc,
"ClassDef");
4164 if (isClassDefMacro) {
4166 if (comment.size()) {
4173 return llvm::StringRef();
4185 if (rawtype->isElaboratedTypeSpecifier() ) {
4186 rawtype = rawtype->getCanonicalTypeInternal().getTypePtr();
4188 if (rawtype->isArrayType()) {
4189 rawtype = type.getTypePtr()->getBaseElementTypeUnsafe ();
4191 if (rawtype->isPointerType() || rawtype->isReferenceType() ) {
4193 clang::QualType pointee;
4194 while ( (pointee = rawtype->getPointeeType()) , pointee.getTypePtrOrNull() && pointee.getTypePtr() != rawtype)
4196 rawtype = pointee.getTypePtr();
4198 if (rawtype->isElaboratedTypeSpecifier() ) {
4199 rawtype = rawtype->getCanonicalTypeInternal().getTypePtr();
4201 if (rawtype->isArrayType()) {
4202 rawtype = rawtype->getBaseElementTypeUnsafe ();
4206 if (rawtype->isArrayType()) {
4207 rawtype = rawtype->getBaseElementTypeUnsafe ();
4228 static const char *names[] =
4229 {
"shared_ptr",
"__shared_ptr",
4230 "vector",
"list",
"deque",
"map",
"multimap",
"set",
"multiset",
"bitset"};
4231 llvm::StringRef clname(cl.getName());
4232 for(
auto &&name : names) {
4233 if (clname == name)
return true;
4243 const clang::CXXRecordDecl ¤tCl)
4246 if (&cl == ¤tCl)
return true;
4248 const clang::CXXRecordDecl* previous = currentCl.getPreviousDecl();
4251 if (
NULL == previous){
4270 const clang::CXXRecordDecl *thisDecl =
4271 llvm::dyn_cast_or_null<clang::CXXRecordDecl>(lh.findScope(typ, cling::LookupHelper::WithDiagnostics));
4275 Error(
"IsOfType",
"Record decl of type %s not found in the AST.", typ.c_str());
4280 const clang::CXXRecordDecl *mostRecentDecl = thisDecl->getMostRecentDecl();
4313 using namespace clang;
4314 struct SearchTypedef:
public TypeVisitor<SearchTypedef, bool> {
4315 bool VisitTypedefType(
const TypedefType* TD) {
4318 bool VisitArrayType(
const ArrayType* AT) {
4319 return Visit(AT->getElementType().getTypePtr());
4321 bool VisitDecltypeType(
const DecltypeType* DT) {
4322 return Visit(DT->getUnderlyingType().getTypePtr());
4324 bool VisitPointerType(
const PointerType* PT) {
4325 return Visit(PT->getPointeeType().getTypePtr());
4327 bool VisitReferenceType(
const ReferenceType* RT) {
4328 return Visit(RT->getPointeeType().getTypePtr());
4330 bool VisitSubstTemplateTypeParmType(
const SubstTemplateTypeParmType* STST) {
4331 return Visit(STST->getReplacementType().getTypePtr());
4333 bool VisitTemplateSpecializationType(
const TemplateSpecializationType* TST) {
4334 for (
int I = 0,
N = TST->getNumArgs();
I <
N; ++
I) {
4335 const TemplateArgument& TA = TST->getArg(
I);
4337 && Visit(TA.getAsType().getTypePtr()))
4342 bool VisitTemplateTypeParmType(
const TemplateTypeParmType* TTPT) {
4345 bool VisitTypeOfType(
const TypeOfType* TOT) {
4346 return TOT->getUnderlyingType().getTypePtr();
4348 bool VisitElaboratedType(
const ElaboratedType* ET) {
4349 NestedNameSpecifier* NNS = ET->getQualifier();
4351 if (NNS->getKind() == NestedNameSpecifier::TypeSpec) {
4352 if (Visit(NNS->getAsType()))
4355 NNS = NNS->getPrefix();
4357 return Visit(ET->getNamedType().getTypePtr());
4372 if (!instance)
return input;
4378 using namespace llvm;
4379 using namespace clang;
4380 const clang::ASTContext &Ctxt = instance->getAsCXXRecordDecl()->getASTContext();
4383 const clang::ElaboratedType* etype
4384 = llvm::dyn_cast<clang::ElaboratedType>(input.getTypePtr());
4388 clang::Qualifiers scope_qualifiers = input.getLocalQualifiers();
4389 assert(instance->getAsCXXRecordDecl()!=0 &&
"ReSubstTemplateArg only makes sense with a type representing a class.");
4391 clang::NestedNameSpecifier *scope = ReSubstTemplateArgNNS(Ctxt,etype->getQualifier(),instance);
4392 clang::QualType subTy =
ReSubstTemplateArg(clang::QualType(etype->getNamedType().getTypePtr(),0),instance);
4394 if (scope) subTy = Ctxt.getElaboratedType(clang::ETK_None,scope,subTy);
4395 subTy = Ctxt.getQualifiedType(subTy,scope_qualifiers);
4399 QualType QT = input;
4403 if (isa<clang::PointerType>(QT.getTypePtr())) {
4405 Qualifiers quals = QT.getQualifiers();
4408 if (nQT == QT->getPointeeType())
return QT;
4410 QT = Ctxt.getPointerType(nQT);
4412 QT = Ctxt.getQualifiedType(QT, quals);
4418 if (isa<ReferenceType>(QT.getTypePtr())) {
4420 bool isLValueRefTy = isa<LValueReferenceType>(QT.getTypePtr());
4421 Qualifiers quals = QT.getQualifiers();
4424 if (nQT == QT->getPointeeType())
return QT;
4428 QT = Ctxt.getLValueReferenceType(nQT);
4430 QT = Ctxt.getRValueReferenceType(nQT);
4432 QT = Ctxt.getQualifiedType(QT, quals);
4438 if (isa<clang::ArrayType>(QT.getTypePtr())) {
4440 Qualifiers quals = QT.getQualifiers();
4442 if (isa<ConstantArrayType>(QT.getTypePtr())) {
4443 const ConstantArrayType *arr = dyn_cast<ConstantArrayType>(QT.getTypePtr());
4447 if (newQT == arr->getElementType())
return QT;
4448 QT = Ctxt.getConstantArrayType (newQT,
4450 arr->getSizeModifier(),
4451 arr->getIndexTypeCVRQualifiers());
4453 }
else if (isa<DependentSizedArrayType>(QT.getTypePtr())) {
4454 const DependentSizedArrayType *arr = dyn_cast<DependentSizedArrayType>(QT.getTypePtr());
4458 if (newQT == QT)
return QT;
4459 QT = Ctxt.getDependentSizedArrayType (newQT,
4461 arr->getSizeModifier(),
4462 arr->getIndexTypeCVRQualifiers(),
4463 arr->getBracketsRange());
4465 }
else if (isa<IncompleteArrayType>(QT.getTypePtr())) {
4466 const IncompleteArrayType *arr
4467 = dyn_cast<IncompleteArrayType>(QT.getTypePtr());
4471 if (newQT == arr->getElementType())
return QT;
4472 QT = Ctxt.getIncompleteArrayType (newQT,
4473 arr->getSizeModifier(),
4474 arr->getIndexTypeCVRQualifiers());
4476 }
else if (isa<VariableArrayType>(QT.getTypePtr())) {
4477 const VariableArrayType *arr
4478 = dyn_cast<VariableArrayType>(QT.getTypePtr());
4482 if (newQT == arr->getElementType())
return QT;
4483 QT = Ctxt.getVariableArrayType (newQT,
4485 arr->getSizeModifier(),
4486 arr->getIndexTypeCVRQualifiers(),
4487 arr->getBracketsRange());
4491 QT = Ctxt.getQualifiedType(QT, quals);
4496 etype = llvm::dyn_cast<clang::ElaboratedType>(instance);
4498 instance = etype->getNamedType().getTypePtr();
4499 if (!instance)
return input;
4502 const clang::TemplateSpecializationType* TST
4503 = llvm::dyn_cast<
const clang::TemplateSpecializationType>(instance);
4505 if (!TST)
return input;
4507 const clang::ClassTemplateSpecializationDecl* TSTdecl
4508 = llvm::dyn_cast_or_null<const clang::ClassTemplateSpecializationDecl>(instance->getAsCXXRecordDecl());
4510 const clang::SubstTemplateTypeParmType *substType
4511 = llvm::dyn_cast<clang::SubstTemplateTypeParmType>(input.getTypePtr());
4515 const clang::ClassTemplateDecl *replacedCtxt = 0;
4517 const clang::DeclContext *replacedDeclCtxt = substType->getReplacedParameter()->getDecl()->getDeclContext();
4518 const clang::CXXRecordDecl *decl = llvm::dyn_cast<clang::CXXRecordDecl>(replacedDeclCtxt);
4519 unsigned int index = substType->getReplacedParameter()->getIndex();
4522 if (decl->getKind() == clang::Decl::ClassTemplatePartialSpecialization) {
4523 const clang::ClassTemplatePartialSpecializationDecl *spec = llvm::dyn_cast<clang::ClassTemplatePartialSpecializationDecl>(decl);
4525 unsigned int depth = substType->getReplacedParameter()->getDepth();
4527 const TemplateArgument *instanceArgs = spec->getTemplateArgs().data();
4528 unsigned int instanceNArgs = spec->getTemplateArgs().size();
4532 for(
unsigned int A = 0;
A < instanceNArgs; ++
A) {
4534 clang::QualType argQualType = instanceArgs[
A].getAsType();
4536 const clang::TemplateTypeParmType *replacementType;
4538 replacementType = llvm::dyn_cast<clang::TemplateTypeParmType>(argQualType);
4540 if (!replacementType) {
4541 const clang::SubstTemplateTypeParmType *argType
4542 = llvm::dyn_cast<clang::SubstTemplateTypeParmType>(argQualType);
4544 clang::QualType replacementQT = argType->getReplacementType();
4545 replacementType = llvm::dyn_cast<clang::TemplateTypeParmType>(replacementQT);
4548 if (replacementType &&
4549 depth == replacementType->getDepth() &&
4550 index == replacementType->getIndex() )
4557 replacedCtxt = spec->getSpecializedTemplate();
4559 replacedCtxt = decl->getDescribedClassTemplate();
4562 replacedCtxt = llvm::dyn_cast<clang::ClassTemplateDecl>(replacedDeclCtxt);
4565 if (replacedCtxt->getCanonicalDecl() == TSTdecl->getSpecializedTemplate()->getCanonicalDecl()
4567 substType->getReplacedParameter()->getDecl()
4568 == TSTdecl->getSpecializedTemplate ()->getTemplateParameters()->getParam(index))
4570 if ( index >= TST->getNumArgs() ) {
4577 return TST->getArg(index).getAsType();
4582 const clang::TemplateSpecializationType* inputTST
4583 = llvm::dyn_cast<
const clang::TemplateSpecializationType>(input.getTypePtr());
4584 const clang::ASTContext& astCtxt = TSTdecl->getASTContext();
4587 bool mightHaveChanged =
false;
4588 llvm::SmallVector<clang::TemplateArgument, 4> desArgs;
4589 for(clang::TemplateSpecializationType::iterator
I = inputTST->begin(),
E = inputTST->end();
4592 desArgs.push_back(*
I);
4596 clang::QualType SubTy =
I->getAsType();
4598 if (llvm::isa<clang::SubstTemplateTypeParmType>(SubTy)
4599 || llvm::isa<clang::TemplateSpecializationType>(SubTy)) {
4601 mightHaveChanged = SubTy != newSubTy;
4602 if (!newSubTy.isNull()) {
4603 desArgs.push_back(clang::TemplateArgument(newSubTy));
4606 desArgs.push_back(*
I);
4610 if (mightHaveChanged) {
4611 clang::Qualifiers qualifiers = input.getLocalQualifiers();
4612 input = astCtxt.getTemplateSpecializationType(inputTST->getTemplateName(),
4615 inputTST->getCanonicalTypeInternal());
4616 input = astCtxt.getQualifiedType(input, qualifiers);
4628 if ( nArgsToRemove == 0 || name ==
"")
4633 const unsigned int length = name.length();
4635 unsigned int nArgsRemoved=0;
4636 unsigned int nBraces=0;
4638 while (nArgsRemoved!=nArgsToRemove && cur<length){
4640 if (c ==
'<') nBraces++;
4641 if (c ==
'>') nBraces--;
4642 if (c ==
',' && nBraces==1 ) nArgsRemoved++;
4646 name = name.substr(0,cur)+
">";
4656 static const char *stls[] =
4657 {
"any",
"vector",
"list",
"deque",
"map",
"multimap",
"set",
"multiset",
"bitset",
4658 "forward_list",
"unordered_set",
"unordered_multiset",
"unordered_map",
"unordered_multimap",0};
4671 for(
int k=1;stls[k];k++) {
if (type.equals(stls[k]))
return values[k];}
4682 TND = TND->getMostRecentDecl();
4683 while (TND && !(TND->hasAttrs()))
4684 TND = TND->getPreviousDecl();
4696 TD = TD->getMostRecentDecl();
4697 while (TD && !(TD->hasAttrs() && TD->isThisDeclarationADefinition()))
4698 TD = TD->getPreviousDecl();
4707 std::list<std::pair<std::string,bool> >& enclosingNamespaces)
4709 const clang::DeclContext* enclosingNamespaceDeclCtxt = decl.getDeclContext();
4710 if (!enclosingNamespaceDeclCtxt)
return;
4712 const clang::NamespaceDecl* enclosingNamespace =
4713 clang::dyn_cast<clang::NamespaceDecl>(enclosingNamespaceDeclCtxt);
4714 if (!enclosingNamespace)
return;
4716 enclosingNamespaces.push_back(std::make_pair(enclosingNamespace->getNameAsString(),
4717 enclosingNamespace->isInline()));
4727 std::list<std::pair<std::string,bool> >& enclosingNamespaces)
4729 const clang::DeclContext* enclosingNamespaceDeclCtxt = ctxt.getParent ();
4732 if (!enclosingNamespaceDeclCtxt) {
4738 const clang::NamespaceDecl* enclosingNamespace = clang::dyn_cast<clang::NamespaceDecl>(enclosingNamespaceDeclCtxt);
4739 if (!enclosingNamespace)
return;
4742 enclosingNamespaces.push_back(std::make_pair(enclosingNamespace->getNameAsString(),
4743 enclosingNamespace->isInline()));
4754 std::list<std::pair<std::string,unsigned int> >& enclosingSc)
4756 const clang::DeclContext* enclosingDeclCtxt = decl.getDeclContext();
4757 if (!enclosingDeclCtxt)
return 0;
4759 unsigned int scopeType;
4761 if (
auto enclosingNamespacePtr =
4762 clang::dyn_cast<clang::NamespaceDecl>(enclosingDeclCtxt)){
4763 scopeType= enclosingNamespacePtr->isInline() ? 1 : 0;
4764 enclosingSc.push_back(std::make_pair(enclosingNamespacePtr->getNameAsString(),scopeType));
4768 if (
auto enclosingClassPtr =
4769 clang::dyn_cast<clang::RecordDecl>(enclosingDeclCtxt)){
4770 return enclosingClassPtr;
4783 std::string::size_type beginVar = 0;
4784 std::string::size_type endVar = 0;
4785 while ((beginVar = txt.find(
'$', beginVar)) != std::string::npos
4786 && beginVar + 1 < txt.length()) {
4787 std::string::size_type beginVarName = beginVar + 1;
4788 std::string::size_type endVarName = std::string::npos;
4789 if (txt[beginVarName] ==
'(') {
4791 endVarName = txt.find(
')', beginVarName);
4793 if (endVarName == std::string::npos) {
4795 varname, txt.c_str() + beginVar);
4798 endVar = endVarName + 1;
4801 beginVarName = beginVar + 1;
4802 endVarName = beginVarName;
4803 while (isalnum(txt[endVarName]) || txt[endVarName] ==
'_')
4805 endVar = endVarName;
4808 const char* val = getenv(txt.substr(beginVarName,
4809 endVarName - beginVarName).c_str());
4812 txt.replace(beginVar, endVar - beginVar, val);
4813 int lenval = strlen(val);
4814 int delta = lenval - (endVar - beginVar);
4818 beginVar = endVar + 1;
4830 const char* envInclPath = getenv(
"ROOT_INCLUDE_PATH");
4834 std::istringstream envInclPathsStream(envInclPath);
4835 std::string inclPath;
4836 while (std::getline(envInclPathsStream, inclPath,
':')) {
4839 if (!inclPath.empty()) {
4840 clingArgs.push_back(
"-I");
4841 clingArgs.push_back(inclPath);
4852 size_t start_pos = 0;
4857 while((start_pos = str.find(from, start_pos)) != std::string::npos) {
4858 str.replace(start_pos, from.length(), to);
4859 start_pos += to.length();
4860 if (recurse) changed =
true;
4873 static const std::string gPathSeparator (
"\\");
4875 static const std::string gPathSeparator (
"/");
4877 return gPathSeparator;
4884 if (theString.size() < theSubstring.size())
return false;
4885 const unsigned int theSubstringSize = theSubstring.size();
4886 return 0 == theString.compare(theString.size() - theSubstringSize,
4895 if (theString.size() < theSubstring.size())
return false;
4896 const unsigned int theSubstringSize = theSubstring.size();
4897 return 0 == theString.compare(0,
4907 clang::Sema &sema = interp.getSema();
4908 cling::Transaction theTransaction(sema);
4909 std::set<clang::Decl *> addedDecls;
4910 for (
auto decl : decls) {
4912 clang::Decl *ncDecl =
const_cast<clang::Decl *
>(decl);
4913 theTransaction.append(ncDecl);
4915 std::string newFwdDecl;
4916 llvm::raw_string_ostream llvmOstr(newFwdDecl);
4917 interp.forwardDeclare(theTransaction, sema, llvmOstr,
true,
nullptr, ignoreFiles);
4930 std::string& defString)
4942 std::string& defString)
4944 std::list<std::pair<std::string,unsigned int> > enclosingNamespaces;
4947 if (rcdPtr)
return rcdPtr;
4950 static const std::string scopeType [] = {
"namespace ",
"inline namespace ",
"class "};
4952 std::string scopeName;
4953 std::string scopeContent;
4954 unsigned int scopeIndex;
4955 for (
auto const & encScope : enclosingNamespaces){
4956 scopeIndex = encScope.second;
4957 scopeName = encScope.first;
4958 scopeContent =
" { " + defString +
" }";
4959 defString = scopeType[scopeIndex] +
4981 const clang::TemplateParameterList& tmplParamList,
4982 const cling::Interpreter& interpreter)
4984 static const char* paramPackWarning=
"Template parameter pack found: autoload of variadic templates is not supported yet.\n";
4987 for (
auto prmIt = tmplParamList.begin();
4988 prmIt != tmplParamList.end(); prmIt++){
4990 if (prmIt != tmplParamList.begin())
4991 templateArgs +=
", ";
4993 auto nDecl = *prmIt;
4994 std::string typeName;
4996 if(nDecl->isParameterPack ()){
5002 if (llvm::isa<clang::TemplateTypeParmDecl>(nDecl)){
5003 typeName =
"typename " + (*prmIt)->getNameAsString();
5006 else if (
auto nttpd = llvm::dyn_cast<clang::NonTypeTemplateParmDecl>(nDecl)){
5007 auto theType = nttpd->getType();
5010 if (theType.getAsString().find(
"enum") != std::string::npos){
5011 std::string astDump;
5012 llvm::raw_string_ostream ostream(astDump);
5013 nttpd->dump(ostream);
5015 ROOT::TMetaUtils::Warning(0,
"Forward declarations of templates with enums as template parameters. The responsible class is: %s\n", astDump.c_str());
5024 else if (
auto ttpd = llvm::dyn_cast<clang::TemplateTemplateParmDecl>(nDecl)){
5027 std::string astDump;
5028 llvm::raw_string_ostream ostream(astDump);
5029 ttpd->dump(ostream);
5031 ROOT::TMetaUtils::Error(0,
"Cannot reconstruct template template parameter forward declaration for %s\n", astDump.c_str());
5036 templateArgs += typeName;
5047 const cling::Interpreter& interpreter,
5048 std::string& defString)
5050 std::string templatePrefixString;
5051 auto tmplParamList= templDecl.getTemplateParameters();
5052 if (!tmplParamList){
5054 "Cannot extract template parameter list for %s",
5055 templDecl.getNameAsString().c_str());
5062 "Problems with arguments for forward declaration of class %s\n",
5063 templDecl.getNameAsString().c_str());
5066 templatePrefixString =
"template " + templatePrefixString +
" ";
5068 defString = templatePrefixString +
"class " + templDecl.getNameAsString();
5069 if (llvm::isa<clang::TemplateTemplateParmDecl>(&templDecl)) {
5083 std::string& argFwdDecl,
5084 const cling::Interpreter& interpreter,
5085 bool acceptStl=
false)
5093 auto argQualType = arg.getAsType();
5096 while (llvm::isa<clang::PointerType>(argQualType.getTypePtr())) argQualType = argQualType->getPointeeType();
5098 auto argTypePtr = argQualType.getTypePtr();
5101 if (llvm::isa<clang::EnumType>(argTypePtr)){
5106 if (llvm::isa<clang::BuiltinType>(argTypePtr)){
5111 if (llvm::isa<clang::TypedefType>(argTypePtr)){
5112 auto tdTypePtr = llvm::dyn_cast<clang::TypedefType>(argTypePtr);
5117 if (llvm::isa<clang::RecordType>(argQualType)){
5119 auto argRecTypePtr = llvm::cast<clang::RecordType>(argTypePtr);
5120 if (
auto argRecDeclPtr = argRecTypePtr->getDecl()){
5135 const cling::Interpreter& interpreter,
5136 std::string& defString,
5144 if (!recordDecl.getIdentifier())
5148 std::string argsFwdDecl;
5150 if (
auto tmplSpecDeclPtr = llvm::dyn_cast<clang::ClassTemplateSpecializationDecl>(&recordDecl)){
5151 std::string argFwdDecl;
5153 std::cout <<
"Class " << recordDecl.getNameAsString()
5154 <<
" is a template specialisation. Treating its arguments.\n";
5155 for(
auto arg : tmplSpecDeclPtr->getTemplateArgs().asArray()){
5158 std::cout <<
" o Template argument ";
5160 std::cout <<
"successfully treated. Arg fwd decl: " << argFwdDecl << std::endl;
5162 std::cout <<
"could not be treated. Abort fwd declaration generation.\n";
5169 argsFwdDecl+=argFwdDecl;
5173 defString=argsFwdDecl;
5178 if (
auto tmplDeclPtr = tmplSpecDeclPtr->getSpecializedTemplate()){
5181 defString = argsFwdDecl +
"\n" + defString;
5186 defString =
"class " + recordDecl.getNameAsString() +
";";
5187 const clang::RecordDecl* rcd =
EncloseInScopes(recordDecl, defString);
5195 defString = argsFwdDecl +
"\n" + defString;
5206 const cling::Interpreter& interpreter,
5207 std::string& fwdDeclString,
5208 std::unordered_set<std::string>* fwdDeclSetPtr)
5210 std::string buffer = tdnDecl.getNameAsString();
5211 std::string underlyingName;
5212 auto underlyingType = tdnDecl.getUnderlyingType().getCanonicalType();
5213 if (
const clang::TagType* TT
5214 = llvm::dyn_cast<clang::TagType>(underlyingType.getTypePtr())) {
5215 if (clang::NamedDecl* ND = TT->getDecl()) {
5216 if (!ND->getIdentifier()) {
5230 if (underlyingName.find(
">::") != std::string::npos)
5233 buffer=
"typedef "+underlyingName+
" "+buffer+
";";
5245 auto& ctxt = tdnDecl.getASTContext();
5246 auto immediatelyUnderlyingType = underlyingType.getSingleStepDesugaredType(ctxt);
5248 if (
auto underlyingTdnTypePtr = llvm::dyn_cast<clang::TypedefType>(immediatelyUnderlyingType.getTypePtr())){
5249 std::string tdnFwdDecl;
5250 auto underlyingTdnDeclPtr = underlyingTdnTypePtr->getDecl();
5255 if (!fwdDeclSetPtr || fwdDeclSetPtr->insert(tdnFwdDecl).second)
5256 fwdDeclString+=tdnFwdDecl;
5257 }
else if (
auto CXXRcdDeclPtr = immediatelyUnderlyingType->getAsCXXRecordDecl()){
5258 std::string classFwdDecl;
5260 std::cout <<
"Typedef " << tdnDecl.getNameAsString() <<
" hides a class: " 5261 << CXXRcdDeclPtr->getNameAsString() << std::endl;
5270 if (!fwdDeclSetPtr || fwdDeclSetPtr->insert(classFwdDecl).second)
5271 fwdDeclString+=classFwdDecl;
5274 fwdDeclString+=buffer;
5286 std::string& valAsString,
5287 const clang::PrintingPolicy& ppolicy)
5289 auto defArgExprPtr = par.getDefaultArg();
5290 auto& ctxt = par.getASTContext();
5291 if(!defArgExprPtr->isEvaluatable(ctxt)){
5295 auto defArgType = par.getType();
5298 if (defArgType->isBooleanType()){
5300 defArgExprPtr->EvaluateAsBooleanCondition (result,ctxt);
5301 valAsString=std::to_string(result);
5306 if (defArgType->isIntegerType()){
5308 defArgExprPtr->EvaluateAsInt(result,ctxt);
5309 auto uintVal = *result.getRawData();
5310 if (result.isNegative()){
5311 long long int intVal=uintVal*-1;
5312 valAsString=std::to_string(intVal);
5314 valAsString=std::to_string(uintVal);
5321 llvm::raw_string_ostream rso(valAsString);
5322 defArgExprPtr->printPretty(rso,
nullptr,ppolicy);
5323 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<list<classA,allocator>,allocator> result: 0 : not stl container code of cont...
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<number> or bitset<number>
void ShortType(std::string &answer, int mode)
Return the absolute type of typeDesc into the string answ.
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'.
SchemaRuleClassMap_t gReadRules
def split(str)
helpers ------------------------------------------------------------------—
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 GenerateTClassFor(const char *requestedName, const clang::CXXRecordDecl *stlClass, const cling::Interpreter &interp, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt)
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
bool HasValidDataMembers(SchemaRuleMap_t &rule, MembersTypeMap_t &members)
Check if given rule contains references to valid data members.
#define dest(otri, vertexptr)