24#include <unordered_set>
27#include "RConfigure.h"
35#include "clang/AST/ASTContext.h"
36#include "clang/AST/Attr.h"
37#include "clang/AST/CXXInheritance.h"
38#include "clang/AST/Decl.h"
39#include "clang/AST/DeclTemplate.h"
40#include "clang/AST/Mangle.h"
41#include "clang/AST/Type.h"
42#include "clang/AST/TypeVisitor.h"
43#include "clang/Frontend/CompilerInstance.h"
44#include "clang/Lex/HeaderSearch.h"
45#include "clang/Lex/ModuleMap.h"
46#include "clang/Lex/Preprocessor.h"
47#include "clang/Lex/PreprocessorOptions.h"
49#include "clang/Sema/Lookup.h"
50#include "clang/Sema/Sema.h"
51#include "clang/Sema/SemaDiagnostic.h"
53#include "cling/Interpreter/LookupHelper.h"
54#include "cling/Interpreter/Transaction.h"
55#include "cling/Interpreter/Interpreter.h"
56#include "cling/Utils/AST.h"
58#include "llvm/Support/Path.h"
59#include "llvm/Support/FileSystem.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();
84 using DeclsCont_t = TNormalizedCtxt::Config_t::SkipCollection;
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 nullptr;
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 nullptr;
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());
184static bool IsTypeInt(
const clang::Type *
type)
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 clang::ASTContext &
C = cl.getASTContext();
207 clang::DeclarationName DName = &
C.Idents.get(
what);
208 auto R = cl.lookup(DName);
209 for (
const clang::NamedDecl *D :
R)
210 if (auto FD =
llvm::dyn_cast<const
clang::FieldDecl>(D))
218static const clang::FieldDecl *GetDataMemberFromAllParents(clang::Sema &SemaR,
const clang::CXXRecordDecl &cl,
const char *
what)
220 clang::DeclarationName DName = &SemaR.Context.Idents.get(
what);
221 clang::LookupResult
R(SemaR, DName, clang::SourceLocation(),
222 clang::Sema::LookupOrdinaryName,
223 clang::Sema::ForExternalRedeclaration);
224 SemaR.LookupInSuper(
R, &
const_cast<clang::CXXRecordDecl&
>(cl));
227 return llvm::dyn_cast<const clang::FieldDecl>(
R.getFoundDecl());
231cling::LookupHelper::DiagSetting ToLHDS(
bool wantDiags) {
233 ? cling::LookupHelper::WithDiagnostics
234 : cling::LookupHelper::NoDiagnostics;
241namespace TMetaUtils {
250 Error(
"TNormalizedCtxt::AddTemplAndNargsToKeep",
251 "Tring to specify a number of template arguments to keep for a null pointer. Exiting without assigning any value.\n");
255 const clang::ClassTemplateDecl* canTempl = templ->getCanonicalDecl();
259 const std::string templateName (canTempl->getNameAsString());
260 const std::string i_str (std::to_string(i));
262 Error(
"TNormalizedCtxt::AddTemplAndNargsToKeep",
263 "Tring to specify for template %s %s arguments to keep, while before this number was %s\n",
264 canTempl->getNameAsString().c_str(),
266 previousArgsToKeep.c_str());
277 const clang::ClassTemplateDecl* constTempl = templ->getCanonicalDecl();
321 const std::string &normalizedName)
325 if (normalizedName.find(
"Double32_t") != std::string::npos
326 || normalizedName.find(
"Float16_t") != std::string::npos)
328 std::unique_ptr<clang::MangleContext> mangleCtx(rDecl->getASTContext().createMangleContext());
329 std::string mangledName;
331 llvm::raw_string_ostream sstr(mangledName);
332 if (
const clang::TypeDecl* TD = llvm::dyn_cast<clang::TypeDecl>(rDecl)) {
333 mangleCtx->mangleCXXRTTI(clang::QualType(TD->getTypeForDecl(), 0), sstr);
336 if (!mangledName.empty()) {
339 if (mangledName[0] ==
'\01')
340 mangledName.erase(0, 1);
342 if (!errDemangle && demangledTIName) {
343 static const char typeinfoNameFor[] =
" `RTTI Type Descriptor'";
344 if (strstr(demangledTIName, typeinfoNameFor)) {
345 std::string demangledName = demangledTIName;
346 demangledName.erase(demangledName.end() - strlen(typeinfoNameFor), demangledName.end());
349 if (!errDemangle && demangledTIName) {
350 static const char typeinfoNameFor[] =
"typeinfo for ";
351 if (!strncmp(demangledTIName, typeinfoNameFor, strlen(typeinfoNameFor))) {
352 std::string demangledName = demangledTIName + strlen(typeinfoNameFor);
354 free(demangledTIName);
355 return demangledName;
359 "Demangled typeinfo name '%s' does not contain `RTTI Type Descriptor'\n",
363 "Demangled typeinfo name '%s' does not start with 'typeinfo for'\n",
368 free(demangledTIName);
380 const clang::RecordDecl *decl,
383 bool rRequestNoInputOperator,
384 bool rRequestOnlyTClass,
385 int rRequestedVersionNumber,
386 int rRequestedRNTupleSerializationMode,
387 const cling::Interpreter &interpreter,
408 const clang::Type *requestedType,
409 const clang::RecordDecl *decl,
410 const char *requestName,
411 unsigned int nTemplateArgsToSkip,
414 bool rRequestNoInputOperator,
415 bool rRequestOnlyTClass,
416 int rRequestVersionNumber,
417 int rRequestedRNTupleSerializationMode,
418 const cling::Interpreter &interpreter,
423 fRequestStreamerInfo(rStreamerInfo),
424 fRequestNoStreamer(rNoStreamer),
425 fRequestNoInputOperator(rRequestNoInputOperator),
426 fRequestOnlyTClass(rRequestOnlyTClass),
427 fRequestedVersionNumber(rRequestVersionNumber),
428 fRequestedRNTupleSerializationMode(rRequestedRNTupleSerializationMode)
438 "Could not remove the requested template arguments.\n");
448 const clang::Type *requestedType,
449 const clang::RecordDecl *decl,
450 const char *requestName,
453 bool rRequestNoInputOperator,
454 bool rRequestOnlyTClass,
455 int rRequestVersionNumber,
456 int rRequestedRNTupleSerializationMode,
457 const cling::Interpreter &interpreter,
462 fRequestStreamerInfo(rStreamerInfo),
463 fRequestNoStreamer(rNoStreamer),
464 fRequestNoInputOperator(rRequestNoInputOperator),
465 fRequestOnlyTClass(rRequestOnlyTClass),
466 fRequestedVersionNumber(rRequestVersionNumber),
467 fRequestedRNTupleSerializationMode(rRequestedRNTupleSerializationMode)
483 const clang::RecordDecl *decl,
484 const char *requestName,
487 bool rRequestNoInputOperator,
488 bool rRequestOnlyTClass,
489 int rRequestVersionNumber,
490 int rRequestedRNTupleSerializationMode,
491 const cling::Interpreter &interpreter,
496 fRequestStreamerInfo(rStreamerInfo),
497 fRequestNoStreamer(rNoStreamer),
498 fRequestNoInputOperator(rRequestNoInputOperator),
499 fRequestOnlyTClass(rRequestOnlyTClass),
500 fRequestedVersionNumber(rRequestVersionNumber),
501 fRequestedRNTupleSerializationMode(rRequestedRNTupleSerializationMode)
511 if (requestName && requestName[0]) {
526 ExistingTypeCheck_t existingTypeCheck,
527 AutoParse_t autoParse,
528 bool *shuttingDownPtr,
529 const int* pgDebug ):
530 fInterpreter(&interpreter),fNormalizedCtxt(&normCtxt),
531 fExistingTypeCheck(existingTypeCheck),
532 fAutoParse(autoParse),
533 fInterpreterIsShuttingDownPtr(shuttingDownPtr),
545 if (tname.empty())
return false;
555 const cling::LookupHelper& lh =
fInterpreter->getLookupHelper();
556 clang::QualType t = lh.findType(nameLong, ToLHDS(
WantDiags()));
559 if (!
dest.isNull() && (
dest != t)) {
562 dest.getAsStringInternal(nameLong,
fInterpreter->getCI()->getASTContext().getPrintingPolicy());
570 const std::string &nameLong)
572 const cling::LookupHelper& lh =
fInterpreter->getLookupHelper();
573 clang::QualType t = lh.findType(nondef.c_str(), ToLHDS(
WantDiags()));
576 if (!
dest.isNull() && (
dest != t) &&
577 nameLong == t.getAsString(
fInterpreter->getCI()->getASTContext().getPrintingPolicy()))
587 const cling::LookupHelper& lh =
fInterpreter->getLookupHelper();
588 const clang::Decl *scope = lh.findScope(base.c_str(), ToLHDS(
WantDiags()),
nullptr);
595 const clang::NamespaceDecl *nsdecl = llvm::dyn_cast<clang::NamespaceDecl>(scope);
596 isInlined = nsdecl && nsdecl->isInline();
608 if (tname.empty())
return false;
625 const cling::LookupHelper& lh =
fInterpreter->getLookupHelper();
626 clang::QualType t = lh.findType(tname.c_str(), ToLHDS(
WantDiags()));
637 clang::PrintingPolicy policy(
fInterpreter->getCI()->getASTContext().getPrintingPolicy());
638 policy.SuppressTagKeyword =
true;
639 policy.SuppressScope =
true;
648 if (strncmp(
result.c_str(),
"const ", 6) == 0) {
651 if (dropstd && strncmp(
result.c_str()+
offset,
"std::", 5) == 0) {
654 for(
unsigned int i = 1; i<
result.length(); ++i) {
657 if (dropstd &&
result.compare(i,5,
"std::",5) == 0) {
666 }
else if ( (i+1) <
result.length() &&
704 clang::QualType toSkip = lh.findType(
name, cling::LookupHelper::WithDiagnostics);
705 if (
const clang::Type* T = toSkip.getTypePtr()) {
706 const clang::TypedefType *
tt = llvm::dyn_cast<clang::TypedefType>(T);
708 clang::Decl* D =
tt->getDecl();
709 fConfig.m_toSkip.insert(D);
711 clang::QualType canon = toSkip->getCanonicalTypeInternal();
712 fConfig.m_toReplace.insert(std::make_pair(canon.getTypePtr(),T));
714 fTypeWithAlternative.insert(T);
727 keepTypedef(lh,
"Double32_t");
728 keepTypedef(lh,
"Float16_t");
729 keepTypedef(lh,
"Long64_t",
true);
730 keepTypedef(lh,
"ULong64_t",
true);
732 clang::QualType toSkip = lh.findType(
"string", cling::LookupHelper::WithDiagnostics);
733 if (!toSkip.isNull()) {
734 if (
const clang::TypedefType* TT
735 = llvm::dyn_cast_or_null<clang::TypedefType>(toSkip.getTypePtr()))
736 fConfig.m_toSkip.insert(TT->getDecl());
738 toSkip = lh.findType(
"std::string", cling::LookupHelper::WithDiagnostics);
739 if (!toSkip.isNull()) {
740 if (
const clang::TypedefType* TT
741 = llvm::dyn_cast_or_null<clang::TypedefType>(toSkip.getTypePtr()))
742 fConfig.m_toSkip.insert(TT->getDecl());
744 clang::QualType canon = toSkip->getCanonicalTypeInternal();
745 fConfig.m_toReplace.insert(std::make_pair(canon.getTypePtr(),toSkip.getTypePtr()));
756 return (cl.getKind() == clang::Decl::ClassTemplatePartialSpecialization
757 || cl.getKind() == clang::Decl::ClassTemplateSpecialization);
764 const cling::Interpreter& interp)
766 clang::Sema* S = &interp.getSema();
767 const clang::NamedDecl* ND = cling::utils::Lookup::Named(S,
name, cl);
768 if (ND == (clang::NamedDecl*)-1)
769 return (clang::FunctionDecl*)-1;
770 return llvm::dyn_cast_or_null<clang::FunctionDecl>(ND);
776const clang::CXXRecordDecl *
778 bool ,
const clang::Type** resultType)
780 const cling::LookupHelper& lh = interp.getLookupHelper();
783 const clang::CXXRecordDecl *
result
784 = llvm::dyn_cast_or_null<clang::CXXRecordDecl>
785 (lh.findScope(
name, cling::LookupHelper::NoDiagnostics, resultType));
787 std::string std_name(
"std::");
791 result = llvm::dyn_cast_or_null<clang::CXXRecordDecl>
792 (lh.findScope(std_name, cling::LookupHelper::NoDiagnostics, resultType));
802 clang::QualType qType(cl->getTypeForDecl(),0);
810 clang::Sema& S = interp.getCI()->getSema();
813 cling::Interpreter::PushTransactionRAII RAII(
const_cast<cling::Interpreter*
>(&interp));
814 return S.RequireCompleteType(Loc, Type, clang::diag::err_incomplete_type);
820 const clang::CXXRecordDecl *context,
const cling::Interpreter &interp)
826 if (!cl->getDefinition() || !cl->isCompleteDefinition()) {
830 if (!CheckDefinition(cl, context) || !CheckDefinition(base, context)) {
834 if (!base->hasDefinition()) {
838 return cl->isDerivedFrom(base);
850 const clang::NamedDecl *base
854 return IsBase(CRD, llvm::dyn_cast<clang::CXXRecordDecl>( base ),
855 llvm::dyn_cast<clang::CXXRecordDecl>(
m.getDeclContext()),interp);
863 const clang::NamedDecl &forcontext,
864 const clang::QualType &qti,
865 const char *R__t,
int rwmode,
866 const cling::Interpreter &interp,
869 static const clang::CXXRecordDecl *TObject_decl
872 kBIT_ISTOBJECT = 0x10000000,
873 kBIT_HASSTREAMER = 0x20000000,
874 kBIT_ISSTRING = 0x40000000,
876 kBIT_ISPOINTER = 0x00001000,
877 kBIT_ISFUNDAMENTAL = 0x00000020,
878 kBIT_ISENUM = 0x00000008
881 const clang::Type &ti( * qti.getTypePtr() );
891 clang::CXXRecordDecl *cxxtype = rawtype->getAsCXXRecordDecl() ;
893 int isTObj = cxxtype && (
IsBase(cxxtype,TObject_decl,
nullptr,interp) || rawname ==
"TObject");
897 if (ti.isPointerType()) kase |= kBIT_ISPOINTER;
898 if (rawtype->isFundamentalType()) kase |= kBIT_ISFUNDAMENTAL;
899 if (rawtype->isEnumeralType()) kase |= kBIT_ISENUM;
902 if (isTObj) kase |= kBIT_ISTOBJECT;
903 if (isStre) kase |= kBIT_HASSTREAMER;
904 if (tiName ==
"string") kase |= kBIT_ISSTRING;
905 if (tiName ==
"string*") kase |= kBIT_ISSTRING;
909 tcl =
" internal error in rootcling ";
914 if (R__t) finalString <<
" " << tiName <<
" " << R__t <<
";" << std::endl;
917 case kBIT_ISFUNDAMENTAL:
919 finalString <<
" R__b >> " << R__t <<
";" << std::endl;
922 case kBIT_ISPOINTER|kBIT_ISTOBJECT|kBIT_HASSTREAMER:
924 finalString <<
" " << R__t <<
" = (" << tiName <<
")R__b.ReadObjectAny(" << tcl <<
");" << std::endl;
933 finalString <<
" Int_t readtemp;" << std::endl
934 <<
" R__b >> readtemp;" << std::endl
935 <<
" " << R__t <<
" = static_cast<" << tiName <<
">(readtemp);" << std::endl;
938 case kBIT_HASSTREAMER:
939 case kBIT_HASSTREAMER|kBIT_ISTOBJECT:
941 finalString <<
" " << R__t <<
".Streamer(R__b);" << std::endl;
944 case kBIT_HASSTREAMER|kBIT_ISPOINTER:
947 finalString <<
" if (R__b.GetInfo() && R__b.GetInfo()->GetOldVersion()<=3) {" << std::endl;
948 if (cxxtype && cxxtype->isAbstract()) {
949 finalString <<
" R__ASSERT(0);// " << objType <<
" is abstract. We assume that older file could not be produced using this streaming method." << std::endl;
951 finalString <<
" " << R__t <<
" = new " << objType <<
";" << std::endl
952 <<
" " << R__t <<
"->Streamer(R__b);" << std::endl;
954 finalString <<
" } else {" << std::endl
955 <<
" " << R__t <<
" = (" << tiName <<
")R__b.ReadObjectAny(" << tcl <<
");" << std::endl
956 <<
" }" << std::endl;
961 finalString <<
" {TString R__str;" << std::endl
962 <<
" R__str.Streamer(R__b);" << std::endl
963 <<
" " << R__t <<
" = R__str.Data();}" << std::endl;
966 case kBIT_ISSTRING|kBIT_ISPOINTER:
968 finalString <<
" {TString R__str;" << std::endl
969 <<
" R__str.Streamer(R__b);" << std::endl
970 <<
" " << R__t <<
" = new string(R__str.Data());}" << std::endl;
975 finalString <<
" " << R__t <<
" = (" << tiName <<
")R__b.ReadObjectAny(" << tcl <<
");" << std::endl;
980 finalString <<
" R__b.StreamObject(&" << R__t <<
"," << tcl <<
");" << std::endl;
988 case kBIT_ISFUNDAMENTAL:
989 case kBIT_ISPOINTER|kBIT_ISTOBJECT|kBIT_HASSTREAMER:
991 finalString <<
" R__b << " << R__t <<
";" << std::endl;
996 finalString <<
" { void *ptr_enum = (void*)&" << R__t <<
";\n";
997 finalString <<
" R__b >> *reinterpret_cast<Int_t*>(ptr_enum); }" << std::endl;
1000 case kBIT_HASSTREAMER:
1001 case kBIT_HASSTREAMER|kBIT_ISTOBJECT:
1002 if (!R__t)
return 0;
1003 finalString <<
" ((" << objType <<
"&)" << R__t <<
").Streamer(R__b);" << std::endl;
1006 case kBIT_HASSTREAMER|kBIT_ISPOINTER:
1007 if (!R__t)
return 1;
1008 finalString <<
" R__b.WriteObjectAny(" << R__t <<
"," << tcl <<
");" << std::endl;
1012 if (!R__t)
return 0;
1013 finalString <<
" {TString R__str(" << R__t <<
".c_str());" << std::endl
1014 <<
" R__str.Streamer(R__b);};" << std::endl;
1017 case kBIT_ISSTRING|kBIT_ISPOINTER:
1018 if (!R__t)
return 0;
1019 finalString <<
" {TString R__str(" << R__t <<
"->c_str());" << std::endl
1020 <<
" R__str.Streamer(R__b);}" << std::endl;
1023 case kBIT_ISPOINTER:
1024 if (!R__t)
return 1;
1025 finalString <<
" R__b.WriteObjectAny(" << R__t <<
"," << tcl <<
");" << std::endl;
1029 if (!R__t)
return 1;
1030 finalString <<
" R__b.StreamObject((" << objType <<
"*)&" << R__t <<
"," << tcl <<
");" << std::endl;
1042 clang::CXXRecordDecl* ncCl =
const_cast<clang::CXXRecordDecl*
>(cl);
1045 cling::Interpreter::PushTransactionRAII clingRAII(
const_cast<cling::Interpreter*
>(&interpreter));
1047 if (
auto* Ctor = interpreter.getCI()->getSema().LookupDefaultConstructor(ncCl)) {
1048 if (Ctor->getAccess() == clang::AS_public && !Ctor->isDeleted()) {
1061 const char *typeOfArg,
1062 const clang::CXXRecordDecl *expectedArgType,
1063 const cling::Interpreter& interpreter)
1065 if (typeOfArg && !expectedArgType) {
1066 const cling::LookupHelper& lh = interpreter.getLookupHelper();
1069 clang::QualType instanceType = lh.findType(typeOfArg, cling::LookupHelper::WithDiagnostics);
1070 if (!instanceType.isNull())
1071 expectedArgType = instanceType->getAsCXXRecordDecl();
1074 if (!expectedArgType)
1075 return EIOCtorCategory::kAbsent;
1078 cling::Interpreter::PushTransactionRAII clingRAII(
const_cast<cling::Interpreter*
>(&interpreter));
1079 for (
auto iter = cl->ctor_begin(), end = cl->ctor_end(); iter != end; ++iter)
1081 if ((iter->getAccess() != clang::AS_public) || (iter->getNumParams() != 1))
1085 clang::QualType argType((*iter->param_begin())->getType());
1086 argType = argType.getDesugaredType(cl->getASTContext());
1088 auto ioCtorCategory = EIOCtorCategory::kAbsent;
1089 if (argType->isPointerType()) {
1090 ioCtorCategory = EIOCtorCategory::kIOPtrType;
1091 argType = argType->getPointeeType();
1092 }
else if (argType->isReferenceType()) {
1093 ioCtorCategory = EIOCtorCategory::kIORefType;
1094 argType = argType.getNonReferenceType();
1098 argType = argType.getDesugaredType(cl->getASTContext());
1099 const clang::CXXRecordDecl *argDecl = argType->getAsCXXRecordDecl();
1101 if (argDecl->getCanonicalDecl() == expectedArgType->getCanonicalDecl()) {
1102 return ioCtorCategory;
1105 std::string realArg = argType.getAsString();
1106 std::string clarg(
"class ");
1108 if (realArg == clarg)
1109 return ioCtorCategory;
1113 return EIOCtorCategory::kAbsent;
1122 const cling::Interpreter& interpreter)
1124 const char *arg = ioctortype.
GetName();
1126 if (!ioctortype.
GetType() && (!arg || !arg[0])) {
1139 const char *method,
const char *
proto,
1140 const cling::Interpreter &interp,
1143 const clang::FunctionDecl* funcD
1144 = interp.getLookupHelper().findFunctionProto(cinfo, method,
proto,
1145 diagnose ? cling::LookupHelper::WithDiagnostics
1146 : cling::LookupHelper::NoDiagnostics);
1148 return llvm::dyn_cast<const clang::CXXMethodDecl>(funcD);
1157 namespace TMetaUtils {
1160 const cling::LookupHelper& lh = interp.getLookupHelper();
1163 clang::QualType instanceType = lh.findType(type_of_arg, cling::LookupHelper::WithDiagnostics);
1164 if (!instanceType.isNull())
1165 fArgType = instanceType->getAsCXXRecordDecl();
1179 const cling::Interpreter &interp)
1181 if (cl->isAbstract())
return false;
1183 for (
auto & ctorType : ctorTypes) {
1187 if (EIOCtorCategory::kAbsent == ioCtorCat)
1190 std::string
proto( ctorType.GetName() );
1191 bool defaultCtor =
proto.empty();
1197 if (EIOCtorCategory::kIOPtrType == ioCtorCat) {
1199 }
else if (EIOCtorCategory::kIORefType == ioCtorCat) {
1203 arg +=
")nullptr )";
1206 const clang::CXXMethodDecl *method
1208 cling::LookupHelper::NoDiagnostics);
1209 if (method && method->getAccess() != clang::AS_public) {
1223 const cling::Interpreter& interp)
1225 if (!cl)
return false;
1227 if (cl->hasUserDeclaredDestructor()) {
1229 cling::Interpreter::PushTransactionRAII clingRAII(
const_cast<cling::Interpreter*
>(&interp));
1230 clang::CXXDestructorDecl *
dest = cl->getDestructor();
1232 return (
dest->getAccess() == clang::AS_public);
1244 const char *methodname,
1246 const cling::Interpreter &interp,
1249 const clang::CXXMethodDecl *method
1251 diagnose ? cling::LookupHelper::WithDiagnostics
1252 : cling::LookupHelper::NoDiagnostics);
1253 return (method && method->getAccess() == clang::AS_public);
1264 const char *
proto =
"TDirectory*";
1265 const char *
name =
"DirectoryAutoAdd";
1279 const char *
proto =
"TCollection*,TFileMergeInfo*";
1280 const char *
name =
"Merge";
1293 const char *
proto =
"TCollection*";
1294 const char *
name =
"Merge";
1309 const char *
proto =
"TFileMergeInfo*";
1310 const char *
name =
"ResetAfterMerge";
1320 const clang::CXXRecordDecl* clxx,
1321 const cling::Interpreter &interp,
1324 static const char *
proto =
"TBuffer&";
1326 const clang::CXXMethodDecl *method
1328 cling::LookupHelper::NoDiagnostics);
1329 const clang::DeclContext *clxx_as_context = llvm::dyn_cast<clang::DeclContext>(clxx);
1331 return (method && method->getDeclContext() == clxx_as_context
1339 const clang::CXXRecordDecl* clxx,
1340 const cling::Interpreter &interp,
1343 static const char *
proto =
"TBuffer&,TClass*";
1345 const clang::CXXMethodDecl *method
1347 cling::LookupHelper::NoDiagnostics);
1348 const clang::DeclContext *clxx_as_context = llvm::dyn_cast<clang::DeclContext>(clxx);
1350 return (method && method->getDeclContext() == clxx_as_context
1380 clang::QualType qualType(&
type,0);
1412 llvm::raw_string_ostream stream(qual_name);
1413 clang::PrintingPolicy policy( cl.getASTContext().getPrintingPolicy() );
1414 policy.SuppressTagKeyword =
true;
1415 policy.SuppressUnwrittenScope =
true;
1417 cl.getNameForDiagnostic(stream,policy,
true);
1420 if ( qual_name ==
"(anonymous " || qual_name ==
"(unnamed" ) {
1421 size_t pos = qual_name.find(
':');
1422 qual_name.erase(0,pos+2);
1438 const clang::Type* declType ( recordDecl.getTypeForDecl() );
1439 clang::QualType qualType(declType,0);
1473 std::stringstream dims;
1474 std::string typenameStr;
1476 const clang::ASTContext& astContext = cl.getASTContext();
1479 for(clang::RecordDecl::field_iterator field_iter = cl.field_begin(), end = cl.field_end();
1487 typenameStr.clear();
1491 clang::QualType fieldType(field_iter->getType());
1492 if (fieldType->isConstantArrayType()) {
1493 const clang::ConstantArrayType *arrayType = llvm::dyn_cast<clang::ConstantArrayType>(fieldType.getTypePtr());
1495 dims <<
"[" << arrayType->getSize().getLimitedValue() <<
"]";
1496 fieldType = arrayType->getElementType();
1497 arrayType = llvm::dyn_cast<clang::ConstantArrayType>(arrayType->getArrayElementTypeNoTypeQual());
1507 for(clang::CXXRecordDecl::base_class_const_iterator iter = cl.bases_begin(), end = cl.bases_end();
1510 std::string basename( iter->getType()->getAsCXXRecordDecl()->getNameAsString() );
1520 const cling::Interpreter &interp,
1523 return interp.getLookupHelper().findFunctionProto(cinfo, method,
proto,
1524 diagnose ? cling::LookupHelper::WithDiagnostics
1525 : cling::LookupHelper::NoDiagnostics);
1559 clang::SourceLocation sourceLocation = decl->getLocation();
1560 clang::SourceManager& sourceManager = decl->getASTContext().getSourceManager();
1562 if (!sourceLocation.isValid() ) {
1566 if (!sourceLocation.isFileID()) {
1567 sourceLocation = sourceManager.getExpansionRange(sourceLocation).getEnd();
1570 if (sourceLocation.isValid() && sourceLocation.isFileID()) {
1571 return sourceManager.getLineNumber(sourceManager.getFileID(sourceLocation),sourceManager.getFileOffset(sourceLocation));
1584 while (llvm::isa<clang::PointerType>(instanceType.getTypePtr())
1585 || llvm::isa<clang::ReferenceType>(instanceType.getTypePtr()))
1587 instanceType = instanceType->getPointeeType();
1590 const clang::ElaboratedType* etype
1591 = llvm::dyn_cast<clang::ElaboratedType>(instanceType.getTypePtr());
1593 instanceType = clang::QualType(etype->getNamedType().getTypePtr(),0);
1606 const clang::CXXRecordDecl* clxx = instanceType->getAsCXXRecordDecl();
1607 if (clxx && clxx->getTemplateSpecializationKind() != clang::TSK_Undeclared) {
1609 const clang::TemplateSpecializationType* TST
1610 = llvm::dyn_cast<const clang::TemplateSpecializationType>(instanceType.getTypePtr());
1617 for (
const clang::TemplateArgument &
TA : TST->template_arguments()) {
1618 if (
TA.getKind() == clang::TemplateArgument::Type) {
1630 const cling::Interpreter &interp,
1633 const clang::CXXRecordDecl *clxx = llvm::dyn_cast<clang::CXXRecordDecl>(cl.
GetRecordDecl());
1634 if (!clxx || clxx->getTemplateSpecializationKind() == clang::TSK_Undeclared)
return false;
1636 clang::QualType instanceType = interp.getLookupHelper().findType(cl.
GetNormalizedName(),
1637 cling::LookupHelper::WithDiagnostics);
1638 if (instanceType.isNull()) {
1651 clang::AnnotateAttr* annAttr = clang::dyn_cast<clang::AnnotateAttr>(attribute);
1656 attrString = annAttr->getAnnotation().str();
1665 size_t substrFound (attributeStr.find(propNames::separator));
1666 if (substrFound==std::string::npos) {
1670 size_t EndPart1 = attributeStr.find_first_of(propNames::separator) ;
1671 attrName = attributeStr.substr(0, EndPart1);
1672 const int separatorLength(propNames::separator.
size());
1673 attrValue = attributeStr.substr(EndPart1 + separatorLength);
1681 std::string attrString;
1683 if (0!=ret)
return ret;
1691 const std::string& propName,
1692 std::string& propValue)
1694 for (clang::Decl::attr_iterator attrIt = decl.attr_begin();
1695 attrIt!=decl.attr_end();++attrIt){
1696 clang::AnnotateAttr* annAttr = clang::dyn_cast<clang::AnnotateAttr>(*attrIt);
1697 if (!annAttr)
continue;
1699 llvm::StringRef attribute = annAttr->getAnnotation();
1700 std::pair<llvm::StringRef,llvm::StringRef> split = attribute.split(propNames::separator.c_str());
1701 if (split.first != propName.c_str())
continue;
1703 propValue = split.second.str();
1714 const std::string& propName,
1717 for (clang::Decl::attr_iterator attrIt = decl.attr_begin();
1718 attrIt!=decl.attr_end();++attrIt){
1719 clang::AnnotateAttr* annAttr = clang::dyn_cast<clang::AnnotateAttr>(*attrIt);
1720 if (!annAttr)
continue;
1722 llvm::StringRef attribute = annAttr->getAnnotation();
1723 std::pair<llvm::StringRef,llvm::StringRef> split = attribute.split(propNames::separator.c_str());
1724 if (split.first != propName.c_str())
continue;
1726 return split.second.getAsInteger(10,propValue);
1737 const clang::CXXRecordDecl *decl,
1738 const cling::Interpreter &interp,
1741 bool& needCollectionProxy)
1745 std::string mappedname;
1747 std::string csymbol = classname;
1755 csymbol.insert(0,
"::");
1761 bool isStd = TMetaUtils::IsStdClass(*decl);
1762 const cling::LookupHelper& lh = interp.getLookupHelper();
1763 bool isString = TMetaUtils::IsOfType(*decl,
"std::string",lh);
1765 bool isStdNotString = isStd && !isString;
1767 finalString <<
"namespace ROOT {" <<
"\n";
1771 finalString <<
" static TClass *" << mappedname.c_str() <<
"_Dictionary();\n"
1772 <<
" static void " << mappedname.c_str() <<
"_TClassManip(TClass*);\n";
1778 finalString <<
" static void *new_" << mappedname.c_str() <<
"(void *p = nullptr);" <<
"\n";
1782 finalString <<
" static void *newArray_";
1783 finalString << mappedname.c_str();
1784 finalString <<
"(Long_t size, void *p);";
1785 finalString <<
"\n";
1790 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";
1793 finalString <<
" static void directoryAutoAdd_" << mappedname.c_str() <<
"(void *obj, TDirectory *dir);" <<
"\n";
1796 finalString <<
" static void streamer_" << mappedname.c_str() <<
"(TBuffer &buf, void *obj);" <<
"\n";
1799 finalString <<
" static void conv_streamer_" << mappedname.c_str() <<
"(TBuffer &buf, void *obj, const TClass*);" <<
"\n";
1802 finalString <<
" static Long64_t merge_" << mappedname.c_str() <<
"(void *obj, TCollection *coll,TFileMergeInfo *info);" <<
"\n";
1805 finalString <<
" static void reset_" << mappedname.c_str() <<
"(void *obj, TFileMergeInfo *info);" <<
"\n";
1812 ROOT::SchemaRuleClassMap_t::iterator rulesIt1 =
ROOT::gReadRules.find( classname.c_str() );
1813 ROOT::SchemaRuleClassMap_t::iterator rulesIt2 =
ROOT::gReadRawRules.find( classname.c_str() );
1824 finalString <<
"\n // Schema evolution read functions\n";
1825 std::list<ROOT::SchemaRuleMap_t>::iterator rIt = rulesIt1->second.begin();
1826 while( rIt != rulesIt1->second.end() ) {
1832 std::string error_string;
1834 Warning(
nullptr,
"%s", error_string.c_str());
1835 rIt = rulesIt1->second.erase(rIt);
1843 if( rIt->find(
"code" ) != rIt->end() ) {
1859 finalString <<
"\n // Schema evolution read raw functions\n";
1860 std::list<ROOT::SchemaRuleMap_t>::iterator rIt = rulesIt2->second.begin();
1861 while( rIt != rulesIt2->second.end() ) {
1867 std::string error_string;
1869 Warning(
nullptr,
"%s", error_string.c_str());
1870 rIt = rulesIt2->second.erase(rIt);
1878 if( rIt->find(
"code" ) == rIt->end() )
1886 finalString <<
"\n" <<
" // Function generating the singleton type initializer" <<
"\n";
1888 finalString <<
" static TGenericClassInfo *GenerateInitInstanceLocal(const " << csymbol <<
"*)" <<
"\n" <<
" {" <<
"\n";
1890 finalString <<
" " << csymbol <<
" *ptr = nullptr;" <<
"\n";
1894 finalString <<
" static ::TVirtualIsAProxy* isa_proxy = new ::TInstrumentedIsAProxy< " << csymbol <<
" >(nullptr);" <<
"\n";
1897 finalString <<
" static ::TVirtualIsAProxy* isa_proxy = new ::TIsAProxy(typeid(" << csymbol <<
"));" <<
"\n";
1899 finalString <<
" static ::ROOT::TGenericClassInfo " <<
"\n" <<
" instance(\"" << classname.c_str() <<
"\", ";
1902 finalString << csymbol <<
"::Class_Version(), ";
1904 finalString <<
"2, ";
1906 finalString <<
"-2, ";
1912 static const char *versionFunc =
"GetClassVersion";
1916 std::string
proto = classname +
"*";
1917 const clang::Decl* ctxt = llvm::dyn_cast<clang::Decl>((*cl).getDeclContext());
1918 const clang::FunctionDecl *methodinfo
1920 interp, cling::LookupHelper::NoDiagnostics);
1928 finalString <<
"GetClassVersion< ";
1929 finalString << classname.c_str();
1930 finalString <<
" >(), ";
1939 for (
unsigned int i=0; i<
filename.length(); i++) {
1944 <<
"," <<
"\n" <<
" typeid(" << csymbol
1945 <<
"), ::ROOT::Internal::DefineBehavior(ptr, ptr)," <<
"\n" <<
" ";
1948 finalString <<
"&" << csymbol <<
"::Dictionary, ";
1950 finalString <<
"&" << mappedname <<
"_Dictionary, ";
1954 TClassTable__kHasCustomStreamerMember = 0x10
1959 rootflag = rootflag | TClassTable__kHasCustomStreamerMember;
1961 finalString <<
"isa_proxy, " << rootflag <<
"," <<
"\n" <<
" sizeof(" << csymbol <<
") );" <<
"\n";
1963 finalString <<
" instance.SetNew(&new_" << mappedname.c_str() <<
");" <<
"\n";
1965 finalString <<
" instance.SetNewArray(&newArray_" << mappedname.c_str() <<
");" <<
"\n";
1968 finalString <<
" instance.SetDelete(&delete_" << mappedname.c_str() <<
");" <<
"\n" <<
" instance.SetDeleteArray(&deleteArray_" << mappedname.c_str() <<
");" <<
"\n" <<
" instance.SetDestructor(&destruct_" << mappedname.c_str() <<
");" <<
"\n";
1971 finalString <<
" instance.SetDirectoryAutoAdd(&directoryAutoAdd_" << mappedname.c_str() <<
");" <<
"\n";
1975 finalString <<
" instance.SetStreamerFunc(&streamer_" << mappedname.c_str() <<
");" <<
"\n";
1979 finalString <<
" instance.SetConvStreamerFunc(&conv_streamer_" << mappedname.c_str() <<
");" <<
"\n";
1982 finalString <<
" instance.SetMerge(&merge_" << mappedname.c_str() <<
");" <<
"\n";
1985 finalString <<
" instance.SetResetAfterMerge(&reset_" << mappedname.c_str() <<
");" <<
"\n";
1988 finalString <<
" instance.AdoptCollectionProxyInfo(TCollectionProxyInfo::Generate(TCollectionProxyInfo::" <<
"Pushback" <<
"<Internal::TStdBitsetHelper< " << classname.c_str() <<
" > >()));" <<
"\n";
1990 needCollectionProxy =
true;
1991 }
else if (stl != 0 &&
1994 int idx = classname.find(
"<");
1996 const char* methodTCP =
nullptr;
2002 methodTCP=
"Pushback";
2005 methodTCP=
"Pushfront";
2011 methodTCP=
"MapInsert";
2023 finalString <<
" instance.AdoptCollectionProxyInfo(TCollectionProxyInfo::Generate(TCollectionProxyInfo::" << methodTCP <<
"< " << classNameForIO.c_str() <<
" >()));" <<
"\n";
2025 needCollectionProxy =
true;
2033 finalString <<
"\n" <<
" instance.AdoptAlternate(::ROOT::AddClassAlternate(\""
2040 finalString <<
"\n" <<
" instance.AdoptAlternate(::ROOT::AddClassAlternate(\""
2050 finalString <<
"\n" <<
" ::ROOT::Internal::TSchemaHelper* rule;" <<
"\n";
2054 finalString <<
"\n" <<
" // the io read rules" <<
"\n" <<
" std::vector<::ROOT::Internal::TSchemaHelper> readrules(" << rulesIt1->second.size() <<
");" <<
"\n";
2056 finalString <<
" instance.SetReadRules( readrules );" <<
"\n";
2060 finalString <<
"\n" <<
" // the io read raw rules" <<
"\n" <<
" std::vector<::ROOT::Internal::TSchemaHelper> readrawrules(" << rulesIt2->second.size() <<
");" <<
"\n";
2062 finalString <<
" instance.SetReadRawRules( readrawrules );" <<
"\n";
2065 finalString <<
" return &instance;" <<
"\n" <<
" }" <<
"\n";
2069 finalString <<
" TGenericClassInfo *GenerateInitInstance(const " << csymbol <<
"*)" <<
"\n" <<
" {\n return GenerateInitInstanceLocal(static_cast<" << csymbol <<
"*>(nullptr));\n }" <<
"\n";
2072 finalString <<
" // Static variable to force the class initialization" <<
"\n";
2076 finalString <<
" static ::ROOT::TGenericClassInfo *_R__UNIQUE_DICT_(Init) = GenerateInitInstanceLocal(static_cast<const " << csymbol <<
"*>(nullptr)); R__UseDummy(_R__UNIQUE_DICT_(Init));" <<
"\n";
2079 finalString <<
"\n" <<
" // Dictionary for non-ClassDef classes" <<
"\n"
2080 <<
" static TClass *" << mappedname <<
"_Dictionary() {\n"
2081 <<
" TClass* theClass ="
2082 <<
"::ROOT::GenerateInitInstanceLocal(static_cast<const " << csymbol <<
"*>(nullptr))->GetClass();\n"
2083 <<
" " << mappedname <<
"_TClassManip(theClass);\n";
2084 finalString <<
" return theClass;\n";
2085 finalString <<
" }\n\n";
2089 std::string manipString;
2090 std::string attribute_s;
2091 std::string attrName, attrValue;
2093 bool attrMapExtracted =
false;
2094 if (decl->hasAttrs()){
2096 for (clang::Decl::attr_iterator attrIt = decl->attr_begin();
2097 attrIt!=decl->attr_end();++attrIt){
2104 if (attrName ==
"name" ||
2105 attrName ==
"pattern" ||
2106 attrName ==
"rootmap")
continue;
2112 if (!attrMapExtracted){
2113 manipString+=
" theClass->CreateAttributeMap();\n";
2114 manipString+=
" TDictAttributeMap* attrMap( theClass->GetAttributeMap() );\n";
2115 attrMapExtracted=
true;
2117 manipString+=
" attrMap->AddProperty(\""+attrName +
"\",\""+attrValue+
"\");\n";
2123 for(clang::CXXRecordDecl::decl_iterator internalDeclIt = decl->decls_begin();
2124 internalDeclIt != decl->decls_end(); ++internalDeclIt){
2125 if (!(!(*internalDeclIt)->isImplicit()
2126 && (clang::isa<clang::FieldDecl>(*internalDeclIt) ||
2127 clang::isa<clang::VarDecl>(*internalDeclIt))))
continue;
2130 if (!internalDeclIt->hasAttrs())
continue;
2132 attrMapExtracted =
false;
2133 bool memberPtrCreated =
false;
2135 for (clang::Decl::attr_iterator attrIt = internalDeclIt->attr_begin();
2136 attrIt!=internalDeclIt->attr_end();++attrIt){
2144 clang::NamedDecl* namedInternalDecl = clang::dyn_cast<clang::NamedDecl> (*internalDeclIt);
2145 if (!namedInternalDecl) {
2146 TMetaUtils::Error(
nullptr,
"Cannot convert field declaration to clang::NamedDecl");
2149 const std::string memberName(namedInternalDecl->getName());
2150 const std::string cppMemberName =
"theMember_"+memberName;
2153 const std::string dataMemberCreation=
" TDataMember* "+cppMemberName+
" = theClass->GetDataMember(\""+memberName+
"\");\n";
2162 if (attrName == propNames::comment ||
2163 attrName == propNames::iotype ||
2164 attrName == propNames::ioname )
continue;
2166 if (!memberPtrCreated){
2167 manipString+=dataMemberCreation;
2168 memberPtrCreated=
true;
2171 if (!attrMapExtracted){
2172 manipString+=
" "+cppMemberName+
"->CreateAttributeMap();\n";
2173 manipString+=
" TDictAttributeMap* memberAttrMap_"+memberName+
"( theMember_"+memberName+
"->GetAttributeMap() );\n";
2174 attrMapExtracted=
true;
2177 manipString+=
" memberAttrMap_"+memberName+
"->AddProperty(\""+attrName +
"\",\""+attrValue+
"\");\n";
2184 finalString <<
" static void " << mappedname <<
"_TClassManip(TClass* " << (manipString.empty() ?
"":
"theClass") <<
"){\n"
2189 finalString <<
"} // end of namespace ROOT" <<
"\n" <<
"\n";
2199 std::string &clsname,
2200 std::string &nsname,
2201 const clang::CXXRecordDecl *cl)
2211 auto ctxt = cl->getEnclosingNamespaceContext();
2212 while(ctxt && ctxt!=cl && ctxt->isInlineNamespace()) {
2213 ctxt = ctxt->getParent();
2216 const clang::NamedDecl *namedCtxt = llvm::dyn_cast<clang::NamedDecl>(ctxt);
2217 if (namedCtxt && namedCtxt!=cl) {
2218 const clang::NamespaceDecl *nsdecl = llvm::dyn_cast<clang::NamespaceDecl>(namedCtxt);
2219 if (nsdecl && !nsdecl->isAnonymousNamespace()) {
2221 clsname.erase (0, nsname.size() + 2);
2233 const clang::DeclContext *ctxt = cl.getDeclContext();
2234 while(ctxt && !ctxt->isNamespace()) {
2235 ctxt = ctxt->getParent();
2249 int closing_brackets = 0;
2253 if (ctxt && ctxt->isNamespace()) {
2255 const clang::NamespaceDecl *ns = llvm::dyn_cast<clang::NamespaceDecl>(ctxt);
2261 out <<
"namespace " << ns->getNameAsString() <<
" {" << std::endl;
2266 return closing_brackets;
2280 clang::TemplateSpecializationKind kind = cl->getTemplateSpecializationKind();
2281 if (kind == clang::TSK_Undeclared ) {
2284 }
else if (kind == clang::TSK_ExplicitSpecialization) {
2298 const char *
name = which;
2299 const char *
proto =
"size_t";
2300 const char *protoPlacement =
"size_t,void*";
2303 const clang::FunctionDecl *operatornew
2306 cling::LookupHelper::NoDiagnostics);
2307 const clang::FunctionDecl *operatornewPlacement
2309 name, protoPlacement, interp,
2310 cling::LookupHelper::NoDiagnostics);
2312 const clang::DeclContext *ctxtnew =
nullptr;
2313 const clang::DeclContext *ctxtnewPlacement =
nullptr;
2316 ctxtnew = operatornew->getParent();
2318 if (operatornewPlacement) {
2319 ctxtnewPlacement = operatornewPlacement->getParent();
2325 operatornewPlacement
2330 ctxtnew = operatornew->getParent();
2332 if (operatornewPlacement) {
2333 ctxtnewPlacement = operatornewPlacement->getParent();
2336 if (!ctxtnewPlacement) {
2344 if (ctxtnew == ctxtnewPlacement) {
2348 const clang::CXXRecordDecl* clnew = llvm::dyn_cast<clang::CXXRecordDecl>(ctxtnew);
2349 const clang::CXXRecordDecl* clnewPlacement = llvm::dyn_cast<clang::CXXRecordDecl>(ctxtnewPlacement);
2350 if (!clnew && !clnewPlacement) {
2356 if (clnew && !clnewPlacement) {
2360 if (!clnew && clnewPlacement) {
2365 if (clnew->isDerivedFrom(clnewPlacement)) {
2395 const clang::CXXRecordDecl *decl,
2396 const cling::Interpreter &interp,
2402 std::string mappedname;
2420 classname.insert(0,
"::");
2423 finalString <<
"namespace ROOT {" <<
"\n";
2428 finalString <<
" // Wrappers around operator new" <<
"\n";
2429 finalString <<
" static void *new_" << mappedname.c_str() <<
"(void *p) {" <<
"\n" <<
" return p ? ";
2431 finalString <<
"new(p) ";
2432 finalString << classname.c_str();
2433 finalString << args;
2434 finalString <<
" : ";
2436 finalString <<
"::new(static_cast<::ROOT::Internal::TOperatorNewHelper*>(p)) ";
2437 finalString << classname.c_str();
2438 finalString << args;
2439 finalString <<
" : ";
2441 finalString <<
"new " << classname.c_str() << args <<
";" <<
"\n";
2442 finalString <<
" }" <<
"\n";
2446 finalString <<
" static void *newArray_";
2447 finalString << mappedname.c_str();
2448 finalString <<
"(Long_t nElements, void *p) {";
2449 finalString <<
"\n";
2450 finalString <<
" return p ? ";
2452 finalString <<
"new(p) ";
2453 finalString << classname.c_str();
2454 finalString <<
"[nElements] : ";
2456 finalString <<
"::new(static_cast<::ROOT::Internal::TOperatorNewHelper*>(p)) ";
2457 finalString << classname.c_str();
2458 finalString <<
"[nElements] : ";
2460 finalString <<
"new ";
2461 finalString << classname.c_str();
2462 finalString <<
"[nElements];";
2463 finalString <<
"\n";
2464 finalString <<
" }";
2465 finalString <<
"\n";
2470 finalString <<
" // Wrapper around operator delete" <<
"\n" <<
" static void delete_" << mappedname.c_str() <<
"(void *p) {" <<
"\n" <<
" delete (static_cast<" << classname.c_str() <<
"*>(p));" <<
"\n" <<
" }" <<
"\n" <<
" static void deleteArray_" << mappedname.c_str() <<
"(void *p) {" <<
"\n" <<
" delete [] (static_cast<" << classname.c_str() <<
"*>(p));" <<
"\n" <<
" }" <<
"\n" <<
" static void destruct_" << mappedname.c_str() <<
"(void *p) {" <<
"\n" <<
" typedef " << classname.c_str() <<
" current_t;" <<
"\n" <<
" (static_cast<current_t*>(p))->~current_t();" <<
"\n" <<
" }" <<
"\n";
2474 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";
2478 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";
2482 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";
2486 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";
2488 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";
2492 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";
2494 finalString <<
"} // end of namespace ROOT for class " << classname.c_str() <<
"\n" <<
"\n";
2501 const cling::Interpreter &interp,
2508 if (version == 0)
return;
2512 const clang::CXXRecordDecl *clxx = llvm::dyn_cast<clang::CXXRecordDecl>(cl.
GetRecordDecl());
2516 for(clang::CXXRecordDecl::base_class_const_iterator iter = clxx->bases_begin(), end = clxx->bases_end();
2522 Internal::RStl::Instance().GenerateTClassFor( iter->getType(), interp, normCtxt);
2527 for(clang::RecordDecl::field_iterator field_iter = clxx->field_begin(), end = clxx->field_end();
2531 std::string mTypename;
2537 if (!strcmp(shortTypeName,
"string")) {
2549 Internal::RStl::Instance().GenerateTClassFor(utype, interp, normCtxt);
2559 const clang::Type *rawtype =
m.getType()->getCanonicalTypeInternal().getTypePtr();
2560 if (rawtype->isArrayType()) {
2561 rawtype = rawtype->getBaseElementTypeUnsafe ();
2575 const clang::CXXRecordDecl* CRD = llvm::dyn_cast<clang::CXXRecordDecl>(cl);
2584 if (!funcCV)
return -1;
2587 if (funcCV == (clang::FunctionDecl*)-1)
return 1;
2602 using res_t = std::pair<bool, int>;
2604 const clang::CompoundStmt* FuncBody
2605 = llvm::dyn_cast_or_null<clang::CompoundStmt>(funcCV->getBody());
2607 return res_t{
false, -1};
2608 if (FuncBody->size() != 1) {
2612 return res_t{
false, -1};
2614 const clang::ReturnStmt* RetStmt
2615 = llvm::dyn_cast<clang::ReturnStmt>(FuncBody->body_back());
2617 return res_t{
false, -1};
2618 const clang::Expr* RetExpr = RetStmt->getRetValue();
2624 if (
auto RetRes = RetExpr->getIntegerConstantExpr(funcCV->getASTContext())) {
2625 if (RetRes->isSigned())
2626 return res_t{
true, (
Version_t)RetRes->getSExtValue()};
2627 return res_t{
true, (
Version_t)RetRes->getZExtValue()};
2629 return res_t{
false, -1};
2645 clang::QualType
type =
m.getType();
2648 if (decl)
return TMetaUtils::IsSTLCont(*decl);
2657 clang::QualType
type = base.getType();
2660 if (decl)
return TMetaUtils::IsSTLCont(*decl);
2670 const std::function<
void(
const clang::Module::Header &)> &closure,
2671 bool includeDirectlyUsedModules)
2680 const std::size_t publicHeaderIndex = 4;
2683 const std::size_t maxArrayLength = ((
sizeof module.Headers) / (
sizeof *module.Headers));
2684 static_assert(publicHeaderIndex + 1 == maxArrayLength,
2685 "'Headers' has changed it's size, we need to update publicHeaderIndex");
2690 llvm::SetVector<const clang::Module *> modules;
2691 modules.insert(&module);
2692 for (
size_t i = 0; i < modules.size(); ++i) {
2693 const clang::Module *M = modules[i];
2694 for (
const clang::Module *subModule : M->submodules())
2695 modules.insert(subModule);
2698 for (
const clang::Module *
m : modules) {
2699 if (includeDirectlyUsedModules) {
2700 for (clang::Module *used :
m->DirectUses) {
2705 for (std::size_t i = 0; i < publicHeaderIndex; i++) {
2706 auto &headerList =
m->Headers[i];
2707 for (
const clang::Module::Header &moduleHeader : headerList) {
2708 closure(moduleHeader);
2722 static char t[4096];
2723 static const char* constwd =
"const ";
2724 static const char* constwdend =
"const";
2729 for (s=typeDesc;*s;s++) {
2732 if (lev==0 && *s==
'*')
continue;
2733 if (lev==0 && (strncmp(constwd,s,strlen(constwd))==0
2734 ||strcmp(constwdend,s)==0 ) ) {
2735 s+=strlen(constwd)-1;
2738 if (lev==0 && *s==
' ' && *(s+1)!=
'*') {
p = t;
continue;}
2739 if (
p - t > (
long)
sizeof(t)) {
2740 printf(
"ERROR (rootcling): type name too long for StortTypeName: %s\n",
2753 const cling::Interpreter& interp)
2758 if (!comment.empty() && comment[0] ==
'!')
2761 clang::QualType
type =
m.getType();
2763 if (
type->isReferenceType()) {
2768 std::string mTypeName =
type.getAsString(
m.getASTContext().getPrintingPolicy());
2769 if (!strcmp(mTypeName.c_str(),
"string") || !strcmp(mTypeName.c_str(),
"string*")) {
2772 if (!strcmp(mTypeName.c_str(),
"std::string") || !strcmp(mTypeName.c_str(),
"std::string*")) {
2780 const clang::Type *rawtype =
type.getTypePtr()->getBaseElementTypeUnsafe ();
2782 if (rawtype->isPointerType()) {
2784 clang::QualType pointee;
2785 while ( (pointee = rawtype->getPointeeType()) , pointee.getTypePtrOrNull() && pointee.getTypePtr() != rawtype)
2787 rawtype = pointee.getTypePtr();
2791 if (rawtype->isFundamentalType() || rawtype->isEnumeralType()) {
2796 const clang::CXXRecordDecl *cxxdecl = rawtype->getAsCXXRecordDecl();
2800 if (version > 0)
return true;
2813 const clang::Type *rawtype =
m.getType().getTypePtr();
2816 clang::QualType pointee;
2817 while ( rawtype->isPointerType() && ((pointee = rawtype->getPointeeType()) , pointee.getTypePtrOrNull()) && pointee.getTypePtr() != rawtype)
2819 rawtype = pointee.getTypePtr();
2833 if (rawtype->isFundamentalType() || rawtype->isEnumeralType()) {
2837 return rawtype->getAsCXXRecordDecl();
2846 const cling::Interpreter &interp,
2848 std::ostream& dictStream,
2850 bool isGenreflex=
false)
2852 const clang::CXXRecordDecl* decl = llvm::dyn_cast<clang::CXXRecordDecl>(cl.
GetRecordDecl());
2854 if (!decl || !decl->isCompleteDefinition()) {
2858 std::string fullname;
2861 Internal::RStl::Instance().GenerateTClassFor(cl.
GetNormalizedName(), llvm::dyn_cast<clang::CXXRecordDecl>(cl.
GetRecordDecl()), interp, normCtxt);
2870 (*WriteStreamerFunc)(cl, interp, normCtxt, dictStream, isGenreflex || cl.RequestStreamerInfo());
2872 ROOT::TMetaUtils::Info(
nullptr,
"Class %s: Do not generate Streamer() [*** custom streamer ***]\n",fullname.c_str());
2894 const cling::Interpreter &interpreter,
2897 const clang::ASTContext& Ctx = interpreter.getCI()->getASTContext();
2899 clang::QualType originalType = instanceType;
2903 if (llvm::isa<clang::PointerType>(instanceType.getTypePtr())) {
2905 clang::Qualifiers quals = instanceType.getQualifiers();
2906 clang::QualType newPointee =
AddDefaultParameters(instanceType->getPointeeType(), interpreter, normCtxt);
2907 if (newPointee != instanceType->getPointeeType()) {
2908 instanceType = Ctx.getPointerType(newPointee);
2910 instanceType = Ctx.getQualifiedType(instanceType, quals);
2912 return instanceType;
2917 if (llvm::isa<clang::ReferenceType>(instanceType.getTypePtr())) {
2919 bool isLValueRefTy = llvm::isa<clang::LValueReferenceType>(instanceType.getTypePtr());
2920 clang::Qualifiers quals = instanceType.getQualifiers();
2921 clang::QualType newPointee =
AddDefaultParameters(instanceType->getPointeeType(), interpreter, normCtxt);
2923 if (newPointee != instanceType->getPointeeType()) {
2926 instanceType = Ctx.getLValueReferenceType(newPointee);
2928 instanceType = Ctx.getRValueReferenceType(newPointee);
2930 instanceType = Ctx.getQualifiedType(instanceType, quals);
2932 return instanceType;
2936 bool prefix_changed =
false;
2937 clang::NestedNameSpecifier *prefix =
nullptr;
2938 clang::Qualifiers prefix_qualifiers = instanceType.getLocalQualifiers();
2939 const clang::ElaboratedType* etype
2940 = llvm::dyn_cast<clang::ElaboratedType>(instanceType.getTypePtr());
2943 prefix = AddDefaultParametersNNS(Ctx, etype->getQualifier(), interpreter, normCtxt);
2944 prefix_changed = prefix != etype->getQualifier();
2945 instanceType = clang::QualType(etype->getNamedType().getTypePtr(),0);
2951 const clang::TemplateSpecializationType* TST
2952 = llvm::dyn_cast<const clang::TemplateSpecializationType>(instanceType.getTypePtr());
2954 const clang::ClassTemplateSpecializationDecl* TSTdecl
2955 = llvm::dyn_cast_or_null<const clang::ClassTemplateSpecializationDecl>(instanceType.getTypePtr()->getAsCXXRecordDecl());
2967 bool mightHaveChanged =
false;
2968 if (TST && TSTdecl) {
2970 clang::Sema& S = interpreter.getCI()->getSema();
2971 clang::TemplateDecl *Template = TSTdecl->getSpecializedTemplate()->getMostRecentDecl();
2972 clang::TemplateParameterList *Params = Template->getTemplateParameters();
2973 clang::TemplateParameterList::iterator Param = Params->
begin();
2977 unsigned int dropDefault = normCtxt.
GetConfig().DropDefaultArg(*Template);
2979 llvm::SmallVector<clang::TemplateArgument, 4> desArgs;
2980 llvm::SmallVector<clang::TemplateArgument, 4> canonArgs;
2981 llvm::ArrayRef<clang::TemplateArgument> template_arguments = TST->template_arguments();
2982 unsigned int Idecl = 0, Edecl = TSTdecl->getTemplateArgs().size();
2983 unsigned int maxAddArg = TSTdecl->getTemplateArgs().size() - dropDefault;
2984 for (
const clang::TemplateArgument *
I = template_arguments.begin(), *E = template_arguments.end(); Idecl != Edecl;
2985 I != E ? ++
I :
nullptr, ++Idecl, ++Param) {
2989 if (
I->getKind() == clang::TemplateArgument::Template) {
2990 clang::TemplateName templateName =
I->getAsTemplate();
2991 clang::TemplateDecl* templateDecl = templateName.getAsTemplateDecl();
2993 clang::DeclContext* declCtxt = templateDecl->getDeclContext();
2995 if (declCtxt && !templateName.getAsQualifiedTemplateName()){
2996 clang::NamespaceDecl* ns = clang::dyn_cast<clang::NamespaceDecl>(declCtxt);
2997 clang::NestedNameSpecifier* nns;
2999 nns = cling::utils::TypeName::CreateNestedNameSpecifier(Ctx, ns);
3000 }
else if (clang::TagDecl* TD = llvm::dyn_cast<clang::TagDecl>(declCtxt)) {
3001 nns = cling::utils::TypeName::CreateNestedNameSpecifier(Ctx,TD,
false );
3004 desArgs.push_back(*
I);
3007 clang::TemplateName UnderlyingTN(templateDecl);
3008 if (clang::UsingShadowDecl *USD = templateName.getAsUsingShadowDecl())
3009 UnderlyingTN = clang::TemplateName(USD);
3010 clang::TemplateName templateNameWithNSS ( Ctx.getQualifiedTemplateName(nns,
false, UnderlyingTN) );
3011 desArgs.push_back(clang::TemplateArgument(templateNameWithNSS));
3012 mightHaveChanged =
true;
3018 if (
I->getKind() != clang::TemplateArgument::Type) {
3019 desArgs.push_back(*
I);
3023 clang::QualType SubTy =
I->getAsType();
3032 if (SubTy != newSubTy) {
3033 mightHaveChanged =
true;
3034 desArgs.push_back(clang::TemplateArgument(newSubTy));
3036 desArgs.push_back(*
I);
3039 }
else if (!isStdDropDefault && Idecl < maxAddArg) {
3041 mightHaveChanged =
true;
3043 const clang::TemplateArgument& templateArg
3044 = TSTdecl->getTemplateArgs().get(Idecl);
3045 if (templateArg.getKind() != clang::TemplateArgument::Type) {
3046 desArgs.push_back(templateArg);
3049 clang::QualType SubTy = templateArg.getAsType();
3051 clang::SourceLocation TemplateLoc = Template->getSourceRange ().getBegin();
3052 clang::SourceLocation RAngleLoc = TSTdecl->getSourceRange().getBegin();
3054 clang::TemplateTypeParmDecl *TTP = llvm::dyn_cast<clang::TemplateTypeParmDecl>(*Param);
3057 cling::Interpreter::PushTransactionRAII clingRAII(
const_cast<cling::Interpreter*
>(&interpreter));
3058 bool HasDefaultArgs;
3059 clang::TemplateArgumentLoc ArgType = S.SubstDefaultTemplateArgumentIfAvailable(
3069 if (ArgType.getArgument().isNull()
3070 || ArgType.getArgument().getKind() != clang::TemplateArgument::Type) {
3072 "Template parameter substitution failed for %s around %s\n",
3073 instanceType.getAsString().c_str(), SubTy.getAsString().c_str());
3076 clang::QualType BetterSubTy = ArgType.getArgument().getAsType();
3077 SubTy = cling::utils::Transform::GetPartiallyDesugaredType(Ctx,BetterSubTy,normCtxt.
GetConfig(),
true);
3080 desArgs.push_back(clang::TemplateArgument(SubTy));
3089 if (mightHaveChanged) {
3090 instanceType = Ctx.getTemplateSpecializationType(TST->getTemplateName(),
3092 TST->getCanonicalTypeInternal());
3096 if (!prefix_changed && !mightHaveChanged)
return originalType;
3098 instanceType = Ctx.getElaboratedType(clang::ElaboratedTypeKeyword::None, prefix, instanceType);
3099 instanceType = Ctx.getQualifiedType(instanceType,prefix_qualifiers);
3101 return instanceType;
3121 llvm::StringRef title;
3124 if (clang::AnnotateAttr *A =
m.getAttr<clang::AnnotateAttr>())
3125 title = A->getAnnotation();
3137 if (errnum) *errnum =
VALID;
3139 if (title.size() == 0 || (title[0] !=
'['))
return llvm::StringRef();
3140 size_t rightbracket = title.find(
']');
3141 if (rightbracket == llvm::StringRef::npos)
return llvm::StringRef();
3143 std::string working;
3144 llvm::StringRef indexvar(title.data()+1,rightbracket-1);
3151 size_t indexvarlen = indexvar.size();
3152 for ( i=0; i<indexvarlen; i++) {
3153 if (!isspace(indexvar[i])) {
3154 working += indexvar[i];
3159 const char *tokenlist =
"*+-";
3160 char *current =
const_cast<char*
>(working.c_str());
3161 current = strtok(current,tokenlist);
3165 if (isdigit(current[0])) {
3166 for(i=0;i<strlen(current);i++) {
3167 if (!isdigit(current[i])) {
3172 if (errstr) *errstr = current;
3173 if (errnum) *errnum =
NOT_INT;
3174 return llvm::StringRef();
3179 const clang::CXXRecordDecl *parent_clxx = llvm::dyn_cast<clang::CXXRecordDecl>(
m.getDeclContext());
3180 const clang::FieldDecl *index1 =
nullptr;
3182 index1 = GetDataMemberFromAll(*parent_clxx, current );
3184 if ( IsFieldDeclInt(index1) ) {
3189 for(clang::RecordDecl::field_iterator field_iter = parent_clxx->field_begin(), end = parent_clxx->field_end();
3193 if ( field_iter->getNameAsString() ==
m.getNameAsString() ) {
3199 if (errstr) *errstr = current;
3200 if (errnum) *errnum =
NOT_DEF;
3201 return llvm::StringRef();
3203 if ( field_iter->getNameAsString() == index1->getNameAsString() ) {
3211 if (errstr) *errstr = current;
3212 if (errnum) *errnum =
NOT_INT;
3213 return llvm::StringRef();
3220 clang::Sema& SemaR =
const_cast<cling::Interpreter&
>(interp).getSema();
3221 index1 = GetDataMemberFromAllParents(SemaR, *parent_clxx, current);
3224 if ( IsFieldDeclInt(index1) ) {
3231 if (errnum) *errnum =
NOT_INT;
3232 if (errstr) *errstr = current;
3236 if (errnum) *errnum =
NOT_INT;
3237 if (errstr) *errstr = current;
3238 return llvm::StringRef();
3240 if ( found && (index1->getAccess() == clang::AS_private) ) {
3243 if (errstr) *errstr = current;
3245 return llvm::StringRef();
3252 if (errstr) *errstr = indexvar;
3253 if (errnum) *errnum =
UNKNOWN;
3254 return llvm::StringRef();
3259 current = strtok(
nullptr, tokenlist);
3275 while((
c = in[i++])) {
3276 const char *repl =
nullptr;
3278 case '+': repl =
"pL";
break;
3279 case '-': repl =
"mI";
break;
3280 case '*': repl =
"mU";
break;
3281 case '/': repl =
"dI";
break;
3282 case '&': repl =
"aN";
break;
3283 case '%': repl =
"pE";
break;
3284 case '|': repl =
"oR";
break;
3285 case '^': repl =
"hA";
break;
3286 case '>': repl =
"gR";
break;
3287 case '<': repl =
"lE";
break;
3288 case '=': repl =
"eQ";
break;
3289 case '~': repl =
"wA";
break;
3290 case '.': repl =
"dO";
break;
3291 case '(': repl =
"oP";
break;
3292 case ')': repl =
"cP";
break;
3293 case '[': repl =
"oB";
break;
3294 case ']': repl =
"cB";
break;
3295 case '{': repl =
"lB";
break;
3296 case '}': repl =
"rB";
break;
3297 case ';': repl =
"sC";
break;
3298 case '#': repl =
"hS";
break;
3299 case '?': repl =
"qM";
break;
3300 case '`': repl =
"bT";
break;
3301 case '!': repl =
"nO";
break;
3302 case ',': repl =
"cO";
break;
3303 case '$': repl =
"dA";
break;
3304 case ' ': repl =
"sP";
break;
3305 case ':': repl =
"cL";
break;
3306 case '"': repl =
"dQ";
break;
3307 case '@': repl =
"aT";
break;
3308 case '\'': repl =
"sQ";
break;
3309 case '\\': repl =
"fI";
break;
3318 if (out.empty() || isdigit(out[0]))
3319 out.insert(out.begin(),
'_');
3322static clang::SourceLocation
3324 clang::SourceLocation sourceLoc) {
3326 if (!sourceLoc.isFileID()) {
3327 return sourceManager.getExpansionRange(sourceLoc).getEnd();
3336 const cling::Interpreter& interp)
3366 using namespace clang;
3367 SourceLocation headerLoc = decl.getLocation();
3369 static const char invalidFilename[] =
"";
3370 if (!headerLoc.isValid())
return invalidFilename;
3372 HeaderSearch& HdrSearch = interp.getCI()->getPreprocessor().getHeaderSearchInfo();
3374 SourceManager& sourceManager = decl.getASTContext().getSourceManager();
3376 FileID headerFID = sourceManager.getFileID(headerLoc);
3377 SourceLocation includeLoc
3379 sourceManager.getIncludeLoc(headerFID));
3381 const FileEntry *headerFE = sourceManager.getFileEntryForID(headerFID);
3382 while (includeLoc.isValid() && sourceManager.isInSystemHeader(includeLoc)) {
3383 ConstSearchDirIterator *foundDir =
nullptr;
3386 assert(headerFE &&
"Couldn't find FileEntry from FID!");
3388 = HdrSearch.LookupFile(llvm::sys::path::filename(headerFE->getName()),
3390 true ,
nullptr, foundDir,
3391 ArrayRef<std::pair<OptionalFileEntryRef, DirectoryEntryRef>>(),
3399 headerFID = sourceManager.getFileID(includeLoc);
3400 headerFE = sourceManager.getFileEntryForID(headerFID);
3405 if (interp.getCI()->getLangOpts().Modules && !headerFE) {
3406 assert(decl.isFirstDecl() &&
"Couldn't trace back include from a decl"
3407 " that is not from an AST file");
3408 assert(StringRef(includeLoc.printToString(sourceManager)).startswith(
"<module-includes>"));
3412 sourceManager.getIncludeLoc(headerFID));
3415 if (!headerFE)
return invalidFilename;
3417 llvm::SmallString<256> headerFileName(headerFE->getName());
3420 llvm::sys::path::remove_dots(headerFileName,
true);
3431 bool isAbsolute = llvm::sys::path::is_absolute(headerFileName);
3432 clang::OptionalFileEntryRef FELong;
3434 for (llvm::sys::path::const_iterator
3435 IDir = llvm::sys::path::begin(headerFileName),
3436 EDir = llvm::sys::path::end(headerFileName);
3437 !FELong && IDir != EDir; ++IDir) {
3443 size_t lenTrailing = headerFileName.size() - (IDir->data() - headerFileName.data());
3444 llvm::StringRef trailingPart(IDir->data(), lenTrailing);
3445 assert(trailingPart.data() + trailingPart.size()
3446 == headerFileName.data() + headerFileName.size()
3447 &&
"Mismatched partitioning of file name!");
3448 ConstSearchDirIterator* FoundDir =
nullptr;
3449 FELong = HdrSearch.LookupFile(trailingPart, SourceLocation(),
3450 true ,
nullptr, FoundDir,
3451 ArrayRef<std::pair<OptionalFileEntryRef, DirectoryEntryRef>>(),
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 ConstSearchDirIterator* FoundDir =
nullptr;
3475 if (HdrSearch.LookupFile(trailingPart, SourceLocation(),
3476 true ,
nullptr, FoundDir,
3477 ArrayRef<std::pair<OptionalFileEntryRef, DirectoryEntryRef>>(),
3480 nullptr,
nullptr ) == FELong) {
3481 return trailingPart.str();
3485 return invalidFilename;
3491 const clang::QualType &qtype,
3492 const clang::ASTContext &astContext)
3494 std::string fqname = cling::utils::TypeName::GetFullyQualifiedName(qtype, astContext);
3503 const clang::QualType &qtype,
3504 const cling::Interpreter &interpreter)
3509 cling::Interpreter::PushTransactionRAII RAII(
const_cast<cling::Interpreter*
>(&interpreter));
3513 interpreter.getCI()->getASTContext());
3521 clang::ClassTemplateDecl*& ctd,
3522 clang::ClassTemplateSpecializationDecl*& ctsd)
3524 using namespace clang;
3525 const Type* theType = qt.getTypePtr();
3532 if (theType->isPointerType()) {
3536 if (
const RecordType* rType = llvm::dyn_cast<RecordType>(theType)) {
3537 ctsd = llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(rType->getDecl());
3539 ctd = ctsd->getSpecializedTemplate();
3544 if (
const SubstTemplateTypeParmType* sttpType = llvm::dyn_cast<SubstTemplateTypeParmType>(theType)){
3549 ctsd = llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(qt->getAsCXXRecordDecl());
3551 ctd = ctsd->getSpecializedTemplate();
3566 using namespace clang;
3567 ClassTemplateSpecializationDecl* ctsd;
3568 ClassTemplateDecl* ctd;
3582 using namespace clang;
3583 TemplateName theTemplateName;
3585 const Type* theType = qt.getTypePtr();
3587 if (
const TemplateSpecializationType* tst = llvm::dyn_cast_or_null<const TemplateSpecializationType>(theType)) {
3588 theTemplateName = tst->getTemplateName();
3591 theTemplateName = TemplateName(ctd);
3594 return theTemplateName;
3600 llvm::SmallVectorImpl<clang::TemplateArgument>& preceedingTArgs,
3601 const clang::NamedDecl& tPar,
3602 const cling::Interpreter& interp,
3606 using namespace clang;
3609 TemplateTypeParmDecl* ttpdPtr =
const_cast<TemplateTypeParmDecl*
>(llvm::dyn_cast<TemplateTypeParmDecl>(&tPar));
3610 if (!ttpdPtr)
return false;
3611 if (!ttpdPtr->hasDefaultArgument())
return false;
3614 QualType tParQualType = ttpdPtr->getDefaultArgument();
3615 const QualType tArgQualType = tArg.getAsType();
3622 if (tParQualType.getTypePtr() == tArgQualType.getTypePtr())
return true;
3633 const clang::ElaboratedType* etype
3634 = llvm::dyn_cast<clang::ElaboratedType>(tParQualType.getTypePtr());
3636 tParQualType = clang::QualType(etype->getNamedType().getTypePtr(),0);
3637 etype = llvm::dyn_cast<clang::ElaboratedType>(tParQualType.getTypePtr());
3640 const TemplateSpecializationType* tst =
3641 llvm::dyn_cast<TemplateSpecializationType>(tParQualType.getTypePtr());
3646 ClassTemplateSpecializationDecl* TSTdecl
3647 = llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(tArgQualType->getAsCXXRecordDecl());
3652 TemplateDecl *Template = tst->getTemplateName().getAsTemplateDecl();
3655 SourceLocation TemplateLoc = Template->getSourceRange ().getBegin();
3658 SourceLocation LAngleLoc = TSTdecl->getSourceRange().getBegin();
3663 TemplateArgument newArg = tArg;
3665 clang::Sema& S = interp.getCI()->getSema();
3666 cling::Interpreter::PushTransactionRAII clingRAII(
const_cast<cling::Interpreter*
>(&interp));
3667 llvm::SmallVector<clang::TemplateArgument, 4> canonArgs;
3668 bool HasDefaultArgs;
3669 TemplateArgumentLoc defTArgLoc = S.SubstDefaultTemplateArgumentIfAvailable(Template,
3678 newArg = defTArgLoc.getArgument();
3679 if (newArg.isNull() ||
3680 newArg.getKind() != clang::TemplateArgument::Type) {
3682 "Template parameter substitution failed!");
3685 ClassTemplateSpecializationDecl* nTSTdecl
3686 = llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(newArg.getAsType()->getAsCXXRecordDecl());
3689 isEqual = (nTSTdecl && 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 if (
auto Value = defArgExpr->getIntegerConstantExpr(astCtxt))
3717 defaultValueAPSInt = *
Value;
3720 const int value = tArg.getAsIntegral().getLimitedValue();
3723 return value == defaultValueAPSInt;
3733 using namespace clang;
3734 if (!nDecl)
return false;
3735 if (
const TemplateTypeParmDecl* ttpd = llvm::dyn_cast<TemplateTypeParmDecl>(nDecl))
3736 return ttpd->hasDefaultArgument();
3737 if (
const NonTypeTemplateParmDecl* nttpd = llvm::dyn_cast<NonTypeTemplateParmDecl>(nDecl))
3738 return nttpd->hasDefaultArgument();
3743static void KeepNParams(clang::QualType& normalizedType,
3744 const clang::QualType& vanillaType,
3745 const cling::Interpreter& interp,
3750 const clang::TemplateArgument &tArg,
3751 const cling::Interpreter& interp,
3753 const clang::ASTContext& astCtxt)
3756 using namespace clang;
3763 if (tArg.getKind() == clang::TemplateArgument::Type) {
3764 QualType thisNormQualType = normTArg.getAsType();
3765 QualType thisArgQualType = tArg.getAsType();
3770 normTArg = TemplateArgument(thisNormQualType);
3771 return (thisNormQualType != thisArgQualType);
3772 }
else if (normTArg.getKind() == clang::TemplateArgument::Pack) {
3773 assert( tArg.getKind() == clang::TemplateArgument::Pack );
3775 SmallVector<TemplateArgument, 2> desArgs;
3776 bool mightHaveChanged =
true;
3777 for (
auto I = normTArg.pack_begin(), E = normTArg.pack_end(),
3778 FI = tArg.pack_begin(), FE = tArg.pack_end();
3779 I != E && FI != FE; ++
I, ++FI)
3781 TemplateArgument pack_arg(*
I);
3783 desArgs.push_back(pack_arg);
3785 if (mightHaveChanged) {
3786 ASTContext &mutableCtx(
const_cast<ASTContext&
>(astCtxt) );
3787 normTArg = TemplateArgument::CreatePackCopy(mutableCtx, desArgs);
3789 return mightHaveChanged;
3800 const clang::QualType& vanillaType,
3801 const cling::Interpreter& interp,
3805 using namespace clang;
3809 ClassTemplateSpecializationDecl* ctsd;
3810 ClassTemplateDecl* ctd;
3811 if (! QualType2Template(vanillaType, ctd, ctsd)) return ;
3817 QualType originalNormalizedType = normalizedType;
3819 const ASTContext& astCtxt = ctsd->getASTContext();
3824 if (llvm::isa<clang::PointerType>(normalizedType.getTypePtr())) {
3826 clang::Qualifiers quals = normalizedType.getQualifiers();
3827 auto valNormalizedType = normalizedType->getPointeeType();
3828 KeepNParams(valNormalizedType,vanillaType, interp, normCtxt);
3829 normalizedType = astCtxt.getPointerType(valNormalizedType);
3831 normalizedType = astCtxt.getQualifiedType(normalizedType, quals);
3837 if (llvm::isa<clang::ReferenceType>(normalizedType.getTypePtr())) {
3839 bool isLValueRefTy = llvm::isa<clang::LValueReferenceType>(normalizedType.getTypePtr());
3840 clang::Qualifiers quals = normalizedType.getQualifiers();
3841 auto valNormType = normalizedType->getPointeeType();
3842 KeepNParams(valNormType, vanillaType, interp, normCtxt);
3846 normalizedType = astCtxt.getLValueReferenceType(valNormType);
3848 normalizedType = astCtxt.getRValueReferenceType(valNormType);
3850 normalizedType = astCtxt.getQualifiedType(normalizedType, quals);
3855 bool prefix_changed =
false;
3856 clang::NestedNameSpecifier* prefix =
nullptr;
3857 clang::Qualifiers prefix_qualifiers = normalizedType.getLocalQualifiers();
3858 const clang::ElaboratedType* etype
3859 = llvm::dyn_cast<clang::ElaboratedType>(normalizedType.getTypePtr());
3863 prefix = AddDefaultParametersNNS(astCtxt, etype->getQualifier(), interp, normCtxt);
3864 prefix_changed = prefix != etype->getQualifier();
3865 normalizedType = clang::QualType(etype->getNamedType().getTypePtr(),0);
3871 const clang::ClassTemplateDecl* ctdWithDefaultArgs = ctd;
3872 for (
const RedeclarableTemplateDecl* rd: ctdWithDefaultArgs->redecls()) {
3873 clang::TemplateParameterList* tpl = rd->getTemplateParameters();
3874 if (tpl->getMinRequiredArguments () < tpl->size()) {
3875 ctdWithDefaultArgs = llvm::dyn_cast<clang::ClassTemplateDecl>(rd);
3880 if (!ctdWithDefaultArgs) {
3881 Error(
"KeepNParams",
"Not found template default arguments\n");
3882 normalizedType=originalNormalizedType;
3886 TemplateParameterList* tParsPtr = ctdWithDefaultArgs->getTemplateParameters();
3887 const TemplateParameterList& tPars = *tParsPtr;
3888 const TemplateArgumentList& tArgs = ctsd->getTemplateArgs();
3891 TemplateName theTemplateName = ExtractTemplateNameFromQualType(normalizedType);
3892 if (theTemplateName.isNull()) {
3893 normalizedType=originalNormalizedType;
3897 const TemplateSpecializationType* normalizedTst =
3898 llvm::dyn_cast<TemplateSpecializationType>(normalizedType.getTypePtr());
3899 if (!normalizedTst) {
3900 normalizedType=originalNormalizedType;
3904 const clang::ClassTemplateSpecializationDecl* TSTdecl
3905 = llvm::dyn_cast_or_null<const clang::ClassTemplateSpecializationDecl>(normalizedType.getTypePtr()->getAsCXXRecordDecl());
3906 bool isStdDropDefault = TSTdecl && IsStdDropDefaultClass(*TSTdecl);
3913 llvm::SmallVector<TemplateArgument, 4> argsToKeep;
3915 const int nArgs = tArgs.size();
3916 const auto &normArgs = normalizedTst->template_arguments();
3917 const int nNormArgs = normArgs.size();
3919 bool mightHaveChanged =
false;
3922 for (
int formal = 0, inst = 0; formal != nArgs; ++formal, ++inst) {
3923 const NamedDecl* tParPtr = tPars.getParam(formal);
3925 Error(
"KeepNParams",
"The parameter number %s is null.\n", formal);
3932 if (formal == nNormArgs || inst == nNormArgs)
break;
3934 const TemplateArgument& tArg = tArgs.get(formal);
3935 TemplateArgument normTArg(normArgs[inst]);
3937 bool shouldKeepArg = nArgsToKeep < 0 || inst < nArgsToKeep;
3938 if (isStdDropDefault) shouldKeepArg =
false;
3947 if ( tParPtr->isTemplateParameterPack() ) {
3952 for( ; inst != nNormArgs; ++inst) {
3953 normTArg = normArgs[inst];
3955 argsToKeep.push_back(normTArg);
3961 argsToKeep.push_back(normTArg);
3964 if (!isStdDropDefault) {
3966 mightHaveChanged =
true;
3976 auto argKind = tArg.getKind();
3977 if (argKind == clang::TemplateArgument::Type){
3979 equal =
areEqualTypes(tArg, argsToKeep, *tParPtr, interp, normCtxt);
3980 }
else if (argKind == clang::TemplateArgument::Integral){
3985 argsToKeep.push_back(normTArg);
3987 mightHaveChanged =
true;
3993 if (!prefix_changed && !mightHaveChanged) {
3994 normalizedType = originalNormalizedType;
3999 if (mightHaveChanged) {
4000 Qualifiers qualifiers = normalizedType.getLocalQualifiers();
4001 normalizedType = astCtxt.getTemplateSpecializationType(theTemplateName,
4003 normalizedType.getTypePtr()->getCanonicalTypeInternal());
4004 normalizedType = astCtxt.getQualifiedType(normalizedType, qualifiers);
4010 normalizedType = astCtxt.getElaboratedType(clang::ElaboratedTypeKeyword::None, prefix, normalizedType);
4011 normalizedType = astCtxt.getQualifiedType(normalizedType,prefix_qualifiers);
4025 clang::ASTContext &ctxt = interpreter.getCI()->getASTContext();
4028 cling::Interpreter::PushTransactionRAII RAII(
const_cast<cling::Interpreter*
>(&interpreter));
4029 clang::QualType normalizedType = cling::utils::Transform::GetPartiallyDesugaredType(ctxt,
type, normCtxt.
GetConfig(),
true );
4037 return normalizedType;
4051 if (
type.isNull()) {
4058 clang::ASTContext &ctxt = interpreter.getCI()->getASTContext();
4059 clang::PrintingPolicy policy(ctxt.getPrintingPolicy());
4060 policy.SuppressTagKeyword =
true;
4061 policy.SuppressScope =
true;
4062 policy.AnonymousTagLocations =
false;
4067 std::string normalizedNameStep1;
4070 cling::Interpreter::PushTransactionRAII clingRAII(
const_cast<cling::Interpreter*
>(&interpreter));
4071 normalizedType.getAsStringInternal(normalizedNameStep1,policy);
4081 if (norm_name.length()>2 && norm_name[0]==
':' && norm_name[1]==
':') {
4082 norm_name.erase(0,2);
4090 const clang::TypeDecl* typeDecl,
4091 const cling::Interpreter &interpreter)
4094 const clang::Sema &sema = interpreter.getSema();
4095 clang::ASTContext& astCtxt = sema.getASTContext();
4096 clang::QualType qualType = astCtxt.getTypeDeclType(typeDecl);
4105std::pair<std::string,clang::QualType>
4107 const cling::Interpreter &interpreter,
4111 std::string thisTypeName;
4112 GetNormalizedName(thisTypeName, thisType, interpreter, normCtxt );
4115 if (!hasChanged)
return std::make_pair(thisTypeName,thisType);
4119 "Name changed from %s to %s\n", thisTypeName.c_str(), thisTypeNameForIO.c_str());
4122 auto& lookupHelper = interpreter.getLookupHelper();
4124 const clang::Type* typePtrForIO;
4125 lookupHelper.findScope(thisTypeNameForIO,
4126 cling::LookupHelper::DiagSetting::NoDiagnostics,
4130 if (!typePtrForIO) {
4132 "Type not found: %s.",thisTypeNameForIO.c_str());
4135 clang::QualType typeForIO(typePtrForIO,0);
4138 if (!typeForIO->isRecordType()) {
4139 return std::make_pair(thisTypeNameForIO,typeForIO);
4142 auto thisDeclForIO = typeForIO->getAsCXXRecordDecl();
4143 if (!thisDeclForIO) {
4145 "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());
4146 return std::make_pair(thisTypeName,thisType);
4149 return std::make_pair(thisTypeNameForIO,typeForIO);
4155 const cling::Interpreter &interpreter,
4167 std::string dictFileName(moduleName);
4168 dictFileName +=
"_rdict.pcm";
4169 return dictFileName;
4173 llvm::errs() << llvm::StringRef(commentStart, 80) <<
'\n';
4199 clang::SourceManager& sourceManager = decl.getASTContext().getSourceManager();
4200 clang::SourceLocation sourceLocation = decl.getEndLoc();
4203 sourceLocation = sourceManager.getExpansionRange(sourceLocation).getEnd();
4211 if (!decl.hasOwningModule() && sourceManager.isLoadedSourceLocation(sourceLocation)) {
4217 const char *commentStart = sourceManager.getCharacterData(sourceLocation, &invalid);
4221 bool skipToSemi =
true;
4222 if (
const clang::FunctionDecl* FD = clang::dyn_cast<clang::FunctionDecl>(&decl)) {
4223 if (FD->isImplicit()) {
4227 if (FD->isExplicitlyDefaulted() || FD->isDeletedAsWritten()) {
4231 }
else if (FD->doesThisDeclarationHaveABody()) {
4234 assert((decl.getEndLoc() != sourceLocation || *commentStart ==
'}'
4236 &&
"Expected macro or end of body at '}'");
4237 if (*commentStart) ++commentStart;
4240 while (*commentStart && isspace(*commentStart)
4241 && *commentStart !=
'\n' && *commentStart !=
'\r') {
4244 if (*commentStart ==
';') ++commentStart;
4248 }
else if (
const clang::EnumConstantDecl* ECD
4249 = clang::dyn_cast<clang::EnumConstantDecl>(&decl)) {
4251 if (ECD->getNextDeclInContext())
4252 while (*commentStart && *commentStart !=
',' && *commentStart !=
'\r' && *commentStart !=
'\n')
4260 while (*commentStart && *commentStart !=
';' && *commentStart !=
'\r' && *commentStart !=
'\n')
4262 if (*commentStart ==
';') ++commentStart;
4266 while ( *commentStart && isspace(*commentStart)
4267 && *commentStart !=
'\n' && *commentStart !=
'\r') {
4271 if (commentStart[0] !=
'/' ||
4272 (commentStart[1] !=
'/' && commentStart[1] !=
'*')) {
4282 unsigned int skipChars = 2;
4283 if (commentStart[0] ==
'/' &&
4284 commentStart[1] ==
'/' &&
4285 (commentStart[2] ==
'/' || commentStart[2] ==
'!') &&
4286 commentStart[3] ==
'<') {
4288 }
else if (commentStart[0] ==
'/' &&
4289 commentStart[1] ==
'*' &&
4290 (commentStart[2] ==
'*' || commentStart[2] ==
'!') &&
4291 commentStart[3] ==
'<') {
4295 commentStart += skipChars;
4298 while ( *commentStart && isspace(*commentStart)
4299 && *commentStart !=
'\n' && *commentStart !=
'\r') {
4302 const char* commentEnd = commentStart;
4304 while (*commentEnd && *commentEnd !=
'\n' && *commentEnd !=
'\r') {
4310 while (commentEnd > commentStart && isspace(commentEnd[-1])) {
4316 unsigned offset = commentStart - sourceManager.getCharacterData(sourceLocation);
4317 *loc = sourceLocation.getLocWithOffset(
offset - 1);
4320 return llvm::StringRef(commentStart, commentEnd - commentStart);
4328 if (!decl)
return false;
4330 auto& sema = interpreter.getCI()->getSema();
4331 auto maybeMacroLoc = decl->getLocation();
4333 if (!maybeMacroLoc.isMacroID())
return false;
4335 static const std::vector<std::string> signatures =
4336 {
"ClassDef",
"ClassDefOverride",
"ClassDefNV",
"ClassDefInline",
"ClassDefInlineOverride",
"ClassDefInlineNV" };
4338 for (
auto &
name : signatures)
4339 if (sema.findMacroSpelling(maybeMacroLoc,
name))
4353 clang::SourceLocation *loc,
4354 const cling::Interpreter &interpreter)
4356 using namespace clang;
4358 const Decl* DeclFileLineDecl
4359 = interpreter.getLookupHelper().findFunctionProto(&decl,
"DeclFileLine",
"",
4360 cling::LookupHelper::NoDiagnostics);
4364 SourceLocation commentSLoc;
4366 if (comment.size()) {
4373 return llvm::StringRef();
4382 const clang::Type *rawtype =
type.getTypePtr();
4385 if (rawtype->isElaboratedTypeSpecifier() ) {
4386 rawtype = rawtype->getCanonicalTypeInternal().getTypePtr();
4388 if (rawtype->isArrayType()) {
4389 rawtype =
type.getTypePtr()->getBaseElementTypeUnsafe ();
4391 if (rawtype->isPointerType() || rawtype->isReferenceType() ) {
4393 clang::QualType pointee;
4394 while ( (pointee = rawtype->getPointeeType()) , pointee.getTypePtrOrNull() && pointee.getTypePtr() != rawtype)
4396 rawtype = pointee.getTypePtr();
4398 if (rawtype->isElaboratedTypeSpecifier() ) {
4399 rawtype = rawtype->getCanonicalTypeInternal().getTypePtr();
4401 if (rawtype->isArrayType()) {
4402 rawtype = rawtype->getBaseElementTypeUnsafe ();
4406 if (rawtype->isArrayType()) {
4407 rawtype = rawtype->getBaseElementTypeUnsafe ();
4418 if (ctxt.isNamespace() || ctxt.isTranslationUnit())
4420 else if(
const auto parentdecl = llvm::dyn_cast<clang::CXXRecordDecl>(&ctxt))
4433 const clang::DeclContext *ctxt = decl.getDeclContext();
4434 switch (decl.getAccess()) {
4435 case clang::AS_public:
4437 case clang::AS_protected:
4439 case clang::AS_private:
4441 case clang::AS_none:
4445 assert(
false &&
"Unexpected value for the access property value in Clang");
4455 return cling::utils::Analyze::IsStdClass(cl);
4465 if (cling::utils::Analyze::IsStdClass(cl)) {
4466 static const char *names[] =
4467 {
"shared_ptr",
"__shared_ptr",
4468 "vector",
"list",
"deque",
"map",
"multimap",
"set",
"multiset",
"bitset"};
4469 llvm::StringRef clname(cl.getName());
4470 for(
auto &&
name : names) {
4471 if (clname ==
name)
return true;
4481 const clang::CXXRecordDecl ¤tCl)
4484 if (&cl == ¤tCl)
return true;
4486 const clang::CXXRecordDecl* previous = currentCl.getPreviousDecl();
4489 if (
nullptr == previous){
4508 const clang::CXXRecordDecl *thisDecl =
4509 llvm::dyn_cast_or_null<clang::CXXRecordDecl>(lh.findScope(typ, cling::LookupHelper::WithDiagnostics));
4513 Error(
"IsOfType",
"Record decl of type %s not found in the AST.", typ.c_str());
4518 const clang::CXXRecordDecl *mostRecentDecl = thisDecl->getMostRecentDecl();
4543 if (!IsStdClass(cl)) {
4544 auto *nsDecl = llvm::dyn_cast<clang::NamespaceDecl>(cl.getDeclContext());
4545 if (cl.getName() !=
"RVec" || nsDecl ==
nullptr || nsDecl->getName() !=
"VecOps")
4548 auto *parentNsDecl = llvm::dyn_cast<clang::NamespaceDecl>(cl.getDeclContext()->getParent());
4549 if (parentNsDecl ==
nullptr || parentNsDecl->getName() !=
"ROOT")
4553 return STLKind(cl.getName());
4557 using namespace clang;
4558 struct SearchTypedef:
public TypeVisitor<SearchTypedef, bool> {
4559 bool VisitTypedefType(
const TypedefType* TD) {
4562 bool VisitArrayType(
const ArrayType* AT) {
4563 return Visit(AT->getElementType().getTypePtr());
4565 bool VisitDecltypeType(
const DecltypeType* DT) {
4566 return Visit(DT->getUnderlyingType().getTypePtr());
4568 bool VisitPointerType(
const PointerType* PT) {
4569 return Visit(PT->getPointeeType().getTypePtr());
4571 bool VisitReferenceType(
const ReferenceType* RT) {
4572 return Visit(RT->getPointeeType().getTypePtr());
4574 bool VisitSubstTemplateTypeParmType(
const SubstTemplateTypeParmType* STST) {
4575 return Visit(STST->getReplacementType().getTypePtr());
4577 bool VisitTemplateSpecializationType(
const TemplateSpecializationType* TST) {
4578 for (
const TemplateArgument &
TA : TST->template_arguments()) {
4579 if (
TA.getKind() == TemplateArgument::Type && Visit(
TA.getAsType().getTypePtr()))
4584 bool VisitTemplateTypeParmType(
const TemplateTypeParmType* TTPT) {
4587 bool VisitTypeOfType(
const TypeOfType* TOT) {
4588 return TOT->getUnmodifiedType().getTypePtr();
4590 bool VisitElaboratedType(
const ElaboratedType* ET) {
4591 NestedNameSpecifier* NNS = ET->getQualifier();
4593 if (NNS->getKind() == NestedNameSpecifier::TypeSpec) {
4594 if (Visit(NNS->getAsType()))
4597 NNS = NNS->getPrefix();
4599 return Visit(ET->getNamedType().getTypePtr());
4620 using namespace llvm;
4621 using namespace clang;
4622 const clang::ASTContext &Ctxt =
instance->getAsCXXRecordDecl()->getASTContext();
4625 const clang::ElaboratedType* etype
4626 = llvm::dyn_cast<clang::ElaboratedType>(
input.getTypePtr());
4630 clang::Qualifiers scope_qualifiers =
input.getLocalQualifiers();
4631 assert(
instance->getAsCXXRecordDecl() !=
nullptr &&
"ReSubstTemplateArg only makes sense with a type representing a class.");
4633 clang::NestedNameSpecifier *scope = ReSubstTemplateArgNNS(Ctxt,etype->getQualifier(),
instance);
4637 subTy = Ctxt.getElaboratedType(clang::ElaboratedTypeKeyword::None, scope, subTy);
4638 subTy = Ctxt.getQualifiedType(subTy,scope_qualifiers);
4642 QualType QT =
input;
4646 if (isa<clang::PointerType>(QT.getTypePtr())) {
4648 Qualifiers quals = QT.getQualifiers();
4651 if (nQT == QT->getPointeeType())
return QT;
4653 QT = Ctxt.getPointerType(nQT);
4655 QT = Ctxt.getQualifiedType(QT, quals);
4661 if (isa<ReferenceType>(QT.getTypePtr())) {
4663 bool isLValueRefTy = isa<LValueReferenceType>(QT.getTypePtr());
4664 Qualifiers quals = QT.getQualifiers();
4667 if (nQT == QT->getPointeeType())
return QT;
4671 QT = Ctxt.getLValueReferenceType(nQT);
4673 QT = Ctxt.getRValueReferenceType(nQT);
4675 QT = Ctxt.getQualifiedType(QT, quals);
4681 if (isa<clang::ArrayType>(QT.getTypePtr())) {
4683 Qualifiers quals = QT.getQualifiers();
4685 if (
const auto arr = dyn_cast<ConstantArrayType>(QT.getTypePtr())) {
4688 if (newQT == arr->getElementType())
return QT;
4689 QT = Ctxt.getConstantArrayType(newQT,
4692 arr->getSizeModifier(),
4693 arr->getIndexTypeCVRQualifiers());
4695 }
else if (
const auto arr = dyn_cast<DependentSizedArrayType>(QT.getTypePtr())) {
4698 if (newQT == QT)
return QT;
4699 QT = Ctxt.getDependentSizedArrayType (newQT,
4701 arr->getSizeModifier(),
4702 arr->getIndexTypeCVRQualifiers(),
4703 arr->getBracketsRange());
4705 }
else if (
const auto arr = dyn_cast<IncompleteArrayType>(QT.getTypePtr())) {
4708 if (newQT == arr->getElementType())
return QT;
4709 QT = Ctxt.getIncompleteArrayType (newQT,
4710 arr->getSizeModifier(),
4711 arr->getIndexTypeCVRQualifiers());
4713 }
else if (
const auto arr = dyn_cast<VariableArrayType>(QT.getTypePtr())) {
4716 if (newQT == arr->getElementType())
return QT;
4717 QT = Ctxt.getVariableArrayType (newQT,
4719 arr->getSizeModifier(),
4720 arr->getIndexTypeCVRQualifiers(),
4721 arr->getBracketsRange());
4725 QT = Ctxt.getQualifiedType(QT, quals);
4730 etype = llvm::dyn_cast<clang::ElaboratedType>(
instance);
4732 instance = etype->getNamedType().getTypePtr();
4736 const clang::TemplateSpecializationType* TST
4737 = llvm::dyn_cast<const clang::TemplateSpecializationType>(
instance);
4739 if (!TST)
return input;
4741 const clang::ClassTemplateSpecializationDecl* TSTdecl
4742 = llvm::dyn_cast_or_null<const clang::ClassTemplateSpecializationDecl>(
instance->getAsCXXRecordDecl());
4744 if (!TSTdecl)
return input;
4746 const clang::SubstTemplateTypeParmType *substType
4747 = llvm::dyn_cast<clang::SubstTemplateTypeParmType>(
input.getTypePtr());
4751 const clang::ClassTemplateDecl *replacedCtxt =
nullptr;
4753 const clang::DeclContext *replacedDeclCtxt = substType->getReplacedParameter()->getDeclContext();
4754 const clang::CXXRecordDecl *decl = llvm::dyn_cast<clang::CXXRecordDecl>(replacedDeclCtxt);
4755 unsigned int index = substType->getReplacedParameter()->getIndex();
4758 if (decl->getKind() == clang::Decl::ClassTemplatePartialSpecialization) {
4759 const clang::ClassTemplatePartialSpecializationDecl *spec = llvm::dyn_cast<clang::ClassTemplatePartialSpecializationDecl>(decl);
4761 unsigned int depth = substType->getReplacedParameter()->getDepth();
4763 const TemplateArgument *instanceArgs = spec->getTemplateArgs().data();
4764 unsigned int instanceNArgs = spec->getTemplateArgs().size();
4768 for(
unsigned int A = 0; A < instanceNArgs; ++A) {
4769 if (instanceArgs[A].getKind() == clang::TemplateArgument::Type) {
4770 clang::QualType argQualType = instanceArgs[A].getAsType();
4772 const clang::TemplateTypeParmType *replacementType;
4774 replacementType = llvm::dyn_cast<clang::TemplateTypeParmType>(argQualType);
4776 if (!replacementType) {
4777 const clang::SubstTemplateTypeParmType *argType
4778 = llvm::dyn_cast<clang::SubstTemplateTypeParmType>(argQualType);
4780 clang::QualType replacementQT = argType->getReplacementType();
4781 replacementType = llvm::dyn_cast<clang::TemplateTypeParmType>(replacementQT);
4784 if (replacementType &&
4785 depth == replacementType->getDepth() &&
4786 index == replacementType->getIndex() )
4793 replacedCtxt = spec->getSpecializedTemplate();
4795 replacedCtxt = decl->getDescribedClassTemplate();
4797 }
else if (
auto const declguide = llvm::dyn_cast<clang::CXXDeductionGuideDecl>(replacedDeclCtxt)) {
4798 replacedCtxt = llvm::dyn_cast<clang::ClassTemplateDecl>(declguide->getDeducedTemplate());
4799 }
else if (
auto const ctdecl = llvm::dyn_cast<clang::ClassTemplateDecl>(replacedDeclCtxt)) {
4800 replacedCtxt = ctdecl;
4802 std::string astDump;
4803 llvm::raw_string_ostream ostream(astDump);
4806 ROOT::TMetaUtils::Warning(
"ReSubstTemplateArg",
"Unexpected type of declaration context for template parameter: %s.\n\tThe responsible class is:\n\t%s\n",
4807 replacedDeclCtxt->getDeclKindName(), astDump.c_str());
4808 replacedCtxt =
nullptr;
4811 if ((replacedCtxt && replacedCtxt->getCanonicalDecl() == TSTdecl->getSpecializedTemplate()->getCanonicalDecl())
4813 substType->getReplacedParameter()
4814 == TSTdecl->getSpecializedTemplate ()->getTemplateParameters()->getParam(
index))
4816 const auto &TAs = TST->template_arguments();
4817 if (
index >= TAs.size()) {
4823 }
else if (TAs[
index].getKind() == clang::TemplateArgument::Type) {
4824 return TAs[
index].getAsType();
4833 const clang::TemplateSpecializationType* inputTST
4834 = llvm::dyn_cast<const clang::TemplateSpecializationType>(
input.getTypePtr());
4835 const clang::ASTContext& astCtxt = TSTdecl->getASTContext();
4838 bool mightHaveChanged =
false;
4839 llvm::SmallVector<clang::TemplateArgument, 4> desArgs;
4840 for (
const clang::TemplateArgument &
TA : inputTST->template_arguments()) {
4841 if (
TA.getKind() != clang::TemplateArgument::Type) {
4842 desArgs.push_back(
TA);
4846 clang::QualType SubTy =
TA.getAsType();
4848 if (llvm::isa<clang::ElaboratedType>(SubTy)
4849 || llvm::isa<clang::SubstTemplateTypeParmType>(SubTy)
4850 || llvm::isa<clang::TemplateSpecializationType>(SubTy)) {
4852 mightHaveChanged = SubTy != newSubTy;
4853 if (!newSubTy.isNull()) {
4854 desArgs.push_back(clang::TemplateArgument(newSubTy));
4857 desArgs.push_back(
TA);
4861 if (mightHaveChanged) {
4862 clang::Qualifiers qualifiers =
input.getLocalQualifiers();
4863 input = astCtxt.getTemplateSpecializationType(inputTST->getTemplateName(),
4865 inputTST->getCanonicalTypeInternal());
4866 input = astCtxt.getQualifiedType(
input, qualifiers);
4878 if ( nArgsToRemove == 0 ||
name ==
"")
4885 unsigned int nArgsRemoved=0;
4886 unsigned int nBraces=0;
4888 while (nArgsRemoved!=nArgsToRemove && cur<
length){
4890 if (
c ==
'<') nBraces++;
4891 if (
c ==
'>') nBraces--;
4892 if (
c ==
',' && nBraces==1 ) nArgsRemoved++;
4906 static const char *stls[] =
4907 {
"any",
"vector",
"list",
"deque",
"map",
"multimap",
"set",
"multiset",
"bitset",
4908 "forward_list",
"unordered_set",
"unordered_multiset",
"unordered_map",
"unordered_multimap",
"RVec",
nullptr};
4922 for(
int k=1;stls[k];k++) {
if (
type.equals(stls[k]))
return values[k];}
4933 TND = TND->getMostRecentDecl();
4934 while (TND && !(TND->hasAttrs()))
4935 TND = TND->getPreviousDecl();
4947 TD = TD->getMostRecentDecl();
4948 while (TD && !(TD->hasAttrs() && TD->isThisDeclarationADefinition()))
4949 TD = TD->getPreviousDecl();
4958 std::list<std::pair<std::string,bool> >& enclosingNamespaces)
4960 const clang::DeclContext* enclosingNamespaceDeclCtxt = decl.getDeclContext();
4961 if (!enclosingNamespaceDeclCtxt)
return;
4963 const clang::NamespaceDecl* enclosingNamespace =
4964 clang::dyn_cast<clang::NamespaceDecl>(enclosingNamespaceDeclCtxt);
4965 if (!enclosingNamespace)
return;
4967 enclosingNamespaces.push_back(std::make_pair(enclosingNamespace->getNameAsString(),
4968 enclosingNamespace->isInline()));
4978 std::list<std::pair<std::string,bool> >& enclosingNamespaces)
4980 const clang::DeclContext* enclosingNamespaceDeclCtxt = ctxt.getParent ();
4983 if (!enclosingNamespaceDeclCtxt) {
4989 const clang::NamespaceDecl* enclosingNamespace = clang::dyn_cast<clang::NamespaceDecl>(enclosingNamespaceDeclCtxt);
4990 if (!enclosingNamespace)
return;
4993 enclosingNamespaces.push_back(std::make_pair(enclosingNamespace->getNameAsString(),
4994 enclosingNamespace->isInline()));
5005 std::list<std::pair<std::string,unsigned int> >& enclosingSc)
5007 const clang::DeclContext* enclosingDeclCtxt = decl.getDeclContext();
5008 if (!enclosingDeclCtxt)
return nullptr;
5010 unsigned int scopeType;
5012 if (
auto enclosingNamespacePtr =
5013 clang::dyn_cast<clang::NamespaceDecl>(enclosingDeclCtxt)){
5014 scopeType= enclosingNamespacePtr->isInline() ? 1 : 0;
5015 enclosingSc.push_back(std::make_pair(enclosingNamespacePtr->getNameAsString(),scopeType));
5019 if (
auto enclosingClassPtr =
5020 clang::dyn_cast<clang::RecordDecl>(enclosingDeclCtxt)){
5021 return enclosingClassPtr;
5033 std::string::size_type beginVar = 0;
5034 std::string::size_type endVar = 0;
5035 while ((beginVar = txt.find(
'$', beginVar)) != std::string::npos
5036 && beginVar + 1 < txt.length()) {
5037 std::string::size_type beginVarName = beginVar + 1;
5038 std::string::size_type endVarName = std::string::npos;
5039 if (txt[beginVarName] ==
'(') {
5041 endVarName = txt.find(
')', beginVarName);
5043 if (endVarName == std::string::npos) {
5045 varname, txt.c_str() + beginVar);
5048 endVar = endVarName + 1;
5051 beginVarName = beginVar + 1;
5052 endVarName = beginVarName;
5053 while (isalnum(txt[endVarName]) || txt[endVarName] ==
'_')
5055 endVar = endVarName;
5058 const char* val = getenv(txt.substr(beginVarName,
5059 endVarName - beginVarName).c_str());
5062 txt.replace(beginVar, endVar - beginVar, val);
5063 int lenval = strlen(val);
5064 int delta = lenval - (endVar - beginVar);
5068 beginVar = endVar + 1;
5080 const char* envInclPath = getenv(
"ROOT_INCLUDE_PATH");
5084 std::istringstream envInclPathsStream(envInclPath);
5085 std::string inclPath;
5086 while (std::getline(envInclPathsStream, inclPath,
':')) {
5089 if (!inclPath.empty()) {
5090 clingArgs.push_back(
"-I");
5091 clingArgs.push_back(inclPath);
5102 size_t start_pos = 0;
5107 while((start_pos = str.find(from, start_pos)) != std::string::npos) {
5108 str.replace(start_pos, from.length(), to);
5109 start_pos += to.length();
5110 if (recurse) changed =
true;
5126 if (theString.size() < theSubstring.size())
return false;
5127 const unsigned int theSubstringSize = theSubstring.size();
5128 return 0 == theString.compare(theString.size() - theSubstringSize,
5137 if (theString.size() < theSubstring.size())
return false;
5138 const unsigned int theSubstringSize = theSubstring.size();
5139 return 0 == theString.compare(0,
5157 size_t linkdeflen = 9;
5159 if (0 == strncasecmp(
filename + (
len - linkdeflen),
"linkdef", linkdeflen - 2)
5175 return llvm::sys::path::extension(
filename) ==
".h" ||
5176 llvm::sys::path::extension(
filename) ==
".hh" ||
5177 llvm::sys::path::extension(
filename) ==
".hpp" ||
5178 llvm::sys::path::extension(
filename) ==
".H" ||
5179 llvm::sys::path::extension(
filename) ==
".h++" ||
5180 llvm::sys::path::extension(
filename) ==
"hxx" ||
5181 llvm::sys::path::extension(
filename) ==
"Hxx" ||
5182 llvm::sys::path::extension(
filename) ==
"HXX";
5188 cling::Interpreter::IgnoreFilesFunc_t ignoreFiles,
5189 const cling::Interpreter &interp,
5192 clang::Sema &sema = interp.getSema();
5193 cling::Transaction theTransaction(sema);
5194 std::set<clang::Decl *> addedDecls;
5195 for (
auto decl : decls) {
5197 clang::Decl *ncDecl =
const_cast<clang::Decl *
>(decl);
5198 theTransaction.append(ncDecl);
5200 std::string newFwdDecl;
5201 llvm::raw_string_ostream llvmOstr(newFwdDecl);
5203 std::string locallogs;
5204 llvm::raw_string_ostream llvmLogStr(locallogs);
5205 interp.forwardDeclare(theTransaction, sema.getPreprocessor(), sema.getASTContext(), llvmOstr,
true,
5206 logs ? &llvmLogStr : nullptr, ignoreFiles);
5210 logs->swap(locallogs);
5222 std::string& defString)
5234 std::string& defString)
5236 std::list<std::pair<std::string,unsigned int> > enclosingNamespaces;
5239 if (rcdPtr)
return rcdPtr;
5242 static const std::string scopeType [] = {
"namespace ",
"inline namespace ",
"class "};
5244 std::string scopeName;
5245 std::string scopeContent;
5246 unsigned int scopeIndex;
5247 for (
auto const & encScope : enclosingNamespaces){
5248 scopeIndex = encScope.second;
5249 scopeName = encScope.first;
5250 scopeContent =
" { " + defString +
" }";
5251 defString = scopeType[scopeIndex] +
5273 const clang::TemplateParameterList& tmplParamList,
5274 const cling::Interpreter& interpreter)
5277 for (
auto prmIt = tmplParamList.begin();
5278 prmIt != tmplParamList.end(); prmIt++){
5280 if (prmIt != tmplParamList.begin())
5281 templateArgs +=
", ";
5283 auto nDecl = *prmIt;
5284 std::string typeName;
5287 if (llvm::isa<clang::TemplateTypeParmDecl>(nDecl)){
5288 typeName =
"typename ";
5289 if (nDecl->isParameterPack())
5291 typeName += (*prmIt)->getNameAsString();
5294 else if (
auto nttpd = llvm::dyn_cast<clang::NonTypeTemplateParmDecl>(nDecl)){
5295 auto theType = nttpd->getType();
5298 if (theType.getAsString().find(
"enum") != std::string::npos){
5299 std::string astDump;
5300 llvm::raw_string_ostream ostream(astDump);
5301 nttpd->dump(ostream);
5303 ROOT::TMetaUtils::Warning(
nullptr,
"Forward declarations of templates with enums as template parameters. The responsible class is: %s\n", astDump.c_str());
5312 else if (
auto ttpd = llvm::dyn_cast<clang::TemplateTemplateParmDecl>(nDecl)){
5315 std::string astDump;
5316 llvm::raw_string_ostream ostream(astDump);
5317 ttpd->dump(ostream);
5319 ROOT::TMetaUtils::Error(
nullptr,
"Cannot reconstruct template template parameter forward declaration for %s\n", astDump.c_str());
5324 templateArgs += typeName;
5335 const cling::Interpreter& interpreter,
5336 std::string& defString)
5338 std::string templatePrefixString;
5339 auto tmplParamList= templDecl.getTemplateParameters();
5340 if (!tmplParamList){
5342 "Cannot extract template parameter list for %s",
5343 templDecl.getNameAsString().c_str());
5350 "Problems with arguments for forward declaration of class %s\n",
5351 templDecl.getNameAsString().c_str());
5354 templatePrefixString =
"template " + templatePrefixString +
" ";
5356 defString = templatePrefixString +
"class ";
5357 if (templDecl.isParameterPack())
5358 defString +=
"... ";
5359 defString += templDecl.getNameAsString();
5360 if (llvm::isa<clang::TemplateTemplateParmDecl>(&templDecl)) {
5374 std::string& argFwdDecl,
5375 const cling::Interpreter& interpreter,
5376 bool acceptStl=
false)
5382 if (clang::TemplateArgument::Type != arg.getKind())
return 0;
5384 auto argQualType = arg.getAsType();
5387 while (llvm::isa<clang::PointerType>(argQualType.getTypePtr())) argQualType = argQualType->getPointeeType();
5389 auto argTypePtr = argQualType.getTypePtr();
5392 if (llvm::isa<clang::EnumType>(argTypePtr)){
5397 if (llvm::isa<clang::BuiltinType>(argTypePtr)){
5402 if (
auto tdTypePtr = llvm::dyn_cast<clang::TypedefType>(argTypePtr)) {
5403 FwdDeclFromTypeDefNameDecl(*tdTypePtr->getDecl(), interpreter, argFwdDecl);
5407 if (
auto argRecTypePtr = llvm::dyn_cast<clang::RecordType>(argTypePtr)){
5409 if (
auto argRecDeclPtr = argRecTypePtr->getDecl()){
5410 FwdDeclFromRcdDecl(*argRecDeclPtr,interpreter,argFwdDecl,acceptStl);
5422 const cling::Interpreter& interpreter,
5423 std::string& defString,
5424 const std::string &normalizedName)
5428 if (
auto tmplSpecDeclPtr = llvm::dyn_cast<clang::ClassTemplateSpecializationDecl>(&recordDecl)) {
5429 if (
const auto *specDef = tmplSpecDeclPtr->getDefinition()) {
5430 if (specDef->getTemplateSpecializationKind() != clang::TSK_ExplicitSpecialization)
5434 std::cout <<
" Forward declaring template spec " << normalizedName <<
":\n";
5435 for (
auto arg : tmplSpecDeclPtr->getTemplateArgs().asArray()) {
5436 std::string argFwdDecl;
5439 std::cout <<
" o Template argument ";
5441 std::cout <<
"successfully treated. Arg fwd decl: " << argFwdDecl << std::endl;
5443 std::cout <<
"could not be treated. Abort fwd declaration generation.\n";
5450 defString += argFwdDecl +
'\n';
5452 defString +=
"template <> class " + normalizedName +
';';
5466 const cling::Interpreter& interpreter,
5467 std::string& defString,
5475 if (!recordDecl.getIdentifier())
5479 std::string argsFwdDecl;
5481 if (
auto tmplSpecDeclPtr = llvm::dyn_cast<clang::ClassTemplateSpecializationDecl>(&recordDecl)){
5482 std::string argFwdDecl;
5484 std::cout <<
"Class " << recordDecl.getNameAsString()
5485 <<
" is a template specialisation. Treating its arguments.\n";
5486 for(
auto arg : tmplSpecDeclPtr->getTemplateArgs().asArray()){
5489 std::cout <<
" o Template argument ";
5491 std::cout <<
"successfully treated. Arg fwd decl: " << argFwdDecl << std::endl;
5493 std::cout <<
"could not be treated. Abort fwd declaration generation.\n";
5500 argsFwdDecl+=argFwdDecl;
5504 defString=argsFwdDecl;
5509 if (
auto tmplDeclPtr = tmplSpecDeclPtr->getSpecializedTemplate()){
5512 defString = argsFwdDecl +
"\n" + defString;
5517 defString =
"class " + recordDecl.getNameAsString() +
";";
5518 const clang::RecordDecl* rcd =
EncloseInScopes(recordDecl, defString);
5526 defString = argsFwdDecl +
"\n" + defString;
5537 const cling::Interpreter& interpreter,
5538 std::string& fwdDeclString,
5539 std::unordered_set<std::string>* fwdDeclSetPtr)
5541 std::string buffer = tdnDecl.getNameAsString();
5542 std::string underlyingName;
5543 auto underlyingType = tdnDecl.getUnderlyingType().getCanonicalType();
5544 if (
const clang::TagType* TT
5545 = llvm::dyn_cast<clang::TagType>(underlyingType.getTypePtr())) {
5546 if (clang::NamedDecl* ND = TT->getDecl()) {
5547 if (!ND->getIdentifier()) {
5561 if (underlyingName.find(
">::") != std::string::npos)
5564 buffer=
"typedef "+underlyingName+
" "+buffer+
";";
5576 auto& ctxt = tdnDecl.getASTContext();
5577 auto immediatelyUnderlyingType = underlyingType.getSingleStepDesugaredType(ctxt);
5579 if (
auto underlyingTdnTypePtr = llvm::dyn_cast<clang::TypedefType>(immediatelyUnderlyingType.getTypePtr())){
5580 std::string tdnFwdDecl;
5581 auto underlyingTdnDeclPtr = underlyingTdnTypePtr->getDecl();
5586 if (!fwdDeclSetPtr || fwdDeclSetPtr->insert(tdnFwdDecl).second)
5587 fwdDeclString+=tdnFwdDecl;
5588 }
else if (
auto CXXRcdDeclPtr = immediatelyUnderlyingType->getAsCXXRecordDecl()){
5589 std::string classFwdDecl;
5591 std::cout <<
"Typedef " << tdnDecl.getNameAsString() <<
" hides a class: "
5592 << CXXRcdDeclPtr->getNameAsString() << std::endl;
5601 if (!fwdDeclSetPtr || fwdDeclSetPtr->insert(classFwdDecl).second)
5602 fwdDeclString+=classFwdDecl;
5605 fwdDeclString+=buffer;
5617 std::string& valAsString,
5618 const clang::PrintingPolicy& ppolicy)
5620 auto defArgExprPtr = par.getDefaultArg();
5621 auto& ctxt = par.getASTContext();
5622 if(!defArgExprPtr->isEvaluatable(ctxt)){
5626 auto defArgType = par.getType();
5629 if (defArgType->isBooleanType()){
5631 defArgExprPtr->EvaluateAsBooleanCondition (
result,ctxt);
5632 valAsString=std::to_string(
result);
5637 if (defArgType->isIntegerType()){
5638 clang::Expr::EvalResult evalResult;
5639 defArgExprPtr->EvaluateAsInt(evalResult, ctxt);
5640 llvm::APSInt
result = evalResult.Val.getInt();
5641 auto uintVal = *
result.getRawData();
5642 if (
result.isNegative()){
5643 long long int intVal=uintVal*-1;
5644 valAsString=std::to_string(intVal);
5646 valAsString=std::to_string(uintVal);
5653 llvm::raw_string_ostream rso(valAsString);
5654 defArgExprPtr->printPretty(rso,
nullptr,ppolicy);
5655 valAsString = rso.str();
The file contains utilities which are foundational and could be used across the core component of ROO...
#define R(a, b, c, d, e, f, g, h, i)
static Roo_reg_AGKInteg1D instance
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
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.
static void CreateNameTypeMap(const clang::CXXRecordDecl &cl, ROOT::MembersTypeMap_t &nameType)
Create the data member name-type map for given class.
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";
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,...)
Use this function in case an error occurred.
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void input
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t dest
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h length
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
Option_t Option_t TPoint TPoint const char mode
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
const_iterator begin() const
const std::string & GetPathSeparator()
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
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)
bool IsSTLBitset(const char *type)
Return true is the name is std::bitset<number> or bitset<number>
constexpr Double_t C()
Velocity of light in .
void ShortType(std::string &answer, int mode)
Return the absolute type of typeDesc into the string answ.