24#include <unordered_set>
27#include "RConfigure.h"
35#include "clang/AST/ASTContext.h"
36#include "clang/AST/Attr.h"
37#include "clang/AST/CXXInheritance.h"
38#include "clang/AST/Decl.h"
39#include "clang/AST/DeclTemplate.h"
40#include "clang/AST/Mangle.h"
41#include "clang/AST/Type.h"
42#include "clang/AST/TypeVisitor.h"
43#include "clang/Frontend/CompilerInstance.h"
44#include "clang/Lex/HeaderSearch.h"
45#include "clang/Lex/ModuleMap.h"
46#include "clang/Lex/Preprocessor.h"
47#include "clang/Lex/PreprocessorOptions.h"
49#include "clang/Sema/Lookup.h"
50#include "clang/Sema/Sema.h"
51#include "clang/Sema/SemaDiagnostic.h"
53#include "cling/Interpreter/LookupHelper.h"
54#include "cling/Interpreter/Transaction.h"
55#include "cling/Interpreter/Interpreter.h"
56#include "cling/Utils/AST.h"
58#include "llvm/Support/Path.h"
59#include "llvm/Support/FileSystem.h"
64#define strncasecmp _strnicmp
84 using DeclsCont_t = TNormalizedCtxt::Config_t::SkipCollection;
101 bool replace =
false);
112 clang::NestedNameSpecifier*
scope,
115 if (!
scope)
return nullptr;
138static bool CheckDefinition(
const clang::CXXRecordDecl *cl,
const clang::CXXRecordDecl *context)
140 if (!cl->hasDefinition()) {
143 "Missing definition for class %s, please #include its header in the header of %s\n",
144 cl->getName().str().c_str(), context->getName().str().c_str());
147 "Missing definition for class %s\n",
148 cl->getName().str().c_str());
161 clang::NestedNameSpecifier *
scope,
164 if (!
scope)
return nullptr;
186 const clang::BuiltinType *
builtin = llvm::dyn_cast<clang::BuiltinType>(
type->getCanonicalTypeInternal().getTypePtr());
206 clang::ASTContext &
C = cl.getASTContext();
207 clang::DeclarationName
DName = &
C.Idents.get(
what);
208 auto R = cl.lookup(
DName);
209 for (
const clang::NamedDecl *D :
R)
221 clang::LookupResult
R(
SemaR,
DName, clang::SourceLocation(),
222 clang::Sema::LookupOrdinaryName,
223 clang::Sema::ForExternalRedeclaration);
224 SemaR.LookupInSuper(
R, &
const_cast<clang::CXXRecordDecl&
>(cl));
227 return llvm::dyn_cast<const clang::FieldDecl>(
R.getFoundDecl());
233 ? cling::LookupHelper::WithDiagnostics
234 : cling::LookupHelper::NoDiagnostics;
241namespace TMetaUtils {
250 Error(
"TNormalizedCtxt::AddTemplAndNargsToKeep",
251 "Tring to specify a number of template arguments to keep for a null pointer. Exiting without assigning any value.\n");
255 const clang::ClassTemplateDecl*
canTempl =
templ->getCanonicalDecl();
260 const std::string
i_str (std::to_string(i));
262 Error(
"TNormalizedCtxt::AddTemplAndNargsToKeep",
263 "Tring to specify for template %s %s arguments to keep, while before this number was %s\n",
264 canTempl->getNameAsString().c_str(),
277 const clang::ClassTemplateDecl*
constTempl =
templ->getCanonicalDecl();
328 std::unique_ptr<clang::MangleContext>
mangleCtx(
rDecl->getASTContext().createMangleContext());
332 if (
const clang::TypeDecl*
TD = llvm::dyn_cast<clang::TypeDecl>(
rDecl)) {
333 mangleCtx->mangleCXXRTTI(clang::QualType(
TD->getTypeForDecl(), 0),
sstr);
359 "Demangled typeinfo name '%s' does not contain `RTTI Type Descriptor'\n",
363 "Demangled typeinfo name '%s' does not start with 'typeinfo for'\n",
380 const clang::RecordDecl *
decl,
409 const clang::RecordDecl *
decl,
438 "Could not remove the requested template arguments.\n");
449 const clang::RecordDecl *
decl,
483 const clang::RecordDecl *
decl,
545 if (
tname.empty())
return false;
559 if (!
dest.isNull() && (
dest != t)) {
576 if (!
dest.isNull() && (
dest != t) &&
595 const clang::NamespaceDecl *
nsdecl = llvm::dyn_cast<clang::NamespaceDecl>(
scope);
608 if (
tname.empty())
return false;
637 clang::PrintingPolicy
policy(
fInterpreter->getCI()->getASTContext().getPrintingPolicy());
638 policy.SuppressTagKeyword =
true;
639 policy.SuppressScope =
true;
654 for(
unsigned int i = 1; i<
result.length(); ++i) {
666 }
else if ( (i+1) <
result.length() &&
704 clang::QualType
toSkip =
lh.findType(
name, cling::LookupHelper::WithDiagnostics);
705 if (
const clang::Type* T =
toSkip.getTypePtr()) {
706 const clang::TypedefType *
tt = llvm::dyn_cast<clang::TypedefType>(T);
708 clang::Decl* D =
tt->getDecl();
709 fConfig.m_toSkip.insert(D);
711 clang::QualType
canon =
toSkip->getCanonicalTypeInternal();
712 fConfig.m_toReplace.insert(std::make_pair(
canon.getTypePtr(),T));
714 fTypeWithAlternative.insert(T);
727 keepTypedef(
lh,
"Double32_t");
728 keepTypedef(
lh,
"Float16_t");
729 keepTypedef(
lh,
"Long64_t",
true);
730 keepTypedef(
lh,
"ULong64_t",
true);
732 clang::QualType
toSkip =
lh.findType(
"string", cling::LookupHelper::WithDiagnostics);
734 if (
const clang::TypedefType* TT
735 = llvm::dyn_cast_or_null<clang::TypedefType>(
toSkip.getTypePtr()))
736 fConfig.m_toSkip.insert(TT->getDecl());
738 toSkip =
lh.findType(
"std::string", cling::LookupHelper::WithDiagnostics);
740 if (
const clang::TypedefType* TT
741 = llvm::dyn_cast_or_null<clang::TypedefType>(
toSkip.getTypePtr()))
742 fConfig.m_toSkip.insert(TT->getDecl());
744 clang::QualType
canon =
toSkip->getCanonicalTypeInternal();
745 fConfig.m_toReplace.insert(std::make_pair(
canon.getTypePtr(),
toSkip.getTypePtr()));
756 return (cl.getKind() == clang::Decl::ClassTemplatePartialSpecialization
757 || cl.getKind() == clang::Decl::ClassTemplateSpecialization);
764 const cling::Interpreter&
interp)
766 clang::Sema* S = &
interp.getSema();
767 const clang::NamedDecl*
ND = cling::utils::Lookup::Named(S,
name, cl);
768 if (
ND == (clang::NamedDecl*)-1)
769 return (clang::FunctionDecl*)-1;
770 return llvm::dyn_cast_or_null<clang::FunctionDecl>(
ND);
776const clang::CXXRecordDecl *
780 const cling::LookupHelper&
lh =
interp.getLookupHelper();
783 const clang::CXXRecordDecl *
result
784 = llvm::dyn_cast_or_null<clang::CXXRecordDecl>
791 result = llvm::dyn_cast_or_null<clang::CXXRecordDecl>
802 clang::QualType
qType(cl->getTypeForDecl(),0);
810 clang::Sema& S =
interp.getCI()->getSema();
813 cling::Interpreter::PushTransactionRAII
RAII(
const_cast<cling::Interpreter*
>(&
interp));
814 return S.RequireCompleteType(
Loc, Type, clang::diag::err_incomplete_type);
820 const clang::CXXRecordDecl *context,
const cling::Interpreter &
interp)
826 if (!cl->getDefinition() || !cl->isCompleteDefinition()) {
834 if (!base->hasDefinition()) {
838 return cl->isDerivedFrom(base);
850 const clang::NamedDecl *base
854 return IsBase(
CRD, llvm::dyn_cast<clang::CXXRecordDecl>( base ),
855 llvm::dyn_cast<clang::CXXRecordDecl>(
m.getDeclContext()),
interp);
864 const clang::QualType &
qti,
866 const cling::Interpreter &
interp,
874 kBIT_ISSTRING = 0x40000000,
881 const clang::Type &
ti( *
qti.getTypePtr() );
904 if (
tiName ==
"string")
kase |= kBIT_ISSTRING;
905 if (
tiName ==
"string*")
kase |= kBIT_ISSTRING;
909 tcl =
" internal error in rootcling ";
934 <<
" R__b >> readtemp;" << std::endl
935 <<
" " <<
R__t <<
" = static_cast<" <<
tiName <<
">(readtemp);" << std::endl;
947 finalString <<
" if (R__b.GetInfo() && R__b.GetInfo()->GetOldVersion()<=3) {" << std::endl;
949 finalString <<
" R__ASSERT(0);// " <<
objType <<
" is abstract. We assume that older file could not be produced using this streaming method." << std::endl;
952 <<
" " <<
R__t <<
"->Streamer(R__b);" << std::endl;
955 <<
" " <<
R__t <<
" = (" <<
tiName <<
")R__b.ReadObjectAny(" <<
tcl <<
");" << std::endl
956 <<
" }" << std::endl;
962 <<
" R__str.Streamer(R__b);" << std::endl
963 <<
" " <<
R__t <<
" = R__str.Data();}" << std::endl;
969 <<
" R__str.Streamer(R__b);" << std::endl
970 <<
" " <<
R__t <<
" = new string(R__str.Data());}" << std::endl;
997 finalString <<
" R__b >> *reinterpret_cast<Int_t*>(ptr_enum); }" << std::endl;
1002 if (!
R__t)
return 0;
1007 if (!
R__t)
return 1;
1012 if (!
R__t)
return 0;
1013 finalString <<
" {TString R__str(" <<
R__t <<
".c_str());" << std::endl
1014 <<
" R__str.Streamer(R__b);};" << std::endl;
1018 if (!
R__t)
return 0;
1019 finalString <<
" {TString R__str(" <<
R__t <<
"->c_str());" << std::endl
1020 <<
" R__str.Streamer(R__b);}" << std::endl;
1024 if (!
R__t)
return 1;
1029 if (!
R__t)
return 1;
1042 clang::CXXRecordDecl*
ncCl =
const_cast<clang::CXXRecordDecl*
>(cl);
1045 cling::Interpreter::PushTransactionRAII
clingRAII(
const_cast<cling::Interpreter*
>(&
interpreter));
1048 if (
Ctor->getAccess() == clang::AS_public && !
Ctor->isDeleted()) {
1066 const cling::LookupHelper&
lh =
interpreter.getLookupHelper();
1075 return EIOCtorCategory::kAbsent;
1078 cling::Interpreter::PushTransactionRAII
clingRAII(
const_cast<cling::Interpreter*
>(&
interpreter));
1079 for (
auto iter = cl->ctor_begin(), end = cl->ctor_end(); iter != end; ++iter)
1081 if ((iter->getAccess() != clang::AS_public) || (iter->getNumParams() != 1))
1085 clang::QualType
argType((*iter->param_begin())->getType());
1089 if (
argType->isPointerType()) {
1092 }
else if (
argType->isReferenceType()) {
1099 const clang::CXXRecordDecl *
argDecl =
argType->getAsCXXRecordDecl();
1106 std::string
clarg(
"class ");
1113 return EIOCtorCategory::kAbsent;
1126 if (!
ioctortype.GetType() && (!arg || !arg[0])) {
1140 const cling::Interpreter &
interp,
1143 const clang::FunctionDecl*
funcD
1145 diagnose ? cling::LookupHelper::WithDiagnostics
1146 : cling::LookupHelper::NoDiagnostics);
1148 return llvm::dyn_cast<const clang::CXXMethodDecl>(
funcD);
1157 namespace TMetaUtils {
1160 const cling::LookupHelper&
lh =
interp.getLookupHelper();
1179 const cling::Interpreter &
interp)
1181 if (cl->isAbstract())
return false;
1187 if (EIOCtorCategory::kAbsent ==
ioCtorCat)
1197 if (EIOCtorCategory::kIOPtrType ==
ioCtorCat) {
1199 }
else if (EIOCtorCategory::kIORefType ==
ioCtorCat) {
1203 arg +=
")nullptr )";
1206 const clang::CXXMethodDecl *
method
1208 cling::LookupHelper::NoDiagnostics);
1209 if (
method &&
method->getAccess() != clang::AS_public) {
1223 const cling::Interpreter&
interp)
1225 if (!cl)
return false;
1227 if (cl->hasUserDeclaredDestructor()) {
1229 cling::Interpreter::PushTransactionRAII
clingRAII(
const_cast<cling::Interpreter*
>(&
interp));
1230 clang::CXXDestructorDecl *
dest = cl->getDestructor();
1232 return (
dest->getAccess() == clang::AS_public);
1246 const cling::Interpreter &
interp,
1249 const clang::CXXMethodDecl *
method
1251 diagnose ? cling::LookupHelper::WithDiagnostics
1252 : cling::LookupHelper::NoDiagnostics);
1253 return (
method &&
method->getAccess() == clang::AS_public);
1264 const char *
proto =
"TDirectory*";
1265 const char *
name =
"DirectoryAutoAdd";
1279 const char *
proto =
"TCollection*,TFileMergeInfo*";
1280 const char *
name =
"Merge";
1293 const char *
proto =
"TCollection*";
1294 const char *
name =
"Merge";
1309 const char *
proto =
"TFileMergeInfo*";
1310 const char *
name =
"ResetAfterMerge";
1320 const clang::CXXRecordDecl*
clxx,
1321 const cling::Interpreter &
interp,
1324 static const char *
proto =
"TBuffer&";
1326 const clang::CXXMethodDecl *
method
1328 cling::LookupHelper::NoDiagnostics);
1339 const clang::CXXRecordDecl*
clxx,
1340 const cling::Interpreter &
interp,
1343 static const char *
proto =
"TBuffer&,TClass*";
1345 const clang::CXXMethodDecl *
method
1347 cling::LookupHelper::NoDiagnostics);
1412 llvm::raw_string_ostream stream(
qual_name);
1413 clang::PrintingPolicy
policy( cl.getASTContext().getPrintingPolicy() );
1414 policy.SuppressTagKeyword =
true;
1415 policy.SuppressUnwrittenScope =
true;
1417 cl.getNameForDiagnostic(stream,
policy,
true);
1473 std::stringstream
dims;
1476 const clang::ASTContext&
astContext = cl.getASTContext();
1479 for(clang::RecordDecl::field_iterator
field_iter = cl.field_begin(), end = cl.field_end();
1493 const clang::ConstantArrayType *
arrayType = llvm::dyn_cast<clang::ConstantArrayType>(
fieldType.getTypePtr());
1495 dims <<
"[" <<
arrayType->getSize().getLimitedValue() <<
"]";
1497 arrayType = llvm::dyn_cast<clang::ConstantArrayType>(
arrayType->getArrayElementTypeNoTypeQual());
1507 for(clang::CXXRecordDecl::base_class_const_iterator iter = cl.bases_begin(), end = cl.bases_end();
1510 std::string
basename( iter->getType()->getAsCXXRecordDecl()->getNameAsString() );
1520 const cling::Interpreter &
interp,
1524 diagnose ? cling::LookupHelper::WithDiagnostics
1525 : cling::LookupHelper::NoDiagnostics);
1584 while (llvm::isa<clang::PointerType>(
instanceType.getTypePtr())
1585 || llvm::isa<clang::ReferenceType>(
instanceType.getTypePtr()))
1590 const clang::ElaboratedType* etype
1591 = llvm::dyn_cast<clang::ElaboratedType>(
instanceType.getTypePtr());
1593 instanceType = clang::QualType(etype->getNamedType().getTypePtr(),0);
1607 if (
clxx &&
clxx->getTemplateSpecializationKind() != clang::TSK_Undeclared) {
1609 const clang::TemplateSpecializationType*
TST
1610 = llvm::dyn_cast<const clang::TemplateSpecializationType>(
instanceType.getTypePtr());
1617 for (
const clang::TemplateArgument &
TA :
TST->template_arguments()) {
1618 if (
TA.getKind() == clang::TemplateArgument::Type) {
1630 const cling::Interpreter &
interp,
1633 const clang::CXXRecordDecl *
clxx = llvm::dyn_cast<clang::CXXRecordDecl>(cl.
GetRecordDecl());
1634 if (!
clxx ||
clxx->getTemplateSpecializationKind() == clang::TSK_Undeclared)
return false;
1637 cling::LookupHelper::WithDiagnostics);
1651 clang::AnnotateAttr*
annAttr = clang::dyn_cast<clang::AnnotateAttr>(
attribute);
1694 for (clang::Decl::attr_iterator
attrIt =
decl.attr_begin();
1696 clang::AnnotateAttr*
annAttr = clang::dyn_cast<clang::AnnotateAttr>(*
attrIt);
1700 std::pair<llvm::StringRef,llvm::StringRef> split =
attribute.split(propNames::separator.c_str());
1701 if (split.first !=
propName.c_str())
continue;
1717 for (clang::Decl::attr_iterator
attrIt =
decl.attr_begin();
1719 clang::AnnotateAttr*
annAttr = clang::dyn_cast<clang::AnnotateAttr>(*
attrIt);
1723 std::pair<llvm::StringRef,llvm::StringRef> split =
attribute.split(propNames::separator.c_str());
1724 if (split.first !=
propName.c_str())
continue;
1726 return split.second.getAsInteger(10,
propValue);
1737 const clang::CXXRecordDecl *
decl,
1738 const cling::Interpreter &
interp,
1747 std::string
csymbol = classname;
1761 bool isStd = TMetaUtils::IsStdClass(*
decl);
1762 const cling::LookupHelper&
lh =
interp.getLookupHelper();
1772 <<
" static void " <<
mappedname.c_str() <<
"_TClassManip(TClass*);\n";
1790 finalString <<
" static void delete_" <<
mappedname.c_str() <<
"(void *p);" <<
"\n" <<
" static void deleteArray_" <<
mappedname.c_str() <<
"(void *p);" <<
"\n" <<
" static void destruct_" <<
mappedname.c_str() <<
"(void *p);" <<
"\n";
1793 finalString <<
" static void directoryAutoAdd_" <<
mappedname.c_str() <<
"(void *obj, TDirectory *dir);" <<
"\n";
1796 finalString <<
" static void streamer_" <<
mappedname.c_str() <<
"(TBuffer &buf, void *obj);" <<
"\n";
1799 finalString <<
" static void conv_streamer_" <<
mappedname.c_str() <<
"(TBuffer &buf, void *obj, const TClass*);" <<
"\n";
1802 finalString <<
" static Long64_t merge_" <<
mappedname.c_str() <<
"(void *obj, TCollection *coll,TFileMergeInfo *info);" <<
"\n";
1805 finalString <<
" static void reset_" <<
mappedname.c_str() <<
"(void *obj, TFileMergeInfo *info);" <<
"\n";
1824 finalString <<
"\n // Schema evolution read functions\n";
1825 std::list<ROOT::SchemaRuleMap_t>::iterator
rIt =
rulesIt1->second.fRules.
begin();
1843 if(
rIt->find(
"code" ) !=
rIt->
end() ) {
1859 finalString <<
"\n // Schema evolution read raw functions\n";
1860 std::list<ROOT::SchemaRuleMap_t>::iterator
rIt =
rulesIt2->second.fRules.
begin();
1886 finalString <<
"\n" <<
" // Function generating the singleton type initializer" <<
"\n";
1888 finalString <<
" static TGenericClassInfo *GenerateInitInstanceLocal(const " <<
csymbol <<
"*)" <<
"\n" <<
" {" <<
"\n";
1894 finalString <<
" static ::TVirtualIsAProxy* isa_proxy = new ::TInstrumentedIsAProxy< " <<
csymbol <<
" >(nullptr);" <<
"\n";
1897 finalString <<
" static ::TVirtualIsAProxy* isa_proxy = new ::TIsAProxy(typeid(" <<
csymbol <<
"));" <<
"\n";
1899 finalString <<
" static ::ROOT::TGenericClassInfo " <<
"\n" <<
" instance(\"" << classname.c_str() <<
"\", ";
1912 static const char *
versionFunc =
"GetClassVersion";
1916 std::string
proto = classname +
"*";
1917 const clang::Decl*
ctxt = llvm::dyn_cast<clang::Decl>((*cl).getDeclContext());
1920 interp, cling::LookupHelper::NoDiagnostics);
1939 for (
unsigned int i=0; i<
filename.length(); i++) {
1944 <<
"," <<
"\n" <<
" typeid(" <<
csymbol
1945 <<
"), ::ROOT::Internal::DefineBehavior(ptr, ptr)," <<
"\n" <<
" ";
1968 finalString <<
" instance.SetDelete(&delete_" <<
mappedname.c_str() <<
");" <<
"\n" <<
" instance.SetDeleteArray(&deleteArray_" <<
mappedname.c_str() <<
");" <<
"\n" <<
" instance.SetDestructor(&destruct_" <<
mappedname.c_str() <<
");" <<
"\n";
1971 finalString <<
" instance.SetDirectoryAutoAdd(&directoryAutoAdd_" <<
mappedname.c_str() <<
");" <<
"\n";
1979 finalString <<
" instance.SetConvStreamerFunc(&conv_streamer_" <<
mappedname.c_str() <<
");" <<
"\n";
1988 finalString <<
" instance.AdoptCollectionProxyInfo(TCollectionProxyInfo::Generate(TCollectionProxyInfo::" <<
"Pushback" <<
"<Internal::TStdBitsetHelper< " << classname.c_str() <<
" > >()));" <<
"\n";
1991 }
else if (
stl != 0 &&
1994 int idx = classname.find(
"<");
2023 finalString <<
" instance.AdoptCollectionProxyInfo(TCollectionProxyInfo::Generate(TCollectionProxyInfo::" <<
methodTCP <<
"< " <<
classNameForIO.c_str() <<
" >()));" <<
"\n";
2033 finalString <<
"\n" <<
" instance.AdoptAlternate(::ROOT::AddClassAlternate(\""
2040 finalString <<
"\n" <<
" instance.AdoptAlternate(::ROOT::AddClassAlternate(\""
2050 finalString <<
"\n" <<
" ::ROOT::Internal::TSchemaHelper* rule;" <<
"\n";
2054 finalString <<
"\n" <<
" // the io read rules" <<
"\n" <<
" std::vector<::ROOT::Internal::TSchemaHelper> readrules(" <<
rulesIt1->second.size() <<
");" <<
"\n";
2056 finalString <<
" instance.SetReadRules( readrules );" <<
"\n";
2057 rulesIt1->second.fGenerated =
true;
2061 finalString <<
"\n" <<
" // the io read raw rules" <<
"\n" <<
" std::vector<::ROOT::Internal::TSchemaHelper> readrawrules(" <<
rulesIt2->second.size() <<
");" <<
"\n";
2063 finalString <<
" instance.SetReadRawRules( readrawrules );" <<
"\n";
2064 rulesIt2->second.fGenerated =
true;
2067 finalString <<
" return &instance;" <<
"\n" <<
" }" <<
"\n";
2071 finalString <<
" TGenericClassInfo *GenerateInitInstance(const " <<
csymbol <<
"*)" <<
"\n" <<
" {\n return GenerateInitInstanceLocal(static_cast<" <<
csymbol <<
"*>(nullptr));\n }" <<
"\n";
2074 finalString <<
" // Static variable to force the class initialization" <<
"\n";
2078 finalString <<
" static ::ROOT::TGenericClassInfo *_R__UNIQUE_DICT_(Init) = GenerateInitInstanceLocal(static_cast<const " <<
csymbol <<
"*>(nullptr)); R__UseDummy(_R__UNIQUE_DICT_(Init));" <<
"\n";
2081 finalString <<
"\n" <<
" // Dictionary for non-ClassDef classes" <<
"\n"
2082 <<
" static TClass *" <<
mappedname <<
"_Dictionary() {\n"
2083 <<
" TClass* theClass ="
2084 <<
"::ROOT::GenerateInitInstanceLocal(static_cast<const " <<
csymbol <<
"*>(nullptr))->GetClass();\n"
2085 <<
" " <<
mappedname <<
"_TClassManip(theClass);\n";
2096 if (
decl->hasAttrs()){
2098 for (clang::Decl::attr_iterator
attrIt =
decl->attr_begin();
2115 manipString+=
" theClass->CreateAttributeMap();\n";
2116 manipString+=
" TDictAttributeMap* attrMap( theClass->GetAttributeMap() );\n";
2127 if (!(!(*internalDeclIt)->isImplicit()
2148 TMetaUtils::Error(
nullptr,
"Cannot convert field declaration to clang::NamedDecl");
2164 if (
attrName == propNames::comment ||
2166 attrName == propNames::ioname )
continue;
2191 finalString <<
"} // end of namespace ROOT" <<
"\n" <<
"\n";
2196 const cling::Interpreter &
interp)
2200 const clang::Type *
typeptr =
nullptr;
2201 const clang::CXXRecordDecl *
target =
2206 std::string
rule{
nRules > 1 ?
"rules" :
"rule"};
2207 std::string
verb{
nRules > 1 ?
"were" :
"was"};
2225 finalString <<
"\n // Schema evolution read functions\n";
2226 std::list<ROOT::SchemaRuleMap_t>::iterator
rIt =
rulesIt1.second.fRules.
begin();
2267 finalString <<
" // Registration Schema evolution read functions\n";
2271 <<
" ::ROOT::Internal::TSchemaHelper* rule;" <<
"\n";
2280 finalString <<
" std::vector<::ROOT::Internal::TSchemaHelper> readrules(" <<
rulesIt1->second.size()
2283 finalString <<
" TClass::RegisterReadRules(TSchemaRule::kReadRule, \"" <<
name
2284 <<
"\", std::move(readrules));\n";
2285 rulesIt1->second.fGenerated =
true;
2290 finalString <<
" std::vector<::ROOT::Internal::TSchemaHelper> readrawrules(" <<
rulesIt2->second.size()
2293 finalString <<
" TClass::RegisterReadRules(TSchemaRule::kReadRawRule, \"" <<
name
2294 <<
"\", std::move(readrawrules));\n";
2295 rulesIt2->second.fGenerated =
true;
2315 const clang::CXXRecordDecl *cl)
2325 auto ctxt = cl->getEnclosingNamespaceContext();
2330 const clang::NamedDecl *
namedCtxt = llvm::dyn_cast<clang::NamedDecl>(
ctxt);
2332 const clang::NamespaceDecl *
nsdecl = llvm::dyn_cast<clang::NamespaceDecl>(
namedCtxt);
2347 const clang::DeclContext *
ctxt = cl.getDeclContext();
2348 while(
ctxt && !
ctxt->isNamespace()) {
2369 const clang::NamespaceDecl *ns = llvm::dyn_cast<clang::NamespaceDecl>(
ctxt);
2375 out <<
"namespace " << ns->getNameAsString() <<
" {" << std::endl;
2394 clang::TemplateSpecializationKind kind = cl->getTemplateSpecializationKind();
2395 if (kind == clang::TSK_Undeclared ) {
2398 }
else if (kind == clang::TSK_ExplicitSpecialization) {
2413 const char *
proto =
"size_t";
2420 cling::LookupHelper::NoDiagnostics);
2424 cling::LookupHelper::NoDiagnostics);
2426 const clang::DeclContext *
ctxtnew =
nullptr;
2462 const clang::CXXRecordDecl*
clnew = llvm::dyn_cast<clang::CXXRecordDecl>(
ctxtnew);
2509 const clang::CXXRecordDecl *
decl,
2510 const cling::Interpreter &
interp,
2534 classname.insert(0,
"::");
2542 finalString <<
" // Wrappers around operator new" <<
"\n";
2543 finalString <<
" static void *new_" <<
mappedname.c_str() <<
"(void *p) {" <<
"\n" <<
" return p ? ";
2550 finalString <<
"::new(static_cast<::ROOT::Internal::TOperatorNewHelper*>(p)) ";
2555 finalString <<
"new " << classname.c_str() << args <<
";" <<
"\n";
2570 finalString <<
"::new(static_cast<::ROOT::Internal::TOperatorNewHelper*>(p)) ";
2584 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";
2588 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";
2592 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";
2596 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";
2600 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";
2602 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";
2606 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";
2608 finalString <<
"} // end of namespace ROOT for class " << classname.c_str() <<
"\n" <<
"\n";
2615 const cling::Interpreter &
interp,
2626 const clang::CXXRecordDecl *
clxx = llvm::dyn_cast<clang::CXXRecordDecl>(cl.
GetRecordDecl());
2630 for(clang::CXXRecordDecl::base_class_const_iterator iter =
clxx->bases_begin(), end =
clxx->bases_end();
2636 Internal::RStl::Instance().GenerateTClassFor( iter->getType(),
interp,
normCtxt);
2641 for(clang::RecordDecl::field_iterator
field_iter =
clxx->field_begin(), end =
clxx->field_end();
2673 const clang::Type *
rawtype =
m.getType()->getCanonicalTypeInternal().getTypePtr();
2689 const clang::CXXRecordDecl*
CRD = llvm::dyn_cast<clang::CXXRecordDecl>(cl);
2701 if (
funcCV == (clang::FunctionDecl*)-1)
return 1;
2716 using res_t = std::pair<bool, int>;
2718 const clang::CompoundStmt*
FuncBody
2719 = llvm::dyn_cast_or_null<clang::CompoundStmt>(
funcCV->getBody());
2721 return res_t{
false, -1};
2726 return res_t{
false, -1};
2728 const clang::ReturnStmt*
RetStmt
2729 = llvm::dyn_cast<clang::ReturnStmt>(
FuncBody->body_back());
2731 return res_t{
false, -1};
2743 return res_t{
false, -1};
2751 return TMetaUtils::IsSTLCont(*
annotated.GetRecordDecl());
2759 clang::QualType
type =
m.getType();
2762 if (
decl)
return TMetaUtils::IsSTLCont(*
decl);
2771 clang::QualType
type = base.getType();
2774 if (
decl)
return TMetaUtils::IsSTLCont(*
decl);
2784 const std::function<
void(
const clang::Module::Header &)> &
closure,
2797 const std::size_t
maxArrayLength = ((
sizeof module.Headers) / (sizeof *module.Headers));
2799 "'Headers' has changed it's size, we need to update publicHeaderIndex");
2804 llvm::SetVector<const clang::Module *>
modules;
2806 for (
size_t i = 0; i <
modules.size(); ++i) {
2807 const clang::Module *M =
modules[i];
2808 for (
const clang::Module *
subModule : M->submodules())
2812 for (
const clang::Module *
m :
modules) {
2814 for (clang::Module *
used :
m->DirectUses) {
2836 static char t[4096];
2837 static const char*
constwd =
"const ";
2846 if (
lev==0 && *s==
'*')
continue;
2852 if (
lev==0 && *s==
' ' && *(s+1)!=
'*') {
p = t;
continue;}
2853 if (
p - t > (
long)
sizeof(t)) {
2854 printf(
"ERROR (rootcling): type name too long for StortTypeName: %s\n",
2867 const cling::Interpreter&
interp)
2872 if (!comment.empty() && comment[0] ==
'!')
2875 clang::QualType
type =
m.getType();
2877 if (
type->isReferenceType()) {
2882 std::string
mTypeName =
type.getAsString(
m.getASTContext().getPrintingPolicy());
2894 const clang::Type *
rawtype =
type.getTypePtr()->getBaseElementTypeUnsafe ();
2896 if (
rawtype->isPointerType()) {
2910 const clang::CXXRecordDecl *
cxxdecl =
rawtype->getAsCXXRecordDecl();
2927 const clang::Type *
rawtype =
m.getType().getTypePtr();
2951 return rawtype->getAsCXXRecordDecl();
2960 const cling::Interpreter &
interp,
2966 const clang::CXXRecordDecl*
decl = llvm::dyn_cast<clang::CXXRecordDecl>(cl.
GetRecordDecl());
2968 if (!
decl || !
decl->isCompleteDefinition()) {
2972 std::string fullname;
2986 ROOT::TMetaUtils::Info(
nullptr,
"Class %s: Do not generate Streamer() [*** custom streamer ***]\n",fullname.c_str());
3011 const clang::ASTContext&
Ctx =
interpreter.getCI()->getASTContext();
3017 if (llvm::isa<clang::PointerType>(
instanceType.getTypePtr())) {
3031 if (llvm::isa<clang::ReferenceType>(
instanceType.getTypePtr())) {
3051 clang::NestedNameSpecifier *prefix =
nullptr;
3053 const clang::ElaboratedType* etype
3054 = llvm::dyn_cast<clang::ElaboratedType>(
instanceType.getTypePtr());
3059 instanceType = clang::QualType(etype->getNamedType().getTypePtr(),0);
3065 const clang::TemplateSpecializationType*
TST
3066 = llvm::dyn_cast<const clang::TemplateSpecializationType>(
instanceType.getTypePtr());
3068 const clang::ClassTemplateSpecializationDecl*
TSTdecl
3069 = llvm::dyn_cast_or_null<const clang::ClassTemplateSpecializationDecl>(
instanceType.getTypePtr()->getAsCXXRecordDecl());
3085 clang::TemplateDecl *Template =
TSTdecl->getSpecializedTemplate()->getMostRecentDecl();
3086 clang::TemplateParameterList *Params = Template->getTemplateParameters();
3093 llvm::SmallVector<clang::TemplateArgument, 4>
desArgs;
3094 llvm::SmallVector<clang::TemplateArgument, 4>
canonArgs;
3103 if (
I->getKind() == clang::TemplateArgument::Template) {
3110 clang::NamespaceDecl* ns = clang::dyn_cast<clang::NamespaceDecl>(
declCtxt);
3111 clang::NestedNameSpecifier*
nns;
3113 nns = cling::utils::TypeName::CreateNestedNameSpecifier(
Ctx, ns);
3114 }
else if (clang::TagDecl*
TD = llvm::dyn_cast<clang::TagDecl>(
declCtxt)) {
3115 nns = cling::utils::TypeName::CreateNestedNameSpecifier(
Ctx,
TD,
false );
3122 if (clang::UsingShadowDecl *
USD =
templateName.getAsUsingShadowDecl())
3132 if (
I->getKind() != clang::TemplateArgument::Type) {
3137 clang::QualType
SubTy =
I->getAsType();
3159 if (
templateArg.getKind() != clang::TemplateArgument::Type) {
3165 clang::SourceLocation
TemplateLoc = Template->getSourceRange ().getBegin();
3168 clang::TemplateTypeParmDecl *
TTP = llvm::dyn_cast<clang::TemplateTypeParmDecl>(*
Param);
3171 cling::Interpreter::PushTransactionRAII
clingRAII(
const_cast<cling::Interpreter*
>(&
interpreter));
3173 clang::TemplateArgumentLoc
ArgType = S.SubstDefaultTemplateArgumentIfAvailable(
3183 if (
ArgType.getArgument().isNull()
3184 ||
ArgType.getArgument().getKind() != clang::TemplateArgument::Type) {
3186 "Template parameter substitution failed for %s around %s\n",
3206 TST->getCanonicalTypeInternal());
3235 llvm::StringRef title;
3238 if (clang::AnnotateAttr *A =
m.getAttr<clang::AnnotateAttr>())
3239 title = A->getAnnotation();
3253 if (title.size() == 0 || (title[0] !=
'['))
return llvm::StringRef();
3255 if (
rightbracket == llvm::StringRef::npos)
return llvm::StringRef();
3274 char *current =
const_cast<char*
>(
working.c_str());
3280 for(i=0;i<
strlen(current);i++) {
3288 return llvm::StringRef();
3293 const clang::CXXRecordDecl *
parent_clxx = llvm::dyn_cast<clang::CXXRecordDecl>(
m.getDeclContext());
3294 const clang::FieldDecl *
index1 =
nullptr;
3307 if (
field_iter->getNameAsString() ==
m.getNameAsString() ) {
3315 return llvm::StringRef();
3327 return llvm::StringRef();
3352 return llvm::StringRef();
3354 if ( found && (
index1->getAccess() == clang::AS_private) ) {
3359 return llvm::StringRef();
3368 return llvm::StringRef();
3389 while((
c = in[i++])) {
3390 const char *
repl =
nullptr;
3392 case '+':
repl =
"pL";
break;
3393 case '-':
repl =
"mI";
break;
3394 case '*':
repl =
"mU";
break;
3395 case '/':
repl =
"dI";
break;
3396 case '&':
repl =
"aN";
break;
3397 case '%':
repl =
"pE";
break;
3398 case '|':
repl =
"oR";
break;
3399 case '^':
repl =
"hA";
break;
3400 case '>':
repl =
"gR";
break;
3401 case '<':
repl =
"lE";
break;
3402 case '=':
repl =
"eQ";
break;
3403 case '~':
repl =
"wA";
break;
3404 case '.':
repl =
"dO";
break;
3405 case '(':
repl =
"oP";
break;
3406 case ')':
repl =
"cP";
break;
3407 case '[':
repl =
"oB";
break;
3408 case ']':
repl =
"cB";
break;
3409 case '{':
repl =
"lB";
break;
3410 case '}':
repl =
"rB";
break;
3411 case ';':
repl =
"sC";
break;
3412 case '#':
repl =
"hS";
break;
3413 case '?':
repl =
"qM";
break;
3414 case '`':
repl =
"bT";
break;
3415 case '!':
repl =
"nO";
break;
3416 case ',':
repl =
"cO";
break;
3417 case '$':
repl =
"dA";
break;
3418 case ' ':
repl =
"sP";
break;
3419 case ':':
repl =
"cL";
break;
3420 case '"':
repl =
"dQ";
break;
3421 case '@':
repl =
"aT";
break;
3422 case '\'':
repl =
"sQ";
break;
3423 case '\':
repl =
"fI";
break;
3432 if (out.empty() ||
isdigit(out[0]))
3433 out.insert(out.begin(),
'_');
3436static clang::SourceLocation
3450 const cling::Interpreter&
interp)
3480 using namespace clang;
3505 ArrayRef<std::pair<OptionalFileEntryRef, DirectoryEntryRef>>(),
3520 assert(
decl.isFirstDecl() &&
"Couldn't trace back include from a decl"
3521 " that is not from an AST file");
3546 clang::OptionalFileEntryRef
FELong;
3548 for (llvm::sys::path::const_iterator
3561 &&
"Mismatched partitioning of file name!");
3565 ArrayRef<std::pair<OptionalFileEntryRef, DirectoryEntryRef>>(),
3577 for (llvm::sys::path::reverse_iterator
3585 &&
"Mismatched partitioning of file name!");
3591 ArrayRef<std::pair<OptionalFileEntryRef, DirectoryEntryRef>>(),
3594 nullptr,
nullptr ) ==
FELong) {
3605 const clang::QualType &
qtype,
3617 const clang::QualType &
qtype,
3623 cling::Interpreter::PushTransactionRAII
RAII(
const_cast<cling::Interpreter*
>(&
interpreter));
3635 clang::ClassTemplateDecl*&
ctd,
3636 clang::ClassTemplateSpecializationDecl*&
ctsd)
3638 using namespace clang;
3646 if (
theType->isPointerType()) {
3651 ctsd = llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(
rType->getDecl());
3653 ctd =
ctsd->getSpecializedTemplate();
3663 ctsd = llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(
qt->getAsCXXRecordDecl());
3665 ctd =
ctsd->getSpecializedTemplate();
3680 using namespace clang;
3696 using namespace clang;
3715 const clang::NamedDecl&
tPar,
3716 const cling::Interpreter&
interp,
3720 using namespace clang;
3725 if (!
ttpdPtr->hasDefaultArgument())
return false;
3747 const clang::ElaboratedType* etype
3748 = llvm::dyn_cast<clang::ElaboratedType>(
tParQualType.getTypePtr());
3750 tParQualType = clang::QualType(etype->getNamedType().getTypePtr(),0);
3751 etype = llvm::dyn_cast<clang::ElaboratedType>(
tParQualType.getTypePtr());
3755 llvm::dyn_cast<TemplateSpecializationType>(
tParQualType.getTypePtr());
3761 = llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(
tArgQualType->getAsCXXRecordDecl());
3779 clang::Sema& S =
interp.getCI()->getSema();
3780 cling::Interpreter::PushTransactionRAII
clingRAII(
const_cast<cling::Interpreter*
>(&
interp));
3781 llvm::SmallVector<clang::TemplateArgument, 4>
canonArgs;
3794 newArg.getKind() != clang::TemplateArgument::Type) {
3796 "Template parameter substitution failed!");
3800 = llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(
newArg.getAsType()->getAsCXXRecordDecl());
3816 const clang::NamedDecl&
tPar)
3818 using namespace clang;
3823 if (!
nttpd.hasDefaultArgument())
3834 const int value =
tArg.getAsIntegral().getLimitedValue();
3847 using namespace clang;
3848 if (!
nDecl)
return false;
3850 return ttpd->hasDefaultArgument();
3852 return nttpd->hasDefaultArgument();
3859 const cling::Interpreter&
interp,
3864 const clang::TemplateArgument &
tArg,
3865 const cling::Interpreter&
interp,
3867 const clang::ASTContext&
astCtxt)
3870 using namespace clang;
3877 if (
tArg.getKind() == clang::TemplateArgument::Type) {
3886 }
else if (
normTArg.getKind() == clang::TemplateArgument::Pack) {
3887 assert(
tArg.getKind() == clang::TemplateArgument::Pack );
3915 const cling::Interpreter&
interp,
3919 using namespace clang;
3928 const int nArgsToKeep =
normCtxt.GetNargsToKeep(
ctd);
3938 if (llvm::isa<clang::PointerType>(
normalizedType.getTypePtr())) {
3951 if (llvm::isa<clang::ReferenceType>(
normalizedType.getTypePtr())) {
3970 clang::NestedNameSpecifier* prefix =
nullptr;
3972 const clang::ElaboratedType* etype
3973 = llvm::dyn_cast<clang::ElaboratedType>(
normalizedType.getTypePtr());
3979 normalizedType = clang::QualType(etype->getNamedType().getTypePtr(),0);
3987 clang::TemplateParameterList*
tpl =
rd->getTemplateParameters();
3988 if (
tpl->getMinRequiredArguments () <
tpl->size()) {
3995 Error(
"KeepNParams",
"Not found template default arguments\n");
4012 llvm::dyn_cast<TemplateSpecializationType>(
normalizedType.getTypePtr());
4018 const clang::ClassTemplateSpecializationDecl*
TSTdecl
4019 = llvm::dyn_cast_or_null<const clang::ClassTemplateSpecializationDecl>(
normalizedType.getTypePtr()->getAsCXXRecordDecl());
4027 llvm::SmallVector<TemplateArgument, 4>
argsToKeep;
4039 Error(
"KeepNParams",
"The parameter number %s is null.\n",
formal);
4061 if (
tParPtr->isTemplateParameterPack() ) {
4091 if (
argKind == clang::TemplateArgument::Type){
4094 }
else if (
argKind == clang::TemplateArgument::Integral){
4142 cling::Interpreter::PushTransactionRAII
RAII(
const_cast<cling::Interpreter*
>(&
interpreter));
4165 if (
type.isNull()) {
4173 clang::PrintingPolicy
policy(
ctxt.getPrintingPolicy());
4174 policy.SuppressTagKeyword =
true;
4175 policy.SuppressScope =
true;
4176 policy.AnonymousTagLocations =
false;
4184 cling::Interpreter::PushTransactionRAII
clingRAII(
const_cast<cling::Interpreter*
>(&
interpreter));
4209 clang::ASTContext&
astCtxt =
sema.getASTContext();
4219std::pair<std::string,clang::QualType>
4240 cling::LookupHelper::DiagSetting::NoDiagnostics,
4259 "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());
4287 llvm::errs() << llvm::StringRef(
commentStart, 80) <<
'\n';
4336 if (
const clang::FunctionDecl*
FD = clang::dyn_cast<clang::FunctionDecl>(&
decl)) {
4337 if (
FD->isImplicit()) {
4341 if (
FD->isExplicitlyDefaulted() ||
FD->isDeletedAsWritten()) {
4345 }
else if (
FD->doesThisDeclarationHaveABody()) {
4350 &&
"Expected macro or end of body at '}'");
4362 }
else if (
const clang::EnumConstantDecl*
ECD
4363 = clang::dyn_cast<clang::EnumConstantDecl>(&
decl)) {
4365 if (
ECD->getNextDeclInContext())
4442 if (!
decl)
return false;
4449 static const std::vector<std::string>
signatures =
4450 {
"ClassDef",
"ClassDefOverride",
"ClassDefNV",
"ClassDefInline",
"ClassDefInlineOverride",
"ClassDefInlineNV" };
4467 clang::SourceLocation *
loc,
4470 using namespace clang;
4473 =
interpreter.getLookupHelper().findFunctionProto(&
decl,
"DeclFileLine",
"",
4474 cling::LookupHelper::NoDiagnostics);
4480 if (comment.size()) {
4487 return llvm::StringRef();
4499 if (
rawtype->isElaboratedTypeSpecifier() ) {
4503 rawtype =
type.getTypePtr()->getBaseElementTypeUnsafe ();
4512 if (
rawtype->isElaboratedTypeSpecifier() ) {
4532 if (
ctxt.isNamespace() ||
ctxt.isTranslationUnit())
4534 else if(
const auto parentdecl = llvm::dyn_cast<clang::CXXRecordDecl>(&
ctxt))
4547 const clang::DeclContext *
ctxt =
decl.getDeclContext();
4548 switch (
decl.getAccess()) {
4549 case clang::AS_public:
4551 case clang::AS_protected:
4553 case clang::AS_private:
4555 case clang::AS_none:
4559 assert(
false &&
"Unexpected value for the access property value in Clang");
4569 return cling::utils::Analyze::IsStdClass(cl);
4579 if (cling::utils::Analyze::IsStdClass(cl)) {
4580 static const char *names[] =
4581 {
"shared_ptr",
"__shared_ptr",
4582 "vector",
"list",
"deque",
"map",
"multimap",
"set",
"multiset",
"bitset"};
4583 llvm::StringRef
clname(cl.getName());
4584 for(
auto &&
name : names) {
4622 const clang::CXXRecordDecl *
thisDecl =
4623 llvm::dyn_cast_or_null<clang::CXXRecordDecl>(
lh.findScope(
typ, cling::LookupHelper::WithDiagnostics));
4627 Error(
"IsOfType",
"Record decl of type %s not found in the AST.",
typ.c_str());
4657 if (!IsStdClass(cl)) {
4658 auto *
nsDecl = llvm::dyn_cast<clang::NamespaceDecl>(cl.getDeclContext());
4659 if (cl.getName() !=
"RVec" ||
nsDecl ==
nullptr ||
nsDecl->getName() !=
"VecOps")
4662 auto *
parentNsDecl = llvm::dyn_cast<clang::NamespaceDecl>(cl.getDeclContext()->getParent());
4667 return STLKind(cl.getName());
4671 using namespace clang;
4672 struct SearchTypedef:
public TypeVisitor<SearchTypedef, bool> {
4677 return Visit(
AT->getElementType().getTypePtr());
4680 return Visit(
DT->getUnderlyingType().getTypePtr());
4683 return Visit(
PT->getPointeeType().getTypePtr());
4686 return Visit(
RT->getPointeeType().getTypePtr());
4689 return Visit(
STST->getReplacementType().getTypePtr());
4693 if (
TA.getKind() == TemplateArgument::Type && Visit(
TA.getAsType().getTypePtr()))
4702 return TOT->getUnmodifiedType().getTypePtr();
4707 if (
NNS->getKind() == NestedNameSpecifier::TypeSpec) {
4708 if (Visit(
NNS->getAsType()))
4713 return Visit(
ET->getNamedType().getTypePtr());
4734 using namespace llvm;
4735 using namespace clang;
4736 const clang::ASTContext &
Ctxt =
instance->getAsCXXRecordDecl()->getASTContext();
4739 const clang::ElaboratedType* etype
4740 = llvm::dyn_cast<clang::ElaboratedType>(
input.getTypePtr());
4745 assert(
instance->getAsCXXRecordDecl() !=
nullptr &&
"ReSubstTemplateArg only makes sense with a type representing a class.");
4765 if (
nQT ==
QT->getPointeeType())
return QT;
4781 if (
nQT ==
QT->getPointeeType())
return QT;
4802 if (
newQT ==
arr->getElementType())
return QT;
4806 arr->getSizeModifier(),
4807 arr->getIndexTypeCVRQualifiers());
4815 arr->getSizeModifier(),
4816 arr->getIndexTypeCVRQualifiers(),
4817 arr->getBracketsRange());
4822 if (
newQT ==
arr->getElementType())
return QT;
4824 arr->getSizeModifier(),
4825 arr->getIndexTypeCVRQualifiers());
4830 if (
newQT ==
arr->getElementType())
return QT;
4833 arr->getSizeModifier(),
4834 arr->getIndexTypeCVRQualifiers(),
4835 arr->getBracketsRange());
4844 etype = llvm::dyn_cast<clang::ElaboratedType>(
instance);
4846 instance = etype->getNamedType().getTypePtr();
4850 const clang::TemplateSpecializationType*
TST
4851 = llvm::dyn_cast<const clang::TemplateSpecializationType>(
instance);
4855 const clang::ClassTemplateSpecializationDecl*
TSTdecl
4856 = llvm::dyn_cast_or_null<const clang::ClassTemplateSpecializationDecl>(
instance->getAsCXXRecordDecl());
4860 const clang::SubstTemplateTypeParmType *
substType
4861 = llvm::dyn_cast<clang::SubstTemplateTypeParmType>(
input.getTypePtr());
4865 const clang::ClassTemplateDecl *
replacedCtxt =
nullptr;
4869 unsigned int index =
substType->getReplacedParameter()->getIndex();
4872 if (
decl->getKind() == clang::Decl::ClassTemplatePartialSpecialization) {
4873 const clang::ClassTemplatePartialSpecializationDecl *
spec = llvm::dyn_cast<clang::ClassTemplatePartialSpecializationDecl>(
decl);
4875 unsigned int depth =
substType->getReplacedParameter()->getDepth();
4891 const clang::SubstTemplateTypeParmType *
argType
4892 = llvm::dyn_cast<clang::SubstTemplateTypeParmType>(
argQualType);
4917 llvm::raw_string_ostream ostream(
astDump);
4920 ROOT::TMetaUtils::Warning(
"ReSubstTemplateArg",
"Unexpected type of declaration context for template parameter: %s.\n\tThe responsible class is:\n\t%s\n",
4928 ==
TSTdecl->getSpecializedTemplate ()->getTemplateParameters()->getParam(
index))
4930 const auto &
TAs =
TST->template_arguments();
4947 const clang::TemplateSpecializationType*
inputTST
4948 = llvm::dyn_cast<const clang::TemplateSpecializationType>(
input.getTypePtr());
4953 llvm::SmallVector<clang::TemplateArgument, 4>
desArgs;
4954 for (
const clang::TemplateArgument &
TA :
inputTST->template_arguments()) {
4955 if (
TA.getKind() != clang::TemplateArgument::Type) {
4960 clang::QualType
SubTy =
TA.getAsType();
4962 if (llvm::isa<clang::ElaboratedType>(
SubTy)
4963 || llvm::isa<clang::SubstTemplateTypeParmType>(
SubTy)
4964 || llvm::isa<clang::TemplateSpecializationType>(
SubTy)) {
4979 inputTST->getCanonicalTypeInternal());
5020 static const char *
stls[] =
5021 {
"any",
"vector",
"list",
"deque",
"map",
"multimap",
"set",
"multiset",
"bitset",
5022 "forward_list",
"unordered_set",
"unordered_multiset",
"unordered_map",
"unordered_multimap",
"RVec",
nullptr};
5036 for(
int k=1;
stls[k];k++) {
if (
type.equals(
stls[k]))
return values[k];}
5047 TND =
TND->getMostRecentDecl();
5048 while (
TND && !(
TND->hasAttrs()))
5049 TND =
TND->getPreviousDecl();
5061 TD =
TD->getMostRecentDecl();
5062 while (
TD && !(
TD->hasAttrs() &&
TD->isThisDeclarationADefinition()))
5063 TD =
TD->getPreviousDecl();
5119 std::list<std::pair<std::string,unsigned int> >&
enclosingSc)
5147 std::string::size_type
beginVar = 0;
5148 std::string::size_type
endVar = 0;
5152 std::string::size_type
endVarName = std::string::npos;
5222 str.replace(
start_pos, from.length(), to);
5289 return llvm::sys::path::extension(
filename) ==
".h" ||
5290 llvm::sys::path::extension(
filename) ==
".hh" ||
5291 llvm::sys::path::extension(
filename) ==
".hpp" ||
5292 llvm::sys::path::extension(
filename) ==
".H" ||
5293 llvm::sys::path::extension(
filename) ==
".h++" ||
5294 llvm::sys::path::extension(
filename) ==
"hxx" ||
5295 llvm::sys::path::extension(
filename) ==
"Hxx" ||
5296 llvm::sys::path::extension(
filename) ==
"HXX";
5302 cling::Interpreter::IgnoreFilesFunc_t
ignoreFiles,
5303 const cling::Interpreter &
interp,
5311 clang::Decl *
ncDecl =
const_cast<clang::Decl *
>(
decl);
5356 static const std::string
scopeType [] = {
"namespace ",
"inline namespace ",
"class "};
5398 std::string typeName;
5401 if (llvm::isa<clang::TemplateTypeParmDecl>(
nDecl)){
5402 typeName =
"typename ";
5403 if (
nDecl->isParameterPack())
5405 typeName += (*prmIt)->getNameAsString();
5408 else if (
auto nttpd = llvm::dyn_cast<clang::NonTypeTemplateParmDecl>(
nDecl)){
5412 if (
theType.getAsString().find(
"enum") != std::string::npos){
5414 llvm::raw_string_ostream ostream(
astDump);
5415 nttpd->dump(ostream);
5426 else if (
auto ttpd = llvm::dyn_cast<clang::TemplateTemplateParmDecl>(
nDecl)){
5430 llvm::raw_string_ostream ostream(
astDump);
5431 ttpd->dump(ostream);
5456 "Cannot extract template parameter list for %s",
5464 "Problems with arguments for forward declaration of class %s\n",
5474 if (llvm::isa<clang::TemplateTemplateParmDecl>(&
templDecl)) {
5496 if (clang::TemplateArgument::Type != arg.getKind())
return 0;
5511 if (llvm::isa<clang::BuiltinType>(
argTypePtr)){
5544 if (
specDef->getTemplateSpecializationKind() != clang::TSK_ExplicitSpecialization)
5548 std::cout <<
" Forward declaring template spec " <<
normalizedName <<
":\n";
5553 std::cout <<
" o Template argument ";
5555 std::cout <<
"successfully treated. Arg fwd decl: " <<
argFwdDecl << std::endl;
5557 std::cout <<
"could not be treated. Abort fwd declaration generation.\n";
5598 std::cout <<
"Class " <<
recordDecl.getNameAsString()
5599 <<
" is a template specialisation. Treating its arguments.\n";
5603 std::cout <<
" o Template argument ";
5605 std::cout <<
"successfully treated. Arg fwd decl: " <<
argFwdDecl << std::endl;
5607 std::cout <<
"could not be treated. Abort fwd declaration generation.\n";
5655 std::string buffer =
tdnDecl.getNameAsString();
5658 if (
const clang::TagType* TT
5660 if (clang::NamedDecl*
ND = TT->getDecl()) {
5661 if (!
ND->getIdentifier()) {
5705 std::cout <<
"Typedef " <<
tdnDecl.getNameAsString() <<
" hides a class: "
5732 const clang::PrintingPolicy&
ppolicy)
5735 auto&
ctxt = par.getASTContext();
5756 if (
result.isNegative()){
The file contains utilities which are foundational and could be used across the core component of ROO...
#define R(a, b, c, d, e, f, g, h, i)
static Roo_reg_AGKInteg1D instance
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
static void indent(ostringstream &buf, int indent_level)
static bool RecurseKeepNParams(clang::TemplateArgument &normTArg, const clang::TemplateArgument &tArg, const cling::Interpreter &interp, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt, const clang::ASTContext &astCtxt)
static clang::SourceLocation getFinalSpellingLoc(clang::SourceManager &sourceManager, clang::SourceLocation sourceLoc)
const clang::DeclContext * GetEnclosingSpace(const clang::RecordDecl &cl)
bool IsTemplate(const clang::Decl &cl)
static void KeepNParams(clang::QualType &normalizedType, const clang::QualType &vanillaType, const cling::Interpreter &interp, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt)
This function allows to manipulate the number of arguments in the type of a template specialisation.
static void CreateNameTypeMap(const clang::CXXRecordDecl &cl, ROOT::MembersTypeMap_t &nameType)
Create the data member name-type map for given class.
const clang::CXXMethodDecl * GetMethodWithProto(const clang::Decl *cinfo, const char *method, const char *proto, const cling::Interpreter &interp, bool diagnose)
int dumpDeclForAssert(const clang::Decl &D, const char *commentStart)
static void replaceEnvVars(const char *varname, std::string &txt)
Reimplementation of TSystem::ExpandPathName() that cannot be used from TMetaUtils.
static bool areEqualValues(const clang::TemplateArgument &tArg, const clang::NamedDecl &tPar)
std::cout << "Are equal values?\n";
static bool isTypeWithDefault(const clang::NamedDecl *nDecl)
Check if this NamedDecl is a template parameter with a default argument.
static int TreatSingleTemplateArg(const clang::TemplateArgument &arg, std::string &argFwdDecl, const cling::Interpreter &interpreter, bool acceptStl=false)
static bool areEqualTypes(const clang::TemplateArgument &tArg, llvm::SmallVectorImpl< clang::TemplateArgument > &preceedingTArgs, const clang::NamedDecl &tPar, const cling::Interpreter &interp, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt)
static bool hasSomeTypedefSomewhere(const clang::Type *T)
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void input
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t dest
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t target
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h length
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
Option_t Option_t TPoint TPoint const char mode
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
const_iterator begin() const
const_iterator end() const
const std::string & GetPathSeparator()
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
void WriteSchemaList(std::list< SchemaRuleMap_t > &rules, const std::string &listName, std::ostream &output)
Write schema rules.
std::map< std::string, ROOT::Internal::TSchemaType > MembersTypeMap_t
void WriteReadRuleFunc(SchemaRuleMap_t &rule, int index, std::string &mappedName, MembersTypeMap_t &members, std::ostream &output)
Write the conversion function for Read rule, the function name is being written to rule["funcname"].
R__EXTERN SchemaRuleClassMap_t gReadRules
bool HasValidDataMembers(SchemaRuleMap_t &rule, MembersTypeMap_t &members, std::string &error_string)
Check if given rule contains references to valid data members.
void WriteReadRawRuleFunc(SchemaRuleMap_t &rule, int index, std::string &mappedName, MembersTypeMap_t &members, std::ostream &output)
Write the conversion function for ReadRaw rule, the function name is being written to rule["funcname"...
R__EXTERN SchemaRuleClassMap_t gReadRawRules
ROOT::ESTLType STLKind(std::string_view type)
Converts STL container name to number.
bool IsStdClass(const char *type)
return true if the class belongs to the std namespace
std::string GetLong64_Name(const char *original)
Replace 'long long' and 'unsigned long long' by 'Long64_t' and 'ULong64_t'.
ROOT::ESTLType IsSTLCont(std::string_view type)
type : type name: vector<list<classA,allocator>,allocator> result: 0 : not stl container code of cont...
char * DemangleName(const char *mangled_name, int &errorCode)
std::string GetNameForIO(const std::string &templateInstanceName, TClassEdit::EModType mode=TClassEdit::kNone, bool *hasChanged=nullptr)
void GetNormalizedName(std::string &norm_name, std::string_view name)
Return the normalized name.
bool IsSTLBitset(const char *type)
Return true is the name is std::bitset<number> or bitset<number>
constexpr Double_t C()
Velocity of light in .