Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 <string>
17#include <vector>
18#include <utility>
19
20#include "BaseSelectionRule.h"
21#include "ClassSelectionRule.h"
23#include "clang/AST/Decl.h"
24
25#include "TClingUtils.h"
26
27namespace cling {
28 class Interpreter;
29}
30
31namespace ROOT{
32 namespace TMetaUtils {
33 class TNormalizedCtxt;
34 }
35}
36#include <iostream>
38
39 template <class ASSOCIATIVECONTAINER>
41 {
42 auto skipAttr = [](const std::string &s) {
43 return "pattern" == s || "name" == s || "file_name" == s;
44 };
45 if (c1.size() != c2.size()) {
46 // We check if the attributes are pattern, name or filename
47 auto skipSizeCheck = true;
48 for (auto &&coll : {c1, c2})
49 {
50 for (auto &&keyValPair : coll) {
52 }
53 }
54 if (!skipSizeCheck) {
55 return false;
56 }
57 }
59 for (auto &&keyValPairC1 : c1) {
60 auto keyC1 = keyValPairC1.first;
61 if (skipAttr(keyC1))
62 continue;
63 auto valC1 = keyValPairC1.second;
64 auto C2It = c2.find(keyC1);
65 if (C2It == c2.end() || valC1 != C2It->second)
66 return false;
67 }
68 } else {
69 return !(c1 != c2);
70 }
71 return true;
72 }
73
74 template<class RULE>
75 inline bool areEqual(const RULE* r1, const RULE* r2, bool moduloNameOrPattern = false){
76 return areEqualAttributes(r1->GetAttributes(), r2->GetAttributes(), moduloNameOrPattern);
77 }
78
79 template<class RULESCOLLECTION>
80 inline bool areEqualColl(const RULESCOLLECTION& r1,
81 const RULESCOLLECTION& r2,
82 bool moduloNameOrPattern = false){
83 if (r1.size() != r2.size()) return false;
84 auto rIt1 = r1.begin();
85 auto rIt2 = r2.begin();
86 for (;rIt1!=r1.cend();++rIt1,++rIt2){
87 if (!areEqual(&(*rIt1),&(*rIt2), moduloNameOrPattern)) return false;
88 }
89 return true;
90 }
91 template<>
95 if (!areEqualAttributes(r1->GetAttributes(), r2->GetAttributes(),moduloNameOrPattern)) return false;
96 // Now check fields
97 if (!areEqualColl(r1->GetFieldSelectionRules(),
98 r2->GetFieldSelectionRules(),
99 true)) return false;
100 // On the same footing, now check methods
101 if (!areEqualColl(r1->GetMethodSelectionRules(),
102 r2->GetMethodSelectionRules(),
103 true)) return false;
104 return true;
105 }
106}
107
108
110
111public:
112 /// Type of selection file
118
119 SelectionRules(cling::Interpreter &interp,
121 const std::vector<std::pair<std::string,std::string>>& namesForExclusion):
124 fRulesCounter(0),
126 fInterp(interp) {
127 long counter=1;
128 for (auto& attrValPair : namesForExclusion){
129 ClassSelectionRule csr(counter++, fInterp);
130 csr.SetAttributeValue(attrValPair.first, attrValPair.second);
131 csr.SetSelected(BaseSelectionRule::kNo);
133 }
134 }
135
137 bool HasClassSelectionRules() const { return !fClassSelectionRules.empty(); }
138 const std::list<ClassSelectionRule>& GetClassSelectionRules() const {
140 }
141
144 return !fFunctionSelectionRules.empty();
145 }
146 const std::list<FunctionSelectionRule>& GetFunctionSelectionRules() const {
148 }
149
151
153 return !fVariableSelectionRules.empty();
154 }
155 const std::list<VariableSelectionRule>& GetVariableSelectionRules() const {
157 }
158
160 bool HasEnumSelectionRules() const { return !fEnumSelectionRules.empty(); }
161 const std::list<EnumSelectionRule>& GetEnumSelectionRules() const {
162 return fEnumSelectionRules;
163 }
164
165 void PrintSelectionRules() const; // print all selection rules
166
167 void ClearSelectionRules(); // clear all selection rules
168
170 bool GetHasFileNameRule() const { return fHasFileNameRule; }
171
172 int CheckDuplicates();
173 void Optimize();
174
175 // These method are called from clr-scan and return true if the Decl selected, false otherwise
176 //const BaseSelectionRule *IsDeclSelected(clang::Decl* D) const;
177 const ClassSelectionRule *IsDeclSelected(const clang::RecordDecl* D, bool includeTypedefRule) const;
178 const ClassSelectionRule *IsDeclSelected(const clang::TypedefNameDecl* D) const;
179 const ClassSelectionRule *IsDeclSelected(const clang::NamespaceDecl* D) const;
180 const BaseSelectionRule *IsDeclSelected(const clang::EnumDecl* D) const;
181 const BaseSelectionRule *IsDeclSelected(const clang::VarDecl* D) const;
182 const BaseSelectionRule *IsDeclSelected(const clang::FieldDecl* D) const;
183 const BaseSelectionRule *IsDeclSelected(const clang::FunctionDecl* D) const;
184 const BaseSelectionRule *IsDeclSelected(const clang::Decl* D) const;
185
186 const ClassSelectionRule *IsClassSelected(const clang::Decl* D, const std::string& qual_name, bool includeTypedefRule) const; // is the class selected
187 const ClassSelectionRule *IsNamespaceSelected(const clang::Decl* D, const std::string& qual_name) const; // is the class selected
188
189 // is the global function, variable, enum selected - the behavior is different for linkdef.h and selection.xml - that's why
190 // we have two functions
191 const BaseSelectionRule *IsVarSelected(const clang::VarDecl* D, const std::string& qual_name) const;
192 const BaseSelectionRule *IsFunSelected(const clang::FunctionDecl* D, const std::string& qual_name) const;
193 const BaseSelectionRule *IsEnumSelected(const clang::EnumDecl* D, const std::string& qual_name) const;
194 const BaseSelectionRule *IsLinkdefVarSelected(const clang::VarDecl* D, const std::string& qual_name) const;
195 const BaseSelectionRule *IsLinkdefFunSelected(const clang::FunctionDecl* D, const std::string& qual_name) const;
196 const BaseSelectionRule *IsLinkdefEnumSelected(const clang::EnumDecl* D, const std::string& qual_name) const;
197
198 // is member (field, method, enum) selected; the behavior for linkdef.h methods is different
199 const BaseSelectionRule *IsMemberSelected(const clang::Decl* D, const std::string& str_name) const;
200 const BaseSelectionRule *IsLinkdefMethodSelected(const clang::Decl* D, const std::string& qual_name) const;
201
202 // Return the number of rules
203 unsigned int Size() const{return fClassSelectionRules.size()+
206 fEnumSelectionRules.size();};
207
208 // returns true if the parent is class or struct
209 bool IsParentClass(const clang::Decl* D) const;
210
211 // the same but returns also the parent name and qualified name
212 bool IsParentClass(const clang::Decl* D, std::string& parent_name, std::string& parent_qual_name) const;
213
214 // returns the parent name and qualified name
215 bool GetParentName(const clang::Decl* D, std::string& parent_name, std::string& parent_qual_name) const;
216
217
218 //bool getParent(clang::Decl* D, clang::Decl* parent); - this method would have saved a lot of efforts but it crashes
219 // and I didn't understand why
220
221 // gets the name and qualified name of the Decl
222 bool GetDeclName(const clang::Decl* D, std::string& name, std::string& qual_name) const;
223
224 // gets the qualname of the decl, no checks performed
225 void GetDeclQualName(const clang::Decl* D, std::string& qual_name) const;
226
227 // gets the function prototype if the Decl (if it is global function or method)
228 bool GetFunctionPrototype(const clang::FunctionDecl* F, std::string& prototype) const;
229
230 bool IsSelectionXMLFile() const {
232 }
233 bool IsLinkdefFile() const {
235 }
239
240 // returns true if all selection rules are used at least once
241 bool AreAllSelectionRulesUsed() const;
242
243 // Go through all the selections rules and lookup the name if any in the AST.
244 // and force the instantiation of template if any are used in the rules.
245 bool SearchNames(cling::Interpreter &interp);
246
247 void FillCache(); // Fill the cache of all selection rules
248
249private:
250 std::list<ClassSelectionRule> fClassSelectionRules; ///< List of the class selection rules
251 std::list<FunctionSelectionRule> fFunctionSelectionRules; ///< List of the global functions selection rules
252 std::list<VariableSelectionRule> fVariableSelectionRules; ///< List of the global variables selection rules
253 std::list<EnumSelectionRule> fEnumSelectionRules; ///< List of the enums selection rules
254
256
257 bool fHasFileNameRule; ///< if we have a file name rule, this should be set to true
259
261 cling::Interpreter &fInterp;
262
263};
264
265#endif
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
char name[80]
Definition TGX11.cxx:110
const_iterator begin() const
const_iterator end() const
The class representing the collection of selection rules.
SelectionRules(cling::Interpreter &interp, ROOT::TMetaUtils::TNormalizedCtxt &normCtxt, const std::vector< std::pair< std::string, std::string > > &namesForExclusion)
bool HasFunctionSelectionRules() const
const BaseSelectionRule * IsLinkdefVarSelected(const clang::VarDecl *D, const std::string &qual_name) const
const std::list< ClassSelectionRule > & GetClassSelectionRules() const
void GetDeclQualName(const clang::Decl *D, std::string &qual_name) const
const BaseSelectionRule * IsVarSelected(const clang::VarDecl *D, const std::string &qual_name) const
const BaseSelectionRule * IsFunSelected(const clang::FunctionDecl *D, const std::string &qual_name) const
void AddVariableSelectionRule(const VariableSelectionRule &varSel)
bool HasEnumSelectionRules() const
void AddClassSelectionRule(const ClassSelectionRule &classSel)
std::list< VariableSelectionRule > fVariableSelectionRules
List of the global variables selection rules.
bool AreAllSelectionRulesUsed() const
ESelectionFileTypes fSelectionFileType
long int fRulesCounter
bool GetFunctionPrototype(const clang::FunctionDecl *F, std::string &prototype) const
bool SearchNames(cling::Interpreter &interp)
bool GetParentName(const clang::Decl *D, std::string &parent_name, std::string &parent_qual_name) const
std::list< FunctionSelectionRule > fFunctionSelectionRules
List of the global functions selection rules.
const BaseSelectionRule * IsLinkdefFunSelected(const clang::FunctionDecl *D, const std::string &qual_name) const
std::list< EnumSelectionRule > fEnumSelectionRules
List of the enums selection rules.
void PrintSelectionRules() const
bool GetHasFileNameRule() const
ROOT::TMetaUtils::TNormalizedCtxt & fNormCtxt
bool HasClassSelectionRules() const
bool IsLinkdefFile() const
bool GetDeclName(const clang::Decl *D, std::string &name, std::string &qual_name) const
const std::list< FunctionSelectionRule > & GetFunctionSelectionRules() const
unsigned int Size() const
bool fHasFileNameRule
if we have a file name rule, this should be set to true
ESelectionFileTypes
Type of selection file.
void AddEnumSelectionRule(const EnumSelectionRule &enumSel)
const std::list< EnumSelectionRule > & GetEnumSelectionRules() const
const BaseSelectionRule * IsMemberSelected(const clang::Decl *D, const std::string &str_name) const
bool IsSelectionXMLFile() const
const std::list< VariableSelectionRule > & GetVariableSelectionRules() const
bool IsParentClass(const clang::Decl *D) const
const BaseSelectionRule * IsLinkdefEnumSelected(const clang::EnumDecl *D, const std::string &qual_name) const
void AddFunctionSelectionRule(const FunctionSelectionRule &funcSel)
bool HasVariableSelectionRules() const
const BaseSelectionRule * IsEnumSelected(const clang::EnumDecl *D, const std::string &qual_name) const
const ClassSelectionRule * IsDeclSelected(const clang::RecordDecl *D, bool includeTypedefRule) const
const ClassSelectionRule * IsNamespaceSelected(const clang::Decl *D, const std::string &qual_name) const
std::list< ClassSelectionRule > fClassSelectionRules
List of the class selection rules.
cling::Interpreter & fInterp
void SetHasFileNameRule(bool file_rule)
void SetSelectionFileType(ESelectionFileTypes fileType)
const BaseSelectionRule * IsLinkdefMethodSelected(const clang::Decl *D, const std::string &qual_name) const
const ClassSelectionRule * IsClassSelected(const clang::Decl *D, const std::string &qual_name, bool includeTypedefRule) const
return c1
Definition legend1.C:41
return c2
Definition legend2.C:14
Namespace for new ROOT classes and functions.
bool areEqualColl(const RULESCOLLECTION &r1, const RULESCOLLECTION &r2, bool moduloNameOrPattern=false)
bool areEqual(const RULE *r1, const RULE *r2, bool moduloNameOrPattern=false)
bool areEqualAttributes(const ASSOCIATIVECONTAINER &c1, const ASSOCIATIVECONTAINER &c2, bool moduloNameOrPattern)
bool areEqual< ClassSelectionRule >(const ClassSelectionRule *r1, const ClassSelectionRule *r2, bool moduloNameOrPattern)