3#include "clang/AST/AST.h"
5#include "cling/Interpreter/Interpreter.h"
24 : fSelectionRules(selectionRules), fIsFirstPass(true), fNormCtxt(normCtxt)
26 clang::TranslationUnitDecl *translUnitDecl = C.getTranslationUnitDecl();
30 cling::Interpreter::PushTransactionRAII RAII(&interp);
32 TraverseDecl(translUnitDecl);
40 TraverseDecl(translUnitDecl);
43 for (llvm::StringMap<ClassSelectionRule>::iterator it =
64 const std::string &className)
66 std::list<std::pair<std::string, bool> > enclosingNamespaces;
70 const unsigned int nNs = enclosingNamespaces.size();
71 if (nNs < 3)
return false;
73 if (enclosingNamespaces.back().second ||
74 enclosingNamespaces.back().first !=
"ROOT")
77 enclosingNamespaces.pop_back();
78 if (enclosingNamespaces.back().second ||
79 enclosingNamespaces.back().first !=
"Meta")
82 enclosingNamespaces.pop_back();
83 if (enclosingNamespaces.back().second ||
84 enclosingNamespaces.back().first !=
"Selection")
88 if (className !=
"" &&
89 (className.find(
"MemberAttributes") == 0 ||
90 className.find(
"ClassAttributes") == 0 || className.find(
"Keep") == 0))
101const clang::TemplateArgumentList *
104 const clang::ClassTemplateSpecializationDecl *tmplSpecDecl =
105 llvm::dyn_cast<clang::ClassTemplateSpecializationDecl>(&cxxRcrdDecl);
107 if (!tmplSpecDecl)
return nullptr;
109 return &tmplSpecDecl->getTemplateArgs();
122 const std::string &pattern)
124 const clang::RecordDecl *rcrdDecl =
126 const clang::CXXRecordDecl *cxxRcrdDecl =
127 llvm::dyn_cast<clang::CXXRecordDecl>(rcrdDecl);
129 if (!cxxRcrdDecl)
return 0;
131 const clang::TemplateArgumentList *tmplArgs =
GetTmplArgList(*cxxRcrdDecl);
132 if (!tmplArgs)
return 0;
134 if (std::string::npos == cxxRcrdDecl->getNameAsString().find(pattern))
137 return tmplArgs->get(0).getAsIntegral().getLimitedValue();
153 const std::string &className,
157 std::string pattern = className.substr(0, className.find_first_of(
"<"));
159 for (
auto fieldPtr : recordDecl.fields()) {
161 unsigned int attrCode =
166 const char *fieldName = fieldPtr->getName().data();
218 const std::string &className,
221 std::string baseName;
222 clang::ASTContext &C = cxxRcrdDecl.getASTContext();
223 for (
auto & base : cxxRcrdDecl.bases()) {
226 std::string pattern =
227 className.substr(0, className.find_first_of(
"<"));
235 auto qt = base.getType();
237 if (baseName ==
"ROOT::Meta::Selection::SelectNoInstance") autoselect =
false;
252 std::string className;
254 className, *recordDecl.getTypeForDecl(), recordDecl);
257 className.replace(0, 23,
"");
263 bool autoselect =
true;
264 if (
auto cxxRcrdDecl = llvm::dyn_cast<clang::CXXRecordDecl>(&recordDecl)) {
269 const size_t lWedgePos(className.find_first_of(
"<"));
270 std::string patternName(
"");
271 if (lWedgePos != std::string::npos &&
272 llvm::isa<clang::ClassTemplateSpecializationDecl>(recordDecl)) {
282 if (!autoselect)
return true;
314 std::string className;
315 GetQualifiedName(className, *recordDecl.getTypeForDecl(), recordDecl);
323 std::string typeName;
324 clang::ASTContext &C = recordDecl.getASTContext();
325 for (clang::RecordDecl::field_iterator filedsIt =
326 recordDecl.field_begin();
327 filedsIt != recordDecl.field_end();
329 const std::string fieldName(filedsIt->getNameAsString());
332 if (!selected && !excluded)
335 GetFullyQualifiedTypeName(typeName, filedsIt->getType(), C);
346 if (
auto tmplSpecDecl = llvm::dyn_cast<clang::ClassTemplateSpecializationDecl>(&recordDecl)) {
348 const std::string &pattern = patternInfoPair.first;
351 if (className.find(pattern) != 0)
continue;
354 auto ctd = tmplSpecDecl->getSpecializedTemplate();
361 clang::ASTContext &C = recordDecl.getASTContext();
362 clang::SourceRange commentRange;
363 std::string userDefinedProperty;
364 userDefinedProperty.reserve(100);
365 for (
auto fieldPtr : recordDecl.fields()) {
366 const auto fieldName = fieldPtr->getName().data();
368 userDefinedProperty =
"!";
370 userDefinedProperty = propNames::comment + propNames::separator +
"||";
372 if (!userDefinedProperty.empty()) {
373 fieldPtr->addAttr(
new(C) clang::AnnotateAttr(commentRange, C, userDefinedProperty, 0));
374 userDefinedProperty =
"";
402 return className.substr(0, className.find_first_of(
"<")) +
"<*>";
413 while (typeName[typeName.size() - 1] ==
'*' ||
414 typeName[typeName.size() - 1] ==
'&') {
415 typeName = typeName.substr(0, typeName.size() - 1);
Select classes and assign properties using C++ syntax.
void SetAttributeValue(const std::string &attributeName, const std::string &attributeValue)
void AddFieldSelectionRule(const VariableSelectionRule &field)
bool fIsFirstPass
Keep trance of the number of passes through the AST.
llvm::StringMap< ClassSelectionRule > fClassNameSelectionRuleMap
Map of the already built sel rules.
void ManageFields(const clang::RecordDecl &, const std::string &, ClassSelectionRule &, bool)
Take care of the class fields.
ROOT::TMetaUtils::TNormalizedCtxt & fNormCtxt
The reference to the normalized context.
llvm::StringMap< std::set< std::string > > fNoAutoSelectedClassFieldNames
Collect the autoexcluded classes.
llvm::StringMap< std::set< std::string > > fAutoSelectedClassFieldNames
Collect the autoselected classes.
void ManageBaseClasses(const clang::CXXRecordDecl &, const std::string &, bool &)
Take care of the class bases.
bool VisitRecordDecl(clang::RecordDecl *)
Visit the entities that needs to be selected.
const clang::TemplateArgumentList * GetTmplArgList(const clang::CXXRecordDecl &)
Get the template arguments list if any.
std::set< const clang::RecordDecl * > fSelectedRecordDecls
The pointers of the selected RecordDecls.
std::string PatternifyName(const std::string &className)
Transform instance name in pattern for selection.
DictSelectionReader(cling::Interpreter &interp, SelectionRules &, const clang::ASTContext &, ROOT::TMetaUtils::TNormalizedCtxt &)
Take the selection rules as input (for consistency w/ other selector interfaces)
SelectionRules & fSelectionRules
The selection rules to be filled.
void GetPointeeType(std::string &typeName)
Get name of the pointee type.
unsigned int ExtractTemplateArgValue(const T &, const std::string &)
Extract the value of the template parameter.
bool InSelectionNamespace(const clang::RecordDecl &, const std::string &str="")
Check if in the ROOT::Meta::Selection namespace.
std::unordered_map< std::string, TemplateInfo > fTemplateInfoMap
List template name - properties map.
bool FirstPass(const clang::RecordDecl &)
First pass on the AST.
bool SecondPass(const clang::RecordDecl &)
Second pass on the AST, using the information of the first one.
The class representing the collection of selection rules.
void AddClassSelectionRule(const ClassSelectionRule &classSel)
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
std::unordered_set< std::string > fUnsplittableMembers
std::unordered_set< std::string > fTransientMembers