|
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 __CPP_PARSER_H__
|
|
|
20 |
#define __CPP_PARSER_H__
|
|
|
21 |
#include "CmdGlobals.h"
|
|
|
22 |
#ifdef __WIN__
|
|
|
23 |
#pragma warning(disable:4786)
|
|
|
24 |
#endif
|
|
|
25 |
|
|
|
26 |
#include <xercesc/dom/DOM.hpp>
|
|
|
27 |
#include <iostream>
|
|
|
28 |
#include <list>
|
|
|
29 |
#include <string>
|
|
|
30 |
#include <vector>
|
|
|
31 |
|
|
|
32 |
#include "CmdGlobals.h"
|
|
|
33 |
|
|
|
34 |
using namespace std;
|
|
|
35 |
|
|
|
36 |
typedef vector<string> headervector;
|
|
|
37 |
|
|
|
38 |
XERCES_CPP_NAMESPACE_USE
|
|
|
39 |
|
|
|
40 |
|
|
|
41 |
/**
|
|
|
42 |
* The CPPParser provides interface for the GCCXML program for C++ parsing functionality
|
|
|
43 |
* It produces a XML document that the HeaderAnalyser interface receives as a input
|
|
|
44 |
* for BBC analysis. The result of the analysis from the HeaderAnalysis is also
|
|
|
45 |
* a XML document.
|
|
|
46 |
*/
|
|
|
47 |
class CPPParser {
|
|
|
48 |
|
|
|
49 |
// Construction / destruction
|
|
|
50 |
public:
|
|
|
51 |
|
|
|
52 |
/**
|
|
|
53 |
* Constructor
|
|
|
54 |
* @param epocroot root of the platform headers( baseline or current)
|
|
|
55 |
*/
|
|
|
56 |
CPPParser(string epocroot);
|
|
|
57 |
|
|
|
58 |
/**
|
|
|
59 |
* Destructor
|
|
|
60 |
*/
|
|
|
61 |
~CPPParser();
|
|
|
62 |
|
|
|
63 |
// Interface methods
|
|
|
64 |
public:
|
|
|
65 |
|
|
|
66 |
/**
|
|
|
67 |
* Parse the filename vectors into XML and eventually into a DOM format
|
|
|
68 |
* @param aFilenames vector of filename to parse
|
|
|
69 |
* @param aVersion version string
|
|
|
70 |
* @param aPath header path
|
|
|
71 |
* @param notRemovedFiles list of not removed files
|
|
|
72 |
* @return pointer to DOMnode
|
|
|
73 |
*/
|
|
|
74 |
DOMNode* parse(const vector<string>& aFilenames, string aVersion, string aPath, list<string>& notRemovedFiles);
|
|
|
75 |
|
|
|
76 |
/**
|
|
|
77 |
* Set baseline directory
|
|
|
78 |
* @param aDir header path
|
|
|
79 |
*/
|
|
|
80 |
void setBaselineDir(string aDir);
|
|
|
81 |
|
|
|
82 |
/**
|
|
|
83 |
* Set forced headers.Specifies a file which is always included
|
|
|
84 |
* first in generated temporary cpp file.
|
|
|
85 |
* @param aHeaders fors
|
|
|
86 |
*/
|
|
|
87 |
void setForcedHeaders(const string& aHeaders);
|
|
|
88 |
|
|
|
89 |
/**
|
|
|
90 |
* Set temporary directory to member variable
|
|
|
91 |
* @param aTempDir reference to temp directory name
|
|
|
92 |
*/
|
|
|
93 |
void setTemp(const string& aTempDir);
|
|
|
94 |
|
|
|
95 |
/**
|
|
|
96 |
* Get macro filename
|
|
|
97 |
* @return name of the file containing all macros found
|
|
|
98 |
*/
|
|
|
99 |
string getMacroFilename();
|
|
|
100 |
|
|
|
101 |
/**
|
|
|
102 |
* Get compilation error file
|
|
|
103 |
* @return compilation error file
|
|
|
104 |
*/
|
|
|
105 |
string getCompErrFile();
|
|
|
106 |
|
|
|
107 |
/**
|
|
|
108 |
* Remove file
|
|
|
109 |
* @param file filename to remove
|
|
|
110 |
* @param notRemovedFiles list of files that couldn't get removed
|
|
|
111 |
*/
|
|
|
112 |
static void RemoveFile(string file, list<string>& notRemovedFiles);
|
|
|
113 |
|
|
|
114 |
|
|
|
115 |
// Helper functions
|
|
|
116 |
private:
|
|
|
117 |
/**
|
|
|
118 |
* Converts a header file with given filename to an XML file
|
|
|
119 |
* (with same base filename and extension .xml).
|
|
|
120 |
*
|
|
|
121 |
* @param aAbsFilename filename to convert
|
|
|
122 |
* @param aVersion version string
|
|
|
123 |
* @return 0 if the conversion succeeded
|
|
|
124 |
* @exception Throw an exception on error
|
|
|
125 |
*/
|
|
|
126 |
int ConvertHToXML(string aAbsFilename, string aVersion);
|
|
|
127 |
|
|
|
128 |
/**
|
|
|
129 |
* Reads in and parses an XML file with given filename. Set the
|
|
|
130 |
* pointer to the document root (DOM Tree root).
|
|
|
131 |
*
|
|
|
132 |
* @param aAbsFilename XML filename to parse
|
|
|
133 |
* @return 0 if the parse succeeded
|
|
|
134 |
*/
|
|
|
135 |
int ExtractDOMFromXML(const string& aAbsFilename);
|
|
|
136 |
|
|
|
137 |
/**
|
|
|
138 |
* Dump macros file
|
|
|
139 |
* @param mdumpfile nacro dumpfile
|
|
|
140 |
* @param ifile
|
|
|
141 |
* @param headers list of headers
|
|
|
142 |
* @return 0 if success
|
|
|
143 |
*/
|
|
|
144 |
int DumpMacros(string mdumpfile, string ifile, vector<string>& headers);
|
|
|
145 |
|
|
|
146 |
/**
|
|
|
147 |
* Preprocess header file
|
|
|
148 |
* @param aAbsFilename filename to remove
|
|
|
149 |
* @param aVersion version name to parse
|
|
|
150 |
* @param aHeaders vector of headers to preprocess
|
|
|
151 |
* @return 0, if success
|
|
|
152 |
*/
|
|
|
153 |
int PreprocessH(string aAbsFilename, string aVersion, vector<string>& aHeaders );
|
|
|
154 |
|
|
|
155 |
/**
|
|
|
156 |
* Opens header file as input, write findings to output file
|
|
|
157 |
* @param aFilename input filename
|
|
|
158 |
* @param aVersion version name to handle
|
|
|
159 |
* @return 0 if success
|
|
|
160 |
*/
|
|
|
161 |
int HandleExports(string aFilename, string aVersion);
|
|
|
162 |
|
|
|
163 |
/**
|
|
|
164 |
* Replace exports
|
|
|
165 |
* @param line line to process from input file
|
|
|
166 |
* @param processedline line processed
|
|
|
167 |
* @return
|
|
|
168 |
*/
|
|
|
169 |
//int ReplaceExport(string line, string& processedline);
|
|
|
170 |
|
|
|
171 |
/**
|
|
|
172 |
* Generate temporary CPP-file
|
|
|
173 |
* @param aFiles filename to remove
|
|
|
174 |
* @param aVersion
|
|
|
175 |
* @param aHeaders
|
|
|
176 |
* @return
|
|
|
177 |
*/
|
|
|
178 |
string generateTempCPPFile(const vector<string>& aFiles, string aVersion, vector<string>& aHeaders );
|
|
|
179 |
|
|
|
180 |
/**
|
|
|
181 |
* Get value of environment variable
|
|
|
182 |
* @param aEnvVarName variable to get
|
|
|
183 |
* @return value of the variable
|
|
|
184 |
* @exception throw axeption if the variable vaue isn't found
|
|
|
185 |
*/
|
|
|
186 |
char* getEnv(char* aEnvVarName);
|
|
|
187 |
|
|
|
188 |
/**
|
|
|
189 |
* Append headers to file
|
|
|
190 |
* @param aHeaders reference to headerpaths
|
|
|
191 |
* @param aFile the header file which the path is taken from
|
|
|
192 |
*/
|
|
|
193 |
void AppendHeader( vector<string>& aHeaders, string aFile );
|
|
|
194 |
|
|
|
195 |
/**
|
|
|
196 |
* Generate GCXML command for prepocessing
|
|
|
197 |
* @param currentDir current directory
|
|
|
198 |
* @param epocRoot epocroot directory
|
|
|
199 |
* @param inputFile to parser
|
|
|
200 |
* @param outputFile to parser
|
|
|
201 |
* @param aHeaders reference to headerpaths
|
|
|
202 |
* @return commandline string to start parser
|
|
|
203 |
*/
|
|
|
204 |
string GeneratePreprocessCmd(const string& currentDir,const string& epocRoot,const string& inputFile,
|
|
|
205 |
const string& outputFile, vector<string>& aHeaders );
|
|
|
206 |
|
|
|
207 |
/**
|
|
|
208 |
* Generate GCXML command for prepocessing
|
|
|
209 |
* @param currentDir current directory
|
|
|
210 |
* @param epocRoot epocroot directory
|
|
|
211 |
* @param inputFile to parser
|
|
|
212 |
* @param outputFile to parser
|
|
|
213 |
* @return commandline string to start parser
|
|
|
214 |
*/
|
|
|
215 |
string GenerateCompilationCmd(const string& currentDir,const string& epocRoot,const string& inputFile,
|
|
|
216 |
const string& outputFile);
|
|
|
217 |
|
|
|
218 |
/**
|
|
|
219 |
* Generate macro extraction command
|
|
|
220 |
* @param currentDir current directory
|
|
|
221 |
* @param epocRoot root directory of headers
|
|
|
222 |
* @param inputFile to parser
|
|
|
223 |
* @param outputFile to parser
|
|
|
224 |
* @param aHeaders reference to headerpaths
|
|
|
225 |
* @return commandline string to start parser
|
|
|
226 |
*/
|
|
|
227 |
string GenerateMacroExtract(const string& currentDir,const string& epocRoot,const string& inputFile,const string& outputFile,
|
|
|
228 |
vector<string>& aHeaders );
|
|
|
229 |
|
|
|
230 |
// Instance variables
|
|
|
231 |
private:
|
|
|
232 |
//! File name for input
|
|
|
233 |
string iInputFilename;
|
|
|
234 |
|
|
|
235 |
//! File name for output
|
|
|
236 |
string iOutputFilename;
|
|
|
237 |
|
|
|
238 |
//! Path where the XML output goes
|
|
|
239 |
string iXMLOutputPath;
|
|
|
240 |
|
|
|
241 |
//! EPOC root path
|
|
|
242 |
string iEpocRoot;
|
|
|
243 |
|
|
|
244 |
//! Working file
|
|
|
245 |
string iOriginalFilename;
|
|
|
246 |
|
|
|
247 |
//! String consisting of forced headers
|
|
|
248 |
string iForcedHeaders;
|
|
|
249 |
|
|
|
250 |
//! Name of the temporary directory
|
|
|
251 |
string iTempDir;
|
|
|
252 |
|
|
|
253 |
//! Name of the macrofile
|
|
|
254 |
string iMacroFilename;
|
|
|
255 |
|
|
|
256 |
//! Compilation error text
|
|
|
257 |
string iCompErrFile;
|
|
|
258 |
|
|
|
259 |
//! Pointer to DOMBuilder
|
|
|
260 |
XERCES_CPP_NAMESPACE_QUALIFIER DOMBuilder* iDOMParser;
|
|
|
261 |
|
|
|
262 |
//! Pointer to DOMDocument
|
|
|
263 |
XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* iDOMDoc;
|
|
|
264 |
|
|
|
265 |
//! Pointer to DOM root node
|
|
|
266 |
XERCES_CPP_NAMESPACE_QUALIFIER DOMNode* iDOMRootElement;
|
|
|
267 |
};
|
|
|
268 |
#endif
|