Logo ROOT   6.08/07
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 <map>
26 #include <unordered_map>
27 #include <list>
28 #include <iosfwd>
29 
30 #include "TMetaUtils.h"
31 
32 namespace clang {
33  class NamedDecl;
34  class CXXRecordDecl;
35  class Type;
36 }
37 namespace cling {
38  class Interpreter;
39 }
40 
42 {
43 public:
44  typedef std::unordered_map<std::string, std::string> AttributesMap_t; // The liste of selection rule's attributes (name, pattern, ...)
45 
46  enum ESelect { // a rule could be selected, vetoed or we don't care about it
48  kNo,
49  kDontCare
50  };
51  enum EMatchType {
55  kNoMatch
56  };
57 
58 private:
59  long fIndex; // Index indicating the ordering of the rules.
60  long fLineNumber=-1; // Line number of the selection file where the rule is located
61  std::string fSelFileName=""; // Name of the selection file
62  AttributesMap_t fAttributes; // list of the attributes of the selection/exclusion rule
63  ESelect fIsSelected; // selected/vetoed/don't care
64  std::list<std::string> fSubPatterns; // a list of subpatterns, generated form a pattern/proto_pattern attribute
65  std::list<std::string> fFileSubPatterns; // a list of subpatterns, generated form a file_pattern attribute
66  bool fMatchFound; // this is true if this selection rule has been used at least once
67  const clang::CXXRecordDecl *fCXXRecordDecl; // Record decl of the entity searched for.
68  const clang::Type *fRequestedType; // Same as the record decl but with some of the typedef preserved (Double32_t, Float16_t, etc..)
69  cling::Interpreter *fInterp;
70 
71  // Cached for performance
72  std::string fName = "";
73  std::string fPattern = "";
74  std::string fProtoName = "";
75  std::string fProtoPattern = "";
76  std::string fFileName = "";
77  std::string fFilePattern = "";
78  std::string fNArgsToKeep = "";
79  bool fHasNameAttribute = false;
80  bool fHasProtoNameAttribute = false;
81  bool fHasPatternAttribute = false;
82  bool fHasProtoPatternAttribute = false;
83  bool fHasFileNameAttribute = false;
84  bool fHasFilePatternAttribute = false;
85  bool fHasFromTypedefAttribute = false;
86  bool fIsFromTypedef = false;
87 
88 public:
89 
90  BaseSelectionRule(ESelect sel) : fIndex(-1),fIsSelected(sel),fMatchFound(false),fCXXRecordDecl(NULL),fRequestedType(NULL),fInterp(NULL) {}
91 
92  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) {}
93 
94  BaseSelectionRule(long index, ESelect sel, const std::string& attributeName, const std::string& attributeValue, cling::Interpreter &interp, const char* selFileName = "",long lineno=-1);
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
bool HasAttributeFileName() 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
const std::string & GetAttributeFilePattern() const
bool HasAttributeFilePattern() const
bool HasAttributeProtoName() const
const char * GetSelFileName() const
const std::string & GetAttributePattern() const
bool HasAttributePattern() 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)
const std::string & GetAttributeProtoName() const
static void DebugPrint(const char *fmt,...)
Print debugging message to stderr and, on Windows, to the system debugger.
Definition: TError.cxx:64
bool HasInterpreter() const
std::unordered_map< std::string, std::string > AttributesMap_t
long GetLineNumber() const
const std::string & GetAttributeName() const
Type
enumeration specifying the integration types.
void Print(std::ostream &os, const OptionType &opt)
cling::Interpreter * fInterp
Definition: TCling.h:48
Print a TSeq at the prompt:
Definition: TDatime.h:114
std::ostream & operator<<(std::ostream &out, const BaseSelectionRule &obj)
const clang::CXXRecordDecl * GetCXXRecordDecl() const
BaseSelectionRule(ESelect sel)
bool HasAttributeProtoPattern() const
const clang::CXXRecordDecl * fCXXRecordDecl
bool HasAttributeName() const
const std::string & GetAttributeProtoPattern() const
#define NULL
Definition: Rtypes.h:82
void SetInterpreter(cling::Interpreter &interp)
BaseSelectionRule(long index, cling::Interpreter &interp, const char *selFileName="", long lineno=-1)
long GetIndex() const
char name[80]
Definition: TGX11.cxx:109