24#include <unordered_set>
27#include "RConfigure.h"
36#include "clang/AST/ASTContext.h"
37#include "clang/AST/Attr.h"
38#include "clang/AST/CXXInheritance.h"
39#include "clang/AST/Decl.h"
40#include "clang/AST/DeclTemplate.h"
41#include "clang/AST/Mangle.h"
42#include "clang/AST/Type.h"
43#include "clang/AST/TypeVisitor.h"
44#include "clang/Frontend/CompilerInstance.h"
45#include "clang/Lex/HeaderSearch.h"
46#include "clang/Lex/ModuleMap.h"
47#include "clang/Lex/Preprocessor.h"
48#include "clang/Lex/PreprocessorOptions.h"
50#include "clang/Sema/Lookup.h"
51#include "clang/Sema/Sema.h"
52#include "clang/Sema/SemaDiagnostic.h"
54#include "cling/Interpreter/LookupHelper.h"
55#include "cling/Interpreter/Transaction.h"
56#include "cling/Interpreter/Interpreter.h"
57#include "cling/Utils/AST.h"
58#include "cling/Interpreter/InterpreterAccessRAII.h"
60#include "llvm/Support/Path.h"
61#include "llvm/Support/FileSystem.h"
66#define strncasecmp _strnicmp
86 using DeclsCont_t = TNormalizedCtxt::Config_t::SkipCollection;
103 bool replace =
false);
114 clang::NestedNameSpecifier*
scope,
117 if (!
scope)
return nullptr;
140static bool CheckDefinition(
const clang::CXXRecordDecl *cl,
const clang::CXXRecordDecl *context)
142 if (!cl->hasDefinition()) {
145 "Missing definition for class %s, please #include its header in the header of %s\n",
146 cl->getName().str().c_str(), context->getName().str().c_str());
149 "Missing definition for class %s\n",
150 cl->getName().str().c_str());
163 clang::NestedNameSpecifier *
scope,
166 if (!
scope)
return nullptr;
188 const clang::BuiltinType *
builtin = llvm::dyn_cast<clang::BuiltinType>(
type->getCanonicalTypeInternal().getTypePtr());
208 clang::ASTContext &
C = cl.getASTContext();
209 clang::DeclarationName
DName = &
C.Idents.get(
what);
210 auto R = cl.lookup(
DName);
211 for (
const clang::NamedDecl *D :
R)
223 clang::LookupResult
R(
SemaR,
DName, clang::SourceLocation(),
224 clang::Sema::LookupOrdinaryName,
225 RedeclarationKind::ForExternalRedeclaration);
226 SemaR.LookupInSuper(
R, &
const_cast<clang::CXXRecordDecl&
>(cl));
229 return llvm::dyn_cast<const clang::FieldDecl>(
R.getFoundDecl());
235 ? cling::LookupHelper::WithDiagnostics
236 : cling::LookupHelper::NoDiagnostics;
243namespace TMetaUtils {
252 Error(
"TNormalizedCtxt::AddTemplAndNargsToKeep",
253 "Tring to specify a number of template arguments to keep for a null pointer. Exiting without assigning any value.\n");
257 const clang::ClassTemplateDecl*
canTempl =
templ->getCanonicalDecl();
262 const std::string
i_str (std::to_string(i));
264 Error(
"TNormalizedCtxt::AddTemplAndNargsToKeep",
265 "Tring to specify for template %s %s arguments to keep, while before this number was %s\n",
266 canTempl->getNameAsString().c_str(),
279 const clang::ClassTemplateDecl*
constTempl =
templ->getCanonicalDecl();
330 std::unique_ptr<clang::MangleContext>
mangleCtx(
rDecl->getASTContext().createMangleContext());
334 if (
const clang::TypeDecl*
TD = llvm::dyn_cast<clang::TypeDecl>(
rDecl)) {
335 mangleCtx->mangleCXXRTTI(clang::QualType(
TD->getTypeForDecl(), 0),
sstr);
361 "Demangled typeinfo name '%s' does not contain `RTTI Type Descriptor'\n",
365 "Demangled typeinfo name '%s' does not start with 'typeinfo for'\n",
382 const clang::RecordDecl *
decl,
413 const clang::RecordDecl *
decl,
444 "Could not remove the requested template arguments.\n");
455 const clang::RecordDecl *
decl,
491 const clang::RecordDecl *
decl,
540 fCheckInClassTable(CheckInClassTable),
554 if (
tname.empty())
return false;
579 if (!
dest.isNull() && (
dest != t)) {
599 if (!
dest.isNull() && (
dest != t) &&
621 const clang::NamespaceDecl *
nsdecl = llvm::dyn_cast<clang::NamespaceDecl>(
scope);
634 if (
tname.empty())
return false;
666 clang::PrintingPolicy
policy(
fInterpreter->getCI()->getASTContext().getPrintingPolicy());
667 policy.SuppressTagKeyword =
true;
668 policy.SuppressScope =
true;
683 for(
unsigned int i = 1; i<
result.length(); ++i) {
695 }
else if ( (i+1) <
result.length() &&
733 clang::QualType
toSkip =
lh.findType(
name, cling::LookupHelper::WithDiagnostics);
734 if (
const clang::Type* T =
toSkip.getTypePtr()) {
735 const clang::TypedefType *
tt = llvm::dyn_cast<clang::TypedefType>(T);
737 clang::Decl* D =
tt->getDecl();
738 fConfig.m_toSkip.insert(D);
740 clang::QualType
canon =
toSkip->getCanonicalTypeInternal();
741 fConfig.m_toReplace.insert(std::make_pair(
canon.getTypePtr(),T));
743 fTypeWithAlternative.insert(T);
756 keepTypedef(
lh,
"Double32_t");
757 keepTypedef(
lh,
"Float16_t");
758 keepTypedef(
lh,
"Long64_t",
true);
759 keepTypedef(
lh,
"ULong64_t",
true);
761 clang::QualType
toSkip =
lh.findType(
"string", cling::LookupHelper::WithDiagnostics);
763 if (
const clang::TypedefType* TT
764 = llvm::dyn_cast_or_null<clang::TypedefType>(
toSkip.getTypePtr()))
765 fConfig.m_toSkip.insert(TT->getDecl());
767 toSkip =
lh.findType(
"std::string", cling::LookupHelper::WithDiagnostics);
769 if (
const clang::TypedefType* TT
770 = llvm::dyn_cast_or_null<clang::TypedefType>(
toSkip.getTypePtr()))
771 fConfig.m_toSkip.insert(TT->getDecl());
773 clang::QualType
canon =
toSkip->getCanonicalTypeInternal();
774 fConfig.m_toReplace.insert(std::make_pair(
canon.getTypePtr(),
toSkip.getTypePtr()));
785 return (cl.getKind() == clang::Decl::ClassTemplatePartialSpecialization
786 || cl.getKind() == clang::Decl::ClassTemplateSpecialization);
793 const cling::Interpreter&
interp)
795 clang::Sema* S = &
interp.getSema();
796 const clang::NamedDecl*
ND = cling::utils::Lookup::Named(S,
name, cl);
797 if (
ND == (clang::NamedDecl*)-1)
798 return (clang::FunctionDecl*)-1;
799 return llvm::dyn_cast_or_null<clang::FunctionDecl>(
ND);
805const clang::CXXRecordDecl *
809 const cling::LookupHelper&
lh =
interp.getLookupHelper();
812 const clang::CXXRecordDecl *
result
813 = llvm::dyn_cast_or_null<clang::CXXRecordDecl>
820 result = llvm::dyn_cast_or_null<clang::CXXRecordDecl>
831 clang::QualType
qType(cl->getTypeForDecl(),0);
839 clang::Sema& S =
interp.getCI()->getSema();
842 cling::Interpreter::PushTransactionRAII
RAII(
const_cast<cling::Interpreter*
>(&
interp));
843 return S.RequireCompleteType(
Loc, Type, clang::diag::err_incomplete_type);
849 const clang::CXXRecordDecl *context,
const cling::Interpreter &
interp)
855 if (!cl->getDefinition() || !cl->isCompleteDefinition()) {
863 if (!base->hasDefinition()) {
867 return cl->isDerivedFrom(base);
879 const clang::NamedDecl *base
883 return IsBase(
CRD, llvm::dyn_cast<clang::CXXRecordDecl>( base ),
884 llvm::dyn_cast<clang::CXXRecordDecl>(
m.getDeclContext()),
interp);
893 const clang::QualType &
qti,
895 const cling::Interpreter &
interp,
903 kBIT_ISSTRING = 0x40000000,
910 const clang::Type &
ti( *
qti.getTypePtr() );
933 if (
tiName ==
"string")
kase |= kBIT_ISSTRING;
934 if (
tiName ==
"string*")
kase |= kBIT_ISSTRING;
938 tcl =
" internal error in rootcling ";
963 <<
" R__b >> readtemp;" << std::endl
964 <<
" " <<
R__t <<
" = static_cast<" <<
tiName <<
">(readtemp);" << std::endl;
976 finalString <<
" if (R__b.GetInfo() && R__b.GetInfo()->GetOldVersion()<=3) {" << std::endl;
978 finalString <<
" R__ASSERT(0);// " <<
objType <<
" is abstract. We assume that older file could not be produced using this streaming method." << std::endl;
981 <<
" " <<
R__t <<
"->Streamer(R__b);" << std::endl;
984 <<
" " <<
R__t <<
" = (" <<
tiName <<
")R__b.ReadObjectAny(" <<
tcl <<
");" << std::endl
985 <<
" }" << std::endl;
991 <<
" R__str.Streamer(R__b);" << std::endl
992 <<
" " <<
R__t <<
" = R__str.Data();}" << std::endl;
998 <<
" R__str.Streamer(R__b);" << std::endl
999 <<
" " <<
R__t <<
" = new string(R__str.Data());}" << std::endl;
1003 if (!
R__t)
return 1;
1008 if (!
R__t)
return 1;
1019 if (!
R__t)
return 0;
1024 if (!
R__t)
return 0;
1026 finalString <<
" R__b >> *reinterpret_cast<Int_t*>(ptr_enum); }" << std::endl;
1031 if (!
R__t)
return 0;
1036 if (!
R__t)
return 1;
1041 if (!
R__t)
return 0;
1042 finalString <<
" {TString R__str(" <<
R__t <<
".c_str());" << std::endl
1043 <<
" R__str.Streamer(R__b);};" << std::endl;
1047 if (!
R__t)
return 0;
1048 finalString <<
" {TString R__str(" <<
R__t <<
"->c_str());" << std::endl
1049 <<
" R__str.Streamer(R__b);}" << std::endl;
1053 if (!
R__t)
return 1;
1058 if (!
R__t)
return 1;
1071 clang::CXXRecordDecl*
ncCl =
const_cast<clang::CXXRecordDecl*
>(cl);
1074 cling::Interpreter::PushTransactionRAII
clingRAII(
const_cast<cling::Interpreter*
>(&
interpreter));
1077 if (
Ctor->getAccess() == clang::AS_public && !
Ctor->isDeleted()) {
1095 const cling::LookupHelper&
lh =
interpreter.getLookupHelper();
1104 return EIOCtorCategory::kAbsent;
1107 cling::Interpreter::PushTransactionRAII
clingRAII(
const_cast<cling::Interpreter*
>(&
interpreter));
1108 for (
auto iter = cl->ctor_begin(), end = cl->ctor_end(); iter != end; ++iter)
1110 if ((iter->getAccess() != clang::AS_public) || (iter->getNumParams() != 1))
1114 clang::QualType
argType((*iter->param_begin())->getType());
1118 if (
argType->isPointerType()) {
1121 }
else if (
argType->isReferenceType()) {
1128 const clang::CXXRecordDecl *
argDecl =
argType->getAsCXXRecordDecl();
1135 std::string
clarg(
"class ");
1142 return EIOCtorCategory::kAbsent;
1155 if (!
ioctortype.GetType() && (!arg || !arg[0])) {
1169 const cling::Interpreter &
interp,
1172 const clang::FunctionDecl*
funcD
1174 diagnose ? cling::LookupHelper::WithDiagnostics
1175 : cling::LookupHelper::NoDiagnostics);
1177 return llvm::dyn_cast<const clang::CXXMethodDecl>(
funcD);
1186 namespace TMetaUtils {
1189 const cling::LookupHelper&
lh =
interp.getLookupHelper();
1208 const cling::Interpreter &
interp)
1210 if (cl->isAbstract())
return false;
1216 if (EIOCtorCategory::kAbsent ==
ioCtorCat)
1226 if (EIOCtorCategory::kIOPtrType ==
ioCtorCat) {
1228 }
else if (EIOCtorCategory::kIORefType ==
ioCtorCat) {
1232 arg +=
")nullptr )";
1235 const clang::CXXMethodDecl *
method
1237 cling::LookupHelper::NoDiagnostics);
1238 if (
method &&
method->getAccess() != clang::AS_public) {
1252 const cling::Interpreter&
interp)
1254 if (!cl)
return false;
1256 if (cl->hasUserDeclaredDestructor()) {
1258 cling::Interpreter::PushTransactionRAII
clingRAII(
const_cast<cling::Interpreter*
>(&
interp));
1259 clang::CXXDestructorDecl *
dest = cl->getDestructor();
1261 return (
dest->getAccess() == clang::AS_public);
1275 const cling::Interpreter &
interp,
1278 const clang::CXXMethodDecl *
method
1280 diagnose ? cling::LookupHelper::WithDiagnostics
1281 : cling::LookupHelper::NoDiagnostics);
1282 return (
method &&
method->getAccess() == clang::AS_public);
1293 const char *
proto =
"TDirectory*";
1294 const char *
name =
"DirectoryAutoAdd";
1308 const char *
proto =
"TCollection*,TFileMergeInfo*";
1309 const char *
name =
"Merge";
1322 const char *
proto =
"TCollection*";
1323 const char *
name =
"Merge";
1338 const char *
proto =
"TFileMergeInfo*";
1339 const char *
name =
"ResetAfterMerge";
1349 const clang::CXXRecordDecl*
clxx,
1350 const cling::Interpreter &
interp,
1353 static const char *
proto =
"TBuffer&";
1355 const clang::CXXMethodDecl *
method
1357 cling::LookupHelper::NoDiagnostics);
1368 const clang::CXXRecordDecl*
clxx,
1369 const cling::Interpreter &
interp,
1372 static const char *
proto =
"TBuffer&,TClass*";
1374 const clang::CXXMethodDecl *
method
1376 cling::LookupHelper::NoDiagnostics);
1441 llvm::raw_string_ostream stream(
qual_name);
1442 clang::PrintingPolicy
policy( cl.getASTContext().getPrintingPolicy() );
1443 policy.SuppressTagKeyword =
true;
1444 policy.SuppressUnwrittenScope =
true;
1446 cl.getNameForDiagnostic(stream,
policy,
true);
1502 std::stringstream
dims;
1505 const clang::ASTContext&
astContext = cl.getASTContext();
1508 for(clang::RecordDecl::field_iterator
field_iter = cl.field_begin(), end = cl.field_end();
1522 const clang::ConstantArrayType *
arrayType = llvm::dyn_cast<clang::ConstantArrayType>(
fieldType.getTypePtr());
1524 dims <<
"[" <<
arrayType->getSize().getLimitedValue() <<
"]";
1526 arrayType = llvm::dyn_cast<clang::ConstantArrayType>(
arrayType->getArrayElementTypeNoTypeQual());
1536 for(clang::CXXRecordDecl::base_class_const_iterator iter = cl.bases_begin(), end = cl.bases_end();
1539 std::string
basename( iter->getType()->getAsCXXRecordDecl()->getNameAsString() );
1549 const cling::Interpreter &
interp,
1553 diagnose ? cling::LookupHelper::WithDiagnostics
1554 : cling::LookupHelper::NoDiagnostics);
1613 while (llvm::isa<clang::PointerType>(
instanceType.getTypePtr())
1614 || llvm::isa<clang::ReferenceType>(
instanceType.getTypePtr()))
1619 const clang::ElaboratedType* etype
1620 = llvm::dyn_cast<clang::ElaboratedType>(
instanceType.getTypePtr());
1622 instanceType = clang::QualType(etype->getNamedType().getTypePtr(),0);
1636 if (
clxx &&
clxx->getTemplateSpecializationKind() != clang::TSK_Undeclared) {
1638 const clang::TemplateSpecializationType*
TST
1639 = llvm::dyn_cast<const clang::TemplateSpecializationType>(
instanceType.getTypePtr());
1646 for (
const clang::TemplateArgument &
TA :
TST->template_arguments()) {
1647 if (
TA.getKind() == clang::TemplateArgument::Type) {
1659 const cling::Interpreter &
interp,
1662 const clang::CXXRecordDecl *
clxx = llvm::dyn_cast<clang::CXXRecordDecl>(cl.
GetRecordDecl());
1663 if (!
clxx ||
clxx->getTemplateSpecializationKind() == clang::TSK_Undeclared)
return false;
1666 cling::LookupHelper::WithDiagnostics);
1680 clang::AnnotateAttr*
annAttr = clang::dyn_cast<clang::AnnotateAttr>(
attribute);
1723 for (clang::Decl::attr_iterator
attrIt =
decl.attr_begin();
1725 clang::AnnotateAttr*
annAttr = clang::dyn_cast<clang::AnnotateAttr>(*
attrIt);
1729 std::pair<llvm::StringRef,llvm::StringRef> split =
attribute.split(propNames::separator.c_str());
1730 if (split.first !=
propName.c_str())
continue;
1746 for (clang::Decl::attr_iterator
attrIt =
decl.attr_begin();
1748 clang::AnnotateAttr*
annAttr = clang::dyn_cast<clang::AnnotateAttr>(*
attrIt);
1752 std::pair<llvm::StringRef,llvm::StringRef> split =
attribute.split(propNames::separator.c_str());
1753 if (split.first !=
propName.c_str())
continue;
1755 return split.second.getAsInteger(10,
propValue);
1766 const clang::CXXRecordDecl *
decl,
1767 const cling::Interpreter &
interp,
1776 std::string
csymbol = classname;
1790 bool isStd = TMetaUtils::IsStdClass(*
decl);
1791 const cling::LookupHelper&
lh =
interp.getLookupHelper();
1801 <<
" static void " <<
mappedname.c_str() <<
"_TClassManip(TClass*);\n";
1819 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";
1822 finalString <<
" static void directoryAutoAdd_" <<
mappedname.c_str() <<
"(void *obj, TDirectory *dir);" <<
"\n";
1825 finalString <<
" static void streamer_" <<
mappedname.c_str() <<
"(TBuffer &buf, void *obj);" <<
"\n";
1828 finalString <<
" static void conv_streamer_" <<
mappedname.c_str() <<
"(TBuffer &buf, void *obj, const TClass*);" <<
"\n";
1831 finalString <<
" static Long64_t merge_" <<
mappedname.c_str() <<
"(void *obj, TCollection *coll,TFileMergeInfo *info);" <<
"\n";
1834 finalString <<
" static void reset_" <<
mappedname.c_str() <<
"(void *obj, TFileMergeInfo *info);" <<
"\n";
1853 finalString <<
"\n // Schema evolution read functions\n";
1854 std::list<ROOT::SchemaRuleMap_t>::iterator
rIt =
rulesIt1->second.fRules.
begin();
1872 if(
rIt->find(
"code" ) !=
rIt->
end() ) {
1888 finalString <<
"\n // Schema evolution read raw functions\n";
1889 std::list<ROOT::SchemaRuleMap_t>::iterator
rIt =
rulesIt2->second.fRules.
begin();
1915 finalString <<
"\n" <<
" // Function generating the singleton type initializer" <<
"\n";
1917 finalString <<
" static TGenericClassInfo *GenerateInitInstanceLocal(const " <<
csymbol <<
"*)" <<
"\n" <<
" {" <<
"\n";
1923 finalString <<
" static ::TVirtualIsAProxy* isa_proxy = new ::TInstrumentedIsAProxy< " <<
csymbol <<
" >(nullptr);" <<
"\n";
1926 finalString <<
" static ::TVirtualIsAProxy* isa_proxy = new ::TIsAProxy(typeid(" <<
csymbol <<
"));" <<
"\n";
1928 finalString <<
" static ::ROOT::TGenericClassInfo " <<
"\n" <<
" instance(\"" << classname.c_str() <<
"\", ";
1941 static const char *
versionFunc =
"GetClassVersion";
1945 std::string
proto = classname +
"*";
1946 const clang::Decl*
ctxt = llvm::dyn_cast<clang::Decl>((*cl).getDeclContext());
1949 interp, cling::LookupHelper::NoDiagnostics);
1968 for (
unsigned int i=0; i<
filename.length(); i++) {
1973 <<
"," <<
"\n" <<
" typeid(" <<
csymbol
1974 <<
"), ::ROOT::Internal::DefineBehavior(ptr, ptr)," <<
"\n" <<
" ";
1997 finalString <<
" instance.SetDelete(&delete_" <<
mappedname.c_str() <<
");" <<
"\n" <<
" instance.SetDeleteArray(&deleteArray_" <<
mappedname.c_str() <<
");" <<
"\n" <<
" instance.SetDestructor(&destruct_" <<
mappedname.c_str() <<
");" <<
"\n";
2000 finalString <<
" instance.SetDirectoryAutoAdd(&directoryAutoAdd_" <<
mappedname.c_str() <<
");" <<
"\n";
2008 finalString <<
" instance.SetConvStreamerFunc(&conv_streamer_" <<
mappedname.c_str() <<
");" <<
"\n";
2017 finalString <<
" instance.AdoptCollectionProxyInfo(TCollectionProxyInfo::Generate(TCollectionProxyInfo::" <<
"Pushback" <<
"<Internal::TStdBitsetHelper< " << classname.c_str() <<
" > >()));" <<
"\n";
2020 }
else if (
stl != 0 &&
2023 int idx = classname.find(
"<");
2052 finalString <<
" instance.AdoptCollectionProxyInfo(TCollectionProxyInfo::Generate(TCollectionProxyInfo::" <<
methodTCP <<
"< " <<
classNameForIO.c_str() <<
" >()));" <<
"\n";
2062 finalString <<
"\n" <<
" instance.AdoptAlternate(::ROOT::AddClassAlternate(\""
2069 finalString <<
"\n" <<
" instance.AdoptAlternate(::ROOT::AddClassAlternate(\""
2087 finalString <<
"\n" <<
" ::ROOT::Internal::TSchemaHelper* rule;" <<
"\n";
2091 finalString <<
"\n" <<
" // the io read rules" <<
"\n" <<
" std::vector<::ROOT::Internal::TSchemaHelper> readrules(" <<
rulesIt1->second.size() <<
");" <<
"\n";
2093 finalString <<
" instance.SetReadRules( readrules );" <<
"\n";
2094 rulesIt1->second.fGenerated =
true;
2098 finalString <<
"\n" <<
" // the io read raw rules" <<
"\n" <<
" std::vector<::ROOT::Internal::TSchemaHelper> readrawrules(" <<
rulesIt2->second.size() <<
");" <<
"\n";
2100 finalString <<
" instance.SetReadRawRules( readrawrules );" <<
"\n";
2101 rulesIt2->second.fGenerated =
true;
2104 finalString <<
" return &instance;" <<
"\n" <<
" }" <<
"\n";
2108 finalString <<
" TGenericClassInfo *GenerateInitInstance(const " <<
csymbol <<
"*)" <<
"\n" <<
" {\n return GenerateInitInstanceLocal(static_cast<" <<
csymbol <<
"*>(nullptr));\n }" <<
"\n";
2111 finalString <<
" // Static variable to force the class initialization" <<
"\n";
2115 finalString <<
" static ::ROOT::TGenericClassInfo *_R__UNIQUE_DICT_(Init) = GenerateInitInstanceLocal(static_cast<const " <<
csymbol <<
"*>(nullptr)); R__UseDummy(_R__UNIQUE_DICT_(Init));" <<
"\n";
2118 finalString <<
"\n" <<
" // Dictionary for non-ClassDef classes" <<
"\n"
2119 <<
" static TClass *" <<
mappedname <<
"_Dictionary() {\n"
2120 <<
" TClass* theClass ="
2121 <<
"::ROOT::GenerateInitInstanceLocal(static_cast<const " <<
csymbol <<
"*>(nullptr))->GetClass();\n"
2122 <<
" " <<
mappedname <<
"_TClassManip(theClass);\n";
2133 if (
decl->hasAttrs()){
2135 for (clang::Decl::attr_iterator
attrIt =
decl->attr_begin();
2152 manipString+=
" theClass->CreateAttributeMap();\n";
2153 manipString+=
" TDictAttributeMap* attrMap( theClass->GetAttributeMap() );\n";
2164 if (!(!(*internalDeclIt)->isImplicit()
2185 TMetaUtils::Error(
nullptr,
"Cannot convert field declaration to clang::NamedDecl");
2201 if (
attrName == propNames::comment ||
2203 attrName == propNames::ioname )
continue;
2228 finalString <<
"} // end of namespace ROOT" <<
"\n" <<
"\n";
2233 const cling::Interpreter &
interp)
2237 const clang::Type *
typeptr =
nullptr;
2238 const clang::CXXRecordDecl *
target =
2243 std::string
rule{
nRules > 1 ?
"rules" :
"rule"};
2244 std::string
verb{
nRules > 1 ?
"were" :
"was"};
2262 finalString <<
"\n // Schema evolution read functions\n";
2263 std::list<ROOT::SchemaRuleMap_t>::iterator
rIt =
rulesIt1.second.fRules.
begin();
2304 finalString <<
" // Registration Schema evolution read functions\n";
2308 <<
" ::ROOT::Internal::TSchemaHelper* rule;" <<
"\n";
2317 finalString <<
" std::vector<::ROOT::Internal::TSchemaHelper> readrules(" <<
rulesIt1->second.size()
2320 finalString <<
" TClass::RegisterReadRules(TSchemaRule::kReadRule, \"" <<
name
2321 <<
"\", std::move(readrules));\n";
2322 rulesIt1->second.fGenerated =
true;
2327 finalString <<
" std::vector<::ROOT::Internal::TSchemaHelper> readrawrules(" <<
rulesIt2->second.size()
2330 finalString <<
" TClass::RegisterReadRules(TSchemaRule::kReadRawRule, \"" <<
name
2331 <<
"\", std::move(readrawrules));\n";
2332 rulesIt2->second.fGenerated =
true;
2352 const clang::CXXRecordDecl *cl)
2362 auto ctxt = cl->getEnclosingNamespaceContext();
2367 const clang::NamedDecl *
namedCtxt = llvm::dyn_cast<clang::NamedDecl>(
ctxt);
2369 const clang::NamespaceDecl *
nsdecl = llvm::dyn_cast<clang::NamespaceDecl>(
namedCtxt);
2384 const clang::DeclContext *
ctxt = cl.getDeclContext();
2385 while(
ctxt && !
ctxt->isNamespace()) {
2406 const clang::NamespaceDecl *ns = llvm::dyn_cast<clang::NamespaceDecl>(
ctxt);
2412 out <<
"namespace " << ns->getNameAsString() <<
" {" << std::endl;
2431 clang::TemplateSpecializationKind kind = cl->getTemplateSpecializationKind();
2432 if (kind == clang::TSK_Undeclared ) {
2435 }
else if (kind == clang::TSK_ExplicitSpecialization) {
2450 const char *
proto =
"size_t";
2457 cling::LookupHelper::NoDiagnostics);
2461 cling::LookupHelper::NoDiagnostics);
2463 const clang::DeclContext *
ctxtnew =
nullptr;
2499 const clang::CXXRecordDecl*
clnew = llvm::dyn_cast<clang::CXXRecordDecl>(
ctxtnew);
2546 const clang::CXXRecordDecl *
decl,
2547 const cling::Interpreter &
interp,
2571 classname.insert(0,
"::");
2579 finalString <<
" // Wrappers around operator new" <<
"\n";
2580 finalString <<
" static void *new_" <<
mappedname.c_str() <<
"(void *p) {" <<
"\n" <<
" return p ? ";
2587 finalString <<
"::new(static_cast<::ROOT::Internal::TOperatorNewHelper*>(p)) ";
2592 finalString <<
"new " << classname.c_str() << args <<
";" <<
"\n";
2607 finalString <<
"::new(static_cast<::ROOT::Internal::TOperatorNewHelper*>(p)) ";
2621 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";
2625 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";
2629 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";
2633 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";
2637 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";
2639 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";
2643 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";
2645 finalString <<
"} // end of namespace ROOT for class " << classname.c_str() <<
"\n" <<
"\n";
2652 const cling::Interpreter &
interp,
2663 const clang::CXXRecordDecl *
clxx = llvm::dyn_cast<clang::CXXRecordDecl>(cl.
GetRecordDecl());
2667 for(clang::CXXRecordDecl::base_class_const_iterator iter =
clxx->bases_begin(), end =
clxx->bases_end();
2673 Internal::RStl::Instance().GenerateTClassFor( iter->getType(),
interp,
normCtxt);
2678 for(clang::RecordDecl::field_iterator
field_iter =
clxx->field_begin(), end =
clxx->field_end();
2710 const clang::Type *
rawtype =
m.getType()->getCanonicalTypeInternal().getTypePtr();
2726 const clang::CXXRecordDecl*
CRD = llvm::dyn_cast<clang::CXXRecordDecl>(cl);
2738 if (
funcCV == (clang::FunctionDecl*)-1)
return 1;
2753 using res_t = std::pair<bool, int>;
2755 const clang::CompoundStmt*
FuncBody
2756 = llvm::dyn_cast_or_null<clang::CompoundStmt>(
funcCV->getBody());
2758 return res_t{
false, -1};
2763 return res_t{
false, -1};
2765 const clang::ReturnStmt*
RetStmt
2766 = llvm::dyn_cast<clang::ReturnStmt>(
FuncBody->body_back());
2768 return res_t{
false, -1};
2780 return res_t{
false, -1};
2788 return TMetaUtils::IsSTLCont(*
annotated.GetRecordDecl());
2796 clang::QualType
type =
m.getType();
2799 if (
decl)
return TMetaUtils::IsSTLCont(*
decl);
2808 clang::QualType
type = base.getType();
2811 if (
decl)
return TMetaUtils::IsSTLCont(*
decl);
2821 const std::function<
void(
const clang::Module::Header &)> &
closure,
2829 llvm::SetVector<const clang::Module *>
modules;
2831 for (
size_t i = 0; i <
modules.size(); ++i) {
2832 const clang::Module *M =
modules[i];
2833 for (
const clang::Module *
subModule : M->submodules())
2837 for (
const clang::Module *
m :
modules) {
2839 for (clang::Module *
used :
m->DirectUses) {
2845 for (
auto HK : {clang::Module::HK_Normal, clang::Module::HK_Textual, clang::Module::HK_Private,
2846 clang::Module::HK_PrivateTextual}) {
2863 static char t[4096];
2864 static const char*
constwd =
"const ";
2873 if (
lev==0 && *s==
'*')
continue;
2879 if (
lev==0 && *s==
' ' && *(s+1)!=
'*') {
p = t;
continue;}
2880 if (
p - t > (
long)
sizeof(t)) {
2881 printf(
"ERROR (rootcling): type name too long for StortTypeName: %s\n",
2894 const cling::Interpreter&
interp)
2899 if (!comment.empty() && comment[0] ==
'!')
2902 clang::QualType
type =
m.getType();
2904 if (
type->isReferenceType()) {
2909 std::string
mTypeName =
type.getAsString(
m.getASTContext().getPrintingPolicy());
2921 const clang::Type *
rawtype =
type.getTypePtr()->getBaseElementTypeUnsafe ();
2923 if (
rawtype->isPointerType()) {
2937 const clang::CXXRecordDecl *
cxxdecl =
rawtype->getAsCXXRecordDecl();
2954 const clang::Type *
rawtype =
m.getType().getTypePtr();
2978 return rawtype->getAsCXXRecordDecl();
2987 const cling::Interpreter &
interp,
2993 const clang::CXXRecordDecl*
decl = llvm::dyn_cast<clang::CXXRecordDecl>(cl.
GetRecordDecl());
2995 if (!
decl || !
decl->isCompleteDefinition()) {
2999 std::string fullname;
3013 ROOT::TMetaUtils::Info(
nullptr,
"Class %s: Do not generate Streamer() [*** custom streamer ***]\n",fullname.c_str());
3038 const clang::ASTContext&
Ctx =
interpreter.getCI()->getASTContext();
3044 if (llvm::isa<clang::PointerType>(
instanceType.getTypePtr())) {
3058 if (llvm::isa<clang::ReferenceType>(
instanceType.getTypePtr())) {
3078 clang::NestedNameSpecifier *prefix =
nullptr;
3080 const clang::ElaboratedType* etype
3081 = llvm::dyn_cast<clang::ElaboratedType>(
instanceType.getTypePtr());
3086 instanceType = clang::QualType(etype->getNamedType().getTypePtr(),0);
3092 const clang::TemplateSpecializationType*
TST
3093 = llvm::dyn_cast<const clang::TemplateSpecializationType>(
instanceType.getTypePtr());
3095 const clang::ClassTemplateSpecializationDecl*
TSTdecl
3096 = llvm::dyn_cast_or_null<const clang::ClassTemplateSpecializationDecl>(
instanceType.getTypePtr()->getAsCXXRecordDecl());
3112 clang::TemplateDecl *
Template =
TSTdecl->getSpecializedTemplate()->getMostRecentDecl();
3113 clang::TemplateParameterList *Params =
Template->getTemplateParameters();
3120 llvm::SmallVector<clang::TemplateArgument, 4>
desArgs;
3121 llvm::SmallVector<clang::TemplateArgument, 4>
canonArgs;
3135 if (
I->getKind() == clang::TemplateArgument::Template) {
3142 clang::NamespaceDecl* ns = clang::dyn_cast<clang::NamespaceDecl>(
declCtxt);
3143 clang::NestedNameSpecifier*
nns;
3145 nns = cling::utils::TypeName::CreateNestedNameSpecifier(
Ctx, ns);
3146 }
else if (clang::TagDecl*
TD = llvm::dyn_cast<clang::TagDecl>(
declCtxt)) {
3147 nns = cling::utils::TypeName::CreateNestedNameSpecifier(
Ctx,
TD,
false );
3154 if (clang::UsingShadowDecl *
USD =
templateName.getAsUsingShadowDecl())
3164 if (
I->getKind() != clang::TemplateArgument::Type) {
3169 clang::QualType
SubTy =
I->getAsType();
3191 if (
templateArg.getKind() != clang::TemplateArgument::Type) {
3200 clang::TemplateTypeParmDecl *
TTP = llvm::dyn_cast<clang::TemplateTypeParmDecl>(*
Param);
3203 cling::Interpreter::PushTransactionRAII
clingRAII(
const_cast<cling::Interpreter*
>(&
interpreter));
3205 clang::TemplateArgumentLoc
ArgType = S.SubstDefaultTemplateArgumentIfAvailable(
3215 if (
ArgType.getArgument().isNull()
3216 ||
ArgType.getArgument().getKind() != clang::TemplateArgument::Type) {
3218 "Template parameter substitution failed for %s around %s\n",
3238 TST->getCanonicalTypeInternal());
3267 llvm::StringRef title;
3270 if (clang::AnnotateAttr *A =
m.getAttr<clang::AnnotateAttr>())
3271 title = A->getAnnotation();
3285 if (title.size() == 0 || (title[0] !=
'['))
return llvm::StringRef();
3287 if (
rightbracket == llvm::StringRef::npos)
return llvm::StringRef();
3306 char *current =
const_cast<char*
>(
working.c_str());
3312 for(i=0;i<
strlen(current);i++) {
3320 return llvm::StringRef();
3325 const clang::CXXRecordDecl *
parent_clxx = llvm::dyn_cast<clang::CXXRecordDecl>(
m.getDeclContext());
3326 const clang::FieldDecl *
index1 =
nullptr;
3339 if (
field_iter->getNameAsString() ==
m.getNameAsString() ) {
3347 return llvm::StringRef();
3359 return llvm::StringRef();
3384 return llvm::StringRef();
3386 if ( found && (
index1->getAccess() == clang::AS_private) ) {
3391 return llvm::StringRef();
3400 return llvm::StringRef();
3421 while((
c =
in[i++])) {
3422 const char *
repl =
nullptr;
3424 case '+':
repl =
"pL";
break;
3425 case '-':
repl =
"mI";
break;
3426 case '*':
repl =
"mU";
break;
3427 case '/':
repl =
"dI";
break;
3428 case '&':
repl =
"aN";
break;
3429 case '%':
repl =
"pE";
break;
3430 case '|':
repl =
"oR";
break;
3431 case '^':
repl =
"hA";
break;
3432 case '>':
repl =
"gR";
break;
3433 case '<':
repl =
"lE";
break;
3434 case '=':
repl =
"eQ";
break;
3435 case '~':
repl =
"wA";
break;
3436 case '.':
repl =
"dO";
break;
3437 case '(':
repl =
"oP";
break;
3438 case ')':
repl =
"cP";
break;
3439 case '[':
repl =
"oB";
break;
3440 case ']':
repl =
"cB";
break;
3441 case '{':
repl =
"lB";
break;
3442 case '}':
repl =
"rB";
break;
3443 case ';':
repl =
"sC";
break;
3444 case '#':
repl =
"hS";
break;
3445 case '?':
repl =
"qM";
break;
3446 case '`':
repl =
"bT";
break;
3447 case '!':
repl =
"nO";
break;
3448 case ',':
repl =
"cO";
break;
3449 case '$':
repl =
"dA";
break;
3450 case ' ':
repl =
"sP";
break;
3451 case ':':
repl =
"cL";
break;
3452 case '"':
repl =
"dQ";
break;
3453 case '@':
repl =
"aT";
break;
3454 case '\'':
repl =
"sQ";
break;
3455 case '\\':
repl =
"fI";
break;
3464 if (out.empty() ||
isdigit(out[0]))
3465 out.insert(out.begin(),
'_');
3468static clang::SourceLocation
3482 const cling::Interpreter&
interp)
3512 using namespace clang;
3537 ArrayRef<std::pair<OptionalFileEntryRef, DirectoryEntryRef>>(),
3552 assert(
decl.isFirstDecl() &&
"Couldn't trace back include from a decl"
3553 " that is not from an AST file");
3578 clang::OptionalFileEntryRef
FELong;
3580 for (llvm::sys::path::const_iterator
3593 &&
"Mismatched partitioning of file name!");
3597 ArrayRef<std::pair<OptionalFileEntryRef, DirectoryEntryRef>>(),
3609 for (llvm::sys::path::reverse_iterator
3617 &&
"Mismatched partitioning of file name!");
3623 ArrayRef<std::pair<OptionalFileEntryRef, DirectoryEntryRef>>(),
3626 nullptr,
nullptr ) ==
FELong) {
3637 const clang::QualType &
qtype,
3649 const clang::QualType &
qtype,
3655 cling::Interpreter::PushTransactionRAII
RAII(
const_cast<cling::Interpreter*
>(&
interpreter));
3667 clang::ClassTemplateDecl*&
ctd,
3668 clang::ClassTemplateSpecializationDecl*&
ctsd)
3670 using namespace clang;
3678 if (
theType->isPointerType()) {
3683 ctsd = llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(
rType->getDecl());
3685 ctd =
ctsd->getSpecializedTemplate();
3695 ctsd = llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(
qt->getAsCXXRecordDecl());
3697 ctd =
ctsd->getSpecializedTemplate();
3712 using namespace clang;
3728 using namespace clang;
3747 const clang::NamedDecl&
tPar,
3748 const cling::Interpreter&
interp,
3752 using namespace clang;
3757 if (!
ttpdPtr->hasDefaultArgument())
return false;
3779 const clang::ElaboratedType* etype
3780 = llvm::dyn_cast<clang::ElaboratedType>(
tParQualType.getTypePtr());
3782 tParQualType = clang::QualType(etype->getNamedType().getTypePtr(),0);
3783 etype = llvm::dyn_cast<clang::ElaboratedType>(
tParQualType.getTypePtr());
3787 llvm::dyn_cast<TemplateSpecializationType>(
tParQualType.getTypePtr());
3793 = llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(
tArgQualType->getAsCXXRecordDecl());
3811 clang::Sema& S =
interp.getCI()->getSema();
3812 cling::Interpreter::PushTransactionRAII
clingRAII(
const_cast<cling::Interpreter*
>(&
interp));
3813 llvm::SmallVector<clang::TemplateArgument, 4>
canonArgs;
3826 newArg.getKind() != clang::TemplateArgument::Type) {
3828 "Template parameter substitution failed!");
3832 = llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(
newArg.getAsType()->getAsCXXRecordDecl());
3848 const clang::NamedDecl&
tPar)
3850 using namespace clang;
3855 if (!
nttpd.hasDefaultArgument())
3860 if (Expr*
defArgExpr =
nttpd.getDefaultArgument().getArgument().getAsExpr()) {
3866 const int value =
tArg.getAsIntegral().getLimitedValue();
3879 using namespace clang;
3880 if (!
nDecl)
return false;
3882 return ttpd->hasDefaultArgument();
3884 return nttpd->hasDefaultArgument();
3891 const cling::Interpreter&
interp,
3896 const clang::TemplateArgument &
tArg,
3897 const cling::Interpreter&
interp,
3899 const clang::ASTContext&
astCtxt)
3902 using namespace clang;
3909 if (
tArg.getKind() == clang::TemplateArgument::Type) {
3918 }
else if (
normTArg.getKind() == clang::TemplateArgument::Pack) {
3919 assert(
tArg.getKind() == clang::TemplateArgument::Pack );
3947 const cling::Interpreter&
interp,
3951 using namespace clang;
3960 const int nArgsToKeep =
normCtxt.GetNargsToKeep(
ctd);
3970 if (llvm::isa<clang::PointerType>(
normalizedType.getTypePtr())) {
3983 if (llvm::isa<clang::ReferenceType>(
normalizedType.getTypePtr())) {
4002 clang::NestedNameSpecifier* prefix =
nullptr;
4004 const clang::ElaboratedType* etype
4005 = llvm::dyn_cast<clang::ElaboratedType>(
normalizedType.getTypePtr());
4011 normalizedType = clang::QualType(etype->getNamedType().getTypePtr(),0);
4019 clang::TemplateParameterList*
tpl =
rd->getTemplateParameters();
4020 if (
tpl->getMinRequiredArguments () <
tpl->size()) {
4027 Error(
"KeepNParams",
"Not found template default arguments\n");
4044 llvm::dyn_cast<TemplateSpecializationType>(
normalizedType.getTypePtr());
4050 const clang::ClassTemplateSpecializationDecl*
TSTdecl
4051 = llvm::dyn_cast_or_null<const clang::ClassTemplateSpecializationDecl>(
normalizedType.getTypePtr()->getAsCXXRecordDecl());
4059 llvm::SmallVector<TemplateArgument, 4>
argsToKeep;
4072 Error(
"KeepNParams",
"The parameter number %s is null.\n",
formal);
4094 if (
tParPtr->isTemplateParameterPack() ) {
4126 if (
argKind == clang::TemplateArgument::Type){
4129 }
else if (
argKind == clang::TemplateArgument::Integral){
4181 cling::Interpreter::PushTransactionRAII
RAII(
const_cast<cling::Interpreter*
>(&
interpreter));
4204 if (
type.isNull()) {
4212 clang::PrintingPolicy
policy(
ctxt.getPrintingPolicy());
4213 policy.SuppressTagKeyword =
true;
4214 policy.SuppressScope =
true;
4215 policy.AnonymousTagLocations =
false;
4223 cling::Interpreter::PushTransactionRAII
clingRAII(
const_cast<cling::Interpreter*
>(&
interpreter));
4256 clang::ASTContext&
astCtxt =
sema.getASTContext();
4266std::pair<std::string,clang::QualType>
4287 cling::LookupHelper::DiagSetting::NoDiagnostics,
4306 "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());
4334 llvm::errs() << llvm::StringRef(
commentStart, 80) <<
'\n';
4383 if (
const clang::FunctionDecl*
FD = clang::dyn_cast<clang::FunctionDecl>(&
decl)) {
4384 if (
FD->isImplicit()) {
4388 if (
FD->isExplicitlyDefaulted() ||
FD->isDeletedAsWritten()) {
4392 }
else if (
FD->doesThisDeclarationHaveABody()) {
4397 &&
"Expected macro or end of body at '}'");
4409 }
else if (
const clang::EnumConstantDecl*
ECD
4410 = clang::dyn_cast<clang::EnumConstantDecl>(&
decl)) {
4412 if (
ECD->getNextDeclInContext())
4489 if (!
decl)
return false;
4496 static const std::vector<std::string>
signatures =
4497 {
"ClassDef",
"ClassDefOverride",
"ClassDefNV",
"ClassDefInline",
"ClassDefInlineOverride",
"ClassDefInlineNV" };
4514 clang::SourceLocation *
loc,
4517 using namespace clang;
4520 =
interpreter.getLookupHelper().findFunctionProto(&
decl,
"DeclFileLine",
"",
4521 cling::LookupHelper::NoDiagnostics);
4527 if (comment.size()) {
4534 return llvm::StringRef();
4546 if (
rawtype->isElaboratedTypeSpecifier() ) {
4550 rawtype =
type.getTypePtr()->getBaseElementTypeUnsafe ();
4559 if (
rawtype->isElaboratedTypeSpecifier() ) {
4579 if (
ctxt.isNamespace() ||
ctxt.isTranslationUnit())
4581 else if(
const auto parentdecl = llvm::dyn_cast<clang::CXXRecordDecl>(&
ctxt))
4594 const clang::DeclContext *
ctxt =
decl.getDeclContext();
4595 switch (
decl.getAccess()) {
4596 case clang::AS_public:
4598 case clang::AS_protected:
4600 case clang::AS_private:
4602 case clang::AS_none:
4606 assert(
false &&
"Unexpected value for the access property value in Clang");
4616 return cling::utils::Analyze::IsStdClass(cl);
4626 if (cling::utils::Analyze::IsStdClass(cl)) {
4627 static const char *names[] =
4628 {
"shared_ptr",
"__shared_ptr",
4629 "vector",
"list",
"deque",
"map",
"multimap",
"set",
"multiset",
"bitset"};
4630 llvm::StringRef
clname(cl.getName());
4631 for(
auto &&
name : names) {
4669 const clang::CXXRecordDecl *
thisDecl =
4670 llvm::dyn_cast_or_null<clang::CXXRecordDecl>(
lh.findScope(
typ, cling::LookupHelper::WithDiagnostics));
4674 Error(
"IsOfType",
"Record decl of type %s not found in the AST.",
typ.c_str());
4704 if (!IsStdClass(cl)) {
4705 auto *
nsDecl = llvm::dyn_cast<clang::NamespaceDecl>(cl.getDeclContext());
4706 if (cl.getName() !=
"RVec" ||
nsDecl ==
nullptr ||
nsDecl->getName() !=
"VecOps")
4709 auto *
parentNsDecl = llvm::dyn_cast<clang::NamespaceDecl>(cl.getDeclContext()->getParent());
4714 return STLKind(cl.getName());
4718 using namespace clang;
4719 struct SearchTypedef:
public TypeVisitor<SearchTypedef, bool> {
4724 return Visit(
AT->getElementType().getTypePtr());
4727 return Visit(
DT->getUnderlyingType().getTypePtr());
4730 return Visit(
PT->getPointeeType().getTypePtr());
4733 return Visit(
RT->getPointeeType().getTypePtr());
4736 return Visit(
STST->getReplacementType().getTypePtr());
4740 if (
TA.getKind() == TemplateArgument::Type && Visit(
TA.getAsType().getTypePtr()))
4749 return TOT->getUnmodifiedType().getTypePtr();
4754 if (
NNS->getKind() == NestedNameSpecifier::TypeSpec) {
4755 if (Visit(
NNS->getAsType()))
4760 return Visit(
ET->getNamedType().getTypePtr());
4781 using namespace llvm;
4782 using namespace clang;
4783 const clang::ASTContext &
Ctxt =
instance->getAsCXXRecordDecl()->getASTContext();
4786 const clang::ElaboratedType* etype
4787 = llvm::dyn_cast<clang::ElaboratedType>(
input.getTypePtr());
4792 assert(
instance->getAsCXXRecordDecl() !=
nullptr &&
"ReSubstTemplateArg only makes sense with a type representing a class.");
4812 if (
nQT ==
QT->getPointeeType())
return QT;
4828 if (
nQT ==
QT->getPointeeType())
return QT;
4849 if (
newQT ==
arr->getElementType())
return QT;
4853 arr->getSizeModifier(),
4854 arr->getIndexTypeCVRQualifiers());
4862 arr->getSizeModifier(),
4863 arr->getIndexTypeCVRQualifiers(),
4864 arr->getBracketsRange());
4869 if (
newQT ==
arr->getElementType())
return QT;
4871 arr->getSizeModifier(),
4872 arr->getIndexTypeCVRQualifiers());
4877 if (
newQT ==
arr->getElementType())
return QT;
4880 arr->getSizeModifier(),
4881 arr->getIndexTypeCVRQualifiers(),
4882 arr->getBracketsRange());
4891 etype = llvm::dyn_cast<clang::ElaboratedType>(
instance);
4893 instance = etype->getNamedType().getTypePtr();
4897 const clang::TemplateSpecializationType*
TST
4898 = llvm::dyn_cast<const clang::TemplateSpecializationType>(
instance);
4902 const clang::ClassTemplateSpecializationDecl*
TSTdecl
4903 = llvm::dyn_cast_or_null<const clang::ClassTemplateSpecializationDecl>(
instance->getAsCXXRecordDecl());
4907 const clang::SubstTemplateTypeParmType *
substType
4908 = llvm::dyn_cast<clang::SubstTemplateTypeParmType>(
input.getTypePtr());
4912 const clang::ClassTemplateDecl *
replacedCtxt =
nullptr;
4916 unsigned int index =
substType->getReplacedParameter()->getIndex();
4919 if (
decl->getKind() == clang::Decl::ClassTemplatePartialSpecialization) {
4920 const clang::ClassTemplatePartialSpecializationDecl *
spec = llvm::dyn_cast<clang::ClassTemplatePartialSpecializationDecl>(
decl);
4922 unsigned int depth =
substType->getReplacedParameter()->getDepth();
4938 const clang::SubstTemplateTypeParmType *
argType
4939 = llvm::dyn_cast<clang::SubstTemplateTypeParmType>(
argQualType);
4964 llvm::raw_string_ostream ostream(
astDump);
4967 ROOT::TMetaUtils::Warning(
"ReSubstTemplateArg",
"Unexpected type of declaration context for template parameter: %s.\n\tThe responsible class is:\n\t%s\n",
4974 const auto &
TAs =
TST->template_arguments();
4991 const clang::TemplateSpecializationType*
inputTST
4992 = llvm::dyn_cast<const clang::TemplateSpecializationType>(
input.getTypePtr());
4997 llvm::SmallVector<clang::TemplateArgument, 4>
desArgs;
4998 for (
const clang::TemplateArgument &
TA :
inputTST->template_arguments()) {
4999 if (
TA.getKind() != clang::TemplateArgument::Type) {
5004 clang::QualType
SubTy =
TA.getAsType();
5006 if (llvm::isa<clang::ElaboratedType>(
SubTy)
5007 || llvm::isa<clang::SubstTemplateTypeParmType>(
SubTy)
5008 || llvm::isa<clang::TemplateSpecializationType>(
SubTy)) {
5023 inputTST->getCanonicalTypeInternal());
5064 static const char *
stls[] =
5065 {
"any",
"vector",
"list",
"deque",
"map",
"multimap",
"set",
"multiset",
"bitset",
5066 "forward_list",
"unordered_set",
"unordered_multiset",
"unordered_map",
"unordered_multimap",
"RVec",
nullptr};
5080 for (
int k = 1;
stls[k]; k++) {
5094 TND =
TND->getMostRecentDecl();
5095 while (
TND && !(
TND->hasAttrs()))
5096 TND =
TND->getPreviousDecl();
5108 TD =
TD->getMostRecentDecl();
5109 while (
TD && !(
TD->hasAttrs() &&
TD->isThisDeclarationADefinition()))
5110 TD =
TD->getPreviousDecl();
5166 std::list<std::pair<std::string,unsigned int> >&
enclosingSc)
5194 std::string::size_type
beginVar = 0;
5195 std::string::size_type
endVar = 0;
5199 std::string::size_type
endVarName = std::string::npos;
5241 const char*
envInclPath = std::getenv(
"ROOT_INCLUDE_PATH");
5276 str.replace(
start_pos, from.length(), to);
5343 return llvm::sys::path::extension(
filename) ==
".h" ||
5344 llvm::sys::path::extension(
filename) ==
".hh" ||
5345 llvm::sys::path::extension(
filename) ==
".hpp" ||
5346 llvm::sys::path::extension(
filename) ==
".H" ||
5347 llvm::sys::path::extension(
filename) ==
".h++" ||
5348 llvm::sys::path::extension(
filename) ==
"hxx" ||
5349 llvm::sys::path::extension(
filename) ==
"Hxx" ||
5350 llvm::sys::path::extension(
filename) ==
"HXX";
5356 cling::Interpreter::IgnoreFilesFunc_t
ignoreFiles,
5357 const cling::Interpreter &
interp,
5365 clang::Decl *
ncDecl =
const_cast<clang::Decl *
>(
decl);
5410 static const std::string
scopeType [] = {
"namespace ",
"inline namespace ",
"class "};
5452 std::string typeName;
5455 if (llvm::isa<clang::TemplateTypeParmDecl>(
nDecl)){
5456 typeName =
"typename ";
5457 if (
nDecl->isParameterPack())
5459 typeName += (*prmIt)->getNameAsString();
5462 else if (
auto nttpd = llvm::dyn_cast<clang::NonTypeTemplateParmDecl>(
nDecl)){
5466 if (
theType.getAsString().find(
"enum") != std::string::npos){
5468 llvm::raw_string_ostream ostream(
astDump);
5469 nttpd->dump(ostream);
5480 else if (
auto ttpd = llvm::dyn_cast<clang::TemplateTemplateParmDecl>(
nDecl)){
5484 llvm::raw_string_ostream ostream(
astDump);
5485 ttpd->dump(ostream);
5510 "Cannot extract template parameter list for %s",
5518 "Problems with arguments for forward declaration of class %s\n",
5528 if (llvm::isa<clang::TemplateTemplateParmDecl>(&
templDecl)) {
5550 if (clang::TemplateArgument::Type != arg.getKind())
return 0;
5565 if (llvm::isa<clang::BuiltinType>(
argTypePtr)){
5598 if (
specDef->getTemplateSpecializationKind() != clang::TSK_ExplicitSpecialization)
5602 std::cout <<
" Forward declaring template spec " <<
normalizedName <<
":\n";
5607 std::cout <<
" o Template argument ";
5609 std::cout <<
"successfully treated. Arg fwd decl: " <<
argFwdDecl << std::endl;
5611 std::cout <<
"could not be treated. Abort fwd declaration generation.\n";
5652 std::cout <<
"Class " <<
recordDecl.getNameAsString()
5653 <<
" is a template specialisation. Treating its arguments.\n";
5657 std::cout <<
" o Template argument ";
5659 std::cout <<
"successfully treated. Arg fwd decl: " <<
argFwdDecl << std::endl;
5661 std::cout <<
"could not be treated. Abort fwd declaration generation.\n";
5709 std::string buffer =
tdnDecl.getNameAsString();
5712 if (
const clang::TagType* TT
5714 if (clang::NamedDecl*
ND = TT->getDecl()) {
5715 if (!
ND->getIdentifier()) {
5759 std::cout <<
"Typedef " <<
tdnDecl.getNameAsString() <<
" hides a class: "
5786 const clang::PrintingPolicy&
ppolicy)
5789 auto&
ctxt = par.getASTContext();
5810 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
short Version_t
Class version identifier (short)
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()
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 .