|
0
|
1 |
/*
|
|
|
2 |
* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
|
3 |
* All rights reserved.
|
|
|
4 |
* This component and the accompanying materials are made available
|
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
|
6 |
* which accompanies this distribution, and is available
|
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
|
8 |
*
|
|
|
9 |
* Initial Contributors:
|
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
|
11 |
*
|
|
|
12 |
* Contributors:
|
|
|
13 |
*
|
|
|
14 |
* Description:
|
|
|
15 |
*
|
|
|
16 |
*/
|
|
|
17 |
|
|
|
18 |
|
|
|
19 |
#ifndef CLASSNODEANALYSIS_H_
|
|
|
20 |
#define CLASSNODEANALYSIS_H_
|
|
|
21 |
|
|
|
22 |
#ifdef __WIN__
|
|
|
23 |
#pragma warning(disable:4786)
|
|
|
24 |
#endif
|
|
|
25 |
#include <xercesc/dom/DOM.hpp>
|
|
|
26 |
#include <vector>
|
|
|
27 |
#include <list>
|
|
|
28 |
#include <string>
|
|
|
29 |
#include "HANodeIterator.h"
|
|
|
30 |
#include "NodeAnalysis.h"
|
|
|
31 |
#include "NodeIndex.h"
|
|
|
32 |
#include "NodeTypeComparator.h"
|
|
|
33 |
using namespace std;
|
|
|
34 |
|
|
|
35 |
XERCES_CPP_NAMESPACE_USE
|
|
|
36 |
|
|
|
37 |
|
|
|
38 |
|
|
|
39 |
template <TIssueType IssueType>
|
|
|
40 |
void AddIssueClass(const HANodeIterator* self,TIssueIdentity classType, const HANodeIterator& ignorenode, int lineNo, const XMLCh* fileid=NULL)
|
|
|
41 |
{
|
|
|
42 |
switch (classType)
|
|
|
43 |
{
|
|
|
44 |
case EIssueIdentityClass:
|
|
|
45 |
AddIssue<EIssueIdentityClass,IssueType>(self,ignorenode,lineNo,fileid);
|
|
|
46 |
break;
|
|
|
47 |
case EIssueIdentityStruct:
|
|
|
48 |
AddIssue<EIssueIdentityStruct,IssueType>(self,ignorenode,lineNo,fileid);
|
|
|
49 |
break;
|
|
|
50 |
case EIssueIdentityUnion:
|
|
|
51 |
AddIssue<EIssueIdentityUnion,IssueType>(self,ignorenode,lineNo,fileid);
|
|
|
52 |
break;
|
|
|
53 |
default:
|
|
|
54 |
assert(false);
|
|
|
55 |
break;
|
|
|
56 |
|
|
|
57 |
};
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
template <TIssueType IssueType>
|
|
|
61 |
void AddIssueField(const HANodeIterator* self,TIssueIdentity classType, const HANodeIterator& ignorenode, int lineNo, const XMLCh* fileid=NULL, const string name = "")
|
|
|
62 |
{
|
|
|
63 |
switch (classType)
|
|
|
64 |
{
|
|
|
65 |
case EIssueIdentityField:
|
|
|
66 |
AddIssue<EIssueIdentityField,IssueType>(self,ignorenode,lineNo,fileid,name);
|
|
|
67 |
break;
|
|
|
68 |
case EIssueIdentityFieldInaccessible:
|
|
|
69 |
AddIssue<EIssueIdentityFieldInaccessible,IssueType>(self,ignorenode,lineNo,fileid, name);
|
|
|
70 |
break;
|
|
|
71 |
default:
|
|
|
72 |
assert(false);
|
|
|
73 |
break;
|
|
|
74 |
|
|
|
75 |
};
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
/**
|
|
|
79 |
* Add issue field
|
|
|
80 |
* @param self pointer to self
|
|
|
81 |
* @param classType type of issue
|
|
|
82 |
* @param ignorenode reference to node
|
|
|
83 |
* @param fileid pointer to fileid
|
|
|
84 |
* @param name reference to name
|
|
|
85 |
*/
|
|
|
86 |
template <TIssueType IssueType>
|
|
|
87 |
void AddIssueField(const HANodeIterator* self,TIssueIdentity classType, const HANodeIterator& ignorenode, int lineNo,const XMLCh* fileid, const DataMember & name)
|
|
|
88 |
{
|
|
|
89 |
switch (classType)
|
|
|
90 |
{
|
|
|
91 |
case EIssueIdentityField:
|
|
|
92 |
AddIssue<EIssueIdentityField,IssueType>(self,ignorenode,lineNo,fileid,name);
|
|
|
93 |
break;
|
|
|
94 |
case EIssueIdentityFieldInaccessible:
|
|
|
95 |
AddIssue<EIssueIdentityFieldInaccessible,IssueType>(self,ignorenode,lineNo,fileid, name);
|
|
|
96 |
break;
|
|
|
97 |
default:
|
|
|
98 |
assert(false);
|
|
|
99 |
break;
|
|
|
100 |
|
|
|
101 |
};
|
|
|
102 |
}
|
|
|
103 |
|
|
|
104 |
|
|
|
105 |
/**
|
|
|
106 |
* The member variables are analyzed for changes in order, type, removal, addition
|
|
|
107 |
* and visibility. Any change, including removal and addition, of the accessible
|
|
|
108 |
* data members of a class is reported.
|
|
|
109 |
*/
|
|
|
110 |
class ClassNodeAnalysis: public NodeAnalysis
|
|
|
111 |
{
|
|
|
112 |
public:
|
|
|
113 |
|
|
|
114 |
static NodeAnalysis* Construct();
|
|
|
115 |
public:
|
|
|
116 |
/**
|
|
|
117 |
* Constructor
|
|
|
118 |
*/
|
|
|
119 |
ClassNodeAnalysis();
|
|
|
120 |
|
|
|
121 |
/**
|
|
|
122 |
* Finds node to analyse it
|
|
|
123 |
* @param baseline baseline node
|
|
|
124 |
* @param current current node
|
|
|
125 |
* @return 0, if there was no issues
|
|
|
126 |
*/
|
|
|
127 |
int FindNodeAndAnalyse(HANodeIterator baseline,HANodeIterator current);
|
|
|
128 |
|
|
|
129 |
/**
|
|
|
130 |
* Analyse
|
|
|
131 |
* @param baseline baseline node
|
|
|
132 |
* @param current current node
|
|
|
133 |
* @param report report or not (default= true)
|
|
|
134 |
* @return 0, if there was no issues
|
|
|
135 |
*/
|
|
|
136 |
int Analyse(HANodeIterator baseline,HANodeIterator current, bool report = true);
|
|
|
137 |
|
|
|
138 |
/**
|
|
|
139 |
* Destructor
|
|
|
140 |
*/
|
|
|
141 |
~ClassNodeAnalysis(){}
|
|
|
142 |
|
|
|
143 |
|
|
|
144 |
protected:
|
|
|
145 |
|
|
|
146 |
/**
|
|
|
147 |
* Analyses fields
|
|
|
148 |
* @param baseline baseline version
|
|
|
149 |
* @param current current version
|
|
|
150 |
* @param bfields base fields vector
|
|
|
151 |
* @param cfields current fields vector
|
|
|
152 |
* @param report to report or not report issues
|
|
|
153 |
* @return 0 if compared fields are equal
|
|
|
154 |
*/
|
|
|
155 |
virtual int compareFields(HANodeIterator baseline,HANodeIterator current,
|
|
|
156 |
const vector<DOMNode*>& bfields, const vector<DOMNode*>& cfields,
|
|
|
157 |
bool report);
|
|
|
158 |
|
|
|
159 |
/**
|
|
|
160 |
* Analyses non-virtual functions
|
|
|
161 |
* @param baseline baseline version
|
|
|
162 |
* @param current current version
|
|
|
163 |
* @param bexportedMethods base exported methods vector
|
|
|
164 |
* @param cexportedMethods current exported methods vector
|
|
|
165 |
* @param identity identity of the issue
|
|
|
166 |
* @param report to report or not report issues
|
|
|
167 |
* @return 0 if compared fields are equal
|
|
|
168 |
*/
|
|
|
169 |
virtual int compareNonvirtualFunctions( HANodeIterator baseline,
|
|
|
170 |
HANodeIterator current,
|
|
|
171 |
const vector<DOMNode*>& bexportedMethods,
|
|
|
172 |
const vector<DOMNode*>& cexportedMethods,
|
|
|
173 |
TIssueIdentity identity,
|
|
|
174 |
bool report);
|
|
|
175 |
|
|
|
176 |
// First bool for signature
|
|
|
177 |
struct MethodMatchFlags
|
|
|
178 |
{
|
|
|
179 |
MethodMatchFlags(bool sM, bool rM) : signatureMatch(sM),returnValueMatch(rM){};
|
|
|
180 |
bool signatureMatch;
|
|
|
181 |
bool returnValueMatch;
|
|
|
182 |
bool IsMatch() {return signatureMatch && returnValueMatch;};
|
|
|
183 |
};
|
|
|
184 |
|
|
|
185 |
/**
|
|
|
186 |
* Analyses virtual functions
|
|
|
187 |
* @param baseline baseline version
|
|
|
188 |
* @param current current version
|
|
|
189 |
* @param bvirtualMethods base virtual methods vector
|
|
|
190 |
* @param cvirtualMethods current virtual methods vector
|
|
|
191 |
* @param report to report or not report issues
|
|
|
192 |
* @return 0 if compared fields are equal
|
|
|
193 |
*/
|
|
|
194 |
virtual int compareVirtualFunctions(HANodeIterator baseline,HANodeIterator current,
|
|
|
195 |
const vector<DOMNode*>& bvirtualMethods,
|
|
|
196 |
const vector<DOMNode*>& cvirtualMethods,
|
|
|
197 |
bool report);
|
|
|
198 |
/**
|
|
|
199 |
* Analyses other members
|
|
|
200 |
* @param baseline baseline version
|
|
|
201 |
* @param current current version
|
|
|
202 |
* @param bothers base other items vector
|
|
|
203 |
* @param cothers current other items vector
|
|
|
204 |
* @param report to report or not report issues
|
|
|
205 |
* @return 0 if compared fields are equal
|
|
|
206 |
*/
|
|
|
207 |
virtual int compareOthers(HANodeIterator baseline,HANodeIterator current,
|
|
|
208 |
const vector<DOMNode*>& bothers, const vector<DOMNode*>& cothers,
|
|
|
209 |
bool report);
|
|
|
210 |
|
|
|
211 |
/**
|
|
|
212 |
* Compares the base sizes of the classes
|
|
|
213 |
* @param baseline to which to compare
|
|
|
214 |
* @param current what to compare
|
|
|
215 |
* @param bfields base data member table
|
|
|
216 |
* @param cfields current data member table
|
|
|
217 |
* @param report if true finding are reported
|
|
|
218 |
* @return 0 if compared fields are equal
|
|
|
219 |
*/
|
|
|
220 |
virtual int compareBaseSizes(HANodeIterator baseline, HANodeIterator current, const NodeIndex::dtable_t& bfields, const NodeIndex::dtable_t& cfields, bool report);
|
|
|
221 |
|
|
|
222 |
protected:
|
|
|
223 |
|
|
|
224 |
/**
|
|
|
225 |
* Compares changes in inheritance
|
|
|
226 |
* @param baseline to which to compare
|
|
|
227 |
* @param current what to compare
|
|
|
228 |
* @param report if true findings are reported
|
|
|
229 |
* @return 0 if compared fields are equal
|
|
|
230 |
*/
|
|
|
231 |
int compareBases(HANodeIterator baseline,HANodeIterator current, bool report);
|
|
|
232 |
|
|
|
233 |
/**
|
|
|
234 |
* Compares methods by function signature (return value is not involved)
|
|
|
235 |
* @param basemethod basemethod to compare
|
|
|
236 |
* @param currentmethod current to compare
|
|
|
237 |
* @return true if signature isn't changed
|
|
|
238 |
*/
|
|
|
239 |
bool compareMethodsSignature(HANodeIterator basemethod,HANodeIterator currentmethod, const NodeTypeComparator& comparator);
|
|
|
240 |
|
|
|
241 |
/**
|
|
|
242 |
* Compares all the members of the class
|
|
|
243 |
* @param baseline baseline version
|
|
|
244 |
* @param current current version
|
|
|
245 |
* @param report if true findings are reported
|
|
|
246 |
* @return 0 if there was no issues
|
|
|
247 |
*/
|
|
|
248 |
int compareClassMembers(HANodeIterator baseline,HANodeIterator current, bool report);
|
|
|
249 |
|
|
|
250 |
/**
|
|
|
251 |
* Analyses and reports the differences between two fields
|
|
|
252 |
* @param basefield baseline field
|
|
|
253 |
* @param currentfield current field
|
|
|
254 |
* @param report if true findings are reported
|
|
|
255 |
* @return 0 if compared fields are equal
|
|
|
256 |
*/
|
|
|
257 |
//int compareField(HANodeIterator basefield,HANodeIterator currentfield, bool report);
|
|
|
258 |
|
|
|
259 |
/**
|
|
|
260 |
* Analyses and reports the differences between two fields
|
|
|
261 |
* @param baseline baseline version
|
|
|
262 |
* @param current current version
|
|
|
263 |
* @param basemember base member to compare
|
|
|
264 |
* @param currentmember current member to compare
|
|
|
265 |
* @param report if true findings are reported
|
|
|
266 |
* @return 0 if compared fields are equal
|
|
|
267 |
*/
|
|
|
268 |
int compareField(HANodeIterator baseline, HANodeIterator current, const DataMember& basemember,const DataMember& currentmember, bool report);
|
|
|
269 |
|
|
|
270 |
/**
|
|
|
271 |
* Analyses the methods return value
|
|
|
272 |
* @param basemethod baseline method
|
|
|
273 |
* @param currentmethod current method
|
|
|
274 |
* @return true if method returns are equal
|
|
|
275 |
*/
|
|
|
276 |
bool compareMethodsReturn(HANodeIterator basemethod,HANodeIterator currentmethod,NodeTypeComparator& cmp);
|
|
|
277 |
|
|
|
278 |
/**
|
|
|
279 |
* Index virtual methods
|
|
|
280 |
* @param node node to index
|
|
|
281 |
* @param virtualMethods virtual methods in node
|
|
|
282 |
* @param vtable virtual method table
|
|
|
283 |
* @param virtualMethodsWithIndex methods indexed
|
|
|
284 |
*/
|
|
|
285 |
void indexVirtualMethods(HANodeIterator node,
|
|
|
286 |
const vector<DOMNode*>& virtualMethods,
|
|
|
287 |
const NodeIndex::vtable_t& vtable,
|
|
|
288 |
vector<pair<DOMNode*,int> >& virtualMethodsWithIndex);
|
|
|
289 |
|
|
|
290 |
/**
|
|
|
291 |
* Compare virtual methods
|
|
|
292 |
* @param baseline baseline version
|
|
|
293 |
* @param current current version
|
|
|
294 |
* @param basevtable base virtual method table
|
|
|
295 |
* @param currentvtable current virtual method table
|
|
|
296 |
* @param report if true findings are reported
|
|
|
297 |
*/
|
|
|
298 |
int compareVirtualTables(HANodeIterator baseline,HANodeIterator current,
|
|
|
299 |
const NodeIndex::vtable_t& basevtable,
|
|
|
300 |
const NodeIndex::vtable_t& currentvtable,
|
|
|
301 |
bool report);
|
|
|
302 |
|
|
|
303 |
// Contains basemethod pointer and a boolean flag telling whether
|
|
|
304 |
// the method was found in current methods or not.
|
|
|
305 |
typedef map<DOMNode*, MethodMatchFlags> MethodMatchMap;
|
|
|
306 |
virtual int compareNonvirtualFunctions( HANodeIterator baseline,
|
|
|
307 |
HANodeIterator current,
|
|
|
308 |
const vector<DOMNode*>& bexportedMethods,
|
|
|
309 |
const vector<DOMNode*>& cexportedMethods,
|
|
|
310 |
TIssueIdentity identity,
|
|
|
311 |
bool report,
|
|
|
312 |
ComparatorVector::const_iterator comparator,
|
|
|
313 |
MethodMatchMap& baseMap,
|
|
|
314 |
MethodMatchMap& currMap,
|
|
|
315 |
int comparatorRound);
|
|
|
316 |
|
|
|
317 |
protected:
|
|
|
318 |
|
|
|
319 |
//! To report added members
|
|
|
320 |
bool iReportAddedMembers;
|
|
|
321 |
//! Identity of the issue found
|
|
|
322 |
TIssueIdentity iIdentity;
|
|
|
323 |
};
|
|
|
324 |
|
|
|
325 |
#endif
|