Logo ROOT  
Reference Guide
SelectionRules.h
Go to the documentation of this file.
1 // @(#)root/core/utils:$Id: SelectionRules.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__SELECTIONRULES_H
13 #define R__SELECTIONRULES_H
14 
15 #include <list>
16 #include "BaseSelectionRule.h"
17 #include "ClassSelectionRule.h"
18 #include "VariableSelectionRule.h"
19 #include "clang/AST/Decl.h"
20 
21 #include "TClingUtils.h"
22 
23 namespace cling {
24  class Interpreter;
25 }
26 
27 namespace ROOT{
28  namespace TMetaUtils {
29  class TNormalizedCtxt;
30  }
31 }
32 #include <iostream>
34 
35  template<class ASSOCIATIVECONTAINER>
36  inline bool areEqualAttributes(const ASSOCIATIVECONTAINER& c1, const ASSOCIATIVECONTAINER& c2, bool moduloNameOrPattern){
37  if (c1.size() != c2.size()) return false;
38  if (moduloNameOrPattern) {
39  for (auto&& keyValPairC1 : c1){
40  auto keyC1 = keyValPairC1.first;
41  if ("pattern" == keyC1 || "name" == keyC1) continue;
42  auto valC1 = keyValPairC1.second;
43  auto C2It = c2.find(keyC1);
44  if (C2It == c2.end() || valC1 != C2It->second) return false;
45  }
46  }
47  else {
48  return !(c1 != c2);
49  }
50  return true;
51  }
52 
53  template<class RULE>
54  inline bool areEqual(const RULE* r1, const RULE* r2, bool moduloNameOrPattern = false){
55  return areEqualAttributes(r1->GetAttributes(), r2->GetAttributes(), moduloNameOrPattern);
56  }
57 
58  template<class RULESCOLLECTION>
59  inline bool areEqualColl(const RULESCOLLECTION& r1,
60  const RULESCOLLECTION& r2,
61  bool moduloNameOrPattern = false){
62  if (r1.size() != r2.size()) return false;
63  auto rIt1 = r1.begin();
64  auto rIt2 = r2.begin();
65  for (;rIt1!=r1.cend();++rIt1,++rIt2){
66  if (!areEqual(&(*rIt1),&(*rIt2), moduloNameOrPattern)) return false;
67  }
68  return true;
69  }
70  template<>
72  const ClassSelectionRule* r2,
73  bool moduloNameOrPattern){
74  if (!areEqualAttributes(r1->GetAttributes(), r2->GetAttributes(),moduloNameOrPattern)) return false;
75  // Now check fields
76  if (!areEqualColl(r1->GetFieldSelectionRules(),
77  r2->GetFieldSelectionRules(),
78  true)) return false;
79  // On the same footing, now check methods
80  if (!areEqualColl(r1->GetMethodSelectionRules(),
81  r2->GetMethodSelectionRules(),
82  true)) return false;
83  return true;
84  }
85 }
86 
87 
89 
90 public:
91  /// Type of selection file
96  };
97 
98  SelectionRules(cling::Interpreter &interp,
100  const std::vector<std::pair<std::string,std::string>>& namesForExclusion):
102  fHasFileNameRule(false),
103  fRulesCounter(0),
104  fNormCtxt(normCtxt),
105  fInterp(interp) {
106  long counter=1;
107  for (auto& attrValPair : namesForExclusion){
108  ClassSelectionRule csr(counter++, fInterp);
109  csr.SetAttributeValue(attrValPair.first, attrValPair.second);
112  }
113  }
114 
115  void AddClassSelectionRule(const ClassSelectionRule& classSel);
116  bool HasClassSelectionRules() const { return !fClassSelectionRules.empty(); }
117  const std::list<ClassSelectionRule>& GetClassSelectionRules() const {
118  return fClassSelectionRules;
119  }
120 
121  void AddFunctionSelectionRule(const FunctionSelectionRule& funcSel);
123  return !fFunctionSelectionRules.empty();
124  }
125  const std::list<FunctionSelectionRule>& GetFunctionSelectionRules() const {
127  }
128 
130 
132  return !fVariableSelectionRules.empty();
133  }
134  const std::list<VariableSelectionRule>& GetVariableSelectionRules() const {
136  }
137 
138  void AddEnumSelectionRule(const EnumSelectionRule& enumSel);
139  bool HasEnumSelectionRules() const { return !fEnumSelectionRules.empty(); }
140  const std::list<EnumSelectionRule>& GetEnumSelectionRules() const {
141  return fEnumSelectionRules;
142  }
143 
144  void PrintSelectionRules() const; // print all selection rules
145 
146  void ClearSelectionRules(); // clear all selection rules
147 
148  void SetHasFileNameRule(bool file_rule) { fHasFileNameRule = file_rule; }
149  bool GetHasFileNameRule() const { return fHasFileNameRule; }
150 
151  int CheckDuplicates();
152  void Optimize();
153 
154  // These method are called from clr-scan and return true if the Decl selected, false otherwise
155  //const BaseSelectionRule *IsDeclSelected(clang::Decl* D) const;
156  const ClassSelectionRule *IsDeclSelected(const clang::RecordDecl* D, bool includeTypedefRule) const;
157  const ClassSelectionRule *IsDeclSelected(const clang::TypedefNameDecl* D) const;
158  const ClassSelectionRule *IsDeclSelected(const clang::NamespaceDecl* D) const;
159  const BaseSelectionRule *IsDeclSelected(const clang::EnumDecl* D) const;
160  const BaseSelectionRule *IsDeclSelected(const clang::VarDecl* D) const;
161  const BaseSelectionRule *IsDeclSelected(const clang::FieldDecl* D) const;
162  const BaseSelectionRule *IsDeclSelected(const clang::FunctionDecl* D) const;
163  const BaseSelectionRule *IsDeclSelected(const clang::Decl* D) const;
164 
165  const ClassSelectionRule *IsClassSelected(const clang::Decl* D, const std::string& qual_name, bool includeTypedefRule) const; // is the class selected
166  const ClassSelectionRule *IsNamespaceSelected(const clang::Decl* D, const std::string& qual_name) const; // is the class selected
167 
168  // is the global function, variable, enum selected - the behavior is different for linkdef.h and selection.xml - that's why
169  // we have two functions
170  const BaseSelectionRule *IsVarSelected(const clang::VarDecl* D, const std::string& qual_name) const;
171  const BaseSelectionRule *IsFunSelected(const clang::FunctionDecl* D, const std::string& qual_name) const;
172  const BaseSelectionRule *IsEnumSelected(const clang::EnumDecl* D, const std::string& qual_name) const;
173  const BaseSelectionRule *IsLinkdefVarSelected(const clang::VarDecl* D, const std::string& qual_name) const;
174  const BaseSelectionRule *IsLinkdefFunSelected(const clang::FunctionDecl* D, const std::string& qual_name) const;
175  const BaseSelectionRule *IsLinkdefEnumSelected(const clang::EnumDecl* D, const std::string& qual_name) const;
176 
177  // is member (field, method, enum) selected; the behavior for linkdef.h methods is different
178  const BaseSelectionRule *IsMemberSelected(const clang::Decl* D, const std::string& str_name) const;
179  const BaseSelectionRule *IsLinkdefMethodSelected(const clang::Decl* D, const std::string& qual_name) const;
180 
181  // Return the number of rules
182  unsigned int Size() const{return fClassSelectionRules.size()+
185  fEnumSelectionRules.size();};
186 
187  // returns true if the parent is class or struct
188  bool IsParentClass(const clang::Decl* D) const;
189 
190  // the same but returns also the parent name and qualified name
191  bool IsParentClass(const clang::Decl* D, std::string& parent_name, std::string& parent_qual_name) const;
192 
193  // returns the parent name and qualified name
194  bool GetParentName(const clang::Decl* D, std::string& parent_name, std::string& parent_qual_name) const;
195 
196 
197  //bool getParent(clang::Decl* D, clang::Decl* parent); - this method would have saved a lot of efforts but it crashes
198  // and I didn't understand why
199 
200  // gets the name and qualified name of the Decl
201  bool GetDeclName(const clang::Decl* D, std::string& name, std::string& qual_name) const;
202 
203  // gets the qualname of the decl, no checks performed
204  void GetDeclQualName(const clang::Decl* D, std::string& qual_name) const;
205 
206  // gets the function prototype if the Decl (if it is global function or method)
207  bool GetFunctionPrototype(const clang::FunctionDecl* F, std::string& prototype) const;
208 
209  bool IsSelectionXMLFile() const {
211  }
212  bool IsLinkdefFile() const {
214  }
216  fSelectionFileType = fileType;
217  }
218 
219  // returns true if all selection rules are used at least once
220  bool AreAllSelectionRulesUsed() const;
221 
222  // Go through all the selections rules and lookup the name if any in the AST.
223  // and force the instantiation of template if any are used in the rules.
224  bool SearchNames(cling::Interpreter &interp);
225 
226  void FillCache(); // Fill the cache of all selection rules
227 
228 private:
229  std::list<ClassSelectionRule> fClassSelectionRules; ///< List of the class selection rules
230  std::list<FunctionSelectionRule> fFunctionSelectionRules; ///< List of the global functions selection rules
231  std::list<VariableSelectionRule> fVariableSelectionRules; ///< List of the global variables selection rules
232  std::list<EnumSelectionRule> fEnumSelectionRules; ///< List of the enums selection rules
233 
235 
236  bool fHasFileNameRule; ///< if we have a file name rule, this should be set to true
237  long int fRulesCounter;
238 
240  cling::Interpreter &fInterp;
241 
242 };
243 
244 #endif
std::list< ClassSelectionRule > fClassSelectionRules
List of the class selection rules.
ROOT::TMetaUtils::TNormalizedCtxt & fNormCtxt
const BaseSelectionRule * IsVarSelected(const clang::VarDecl *D, const std::string &qual_name) const
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn&#39;t allow to forward declare tb...
Definition: StringConv.hxx:21
return c1
Definition: legend1.C:41
const std::list< FunctionSelectionRule > & GetFunctionSelectionRules() const
void GetDeclQualName(const clang::Decl *D, std::string &qual_name) const
bool HasClassSelectionRules() const
bool HasEnumSelectionRules() const
ESelectionFileTypes
Type of selection file.
std::list< VariableSelectionRule > fVariableSelectionRules
List of the global variables selection rules.
void SetHasFileNameRule(bool file_rule)
const BaseSelectionRule * IsLinkdefMethodSelected(const clang::Decl *D, const std::string &qual_name) const
const BaseSelectionRule * IsLinkdefEnumSelected(const clang::EnumDecl *D, const std::string &qual_name) const
unsigned int Size() const
long int fRulesCounter
SelectionRules(cling::Interpreter &interp, ROOT::TMetaUtils::TNormalizedCtxt &normCtxt, const std::vector< std::pair< std::string, std::string >> &namesForExclusion)
const ClassSelectionRule * IsClassSelected(const clang::Decl *D, const std::string &qual_name, bool includeTypedefRule) const
bool HasFunctionSelectionRules() const
void ClearSelectionRules()
bool GetParentName(const clang::Decl *D, std::string &parent_name, std::string &parent_qual_name) const
bool IsSelectionXMLFile() const
bool GetHasFileNameRule() const
const BaseSelectionRule * IsLinkdefFunSelected(const clang::FunctionDecl *D, const std::string &qual_name) const
const std::list< EnumSelectionRule > & GetEnumSelectionRules() const
void AddFunctionSelectionRule(const FunctionSelectionRule &funcSel)
The class representing the collection of selection rules.
bool fHasFileNameRule
if we have a file name rule, this should be set to true
bool GetDeclName(const clang::Decl *D, std::string &name, std::string &qual_name) const
const std::list< ClassSelectionRule > & GetClassSelectionRules() const
#define F(x, y, z)
const BaseSelectionRule * IsMemberSelected(const clang::Decl *D, const std::string &str_name) const
bool AreAllSelectionRulesUsed() const
void SetSelectionFileType(ESelectionFileTypes fileType)
bool GetFunctionPrototype(const clang::FunctionDecl *F, std::string &prototype) const
const BaseSelectionRule * IsFunSelected(const clang::FunctionDecl *D, const std::string &qual_name) const
const ClassSelectionRule * IsDeclSelected(const clang::RecordDecl *D, bool includeTypedefRule) const
void AddVariableSelectionRule(const VariableSelectionRule &varSel)
cling::Interpreter & fInterp
const BaseSelectionRule * IsLinkdefVarSelected(const clang::VarDecl *D, const std::string &qual_name) const
return c2
Definition: legend2.C:14
const BaseSelectionRule * IsEnumSelected(const clang::EnumDecl *D, const std::string &qual_name) const
std::list< EnumSelectionRule > fEnumSelectionRules
List of the enums selection rules.
bool areEqual(const RULE *r1, const RULE *r2, bool moduloNameOrPattern=false)
Print a TSeq at the prompt:
Definition: TDatime.h:115
const ClassSelectionRule * IsNamespaceSelected(const clang::Decl *D, const std::string &qual_name) const
void SetSelected(ESelect sel)
bool IsParentClass(const clang::Decl *D) const
void AddClassSelectionRule(const ClassSelectionRule &classSel)
void AddEnumSelectionRule(const EnumSelectionRule &enumSel)
ESelectionFileTypes fSelectionFileType
void SetAttributeValue(const std::string &attributeName, const std::string &attributeValue)
bool areEqualColl(const RULESCOLLECTION &r1, const RULESCOLLECTION &r2, bool moduloNameOrPattern=false)
const std::list< VariableSelectionRule > & GetVariableSelectionRules() const
std::list< FunctionSelectionRule > fFunctionSelectionRules
List of the global functions selection rules.
bool areEqualAttributes(const ASSOCIATIVECONTAINER &c1, const ASSOCIATIVECONTAINER &c2, bool moduloNameOrPattern)
bool areEqual< ClassSelectionRule >(const ClassSelectionRule *r1, const ClassSelectionRule *r2, bool moduloNameOrPattern)
void PrintSelectionRules() const
bool IsLinkdefFile() const
bool HasVariableSelectionRules() const
char name[80]
Definition: TGX11.cxx:109
bool SearchNames(cling::Interpreter &interp)