|
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 |
#include <stdio.h>
|
|
|
18 |
|
|
|
19 |
#include <stdlib.h>
|
|
|
20 |
#include "CmdGlobals.h"
|
|
|
21 |
#ifdef __WIN__
|
|
|
22 |
#include <windows.h>
|
|
|
23 |
#include <direct.h>
|
|
|
24 |
#else
|
|
|
25 |
#include <errno.h>
|
|
|
26 |
#endif
|
|
|
27 |
|
|
|
28 |
|
|
|
29 |
#include <xercesc/dom/DOM.hpp>
|
|
|
30 |
#include <xercesc/parsers/AbstractDOMParser.hpp>
|
|
|
31 |
|
|
|
32 |
#include <iostream>
|
|
|
33 |
#include <fstream>
|
|
|
34 |
#include <string>
|
|
|
35 |
|
|
|
36 |
#include "CPPParser.h"
|
|
|
37 |
#include "XMLModuleErrorHandler.h"
|
|
|
38 |
#include "HAException.h"
|
|
|
39 |
#include "BBCFileUtils.h"
|
|
|
40 |
#include "Utils.h"
|
|
|
41 |
#include "XMLUtils.h"
|
|
|
42 |
|
|
|
43 |
XERCES_CPP_NAMESPACE_USE
|
|
|
44 |
|
|
|
45 |
const int KMaxFilenameLength = 512;
|
|
|
46 |
const int KMaxDirLength=1024;
|
|
|
47 |
|
|
|
48 |
// The C++ parser executable
|
|
|
49 |
#ifdef __WIN__
|
|
|
50 |
static const char* GCCXML_COMMAND = "ha_gccxml_cc1plus ";
|
|
|
51 |
#else
|
|
|
52 |
static const char* GCCXML_COMMAND = "./ha_gccxml_cc1plus ";
|
|
|
53 |
#endif
|
|
|
54 |
|
|
|
55 |
// Parameters to parser
|
|
|
56 |
//
|
|
|
57 |
//static const char* GCCXML_DEFINE = " -D_DEBUG -D__wchar_t=wchar_t -D_UNICODE -D__SYMBIAN32__ -D__SERIES60_30__ -D__SERIES60_3X__ -D__GCC32__ -D__EPOC32__ -D__GCC32__ -D__MARM__ -D__GCCXML__ -D__MARM_ARM4__ -D__MARM_ARMV5__ -D__EXE__ -UWIN32 -U__i386__ -U_WIN32 -U__WIN32__";
|
|
|
58 |
static const char* GCCXML_DEFINE = " -D_DEBUG -D_UNICODE -D__SYMBIAN32__ -D__SERIES60_30__ -D__SERIES60_3X__ -D__GCC32__ -D__GNUC__ -D__EPOC32__ -D__GCC32__ -D__MARM__ -D__GCCXML__ -D__MARM_ARM4__ -D__MARM_ARMV5__ -D__EXE__ -UWIN32 -U__i386__ -U_WIN32 -U__WIN32__";
|
|
|
59 |
|
|
|
60 |
static const char* GCCXML_OPTIONS = " -E -g -nostdinc -Wall -Wno-ctor-dtor-privacy -Wno-unknown-pragmas -fshort-wchar -quiet -w ";
|
|
|
61 |
|
|
|
62 |
// Output file define
|
|
|
63 |
static const char* GCCXML_OUTPUT = " -o ";
|
|
|
64 |
|
|
|
65 |
static const char* GCCXML_INCLUDEPATH = " -I ";
|
|
|
66 |
|
|
|
67 |
// XML output file define
|
|
|
68 |
static const char* GCCXML_XML_OUTPUT = " -fxml=";
|
|
|
69 |
|
|
|
70 |
static const char* GCCXML_MACRO_OUTPUT = " -dD ";
|
|
|
71 |
|
|
|
72 |
#ifdef __WIN__
|
|
|
73 |
// Error code when file remove fails
|
|
|
74 |
const int KErrorRemoveFailed=0;
|
|
|
75 |
static const char* GCCXML_COMP_OPTIONS = " -fpreprocessed -g -nostdinc -Wall -Wno-ctor-dtor-privacy -Wno-unknown-pragmas -fshort-wchar -quiet -w -o nul";
|
|
|
76 |
#else
|
|
|
77 |
static const char* GCCXML_COMP_OPTIONS = " -fpreprocessed -g -nostdinc -Wall -Wno-ctor-dtor-privacy -Wno-unknown-pragmas -fshort-wchar -quiet -w -o /dev/null";
|
|
|
78 |
#endif
|
|
|
79 |
|
|
|
80 |
|
|
|
81 |
// ----------------------------------------------------------------------------
|
|
|
82 |
// CPPParser::GenerateCompilationCmd
|
|
|
83 |
// Generate command for compilation
|
|
|
84 |
// ----------------------------------------------------------------------------
|
|
|
85 |
//
|
|
|
86 |
string CPPParser::GenerateCompilationCmd(const string& currentDir,const string& epocRoot,const string& inputFile,const string& outputFile)
|
|
|
87 |
{
|
|
|
88 |
string cmdline;
|
|
|
89 |
if (currentDir != "")
|
|
|
90 |
{
|
|
|
91 |
cmdline = currentDir + "\"" + DIR_SEPARATOR + "\"";
|
|
|
92 |
}
|
|
|
93 |
cmdline += GCCXML_COMMAND;
|
|
|
94 |
cmdline += GCCXML_COMP_OPTIONS;
|
|
|
95 |
cmdline += GCCXML_XML_OUTPUT + string("\"") + outputFile + string("\" \"");
|
|
|
96 |
|
|
|
97 |
|
|
|
98 |
cmdline += inputFile + string("\"")+ string(" 2>\"") + iCompErrFile + string("\"");
|
|
|
99 |
|
|
|
100 |
//cout << "-------COMPILATION-----------------------\n";
|
|
|
101 |
//cout << cmdline << endl;
|
|
|
102 |
//cout << "-----------------------------------------\n";
|
|
|
103 |
return cmdline;
|
|
|
104 |
|
|
|
105 |
}
|
|
|
106 |
|
|
|
107 |
|
|
|
108 |
// ----------------------------------------------------------------------------
|
|
|
109 |
// CPPParser::GeneratePreprocessCmd
|
|
|
110 |
// Generate GCXML command for prepocessing
|
|
|
111 |
// ----------------------------------------------------------------------------
|
|
|
112 |
//
|
|
|
113 |
string CPPParser::GeneratePreprocessCmd(const string& currentDir,const string& epocRoot,const string& inputFile,const string& outputFile,
|
|
|
114 |
vector<string>& aHeaders )
|
|
|
115 |
{
|
|
|
116 |
string cmdline;
|
|
|
117 |
|
|
|
118 |
if (currentDir != "")
|
|
|
119 |
{
|
|
|
120 |
cmdline = currentDir + DIR_SEPARATOR;
|
|
|
121 |
}
|
|
|
122 |
cmdline += GCCXML_COMMAND;
|
|
|
123 |
|
|
|
124 |
list<pair<string, string> > includes = BBCFileUtils::extractFilenames(epocRoot);
|
|
|
125 |
list<pair<string, string> >::iterator listbegin = includes.begin();
|
|
|
126 |
list<pair<string, string> >::iterator listend = includes.end();
|
|
|
127 |
for(; listbegin != listend; listbegin++)
|
|
|
128 |
{
|
|
|
129 |
cmdline += GCCXML_INCLUDEPATH + string("\"") + listbegin->first + string("\"");
|
|
|
130 |
}
|
|
|
131 |
|
|
|
132 |
if ( !aHeaders.empty() )
|
|
|
133 |
{
|
|
|
134 |
int size = (int)aHeaders.size();
|
|
|
135 |
int i = 0;
|
|
|
136 |
|
|
|
137 |
for(;i < size; i++)
|
|
|
138 |
{
|
|
|
139 |
string headerfile = aHeaders.at(i);
|
|
|
140 |
|
|
|
141 |
cmdline += GCCXML_INCLUDEPATH + string("\"") + headerfile + string("\"");
|
|
|
142 |
}
|
|
|
143 |
}
|
|
|
144 |
|
|
|
145 |
cmdline += GCCXML_DEFINE;
|
|
|
146 |
cmdline += GCCXML_OPTIONS;
|
|
|
147 |
cmdline += GCCXML_OUTPUT + string("\"") + outputFile + string("\" \"");
|
|
|
148 |
cmdline += inputFile + string("\"");
|
|
|
149 |
|
|
|
150 |
//cout << "-------- PREPROCESS COMMAND --------------" << endl;
|
|
|
151 |
//cout << cmdline << endl;
|
|
|
152 |
//cout << "------------------------------------------" << endl;
|
|
|
153 |
|
|
|
154 |
return cmdline;
|
|
|
155 |
|
|
|
156 |
}
|
|
|
157 |
|
|
|
158 |
// ----------------------------------------------------------------------------
|
|
|
159 |
// CPPParser::GenerateMacroExtract
|
|
|
160 |
// Generate commanf or macro extract
|
|
|
161 |
// ----------------------------------------------------------------------------
|
|
|
162 |
//
|
|
|
163 |
string CPPParser::GenerateMacroExtract(const string& currentDir,const string& epocRoot,const string& inputFile,const string& outputFile,
|
|
|
164 |
vector<string>& aHeaders )
|
|
|
165 |
{
|
|
|
166 |
string cmdline;
|
|
|
167 |
|
|
|
168 |
if (currentDir != "")
|
|
|
169 |
{
|
|
|
170 |
cmdline = currentDir + DIR_SEPARATOR;
|
|
|
171 |
}
|
|
|
172 |
cmdline += GCCXML_COMMAND;
|
|
|
173 |
|
|
|
174 |
list<pair<string, string> > includes = BBCFileUtils::extractFilenames(epocRoot);
|
|
|
175 |
list<pair<string, string> >::iterator listbegin = includes.begin();
|
|
|
176 |
list<pair<string, string> >::iterator listend = includes.end();
|
|
|
177 |
for(; listbegin != listend; listbegin++)
|
|
|
178 |
{
|
|
|
179 |
cmdline += GCCXML_INCLUDEPATH + string("\"") + listbegin->first + string("\"");
|
|
|
180 |
}
|
|
|
181 |
|
|
|
182 |
if ( !aHeaders.empty() )
|
|
|
183 |
{
|
|
|
184 |
int size = (int)aHeaders.size();
|
|
|
185 |
int i = 0;
|
|
|
186 |
|
|
|
187 |
for(;i < size; i++)
|
|
|
188 |
{
|
|
|
189 |
string headerfile = aHeaders.at(i);
|
|
|
190 |
cmdline += GCCXML_INCLUDEPATH + string("\"") + headerfile + string("\"");
|
|
|
191 |
}
|
|
|
192 |
}
|
|
|
193 |
|
|
|
194 |
cmdline += GCCXML_DEFINE;
|
|
|
195 |
cmdline += GCCXML_OPTIONS;
|
|
|
196 |
|
|
|
197 |
cmdline += GCCXML_MACRO_OUTPUT;
|
|
|
198 |
cmdline += GCCXML_OUTPUT + string("\"") + outputFile + string("\" \"");
|
|
|
199 |
|
|
|
200 |
cmdline += inputFile + string("\"")+ string(" 2>\"") + iCompErrFile + string("\"");
|
|
|
201 |
|
|
|
202 |
//cout << "-----------------------------------------\n";
|
|
|
203 |
//cout << cmdline << endl;
|
|
|
204 |
//cout << "-----------------------------------------\n";
|
|
|
205 |
return cmdline;
|
|
|
206 |
|
|
|
207 |
}
|
|
|
208 |
|
|
|
209 |
// ----------------------------------------------------------------------------
|
|
|
210 |
// CPPParser::CPPParser
|
|
|
211 |
// Constructor
|
|
|
212 |
// ----------------------------------------------------------------------------
|
|
|
213 |
//
|
|
|
214 |
CPPParser::CPPParser(string epocroot)
|
|
|
215 |
: iInputFilename(), iOutputFilename(), iXMLOutputPath(),
|
|
|
216 |
iEpocRoot(epocroot), iDOMParser(NULL), iDOMDoc(NULL),
|
|
|
217 |
iDOMRootElement(NULL), iCompErrFile()
|
|
|
218 |
{
|
|
|
219 |
|
|
|
220 |
}
|
|
|
221 |
|
|
|
222 |
|
|
|
223 |
// ----------------------------------------------------------------------------
|
|
|
224 |
// CPPParser::~CPPParser
|
|
|
225 |
// Destructor
|
|
|
226 |
// ----------------------------------------------------------------------------
|
|
|
227 |
//
|
|
|
228 |
CPPParser::~CPPParser()
|
|
|
229 |
{
|
|
|
230 |
if (iDOMParser != NULL)
|
|
|
231 |
{
|
|
|
232 |
iDOMParser->resetDocumentPool();
|
|
|
233 |
iDOMParser->release();
|
|
|
234 |
iDOMParser = NULL;
|
|
|
235 |
}
|
|
|
236 |
}
|
|
|
237 |
|
|
|
238 |
|
|
|
239 |
// ----------------------------------------------------------------------------
|
|
|
240 |
// CPPParser::parse
|
|
|
241 |
// Please, note that iOutputFilename is changed internally in different
|
|
|
242 |
// function calls.
|
|
|
243 |
// ----------------------------------------------------------------------------
|
|
|
244 |
//
|
|
|
245 |
DOMNode* CPPParser::parse(const vector<string>& aFilenames, string aVersion, string aPath, list<string>& notRemovedFiles)
|
|
|
246 |
{
|
|
|
247 |
DOMNode* ret = NULL;
|
|
|
248 |
|
|
|
249 |
int err = 0;
|
|
|
250 |
headervector headers;
|
|
|
251 |
string cppfilename = generateTempCPPFile(aFilenames, aVersion, headers );
|
|
|
252 |
|
|
|
253 |
string extensionStripped = BBCFileUtils::StripFilenameExtension(cppfilename);
|
|
|
254 |
iOriginalFilename = BBCFileUtils::StripPath(extensionStripped);
|
|
|
255 |
iCompErrFile = iTempDir + DIR_SEPARATOR + iOriginalFilename + "-" + aVersion + "-comperr.txt";
|
|
|
256 |
try
|
|
|
257 |
{
|
|
|
258 |
err = PreprocessH(cppfilename, aVersion, headers);
|
|
|
259 |
} catch (HAException error)
|
|
|
260 |
{
|
|
|
261 |
#if !defined(_DEBUG) && !defined(DEBUG)
|
|
|
262 |
RemoveFile(cppfilename, notRemovedFiles);
|
|
|
263 |
RemoveFile(iMacroFilename, notRemovedFiles);
|
|
|
264 |
#endif
|
|
|
265 |
throw error;
|
|
|
266 |
}
|
|
|
267 |
RemoveFile(cppfilename, notRemovedFiles);
|
|
|
268 |
string prefilename = iOutputFilename;
|
|
|
269 |
HandleExports(iOutputFilename, aVersion);
|
|
|
270 |
string pre2filename = iOutputFilename;
|
|
|
271 |
try
|
|
|
272 |
{
|
|
|
273 |
err = ConvertHToXML(iOutputFilename, aVersion);
|
|
|
274 |
} catch (HAException error)
|
|
|
275 |
{
|
|
|
276 |
#if !defined(_DEBUG) && !defined(DEBUG)
|
|
|
277 |
RemoveFile(prefilename, notRemovedFiles);
|
|
|
278 |
RemoveFile(pre2filename, notRemovedFiles);
|
|
|
279 |
RemoveFile(iMacroFilename, notRemovedFiles);
|
|
|
280 |
#endif
|
|
|
281 |
throw error;
|
|
|
282 |
}
|
|
|
283 |
if (err == 0)
|
|
|
284 |
{
|
|
|
285 |
err = ExtractDOMFromXML(iOutputFilename);
|
|
|
286 |
ret = iDOMRootElement;
|
|
|
287 |
}
|
|
|
288 |
headers.clear();
|
|
|
289 |
RemoveFile(prefilename, notRemovedFiles);
|
|
|
290 |
RemoveFile(pre2filename, notRemovedFiles);
|
|
|
291 |
#if !defined(_DEBUG) && !defined(DEBUG)
|
|
|
292 |
RemoveFile(iOutputFilename, notRemovedFiles);
|
|
|
293 |
#endif
|
|
|
294 |
|
|
|
295 |
return ret;
|
|
|
296 |
}
|
|
|
297 |
|
|
|
298 |
|
|
|
299 |
// ----------------------------------------------------------------------------
|
|
|
300 |
// CPPParser::RemoveFile
|
|
|
301 |
// Remove given file
|
|
|
302 |
// ----------------------------------------------------------------------------
|
|
|
303 |
//
|
|
|
304 |
void CPPParser::RemoveFile(string file, list<string>& notRemovedFiles)
|
|
|
305 |
{
|
|
|
306 |
int success;
|
|
|
307 |
/*#ifdef __WIN__
|
|
|
308 |
success = DeleteFile(file.c_str());
|
|
|
309 |
if (success == KErrorRemoveFailed)
|
|
|
310 |
{
|
|
|
311 |
unsigned long int errorcode = GetLastError();
|
|
|
312 |
if (errorcode != ERROR_FILE_NOT_FOUND)
|
|
|
313 |
{
|
|
|
314 |
notRemovedFiles.push_back(file);
|
|
|
315 |
}
|
|
|
316 |
}
|
|
|
317 |
#else
|
|
|
318 |
success = unlink(file.c_str());
|
|
|
319 |
if (success == -1)
|
|
|
320 |
{
|
|
|
321 |
if (errno != ENOENT)
|
|
|
322 |
{
|
|
|
323 |
notRemovedFiles.push_back(file);
|
|
|
324 |
}
|
|
|
325 |
}
|
|
|
326 |
#endif*/
|
|
|
327 |
REMOVE_FILE_FUNCTION
|
|
|
328 |
}
|
|
|
329 |
|
|
|
330 |
|
|
|
331 |
// ----------------------------------------------------------------------------
|
|
|
332 |
// CPPParser::GenerateMacroExtract
|
|
|
333 |
// Converts a header file with given filename to an XML file
|
|
|
334 |
// (with same base filename and extension .xml).
|
|
|
335 |
//
|
|
|
336 |
// Throw an exception on error
|
|
|
337 |
// ----------------------------------------------------------------------------
|
|
|
338 |
//
|
|
|
339 |
int CPPParser::ConvertHToXML(string aFilename, string aVersion)
|
|
|
340 |
{
|
|
|
341 |
int ret = 0;
|
|
|
342 |
string oFilename;
|
|
|
343 |
string iFilename;
|
|
|
344 |
string tempOFilename;
|
|
|
345 |
|
|
|
346 |
iFilename = aFilename;
|
|
|
347 |
tempOFilename = BBCFileUtils::StripPath(BBCFileUtils::StripFilenameExtension(iFilename));
|
|
|
348 |
|
|
|
349 |
oFilename = iTempDir + DIR_SEPARATOR + iOriginalFilename + "-" + aVersion + ".xml";
|
|
|
350 |
char currentDir[KMaxDirLength];
|
|
|
351 |
getcwd(currentDir,KMaxDirLength);
|
|
|
352 |
#ifdef USE_INCLUDED_GCC_DISTRIBUTION
|
|
|
353 |
string cmdline = GenerateCompilationCmd(currentDir, iEpocRoot, iFilename, oFilename);
|
|
|
354 |
#else
|
|
|
355 |
string empty("");
|
|
|
356 |
string cmdline = GenerateCompilationCmd(empty, iEpocRoot, iFilename, oFilename);
|
|
|
357 |
#endif
|
|
|
358 |
|
|
|
359 |
ret = system(cmdline.c_str());
|
|
|
360 |
iXMLOutputPath = iTempDir;
|
|
|
361 |
iOutputFilename = oFilename;
|
|
|
362 |
iInputFilename = iFilename;
|
|
|
363 |
if (ret != 0)
|
|
|
364 |
{
|
|
|
365 |
throw(HAException("GCCXML Error, please see above for more information"));
|
|
|
366 |
}
|
|
|
367 |
return ret;
|
|
|
368 |
}
|
|
|
369 |
|
|
|
370 |
// ----------------------------------------------------------------------------
|
|
|
371 |
// CPPParser::GenerateMacroExtract
|
|
|
372 |
// Generate temporary CPP-file
|
|
|
373 |
// ----------------------------------------------------------------------------
|
|
|
374 |
//
|
|
|
375 |
int CPPParser::DumpMacros(string mdumpfile, string ifile, vector<string>& headers)
|
|
|
376 |
{
|
|
|
377 |
int ret = 0;
|
|
|
378 |
string cmdbuf;
|
|
|
379 |
char currentDir[KMaxDirLength];
|
|
|
380 |
getcwd(currentDir,KMaxDirLength);
|
|
|
381 |
#ifdef USE_INCLUDED_GCC_DISTRIBUTION
|
|
|
382 |
cmdbuf = GenerateMacroExtract(currentDir, iEpocRoot, ifile, mdumpfile, headers);
|
|
|
383 |
#else
|
|
|
384 |
string empty("");
|
|
|
385 |
cmdbuf = GenerateMacroExtract(empty, iEpocRoot, ifile, mdumpfile,headers);
|
|
|
386 |
#endif
|
|
|
387 |
|
|
|
388 |
ret = system(cmdbuf.c_str());
|
|
|
389 |
return ret;
|
|
|
390 |
}
|
|
|
391 |
|
|
|
392 |
|
|
|
393 |
// ----------------------------------------------------------------------------
|
|
|
394 |
// CPPParser::ExtractDOMFromXML
|
|
|
395 |
// Reads in and parses an XML file with given filename.
|
|
|
396 |
// ----------------------------------------------------------------------------
|
|
|
397 |
//
|
|
|
398 |
int CPPParser::ExtractDOMFromXML(const string& aXMLFilename)
|
|
|
399 |
{
|
|
|
400 |
int ret = 0;
|
|
|
401 |
|
|
|
402 |
if (iDOMParser != NULL) {
|
|
|
403 |
iDOMParser->resetDocumentPool();
|
|
|
404 |
iDOMParser->release();
|
|
|
405 |
iDOMParser = NULL;
|
|
|
406 |
}
|
|
|
407 |
|
|
|
408 |
return ParseXMLFile(aXMLFilename, iDOMParser, iDOMDoc, iDOMRootElement);
|
|
|
409 |
}
|
|
|
410 |
|
|
|
411 |
// ----------------------------------------------------------------------------
|
|
|
412 |
// CPPParser::setBaselineDir
|
|
|
413 |
// ----------------------------------------------------------------------------
|
|
|
414 |
//
|
|
|
415 |
void CPPParser::setBaselineDir(string aRoot)
|
|
|
416 |
{
|
|
|
417 |
iEpocRoot = aRoot;
|
|
|
418 |
}
|
|
|
419 |
|
|
|
420 |
|
|
|
421 |
// ----------------------------------------------------------------------------
|
|
|
422 |
// CPPParser::PreprocessH
|
|
|
423 |
// ----------------------------------------------------------------------------
|
|
|
424 |
//
|
|
|
425 |
int CPPParser::PreprocessH(string aFilename, string aVersion, vector<string>& headers )
|
|
|
426 |
{
|
|
|
427 |
int ret = 0;
|
|
|
428 |
string oFilename;
|
|
|
429 |
string iFilename;
|
|
|
430 |
|
|
|
431 |
string tempOFilename;
|
|
|
432 |
|
|
|
433 |
iFilename = aFilename;
|
|
|
434 |
tempOFilename = iOriginalFilename;
|
|
|
435 |
|
|
|
436 |
oFilename = iTempDir + DIR_SEPARATOR + tempOFilename + "-" + aVersion + ".pre";
|
|
|
437 |
iMacroFilename = iTempDir + DIR_SEPARATOR + iOriginalFilename + "-" + aVersion + "-macros.txt";
|
|
|
438 |
ret = DumpMacros(iMacroFilename, iFilename,headers);
|
|
|
439 |
if (ret != 0)
|
|
|
440 |
{
|
|
|
441 |
throw(HAException("GCCXML Error, please see above for more information"));
|
|
|
442 |
}
|
|
|
443 |
|
|
|
444 |
char currentDir[KMaxDirLength];
|
|
|
445 |
getcwd(currentDir,KMaxDirLength);
|
|
|
446 |
|
|
|
447 |
#ifdef USE_INCLUDED_GCC_DISTRIBUTION
|
|
|
448 |
string cmdline = GeneratePreprocessCmd(currentDir,iEpocRoot,iFilename,oFilename, headers);
|
|
|
449 |
#else
|
|
|
450 |
string empty("");
|
|
|
451 |
string cmdline = GeneratePreprocessCmd(empty,iEpocRoot,iFilename,oFilename, headers);
|
|
|
452 |
#endif
|
|
|
453 |
|
|
|
454 |
ret = system(cmdline.c_str());
|
|
|
455 |
if (ret != 0)
|
|
|
456 |
{
|
|
|
457 |
throw(HAException("GCCXML Error, please see above for more information"));
|
|
|
458 |
}
|
|
|
459 |
iXMLOutputPath = iTempDir;
|
|
|
460 |
iOutputFilename = oFilename;
|
|
|
461 |
iInputFilename = iFilename;
|
|
|
462 |
return ret;
|
|
|
463 |
}
|
|
|
464 |
|
|
|
465 |
// ----------------------------------------------------------------------------
|
|
|
466 |
// CPPParser::HandleExports
|
|
|
467 |
// ----------------------------------------------------------------------------
|
|
|
468 |
//
|
|
|
469 |
int CPPParser::HandleExports(string aFilename, string aVersion)
|
|
|
470 |
{
|
|
|
471 |
int ret = 0;
|
|
|
472 |
string ofilename = aFilename + ".2";
|
|
|
473 |
|
|
|
474 |
ifstream input(aFilename.c_str(), ios::in);
|
|
|
475 |
ofstream output(ofilename.c_str(), ios::out);
|
|
|
476 |
iOutputFilename = ofilename;
|
|
|
477 |
char c;
|
|
|
478 |
string toflush = "";
|
|
|
479 |
unsigned int matches = 0;
|
|
|
480 |
string tofind = STR_EXPORT_HACK;
|
|
|
481 |
string attribstr = STR_ATTRIBUTE_STR;
|
|
|
482 |
string outputBuffer;
|
|
|
483 |
outputBuffer.reserve(PREPROCESS_BUFFERSIZE);
|
|
|
484 |
int state = EStateSearching;
|
|
|
485 |
bool purevirtual = false;
|
|
|
486 |
bool possiblepurevirtual = false;
|
|
|
487 |
while (input.get(c))
|
|
|
488 |
{
|
|
|
489 |
if (outputBuffer.length() >= PREPROCESS_BUFFERSIZE)
|
|
|
490 |
{
|
|
|
491 |
output << outputBuffer;
|
|
|
492 |
outputBuffer = "";
|
|
|
493 |
}
|
|
|
494 |
if (state == EStateSearching)
|
|
|
495 |
{
|
|
|
496 |
if (c == tofind.at(matches))
|
|
|
497 |
{
|
|
|
498 |
matches++;
|
|
|
499 |
toflush += c;
|
|
|
500 |
} else
|
|
|
501 |
{
|
|
|
502 |
matches = 0;
|
|
|
503 |
if (!toflush.empty())
|
|
|
504 |
{
|
|
|
505 |
outputBuffer += toflush;
|
|
|
506 |
toflush = "";
|
|
|
507 |
}
|
|
|
508 |
outputBuffer += c;
|
|
|
509 |
}
|
|
|
510 |
if (matches == tofind.length())
|
|
|
511 |
{
|
|
|
512 |
toflush = "";
|
|
|
513 |
state = EStateReplacing;
|
|
|
514 |
matches = 0;
|
|
|
515 |
}
|
|
|
516 |
} else if (state == EStateReplacing)
|
|
|
517 |
{
|
|
|
518 |
if (c == '=')
|
|
|
519 |
{
|
|
|
520 |
if (possiblepurevirtual == true && !toflush.empty())
|
|
|
521 |
{
|
|
|
522 |
outputBuffer += toflush;
|
|
|
523 |
toflush = "";
|
|
|
524 |
}
|
|
|
525 |
possiblepurevirtual = true;
|
|
|
526 |
toflush += c;
|
|
|
527 |
} else if (possiblepurevirtual == true && c!= ';')
|
|
|
528 |
{
|
|
|
529 |
if (c == ' ')
|
|
|
530 |
{
|
|
|
531 |
toflush += c;
|
|
|
532 |
} else if (c == '\t')
|
|
|
533 |
{
|
|
|
534 |
toflush += c;
|
|
|
535 |
} else if (c == '0')
|
|
|
536 |
{
|
|
|
537 |
toflush += c;
|
|
|
538 |
purevirtual = true;
|
|
|
539 |
} else
|
|
|
540 |
{
|
|
|
541 |
outputBuffer += toflush;
|
|
|
542 |
outputBuffer += c;
|
|
|
543 |
toflush = "";
|
|
|
544 |
possiblepurevirtual = false;
|
|
|
545 |
purevirtual = false;
|
|
|
546 |
}
|
|
|
547 |
} else if (c == ';')
|
|
|
548 |
{
|
|
|
549 |
state = EStateSearching;
|
|
|
550 |
if (purevirtual)
|
|
|
551 |
{
|
|
|
552 |
} else if (possiblepurevirtual)
|
|
|
553 |
{
|
|
|
554 |
outputBuffer += toflush;
|
|
|
555 |
toflush = "";
|
|
|
556 |
}
|
|
|
557 |
|
|
|
558 |
outputBuffer += " ";
|
|
|
559 |
outputBuffer += attribstr;
|
|
|
560 |
if (!toflush.empty())
|
|
|
561 |
{
|
|
|
562 |
outputBuffer += " ";
|
|
|
563 |
outputBuffer += toflush;
|
|
|
564 |
toflush = "";
|
|
|
565 |
}
|
|
|
566 |
possiblepurevirtual = false;
|
|
|
567 |
purevirtual = false;
|
|
|
568 |
outputBuffer += ';';
|
|
|
569 |
} else
|
|
|
570 |
{
|
|
|
571 |
outputBuffer += c;
|
|
|
572 |
}
|
|
|
573 |
} else if (state == EStateReplaceDone)
|
|
|
574 |
{
|
|
|
575 |
|
|
|
576 |
}
|
|
|
577 |
|
|
|
578 |
}
|
|
|
579 |
if (outputBuffer.length() != 0)
|
|
|
580 |
{
|
|
|
581 |
output << outputBuffer;
|
|
|
582 |
}
|
|
|
583 |
return ret;
|
|
|
584 |
}
|
|
|
585 |
|
|
|
586 |
|
|
|
587 |
// ----------------------------------------------------------------------------
|
|
|
588 |
// CPPParser::ReplaceExport
|
|
|
589 |
// ----------------------------------------------------------------------------
|
|
|
590 |
//
|
|
|
591 |
#if 0
|
|
|
592 |
int CPPParser::ReplaceExport(string line, string& processedline)
|
|
|
593 |
{
|
|
|
594 |
int ret = 0;
|
|
|
595 |
if (processedline.length() == 0)
|
|
|
596 |
{
|
|
|
597 |
string tofind = STR_EXPORT_HACK;
|
|
|
598 |
size_t idx = line.find(tofind);
|
|
|
599 |
if (idx != string::npos)
|
|
|
600 |
{
|
|
|
601 |
unsigned int start = (unsigned int)idx + tofind.length();
|
|
|
602 |
int len = (int)line.length() - start;
|
|
|
603 |
string sub = line.substr(start+1, len-1);
|
|
|
604 |
int insertidx = (int)sub.rfind("=0;");
|
|
|
605 |
|
|
|
606 |
if (insertidx < 0)
|
|
|
607 |
{
|
|
|
608 |
insertidx = (int)sub.rfind("= 0;");
|
|
|
609 |
if (insertidx < 0)
|
|
|
610 |
{
|
|
|
611 |
insertidx = (int)sub.rfind(';');
|
|
|
612 |
}
|
|
|
613 |
}
|
|
|
614 |
if (insertidx > 0)
|
|
|
615 |
{
|
|
|
616 |
sub.insert(insertidx, " __attribute((gccxml(\"exported\")))");
|
|
|
617 |
} else
|
|
|
618 |
{
|
|
|
619 |
ret = 1;
|
|
|
620 |
}
|
|
|
621 |
processedline.append(sub);
|
|
|
622 |
} else
|
|
|
623 |
{
|
|
|
624 |
if (processedline.find("};") != string::npos )
|
|
|
625 |
{
|
|
|
626 |
processedline.append(line);
|
|
|
627 |
ret = 0;
|
|
|
628 |
}
|
|
|
629 |
}
|
|
|
630 |
} else
|
|
|
631 |
{
|
|
|
632 |
string sub = line;
|
|
|
633 |
int insertidx = (int)sub.rfind("=0;");
|
|
|
634 |
|
|
|
635 |
if (insertidx < 0)
|
|
|
636 |
{
|
|
|
637 |
insertidx = (int)sub.rfind("= 0;");
|
|
|
638 |
if (insertidx < 0)
|
|
|
639 |
{
|
|
|
640 |
insertidx = (int)sub.rfind(';');
|
|
|
641 |
}
|
|
|
642 |
}
|
|
|
643 |
if (insertidx > 0)
|
|
|
644 |
{
|
|
|
645 |
sub.insert(insertidx, " __attribute((gccxml(\"exported\")))");
|
|
|
646 |
ret = 0;
|
|
|
647 |
} else
|
|
|
648 |
{
|
|
|
649 |
ret = 1;
|
|
|
650 |
}
|
|
|
651 |
processedline = "";
|
|
|
652 |
processedline.append(sub);
|
|
|
653 |
}
|
|
|
654 |
return ret;
|
|
|
655 |
}
|
|
|
656 |
#endif
|
|
|
657 |
|
|
|
658 |
|
|
|
659 |
// ----------------------------------------------------------------------------
|
|
|
660 |
// CPPParser::getEnv
|
|
|
661 |
// ----------------------------------------------------------------------------
|
|
|
662 |
//
|
|
|
663 |
char* CPPParser::getEnv(char* aEnvVarName)
|
|
|
664 |
{
|
|
|
665 |
char* ret = getenv(aEnvVarName);
|
|
|
666 |
if (ret == NULL)
|
|
|
667 |
{
|
|
|
668 |
string s("Environment variable not defined: ");
|
|
|
669 |
s += aEnvVarName;
|
|
|
670 |
throw(new HAException(s));
|
|
|
671 |
}
|
|
|
672 |
return ret;
|
|
|
673 |
}
|
|
|
674 |
|
|
|
675 |
// ----------------------------------------------------------------------------
|
|
|
676 |
// CPPParser::generateTempCPPFile
|
|
|
677 |
// ----------------------------------------------------------------------------
|
|
|
678 |
//
|
|
|
679 |
string CPPParser::generateTempCPPFile(const vector<string>& aFiles, string aVersion, vector<string>& aHeaders)
|
|
|
680 |
{
|
|
|
681 |
string headers = "";
|
|
|
682 |
|
|
|
683 |
if (!iForcedHeaders.empty())
|
|
|
684 |
{
|
|
|
685 |
// START -- Support for multiple forced headers
|
|
|
686 |
list<pair<string, string> > fheaders = BBCFileUtils::extractFilenames(iForcedHeaders);
|
|
|
687 |
list<pair<string, string> >::iterator fheadersbegin = fheaders.begin();
|
|
|
688 |
|
|
|
689 |
for(; fheadersbegin != fheaders.end(); fheadersbegin++)
|
|
|
690 |
{
|
|
|
691 |
headers += "#include \"";
|
|
|
692 |
headers += fheadersbegin->first;
|
|
|
693 |
headers += "\"\n";
|
|
|
694 |
}
|
|
|
695 |
// END -- Support for multiple forced headers
|
|
|
696 |
}
|
|
|
697 |
|
|
|
698 |
size_t filecount = aFiles.size();
|
|
|
699 |
int filehash = 0;
|
|
|
700 |
string ret = "";
|
|
|
701 |
for (unsigned int i = 0; i < filecount; i++)
|
|
|
702 |
{
|
|
|
703 |
// Append header folder to include vector
|
|
|
704 |
//string& hdr = aFiles.at(i);
|
|
|
705 |
AppendHeader( aHeaders, aFiles.at(i) );
|
|
|
706 |
|
|
|
707 |
string fn = aFiles.at(i);
|
|
|
708 |
headers += "#include \"";
|
|
|
709 |
headers += fn;
|
|
|
710 |
headers += "\"\n";
|
|
|
711 |
fn += "-";
|
|
|
712 |
fn += aVersion;
|
|
|
713 |
filehash += BBCFileUtils::quickHash(fn);
|
|
|
714 |
}
|
|
|
715 |
string temp;
|
|
|
716 |
itoa(filehash, temp, 10);
|
|
|
717 |
ret = iTempDir + DIR_SEPARATOR + temp + ".cpp";
|
|
|
718 |
|
|
|
719 |
ofstream output(ret.c_str(), ios::out);
|
|
|
720 |
output << headers;
|
|
|
721 |
output.close();
|
|
|
722 |
return ret;
|
|
|
723 |
}
|
|
|
724 |
|
|
|
725 |
// ----------------------------------------------------------------------------
|
|
|
726 |
// CPPParser::setForcedHeaders
|
|
|
727 |
// ----------------------------------------------------------------------------
|
|
|
728 |
//
|
|
|
729 |
void CPPParser::setForcedHeaders(const string& aHeaders)
|
|
|
730 |
{
|
|
|
731 |
iForcedHeaders = aHeaders;
|
|
|
732 |
}
|
|
|
733 |
|
|
|
734 |
// ----------------------------------------------------------------------------
|
|
|
735 |
// CPPParser::setTemp
|
|
|
736 |
// Set temp file
|
|
|
737 |
// ----------------------------------------------------------------------------
|
|
|
738 |
//
|
|
|
739 |
void CPPParser::setTemp(const string& aTempDir)
|
|
|
740 |
{
|
|
|
741 |
iTempDir = aTempDir;
|
|
|
742 |
}
|
|
|
743 |
|
|
|
744 |
// ----------------------------------------------------------------------------
|
|
|
745 |
// CPPParser::getMacroFilename
|
|
|
746 |
// Returns macro filename
|
|
|
747 |
// ----------------------------------------------------------------------------
|
|
|
748 |
//
|
|
|
749 |
string CPPParser::getMacroFilename()
|
|
|
750 |
{
|
|
|
751 |
return iMacroFilename;
|
|
|
752 |
}
|
|
|
753 |
|
|
|
754 |
// ----------------------------------------------------------------------------
|
|
|
755 |
// CPPParser::getCompErrFile
|
|
|
756 |
// Returns compilation error filename
|
|
|
757 |
// ----------------------------------------------------------------------------
|
|
|
758 |
//
|
|
|
759 |
string CPPParser::getCompErrFile()
|
|
|
760 |
{
|
|
|
761 |
return iCompErrFile;
|
|
|
762 |
}
|
|
|
763 |
|
|
|
764 |
// ----------------------------------------------------------------------------
|
|
|
765 |
// CPPParser::AppendHeader
|
|
|
766 |
// ----------------------------------------------------------------------------
|
|
|
767 |
//
|
|
|
768 |
void CPPParser::AppendHeader( vector<string>& aHeaders, string aFile )
|
|
|
769 |
{
|
|
|
770 |
string onlyFolder = aFile;
|
|
|
771 |
|
|
|
772 |
string::size_type idx = onlyFolder.rfind(DIR_SEPARATOR);
|
|
|
773 |
|
|
|
774 |
// for other separation formats
|
|
|
775 |
if (idx != string::npos)
|
|
|
776 |
{
|
|
|
777 |
onlyFolder.erase( idx );
|
|
|
778 |
}
|
|
|
779 |
|
|
|
780 |
if (onlyFolder.size() == ANALYSER_HEADER_SIZE)
|
|
|
781 |
{
|
|
|
782 |
onlyFolder += APPEND_DIR_SEPARATOR;
|
|
|
783 |
}
|
|
|
784 |
|
|
|
785 |
bool notFound = true;
|
|
|
786 |
unsigned int size = (unsigned int)aHeaders.size();
|
|
|
787 |
|
|
|
788 |
for(unsigned int g = 0; g < size ; g++ )
|
|
|
789 |
{
|
|
|
790 |
if( aHeaders.at(g) == onlyFolder )
|
|
|
791 |
{
|
|
|
792 |
notFound = false;
|
|
|
793 |
size = (unsigned int)aHeaders.size();
|
|
|
794 |
}
|
|
|
795 |
}
|
|
|
796 |
|
|
|
797 |
if( notFound )
|
|
|
798 |
{
|
|
|
799 |
aHeaders.push_back( onlyFolder );
|
|
|
800 |
}
|
|
|
801 |
}
|