#include <projectporter.h>
Inheritance diagram for ProjectPorter:


Definition at line 32 of file projectporter.h.
Public Member Functions | |
| ProjectPorter (QString basePath, QStringList includeDirectories, QStringList qt3HeadersFilenames=QStringList()) | |
| void | enableCppParsing (bool enable) |
| void | enableMissingFilesWarnings (bool enable) |
| void | portProject (QString filePath) |
| void | portFile (QString filePath) |
Private Slots | |
| void | error (QString type, QString text) |
Private Member Functions | |
| void | portProject (QString inPath, QString proFileName) |
| void | portProFile (QString fileName, QMap< QString, QString > tagMap) |
| void | portFiles (QString basePath, QStringList fileNames) |
| void | enableAttributes (const IncludeFiles &includeFiles, const QString &fileName) |
Private Attributes | |
| QSet< QString > | processedFilesSet |
| QString | basePath |
| QStringList | includeDirectories |
| PreprocessorCache | preprocessorCache |
| Rpp::DefineMap * | defaultDefinitions |
| FilePorter | filePorter |
| QStringList | qt3HeadersFilenames |
| bool | analyze |
| bool | warnings |
| ProjectPorter::ProjectPorter | ( | QString | basePath, | |
| QStringList | includeDirectories, | |||
| QStringList | qt3HeadersFilenames = QStringList() | |||
| ) |
Definition at line 40 of file projectporter.cpp.
00041 :basePath(basePath) 00042 ,includeDirectories(includeDirectories) 00043 ,defaultDefinitions(defaultMacros(preprocessorCache)) 00044 ,filePorter(preprocessorCache) 00045 ,qt3HeadersFilenames(qt3HeadersFilenames) 00046 ,analyze(true) 00047 ,warnings(false) 00048 {}
| void ProjectPorter::enableCppParsing | ( | bool | enable | ) |
Definition at line 50 of file projectporter.cpp.
References analyze.
Referenced by main().
00051 { 00052 analyze = enable; 00053 }
| void ProjectPorter::enableMissingFilesWarnings | ( | bool | enable | ) |
Definition at line 55 of file projectporter.cpp.
References warnings.
Referenced by main().
00056 { 00057 warnings = enable; 00058 }
| void ProjectPorter::portProject | ( | QString | filePath | ) |
Definition at line 60 of file projectporter.cpp.
References QFileInfo::fileName(), and QFileInfo::path().
Referenced by main(), and portProject().
00061 { 00062 QFileInfo fileInfo(fileName); 00063 portProject(fileInfo.path(), fileInfo.fileName()); 00064 }
Here is the call graph for this function:

| void ProjectPorter::portFile | ( | QString | filePath | ) |
Definition at line 69 of file projectporter.cpp.
References analyze, basePath, QObject::connect(), defaultDefinitions, enableAttributes(), error(), PreprocessorController::evaluate(), includeDirectories, portFiles(), preprocessorCache, qt3HeadersFilenames, SIGNAL, and SLOT.
Referenced by main().
00070 { 00071 if (analyze) { 00072 IncludeFiles includeFiles(basePath, includeDirectories); 00073 00074 PreprocessorController preprocessor(includeFiles, preprocessorCache, qt3HeadersFilenames); 00075 connect(&preprocessor, SIGNAL(error(QString,QString)), SLOT(error(QString,QString))); 00076 00077 Rpp::DefineMap definitionsCopy = *defaultDefinitions; 00078 // Preprocess 00079 TokenSectionSequence translationUnit = preprocessor.evaluate(fileName, &definitionsCopy); 00080 // Parse 00081 TranslationUnit translationUnitData = TranslationUnitAnalyzer().analyze(translationUnit); 00082 00083 // Enable attribute generation for this file. 00084 enableAttributes(includeFiles, fileName); 00085 // Generate attributes. 00086 CodeModelAttributes().createAttributes(translationUnitData); 00087 } 00088 00089 portFiles(QString(), QStringList() << fileName); 00090 }
Here is the call graph for this function:

Definition at line 92 of file projectporter.cpp.
References QByteArray::constData(), printf, QString::toLocal8Bit(), type, and warnings.
Referenced by portFile(), and portProject().
00093 { 00094 if (warnings && type == "Error") 00095 printf("Warning: %s\n", text.toLocal8Bit().constData()); 00096 }
Definition at line 98 of file projectporter.cpp.
References analyze, TranslationUnitAnalyzer::analyze(), QList< T >::at(), basePath, Logger::beginSection(), QObject::connect(), constData(), CodeModelAttributes::createAttributes(), defaultDefinitions, enableAttributes(), error(), PreprocessorController::evaluate(), QFile::exists(), QFileInfo::exists(), Logger::globalState, i, includeDirectories, Logger::instance(), QList< T >::isEmpty(), QList< T >::last(), loadFile(), portFiles(), portProFile(), portProject(), preprocessorCache, printf, proFileTagMap(), qt3HeadersFilenames, SIGNAL, QList< T >::size(), QString::SkipEmptyParts, SLOT, QString::split(), and QDir::toNativeSeparators().
00099 { 00100 QString fullInFileName = basePath + "/" + proFileName; 00101 QFileInfo infileInfo(fullInFileName); 00102 if (!infileInfo.exists()) { 00103 printf("Could not open file: %s\n", QDir::toNativeSeparators(fullInFileName).toLocal8Bit().constData()); 00104 return; 00105 } 00106 00107 QString proFileContents = loadFile(fullInFileName); 00108 QMap<QString, QString> proFileMap = proFileTagMap(proFileContents, QDir(basePath).absolutePath()); 00109 00110 00111 // Check if this is a TEMPLATE = subdirs .pro file, in that case we 00112 // process each subdir (recursively). 00113 00114 QString templateTag = proFileMap["TEMPLATE"]; 00115 if (templateTag == "subdirs") { 00116 QStringList subdirs = proFileMap["SUBDIRS"].split(" ", QString::SkipEmptyParts); 00117 foreach(QString subdir, subdirs) { 00118 QString newBasePath = basePath + "/" + subdir; 00119 QStringList dirsInSubdir = subdir.split(QRegExp("/|\\\\"), QString::SkipEmptyParts); 00120 QString newProFileName = dirsInSubdir.last() + ".pro"; 00121 portProject(newBasePath, newProFileName); 00122 } 00123 return; 00124 } 00125 00126 // Get headers and sources file names from .pro file. 00127 QStringList sources = proFileMap["SOURCES"].split(" ", QString::SkipEmptyParts); 00128 QStringList headers = proFileMap["HEADERS"].split(" ", QString::SkipEmptyParts); 00129 QStringList forms = proFileMap["FORMS"].split(" ", QString::SkipEmptyParts); 00130 QStringList uidoth; 00131 for (int i = 0; i < forms.size(); ++i) { 00132 QString ui_h = forms.at(i) + ".h"; 00133 if (QFile::exists(basePath + "/" + ui_h)) 00134 uidoth += ui_h; 00135 } 00136 00137 if (analyze) { 00138 printf("Parsing"); 00139 // Get include paths from the pro file. 00140 QStringList includeProPaths = proFileMap["INCLUDEPATH"].split(" ", QString::SkipEmptyParts); 00141 QStringList dependProPaths = proFileMap["DEPENDPATH"].split(" ", QString::SkipEmptyParts); 00142 IncludeFiles includeFiles(basePath, includeDirectories + includeProPaths + dependProPaths); 00143 00144 PreprocessorController preprocessorController(includeFiles, preprocessorCache, qt3HeadersFilenames); 00145 connect(&preprocessorController, SIGNAL(error(QString,QString)), SLOT(error(QString,QString))); 00146 00147 TranslationUnitAnalyzer translationUnitAnalyzer; 00148 CodeModelAttributes codeModelAttributes; 00149 00150 // Enable attribute generation for header files. 00151 foreach(QString headerFile, headers) 00152 enableAttributes(includeFiles, headerFile); 00153 00154 // Enable attribute generation for ui.h files. 00155 foreach(QString headerFile, uidoth) 00156 enableAttributes(includeFiles, headerFile); 00157 00158 // Analyze each translation unit. (one per cpp file) 00159 foreach(QString sourceFile, sources) { 00160 printf("."); 00161 fflush(stdout); 00162 Rpp::DefineMap definitionsCopy = *defaultDefinitions; 00163 TokenSectionSequence translationUnit = 00164 preprocessorController.evaluate(sourceFile, &definitionsCopy); 00165 TranslationUnit translationUnitData = 00166 translationUnitAnalyzer.analyze(translationUnit); 00167 00168 // Enable attribute generation for this file. 00169 enableAttributes(includeFiles, sourceFile); 00170 00171 codeModelAttributes.createAttributes(translationUnitData); 00172 } 00173 puts(""); 00174 } 00175 00176 00177 // Port files. 00178 portFiles(basePath, sources); 00179 portFiles(basePath, headers); 00180 if (!uidoth.isEmpty()) 00181 portFiles(basePath, uidoth); 00182 00183 Logger::instance()->globalState["currentFileName"] = proFileName; 00184 Logger::instance()->beginSection(); 00185 portProFile(fullInFileName, proFileMap); 00186 }
Here is the call graph for this function:

Definition at line 217 of file projectporter.cpp.
References Logger::addEntry(), QList< T >::at(), QTextStream::atEnd(), QFile::close(), Logger::commitSection(), QStringList::contains(), QList< T >::count(), detectLineEndings(), filePorter, QTextStream::flush(), Logger::globalState, i, QList< T >::insert(), QSet< T >::insert(), FileWriter::instance(), Logger::instance(), isEmpty(), QSet< T >::isEmpty(), name, QFile::open(), QString::prepend(), QIODevice::readAll(), QTextStream::readLine(), QIODevice::ReadOnly, QSet< T >::remove(), Logger::revertSection(), QFile::seek(), QString::SkipEmptyParts, QString::startsWith(), QString::trimmed(), FilePorter::usedQtModules(), QMap< Key, T >::value(), FileWriter::WriteFailed, FileWriter::writeFileVerbously(), FileWriter::WriteSkipped, and FileWriter::WriteSucceeded.
Referenced by portProject().
00218 { 00219 // Read pro file. 00220 QFile proFile(fileName); 00221 if (!proFile.open(QIODevice::ReadOnly)) 00222 return; 00223 00224 const QByteArray contents = proFile.readAll(); 00225 const QByteArray lineEnding = detectLineEndings(contents); 00226 proFile.seek(0); 00227 00228 QTextStream proTextStream(&proFile); 00229 QStringList lines; 00230 while (!proTextStream.atEnd()) 00231 lines += proTextStream.readLine(); 00232 00233 proFile.close(); 00234 00235 // Find out what modules we should add to the QT variable. 00236 QSet<QByteArray> qtModules; 00237 00238 // Add qt3support to the Qt tag 00239 qtModules.insert("qt3support"); 00240 00241 // Read CONFIG and add other modules. 00242 QStringList config = tagMap["CONFIG"].split(" ", QString::SkipEmptyParts); 00243 if (config.contains("opengl")) 00244 qtModules.insert("opengl"); 00245 if (config.contains("xml")) 00246 qtModules.insert("xml"); 00247 if (config.contains("sql")) 00248 qtModules.insert("sql"); 00249 if (config.contains("network")) 00250 qtModules.insert("network"); 00251 00252 // Get set of used modules from the file porter. 00253 qtModules += filePorter.usedQtModules(); 00254 00255 // Remove gui and core. 00256 qtModules.remove("gui"); 00257 qtModules.remove("core"); 00258 00259 // Qt3Support is already added. 00260 qtModules.remove("3support"); 00261 00262 // Remove modules already present in the QT variable. 00263 QStringList qt = tagMap["QT"].split(" ", QString::SkipEmptyParts); 00264 foreach(QString name, qt) { 00265 qtModules.remove(name.toLatin1()); 00266 } 00267 00268 Logger *logger = Logger::instance(); 00269 bool changesMade = false; 00270 00271 if (!qtModules.isEmpty()) { 00272 changesMade = true; 00273 QString insertText = "QT += "; 00274 foreach(QByteArray module, qtModules) { 00275 insertText += module + QLatin1Char(' '); 00276 } 00277 lines += QString("#The following line was inserted by qt3to4"); 00278 lines += insertText; 00279 QString logText = "In file " 00280 + logger->globalState.value("currentFileName") 00281 + ": Added entry " 00282 + insertText; 00283 logger->addEntry(new PlainLogEntry("Info", "Porting", logText)); 00284 } 00285 00286 // Add uic3 if we have forms, and change FORMS and INTERFACES to FORMS3 00287 if (!tagMap["FORMS"].isEmpty() || !tagMap["INTERFACES"].isEmpty()) { 00288 changesMade = true; 00289 lines += QString("#The following line was inserted by qt3to4"); 00290 QString insertText = "CONFIG += uic3" + lineEnding; 00291 lines += insertText; 00292 QString logText = "In file " 00293 + logger->globalState.value("currentFileName") 00294 + ": Added entry " 00295 + insertText; 00296 logger->addEntry(new PlainLogEntry("Info", "Porting", logText)); 00297 00298 const QString formsToForms3("#The following line was changed from FORMS to FORMS3 by qt3to4"); 00299 const QString interfacesToForms3("#The following line was changed from INTERFACES to FORMS3 by qt3to4"); 00300 for (int i = 0; i < lines.count(); ++i) { 00301 QString cLine = lines.at(i); 00302 cLine = cLine.trimmed(); 00303 if (cLine.startsWith("FORMS")) { 00304 lines[i].replace("FORMS", "FORMS3"); 00305 lines.insert(i, formsToForms3); 00306 ++i; 00307 QString logText = "In file " 00308 + logger->globalState.value("currentFileName") 00309 + ": Renamed FORMS to FORMS3"; 00310 logger->addEntry(new PlainLogEntry("Info", "Porting", logText)); 00311 } else if (cLine.startsWith("INTERFACES")) { 00312 lines[i].replace("INTERFACES", "FORMS3"); 00313 lines.insert(i, interfacesToForms3); 00314 ++i; 00315 QString logText = "In file " 00316 + logger->globalState.value("currentFileName") 00317 + ": Renamed INTERFACES to FORMS3"; 00318 logger->addEntry(new PlainLogEntry("Info", "Porting", logText)); 00319 } 00320 } 00321 } 00322 00323 // Comment out any REQUIRES tag. 00324 if (!tagMap["REQUIRES"].isEmpty()) { 00325 changesMade = true; 00326 QString insertText("#The following line was commented out by qt3to4"); 00327 for (int i = 0; i < lines.count(); ++i) { 00328 if (lines.at(i).startsWith("REQUIRES")) { 00329 QString lineCopy = lines.at(i); 00330 lineCopy.prepend('#'); 00331 lines[i] = lineCopy; 00332 lines.insert(i, insertText); 00333 ++i; //skip ahead, we just insertet a line at i. 00334 QString logText = "In file " 00335 + logger->globalState.value("currentFileName") 00336 + ": Commented out REQUIRES section"; 00337 logger->addEntry(new PlainLogEntry("Info", "Porting", logText)); 00338 } 00339 } 00340 } 00341 00342 // Check if any changes has been made. 00343 if (!changesMade) { 00344 Logger::instance()->addEntry( 00345 new PlainLogEntry("Info", "Porting", QLatin1String("No changes made to file ") + fileName)); 00346 Logger::instance()->commitSection(); 00347 return; 00348 } 00349 00350 // Write lines to array. 00351 QByteArray bob; 00352 QTextStream outProFileStream(&bob); 00353 foreach(QString line, lines) 00354 outProFileStream << line << lineEnding; 00355 outProFileStream.flush(); 00356 00357 // Write array to file, commit log if write was successful. 00358 FileWriter::WriteResult result = FileWriter::instance()->writeFileVerbously(fileName, bob); 00359 if (result == FileWriter::WriteSucceeded) { 00360 logger->commitSection(); 00361 } else if (result == FileWriter::WriteFailed) { 00362 logger->revertSection(); 00363 logger->addEntry( 00364 new PlainLogEntry("Error", "Porting", QLatin1String("Error writing to file ") + fileName)); 00365 } else if (result == FileWriter::WriteSkipped) { 00366 logger->revertSection(); 00367 logger->addEntry( 00368 new PlainLogEntry("Error", "Porting", QLatin1String("User skipped file ") + fileName)); 00369 } else { 00370 // Internal error. 00371 logger->revertSection(); 00372 const QString errorString = QLatin1String("Internal error in qt3to4 - FileWriter returned invalid result code while writing to ") + fileName; 00373 logger->addEntry(new PlainLogEntry("Error", "Porting", errorString)); 00374 } 00375 }
Here is the call graph for this function:

| void ProjectPorter::portFiles | ( | QString | basePath, | |
| QStringList | fileNames | |||
| ) | [private] |
Definition at line 192 of file projectporter.cpp.
References basePath, QDir::cleanPath(), constData(), QSet< T >::contains(), QFileInfo::exists(), filePorter, Logger::globalState, QSet< T >::insert(), Logger::instance(), QFileInfo::isAbsolute(), FilePorter::port(), printf, processedFilesSet, and QDir::toNativeSeparators().
Referenced by portFile(), and portProject().
00193 { 00194 foreach(QString fileName, fileNames) { 00195 QString fullFilePath; 00196 QFileInfo fileInfo(fileName); 00197 if (fileInfo.isAbsolute()) { 00198 fullFilePath = QDir::cleanPath(fileName); 00199 } else { 00200 fullFilePath = QDir::cleanPath(basePath + "/" + fileName); 00201 } 00202 00203 QFileInfo fullFilePathInfo(fullFilePath); 00204 if (!fullFilePathInfo.exists()) { 00205 printf("Could not find file: %s\n", QDir::toNativeSeparators(fullFilePath).toLocal8Bit().constData()); 00206 continue; 00207 } 00208 00209 if (!processedFilesSet.contains(fullFilePath)){ 00210 Logger::instance()->globalState["currentFileName"] = fullFilePath; 00211 filePorter.port(fullFilePath); 00212 processedFilesSet.insert(fullFilePath); 00213 } 00214 } 00215 }
Here is the call graph for this function:

| void ProjectPorter::enableAttributes | ( | const IncludeFiles & | includeFiles, | |
| const QString & | fileName | |||
| ) | [private] |
Definition at line 381 of file projectporter.cpp.
References TokenEngine::TokenAttributes::addAttribute(), IncludeFiles::angleBracketLookup(), QFile::exists(), preprocessorCache, IncludeFiles::resolve(), PreprocessorCache::sourceTokens(), and TokenEngine::TokenContainer::tokenAttributes().
Referenced by portFile(), and portProject().
00382 { 00383 QString resolvedFilePath = includeFiles.resolve(fileName); 00384 if (!QFile::exists(resolvedFilePath)) 00385 resolvedFilePath = includeFiles.angleBracketLookup(fileName); 00386 if (!QFile::exists(resolvedFilePath)) 00387 return; 00388 00389 TokenContainer tokenContainer = preprocessorCache.sourceTokens(resolvedFilePath); 00390 TokenAttributes *attributes = tokenContainer.tokenAttributes(); 00391 attributes->addAttribute("CreateAttributes", "True"); 00392 }
Here is the call graph for this function:

QSet<QString> ProjectPorter::processedFilesSet [private] |
QString ProjectPorter::basePath [private] |
Definition at line 50 of file projectporter.h.
Referenced by portFile(), portFiles(), and portProject().
QStringList ProjectPorter::includeDirectories [private] |
Definition at line 52 of file projectporter.h.
Referenced by enableAttributes(), portFile(), and portProject().
Rpp::DefineMap* ProjectPorter::defaultDefinitions [private] |
FilePorter ProjectPorter::filePorter [private] |
bool ProjectPorter::analyze [private] |
Definition at line 56 of file projectporter.h.
Referenced by enableCppParsing(), portFile(), and portProject().
bool ProjectPorter::warnings [private] |
Definition at line 57 of file projectporter.h.
Referenced by enableMissingFilesWarnings(), and error().
1.5.1