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" 46 #include "clang/Sema/SemaDiagnostic.h" 48 #include "cling/Interpreter/LookupHelper.h" 49 #include "cling/Interpreter/Transaction.h" 50 #include "cling/Interpreter/Interpreter.h" 51 #include "cling/Utils/AST.h" 53 #include "llvm/Support/Path.h" 54 #include "llvm/Support/FileSystem.h" 57 #include "../../../interpreter/llvm/src/tools/clang/lib/Sema/HackForDefaultTemplateArg.h" 62 namespace TMetaUtils {
66 class TNormalizedCtxtImpl {
67 using DeclsCont_t = TNormalizedCtxt::Config_t::SkipCollection;
73 TypesCont_t fTypeWithAlternative;
74 static TemplPtrIntMap_t fTemplatePtrArgsToKeepMap;
76 TNormalizedCtxtImpl(
const cling::LookupHelper &lh);
78 const Config_t &GetConfig()
const {
return fConfig; }
79 const TypesCont_t &GetTypeWithAlternative()
const {
return fTypeWithAlternative; }
80 void AddTemplAndNargsToKeep(
const clang::ClassTemplateDecl* templ,
unsigned int i);
81 int GetNargsToKeep(
const clang::ClassTemplateDecl* templ)
const;
82 const TemplPtrIntMap_t GetTemplNargsToKeepMap()
const {
return fTemplatePtrArgsToKeepMap; }
83 void keepTypedef(
const cling::LookupHelper &lh,
const char*
name,
84 bool replace =
false);
94 static clang::NestedNameSpecifier* AddDefaultParametersNNS(
const clang::ASTContext& Ctx,
95 clang::NestedNameSpecifier* scope,
96 const cling::Interpreter &interpreter,
100 const clang::Type* scope_type = scope->getAsType();
103 clang::NestedNameSpecifier* outer_scope = scope->getPrefix();
105 outer_scope = AddDefaultParametersNNS(Ctx, outer_scope, interpreter, normCtxt);
108 clang::QualType addDefault =
111 if (addDefault.getTypePtr() != scope_type)
112 return clang::NestedNameSpecifier::Create(Ctx,outer_scope,
114 addDefault.getTypePtr());
121 static bool CheckDefinition(
const clang::CXXRecordDecl *cl,
const clang::CXXRecordDecl *context)
123 if (!cl->hasDefinition()) {
126 "Missing definition for class %s, please #include its header in the header of %s\n",
127 cl->getName().str().c_str(), context->getName().str().c_str());
130 "Missing definition for class %s\n",
131 cl->getName().str().c_str());
143 static clang::NestedNameSpecifier* ReSubstTemplateArgNNS(
const clang::ASTContext &Ctxt,
144 clang::NestedNameSpecifier *scope,
147 if (!scope)
return 0;
149 const clang::Type* scope_type = scope->getAsType();
151 clang::NestedNameSpecifier* outer_scope = scope->getPrefix();
153 outer_scope = ReSubstTemplateArgNNS(Ctxt, outer_scope, instance);
155 clang::QualType substScope =
158 scope = clang::NestedNameSpecifier::Create(Ctxt,outer_scope,
160 substScope.getTypePtr());
169 const clang::BuiltinType * builtin = llvm::dyn_cast<clang::BuiltinType>(type->getCanonicalTypeInternal().getTypePtr());
171 return builtin->isInteger();
179 static bool IsFieldDeclInt(
const clang::FieldDecl *field)
181 return IsTypeInt(field->getType().getTypePtr());
187 static const clang::FieldDecl *GetDataMemberFromAll(
const clang::CXXRecordDecl &cl, llvm::StringRef
what)
189 for(clang::RecordDecl::field_iterator field_iter = cl.field_begin(), end = cl.field_end();
192 if (field_iter->getName() ==
what) {
202 static bool CXXRecordDecl__FindOrdinaryMember(
const clang::CXXBaseSpecifier *Specifier,
203 clang::CXXBasePath &Path,
206 clang::RecordDecl *BaseRecord = Specifier->getType()->getAs<clang::RecordType>()->getDecl();
208 const clang::CXXRecordDecl *clxx = llvm::dyn_cast<clang::CXXRecordDecl>(BaseRecord);
209 if (clxx == 0)
return false;
211 const clang::FieldDecl *found = GetDataMemberFromAll(*clxx,(
const char*)Name);
215 clang::NamedDecl* NonConstFD =
const_cast<clang::FieldDecl*
>(found);
216 clang::NamedDecl** BaseSpecFirstHack
217 =
reinterpret_cast<clang::NamedDecl**
>(NonConstFD);
218 Path.Decls = clang::DeclContextLookupResult(llvm::ArrayRef<clang::NamedDecl*>(BaseSpecFirstHack, 1));
243 static const clang::FieldDecl *GetDataMemberFromAllParents(
const clang::CXXRecordDecl &cl,
const char *what)
245 clang::CXXBasePaths Paths;
246 Paths.setOrigin(const_cast<clang::CXXRecordDecl*>(&cl));
247 if (cl.lookupInBases([=](
const clang::CXXBaseSpecifier *Specifier, clang::CXXBasePath &Path) {
248 return CXXRecordDecl__FindOrdinaryMember(Specifier, Path, what);}, Paths))
250 clang::CXXBasePaths::paths_iterator iter = Paths.begin();
251 if (iter != Paths.end()) {
253 const clang::FieldDecl *found = (clang::FieldDecl *)iter->Decls.data();
261 cling::LookupHelper::DiagSetting ToLHDS(
bool wantDiags) {
263 ? cling::LookupHelper::WithDiagnostics
264 : cling::LookupHelper::NoDiagnostics;
271 namespace TMetaUtils {
277 void TNormalizedCtxtImpl::AddTemplAndNargsToKeep(
const clang::ClassTemplateDecl* templ,
280 Error(
"TNormalizedCtxt::AddTemplAndNargsToKeep",
281 "Tring to specify a number of template arguments to keep for a null pointer. Exiting without assigning any value.\n");
285 const clang::ClassTemplateDecl* canTempl = templ->getCanonicalDecl();
287 if(fTemplatePtrArgsToKeepMap.count(canTempl)==1 &&
288 fTemplatePtrArgsToKeepMap[canTempl]!=(int)i){
289 const std::string templateName (canTempl->getNameAsString());
290 const std::string i_str (std::to_string(i));
291 const std::string previousArgsToKeep(std::to_string(fTemplatePtrArgsToKeepMap[canTempl]));
292 Error(
"TNormalizedCtxt::AddTemplAndNargsToKeep",
293 "Tring to specify for template %s %s arguments to keep, while before this number was %s\n",
294 canTempl->getNameAsString().c_str(),
296 previousArgsToKeep.c_str());
299 fTemplatePtrArgsToKeepMap[canTempl]=i;
306 int TNormalizedCtxtImpl::GetNargsToKeep(
const clang::ClassTemplateDecl* templ)
const{
307 const clang::ClassTemplateDecl* constTempl = templ->getCanonicalDecl();
308 auto thePairPtr = fTemplatePtrArgsToKeepMap.find(constTempl);
309 int nArgsToKeep = (thePairPtr != fTemplatePtrArgsToKeepMap.end() ) ? thePairPtr->second : -1;
317 fImpl(new TNormalizedCtxtImpl(lh))
328 return fImpl->GetConfig();
331 return fImpl->GetTypeWithAlternative();
335 return fImpl->AddTemplAndNargsToKeep(templ, i);
339 return fImpl->GetNargsToKeep(templ);
342 return fImpl->GetTemplNargsToKeepMap();
347 return fImpl->keepTypedef(lh, name, replace);
357 const clang::RecordDecl *decl,
360 bool rRequestNoInputOperator,
361 bool rRequestOnlyTClass,
362 int rRequestedVersionNumber,
363 const cling::Interpreter &interpreter,
365 fRuleIndex(index), fDecl(decl), fRequestStreamerInfo(rStreamerInfo), fRequestNoStreamer(rNoStreamer),
366 fRequestNoInputOperator(rRequestNoInputOperator), fRequestOnlyTClass(rRequestOnlyTClass), fRequestedVersionNumber(rRequestedVersionNumber)
377 const clang::RecordDecl *decl,
378 const char *requestName,
379 unsigned int nTemplateArgsToSkip,
382 bool rRequestNoInputOperator,
383 bool rRequestOnlyTClass,
384 int rRequestVersionNumber,
385 const cling::Interpreter &interpreter,
397 "Could not remove the requested template arguments.\n");
406 const clang::RecordDecl *decl,
407 const char *requestName,
410 bool rRequestNoInputOperator,
411 bool rRequestOnlyTClass,
412 int rRequestVersionNumber,
413 const cling::Interpreter &interpreter,
429 const clang::RecordDecl *decl,
430 const char *requestName,
433 bool rRequestNoInputOperator,
434 bool rRequestOnlyTClass,
435 int rRequestVersionNumber,
436 const cling::Interpreter &interpreter,
447 if (requestName && requestName[0]) {
463 ExistingTypeCheck_t existingTypeCheck,
464 AutoParse_t autoParse,
465 const int* pgDebug ):
466 fInterpreter(&interpreter),fNormalizedCtxt(&normCtxt),
467 fExistingTypeCheck(existingTypeCheck),
468 fAutoParse(autoParse), fPDebug(pgDebug)
479 if (tname.empty())
return false;
489 const cling::LookupHelper& lh =
fInterpreter->getLookupHelper();
490 clang::QualType t = lh.findType(nameLong, ToLHDS(
WantDiags()));
493 if (!dest.isNull() && (dest != t)) {
496 dest.getAsStringInternal(nameLong,
fInterpreter->getCI()->getASTContext().getPrintingPolicy());
504 const std::string &nameLong)
506 const cling::LookupHelper& lh =
fInterpreter->getLookupHelper();
507 clang::QualType t = lh.findType(nondef.c_str(), ToLHDS(
WantDiags()));
510 if (!dest.isNull() && (dest != t) &&
511 nameLong == t.getAsString(
fInterpreter->getCI()->getASTContext().getPrintingPolicy()))
521 const cling::LookupHelper& lh =
fInterpreter->getLookupHelper();
522 const clang::Decl *scope = lh.findScope(base.c_str(), ToLHDS(
WantDiags()), 0);
529 const clang::NamespaceDecl *nsdecl = llvm::dyn_cast<clang::NamespaceDecl>(scope);
530 isInlined = nsdecl && nsdecl->isInline();
541 if (tname.empty())
return false;
549 return ! result.empty();
558 const cling::LookupHelper& lh =
fInterpreter->getLookupHelper();
559 clang::QualType t = lh.findType(tname.c_str(), ToLHDS(
WantDiags()));
566 if (!dest.isNull() && dest != t) {
570 clang::PrintingPolicy policy(
fInterpreter->getCI()->getASTContext().getPrintingPolicy());
571 policy.SuppressTagKeyword =
true;
572 policy.SuppressScope =
true;
578 dest.getAsStringInternal(result, policy);
580 unsigned long offset = 0;
581 if (strncmp(result.c_str(),
"const ", 6) == 0) {
584 if (strncmp(result.c_str()+offset,
"std::", 5) == 0) {
585 result.erase(offset,5);
587 for(
unsigned int i = 1; i<result.length(); ++i) {
588 if (result[i]==
's') {
589 if (result[i-1]==
'<' || result[i-1]==
',' || result[i-1]==
' ') {
590 if (result.compare(i,5,
"std::",5) == 0) {
595 if (result[i]==
' ') {
596 if (result[i-1] ==
',') {
599 }
else if ( (i+1) < result.length() &&
600 (result[i+1]==
'*' || result[i+1]==
'&' || result[i+1]==
'[') ) {
625 void ROOT::TMetaUtils::TNormalizedCtxtImpl::keepTypedef(
const cling::LookupHelper &lh,
628 clang::QualType toSkip = lh.findType(name, cling::LookupHelper::WithDiagnostics);
630 const clang::TypedefType *
tt = llvm::dyn_cast<clang::TypedefType>(
T);
632 clang::Decl* D = tt->getDecl();
633 fConfig.m_toSkip.insert(D);
635 clang::QualType canon = toSkip->getCanonicalTypeInternal();
636 fConfig.m_toReplace.insert(std::make_pair(canon.getTypePtr(),
T));
638 fTypeWithAlternative.insert(
T);
649 ROOT::TMetaUtils::TNormalizedCtxtImpl::TNormalizedCtxtImpl(
const cling::LookupHelper &lh)
651 keepTypedef(lh,
"Double32_t");
652 keepTypedef(lh,
"Float16_t");
653 keepTypedef(lh,
"Long64_t",
true);
654 keepTypedef(lh,
"ULong64_t",
true);
656 clang::QualType toSkip = lh.findType(
"string", cling::LookupHelper::WithDiagnostics);
657 if (
const clang::TypedefType* TT
658 = llvm::dyn_cast_or_null<clang::TypedefType>(toSkip.getTypePtr()))
659 fConfig.m_toSkip.insert(TT->getDecl());
661 toSkip = lh.findType(
"std::string", cling::LookupHelper::WithDiagnostics);
662 if (!toSkip.isNull()) {
663 if (
const clang::TypedefType* TT
664 = llvm::dyn_cast_or_null<clang::TypedefType>(toSkip.getTypePtr()))
665 fConfig.m_toSkip.insert(TT->getDecl());
667 clang::QualType canon = toSkip->getCanonicalTypeInternal();
668 fConfig.m_toReplace.insert(std::make_pair(canon.getTypePtr(),toSkip.getTypePtr()));
673 TNCtxtFullQual::TemplPtrIntMap_t TNCtxtFullQual::fTemplatePtrArgsToKeepMap=TNCtxtFullQual::TemplPtrIntMap_t{};
679 return (cl.getKind() == clang::Decl::ClassTemplatePartialSpecialization
680 || cl.getKind() == clang::Decl::ClassTemplateSpecialization);
687 const cling::Interpreter& interp)
689 clang::Sema*
S = &interp.getSema();
690 const clang::NamedDecl* ND = cling::utils::Lookup::Named(S, name, cl);
691 if (ND == (clang::NamedDecl*)-1)
692 return (clang::FunctionDecl*)-1;
693 return llvm::dyn_cast_or_null<clang::FunctionDecl>(ND);
699 const clang::CXXRecordDecl *
703 const cling::LookupHelper& lh = interp.getLookupHelper();
706 const clang::CXXRecordDecl *
result 707 = llvm::dyn_cast_or_null<clang::CXXRecordDecl>
708 (lh.findScope(name, cling::LookupHelper::NoDiagnostics, resultType));
710 std::string std_name(
"std::");
714 result = llvm::dyn_cast_or_null<clang::CXXRecordDecl>
715 (lh.findScope(std_name, cling::LookupHelper::NoDiagnostics, resultType));
725 clang::QualType qType(cl->getTypeForDecl(),0);
733 clang::Sema&
S = interp.getCI()->getSema();
736 cling::Interpreter::PushTransactionRAII RAII(const_cast<cling::Interpreter*>(&interp));
737 return S.RequireCompleteType(Loc, Type, clang::diag::err_incomplete_type);
743 const clang::CXXRecordDecl *context,
const cling::Interpreter &interp)
749 if (!cl->getDefinition() || !cl->isCompleteDefinition()) {
753 if (!CheckDefinition(cl, context) || !CheckDefinition(base, context)) {
757 if (!base->hasDefinition()) {
761 return cl->isDerivedFrom(base);
773 const clang::NamedDecl *base
777 return IsBase(CRD, llvm::dyn_cast<clang::CXXRecordDecl>( base ),
778 llvm::dyn_cast<clang::CXXRecordDecl>(m.getDeclContext()),interp);
786 const clang::NamedDecl &forcontext,
787 const clang::QualType &qti,
788 const char *R__t,
int rwmode,
789 const cling::Interpreter &interp,
792 static const clang::CXXRecordDecl *TObject_decl
795 kBIT_ISTOBJECT = 0x10000000,
796 kBIT_HASSTREAMER = 0x20000000,
797 kBIT_ISSTRING = 0x40000000,
799 kBIT_ISPOINTER = 0x00001000,
800 kBIT_ISFUNDAMENTAL = 0x00000020,
801 kBIT_ISENUM = 0x00000008
814 clang::CXXRecordDecl *cxxtype = rawtype->getAsCXXRecordDecl() ;
816 int isTObj = cxxtype && (
IsBase(cxxtype,TObject_decl,
nullptr,interp) || rawname ==
"TObject");
820 if (ti.isPointerType()) kase |= kBIT_ISPOINTER;
821 if (rawtype->isFundamentalType()) kase |= kBIT_ISFUNDAMENTAL;
822 if (rawtype->isEnumeralType()) kase |= kBIT_ISENUM;
825 if (isTObj) kase |= kBIT_ISTOBJECT;
826 if (isStre) kase |= kBIT_HASSTREAMER;
827 if (tiName ==
"string") kase |= kBIT_ISSTRING;
828 if (tiName ==
"string*") kase |= kBIT_ISSTRING;
832 tcl =
" internal error in rootcling ";
838 if (R__t) finalString <<
" " << tiName <<
" " << R__t <<
";" << std::endl;
841 case kBIT_ISFUNDAMENTAL:
843 finalString <<
" R__b >> " << R__t <<
";" << std::endl;
846 case kBIT_ISPOINTER|kBIT_ISTOBJECT|kBIT_HASSTREAMER:
848 finalString <<
" " << R__t <<
" = (" << tiName <<
")R__b.ReadObjectAny(" << tcl <<
");" << std::endl;
857 finalString <<
" Int_t readtemp;" << std::endl
858 <<
" R__b >> readtemp;" << std::endl
859 <<
" " << R__t <<
" = static_cast<" << tiName <<
">(readtemp);" << std::endl;
862 case kBIT_HASSTREAMER:
863 case kBIT_HASSTREAMER|kBIT_ISTOBJECT:
865 finalString <<
" " << R__t <<
".Streamer(R__b);" << std::endl;
868 case kBIT_HASSTREAMER|kBIT_ISPOINTER:
871 finalString <<
" if (R__b.GetInfo() && R__b.GetInfo()->GetOldVersion()<=3) {" << std::endl;
872 if (cxxtype && cxxtype->isAbstract()) {
873 finalString <<
" R__ASSERT(0);// " << objType <<
" is abstract. We assume that older file could not be produced using this streaming method." << std::endl;
875 finalString <<
" " << R__t <<
" = new " << objType <<
";" << std::endl
876 <<
" " << R__t <<
"->Streamer(R__b);" << std::endl;
878 finalString <<
" } else {" << std::endl
879 <<
" " << R__t <<
" = (" << tiName <<
")R__b.ReadObjectAny(" << tcl <<
");" << std::endl
880 <<
" }" << std::endl;
885 finalString <<
" {TString R__str;" << std::endl
886 <<
" R__str.Streamer(R__b);" << std::endl
887 <<
" " << R__t <<
" = R__str.Data();}" << std::endl;
890 case kBIT_ISSTRING|kBIT_ISPOINTER:
892 finalString <<
" {TString R__str;" << std::endl
893 <<
" R__str.Streamer(R__b);" << std::endl
894 <<
" " << R__t <<
" = new string(R__str.Data());}" << std::endl;
899 finalString <<
" " << R__t <<
" = (" << tiName <<
")R__b.ReadObjectAny(" << tcl <<
");" << std::endl;
904 finalString <<
" R__b.StreamObject(&" << R__t <<
"," << tcl <<
");" << std::endl;
912 case kBIT_ISFUNDAMENTAL:
913 case kBIT_ISPOINTER|kBIT_ISTOBJECT|kBIT_HASSTREAMER:
915 finalString <<
" R__b << " << R__t <<
";" << std::endl;
920 finalString <<
" { void *ptr_enum = (void*)&" << R__t <<
";\n";
921 finalString <<
" R__b >> *reinterpret_cast<Int_t*>(ptr_enum); }" << std::endl;
924 case kBIT_HASSTREAMER:
925 case kBIT_HASSTREAMER|kBIT_ISTOBJECT:
927 finalString <<
" ((" << objType <<
"&)" << R__t <<
").Streamer(R__b);" << std::endl;
930 case kBIT_HASSTREAMER|kBIT_ISPOINTER:
932 finalString <<
" R__b.WriteObjectAny(" << R__t <<
"," << tcl <<
");" << std::endl;
937 finalString <<
" {TString R__str(" << R__t <<
".c_str());" << std::endl
938 <<
" R__str.Streamer(R__b);};" << std::endl;
941 case kBIT_ISSTRING|kBIT_ISPOINTER:
943 finalString <<
" {TString R__str(" << R__t <<
"->c_str());" << std::endl
944 <<
" R__str.Streamer(R__b);}" << std::endl;
949 finalString <<
" R__b.WriteObjectAny(" << R__t <<
"," << tcl <<
");" << std::endl;
954 finalString <<
" R__b.StreamObject((" << objType <<
"*)&" << R__t <<
"," << tcl <<
");" << std::endl;
965 const cling::Interpreter& interpreter)
967 const char *arg = ioctortype.
GetName();
969 if (ioctortype.
GetType() ==0 && (arg == 0 || arg[0] ==
'\0')) {
971 clang::CXXRecordDecl* ncCl =
const_cast<clang::CXXRecordDecl*
>(cl);
974 cling::Interpreter::PushTransactionRAII clingRAII(const_cast<cling::Interpreter*>(&interpreter));
976 if (
auto* Ctor = interpreter.getCI()->getSema().LookupDefaultConstructor(ncCl)) {
977 if (Ctor->getAccess() == clang::AS_public) {
984 for (clang::CXXRecordDecl::ctor_iterator iter = cl->ctor_begin(), end = cl->ctor_end();
988 if (iter->getAccess() != clang::AS_public)
992 if (iter->getNumParams() == 1) {
993 clang::QualType argType( (*iter->param_begin())->getType() );
994 argType = argType.getDesugaredType(cl->getASTContext());
997 if (argType->isPointerType()) {
999 argType = argType->getPointeeType();
1000 }
else if (argType->isReferenceType()){
1002 argType = argType.getNonReferenceType();
1005 argType = argType.getDesugaredType(cl->getASTContext());
1006 const clang::CXXRecordDecl *argDecl = argType->getAsCXXRecordDecl();
1007 if (argDecl && ioctortype.
GetType()) {
1008 if (argDecl->getCanonicalDecl() == ioctortype.
GetType()->getCanonicalDecl()) {
1009 return ioCtorCategory;
1012 std::string realArg = argType.getAsString();
1013 std::string clarg(
"class ");
1015 if (realArg == clarg) {
1016 return ioCtorCategory;
1031 const char *method,
const char *
proto,
1032 const cling::Interpreter &interp,
1035 const clang::FunctionDecl* funcD
1036 = interp.getLookupHelper().findFunctionProto(cinfo, method, proto,
1037 diagnose ? cling::LookupHelper::WithDiagnostics
1038 : cling::LookupHelper::NoDiagnostics);
1040 return llvm::dyn_cast<
const clang::CXXMethodDecl>(funcD);
1049 namespace TMetaUtils {
1052 const cling::LookupHelper& lh = interp.getLookupHelper();
1055 clang::QualType instanceType = lh.findType(type_of_arg, cling::LookupHelper::WithDiagnostics);
1056 if (!instanceType.isNull())
1057 fArgType = instanceType->getAsCXXRecordDecl();
1071 const cling::Interpreter &interp)
1073 if (cl->isAbstract())
return false;
1075 for (RConstructorTypes::const_iterator ctorTypeIt = ctorTypes.begin();
1076 ctorTypeIt!=ctorTypes.end(); ++ctorTypeIt) {
1083 std::string
proto( ctorTypeIt->GetName() );
1084 bool defaultCtor =
proto.empty();
1096 arg +=
")nullptr )";
1099 const clang::CXXMethodDecl *method
1101 cling::LookupHelper::NoDiagnostics);
1102 if (method && method->getAccess() != clang::AS_public) {
1117 if (!cl)
return false;
1119 if (cl->hasUserDeclaredDestructor()) {
1121 clang::CXXDestructorDecl *
dest = cl->getDestructor();
1123 return (dest->getAccess() == clang::AS_public);
1135 const char *methodname,
1137 const cling::Interpreter &interp,
1140 const clang::CXXMethodDecl *method
1142 diagnose ? cling::LookupHelper::WithDiagnostics
1143 : cling::LookupHelper::NoDiagnostics);
1144 return (method && method->getAccess() == clang::AS_public);
1155 const char *proto =
"TDirectory*";
1156 const char *name =
"DirectoryAutoAdd";
1170 const char *proto =
"TCollection*,TFileMergeInfo*";
1171 const char *name =
"Merge";
1184 const char *proto =
"TCollection*";
1185 const char *name =
"Merge";
1200 const char *proto =
"TFileMergeInfo*";
1201 const char *name =
"ResetAfterMerge";
1211 const clang::CXXRecordDecl* clxx,
1212 const cling::Interpreter &interp,
1215 static const char *proto =
"TBuffer&";
1217 const clang::CXXMethodDecl *method
1219 cling::LookupHelper::NoDiagnostics);
1220 const clang::DeclContext *clxx_as_context = llvm::dyn_cast<clang::DeclContext>(clxx);
1222 return (method && method->getDeclContext() == clxx_as_context
1230 const clang::CXXRecordDecl* clxx,
1231 const cling::Interpreter &interp,
1234 static const char *proto =
"TBuffer&,TClass*";
1236 const clang::CXXMethodDecl *method
1238 cling::LookupHelper::NoDiagnostics);
1239 const clang::DeclContext *clxx_as_context = llvm::dyn_cast<clang::DeclContext>(clxx);
1241 return (method && method->getDeclContext() == clxx_as_context
1271 clang::QualType qualType(&type,0);
1303 llvm::raw_string_ostream stream(qual_name);
1304 clang::PrintingPolicy policy( cl.getASTContext().getPrintingPolicy() );
1305 policy.SuppressTagKeyword =
true;
1306 policy.SuppressUnwrittenScope =
true;
1308 cl.getNameForDiagnostic(stream,policy,
true);
1311 if ( qual_name ==
"(anonymous " ) {
1312 size_t pos = qual_name.find(
':');
1313 qual_name.erase(0,pos+2);
1329 const clang::Type* declType ( recordDecl.getTypeForDecl() );
1330 clang::QualType qualType(declType,0);
1364 std::stringstream dims;
1365 std::string typenameStr;
1367 const clang::ASTContext& astContext = cl.getASTContext();
1370 for(clang::RecordDecl::field_iterator field_iter = cl.field_begin(), end = cl.field_end();
1378 typenameStr.clear();
1382 clang::QualType fieldType(field_iter->getType());
1383 if (fieldType->isConstantArrayType()) {
1384 const clang::ConstantArrayType *arrayType = llvm::dyn_cast<clang::ConstantArrayType>(fieldType.getTypePtr());
1386 dims <<
"[" << arrayType->getSize().getLimitedValue() <<
"]";
1387 fieldType = arrayType->getElementType();
1388 arrayType = llvm::dyn_cast<clang::ConstantArrayType>(arrayType->getArrayElementTypeNoTypeQual());
1398 for(clang::CXXRecordDecl::base_class_const_iterator iter = cl.bases_begin(), end = cl.bases_end();
1401 std::string basename( iter->getType()->getAsCXXRecordDecl()->getNameAsString() );
1411 const cling::Interpreter &interp,
1414 return interp.getLookupHelper().findFunctionProto(cinfo, method, proto,
1415 diagnose ? cling::LookupHelper::WithDiagnostics
1416 : cling::LookupHelper::NoDiagnostics);
1450 clang::SourceLocation sourceLocation = decl->getLocation();
1451 clang::SourceManager& sourceManager = decl->getASTContext().getSourceManager();
1453 if (!sourceLocation.isValid() ) {
1457 if (!sourceLocation.isFileID()) {
1458 sourceLocation = sourceManager.getExpansionRange(sourceLocation).second;
1461 if (sourceLocation.isValid() && sourceLocation.isFileID()) {
1462 return sourceManager.getLineNumber(sourceManager.getFileID(sourceLocation),sourceManager.getFileOffset(sourceLocation));
1475 while (llvm::isa<clang::PointerType>(instanceType.getTypePtr())
1476 || llvm::isa<clang::ReferenceType>(instanceType.getTypePtr()))
1478 instanceType = instanceType->getPointeeType();
1481 const clang::ElaboratedType* etype
1482 = llvm::dyn_cast<clang::ElaboratedType>(instanceType.getTypePtr());
1484 instanceType = clang::QualType(etype->getNamedType().getTypePtr(),0);
1497 const clang::CXXRecordDecl* clxx = instanceType->getAsCXXRecordDecl();
1498 if (clxx && clxx->getTemplateSpecializationKind() != clang::TSK_Undeclared) {
1500 const clang::TemplateSpecializationType* TST
1501 = llvm::dyn_cast<
const clang::TemplateSpecializationType>(instanceType.getTypePtr());
1508 for(clang::TemplateSpecializationType::iterator
1509 I = TST->begin(),
E = TST->end();
1527 const cling::Interpreter &interp,
1530 const clang::CXXRecordDecl* clxx = llvm::dyn_cast<clang::CXXRecordDecl>(cl.
GetRecordDecl());
1531 if (clxx->getTemplateSpecializationKind() == clang::TSK_Undeclared)
return 0;
1533 clang::QualType instanceType = interp.getLookupHelper().findType(cl.
GetNormalizedName(),
1534 cling::LookupHelper::WithDiagnostics);
1535 if (instanceType.isNull()) {
1548 clang::AnnotateAttr* annAttr = clang::dyn_cast<clang::AnnotateAttr>(attribute);
1553 attrString = annAttr->getAnnotation();
1563 if (substrFound==std::string::npos) {
1568 attrName = attributeStr.substr(0, EndPart1);
1570 attrValue = attributeStr.substr(EndPart1 + separatorLength);
1578 std::string attrString;
1580 if (0!=ret)
return ret;
1588 const std::string& propName,
1589 std::string& propValue)
1591 for (clang::Decl::attr_iterator attrIt = decl.attr_begin();
1592 attrIt!=decl.attr_end();++attrIt){
1593 clang::AnnotateAttr* annAttr = clang::dyn_cast<clang::AnnotateAttr>(*attrIt);
1594 if (!annAttr)
continue;
1596 llvm::StringRef attribute = annAttr->getAnnotation();
1597 std::pair<llvm::StringRef,llvm::StringRef> split = attribute.split(
propNames::separator.c_str());
1598 if (split.first != propName.c_str())
continue;
1600 propValue = split.second;
1611 const std::string& propName,
1614 for (clang::Decl::attr_iterator attrIt = decl.attr_begin();
1615 attrIt!=decl.attr_end();++attrIt){
1616 clang::AnnotateAttr* annAttr = clang::dyn_cast<clang::AnnotateAttr>(*attrIt);
1617 if (!annAttr)
continue;
1619 llvm::StringRef attribute = annAttr->getAnnotation();
1620 std::pair<llvm::StringRef,llvm::StringRef> split = attribute.split(
propNames::separator.c_str());
1621 if (split.first != propName.c_str())
continue;
1623 return split.second.getAsInteger(10,propValue);
1634 const clang::CXXRecordDecl *decl,
1635 const cling::Interpreter &interp,
1638 bool& needCollectionProxy)
1642 std::string mappedname;
1644 std::string csymbol = classname;
1652 csymbol.insert(0,
"::");
1659 const cling::LookupHelper& lh = interp.getLookupHelper();
1662 bool isStdNotString = isStd && !isString;
1664 finalString <<
"namespace ROOT {" <<
"\n";
1668 finalString <<
" static TClass *" << mappedname.c_str() <<
"_Dictionary();\n" 1669 <<
" static void " << mappedname.c_str() <<
"_TClassManip(TClass*);\n";
1675 finalString <<
" static void *new_" << mappedname.c_str() <<
"(void *p = 0);" <<
"\n";
1679 finalString <<
" static void *newArray_";
1680 finalString << mappedname.c_str();
1681 finalString <<
"(Long_t size, void *p);";
1682 finalString <<
"\n";
1687 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";
1690 finalString <<
" static void directoryAutoAdd_" << mappedname.c_str() <<
"(void *obj, TDirectory *dir);" <<
"\n";
1693 finalString <<
" static void streamer_" << mappedname.c_str() <<
"(TBuffer &buf, void *obj);" <<
"\n";
1696 finalString <<
" static void conv_streamer_" << mappedname.c_str() <<
"(TBuffer &buf, void *obj, const TClass*);" <<
"\n";
1699 finalString <<
" static Long64_t merge_" << mappedname.c_str() <<
"(void *obj, TCollection *coll,TFileMergeInfo *info);" <<
"\n";
1702 finalString <<
" static void reset_" << mappedname.c_str() <<
"(void *obj, TFileMergeInfo *info);" <<
"\n";
1709 std::string declName;
1711 ROOT::SchemaRuleClassMap_t::iterator rulesIt1 =
ROOT::gReadRules.find( declName.c_str() );
1712 ROOT::SchemaRuleClassMap_t::iterator rulesIt2 =
ROOT::gReadRawRules.find( declName.c_str() );
1723 finalString <<
"\n // Schema evolution read functions\n";
1724 std::list<ROOT::SchemaRuleMap_t>::iterator rIt = rulesIt1->second.begin();
1725 while( rIt != rulesIt1->second.end() ) {
1732 rIt = rulesIt1->second.erase(rIt);
1740 if( rIt->find(
"code" ) != rIt->end() ) {
1756 finalString <<
"\n // Schema evolution read raw functions\n";
1757 std::list<ROOT::SchemaRuleMap_t>::iterator rIt = rulesIt2->second.begin();
1758 while( rIt != rulesIt2->second.end() ) {
1765 rIt = rulesIt2->second.erase(rIt);
1773 if( rIt->find(
"code" ) == rIt->end() )
1781 finalString <<
"\n" <<
" // Function generating the singleton type initializer" <<
"\n";
1783 finalString <<
" static TGenericClassInfo *GenerateInitInstanceLocal(const " << csymbol <<
"*)" <<
"\n" <<
" {" <<
"\n";
1785 finalString <<
" " << csymbol <<
" *ptr = 0;" <<
"\n";
1789 finalString <<
" static ::TVirtualIsAProxy* isa_proxy = new ::TInstrumentedIsAProxy< " << csymbol <<
" >(0);" <<
"\n";
1792 finalString <<
" static ::TVirtualIsAProxy* isa_proxy = new ::TIsAProxy(typeid(" << csymbol <<
"));" <<
"\n";
1794 finalString <<
" static ::ROOT::TGenericClassInfo " <<
"\n" <<
" instance(\"" << classname.c_str() <<
"\", ";
1797 finalString << csymbol <<
"::Class_Version(), ";
1799 finalString <<
"2, ";
1801 finalString <<
"-2, ";
1807 static const char *versionFunc =
"GetClassVersion";
1811 std::string proto = classname +
"*";
1812 const clang::Decl* ctxt = llvm::dyn_cast<clang::Decl>((*cl).getDeclContext());
1813 const clang::FunctionDecl *methodinfo
1815 interp, cling::LookupHelper::NoDiagnostics);
1823 finalString <<
"GetClassVersion< ";
1824 finalString << classname.c_str();
1825 finalString <<
" >(), ";
1833 if (filename.length() > 0) {
1834 for (
unsigned int i=0; i<filename.length(); i++) {
1835 if (filename[i]==
'\\') filename[i]=
'/';
1839 <<
"," <<
"\n" <<
" typeid(" << csymbol
1840 <<
"), ::ROOT::Internal::DefineBehavior(ptr, ptr)," <<
"\n" <<
" ";
1843 finalString <<
"&" << csymbol <<
"::Dictionary, ";
1845 finalString <<
"&" << mappedname <<
"_Dictionary, ";
1849 TClassTable__kHasCustomStreamerMember = 0x10
1854 rootflag = rootflag | TClassTable__kHasCustomStreamerMember;
1856 finalString <<
"isa_proxy, " << rootflag <<
"," <<
"\n" <<
" sizeof(" << csymbol <<
") );" <<
"\n";
1858 finalString <<
" instance.SetNew(&new_" << mappedname.c_str() <<
");" <<
"\n";
1860 finalString <<
" instance.SetNewArray(&newArray_" << mappedname.c_str() <<
");" <<
"\n";
1863 finalString <<
" instance.SetDelete(&delete_" << mappedname.c_str() <<
");" <<
"\n" <<
" instance.SetDeleteArray(&deleteArray_" << mappedname.c_str() <<
");" <<
"\n" <<
" instance.SetDestructor(&destruct_" << mappedname.c_str() <<
");" <<
"\n";
1866 finalString <<
" instance.SetDirectoryAutoAdd(&directoryAutoAdd_" << mappedname.c_str() <<
");" <<
"\n";
1870 finalString <<
" instance.SetStreamerFunc(&streamer_" << mappedname.c_str() <<
");" <<
"\n";
1874 finalString <<
" instance.SetConvStreamerFunc(&conv_streamer_" << mappedname.c_str() <<
");" <<
"\n";
1877 finalString <<
" instance.SetMerge(&merge_" << mappedname.c_str() <<
");" <<
"\n";
1880 finalString <<
" instance.SetResetAfterMerge(&reset_" << mappedname.c_str() <<
");" <<
"\n";
1883 finalString <<
" instance.AdoptCollectionProxyInfo(TCollectionProxyInfo::Generate(TCollectionProxyInfo::" <<
"Pushback" <<
"<Internal::TStdBitsetHelper< " << classname.c_str() <<
" > >()));" <<
"\n";
1885 needCollectionProxy =
true;
1886 }
else if (stl != 0 &&
1889 int idx = classname.find(
"<");
1890 int stlType = (idx!=(int)std::string::npos) ?
TClassEdit::STLKind(classname.substr(0,idx).c_str()) : 0;
1891 const char* methodTCP=0;
1896 methodTCP=
"Pushback";
1899 methodTCP=
"Pushfront";
1905 methodTCP=
"MapInsert";
1914 finalString <<
" instance.AdoptCollectionProxyInfo(TCollectionProxyInfo::Generate(TCollectionProxyInfo::" << methodTCP <<
"< " << classname.c_str() <<
" >()));" <<
"\n";
1916 needCollectionProxy =
true;
1924 finalString <<
"\n" <<
" ::ROOT::AddClassAlternate(\"" 1933 finalString <<
"\n" <<
" ROOT::Internal::TSchemaHelper* rule;" <<
"\n";
1937 finalString <<
"\n" <<
" // the io read rules" <<
"\n" <<
" std::vector<ROOT::Internal::TSchemaHelper> readrules(" << rulesIt1->second.size() <<
");" <<
"\n";
1939 finalString <<
" instance.SetReadRules( readrules );" <<
"\n";
1943 finalString <<
"\n" <<
" // the io read raw rules" <<
"\n" <<
" std::vector<ROOT::Internal::TSchemaHelper> readrawrules(" << rulesIt2->second.size() <<
");" <<
"\n";
1945 finalString <<
" instance.SetReadRawRules( readrawrules );" <<
"\n";
1948 finalString <<
" return &instance;" <<
"\n" <<
" }" <<
"\n";
1952 finalString <<
" TGenericClassInfo *GenerateInitInstance(const " << csymbol <<
"*)" <<
"\n" <<
" {\n return GenerateInitInstanceLocal((" << csymbol <<
"*)0);\n }" <<
"\n";
1955 finalString <<
" // Static variable to force the class initialization" <<
"\n";
1959 finalString <<
" static ::ROOT::TGenericClassInfo *_R__UNIQUE_(Init) = GenerateInitInstanceLocal((const " << csymbol <<
"*)0x0); R__UseDummy(_R__UNIQUE_(Init));" <<
"\n";
1962 finalString <<
"\n" <<
" // Dictionary for non-ClassDef classes" <<
"\n" 1963 <<
" static TClass *" << mappedname <<
"_Dictionary() {\n" 1964 <<
" TClass* theClass =" 1965 <<
"::ROOT::GenerateInitInstanceLocal((const " << csymbol <<
"*)0x0)->GetClass();\n" 1966 <<
" " << mappedname <<
"_TClassManip(theClass);\n";
1967 finalString <<
" return theClass;\n";
1968 finalString <<
" }\n\n";
1972 std::string manipString;
1973 std::string attribute_s;
1974 std::string attrName, attrValue;
1976 bool attrMapExtracted =
false;
1977 if (decl->hasAttrs()){
1979 for (clang::Decl::attr_iterator attrIt = decl->attr_begin();
1980 attrIt!=decl->attr_end();++attrIt){
1987 if (attrName ==
"name" ||
1988 attrName ==
"pattern" ||
1989 attrName ==
"rootmap")
continue;
1995 if (!attrMapExtracted){
1996 manipString+=
" theClass->CreateAttributeMap();\n";
1997 manipString+=
" TDictAttributeMap* attrMap( theClass->GetAttributeMap() );\n";
1998 attrMapExtracted=
true;
2000 manipString+=
" attrMap->AddProperty(\""+attrName +
"\",\""+attrValue+
"\");\n";
2006 for(clang::CXXRecordDecl::decl_iterator internalDeclIt = decl->decls_begin();
2007 internalDeclIt != decl->decls_end(); ++internalDeclIt){
2008 if (!(!(*internalDeclIt)->isImplicit()
2009 && (clang::isa<clang::FieldDecl>(*internalDeclIt) ||
2010 clang::isa<clang::VarDecl>(*internalDeclIt))))
continue;
2013 if (!internalDeclIt->hasAttrs())
continue;
2015 attrMapExtracted =
false;
2016 bool memberPtrCreated =
false;
2018 for (clang::Decl::attr_iterator attrIt = internalDeclIt->attr_begin();
2019 attrIt!=internalDeclIt->attr_end();++attrIt){
2027 clang::NamedDecl* namedInternalDecl = clang::dyn_cast<clang::NamedDecl> (*internalDeclIt);
2028 if (!namedInternalDecl) {
2032 const std::string memberName(namedInternalDecl->getName());
2033 const std::string cppMemberName=
"theMember_"+memberName;
2036 const std::string dataMemberCreation=
" TDataMember* "+cppMemberName+
" = theClass->GetDataMember(\""+memberName+
"\");\n";
2049 if (!memberPtrCreated){
2050 manipString+=dataMemberCreation;
2051 memberPtrCreated=
true;
2054 if (!attrMapExtracted){
2055 manipString+=
" "+cppMemberName+
"->CreateAttributeMap();\n";
2056 manipString+=
" TDictAttributeMap* memberAttrMap_"+memberName+
"( theMember_"+memberName+
"->GetAttributeMap() );\n";
2057 attrMapExtracted=
true;
2060 manipString+=
" memberAttrMap_"+memberName+
"->AddProperty(\""+attrName +
"\",\""+attrValue+
"\");\n";
2067 finalString <<
" static void " << mappedname <<
"_TClassManip(TClass* " << (manipString.empty() ?
"":
"theClass") <<
"){\n" 2072 finalString <<
"} // end of namespace ROOT" <<
"\n" <<
"\n";
2082 std::string &clsname,
2083 std::string &nsname,
2084 const clang::CXXRecordDecl *cl)
2094 auto ctxt = cl->getEnclosingNamespaceContext();
2095 while(ctxt && ctxt!=cl && ctxt->isInlineNamespace()) {
2096 ctxt = ctxt->getParent();
2099 const clang::NamedDecl *namedCtxt = llvm::dyn_cast<clang::NamedDecl>(ctxt);
2100 if (namedCtxt && namedCtxt!=cl) {
2101 const clang::NamespaceDecl *nsdecl = llvm::dyn_cast<clang::NamespaceDecl>(namedCtxt);
2102 if (nsdecl != 0 && !nsdecl->isAnonymousNamespace()) {
2104 clsname.erase (0, nsname.size() + 2);
2116 const clang::DeclContext *ctxt = cl.getDeclContext();
2117 while(ctxt && !ctxt->isNamespace()) {
2118 ctxt = ctxt->getParent();
2132 int closing_brackets = 0;
2136 if (ctxt && ctxt->isNamespace()) {
2141 const clang::NamespaceDecl *ns = llvm::dyn_cast<clang::NamespaceDecl>(ctxt);
2144 out <<
"namespace " << ns->getNameAsString() <<
" {" << std::endl;
2148 return closing_brackets;
2162 clang::TemplateSpecializationKind kind = cl->getTemplateSpecializationKind();
2163 if (kind == clang::TSK_Undeclared ) {
2166 }
else if (kind == clang::TSK_ExplicitSpecialization) {
2180 const char *name = which;
2181 const char *proto =
"size_t";
2182 const char *protoPlacement =
"size_t,void*";
2185 const clang::FunctionDecl *operatornew
2187 name, proto, interp,
2188 cling::LookupHelper::NoDiagnostics);
2189 const clang::FunctionDecl *operatornewPlacement
2191 name, protoPlacement, interp,
2192 cling::LookupHelper::NoDiagnostics);
2194 const clang::DeclContext *ctxtnew = 0;
2195 const clang::DeclContext *ctxtnewPlacement = 0;
2198 ctxtnew = operatornew->getParent();
2200 if (operatornewPlacement) {
2201 ctxtnewPlacement = operatornewPlacement->getParent();
2207 operatornewPlacement
2212 ctxtnew = operatornew->getParent();
2214 if (operatornewPlacement) {
2215 ctxtnewPlacement = operatornewPlacement->getParent();
2218 if (ctxtnewPlacement == 0) {
2226 if (ctxtnew == ctxtnewPlacement) {
2230 const clang::CXXRecordDecl* clnew = llvm::dyn_cast<clang::CXXRecordDecl>(ctxtnew);
2231 const clang::CXXRecordDecl* clnewPlacement = llvm::dyn_cast<clang::CXXRecordDecl>(ctxtnewPlacement);
2232 if (clnew == 0 && clnewPlacement == 0) {
2238 if (clnew != 0 && clnewPlacement == 0) {
2242 if (clnew == 0 && clnewPlacement != 0) {
2247 if (clnew->isDerivedFrom(clnewPlacement)) {
2277 const clang::CXXRecordDecl *decl,
2278 const cling::Interpreter &interp,
2284 std::string mappedname;
2302 classname.insert(0,
"::");
2305 finalString <<
"namespace ROOT {" <<
"\n";
2310 finalString <<
" // Wrappers around operator new" <<
"\n";
2311 finalString <<
" static void *new_" << mappedname.c_str() <<
"(void *p) {" <<
"\n" <<
" return p ? ";
2313 finalString <<
"new(p) ";
2314 finalString << classname.c_str();
2315 finalString << args;
2316 finalString <<
" : ";
2318 finalString <<
"::new((::ROOT::Internal::TOperatorNewHelper*)p) ";
2319 finalString << classname.c_str();
2320 finalString << args;
2321 finalString <<
" : ";
2323 finalString <<
"new " << classname.c_str() << args <<
";" <<
"\n";
2324 finalString <<
" }" <<
"\n";
2328 finalString <<
" static void *newArray_";
2329 finalString << mappedname.c_str();
2330 finalString <<
"(Long_t nElements, void *p) {";
2331 finalString <<
"\n";
2332 finalString <<
" return p ? ";
2334 finalString <<
"new(p) ";
2335 finalString << classname.c_str();
2336 finalString <<
"[nElements] : ";
2338 finalString <<
"::new((::ROOT::Internal::TOperatorNewHelper*)p) ";
2339 finalString << classname.c_str();
2340 finalString <<
"[nElements] : ";
2342 finalString <<
"new ";
2343 finalString << classname.c_str();
2344 finalString <<
"[nElements];";
2345 finalString <<
"\n";
2346 finalString <<
" }";
2347 finalString <<
"\n";
2352 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";
2356 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";
2360 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";
2364 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";
2368 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";
2370 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";
2374 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";
2376 finalString <<
"} // end of namespace ROOT for class " << classname.c_str() <<
"\n" <<
"\n";
2383 const cling::Interpreter &interp,
2390 if (version == 0)
return;
2394 const clang::CXXRecordDecl *clxx = llvm::dyn_cast<clang::CXXRecordDecl>(cl.
GetRecordDecl());
2395 if (clxx == 0)
return;
2398 for(clang::CXXRecordDecl::base_class_const_iterator iter = clxx->bases_begin(), end = clxx->bases_end();
2409 for(clang::RecordDecl::field_iterator field_iter = clxx->field_begin(), end = clxx->field_end();
2413 std::string mTypename;
2419 if (!strcmp(shortTypeName,
"string")) {
2441 const clang::Type *rawtype = m.getType()->getCanonicalTypeInternal().getTypePtr();
2442 if (rawtype->isArrayType()) {
2443 rawtype = rawtype->getBaseElementTypeUnsafe ();
2457 const clang::CXXRecordDecl* CRD = llvm::dyn_cast<clang::CXXRecordDecl>(cl);
2465 if (!funcCV)
return -1;
2467 if (funcCV == (clang::FunctionDecl*)-1)
return 1;
2469 const clang::CompoundStmt* FuncBody
2470 = llvm::dyn_cast_or_null<clang::CompoundStmt>(funcCV->getBody());
2471 if (!FuncBody)
return -1;
2472 if (FuncBody->size() != 1) {
2478 const clang::ReturnStmt* RetStmt
2479 = llvm::dyn_cast<clang::ReturnStmt>(FuncBody->body_back());
2480 if (!RetStmt)
return -1;
2481 const clang::Expr* RetExpr = RetStmt->getRetValue();
2487 llvm::APSInt RetRes;
2488 if (!RetExpr->isIntegerConstantExpr(RetRes, funcCV->getASTContext()))
2490 if (RetRes.isSigned()) {
2491 return (
Version_t)RetRes.getSExtValue();
2494 return (
Version_t)RetRes.getZExtValue();
2510 clang::QualType type = m.getType();
2522 clang::QualType type = base.getType();
2537 static char t[4096];
2538 static const char* constwd =
"const ";
2539 static const char* constwdend =
"const";
2544 for (s=typeDesc;*s;s++) {
2547 if (lev==0 && *s==
'*')
continue;
2548 if (lev==0 && (strncmp(constwd,s,strlen(constwd))==0
2549 ||strcmp(constwdend,s)==0 ) ) {
2550 s+=strlen(constwd)-1;
2553 if (lev==0 && *s==
' ' && *(s+1)!=
'*') { p = t;
continue;}
2554 if (p - t > (
long)
sizeof(t)) {
2555 printf(
"ERROR (rootcling): type name too long for StortTypeName: %s\n",
2568 const cling::Interpreter& interp)
2573 if (comment[0] ==
'!')
return false;
2575 clang::QualType type = m.getType();
2577 if (type->isReferenceType()) {
2582 std::string mTypeName = type.getAsString(m.getASTContext().getPrintingPolicy());
2583 if (!strcmp(mTypeName.c_str(),
"string") || !strcmp(mTypeName.c_str(),
"string*")) {
2586 if (!strcmp(mTypeName.c_str(),
"std::string") || !strcmp(mTypeName.c_str(),
"std::string*")) {
2594 const clang::Type *rawtype = type.getTypePtr()->getBaseElementTypeUnsafe ();
2596 if (rawtype->isPointerType()) {
2598 clang::QualType pointee;
2599 while ( (pointee = rawtype->getPointeeType()) , pointee.getTypePtrOrNull() && pointee.getTypePtr() != rawtype)
2601 rawtype = pointee.getTypePtr();
2605 if (rawtype->isFundamentalType() || rawtype->isEnumeralType()) {
2610 const clang::CXXRecordDecl *cxxdecl = rawtype->getAsCXXRecordDecl();
2614 if (version > 0)
return true;
2627 const clang::Type *rawtype = m.getType().getTypePtr();
2630 clang::QualType pointee;
2631 while ( rawtype->isPointerType() && ((pointee = rawtype->getPointeeType()) , pointee.getTypePtrOrNull()) && pointee.getTypePtr() != rawtype)
2633 rawtype = pointee.getTypePtr();
2647 if (rawtype->isFundamentalType() || rawtype->isEnumeralType()) {
2651 return rawtype->getAsCXXRecordDecl();
2660 const cling::Interpreter &interp,
2662 std::ostream& dictStream,
2664 bool isGenreflex=
false)
2666 const clang::CXXRecordDecl* decl = llvm::dyn_cast<clang::CXXRecordDecl>(cl.
GetRecordDecl());
2668 if (!decl || !decl->isCompleteDefinition()) {
2672 std::string fullname;
2684 (*WriteStreamerFunc)(cl, interp, normCtxt, dictStream, isGenreflex || cl.RequestStreamerInfo());
2686 ROOT::TMetaUtils::Info(0,
"Class %s: Do not generate Streamer() [*** custom streamer ***]\n",fullname.c_str());
2708 const cling::Interpreter &interpreter,
2711 const clang::ASTContext& Ctx = interpreter.getCI()->getASTContext();
2713 clang::QualType originalType = instanceType;
2717 if (llvm::isa<clang::PointerType>(instanceType.getTypePtr())) {
2719 clang::Qualifiers quals = instanceType.getQualifiers();
2720 clang::QualType newPointee =
AddDefaultParameters(instanceType->getPointeeType(), interpreter, normCtxt);
2721 if (newPointee != instanceType->getPointeeType()) {
2722 instanceType = Ctx.getPointerType(newPointee);
2724 instanceType = Ctx.getQualifiedType(instanceType, quals);
2726 return instanceType;
2731 if (llvm::isa<clang::ReferenceType>(instanceType.getTypePtr())) {
2733 bool isLValueRefTy = llvm::isa<clang::LValueReferenceType>(instanceType.getTypePtr());
2734 clang::Qualifiers quals = instanceType.getQualifiers();
2735 clang::QualType newPointee =
AddDefaultParameters(instanceType->getPointeeType(), interpreter, normCtxt);
2737 if (newPointee != instanceType->getPointeeType()) {
2740 instanceType = Ctx.getLValueReferenceType(newPointee);
2742 instanceType = Ctx.getRValueReferenceType(newPointee);
2744 instanceType = Ctx.getQualifiedType(instanceType, quals);
2746 return instanceType;
2750 bool prefix_changed =
false;
2751 clang::NestedNameSpecifier* prefix = 0;
2752 clang::Qualifiers prefix_qualifiers = instanceType.getLocalQualifiers();
2753 const clang::ElaboratedType* etype
2754 = llvm::dyn_cast<clang::ElaboratedType>(instanceType.getTypePtr());
2757 prefix = AddDefaultParametersNNS(Ctx, etype->getQualifier(), interpreter, normCtxt);
2758 prefix_changed = prefix != etype->getQualifier();
2759 instanceType = clang::QualType(etype->getNamedType().getTypePtr(),0);
2765 const clang::TemplateSpecializationType* TST
2766 = llvm::dyn_cast<
const clang::TemplateSpecializationType>(instanceType.getTypePtr());
2768 const clang::ClassTemplateSpecializationDecl* TSTdecl
2769 = llvm::dyn_cast_or_null<const clang::ClassTemplateSpecializationDecl>(instanceType.getTypePtr()->getAsCXXRecordDecl());
2781 bool mightHaveChanged =
false;
2782 if (TST && TSTdecl) {
2784 clang::Sema&
S = interpreter.getCI()->getSema();
2785 clang::TemplateDecl *Template = TSTdecl->getSpecializedTemplate()->getMostRecentDecl();
2786 clang::TemplateParameterList *Params = Template->getTemplateParameters();
2787 clang::TemplateParameterList::iterator Param = Params->begin();
2791 unsigned int dropDefault = normCtxt.
GetConfig().DropDefaultArg(*Template);
2793 llvm::SmallVector<clang::TemplateArgument, 4> desArgs;
2794 unsigned int Idecl = 0, Edecl = TSTdecl->getTemplateArgs().size();
2795 unsigned int maxAddArg = TSTdecl->getTemplateArgs().size() - dropDefault;
2796 for(clang::TemplateSpecializationType::iterator
2797 I = TST->begin(),
E = TST->end();
2799 I!=
E ? ++
I : 0, ++Idecl, ++Param) {
2803 if (
I->getKind() == clang::TemplateArgument::Template) {
2804 clang::TemplateName templateName =
I->getAsTemplate();
2805 clang::TemplateDecl* templateDecl = templateName.getAsTemplateDecl();
2807 clang::DeclContext* declCtxt = templateDecl->getDeclContext();
2809 if (declCtxt && !templateName.getAsQualifiedTemplateName()){
2810 clang::NamespaceDecl* ns = clang::dyn_cast<clang::NamespaceDecl>(declCtxt);
2811 clang::NestedNameSpecifier* nns;
2813 nns = cling::utils::TypeName::CreateNestedNameSpecifier(Ctx, ns);
2814 }
else if (clang::TagDecl* TD = llvm::dyn_cast<clang::TagDecl>(declCtxt)) {
2815 nns = cling::utils::TypeName::CreateNestedNameSpecifier(Ctx,TD,
false );
2818 desArgs.push_back(*
I);
2821 clang::TemplateName templateNameWithNSS ( Ctx.getQualifiedTemplateName(nns,
false, templateDecl) );
2822 desArgs.push_back(clang::TemplateArgument(templateNameWithNSS));
2823 mightHaveChanged =
true;
2830 desArgs.push_back(*
I);
2834 clang::QualType SubTy =
I->getAsType();
2843 if (SubTy != newSubTy) {
2844 mightHaveChanged =
true;
2845 desArgs.push_back(clang::TemplateArgument(newSubTy));
2847 desArgs.push_back(*
I);
2850 }
else if (!isStdDropDefault && Idecl < maxAddArg) {
2852 mightHaveChanged =
true;
2854 const clang::TemplateArgument& templateArg
2855 = TSTdecl->getTemplateArgs().get(Idecl);
2857 desArgs.push_back(templateArg);
2860 clang::QualType SubTy = templateArg.getAsType();
2862 clang::SourceLocation TemplateLoc = Template->getSourceRange ().getBegin();
2863 clang::SourceLocation RAngleLoc = TSTdecl->getSourceRange().getBegin();
2865 clang::TemplateTypeParmDecl *TTP = llvm::dyn_cast<clang::TemplateTypeParmDecl>(*Param);
2868 cling::Interpreter::PushTransactionRAII clingRAII(const_cast<cling::Interpreter*>(&interpreter));
2869 clang::sema::HackForDefaultTemplateArg raii;
2870 bool HasDefaultArgs;
2871 clang::TemplateArgumentLoc ArgType = S.SubstDefaultTemplateArgumentIfAvailable(
2880 if (ArgType.getArgument().isNull()
2883 "Template parameter substitution failed for %s around %s",
2884 instanceType.getAsString().c_str(),
2885 SubTy.getAsString().c_str()
2889 clang::QualType BetterSubTy = ArgType.getArgument().getAsType();
2890 SubTy = cling::utils::Transform::GetPartiallyDesugaredType(Ctx,BetterSubTy,normCtxt.
GetConfig(),
true);
2893 desArgs.push_back(clang::TemplateArgument(SubTy));
2902 if (mightHaveChanged) {
2903 instanceType = Ctx.getTemplateSpecializationType(TST->getTemplateName(),
2906 TST->getCanonicalTypeInternal());
2910 if (!prefix_changed && !mightHaveChanged)
return originalType;
2912 instanceType = Ctx.getElaboratedType(clang::ETK_None,prefix,instanceType);
2913 instanceType = Ctx.getQualifiedType(instanceType,prefix_qualifiers);
2915 return instanceType;
2935 llvm::StringRef title;
2938 if (clang::AnnotateAttr *
A = m.getAttr<clang::AnnotateAttr>())
2939 title =
A->getAnnotation();
2951 if (errnum) *errnum =
VALID;
2953 if (title.size() == 0 || (title[0] !=
'['))
return llvm::StringRef();
2954 size_t rightbracket = title.find(
']');
2955 if (rightbracket == llvm::StringRef::npos)
return llvm::StringRef();
2957 std::string working;
2958 llvm::StringRef indexvar(title.data()+1,rightbracket-1);
2965 size_t indexvarlen = indexvar.size();
2966 for ( i=0; i<indexvarlen; i++) {
2967 if (!isspace(indexvar[i])) {
2968 working += indexvar[i];
2973 const char *tokenlist =
"*+-";
2974 char *current =
const_cast<char*
>(working.c_str());
2975 current = strtok(current,tokenlist);
2977 while (current!=0) {
2979 if (isdigit(current[0])) {
2980 for(i=0;i<strlen(current);i++) {
2981 if (!isdigit(current[0])) {
2986 if (errstr) *errstr = current;
2987 if (errnum) *errnum =
NOT_INT;
2988 return llvm::StringRef();
2994 const clang::CXXRecordDecl *parent_clxx = llvm::dyn_cast<clang::CXXRecordDecl>(m.getDeclContext());
2995 const clang::FieldDecl *index1 = 0;
2997 index1 = GetDataMemberFromAll(*parent_clxx, current );
2999 if ( IsFieldDeclInt(index1) ) {
3005 for(clang::RecordDecl::field_iterator field_iter = parent_clxx->field_begin(), end = parent_clxx->field_end();
3009 if ( field_iter->getNameAsString() == m.getNameAsString() ) {
3015 if (errstr) *errstr = current;
3016 if (errnum) *errnum =
NOT_DEF;
3017 return llvm::StringRef();
3019 if ( field_iter->getNameAsString() == index1->getNameAsString() ) {
3027 if (errstr) *errstr = current;
3028 if (errnum) *errnum =
NOT_INT;
3029 return llvm::StringRef();
3034 index1 = GetDataMemberFromAllParents( *parent_clxx, current );
3036 if ( IsFieldDeclInt(index1) ) {
3043 if (errnum) *errnum =
NOT_INT;
3044 if (errstr) *errstr = current;
3048 if (errnum) *errnum =
NOT_INT;
3049 if (errstr) *errstr = current;
3050 return llvm::StringRef();
3052 if ( found && (index1->getAccess() == clang::AS_private) ) {
3055 if (errstr) *errstr = current;
3057 return llvm::StringRef();
3064 if (errstr) *errstr = indexvar;
3065 if (errnum) *errnum =
UNKNOWN;
3066 return llvm::StringRef();
3071 current = strtok(0,tokenlist);
3084 out.resize(strlen(in)*2);
3085 unsigned int i=0,j=0,
c;
3087 if (out.capacity() < (j+3)) {
3091 case '+': strcpy(const_cast<char*>(out.data())+j,
"pL"); j+=2;
break;
3092 case '-': strcpy(const_cast<char*>(out.data())+j,
"mI"); j+=2;
break;
3093 case '*': strcpy(const_cast<char*>(out.data())+j,
"mU"); j+=2;
break;
3094 case '/': strcpy(const_cast<char*>(out.data())+j,
"dI"); j+=2;
break;
3095 case '&': strcpy(const_cast<char*>(out.data())+j,
"aN"); j+=2;
break;
3096 case '%': strcpy(const_cast<char*>(out.data())+j,
"pE"); j+=2;
break;
3097 case '|': strcpy(const_cast<char*>(out.data())+j,
"oR"); j+=2;
break;
3098 case '^': strcpy(const_cast<char*>(out.data())+j,
"hA"); j+=2;
break;
3099 case '>': strcpy(const_cast<char*>(out.data())+j,
"gR"); j+=2;
break;
3100 case '<': strcpy(const_cast<char*>(out.data())+j,
"lE"); j+=2;
break;
3101 case '=': strcpy(const_cast<char*>(out.data())+j,
"eQ"); j+=2;
break;
3102 case '~': strcpy(const_cast<char*>(out.data())+j,
"wA"); j+=2;
break;
3103 case '.': strcpy(const_cast<char*>(out.data())+j,
"dO"); j+=2;
break;
3104 case '(': strcpy(const_cast<char*>(out.data())+j,
"oP"); j+=2;
break;
3105 case ')': strcpy(const_cast<char*>(out.data())+j,
"cP"); j+=2;
break;
3106 case '[': strcpy(const_cast<char*>(out.data())+j,
"oB"); j+=2;
break;
3107 case ']': strcpy(const_cast<char*>(out.data())+j,
"cB"); j+=2;
break;
3108 case '!': strcpy(const_cast<char*>(out.data())+j,
"nO"); j+=2;
break;
3109 case ',': strcpy(const_cast<char*>(out.data())+j,
"cO"); j+=2;
break;
3110 case '$': strcpy(const_cast<char*>(out.data())+j,
"dA"); j+=2;
break;
3111 case ' ': strcpy(const_cast<char*>(out.data())+j,
"sP"); j+=2;
break;
3112 case ':': strcpy(const_cast<char*>(out.data())+j,
"cL"); j+=2;
break;
3113 case '"': strcpy(const_cast<char*>(out.data())+j,
"dQ"); j+=2;
break;
3114 case '@': strcpy(const_cast<char*>(out.data())+j,
"aT"); j+=2;
break;
3115 case '\'': strcpy(const_cast<char*>(out.data())+j,
"sQ"); j+=2;
break;
3116 case '\\': strcpy(const_cast<char*>(out.data())+j,
"fI"); j+=2;
break;
3117 default: out[j++]=
c;
break;
3124 std::size_t firstNonNumber = out.find_first_not_of(
"0123456789");
3125 out.replace(0,firstNonNumber,
"");
3130 static clang::SourceLocation
3132 clang::SourceLocation sourceLoc) {
3134 if (!sourceLoc.isFileID()) {
3135 return sourceManager.getExpansionRange(sourceLoc).second;
3144 const cling::Interpreter& interp)
3174 using namespace clang;
3175 SourceLocation headerLoc = decl.getLocation();
3177 static const char invalidFilename[] =
"";
3178 if (!headerLoc.isValid())
return invalidFilename;
3180 HeaderSearch& HdrSearch = interp.getCI()->getPreprocessor().getHeaderSearchInfo();
3182 SourceManager& sourceManager = decl.getASTContext().getSourceManager();
3184 FileID headerFID = sourceManager.getFileID(headerLoc);
3185 SourceLocation includeLoc
3187 sourceManager.getIncludeLoc(headerFID));
3189 const FileEntry *headerFE = sourceManager.getFileEntryForID(headerFID);
3190 while (includeLoc.isValid() && sourceManager.isInSystemHeader(includeLoc)) {
3191 const DirectoryLookup *foundDir = 0;
3194 const FileEntry *FEhdr
3195 = HdrSearch.LookupFile(llvm::sys::path::filename(headerFE->getName()),
3198 ArrayRef<std::pair<const FileEntry *, const DirectoryEntry *>>(),
3205 headerFID = sourceManager.getFileID(includeLoc);
3206 headerFE = sourceManager.getFileEntryForID(headerFID);
3208 sourceManager.getIncludeLoc(headerFID));
3211 if (!headerFE)
return invalidFilename;
3212 llvm::StringRef headerFileName = headerFE->getName();
3223 bool isAbsolute = llvm::sys::path::is_absolute(headerFileName);
3224 const FileEntry* FELong = 0;
3226 for (llvm::sys::path::const_iterator
3227 IDir = llvm::sys::path::begin(headerFileName),
3228 EDir = llvm::sys::path::end(headerFileName);
3229 !FELong && IDir != EDir; ++IDir) {
3235 size_t lenTrailing = headerFileName.size() - (IDir->data() - headerFileName.data());
3236 llvm::StringRef trailingPart(IDir->data(), lenTrailing);
3237 assert(trailingPart.data() + trailingPart.size()
3238 == headerFileName.data() + headerFileName.size()
3239 &&
"Mismatched partitioning of file name!");
3240 const DirectoryLookup* FoundDir = 0;
3241 FELong = HdrSearch.LookupFile(trailingPart, SourceLocation(),
3243 ArrayRef<std::pair<const FileEntry *, const DirectoryEntry *>>(),
3250 return invalidFilename;
3254 for (llvm::sys::path::reverse_iterator
3255 IDir = llvm::sys::path::rbegin(headerFileName),
3256 EDir = llvm::sys::path::rend(headerFileName);
3257 IDir != EDir; ++IDir) {
3258 size_t lenTrailing = headerFileName.size() - (IDir->data() - headerFileName.data());
3259 llvm::StringRef trailingPart(IDir->data(), lenTrailing);
3260 assert(trailingPart.data() + trailingPart.size()
3261 == headerFileName.data() + headerFileName.size()
3262 &&
"Mismatched partitioning of file name!");
3263 const DirectoryLookup* FoundDir = 0;
3266 if (HdrSearch.LookupFile(trailingPart, SourceLocation(),
3268 ArrayRef<std::pair<const FileEntry *, const DirectoryEntry *>>(),
3272 return trailingPart;
3276 return invalidFilename;
3282 const clang::QualType &qtype,
3283 const clang::ASTContext &astContext)
3285 std::string fqname = cling::utils::TypeName::GetFullyQualifiedName(qtype, astContext);
3294 const clang::QualType &qtype,
3295 const cling::Interpreter &interpreter)
3299 interpreter.getCI()->getASTContext());
3311 const char* rootsys = getenv(
"ROOTSYS");
3313 Error(0,
"Environment variable ROOTSYS not set!");
3316 return std::string(
"-I") + rootsys +
"/etc";
3319 return std::string(
"-I") + ROOTETCDIR;
3328 #ifdef R__EXTERN_LLVMDIR 3329 return R__EXTERN_LLVMDIR;
3332 .substr(2, std::string::npos) +
"/cling";
3341 clang::ClassTemplateDecl*& ctd,
3342 clang::ClassTemplateSpecializationDecl*& ctsd)
3344 using namespace clang;
3345 const Type* theType = qt.getTypePtr();
3352 if (theType->isPointerType()) {
3356 if (
const RecordType* rType = llvm::dyn_cast<RecordType>(theType)) {
3357 ctsd = llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(rType->getDecl());
3359 ctd = ctsd->getSpecializedTemplate();
3364 if (
const SubstTemplateTypeParmType* sttpType = llvm::dyn_cast<SubstTemplateTypeParmType>(theType)){
3369 ctsd = llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(qt->getAsCXXRecordDecl());
3371 ctd = ctsd->getSpecializedTemplate();
3386 using namespace clang;
3387 ClassTemplateSpecializationDecl* ctsd;
3388 ClassTemplateDecl* ctd;
3402 using namespace clang;
3403 TemplateName theTemplateName;
3405 const Type* theType = qt.getTypePtr();
3407 if (
const TemplateSpecializationType* tst = llvm::dyn_cast_or_null<const TemplateSpecializationType>(theType)) {
3408 theTemplateName = tst->getTemplateName();
3411 theTemplateName = TemplateName(ctd);
3414 return theTemplateName;
3420 llvm::SmallVectorImpl<clang::TemplateArgument>& preceedingTArgs,
3421 const clang::NamedDecl& tPar,
3422 const cling::Interpreter& interp,
3426 using namespace clang;
3429 TemplateTypeParmDecl* ttpdPtr =
const_cast<TemplateTypeParmDecl*
>(llvm::dyn_cast<TemplateTypeParmDecl>(&tPar));
3430 if (!ttpdPtr)
return false;
3431 if (!ttpdPtr->hasDefaultArgument())
return false;
3434 QualType tParQualType = ttpdPtr->getDefaultArgument();
3435 const QualType tArgQualType = tArg.getAsType();
3442 if (tParQualType.getTypePtr() == tArgQualType.getTypePtr())
return true;
3453 const clang::ElaboratedType* etype
3454 = llvm::dyn_cast<clang::ElaboratedType>(tParQualType.getTypePtr());
3456 tParQualType = clang::QualType(etype->getNamedType().getTypePtr(),0);
3457 etype = llvm::dyn_cast<clang::ElaboratedType>(tParQualType.getTypePtr());
3460 const TemplateSpecializationType* tst =
3461 llvm::dyn_cast<TemplateSpecializationType>(tParQualType.getTypePtr());
3466 ClassTemplateSpecializationDecl* TSTdecl
3467 = llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(tArgQualType->getAsCXXRecordDecl());
3472 TemplateDecl *Template = tst->getTemplateName().getAsTemplateDecl();
3475 SourceLocation TemplateLoc = Template->getSourceRange ().getBegin();
3478 SourceLocation LAngleLoc = TSTdecl->getSourceRange().getBegin();
3483 TemplateArgument newArg = tArg;
3485 clang::Sema&
S = interp.getCI()->getSema();
3486 cling::Interpreter::PushTransactionRAII clingRAII(const_cast<cling::Interpreter*>(&interp));
3487 clang::sema::HackForDefaultTemplateArg raii;
3488 bool HasDefaultArgs;
3489 TemplateArgumentLoc defTArgLoc = S.SubstDefaultTemplateArgumentIfAvailable(Template,
3497 newArg = defTArgLoc.getArgument();
3498 if (newArg.isNull() ||
3501 "Template parameter substitution failed!");
3504 ClassTemplateSpecializationDecl* nTSTdecl
3505 = llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(newArg.getAsType()->getAsCXXRecordDecl());
3508 isEqual = nTSTdecl->getMostRecentDecl() == TSTdecl->getMostRecentDecl() ||
3509 tParQualType.getTypePtr() == newArg.getAsType().getTypePtr();
3521 const clang::NamedDecl& tPar)
3523 using namespace clang;
3524 const NonTypeTemplateParmDecl* nttpdPtr = llvm::dyn_cast<NonTypeTemplateParmDecl>(&tPar);
3525 if (!nttpdPtr)
return false;
3526 const NonTypeTemplateParmDecl& nttpd = *nttpdPtr;
3528 if (!nttpd.hasDefaultArgument())
3532 llvm::APSInt defaultValueAPSInt(64,
false);
3533 if (Expr* defArgExpr = nttpd.getDefaultArgument()) {
3534 const ASTContext& astCtxt = nttpdPtr->getASTContext();
3535 defArgExpr->isIntegerConstantExpr(defaultValueAPSInt, astCtxt);
3538 const int value = tArg.getAsIntegral().getLimitedValue();
3541 return value == defaultValueAPSInt;
3551 using namespace clang;
3552 if (!nDecl)
return false;
3553 if (
const TemplateTypeParmDecl* ttpd = llvm::dyn_cast<TemplateTypeParmDecl>(nDecl))
3554 return ttpd->hasDefaultArgument();
3555 if (
const NonTypeTemplateParmDecl* nttpd = llvm::dyn_cast<NonTypeTemplateParmDecl>(nDecl))
3556 return nttpd->hasDefaultArgument();
3561 static void KeepNParams(clang::QualType& normalizedType,
3562 const clang::QualType& vanillaType,
3563 const cling::Interpreter& interp,
3568 const clang::TemplateArgument &tArg,
3569 const cling::Interpreter& interp,
3571 const clang::ASTContext& astCtxt)
3574 using namespace clang;
3582 QualType thisNormQualType = normTArg.getAsType();
3583 QualType thisArgQualType = tArg.getAsType();
3588 normTArg = TemplateArgument(thisNormQualType);
3589 return (thisNormQualType != thisArgQualType);
3590 }
else if (normTArg.getKind() == clang::TemplateArgument::Pack) {
3591 assert( tArg.getKind() == clang::TemplateArgument::Pack );
3593 SmallVector<TemplateArgument, 2> desArgs;
3594 bool mightHaveChanged =
true;
3595 for (
auto I = normTArg.pack_begin(),
E = normTArg.pack_end(),
3596 FI = tArg.pack_begin(), FE = tArg.pack_end();
3597 I !=
E && FI != FE; ++
I, ++FI)
3599 TemplateArgument pack_arg(*
I);
3601 desArgs.push_back(pack_arg);
3603 if (mightHaveChanged) {
3604 ASTContext &mutableCtx( const_cast<ASTContext&>(astCtxt) );
3605 normTArg = TemplateArgument::CreatePackCopy(mutableCtx, desArgs);
3607 return mightHaveChanged;
3618 const clang::QualType& vanillaType,
3619 const cling::Interpreter& interp,
3623 using namespace clang;
3627 ClassTemplateSpecializationDecl* ctsd;
3628 ClassTemplateDecl* ctd;
3635 QualType originalNormalizedType = normalizedType;
3637 const ASTContext& astCtxt = ctsd->getASTContext();
3642 if (llvm::isa<clang::PointerType>(normalizedType.getTypePtr())) {
3644 clang::Qualifiers quals = normalizedType.getQualifiers();
3645 auto valNormalizedType = normalizedType->getPointeeType();
3646 KeepNParams(valNormalizedType,vanillaType, interp, normCtxt);
3647 normalizedType = astCtxt.getPointerType(valNormalizedType);
3649 normalizedType = astCtxt.getQualifiedType(normalizedType, quals);
3655 if (llvm::isa<clang::ReferenceType>(normalizedType.getTypePtr())) {
3657 bool isLValueRefTy = llvm::isa<clang::LValueReferenceType>(normalizedType.getTypePtr());
3658 clang::Qualifiers quals = normalizedType.getQualifiers();
3659 auto valNormType = normalizedType->getPointeeType();
3660 KeepNParams(valNormType, vanillaType, interp, normCtxt);
3664 normalizedType = astCtxt.getLValueReferenceType(valNormType);
3666 normalizedType = astCtxt.getRValueReferenceType(valNormType);
3668 normalizedType = astCtxt.getQualifiedType(normalizedType, quals);
3673 bool prefix_changed =
false;
3674 clang::NestedNameSpecifier* prefix =
nullptr;
3675 clang::Qualifiers prefix_qualifiers = normalizedType.getLocalQualifiers();
3676 const clang::ElaboratedType* etype
3677 = llvm::dyn_cast<clang::ElaboratedType>(normalizedType.getTypePtr());
3681 prefix = AddDefaultParametersNNS(astCtxt, etype->getQualifier(), interp, normCtxt);
3682 prefix_changed = prefix != etype->getQualifier();
3683 normalizedType = clang::QualType(etype->getNamedType().getTypePtr(),0);
3689 const clang::ClassTemplateDecl* ctdWithDefaultArgs = ctd;
3690 for (
const RedeclarableTemplateDecl* rd: ctdWithDefaultArgs->redecls()) {
3691 clang::TemplateParameterList* tpl = rd->getTemplateParameters();
3692 if (tpl->getMinRequiredArguments () < tpl->size())
3693 ctdWithDefaultArgs = llvm::dyn_cast<clang::ClassTemplateDecl>(rd);
3695 TemplateParameterList* tParsPtr = ctdWithDefaultArgs->getTemplateParameters();
3696 const TemplateParameterList& tPars = *tParsPtr;
3697 const TemplateArgumentList& tArgs = ctsd->getTemplateArgs();
3701 if (theTemplateName.isNull()) {
3702 normalizedType=originalNormalizedType;
3706 const TemplateSpecializationType* normalizedTst =
3707 llvm::dyn_cast<TemplateSpecializationType>(normalizedType.getTypePtr());
3708 if (!normalizedTst) {
3709 normalizedType=originalNormalizedType;
3713 const clang::ClassTemplateSpecializationDecl* TSTdecl
3714 = llvm::dyn_cast_or_null<const clang::ClassTemplateSpecializationDecl>(normalizedType.getTypePtr()->getAsCXXRecordDecl());
3722 llvm::SmallVector<TemplateArgument, 4> argsToKeep;
3724 const int nArgs = tArgs.size();
3725 const int nNormArgs = normalizedTst->getNumArgs();
3727 bool mightHaveChanged =
false;
3730 for (
int formal = 0, inst = 0; formal != nArgs; ++formal, ++inst) {
3731 const NamedDecl* tParPtr = tPars.getParam(formal);
3733 Error(
"KeepNParams",
"The parameter number %s is null.\n", formal);
3740 if (formal == nNormArgs || inst == nNormArgs)
break;
3742 const TemplateArgument& tArg = tArgs.get(formal);
3743 TemplateArgument normTArg(normalizedTst->getArgs()[inst]);
3745 bool shouldKeepArg = nArgsToKeep < 0 || inst <
nArgsToKeep;
3746 if (isStdDropDefault) shouldKeepArg =
false;
3755 if ( tParPtr->isTemplateParameterPack() ) {
3760 for( ; inst != nNormArgs; ++inst) {
3761 normTArg = normalizedTst->getArgs()[inst];
3763 argsToKeep.push_back(normTArg);
3769 argsToKeep.push_back(normTArg);
3772 if (!isStdDropDefault) {
3774 mightHaveChanged =
true;
3784 auto argKind = tArg.getKind();
3787 equal =
areEqualTypes(tArg, argsToKeep, *tParPtr, interp, normCtxt);
3788 }
else if (argKind == clang::TemplateArgument::Integral){
3793 argsToKeep.push_back(normTArg);
3795 mightHaveChanged =
true;
3801 if (!prefix_changed && !mightHaveChanged) {
3802 normalizedType = originalNormalizedType;
3807 if (mightHaveChanged) {
3808 Qualifiers qualifiers = normalizedType.getLocalQualifiers();
3809 normalizedType = astCtxt.getTemplateSpecializationType(theTemplateName,
3812 normalizedType.getTypePtr()->getCanonicalTypeInternal());
3813 normalizedType = astCtxt.getQualifiedType(normalizedType, qualifiers);
3819 normalizedType = astCtxt.getElaboratedType(clang::ETK_None,prefix,normalizedType);
3820 normalizedType = astCtxt.getQualifiedType(normalizedType,prefix_qualifiers);
3834 clang::ASTContext &ctxt = interpreter.getCI()->getASTContext();
3836 clang::QualType normalizedType = cling::utils::Transform::GetPartiallyDesugaredType(ctxt, type, normCtxt.
GetConfig(),
true );
3842 KeepNParams(normalizedType,type,interpreter,normCtxt);
3844 return normalizedType;
3858 if (type.isNull()) {
3865 clang::ASTContext &ctxt = interpreter.getCI()->getASTContext();
3866 clang::PrintingPolicy policy(ctxt.getPrintingPolicy());
3867 policy.SuppressTagKeyword =
true;
3868 policy.SuppressScope =
true;
3869 policy.AnonymousTagLocations =
false;
3874 std::string normalizedNameStep1;
3875 normalizedType.getAsStringInternal(normalizedNameStep1,policy);
3885 if (norm_name.length()>2 && norm_name[0]==
':' && norm_name[1]==
':') {
3886 norm_name.erase(0,2);
3894 const clang::TypeDecl* typeDecl,
3895 const cling::Interpreter &interpreter)
3898 const clang::Sema &sema = interpreter.getSema();
3899 clang::ASTContext& astCtxt = sema.getASTContext();
3900 clang::QualType qualType = astCtxt.getTypeDeclType(typeDecl);
3909 std::pair<std::string,clang::QualType>
3911 const cling::Interpreter &interpreter,
3915 std::string thisTypeName;
3919 if (!hasChanged)
return std::make_pair(thisTypeName,thisType);
3923 "Name changed from %s to %s\n", thisTypeName.c_str(), thisTypeNameForIO.c_str());
3926 auto& lookupHelper = interpreter.getLookupHelper();
3929 lookupHelper.findScope(thisTypeNameForIO,
3930 cling::LookupHelper::DiagSetting::NoDiagnostics,
3934 if (!typePtrForIO) {
3936 "Type not found: %s.",thisTypeNameForIO.c_str());
3939 clang::QualType typeForIO(typePtrForIO,0);
3942 if (!typeForIO->isRecordType()) {
3943 return std::make_pair(thisTypeNameForIO,typeForIO);
3946 auto thisDeclForIO = typeForIO->getAsCXXRecordDecl();
3947 if (!thisDeclForIO) {
3949 "The type for IO corresponding to %s is %s and it could not be found in the AST as class.\n", thisTypeName.c_str(), thisTypeNameForIO.c_str());
3950 return std::make_pair(thisTypeName,thisType);
3953 return std::make_pair(thisTypeNameForIO,typeForIO);
3959 const cling::Interpreter &interpreter,
3970 const std::string defaultInclude (
"include");
3973 const char* rootSysContent = getenv(
"ROOTSYS");
3974 if (rootSysContent) {
3975 std::string incl_rootsys (rootSysContent);
3976 return incl_rootsys +
"/" + defaultInclude;
3978 Error(0,
"Environment variable ROOTSYS not set");
3979 return defaultInclude;
3986 return defaultInclude;
3994 std::string dictFileName(moduleName);
3995 dictFileName +=
"_rdict.pcm";
3996 return dictFileName;
4003 const char* moduleFileName,
4004 const char* headers[])
4006 clang::Preprocessor& PP = CI->getPreprocessor();
4007 clang::ModuleMap& ModuleMap = PP.getHeaderSearchInfo().getModuleMap();
4010 clang::HeaderSearch& HS = CI->getPreprocessor().getHeaderSearchInfo();
4011 HS.setModuleCachePath(llvm::sys::path::parent_path(moduleFileName));
4013 llvm::StringRef moduleName = llvm::sys::path::filename(moduleFileName);
4014 moduleName = llvm::sys::path::stem(moduleName);
4016 std::pair<clang::Module*, bool> modCreation;
4019 = ModuleMap.findOrCreateModule(moduleName.str(),
4022 if (!modCreation.second && !strstr(moduleFileName,
"/allDict_rdict.pcm")) {
4023 std::cerr <<
"TMetaUtils::declareModuleMap: " 4024 "Duplicate definition of dictionary module " 4025 << moduleFileName << std::endl;
4030 clang::HeaderSearch& HdrSearch = PP.getHeaderSearchInfo();
4031 for (
const char** hdr = headers; hdr && *hdr; ++hdr) {
4032 const clang::DirectoryLookup* CurDir;
4033 const clang::FileEntry* hdrFileEntry
4034 = HdrSearch.LookupFile(*hdr, clang::SourceLocation(),
4036 llvm::ArrayRef<std::pair<
const clang::FileEntry *,
4037 const clang::DirectoryEntry *>>(),
4042 if (!hdrFileEntry) {
4043 std::cerr <<
"TMetaUtils::declareModuleMap: " 4044 "Cannot find header file " << *hdr
4045 <<
" included in dictionary module " 4047 <<
" in include search path!";
4048 hdrFileEntry = PP.getFileManager().getFile(*hdr,
false,
4050 }
else if (getenv(
"ROOT_MODULES")) {
4052 llvm::StringRef srHdrDir(hdrFileEntry->getName());
4053 srHdrDir = llvm::sys::path::parent_path(srHdrDir);
4054 const clang::DirectoryEntry* Dir
4055 = PP.getFileManager().getDirectory(srHdrDir);
4057 HdrSearch.setDirectoryHasModuleMap(Dir);
4061 ModuleMap.addHeader(modCreation.first,
4062 clang::Module::Header{*hdr,hdrFileEntry},
4063 clang::ModuleMap::NormalHeader);
4065 return modCreation.first;
4069 llvm::errs() << llvm::StringRef(commentStart, 80) <<
'\n';
4095 clang::SourceManager& sourceManager = decl.getASTContext().getSourceManager();
4096 clang::SourceLocation sourceLocation = decl.getLocEnd();
4099 sourceLocation = sourceManager.getExpansionRange(sourceLocation).second;
4100 if (sourceManager.isLoadedSourceLocation(sourceLocation)) {
4106 const char *commentStart = sourceManager.getCharacterData(sourceLocation, &invalid);
4110 bool skipToSemi =
true;
4111 if (
const clang::FunctionDecl* FD = clang::dyn_cast<clang::FunctionDecl>(&decl)) {
4112 if (FD->isImplicit()) {
4116 if (FD->isExplicitlyDefaulted() || FD->isDeletedAsWritten()) {
4120 }
else if (FD->doesThisDeclarationHaveABody()) {
4123 assert((decl.getLocEnd() != sourceLocation || *commentStart ==
'}' 4125 &&
"Expected macro or end of body at '}'");
4126 if (*commentStart) ++commentStart;
4129 while (*commentStart && isspace(*commentStart)
4130 && *commentStart !=
'\n' && *commentStart !=
'\r') {
4133 if (*commentStart ==
';') ++commentStart;
4137 }
else if (
const clang::EnumConstantDecl* ECD
4138 = clang::dyn_cast<clang::EnumConstantDecl>(&decl)) {
4140 if (ECD->getNextDeclInContext())
4141 while (*commentStart && *commentStart !=
',' && *commentStart !=
'\r' && *commentStart !=
'\n')
4149 while (*commentStart && *commentStart !=
';' && *commentStart !=
'\r' && *commentStart !=
'\n')
4151 if (*commentStart ==
';') ++commentStart;
4155 while ( *commentStart && isspace(*commentStart)
4156 && *commentStart !=
'\n' && *commentStart !=
'\r') {
4160 if (commentStart[0] !=
'/' ||
4161 (commentStart[1] !=
'/' && commentStart[1] !=
'*')) {
4171 unsigned int skipChars = 2;
4172 if (commentStart[0] ==
'/' &&
4173 commentStart[1] ==
'/' &&
4174 (commentStart[2] ==
'/' || commentStart[2] ==
'!') &&
4175 commentStart[3] ==
'<') {
4177 }
else if (commentStart[0] ==
'/' &&
4178 commentStart[1] ==
'*' &&
4179 (commentStart[2] ==
'*' || commentStart[2] ==
'!') &&
4180 commentStart[3] ==
'<') {
4184 commentStart += skipChars;
4187 while ( *commentStart && isspace(*commentStart)
4188 && *commentStart !=
'\n' && *commentStart !=
'\r') {
4191 const char* commentEnd = commentStart;
4193 while (*commentEnd && *commentEnd !=
'\n' && *commentEnd !=
'\r') {
4199 while (commentEnd > commentStart && isspace(commentEnd[-1])) {
4205 unsigned offset = commentStart - sourceManager.getCharacterData(sourceLocation);
4206 *loc = sourceLocation.getLocWithOffset(offset - 1);
4209 return llvm::StringRef(commentStart, commentEnd - commentStart);
4220 clang::SourceLocation *loc,
4221 const cling::Interpreter &interpreter)
4223 using namespace clang;
4224 SourceLocation commentSLoc;
4227 Sema& sema = interpreter.getCI()->getSema();
4229 const Decl* DeclFileLineDecl
4230 = interpreter.getLookupHelper().findFunctionProto(&decl,
"DeclFileLine",
"",
4231 cling::LookupHelper::NoDiagnostics);
4232 if (!DeclFileLineDecl)
return llvm::StringRef();
4235 SourceLocation maybeMacroLoc = DeclFileLineDecl->getLocation();
4236 bool isClassDefMacro = maybeMacroLoc.isMacroID() && sema.findMacroSpelling(maybeMacroLoc,
"ClassDef");
4237 if (isClassDefMacro) {
4239 if (comment.size()) {
4246 return llvm::StringRef();
4258 if (rawtype->isElaboratedTypeSpecifier() ) {
4259 rawtype = rawtype->getCanonicalTypeInternal().getTypePtr();
4261 if (rawtype->isArrayType()) {
4262 rawtype = type.getTypePtr()->getBaseElementTypeUnsafe ();
4264 if (rawtype->isPointerType() || rawtype->isReferenceType() ) {
4266 clang::QualType pointee;
4267 while ( (pointee = rawtype->getPointeeType()) , pointee.getTypePtrOrNull() && pointee.getTypePtr() != rawtype)
4269 rawtype = pointee.getTypePtr();
4271 if (rawtype->isElaboratedTypeSpecifier() ) {
4272 rawtype = rawtype->getCanonicalTypeInternal().getTypePtr();
4274 if (rawtype->isArrayType()) {
4275 rawtype = rawtype->getBaseElementTypeUnsafe ();
4279 if (rawtype->isArrayType()) {
4280 rawtype = rawtype->getBaseElementTypeUnsafe ();
4301 static const char *names[] =
4302 {
"shared_ptr",
"__shared_ptr",
4303 "vector",
"list",
"deque",
"map",
"multimap",
"set",
"multiset",
"bitset"};
4304 llvm::StringRef clname(cl.getName());
4305 for(
auto &&name : names) {
4306 if (clname == name)
return true;
4316 const clang::CXXRecordDecl ¤tCl)
4319 if (&cl == ¤tCl)
return true;
4321 const clang::CXXRecordDecl* previous = currentCl.getPreviousDecl();
4324 if (
NULL == previous){
4343 const clang::CXXRecordDecl *thisDecl =
4344 llvm::dyn_cast_or_null<clang::CXXRecordDecl>(lh.findScope(typ, cling::LookupHelper::WithDiagnostics));
4348 Error(
"IsOfType",
"Record decl of type %s not found in the AST.", typ.c_str());
4353 const clang::CXXRecordDecl *mostRecentDecl = thisDecl->getMostRecentDecl();
4386 using namespace clang;
4387 struct SearchTypedef:
public TypeVisitor<SearchTypedef, bool> {
4388 bool VisitTypedefType(
const TypedefType* TD) {
4391 bool VisitArrayType(
const ArrayType* AT) {
4392 return Visit(AT->getElementType().getTypePtr());
4394 bool VisitDecltypeType(
const DecltypeType* DT) {
4395 return Visit(DT->getUnderlyingType().getTypePtr());
4397 bool VisitPointerType(
const PointerType* PT) {
4398 return Visit(PT->getPointeeType().getTypePtr());
4400 bool VisitReferenceType(
const ReferenceType* RT) {
4401 return Visit(RT->getPointeeType().getTypePtr());
4403 bool VisitSubstTemplateTypeParmType(
const SubstTemplateTypeParmType* STST) {
4404 return Visit(STST->getReplacementType().getTypePtr());
4406 bool VisitTemplateSpecializationType(
const TemplateSpecializationType* TST) {
4407 for (
int I = 0,
N = TST->getNumArgs();
I <
N; ++
I) {
4408 const TemplateArgument& TA = TST->getArg(
I);
4410 && Visit(TA.getAsType().getTypePtr()))
4415 bool VisitTemplateTypeParmType(
const TemplateTypeParmType* TTPT) {
4418 bool VisitTypeOfType(
const TypeOfType* TOT) {
4419 return TOT->getUnderlyingType().getTypePtr();
4421 bool VisitElaboratedType(
const ElaboratedType* ET) {
4422 NestedNameSpecifier* NNS = ET->getQualifier();
4424 if (NNS->getKind() == NestedNameSpecifier::TypeSpec) {
4425 if (Visit(NNS->getAsType()))
4428 NNS = NNS->getPrefix();
4430 return Visit(ET->getNamedType().getTypePtr());
4445 if (!instance)
return input;
4451 using namespace llvm;
4452 using namespace clang;
4453 const clang::ASTContext &Ctxt = instance->getAsCXXRecordDecl()->getASTContext();
4456 const clang::ElaboratedType* etype
4457 = llvm::dyn_cast<clang::ElaboratedType>(input.getTypePtr());
4461 clang::Qualifiers scope_qualifiers = input.getLocalQualifiers();
4462 assert(instance->getAsCXXRecordDecl()!=0 &&
"ReSubstTemplateArg only makes sense with a type representing a class.");
4464 clang::NestedNameSpecifier *scope = ReSubstTemplateArgNNS(Ctxt,etype->getQualifier(),instance);
4465 clang::QualType subTy =
ReSubstTemplateArg(clang::QualType(etype->getNamedType().getTypePtr(),0),instance);
4467 if (scope) subTy = Ctxt.getElaboratedType(clang::ETK_None,scope,subTy);
4468 subTy = Ctxt.getQualifiedType(subTy,scope_qualifiers);
4472 QualType QT = input;
4476 if (isa<clang::PointerType>(QT.getTypePtr())) {
4478 Qualifiers quals = QT.getQualifiers();
4481 if (nQT == QT->getPointeeType())
return QT;
4483 QT = Ctxt.getPointerType(nQT);
4485 QT = Ctxt.getQualifiedType(QT, quals);
4491 if (isa<ReferenceType>(QT.getTypePtr())) {
4493 bool isLValueRefTy = isa<LValueReferenceType>(QT.getTypePtr());
4494 Qualifiers quals = QT.getQualifiers();
4497 if (nQT == QT->getPointeeType())
return QT;
4501 QT = Ctxt.getLValueReferenceType(nQT);
4503 QT = Ctxt.getRValueReferenceType(nQT);
4505 QT = Ctxt.getQualifiedType(QT, quals);
4511 if (isa<clang::ArrayType>(QT.getTypePtr())) {
4513 Qualifiers quals = QT.getQualifiers();
4515 if (isa<ConstantArrayType>(QT.getTypePtr())) {
4516 const ConstantArrayType *arr = dyn_cast<ConstantArrayType>(QT.getTypePtr());
4520 if (newQT == arr->getElementType())
return QT;
4521 QT = Ctxt.getConstantArrayType (newQT,
4523 arr->getSizeModifier(),
4524 arr->getIndexTypeCVRQualifiers());
4526 }
else if (isa<DependentSizedArrayType>(QT.getTypePtr())) {
4527 const DependentSizedArrayType *arr = dyn_cast<DependentSizedArrayType>(QT.getTypePtr());
4531 if (newQT == QT)
return QT;
4532 QT = Ctxt.getDependentSizedArrayType (newQT,
4534 arr->getSizeModifier(),
4535 arr->getIndexTypeCVRQualifiers(),
4536 arr->getBracketsRange());
4538 }
else if (isa<IncompleteArrayType>(QT.getTypePtr())) {
4539 const IncompleteArrayType *arr
4540 = dyn_cast<IncompleteArrayType>(QT.getTypePtr());
4544 if (newQT == arr->getElementType())
return QT;
4545 QT = Ctxt.getIncompleteArrayType (newQT,
4546 arr->getSizeModifier(),
4547 arr->getIndexTypeCVRQualifiers());
4549 }
else if (isa<VariableArrayType>(QT.getTypePtr())) {
4550 const VariableArrayType *arr
4551 = dyn_cast<VariableArrayType>(QT.getTypePtr());
4555 if (newQT == arr->getElementType())
return QT;
4556 QT = Ctxt.getVariableArrayType (newQT,
4558 arr->getSizeModifier(),
4559 arr->getIndexTypeCVRQualifiers(),
4560 arr->getBracketsRange());
4564 QT = Ctxt.getQualifiedType(QT, quals);
4569 etype = llvm::dyn_cast<clang::ElaboratedType>(instance);
4571 instance = etype->getNamedType().getTypePtr();
4572 if (!instance)
return input;
4575 const clang::TemplateSpecializationType* TST
4576 = llvm::dyn_cast<
const clang::TemplateSpecializationType>(instance);
4578 if (!TST)
return input;
4580 const clang::ClassTemplateSpecializationDecl* TSTdecl
4581 = llvm::dyn_cast_or_null<const clang::ClassTemplateSpecializationDecl>(instance->getAsCXXRecordDecl());
4583 const clang::SubstTemplateTypeParmType *substType
4584 = llvm::dyn_cast<clang::SubstTemplateTypeParmType>(input.getTypePtr());
4588 const clang::ClassTemplateDecl *replacedCtxt = 0;
4590 const clang::DeclContext *replacedDeclCtxt = substType->getReplacedParameter()->getDecl()->getDeclContext();
4591 const clang::CXXRecordDecl *decl = llvm::dyn_cast<clang::CXXRecordDecl>(replacedDeclCtxt);
4592 unsigned int index = substType->getReplacedParameter()->getIndex();
4595 if (decl->getKind() == clang::Decl::ClassTemplatePartialSpecialization) {
4596 const clang::ClassTemplatePartialSpecializationDecl *spec = llvm::dyn_cast<clang::ClassTemplatePartialSpecializationDecl>(decl);
4598 unsigned int depth = substType->getReplacedParameter()->getDepth();
4600 const TemplateArgument *instanceArgs = spec->getTemplateArgs().data();
4601 unsigned int instanceNArgs = spec->getTemplateArgs().size();
4605 for(
unsigned int A = 0;
A < instanceNArgs; ++
A) {
4607 clang::QualType argQualType = instanceArgs[
A].getAsType();
4609 const clang::TemplateTypeParmType *replacementType;
4611 replacementType = llvm::dyn_cast<clang::TemplateTypeParmType>(argQualType);
4613 if (!replacementType) {
4614 const clang::SubstTemplateTypeParmType *argType
4615 = llvm::dyn_cast<clang::SubstTemplateTypeParmType>(argQualType);
4617 clang::QualType replacementQT = argType->getReplacementType();
4618 replacementType = llvm::dyn_cast<clang::TemplateTypeParmType>(replacementQT);
4621 if (replacementType &&
4622 depth == replacementType->getDepth() &&
4623 index == replacementType->getIndex() )
4630 replacedCtxt = spec->getSpecializedTemplate();
4632 replacedCtxt = decl->getDescribedClassTemplate();
4635 replacedCtxt = llvm::dyn_cast<clang::ClassTemplateDecl>(replacedDeclCtxt);
4638 if (replacedCtxt->getCanonicalDecl() == TSTdecl->getSpecializedTemplate()->getCanonicalDecl()
4640 substType->getReplacedParameter()->getDecl()
4641 == TSTdecl->getSpecializedTemplate ()->getTemplateParameters()->getParam(index))
4643 if ( index >= TST->getNumArgs() ) {
4650 return TST->getArg(index).getAsType();
4655 const clang::TemplateSpecializationType* inputTST
4656 = llvm::dyn_cast<
const clang::TemplateSpecializationType>(input.getTypePtr());
4657 const clang::ASTContext& astCtxt = TSTdecl->getASTContext();
4660 bool mightHaveChanged =
false;
4661 llvm::SmallVector<clang::TemplateArgument, 4> desArgs;
4662 for(clang::TemplateSpecializationType::iterator
I = inputTST->begin(),
E = inputTST->end();
4665 desArgs.push_back(*
I);
4669 clang::QualType SubTy =
I->getAsType();
4671 if (llvm::isa<clang::SubstTemplateTypeParmType>(SubTy)
4672 || llvm::isa<clang::TemplateSpecializationType>(SubTy)) {
4674 mightHaveChanged = SubTy != newSubTy;
4675 if (!newSubTy.isNull()) {
4676 desArgs.push_back(clang::TemplateArgument(newSubTy));
4679 desArgs.push_back(*
I);
4683 if (mightHaveChanged) {
4684 clang::Qualifiers qualifiers = input.getLocalQualifiers();
4685 input = astCtxt.getTemplateSpecializationType(inputTST->getTemplateName(),
4688 inputTST->getCanonicalTypeInternal());
4689 input = astCtxt.getQualifiedType(input, qualifiers);
4701 if ( nArgsToRemove == 0 || name ==
"")
4706 const unsigned int length = name.length();
4708 unsigned int nArgsRemoved=0;
4709 unsigned int nBraces=0;
4711 while (nArgsRemoved!=nArgsToRemove && cur<length){
4713 if (c ==
'<') nBraces++;
4714 if (c ==
'>') nBraces--;
4715 if (c ==
',' && nBraces==1 ) nArgsRemoved++;
4719 name = name.substr(0,cur)+
">";
4729 static const char *stls[] =
4730 {
"any",
"vector",
"list",
"deque",
"map",
"multimap",
"set",
"multiset",
"bitset",
4731 "forward_list",
"unordered_set",
"unordered_multiset",
"unordered_map",
"unordered_multimap",0};
4744 for(
int k=1;stls[k];k++) {
if (type.equals(stls[k]))
return values[k];}
4755 TND = TND->getMostRecentDecl();
4756 while (TND && !(TND->hasAttrs()))
4757 TND = TND->getPreviousDecl();
4769 TD = TD->getMostRecentDecl();
4770 while (TD && !(TD->hasAttrs() && TD->isThisDeclarationADefinition()))
4771 TD = TD->getPreviousDecl();
4780 std::list<std::pair<std::string,bool> >& enclosingNamespaces)
4782 const clang::DeclContext* enclosingNamespaceDeclCtxt = decl.getDeclContext();
4783 if (!enclosingNamespaceDeclCtxt)
return;
4785 const clang::NamespaceDecl* enclosingNamespace =
4786 clang::dyn_cast<clang::NamespaceDecl>(enclosingNamespaceDeclCtxt);
4787 if (!enclosingNamespace)
return;
4789 enclosingNamespaces.push_back(std::make_pair(enclosingNamespace->getNameAsString(),
4790 enclosingNamespace->isInline()));
4800 std::list<std::pair<std::string,bool> >& enclosingNamespaces)
4802 const clang::DeclContext* enclosingNamespaceDeclCtxt = ctxt.getParent ();
4805 if (!enclosingNamespaceDeclCtxt) {
4811 const clang::NamespaceDecl* enclosingNamespace = clang::dyn_cast<clang::NamespaceDecl>(enclosingNamespaceDeclCtxt);
4812 if (!enclosingNamespace)
return;
4815 enclosingNamespaces.push_back(std::make_pair(enclosingNamespace->getNameAsString(),
4816 enclosingNamespace->isInline()));
4827 std::list<std::pair<std::string,unsigned int> >& enclosingSc)
4829 const clang::DeclContext* enclosingDeclCtxt = decl.getDeclContext();
4830 if (!enclosingDeclCtxt)
return 0;
4832 unsigned int scopeType;
4834 if (
auto enclosingNamespacePtr =
4835 clang::dyn_cast<clang::NamespaceDecl>(enclosingDeclCtxt)){
4836 scopeType= enclosingNamespacePtr->isInline() ? 1 : 0;
4837 enclosingSc.push_back(std::make_pair(enclosingNamespacePtr->getNameAsString(),scopeType));
4841 if (
auto enclosingClassPtr =
4842 clang::dyn_cast<clang::RecordDecl>(enclosingDeclCtxt)){
4843 return enclosingClassPtr;
4856 std::string::size_type beginVar = 0;
4857 std::string::size_type endVar = 0;
4858 while ((beginVar = txt.find(
'$', beginVar)) != std::string::npos
4859 && beginVar + 1 < txt.length()) {
4860 std::string::size_type beginVarName = beginVar + 1;
4861 std::string::size_type endVarName = std::string::npos;
4862 if (txt[beginVarName] ==
'(') {
4864 endVarName = txt.find(
')', beginVarName);
4866 if (endVarName == std::string::npos) {
4868 varname, txt.c_str() + beginVar);
4871 endVar = endVarName + 1;
4874 beginVarName = beginVar + 1;
4875 endVarName = beginVarName;
4876 while (isalnum(txt[endVarName]) || txt[endVarName] ==
'_')
4878 endVar = endVarName;
4881 const char* val = getenv(txt.substr(beginVarName,
4882 endVarName - beginVarName).c_str());
4885 txt.replace(beginVar, endVar - beginVar, val);
4886 int lenval = strlen(val);
4887 int delta = lenval - (endVar - beginVar);
4891 beginVar = endVar + 1;
4903 const char* envInclPath = getenv(
"ROOT_INCLUDE_PATH");
4907 std::istringstream envInclPathsStream(envInclPath);
4908 std::string inclPath;
4909 while (std::getline(envInclPathsStream, inclPath,
':')) {
4912 if (!inclPath.empty()) {
4913 clingArgs.push_back(
"-I");
4914 clingArgs.push_back(inclPath);
4925 size_t start_pos = 0;
4930 while((start_pos = str.find(from, start_pos)) != std::string::npos) {
4931 str.replace(start_pos, from.length(), to);
4932 start_pos += to.length();
4933 if (recurse) changed =
true;
4946 static const std::string gPathSeparator (
"\\");
4948 static const std::string gPathSeparator (
"/");
4950 return gPathSeparator;
4957 if (theString.size() < theSubstring.size())
return false;
4958 const unsigned int theSubstringSize = theSubstring.size();
4959 return 0 == theString.compare(theString.size() - theSubstringSize,
4968 if (theString.size() < theSubstring.size())
return false;
4969 const unsigned int theSubstringSize = theSubstring.size();
4970 return 0 == theString.compare(0,
4980 clang::Sema &sema = interp.getSema();
4981 cling::Transaction theTransaction(sema);
4982 std::set<clang::Decl *> addedDecls;
4983 for (
auto decl : decls) {
4985 clang::Decl *ncDecl =
const_cast<clang::Decl *
>(decl);
4986 theTransaction.append(ncDecl);
4988 std::string newFwdDecl;
4989 llvm::raw_string_ostream llvmOstr(newFwdDecl);
4990 interp.forwardDeclare(theTransaction, sema, llvmOstr,
true,
nullptr, ignoreFiles);
5003 std::string& defString)
5015 std::string& defString)
5017 std::list<std::pair<std::string,unsigned int> > enclosingNamespaces;
5020 if (rcdPtr)
return rcdPtr;
5023 static const std::string scopeType [] = {
"namespace ",
"inline namespace ",
"class "};
5025 std::string scopeName;
5026 std::string scopeContent;
5027 unsigned int scopeIndex;
5028 for (
auto const & encScope : enclosingNamespaces){
5029 scopeIndex = encScope.second;
5030 scopeName = encScope.first;
5031 scopeContent =
" { " + defString +
" }";
5032 defString = scopeType[scopeIndex] +
5054 const clang::TemplateParameterList& tmplParamList,
5055 const cling::Interpreter& interpreter)
5057 static const char* paramPackWarning=
"Template parameter pack found: autoload of variadic templates is not supported yet.\n";
5060 for (
auto prmIt = tmplParamList.begin();
5061 prmIt != tmplParamList.end(); prmIt++){
5063 if (prmIt != tmplParamList.begin())
5064 templateArgs +=
", ";
5066 auto nDecl = *prmIt;
5067 std::string typeName;
5069 if(nDecl->isParameterPack ()){
5075 if (llvm::isa<clang::TemplateTypeParmDecl>(nDecl)){
5076 typeName =
"typename " + (*prmIt)->getNameAsString();
5079 else if (
auto nttpd = llvm::dyn_cast<clang::NonTypeTemplateParmDecl>(nDecl)){
5080 auto theType = nttpd->getType();
5083 if (theType.getAsString().find(
"enum") != std::string::npos){
5084 std::string astDump;
5085 llvm::raw_string_ostream ostream(astDump);
5086 nttpd->dump(ostream);
5088 ROOT::TMetaUtils::Warning(0,
"Forward declarations of templates with enums as template parameters. The responsible class is: %s\n", astDump.c_str());
5097 else if (
auto ttpd = llvm::dyn_cast<clang::TemplateTemplateParmDecl>(nDecl)){
5100 std::string astDump;
5101 llvm::raw_string_ostream ostream(astDump);
5102 ttpd->dump(ostream);
5104 ROOT::TMetaUtils::Error(0,
"Cannot reconstruct template template parameter forward declaration for %s\n", astDump.c_str());
5109 templateArgs += typeName;
5120 const cling::Interpreter& interpreter,
5121 std::string& defString)
5123 std::string templatePrefixString;
5124 auto tmplParamList= templDecl.getTemplateParameters();
5125 if (!tmplParamList){
5127 "Cannot extract template parameter list for %s",
5128 templDecl.getNameAsString().c_str());
5135 "Problems with arguments for forward declaration of class %s\n",
5136 templDecl.getNameAsString().c_str());
5139 templatePrefixString =
"template " + templatePrefixString +
" ";
5141 defString = templatePrefixString +
"class " + templDecl.getNameAsString();
5142 if (llvm::isa<clang::TemplateTemplateParmDecl>(&templDecl)) {
5156 std::string& argFwdDecl,
5157 const cling::Interpreter& interpreter,
5158 bool acceptStl=
false)
5166 auto argQualType = arg.getAsType();
5169 while (llvm::isa<clang::PointerType>(argQualType.getTypePtr())) argQualType = argQualType->getPointeeType();
5171 auto argTypePtr = argQualType.getTypePtr();
5174 if (llvm::isa<clang::EnumType>(argTypePtr)){
5179 if (llvm::isa<clang::BuiltinType>(argTypePtr)){
5184 if (llvm::isa<clang::TypedefType>(argTypePtr)){
5185 auto tdTypePtr = llvm::dyn_cast<clang::TypedefType>(argTypePtr);
5190 if (llvm::isa<clang::RecordType>(argQualType)){
5192 auto argRecTypePtr = llvm::cast<clang::RecordType>(argTypePtr);
5193 if (
auto argRecDeclPtr = argRecTypePtr->getDecl()){
5208 const cling::Interpreter& interpreter,
5209 std::string& defString,
5217 if (!recordDecl.getIdentifier())
5221 std::string argsFwdDecl;
5223 if (
auto tmplSpecDeclPtr = llvm::dyn_cast<clang::ClassTemplateSpecializationDecl>(&recordDecl)){
5224 std::string argFwdDecl;
5226 std::cout <<
"Class " << recordDecl.getNameAsString()
5227 <<
" is a template specialisation. Treating its arguments.\n";
5228 for(
auto arg : tmplSpecDeclPtr->getTemplateArgs().asArray()){
5231 std::cout <<
" o Template argument ";
5233 std::cout <<
"successfully treated. Arg fwd decl: " << argFwdDecl << std::endl;
5235 std::cout <<
"could not be treated. Abort fwd declaration generation.\n";
5242 argsFwdDecl+=argFwdDecl;
5246 defString=argsFwdDecl;
5251 if (
auto tmplDeclPtr = tmplSpecDeclPtr->getSpecializedTemplate()){
5254 defString = argsFwdDecl +
"\n" + defString;
5259 defString =
"class " + recordDecl.getNameAsString() +
";";
5260 const clang::RecordDecl* rcd =
EncloseInScopes(recordDecl, defString);
5268 defString = argsFwdDecl +
"\n" + defString;
5279 const cling::Interpreter& interpreter,
5280 std::string& fwdDeclString,
5281 std::unordered_set<std::string>* fwdDeclSetPtr)
5283 std::string buffer = tdnDecl.getNameAsString();
5284 std::string underlyingName;
5285 auto underlyingType = tdnDecl.getUnderlyingType().getCanonicalType();
5286 if (
const clang::TagType* TT
5287 = llvm::dyn_cast<clang::TagType>(underlyingType.getTypePtr())) {
5288 if (clang::NamedDecl* ND = TT->getDecl()) {
5289 if (!ND->getIdentifier()) {
5303 if (underlyingName.find(
">::") != std::string::npos)
5306 buffer=
"typedef "+underlyingName+
" "+buffer+
";";
5318 auto& ctxt = tdnDecl.getASTContext();
5319 auto immediatelyUnderlyingType = underlyingType.getSingleStepDesugaredType(ctxt);
5321 if (
auto underlyingTdnTypePtr = llvm::dyn_cast<clang::TypedefType>(immediatelyUnderlyingType.getTypePtr())){
5322 std::string tdnFwdDecl;
5323 auto underlyingTdnDeclPtr = underlyingTdnTypePtr->getDecl();
5328 if (!fwdDeclSetPtr || fwdDeclSetPtr->insert(tdnFwdDecl).second)
5329 fwdDeclString+=tdnFwdDecl;
5330 }
else if (
auto CXXRcdDeclPtr = immediatelyUnderlyingType->getAsCXXRecordDecl()){
5331 std::string classFwdDecl;
5333 std::cout <<
"Typedef " << tdnDecl.getNameAsString() <<
" hides a class: " 5334 << CXXRcdDeclPtr->getNameAsString() << std::endl;
5343 if (!fwdDeclSetPtr || fwdDeclSetPtr->insert(classFwdDecl).second)
5344 fwdDeclString+=classFwdDecl;
5347 fwdDeclString+=buffer;
5359 std::string& valAsString,
5360 const clang::PrintingPolicy& ppolicy)
5362 auto defArgExprPtr = par.getDefaultArg();
5363 auto& ctxt = par.getASTContext();
5364 if(!defArgExprPtr->isEvaluatable(ctxt)){
5368 auto defArgType = par.getType();
5371 if (defArgType->isBooleanType()){
5373 defArgExprPtr->EvaluateAsBooleanCondition (result,ctxt);
5374 valAsString=std::to_string(result);
5379 if (defArgType->isIntegerType()){
5381 defArgExprPtr->EvaluateAsInt(result,ctxt);
5382 auto uintVal = *result.getRawData();
5383 if (result.isNegative()){
5384 long long int intVal=uintVal*-1;
5385 valAsString=std::to_string(intVal);
5387 valAsString=std::to_string(uintVal);
5394 llvm::raw_string_ostream rso(valAsString);
5395 defArgExprPtr->printPretty(rso,
nullptr,ppolicy);
5396 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...
std::map< std::string, ROOT::Internal::TSchemaType > MembersTypeMap_t
This namespace contains pre-defined functions to be used in conjuction with TExecutor::Map and TExecu...
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.
bool IsSTLBitset(const char *type)
Return true is the name is std::bitset<number> or bitset<number>
bool HasValidDataMembers(SchemaRuleMap_t &rule, MembersTypeMap_t &members)
Check if given rule contains references to valid data members.
void ShortType(std::string &answer, int mode)
Return the absolute type of typeDesc into the string answ.
std::string GetNameForIO(const std::string &templateInstanceName, TClassEdit::EModType mode=TClassEdit::kNone, bool *hasChanged=nullptr)
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'.
RooArgSet S(const RooAbsArg &v1)
SchemaRuleClassMap_t gReadRules
#define dest(otri, vertexptr)
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