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 __ANALYSER_H__
|
|
20 |
#define __ANALYSER_H__
|
|
21 |
|
|
22 |
#include "CmdGlobals.h"
|
|
23 |
#ifdef __WIN__
|
|
24 |
#pragma warning(disable:4786)
|
|
25 |
#endif
|
|
26 |
|
|
27 |
#include <string>
|
|
28 |
#include <vector>
|
|
29 |
#include <map>
|
|
30 |
#include <list>
|
|
31 |
|
|
32 |
#include <xercesc/dom/DOM.hpp>
|
|
33 |
#include "ReportGenerator.h"
|
|
34 |
#include "AnalyserParams.h"
|
|
35 |
#include "PlatformData.h"
|
|
36 |
|
|
37 |
class CommandLine;
|
|
38 |
class CPPParser;
|
|
39 |
|
|
40 |
using namespace std;
|
|
41 |
XERCES_CPP_NAMESPACE_USE
|
|
42 |
|
|
43 |
typedef pair<string,string> stringpair;
|
|
44 |
typedef vector<string> stringvector;
|
|
45 |
typedef map<string,string> stringmap;
|
|
46 |
typedef stringvector::const_iterator StringVecIterC;
|
|
47 |
typedef stringmap::const_iterator StringMapIterC;
|
|
48 |
typedef stringvector::iterator StringVecIter;
|
|
49 |
typedef stringmap::iterator StringMapIter;
|
|
50 |
typedef pair<Header*, Header*> HeaderPair;
|
|
51 |
typedef vector<HeaderPair> PlatformHeaders;
|
|
52 |
|
|
53 |
/**
|
|
54 |
* LessStringPair
|
|
55 |
* This function returns true if the stringpair lhs is less than the rhs.
|
|
56 |
*/
|
|
57 |
inline bool LessStringPair( const stringpair& lhs, const stringpair& rhs )
|
|
58 |
{
|
|
59 |
if( lhs.first == rhs.first )
|
|
60 |
return lhs.second < rhs.second;
|
|
61 |
|
|
62 |
return lhs.first < rhs.first;
|
|
63 |
}
|
|
64 |
|
|
65 |
template<class TYPE> struct RemoveTrailingDirSeparator : public unary_function<TYPE, void>{} ;
|
|
66 |
/**
|
|
67 |
* RemoveTrailingDirSeparator
|
|
68 |
* Template function which removes the trailing dir separator from the filename.
|
|
69 |
*/
|
|
70 |
template<> struct RemoveTrailingDirSeparator<stringpair> : public unary_function<stringpair, void>
|
|
71 |
{
|
|
72 |
void operator() (stringpair& x)
|
|
73 |
{
|
|
74 |
if( x.first.at(0) == DIR_SEPARATOR )
|
|
75 |
{
|
|
76 |
x.first.erase(0,1);
|
|
77 |
}
|
|
78 |
if( x.second.at(0) == DIR_SEPARATOR )
|
|
79 |
{
|
|
80 |
x.second.erase(0,1);
|
|
81 |
}
|
|
82 |
}
|
|
83 |
};
|
|
84 |
|
|
85 |
struct StructMember
|
|
86 |
{
|
|
87 |
string elementName;
|
|
88 |
string elementType;
|
|
89 |
string elementValue;
|
|
90 |
int lineNo;
|
|
91 |
};
|
|
92 |
|
|
93 |
struct StructElement
|
|
94 |
{
|
|
95 |
string structName;
|
|
96 |
vector<StructMember>members; // pair<memType,memNeme>
|
|
97 |
int lineNo;
|
|
98 |
};
|
|
99 |
struct EnumMember
|
|
100 |
{
|
|
101 |
string enumMemName; // mem name
|
|
102 |
string enumVal; // memvalue
|
|
103 |
int lineNo;
|
|
104 |
};
|
|
105 |
struct EnumElement
|
|
106 |
{
|
|
107 |
string enumName;
|
|
108 |
vector<EnumMember> enums;
|
|
109 |
int lineNo;
|
|
110 |
};
|
|
111 |
|
|
112 |
struct MacroElement
|
|
113 |
{
|
|
114 |
string macroName; // pair<macro name , macro value>
|
|
115 |
string macroVal;
|
|
116 |
int lineNo;
|
|
117 |
};
|
|
118 |
|
|
119 |
struct ResourceContent
|
|
120 |
{
|
|
121 |
string RHFileName;
|
|
122 |
vector<StructElement> structList;
|
|
123 |
vector<EnumElement> enumList;
|
|
124 |
vector<MacroElement> macroList;
|
|
125 |
};
|
|
126 |
|
|
127 |
|
|
128 |
/**
|
|
129 |
* The parameters given to Headeranalyser are stored in in this class.
|
|
130 |
* Analyser class also coordinates the operation of other components and
|
|
131 |
* handles the environment variables handling.
|
|
132 |
*/
|
|
133 |
class Analyser
|
|
134 |
{
|
|
135 |
public:
|
|
136 |
/**
|
|
137 |
* Constructor
|
|
138 |
* @param args Pointer to commanline arguments
|
|
139 |
* @param argc Argument count
|
|
140 |
*/
|
|
141 |
Analyser(char** args, int argc);
|
|
142 |
|
|
143 |
/**
|
|
144 |
* Constructor
|
|
145 |
*/
|
|
146 |
Analyser();
|
|
147 |
|
|
148 |
/**
|
|
149 |
* Destructor
|
|
150 |
*/
|
|
151 |
~Analyser();
|
|
152 |
|
|
153 |
public:
|
|
154 |
/**
|
|
155 |
* Does the actual analyse of headers and creates a analysis report.
|
|
156 |
* @return Error code, return code 0 means no error.
|
|
157 |
*/
|
|
158 |
int analyse();
|
|
159 |
|
|
160 |
/**
|
|
161 |
* Check files in dir
|
|
162 |
* @param baselineFile Baseline platform's file to be analysed
|
|
163 |
* @param currentFile Current platform's file to be analysed
|
|
164 |
* @param reportfile The name of the report file
|
|
165 |
* @return Error code, return code 0 means no error.
|
|
166 |
*/
|
|
167 |
//int analyse(string baselineFile, string currentFile, string reportfile);
|
|
168 |
|
|
169 |
/**
|
|
170 |
* Starts analysing the headers by passing the parsed trees to analyser
|
|
171 |
* components.
|
|
172 |
* @param baseline Pointer to the root of the tree parsed from the baseline
|
|
173 |
* platform
|
|
174 |
* @param current Pointer to the root of the tree parsed from the current
|
|
175 |
* platform
|
|
176 |
* @param files Headerfiles to be analysed
|
|
177 |
* @param report Reference to a <code>ReportGenerator</code> object
|
|
178 |
* @return Error code, return code 0 means no error.
|
|
179 |
*/
|
|
180 |
int analyseTrees(DOMNode* baseline, DOMNode* current, const list< pair<string,string> >& files, ReportGenerator & report);
|
|
181 |
|
|
182 |
/**
|
|
183 |
* Analyse bundle of files. Bundle size is between 1- 9999.
|
|
184 |
*
|
|
185 |
* @param basefilenames Bundle of filenames in baseline platform
|
|
186 |
* @param curfilenames Bundle of filenames in current platform
|
|
187 |
* @param report Reference to <code>ReportGenerator</code>
|
|
188 |
* @param issues Number of issues found
|
|
189 |
* @return Returns true, if the analysis was successful and no
|
|
190 |
* exceptions were caught.
|
|
191 |
*/
|
|
192 |
bool AnalyseBundle( const stringvector& basefilenames,
|
|
193 |
const stringvector& curfilenames,
|
|
194 |
ReportGenerator& report,
|
|
195 |
int& issues,
|
|
196 |
CPPParser* baseParser = 0,
|
|
197 |
CPPParser* currParser = 0,
|
|
198 |
stringvector* basecompileset = 0,
|
|
199 |
stringvector* currcompileset = 0);
|
|
200 |
|
|
201 |
|
|
202 |
private:
|
|
203 |
|
|
204 |
// base type
|
|
205 |
enum basetype {
|
|
206 |
EBase=0,
|
|
207 |
ECurrent
|
|
208 |
};
|
|
209 |
|
|
210 |
/**
|
|
211 |
* guard exists. checks for existence of "include" guards in the set of files
|
|
212 |
* @param aFiles, set of files to be evaluated
|
|
213 |
* @param aGuard, include guard returned for aFile
|
|
214 |
* @return boolean value indicating existence of "include" guards
|
|
215 |
*/
|
|
216 |
bool guardExists(const string& aFile, string& aGuard);
|
|
217 |
|
|
218 |
/**
|
|
219 |
* Validate Headers. validates headers for automatic include guard inclusion
|
|
220 |
* this scans both the pairs of headers passed as arguments
|
|
221 |
* it creates a seperate headers pair list of those that do not have include guards.
|
|
222 |
* @param aFiles, set of files to be evaluated
|
|
223 |
* @param aUnsuccessful, set of files without include guards
|
|
224 |
*/
|
|
225 |
void validateHeaders(vector<pair<string, string> >& aFiles, vector<pair<string, string> >& aUnsuccessful);
|
|
226 |
|
|
227 |
/**
|
|
228 |
* Read parameters. readParameters should be called so that first is called
|
|
229 |
* baseline command and after that current command, otherwise it
|
|
230 |
* doesn't work.
|
|
231 |
* @param type Platform type, either baseline or current.
|
|
232 |
* @param files List of files
|
|
233 |
* @param forcedheaders List of forced headers given in commandline arguments
|
|
234 |
*/
|
|
235 |
void readParameters(basetype type, list<pair<string,string> >& files, string& forcedheaders);
|
|
236 |
|
|
237 |
/**
|
|
238 |
* Finds a replacement for a given baseline header if any. Tries to find an
|
|
239 |
* entry for the given <code>aFile</code> and returns an <code>std::pair</code>
|
|
240 |
* containing original (baseline) filename and the replacing filename.
|
|
241 |
* @param aFile String pair containing filename to be checked.
|
|
242 |
* @param aReplaceMap Map containing the files to be replaced with the replacing ones.
|
|
243 |
* @param aCurrentFiles List of the current platforms headerfiles.
|
|
244 |
* @return Pair containing the baseline header's name as a first string and the
|
|
245 |
* replacing name as a second string.
|
|
246 |
*/
|
|
247 |
pair<string, string> processFileReplaces(pair<string, string>& aFile, const stringmap& aReplaceMap, list<pair<string, string> >& aCurrentFiles);
|
|
248 |
|
|
249 |
/**
|
|
250 |
* Explodes the replace list (a string) into a map.
|
|
251 |
*
|
|
252 |
* String syntax is:
|
|
253 |
* original filename>replacement file;original filename>replacement;...
|
|
254 |
*
|
|
255 |
* Original filename must refer to the baseline file that has been
|
|
256 |
* replaced with replacement file in the current version; original
|
|
257 |
* filename must not contain a path, just the simple filename.
|
|
258 |
*
|
|
259 |
* Replacement filename must contain the full path of the current
|
|
260 |
* version file that replaces the baseline file (original filename).
|
|
261 |
*
|
|
262 |
* @param aReplaceList Value of a commandline argument containing the file replacements.
|
|
263 |
* @param aReplaceMap Reference to the map in which the headerfile pairs are populated.
|
|
264 |
*/
|
|
265 |
void createReplaceMap(const string& aReplaceList, stringmap& aReplaceMap);
|
|
266 |
|
|
267 |
/**
|
|
268 |
* Checks file differencies
|
|
269 |
* @param aFiles Files to check
|
|
270 |
* @param aMismatches Mismatches found
|
|
271 |
*/
|
|
272 |
void fileDiffs(vector<pair<string, string> >& aFiles, list<string>& aMismatches);
|
|
273 |
|
|
274 |
/**
|
|
275 |
* Gets filename without path
|
|
276 |
* @param aFilename Original filename (with or without the path).
|
|
277 |
* @return Plain filename with the path stripped off.
|
|
278 |
*/
|
|
279 |
string getFilenameWithoutDir(const string& aFilename);
|
|
280 |
|
|
281 |
/**
|
|
282 |
* Validates and processes given commandline parameters.
|
|
283 |
* @return 0, if processing succeeds.
|
|
284 |
*/
|
|
285 |
int processParameters();
|
|
286 |
|
|
287 |
/**
|
|
288 |
* Tests if the file is available
|
|
289 |
* @param map Map of files
|
|
290 |
*/
|
|
291 |
//void testFileAvailability(stringmap map);
|
|
292 |
|
|
293 |
/**
|
|
294 |
* Merges baseline and current files into one vector.
|
|
295 |
* @param aBasefiles List of baseline files.
|
|
296 |
* @param aCurrentfiles List of current files.
|
|
297 |
* @param aReplaceList Value of a commandline argument containing the file replacements.
|
|
298 |
* @param aMatches Vector in which the matching files are returned.
|
|
299 |
*/
|
|
300 |
void MergeFiles(const list<pair<string, string> >& aBasefiles, list<pair<string, string> >& aCurrentfiles,
|
|
301 |
const string& aReplaceList, vector<pair<string, string> >& aMatches);
|
|
302 |
|
|
303 |
/**
|
|
304 |
* Check files in dir
|
|
305 |
* @param allfiles list of files to check
|
|
306 |
* @param sets
|
|
307 |
* @return list pair of files
|
|
308 |
*/
|
|
309 |
void diffs( const list<pair<string, string> >& allfiles,
|
|
310 |
const list<pair<string, string> >& sets,
|
|
311 |
list<pair<string, string> >& result);
|
|
312 |
|
|
313 |
/**
|
|
314 |
* Get the actual name of a file.
|
|
315 |
* @param sets
|
|
316 |
* @return list pair of files
|
|
317 |
*/
|
|
318 |
list<stringpair > canonicalizeFilename(list<pair<string,string> >& sets);
|
|
319 |
|
|
320 |
/**
|
|
321 |
* Check and fix bundlesize parameter value
|
|
322 |
* Show warnig, if the value is over warning level.
|
|
323 |
* @return bundlesize
|
|
324 |
*/
|
|
325 |
int handleBundlesizeParam();
|
|
326 |
|
|
327 |
/**
|
|
328 |
* Get replace parameter
|
|
329 |
* @return string of replace files
|
|
330 |
*/
|
|
331 |
string getReplaceParam();
|
|
332 |
|
|
333 |
/**
|
|
334 |
* To Initailze iBasePlatformData and iProductPlatformData
|
|
335 |
* and set all the headers' status provided for analyse to 'HDR_STATUS_TO_BE_ANALYZED'.
|
|
336 |
*/
|
|
337 |
void InitializePlatforms(PlatformHeaders& pfHeaders, vector<pair<string, string> >& headers, vector<pair<string, string> >& excludeheaders, vector<pair<string, string> >& resourcevector);
|
|
338 |
|
|
339 |
/**
|
|
340 |
* To analyse all the provided headers with system include paths and additional dependent headers.
|
|
341 |
*/
|
|
342 |
void AnalyzePlatforms(PlatformHeaders& pfHeaders, PlatformHeaders& unsuccessfulHeaders, ReportGenerator& report, int& issues, bool createThread);
|
|
343 |
|
|
344 |
/**
|
|
345 |
* To analyse header with default parameters.
|
|
346 |
*/
|
|
347 |
void AnalyseHeaders(const vector<pair<string, string> >& headerList, int bundlesize, ReportGenerator& report, int& issues, int& compErrors);
|
|
348 |
|
|
349 |
/**
|
|
350 |
* Wrapper function to analyse all files in a component in separate thread
|
|
351 |
*
|
|
352 |
* @param report Reference to <code>ReportGenerator</code>
|
|
353 |
* @param issues Number of issues found
|
|
354 |
* @param baseParser CPPParser object
|
|
355 |
* @param currParser CPPParser object
|
|
356 |
* @param pfHeaders Reference to PlatformHeaders
|
|
357 |
* @param unsuccessfulHdrs Reference to unsuccessful PlatformHeaders
|
|
358 |
*/
|
|
359 |
void Analyser::Wrapper( ReportGenerator& report,
|
|
360 |
int& issues,
|
|
361 |
CPPParser baseParser,
|
|
362 |
CPPParser currParser,
|
|
363 |
PlatformHeaders& pfHeaders,
|
|
364 |
PlatformHeaders& unsuccessfulHdrs
|
|
365 |
);
|
|
366 |
|
|
367 |
/**
|
|
368 |
* Wrapper function to analyse group of files in a component individually in different thread
|
|
369 |
*
|
|
370 |
* @param filenames Vector of filenames to be analysed individually
|
|
371 |
* @param pfHeaders Reference to PlatformHeaders
|
|
372 |
* @param unsuccessfulHdrs Reference to unsuccessful PlatformHeaders
|
|
373 |
* @param report Reference to <code>ReportGenerator</code>
|
|
374 |
* @param issues Number of issues found
|
|
375 |
*/
|
|
376 |
void Analyser::Wrapper2(stringvector filenames, PlatformHeaders& pfHeaders, PlatformHeaders& unsuccessfulHeaders, ReportGenerator& report, int& issues);
|
|
377 |
|
|
378 |
/**
|
|
379 |
* To analysis of .rh file, using text parser.
|
|
380 |
* resourcevector - list of baseline and current .rh pair
|
|
381 |
* icludes- any included file other than .rh will be returned
|
|
382 |
* report - Report pointer to fill issues in report
|
|
383 |
*/
|
|
384 |
void ParseAndCompareResourceFiles(vector<pair< string, string> >& resourcevector, ReportGenerator& report);
|
|
385 |
|
|
386 |
/**
|
|
387 |
* Get list of enums, structs and macros in ResourceContent, present in one .rh file, using text parser.
|
|
388 |
* includes - returns list of .rh files included in current analyzed .rh file
|
|
389 |
*/
|
|
390 |
void getElementListFromRHFile(std::ifstream& RHFile,ResourceContent& resource, vector<string>& includes );
|
|
391 |
|
|
392 |
/**
|
|
393 |
* Comapre baseline and current resources filled in ResourceContent data stucture.
|
|
394 |
* report - Report pointer to fill issues in report
|
|
395 |
*/
|
|
396 |
void compareResources(ResourceContent& baseResource, ResourceContent& curResource, ReportGenerator& report);
|
|
397 |
|
|
398 |
private:
|
|
399 |
|
|
400 |
//! Pointer to Commandline object
|
|
401 |
CommandLine* iCmdLine;
|
|
402 |
|
|
403 |
//! Pointer to CPPParser object
|
|
404 |
CPPParser* iCPPParser;
|
|
405 |
|
|
406 |
//! count of analysed files
|
|
407 |
int iAnalysedFileCount;
|
|
408 |
|
|
409 |
//! true if the header set is given with SET parameter
|
|
410 |
bool iHeaderSetInUse;
|
|
411 |
|
|
412 |
//! count of files
|
|
413 |
list<pair<string, string> > iFiles;
|
|
414 |
|
|
415 |
//! count of files
|
|
416 |
list<pair<string, string> > iFiles2;
|
|
417 |
|
|
418 |
//! String containing forced baseline file names
|
|
419 |
string iForcedBaselineHeaders;
|
|
420 |
|
|
421 |
//! String containing forced current file names
|
|
422 |
string iForcedCurrentHeaders;
|
|
423 |
|
|
424 |
//! Parameter to analyser
|
|
425 |
AnalyserParams iParams;
|
|
426 |
|
|
427 |
//! Reference to ReportGenerator
|
|
428 |
ReportGenerator iReport;
|
|
429 |
|
|
430 |
//! List of not removed files
|
|
431 |
list<string> iNotRemovedFiles;
|
|
432 |
|
|
433 |
//! Files with macros
|
|
434 |
list<string> iMacroFiles;
|
|
435 |
|
|
436 |
//! Name of the macrofile
|
|
437 |
string iCompErrTxt;
|
|
438 |
|
|
439 |
//! Resource File Already Anaylyzed
|
|
440 |
|
|
441 |
vector<pair<string, string> > iRHFile_Analyzed;
|
|
442 |
|
|
443 |
|
|
444 |
//! Pointer Variable to store base platform data
|
|
445 |
PlatformData* iBasePlatformData;
|
|
446 |
|
|
447 |
//! Pointer Variable to store product platform data
|
|
448 |
PlatformData* iProductPlatformData;
|
|
449 |
|
|
450 |
//! Flag to check base platformdata's existence
|
|
451 |
bool iUseBaselinePlatformData;
|
|
452 |
|
|
453 |
//! Flag to check product platformdata's existence
|
|
454 |
bool iUseCurrentPlatformData;
|
|
455 |
|
|
456 |
//! Flag set to be true,if 2nd time analyze with single header required
|
|
457 |
bool iOnlySystemIncludeRequired;
|
|
458 |
|
|
459 |
//! Headers to be analyzed in baseline platform
|
|
460 |
stringvector iBaseFilenames;
|
|
461 |
|
|
462 |
//! Headers to be analyzed in product platform
|
|
463 |
stringvector iCurrFilenames;
|
|
464 |
|
|
465 |
//! Files without include guards need to be compiled individually
|
|
466 |
PlatformHeaders iInvalidFiles;
|
|
467 |
|
|
468 |
//! Additional headers needed to compile baseline
|
|
469 |
stringvector iBaseIncludes;
|
|
470 |
|
|
471 |
//! Additional headers needed to compile product
|
|
472 |
stringvector iCurrIncludes;
|
|
473 |
|
|
474 |
//! False by default. If mentioned then use thread. Set the bool to true.
|
|
475 |
bool iUseThread;
|
|
476 |
|
|
477 |
};
|
|
478 |
|
|
479 |
#endif
|