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"
57#include "cling/Interpreter/InterpreterAccessRAII.h"
59#include "llvm/Support/Path.h"
60#include "llvm/Support/FileSystem.h"
65#define strncasecmp _strnicmp
85 using DeclsCont_t = TNormalizedCtxt::Config_t::SkipCollection;
102 bool replace =
false);
113 clang::NestedNameSpecifier*
scope,
116 if (!
scope)
return nullptr;
139static bool CheckDefinition(
const clang::CXXRecordDecl *cl,
const clang::CXXRecordDecl *context)
141 if (!cl->hasDefinition()) {
144 "Missing definition for class %s, please #include its header in the header of %s\n",
145 cl->getName().str().c_str(), context->getName().str().c_str());
148 "Missing definition for class %s\n",
149 cl->getName().str().c_str());
162 clang::NestedNameSpecifier *
scope,
165 if (!
scope)
return nullptr;
187 const clang::BuiltinType *
builtin = llvm::dyn_cast<clang::BuiltinType>(
type->getCanonicalTypeInternal().getTypePtr());
207 clang::ASTContext &
C = cl.getASTContext();
208 clang::DeclarationName
DName = &
C.Idents.get(
what);
209 auto R = cl.lookup(
DName);
210 for (
const clang::NamedDecl *D :
R)
222 clang::LookupResult
R(
SemaR,
DName, clang::SourceLocation(),
223 clang::Sema::LookupOrdinaryName,
224 clang::Sema::ForExternalRedeclaration);
225 SemaR.LookupInSuper(
R, &
const_cast<clang::CXXRecordDecl&
>(cl));
228 return llvm::dyn_cast<const clang::FieldDecl>(
R.getFoundDecl());
234 ? cling::LookupHelper::WithDiagnostics
235 : cling::LookupHelper::NoDiagnostics;
242namespace TMetaUtils {
251 Error(
"TNormalizedCtxt::AddTemplAndNargsToKeep",
252 "Tring to specify a number of template arguments to keep for a null pointer. Exiting without assigning any value.\n");
256 const clang::ClassTemplateDecl*
canTempl =
templ->getCanonicalDecl();
261 const std::string
i_str (std::to_string(i));
263 Error(
"TNormalizedCtxt::AddTemplAndNargsToKeep",
264 "Tring to specify for template %s %s arguments to keep, while before this number was %s\n",
265 canTempl->getNameAsString().c_str(),
278 const clang::ClassTemplateDecl*
constTempl =
templ->getCanonicalDecl();
329 std::unique_ptr<clang::MangleContext>
mangleCtx(
rDecl->getASTContext().createMangleContext());
333 if (
const clang::TypeDecl*
TD = llvm::dyn_cast<clang::TypeDecl>(
rDecl)) {
334 mangleCtx->mangleCXXRTTI(clang::QualType(
TD->getTypeForDecl(), 0),
sstr);
360 "Demangled typeinfo name '%s' does not contain `RTTI Type Descriptor'\n",
364 "Demangled typeinfo name '%s' does not start with 'typeinfo for'\n",
381 const clang::RecordDecl *
decl,
410 const clang::RecordDecl *
decl,
439 "Could not remove the requested template arguments.\n");
450 const clang::RecordDecl *
decl,
484 const clang::RecordDecl *
decl,
531 fCheckInClassTable(CheckInClassTable),
545 if (
tname.empty())
return false;
570 if (!
dest.isNull() && (
dest != t)) {
590 if (!
dest.isNull() && (
dest != t) &&
612 const clang::NamespaceDecl *
nsdecl = llvm::dyn_cast<clang::NamespaceDecl>(
scope);
625 if (
tname.empty())
return false;
657 clang::PrintingPolicy
policy(
fInterpreter->getCI()->getASTContext().getPrintingPolicy());
658 policy.SuppressTagKeyword =
true;
659 policy.SuppressScope =
true;
674 for(
unsigned int i = 1; i<
result.length(); ++i) {
686 }
else if ( (i+1) <
result.length() &&
724 clang::QualType
toSkip =
lh.findType(
name, cling::LookupHelper::WithDiagnostics);
725 if (
const clang::Type* T =
toSkip.getTypePtr()) {
726 const clang::TypedefType *
tt = llvm::dyn_cast<clang::TypedefType>(T);
728 clang::Decl* D =
tt->getDecl();
729 fConfig.m_toSkip.insert(D);
731 clang::QualType
canon =
toSkip->getCanonicalTypeInternal();
732 fConfig.m_toReplace.insert(std::make_pair(
canon.getTypePtr(),T));
734 fTypeWithAlternative.insert(T);
747 keepTypedef(
lh,
"Double32_t");
748 keepTypedef(
lh,
"Float16_t");
749 keepTypedef(
lh,
"Long64_t",
true);
750 keepTypedef(
lh,
"ULong64_t",
true);
752 clang::QualType
toSkip =
lh.findType(
"string", cling::LookupHelper::WithDiagnostics);
754 if (
const clang::TypedefType* TT
755 = llvm::dyn_cast_or_null<clang::TypedefType>(
toSkip.getTypePtr()))
756 fConfig.m_toSkip.insert(TT->getDecl());
758 toSkip =
lh.findType(
"std::string", cling::LookupHelper::WithDiagnostics);
760 if (
const clang::TypedefType* TT
761 = llvm::dyn_cast_or_null<clang::TypedefType>(
toSkip.getTypePtr()))
762 fConfig.m_toSkip.insert(TT->getDecl());
764 clang::QualType
canon =
toSkip->getCanonicalTypeInternal();
765 fConfig.m_toReplace.insert(std::make_pair(
canon.getTypePtr(),
toSkip.getTypePtr()));
776 return (cl.getKind() == clang::Decl::ClassTemplatePartialSpecialization
777 || cl.getKind() == clang::Decl::ClassTemplateSpecialization);
784 const cling::Interpreter&
interp)
786 clang::Sema* S = &
interp.getSema();
787 const clang::NamedDecl*
ND = cling::utils::Lookup::Named(S,
name, cl);
788 if (
ND == (clang::NamedDecl*)-1)
789 return (clang::FunctionDecl*)-1;
790 return llvm::dyn_cast_or_null<clang::FunctionDecl>(
ND);
796const clang::CXXRecordDecl *
800 const cling::LookupHelper&
lh =
interp.getLookupHelper();
803 const clang::CXXRecordDecl *
result
804 = llvm::dyn_cast_or_null<clang::CXXRecordDecl>
811 result = llvm::dyn_cast_or_null<clang::CXXRecordDecl>
822 clang::QualType
qType(cl->getTypeForDecl(),0);
830 clang::Sema& S =
interp.getCI()->getSema();
833 cling::Interpreter::PushTransactionRAII
RAII(
const_cast<cling::Interpreter*
>(&
interp));
834 return S.RequireCompleteType(
Loc, Type, clang::diag::err_incomplete_type);
840 const clang::CXXRecordDecl *context,
const cling::Interpreter &
interp)
846 if (!cl->getDefinition() || !cl->isCompleteDefinition()) {
854 if (!base->hasDefinition()) {
858 return cl->isDerivedFrom(base);
870 const clang::NamedDecl *base
874 return IsBase(
CRD, llvm::dyn_cast<clang::CXXRecordDecl>( base ),
875 llvm::dyn_cast<clang::CXXRecordDecl>(
m.getDeclContext()),
interp);
884 const clang::QualType &
qti,
886 const cling::Interpreter &
interp,
894 kBIT_ISSTRING = 0x40000000,
901 const clang::Type &
ti( *
qti.getTypePtr() );
924 if (
tiName ==
"string")
kase |= kBIT_ISSTRING;
925 if (
tiName ==
"string*")
kase |= kBIT_ISSTRING;
929 tcl =
" internal error in rootcling ";
954 <<
" R__b >> readtemp;" << std::endl
955 <<
" " <<
R__t <<
" = static_cast<" <<
tiName <<
">(readtemp);" << std::endl;
967 finalString <<
" if (R__b.GetInfo() && R__b.GetInfo()->GetOldVersion()<=3) {" << std::endl;
969 finalString <<
" R__ASSERT(0);// " <<
objType <<
" is abstract. We assume that older file could not be produced using this streaming method." << std::endl;
972 <<
" " <<
R__t <<
"->Streamer(R__b);" << std::endl;
975 <<
" " <<
R__t <<
" = (" <<
tiName <<
")R__b.ReadObjectAny(" <<
tcl <<
");" << std::endl
976 <<
" }" << std::endl;
982 <<
" R__str.Streamer(R__b);" << std::endl
983 <<
" " <<
R__t <<
" = R__str.Data();}" << std::endl;
989 <<
" R__str.Streamer(R__b);" << std::endl
990 <<
" " <<
R__t <<
" = new string(R__str.Data());}" << std::endl;
1010 if (!
R__t)
return 0;
1015 if (!
R__t)
return 0;
1017 finalString <<
" R__b >> *reinterpret_cast<Int_t*>(ptr_enum); }" << std::endl;
1022 if (!
R__t)
return 0;
1027 if (!
R__t)
return 1;
1032 if (!
R__t)
return 0;
1033 finalString <<
" {TString R__str(" <<
R__t <<
".c_str());" << std::endl
1034 <<
" R__str.Streamer(R__b);};" << std::endl;
1038 if (!
R__t)
return 0;
1039 finalString <<
" {TString R__str(" <<
R__t <<
"->c_str());" << std::endl
1040 <<
" R__str.Streamer(R__b);}" << std::endl;
1044 if (!
R__t)
return 1;
1049 if (!
R__t)
return 1;
1062 clang::CXXRecordDecl*
ncCl =
const_cast<clang::CXXRecordDecl*
>(cl);
1065 cling::Interpreter::PushTransactionRAII
clingRAII(
const_cast<cling::Interpreter*
>(&
interpreter));
1068 if (
Ctor->getAccess() == clang::AS_public && !
Ctor->isDeleted()) {
1086 const cling::LookupHelper&
lh =
interpreter.getLookupHelper();
1095 return EIOCtorCategory::kAbsent;
1098 cling::Interpreter::PushTransactionRAII
clingRAII(
const_cast<cling::Interpreter*
>(&
interpreter));
1099 for (
auto iter = cl->ctor_begin(), end = cl->ctor_end(); iter != end; ++iter)
1101 if ((iter->getAccess() != clang::AS_public) || (iter->getNumParams() != 1))
1105 clang::QualType
argType((*iter->param_begin())->getType());
1109 if (
argType->isPointerType()) {
1112 }
else if (
argType->isReferenceType()) {
1119 const clang::CXXRecordDecl *
argDecl =
argType->getAsCXXRecordDecl();
1126 std::string
clarg(
"class ");
1133 return EIOCtorCategory::kAbsent;
1146 if (!
ioctortype.GetType() && (!arg || !arg[0])) {
1160 const cling::Interpreter &
interp,
1163 const clang::FunctionDecl*
funcD
1165 diagnose ? cling::LookupHelper::WithDiagnostics
1166 : cling::LookupHelper::NoDiagnostics);
1168 return llvm::dyn_cast<const clang::CXXMethodDecl>(
funcD);
1177 namespace TMetaUtils {
1180 const cling::LookupHelper&
lh =
interp.getLookupHelper();
1199 const cling::Interpreter &
interp)
1201 if (cl->isAbstract())
return false;
1207 if (EIOCtorCategory::kAbsent ==
ioCtorCat)
1217 if (EIOCtorCategory::kIOPtrType ==
ioCtorCat) {
1219 }
else if (EIOCtorCategory::kIORefType ==
ioCtorCat) {
1223 arg +=
")nullptr )";
1226 const clang::CXXMethodDecl *
method
1228 cling::LookupHelper::NoDiagnostics);
1229 if (
method &&
method->getAccess() != clang::AS_public) {
1243 const cling::Interpreter&
interp)
1245 if (!cl)
return false;
1247 if (cl->hasUserDeclaredDestructor()) {
1249 cling::Interpreter::PushTransactionRAII
clingRAII(
const_cast<cling::Interpreter*
>(&
interp));
1250 clang::CXXDestructorDecl *
dest = cl->getDestructor();
1252 return (
dest->getAccess() == clang::AS_public);
1266 const cling::Interpreter &
interp,
1269 const clang::CXXMethodDecl *
method
1271 diagnose ? cling::LookupHelper::WithDiagnostics
1272 : cling::LookupHelper::NoDiagnostics);
1273 return (
method &&
method->getAccess() == clang::AS_public);
1284 const char *
proto =
"TDirectory*";
1285 const char *
name =
"DirectoryAutoAdd";
1299 const char *
proto =
"TCollection*,TFileMergeInfo*";
1300 const char *
name =
"Merge";
1313 const char *
proto =
"TCollection*";
1314 const char *
name =
"Merge";
1329 const char *
proto =
"TFileMergeInfo*";
1330 const char *
name =
"ResetAfterMerge";
1340 const clang::CXXRecordDecl*
clxx,
1341 const cling::Interpreter &
interp,
1344 static const char *
proto =
"TBuffer&";
1346 const clang::CXXMethodDecl *
method
1348 cling::LookupHelper::NoDiagnostics);
1359 const clang::CXXRecordDecl*
clxx,
1360 const cling::Interpreter &
interp,
1363 static const char *
proto =
"TBuffer&,TClass*";
1365 const clang::CXXMethodDecl *
method
1367 cling::LookupHelper::NoDiagnostics);
1432 llvm::raw_string_ostream stream(
qual_name);
1433 clang::PrintingPolicy
policy( cl.getASTContext().getPrintingPolicy() );
1434 policy.SuppressTagKeyword =
true;
1435 policy.SuppressUnwrittenScope =
true;
1437 cl.getNameForDiagnostic(stream,
policy,
true);
1493 std::stringstream
dims;
1496 const clang::ASTContext&
astContext = cl.getASTContext();
1499 for(clang::RecordDecl::field_iterator
field_iter = cl.field_begin(), end = cl.field_end();
1513 const clang::ConstantArrayType *
arrayType = llvm::dyn_cast<clang::ConstantArrayType>(
fieldType.getTypePtr());
1515 dims <<
"[" <<
arrayType->getSize().getLimitedValue() <<
"]";
1517 arrayType = llvm::dyn_cast<clang::ConstantArrayType>(
arrayType->getArrayElementTypeNoTypeQual());
1527 for(clang::CXXRecordDecl::base_class_const_iterator iter = cl.bases_begin(), end = cl.bases_end();
1530 std::string
basename( iter->getType()->getAsCXXRecordDecl()->getNameAsString() );
1540 const cling::Interpreter &
interp,
1544 diagnose ? cling::LookupHelper::WithDiagnostics
1545 : cling::LookupHelper::NoDiagnostics);
1604 while (llvm::isa<clang::PointerType>(
instanceType.getTypePtr())
1605 || llvm::isa<clang::ReferenceType>(
instanceType.getTypePtr()))
1610 const clang::ElaboratedType* etype
1611 = llvm::dyn_cast<clang::ElaboratedType>(
instanceType.getTypePtr());
1613 instanceType = clang::QualType(etype->getNamedType().getTypePtr(),0);
1627 if (
clxx &&
clxx->getTemplateSpecializationKind() != clang::TSK_Undeclared) {
1629 const clang::TemplateSpecializationType*
TST
1630 = llvm::dyn_cast<const clang::TemplateSpecializationType>(
instanceType.getTypePtr());
1637 for (
const clang::TemplateArgument &
TA :
TST->template_arguments()) {
1638 if (
TA.getKind() == clang::TemplateArgument::Type) {
1650 const cling::Interpreter &
interp,
1653 const clang::CXXRecordDecl *
clxx = llvm::dyn_cast<clang::CXXRecordDecl>(cl.
GetRecordDecl());
1654 if (!
clxx ||
clxx->getTemplateSpecializationKind() == clang::TSK_Undeclared)
return false;
1657 cling::LookupHelper::WithDiagnostics);
1671 clang::AnnotateAttr*
annAttr = clang::dyn_cast<clang::AnnotateAttr>(
attribute);
1714 for (clang::Decl::attr_iterator
attrIt =
decl.attr_begin();
1716 clang::AnnotateAttr*
annAttr = clang::dyn_cast<clang::AnnotateAttr>(*
attrIt);
1720 std::pair<llvm::StringRef,llvm::StringRef> split =
attribute.split(propNames::separator.c_str());
1721 if (split.first !=
propName.c_str())
continue;
1737 for (clang::Decl::attr_iterator
attrIt =
decl.attr_begin();
1739 clang::AnnotateAttr*
annAttr = clang::dyn_cast<clang::AnnotateAttr>(*
attrIt);
1743 std::pair<llvm::StringRef,llvm::StringRef> split =
attribute.split(propNames::separator.c_str());
1744 if (split.first !=
propName.c_str())
continue;
1746 return split.second.getAsInteger(10,
propValue);
1757 const clang::CXXRecordDecl *
decl,
1758 const cling::Interpreter &
interp,
1767 std::string
csymbol = classname;
1781 bool isStd = TMetaUtils::IsStdClass(*
decl);
1782 const cling::LookupHelper&
lh =
interp.getLookupHelper();
1792 <<
" static void " <<
mappedname.c_str() <<
"_TClassManip(TClass*);\n";
1810 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";
1813 finalString <<
" static void directoryAutoAdd_" <<
mappedname.c_str() <<
"(void *obj, TDirectory *dir);" <<
"\n";
1816 finalString <<
" static void streamer_" <<
mappedname.c_str() <<
"(TBuffer &buf, void *obj);" <<
"\n";
1819 finalString <<
" static void conv_streamer_" <<
mappedname.c_str() <<
"(TBuffer &buf, void *obj, const TClass*);" <<
"\n";
1822 finalString <<
" static Long64_t merge_" <<
mappedname.c_str() <<
"(void *obj, TCollection *coll,TFileMergeInfo *info);" <<
"\n";
1825 finalString <<
" static void reset_" <<
mappedname.c_str() <<
"(void *obj, TFileMergeInfo *info);" <<
"\n";
1844 finalString <<
"\n // Schema evolution read functions\n";
1845 std::list<ROOT::SchemaRuleMap_t>::iterator
rIt =
rulesIt1->second.fRules.
begin();
1863 if(
rIt->find(
"code" ) !=
rIt->
end() ) {
1879 finalString <<
"\n // Schema evolution read raw functions\n";
1880 std::list<ROOT::SchemaRuleMap_t>::iterator
rIt =
rulesIt2->second.fRules.
begin();
1906 finalString <<
"\n" <<
" // Function generating the singleton type initializer" <<
"\n";
1908 finalString <<
" static TGenericClassInfo *GenerateInitInstanceLocal(const " <<
csymbol <<
"*)" <<
"\n" <<
" {" <<
"\n";
1914 finalString <<
" static ::TVirtualIsAProxy* isa_proxy = new ::TInstrumentedIsAProxy< " <<
csymbol <<
" >(nullptr);" <<
"\n";
1917 finalString <<
" static ::TVirtualIsAProxy* isa_proxy = new ::TIsAProxy(typeid(" <<
csymbol <<
"));" <<
"\n";
1919 finalString <<
" static ::ROOT::TGenericClassInfo " <<
"\n" <<
" instance(\"" << classname.c_str() <<
"\", ";
1932 static const char *
versionFunc =
"GetClassVersion";
1936 std::string
proto = classname +
"*";
1937 const clang::Decl*
ctxt = llvm::dyn_cast<clang::Decl>((*cl).getDeclContext());
1940 interp, cling::LookupHelper::NoDiagnostics);
1959 for (
unsigned int i=0; i<
filename.length(); i++) {
1964 <<
"," <<
"\n" <<
" typeid(" <<
csymbol
1965 <<
"), ::ROOT::Internal::DefineBehavior(ptr, ptr)," <<
"\n" <<
" ";
1988 finalString <<
" instance.SetDelete(&delete_" <<
mappedname.c_str() <<
");" <<
"\n" <<
" instance.SetDeleteArray(&deleteArray_" <<
mappedname.c_str() <<
");" <<
"\n" <<
" instance.SetDestructor(&destruct_" <<
mappedname.c_str() <<
");" <<
"\n";
1991 finalString <<
" instance.SetDirectoryAutoAdd(&directoryAutoAdd_" <<
mappedname.c_str() <<
");" <<
"\n";
1999 finalString <<
" instance.SetConvStreamerFunc(&conv_streamer_" <<
mappedname.c_str() <<
");" <<
"\n";
2008 finalString <<
" instance.AdoptCollectionProxyInfo(TCollectionProxyInfo::Generate(TCollectionProxyInfo::" <<
"Pushback" <<
"<Internal::TStdBitsetHelper< " << classname.c_str() <<
" > >()));" <<
"\n";
2011 }
else if (
stl != 0 &&
2014 int idx = classname.find(
"<");
2043 finalString <<
" instance.AdoptCollectionProxyInfo(TCollectionProxyInfo::Generate(TCollectionProxyInfo::" <<
methodTCP <<
"< " <<
classNameForIO.c_str() <<
" >()));" <<
"\n";
2053 finalString <<
"\n" <<
" instance.AdoptAlternate(::ROOT::AddClassAlternate(\""
2060 finalString <<
"\n" <<
" instance.AdoptAlternate(::ROOT::AddClassAlternate(\""
2070 finalString <<
"\n" <<
" ::ROOT::Internal::TSchemaHelper* rule;" <<
"\n";
2074 finalString <<
"\n" <<
" // the io read rules" <<
"\n" <<
" std::vector<::ROOT::Internal::TSchemaHelper> readrules(" <<
rulesIt1->second.size() <<
");" <<
"\n";
2076 finalString <<
" instance.SetReadRules( readrules );" <<
"\n";
2077 rulesIt1->second.fGenerated =
true;
2081 finalString <<
"\n" <<
" // the io read raw rules" <<
"\n" <<
" std::vector<::ROOT::Internal::TSchemaHelper> readrawrules(" <<
rulesIt2->second.size() <<
");" <<
"\n";
2083 finalString <<
" instance.SetReadRawRules( readrawrules );" <<
"\n";
2084 rulesIt2->second.fGenerated =
true;
2087 finalString <<
" return &instance;" <<
"\n" <<
" }" <<
"\n";
2091 finalString <<
" TGenericClassInfo *GenerateInitInstance(const " <<
csymbol <<
"*)" <<
"\n" <<
" {\n return GenerateInitInstanceLocal(static_cast<" <<
csymbol <<
"*>(nullptr));\n }" <<
"\n";
2094 finalString <<
" // Static variable to force the class initialization" <<
"\n";
2098 finalString <<
" static ::ROOT::TGenericClassInfo *_R__UNIQUE_DICT_(Init) = GenerateInitInstanceLocal(static_cast<const " <<
csymbol <<
"*>(nullptr)); R__UseDummy(_R__UNIQUE_DICT_(Init));" <<
"\n";
2101 finalString <<
"\n" <<
" // Dictionary for non-ClassDef classes" <<
"\n"
2102 <<
" static TClass *" <<
mappedname <<
"_Dictionary() {\n"
2103 <<
" TClass* theClass ="
2104 <<
"::ROOT::GenerateInitInstanceLocal(static_cast<const " <<
csymbol <<
"*>(nullptr))->GetClass();\n"
2105 <<
" " <<
mappedname <<
"_TClassManip(theClass);\n";
2116 if (
decl->hasAttrs()){
2118 for (clang::Decl::attr_iterator
attrIt =
decl->attr_begin();
2135 manipString+=
" theClass->CreateAttributeMap();\n";
2136 manipString+=
" TDictAttributeMap* attrMap( theClass->GetAttributeMap() );\n";
2147 if (!(!(*internalDeclIt)->isImplicit()
2168 TMetaUtils::Error(
nullptr,
"Cannot convert field declaration to clang::NamedDecl");
2184 if (
attrName == propNames::comment ||
2186 attrName == propNames::ioname )
continue;
2211 finalString <<
"} // end of namespace ROOT" <<
"\n" <<
"\n";
2216 const cling::Interpreter &
interp)
2220 const clang::Type *
typeptr =
nullptr;
2221 const clang::CXXRecordDecl *
target =
2226 std::string
rule{
nRules > 1 ?
"rules" :
"rule"};
2227 std::string
verb{
nRules > 1 ?
"were" :
"was"};
2245 finalString <<
"\n // Schema evolution read functions\n";
2246 std::list<ROOT::SchemaRuleMap_t>::iterator
rIt =
rulesIt1.second.fRules.
begin();
2287 finalString <<
" // Registration Schema evolution read functions\n";
2291 <<
" ::ROOT::Internal::TSchemaHelper* rule;" <<
"\n";
2300 finalString <<
" std::vector<::ROOT::Internal::TSchemaHelper> readrules(" <<
rulesIt1->second.size()
2303 finalString <<
" TClass::RegisterReadRules(TSchemaRule::kReadRule, \"" <<
name
2304 <<
"\", std::move(readrules));\n";
2305 rulesIt1->second.fGenerated =
true;
2310 finalString <<
" std::vector<::ROOT::Internal::TSchemaHelper> readrawrules(" <<
rulesIt2->second.size()
2313 finalString <<
" TClass::RegisterReadRules(TSchemaRule::kReadRawRule, \"" <<
name
2314 <<
"\", std::move(readrawrules));\n";
2315 rulesIt2->second.fGenerated =
true;
2335 const clang::CXXRecordDecl *cl)
2345 auto ctxt = cl->getEnclosingNamespaceContext();
2350 const clang::NamedDecl *
namedCtxt = llvm::dyn_cast<clang::NamedDecl>(
ctxt);
2352 const clang::NamespaceDecl *
nsdecl = llvm::dyn_cast<clang::NamespaceDecl>(
namedCtxt);
2367 const clang::DeclContext *
ctxt = cl.getDeclContext();
2368 while(
ctxt && !
ctxt->isNamespace()) {
2389 const clang::NamespaceDecl *ns = llvm::dyn_cast<clang::NamespaceDecl>(
ctxt);
2395 out <<
"namespace " << ns->getNameAsString() <<
" {" << std::endl;
2414 clang::TemplateSpecializationKind kind = cl->getTemplateSpecializationKind();
2415 if (kind == clang::TSK_Undeclared ) {
2418 }
else if (kind == clang::TSK_ExplicitSpecialization) {
2433 const char *
proto =
"size_t";
2440 cling::LookupHelper::NoDiagnostics);
2444 cling::LookupHelper::NoDiagnostics);
2446 const clang::DeclContext *
ctxtnew =
nullptr;
2482 const clang::CXXRecordDecl*
clnew = llvm::dyn_cast<clang::CXXRecordDecl>(
ctxtnew);
2529 const clang::CXXRecordDecl *
decl,
2530 const cling::Interpreter &
interp,
2554 classname.insert(0,
"::");
2562 finalString <<
" // Wrappers around operator new" <<
"\n";
2563 finalString <<
" static void *new_" <<
mappedname.c_str() <<
"(void *p) {" <<
"\n" <<
" return p ? ";
2570 finalString <<
"::new(static_cast<::ROOT::Internal::TOperatorNewHelper*>(p)) ";
2575 finalString <<
"new " << classname.c_str() << args <<
";" <<
"\n";
2590 finalString <<
"::new(static_cast<::ROOT::Internal::TOperatorNewHelper*>(p)) ";
2604 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";
2608 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";
2612 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";
2616 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";
2620 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";
2622 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";
2626 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";
2628 finalString <<
"} // end of namespace ROOT for class " << classname.c_str() <<
"\n" <<
"\n";
2635 const cling::Interpreter &
interp,
2646 const clang::CXXRecordDecl *
clxx = llvm::dyn_cast<clang::CXXRecordDecl>(cl.
GetRecordDecl());
2650 for(clang::CXXRecordDecl::base_class_const_iterator iter =
clxx->bases_begin(), end =
clxx->bases_end();
2656 Internal::RStl::Instance().GenerateTClassFor( iter->getType(),
interp,
normCtxt);
2661 for(clang::RecordDecl::field_iterator
field_iter =
clxx->field_begin(), end =
clxx->field_end();
2693 const clang::Type *
rawtype =
m.getType()->getCanonicalTypeInternal().getTypePtr();
2709 const clang::CXXRecordDecl*
CRD = llvm::dyn_cast<clang::CXXRecordDecl>(cl);
2721 if (
funcCV == (clang::FunctionDecl*)-1)
return 1;
2736 using res_t = std::pair<bool, int>;
2738 const clang::CompoundStmt*
FuncBody
2739 = llvm::dyn_cast_or_null<clang::CompoundStmt>(
funcCV->getBody());
2741 return res_t{
false, -1};
2746 return res_t{
false, -1};
2748 const clang::ReturnStmt*
RetStmt
2749 = llvm::dyn_cast<clang::ReturnStmt>(
FuncBody->body_back());
2751 return res_t{
false, -1};
2763 return res_t{
false, -1};
2771 return TMetaUtils::IsSTLCont(*
annotated.GetRecordDecl());
2779 clang::QualType
type =
m.getType();
2782 if (
decl)
return TMetaUtils::IsSTLCont(*
decl);
2791 clang::QualType
type = base.getType();
2794 if (
decl)
return TMetaUtils::IsSTLCont(*
decl);
2804 const std::function<
void(
const clang::Module::Header &)> &
closure,
2812 llvm::SetVector<const clang::Module *>
modules;
2814 for (
size_t i = 0; i <
modules.size(); ++i) {
2815 const clang::Module *M =
modules[i];
2816 for (
const clang::Module *
subModule : M->submodules())
2820 for (
const clang::Module *
m :
modules) {
2822 for (clang::Module *
used :
m->DirectUses) {
2828 for (
auto HK : {clang::Module::HK_Normal, clang::Module::HK_Textual, clang::Module::HK_Private,
2829 clang::Module::HK_PrivateTextual}) {
2846 static char t[4096];
2847 static const char*
constwd =
"const ";
2856 if (
lev==0 && *s==
'*')
continue;
2862 if (
lev==0 && *s==
' ' && *(s+1)!=
'*') {
p = t;
continue;}
2863 if (
p - t > (
long)
sizeof(t)) {
2864 printf(
"ERROR (rootcling): type name too long for StortTypeName: %s\n",
2877 const cling::Interpreter&
interp)
2882 if (!comment.empty() && comment[0] ==
'!')
2885 clang::QualType
type =
m.getType();
2887 if (
type->isReferenceType()) {
2892 std::string
mTypeName =
type.getAsString(
m.getASTContext().getPrintingPolicy());
2904 const clang::Type *
rawtype =
type.getTypePtr()->getBaseElementTypeUnsafe ();
2906 if (
rawtype->isPointerType()) {
2920 const clang::CXXRecordDecl *
cxxdecl =
rawtype->getAsCXXRecordDecl();
2937 const clang::Type *
rawtype =
m.getType().getTypePtr();
2961 return rawtype->getAsCXXRecordDecl();
2970 const cling::Interpreter &
interp,
2976 const clang::CXXRecordDecl*
decl = llvm::dyn_cast<clang::CXXRecordDecl>(cl.
GetRecordDecl());
2978 if (!
decl || !
decl->isCompleteDefinition()) {
2982 std::string fullname;
2996 ROOT::TMetaUtils::Info(
nullptr,
"Class %s: Do not generate Streamer() [*** custom streamer ***]\n",fullname.c_str());
3021 const clang::ASTContext&
Ctx =
interpreter.getCI()->getASTContext();
3027 if (llvm::isa<clang::PointerType>(
instanceType.getTypePtr())) {
3041 if (llvm::isa<clang::ReferenceType>(
instanceType.getTypePtr())) {
3061 clang::NestedNameSpecifier *prefix =
nullptr;
3063 const clang::ElaboratedType* etype
3064 = llvm::dyn_cast<clang::ElaboratedType>(
instanceType.getTypePtr());
3069 instanceType = clang::QualType(etype->getNamedType().getTypePtr(),0);
3075 const clang::TemplateSpecializationType*
TST
3076 = llvm::dyn_cast<const clang::TemplateSpecializationType>(
instanceType.getTypePtr());
3078 const clang::ClassTemplateSpecializationDecl*
TSTdecl
3079 = llvm::dyn_cast_or_null<const clang::ClassTemplateSpecializationDecl>(
instanceType.getTypePtr()->getAsCXXRecordDecl());
3095 clang::TemplateDecl *Template =
TSTdecl->getSpecializedTemplate()->getMostRecentDecl();
3096 clang::TemplateParameterList *Params = Template->getTemplateParameters();
3103 llvm::SmallVector<clang::TemplateArgument, 4>
desArgs;
3104 llvm::SmallVector<clang::TemplateArgument, 4>
canonArgs;
3113 if (
I->getKind() == clang::TemplateArgument::Template) {
3120 clang::NamespaceDecl* ns = clang::dyn_cast<clang::NamespaceDecl>(
declCtxt);
3121 clang::NestedNameSpecifier*
nns;
3123 nns = cling::utils::TypeName::CreateNestedNameSpecifier(
Ctx, ns);
3124 }
else if (clang::TagDecl*
TD = llvm::dyn_cast<clang::TagDecl>(
declCtxt)) {
3125 nns = cling::utils::TypeName::CreateNestedNameSpecifier(
Ctx,
TD,
false );
3132 if (clang::UsingShadowDecl *
USD =
templateName.getAsUsingShadowDecl())
3142 if (
I->getKind() != clang::TemplateArgument::Type) {
3147 clang::QualType
SubTy =
I->getAsType();
3169 if (
templateArg.getKind() != clang::TemplateArgument::Type) {
3175 clang::SourceLocation
TemplateLoc = Template->getSourceRange ().getBegin();
3178 clang::TemplateTypeParmDecl *
TTP = llvm::dyn_cast<clang::TemplateTypeParmDecl>(*
Param);
3181 cling::Interpreter::PushTransactionRAII
clingRAII(
const_cast<cling::Interpreter*
>(&
interpreter));
3183 clang::TemplateArgumentLoc
ArgType = S.SubstDefaultTemplateArgumentIfAvailable(
3193 if (
ArgType.getArgument().isNull()
3194 ||
ArgType.getArgument().getKind() != clang::TemplateArgument::Type) {
3196 "Template parameter substitution failed for %s around %s\n",
3216 TST->getCanonicalTypeInternal());
3245 llvm::StringRef title;
3248 if (clang::AnnotateAttr *A =
m.getAttr<clang::AnnotateAttr>())
3249 title = A->getAnnotation();
3263 if (title.size() == 0 || (title[0] !=
'['))
return llvm::StringRef();
3265 if (
rightbracket == llvm::StringRef::npos)
return llvm::StringRef();
3284 char *current =
const_cast<char*
>(
working.c_str());
3290 for(i=0;i<
strlen(current);i++) {
3298 return llvm::StringRef();
3303 const clang::CXXRecordDecl *
parent_clxx = llvm::dyn_cast<clang::CXXRecordDecl>(
m.getDeclContext());
3304 const clang::FieldDecl *
index1 =
nullptr;
3317 if (
field_iter->getNameAsString() ==
m.getNameAsString() ) {
3325 return llvm::StringRef();
3337 return llvm::StringRef();
3362 return llvm::StringRef();
3364 if ( found && (
index1->getAccess() == clang::AS_private) ) {
3369 return llvm::StringRef();
3378 return llvm::StringRef();
3399 while((
c = in[i++])) {
3400 const char *
repl =
nullptr;
3402 case '+':
repl =
"pL";
break;
3403 case '-':
repl =
"mI";
break;
3404 case '*':
repl =
"mU";
break;
3405 case '/':
repl =
"dI";
break;
3406 case '&':
repl =
"aN";
break;
3407 case '%':
repl =
"pE";
break;
3408 case '|':
repl =
"oR";
break;
3409 case '^':
repl =
"hA";
break;
3410 case '>':
repl =
"gR";
break;
3411 case '<':
repl =
"lE";
break;
3412 case '=':
repl =
"eQ";
break;
3413 case '~':
repl =
"wA";
break;
3414 case '.':
repl =
"dO";
break;
3415 case '(':
repl =
"oP";
break;
3416 case ')':
repl =
"cP";
break;
3417 case '[':
repl =
"oB";
break;
3418 case ']':
repl =
"cB";
break;
3419 case '{':
repl =
"lB";
break;
3420 case '}':
repl =
"rB";
break;
3421 case ';':
repl =
"sC";
break;
3422 case '#':
repl =
"hS";
break;
3423 case '?':
repl =
"qM";
break;
3424 case '`':
repl =
"bT";
break;
3425 case '!':
repl =
"nO";
break;
3426 case ',':
repl =
"cO";
break;
3427 case '$':
repl =
"dA";
break;
3428 case ' ':
repl =
"sP";
break;
3429 case ':':
repl =
"cL";
break;
3430 case '"':
repl =
"dQ";
break;
3431 case '@':
repl =
"aT";
break;
3432 case '\'':
repl =
"sQ";
break;
3433 case '\\':
repl =
"fI";
break;
3442 if (out.empty() ||
isdigit(out[0]))
3443 out.insert(out.begin(),
'_');
3446static clang::SourceLocation
3460 const cling::Interpreter&
interp)
3490 using namespace clang;
3515 ArrayRef<std::pair<OptionalFileEntryRef, DirectoryEntryRef>>(),
3530 assert(
decl.isFirstDecl() &&
"Couldn't trace back include from a decl"
3531 " that is not from an AST file");
3556 clang::OptionalFileEntryRef
FELong;
3558 for (llvm::sys::path::const_iterator
3571 &&
"Mismatched partitioning of file name!");
3575 ArrayRef<std::pair<OptionalFileEntryRef, DirectoryEntryRef>>(),
3587 for (llvm::sys::path::reverse_iterator
3595 &&
"Mismatched partitioning of file name!");
3601 ArrayRef<std::pair<OptionalFileEntryRef, DirectoryEntryRef>>(),
3604 nullptr,
nullptr ) ==
FELong) {
3615 const clang::QualType &
qtype,
3627 const clang::QualType &
qtype,
3633 cling::Interpreter::PushTransactionRAII
RAII(
const_cast<cling::Interpreter*
>(&
interpreter));
3645 clang::ClassTemplateDecl*&
ctd,
3646 clang::ClassTemplateSpecializationDecl*&
ctsd)
3648 using namespace clang;
3656 if (
theType->isPointerType()) {
3661 ctsd = llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(
rType->getDecl());
3663 ctd =
ctsd->getSpecializedTemplate();
3673 ctsd = llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(
qt->getAsCXXRecordDecl());
3675 ctd =
ctsd->getSpecializedTemplate();
3690 using namespace clang;
3706 using namespace clang;
3725 const clang::NamedDecl&
tPar,
3726 const cling::Interpreter&
interp,
3730 using namespace clang;
3735 if (!
ttpdPtr->hasDefaultArgument())
return false;
3757 const clang::ElaboratedType* etype
3758 = llvm::dyn_cast<clang::ElaboratedType>(
tParQualType.getTypePtr());
3760 tParQualType = clang::QualType(etype->getNamedType().getTypePtr(),0);
3761 etype = llvm::dyn_cast<clang::ElaboratedType>(
tParQualType.getTypePtr());
3765 llvm::dyn_cast<TemplateSpecializationType>(
tParQualType.getTypePtr());
3771 = llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(
tArgQualType->getAsCXXRecordDecl());
3789 clang::Sema& S =
interp.getCI()->getSema();
3790 cling::Interpreter::PushTransactionRAII
clingRAII(
const_cast<cling::Interpreter*
>(&
interp));
3791 llvm::SmallVector<clang::TemplateArgument, 4>
canonArgs;
3804 newArg.getKind() != clang::TemplateArgument::Type) {
3806 "Template parameter substitution failed!");
3810 = llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(
newArg.getAsType()->getAsCXXRecordDecl());
3826 const clang::NamedDecl&
tPar)
3828 using namespace clang;
3833 if (!
nttpd.hasDefaultArgument())
3844 const int value =
tArg.getAsIntegral().getLimitedValue();
3857 using namespace clang;
3858 if (!
nDecl)
return false;
3860 return ttpd->hasDefaultArgument();
3862 return nttpd->hasDefaultArgument();
3869 const cling::Interpreter&
interp,
3874 const clang::TemplateArgument &
tArg,
3875 const cling::Interpreter&
interp,
3877 const clang::ASTContext&
astCtxt)
3880 using namespace clang;
3887 if (
tArg.getKind() == clang::TemplateArgument::Type) {
3896 }
else if (
normTArg.getKind() == clang::TemplateArgument::Pack) {
3897 assert(
tArg.getKind() == clang::TemplateArgument::Pack );
3925 const cling::Interpreter&
interp,
3929 using namespace clang;
3938 const int nArgsToKeep =
normCtxt.GetNargsToKeep(
ctd);
3948 if (llvm::isa<clang::PointerType>(
normalizedType.getTypePtr())) {
3961 if (llvm::isa<clang::ReferenceType>(
normalizedType.getTypePtr())) {
3980 clang::NestedNameSpecifier* prefix =
nullptr;
3982 const clang::ElaboratedType* etype
3983 = llvm::dyn_cast<clang::ElaboratedType>(
normalizedType.getTypePtr());
3989 normalizedType = clang::QualType(etype->getNamedType().getTypePtr(),0);
3997 clang::TemplateParameterList*
tpl =
rd->getTemplateParameters();
3998 if (
tpl->getMinRequiredArguments () <
tpl->size()) {
4005 Error(
"KeepNParams",
"Not found template default arguments\n");
4022 llvm::dyn_cast<TemplateSpecializationType>(
normalizedType.getTypePtr());
4028 const clang::ClassTemplateSpecializationDecl*
TSTdecl
4029 = llvm::dyn_cast_or_null<const clang::ClassTemplateSpecializationDecl>(
normalizedType.getTypePtr()->getAsCXXRecordDecl());
4037 llvm::SmallVector<TemplateArgument, 4>
argsToKeep;
4049 Error(
"KeepNParams",
"The parameter number %s is null.\n",
formal);
4071 if (
tParPtr->isTemplateParameterPack() ) {
4101 if (
argKind == clang::TemplateArgument::Type){
4104 }
else if (
argKind == clang::TemplateArgument::Integral){
4152 cling::Interpreter::PushTransactionRAII
RAII(
const_cast<cling::Interpreter*
>(&
interpreter));
4175 if (
type.isNull()) {
4183 clang::PrintingPolicy
policy(
ctxt.getPrintingPolicy());
4184 policy.SuppressTagKeyword =
true;
4185 policy.SuppressScope =
true;
4186 policy.AnonymousTagLocations =
false;
4194 cling::Interpreter::PushTransactionRAII
clingRAII(
const_cast<cling::Interpreter*
>(&
interpreter));
4227 clang::ASTContext&
astCtxt =
sema.getASTContext();
4237std::pair<std::string,clang::QualType>
4258 cling::LookupHelper::DiagSetting::NoDiagnostics,
4277 "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());
4305 llvm::errs() << llvm::StringRef(
commentStart, 80) <<
'\n';
4354 if (
const clang::FunctionDecl*
FD = clang::dyn_cast<clang::FunctionDecl>(&
decl)) {
4355 if (
FD->isImplicit()) {
4359 if (
FD->isExplicitlyDefaulted() ||
FD->isDeletedAsWritten()) {
4363 }
else if (
FD->doesThisDeclarationHaveABody()) {
4368 &&
"Expected macro or end of body at '}'");
4380 }
else if (
const clang::EnumConstantDecl*
ECD
4381 = clang::dyn_cast<clang::EnumConstantDecl>(&
decl)) {
4383 if (
ECD->getNextDeclInContext())
4460 if (!
decl)
return false;
4467 static const std::vector<std::string>
signatures =
4468 {
"ClassDef",
"ClassDefOverride",
"ClassDefNV",
"ClassDefInline",
"ClassDefInlineOverride",
"ClassDefInlineNV" };
4485 clang::SourceLocation *
loc,
4488 using namespace clang;
4491 =
interpreter.getLookupHelper().findFunctionProto(&
decl,
"DeclFileLine",
"",
4492 cling::LookupHelper::NoDiagnostics);
4498 if (comment.size()) {
4505 return llvm::StringRef();
4517 if (
rawtype->isElaboratedTypeSpecifier() ) {
4521 rawtype =
type.getTypePtr()->getBaseElementTypeUnsafe ();
4530 if (
rawtype->isElaboratedTypeSpecifier() ) {
4550 if (
ctxt.isNamespace() ||
ctxt.isTranslationUnit())
4552 else if(
const auto parentdecl = llvm::dyn_cast<clang::CXXRecordDecl>(&
ctxt))
4565 const clang::DeclContext *
ctxt =
decl.getDeclContext();
4566 switch (
decl.getAccess()) {
4567 case clang::AS_public:
4569 case clang::AS_protected:
4571 case clang::AS_private:
4573 case clang::AS_none:
4577 assert(
false &&
"Unexpected value for the access property value in Clang");
4587 return cling::utils::Analyze::IsStdClass(cl);
4597 if (cling::utils::Analyze::IsStdClass(cl)) {
4598 static const char *names[] =
4599 {
"shared_ptr",
"__shared_ptr",
4600 "vector",
"list",
"deque",
"map",
"multimap",
"set",
"multiset",
"bitset"};
4601 llvm::StringRef
clname(cl.getName());
4602 for(
auto &&
name : names) {
4640 const clang::CXXRecordDecl *
thisDecl =
4641 llvm::dyn_cast_or_null<clang::CXXRecordDecl>(
lh.findScope(
typ, cling::LookupHelper::WithDiagnostics));
4645 Error(
"IsOfType",
"Record decl of type %s not found in the AST.",
typ.c_str());
4675 if (!IsStdClass(cl)) {
4676 auto *
nsDecl = llvm::dyn_cast<clang::NamespaceDecl>(cl.getDeclContext());
4677 if (cl.getName() !=
"RVec" ||
nsDecl ==
nullptr ||
nsDecl->getName() !=
"VecOps")
4680 auto *
parentNsDecl = llvm::dyn_cast<clang::NamespaceDecl>(cl.getDeclContext()->getParent());
4685 return STLKind(cl.getName());
4689 using namespace clang;
4690 struct SearchTypedef:
public TypeVisitor<SearchTypedef, bool> {
4695 return Visit(
AT->getElementType().getTypePtr());
4698 return Visit(
DT->getUnderlyingType().getTypePtr());
4701 return Visit(
PT->getPointeeType().getTypePtr());
4704 return Visit(
RT->getPointeeType().getTypePtr());
4707 return Visit(
STST->getReplacementType().getTypePtr());
4711 if (
TA.getKind() == TemplateArgument::Type && Visit(
TA.getAsType().getTypePtr()))
4720 return TOT->getUnmodifiedType().getTypePtr();
4725 if (
NNS->getKind() == NestedNameSpecifier::TypeSpec) {
4726 if (Visit(
NNS->getAsType()))
4731 return Visit(
ET->getNamedType().getTypePtr());
4752 using namespace llvm;
4753 using namespace clang;
4754 const clang::ASTContext &
Ctxt =
instance->getAsCXXRecordDecl()->getASTContext();
4757 const clang::ElaboratedType* etype
4758 = llvm::dyn_cast<clang::ElaboratedType>(
input.getTypePtr());
4763 assert(
instance->getAsCXXRecordDecl() !=
nullptr &&
"ReSubstTemplateArg only makes sense with a type representing a class.");
4783 if (
nQT ==
QT->getPointeeType())
return QT;
4799 if (
nQT ==
QT->getPointeeType())
return QT;
4820 if (
newQT ==
arr->getElementType())
return QT;
4824 arr->getSizeModifier(),
4825 arr->getIndexTypeCVRQualifiers());
4833 arr->getSizeModifier(),
4834 arr->getIndexTypeCVRQualifiers(),
4835 arr->getBracketsRange());
4840 if (
newQT ==
arr->getElementType())
return QT;
4842 arr->getSizeModifier(),
4843 arr->getIndexTypeCVRQualifiers());
4848 if (
newQT ==
arr->getElementType())
return QT;
4851 arr->getSizeModifier(),
4852 arr->getIndexTypeCVRQualifiers(),
4853 arr->getBracketsRange());
4862 etype = llvm::dyn_cast<clang::ElaboratedType>(
instance);
4864 instance = etype->getNamedType().getTypePtr();
4868 const clang::TemplateSpecializationType*
TST
4869 = llvm::dyn_cast<const clang::TemplateSpecializationType>(
instance);
4873 const clang::ClassTemplateSpecializationDecl*
TSTdecl
4874 = llvm::dyn_cast_or_null<const clang::ClassTemplateSpecializationDecl>(
instance->getAsCXXRecordDecl());
4878 const clang::SubstTemplateTypeParmType *
substType
4879 = llvm::dyn_cast<clang::SubstTemplateTypeParmType>(
input.getTypePtr());
4883 const clang::ClassTemplateDecl *
replacedCtxt =
nullptr;
4887 unsigned int index =
substType->getReplacedParameter()->getIndex();
4890 if (
decl->getKind() == clang::Decl::ClassTemplatePartialSpecialization) {
4891 const clang::ClassTemplatePartialSpecializationDecl *
spec = llvm::dyn_cast<clang::ClassTemplatePartialSpecializationDecl>(
decl);
4893 unsigned int depth =
substType->getReplacedParameter()->getDepth();
4909 const clang::SubstTemplateTypeParmType *
argType
4910 = llvm::dyn_cast<clang::SubstTemplateTypeParmType>(
argQualType);
4935 llvm::raw_string_ostream ostream(
astDump);
4938 ROOT::TMetaUtils::Warning(
"ReSubstTemplateArg",
"Unexpected type of declaration context for template parameter: %s.\n\tThe responsible class is:\n\t%s\n",
4945 const auto &
TAs =
TST->template_arguments();
4962 const clang::TemplateSpecializationType*
inputTST
4963 = llvm::dyn_cast<const clang::TemplateSpecializationType>(
input.getTypePtr());
4968 llvm::SmallVector<clang::TemplateArgument, 4>
desArgs;
4969 for (
const clang::TemplateArgument &
TA :
inputTST->template_arguments()) {
4970 if (
TA.getKind() != clang::TemplateArgument::Type) {
4975 clang::QualType
SubTy =
TA.getAsType();
4977 if (llvm::isa<clang::ElaboratedType>(
SubTy)
4978 || llvm::isa<clang::SubstTemplateTypeParmType>(
SubTy)
4979 || llvm::isa<clang::TemplateSpecializationType>(
SubTy)) {
4994 inputTST->getCanonicalTypeInternal());
5035 static const char *
stls[] =
5036 {
"any",
"vector",
"list",
"deque",
"map",
"multimap",
"set",
"multiset",
"bitset",
5037 "forward_list",
"unordered_set",
"unordered_multiset",
"unordered_map",
"unordered_multimap",
"RVec",
nullptr};
5051 for (
int k = 1;
stls[k]; k++) {
5065 TND =
TND->getMostRecentDecl();
5066 while (
TND && !(
TND->hasAttrs()))
5067 TND =
TND->getPreviousDecl();
5079 TD =
TD->getMostRecentDecl();
5080 while (
TD && !(
TD->hasAttrs() &&
TD->isThisDeclarationADefinition()))
5081 TD =
TD->getPreviousDecl();
5137 std::list<std::pair<std::string,unsigned int> >&
enclosingSc)
5165 std::string::size_type
beginVar = 0;
5166 std::string::size_type
endVar = 0;
5170 std::string::size_type
endVarName = std::string::npos;
5240 str.replace(
start_pos, from.length(), to);
5307 return llvm::sys::path::extension(
filename) ==
".h" ||
5308 llvm::sys::path::extension(
filename) ==
".hh" ||
5309 llvm::sys::path::extension(
filename) ==
".hpp" ||
5310 llvm::sys::path::extension(
filename) ==
".H" ||
5311 llvm::sys::path::extension(
filename) ==
".h++" ||
5312 llvm::sys::path::extension(
filename) ==
"hxx" ||
5313 llvm::sys::path::extension(
filename) ==
"Hxx" ||
5314 llvm::sys::path::extension(
filename) ==
"HXX";
5320 cling::Interpreter::IgnoreFilesFunc_t
ignoreFiles,
5321 const cling::Interpreter &
interp,
5329 clang::Decl *
ncDecl =
const_cast<clang::Decl *
>(
decl);
5374 static const std::string
scopeType [] = {
"namespace ",
"inline namespace ",
"class "};
5416 std::string typeName;
5419 if (llvm::isa<clang::TemplateTypeParmDecl>(
nDecl)){
5420 typeName =
"typename ";
5421 if (
nDecl->isParameterPack())
5423 typeName += (*prmIt)->getNameAsString();
5426 else if (
auto nttpd = llvm::dyn_cast<clang::NonTypeTemplateParmDecl>(
nDecl)){
5430 if (
theType.getAsString().find(
"enum") != std::string::npos){
5432 llvm::raw_string_ostream ostream(
astDump);
5433 nttpd->dump(ostream);
5444 else if (
auto ttpd = llvm::dyn_cast<clang::TemplateTemplateParmDecl>(
nDecl)){
5448 llvm::raw_string_ostream ostream(
astDump);
5449 ttpd->dump(ostream);
5474 "Cannot extract template parameter list for %s",
5482 "Problems with arguments for forward declaration of class %s\n",
5492 if (llvm::isa<clang::TemplateTemplateParmDecl>(&
templDecl)) {
5514 if (clang::TemplateArgument::Type != arg.getKind())
return 0;
5529 if (llvm::isa<clang::BuiltinType>(
argTypePtr)){
5562 if (
specDef->getTemplateSpecializationKind() != clang::TSK_ExplicitSpecialization)
5566 std::cout <<
" Forward declaring template spec " <<
normalizedName <<
":\n";
5571 std::cout <<
" o Template argument ";
5573 std::cout <<
"successfully treated. Arg fwd decl: " <<
argFwdDecl << std::endl;
5575 std::cout <<
"could not be treated. Abort fwd declaration generation.\n";
5616 std::cout <<
"Class " <<
recordDecl.getNameAsString()
5617 <<
" is a template specialisation. Treating its arguments.\n";
5621 std::cout <<
" o Template argument ";
5623 std::cout <<
"successfully treated. Arg fwd decl: " <<
argFwdDecl << std::endl;
5625 std::cout <<
"could not be treated. Abort fwd declaration generation.\n";
5673 std::string buffer =
tdnDecl.getNameAsString();
5676 if (
const clang::TagType* TT
5678 if (clang::NamedDecl*
ND = TT->getDecl()) {
5679 if (!
ND->getIdentifier()) {
5723 std::cout <<
"Typedef " <<
tdnDecl.getNameAsString() <<
" hides a class: "
5750 const clang::PrintingPolicy&
ppolicy)
5753 auto&
ctxt = par.getASTContext();
5774 if (
result.isNegative()){
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)
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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 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 target
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_iterator end() const
A RAII helper to remove and readd enclosing _Atomic() It expects no spaces at the beginning or end of...
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)
void GetNormalizedName(std::string &norm_name, std::string_view name)
Return the normalized name.
bool IsSTLBitset(const char *type)
Return true is the name is std::bitset<number> or bitset<number>
constexpr Double_t C()
Velocity of light in .