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/AST/QualTypeNames.h"
49#include "clang/Lex/PreprocessorOptions.h"
51#include "clang/Sema/Lookup.h"
52#include "clang/Sema/Sema.h"
53#include "clang/Sema/SemaDiagnostic.h"
55#include "cling/Interpreter/LookupHelper.h"
56#include "cling/Interpreter/Transaction.h"
57#include "cling/Interpreter/Interpreter.h"
58#include "cling/Utils/AST.h"
59#include "cling/Interpreter/InterpreterAccessRAII.h"
61#include "llvm/Support/Path.h"
62#include "llvm/Support/FileSystem.h"
67#define strncasecmp _strnicmp
87 using DeclsCont_t = TNormalizedCtxt::Config_t::SkipCollection;
104 bool replace =
false);
115 clang::NestedNameSpecifier
scope,
118 if (
scope.getKind() == clang::NestedNameSpecifier::Kind::Type) {
130 return clang::NestedNameSpecifier(
addDefault.getTypePtr());
137static bool CheckDefinition(
const clang::CXXRecordDecl *cl,
const clang::CXXRecordDecl *context)
139 if (!cl->hasDefinition()) {
142 "Missing definition for class %s, please #include its header in the header of %s\n",
143 cl->getName().str().c_str(), context->getName().str().c_str());
146 "Missing definition for class %s\n",
147 cl->getName().str().c_str());
158 const clang::BuiltinType *
builtin = llvm::dyn_cast<clang::BuiltinType>(
type->getCanonicalTypeInternal().getTypePtr());
178 clang::ASTContext &
C = cl.getASTContext();
179 clang::DeclarationName
DName = &
C.Idents.get(
what);
180 auto R = cl.lookup(
DName);
181 for (
const clang::NamedDecl *D :
R)
193 clang::LookupResult
R(
SemaR,
DName, clang::SourceLocation(),
194 clang::Sema::LookupOrdinaryName,
195 RedeclarationKind::ForExternalRedeclaration);
196 SemaR.LookupInSuper(
R, &
const_cast<clang::CXXRecordDecl&
>(cl));
199 return llvm::dyn_cast<const clang::FieldDecl>(
R.getFoundDecl());
205 ? cling::LookupHelper::WithDiagnostics
206 : cling::LookupHelper::NoDiagnostics;
213namespace TMetaUtils {
222 Error(
"TNormalizedCtxt::AddTemplAndNargsToKeep",
223 "Tring to specify a number of template arguments to keep for a null pointer. Exiting without assigning any value.\n");
227 const clang::ClassTemplateDecl*
canTempl =
templ->getCanonicalDecl();
232 const std::string
i_str (std::to_string(i));
234 Error(
"TNormalizedCtxt::AddTemplAndNargsToKeep",
235 "Tring to specify for template %s %s arguments to keep, while before this number was %s\n",
236 canTempl->getNameAsString().c_str(),
249 const clang::ClassTemplateDecl*
constTempl =
templ->getCanonicalDecl();
300 std::unique_ptr<clang::MangleContext>
mangleCtx(
rDecl->getASTContext().createMangleContext());
304 if (
const clang::TypeDecl*
TD = llvm::dyn_cast<clang::TypeDecl>(
rDecl)) {
331 "Demangled typeinfo name '%s' does not contain `RTTI Type Descriptor'\n",
335 "Demangled typeinfo name '%s' does not start with 'typeinfo for'\n",
352 const clang::RecordDecl *
decl,
383 const clang::RecordDecl *
decl,
414 "Could not remove the requested template arguments.\n");
425 const clang::RecordDecl *
decl,
461 const clang::RecordDecl *
decl,
510 fCheckInClassTable(CheckInClassTable),
524 if (
tname.empty())
return false;
549 if (!
dest.isNull() && (
dest != t)) {
569 if (!
dest.isNull() && (
dest != t) &&
591 const clang::NamespaceDecl *
nsdecl = llvm::dyn_cast<clang::NamespaceDecl>(
scope);
604 if (
tname.empty())
return false;
636 clang::PrintingPolicy
policy(
fInterpreter->getCI()->getASTContext().getPrintingPolicy());
637 policy.SuppressTagKeyword =
true;
638 policy.SuppressTagKeywordInAnonNames =
true;
643 policy.SuppressUnwrittenScope =
true;
656 for(
unsigned int i = 1; i<
result.length(); ++i) {
668 }
else if ( (i+1) <
result.length() &&
695 if (!
dest.isNull()) {
696 for (std::string_view
kw : {
"class ",
"struct ",
"enum "}) {
697 if (
tname.compare(0,
kw.size(),
kw) == 0) {
727 clang::QualType
toSkip =
lh.findType(
name, cling::LookupHelper::WithDiagnostics);
728 if (
const clang::Type* T =
toSkip.getTypePtr()) {
729 const clang::TypedefType *
tt = llvm::dyn_cast<clang::TypedefType>(T);
731 clang::Decl* D =
tt->getDecl();
732 fConfig.m_toSkip.insert(D);
734 clang::QualType
canon =
toSkip->getCanonicalTypeInternal();
735 fConfig.m_toReplace.insert(std::make_pair(
canon.getTypePtr(),T));
737 fTypeWithAlternative.insert(T);
750 keepTypedef(
lh,
"Double32_t");
751 keepTypedef(
lh,
"Float16_t");
752 keepTypedef(
lh,
"Long64_t",
true);
753 keepTypedef(
lh,
"ULong64_t",
true);
755 clang::QualType
toSkip =
lh.findType(
"string", cling::LookupHelper::WithDiagnostics);
757 if (
const clang::TypedefType* TT
758 = llvm::dyn_cast_or_null<clang::TypedefType>(
toSkip.getTypePtr()))
759 fConfig.m_toSkip.insert(TT->getDecl());
761 toSkip =
lh.findType(
"std::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 clang::QualType
canon =
toSkip->getCanonicalTypeInternal();
768 fConfig.m_toReplace.insert(std::make_pair(
canon.getTypePtr(),
toSkip.getTypePtr()));
779 return (cl.getKind() == clang::Decl::ClassTemplatePartialSpecialization
780 || cl.getKind() == clang::Decl::ClassTemplateSpecialization);
787 const cling::Interpreter&
interp)
789 clang::Sema* S = &
interp.getSema();
790 const clang::NamedDecl*
ND = cling::utils::Lookup::Named(S,
name, cl);
791 if (
ND == (clang::NamedDecl*)-1)
792 return (clang::FunctionDecl*)-1;
793 return llvm::dyn_cast_or_null<clang::FunctionDecl>(
ND);
799const clang::CXXRecordDecl *
803 const cling::LookupHelper&
lh =
interp.getLookupHelper();
806 const clang::CXXRecordDecl *
result
807 = llvm::dyn_cast_or_null<clang::CXXRecordDecl>
814 result = llvm::dyn_cast_or_null<clang::CXXRecordDecl>
825 clang::QualType
qType = cl->getASTContext().getCanonicalTagType(cl);
833 clang::Sema& S =
interp.getCI()->getSema();
836 cling::Interpreter::PushTransactionRAII
RAII(
const_cast<cling::Interpreter*
>(&
interp));
837 return S.RequireCompleteType(
Loc, Type, clang::diag::err_incomplete_type);
843 const clang::CXXRecordDecl *context,
const cling::Interpreter &
interp)
849 if (!cl->getDefinition() || !cl->isCompleteDefinition()) {
857 if (!base->hasDefinition()) {
861 return cl->isDerivedFrom(base);
873 const clang::NamedDecl *base
877 return IsBase(
CRD, llvm::dyn_cast<clang::CXXRecordDecl>( base ),
878 llvm::dyn_cast<clang::CXXRecordDecl>(
m.getDeclContext()),
interp);
887 const clang::QualType &
qti,
889 const cling::Interpreter &
interp,
897 kBIT_ISSTRING = 0x40000000,
904 const clang::Type &
ti( *
qti.getTypePtr() );
927 if (
tiName ==
"string")
kase |= kBIT_ISSTRING;
928 if (
tiName ==
"string*")
kase |= kBIT_ISSTRING;
932 tcl =
" internal error in rootcling ";
957 <<
" R__b >> readtemp;" << std::endl
958 <<
" " <<
R__t <<
" = static_cast<" <<
tiName <<
">(readtemp);" << std::endl;
970 finalString <<
" if (R__b.GetInfo() && R__b.GetInfo()->GetOldVersion()<=3) {" << std::endl;
972 finalString <<
" R__ASSERT(0);// " <<
objType <<
" is abstract. We assume that older file could not be produced using this streaming method." << std::endl;
975 <<
" " <<
R__t <<
"->Streamer(R__b);" << std::endl;
978 <<
" " <<
R__t <<
" = (" <<
tiName <<
")R__b.ReadObjectAny(" <<
tcl <<
");" << std::endl
979 <<
" }" << std::endl;
985 <<
" R__str.Streamer(R__b);" << std::endl
986 <<
" " <<
R__t <<
" = R__str.Data();}" << std::endl;
992 <<
" R__str.Streamer(R__b);" << std::endl
993 <<
" " <<
R__t <<
" = new string(R__str.Data());}" << std::endl;
1002 if (!
R__t)
return 1;
1013 if (!
R__t)
return 0;
1018 if (!
R__t)
return 0;
1020 finalString <<
" R__b >> *reinterpret_cast<Int_t*>(ptr_enum); }" << std::endl;
1025 if (!
R__t)
return 0;
1030 if (!
R__t)
return 1;
1035 if (!
R__t)
return 0;
1036 finalString <<
" {TString R__str(" <<
R__t <<
".c_str());" << std::endl
1037 <<
" R__str.Streamer(R__b);};" << std::endl;
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 1;
1052 if (!
R__t)
return 1;
1065 clang::CXXRecordDecl*
ncCl =
const_cast<clang::CXXRecordDecl*
>(cl);
1068 cling::Interpreter::PushTransactionRAII
clingRAII(
const_cast<cling::Interpreter*
>(&
interpreter));
1071 if (
Ctor->getAccess() == clang::AS_public && !
Ctor->isDeleted()) {
1089 const cling::LookupHelper&
lh =
interpreter.getLookupHelper();
1098 return EIOCtorCategory::kAbsent;
1101 cling::Interpreter::PushTransactionRAII
clingRAII(
const_cast<cling::Interpreter*
>(&
interpreter));
1102 for (
auto iter = cl->ctor_begin(), end = cl->ctor_end(); iter != end; ++iter)
1104 if ((iter->getAccess() != clang::AS_public) || (iter->getNumParams() != 1))
1108 clang::QualType
argType((*iter->param_begin())->getType());
1112 if (
argType->isPointerType()) {
1115 }
else if (
argType->isReferenceType()) {
1122 const clang::CXXRecordDecl *
argDecl =
argType->getAsCXXRecordDecl();
1129 std::string
clarg(
"class ");
1136 return EIOCtorCategory::kAbsent;
1149 if (!
ioctortype.GetType() && (!arg || !arg[0])) {
1163 const cling::Interpreter &
interp,
1166 const clang::FunctionDecl*
funcD
1168 diagnose ? cling::LookupHelper::WithDiagnostics
1169 : cling::LookupHelper::NoDiagnostics);
1171 return llvm::dyn_cast<const clang::CXXMethodDecl>(
funcD);
1180 namespace TMetaUtils {
1183 const cling::LookupHelper&
lh =
interp.getLookupHelper();
1202 const cling::Interpreter &
interp)
1204 if (cl->isAbstract())
return false;
1210 if (EIOCtorCategory::kAbsent ==
ioCtorCat)
1220 if (EIOCtorCategory::kIOPtrType ==
ioCtorCat) {
1222 }
else if (EIOCtorCategory::kIORefType ==
ioCtorCat) {
1226 arg +=
")nullptr )";
1229 const clang::CXXMethodDecl *
method
1231 cling::LookupHelper::NoDiagnostics);
1232 if (
method &&
method->getAccess() != clang::AS_public) {
1246 const cling::Interpreter&
interp)
1248 if (!cl)
return false;
1250 if (cl->hasUserDeclaredDestructor()) {
1252 cling::Interpreter::PushTransactionRAII
clingRAII(
const_cast<cling::Interpreter*
>(&
interp));
1253 clang::CXXDestructorDecl *
dest = cl->getDestructor();
1255 return (
dest->getAccess() == clang::AS_public);
1269 const cling::Interpreter &
interp,
1272 const clang::CXXMethodDecl *
method
1274 diagnose ? cling::LookupHelper::WithDiagnostics
1275 : cling::LookupHelper::NoDiagnostics);
1276 return (
method &&
method->getAccess() == clang::AS_public);
1287 const char *
proto =
"TDirectory*";
1288 const char *
name =
"DirectoryAutoAdd";
1302 const char *
proto =
"TCollection*,TFileMergeInfo*";
1303 const char *
name =
"Merge";
1316 const char *
proto =
"TCollection*";
1317 const char *
name =
"Merge";
1332 const char *
proto =
"TFileMergeInfo*";
1333 const char *
name =
"ResetAfterMerge";
1343 const clang::CXXRecordDecl*
clxx,
1344 const cling::Interpreter &
interp,
1347 static const char *
proto =
"TBuffer&";
1349 const clang::CXXMethodDecl *
method
1351 cling::LookupHelper::NoDiagnostics);
1362 const clang::CXXRecordDecl*
clxx,
1363 const cling::Interpreter &
interp,
1366 static const char *
proto =
"TBuffer&,TClass*";
1368 const clang::CXXMethodDecl *
method
1370 cling::LookupHelper::NoDiagnostics);
1435 llvm::raw_string_ostream stream(
qual_name);
1436 clang::PrintingPolicy
policy( cl.getASTContext().getPrintingPolicy() );
1437 policy.SuppressTagKeyword =
true;
1438 policy.SuppressTagKeywordInAnonNames =
true;
1439 policy.SuppressUnwrittenScope =
true;
1441 cl.getNameForDiagnostic(stream,
policy,
true);
1496 std::stringstream
dims;
1499 const clang::ASTContext&
astContext = cl.getASTContext();
1502 for(clang::RecordDecl::field_iterator
field_iter = cl.field_begin(), end = cl.field_end();
1516 const clang::ConstantArrayType *
arrayType = llvm::dyn_cast<clang::ConstantArrayType>(
fieldType.getTypePtr());
1518 dims <<
"[" <<
arrayType->getSize().getLimitedValue() <<
"]";
1520 arrayType = llvm::dyn_cast<clang::ConstantArrayType>(
arrayType->getArrayElementTypeNoTypeQual());
1530 for(clang::CXXRecordDecl::base_class_const_iterator iter = cl.bases_begin(), end = cl.bases_end();
1533 std::string
basename( iter->getType()->getAsCXXRecordDecl()->getNameAsString() );
1543 const cling::Interpreter &
interp,
1547 diagnose ? cling::LookupHelper::WithDiagnostics
1548 : cling::LookupHelper::NoDiagnostics);
1607 while (llvm::isa<clang::PointerType>(
instanceType.getTypePtr())
1608 || llvm::isa<clang::ReferenceType>(
instanceType.getTypePtr()))
1624 if (
clxx &&
clxx->getTemplateSpecializationKind() != clang::TSK_Undeclared) {
1626 const clang::TemplateSpecializationType*
TST
1627 = llvm::dyn_cast<const clang::TemplateSpecializationType>(
instanceType.getTypePtr());
1634 for (
const clang::TemplateArgument &
TA :
TST->template_arguments()) {
1635 if (
TA.getKind() == clang::TemplateArgument::Type) {
1647 const cling::Interpreter &
interp,
1650 const clang::CXXRecordDecl *
clxx = llvm::dyn_cast<clang::CXXRecordDecl>(cl.
GetRecordDecl());
1651 if (!
clxx ||
clxx->getTemplateSpecializationKind() == clang::TSK_Undeclared)
return false;
1654 cling::LookupHelper::WithDiagnostics);
1668 clang::AnnotateAttr*
annAttr = clang::dyn_cast<clang::AnnotateAttr>(
attribute);
1711 for (clang::Decl::attr_iterator
attrIt =
decl.attr_begin();
1713 clang::AnnotateAttr*
annAttr = clang::dyn_cast<clang::AnnotateAttr>(*
attrIt);
1717 std::pair<llvm::StringRef,llvm::StringRef> split =
attribute.split(propNames::separator.c_str());
1718 if (split.first !=
propName.c_str())
continue;
1734 for (clang::Decl::attr_iterator
attrIt =
decl.attr_begin();
1736 clang::AnnotateAttr*
annAttr = clang::dyn_cast<clang::AnnotateAttr>(*
attrIt);
1740 std::pair<llvm::StringRef,llvm::StringRef> split =
attribute.split(propNames::separator.c_str());
1741 if (split.first !=
propName.c_str())
continue;
1743 return split.second.getAsInteger(10,
propValue);
1754 const clang::CXXRecordDecl *
decl,
1755 const cling::Interpreter &
interp,
1764 std::string
csymbol = classname;
1778 bool isStd = TMetaUtils::IsStdClass(*
decl);
1779 const cling::LookupHelper&
lh =
interp.getLookupHelper();
1789 <<
" static void " <<
mappedname.c_str() <<
"_TClassManip(TClass*);\n";
1807 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";
1810 finalString <<
" static void directoryAutoAdd_" <<
mappedname.c_str() <<
"(void *obj, TDirectory *dir);" <<
"\n";
1813 finalString <<
" static void streamer_" <<
mappedname.c_str() <<
"(TBuffer &buf, void *obj);" <<
"\n";
1816 finalString <<
" static void conv_streamer_" <<
mappedname.c_str() <<
"(TBuffer &buf, void *obj, const TClass*);" <<
"\n";
1819 finalString <<
" static Long64_t merge_" <<
mappedname.c_str() <<
"(void *obj, TCollection *coll,TFileMergeInfo *info);" <<
"\n";
1822 finalString <<
" static void reset_" <<
mappedname.c_str() <<
"(void *obj, TFileMergeInfo *info);" <<
"\n";
1841 finalString <<
"\n // Schema evolution read functions\n";
1842 std::list<ROOT::SchemaRuleMap_t>::iterator
rIt =
rulesIt1->second.fRules.
begin();
1860 if(
rIt->find(
"code" ) !=
rIt->
end() ) {
1876 finalString <<
"\n // Schema evolution read raw functions\n";
1877 std::list<ROOT::SchemaRuleMap_t>::iterator
rIt =
rulesIt2->second.fRules.
begin();
1903 finalString <<
"\n" <<
" // Function generating the singleton type initializer" <<
"\n";
1905 finalString <<
" static TGenericClassInfo *GenerateInitInstanceLocal(const " <<
csymbol <<
"*)" <<
"\n" <<
" {" <<
"\n";
1911 finalString <<
" static ::TVirtualIsAProxy* isa_proxy = new ::TInstrumentedIsAProxy< " <<
csymbol <<
" >(nullptr);" <<
"\n";
1914 finalString <<
" static ::TVirtualIsAProxy* isa_proxy = new ::TIsAProxy(typeid(" <<
csymbol <<
"));" <<
"\n";
1916 finalString <<
" static ::ROOT::TGenericClassInfo " <<
"\n" <<
" instance(\"" << classname.c_str() <<
"\", ";
1929 static const char *
versionFunc =
"GetClassVersion";
1933 std::string
proto = classname +
"*";
1934 const clang::Decl*
ctxt = llvm::dyn_cast<clang::Decl>((*cl).getDeclContext());
1937 interp, cling::LookupHelper::NoDiagnostics);
1956 for (
unsigned int i=0; i<
filename.length(); i++) {
1961 <<
"," <<
"\n" <<
" typeid(" <<
csymbol
1962 <<
"), ::ROOT::Internal::DefineBehavior(ptr, ptr)," <<
"\n" <<
" ";
1979 <<
" sizeof(" <<
csymbol <<
"), alignof(" <<
csymbol <<
") );" <<
"\n";
1986 finalString <<
" instance.SetDelete(&delete_" <<
mappedname.c_str() <<
");" <<
"\n" <<
" instance.SetDeleteArray(&deleteArray_" <<
mappedname.c_str() <<
");" <<
"\n" <<
" instance.SetDestructor(&destruct_" <<
mappedname.c_str() <<
");" <<
"\n";
1989 finalString <<
" instance.SetDirectoryAutoAdd(&directoryAutoAdd_" <<
mappedname.c_str() <<
");" <<
"\n";
1997 finalString <<
" instance.SetConvStreamerFunc(&conv_streamer_" <<
mappedname.c_str() <<
");" <<
"\n";
2006 finalString <<
" instance.AdoptCollectionProxyInfo(TCollectionProxyInfo::Generate(TCollectionProxyInfo::" <<
"Pushback" <<
"<Internal::TStdBitsetHelper< " << classname.c_str() <<
" > >()));" <<
"\n";
2009 }
else if (
stl != 0 &&
2012 int idx = classname.find(
"<");
2043 finalString <<
" \"Class with alignment strictly greater than 4096 are currently not supported in "
2044 "CollectionProxy. \"\n";
2045 finalString <<
" \"Please report this case to the developers\");\n";
2046 finalString <<
" instance.AdoptCollectionProxyInfo(TCollectionProxyInfo::Generate(TCollectionProxyInfo::" <<
methodTCP <<
"< " <<
classNameForIO.c_str() <<
" >()));" <<
"\n";
2056 finalString <<
"\n" <<
" instance.AdoptAlternate(::ROOT::AddClassAlternate(\""
2063 finalString <<
"\n" <<
" instance.AdoptAlternate(::ROOT::AddClassAlternate(\""
2081 finalString <<
"\n" <<
" ::ROOT::Internal::TSchemaHelper* rule;" <<
"\n";
2085 finalString <<
"\n" <<
" // the io read rules" <<
"\n" <<
" std::vector<::ROOT::Internal::TSchemaHelper> readrules(" <<
rulesIt1->second.size() <<
");" <<
"\n";
2087 finalString <<
" instance.SetReadRules( readrules );" <<
"\n";
2088 rulesIt1->second.fGenerated =
true;
2092 finalString <<
"\n" <<
" // the io read raw rules" <<
"\n" <<
" std::vector<::ROOT::Internal::TSchemaHelper> readrawrules(" <<
rulesIt2->second.size() <<
");" <<
"\n";
2094 finalString <<
" instance.SetReadRawRules( readrawrules );" <<
"\n";
2095 rulesIt2->second.fGenerated =
true;
2098 finalString <<
" return &instance;" <<
"\n" <<
" }" <<
"\n";
2102 finalString <<
" TGenericClassInfo *GenerateInitInstance(const " <<
csymbol <<
"*)" <<
"\n" <<
" {\n return GenerateInitInstanceLocal(static_cast<" <<
csymbol <<
"*>(nullptr));\n }" <<
"\n";
2105 finalString <<
" // Static variable to force the class initialization" <<
"\n";
2109 finalString <<
" static ::ROOT::TGenericClassInfo *_R__UNIQUE_DICT_(Init) = GenerateInitInstanceLocal(static_cast<const " <<
csymbol <<
"*>(nullptr)); R__UseDummy(_R__UNIQUE_DICT_(Init));" <<
"\n";
2112 finalString <<
"\n" <<
" // Dictionary for non-ClassDef classes" <<
"\n"
2113 <<
" static TClass *" <<
mappedname <<
"_Dictionary() {\n"
2114 <<
" TClass* theClass ="
2115 <<
"::ROOT::GenerateInitInstanceLocal(static_cast<const " <<
csymbol <<
"*>(nullptr))->GetClass();\n"
2116 <<
" " <<
mappedname <<
"_TClassManip(theClass);\n";
2127 if (
decl->hasAttrs()){
2129 for (clang::Decl::attr_iterator
attrIt =
decl->attr_begin();
2146 manipString+=
" theClass->CreateAttributeMap();\n";
2147 manipString+=
" TDictAttributeMap* attrMap( theClass->GetAttributeMap() );\n";
2158 if (!(!(*internalDeclIt)->isImplicit()
2179 TMetaUtils::Error(
nullptr,
"Cannot convert field declaration to clang::NamedDecl");
2195 if (
attrName == propNames::comment ||
2197 attrName == propNames::ioname )
continue;
2222 finalString <<
"} // end of namespace ROOT" <<
"\n" <<
"\n";
2227 const cling::Interpreter &
interp)
2231 const clang::Type *
typeptr =
nullptr;
2232 const clang::CXXRecordDecl *
target =
2237 std::string
rule{
nRules > 1 ?
"rules" :
"rule"};
2238 std::string
verb{
nRules > 1 ?
"were" :
"was"};
2256 finalString <<
"\n // Schema evolution read functions\n";
2257 std::list<ROOT::SchemaRuleMap_t>::iterator
rIt =
rulesIt1.second.fRules.
begin();
2298 finalString <<
" // Registration Schema evolution read functions\n";
2302 <<
" ::ROOT::Internal::TSchemaHelper* rule;" <<
"\n";
2311 finalString <<
" std::vector<::ROOT::Internal::TSchemaHelper> readrules(" <<
rulesIt1->second.size()
2314 finalString <<
" TClass::RegisterReadRules(TSchemaRule::kReadRule, \"" <<
name
2315 <<
"\", std::move(readrules));\n";
2316 rulesIt1->second.fGenerated =
true;
2321 finalString <<
" std::vector<::ROOT::Internal::TSchemaHelper> readrawrules(" <<
rulesIt2->second.size()
2324 finalString <<
" TClass::RegisterReadRules(TSchemaRule::kReadRawRule, \"" <<
name
2325 <<
"\", std::move(readrawrules));\n";
2326 rulesIt2->second.fGenerated =
true;
2346 const clang::CXXRecordDecl *cl)
2356 auto ctxt = cl->getEnclosingNamespaceContext();
2361 const clang::NamedDecl *
namedCtxt = llvm::dyn_cast<clang::NamedDecl>(
ctxt);
2363 const clang::NamespaceDecl *
nsdecl = llvm::dyn_cast<clang::NamespaceDecl>(
namedCtxt);
2378 const clang::DeclContext *
ctxt = cl.getDeclContext();
2379 while(
ctxt && !
ctxt->isNamespace()) {
2400 const clang::NamespaceDecl *ns = llvm::dyn_cast<clang::NamespaceDecl>(
ctxt);
2406 out <<
"namespace " << ns->getNameAsString() <<
" {" << std::endl;
2425 clang::TemplateSpecializationKind kind = cl->getTemplateSpecializationKind();
2426 if (kind == clang::TSK_Undeclared ) {
2429 }
else if (kind == clang::TSK_ExplicitSpecialization) {
2444 const char *
proto =
"size_t";
2451 cling::LookupHelper::NoDiagnostics);
2455 cling::LookupHelper::NoDiagnostics);
2457 const clang::DeclContext *
ctxtnew =
nullptr;
2493 const clang::CXXRecordDecl*
clnew = llvm::dyn_cast<clang::CXXRecordDecl>(
ctxtnew);
2540 const clang::CXXRecordDecl *
decl,
2541 const cling::Interpreter &
interp,
2565 classname.insert(0,
"::");
2573 finalString <<
" // Wrappers around operator new" <<
"\n";
2574 finalString <<
" static void *new_" <<
mappedname.c_str() <<
"(void *p) {" <<
"\n" <<
" return p ? ";
2581 finalString <<
"::new(static_cast<::ROOT::Internal::TOperatorNewHelper*>(p)) ";
2586 finalString <<
"new " << classname.c_str() << args <<
";" <<
"\n";
2601 finalString <<
"::new(static_cast<::ROOT::Internal::TOperatorNewHelper*>(p)) ";
2615 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";
2619 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";
2623 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";
2627 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";
2631 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";
2633 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";
2637 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";
2639 finalString <<
"} // end of namespace ROOT for class " << classname.c_str() <<
"\n" <<
"\n";
2646 const cling::Interpreter &
interp,
2657 const clang::CXXRecordDecl *
clxx = llvm::dyn_cast<clang::CXXRecordDecl>(cl.
GetRecordDecl());
2661 for(clang::CXXRecordDecl::base_class_const_iterator iter =
clxx->bases_begin(), end =
clxx->bases_end();
2667 Internal::RStl::Instance().GenerateTClassFor( iter->getType(),
interp,
normCtxt);
2672 for(clang::RecordDecl::field_iterator
field_iter =
clxx->field_begin(), end =
clxx->field_end();
2704 const clang::Type *
rawtype =
m.getType()->getCanonicalTypeInternal().getTypePtr();
2720 const clang::CXXRecordDecl*
CRD = llvm::dyn_cast<clang::CXXRecordDecl>(cl);
2732 if (
funcCV == (clang::FunctionDecl*)-1)
return 1;
2747 using res_t = std::pair<bool, int>;
2749 const clang::CompoundStmt*
FuncBody
2750 = llvm::dyn_cast_or_null<clang::CompoundStmt>(
funcCV->getBody());
2752 return res_t{
false, -1};
2757 return res_t{
false, -1};
2759 const clang::ReturnStmt*
RetStmt
2760 = llvm::dyn_cast<clang::ReturnStmt>(
FuncBody->body_back());
2762 return res_t{
false, -1};
2774 return res_t{
false, -1};
2782 return TMetaUtils::IsSTLCont(*
annotated.GetRecordDecl());
2790 clang::QualType
type =
m.getType();
2793 if (
decl)
return TMetaUtils::IsSTLCont(*
decl);
2802 clang::QualType
type = base.getType();
2805 if (
decl)
return TMetaUtils::IsSTLCont(*
decl);
2815 const std::function<
void(
const clang::Module::Header &)> &
closure,
2823 llvm::SetVector<const clang::Module *>
modules;
2825 for (
size_t i = 0; i <
modules.size(); ++i) {
2826 const clang::Module *M =
modules[i];
2827 for (
const clang::Module *
subModule : M->submodules())
2831 for (
const clang::Module *
m :
modules) {
2833 for (clang::Module *
used :
m->DirectUses) {
2839 for (
auto HK : {clang::Module::HK_Normal, clang::Module::HK_Textual, clang::Module::HK_Private,
2840 clang::Module::HK_PrivateTextual}) {
2857 static char t[4096];
2858 static const char*
constwd =
"const ";
2867 if (
lev==0 && *s==
'*')
continue;
2873 if (
lev==0 && *s==
' ' && *(s+1)!=
'*') {
p = t;
continue;}
2874 if (
p - t > (
long)
sizeof(t)) {
2875 printf(
"ERROR (rootcling): type name too long for StortTypeName: %s\n",
2888 const cling::Interpreter&
interp)
2893 if (!comment.empty() && comment[0] ==
'!')
2896 clang::QualType
type =
m.getType();
2898 if (
type->isReferenceType()) {
2903 std::string
mTypeName =
type.getAsString(
m.getASTContext().getPrintingPolicy());
2915 const clang::Type *
rawtype =
type.getTypePtr()->getBaseElementTypeUnsafe ();
2917 if (
rawtype->isPointerType()) {
2931 const clang::CXXRecordDecl *
cxxdecl =
rawtype->getAsCXXRecordDecl();
2948 const clang::Type *
rawtype =
m.getType().getTypePtr();
2972 return rawtype->getAsCXXRecordDecl();
2981 const cling::Interpreter &
interp,
2987 const clang::CXXRecordDecl*
decl = llvm::dyn_cast<clang::CXXRecordDecl>(cl.
GetRecordDecl());
2989 if (!
decl || !
decl->isCompleteDefinition()) {
2993 std::string fullname;
3007 ROOT::TMetaUtils::Info(
nullptr,
"Class %s: Do not generate Streamer() [*** custom streamer ***]\n",fullname.c_str());
3032 const clang::ASTContext&
Ctx =
interpreter.getCI()->getASTContext();
3038 if (llvm::isa<clang::PointerType>(
instanceType.getTypePtr())) {
3052 if (llvm::isa<clang::ReferenceType>(
instanceType.getTypePtr())) {
3072 clang::NestedNameSpecifier prefix = std::nullopt;
3086 const clang::TemplateSpecializationType*
TST
3087 = llvm::dyn_cast<const clang::TemplateSpecializationType>(
instanceType.getTypePtr());
3089 const clang::ClassTemplateSpecializationDecl*
TSTdecl
3090 = llvm::dyn_cast_or_null<const clang::ClassTemplateSpecializationDecl>(
instanceType.getTypePtr()->getAsCXXRecordDecl());
3106 clang::TemplateDecl *
Template =
TSTdecl->getSpecializedTemplate()->getMostRecentDecl();
3107 clang::TemplateParameterList *Params =
Template->getTemplateParameters();
3114 llvm::SmallVector<clang::TemplateArgument, 4>
desArgs;
3115 llvm::SmallVector<clang::TemplateArgument, 4>
canonArgs;
3129 if (
I->getKind() == clang::TemplateArgument::Template) {
3136 clang::NamespaceDecl* ns = clang::dyn_cast<clang::NamespaceDecl>(
declCtxt);
3137 clang::NestedNameSpecifier
nns;
3139 nns = cling::utils::TypeName::CreateNestedNameSpecifier(
Ctx, ns);
3140 }
else if (clang::TagDecl*
TD = llvm::dyn_cast<clang::TagDecl>(
declCtxt)) {
3141 nns = cling::utils::TypeName::CreateNestedNameSpecifier(
Ctx,
TD,
false );
3148 if (clang::UsingShadowDecl *
USD =
templateName.getAsUsingShadowDecl())
3158 if (
I->getKind() != clang::TemplateArgument::Type) {
3163 clang::QualType
SubTy =
I->getAsType();
3185 if (
templateArg.getKind() != clang::TemplateArgument::Type) {
3194 clang::TemplateTypeParmDecl *
TTP = llvm::dyn_cast<clang::TemplateTypeParmDecl>(*
Param);
3197 cling::Interpreter::PushTransactionRAII
clingRAII(
const_cast<cling::Interpreter*
>(&
interpreter));
3199 clang::TemplateArgumentLoc
ArgType = S.SubstDefaultTemplateArgumentIfAvailable(
3201 clang::SourceLocation(),
3210 if (
ArgType.getArgument().isNull()
3211 ||
ArgType.getArgument().getKind() != clang::TemplateArgument::Type) {
3213 "Template parameter substitution failed for %s around %s\n",
3232 TST->getTemplateName(),
3235 TST->getCanonicalTypeInternal());
3266 llvm::StringRef title;
3269 if (clang::AnnotateAttr *A =
m.getAttr<clang::AnnotateAttr>())
3270 title = A->getAnnotation();
3284 if (title.size() == 0 || (title[0] !=
'['))
return llvm::StringRef();
3286 if (
rightbracket == llvm::StringRef::npos)
return llvm::StringRef();
3305 char *current =
const_cast<char*
>(
working.c_str());
3311 for(i=0;i<
strlen(current);i++) {
3319 return llvm::StringRef();
3324 const clang::CXXRecordDecl *
parent_clxx = llvm::dyn_cast<clang::CXXRecordDecl>(
m.getDeclContext());
3325 const clang::FieldDecl *
index1 =
nullptr;
3338 if (
field_iter->getNameAsString() ==
m.getNameAsString() ) {
3346 return llvm::StringRef();
3358 return llvm::StringRef();
3383 return llvm::StringRef();
3385 if ( found && (
index1->getAccess() == clang::AS_private) ) {
3390 return llvm::StringRef();
3399 return llvm::StringRef();
3420 while((
c = in[i++])) {
3421 const char *
repl =
nullptr;
3423 case '+':
repl =
"pL";
break;
3424 case '-':
repl =
"mI";
break;
3425 case '*':
repl =
"mU";
break;
3426 case '/':
repl =
"dI";
break;
3427 case '&':
repl =
"aN";
break;
3428 case '%':
repl =
"pE";
break;
3429 case '|':
repl =
"oR";
break;
3430 case '^':
repl =
"hA";
break;
3431 case '>':
repl =
"gR";
break;
3432 case '<':
repl =
"lE";
break;
3433 case '=':
repl =
"eQ";
break;
3434 case '~':
repl =
"wA";
break;
3435 case '.':
repl =
"dO";
break;
3436 case '(':
repl =
"oP";
break;
3437 case ')':
repl =
"cP";
break;
3438 case '[':
repl =
"oB";
break;
3439 case ']':
repl =
"cB";
break;
3440 case '{':
repl =
"lB";
break;
3441 case '}':
repl =
"rB";
break;
3442 case ';':
repl =
"sC";
break;
3443 case '#':
repl =
"hS";
break;
3444 case '?':
repl =
"qM";
break;
3445 case '`':
repl =
"bT";
break;
3446 case '!':
repl =
"nO";
break;
3447 case ',':
repl =
"cO";
break;
3448 case '$':
repl =
"dA";
break;
3449 case ' ':
repl =
"sP";
break;
3450 case ':':
repl =
"cL";
break;
3451 case '"':
repl =
"dQ";
break;
3452 case '@':
repl =
"aT";
break;
3453 case '\'':
repl =
"sQ";
break;
3454 case '\\':
repl =
"fI";
break;
3463 if (out.empty() ||
isdigit(out[0]))
3464 out.insert(out.begin(),
'_');
3467static clang::SourceLocation
3481 const cling::Interpreter&
interp)
3511 using namespace clang;
3536 ArrayRef<std::pair<OptionalFileEntryRef, DirectoryEntryRef>>(),
3551 assert(
decl.isFirstDecl() &&
"Couldn't trace back include from a decl"
3552 " that is not from an AST file");
3577 clang::OptionalFileEntryRef
FELong;
3579 for (llvm::sys::path::const_iterator
3592 &&
"Mismatched partitioning of file name!");
3596 ArrayRef<std::pair<OptionalFileEntryRef, DirectoryEntryRef>>(),
3608 for (llvm::sys::path::reverse_iterator
3616 &&
"Mismatched partitioning of file name!");
3622 ArrayRef<std::pair<OptionalFileEntryRef, DirectoryEntryRef>>(),
3625 nullptr,
nullptr ) ==
FELong) {
3636 const clang::QualType &
qtype,
3648 const clang::QualType &
qtype,
3654 cling::Interpreter::PushTransactionRAII
RAII(
const_cast<cling::Interpreter*
>(&
interpreter));
3666 clang::ClassTemplateDecl*&
ctd,
3667 clang::ClassTemplateSpecializationDecl*&
ctsd)
3669 using namespace clang;
3677 if (
theType->isPointerType()) {
3682 ctsd = llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(
rType->getDecl());
3684 ctd =
ctsd->getSpecializedTemplate();
3694 ctsd = llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(
qt->getAsCXXRecordDecl());
3696 ctd =
ctsd->getSpecializedTemplate();
3711 using namespace clang;
3727 using namespace clang;
3744 const clang::NamedDecl&
tPar,
3745 const cling::Interpreter&
interp,
3749 using namespace clang;
3754 if (!
ttpdPtr->hasDefaultArgument())
return false;
3777 llvm::dyn_cast<TemplateSpecializationType>(
tParQualType.getTypePtr());
3783 = llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(
tArgQualType->getAsCXXRecordDecl());
3801 clang::Sema& S =
interp.getCI()->getSema();
3802 cling::Interpreter::PushTransactionRAII
clingRAII(
const_cast<cling::Interpreter*
>(&
interp));
3803 llvm::SmallVector<clang::TemplateArgument, 4>
canonArgs;
3806 clang::SourceLocation(),
3817 newArg.getKind() != clang::TemplateArgument::Type) {
3819 "Template parameter substitution failed!");
3823 = llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(
newArg.getAsType()->getAsCXXRecordDecl());
3839 const clang::NamedDecl&
tPar)
3841 using namespace clang;
3846 if (!
nttpd.hasDefaultArgument())
3851 if (Expr*
defArgExpr =
nttpd.getDefaultArgument().getArgument().getAsExpr()) {
3857 const int value =
tArg.getAsIntegral().getLimitedValue();
3870 using namespace clang;
3871 if (!
nDecl)
return false;
3873 return ttpd->hasDefaultArgument();
3875 return nttpd->hasDefaultArgument();
3882 const cling::Interpreter&
interp,
3887 const clang::TemplateArgument &
tArg,
3888 const cling::Interpreter&
interp,
3890 const clang::ASTContext&
astCtxt)
3893 using namespace clang;
3900 if (
tArg.getKind() == clang::TemplateArgument::Type) {
3909 }
else if (
normTArg.getKind() == clang::TemplateArgument::Pack) {
3910 assert(
tArg.getKind() == clang::TemplateArgument::Pack );
3938 const cling::Interpreter&
interp,
3942 using namespace clang;
3951 const int nArgsToKeep =
normCtxt.GetNargsToKeep(
ctd);
3961 if (llvm::isa<clang::PointerType>(
normalizedType.getTypePtr())) {
3974 if (llvm::isa<clang::ReferenceType>(
normalizedType.getTypePtr())) {
3993 clang::NestedNameSpecifier prefix = std::nullopt;
4010 clang::TemplateParameterList*
tpl =
rd->getTemplateParameters();
4011 if (
tpl->getMinRequiredArguments () <
tpl->size()) {
4018 Error(
"KeepNParams",
"Not found template default arguments\n");
4037 llvm::dyn_cast<TemplateSpecializationType>(
normalizedType.getTypePtr());
4043 const clang::ClassTemplateSpecializationDecl*
TSTdecl
4044 = llvm::dyn_cast_or_null<const clang::ClassTemplateSpecializationDecl>(
normalizedType.getTypePtr()->getAsCXXRecordDecl());
4052 llvm::SmallVector<TemplateArgument, 4>
argsToKeep;
4065 Error(
"KeepNParams",
"The parameter number %s is null.\n",
formal);
4087 if (
tParPtr->isTemplateParameterPack() ) {
4119 if (
argKind == clang::TemplateArgument::Type){
4122 }
else if (
argKind == clang::TemplateArgument::Integral){
4178 cling::Interpreter::PushTransactionRAII
RAII(
const_cast<cling::Interpreter*
>(&
interpreter));
4201 if (
type.isNull()) {
4209 clang::PrintingPolicy
policy(
ctxt.getPrintingPolicy());
4210 policy.SuppressTagKeyword =
true;
4211 policy.SuppressTagKeywordInAnonNames =
true;
4212 policy.AnonymousTagLocations =
false;
4217 policy.SuppressUnwrittenScope =
true;
4222 cling::Interpreter::PushTransactionRAII
clingRAII(
const_cast<cling::Interpreter*
>(&
interpreter));
4255 clang::ASTContext&
astCtxt =
sema.getASTContext();
4265std::pair<std::string,clang::QualType>
4286 cling::LookupHelper::DiagSetting::NoDiagnostics,
4305 "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());
4333 llvm::errs() << llvm::StringRef(
commentStart, 80) <<
'\n';
4382 if (
const clang::FunctionDecl*
FD = clang::dyn_cast<clang::FunctionDecl>(&
decl)) {
4383 if (
FD->isImplicit()) {
4387 if (
FD->isExplicitlyDefaulted() ||
FD->isDeletedAsWritten()) {
4391 }
else if (
FD->doesThisDeclarationHaveABody()) {
4396 &&
"Expected macro or end of body at '}'");
4408 }
else if (
const clang::EnumConstantDecl*
ECD
4409 = clang::dyn_cast<clang::EnumConstantDecl>(&
decl)) {
4411 if (
ECD->getNextDeclInContext())
4488 if (!
decl)
return false;
4495 static const std::vector<std::string>
signatures =
4496 {
"ClassDef",
"ClassDefOverride",
"ClassDefNV",
"ClassDefInline",
"ClassDefInlineOverride",
"ClassDefInlineNV" };
4513 clang::SourceLocation *
loc,
4516 using namespace clang;
4519 =
interpreter.getLookupHelper().findFunctionProto(&
decl,
"DeclFileLine",
"",
4520 cling::LookupHelper::NoDiagnostics);
4526 if (comment.size()) {
4533 return llvm::StringRef();
4545 if (
rawtype->isElaboratedTypeSpecifier() ) {
4549 rawtype =
type.getTypePtr()->getBaseElementTypeUnsafe ();
4558 if (
rawtype->isElaboratedTypeSpecifier() ) {
4578 if (
ctxt.isNamespace() ||
ctxt.isTranslationUnit())
4580 else if(
const auto parentdecl = llvm::dyn_cast<clang::CXXRecordDecl>(&
ctxt))
4593 const clang::DeclContext *
ctxt =
decl.getDeclContext();
4594 switch (
decl.getAccess()) {
4595 case clang::AS_public:
4597 case clang::AS_protected:
4599 case clang::AS_private:
4601 case clang::AS_none:
4605 assert(
false &&
"Unexpected value for the access property value in Clang");
4615 return cling::utils::Analyze::IsStdClass(cl);
4625 if (cling::utils::Analyze::IsStdClass(cl)) {
4626 static const char *names[] =
4627 {
"shared_ptr",
"__shared_ptr",
4628 "vector",
"list",
"deque",
"map",
"multimap",
"set",
"multiset",
"bitset"};
4629 llvm::StringRef
clname(cl.getName());
4630 for(
auto &&
name : names) {
4668 const clang::CXXRecordDecl *
thisDecl =
4669 llvm::dyn_cast_or_null<clang::CXXRecordDecl>(
lh.findScope(
typ, cling::LookupHelper::WithDiagnostics));
4673 Error(
"IsOfType",
"Record decl of type %s not found in the AST.",
typ.c_str());
4703 if (!IsStdClass(cl)) {
4704 auto *
nsDecl = llvm::dyn_cast<clang::NamespaceDecl>(cl.getDeclContext());
4705 if (cl.getName() !=
"RVec" ||
nsDecl ==
nullptr ||
nsDecl->getName() !=
"VecOps")
4708 auto *
parentNsDecl = llvm::dyn_cast<clang::NamespaceDecl>(cl.getDeclContext()->getParent());
4713 return STLKind(cl.getName());
4717 using namespace clang;
4718 struct SearchTypedef:
public TypeVisitor<SearchTypedef, bool> {
4723 return Visit(
AT->getElementType().getTypePtr());
4726 return Visit(
DT->getUnderlyingType().getTypePtr());
4729 return Visit(
PT->getPointeeType().getTypePtr());
4732 return Visit(
RT->getPointeeType().getTypePtr());
4735 return Visit(
STST->getReplacementType().getTypePtr());
4739 if (
TA.getKind() == TemplateArgument::Type && Visit(
TA.getAsType().getTypePtr()))
4748 return TOT->getUnmodifiedType().getTypePtr();
4769 using namespace llvm;
4770 using namespace clang;
4771 const clang::ASTContext &
Ctxt =
instance->getAsCXXRecordDecl()->getASTContext();
4784 if (
nQT ==
QT->getPointeeType())
return QT;
4800 if (
nQT ==
QT->getPointeeType())
return QT;
4821 if (
newQT ==
arr->getElementType())
return QT;
4825 arr->getSizeModifier(),
4826 arr->getIndexTypeCVRQualifiers());
4834 arr->getSizeModifier(),
4835 arr->getIndexTypeCVRQualifiers());
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());
4860 const clang::TemplateSpecializationType*
TST
4861 = llvm::dyn_cast<const clang::TemplateSpecializationType>(
instance);
4865 const clang::ClassTemplateSpecializationDecl*
TSTdecl
4866 = llvm::dyn_cast_or_null<const clang::ClassTemplateSpecializationDecl>(
instance->getAsCXXRecordDecl());
4870 const clang::SubstTemplateTypeParmType *
substType
4871 = llvm::dyn_cast<clang::SubstTemplateTypeParmType>(
input.getTypePtr());
4875 const clang::ClassTemplateDecl *
replacedCtxt =
nullptr;
4879 unsigned int index =
substType->getReplacedParameter()->getIndex();
4882 if (
decl->getKind() == clang::Decl::ClassTemplatePartialSpecialization) {
4883 const clang::ClassTemplatePartialSpecializationDecl *
spec = llvm::dyn_cast<clang::ClassTemplatePartialSpecializationDecl>(
decl);
4885 unsigned int depth =
substType->getReplacedParameter()->getDepth();
4901 const clang::SubstTemplateTypeParmType *
argType
4902 = llvm::dyn_cast<clang::SubstTemplateTypeParmType>(
argQualType);
4927 llvm::raw_string_ostream ostream(
astDump);
4930 ROOT::TMetaUtils::Warning(
"ReSubstTemplateArg",
"Unexpected type of declaration context for template parameter: %s.\n\tThe responsible class is:\n\t%s\n",
4937 const auto &
TAs =
TST->template_arguments();
4954 const clang::TemplateSpecializationType*
inputTST
4955 = llvm::dyn_cast<const clang::TemplateSpecializationType>(
input.getTypePtr());
4960 llvm::SmallVector<clang::TemplateArgument, 4>
desArgs;
4961 for (
const clang::TemplateArgument &
TA :
inputTST->template_arguments()) {
4962 if (
TA.getKind() != clang::TemplateArgument::Type) {
4967 clang::QualType
SubTy =
TA.getAsType();
4969 if (
SubTy->getPrefix()
4970 || llvm::isa<clang::SubstTemplateTypeParmType>(
SubTy)
4971 || llvm::isa<clang::TemplateSpecializationType>(
SubTy)) {
4988 inputTST->getCanonicalTypeInternal());
5029 static const char *
stls[] =
5030 {
"any",
"vector",
"list",
"deque",
"map",
"multimap",
"set",
"multiset",
"bitset",
5031 "forward_list",
"unordered_set",
"unordered_multiset",
"unordered_map",
"unordered_multimap",
"RVec",
nullptr};
5045 for (
int k = 1;
stls[k]; k++) {
5059 TND =
TND->getMostRecentDecl();
5060 while (
TND && !(
TND->hasAttrs()))
5061 TND =
TND->getPreviousDecl();
5073 TD =
TD->getMostRecentDecl();
5074 while (
TD && !(
TD->hasAttrs() &&
TD->isThisDeclarationADefinition()))
5075 TD =
TD->getPreviousDecl();
5131 std::list<std::pair<std::string,unsigned int> >&
enclosingSc)
5159 std::string::size_type
beginVar = 0;
5160 std::string::size_type
endVar = 0;
5164 std::string::size_type
endVarName = std::string::npos;
5206 const char*
envInclPath = std::getenv(
"ROOT_INCLUDE_PATH");
5241 str.replace(
start_pos, from.length(), to);
5308 return llvm::sys::path::extension(
filename) ==
".h" ||
5309 llvm::sys::path::extension(
filename) ==
".hh" ||
5310 llvm::sys::path::extension(
filename) ==
".hpp" ||
5311 llvm::sys::path::extension(
filename) ==
".H" ||
5312 llvm::sys::path::extension(
filename) ==
".h++" ||
5313 llvm::sys::path::extension(
filename) ==
"hxx" ||
5314 llvm::sys::path::extension(
filename) ==
"Hxx" ||
5315 llvm::sys::path::extension(
filename) ==
"HXX";
5321 cling::Interpreter::IgnoreFilesFunc_t
ignoreFiles,
5322 const cling::Interpreter &
interp,
5330 clang::Decl *
ncDecl =
const_cast<clang::Decl *
>(
decl);
5375 static const std::string
scopeType [] = {
"namespace ",
"inline namespace ",
"class "};
5417 std::string typeName;
5420 if (llvm::isa<clang::TemplateTypeParmDecl>(
nDecl)){
5421 typeName =
"typename ";
5422 if (
nDecl->isParameterPack())
5424 typeName += (*prmIt)->getNameAsString();
5427 else if (
auto nttpd = llvm::dyn_cast<clang::NonTypeTemplateParmDecl>(
nDecl)){
5431 if (
theType.getAsString().find(
"enum") != std::string::npos){
5433 llvm::raw_string_ostream ostream(
astDump);
5434 nttpd->dump(ostream);
5445 else if (
auto ttpd = llvm::dyn_cast<clang::TemplateTemplateParmDecl>(
nDecl)){
5449 llvm::raw_string_ostream ostream(
astDump);
5450 ttpd->dump(ostream);
5475 "Cannot extract template parameter list for %s",
5483 "Problems with arguments for forward declaration of class %s\n",
5493 if (llvm::isa<clang::TemplateTemplateParmDecl>(&
templDecl)) {
5515 if (clang::TemplateArgument::Type != arg.getKind())
return 0;
5530 if (llvm::isa<clang::BuiltinType>(
argTypePtr)){
5563 if (
specDef->getTemplateSpecializationKind() != clang::TSK_ExplicitSpecialization)
5567 std::cout <<
" Forward declaring template spec " <<
normalizedName <<
":\n";
5572 std::cout <<
" o Template argument ";
5574 std::cout <<
"successfully treated. Arg fwd decl: " <<
argFwdDecl << std::endl;
5576 std::cout <<
"could not be treated. Abort fwd declaration generation.\n";
5617 std::cout <<
"Class " <<
recordDecl.getNameAsString()
5618 <<
" is a template specialisation. Treating its arguments.\n";
5622 std::cout <<
" o Template argument ";
5624 std::cout <<
"successfully treated. Arg fwd decl: " <<
argFwdDecl << std::endl;
5626 std::cout <<
"could not be treated. Abort fwd declaration generation.\n";
5674 std::string buffer =
tdnDecl.getNameAsString();
5677 if (
const clang::TagType* TT
5679 if (clang::NamedDecl*
ND = TT->getDecl()) {
5680 if (!
ND->getIdentifier()) {
5724 std::cout <<
"Typedef " <<
tdnDecl.getNameAsString() <<
" hides a class: "
5751 const clang::PrintingPolicy&
ppolicy)
5754 auto&
ctxt = par.getASTContext();
5775 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 .