24#include "TClingUtils.h"
30#include "clang/Basic/SourceLocation.h"
31#include "clang/Basic/SourceManager.h"
32#include "clang/AST/DeclCXX.h"
33#include "clang/AST/ASTContext.h"
34#include "clang/AST/DeclTemplate.h"
43 clang::ASTContext& ctx = D->getASTContext();
44 clang::SourceManager& SM = ctx.getSourceManager();
45 clang::SourceLocation SL = D->getLocation();
50 SL = SM.getExpansionLoc(SL);
52 if (SL.isValid() && SL.isFileID()) {
53 clang::PresumedLoc PLoc = SM.getPresumedLoc(SL);
54 return PLoc.getFilename();
66 if((strcmp(srcname,filename)==0)) {
71 char i1name[_MAX_PATH];
72 char fullfile[_MAX_PATH];
73 _fullpath( i1name, srcname, _MAX_PATH );
74 _fullpath( fullfile, filename, _MAX_PATH );
75 if((stricmp(i1name, fullfile)==0))
return 1;
77 struct stat statBufItem;
79 if ( ( 0 == stat( filename, & statBufItem ) )
80 && ( 0 == stat( srcname, & statBuf ) )
81 && ( statBufItem.st_dev == statBuf.st_dev )
82 && ( statBufItem.st_ino == statBuf.st_ino )
83 && ( statBufItem.st_size == statBuf.st_size )
84 && ( statBufItem.st_mtime == statBuf.st_mtime )
93 : fIndex(index),fLineNumber(lineno),fSelFileName(selFileName),fIsSelected(sel),fMatchFound(false),fCXXRecordDecl(0),fRequestedType(0),fInterp(&interp)
95 fAttributes.insert(AttributesMap_t::value_type(attributeName, attributeValue));
110 AttributesMap_t::const_iterator iter =
fAttributes.find(attributeName);
118 AttributesMap_t::const_iterator iter =
fAttributes.find(attributeName);
121 returnValue = retVal ? iter->second :
"";
128 std::string localAttributeValue(attributeValue);
130 int pos = attributeName.find(
"pattern");
131 int pos_file = attributeName.find(
"file_pattern");
134 if (attributeName ==
"name" || pos> -1){
135 while(std::isspace(*localAttributeValue.begin())) localAttributeValue.erase(localAttributeValue.begin());
136 while(std::isspace(*localAttributeValue.rbegin()))localAttributeValue.erase(localAttributeValue.length()-1);
138 fAttributes.insert(AttributesMap_t::value_type(attributeName, localAttributeValue));
163 for (
int i = 0; i < level; ++i) {
169 for (
auto&& attr : orderedAttributes) {
170 out<<tabs<<attr.first<<
" = "<<attr.second<<std::endl;
174 out<<tabs<<
"No attributes"<<std::endl;
186 const std::string&
name,
187 const std::string& prototype,
188 bool isLinkdef)
const
207 const std::string& name_value =
fName;
208 const std::string& pattern_value =
fPattern;
211 const clang::CXXRecordDecl *D = llvm::dyn_cast<clang::CXXRecordDecl>(decl);
212 bool isTypedefNametoRecordDecl =
false;
216 const clang::TypedefNameDecl* typedefNameDecl = llvm::dyn_cast<clang::TypedefNameDecl> (decl);
217 isTypedefNametoRecordDecl = typedefNameDecl &&
218 ROOT::TMetaUtils::GetUnderlyingRecordDecl(typedefNameDecl->getUnderlyingType());
223 if ( target && D && target == D ) {
229 if (name_value ==
name) {
233 (
fCXXRecordDecl != (
void*)-1 && isTypedefNametoRecordDecl && !decl->hasOwningModule())){
236 const clang::CXXRecordDecl *target
246 if ( target && D && target == D ) {
254 const std::string& file_name_value =
fFileName;
267 if (!strncmp(
name.c_str(),
"R__Init", 7) ||
268 strstr(
name.c_str(),
"::R__Init")) {
271 if (!
name.compare(0, 24,
"ROOT::R__dummyintdefault")) {
274 if (!
name.compare(0, 27,
"ROOT::R__dummyVersionNumber")) {
277 if (!
name.compare(0, 22,
"ROOT::R__dummyStreamer")) {
280 if (
name.find(
"(anonymous namespace)") != std::string::npos) {
303 if (!patternMatched && !isLinkdef) {
304 std::string auxName(
name);
305 std::string &nameNoSpaces = auxName;
306 nameNoSpaces.erase(std::remove_if(nameNoSpaces.begin(), nameNoSpaces.end(), isspace),
308 if (
name.size() != nameNoSpaces.size()) {
319 if (!patternMatched &&
324 if (
name.size() != auxName.size()) {
331 if (patternMatched) {
351 if (!prototype.empty()) {
375 std::string temp = pattern;
380 if (pattern.size()==1 && pattern ==
"*"){
385 while (!temp.empty()){
386 pos = temp.find(
"*");
394 out.push_back(split);
400 temp = temp.substr(1);
402 else if (pos == (
int)(temp.length()-1)) {
403 if (pos > 0 && temp.at(pos-1) ==
'\\') {
404 split += temp.substr(0, temp.length()-2);
405 split += temp.at(pos);
406 out.push_back(split);
410 temp = temp.substr(0, (temp.length()-1));
413 if (pos > 0 && temp.at(pos-1) ==
'\\') {
414 split += temp.substr(0, pos-1);
415 split += temp.at(pos);
419 temp = temp.substr(pos);
424 split += temp.substr(0, pos);
427 split = temp.substr(0, pos);
430 temp = temp.substr(pos);
431 out.push_back(split);
447 bool begin = pattern.front() ==
'*';
448 if (pattern.size() == 1 && begin) {
453 std::list<std::string>::const_iterator it = patterns_list.begin();
454 size_t pos1, pos2, pos3;
455 pos1= pos2= pos3= std::string::npos;
456 bool end = pattern.back() ==
'*';
459 const std::string& last = patterns_list.back();
460 size_t pos_end =
test.rfind(last);
462 if (pos_end == std::string::npos) {
468 int len = last.length();
469 if ((pos_end+len) <
test.length()) {
475 pos1 =
test.find(*it);
478 if (pos1 == std::string::npos || (!begin && pos1 != 0)) {
486 int len = (*it).length();
487 int pos_colon =
test.find(
"::", pos1+len);
489 if (pos_colon > -1) {
495 if (patterns_list.size() > 1) {
496 if (((*it).length())+pos1 > pos_end) {
505 for (; it != patterns_list.end(); ++it) {
507 pos2 =
test.find(*it);
556 std::cout<<
"Error - A pattern selection without sub patterns." <<std::endl;
static bool R__match_filename(const char *srcname, const char *filename)
static const char * R__GetDeclSourceFileName(const clang::Decl *D)
void SetAttributeValue(const std::string &attributeName, const std::string &attributeValue)
bool fHasFilePatternAttribute
bool GetAttributeValue(const std::string &attributeName, std::string &returnValue) const
bool CheckPattern(const std::string &test, const std::string &pattern, const std::list< std::string > &patterns_list, bool isLinkdef) const
bool fHasPatternAttribute
void SetSelected(ESelect sel)
void ProcessPattern(const std::string &pattern, std::list< std::string > &out) const
const clang::CXXRecordDecl * fCXXRecordDecl
bool fHasProtoNameAttribute
std::list< std::string > fSubPatterns
virtual void DebugPrint() const
EMatchType Match(const clang::NamedDecl *decl, const std::string &name, const std::string &prototype, bool isLinkdef) const
void SetCXXRecordDecl(const clang::CXXRecordDecl *decl, const clang::Type *typeptr)
bool GetMatchFound() const
const clang::Type * GetRequestedType() const
std::string fProtoPattern
const AttributesMap_t & GetAttributes() const
ESelect GetSelected() const
bool HasAttributeWithName(const std::string &attributeName) const
AttributesMap_t fAttributes
bool fHasProtoPatternAttribute
cling::Interpreter * fInterp
const clang::Type * fRequestedType
bool fHasFileNameAttribute
void SetMatchFound(bool match)
std::unordered_map< std::string, std::string > AttributesMap_t
void PrintAttributes(int level) const
std::list< std::string > fFileSubPatterns
BaseSelectionRule(ESelect sel)
virtual void Print(std::ostream &out) const =0
bool fHasFromTypedefAttribute
Type
enumeration specifying the integration types.
std::string InsertStd(const char *tname)
ROOT::ESTLType IsSTLCont(std::string_view type)
type : type name: vector<list<classA,allocator>,allocator> result: 0 : not stl container code of cont...
void GetNormalizedName(std::string &norm_name, std::string_view name)
Return the normalized name.