Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 <map>
26 #include <unordered_map>
27 #include <list>
28 #include <iosfwd>
29 
30 namespace clang {
31  class NamedDecl;
32  class CXXRecordDecl;
33  class Type;
34 }
35 namespace cling {
36  class Interpreter;
37 }
38 
39 class BaseSelectionRule
40 {
41 public:
42  typedef std::unordered_map<std::string, std::string> AttributesMap_t; // The liste of selection rule's attributes (name, pattern, ...)
43 
44  enum ESelect { // a rule could be selected, vetoed or we don't care about it
45  kYes,
46  kNo,
47  kDontCare
48  };
49  enum EMatchType {
50  kName,
51  kPattern,
52  kFile,
53  kNoMatch
54  };
55 
56 private:
57  long fIndex; // Index indicating the ordering of the rules.
58  long fLineNumber=-1; // Line number of the selection file where the rule is located
59  std::string fSelFileName=""; // Name of the selection file
60  AttributesMap_t fAttributes; // list of the attributes of the selection/exclusion rule
61  ESelect fIsSelected; // selected/vetoed/don't care
62  std::list<std::string> fSubPatterns; // a list of subpatterns, generated form a pattern/proto_pattern attribute
63  std::list<std::string> fFileSubPatterns; // a list of subpatterns, generated form a file_pattern attribute
64  bool fMatchFound; // this is true if this selection rule has been used at least once
65  const clang::CXXRecordDecl *fCXXRecordDecl; // Record decl of the entity searched for.
66  const clang::Type *fRequestedType; // Same as the record decl but with some of the typedef preserved (Double32_t, Float16_t, etc..)
67  cling::Interpreter *fInterp;
68 
69  // Cached for performance
70  std::string fName = "";
71  std::string fPattern = "";
72  std::string fProtoName = "";
73  std::string fProtoPattern = "";
74  std::string fFileName = "";
75  std::string fFilePattern = "";
76  std::string fNArgsToKeep = "";
77  bool fHasNameAttribute = false;
78  bool fHasProtoNameAttribute = false;
79  bool fHasPatternAttribute = false;
80  bool fHasProtoPatternAttribute = false;
81  bool fHasFileNameAttribute = false;
82  bool fHasFilePatternAttribute = false;
83  bool fHasFromTypedefAttribute = false;
84  bool fIsFromTypedef = false;
85 
86 public:
87 
88  BaseSelectionRule(ESelect sel) : fIndex(-1),fIsSelected(sel),fMatchFound(false),fCXXRecordDecl(NULL),fRequestedType(NULL),fInterp(NULL) {}
89 
90  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) {}
91 
92  BaseSelectionRule(long index, ESelect sel, const std::string& attributeName, const std::string& attributeValue, cling::Interpreter &interp, const char* selFileName = "",long lineno=-1);
93 
94  virtual ~BaseSelectionRule() = default;
95 
96  virtual void DebugPrint() const;
97  virtual void Print(std::ostream &out) const = 0;
98 
99  long GetIndex() const { return fIndex; }
100  void SetIndex(long index) { fIndex=index; }
101 
102  long GetLineNumber() const { return fLineNumber; }
103  const char* GetSelFileName() const { return fSelFileName.c_str(); }
104 
105  bool HasAttributeWithName(const std::string& attributeName) const; // returns true if there is an attribute with the specified name
106 
107  void FillCache(); // Fill the cache for performant attribute retrival
108 
109  bool GetAttributeValue(const std::string& attributeName, std::string& returnValue) const; // returns the value of the attribute with name attributeName
110 
111  inline const std::string& GetAttributeName() const {return fName;};
112  inline bool HasAttributeName() const {return fHasNameAttribute;};
113 
114  inline const std::string& GetAttributeProtoName() const {return fProtoName;};
115  inline bool HasAttributeProtoName() const {return fHasProtoNameAttribute;};
116 
117  inline const std::string& GetAttributePattern() const {return fPattern;};
118  inline bool HasAttributePattern() const {return fHasPatternAttribute;};
119 
120  inline const std::string& GetAttributeProtoPattern() const {return fProtoPattern;};
121  inline bool HasAttributeProtoPattern() const {return fHasProtoPatternAttribute;};
122 
123  inline const std::string& GetAttributeFileName() const {return fFileName;};
124  inline bool HasAttributeFileName() const {return fHasFileNameAttribute;};
125 
126  inline const std::string& GetAttributeFilePattern() const {return fFilePattern;};
127  inline bool HasAttributeFilePattern() const {return fHasFilePatternAttribute;};
128 
129  inline bool IsFromTypedef() const {return fIsFromTypedef;};
130  inline bool HasAttributeFromTypedef() const {return fHasFromTypedefAttribute;};
131 
132  inline const std::string& GetAttributeNArgsToKeep() const {return fNArgsToKeep;};
133 
134  void SetAttributeValue(const std::string& attributeName, const std::string& attributeValue); // sets an attribute with name attribute name and value attributeValue
135 
136  ESelect GetSelected() const;
137  void SetSelected(ESelect sel);
138 
139  bool HasInterpreter() const {return fInterp!=NULL; };
140  void SetInterpreter(cling::Interpreter& interp) {fInterp=&interp; };
141 
142  const AttributesMap_t& GetAttributes() const; // returns the list of attributes
143  void PrintAttributes(int level) const; // prints the list of attributes - level is the number of tabs from the beginning of the line
144  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
145 
146  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
147 
148  void SetMatchFound(bool match); // set fMatchFound
149  bool GetMatchFound() const; // get fMatchFound
150 
151  const clang::Type *GetRequestedType() const;
152  inline const clang::CXXRecordDecl *GetCXXRecordDecl() const {return fCXXRecordDecl;} ;
153  void SetCXXRecordDecl(const clang::CXXRecordDecl *decl, const clang::Type *typeptr);
154 
155 protected:
156 
157  // Checks if the test string matches against the pattern (which has produced the list of sub-patterns patterns_list). There is
158  // difference if we are processing linkdef.h or selection.xmlpatterns
159  inline bool CheckPattern(const std::string& test, const std::string& pattern, const std::list<std::string>& patterns_list, bool isLinkdef) const;
160 
161  inline void ProcessPattern(const std::string& pattern, std::list<std::string>& out) const; // divides a pattern into a list of sub-patterns
162 };
163 
164 inline std::ostream &operator<<(std::ostream& out, const BaseSelectionRule &obj)
165 {
166  obj.Print(out);
167  return out;
168 }
169 #endif