24#include <unordered_set>
26#include "RConfigure.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/Mangle.h"
39#include "clang/AST/Type.h"
40#include "clang/AST/TypeVisitor.h"
41#include "clang/Frontend/CompilerInstance.h"
42#include "clang/Lex/HeaderSearch.h"
43#include "clang/Lex/ModuleMap.h"
44#include "clang/Lex/Preprocessor.h"
45#include "clang/Lex/PreprocessorOptions.h"
47#include "clang/Sema/Sema.h"
48#include "clang/Sema/SemaDiagnostic.h"
50#include "cling/Interpreter/LookupHelper.h"
51#include "cling/Interpreter/Transaction.h"
52#include "cling/Interpreter/Interpreter.h"
53#include "cling/Utils/AST.h"
55#include "llvm/Support/Path.h"
56#include "llvm/Support/FileSystem.h"
59#include "../../../interpreter/llvm/src/tools/clang/lib/Sema/HackForDefaultTemplateArg.h"
64#define strncasecmp _strnicmp
75 llvm::SmallString<256> result_path;
76 llvm::sys::fs::real_path(path, result_path,
true);
77 return result_path.str().str();
83class TNormalizedCtxtImpl {
84 using DeclsCont_t = TNormalizedCtxt::Config_t::SkipCollection;
90 TypesCont_t fTypeWithAlternative;
91 static TemplPtrIntMap_t fTemplatePtrArgsToKeepMap;
93 TNormalizedCtxtImpl(
const cling::LookupHelper &lh);
95 const Config_t &GetConfig()
const {
return fConfig; }
96 const TypesCont_t &GetTypeWithAlternative()
const {
return fTypeWithAlternative; }
97 void AddTemplAndNargsToKeep(
const clang::ClassTemplateDecl* templ,
unsigned int i);
98 int GetNargsToKeep(
const clang::ClassTemplateDecl* templ)
const;
99 const TemplPtrIntMap_t GetTemplNargsToKeepMap()
const {
return fTemplatePtrArgsToKeepMap; }
100 void keepTypedef(
const cling::LookupHelper &lh,
const char*
name,
101 bool replace =
false);
111static clang::NestedNameSpecifier* AddDefaultParametersNNS(
const clang::ASTContext& Ctx,
112 clang::NestedNameSpecifier* scope,
113 const cling::Interpreter &interpreter,
115 if (!scope)
return 0;
117 const clang::Type* scope_type = scope->getAsType();
120 clang::NestedNameSpecifier* outer_scope = scope->getPrefix();
122 outer_scope = AddDefaultParametersNNS(Ctx, outer_scope, interpreter, normCtxt);
125 clang::QualType addDefault =
128 if (addDefault.getTypePtr() != scope_type)
129 return clang::NestedNameSpecifier::Create(Ctx,outer_scope,
131 addDefault.getTypePtr());
138static bool CheckDefinition(
const clang::CXXRecordDecl *cl,
const clang::CXXRecordDecl *context)
140 if (!cl->hasDefinition()) {
143 "Missing definition for class %s, please #include its header in the header of %s\n",
144 cl->getName().str().c_str(), context->getName().str().c_str());
147 "Missing definition for class %s\n",
148 cl->getName().str().c_str());
160static clang::NestedNameSpecifier* ReSubstTemplateArgNNS(
const clang::ASTContext &Ctxt,
161 clang::NestedNameSpecifier *scope,
164 if (!scope)
return 0;
166 const clang::Type* scope_type = scope->getAsType();
168 clang::NestedNameSpecifier* outer_scope = scope->getPrefix();
170 outer_scope = ReSubstTemplateArgNNS(Ctxt, outer_scope,
instance);
172 clang::QualType substScope =
175 scope = clang::NestedNameSpecifier::Create(Ctxt,outer_scope,
177 substScope.getTypePtr());
186 const clang::BuiltinType * builtin = llvm::dyn_cast<clang::BuiltinType>(
type->getCanonicalTypeInternal().getTypePtr());
188 return builtin->isInteger();
196static bool IsFieldDeclInt(
const clang::FieldDecl *field)
198 return IsTypeInt(field->getType().getTypePtr());
204static const clang::FieldDecl *GetDataMemberFromAll(
const clang::CXXRecordDecl &cl, llvm::StringRef
what)
206 for(clang::RecordDecl::field_iterator field_iter = cl.field_begin(), end = cl.field_end();
209 if (field_iter->getName() ==
what) {
219static bool CXXRecordDecl__FindOrdinaryMember(
const clang::CXXBaseSpecifier *Specifier,
220 clang::CXXBasePath &Path,
223 clang::RecordDecl *BaseRecord = Specifier->getType()->getAs<clang::RecordType>()->getDecl();
225 const clang::CXXRecordDecl *clxx = llvm::dyn_cast<clang::CXXRecordDecl>(BaseRecord);
226 if (clxx == 0)
return false;
228 const clang::FieldDecl *found = GetDataMemberFromAll(*clxx,(
const char*)
Name);
232 clang::NamedDecl* NonConstFD =
const_cast<clang::FieldDecl*
>(found);
233 clang::NamedDecl** BaseSpecFirstHack
234 =
reinterpret_cast<clang::NamedDecl**
>(NonConstFD);
235 Path.Decls = clang::DeclContextLookupResult(llvm::ArrayRef<clang::NamedDecl*>(BaseSpecFirstHack, 1));
260static const clang::FieldDecl *GetDataMemberFromAllParents(
const clang::CXXRecordDecl &cl,
const char *
what)
262 clang::CXXBasePaths Paths;
263 Paths.setOrigin(
const_cast<clang::CXXRecordDecl*
>(&cl));
264 if (cl.lookupInBases([=](
const clang::CXXBaseSpecifier *Specifier, clang::CXXBasePath &Path) {
265 return CXXRecordDecl__FindOrdinaryMember(Specifier, Path, what);}, Paths))
267 clang::CXXBasePaths::paths_iterator iter = Paths.begin();
268 if (iter != Paths.end()) {
270 const clang::FieldDecl *found = (clang::FieldDecl *)iter->Decls.data();
278cling::LookupHelper::DiagSetting ToLHDS(
bool wantDiags) {
280 ? cling::LookupHelper::WithDiagnostics
281 : cling::LookupHelper::NoDiagnostics;
288namespace TMetaUtils {
294void TNormalizedCtxtImpl::AddTemplAndNargsToKeep(
const clang::ClassTemplateDecl* templ,
297 Error(
"TNormalizedCtxt::AddTemplAndNargsToKeep",
298 "Tring to specify a number of template arguments to keep for a null pointer. Exiting without assigning any value.\n");
302 const clang::ClassTemplateDecl* canTempl = templ->getCanonicalDecl();
304 if(fTemplatePtrArgsToKeepMap.count(canTempl)==1 &&
305 fTemplatePtrArgsToKeepMap[canTempl]!=(
int)i){
306 const std::string templateName (canTempl->getNameAsString());
307 const std::string i_str (std::to_string(i));
308 const std::string previousArgsToKeep(std::to_string(fTemplatePtrArgsToKeepMap[canTempl]));
309 Error(
"TNormalizedCtxt::AddTemplAndNargsToKeep",
310 "Tring to specify for template %s %s arguments to keep, while before this number was %s\n",
311 canTempl->getNameAsString().c_str(),
313 previousArgsToKeep.c_str());
316 fTemplatePtrArgsToKeepMap[canTempl]=i;
323int TNormalizedCtxtImpl::GetNargsToKeep(
const clang::ClassTemplateDecl* templ)
const{
324 const clang::ClassTemplateDecl* constTempl = templ->getCanonicalDecl();
325 auto thePairPtr = fTemplatePtrArgsToKeepMap.find(constTempl);
326 int nArgsToKeep = (thePairPtr != fTemplatePtrArgsToKeepMap.end() ) ? thePairPtr->second : -1;
334 fImpl(new TNormalizedCtxtImpl(lh))
338 fImpl(new TNormalizedCtxtImpl(*other.fImpl))
345 return fImpl->GetConfig();
348 return fImpl->GetTypeWithAlternative();
352 return fImpl->AddTemplAndNargsToKeep(templ, i);
356 return fImpl->GetNargsToKeep(templ);
359 return fImpl->GetTemplNargsToKeepMap();
364 return fImpl->keepTypedef(lh,
name, replace);
368 const std::string &normalizedName)
372 if (normalizedName.find(
"Double32_t") != std::string::npos
373 || normalizedName.find(
"Float16_t") != std::string::npos)
375 std::unique_ptr<clang::MangleContext> mangleCtx(rDecl->getASTContext().createMangleContext());
376 std::string mangledName;
378 llvm::raw_string_ostream sstr(mangledName);
379 if (
const clang::TypeDecl* TD = llvm::dyn_cast<clang::TypeDecl>(rDecl)) {
380 mangleCtx->mangleCXXRTTI(clang::QualType(TD->getTypeForDecl(), 0), sstr);
383 if (!mangledName.empty()) {
386 if (mangledName[0] ==
'\01')
387 mangledName.erase(0, 1);
389 if (!errDemangle && demangledTIName) {
390 static const char typeinfoNameFor[] =
" `RTTI Type Descriptor'";
391 if (strstr(demangledTIName, typeinfoNameFor)) {
392 std::string demangledName = demangledTIName;
393 demangledName.erase(demangledName.end() - strlen(typeinfoNameFor), demangledName.end());
394 if (demangledName.compare(0, 6,
"class ") == 0)
395 demangledName.erase(0, 6);
396 else if (demangledName.compare(0, 7,
"struct ") == 0)
397 demangledName.erase(0, 7);
400 if (!errDemangle && demangledTIName) {
401 static const char typeinfoNameFor[] =
"typeinfo for ";
402 if (!strncmp(demangledTIName, typeinfoNameFor, strlen(typeinfoNameFor))) {
403 std::string demangledName = demangledTIName + strlen(typeinfoNameFor);
405 free(demangledTIName);
406 return demangledName;
410 "Demangled typeinfo name '%s' does not contain `RTTI Type Descriptor'\n",
414 "Demangled typeinfo name '%s' does not start with 'typeinfo for'\n",
419 free(demangledTIName);
430 const clang::RecordDecl *decl,
433 bool rRequestNoInputOperator,
434 bool rRequestOnlyTClass,
435 int rRequestedVersionNumber,
436 const cling::Interpreter &interpreter,
450 const clang::RecordDecl *decl,
451 const char *requestName,
452 unsigned int nTemplateArgsToSkip,
455 bool rRequestNoInputOperator,
456 bool rRequestOnlyTClass,
457 int rRequestVersionNumber,
458 const cling::Interpreter &interpreter,
460 fRuleIndex(index), fDecl(decl), fRequestedName(
""), fRequestStreamerInfo(rStreamerInfo), fRequestNoStreamer(rNoStreamer),
461 fRequestNoInputOperator(rRequestNoInputOperator), fRequestOnlyTClass(rRequestOnlyTClass), fRequestedVersionNumber(rRequestVersionNumber)
470 "Could not remove the requested template arguments.\n");
480 const clang::RecordDecl *decl,
481 const char *requestName,
484 bool rRequestNoInputOperator,
485 bool rRequestOnlyTClass,
486 int rRequestVersionNumber,
487 const cling::Interpreter &interpreter,
489 fRuleIndex(index), fDecl(decl), fRequestedName(
""), fRequestStreamerInfo(rStreamerInfo), fRequestNoStreamer(rNoStreamer),
490 fRequestNoInputOperator(rRequestNoInputOperator), fRequestOnlyTClass(rRequestOnlyTClass), fRequestedVersionNumber(rRequestVersionNumber)
504 const clang::RecordDecl *decl,
505 const char *requestName,
508 bool rRequestNoInputOperator,
509 bool rRequestOnlyTClass,
510 int rRequestVersionNumber,
511 const cling::Interpreter &interpreter,
513 fRuleIndex(index), fDecl(decl), fRequestedName(
""), fRequestStreamerInfo(rStreamerInfo), fRequestNoStreamer(rNoStreamer), fRequestNoInputOperator(rRequestNoInputOperator), fRequestOnlyTClass(rRequestOnlyTClass), fRequestedVersionNumber(rRequestVersionNumber)
522 if (requestName && requestName[0]) {
537 ExistingTypeCheck_t existingTypeCheck,
538 AutoParse_t autoParse,
539 bool *shuttingDownPtr,
540 const int* pgDebug ):
541 fInterpreter(&interpreter),fNormalizedCtxt(&normCtxt),
542 fExistingTypeCheck(existingTypeCheck),
543 fAutoParse(autoParse),
544 fInterpreterIsShuttingDownPtr(shuttingDownPtr),
556 if (tname.empty())
return false;
566 const cling::LookupHelper& lh =
fInterpreter->getLookupHelper();
567 clang::QualType t = lh.findType(nameLong, ToLHDS(
WantDiags()));
570 if (!
dest.isNull() && (
dest != t)) {
573 dest.getAsStringInternal(nameLong,
fInterpreter->getCI()->getASTContext().getPrintingPolicy());
581 const std::string &nameLong)
583 const cling::LookupHelper& lh =
fInterpreter->getLookupHelper();
584 clang::QualType t = lh.findType(nondef.c_str(), ToLHDS(
WantDiags()));
587 if (!
dest.isNull() && (
dest != t) &&
588 nameLong == t.getAsString(
fInterpreter->getCI()->getASTContext().getPrintingPolicy()))
598 const cling::LookupHelper& lh =
fInterpreter->getLookupHelper();
599 const clang::Decl *scope = lh.findScope(base.c_str(), ToLHDS(
WantDiags()), 0);
606 const clang::NamespaceDecl *nsdecl = llvm::dyn_cast<clang::NamespaceDecl>(scope);
607 isInlined = nsdecl && nsdecl->isInline();
619 if (tname.empty())
return false;
627 return ! result.empty();
636 const cling::LookupHelper& lh =
fInterpreter->getLookupHelper();
637 clang::QualType t = lh.findType(tname.c_str(), ToLHDS(
WantDiags()));
648 clang::PrintingPolicy policy(
fInterpreter->getCI()->getASTContext().getPrintingPolicy());
649 policy.SuppressTagKeyword =
true;
650 policy.SuppressScope =
true;
656 dest.getAsStringInternal(result, policy);
658 unsigned long offset = 0;
659 if (strncmp(result.c_str(),
"const ", 6) == 0) {
662 if (dropstd && strncmp(result.c_str()+offset,
"std::", 5) == 0) {
663 result.erase(offset,5);
665 for(
unsigned int i = 1; i<result.length(); ++i) {
666 if (result[i]==
's') {
667 if (result[i-1]==
'<' || result[i-1]==
',' || result[i-1]==
' ') {
668 if (dropstd && result.compare(i,5,
"std::",5) == 0) {
673 if (result[i]==
' ') {
674 if (result[i-1] ==
',') {
677 }
else if ( (i+1) < result.length() &&
678 (result[i+1]==
'*' || result[i+1]==
'&' || result[i+1]==
'[') ) {
712void ROOT::TMetaUtils::TNormalizedCtxtImpl::keepTypedef(
const cling::LookupHelper &lh,
715 clang::QualType toSkip = lh.findType(
name, cling::LookupHelper::WithDiagnostics);
717 const clang::TypedefType *
tt = llvm::dyn_cast<clang::TypedefType>(
T);
719 clang::Decl* D =
tt->getDecl();
720 fConfig.m_toSkip.insert(D);
722 clang::QualType canon = toSkip->getCanonicalTypeInternal();
723 fConfig.m_toReplace.insert(std::make_pair(canon.getTypePtr(),
T));
725 fTypeWithAlternative.insert(
T);
736ROOT::TMetaUtils::TNormalizedCtxtImpl::TNormalizedCtxtImpl(
const cling::LookupHelper &lh)
738 keepTypedef(lh,
"Double32_t");
739 keepTypedef(lh,
"Float16_t");
740 keepTypedef(lh,
"Long64_t",
true);
741 keepTypedef(lh,
"ULong64_t",
true);
743 clang::QualType toSkip = lh.findType(
"string", cling::LookupHelper::WithDiagnostics);
744 if (!toSkip.isNull()) {
745 if (
const clang::TypedefType* TT
746 = llvm::dyn_cast_or_null<clang::TypedefType>(toSkip.getTypePtr()))
747 fConfig.m_toSkip.insert(TT->getDecl());
749 toSkip = lh.findType(
"std::string", cling::LookupHelper::WithDiagnostics);
750 if (!toSkip.isNull()) {
751 if (
const clang::TypedefType* TT
752 = llvm::dyn_cast_or_null<clang::TypedefType>(toSkip.getTypePtr()))
753 fConfig.m_toSkip.insert(TT->getDecl());
755 clang::QualType canon = toSkip->getCanonicalTypeInternal();
756 fConfig.m_toReplace.insert(std::make_pair(canon.getTypePtr(),toSkip.getTypePtr()));
761TNCtxtFullQual::TemplPtrIntMap_t TNCtxtFullQual::fTemplatePtrArgsToKeepMap=TNCtxtFullQual::TemplPtrIntMap_t{};
767 return (cl.getKind() == clang::Decl::ClassTemplatePartialSpecialization
768 || cl.getKind() == clang::Decl::ClassTemplateSpecialization);
775 const cling::Interpreter& interp)
777 clang::Sema*
S = &interp.getSema();
778 const clang::NamedDecl* ND = cling::utils::Lookup::Named(
S,
name, cl);
779 if (ND == (clang::NamedDecl*)-1)
780 return (clang::FunctionDecl*)-1;
781 return llvm::dyn_cast_or_null<clang::FunctionDecl>(ND);
787const clang::CXXRecordDecl *
791 const cling::LookupHelper& lh = interp.getLookupHelper();
794 const clang::CXXRecordDecl *result
795 = llvm::dyn_cast_or_null<clang::CXXRecordDecl>
796 (lh.findScope(
name, cling::LookupHelper::NoDiagnostics, resultType));
798 std::string std_name(
"std::");
802 result = llvm::dyn_cast_or_null<clang::CXXRecordDecl>
803 (lh.findScope(std_name, cling::LookupHelper::NoDiagnostics, resultType));
813 clang::QualType qType(cl->getTypeForDecl(),0);
821 clang::Sema&
S = interp.getCI()->getSema();
824 cling::Interpreter::PushTransactionRAII RAII(
const_cast<cling::Interpreter*
>(&interp));
825 return S.RequireCompleteType(Loc,
Type, clang::diag::err_incomplete_type);
831 const clang::CXXRecordDecl *context,
const cling::Interpreter &interp)
837 if (!cl->getDefinition() || !cl->isCompleteDefinition()) {
841 if (!CheckDefinition(cl, context) || !CheckDefinition(base, context)) {
845 if (!base->hasDefinition()) {
849 return cl->isDerivedFrom(base);
861 const clang::NamedDecl *base
865 return IsBase(CRD, llvm::dyn_cast<clang::CXXRecordDecl>( base ),
866 llvm::dyn_cast<clang::CXXRecordDecl>(
m.getDeclContext()),interp);
874 const clang::NamedDecl &forcontext,
875 const clang::QualType &qti,
876 const char *R__t,
int rwmode,
877 const cling::Interpreter &interp,
880 static const clang::CXXRecordDecl *TObject_decl
883 kBIT_ISTOBJECT = 0x10000000,
884 kBIT_HASSTREAMER = 0x20000000,
885 kBIT_ISSTRING = 0x40000000,
887 kBIT_ISPOINTER = 0x00001000,
888 kBIT_ISFUNDAMENTAL = 0x00000020,
889 kBIT_ISENUM = 0x00000008
902 clang::CXXRecordDecl *cxxtype = rawtype->getAsCXXRecordDecl() ;
904 int isTObj = cxxtype && (
IsBase(cxxtype,TObject_decl,
nullptr,interp) || rawname ==
"TObject");
908 if (ti.isPointerType()) kase |= kBIT_ISPOINTER;
909 if (rawtype->isFundamentalType()) kase |= kBIT_ISFUNDAMENTAL;
910 if (rawtype->isEnumeralType()) kase |= kBIT_ISENUM;
913 if (isTObj) kase |= kBIT_ISTOBJECT;
914 if (isStre) kase |= kBIT_HASSTREAMER;
915 if (tiName ==
"string") kase |= kBIT_ISSTRING;
916 if (tiName ==
"string*") kase |= kBIT_ISSTRING;
920 tcl =
" internal error in rootcling ";
926 if (R__t) finalString <<
" " << tiName <<
" " << R__t <<
";" << std::endl;
929 case kBIT_ISFUNDAMENTAL:
931 finalString <<
" R__b >> " << R__t <<
";" << std::endl;
934 case kBIT_ISPOINTER|kBIT_ISTOBJECT|kBIT_HASSTREAMER:
936 finalString <<
" " << R__t <<
" = (" << tiName <<
")R__b.ReadObjectAny(" << tcl <<
");" << std::endl;
945 finalString <<
" Int_t readtemp;" << std::endl
946 <<
" R__b >> readtemp;" << std::endl
947 <<
" " << R__t <<
" = static_cast<" << tiName <<
">(readtemp);" << std::endl;
950 case kBIT_HASSTREAMER:
951 case kBIT_HASSTREAMER|kBIT_ISTOBJECT:
953 finalString <<
" " << R__t <<
".Streamer(R__b);" << std::endl;
956 case kBIT_HASSTREAMER|kBIT_ISPOINTER:
959 finalString <<
" if (R__b.GetInfo() && R__b.GetInfo()->GetOldVersion()<=3) {" << std::endl;
960 if (cxxtype && cxxtype->isAbstract()) {
961 finalString <<
" R__ASSERT(0);// " << objType <<
" is abstract. We assume that older file could not be produced using this streaming method." << std::endl;
963 finalString <<
" " << R__t <<
" = new " << objType <<
";" << std::endl
964 <<
" " << R__t <<
"->Streamer(R__b);" << std::endl;
966 finalString <<
" } else {" << std::endl
967 <<
" " << R__t <<
" = (" << tiName <<
")R__b.ReadObjectAny(" << tcl <<
");" << std::endl
968 <<
" }" << std::endl;
973 finalString <<
" {TString R__str;" << std::endl
974 <<
" R__str.Streamer(R__b);" << std::endl
975 <<
" " << R__t <<
" = R__str.Data();}" << std::endl;
978 case kBIT_ISSTRING|kBIT_ISPOINTER:
980 finalString <<
" {TString R__str;" << std::endl
981 <<
" R__str.Streamer(R__b);" << std::endl
982 <<
" " << R__t <<
" = new string(R__str.Data());}" << std::endl;
987 finalString <<
" " << R__t <<
" = (" << tiName <<
")R__b.ReadObjectAny(" << tcl <<
");" << std::endl;
992 finalString <<
" R__b.StreamObject(&" << R__t <<
"," << tcl <<
");" << std::endl;
1000 case kBIT_ISFUNDAMENTAL:
1001 case kBIT_ISPOINTER|kBIT_ISTOBJECT|kBIT_HASSTREAMER:
1002 if (!R__t)
return 0;
1003 finalString <<
" R__b << " << R__t <<
";" << std::endl;
1007 if (!R__t)
return 0;
1008 finalString <<
" { void *ptr_enum = (void*)&" << R__t <<
";\n";
1009 finalString <<
" R__b >> *reinterpret_cast<Int_t*>(ptr_enum); }" << std::endl;
1012 case kBIT_HASSTREAMER:
1013 case kBIT_HASSTREAMER|kBIT_ISTOBJECT:
1014 if (!R__t)
return 0;
1015 finalString <<
" ((" << objType <<
"&)" << R__t <<
").Streamer(R__b);" << std::endl;
1018 case kBIT_HASSTREAMER|kBIT_ISPOINTER:
1019 if (!R__t)
return 1;
1020 finalString <<
" R__b.WriteObjectAny(" << R__t <<
"," << tcl <<
");" << std::endl;
1024 if (!R__t)
return 0;
1025 finalString <<
" {TString R__str(" << R__t <<
".c_str());" << std::endl
1026 <<
" R__str.Streamer(R__b);};" << std::endl;
1029 case kBIT_ISSTRING|kBIT_ISPOINTER:
1030 if (!R__t)
return 0;
1031 finalString <<
" {TString R__str(" << R__t <<
"->c_str());" << std::endl
1032 <<
" R__str.Streamer(R__b);}" << std::endl;
1035 case kBIT_ISPOINTER:
1036 if (!R__t)
return 1;
1037 finalString <<
" R__b.WriteObjectAny(" << R__t <<
"," << tcl <<
");" << std::endl;
1041 if (!R__t)
return 1;
1042 finalString <<
" R__b.StreamObject((" << objType <<
"*)&" << R__t <<
"," << tcl <<
");" << std::endl;
1054 clang::CXXRecordDecl* ncCl =
const_cast<clang::CXXRecordDecl*
>(cl);
1057 cling::Interpreter::PushTransactionRAII clingRAII(
const_cast<cling::Interpreter*
>(&interpreter));
1059 if (
auto* Ctor = interpreter.getCI()->getSema().LookupDefaultConstructor(ncCl)) {
1060 if (Ctor->getAccess() == clang::AS_public && !Ctor->isDeleted()) {
1073 const char *typeOfArg,
1074 const clang::CXXRecordDecl *expectedArgType,
1075 const cling::Interpreter& interpreter)
1077 if (typeOfArg && !expectedArgType) {
1078 const cling::LookupHelper& lh = interpreter.getLookupHelper();
1081 clang::QualType instanceType = lh.findType(typeOfArg, cling::LookupHelper::WithDiagnostics);
1082 if (!instanceType.isNull())
1083 expectedArgType = instanceType->getAsCXXRecordDecl();
1086 if (!expectedArgType)
1087 return EIOCtorCategory::kAbsent;
1089 for (
auto iter = cl->ctor_begin(), end = cl->ctor_end(); iter != end; ++iter)
1091 if ((iter->getAccess() != clang::AS_public) || (iter->getNumParams() != 1))
1095 clang::QualType argType((*iter->param_begin())->getType());
1096 argType = argType.getDesugaredType(cl->getASTContext());
1098 auto ioCtorCategory = EIOCtorCategory::kAbsent;
1099 if (argType->isPointerType()) {
1100 ioCtorCategory = EIOCtorCategory::kIOPtrType;
1101 argType = argType->getPointeeType();
1102 }
else if (argType->isReferenceType()) {
1103 ioCtorCategory = EIOCtorCategory::kIORefType;
1104 argType = argType.getNonReferenceType();
1108 argType = argType.getDesugaredType(cl->getASTContext());
1109 const clang::CXXRecordDecl *argDecl = argType->getAsCXXRecordDecl();
1111 if (argDecl->getCanonicalDecl() == expectedArgType->getCanonicalDecl()) {
1112 return ioCtorCategory;
1115 std::string realArg = argType.getAsString();
1116 std::string clarg(
"class ");
1118 if (realArg == clarg)
1119 return ioCtorCategory;
1123 return EIOCtorCategory::kAbsent;
1132 const cling::Interpreter& interpreter)
1134 const char *arg = ioctortype.
GetName();
1136 if (!ioctortype.
GetType() && (!arg || !arg[0])) {
1149 const char *method,
const char *
proto,
1150 const cling::Interpreter &interp,
1153 const clang::FunctionDecl* funcD
1154 = interp.getLookupHelper().findFunctionProto(cinfo, method,
proto,
1155 diagnose ? cling::LookupHelper::WithDiagnostics
1156 : cling::LookupHelper::NoDiagnostics);
1158 return llvm::dyn_cast<const clang::CXXMethodDecl>(funcD);
1167 namespace TMetaUtils {
1170 const cling::LookupHelper& lh = interp.getLookupHelper();
1173 clang::QualType instanceType = lh.findType(type_of_arg, cling::LookupHelper::WithDiagnostics);
1174 if (!instanceType.isNull())
1175 fArgType = instanceType->getAsCXXRecordDecl();
1189 const cling::Interpreter &interp)
1191 if (cl->isAbstract())
return false;
1193 for (
auto & ctorType : ctorTypes) {
1197 if (EIOCtorCategory::kAbsent == ioCtorCat)
1200 std::string
proto( ctorType.GetName() );
1201 bool defaultCtor =
proto.empty();
1207 if (EIOCtorCategory::kIOPtrType == ioCtorCat) {
1209 }
else if (EIOCtorCategory::kIORefType == ioCtorCat) {
1213 arg +=
")nullptr )";
1216 const clang::CXXMethodDecl *method
1218 cling::LookupHelper::NoDiagnostics);
1219 if (method && method->getAccess() != clang::AS_public) {
1233 const cling::Interpreter& interp)
1235 if (!cl)
return false;
1237 if (cl->hasUserDeclaredDestructor()) {
1239 cling::Interpreter::PushTransactionRAII clingRAII(
const_cast<cling::Interpreter*
>(&interp));
1240 clang::CXXDestructorDecl *
dest = cl->getDestructor();
1242 return (
dest->getAccess() == clang::AS_public);
1254 const char *methodname,
1256 const cling::Interpreter &interp,
1259 const clang::CXXMethodDecl *method
1261 diagnose ? cling::LookupHelper::WithDiagnostics
1262 : cling::LookupHelper::NoDiagnostics);
1263 return (method && method->getAccess() == clang::AS_public);
1274 const char *
proto =
"TDirectory*";
1275 const char *
name =
"DirectoryAutoAdd";
1289 const char *
proto =
"TCollection*,TFileMergeInfo*";
1290 const char *
name =
"Merge";
1303 const char *
proto =
"TCollection*";
1304 const char *
name =
"Merge";
1319 const char *
proto =
"TFileMergeInfo*";
1320 const char *
name =
"ResetAfterMerge";
1330 const clang::CXXRecordDecl* clxx,
1331 const cling::Interpreter &interp,
1334 static const char *
proto =
"TBuffer&";
1336 const clang::CXXMethodDecl *method
1338 cling::LookupHelper::NoDiagnostics);
1339 const clang::DeclContext *clxx_as_context = llvm::dyn_cast<clang::DeclContext>(clxx);
1341 return (method && method->getDeclContext() == clxx_as_context
1349 const clang::CXXRecordDecl* clxx,
1350 const cling::Interpreter &interp,
1353 static const char *
proto =
"TBuffer&,TClass*";
1355 const clang::CXXMethodDecl *method
1357 cling::LookupHelper::NoDiagnostics);
1358 const clang::DeclContext *clxx_as_context = llvm::dyn_cast<clang::DeclContext>(clxx);
1360 return (method && method->getDeclContext() == clxx_as_context
1390 clang::QualType qualType(&
type,0);
1422 llvm::raw_string_ostream stream(qual_name);
1423 clang::PrintingPolicy policy( cl.getASTContext().getPrintingPolicy() );
1424 policy.SuppressTagKeyword =
true;
1425 policy.SuppressUnwrittenScope =
true;
1427 cl.getNameForDiagnostic(stream,policy,
true);
1430 if ( qual_name ==
"(anonymous " ) {
1431 size_t pos = qual_name.find(
':');
1432 qual_name.erase(0,pos+2);
1448 const clang::Type* declType ( recordDecl.getTypeForDecl() );
1449 clang::QualType qualType(declType,0);
1483 std::stringstream dims;
1484 std::string typenameStr;
1486 const clang::ASTContext& astContext = cl.getASTContext();
1489 for(clang::RecordDecl::field_iterator field_iter = cl.field_begin(), end = cl.field_end();
1497 typenameStr.clear();
1501 clang::QualType fieldType(field_iter->getType());
1502 if (fieldType->isConstantArrayType()) {
1503 const clang::ConstantArrayType *arrayType = llvm::dyn_cast<clang::ConstantArrayType>(fieldType.getTypePtr());
1505 dims <<
"[" << arrayType->getSize().getLimitedValue() <<
"]";
1506 fieldType = arrayType->getElementType();
1507 arrayType = llvm::dyn_cast<clang::ConstantArrayType>(arrayType->getArrayElementTypeNoTypeQual());
1517 for(clang::CXXRecordDecl::base_class_const_iterator iter = cl.bases_begin(), end = cl.bases_end();
1520 std::string basename( iter->getType()->getAsCXXRecordDecl()->getNameAsString() );
1530 const cling::Interpreter &interp,
1533 return interp.getLookupHelper().findFunctionProto(cinfo, method,
proto,
1534 diagnose ? cling::LookupHelper::WithDiagnostics
1535 : cling::LookupHelper::NoDiagnostics);
1569 clang::SourceLocation sourceLocation = decl->getLocation();
1570 clang::SourceManager& sourceManager = decl->getASTContext().getSourceManager();
1572 if (!sourceLocation.isValid() ) {
1576 if (!sourceLocation.isFileID()) {
1577 sourceLocation = sourceManager.getExpansionRange(sourceLocation).second;
1580 if (sourceLocation.isValid() && sourceLocation.isFileID()) {
1581 return sourceManager.getLineNumber(sourceManager.getFileID(sourceLocation),sourceManager.getFileOffset(sourceLocation));
1594 while (llvm::isa<clang::PointerType>(instanceType.getTypePtr())
1595 || llvm::isa<clang::ReferenceType>(instanceType.getTypePtr()))
1597 instanceType = instanceType->getPointeeType();
1600 const clang::ElaboratedType* etype
1601 = llvm::dyn_cast<clang::ElaboratedType>(instanceType.getTypePtr());
1603 instanceType = clang::QualType(etype->getNamedType().getTypePtr(),0);
1615 bool result =
false;
1616 const clang::CXXRecordDecl* clxx = instanceType->getAsCXXRecordDecl();
1617 if (clxx && clxx->getTemplateSpecializationKind() != clang::TSK_Undeclared) {
1619 const clang::TemplateSpecializationType* TST
1620 = llvm::dyn_cast<const clang::TemplateSpecializationType>(instanceType.getTypePtr());
1627 for(clang::TemplateSpecializationType::iterator
1628 I = TST->begin(),
E = TST->end();
1646 const cling::Interpreter &interp,
1649 const clang::CXXRecordDecl* clxx = llvm::dyn_cast<clang::CXXRecordDecl>(cl.
GetRecordDecl());
1650 if (clxx->getTemplateSpecializationKind() == clang::TSK_Undeclared)
return 0;
1652 clang::QualType instanceType = interp.getLookupHelper().findType(cl.
GetNormalizedName(),
1653 cling::LookupHelper::WithDiagnostics);
1654 if (instanceType.isNull()) {
1667 clang::AnnotateAttr* annAttr = clang::dyn_cast<clang::AnnotateAttr>(attribute);
1672 attrString = annAttr->getAnnotation();
1682 if (substrFound==std::string::npos) {
1687 attrName = attributeStr.substr(0, EndPart1);
1689 attrValue = attributeStr.substr(EndPart1 + separatorLength);
1697 std::string attrString;
1699 if (0!=ret)
return ret;
1707 const std::string& propName,
1708 std::string& propValue)
1710 for (clang::Decl::attr_iterator attrIt = decl.attr_begin();
1711 attrIt!=decl.attr_end();++attrIt){
1712 clang::AnnotateAttr* annAttr = clang::dyn_cast<clang::AnnotateAttr>(*attrIt);
1713 if (!annAttr)
continue;
1715 llvm::StringRef attribute = annAttr->getAnnotation();
1716 std::pair<llvm::StringRef,llvm::StringRef> split = attribute.split(
propNames::separator.c_str());
1717 if (split.first != propName.c_str())
continue;
1719 propValue = split.second;
1730 const std::string& propName,
1733 for (clang::Decl::attr_iterator attrIt = decl.attr_begin();
1734 attrIt!=decl.attr_end();++attrIt){
1735 clang::AnnotateAttr* annAttr = clang::dyn_cast<clang::AnnotateAttr>(*attrIt);
1736 if (!annAttr)
continue;
1738 llvm::StringRef attribute = annAttr->getAnnotation();
1739 std::pair<llvm::StringRef,llvm::StringRef> split = attribute.split(
propNames::separator.c_str());
1740 if (split.first != propName.c_str())
continue;
1742 return split.second.getAsInteger(10,propValue);
1753 const clang::CXXRecordDecl *decl,
1754 const cling::Interpreter &interp,
1757 bool& needCollectionProxy)
1761 std::string mappedname;
1763 std::string csymbol = classname;
1771 csymbol.insert(0,
"::");
1778 const cling::LookupHelper& lh = interp.getLookupHelper();
1781 bool isStdNotString = isStd && !isString;
1783 finalString <<
"namespace ROOT {" <<
"\n";
1787 finalString <<
" static TClass *" << mappedname.c_str() <<
"_Dictionary();\n"
1788 <<
" static void " << mappedname.c_str() <<
"_TClassManip(TClass*);\n";
1794 finalString <<
" static void *new_" << mappedname.c_str() <<
"(void *p = 0);" <<
"\n";
1798 finalString <<
" static void *newArray_";
1799 finalString << mappedname.c_str();
1800 finalString <<
"(Long_t size, void *p);";
1801 finalString <<
"\n";
1806 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";
1809 finalString <<
" static void directoryAutoAdd_" << mappedname.c_str() <<
"(void *obj, TDirectory *dir);" <<
"\n";
1812 finalString <<
" static void streamer_" << mappedname.c_str() <<
"(TBuffer &buf, void *obj);" <<
"\n";
1815 finalString <<
" static void conv_streamer_" << mappedname.c_str() <<
"(TBuffer &buf, void *obj, const TClass*);" <<
"\n";
1818 finalString <<
" static Long64_t merge_" << mappedname.c_str() <<
"(void *obj, TCollection *coll,TFileMergeInfo *info);" <<
"\n";
1821 finalString <<
" static void reset_" << mappedname.c_str() <<
"(void *obj, TFileMergeInfo *info);" <<
"\n";
1828 ROOT::SchemaRuleClassMap_t::iterator rulesIt1 =
ROOT::gReadRules.find( classname.c_str() );
1829 ROOT::SchemaRuleClassMap_t::iterator rulesIt2 =
ROOT::gReadRawRules.find( classname.c_str() );
1840 finalString <<
"\n // Schema evolution read functions\n";
1841 std::list<ROOT::SchemaRuleMap_t>::iterator rIt = rulesIt1->second.begin();
1842 while( rIt != rulesIt1->second.end() ) {
1848 std::string error_string;
1850 Warning(0,
"%s", error_string.c_str());
1851 rIt = rulesIt1->second.erase(rIt);
1859 if( rIt->find(
"code" ) != rIt->end() ) {
1875 finalString <<
"\n // Schema evolution read raw functions\n";
1876 std::list<ROOT::SchemaRuleMap_t>::iterator rIt = rulesIt2->second.begin();
1877 while( rIt != rulesIt2->second.end() ) {
1883 std::string error_string;
1885 Warning(0,
"%s", error_string.c_str());
1886 rIt = rulesIt2->second.erase(rIt);
1894 if( rIt->find(
"code" ) == rIt->end() )
1902 finalString <<
"\n" <<
" // Function generating the singleton type initializer" <<
"\n";
1904 finalString <<
" static TGenericClassInfo *GenerateInitInstanceLocal(const " << csymbol <<
"*)" <<
"\n" <<
" {" <<
"\n";
1906 finalString <<
" " << csymbol <<
" *ptr = 0;" <<
"\n";
1910 finalString <<
" static ::TVirtualIsAProxy* isa_proxy = new ::TInstrumentedIsAProxy< " << csymbol <<
" >(0);" <<
"\n";
1913 finalString <<
" static ::TVirtualIsAProxy* isa_proxy = new ::TIsAProxy(typeid(" << csymbol <<
"));" <<
"\n";
1915 finalString <<
" static ::ROOT::TGenericClassInfo " <<
"\n" <<
" instance(\"" << classname.c_str() <<
"\", ";
1918 finalString << csymbol <<
"::Class_Version(), ";
1920 finalString <<
"2, ";
1922 finalString <<
"-2, ";
1928 static const char *versionFunc =
"GetClassVersion";
1932 std::string
proto = classname +
"*";
1933 const clang::Decl* ctxt = llvm::dyn_cast<clang::Decl>((*cl).getDeclContext());
1934 const clang::FunctionDecl *methodinfo
1936 interp, cling::LookupHelper::NoDiagnostics);
1944 finalString <<
"GetClassVersion< ";
1945 finalString << classname.c_str();
1946 finalString <<
" >(), ";
1954 if (filename.length() > 0) {
1955 for (
unsigned int i=0; i<filename.length(); i++) {
1956 if (filename[i]==
'\\') filename[i]=
'/';
1960 <<
"," <<
"\n" <<
" typeid(" << csymbol
1961 <<
"), ::ROOT::Internal::DefineBehavior(ptr, ptr)," <<
"\n" <<
" ";
1964 finalString <<
"&" << csymbol <<
"::Dictionary, ";
1966 finalString <<
"&" << mappedname <<
"_Dictionary, ";
1970 TClassTable__kHasCustomStreamerMember = 0x10
1975 rootflag = rootflag | TClassTable__kHasCustomStreamerMember;
1977 finalString <<
"isa_proxy, " << rootflag <<
"," <<
"\n" <<
" sizeof(" << csymbol <<
") );" <<
"\n";
1979 finalString <<
" instance.SetNew(&new_" << mappedname.c_str() <<
");" <<
"\n";
1981 finalString <<
" instance.SetNewArray(&newArray_" << mappedname.c_str() <<
");" <<
"\n";
1984 finalString <<
" instance.SetDelete(&delete_" << mappedname.c_str() <<
");" <<
"\n" <<
" instance.SetDeleteArray(&deleteArray_" << mappedname.c_str() <<
");" <<
"\n" <<
" instance.SetDestructor(&destruct_" << mappedname.c_str() <<
");" <<
"\n";
1987 finalString <<
" instance.SetDirectoryAutoAdd(&directoryAutoAdd_" << mappedname.c_str() <<
");" <<
"\n";
1991 finalString <<
" instance.SetStreamerFunc(&streamer_" << mappedname.c_str() <<
");" <<
"\n";
1995 finalString <<
" instance.SetConvStreamerFunc(&conv_streamer_" << mappedname.c_str() <<
");" <<
"\n";
1998 finalString <<
" instance.SetMerge(&merge_" << mappedname.c_str() <<
");" <<
"\n";
2001 finalString <<
" instance.SetResetAfterMerge(&reset_" << mappedname.c_str() <<
");" <<
"\n";
2004 finalString <<
" instance.AdoptCollectionProxyInfo(TCollectionProxyInfo::Generate(TCollectionProxyInfo::" <<
"Pushback" <<
"<Internal::TStdBitsetHelper< " << classname.c_str() <<
" > >()));" <<
"\n";
2006 needCollectionProxy =
true;
2007 }
else if (stl != 0 &&
2010 int idx = classname.find(
"<");
2012 const char* methodTCP=0;
2017 methodTCP=
"Pushback";
2020 methodTCP=
"Pushfront";
2026 methodTCP=
"MapInsert";
2038 finalString <<
" instance.AdoptCollectionProxyInfo(TCollectionProxyInfo::Generate(TCollectionProxyInfo::" << methodTCP <<
"< " << classNameForIO.c_str() <<
" >()));" <<
"\n";
2040 needCollectionProxy =
true;
2048 finalString <<
"\n" <<
" ::ROOT::AddClassAlternate(\""
2055 finalString <<
"\n" <<
" ::ROOT::AddClassAlternate(\""
2065 finalString <<
"\n" <<
" ::ROOT::Internal::TSchemaHelper* rule;" <<
"\n";
2069 finalString <<
"\n" <<
" // the io read rules" <<
"\n" <<
" std::vector<::ROOT::Internal::TSchemaHelper> readrules(" << rulesIt1->second.size() <<
");" <<
"\n";
2071 finalString <<
" instance.SetReadRules( readrules );" <<
"\n";
2075 finalString <<
"\n" <<
" // the io read raw rules" <<
"\n" <<
" std::vector<::ROOT::Internal::TSchemaHelper> readrawrules(" << rulesIt2->second.size() <<
");" <<
"\n";
2077 finalString <<
" instance.SetReadRawRules( readrawrules );" <<
"\n";
2080 finalString <<
" return &instance;" <<
"\n" <<
" }" <<
"\n";
2084 finalString <<
" TGenericClassInfo *GenerateInitInstance(const " << csymbol <<
"*)" <<
"\n" <<
" {\n return GenerateInitInstanceLocal((" << csymbol <<
"*)0);\n }" <<
"\n";
2087 finalString <<
" // Static variable to force the class initialization" <<
"\n";
2091 finalString <<
" static ::ROOT::TGenericClassInfo *_R__UNIQUE_DICT_(Init) = GenerateInitInstanceLocal((const " << csymbol <<
"*)0x0); R__UseDummy(_R__UNIQUE_DICT_(Init));" <<
"\n";
2094 finalString <<
"\n" <<
" // Dictionary for non-ClassDef classes" <<
"\n"
2095 <<
" static TClass *" << mappedname <<
"_Dictionary() {\n"
2096 <<
" TClass* theClass ="
2097 <<
"::ROOT::GenerateInitInstanceLocal((const " << csymbol <<
"*)0x0)->GetClass();\n"
2098 <<
" " << mappedname <<
"_TClassManip(theClass);\n";
2099 finalString <<
" return theClass;\n";
2100 finalString <<
" }\n\n";
2104 std::string manipString;
2105 std::string attribute_s;
2106 std::string attrName, attrValue;
2108 bool attrMapExtracted =
false;
2109 if (decl->hasAttrs()){
2111 for (clang::Decl::attr_iterator attrIt = decl->attr_begin();
2112 attrIt!=decl->attr_end();++attrIt){
2119 if (attrName ==
"name" ||
2120 attrName ==
"pattern" ||
2121 attrName ==
"rootmap")
continue;
2127 if (!attrMapExtracted){
2128 manipString+=
" theClass->CreateAttributeMap();\n";
2129 manipString+=
" TDictAttributeMap* attrMap( theClass->GetAttributeMap() );\n";
2130 attrMapExtracted=
true;
2132 manipString+=
" attrMap->AddProperty(\""+attrName +
"\",\""+attrValue+
"\");\n";
2138 for(clang::CXXRecordDecl::decl_iterator internalDeclIt = decl->decls_begin();
2139 internalDeclIt != decl->decls_end(); ++internalDeclIt){
2140 if (!(!(*internalDeclIt)->isImplicit()
2141 && (clang::isa<clang::FieldDecl>(*internalDeclIt) ||
2142 clang::isa<clang::VarDecl>(*internalDeclIt))))
continue;
2145 if (!internalDeclIt->hasAttrs())
continue;
2147 attrMapExtracted =
false;
2148 bool memberPtrCreated =
false;
2150 for (clang::Decl::attr_iterator attrIt = internalDeclIt->attr_begin();
2151 attrIt!=internalDeclIt->attr_end();++attrIt){
2159 clang::NamedDecl* namedInternalDecl = clang::dyn_cast<clang::NamedDecl> (*internalDeclIt);
2160 if (!namedInternalDecl) {
2164 const std::string memberName(namedInternalDecl->getName());
2165 const std::string cppMemberName=
"theMember_"+memberName;
2168 const std::string dataMemberCreation=
" TDataMember* "+cppMemberName+
" = theClass->GetDataMember(\""+memberName+
"\");\n";
2181 if (!memberPtrCreated){
2182 manipString+=dataMemberCreation;
2183 memberPtrCreated=
true;
2186 if (!attrMapExtracted){
2187 manipString+=
" "+cppMemberName+
"->CreateAttributeMap();\n";
2188 manipString+=
" TDictAttributeMap* memberAttrMap_"+memberName+
"( theMember_"+memberName+
"->GetAttributeMap() );\n";
2189 attrMapExtracted=
true;
2192 manipString+=
" memberAttrMap_"+memberName+
"->AddProperty(\""+attrName +
"\",\""+attrValue+
"\");\n";
2199 finalString <<
" static void " << mappedname <<
"_TClassManip(TClass* " << (manipString.empty() ?
"":
"theClass") <<
"){\n"
2204 finalString <<
"} // end of namespace ROOT" <<
"\n" <<
"\n";
2214 std::string &clsname,
2215 std::string &nsname,
2216 const clang::CXXRecordDecl *cl)
2226 auto ctxt = cl->getEnclosingNamespaceContext();
2227 while(ctxt && ctxt!=cl && ctxt->isInlineNamespace()) {
2228 ctxt = ctxt->getParent();
2231 const clang::NamedDecl *namedCtxt = llvm::dyn_cast<clang::NamedDecl>(ctxt);
2232 if (namedCtxt && namedCtxt!=cl) {
2233 const clang::NamespaceDecl *nsdecl = llvm::dyn_cast<clang::NamespaceDecl>(namedCtxt);
2234 if (nsdecl != 0 && !nsdecl->isAnonymousNamespace()) {
2236 clsname.erase (0, nsname.size() + 2);
2248 const clang::DeclContext *ctxt = cl.getDeclContext();
2249 while(ctxt && !ctxt->isNamespace()) {
2250 ctxt = ctxt->getParent();
2264 int closing_brackets = 0;
2268 if (ctxt && ctxt->isNamespace()) {
2273 const clang::NamespaceDecl *
ns = llvm::dyn_cast<clang::NamespaceDecl>(ctxt);
2276 out <<
"namespace " <<
ns->getNameAsString() <<
" {" << std::endl;
2280 return closing_brackets;
2294 clang::TemplateSpecializationKind kind = cl->getTemplateSpecializationKind();
2295 if (kind == clang::TSK_Undeclared ) {
2298 }
else if (kind == clang::TSK_ExplicitSpecialization) {
2312 const char *
name = which;
2313 const char *
proto =
"size_t";
2314 const char *protoPlacement =
"size_t,void*";
2317 const clang::FunctionDecl *operatornew
2320 cling::LookupHelper::NoDiagnostics);
2321 const clang::FunctionDecl *operatornewPlacement
2323 name, protoPlacement, interp,
2324 cling::LookupHelper::NoDiagnostics);
2326 const clang::DeclContext *ctxtnew = 0;
2327 const clang::DeclContext *ctxtnewPlacement = 0;
2330 ctxtnew = operatornew->getParent();
2332 if (operatornewPlacement) {
2333 ctxtnewPlacement = operatornewPlacement->getParent();
2339 operatornewPlacement
2344 ctxtnew = operatornew->getParent();
2346 if (operatornewPlacement) {
2347 ctxtnewPlacement = operatornewPlacement->getParent();
2350 if (ctxtnewPlacement == 0) {
2358 if (ctxtnew == ctxtnewPlacement) {
2362 const clang::CXXRecordDecl* clnew = llvm::dyn_cast<clang::CXXRecordDecl>(ctxtnew);
2363 const clang::CXXRecordDecl* clnewPlacement = llvm::dyn_cast<clang::CXXRecordDecl>(ctxtnewPlacement);
2364 if (clnew == 0 && clnewPlacement == 0) {
2370 if (clnew != 0 && clnewPlacement == 0) {
2374 if (clnew == 0 && clnewPlacement != 0) {
2379 if (clnew->isDerivedFrom(clnewPlacement)) {
2409 const clang::CXXRecordDecl *decl,
2410 const cling::Interpreter &interp,
2416 std::string mappedname;
2434 classname.insert(0,
"::");
2437 finalString <<
"namespace ROOT {" <<
"\n";
2442 finalString <<
" // Wrappers around operator new" <<
"\n";
2443 finalString <<
" static void *new_" << mappedname.c_str() <<
"(void *p) {" <<
"\n" <<
" return p ? ";
2445 finalString <<
"new(p) ";
2446 finalString << classname.c_str();
2447 finalString << args;
2448 finalString <<
" : ";
2450 finalString <<
"::new((::ROOT::Internal::TOperatorNewHelper*)p) ";
2451 finalString << classname.c_str();
2452 finalString << args;
2453 finalString <<
" : ";
2455 finalString <<
"new " << classname.c_str() << args <<
";" <<
"\n";
2456 finalString <<
" }" <<
"\n";
2460 finalString <<
" static void *newArray_";
2461 finalString << mappedname.c_str();
2462 finalString <<
"(Long_t nElements, void *p) {";
2463 finalString <<
"\n";
2464 finalString <<
" return p ? ";
2466 finalString <<
"new(p) ";
2467 finalString << classname.c_str();
2468 finalString <<
"[nElements] : ";
2470 finalString <<
"::new((::ROOT::Internal::TOperatorNewHelper*)p) ";
2471 finalString << classname.c_str();
2472 finalString <<
"[nElements] : ";
2474 finalString <<
"new ";
2475 finalString << classname.c_str();
2476 finalString <<
"[nElements];";
2477 finalString <<
"\n";
2478 finalString <<
" }";
2479 finalString <<
"\n";
2484 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";
2488 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";
2492 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";
2496 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";
2500 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";
2502 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";
2506 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";
2508 finalString <<
"} // end of namespace ROOT for class " << classname.c_str() <<
"\n" <<
"\n";
2515 const cling::Interpreter &interp,
2522 if (version == 0)
return;
2526 const clang::CXXRecordDecl *clxx = llvm::dyn_cast<clang::CXXRecordDecl>(cl.
GetRecordDecl());
2527 if (clxx == 0)
return;
2530 for(clang::CXXRecordDecl::base_class_const_iterator iter = clxx->bases_begin(), end = clxx->bases_end();
2536 Internal::RStl::Instance().GenerateTClassFor( iter->getType(), interp, normCtxt);
2541 for(clang::RecordDecl::field_iterator field_iter = clxx->field_begin(), end = clxx->field_end();
2545 std::string mTypename;
2551 if (!strcmp(shortTypeName,
"string")) {
2563 Internal::RStl::Instance().GenerateTClassFor(utype, interp, normCtxt);
2573 const clang::Type *rawtype =
m.getType()->getCanonicalTypeInternal().getTypePtr();
2574 if (rawtype->isArrayType()) {
2575 rawtype = rawtype->getBaseElementTypeUnsafe ();
2589 const clang::CXXRecordDecl* CRD = llvm::dyn_cast<clang::CXXRecordDecl>(cl);
2598 if (!funcCV)
return -1;
2601 if (funcCV == (clang::FunctionDecl*)-1)
return 1;
2616 using res_t = std::pair<bool, int>;
2618 const clang::CompoundStmt* FuncBody
2619 = llvm::dyn_cast_or_null<clang::CompoundStmt>(funcCV->getBody());
2621 return res_t{
false, -1};
2622 if (FuncBody->size() != 1) {
2626 return res_t{
false, -1};
2628 const clang::ReturnStmt* RetStmt
2629 = llvm::dyn_cast<clang::ReturnStmt>(FuncBody->body_back());
2631 return res_t{
false, -1};
2632 const clang::Expr* RetExpr = RetStmt->getRetValue();
2638 llvm::APSInt RetRes;
2639 if (!RetExpr->isIntegerConstantExpr(RetRes, funcCV->getASTContext()))
2640 return res_t{
false, -1};
2641 if (RetRes.isSigned()) {
2642 return res_t{
true, (
Version_t)RetRes.getSExtValue()};
2645 return res_t{
true, (
Version_t)RetRes.getZExtValue()};
2661 clang::QualType
type =
m.getType();
2673 clang::QualType
type = base.getType();
2686 const std::function<
void(
const clang::Module::Header &)> &closure,
2687 bool includeDirectlyUsedModules)
2696 const std::size_t publicHeaderIndex = 4;
2699 const std::size_t maxArrayLength = ((
sizeof module.Headers) / (
sizeof *
module.Headers));
2700 static_assert(publicHeaderIndex + 1 == maxArrayLength,
2701 "'Headers' has changed it's size, we need to update publicHeaderIndex");
2706 llvm::SetVector<const clang::Module *> modules;
2708 for (
size_t i = 0; i < modules.size(); ++i) {
2709 const clang::Module *M = modules[i];
2710 for (
const clang::Module *subModule : M->submodules())
2711 modules.insert(subModule);
2714 for (
const clang::Module *
m : modules) {
2715 if (includeDirectlyUsedModules) {
2716 for (clang::Module *used :
m->DirectUses) {
2721 for (std::size_t i = 0; i < publicHeaderIndex; i++) {
2722 auto &headerList =
m->Headers[i];
2723 for (
const clang::Module::Header &moduleHeader : headerList) {
2724 closure(moduleHeader);
2738 static char t[4096];
2739 static const char* constwd =
"const ";
2740 static const char* constwdend =
"const";
2745 for (
s=typeDesc;*
s;
s++) {
2748 if (lev==0 && *
s==
'*')
continue;
2749 if (lev==0 && (strncmp(constwd,
s,strlen(constwd))==0
2750 ||strcmp(constwdend,
s)==0 ) ) {
2751 s+=strlen(constwd)-1;
2754 if (lev==0 && *
s==
' ' && *(
s+1)!=
'*') { p = t;
continue;}
2755 if (p - t > (
long)
sizeof(t)) {
2756 printf(
"ERROR (rootcling): type name too long for StortTypeName: %s\n",
2769 const cling::Interpreter& interp)
2774 if (
comment[0] ==
'!')
return false;
2776 clang::QualType
type =
m.getType();
2778 if (
type->isReferenceType()) {
2783 std::string mTypeName =
type.getAsString(
m.getASTContext().getPrintingPolicy());
2784 if (!strcmp(mTypeName.c_str(),
"string") || !strcmp(mTypeName.c_str(),
"string*")) {
2787 if (!strcmp(mTypeName.c_str(),
"std::string") || !strcmp(mTypeName.c_str(),
"std::string*")) {
2795 const clang::Type *rawtype =
type.getTypePtr()->getBaseElementTypeUnsafe ();
2797 if (rawtype->isPointerType()) {
2799 clang::QualType pointee;
2800 while ( (pointee = rawtype->getPointeeType()) , pointee.getTypePtrOrNull() && pointee.getTypePtr() != rawtype)
2802 rawtype = pointee.getTypePtr();
2806 if (rawtype->isFundamentalType() || rawtype->isEnumeralType()) {
2811 const clang::CXXRecordDecl *cxxdecl = rawtype->getAsCXXRecordDecl();
2815 if (version > 0)
return true;
2831 clang::QualType pointee;
2832 while ( rawtype->isPointerType() && ((pointee = rawtype->getPointeeType()) , pointee.getTypePtrOrNull()) && pointee.getTypePtr() != rawtype)
2834 rawtype = pointee.getTypePtr();
2848 if (rawtype->isFundamentalType() || rawtype->isEnumeralType()) {
2852 return rawtype->getAsCXXRecordDecl();
2861 const cling::Interpreter &interp,
2863 std::ostream& dictStream,
2865 bool isGenreflex=
false)
2867 const clang::CXXRecordDecl* decl = llvm::dyn_cast<clang::CXXRecordDecl>(cl.
GetRecordDecl());
2869 if (!decl || !decl->isCompleteDefinition()) {
2873 std::string fullname;
2876 Internal::RStl::Instance().GenerateTClassFor(cl.
GetNormalizedName(), llvm::dyn_cast<clang::CXXRecordDecl>(cl.
GetRecordDecl()), interp, normCtxt);
2885 (*WriteStreamerFunc)(cl, interp, normCtxt, dictStream, isGenreflex || cl.RequestStreamerInfo());
2887 ROOT::TMetaUtils::Info(0,
"Class %s: Do not generate Streamer() [*** custom streamer ***]\n",fullname.c_str());
2909 const cling::Interpreter &interpreter,
2912 const clang::ASTContext& Ctx = interpreter.getCI()->getASTContext();
2914 clang::QualType originalType = instanceType;
2918 if (llvm::isa<clang::PointerType>(instanceType.getTypePtr())) {
2920 clang::Qualifiers quals = instanceType.getQualifiers();
2921 clang::QualType newPointee =
AddDefaultParameters(instanceType->getPointeeType(), interpreter, normCtxt);
2922 if (newPointee != instanceType->getPointeeType()) {
2923 instanceType = Ctx.getPointerType(newPointee);
2925 instanceType = Ctx.getQualifiedType(instanceType, quals);
2927 return instanceType;
2932 if (llvm::isa<clang::ReferenceType>(instanceType.getTypePtr())) {
2934 bool isLValueRefTy = llvm::isa<clang::LValueReferenceType>(instanceType.getTypePtr());
2935 clang::Qualifiers quals = instanceType.getQualifiers();
2936 clang::QualType newPointee =
AddDefaultParameters(instanceType->getPointeeType(), interpreter, normCtxt);
2938 if (newPointee != instanceType->getPointeeType()) {
2941 instanceType = Ctx.getLValueReferenceType(newPointee);
2943 instanceType = Ctx.getRValueReferenceType(newPointee);
2945 instanceType = Ctx.getQualifiedType(instanceType, quals);
2947 return instanceType;
2951 bool prefix_changed =
false;
2952 clang::NestedNameSpecifier* prefix = 0;
2953 clang::Qualifiers prefix_qualifiers = instanceType.getLocalQualifiers();
2954 const clang::ElaboratedType* etype
2955 = llvm::dyn_cast<clang::ElaboratedType>(instanceType.getTypePtr());
2958 prefix = AddDefaultParametersNNS(Ctx, etype->getQualifier(), interpreter, normCtxt);
2959 prefix_changed = prefix != etype->getQualifier();
2960 instanceType = clang::QualType(etype->getNamedType().getTypePtr(),0);
2966 const clang::TemplateSpecializationType* TST
2967 = llvm::dyn_cast<const clang::TemplateSpecializationType>(instanceType.getTypePtr());
2969 const clang::ClassTemplateSpecializationDecl* TSTdecl
2970 = llvm::dyn_cast_or_null<const clang::ClassTemplateSpecializationDecl>(instanceType.getTypePtr()->getAsCXXRecordDecl());
2982 bool mightHaveChanged =
false;
2983 if (TST && TSTdecl) {
2985 clang::Sema&
S = interpreter.getCI()->getSema();
2986 clang::TemplateDecl *Template = TSTdecl->getSpecializedTemplate()->getMostRecentDecl();
2987 clang::TemplateParameterList *Params = Template->getTemplateParameters();
2988 clang::TemplateParameterList::iterator Param = Params->
begin();
2992 unsigned int dropDefault = normCtxt.
GetConfig().DropDefaultArg(*Template);
2994 llvm::SmallVector<clang::TemplateArgument, 4> desArgs;
2995 unsigned int Idecl = 0, Edecl = TSTdecl->getTemplateArgs().size();
2996 unsigned int maxAddArg = TSTdecl->getTemplateArgs().size() - dropDefault;
2997 for(clang::TemplateSpecializationType::iterator
2998 I = TST->begin(),
E = TST->end();
3000 I!=
E ? ++
I : 0, ++Idecl, ++Param) {
3004 if (
I->getKind() == clang::TemplateArgument::Template) {
3005 clang::TemplateName templateName =
I->getAsTemplate();
3006 clang::TemplateDecl* templateDecl = templateName.getAsTemplateDecl();
3008 clang::DeclContext* declCtxt = templateDecl->getDeclContext();
3010 if (declCtxt && !templateName.getAsQualifiedTemplateName()){
3011 clang::NamespaceDecl*
ns = clang::dyn_cast<clang::NamespaceDecl>(declCtxt);
3012 clang::NestedNameSpecifier* nns;
3014 nns = cling::utils::TypeName::CreateNestedNameSpecifier(Ctx,
ns);
3015 }
else if (clang::TagDecl* TD = llvm::dyn_cast<clang::TagDecl>(declCtxt)) {
3016 nns = cling::utils::TypeName::CreateNestedNameSpecifier(Ctx,TD,
false );
3019 desArgs.push_back(*
I);
3022 clang::TemplateName templateNameWithNSS ( Ctx.getQualifiedTemplateName(nns,
false, templateDecl) );
3023 desArgs.push_back(clang::TemplateArgument(templateNameWithNSS));
3024 mightHaveChanged =
true;
3031 desArgs.push_back(*
I);
3035 clang::QualType SubTy =
I->getAsType();
3044 if (SubTy != newSubTy) {
3045 mightHaveChanged =
true;
3046 desArgs.push_back(clang::TemplateArgument(newSubTy));
3048 desArgs.push_back(*
I);
3051 }
else if (!isStdDropDefault && Idecl < maxAddArg) {
3053 mightHaveChanged =
true;
3055 const clang::TemplateArgument& templateArg
3056 = TSTdecl->getTemplateArgs().get(Idecl);
3058 desArgs.push_back(templateArg);
3061 clang::QualType SubTy = templateArg.getAsType();
3063 clang::SourceLocation TemplateLoc = Template->getSourceRange ().getBegin();
3064 clang::SourceLocation RAngleLoc = TSTdecl->getSourceRange().getBegin();
3066 clang::TemplateTypeParmDecl *TTP = llvm::dyn_cast<clang::TemplateTypeParmDecl>(*Param);
3069 cling::Interpreter::PushTransactionRAII clingRAII(
const_cast<cling::Interpreter*
>(&interpreter));
3070 clang::sema::HackForDefaultTemplateArg raii;
3071 bool HasDefaultArgs;
3072 clang::TemplateArgumentLoc ArgType =
S.SubstDefaultTemplateArgumentIfAvailable(
3081 if (ArgType.getArgument().isNull()
3084 "Template parameter substitution failed for %s around %s\n",
3085 instanceType.getAsString().c_str(), SubTy.getAsString().c_str());
3088 clang::QualType BetterSubTy = ArgType.getArgument().getAsType();
3089 SubTy = cling::utils::Transform::GetPartiallyDesugaredType(Ctx,BetterSubTy,normCtxt.
GetConfig(),
true);
3092 desArgs.push_back(clang::TemplateArgument(SubTy));
3101 if (mightHaveChanged) {
3102 instanceType = Ctx.getTemplateSpecializationType(TST->getTemplateName(),
3104 TST->getCanonicalTypeInternal());
3108 if (!prefix_changed && !mightHaveChanged)
return originalType;
3110 instanceType = Ctx.getElaboratedType(clang::ETK_None,prefix,instanceType);
3111 instanceType = Ctx.getQualifiedType(instanceType,prefix_qualifiers);
3113 return instanceType;
3133 llvm::StringRef title;
3136 if (clang::AnnotateAttr *
A =
m.getAttr<clang::AnnotateAttr>())
3137 title =
A->getAnnotation();
3149 if (errnum) *errnum =
VALID;
3151 if (title.size() == 0 || (title[0] !=
'['))
return llvm::StringRef();
3152 size_t rightbracket = title.find(
']');
3153 if (rightbracket == llvm::StringRef::npos)
return llvm::StringRef();
3155 std::string working;
3156 llvm::StringRef indexvar(title.data()+1,rightbracket-1);
3163 size_t indexvarlen = indexvar.size();
3164 for ( i=0; i<indexvarlen; i++) {
3165 if (!isspace(indexvar[i])) {
3166 working += indexvar[i];
3171 const char *tokenlist =
"*+-";
3172 char *current =
const_cast<char*
>(working.c_str());
3173 current = strtok(current,tokenlist);
3175 while (current!=0) {
3177 if (isdigit(current[0])) {
3178 for(i=0;i<strlen(current);i++) {
3179 if (!isdigit(current[i])) {
3184 if (errstr) *errstr = current;
3185 if (errnum) *errnum =
NOT_INT;
3186 return llvm::StringRef();
3192 const clang::CXXRecordDecl *parent_clxx = llvm::dyn_cast<clang::CXXRecordDecl>(
m.getDeclContext());
3193 const clang::FieldDecl *index1 = 0;
3195 index1 = GetDataMemberFromAll(*parent_clxx, current );
3197 if ( IsFieldDeclInt(index1) ) {
3203 for(clang::RecordDecl::field_iterator field_iter = parent_clxx->field_begin(), end = parent_clxx->field_end();
3207 if ( field_iter->getNameAsString() ==
m.getNameAsString() ) {
3213 if (errstr) *errstr = current;
3214 if (errnum) *errnum =
NOT_DEF;
3215 return llvm::StringRef();
3217 if ( field_iter->getNameAsString() == index1->getNameAsString() ) {
3225 if (errstr) *errstr = current;
3226 if (errnum) *errnum =
NOT_INT;
3227 return llvm::StringRef();
3232 index1 = GetDataMemberFromAllParents( *parent_clxx, current );
3234 if ( IsFieldDeclInt(index1) ) {
3241 if (errnum) *errnum =
NOT_INT;
3242 if (errstr) *errstr = current;
3246 if (errnum) *errnum =
NOT_INT;
3247 if (errstr) *errstr = current;
3248 return llvm::StringRef();
3250 if ( found && (index1->getAccess() == clang::AS_private) ) {
3253 if (errstr) *errstr = current;
3255 return llvm::StringRef();
3262 if (errstr) *errstr = indexvar;
3263 if (errnum) *errnum =
UNKNOWN;
3264 return llvm::StringRef();
3269 current = strtok(0,tokenlist);
3282 out.resize(strlen(in)*2);
3283 unsigned int i=0,j=0,
c;
3285 if (out.capacity() < (j+3)) {
3289 case '+': strcpy(
const_cast<char*
>(out.data())+j,
"pL"); j+=2;
break;
3290 case '-': strcpy(
const_cast<char*
>(out.data())+j,
"mI"); j+=2;
break;
3291 case '*': strcpy(
const_cast<char*
>(out.data())+j,
"mU"); j+=2;
break;
3292 case '/': strcpy(
const_cast<char*
>(out.data())+j,
"dI"); j+=2;
break;
3293 case '&': strcpy(
const_cast<char*
>(out.data())+j,
"aN"); j+=2;
break;
3294 case '%': strcpy(
const_cast<char*
>(out.data())+j,
"pE"); j+=2;
break;
3295 case '|': strcpy(
const_cast<char*
>(out.data())+j,
"oR"); j+=2;
break;
3296 case '^': strcpy(
const_cast<char*
>(out.data())+j,
"hA"); j+=2;
break;
3297 case '>': strcpy(
const_cast<char*
>(out.data())+j,
"gR"); j+=2;
break;
3298 case '<': strcpy(
const_cast<char*
>(out.data())+j,
"lE"); j+=2;
break;
3299 case '=': strcpy(
const_cast<char*
>(out.data())+j,
"eQ"); j+=2;
break;
3300 case '~': strcpy(
const_cast<char*
>(out.data())+j,
"wA"); j+=2;
break;
3301 case '.': strcpy(
const_cast<char*
>(out.data())+j,
"dO"); j+=2;
break;
3302 case '(': strcpy(
const_cast<char*
>(out.data())+j,
"oP"); j+=2;
break;
3303 case ')': strcpy(
const_cast<char*
>(out.data())+j,
"cP"); j+=2;
break;
3304 case '[': strcpy(
const_cast<char*
>(out.data())+j,
"oB"); j+=2;
break;
3305 case ']': strcpy(
const_cast<char*
>(out.data())+j,
"cB"); j+=2;
break;
3306 case '!': strcpy(
const_cast<char*
>(out.data())+j,
"nO"); j+=2;
break;
3307 case ',': strcpy(
const_cast<char*
>(out.data())+j,
"cO"); j+=2;
break;
3308 case '$': strcpy(
const_cast<char*
>(out.data())+j,
"dA"); j+=2;
break;
3309 case ' ': strcpy(
const_cast<char*
>(out.data())+j,
"sP"); j+=2;
break;
3310 case ':': strcpy(
const_cast<char*
>(out.data())+j,
"cL"); j+=2;
break;
3311 case '"': strcpy(
const_cast<char*
>(out.data())+j,
"dQ"); j+=2;
break;
3312 case '@': strcpy(
const_cast<char*
>(out.data())+j,
"aT"); j+=2;
break;
3313 case '\'': strcpy(
const_cast<char*
>(out.data())+j,
"sQ"); j+=2;
break;
3314 case '\\': strcpy(
const_cast<char*
>(out.data())+j,
"fI"); j+=2;
break;
3315 default: out[j++]=
c;
break;
3322 std::size_t firstNonNumber = out.find_first_not_of(
"0123456789");
3323 out.replace(0,firstNonNumber,
"");
3328static clang::SourceLocation
3330 clang::SourceLocation sourceLoc) {
3332 if (!sourceLoc.isFileID()) {
3333 return sourceManager.getExpansionRange(sourceLoc).second;
3342 const cling::Interpreter& interp)
3372 using namespace clang;
3373 SourceLocation headerLoc = decl.getLocation();
3375 static const char invalidFilename[] =
"";
3376 if (!headerLoc.isValid())
return invalidFilename;
3378 HeaderSearch& HdrSearch = interp.getCI()->getPreprocessor().getHeaderSearchInfo();
3380 SourceManager& sourceManager = decl.getASTContext().getSourceManager();
3382 FileID headerFID = sourceManager.getFileID(headerLoc);
3383 SourceLocation includeLoc
3385 sourceManager.getIncludeLoc(headerFID));
3387 const FileEntry *headerFE = sourceManager.getFileEntryForID(headerFID);
3388 while (includeLoc.isValid() && sourceManager.isInSystemHeader(includeLoc)) {
3389 const DirectoryLookup *foundDir = 0;
3392 assert(headerFE &&
"Couldn't find FileEntry from FID!");
3393 const FileEntry *FEhdr
3394 = HdrSearch.LookupFile(llvm::sys::path::filename(headerFE->getName()),
3397 ArrayRef<std::pair<const FileEntry *, const DirectoryEntry *>>(),
3404 headerFID = sourceManager.getFileID(includeLoc);
3405 headerFE = sourceManager.getFileEntryForID(headerFID);
3410 if (interp.getCI()->getLangOpts().Modules && !headerFE) {
3411 assert(decl.isFirstDecl() &&
"Couldn't trace back include from a decl"
3412 " that is not from an AST file");
3413 assert(StringRef(includeLoc.printToString(sourceManager)).startswith(
"<module-includes>"));
3417 sourceManager.getIncludeLoc(headerFID));
3420 if (!headerFE)
return invalidFilename;
3421 llvm::StringRef headerFileName = headerFE->getName();
3432 bool isAbsolute = llvm::sys::path::is_absolute(headerFileName);
3433 const FileEntry* FELong = 0;
3435 for (llvm::sys::path::const_iterator
3436 IDir = llvm::sys::path::begin(headerFileName),
3437 EDir = llvm::sys::path::end(headerFileName);
3438 !FELong && IDir != EDir; ++IDir) {
3444 size_t lenTrailing = headerFileName.size() - (IDir->data() - headerFileName.data());
3445 llvm::StringRef trailingPart(IDir->data(), lenTrailing);
3446 assert(trailingPart.data() + trailingPart.size()
3447 == headerFileName.data() + headerFileName.size()
3448 &&
"Mismatched partitioning of file name!");
3449 const DirectoryLookup* FoundDir = 0;
3450 FELong = HdrSearch.LookupFile(trailingPart, SourceLocation(),
3452 ArrayRef<std::pair<const FileEntry *, const DirectoryEntry *>>(),
3459 return invalidFilename;
3463 for (llvm::sys::path::reverse_iterator
3464 IDir = llvm::sys::path::rbegin(headerFileName),
3465 EDir = llvm::sys::path::rend(headerFileName);
3466 IDir != EDir; ++IDir) {
3467 size_t lenTrailing = headerFileName.size() - (IDir->data() - headerFileName.data());
3468 llvm::StringRef trailingPart(IDir->data(), lenTrailing);
3469 assert(trailingPart.data() + trailingPart.size()
3470 == headerFileName.data() + headerFileName.size()
3471 &&
"Mismatched partitioning of file name!");
3472 const DirectoryLookup* FoundDir = 0;
3475 if (HdrSearch.LookupFile(trailingPart, SourceLocation(),
3477 ArrayRef<std::pair<const FileEntry *, const DirectoryEntry *>>(),
3482 return trailingPart;
3486 return invalidFilename;
3492 const clang::QualType &qtype,
3493 const clang::ASTContext &astContext)
3495 std::string fqname = cling::utils::TypeName::GetFullyQualifiedName(qtype, astContext);
3504 const clang::QualType &qtype,
3505 const cling::Interpreter &interpreter)
3510 cling::Interpreter::PushTransactionRAII RAII(
const_cast<cling::Interpreter*
>(&interpreter));
3514 interpreter.getCI()->getASTContext());
3522 clang::ClassTemplateDecl*& ctd,
3523 clang::ClassTemplateSpecializationDecl*& ctsd)
3525 using namespace clang;
3526 const Type* theType = qt.getTypePtr();
3533 if (theType->isPointerType()) {
3537 if (
const RecordType* rType = llvm::dyn_cast<RecordType>(theType)) {
3538 ctsd = llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(rType->getDecl());
3540 ctd = ctsd->getSpecializedTemplate();
3545 if (
const SubstTemplateTypeParmType* sttpType = llvm::dyn_cast<SubstTemplateTypeParmType>(theType)){
3550 ctsd = llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(qt->getAsCXXRecordDecl());
3552 ctd = ctsd->getSpecializedTemplate();
3567 using namespace clang;
3568 ClassTemplateSpecializationDecl* ctsd;
3569 ClassTemplateDecl* ctd;
3583 using namespace clang;
3584 TemplateName theTemplateName;
3586 const Type* theType = qt.getTypePtr();
3588 if (
const TemplateSpecializationType* tst = llvm::dyn_cast_or_null<const TemplateSpecializationType>(theType)) {
3589 theTemplateName = tst->getTemplateName();
3592 theTemplateName = TemplateName(ctd);
3595 return theTemplateName;
3601 llvm::SmallVectorImpl<clang::TemplateArgument>& preceedingTArgs,
3602 const clang::NamedDecl& tPar,
3603 const cling::Interpreter& interp,
3607 using namespace clang;
3610 TemplateTypeParmDecl* ttpdPtr =
const_cast<TemplateTypeParmDecl*
>(llvm::dyn_cast<TemplateTypeParmDecl>(&tPar));
3611 if (!ttpdPtr)
return false;
3612 if (!ttpdPtr->hasDefaultArgument())
return false;
3615 QualType tParQualType = ttpdPtr->getDefaultArgument();
3616 const QualType tArgQualType = tArg.getAsType();
3623 if (tParQualType.getTypePtr() == tArgQualType.getTypePtr())
return true;
3634 const clang::ElaboratedType* etype
3635 = llvm::dyn_cast<clang::ElaboratedType>(tParQualType.getTypePtr());
3637 tParQualType = clang::QualType(etype->getNamedType().getTypePtr(),0);
3638 etype = llvm::dyn_cast<clang::ElaboratedType>(tParQualType.getTypePtr());
3641 const TemplateSpecializationType* tst =
3642 llvm::dyn_cast<TemplateSpecializationType>(tParQualType.getTypePtr());
3647 ClassTemplateSpecializationDecl* TSTdecl
3648 = llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(tArgQualType->getAsCXXRecordDecl());
3653 TemplateDecl *Template = tst->getTemplateName().getAsTemplateDecl();
3656 SourceLocation TemplateLoc = Template->getSourceRange ().getBegin();
3659 SourceLocation LAngleLoc = TSTdecl->getSourceRange().getBegin();
3664 TemplateArgument newArg = tArg;
3666 clang::Sema&
S = interp.getCI()->getSema();
3667 cling::Interpreter::PushTransactionRAII clingRAII(
const_cast<cling::Interpreter*
>(&interp));
3668 clang::sema::HackForDefaultTemplateArg raii;
3669 bool HasDefaultArgs;
3670 TemplateArgumentLoc defTArgLoc =
S.SubstDefaultTemplateArgumentIfAvailable(Template,
3678 newArg = defTArgLoc.getArgument();
3679 if (newArg.isNull() ||
3682 "Template parameter substitution failed!");
3685 ClassTemplateSpecializationDecl* nTSTdecl
3686 = llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(newArg.getAsType()->getAsCXXRecordDecl());
3689 isEqual = nTSTdecl->getMostRecentDecl() == TSTdecl->getMostRecentDecl() ||
3690 tParQualType.getTypePtr() == newArg.getAsType().getTypePtr();
3702 const clang::NamedDecl& tPar)
3704 using namespace clang;
3705 const NonTypeTemplateParmDecl* nttpdPtr = llvm::dyn_cast<NonTypeTemplateParmDecl>(&tPar);
3706 if (!nttpdPtr)
return false;
3707 const NonTypeTemplateParmDecl& nttpd = *nttpdPtr;
3709 if (!nttpd.hasDefaultArgument())
3713 llvm::APSInt defaultValueAPSInt(64,
false);
3714 if (Expr* defArgExpr = nttpd.getDefaultArgument()) {
3715 const ASTContext& astCtxt = nttpdPtr->getASTContext();
3716 defArgExpr->isIntegerConstantExpr(defaultValueAPSInt, astCtxt);
3719 const int value = tArg.getAsIntegral().getLimitedValue();
3722 return value == defaultValueAPSInt;
3732 using namespace clang;
3733 if (!nDecl)
return false;
3734 if (
const TemplateTypeParmDecl* ttpd = llvm::dyn_cast<TemplateTypeParmDecl>(nDecl))
3735 return ttpd->hasDefaultArgument();
3736 if (
const NonTypeTemplateParmDecl* nttpd = llvm::dyn_cast<NonTypeTemplateParmDecl>(nDecl))
3737 return nttpd->hasDefaultArgument();
3742static void KeepNParams(clang::QualType& normalizedType,
3743 const clang::QualType& vanillaType,
3744 const cling::Interpreter& interp,
3749 const clang::TemplateArgument &tArg,
3750 const cling::Interpreter& interp,
3752 const clang::ASTContext& astCtxt)
3755 using namespace clang;
3763 QualType thisNormQualType = normTArg.getAsType();
3764 QualType thisArgQualType = tArg.getAsType();
3769 normTArg = TemplateArgument(thisNormQualType);
3770 return (thisNormQualType != thisArgQualType);
3771 }
else if (normTArg.getKind() == clang::TemplateArgument::Pack) {
3772 assert( tArg.getKind() == clang::TemplateArgument::Pack );
3774 SmallVector<TemplateArgument, 2> desArgs;
3775 bool mightHaveChanged =
true;
3776 for (
auto I = normTArg.pack_begin(),
E = normTArg.pack_end(),
3777 FI = tArg.pack_begin(), FE = tArg.pack_end();
3778 I !=
E && FI != FE; ++
I, ++FI)
3780 TemplateArgument pack_arg(*
I);
3782 desArgs.push_back(pack_arg);
3784 if (mightHaveChanged) {
3785 ASTContext &mutableCtx(
const_cast<ASTContext&
>(astCtxt) );
3786 normTArg = TemplateArgument::CreatePackCopy(mutableCtx, desArgs);
3788 return mightHaveChanged;
3799 const clang::QualType& vanillaType,
3800 const cling::Interpreter& interp,
3804 using namespace clang;
3808 ClassTemplateSpecializationDecl* ctsd;
3809 ClassTemplateDecl* ctd;
3816 QualType originalNormalizedType = normalizedType;
3818 const ASTContext& astCtxt = ctsd->getASTContext();
3823 if (llvm::isa<clang::PointerType>(normalizedType.getTypePtr())) {
3825 clang::Qualifiers quals = normalizedType.getQualifiers();
3826 auto valNormalizedType = normalizedType->getPointeeType();
3827 KeepNParams(valNormalizedType,vanillaType, interp, normCtxt);
3828 normalizedType = astCtxt.getPointerType(valNormalizedType);
3830 normalizedType = astCtxt.getQualifiedType(normalizedType, quals);
3836 if (llvm::isa<clang::ReferenceType>(normalizedType.getTypePtr())) {
3838 bool isLValueRefTy = llvm::isa<clang::LValueReferenceType>(normalizedType.getTypePtr());
3839 clang::Qualifiers quals = normalizedType.getQualifiers();
3840 auto valNormType = normalizedType->getPointeeType();
3841 KeepNParams(valNormType, vanillaType, interp, normCtxt);
3845 normalizedType = astCtxt.getLValueReferenceType(valNormType);
3847 normalizedType = astCtxt.getRValueReferenceType(valNormType);
3849 normalizedType = astCtxt.getQualifiedType(normalizedType, quals);
3854 bool prefix_changed =
false;
3855 clang::NestedNameSpecifier* prefix =
nullptr;
3856 clang::Qualifiers prefix_qualifiers = normalizedType.getLocalQualifiers();
3857 const clang::ElaboratedType* etype
3858 = llvm::dyn_cast<clang::ElaboratedType>(normalizedType.getTypePtr());
3862 prefix = AddDefaultParametersNNS(astCtxt, etype->getQualifier(), interp, normCtxt);
3863 prefix_changed = prefix != etype->getQualifier();
3864 normalizedType = clang::QualType(etype->getNamedType().getTypePtr(),0);
3870 const clang::ClassTemplateDecl* ctdWithDefaultArgs = ctd;
3871 for (
const RedeclarableTemplateDecl* rd: ctdWithDefaultArgs->redecls()) {
3872 clang::TemplateParameterList* tpl = rd->getTemplateParameters();
3873 if (tpl->getMinRequiredArguments () < tpl->size())
3874 ctdWithDefaultArgs = llvm::dyn_cast<clang::ClassTemplateDecl>(rd);
3876 TemplateParameterList* tParsPtr = ctdWithDefaultArgs->getTemplateParameters();
3877 const TemplateParameterList& tPars = *tParsPtr;
3878 const TemplateArgumentList& tArgs = ctsd->getTemplateArgs();
3882 if (theTemplateName.isNull()) {
3883 normalizedType=originalNormalizedType;
3887 const TemplateSpecializationType* normalizedTst =
3888 llvm::dyn_cast<TemplateSpecializationType>(normalizedType.getTypePtr());
3889 if (!normalizedTst) {
3890 normalizedType=originalNormalizedType;
3894 const clang::ClassTemplateSpecializationDecl* TSTdecl
3895 = llvm::dyn_cast_or_null<const clang::ClassTemplateSpecializationDecl>(normalizedType.getTypePtr()->getAsCXXRecordDecl());
3903 llvm::SmallVector<TemplateArgument, 4> argsToKeep;
3905 const int nArgs = tArgs.size();
3906 const int nNormArgs = normalizedTst->getNumArgs();
3908 bool mightHaveChanged =
false;
3911 for (
int formal = 0, inst = 0; formal != nArgs; ++formal, ++inst) {
3912 const NamedDecl* tParPtr = tPars.getParam(formal);
3914 Error(
"KeepNParams",
"The parameter number %s is null.\n", formal);
3921 if (formal == nNormArgs || inst == nNormArgs)
break;
3923 const TemplateArgument& tArg = tArgs.get(formal);
3924 TemplateArgument normTArg(normalizedTst->getArgs()[inst]);
3927 if (isStdDropDefault) shouldKeepArg =
false;
3936 if ( tParPtr->isTemplateParameterPack() ) {
3941 for( ; inst != nNormArgs; ++inst) {
3942 normTArg = normalizedTst->getArgs()[inst];
3944 argsToKeep.push_back(normTArg);
3950 argsToKeep.push_back(normTArg);
3953 if (!isStdDropDefault) {
3955 mightHaveChanged =
true;
3965 auto argKind = tArg.getKind();
3968 equal =
areEqualTypes(tArg, argsToKeep, *tParPtr, interp, normCtxt);
3969 }
else if (argKind == clang::TemplateArgument::Integral){
3974 argsToKeep.push_back(normTArg);
3976 mightHaveChanged =
true;
3982 if (!prefix_changed && !mightHaveChanged) {
3983 normalizedType = originalNormalizedType;
3988 if (mightHaveChanged) {
3989 Qualifiers qualifiers = normalizedType.getLocalQualifiers();
3990 normalizedType = astCtxt.getTemplateSpecializationType(theTemplateName,
3992 normalizedType.getTypePtr()->getCanonicalTypeInternal());
3993 normalizedType = astCtxt.getQualifiedType(normalizedType, qualifiers);
3999 normalizedType = astCtxt.getElaboratedType(clang::ETK_None,prefix,normalizedType);
4000 normalizedType = astCtxt.getQualifiedType(normalizedType,prefix_qualifiers);
4014 clang::ASTContext &ctxt = interpreter.getCI()->getASTContext();
4017 cling::Interpreter::PushTransactionRAII RAII(
const_cast<cling::Interpreter*
>(&interpreter));
4018 clang::QualType normalizedType = cling::utils::Transform::GetPartiallyDesugaredType(ctxt,
type, normCtxt.
GetConfig(),
true );
4026 return normalizedType;
4040 if (
type.isNull()) {
4047 clang::ASTContext &ctxt = interpreter.getCI()->getASTContext();
4048 clang::PrintingPolicy policy(ctxt.getPrintingPolicy());
4049 policy.SuppressTagKeyword =
true;
4050 policy.SuppressScope =
true;
4051 policy.AnonymousTagLocations =
false;
4056 std::string normalizedNameStep1;
4059 cling::Interpreter::PushTransactionRAII clingRAII(
const_cast<cling::Interpreter*
>(&interpreter));
4060 normalizedType.getAsStringInternal(normalizedNameStep1,policy);
4070 if (norm_name.length()>2 && norm_name[0]==
':' && norm_name[1]==
':') {
4071 norm_name.erase(0,2);
4079 const clang::TypeDecl* typeDecl,
4080 const cling::Interpreter &interpreter)
4083 const clang::Sema &sema = interpreter.getSema();
4084 clang::ASTContext& astCtxt = sema.getASTContext();
4085 clang::QualType qualType = astCtxt.getTypeDeclType(typeDecl);
4094std::pair<std::string,clang::QualType>
4096 const cling::Interpreter &interpreter,
4100 std::string thisTypeName;
4104 if (!hasChanged)
return std::make_pair(thisTypeName,thisType);
4108 "Name changed from %s to %s\n", thisTypeName.c_str(), thisTypeNameForIO.c_str());
4111 auto& lookupHelper = interpreter.getLookupHelper();
4114 lookupHelper.findScope(thisTypeNameForIO,
4115 cling::LookupHelper::DiagSetting::NoDiagnostics,
4119 if (!typePtrForIO) {
4121 "Type not found: %s.",thisTypeNameForIO.c_str());
4124 clang::QualType typeForIO(typePtrForIO,0);
4127 if (!typeForIO->isRecordType()) {
4128 return std::make_pair(thisTypeNameForIO,typeForIO);
4131 auto thisDeclForIO = typeForIO->getAsCXXRecordDecl();
4132 if (!thisDeclForIO) {
4134 "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());
4135 return std::make_pair(thisTypeName,thisType);
4138 return std::make_pair(thisTypeNameForIO,typeForIO);
4144 const cling::Interpreter &interpreter,
4156 std::string dictFileName(moduleName);
4157 dictFileName +=
"_rdict.pcm";
4158 return dictFileName;
4162 llvm::errs() << llvm::StringRef(commentStart, 80) <<
'\n';
4188 clang::SourceManager& sourceManager = decl.getASTContext().getSourceManager();
4189 clang::SourceLocation sourceLocation = decl.getLocEnd();
4192 sourceLocation = sourceManager.getExpansionRange(sourceLocation).second;
4200 if (!decl.hasOwningModule() && sourceManager.isLoadedSourceLocation(sourceLocation)) {
4206 const char *commentStart = sourceManager.getCharacterData(sourceLocation, &invalid);
4210 bool skipToSemi =
true;
4211 if (
const clang::FunctionDecl* FD = clang::dyn_cast<clang::FunctionDecl>(&decl)) {
4212 if (FD->isImplicit()) {
4216 if (FD->isExplicitlyDefaulted() || FD->isDeletedAsWritten()) {
4220 }
else if (FD->doesThisDeclarationHaveABody()) {
4223 assert((decl.getLocEnd() != sourceLocation || *commentStart ==
'}'
4225 &&
"Expected macro or end of body at '}'");
4226 if (*commentStart) ++commentStart;
4229 while (*commentStart && isspace(*commentStart)
4230 && *commentStart !=
'\n' && *commentStart !=
'\r') {
4233 if (*commentStart ==
';') ++commentStart;
4237 }
else if (
const clang::EnumConstantDecl* ECD
4238 = clang::dyn_cast<clang::EnumConstantDecl>(&decl)) {
4240 if (ECD->getNextDeclInContext())
4241 while (*commentStart && *commentStart !=
',' && *commentStart !=
'\r' && *commentStart !=
'\n')
4249 while (*commentStart && *commentStart !=
';' && *commentStart !=
'\r' && *commentStart !=
'\n')
4251 if (*commentStart ==
';') ++commentStart;
4255 while ( *commentStart && isspace(*commentStart)
4256 && *commentStart !=
'\n' && *commentStart !=
'\r') {
4260 if (commentStart[0] !=
'/' ||
4261 (commentStart[1] !=
'/' && commentStart[1] !=
'*')) {
4271 unsigned int skipChars = 2;
4272 if (commentStart[0] ==
'/' &&
4273 commentStart[1] ==
'/' &&
4274 (commentStart[2] ==
'/' || commentStart[2] ==
'!') &&
4275 commentStart[3] ==
'<') {
4277 }
else if (commentStart[0] ==
'/' &&
4278 commentStart[1] ==
'*' &&
4279 (commentStart[2] ==
'*' || commentStart[2] ==
'!') &&
4280 commentStart[3] ==
'<') {
4284 commentStart += skipChars;
4287 while ( *commentStart && isspace(*commentStart)
4288 && *commentStart !=
'\n' && *commentStart !=
'\r') {
4291 const char* commentEnd = commentStart;
4293 while (*commentEnd && *commentEnd !=
'\n' && *commentEnd !=
'\r') {
4299 while (commentEnd > commentStart && isspace(commentEnd[-1])) {
4305 unsigned offset = commentStart - sourceManager.getCharacterData(sourceLocation);
4306 *loc = sourceLocation.getLocWithOffset(offset - 1);
4309 return llvm::StringRef(commentStart, commentEnd - commentStart);
4320 clang::SourceLocation *loc,
4321 const cling::Interpreter &interpreter)
4323 using namespace clang;
4324 SourceLocation commentSLoc;
4327 Sema& sema = interpreter.getCI()->getSema();
4329 const Decl* DeclFileLineDecl
4330 = interpreter.getLookupHelper().findFunctionProto(&decl,
"DeclFileLine",
"",
4331 cling::LookupHelper::NoDiagnostics);
4332 if (!DeclFileLineDecl)
return llvm::StringRef();
4335 SourceLocation maybeMacroLoc = DeclFileLineDecl->getLocation();
4336 bool isClassDefMacro = maybeMacroLoc.isMacroID() && sema.findMacroSpelling(maybeMacroLoc,
"ClassDef");
4337 if (isClassDefMacro) {
4346 return llvm::StringRef();
4358 if (rawtype->isElaboratedTypeSpecifier() ) {
4359 rawtype = rawtype->getCanonicalTypeInternal().getTypePtr();
4361 if (rawtype->isArrayType()) {
4362 rawtype =
type.getTypePtr()->getBaseElementTypeUnsafe ();
4364 if (rawtype->isPointerType() || rawtype->isReferenceType() ) {
4366 clang::QualType pointee;
4367 while ( (pointee = rawtype->getPointeeType()) , pointee.getTypePtrOrNull() && pointee.getTypePtr() != rawtype)
4369 rawtype = pointee.getTypePtr();
4371 if (rawtype->isElaboratedTypeSpecifier() ) {
4372 rawtype = rawtype->getCanonicalTypeInternal().getTypePtr();
4374 if (rawtype->isArrayType()) {
4375 rawtype = rawtype->getBaseElementTypeUnsafe ();
4379 if (rawtype->isArrayType()) {
4380 rawtype = rawtype->getBaseElementTypeUnsafe ();
4401 static const char *names[] =
4402 {
"shared_ptr",
"__shared_ptr",
4403 "vector",
"list",
"deque",
"map",
"multimap",
"set",
"multiset",
"bitset"};
4404 llvm::StringRef clname(cl.getName());
4405 for(
auto &&
name : names) {
4406 if (clname ==
name)
return true;
4416 const clang::CXXRecordDecl ¤tCl)
4419 if (&cl == ¤tCl)
return true;
4421 const clang::CXXRecordDecl* previous = currentCl.getPreviousDecl();
4424 if (NULL == previous){
4443 const clang::CXXRecordDecl *thisDecl =
4444 llvm::dyn_cast_or_null<clang::CXXRecordDecl>(lh.findScope(typ, cling::LookupHelper::WithDiagnostics));
4448 Error(
"IsOfType",
"Record decl of type %s not found in the AST.", typ.c_str());
4453 const clang::CXXRecordDecl *mostRecentDecl = thisDecl->getMostRecentDecl();
4486 using namespace clang;
4487 struct SearchTypedef:
public TypeVisitor<SearchTypedef, bool> {
4488 bool VisitTypedefType(
const TypedefType* TD) {
4491 bool VisitArrayType(
const ArrayType* AT) {
4492 return Visit(AT->getElementType().getTypePtr());
4494 bool VisitDecltypeType(
const DecltypeType* DT) {
4495 return Visit(DT->getUnderlyingType().getTypePtr());
4497 bool VisitPointerType(
const PointerType* PT) {
4498 return Visit(PT->getPointeeType().getTypePtr());
4500 bool VisitReferenceType(
const ReferenceType* RT) {
4501 return Visit(RT->getPointeeType().getTypePtr());
4503 bool VisitSubstTemplateTypeParmType(
const SubstTemplateTypeParmType* STST) {
4504 return Visit(STST->getReplacementType().getTypePtr());
4506 bool VisitTemplateSpecializationType(
const TemplateSpecializationType* TST) {
4507 for (
int I = 0,
N = TST->getNumArgs();
I <
N; ++
I) {
4508 const TemplateArgument& TA = TST->getArg(
I);
4510 && Visit(TA.getAsType().getTypePtr()))
4515 bool VisitTemplateTypeParmType(
const TemplateTypeParmType* TTPT) {
4518 bool VisitTypeOfType(
const TypeOfType* TOT) {
4519 return TOT->getUnderlyingType().getTypePtr();
4521 bool VisitElaboratedType(
const ElaboratedType* ET) {
4522 NestedNameSpecifier* NNS = ET->getQualifier();
4524 if (NNS->getKind() == NestedNameSpecifier::TypeSpec) {
4525 if (Visit(NNS->getAsType()))
4528 NNS = NNS->getPrefix();
4530 return Visit(ET->getNamedType().getTypePtr());
4551 using namespace llvm;
4552 using namespace clang;
4553 const clang::ASTContext &Ctxt =
instance->getAsCXXRecordDecl()->getASTContext();
4556 const clang::ElaboratedType* etype
4557 = llvm::dyn_cast<clang::ElaboratedType>(input.getTypePtr());
4561 clang::Qualifiers scope_qualifiers = input.getLocalQualifiers();
4562 assert(
instance->getAsCXXRecordDecl()!=0 &&
"ReSubstTemplateArg only makes sense with a type representing a class.");
4564 clang::NestedNameSpecifier *scope = ReSubstTemplateArgNNS(Ctxt,etype->getQualifier(),
instance);
4567 if (scope) subTy = Ctxt.getElaboratedType(clang::ETK_None,scope,subTy);
4568 subTy = Ctxt.getQualifiedType(subTy,scope_qualifiers);
4572 QualType QT = input;
4576 if (isa<clang::PointerType>(QT.getTypePtr())) {
4578 Qualifiers quals = QT.getQualifiers();
4581 if (nQT == QT->getPointeeType())
return QT;
4583 QT = Ctxt.getPointerType(nQT);
4585 QT = Ctxt.getQualifiedType(QT, quals);
4591 if (isa<ReferenceType>(QT.getTypePtr())) {
4593 bool isLValueRefTy = isa<LValueReferenceType>(QT.getTypePtr());
4594 Qualifiers quals = QT.getQualifiers();
4597 if (nQT == QT->getPointeeType())
return QT;
4601 QT = Ctxt.getLValueReferenceType(nQT);
4603 QT = Ctxt.getRValueReferenceType(nQT);
4605 QT = Ctxt.getQualifiedType(QT, quals);
4611 if (isa<clang::ArrayType>(QT.getTypePtr())) {
4613 Qualifiers quals = QT.getQualifiers();
4615 if (
const auto arr = dyn_cast<ConstantArrayType>(QT.getTypePtr())) {
4618 if (newQT == arr->getElementType())
return QT;
4619 QT = Ctxt.getConstantArrayType (newQT,
4621 arr->getSizeModifier(),
4622 arr->getIndexTypeCVRQualifiers());
4624 }
else if (
const auto arr = dyn_cast<DependentSizedArrayType>(QT.getTypePtr())) {
4627 if (newQT == QT)
return QT;
4628 QT = Ctxt.getDependentSizedArrayType (newQT,
4630 arr->getSizeModifier(),
4631 arr->getIndexTypeCVRQualifiers(),
4632 arr->getBracketsRange());
4634 }
else if (
const auto arr = dyn_cast<IncompleteArrayType>(QT.getTypePtr())) {
4637 if (newQT == arr->getElementType())
return QT;
4638 QT = Ctxt.getIncompleteArrayType (newQT,
4639 arr->getSizeModifier(),
4640 arr->getIndexTypeCVRQualifiers());
4642 }
else if (
const auto arr = dyn_cast<VariableArrayType>(QT.getTypePtr())) {
4645 if (newQT == arr->getElementType())
return QT;
4646 QT = Ctxt.getVariableArrayType (newQT,
4648 arr->getSizeModifier(),
4649 arr->getIndexTypeCVRQualifiers(),
4650 arr->getBracketsRange());
4654 QT = Ctxt.getQualifiedType(QT, quals);
4659 etype = llvm::dyn_cast<clang::ElaboratedType>(
instance);
4661 instance = etype->getNamedType().getTypePtr();
4665 const clang::TemplateSpecializationType* TST
4666 = llvm::dyn_cast<const clang::TemplateSpecializationType>(
instance);
4668 if (!TST)
return input;
4670 const clang::ClassTemplateSpecializationDecl* TSTdecl
4671 = llvm::dyn_cast_or_null<const clang::ClassTemplateSpecializationDecl>(
instance->getAsCXXRecordDecl());
4673 const clang::SubstTemplateTypeParmType *substType
4674 = llvm::dyn_cast<clang::SubstTemplateTypeParmType>(input.getTypePtr());
4678 const clang::ClassTemplateDecl *replacedCtxt = 0;
4680 const clang::DeclContext *replacedDeclCtxt = substType->getReplacedParameter()->getDecl()->getDeclContext();
4681 const clang::CXXRecordDecl *decl = llvm::dyn_cast<clang::CXXRecordDecl>(replacedDeclCtxt);
4682 unsigned int index = substType->getReplacedParameter()->getIndex();
4685 if (decl->getKind() == clang::Decl::ClassTemplatePartialSpecialization) {
4686 const clang::ClassTemplatePartialSpecializationDecl *
spec = llvm::dyn_cast<clang::ClassTemplatePartialSpecializationDecl>(decl);
4688 unsigned int depth = substType->getReplacedParameter()->getDepth();
4690 const TemplateArgument *instanceArgs =
spec->getTemplateArgs().data();
4691 unsigned int instanceNArgs =
spec->getTemplateArgs().size();
4695 for(
unsigned int A = 0;
A < instanceNArgs; ++
A) {
4697 clang::QualType argQualType = instanceArgs[
A].getAsType();
4699 const clang::TemplateTypeParmType *replacementType;
4701 replacementType = llvm::dyn_cast<clang::TemplateTypeParmType>(argQualType);
4703 if (!replacementType) {
4704 const clang::SubstTemplateTypeParmType *argType
4705 = llvm::dyn_cast<clang::SubstTemplateTypeParmType>(argQualType);
4707 clang::QualType replacementQT = argType->getReplacementType();
4708 replacementType = llvm::dyn_cast<clang::TemplateTypeParmType>(replacementQT);
4711 if (replacementType &&
4712 depth == replacementType->getDepth() &&
4713 index == replacementType->getIndex() )
4720 replacedCtxt =
spec->getSpecializedTemplate();
4722 replacedCtxt = decl->getDescribedClassTemplate();
4724 }
else if (
auto const declguide = llvm::dyn_cast<clang::CXXDeductionGuideDecl>(replacedDeclCtxt)) {
4725 replacedCtxt = llvm::dyn_cast<clang::ClassTemplateDecl>(declguide->getDeducedTemplate());
4726 }
else if (
auto const ctdecl = llvm::dyn_cast<clang::ClassTemplateDecl>(replacedDeclCtxt)) {
4727 replacedCtxt = ctdecl;
4729 std::string astDump;
4730 llvm::raw_string_ostream ostream(astDump);
4733 ROOT::TMetaUtils::Warning(
"ReSubstTemplateArg",
"Unexpected type of declaration context for template parameter: %s.\n\tThe responsible class is:\n\t%s\n",
4734 replacedDeclCtxt->getDeclKindName(), astDump.c_str());
4735 replacedCtxt =
nullptr;
4738 if ((replacedCtxt && replacedCtxt->getCanonicalDecl() == TSTdecl->getSpecializedTemplate()->getCanonicalDecl())
4740 substType->getReplacedParameter()->getDecl()
4741 == TSTdecl->getSpecializedTemplate ()->getTemplateParameters()->getParam(index))
4743 if ( index >= TST->getNumArgs() ) {
4750 return TST->getArg(index).getAsType();
4755 const clang::TemplateSpecializationType* inputTST
4756 = llvm::dyn_cast<const clang::TemplateSpecializationType>(input.getTypePtr());
4757 const clang::ASTContext& astCtxt = TSTdecl->getASTContext();
4760 bool mightHaveChanged =
false;
4761 llvm::SmallVector<clang::TemplateArgument, 4> desArgs;
4762 for(clang::TemplateSpecializationType::iterator
I = inputTST->begin(),
E = inputTST->end();
4765 desArgs.push_back(*
I);
4769 clang::QualType SubTy =
I->getAsType();
4771 if (llvm::isa<clang::SubstTemplateTypeParmType>(SubTy)
4772 || llvm::isa<clang::TemplateSpecializationType>(SubTy)) {
4774 mightHaveChanged = SubTy != newSubTy;
4775 if (!newSubTy.isNull()) {
4776 desArgs.push_back(clang::TemplateArgument(newSubTy));
4779 desArgs.push_back(*
I);
4783 if (mightHaveChanged) {
4784 clang::Qualifiers qualifiers = input.getLocalQualifiers();
4785 input = astCtxt.getTemplateSpecializationType(inputTST->getTemplateName(),
4787 inputTST->getCanonicalTypeInternal());
4788 input = astCtxt.getQualifiedType(input, qualifiers);
4800 if ( nArgsToRemove == 0 ||
name ==
"")
4805 const unsigned int length =
name.length();
4807 unsigned int nArgsRemoved=0;
4808 unsigned int nBraces=0;
4810 while (nArgsRemoved!=nArgsToRemove && cur<length){
4812 if (
c ==
'<') nBraces++;
4813 if (
c ==
'>') nBraces--;
4814 if (
c ==
',' && nBraces==1 ) nArgsRemoved++;
4828 static const char *stls[] =
4829 {
"any",
"vector",
"list",
"deque",
"map",
"multimap",
"set",
"multiset",
"bitset",
4830 "forward_list",
"unordered_set",
"unordered_multiset",
"unordered_map",
"unordered_multimap",0};
4843 for(
int k=1;stls[k];k++) {
if (
type.equals(stls[k]))
return values[k];}
4854 TND = TND->getMostRecentDecl();
4855 while (TND && !(TND->hasAttrs()))
4856 TND = TND->getPreviousDecl();
4868 TD = TD->getMostRecentDecl();
4869 while (TD && !(TD->hasAttrs() && TD->isThisDeclarationADefinition()))
4870 TD = TD->getPreviousDecl();
4879 std::list<std::pair<std::string,bool> >& enclosingNamespaces)
4881 const clang::DeclContext* enclosingNamespaceDeclCtxt = decl.getDeclContext();
4882 if (!enclosingNamespaceDeclCtxt)
return;
4884 const clang::NamespaceDecl* enclosingNamespace =
4885 clang::dyn_cast<clang::NamespaceDecl>(enclosingNamespaceDeclCtxt);
4886 if (!enclosingNamespace)
return;
4888 enclosingNamespaces.push_back(std::make_pair(enclosingNamespace->getNameAsString(),
4889 enclosingNamespace->isInline()));
4899 std::list<std::pair<std::string,bool> >& enclosingNamespaces)
4901 const clang::DeclContext* enclosingNamespaceDeclCtxt = ctxt.getParent ();
4904 if (!enclosingNamespaceDeclCtxt) {
4910 const clang::NamespaceDecl* enclosingNamespace = clang::dyn_cast<clang::NamespaceDecl>(enclosingNamespaceDeclCtxt);
4911 if (!enclosingNamespace)
return;
4914 enclosingNamespaces.push_back(std::make_pair(enclosingNamespace->getNameAsString(),
4915 enclosingNamespace->isInline()));
4926 std::list<std::pair<std::string,unsigned int> >& enclosingSc)
4928 const clang::DeclContext* enclosingDeclCtxt = decl.getDeclContext();
4929 if (!enclosingDeclCtxt)
return 0;
4931 unsigned int scopeType;
4933 if (
auto enclosingNamespacePtr =
4934 clang::dyn_cast<clang::NamespaceDecl>(enclosingDeclCtxt)){
4935 scopeType= enclosingNamespacePtr->isInline() ? 1 : 0;
4936 enclosingSc.push_back(std::make_pair(enclosingNamespacePtr->getNameAsString(),scopeType));
4940 if (
auto enclosingClassPtr =
4941 clang::dyn_cast<clang::RecordDecl>(enclosingDeclCtxt)){
4942 return enclosingClassPtr;
4955 std::string::size_type beginVar = 0;
4956 std::string::size_type endVar = 0;
4957 while ((beginVar = txt.find(
'$', beginVar)) != std::string::npos
4958 && beginVar + 1 < txt.length()) {
4959 std::string::size_type beginVarName = beginVar + 1;
4960 std::string::size_type endVarName = std::string::npos;
4961 if (txt[beginVarName] ==
'(') {
4963 endVarName = txt.find(
')', beginVarName);
4965 if (endVarName == std::string::npos) {
4967 varname, txt.c_str() + beginVar);
4970 endVar = endVarName + 1;
4973 beginVarName = beginVar + 1;
4974 endVarName = beginVarName;
4975 while (isalnum(txt[endVarName]) || txt[endVarName] ==
'_')
4977 endVar = endVarName;
4980 const char* val = getenv(txt.substr(beginVarName,
4981 endVarName - beginVarName).c_str());
4984 txt.replace(beginVar, endVar - beginVar, val);
4985 int lenval = strlen(val);
4986 int delta = lenval - (endVar - beginVar);
4990 beginVar = endVar + 1;
5002 const char* envInclPath = getenv(
"ROOT_INCLUDE_PATH");
5006 std::istringstream envInclPathsStream(envInclPath);
5007 std::string inclPath;
5008 while (std::getline(envInclPathsStream, inclPath,
':')) {
5011 if (!inclPath.empty()) {
5012 clingArgs.push_back(
"-I");
5013 clingArgs.push_back(inclPath);
5024 size_t start_pos = 0;
5029 while((start_pos = str.find(from, start_pos)) != std::string::npos) {
5030 str.replace(start_pos, from.length(), to);
5031 start_pos += to.length();
5032 if (recurse) changed =
true;
5048 if (theString.size() < theSubstring.size())
return false;
5049 const unsigned int theSubstringSize = theSubstring.size();
5050 return 0 == theString.compare(theString.size() - theSubstringSize,
5059 if (theString.size() < theSubstring.size())
return false;
5060 const unsigned int theSubstringSize = theSubstring.size();
5061 return 0 == theString.compare(0,
5074 if ((strstr(filename,
"LinkDef") || strstr(filename,
"Linkdef") ||
5075 strstr(filename,
"linkdef")) && strstr(filename,
".h")) {
5078 size_t len = strlen(filename);
5079 size_t linkdeflen = 9;
5081 if (0 == strncasecmp(filename + (len - linkdeflen),
"linkdef", linkdeflen - 2)
5082 && 0 == strcmp(filename + (len - 2),
".h")
5111 clang::Sema &sema = interp.getSema();
5112 cling::Transaction theTransaction(sema);
5113 std::set<clang::Decl *> addedDecls;
5114 for (
auto decl : decls) {
5116 clang::Decl *ncDecl =
const_cast<clang::Decl *
>(decl);
5117 theTransaction.append(ncDecl);
5119 std::string newFwdDecl;
5120 llvm::raw_string_ostream llvmOstr(newFwdDecl);
5121 interp.forwardDeclare(theTransaction, sema.getPreprocessor(), sema.getASTContext(), llvmOstr,
true,
nullptr, ignoreFiles);
5134 std::string& defString)
5146 std::string& defString)
5148 std::list<std::pair<std::string,unsigned int> > enclosingNamespaces;
5151 if (rcdPtr)
return rcdPtr;
5154 static const std::string scopeType [] = {
"namespace ",
"inline namespace ",
"class "};
5156 std::string scopeName;
5157 std::string scopeContent;
5158 unsigned int scopeIndex;
5159 for (
auto const & encScope : enclosingNamespaces){
5160 scopeIndex = encScope.second;
5161 scopeName = encScope.first;
5162 scopeContent =
" { " + defString +
" }";
5163 defString = scopeType[scopeIndex] +
5185 const clang::TemplateParameterList& tmplParamList,
5186 const cling::Interpreter& interpreter)
5189 for (
auto prmIt = tmplParamList.begin();
5190 prmIt != tmplParamList.end(); prmIt++){
5192 if (prmIt != tmplParamList.begin())
5193 templateArgs +=
", ";
5195 auto nDecl = *prmIt;
5196 std::string typeName;
5199 if (llvm::isa<clang::TemplateTypeParmDecl>(nDecl)){
5200 typeName =
"typename ";
5201 if (nDecl->isParameterPack())
5203 typeName += (*prmIt)->getNameAsString();
5206 else if (
auto nttpd = llvm::dyn_cast<clang::NonTypeTemplateParmDecl>(nDecl)){
5207 auto theType = nttpd->getType();
5210 if (theType.getAsString().find(
"enum") != std::string::npos){
5211 std::string astDump;
5212 llvm::raw_string_ostream ostream(astDump);
5213 nttpd->dump(ostream);
5215 ROOT::TMetaUtils::Warning(0,
"Forward declarations of templates with enums as template parameters. The responsible class is: %s\n", astDump.c_str());
5224 else if (
auto ttpd = llvm::dyn_cast<clang::TemplateTemplateParmDecl>(nDecl)){
5227 std::string astDump;
5228 llvm::raw_string_ostream ostream(astDump);
5229 ttpd->dump(ostream);
5231 ROOT::TMetaUtils::Error(0,
"Cannot reconstruct template template parameter forward declaration for %s\n", astDump.c_str());
5236 templateArgs += typeName;
5247 const cling::Interpreter& interpreter,
5248 std::string& defString)
5250 std::string templatePrefixString;
5251 auto tmplParamList= templDecl.getTemplateParameters();
5252 if (!tmplParamList){
5254 "Cannot extract template parameter list for %s",
5255 templDecl.getNameAsString().c_str());
5262 "Problems with arguments for forward declaration of class %s\n",
5263 templDecl.getNameAsString().c_str());
5266 templatePrefixString =
"template " + templatePrefixString +
" ";
5268 defString = templatePrefixString +
"class ";
5269 if (templDecl.isParameterPack())
5270 defString +=
"... ";
5271 defString += templDecl.getNameAsString();
5272 if (llvm::isa<clang::TemplateTemplateParmDecl>(&templDecl)) {
5286 std::string& argFwdDecl,
5287 const cling::Interpreter& interpreter,
5288 bool acceptStl=
false)
5296 auto argQualType = arg.getAsType();
5299 while (llvm::isa<clang::PointerType>(argQualType.getTypePtr())) argQualType = argQualType->getPointeeType();
5301 auto argTypePtr = argQualType.getTypePtr();
5304 if (llvm::isa<clang::EnumType>(argTypePtr)){
5309 if (llvm::isa<clang::BuiltinType>(argTypePtr)){
5314 if (
auto tdTypePtr = llvm::dyn_cast<clang::TypedefType>(argTypePtr)) {
5319 if (
auto argRecTypePtr = llvm::dyn_cast<clang::RecordType>(argTypePtr)){
5321 if (
auto argRecDeclPtr = argRecTypePtr->getDecl()){
5336 const cling::Interpreter& interpreter,
5337 std::string& defString,
5345 if (!recordDecl.getIdentifier())
5349 std::string argsFwdDecl;
5351 if (
auto tmplSpecDeclPtr = llvm::dyn_cast<clang::ClassTemplateSpecializationDecl>(&recordDecl)){
5352 std::string argFwdDecl;
5354 std::cout <<
"Class " << recordDecl.getNameAsString()
5355 <<
" is a template specialisation. Treating its arguments.\n";
5356 for(
auto arg : tmplSpecDeclPtr->getTemplateArgs().asArray()){
5359 std::cout <<
" o Template argument ";
5361 std::cout <<
"successfully treated. Arg fwd decl: " << argFwdDecl << std::endl;
5363 std::cout <<
"could not be treated. Abort fwd declaration generation.\n";
5370 argsFwdDecl+=argFwdDecl;
5374 defString=argsFwdDecl;
5379 if (
auto tmplDeclPtr = tmplSpecDeclPtr->getSpecializedTemplate()){
5382 defString = argsFwdDecl +
"\n" + defString;
5387 defString =
"class " + recordDecl.getNameAsString() +
";";
5388 const clang::RecordDecl* rcd =
EncloseInScopes(recordDecl, defString);
5396 defString = argsFwdDecl +
"\n" + defString;
5407 const cling::Interpreter& interpreter,
5408 std::string& fwdDeclString,
5409 std::unordered_set<std::string>* fwdDeclSetPtr)
5411 std::string buffer = tdnDecl.getNameAsString();
5412 std::string underlyingName;
5413 auto underlyingType = tdnDecl.getUnderlyingType().getCanonicalType();
5414 if (
const clang::TagType* TT
5415 = llvm::dyn_cast<clang::TagType>(underlyingType.getTypePtr())) {
5416 if (clang::NamedDecl* ND = TT->getDecl()) {
5417 if (!ND->getIdentifier()) {
5431 if (underlyingName.find(
">::") != std::string::npos)
5434 buffer=
"typedef "+underlyingName+
" "+buffer+
";";
5446 auto& ctxt = tdnDecl.getASTContext();
5447 auto immediatelyUnderlyingType = underlyingType.getSingleStepDesugaredType(ctxt);
5449 if (
auto underlyingTdnTypePtr = llvm::dyn_cast<clang::TypedefType>(immediatelyUnderlyingType.getTypePtr())){
5450 std::string tdnFwdDecl;
5451 auto underlyingTdnDeclPtr = underlyingTdnTypePtr->getDecl();
5456 if (!fwdDeclSetPtr || fwdDeclSetPtr->insert(tdnFwdDecl).second)
5457 fwdDeclString+=tdnFwdDecl;
5458 }
else if (
auto CXXRcdDeclPtr = immediatelyUnderlyingType->getAsCXXRecordDecl()){
5459 std::string classFwdDecl;
5461 std::cout <<
"Typedef " << tdnDecl.getNameAsString() <<
" hides a class: "
5462 << CXXRcdDeclPtr->getNameAsString() << std::endl;
5471 if (!fwdDeclSetPtr || fwdDeclSetPtr->insert(classFwdDecl).second)
5472 fwdDeclString+=classFwdDecl;
5475 fwdDeclString+=buffer;
5487 std::string& valAsString,
5488 const clang::PrintingPolicy& ppolicy)
5490 auto defArgExprPtr = par.getDefaultArg();
5491 auto& ctxt = par.getASTContext();
5492 if(!defArgExprPtr->isEvaluatable(ctxt)){
5496 auto defArgType = par.getType();
5499 if (defArgType->isBooleanType()){
5501 defArgExprPtr->EvaluateAsBooleanCondition (result,ctxt);
5502 valAsString=std::to_string(result);
5507 if (defArgType->isIntegerType()){
5508 llvm::APSInt result;
5509 defArgExprPtr->EvaluateAsInt(result,ctxt);
5510 auto uintVal = *result.getRawData();
5511 if (result.isNegative()){
5512 long long int intVal=uintVal*-1;
5513 valAsString=std::to_string(intVal);
5515 valAsString=std::to_string(uintVal);
5522 llvm::raw_string_ostream rso(valAsString);
5523 defArgExprPtr->printPretty(rso,
nullptr,ppolicy);
5524 valAsString = rso.str();
The file contains utilities which are foundational and could be used across the core component of ROO...
static std::string GetCppName(const CPPInstance *self)
static void indent(ostringstream &buf, int indent_level)
static bool RecurseKeepNParams(clang::TemplateArgument &normTArg, const clang::TemplateArgument &tArg, const cling::Interpreter &interp, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt, const clang::ASTContext &astCtxt)
static clang::SourceLocation getFinalSpellingLoc(clang::SourceManager &sourceManager, clang::SourceLocation sourceLoc)
const clang::DeclContext * GetEnclosingSpace(const clang::RecordDecl &cl)
bool IsTemplate(const clang::Decl &cl)
static void KeepNParams(clang::QualType &normalizedType, const clang::QualType &vanillaType, const cling::Interpreter &interp, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt)
This function allows to manipulate the number of arguments in the type of a template specialisation.
const clang::CXXMethodDecl * GetMethodWithProto(const clang::Decl *cinfo, const char *method, const char *proto, const cling::Interpreter &interp, bool diagnose)
int dumpDeclForAssert(const clang::Decl &D, const char *commentStart)
static void replaceEnvVars(const char *varname, std::string &txt)
Reimplementation of TSystem::ExpandPathName() that cannot be used from TMetaUtils.
static bool areEqualValues(const clang::TemplateArgument &tArg, const clang::NamedDecl &tPar)
std::cout << "Are equal values?\n";
ROOT::TMetaUtils::TNormalizedCtxtImpl TNCtxtFullQual
static bool isTypeWithDefault(const clang::NamedDecl *nDecl)
Check if this NamedDecl is a template parameter with a default argument.
static int TreatSingleTemplateArg(const clang::TemplateArgument &arg, std::string &argFwdDecl, const cling::Interpreter &interpreter, bool acceptStl=false)
static bool areEqualTypes(const clang::TemplateArgument &tArg, llvm::SmallVectorImpl< clang::TemplateArgument > &preceedingTArgs, const clang::NamedDecl &tPar, const cling::Interpreter &interp, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt)
static bool hasSomeTypedefSomewhere(const clang::Type *T)
void Error(const char *location, const char *msgfmt,...)
void Warning(const char *location, const char *msgfmt,...)
const_iterator begin() const
Type
enumeration specifying the integration types.
const std::string & GetPathSeparator()
void function(const Char_t *name_, T fun, const Char_t *docstring=0)
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
void WriteSchemaList(std::list< SchemaRuleMap_t > &rules, const std::string &listName, std::ostream &output)
Write schema rules.
std::map< std::string, ROOT::Internal::TSchemaType > MembersTypeMap_t
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"].
R__EXTERN SchemaRuleClassMap_t gReadRules
bool HasValidDataMembers(SchemaRuleMap_t &rule, MembersTypeMap_t &members, std::string &error_string)
Check if given rule contains references to valid data members.
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"...
R__EXTERN SchemaRuleClassMap_t gReadRawRules
RooArgSet S(const RooAbsArg &v1)
static Roo_reg_AGKInteg1D instance
ROOT::ESTLType STLKind(std::string_view type)
Converts STL container name to number.
bool IsStdClass(const char *type)
return true if the class belongs to the std namespace
std::string GetLong64_Name(const char *original)
Replace 'long long' and 'unsigned long long' by 'Long64_t' and 'ULong64_t'.
ROOT::ESTLType IsSTLCont(std::string_view type)
type : type name: vector<list<classA,allocator>,allocator> result: 0 : not stl container code of cont...
char * DemangleName(const char *mangled_name, int &errorCode)
std::string GetNameForIO(const std::string &templateInstanceName, TClassEdit::EModType mode=TClassEdit::kNone, bool *hasChanged=nullptr)
void GetNormalizedName(std::string &norm_name, std::string_view name)
Return the normalized name.
bool IsSTLBitset(const char *type)
Return true is the name is std::bitset<number> or bitset<number>
static constexpr double s
static constexpr double ns
constexpr Double_t E()
Base of natural log:
void ShortType(std::string &answer, int mode)
Return the absolute type of typeDesc into the string answ.
#define dest(otri, vertexptr)