Logo ROOT   master
Reference Guide
BaseSelectionRule.h
Go to the documentation of this file.
1 // @(#)root/core/utils:$Id: BaseSelectionRule.h 28529 2009-05-11 16:43:35Z pcanal $
2 // Author: Velislava Spasova September 2010
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2011, Rene Brun, Fons Rademakers and al. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef R__BASESELECTIONRULE_H
13 #define R__BASESELECTIONRULE_H
14 
15 //////////////////////////////////////////////////////////////////////////
16 // //
17 // BaseSelectionRule //
18 // //
19 // Base selection class from which all //
20 // selection classes should be derived //
21 // //
22 //////////////////////////////////////////////////////////////////////////
23 
24 #include <string>
25 #include <unordered_map>
26 #include <list>
27 #include <iosfwd>
28 
29 namespace clang {
30  class NamedDecl;
31  class CXXRecordDecl;
32  class Type;
33 }
34 namespace cling {
35  class Interpreter;
36 }
37 
39 {
40 public:
41  typedef std::unordered_map<std::string, std::string> AttributesMap_t; // The liste of selection rule's attributes (name, pattern, ...)
42 
43  enum ESelect { // a rule could be selected, vetoed or we don't care about it
45  kNo,
47  };
48  enum EMatchType {
53  };
54 
55 private:
56  long fIndex; // Index indicating the ordering of the rules.
57  long fLineNumber=-1; // Line number of the selection file where the rule is located
58  std::string fSelFileName=""; // Name of the selection file
59  AttributesMap_t fAttributes; // list of the attributes of the selection/exclusion rule
60  ESelect fIsSelected; // selected/vetoed/don't care
61  std::list<std::string> fSubPatterns; // a list of subpatterns, generated form a pattern/proto_pattern attribute
62  std::list<std::string> fFileSubPatterns; // a list of subpatterns, generated form a file_pattern attribute
63  bool fMatchFound; // this is true if this selection rule has been used at least once
64  const clang::CXXRecordDecl *fCXXRecordDecl; // Record decl of the entity searched for.
65  const clang::Type *fRequestedType; // Same as the record decl but with some of the typedef preserved (Double32_t, Float16_t, etc..)
66  cling::Interpreter *fInterp;
67 
68  // Cached for performance
69  std::string fName = "";
70  std::string fPattern = "";
71  std::string fProtoName = "";
72  std::string fProtoPattern = "";
73  std::string fFileName = "";
74  std::string fFilePattern = "";
75  std::string fNArgsToKeep = "";
76  bool fHasNameAttribute = false;
77  bool fHasProtoNameAttribute = false;
78  bool fHasPatternAttribute = false;
80  bool fHasFileNameAttribute = false;
83  bool fIsFromTypedef = false;
84 
85 public:
86 
88 
89  BaseSelectionRule(long index, cling::Interpreter &interp, const char* selFileName = "", long lineno=-1) : fIndex(index),fLineNumber(lineno),fSelFileName(selFileName),fIsSelected(kNo),fMatchFound(false),fCXXRecordDecl(0),fRequestedType(0),fInterp(&interp) {}
90 
91  BaseSelectionRule(long index, ESelect sel, const std::string& attributeName, const std::string& attributeValue, cling::Interpreter &interp, const char* selFileName = "",long lineno=-1);
92 
93  virtual ~BaseSelectionRule() = default;
94 
95  virtual void DebugPrint() const;
96  virtual void Print(std::ostream &out) const = 0;
97 
98  long GetIndex() const { return fIndex; }
99  void SetIndex(long index) { fIndex=index; }
100 
101  long GetLineNumber() const { return fLineNumber; }
102  const char* GetSelFileName() const { return fSelFileName.c_str(); }
103 
104  bool HasAttributeWithName(const std::string& attributeName) const; // returns true if there is an attribute with the specified name
105 
106  void FillCache(); // Fill the cache for performant attribute retrival
107 
108  bool GetAttributeValue(const std::string& attributeName, std::string& returnValue) const; // returns the value of the attribute with name attributeName
109 
110  inline const std::string& GetAttributeName() const {return fName;};
111  inline bool HasAttributeName() const {return fHasNameAttribute;};
112 
113  inline const std::string& GetAttributeProtoName() const {return fProtoName;};
114  inline bool HasAttributeProtoName() const {return fHasProtoNameAttribute;};
115 
116  inline const std::string& GetAttributePattern() const {return fPattern;};
117  inline bool HasAttributePattern() const {return fHasPatternAttribute;};
118 
119  inline const std::string& GetAttributeProtoPattern() const {return fProtoPattern;};
121 
122  inline const std::string& GetAttributeFileName() const {return fFileName;};
123  inline bool HasAttributeFileName() const {return fHasFileNameAttribute;};
124 
125  inline const std::string& GetAttributeFilePattern() const {return fFilePattern;};
126  inline bool HasAttributeFilePattern() const {return fHasFilePatternAttribute;};
127 
128  inline bool IsFromTypedef() const {return fIsFromTypedef;};
129  inline bool HasAttributeFromTypedef() const {return fHasFromTypedefAttribute;};
130 
131  inline const std::string& GetAttributeNArgsToKeep() const {return fNArgsToKeep;};
132 
133  void SetAttributeValue(const std::string& attributeName, const std::string& attributeValue); // sets an attribute with name attribute name and value attributeValue
134 
135  ESelect GetSelected() const;
136  void SetSelected(ESelect sel);
137 
138  bool HasInterpreter() const {return fInterp!=NULL; };
139  void SetInterpreter(cling::Interpreter& interp) {fInterp=&interp; };
140 
141  const AttributesMap_t& GetAttributes() const; // returns the list of attributes
142  void PrintAttributes(int level) const; // prints the list of attributes - level is the number of tabs from the beginning of the line
143  void PrintAttributes(std::ostream &out, int level) const; // prints the list of attributes - level is the number of tabs from the beginning of the line
144 
145  EMatchType Match(const clang::NamedDecl *decl, const std::string& name, const std::string& prototype, bool isLinkdef) const; // for more detailed description look at the .cxx file
146 
147  void SetMatchFound(bool match); // set fMatchFound
148  bool GetMatchFound() const; // get fMatchFound
149 
150  const clang::Type *GetRequestedType() const;
151  inline const clang::CXXRecordDecl *GetCXXRecordDecl() const {return fCXXRecordDecl;} ;
152  void SetCXXRecordDecl(const clang::CXXRecordDecl *decl, const clang::Type *typeptr);
153 
154 protected:
155 
156  // Checks if the test string matches against the pattern (which has produced the list of sub-patterns patterns_list). There is
157  // difference if we are processing linkdef.h or selection.xmlpatterns
158  inline bool CheckPattern(const std::string& test, const std::string& pattern, const std::list<std::string>& patterns_list, bool isLinkdef) const;
159 
160  inline void ProcessPattern(const std::string& pattern, std::list<std::string>& out) const; // divides a pattern into a list of sub-patterns
161 };
162 
163 inline std::ostream &operator<<(std::ostream& out, const BaseSelectionRule &obj)
164 {
165  obj.Print(out);
166  return out;
167 }
168 #endif
bool HasAttributeFileName() const
virtual ~BaseSelectionRule()=default
void ProcessPattern(const std::string &pattern, std::list< std::string > &out) const
EMatchType Match(const clang::NamedDecl *decl, const std::string &name, const std::string &prototype, bool isLinkdef) const
virtual void DebugPrint() const
std::string fNArgsToKeep
ESelect GetSelected() const
bool GetMatchFound() const
const std::string & GetAttributeFileName() const
std::list< std::string > fSubPatterns
const std::string & GetAttributeNArgsToKeep() const
Definition: test.py:1
std::list< std::string > fFileSubPatterns
const clang::Type * fRequestedType
std::string fFilePattern
const std::string & GetAttributeFilePattern() const
bool HasAttributeFilePattern() const
bool HasAttributeProtoName() const
const char * GetSelFileName() const
const clang::Type * GetRequestedType() const
const std::string & GetAttributePattern() const
bool HasAttributePattern() const
const AttributesMap_t & GetAttributes() const
void PrintAttributes(int level) const
virtual void Print(std::ostream &out) const =0
static const std::string pattern("pattern")
bool HasAttributeFromTypedef() const
AttributesMap_t fAttributes
bool IsFromTypedef() const
void SetIndex(long index)
bool CheckPattern(const std::string &test, const std::string &pattern, const std::list< std::string > &patterns_list, bool isLinkdef) const
const std::string & GetAttributeProtoName() const
std::string fProtoPattern
bool HasInterpreter() const
std::unordered_map< std::string, std::string > AttributesMap_t
long GetLineNumber() const
bool GetAttributeValue(const std::string &attributeName, std::string &returnValue) const
const std::string & GetAttributeName() const
Type
enumeration specifying the integration types.
cling::Interpreter * fInterp
Print a TSeq at the prompt:
Definition: TDatime.h:115
std::ostream & operator<<(std::ostream &out, const BaseSelectionRule &obj)
const clang::CXXRecordDecl * GetCXXRecordDecl() const
void SetSelected(ESelect sel)
BaseSelectionRule(ESelect sel)
void SetAttributeValue(const std::string &attributeName, const std::string &attributeValue)
std::string fProtoName
bool HasAttributeProtoPattern() const
void SetCXXRecordDecl(const clang::CXXRecordDecl *decl, const clang::Type *typeptr)
void SetMatchFound(bool match)
const clang::CXXRecordDecl * fCXXRecordDecl
bool HasAttributeName() const
const std::string & GetAttributeProtoPattern() const
std::string fSelFileName
void SetInterpreter(cling::Interpreter &interp)
bool HasAttributeWithName(const std::string &attributeName) const
BaseSelectionRule(long index, cling::Interpreter &interp, const char *selFileName="", long lineno=-1)
long GetIndex() const
char name[80]
Definition: TGX11.cxx:109