24#include <unordered_set>
27#include "RConfigure.h"
35#include "clang/AST/ASTContext.h"
36#include "clang/AST/Attr.h"
37#include "clang/AST/CXXInheritance.h"
38#include "clang/AST/Decl.h"
39#include "clang/AST/DeclTemplate.h"
40#include "clang/AST/Mangle.h"
41#include "clang/AST/Type.h"
42#include "clang/AST/TypeVisitor.h"
43#include "clang/Frontend/CompilerInstance.h"
44#include "clang/Lex/HeaderSearch.h"
45#include "clang/Lex/ModuleMap.h"
46#include "clang/Lex/Preprocessor.h"
47#include "clang/Lex/PreprocessorOptions.h"
49#include "clang/Sema/Lookup.h"
50#include "clang/Sema/Sema.h"
51#include "clang/Sema/SemaDiagnostic.h"
53#include "cling/Interpreter/LookupHelper.h"
54#include "cling/Interpreter/Transaction.h"
55#include "cling/Interpreter/Interpreter.h"
56#include "cling/Utils/AST.h"
57#include "cling/Interpreter/InterpreterAccessRAII.h"
59#include "llvm/Support/Path.h"
60#include "llvm/Support/FileSystem.h"
65#define strncasecmp _strnicmp
85 using DeclsCont_t = TNormalizedCtxt::Config_t::SkipCollection;
102 bool replace =
false);
113 clang::NestedNameSpecifier*
scope,
116 if (!
scope)
return nullptr;
139static bool CheckDefinition(
const clang::CXXRecordDecl *cl,
const clang::CXXRecordDecl *context)
141 if (!cl->hasDefinition()) {
144 "Missing definition for class %s, please #include its header in the header of %s\n",
145 cl->getName().str().c_str(), context->getName().str().c_str());
148 "Missing definition for class %s\n",
149 cl->getName().str().c_str());
162 clang::NestedNameSpecifier *
scope,
165 if (!
scope)
return nullptr;
187 const clang::BuiltinType *
builtin = llvm::dyn_cast<clang::BuiltinType>(
type->getCanonicalTypeInternal().getTypePtr());
207 clang::ASTContext &
C = cl.getASTContext();
208 clang::DeclarationName
DName = &
C.Idents.get(
what);
209 auto R = cl.lookup(
DName);
210 for (
const clang::NamedDecl *D :
R)
222 clang::LookupResult
R(
SemaR,
DName, clang::SourceLocation(),
223 clang::Sema::LookupOrdinaryName,
224 clang::Sema::ForExternalRedeclaration);
225 SemaR.LookupInSuper(
R, &
const_cast<clang::CXXRecordDecl&
>(cl));
228 return llvm::dyn_cast<const clang::FieldDecl>(
R.getFoundDecl());
234 ? cling::LookupHelper::WithDiagnostics
235 : cling::LookupHelper::NoDiagnostics;
242namespace TMetaUtils {
251 Error(
"TNormalizedCtxt::AddTemplAndNargsToKeep",
252 "Tring to specify a number of template arguments to keep for a null pointer. Exiting without assigning any value.\n");
256 const clang::ClassTemplateDecl*
canTempl =
templ->getCanonicalDecl();
261 const std::string
i_str (std::to_string(i));
263 Error(
"TNormalizedCtxt::AddTemplAndNargsToKeep",
264 "Tring to specify for template %s %s arguments to keep, while before this number was %s\n",
265 canTempl->getNameAsString().c_str(),
278 const clang::ClassTemplateDecl*
constTempl =
templ->getCanonicalDecl();
329 std::unique_ptr<clang::MangleContext>
mangleCtx(
rDecl->getASTContext().createMangleContext());
333 if (
const clang::TypeDecl*
TD = llvm::dyn_cast<clang::TypeDecl>(
rDecl)) {
334 mangleCtx->mangleCXXRTTI(clang::QualType(
TD->getTypeForDecl(), 0),
sstr);
360 "Demangled typeinfo name '%s' does not contain `RTTI Type Descriptor'\n",
364 "Demangled typeinfo name '%s' does not start with 'typeinfo for'\n",
381 const clang::RecordDecl *
decl,
410 const clang::RecordDecl *
decl,
439 "Could not remove the requested template arguments.\n");
450 const clang::RecordDecl *
decl,
484 const clang::RecordDecl *
decl,
546 if (
tname.empty())
return false;
560 if (!
dest.isNull() && (
dest != t)) {
580 if (!
dest.isNull() && (
dest != t) &&
602 const clang::NamespaceDecl *
nsdecl = llvm::dyn_cast<clang::NamespaceDecl>(
scope);
615 if (
tname.empty())
return false;
647 clang::PrintingPolicy
policy(
fInterpreter->getCI()->getASTContext().getPrintingPolicy());
648 policy.SuppressTagKeyword =
true;
649 policy.SuppressScope =
true;
664 for(
unsigned int i = 1; i<
result.length(); ++i) {
676 }
else if ( (i+1) <
result.length() &&
714 clang::QualType
toSkip =
lh.findType(
name, cling::LookupHelper::WithDiagnostics);
715 if (
const clang::Type* T =
toSkip.getTypePtr()) {
716 const clang::TypedefType *
tt = llvm::dyn_cast<clang::TypedefType>(T);
718 clang::Decl* D =
tt->getDecl();
719 fConfig.m_toSkip.insert(D);
721 clang::QualType
canon =
toSkip->getCanonicalTypeInternal();
722 fConfig.m_toReplace.insert(std::make_pair(
canon.getTypePtr(),T));
724 fTypeWithAlternative.insert(T);
737 keepTypedef(
lh,
"Double32_t");
738 keepTypedef(
lh,
"Float16_t");
739 keepTypedef(
lh,
"Long64_t",
true);
740 keepTypedef(
lh,
"ULong64_t",
true);
742 clang::QualType
toSkip =
lh.findType(
"string", cling::LookupHelper::WithDiagnostics);
744 if (
const clang::TypedefType* TT
745 = llvm::dyn_cast_or_null<clang::TypedefType>(
toSkip.getTypePtr()))
746 fConfig.m_toSkip.insert(TT->getDecl());
748 toSkip =
lh.findType(
"std::string", cling::LookupHelper::WithDiagnostics);
750 if (
const clang::TypedefType* TT
751 = llvm::dyn_cast_or_null<clang::TypedefType>(
toSkip.getTypePtr()))
752 fConfig.m_toSkip.insert(TT->getDecl());
754 clang::QualType
canon =
toSkip->getCanonicalTypeInternal();
755 fConfig.m_toReplace.insert(std::make_pair(
canon.getTypePtr(),
toSkip.getTypePtr()));
766 return (cl.getKind() == clang::Decl::ClassTemplatePartialSpecialization
767 || cl.getKind() == clang::Decl::ClassTemplateSpecialization);
774 const cling::Interpreter&
interp)
776 clang::Sema* S = &
interp.getSema();
777 const clang::NamedDecl*
ND = cling::utils::Lookup::Named(S,
name, cl);
778 if (
ND == (clang::NamedDecl*)-1)
779 return (clang::FunctionDecl*)-1;
780 return llvm::dyn_cast_or_null<clang::FunctionDecl>(
ND);
786const clang::CXXRecordDecl *
790 const cling::LookupHelper&
lh =
interp.getLookupHelper();
793 const clang::CXXRecordDecl *
result
794 = llvm::dyn_cast_or_null<clang::CXXRecordDecl>
801 result = llvm::dyn_cast_or_null<clang::CXXRecordDecl>
812 clang::QualType
qType(cl->getTypeForDecl(),0);
820 clang::Sema& S =
interp.getCI()->getSema();
823 cling::Interpreter::PushTransactionRAII
RAII(
const_cast<cling::Interpreter*
>(&
interp));
824 return S.RequireCompleteType(
Loc, Type, clang::diag::err_incomplete_type);
830 const clang::CXXRecordDecl *context,
const cling::Interpreter &
interp)
836 if (!cl->getDefinition() || !cl->isCompleteDefinition()) {
844 if (!base->hasDefinition()) {
848 return cl->isDerivedFrom(base);
860 const clang::NamedDecl *base
864 return IsBase(
CRD, llvm::dyn_cast<clang::CXXRecordDecl>( base ),
865 llvm::dyn_cast<clang::CXXRecordDecl>(
m.getDeclContext()),
interp);
874 const clang::QualType &
qti,
876 const cling::Interpreter &
interp,
884 kBIT_ISSTRING = 0x40000000,
891 const clang::Type &
ti( *
qti.getTypePtr() );
914 if (
tiName ==
"string")
kase |= kBIT_ISSTRING;
915 if (
tiName ==
"string*")
kase |= kBIT_ISSTRING;
919 tcl =
" internal error in rootcling ";
944 <<
" R__b >> readtemp;" << std::endl
945 <<
" " <<
R__t <<
" = static_cast<" <<
tiName <<
">(readtemp);" << std::endl;
957 finalString <<
" if (R__b.GetInfo() && R__b.GetInfo()->GetOldVersion()<=3) {" << std::endl;
959 finalString <<
" R__ASSERT(0);// " <<
objType <<
" is abstract. We assume that older file could not be produced using this streaming method." << std::endl;
962 <<
" " <<
R__t <<
"->Streamer(R__b);" << std::endl;
965 <<
" " <<
R__t <<
" = (" <<
tiName <<
")R__b.ReadObjectAny(" <<
tcl <<
");" << std::endl
966 <<
" }" << std::endl;
972 <<
" R__str.Streamer(R__b);" << std::endl
973 <<
" " <<
R__t <<
" = R__str.Data();}" << std::endl;
979 <<
" R__str.Streamer(R__b);" << std::endl
980 <<
" " <<
R__t <<
" = new string(R__str.Data());}" << std::endl;
1000 if (!
R__t)
return 0;
1005 if (!
R__t)
return 0;
1007 finalString <<
" R__b >> *reinterpret_cast<Int_t*>(ptr_enum); }" << std::endl;
1012 if (!
R__t)
return 0;
1017 if (!
R__t)
return 1;
1022 if (!
R__t)
return 0;
1023 finalString <<
" {TString R__str(" <<
R__t <<
".c_str());" << std::endl
1024 <<
" R__str.Streamer(R__b);};" << std::endl;
1028 if (!
R__t)
return 0;
1029 finalString <<
" {TString R__str(" <<
R__t <<
"->c_str());" << std::endl
1030 <<
" R__str.Streamer(R__b);}" << std::endl;
1034 if (!
R__t)
return 1;
1039 if (!
R__t)
return 1;
1052 clang::CXXRecordDecl*
ncCl =
const_cast<clang::CXXRecordDecl*
>(cl);
1055 cling::Interpreter::PushTransactionRAII
clingRAII(
const_cast<cling::Interpreter*
>(&
interpreter));
1058 if (
Ctor->getAccess() == clang::AS_public && !
Ctor->isDeleted()) {
1076 const cling::LookupHelper&
lh =
interpreter.getLookupHelper();
1085 return EIOCtorCategory::kAbsent;
1088 cling::Interpreter::PushTransactionRAII
clingRAII(
const_cast<cling::Interpreter*
>(&
interpreter));
1089 for (
auto iter = cl->ctor_begin(), end = cl->ctor_end(); iter != end; ++iter)
1091 if ((iter->getAccess() != clang::AS_public) || (iter->getNumParams() != 1))
1095 clang::QualType
argType((*iter->param_begin())->getType());
1099 if (
argType->isPointerType()) {
1102 }
else if (
argType->isReferenceType()) {
1109 const clang::CXXRecordDecl *
argDecl =
argType->getAsCXXRecordDecl();
1116 std::string
clarg(
"class ");
1123 return EIOCtorCategory::kAbsent;
1136 if (!
ioctortype.GetType() && (!arg || !arg[0])) {
1150 const cling::Interpreter &
interp,
1153 const clang::FunctionDecl*
funcD
1155 diagnose ? cling::LookupHelper::WithDiagnostics
1156 : cling::LookupHelper::NoDiagnostics);
1158 return llvm::dyn_cast<const clang::CXXMethodDecl>(
funcD);
1167 namespace TMetaUtils {
1170 const cling::LookupHelper&
lh =
interp.getLookupHelper();
1189 const cling::Interpreter &
interp)
1191 if (cl->isAbstract())
return false;
1197 if (EIOCtorCategory::kAbsent ==
ioCtorCat)
1207 if (EIOCtorCategory::kIOPtrType ==
ioCtorCat) {
1209 }
else if (EIOCtorCategory::kIORefType ==
ioCtorCat) {
1213 arg +=
")nullptr )";
1216 const clang::CXXMethodDecl *
method
1218 cling::LookupHelper::NoDiagnostics);
1219 if (
method &&
method->getAccess() != clang::AS_public) {
1233 const cling::Interpreter&
interp)
1235 if (!cl)
return false;
1237 if (cl->hasUserDeclaredDestructor()) {
1239 cling::Interpreter::PushTransactionRAII
clingRAII(
const_cast<cling::Interpreter*
>(&
interp));
1240 clang::CXXDestructorDecl *
dest = cl->getDestructor();
1242 return (
dest->getAccess() == clang::AS_public);
1256 const cling::Interpreter &
interp,
1259 const clang::CXXMethodDecl *
method
1261 diagnose ? cling::LookupHelper::WithDiagnostics
1262 : cling::LookupHelper::NoDiagnostics);
1263 return (
method &&
method->getAccess() == clang::AS_public);
1274 const char *
proto =
"TDirectory*";
1275 const char *
name =
"DirectoryAutoAdd";
1289 const char *
proto =
"TCollection*,TFileMergeInfo*";
1290 const char *
name =
"Merge";
1303 const char *
proto =
"TCollection*";
1304 const char *
name =
"Merge";
1319 const char *
proto =
"TFileMergeInfo*";
1320 const char *
name =
"ResetAfterMerge";
1330 const clang::CXXRecordDecl*
clxx,
1331 const cling::Interpreter &
interp,
1334 static const char *
proto =
"TBuffer&";
1336 const clang::CXXMethodDecl *
method
1338 cling::LookupHelper::NoDiagnostics);
1349 const clang::CXXRecordDecl*
clxx,
1350 const cling::Interpreter &
interp,
1353 static const char *
proto =
"TBuffer&,TClass*";
1355 const clang::CXXMethodDecl *
method
1357 cling::LookupHelper::NoDiagnostics);
1422 llvm::raw_string_ostream stream(
qual_name);
1423 clang::PrintingPolicy
policy( cl.getASTContext().getPrintingPolicy() );
1424 policy.SuppressTagKeyword =
true;
1425 policy.SuppressUnwrittenScope =
true;
1427 cl.getNameForDiagnostic(stream,
policy,
true);
1483 std::stringstream
dims;
1486 const clang::ASTContext&
astContext = cl.getASTContext();
1489 for(clang::RecordDecl::field_iterator
field_iter = cl.field_begin(), end = cl.field_end();
1503 const clang::ConstantArrayType *
arrayType = llvm::dyn_cast<clang::ConstantArrayType>(
fieldType.getTypePtr());
1505 dims <<
"[" <<
arrayType->getSize().getLimitedValue() <<
"]";
1507 arrayType = llvm::dyn_cast<clang::ConstantArrayType>(
arrayType->getArrayElementTypeNoTypeQual());
1517 for(clang::CXXRecordDecl::base_class_const_iterator iter = cl.bases_begin(), end = cl.bases_end();
1520 std::string
basename( iter->getType()->getAsCXXRecordDecl()->getNameAsString() );
1530 const cling::Interpreter &
interp,
1534 diagnose ? cling::LookupHelper::WithDiagnostics
1535 : cling::LookupHelper::NoDiagnostics);
1594 while (llvm::isa<clang::PointerType>(
instanceType.getTypePtr())
1595 || llvm::isa<clang::ReferenceType>(
instanceType.getTypePtr()))
1600 const clang::ElaboratedType* etype
1601 = llvm::dyn_cast<clang::ElaboratedType>(
instanceType.getTypePtr());
1603 instanceType = clang::QualType(etype->getNamedType().getTypePtr(),0);
1617 if (
clxx &&
clxx->getTemplateSpecializationKind() != clang::TSK_Undeclared) {
1619 const clang::TemplateSpecializationType*
TST
1620 = llvm::dyn_cast<const clang::TemplateSpecializationType>(
instanceType.getTypePtr());
1627 for (
const clang::TemplateArgument &
TA :
TST->template_arguments()) {
1628 if (
TA.getKind() == clang::TemplateArgument::Type) {
1640 const cling::Interpreter &
interp,
1643 const clang::CXXRecordDecl *
clxx = llvm::dyn_cast<clang::CXXRecordDecl>(cl.
GetRecordDecl());
1644 if (!
clxx ||
clxx->getTemplateSpecializationKind() == clang::TSK_Undeclared)
return false;
1647 cling::LookupHelper::WithDiagnostics);
1661 clang::AnnotateAttr*
annAttr = clang::dyn_cast<clang::AnnotateAttr>(
attribute);
1704 for (clang::Decl::attr_iterator
attrIt =
decl.attr_begin();
1706 clang::AnnotateAttr*
annAttr = clang::dyn_cast<clang::AnnotateAttr>(*
attrIt);
1710 std::pair<llvm::StringRef,llvm::StringRef> split =
attribute.split(propNames::separator.c_str());
1711 if (split.first !=
propName.c_str())
continue;
1727 for (clang::Decl::attr_iterator
attrIt =
decl.attr_begin();
1729 clang::AnnotateAttr*
annAttr = clang::dyn_cast<clang::AnnotateAttr>(*
attrIt);
1733 std::pair<llvm::StringRef,llvm::StringRef> split =
attribute.split(propNames::separator.c_str());
1734 if (split.first !=
propName.c_str())
continue;
1736 return split.second.getAsInteger(10,
propValue);
1747 const clang::CXXRecordDecl *
decl,
1748 const cling::Interpreter &
interp,
1757 std::string
csymbol = classname;
1771 bool isStd = TMetaUtils::IsStdClass(*
decl);
1772 const cling::LookupHelper&
lh =
interp.getLookupHelper();
1782 <<
" static void " <<
mappedname.c_str() <<
"_TClassManip(TClass*);\n";
1800 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";
1803 finalString <<
" static void directoryAutoAdd_" <<
mappedname.c_str() <<
"(void *obj, TDirectory *dir);" <<
"\n";
1806 finalString <<
" static void streamer_" <<
mappedname.c_str() <<
"(TBuffer &buf, void *obj);" <<
"\n";
1809 finalString <<
" static void conv_streamer_" <<
mappedname.c_str() <<
"(TBuffer &buf, void *obj, const TClass*);" <<
"\n";
1812 finalString <<
" static Long64_t merge_" <<
mappedname.c_str() <<
"(void *obj, TCollection *coll,TFileMergeInfo *info);" <<
"\n";
1815 finalString <<
" static void reset_" <<
mappedname.c_str() <<
"(void *obj, TFileMergeInfo *info);" <<
"\n";
1834 finalString <<
"\n // Schema evolution read functions\n";
1853 if(
rIt->find(
"code" ) !=
rIt->
end() ) {
1869 finalString <<
"\n // Schema evolution read raw functions\n";
1896 finalString <<
"\n" <<
" // Function generating the singleton type initializer" <<
"\n";
1898 finalString <<
" static TGenericClassInfo *GenerateInitInstanceLocal(const " <<
csymbol <<
"*)" <<
"\n" <<
" {" <<
"\n";
1904 finalString <<
" static ::TVirtualIsAProxy* isa_proxy = new ::TInstrumentedIsAProxy< " <<
csymbol <<
" >(nullptr);" <<
"\n";
1907 finalString <<
" static ::TVirtualIsAProxy* isa_proxy = new ::TIsAProxy(typeid(" <<
csymbol <<
"));" <<
"\n";
1909 finalString <<
" static ::ROOT::TGenericClassInfo " <<
"\n" <<
" instance(\"" << classname.c_str() <<
"\", ";
1922 static const char *
versionFunc =
"GetClassVersion";
1926 std::string
proto = classname +
"*";
1927 const clang::Decl*
ctxt = llvm::dyn_cast<clang::Decl>((*cl).getDeclContext());
1930 interp, cling::LookupHelper::NoDiagnostics);
1949 for (
unsigned int i=0; i<
filename.length(); i++) {
1954 <<
"," <<
"\n" <<
" typeid(" <<
csymbol
1955 <<
"), ::ROOT::Internal::DefineBehavior(ptr, ptr)," <<
"\n" <<
" ";
1978 finalString <<
" instance.SetDelete(&delete_" <<
mappedname.c_str() <<
");" <<
"\n" <<
" instance.SetDeleteArray(&deleteArray_" <<
mappedname.c_str() <<
");" <<
"\n" <<
" instance.SetDestructor(&destruct_" <<
mappedname.c_str() <<
");" <<
"\n";
1981 finalString <<
" instance.SetDirectoryAutoAdd(&directoryAutoAdd_" <<
mappedname.c_str() <<
");" <<
"\n";
1989 finalString <<
" instance.SetConvStreamerFunc(&conv_streamer_" <<
mappedname.c_str() <<
");" <<
"\n";
1998 finalString <<
" instance.AdoptCollectionProxyInfo(TCollectionProxyInfo::Generate(TCollectionProxyInfo::" <<
"Pushback" <<
"<Internal::TStdBitsetHelper< " << classname.c_str() <<
" > >()));" <<
"\n";
2001 }
else if (
stl != 0 &&
2004 int idx = classname.find(
"<");
2033 finalString <<
" instance.AdoptCollectionProxyInfo(TCollectionProxyInfo::Generate(TCollectionProxyInfo::" <<
methodTCP <<
"< " <<
classNameForIO.c_str() <<
" >()));" <<
"\n";
2043 finalString <<
"\n" <<
" instance.AdoptAlternate(::ROOT::AddClassAlternate(\""
2050 finalString <<
"\n" <<
" instance.AdoptAlternate(::ROOT::AddClassAlternate(\""
2060 finalString <<
"\n" <<
" ::ROOT::Internal::TSchemaHelper* rule;" <<
"\n";
2064 finalString <<
"\n" <<
" // the io read rules" <<
"\n" <<
" std::vector<::ROOT::Internal::TSchemaHelper> readrules(" <<
rulesIt1->second.size() <<
");" <<
"\n";
2066 finalString <<
" instance.SetReadRules( readrules );" <<
"\n";
2070 finalString <<
"\n" <<
" // the io read raw rules" <<
"\n" <<
" std::vector<::ROOT::Internal::TSchemaHelper> readrawrules(" <<
rulesIt2->second.size() <<
");" <<
"\n";
2072 finalString <<
" instance.SetReadRawRules( readrawrules );" <<
"\n";
2075 finalString <<
" return &instance;" <<
"\n" <<
" }" <<
"\n";
2079 finalString <<
" TGenericClassInfo *GenerateInitInstance(const " <<
csymbol <<
"*)" <<
"\n" <<
" {\n return GenerateInitInstanceLocal(static_cast<" <<
csymbol <<
"*>(nullptr));\n }" <<
"\n";
2082 finalString <<
" // Static variable to force the class initialization" <<
"\n";
2086 finalString <<
" static ::ROOT::TGenericClassInfo *_R__UNIQUE_DICT_(Init) = GenerateInitInstanceLocal(static_cast<const " <<
csymbol <<
"*>(nullptr)); R__UseDummy(_R__UNIQUE_DICT_(Init));" <<
"\n";
2089 finalString <<
"\n" <<
" // Dictionary for non-ClassDef classes" <<
"\n"
2090 <<
" static TClass *" <<
mappedname <<
"_Dictionary() {\n"
2091 <<
" TClass* theClass ="
2092 <<
"::ROOT::GenerateInitInstanceLocal(static_cast<const " <<
csymbol <<
"*>(nullptr))->GetClass();\n"
2093 <<
" " <<
mappedname <<
"_TClassManip(theClass);\n";
2104 if (
decl->hasAttrs()){
2106 for (clang::Decl::attr_iterator
attrIt =
decl->attr_begin();
2123 manipString+=
" theClass->CreateAttributeMap();\n";
2124 manipString+=
" TDictAttributeMap* attrMap( theClass->GetAttributeMap() );\n";
2135 if (!(!(*internalDeclIt)->isImplicit()
2156 TMetaUtils::Error(
nullptr,
"Cannot convert field declaration to clang::NamedDecl");
2172 if (
attrName == propNames::comment ||
2174 attrName == propNames::ioname )
continue;
2199 finalString <<
"} // end of namespace ROOT" <<
"\n" <<
"\n";
2211 const clang::CXXRecordDecl *cl)
2221 auto ctxt = cl->getEnclosingNamespaceContext();
2226 const clang::NamedDecl *
namedCtxt = llvm::dyn_cast<clang::NamedDecl>(
ctxt);
2228 const clang::NamespaceDecl *
nsdecl = llvm::dyn_cast<clang::NamespaceDecl>(
namedCtxt);
2243 const clang::DeclContext *
ctxt = cl.getDeclContext();
2244 while(
ctxt && !
ctxt->isNamespace()) {
2265 const clang::NamespaceDecl *ns = llvm::dyn_cast<clang::NamespaceDecl>(
ctxt);
2271 out <<
"namespace " << ns->getNameAsString() <<
" {" << std::endl;
2290 clang::TemplateSpecializationKind kind = cl->getTemplateSpecializationKind();
2291 if (kind == clang::TSK_Undeclared ) {
2294 }
else if (kind == clang::TSK_ExplicitSpecialization) {
2309 const char *
proto =
"size_t";
2316 cling::LookupHelper::NoDiagnostics);
2320 cling::LookupHelper::NoDiagnostics);
2322 const clang::DeclContext *
ctxtnew =
nullptr;
2358 const clang::CXXRecordDecl*
clnew = llvm::dyn_cast<clang::CXXRecordDecl>(
ctxtnew);
2405 const clang::CXXRecordDecl *
decl,
2406 const cling::Interpreter &
interp,
2430 classname.insert(0,
"::");
2438 finalString <<
" // Wrappers around operator new" <<
"\n";
2439 finalString <<
" static void *new_" <<
mappedname.c_str() <<
"(void *p) {" <<
"\n" <<
" return p ? ";
2446 finalString <<
"::new(static_cast<::ROOT::Internal::TOperatorNewHelper*>(p)) ";
2451 finalString <<
"new " << classname.c_str() << args <<
";" <<
"\n";
2466 finalString <<
"::new(static_cast<::ROOT::Internal::TOperatorNewHelper*>(p)) ";
2480 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";
2484 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";
2488 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";
2492 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";
2496 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";
2498 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";
2502 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";
2504 finalString <<
"} // end of namespace ROOT for class " << classname.c_str() <<
"\n" <<
"\n";
2511 const cling::Interpreter &
interp,
2522 const clang::CXXRecordDecl *
clxx = llvm::dyn_cast<clang::CXXRecordDecl>(cl.
GetRecordDecl());
2526 for(clang::CXXRecordDecl::base_class_const_iterator iter =
clxx->bases_begin(), end =
clxx->bases_end();
2532 Internal::RStl::Instance().GenerateTClassFor( iter->getType(),
interp,
normCtxt);
2537 for(clang::RecordDecl::field_iterator
field_iter =
clxx->field_begin(), end =
clxx->field_end();
2569 const clang::Type *
rawtype =
m.getType()->getCanonicalTypeInternal().getTypePtr();
2585 const clang::CXXRecordDecl*
CRD = llvm::dyn_cast<clang::CXXRecordDecl>(cl);
2597 if (
funcCV == (clang::FunctionDecl*)-1)
return 1;
2612 using res_t = std::pair<bool, int>;
2614 const clang::CompoundStmt*
FuncBody
2615 = llvm::dyn_cast_or_null<clang::CompoundStmt>(
funcCV->getBody());
2617 return res_t{
false, -1};
2622 return res_t{
false, -1};
2624 const clang::ReturnStmt*
RetStmt
2625 = llvm::dyn_cast<clang::ReturnStmt>(
FuncBody->body_back());
2627 return res_t{
false, -1};
2639 return res_t{
false, -1};
2647 return TMetaUtils::IsSTLCont(*
annotated.GetRecordDecl());
2655 clang::QualType
type =
m.getType();
2658 if (
decl)
return TMetaUtils::IsSTLCont(*
decl);
2667 clang::QualType
type = base.getType();
2670 if (
decl)
return TMetaUtils::IsSTLCont(*
decl);
2680 const std::function<
void(
const clang::Module::Header &)> &
closure,
2693 const std::size_t
maxArrayLength = ((
sizeof module.Headers) / (sizeof *module.Headers));
2695 "'Headers' has changed it's size, we need to update publicHeaderIndex");
2700 llvm::SetVector<const clang::Module *>
modules;
2702 for (
size_t i = 0; i <
modules.size(); ++i) {
2703 const clang::Module *M =
modules[i];
2704 for (
const clang::Module *
subModule : M->submodules())
2708 for (
const clang::Module *
m :
modules) {
2710 for (clang::Module *
used :
m->DirectUses) {
2732 static char t[4096];
2733 static const char*
constwd =
"const ";
2742 if (
lev==0 && *s==
'*')
continue;
2748 if (
lev==0 && *s==
' ' && *(s+1)!=
'*') {
p = t;
continue;}
2749 if (
p - t > (
long)
sizeof(t)) {
2750 printf(
"ERROR (rootcling): type name too long for StortTypeName: %s\n",
2763 const cling::Interpreter&
interp)
2768 if (!comment.empty() && comment[0] ==
'!')
2771 clang::QualType
type =
m.getType();
2773 if (
type->isReferenceType()) {
2778 std::string
mTypeName =
type.getAsString(
m.getASTContext().getPrintingPolicy());
2790 const clang::Type *
rawtype =
type.getTypePtr()->getBaseElementTypeUnsafe ();
2792 if (
rawtype->isPointerType()) {
2806 const clang::CXXRecordDecl *
cxxdecl =
rawtype->getAsCXXRecordDecl();
2823 const clang::Type *
rawtype =
m.getType().getTypePtr();
2847 return rawtype->getAsCXXRecordDecl();
2856 const cling::Interpreter &
interp,
2862 const clang::CXXRecordDecl*
decl = llvm::dyn_cast<clang::CXXRecordDecl>(cl.
GetRecordDecl());
2864 if (!
decl || !
decl->isCompleteDefinition()) {
2868 std::string fullname;
2882 ROOT::TMetaUtils::Info(
nullptr,
"Class %s: Do not generate Streamer() [*** custom streamer ***]\n",fullname.c_str());
2907 const clang::ASTContext&
Ctx =
interpreter.getCI()->getASTContext();
2913 if (llvm::isa<clang::PointerType>(
instanceType.getTypePtr())) {
2927 if (llvm::isa<clang::ReferenceType>(
instanceType.getTypePtr())) {
2947 clang::NestedNameSpecifier *prefix =
nullptr;
2949 const clang::ElaboratedType* etype
2950 = llvm::dyn_cast<clang::ElaboratedType>(
instanceType.getTypePtr());
2955 instanceType = clang::QualType(etype->getNamedType().getTypePtr(),0);
2961 const clang::TemplateSpecializationType*
TST
2962 = llvm::dyn_cast<const clang::TemplateSpecializationType>(
instanceType.getTypePtr());
2964 const clang::ClassTemplateSpecializationDecl*
TSTdecl
2965 = llvm::dyn_cast_or_null<const clang::ClassTemplateSpecializationDecl>(
instanceType.getTypePtr()->getAsCXXRecordDecl());
2981 clang::TemplateDecl *Template =
TSTdecl->getSpecializedTemplate()->getMostRecentDecl();
2982 clang::TemplateParameterList *Params = Template->getTemplateParameters();
2989 llvm::SmallVector<clang::TemplateArgument, 4>
desArgs;
2990 llvm::SmallVector<clang::TemplateArgument, 4>
canonArgs;
2999 if (
I->getKind() == clang::TemplateArgument::Template) {
3006 clang::NamespaceDecl* ns = clang::dyn_cast<clang::NamespaceDecl>(
declCtxt);
3007 clang::NestedNameSpecifier*
nns;
3009 nns = cling::utils::TypeName::CreateNestedNameSpecifier(
Ctx, ns);
3010 }
else if (clang::TagDecl*
TD = llvm::dyn_cast<clang::TagDecl>(
declCtxt)) {
3011 nns = cling::utils::TypeName::CreateNestedNameSpecifier(
Ctx,
TD,
false );
3018 if (clang::UsingShadowDecl *
USD =
templateName.getAsUsingShadowDecl())
3028 if (
I->getKind() != clang::TemplateArgument::Type) {
3033 clang::QualType
SubTy =
I->getAsType();
3055 if (
templateArg.getKind() != clang::TemplateArgument::Type) {
3061 clang::SourceLocation
TemplateLoc = Template->getSourceRange ().getBegin();
3064 clang::TemplateTypeParmDecl *
TTP = llvm::dyn_cast<clang::TemplateTypeParmDecl>(*
Param);
3067 cling::Interpreter::PushTransactionRAII
clingRAII(
const_cast<cling::Interpreter*
>(&
interpreter));
3069 clang::TemplateArgumentLoc
ArgType = S.SubstDefaultTemplateArgumentIfAvailable(
3079 if (
ArgType.getArgument().isNull()
3080 ||
ArgType.getArgument().getKind() != clang::TemplateArgument::Type) {
3082 "Template parameter substitution failed for %s around %s\n",
3102 TST->getCanonicalTypeInternal());
3131 llvm::StringRef title;
3134 if (clang::AnnotateAttr *A =
m.getAttr<clang::AnnotateAttr>())
3135 title = A->getAnnotation();
3149 if (title.size() == 0 || (title[0] !=
'['))
return llvm::StringRef();
3151 if (
rightbracket == llvm::StringRef::npos)
return llvm::StringRef();
3170 char *current =
const_cast<char*
>(
working.c_str());
3176 for(i=0;i<
strlen(current);i++) {
3184 return llvm::StringRef();
3189 const clang::CXXRecordDecl *
parent_clxx = llvm::dyn_cast<clang::CXXRecordDecl>(
m.getDeclContext());
3190 const clang::FieldDecl *
index1 =
nullptr;
3203 if (
field_iter->getNameAsString() ==
m.getNameAsString() ) {
3211 return llvm::StringRef();
3223 return llvm::StringRef();
3248 return llvm::StringRef();
3250 if ( found && (
index1->getAccess() == clang::AS_private) ) {
3255 return llvm::StringRef();
3264 return llvm::StringRef();
3285 while((
c = in[i++])) {
3286 const char *
repl =
nullptr;
3288 case '+':
repl =
"pL";
break;
3289 case '-':
repl =
"mI";
break;
3290 case '*':
repl =
"mU";
break;
3291 case '/':
repl =
"dI";
break;
3292 case '&':
repl =
"aN";
break;
3293 case '%':
repl =
"pE";
break;
3294 case '|':
repl =
"oR";
break;
3295 case '^':
repl =
"hA";
break;
3296 case '>':
repl =
"gR";
break;
3297 case '<':
repl =
"lE";
break;
3298 case '=':
repl =
"eQ";
break;
3299 case '~':
repl =
"wA";
break;
3300 case '.':
repl =
"dO";
break;
3301 case '(':
repl =
"oP";
break;
3302 case ')':
repl =
"cP";
break;
3303 case '[':
repl =
"oB";
break;
3304 case ']':
repl =
"cB";
break;
3305 case '{':
repl =
"lB";
break;
3306 case '}':
repl =
"rB";
break;
3307 case ';':
repl =
"sC";
break;
3308 case '#':
repl =
"hS";
break;
3309 case '?':
repl =
"qM";
break;
3310 case '`':
repl =
"bT";
break;
3311 case '!':
repl =
"nO";
break;
3312 case ',':
repl =
"cO";
break;
3313 case '$':
repl =
"dA";
break;
3314 case ' ':
repl =
"sP";
break;
3315 case ':':
repl =
"cL";
break;
3316 case '"':
repl =
"dQ";
break;
3317 case '@':
repl =
"aT";
break;
3318 case '\'':
repl =
"sQ";
break;
3319 case '\\':
repl =
"fI";
break;
3328 if (out.empty() ||
isdigit(out[0]))
3329 out.insert(out.begin(),
'_');
3332static clang::SourceLocation
3346 const cling::Interpreter&
interp)
3376 using namespace clang;
3401 ArrayRef<std::pair<OptionalFileEntryRef, DirectoryEntryRef>>(),
3416 assert(
decl.isFirstDecl() &&
"Couldn't trace back include from a decl"
3417 " that is not from an AST file");
3442 clang::OptionalFileEntryRef
FELong;
3444 for (llvm::sys::path::const_iterator
3457 &&
"Mismatched partitioning of file name!");
3461 ArrayRef<std::pair<OptionalFileEntryRef, DirectoryEntryRef>>(),
3473 for (llvm::sys::path::reverse_iterator
3481 &&
"Mismatched partitioning of file name!");
3487 ArrayRef<std::pair<OptionalFileEntryRef, DirectoryEntryRef>>(),
3490 nullptr,
nullptr ) ==
FELong) {
3501 const clang::QualType &
qtype,
3513 const clang::QualType &
qtype,
3519 cling::Interpreter::PushTransactionRAII
RAII(
const_cast<cling::Interpreter*
>(&
interpreter));
3531 clang::ClassTemplateDecl*&
ctd,
3532 clang::ClassTemplateSpecializationDecl*&
ctsd)
3534 using namespace clang;
3542 if (
theType->isPointerType()) {
3547 ctsd = llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(
rType->getDecl());
3549 ctd =
ctsd->getSpecializedTemplate();
3559 ctsd = llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(
qt->getAsCXXRecordDecl());
3561 ctd =
ctsd->getSpecializedTemplate();
3576 using namespace clang;
3592 using namespace clang;
3611 const clang::NamedDecl&
tPar,
3612 const cling::Interpreter&
interp,
3616 using namespace clang;
3621 if (!
ttpdPtr->hasDefaultArgument())
return false;
3643 const clang::ElaboratedType* etype
3644 = llvm::dyn_cast<clang::ElaboratedType>(
tParQualType.getTypePtr());
3646 tParQualType = clang::QualType(etype->getNamedType().getTypePtr(),0);
3647 etype = llvm::dyn_cast<clang::ElaboratedType>(
tParQualType.getTypePtr());
3651 llvm::dyn_cast<TemplateSpecializationType>(
tParQualType.getTypePtr());
3657 = llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(
tArgQualType->getAsCXXRecordDecl());
3675 clang::Sema& S =
interp.getCI()->getSema();
3676 cling::Interpreter::PushTransactionRAII
clingRAII(
const_cast<cling::Interpreter*
>(&
interp));
3677 llvm::SmallVector<clang::TemplateArgument, 4>
canonArgs;
3690 newArg.getKind() != clang::TemplateArgument::Type) {
3692 "Template parameter substitution failed!");
3696 = llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(
newArg.getAsType()->getAsCXXRecordDecl());
3712 const clang::NamedDecl&
tPar)
3714 using namespace clang;
3719 if (!
nttpd.hasDefaultArgument())
3730 const int value =
tArg.getAsIntegral().getLimitedValue();
3743 using namespace clang;
3744 if (!
nDecl)
return false;
3746 return ttpd->hasDefaultArgument();
3748 return nttpd->hasDefaultArgument();
3755 const cling::Interpreter&
interp,
3760 const clang::TemplateArgument &
tArg,
3761 const cling::Interpreter&
interp,
3763 const clang::ASTContext&
astCtxt)
3766 using namespace clang;
3773 if (
tArg.getKind() == clang::TemplateArgument::Type) {
3782 }
else if (
normTArg.getKind() == clang::TemplateArgument::Pack) {
3783 assert(
tArg.getKind() == clang::TemplateArgument::Pack );
3811 const cling::Interpreter&
interp,
3815 using namespace clang;
3824 const int nArgsToKeep =
normCtxt.GetNargsToKeep(
ctd);
3834 if (llvm::isa<clang::PointerType>(
normalizedType.getTypePtr())) {
3847 if (llvm::isa<clang::ReferenceType>(
normalizedType.getTypePtr())) {
3866 clang::NestedNameSpecifier* prefix =
nullptr;
3868 const clang::ElaboratedType* etype
3869 = llvm::dyn_cast<clang::ElaboratedType>(
normalizedType.getTypePtr());
3875 normalizedType = clang::QualType(etype->getNamedType().getTypePtr(),0);
3883 clang::TemplateParameterList*
tpl =
rd->getTemplateParameters();
3884 if (
tpl->getMinRequiredArguments () <
tpl->size()) {
3891 Error(
"KeepNParams",
"Not found template default arguments\n");
3908 llvm::dyn_cast<TemplateSpecializationType>(
normalizedType.getTypePtr());
3914 const clang::ClassTemplateSpecializationDecl*
TSTdecl
3915 = llvm::dyn_cast_or_null<const clang::ClassTemplateSpecializationDecl>(
normalizedType.getTypePtr()->getAsCXXRecordDecl());
3923 llvm::SmallVector<TemplateArgument, 4>
argsToKeep;
3935 Error(
"KeepNParams",
"The parameter number %s is null.\n",
formal);
3957 if (
tParPtr->isTemplateParameterPack() ) {
3987 if (
argKind == clang::TemplateArgument::Type){
3990 }
else if (
argKind == clang::TemplateArgument::Integral){
4038 cling::Interpreter::PushTransactionRAII
RAII(
const_cast<cling::Interpreter*
>(&
interpreter));
4061 if (
type.isNull()) {
4069 clang::PrintingPolicy
policy(
ctxt.getPrintingPolicy());
4070 policy.SuppressTagKeyword =
true;
4071 policy.SuppressScope =
true;
4072 policy.AnonymousTagLocations =
false;
4080 cling::Interpreter::PushTransactionRAII
clingRAII(
const_cast<cling::Interpreter*
>(&
interpreter));
4105 clang::ASTContext&
astCtxt =
sema.getASTContext();
4115std::pair<std::string,clang::QualType>
4136 cling::LookupHelper::DiagSetting::NoDiagnostics,
4155 "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());
4183 llvm::errs() << llvm::StringRef(
commentStart, 80) <<
'\n';
4232 if (
const clang::FunctionDecl*
FD = clang::dyn_cast<clang::FunctionDecl>(&
decl)) {
4233 if (
FD->isImplicit()) {
4237 if (
FD->isExplicitlyDefaulted() ||
FD->isDeletedAsWritten()) {
4241 }
else if (
FD->doesThisDeclarationHaveABody()) {
4246 &&
"Expected macro or end of body at '}'");
4258 }
else if (
const clang::EnumConstantDecl*
ECD
4259 = clang::dyn_cast<clang::EnumConstantDecl>(&
decl)) {
4261 if (
ECD->getNextDeclInContext())
4338 if (!
decl)
return false;
4345 static const std::vector<std::string>
signatures =
4346 {
"ClassDef",
"ClassDefOverride",
"ClassDefNV",
"ClassDefInline",
"ClassDefInlineOverride",
"ClassDefInlineNV" };
4363 clang::SourceLocation *
loc,
4366 using namespace clang;
4369 =
interpreter.getLookupHelper().findFunctionProto(&
decl,
"DeclFileLine",
"",
4370 cling::LookupHelper::NoDiagnostics);
4376 if (comment.size()) {
4383 return llvm::StringRef();
4395 if (
rawtype->isElaboratedTypeSpecifier() ) {
4399 rawtype =
type.getTypePtr()->getBaseElementTypeUnsafe ();
4408 if (
rawtype->isElaboratedTypeSpecifier() ) {
4428 if (
ctxt.isNamespace() ||
ctxt.isTranslationUnit())
4430 else if(
const auto parentdecl = llvm::dyn_cast<clang::CXXRecordDecl>(&
ctxt))
4443 const clang::DeclContext *
ctxt =
decl.getDeclContext();
4444 switch (
decl.getAccess()) {
4445 case clang::AS_public:
4447 case clang::AS_protected:
4449 case clang::AS_private:
4451 case clang::AS_none:
4455 assert(
false &&
"Unexpected value for the access property value in Clang");
4465 return cling::utils::Analyze::IsStdClass(cl);
4475 if (cling::utils::Analyze::IsStdClass(cl)) {
4476 static const char *names[] =
4477 {
"shared_ptr",
"__shared_ptr",
4478 "vector",
"list",
"deque",
"map",
"multimap",
"set",
"multiset",
"bitset"};
4479 llvm::StringRef
clname(cl.getName());
4480 for(
auto &&
name : names) {
4518 const clang::CXXRecordDecl *
thisDecl =
4519 llvm::dyn_cast_or_null<clang::CXXRecordDecl>(
lh.findScope(
typ, cling::LookupHelper::WithDiagnostics));
4523 Error(
"IsOfType",
"Record decl of type %s not found in the AST.",
typ.c_str());
4553 if (!IsStdClass(cl)) {
4554 auto *
nsDecl = llvm::dyn_cast<clang::NamespaceDecl>(cl.getDeclContext());
4555 if (cl.getName() !=
"RVec" ||
nsDecl ==
nullptr ||
nsDecl->getName() !=
"VecOps")
4558 auto *
parentNsDecl = llvm::dyn_cast<clang::NamespaceDecl>(cl.getDeclContext()->getParent());
4563 return STLKind(cl.getName());
4567 using namespace clang;
4568 struct SearchTypedef:
public TypeVisitor<SearchTypedef, bool> {
4573 return Visit(
AT->getElementType().getTypePtr());
4576 return Visit(
DT->getUnderlyingType().getTypePtr());
4579 return Visit(
PT->getPointeeType().getTypePtr());
4582 return Visit(
RT->getPointeeType().getTypePtr());
4585 return Visit(
STST->getReplacementType().getTypePtr());
4589 if (
TA.getKind() == TemplateArgument::Type && Visit(
TA.getAsType().getTypePtr()))
4598 return TOT->getUnmodifiedType().getTypePtr();
4603 if (
NNS->getKind() == NestedNameSpecifier::TypeSpec) {
4604 if (Visit(
NNS->getAsType()))
4609 return Visit(
ET->getNamedType().getTypePtr());
4630 using namespace llvm;
4631 using namespace clang;
4632 const clang::ASTContext &
Ctxt =
instance->getAsCXXRecordDecl()->getASTContext();
4635 const clang::ElaboratedType* etype
4636 = llvm::dyn_cast<clang::ElaboratedType>(
input.getTypePtr());
4641 assert(
instance->getAsCXXRecordDecl() !=
nullptr &&
"ReSubstTemplateArg only makes sense with a type representing a class.");
4661 if (
nQT ==
QT->getPointeeType())
return QT;
4677 if (
nQT ==
QT->getPointeeType())
return QT;
4698 if (
newQT ==
arr->getElementType())
return QT;
4702 arr->getSizeModifier(),
4703 arr->getIndexTypeCVRQualifiers());
4711 arr->getSizeModifier(),
4712 arr->getIndexTypeCVRQualifiers(),
4713 arr->getBracketsRange());
4718 if (
newQT ==
arr->getElementType())
return QT;
4720 arr->getSizeModifier(),
4721 arr->getIndexTypeCVRQualifiers());
4726 if (
newQT ==
arr->getElementType())
return QT;
4729 arr->getSizeModifier(),
4730 arr->getIndexTypeCVRQualifiers(),
4731 arr->getBracketsRange());
4740 etype = llvm::dyn_cast<clang::ElaboratedType>(
instance);
4742 instance = etype->getNamedType().getTypePtr();
4746 const clang::TemplateSpecializationType*
TST
4747 = llvm::dyn_cast<const clang::TemplateSpecializationType>(
instance);
4751 const clang::ClassTemplateSpecializationDecl*
TSTdecl
4752 = llvm::dyn_cast_or_null<const clang::ClassTemplateSpecializationDecl>(
instance->getAsCXXRecordDecl());
4756 const clang::SubstTemplateTypeParmType *
substType
4757 = llvm::dyn_cast<clang::SubstTemplateTypeParmType>(
input.getTypePtr());
4761 const clang::ClassTemplateDecl *
replacedCtxt =
nullptr;
4765 unsigned int index =
substType->getReplacedParameter()->getIndex();
4768 if (
decl->getKind() == clang::Decl::ClassTemplatePartialSpecialization) {
4769 const clang::ClassTemplatePartialSpecializationDecl *
spec = llvm::dyn_cast<clang::ClassTemplatePartialSpecializationDecl>(
decl);
4771 unsigned int depth =
substType->getReplacedParameter()->getDepth();
4787 const clang::SubstTemplateTypeParmType *
argType
4788 = llvm::dyn_cast<clang::SubstTemplateTypeParmType>(
argQualType);
4813 llvm::raw_string_ostream ostream(
astDump);
4816 ROOT::TMetaUtils::Warning(
"ReSubstTemplateArg",
"Unexpected type of declaration context for template parameter: %s.\n\tThe responsible class is:\n\t%s\n",
4823 const auto &
TAs =
TST->template_arguments();
4840 const clang::TemplateSpecializationType*
inputTST
4841 = llvm::dyn_cast<const clang::TemplateSpecializationType>(
input.getTypePtr());
4846 llvm::SmallVector<clang::TemplateArgument, 4>
desArgs;
4847 for (
const clang::TemplateArgument &
TA :
inputTST->template_arguments()) {
4848 if (
TA.getKind() != clang::TemplateArgument::Type) {
4853 clang::QualType
SubTy =
TA.getAsType();
4855 if (llvm::isa<clang::ElaboratedType>(
SubTy)
4856 || llvm::isa<clang::SubstTemplateTypeParmType>(
SubTy)
4857 || llvm::isa<clang::TemplateSpecializationType>(
SubTy)) {
4872 inputTST->getCanonicalTypeInternal());
4913 static const char *
stls[] =
4914 {
"any",
"vector",
"list",
"deque",
"map",
"multimap",
"set",
"multiset",
"bitset",
4915 "forward_list",
"unordered_set",
"unordered_multiset",
"unordered_map",
"unordered_multimap",
"RVec",
nullptr};
4929 for(
int k=1;
stls[k];k++) {
if (
type.equals(
stls[k]))
return values[k];}
4940 TND =
TND->getMostRecentDecl();
4941 while (
TND && !(
TND->hasAttrs()))
4942 TND =
TND->getPreviousDecl();
4954 TD =
TD->getMostRecentDecl();
4955 while (
TD && !(
TD->hasAttrs() &&
TD->isThisDeclarationADefinition()))
4956 TD =
TD->getPreviousDecl();
5012 std::list<std::pair<std::string,unsigned int> >&
enclosingSc)
5040 std::string::size_type
beginVar = 0;
5041 std::string::size_type
endVar = 0;
5045 std::string::size_type
endVarName = std::string::npos;
5115 str.replace(
start_pos, from.length(), to);
5182 return llvm::sys::path::extension(
filename) ==
".h" ||
5183 llvm::sys::path::extension(
filename) ==
".hh" ||
5184 llvm::sys::path::extension(
filename) ==
".hpp" ||
5185 llvm::sys::path::extension(
filename) ==
".H" ||
5186 llvm::sys::path::extension(
filename) ==
".h++" ||
5187 llvm::sys::path::extension(
filename) ==
"hxx" ||
5188 llvm::sys::path::extension(
filename) ==
"Hxx" ||
5189 llvm::sys::path::extension(
filename) ==
"HXX";
5195 cling::Interpreter::IgnoreFilesFunc_t
ignoreFiles,
5196 const cling::Interpreter &
interp,
5204 clang::Decl *
ncDecl =
const_cast<clang::Decl *
>(
decl);
5249 static const std::string
scopeType [] = {
"namespace ",
"inline namespace ",
"class "};
5291 std::string typeName;
5294 if (llvm::isa<clang::TemplateTypeParmDecl>(
nDecl)){
5295 typeName =
"typename ";
5296 if (
nDecl->isParameterPack())
5298 typeName += (*prmIt)->getNameAsString();
5301 else if (
auto nttpd = llvm::dyn_cast<clang::NonTypeTemplateParmDecl>(
nDecl)){
5305 if (
theType.getAsString().find(
"enum") != std::string::npos){
5307 llvm::raw_string_ostream ostream(
astDump);
5308 nttpd->dump(ostream);
5319 else if (
auto ttpd = llvm::dyn_cast<clang::TemplateTemplateParmDecl>(
nDecl)){
5323 llvm::raw_string_ostream ostream(
astDump);
5324 ttpd->dump(ostream);
5349 "Cannot extract template parameter list for %s",
5357 "Problems with arguments for forward declaration of class %s\n",
5367 if (llvm::isa<clang::TemplateTemplateParmDecl>(&
templDecl)) {
5389 if (clang::TemplateArgument::Type != arg.getKind())
return 0;
5404 if (llvm::isa<clang::BuiltinType>(
argTypePtr)){
5437 if (
specDef->getTemplateSpecializationKind() != clang::TSK_ExplicitSpecialization)
5441 std::cout <<
" Forward declaring template spec " <<
normalizedName <<
":\n";
5446 std::cout <<
" o Template argument ";
5448 std::cout <<
"successfully treated. Arg fwd decl: " <<
argFwdDecl << std::endl;
5450 std::cout <<
"could not be treated. Abort fwd declaration generation.\n";
5491 std::cout <<
"Class " <<
recordDecl.getNameAsString()
5492 <<
" is a template specialisation. Treating its arguments.\n";
5496 std::cout <<
" o Template argument ";
5498 std::cout <<
"successfully treated. Arg fwd decl: " <<
argFwdDecl << std::endl;
5500 std::cout <<
"could not be treated. Abort fwd declaration generation.\n";
5548 std::string buffer =
tdnDecl.getNameAsString();
5551 if (
const clang::TagType* TT
5553 if (clang::NamedDecl*
ND = TT->getDecl()) {
5554 if (!
ND->getIdentifier()) {
5598 std::cout <<
"Typedef " <<
tdnDecl.getNameAsString() <<
" hides a class: "
5625 const clang::PrintingPolicy&
ppolicy)
5628 auto&
ctxt = par.getASTContext();
5649 if (
result.isNegative()){
The file contains utilities which are foundational and could be used across the core component of ROO...
#define R(a, b, c, d, e, f, g, h, i)
static Roo_reg_AGKInteg1D instance
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
static void indent(ostringstream &buf, int indent_level)
static bool RecurseKeepNParams(clang::TemplateArgument &normTArg, const clang::TemplateArgument &tArg, const cling::Interpreter &interp, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt, const clang::ASTContext &astCtxt)
static clang::SourceLocation getFinalSpellingLoc(clang::SourceManager &sourceManager, clang::SourceLocation sourceLoc)
const clang::DeclContext * GetEnclosingSpace(const clang::RecordDecl &cl)
bool IsTemplate(const clang::Decl &cl)
static void KeepNParams(clang::QualType &normalizedType, const clang::QualType &vanillaType, const cling::Interpreter &interp, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt)
This function allows to manipulate the number of arguments in the type of a template specialisation.
static void CreateNameTypeMap(const clang::CXXRecordDecl &cl, ROOT::MembersTypeMap_t &nameType)
Create the data member name-type map for given class.
const clang::CXXMethodDecl * GetMethodWithProto(const clang::Decl *cinfo, const char *method, const char *proto, const cling::Interpreter &interp, bool diagnose)
int dumpDeclForAssert(const clang::Decl &D, const char *commentStart)
static void replaceEnvVars(const char *varname, std::string &txt)
Reimplementation of TSystem::ExpandPathName() that cannot be used from TMetaUtils.
static bool areEqualValues(const clang::TemplateArgument &tArg, const clang::NamedDecl &tPar)
std::cout << "Are equal values?\n";
static bool isTypeWithDefault(const clang::NamedDecl *nDecl)
Check if this NamedDecl is a template parameter with a default argument.
static int TreatSingleTemplateArg(const clang::TemplateArgument &arg, std::string &argFwdDecl, const cling::Interpreter &interpreter, bool acceptStl=false)
static bool areEqualTypes(const clang::TemplateArgument &tArg, llvm::SmallVectorImpl< clang::TemplateArgument > &preceedingTArgs, const clang::NamedDecl &tPar, const cling::Interpreter &interp, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt)
static bool hasSomeTypedefSomewhere(const clang::Type *T)
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void input
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t dest
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t 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
const std::string & GetPathSeparator()
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
void WriteSchemaList(std::list< SchemaRuleMap_t > &rules, const std::string &listName, std::ostream &output)
Write schema rules.
std::map< std::string, ROOT::Internal::TSchemaType > MembersTypeMap_t
void WriteReadRuleFunc(SchemaRuleMap_t &rule, int index, std::string &mappedName, MembersTypeMap_t &members, std::ostream &output)
Write the conversion function for Read rule, the function name is being written to rule["funcname"].
R__EXTERN SchemaRuleClassMap_t gReadRules
bool HasValidDataMembers(SchemaRuleMap_t &rule, MembersTypeMap_t &members, std::string &error_string)
Check if given rule contains references to valid data members.
void WriteReadRawRuleFunc(SchemaRuleMap_t &rule, int index, std::string &mappedName, MembersTypeMap_t &members, std::ostream &output)
Write the conversion function for ReadRaw rule, the function name is being written to rule["funcname"...
R__EXTERN SchemaRuleClassMap_t gReadRawRules
ROOT::ESTLType STLKind(std::string_view type)
Converts STL container name to number.
bool IsStdClass(const char *type)
return true if the class belongs to the std namespace
std::string GetLong64_Name(const char *original)
Replace 'long long' and 'unsigned long long' by 'Long64_t' and 'ULong64_t'.
ROOT::ESTLType IsSTLCont(std::string_view type)
type : type name: vector<list<classA,allocator>,allocator> result: 0 : not stl container code of cont...
char * DemangleName(const char *mangled_name, int &errorCode)
std::string GetNameForIO(const std::string &templateInstanceName, TClassEdit::EModType mode=TClassEdit::kNone, bool *hasChanged=nullptr)
bool IsSTLBitset(const char *type)
Return true is the name is std::bitset<number> or bitset<number>
constexpr Double_t C()
Velocity of light in .