24#include <unordered_set>
27#include "RConfigure.h"
36#include "clang/AST/ASTContext.h"
37#include "clang/AST/Attr.h"
38#include "clang/AST/CXXInheritance.h"
39#include "clang/AST/Decl.h"
40#include "clang/AST/DeclTemplate.h"
41#include "clang/AST/Mangle.h"
42#include "clang/AST/Type.h"
43#include "clang/AST/TypeVisitor.h"
44#include "clang/Frontend/CompilerInstance.h"
45#include "clang/Lex/HeaderSearch.h"
46#include "clang/Lex/ModuleMap.h"
47#include "clang/Lex/Preprocessor.h"
48#include "clang/Lex/PreprocessorOptions.h"
50#include "clang/Sema/Lookup.h"
51#include "clang/Sema/Sema.h"
52#include "clang/Sema/SemaDiagnostic.h"
54#include "cling/Interpreter/LookupHelper.h"
55#include "cling/Interpreter/Transaction.h"
56#include "cling/Interpreter/Interpreter.h"
57#include "cling/Utils/AST.h"
58#include "cling/Interpreter/InterpreterAccessRAII.h"
60#include "llvm/Support/Path.h"
61#include "llvm/Support/FileSystem.h"
66#define strncasecmp _strnicmp
86 using DeclsCont_t = TNormalizedCtxt::Config_t::SkipCollection;
103 bool replace =
false);
114 clang::NestedNameSpecifier*
scope,
117 if (!
scope)
return nullptr;
140static bool CheckDefinition(
const clang::CXXRecordDecl *cl,
const clang::CXXRecordDecl *context)
142 if (!cl->hasDefinition()) {
145 "Missing definition for class %s, please #include its header in the header of %s\n",
146 cl->getName().str().c_str(), context->getName().str().c_str());
149 "Missing definition for class %s\n",
150 cl->getName().str().c_str());
163 clang::NestedNameSpecifier *
scope,
166 if (!
scope)
return nullptr;
188 const clang::BuiltinType *
builtin = llvm::dyn_cast<clang::BuiltinType>(
type->getCanonicalTypeInternal().getTypePtr());
208 clang::ASTContext &
C = cl.getASTContext();
209 clang::DeclarationName
DName = &
C.Idents.get(
what);
210 auto R = cl.lookup(
DName);
211 for (
const clang::NamedDecl *D :
R)
223 clang::LookupResult
R(
SemaR,
DName, clang::SourceLocation(),
224 clang::Sema::LookupOrdinaryName,
225 RedeclarationKind::ForExternalRedeclaration);
226 SemaR.LookupInSuper(
R, &
const_cast<clang::CXXRecordDecl&
>(cl));
229 return llvm::dyn_cast<const clang::FieldDecl>(
R.getFoundDecl());
235 ? cling::LookupHelper::WithDiagnostics
236 : cling::LookupHelper::NoDiagnostics;
243namespace TMetaUtils {
252 Error(
"TNormalizedCtxt::AddTemplAndNargsToKeep",
253 "Tring to specify a number of template arguments to keep for a null pointer. Exiting without assigning any value.\n");
257 const clang::ClassTemplateDecl*
canTempl =
templ->getCanonicalDecl();
262 const std::string
i_str (std::to_string(i));
264 Error(
"TNormalizedCtxt::AddTemplAndNargsToKeep",
265 "Tring to specify for template %s %s arguments to keep, while before this number was %s\n",
266 canTempl->getNameAsString().c_str(),
279 const clang::ClassTemplateDecl*
constTempl =
templ->getCanonicalDecl();
330 std::unique_ptr<clang::MangleContext>
mangleCtx(
rDecl->getASTContext().createMangleContext());
334 if (
const clang::TypeDecl*
TD = llvm::dyn_cast<clang::TypeDecl>(
rDecl)) {
335 mangleCtx->mangleCXXRTTI(clang::QualType(
TD->getTypeForDecl(), 0),
sstr);
361 "Demangled typeinfo name '%s' does not contain `RTTI Type Descriptor'\n",
365 "Demangled typeinfo name '%s' does not start with 'typeinfo for'\n",
382 const clang::RecordDecl *
decl,
413 const clang::RecordDecl *
decl,
444 "Could not remove the requested template arguments.\n");
455 const clang::RecordDecl *
decl,
491 const clang::RecordDecl *
decl,
540 fCheckInClassTable(CheckInClassTable),
554 if (
tname.empty())
return false;
579 if (!
dest.isNull() && (
dest != t)) {
599 if (!
dest.isNull() && (
dest != t) &&
621 const clang::NamespaceDecl *
nsdecl = llvm::dyn_cast<clang::NamespaceDecl>(
scope);
634 if (
tname.empty())
return false;
666 clang::PrintingPolicy
policy(
fInterpreter->getCI()->getASTContext().getPrintingPolicy());
667 policy.SuppressTagKeyword =
true;
668 policy.SuppressScope =
true;
683 for(
unsigned int i = 1; i<
result.length(); ++i) {
695 }
else if ( (i+1) <
result.length() &&
733 clang::QualType
toSkip =
lh.findType(
name, cling::LookupHelper::WithDiagnostics);
734 if (
const clang::Type* T =
toSkip.getTypePtr()) {
735 const clang::TypedefType *
tt = llvm::dyn_cast<clang::TypedefType>(T);
737 clang::Decl* D =
tt->getDecl();
738 fConfig.m_toSkip.insert(D);
740 clang::QualType
canon =
toSkip->getCanonicalTypeInternal();
741 fConfig.m_toReplace.insert(std::make_pair(
canon.getTypePtr(),T));
743 fTypeWithAlternative.insert(T);
756 keepTypedef(
lh,
"Double32_t");
757 keepTypedef(
lh,
"Float16_t");
758 keepTypedef(
lh,
"Long64_t",
true);
759 keepTypedef(
lh,
"ULong64_t",
true);
761 clang::QualType
toSkip =
lh.findType(
"string", cling::LookupHelper::WithDiagnostics);
763 if (
const clang::TypedefType* TT
764 = llvm::dyn_cast_or_null<clang::TypedefType>(
toSkip.getTypePtr()))
765 fConfig.m_toSkip.insert(TT->getDecl());
767 toSkip =
lh.findType(
"std::string", cling::LookupHelper::WithDiagnostics);
769 if (
const clang::TypedefType* TT
770 = llvm::dyn_cast_or_null<clang::TypedefType>(
toSkip.getTypePtr()))
771 fConfig.m_toSkip.insert(TT->getDecl());
773 clang::QualType
canon =
toSkip->getCanonicalTypeInternal();
774 fConfig.m_toReplace.insert(std::make_pair(
canon.getTypePtr(),
toSkip.getTypePtr()));
785 return (cl.getKind() == clang::Decl::ClassTemplatePartialSpecialization
786 || cl.getKind() == clang::Decl::ClassTemplateSpecialization);
793 const cling::Interpreter&
interp)
795 clang::Sema* S = &
interp.getSema();
796 const clang::NamedDecl*
ND = cling::utils::Lookup::Named(S,
name, cl);
797 if (
ND == (clang::NamedDecl*)-1)
798 return (clang::FunctionDecl*)-1;
799 return llvm::dyn_cast_or_null<clang::FunctionDecl>(
ND);
805const clang::CXXRecordDecl *
809 const cling::LookupHelper&
lh =
interp.getLookupHelper();
812 const clang::CXXRecordDecl *
result
813 = llvm::dyn_cast_or_null<clang::CXXRecordDecl>
820 result = llvm::dyn_cast_or_null<clang::CXXRecordDecl>
831 clang::QualType
qType(cl->getTypeForDecl(),0);
839 clang::Sema& S =
interp.getCI()->getSema();
842 cling::Interpreter::PushTransactionRAII
RAII(
const_cast<cling::Interpreter*
>(&
interp));
843 return S.RequireCompleteType(
Loc, Type, clang::diag::err_incomplete_type);
849 const clang::CXXRecordDecl *context,
const cling::Interpreter &
interp)
855 if (!cl->getDefinition() || !cl->isCompleteDefinition()) {
863 if (!base->hasDefinition()) {
867 return cl->isDerivedFrom(base);
879 const clang::NamedDecl *base
883 return IsBase(
CRD, llvm::dyn_cast<clang::CXXRecordDecl>( base ),
884 llvm::dyn_cast<clang::CXXRecordDecl>(
m.getDeclContext()),
interp);
893 const clang::QualType &
qti,
895 const cling::Interpreter &
interp,
903 kBIT_ISSTRING = 0x40000000,
910 const clang::Type &
ti( *
qti.getTypePtr() );
933 if (
tiName ==
"string")
kase |= kBIT_ISSTRING;
934 if (
tiName ==
"string*")
kase |= kBIT_ISSTRING;
938 tcl =
" internal error in rootcling ";
963 <<
" R__b >> readtemp;" << std::endl
964 <<
" " <<
R__t <<
" = static_cast<" <<
tiName <<
">(readtemp);" << std::endl;
976 finalString <<
" if (R__b.GetInfo() && R__b.GetInfo()->GetOldVersion()<=3) {" << std::endl;
978 finalString <<
" R__ASSERT(0);// " <<
objType <<
" is abstract. We assume that older file could not be produced using this streaming method." << std::endl;
981 <<
" " <<
R__t <<
"->Streamer(R__b);" << std::endl;
984 <<
" " <<
R__t <<
" = (" <<
tiName <<
")R__b.ReadObjectAny(" <<
tcl <<
");" << std::endl
985 <<
" }" << std::endl;
991 <<
" R__str.Streamer(R__b);" << std::endl
992 <<
" " <<
R__t <<
" = R__str.Data();}" << std::endl;
998 <<
" R__str.Streamer(R__b);" << std::endl
999 <<
" " <<
R__t <<
" = new string(R__str.Data());}" << std::endl;
1003 if (!
R__t)
return 1;
1008 if (!
R__t)
return 1;
1019 if (!
R__t)
return 0;
1024 if (!
R__t)
return 0;
1026 finalString <<
" R__b >> *reinterpret_cast<Int_t*>(ptr_enum); }" << std::endl;
1031 if (!
R__t)
return 0;
1036 if (!
R__t)
return 1;
1041 if (!
R__t)
return 0;
1042 finalString <<
" {TString R__str(" <<
R__t <<
".c_str());" << std::endl
1043 <<
" R__str.Streamer(R__b);};" << std::endl;
1047 if (!
R__t)
return 0;
1048 finalString <<
" {TString R__str(" <<
R__t <<
"->c_str());" << std::endl
1049 <<
" R__str.Streamer(R__b);}" << std::endl;
1053 if (!
R__t)
return 1;
1058 if (!
R__t)
return 1;
1071 clang::CXXRecordDecl*
ncCl =
const_cast<clang::CXXRecordDecl*
>(cl);
1074 cling::Interpreter::PushTransactionRAII
clingRAII(
const_cast<cling::Interpreter*
>(&
interpreter));
1077 if (
Ctor->getAccess() == clang::AS_public && !
Ctor->isDeleted()) {
1095 const cling::LookupHelper&
lh =
interpreter.getLookupHelper();
1104 return EIOCtorCategory::kAbsent;
1107 cling::Interpreter::PushTransactionRAII
clingRAII(
const_cast<cling::Interpreter*
>(&
interpreter));
1108 for (
auto iter = cl->ctor_begin(), end = cl->ctor_end(); iter != end; ++iter)
1110 if ((iter->getAccess() != clang::AS_public) || (iter->getNumParams() != 1))
1114 clang::QualType
argType((*iter->param_begin())->getType());
1118 if (
argType->isPointerType()) {
1121 }
else if (
argType->isReferenceType()) {
1128 const clang::CXXRecordDecl *
argDecl =
argType->getAsCXXRecordDecl();
1135 std::string
clarg(
"class ");
1142 return EIOCtorCategory::kAbsent;
1155 if (!
ioctortype.GetType() && (!arg || !arg[0])) {
1169 const cling::Interpreter &
interp,
1172 const clang::FunctionDecl*
funcD
1174 diagnose ? cling::LookupHelper::WithDiagnostics
1175 : cling::LookupHelper::NoDiagnostics);
1177 return llvm::dyn_cast<const clang::CXXMethodDecl>(
funcD);
1186 namespace TMetaUtils {
1189 const cling::LookupHelper&
lh =
interp.getLookupHelper();
1208 const cling::Interpreter &
interp)
1210 if (cl->isAbstract())
return false;
1216 if (EIOCtorCategory::kAbsent ==
ioCtorCat)
1226 if (EIOCtorCategory::kIOPtrType ==
ioCtorCat) {
1228 }
else if (EIOCtorCategory::kIORefType ==
ioCtorCat) {
1232 arg +=
")nullptr )";
1235 const clang::CXXMethodDecl *
method
1237 cling::LookupHelper::NoDiagnostics);
1238 if (
method &&
method->getAccess() != clang::AS_public) {
1252 const cling::Interpreter&
interp)
1254 if (!cl)
return false;
1256 if (cl->hasUserDeclaredDestructor()) {
1258 cling::Interpreter::PushTransactionRAII
clingRAII(
const_cast<cling::Interpreter*
>(&
interp));
1259 clang::CXXDestructorDecl *
dest = cl->getDestructor();
1261 return (
dest->getAccess() == clang::AS_public);
1275 const cling::Interpreter &
interp,
1278 const clang::CXXMethodDecl *
method
1280 diagnose ? cling::LookupHelper::WithDiagnostics
1281 : cling::LookupHelper::NoDiagnostics);
1282 return (
method &&
method->getAccess() == clang::AS_public);
1293 const char *
proto =
"TDirectory*";
1294 const char *
name =
"DirectoryAutoAdd";
1308 const char *
proto =
"TCollection*,TFileMergeInfo*";
1309 const char *
name =
"Merge";
1322 const char *
proto =
"TCollection*";
1323 const char *
name =
"Merge";
1338 const char *
proto =
"TFileMergeInfo*";
1339 const char *
name =
"ResetAfterMerge";
1349 const clang::CXXRecordDecl*
clxx,
1350 const cling::Interpreter &
interp,
1353 static const char *
proto =
"TBuffer&";
1355 const clang::CXXMethodDecl *
method
1357 cling::LookupHelper::NoDiagnostics);
1368 const clang::CXXRecordDecl*
clxx,
1369 const cling::Interpreter &
interp,
1372 static const char *
proto =
"TBuffer&,TClass*";
1374 const clang::CXXMethodDecl *
method
1376 cling::LookupHelper::NoDiagnostics);
1441 llvm::raw_string_ostream stream(
qual_name);
1442 clang::PrintingPolicy
policy( cl.getASTContext().getPrintingPolicy() );
1443 policy.SuppressTagKeyword =
true;
1444 policy.SuppressUnwrittenScope =
true;
1446 cl.getNameForDiagnostic(stream,
policy,
true);
1502 std::stringstream
dims;
1505 const clang::ASTContext&
astContext = cl.getASTContext();
1508 for(clang::RecordDecl::field_iterator
field_iter = cl.field_begin(), end = cl.field_end();
1522 const clang::ConstantArrayType *
arrayType = llvm::dyn_cast<clang::ConstantArrayType>(
fieldType.getTypePtr());
1524 dims <<
"[" <<
arrayType->getSize().getLimitedValue() <<
"]";
1526 arrayType = llvm::dyn_cast<clang::ConstantArrayType>(
arrayType->getArrayElementTypeNoTypeQual());
1536 for(clang::CXXRecordDecl::base_class_const_iterator iter = cl.bases_begin(), end = cl.bases_end();
1539 std::string
basename( iter->getType()->getAsCXXRecordDecl()->getNameAsString() );
1549 const cling::Interpreter &
interp,
1553 diagnose ? cling::LookupHelper::WithDiagnostics
1554 : cling::LookupHelper::NoDiagnostics);
1613 while (llvm::isa<clang::PointerType>(
instanceType.getTypePtr())
1614 || llvm::isa<clang::ReferenceType>(
instanceType.getTypePtr()))
1619 const clang::ElaboratedType* etype
1620 = llvm::dyn_cast<clang::ElaboratedType>(
instanceType.getTypePtr());
1622 instanceType = clang::QualType(etype->getNamedType().getTypePtr(),0);
1636 if (
clxx &&
clxx->getTemplateSpecializationKind() != clang::TSK_Undeclared) {
1638 const clang::TemplateSpecializationType*
TST
1639 = llvm::dyn_cast<const clang::TemplateSpecializationType>(
instanceType.getTypePtr());
1646 for (
const clang::TemplateArgument &
TA :
TST->template_arguments()) {
1647 if (
TA.getKind() == clang::TemplateArgument::Type) {
1659 const cling::Interpreter &
interp,
1662 const clang::CXXRecordDecl *
clxx = llvm::dyn_cast<clang::CXXRecordDecl>(cl.
GetRecordDecl());
1663 if (!
clxx ||
clxx->getTemplateSpecializationKind() == clang::TSK_Undeclared)
return false;
1666 cling::LookupHelper::WithDiagnostics);
1680 clang::AnnotateAttr*
annAttr = clang::dyn_cast<clang::AnnotateAttr>(
attribute);
1723 for (clang::Decl::attr_iterator
attrIt =
decl.attr_begin();
1725 clang::AnnotateAttr*
annAttr = clang::dyn_cast<clang::AnnotateAttr>(*
attrIt);
1729 std::pair<llvm::StringRef,llvm::StringRef> split =
attribute.split(propNames::separator.c_str());
1730 if (split.first !=
propName.c_str())
continue;
1746 for (clang::Decl::attr_iterator
attrIt =
decl.attr_begin();
1748 clang::AnnotateAttr*
annAttr = clang::dyn_cast<clang::AnnotateAttr>(*
attrIt);
1752 std::pair<llvm::StringRef,llvm::StringRef> split =
attribute.split(propNames::separator.c_str());
1753 if (split.first !=
propName.c_str())
continue;
1755 return split.second.getAsInteger(10,
propValue);
1766 const clang::CXXRecordDecl *
decl,
1767 const cling::Interpreter &
interp,
1776 std::string
csymbol = classname;
1790 bool isStd = TMetaUtils::IsStdClass(*
decl);
1791 const cling::LookupHelper&
lh =
interp.getLookupHelper();
1801 <<
" static void " <<
mappedname.c_str() <<
"_TClassManip(TClass*);\n";
1819 finalString <<
" static void delete_" <<
mappedname.c_str() <<
"(void *p);" <<
"\n" <<
" static void deleteArray_" <<
mappedname.c_str() <<
"(void *p);" <<
"\n" <<
" static void destruct_" <<
mappedname.c_str() <<
"(void *p);" <<
"\n";
1822 finalString <<
" static void directoryAutoAdd_" <<
mappedname.c_str() <<
"(void *obj, TDirectory *dir);" <<
"\n";
1825 finalString <<
" static void streamer_" <<
mappedname.c_str() <<
"(TBuffer &buf, void *obj);" <<
"\n";
1828 finalString <<
" static void conv_streamer_" <<
mappedname.c_str() <<
"(TBuffer &buf, void *obj, const TClass*);" <<
"\n";
1831 finalString <<
" static Long64_t merge_" <<
mappedname.c_str() <<
"(void *obj, TCollection *coll,TFileMergeInfo *info);" <<
"\n";
1834 finalString <<
" static void reset_" <<
mappedname.c_str() <<
"(void *obj, TFileMergeInfo *info);" <<
"\n";
1853 finalString <<
"\n // Schema evolution read functions\n";
1854 std::list<ROOT::SchemaRuleMap_t>::iterator
rIt =
rulesIt1->second.fRules.
begin();
1872 if(
rIt->find(
"code" ) !=
rIt->
end() ) {
1888 finalString <<
"\n // Schema evolution read raw functions\n";
1889 std::list<ROOT::SchemaRuleMap_t>::iterator
rIt =
rulesIt2->second.fRules.
begin();
1915 finalString <<
"\n" <<
" // Function generating the singleton type initializer" <<
"\n";
1917 finalString <<
" static TGenericClassInfo *GenerateInitInstanceLocal(const " <<
csymbol <<
"*)" <<
"\n" <<
" {" <<
"\n";
1923 finalString <<
" static ::TVirtualIsAProxy* isa_proxy = new ::TInstrumentedIsAProxy< " <<
csymbol <<
" >(nullptr);" <<
"\n";
1926 finalString <<
" static ::TVirtualIsAProxy* isa_proxy = new ::TIsAProxy(typeid(" <<
csymbol <<
"));" <<
"\n";
1928 finalString <<
" static ::ROOT::TGenericClassInfo " <<
"\n" <<
" instance(\"" << classname.c_str() <<
"\", ";
1941 static const char *
versionFunc =
"GetClassVersion";
1945 std::string
proto = classname +
"*";
1946 const clang::Decl*
ctxt = llvm::dyn_cast<clang::Decl>((*cl).getDeclContext());
1949 interp, cling::LookupHelper::NoDiagnostics);
1968 for (
unsigned int i=0; i<
filename.length(); i++) {
1973 <<
"," <<
"\n" <<
" typeid(" <<
csymbol
1974 <<
"), ::ROOT::Internal::DefineBehavior(ptr, ptr)," <<
"\n" <<
" ";
1991 <<
" sizeof(" <<
csymbol <<
"), alignof(" <<
csymbol <<
") );" <<
"\n";
1998 finalString <<
" instance.SetDelete(&delete_" <<
mappedname.c_str() <<
");" <<
"\n" <<
" instance.SetDeleteArray(&deleteArray_" <<
mappedname.c_str() <<
");" <<
"\n" <<
" instance.SetDestructor(&destruct_" <<
mappedname.c_str() <<
");" <<
"\n";
2001 finalString <<
" instance.SetDirectoryAutoAdd(&directoryAutoAdd_" <<
mappedname.c_str() <<
");" <<
"\n";
2009 finalString <<
" instance.SetConvStreamerFunc(&conv_streamer_" <<
mappedname.c_str() <<
");" <<
"\n";
2018 finalString <<
" instance.AdoptCollectionProxyInfo(TCollectionProxyInfo::Generate(TCollectionProxyInfo::" <<
"Pushback" <<
"<Internal::TStdBitsetHelper< " << classname.c_str() <<
" > >()));" <<
"\n";
2021 }
else if (
stl != 0 &&
2024 int idx = classname.find(
"<");
2055 finalString <<
" \"Class with alignment strictly greater than 4096 are currently not supported in "
2056 "CollectionProxy. \"\n";
2057 finalString <<
" \"Please report this case to the developers\");\n";
2058 finalString <<
" instance.AdoptCollectionProxyInfo(TCollectionProxyInfo::Generate(TCollectionProxyInfo::" <<
methodTCP <<
"< " <<
classNameForIO.c_str() <<
" >()));" <<
"\n";
2068 finalString <<
"\n" <<
" instance.AdoptAlternate(::ROOT::AddClassAlternate(\""
2075 finalString <<
"\n" <<
" instance.AdoptAlternate(::ROOT::AddClassAlternate(\""
2093 finalString <<
"\n" <<
" ::ROOT::Internal::TSchemaHelper* rule;" <<
"\n";
2097 finalString <<
"\n" <<
" // the io read rules" <<
"\n" <<
" std::vector<::ROOT::Internal::TSchemaHelper> readrules(" <<
rulesIt1->second.size() <<
");" <<
"\n";
2099 finalString <<
" instance.SetReadRules( readrules );" <<
"\n";
2100 rulesIt1->second.fGenerated =
true;
2104 finalString <<
"\n" <<
" // the io read raw rules" <<
"\n" <<
" std::vector<::ROOT::Internal::TSchemaHelper> readrawrules(" <<
rulesIt2->second.size() <<
");" <<
"\n";
2106 finalString <<
" instance.SetReadRawRules( readrawrules );" <<
"\n";
2107 rulesIt2->second.fGenerated =
true;
2110 finalString <<
" return &instance;" <<
"\n" <<
" }" <<
"\n";
2114 finalString <<
" TGenericClassInfo *GenerateInitInstance(const " <<
csymbol <<
"*)" <<
"\n" <<
" {\n return GenerateInitInstanceLocal(static_cast<" <<
csymbol <<
"*>(nullptr));\n }" <<
"\n";
2117 finalString <<
" // Static variable to force the class initialization" <<
"\n";
2121 finalString <<
" static ::ROOT::TGenericClassInfo *_R__UNIQUE_DICT_(Init) = GenerateInitInstanceLocal(static_cast<const " <<
csymbol <<
"*>(nullptr)); R__UseDummy(_R__UNIQUE_DICT_(Init));" <<
"\n";
2124 finalString <<
"\n" <<
" // Dictionary for non-ClassDef classes" <<
"\n"
2125 <<
" static TClass *" <<
mappedname <<
"_Dictionary() {\n"
2126 <<
" TClass* theClass ="
2127 <<
"::ROOT::GenerateInitInstanceLocal(static_cast<const " <<
csymbol <<
"*>(nullptr))->GetClass();\n"
2128 <<
" " <<
mappedname <<
"_TClassManip(theClass);\n";
2139 if (
decl->hasAttrs()){
2141 for (clang::Decl::attr_iterator
attrIt =
decl->attr_begin();
2158 manipString+=
" theClass->CreateAttributeMap();\n";
2159 manipString+=
" TDictAttributeMap* attrMap( theClass->GetAttributeMap() );\n";
2170 if (!(!(*internalDeclIt)->isImplicit()
2191 TMetaUtils::Error(
nullptr,
"Cannot convert field declaration to clang::NamedDecl");
2207 if (
attrName == propNames::comment ||
2209 attrName == propNames::ioname )
continue;
2234 finalString <<
"} // end of namespace ROOT" <<
"\n" <<
"\n";
2239 const cling::Interpreter &
interp)
2243 const clang::Type *
typeptr =
nullptr;
2244 const clang::CXXRecordDecl *
target =
2249 std::string
rule{
nRules > 1 ?
"rules" :
"rule"};
2250 std::string
verb{
nRules > 1 ?
"were" :
"was"};
2268 finalString <<
"\n // Schema evolution read functions\n";
2269 std::list<ROOT::SchemaRuleMap_t>::iterator
rIt =
rulesIt1.second.fRules.
begin();
2310 finalString <<
" // Registration Schema evolution read functions\n";
2314 <<
" ::ROOT::Internal::TSchemaHelper* rule;" <<
"\n";
2323 finalString <<
" std::vector<::ROOT::Internal::TSchemaHelper> readrules(" <<
rulesIt1->second.size()
2326 finalString <<
" TClass::RegisterReadRules(TSchemaRule::kReadRule, \"" <<
name
2327 <<
"\", std::move(readrules));\n";
2328 rulesIt1->second.fGenerated =
true;
2333 finalString <<
" std::vector<::ROOT::Internal::TSchemaHelper> readrawrules(" <<
rulesIt2->second.size()
2336 finalString <<
" TClass::RegisterReadRules(TSchemaRule::kReadRawRule, \"" <<
name
2337 <<
"\", std::move(readrawrules));\n";
2338 rulesIt2->second.fGenerated =
true;
2358 const clang::CXXRecordDecl *cl)
2368 auto ctxt = cl->getEnclosingNamespaceContext();
2373 const clang::NamedDecl *
namedCtxt = llvm::dyn_cast<clang::NamedDecl>(
ctxt);
2375 const clang::NamespaceDecl *
nsdecl = llvm::dyn_cast<clang::NamespaceDecl>(
namedCtxt);
2390 const clang::DeclContext *
ctxt = cl.getDeclContext();
2391 while(
ctxt && !
ctxt->isNamespace()) {
2412 const clang::NamespaceDecl *ns = llvm::dyn_cast<clang::NamespaceDecl>(
ctxt);
2418 out <<
"namespace " << ns->getNameAsString() <<
" {" << std::endl;
2437 clang::TemplateSpecializationKind kind = cl->getTemplateSpecializationKind();
2438 if (kind == clang::TSK_Undeclared ) {
2441 }
else if (kind == clang::TSK_ExplicitSpecialization) {
2456 const char *
proto =
"size_t";
2463 cling::LookupHelper::NoDiagnostics);
2467 cling::LookupHelper::NoDiagnostics);
2469 const clang::DeclContext *
ctxtnew =
nullptr;
2505 const clang::CXXRecordDecl*
clnew = llvm::dyn_cast<clang::CXXRecordDecl>(
ctxtnew);
2552 const clang::CXXRecordDecl *
decl,
2553 const cling::Interpreter &
interp,
2577 classname.insert(0,
"::");
2585 finalString <<
" // Wrappers around operator new" <<
"\n";
2586 finalString <<
" static void *new_" <<
mappedname.c_str() <<
"(void *p) {" <<
"\n" <<
" return p ? ";
2593 finalString <<
"::new(static_cast<::ROOT::Internal::TOperatorNewHelper*>(p)) ";
2598 finalString <<
"new " << classname.c_str() << args <<
";" <<
"\n";
2613 finalString <<
"::new(static_cast<::ROOT::Internal::TOperatorNewHelper*>(p)) ";
2627 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";
2631 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";
2635 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";
2639 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";
2643 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";
2645 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";
2649 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";
2651 finalString <<
"} // end of namespace ROOT for class " << classname.c_str() <<
"\n" <<
"\n";
2658 const cling::Interpreter &
interp,
2669 const clang::CXXRecordDecl *
clxx = llvm::dyn_cast<clang::CXXRecordDecl>(cl.
GetRecordDecl());
2673 for(clang::CXXRecordDecl::base_class_const_iterator iter =
clxx->bases_begin(), end =
clxx->bases_end();
2679 Internal::RStl::Instance().GenerateTClassFor( iter->getType(),
interp,
normCtxt);
2684 for(clang::RecordDecl::field_iterator
field_iter =
clxx->field_begin(), end =
clxx->field_end();
2716 const clang::Type *
rawtype =
m.getType()->getCanonicalTypeInternal().getTypePtr();
2732 const clang::CXXRecordDecl*
CRD = llvm::dyn_cast<clang::CXXRecordDecl>(cl);
2744 if (
funcCV == (clang::FunctionDecl*)-1)
return 1;
2759 using res_t = std::pair<bool, int>;
2761 const clang::CompoundStmt*
FuncBody
2762 = llvm::dyn_cast_or_null<clang::CompoundStmt>(
funcCV->getBody());
2764 return res_t{
false, -1};
2769 return res_t{
false, -1};
2771 const clang::ReturnStmt*
RetStmt
2772 = llvm::dyn_cast<clang::ReturnStmt>(
FuncBody->body_back());
2774 return res_t{
false, -1};
2786 return res_t{
false, -1};
2794 return TMetaUtils::IsSTLCont(*
annotated.GetRecordDecl());
2802 clang::QualType
type =
m.getType();
2805 if (
decl)
return TMetaUtils::IsSTLCont(*
decl);
2814 clang::QualType
type = base.getType();
2817 if (
decl)
return TMetaUtils::IsSTLCont(*
decl);
2827 const std::function<
void(
const clang::Module::Header &)> &
closure,
2835 llvm::SetVector<const clang::Module *>
modules;
2837 for (
size_t i = 0; i <
modules.size(); ++i) {
2838 const clang::Module *M =
modules[i];
2839 for (
const clang::Module *
subModule : M->submodules())
2843 for (
const clang::Module *
m :
modules) {
2845 for (clang::Module *
used :
m->DirectUses) {
2851 for (
auto HK : {clang::Module::HK_Normal, clang::Module::HK_Textual, clang::Module::HK_Private,
2852 clang::Module::HK_PrivateTextual}) {
2869 static char t[4096];
2870 static const char*
constwd =
"const ";
2879 if (
lev==0 && *s==
'*')
continue;
2885 if (
lev==0 && *s==
' ' && *(s+1)!=
'*') {
p = t;
continue;}
2886 if (
p - t > (
long)
sizeof(t)) {
2887 printf(
"ERROR (rootcling): type name too long for StortTypeName: %s\n",
2900 const cling::Interpreter&
interp)
2905 if (!comment.empty() && comment[0] ==
'!')
2908 clang::QualType
type =
m.getType();
2910 if (
type->isReferenceType()) {
2915 std::string
mTypeName =
type.getAsString(
m.getASTContext().getPrintingPolicy());
2927 const clang::Type *
rawtype =
type.getTypePtr()->getBaseElementTypeUnsafe ();
2929 if (
rawtype->isPointerType()) {
2943 const clang::CXXRecordDecl *
cxxdecl =
rawtype->getAsCXXRecordDecl();
2960 const clang::Type *
rawtype =
m.getType().getTypePtr();
2984 return rawtype->getAsCXXRecordDecl();
2993 const cling::Interpreter &
interp,
2999 const clang::CXXRecordDecl*
decl = llvm::dyn_cast<clang::CXXRecordDecl>(cl.
GetRecordDecl());
3001 if (!
decl || !
decl->isCompleteDefinition()) {
3005 std::string fullname;
3019 ROOT::TMetaUtils::Info(
nullptr,
"Class %s: Do not generate Streamer() [*** custom streamer ***]\n",fullname.c_str());
3044 const clang::ASTContext&
Ctx =
interpreter.getCI()->getASTContext();
3050 if (llvm::isa<clang::PointerType>(
instanceType.getTypePtr())) {
3064 if (llvm::isa<clang::ReferenceType>(
instanceType.getTypePtr())) {
3084 clang::NestedNameSpecifier *prefix =
nullptr;
3086 const clang::ElaboratedType* etype
3087 = llvm::dyn_cast<clang::ElaboratedType>(
instanceType.getTypePtr());
3092 instanceType = clang::QualType(etype->getNamedType().getTypePtr(),0);
3098 const clang::TemplateSpecializationType*
TST
3099 = llvm::dyn_cast<const clang::TemplateSpecializationType>(
instanceType.getTypePtr());
3101 const clang::ClassTemplateSpecializationDecl*
TSTdecl
3102 = llvm::dyn_cast_or_null<const clang::ClassTemplateSpecializationDecl>(
instanceType.getTypePtr()->getAsCXXRecordDecl());
3118 clang::TemplateDecl *
Template =
TSTdecl->getSpecializedTemplate()->getMostRecentDecl();
3119 clang::TemplateParameterList *Params =
Template->getTemplateParameters();
3126 llvm::SmallVector<clang::TemplateArgument, 4>
desArgs;
3127 llvm::SmallVector<clang::TemplateArgument, 4>
canonArgs;
3141 if (
I->getKind() == clang::TemplateArgument::Template) {
3148 clang::NamespaceDecl* ns = clang::dyn_cast<clang::NamespaceDecl>(
declCtxt);
3149 clang::NestedNameSpecifier*
nns;
3151 nns = cling::utils::TypeName::CreateNestedNameSpecifier(
Ctx, ns);
3152 }
else if (clang::TagDecl*
TD = llvm::dyn_cast<clang::TagDecl>(
declCtxt)) {
3153 nns = cling::utils::TypeName::CreateNestedNameSpecifier(
Ctx,
TD,
false );
3160 if (clang::UsingShadowDecl *
USD =
templateName.getAsUsingShadowDecl())
3170 if (
I->getKind() != clang::TemplateArgument::Type) {
3175 clang::QualType
SubTy =
I->getAsType();
3197 if (
templateArg.getKind() != clang::TemplateArgument::Type) {
3206 clang::TemplateTypeParmDecl *
TTP = llvm::dyn_cast<clang::TemplateTypeParmDecl>(*
Param);
3209 cling::Interpreter::PushTransactionRAII
clingRAII(
const_cast<cling::Interpreter*
>(&
interpreter));
3211 clang::TemplateArgumentLoc
ArgType = S.SubstDefaultTemplateArgumentIfAvailable(
3221 if (
ArgType.getArgument().isNull()
3222 ||
ArgType.getArgument().getKind() != clang::TemplateArgument::Type) {
3224 "Template parameter substitution failed for %s around %s\n",
3244 TST->getCanonicalTypeInternal());
3273 llvm::StringRef title;
3276 if (clang::AnnotateAttr *A =
m.getAttr<clang::AnnotateAttr>())
3277 title = A->getAnnotation();
3291 if (title.size() == 0 || (title[0] !=
'['))
return llvm::StringRef();
3293 if (
rightbracket == llvm::StringRef::npos)
return llvm::StringRef();
3312 char *current =
const_cast<char*
>(
working.c_str());
3318 for(i=0;i<
strlen(current);i++) {
3326 return llvm::StringRef();
3331 const clang::CXXRecordDecl *
parent_clxx = llvm::dyn_cast<clang::CXXRecordDecl>(
m.getDeclContext());
3332 const clang::FieldDecl *
index1 =
nullptr;
3345 if (
field_iter->getNameAsString() ==
m.getNameAsString() ) {
3353 return llvm::StringRef();
3365 return llvm::StringRef();
3390 return llvm::StringRef();
3392 if ( found && (
index1->getAccess() == clang::AS_private) ) {
3397 return llvm::StringRef();
3406 return llvm::StringRef();
3427 while((
c =
in[i++])) {
3428 const char *
repl =
nullptr;
3430 case '+':
repl =
"pL";
break;
3431 case '-':
repl =
"mI";
break;
3432 case '*':
repl =
"mU";
break;
3433 case '/':
repl =
"dI";
break;
3434 case '&':
repl =
"aN";
break;
3435 case '%':
repl =
"pE";
break;
3436 case '|':
repl =
"oR";
break;
3437 case '^':
repl =
"hA";
break;
3438 case '>':
repl =
"gR";
break;
3439 case '<':
repl =
"lE";
break;
3440 case '=':
repl =
"eQ";
break;
3441 case '~':
repl =
"wA";
break;
3442 case '.':
repl =
"dO";
break;
3443 case '(':
repl =
"oP";
break;
3444 case ')':
repl =
"cP";
break;
3445 case '[':
repl =
"oB";
break;
3446 case ']':
repl =
"cB";
break;
3447 case '{':
repl =
"lB";
break;
3448 case '}':
repl =
"rB";
break;
3449 case ';':
repl =
"sC";
break;
3450 case '#':
repl =
"hS";
break;
3451 case '?':
repl =
"qM";
break;
3452 case '`':
repl =
"bT";
break;
3453 case '!':
repl =
"nO";
break;
3454 case ',':
repl =
"cO";
break;
3455 case '$':
repl =
"dA";
break;
3456 case ' ':
repl =
"sP";
break;
3457 case ':':
repl =
"cL";
break;
3458 case '"':
repl =
"dQ";
break;
3459 case '@':
repl =
"aT";
break;
3460 case '\'':
repl =
"sQ";
break;
3461 case '\\':
repl =
"fI";
break;
3470 if (out.empty() ||
isdigit(out[0]))
3471 out.insert(out.begin(),
'_');
3474static clang::SourceLocation
3488 const cling::Interpreter&
interp)
3518 using namespace clang;
3543 ArrayRef<std::pair<OptionalFileEntryRef, DirectoryEntryRef>>(),
3558 assert(
decl.isFirstDecl() &&
"Couldn't trace back include from a decl"
3559 " that is not from an AST file");
3584 clang::OptionalFileEntryRef
FELong;
3586 for (llvm::sys::path::const_iterator
3599 &&
"Mismatched partitioning of file name!");
3603 ArrayRef<std::pair<OptionalFileEntryRef, DirectoryEntryRef>>(),
3615 for (llvm::sys::path::reverse_iterator
3623 &&
"Mismatched partitioning of file name!");
3629 ArrayRef<std::pair<OptionalFileEntryRef, DirectoryEntryRef>>(),
3632 nullptr,
nullptr ) ==
FELong) {
3643 const clang::QualType &
qtype,
3655 const clang::QualType &
qtype,
3661 cling::Interpreter::PushTransactionRAII
RAII(
const_cast<cling::Interpreter*
>(&
interpreter));
3673 clang::ClassTemplateDecl*&
ctd,
3674 clang::ClassTemplateSpecializationDecl*&
ctsd)
3676 using namespace clang;
3684 if (
theType->isPointerType()) {
3689 ctsd = llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(
rType->getDecl());
3691 ctd =
ctsd->getSpecializedTemplate();
3701 ctsd = llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(
qt->getAsCXXRecordDecl());
3703 ctd =
ctsd->getSpecializedTemplate();
3718 using namespace clang;
3734 using namespace clang;
3753 const clang::NamedDecl&
tPar,
3754 const cling::Interpreter&
interp,
3758 using namespace clang;
3763 if (!
ttpdPtr->hasDefaultArgument())
return false;
3785 const clang::ElaboratedType* etype
3786 = llvm::dyn_cast<clang::ElaboratedType>(
tParQualType.getTypePtr());
3788 tParQualType = clang::QualType(etype->getNamedType().getTypePtr(),0);
3789 etype = llvm::dyn_cast<clang::ElaboratedType>(
tParQualType.getTypePtr());
3793 llvm::dyn_cast<TemplateSpecializationType>(
tParQualType.getTypePtr());
3799 = llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(
tArgQualType->getAsCXXRecordDecl());
3817 clang::Sema& S =
interp.getCI()->getSema();
3818 cling::Interpreter::PushTransactionRAII
clingRAII(
const_cast<cling::Interpreter*
>(&
interp));
3819 llvm::SmallVector<clang::TemplateArgument, 4>
canonArgs;
3832 newArg.getKind() != clang::TemplateArgument::Type) {
3834 "Template parameter substitution failed!");
3838 = llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(
newArg.getAsType()->getAsCXXRecordDecl());
3854 const clang::NamedDecl&
tPar)
3856 using namespace clang;
3861 if (!
nttpd.hasDefaultArgument())
3866 if (Expr*
defArgExpr =
nttpd.getDefaultArgument().getArgument().getAsExpr()) {
3872 const int value =
tArg.getAsIntegral().getLimitedValue();
3885 using namespace clang;
3886 if (!
nDecl)
return false;
3888 return ttpd->hasDefaultArgument();
3890 return nttpd->hasDefaultArgument();
3897 const cling::Interpreter&
interp,
3902 const clang::TemplateArgument &
tArg,
3903 const cling::Interpreter&
interp,
3905 const clang::ASTContext&
astCtxt)
3908 using namespace clang;
3915 if (
tArg.getKind() == clang::TemplateArgument::Type) {
3924 }
else if (
normTArg.getKind() == clang::TemplateArgument::Pack) {
3925 assert(
tArg.getKind() == clang::TemplateArgument::Pack );
3953 const cling::Interpreter&
interp,
3957 using namespace clang;
3966 const int nArgsToKeep =
normCtxt.GetNargsToKeep(
ctd);
3976 if (llvm::isa<clang::PointerType>(
normalizedType.getTypePtr())) {
3989 if (llvm::isa<clang::ReferenceType>(
normalizedType.getTypePtr())) {
4008 clang::NestedNameSpecifier* prefix =
nullptr;
4010 const clang::ElaboratedType* etype
4011 = llvm::dyn_cast<clang::ElaboratedType>(
normalizedType.getTypePtr());
4017 normalizedType = clang::QualType(etype->getNamedType().getTypePtr(),0);
4025 clang::TemplateParameterList*
tpl =
rd->getTemplateParameters();
4026 if (
tpl->getMinRequiredArguments () <
tpl->size()) {
4033 Error(
"KeepNParams",
"Not found template default arguments\n");
4050 llvm::dyn_cast<TemplateSpecializationType>(
normalizedType.getTypePtr());
4056 const clang::ClassTemplateSpecializationDecl*
TSTdecl
4057 = llvm::dyn_cast_or_null<const clang::ClassTemplateSpecializationDecl>(
normalizedType.getTypePtr()->getAsCXXRecordDecl());
4065 llvm::SmallVector<TemplateArgument, 4>
argsToKeep;
4078 Error(
"KeepNParams",
"The parameter number %s is null.\n",
formal);
4100 if (
tParPtr->isTemplateParameterPack() ) {
4132 if (
argKind == clang::TemplateArgument::Type){
4135 }
else if (
argKind == clang::TemplateArgument::Integral){
4187 cling::Interpreter::PushTransactionRAII
RAII(
const_cast<cling::Interpreter*
>(&
interpreter));
4210 if (
type.isNull()) {
4218 clang::PrintingPolicy
policy(
ctxt.getPrintingPolicy());
4219 policy.SuppressTagKeyword =
true;
4220 policy.SuppressScope =
true;
4221 policy.AnonymousTagLocations =
false;
4229 cling::Interpreter::PushTransactionRAII
clingRAII(
const_cast<cling::Interpreter*
>(&
interpreter));
4262 clang::ASTContext&
astCtxt =
sema.getASTContext();
4272std::pair<std::string,clang::QualType>
4293 cling::LookupHelper::DiagSetting::NoDiagnostics,
4312 "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());
4340 llvm::errs() << llvm::StringRef(
commentStart, 80) <<
'\n';
4389 if (
const clang::FunctionDecl*
FD = clang::dyn_cast<clang::FunctionDecl>(&
decl)) {
4390 if (
FD->isImplicit()) {
4394 if (
FD->isExplicitlyDefaulted() ||
FD->isDeletedAsWritten()) {
4398 }
else if (
FD->doesThisDeclarationHaveABody()) {
4403 &&
"Expected macro or end of body at '}'");
4415 }
else if (
const clang::EnumConstantDecl*
ECD
4416 = clang::dyn_cast<clang::EnumConstantDecl>(&
decl)) {
4418 if (
ECD->getNextDeclInContext())
4495 if (!
decl)
return false;
4502 static const std::vector<std::string>
signatures =
4503 {
"ClassDef",
"ClassDefOverride",
"ClassDefNV",
"ClassDefInline",
"ClassDefInlineOverride",
"ClassDefInlineNV" };
4520 clang::SourceLocation *
loc,
4523 using namespace clang;
4526 =
interpreter.getLookupHelper().findFunctionProto(&
decl,
"DeclFileLine",
"",
4527 cling::LookupHelper::NoDiagnostics);
4533 if (comment.size()) {
4540 return llvm::StringRef();
4552 if (
rawtype->isElaboratedTypeSpecifier() ) {
4556 rawtype =
type.getTypePtr()->getBaseElementTypeUnsafe ();
4565 if (
rawtype->isElaboratedTypeSpecifier() ) {
4585 if (
ctxt.isNamespace() ||
ctxt.isTranslationUnit())
4587 else if(
const auto parentdecl = llvm::dyn_cast<clang::CXXRecordDecl>(&
ctxt))
4600 const clang::DeclContext *
ctxt =
decl.getDeclContext();
4601 switch (
decl.getAccess()) {
4602 case clang::AS_public:
4604 case clang::AS_protected:
4606 case clang::AS_private:
4608 case clang::AS_none:
4612 assert(
false &&
"Unexpected value for the access property value in Clang");
4622 return cling::utils::Analyze::IsStdClass(cl);
4632 if (cling::utils::Analyze::IsStdClass(cl)) {
4633 static const char *names[] =
4634 {
"shared_ptr",
"__shared_ptr",
4635 "vector",
"list",
"deque",
"map",
"multimap",
"set",
"multiset",
"bitset"};
4636 llvm::StringRef
clname(cl.getName());
4637 for(
auto &&
name : names) {
4675 const clang::CXXRecordDecl *
thisDecl =
4676 llvm::dyn_cast_or_null<clang::CXXRecordDecl>(
lh.findScope(
typ, cling::LookupHelper::WithDiagnostics));
4680 Error(
"IsOfType",
"Record decl of type %s not found in the AST.",
typ.c_str());
4710 if (!IsStdClass(cl)) {
4711 auto *
nsDecl = llvm::dyn_cast<clang::NamespaceDecl>(cl.getDeclContext());
4712 if (cl.getName() !=
"RVec" ||
nsDecl ==
nullptr ||
nsDecl->getName() !=
"VecOps")
4715 auto *
parentNsDecl = llvm::dyn_cast<clang::NamespaceDecl>(cl.getDeclContext()->getParent());
4720 return STLKind(cl.getName());
4724 using namespace clang;
4725 struct SearchTypedef:
public TypeVisitor<SearchTypedef, bool> {
4730 return Visit(
AT->getElementType().getTypePtr());
4733 return Visit(
DT->getUnderlyingType().getTypePtr());
4736 return Visit(
PT->getPointeeType().getTypePtr());
4739 return Visit(
RT->getPointeeType().getTypePtr());
4742 return Visit(
STST->getReplacementType().getTypePtr());
4746 if (
TA.getKind() == TemplateArgument::Type && Visit(
TA.getAsType().getTypePtr()))
4755 return TOT->getUnmodifiedType().getTypePtr();
4760 if (
NNS->getKind() == NestedNameSpecifier::TypeSpec) {
4761 if (Visit(
NNS->getAsType()))
4766 return Visit(
ET->getNamedType().getTypePtr());
4787 using namespace llvm;
4788 using namespace clang;
4789 const clang::ASTContext &
Ctxt =
instance->getAsCXXRecordDecl()->getASTContext();
4792 const clang::ElaboratedType* etype
4793 = llvm::dyn_cast<clang::ElaboratedType>(
input.getTypePtr());
4798 assert(
instance->getAsCXXRecordDecl() !=
nullptr &&
"ReSubstTemplateArg only makes sense with a type representing a class.");
4818 if (
nQT ==
QT->getPointeeType())
return QT;
4834 if (
nQT ==
QT->getPointeeType())
return QT;
4855 if (
newQT ==
arr->getElementType())
return QT;
4859 arr->getSizeModifier(),
4860 arr->getIndexTypeCVRQualifiers());
4868 arr->getSizeModifier(),
4869 arr->getIndexTypeCVRQualifiers(),
4870 arr->getBracketsRange());
4875 if (
newQT ==
arr->getElementType())
return QT;
4877 arr->getSizeModifier(),
4878 arr->getIndexTypeCVRQualifiers());
4883 if (
newQT ==
arr->getElementType())
return QT;
4886 arr->getSizeModifier(),
4887 arr->getIndexTypeCVRQualifiers(),
4888 arr->getBracketsRange());
4897 etype = llvm::dyn_cast<clang::ElaboratedType>(
instance);
4899 instance = etype->getNamedType().getTypePtr();
4903 const clang::TemplateSpecializationType*
TST
4904 = llvm::dyn_cast<const clang::TemplateSpecializationType>(
instance);
4908 const clang::ClassTemplateSpecializationDecl*
TSTdecl
4909 = llvm::dyn_cast_or_null<const clang::ClassTemplateSpecializationDecl>(
instance->getAsCXXRecordDecl());
4913 const clang::SubstTemplateTypeParmType *
substType
4914 = llvm::dyn_cast<clang::SubstTemplateTypeParmType>(
input.getTypePtr());
4918 const clang::ClassTemplateDecl *
replacedCtxt =
nullptr;
4922 unsigned int index =
substType->getReplacedParameter()->getIndex();
4925 if (
decl->getKind() == clang::Decl::ClassTemplatePartialSpecialization) {
4926 const clang::ClassTemplatePartialSpecializationDecl *
spec = llvm::dyn_cast<clang::ClassTemplatePartialSpecializationDecl>(
decl);
4928 unsigned int depth =
substType->getReplacedParameter()->getDepth();
4944 const clang::SubstTemplateTypeParmType *
argType
4945 = llvm::dyn_cast<clang::SubstTemplateTypeParmType>(
argQualType);
4970 llvm::raw_string_ostream ostream(
astDump);
4973 ROOT::TMetaUtils::Warning(
"ReSubstTemplateArg",
"Unexpected type of declaration context for template parameter: %s.\n\tThe responsible class is:\n\t%s\n",
4980 const auto &
TAs =
TST->template_arguments();
4997 const clang::TemplateSpecializationType*
inputTST
4998 = llvm::dyn_cast<const clang::TemplateSpecializationType>(
input.getTypePtr());
5003 llvm::SmallVector<clang::TemplateArgument, 4>
desArgs;
5004 for (
const clang::TemplateArgument &
TA :
inputTST->template_arguments()) {
5005 if (
TA.getKind() != clang::TemplateArgument::Type) {
5010 clang::QualType
SubTy =
TA.getAsType();
5012 if (llvm::isa<clang::ElaboratedType>(
SubTy)
5013 || llvm::isa<clang::SubstTemplateTypeParmType>(
SubTy)
5014 || llvm::isa<clang::TemplateSpecializationType>(
SubTy)) {
5029 inputTST->getCanonicalTypeInternal());
5070 static const char *
stls[] =
5071 {
"any",
"vector",
"list",
"deque",
"map",
"multimap",
"set",
"multiset",
"bitset",
5072 "forward_list",
"unordered_set",
"unordered_multiset",
"unordered_map",
"unordered_multimap",
"RVec",
nullptr};
5086 for (
int k = 1;
stls[k]; k++) {
5100 TND =
TND->getMostRecentDecl();
5101 while (
TND && !(
TND->hasAttrs()))
5102 TND =
TND->getPreviousDecl();
5114 TD =
TD->getMostRecentDecl();
5115 while (
TD && !(
TD->hasAttrs() &&
TD->isThisDeclarationADefinition()))
5116 TD =
TD->getPreviousDecl();
5172 std::list<std::pair<std::string,unsigned int> >&
enclosingSc)
5200 std::string::size_type
beginVar = 0;
5201 std::string::size_type
endVar = 0;
5205 std::string::size_type
endVarName = std::string::npos;
5247 const char*
envInclPath = std::getenv(
"ROOT_INCLUDE_PATH");
5282 str.replace(
start_pos, from.length(), to);
5349 return llvm::sys::path::extension(
filename) ==
".h" ||
5350 llvm::sys::path::extension(
filename) ==
".hh" ||
5351 llvm::sys::path::extension(
filename) ==
".hpp" ||
5352 llvm::sys::path::extension(
filename) ==
".H" ||
5353 llvm::sys::path::extension(
filename) ==
".h++" ||
5354 llvm::sys::path::extension(
filename) ==
"hxx" ||
5355 llvm::sys::path::extension(
filename) ==
"Hxx" ||
5356 llvm::sys::path::extension(
filename) ==
"HXX";
5362 cling::Interpreter::IgnoreFilesFunc_t
ignoreFiles,
5363 const cling::Interpreter &
interp,
5371 clang::Decl *
ncDecl =
const_cast<clang::Decl *
>(
decl);
5416 static const std::string
scopeType [] = {
"namespace ",
"inline namespace ",
"class "};
5458 std::string typeName;
5461 if (llvm::isa<clang::TemplateTypeParmDecl>(
nDecl)){
5462 typeName =
"typename ";
5463 if (
nDecl->isParameterPack())
5465 typeName += (*prmIt)->getNameAsString();
5468 else if (
auto nttpd = llvm::dyn_cast<clang::NonTypeTemplateParmDecl>(
nDecl)){
5472 if (
theType.getAsString().find(
"enum") != std::string::npos){
5474 llvm::raw_string_ostream ostream(
astDump);
5475 nttpd->dump(ostream);
5486 else if (
auto ttpd = llvm::dyn_cast<clang::TemplateTemplateParmDecl>(
nDecl)){
5490 llvm::raw_string_ostream ostream(
astDump);
5491 ttpd->dump(ostream);
5516 "Cannot extract template parameter list for %s",
5524 "Problems with arguments for forward declaration of class %s\n",
5534 if (llvm::isa<clang::TemplateTemplateParmDecl>(&
templDecl)) {
5556 if (clang::TemplateArgument::Type != arg.getKind())
return 0;
5571 if (llvm::isa<clang::BuiltinType>(
argTypePtr)){
5604 if (
specDef->getTemplateSpecializationKind() != clang::TSK_ExplicitSpecialization)
5608 std::cout <<
" Forward declaring template spec " <<
normalizedName <<
":\n";
5613 std::cout <<
" o Template argument ";
5615 std::cout <<
"successfully treated. Arg fwd decl: " <<
argFwdDecl << std::endl;
5617 std::cout <<
"could not be treated. Abort fwd declaration generation.\n";
5658 std::cout <<
"Class " <<
recordDecl.getNameAsString()
5659 <<
" is a template specialisation. Treating its arguments.\n";
5663 std::cout <<
" o Template argument ";
5665 std::cout <<
"successfully treated. Arg fwd decl: " <<
argFwdDecl << std::endl;
5667 std::cout <<
"could not be treated. Abort fwd declaration generation.\n";
5715 std::string buffer =
tdnDecl.getNameAsString();
5718 if (
const clang::TagType* TT
5720 if (clang::NamedDecl*
ND = TT->getDecl()) {
5721 if (!
ND->getIdentifier()) {
5765 std::cout <<
"Typedef " <<
tdnDecl.getNameAsString() <<
" hides a class: "
5792 const clang::PrintingPolicy&
ppolicy)
5795 auto&
ctxt = par.getASTContext();
5816 if (
result.isNegative()){
The file contains utilities which are foundational and could be used across the core component of ROO...
#define R(a, b, c, d, e, f, g, h, i)
static Roo_reg_AGKInteg1D instance
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
short Version_t
Class version identifier (short)
static void indent(ostringstream &buf, int indent_level)
static bool RecurseKeepNParams(clang::TemplateArgument &normTArg, const clang::TemplateArgument &tArg, const cling::Interpreter &interp, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt, const clang::ASTContext &astCtxt)
static clang::SourceLocation getFinalSpellingLoc(clang::SourceManager &sourceManager, clang::SourceLocation sourceLoc)
const clang::DeclContext * GetEnclosingSpace(const clang::RecordDecl &cl)
bool IsTemplate(const clang::Decl &cl)
static void KeepNParams(clang::QualType &normalizedType, const clang::QualType &vanillaType, const cling::Interpreter &interp, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt)
This function allows to manipulate the number of arguments in the type of a template specialisation.
static void CreateNameTypeMap(const clang::CXXRecordDecl &cl, ROOT::MembersTypeMap_t &nameType)
Create the data member name-type map for given class.
const clang::CXXMethodDecl * GetMethodWithProto(const clang::Decl *cinfo, const char *method, const char *proto, const cling::Interpreter &interp, bool diagnose)
int dumpDeclForAssert(const clang::Decl &D, const char *commentStart)
static void replaceEnvVars(const char *varname, std::string &txt)
Reimplementation of TSystem::ExpandPathName() that cannot be used from TMetaUtils.
static bool areEqualValues(const clang::TemplateArgument &tArg, const clang::NamedDecl &tPar)
std::cout << "Are equal values?\n";
static bool isTypeWithDefault(const clang::NamedDecl *nDecl)
Check if this NamedDecl is a template parameter with a default argument.
static int TreatSingleTemplateArg(const clang::TemplateArgument &arg, std::string &argFwdDecl, const cling::Interpreter &interpreter, bool acceptStl=false)
static bool areEqualTypes(const clang::TemplateArgument &tArg, llvm::SmallVectorImpl< clang::TemplateArgument > &preceedingTArgs, const clang::NamedDecl &tPar, const cling::Interpreter &interp, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt)
static bool hasSomeTypedefSomewhere(const clang::Type *T)
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void input
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t dest
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t target
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h length
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
Option_t Option_t TPoint TPoint const char mode
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
const_iterator begin() const
const_iterator end() const
A RAII helper to remove and readd enclosing _Atomic() It expects no spaces at the beginning or end of...
const std::string & GetPathSeparator()
void WriteSchemaList(std::list< SchemaRuleMap_t > &rules, const std::string &listName, std::ostream &output)
Write schema rules.
std::map< std::string, ROOT::Internal::TSchemaType > MembersTypeMap_t
void WriteReadRuleFunc(SchemaRuleMap_t &rule, int index, std::string &mappedName, MembersTypeMap_t &members, std::ostream &output)
Write the conversion function for Read rule, the function name is being written to rule["funcname"].
R__EXTERN SchemaRuleClassMap_t gReadRules
bool HasValidDataMembers(SchemaRuleMap_t &rule, MembersTypeMap_t &members, std::string &error_string)
Check if given rule contains references to valid data members.
void WriteReadRawRuleFunc(SchemaRuleMap_t &rule, int index, std::string &mappedName, MembersTypeMap_t &members, std::ostream &output)
Write the conversion function for ReadRaw rule, the function name is being written to rule["funcname"...
R__EXTERN SchemaRuleClassMap_t gReadRawRules
ROOT::ESTLType STLKind(std::string_view type)
Converts STL container name to number.
bool IsStdClass(const char *type)
return true if the class belongs to the std namespace
std::string GetLong64_Name(const char *original)
Replace 'long long' and 'unsigned long long' by 'Long64_t' and 'ULong64_t'.
ROOT::ESTLType IsSTLCont(std::string_view type)
type : type name: vector<list<classA,allocator>,allocator> result: 0 : not stl container code of cont...
char * DemangleName(const char *mangled_name, int &errorCode)
std::string GetNameForIO(const std::string &templateInstanceName, TClassEdit::EModType mode=TClassEdit::kNone, bool *hasChanged=nullptr)
void GetNormalizedName(std::string &norm_name, std::string_view name)
Return the normalized name.
bool IsSTLBitset(const char *type)
Return true is the name is std::bitset<number> or bitset<number>
constexpr Double_t C()
Velocity of light in .