automoc: move some code from the big parsing loop into separate functions

Alex
This commit is contained in:
Alex Neundorf 2011-11-22 21:35:08 +01:00
parent bc7560e6e5
commit 74ab0f6aa4
1 changed files with 47 additions and 30 deletions

View File

@ -37,6 +37,50 @@ static bool containsQ_OBJECT(const std::string& text)
} }
static std::string findMatchingHeader(const std::string& absPath,
const std::string& mocSubDir,
const std::string& basename,
const std::list<std::string>& headerExtensions)
{
std::string header;
for(std::list<std::string>::const_iterator ext = headerExtensions.begin();
ext != headerExtensions.end();
++ext)
{
std::string sourceFilePath = absPath + basename + (*ext);
if (cmsys::SystemTools::FileExists(sourceFilePath.c_str()))
{
header = sourceFilePath;
break;
}
if (!mocSubDir.empty())
{
sourceFilePath = mocSubDir + basename + (*ext);
if (cmsys::SystemTools::FileExists(sourceFilePath.c_str()))
{
header = sourceFilePath;
break;
}
}
}
return header;
}
static std::string extractSubDir(const std::string& absPath,
const std::string& currentMoc)
{
std::string subDir;
if (currentMoc.find_first_of('/') != std::string::npos)
{
subDir = absPath
+ cmsys::SystemTools::GetFilenamePath(currentMoc) + '/';
}
return subDir;
}
cmQtAutomoc::cmQtAutomoc() cmQtAutomoc::cmQtAutomoc()
:Verbose(cmsys::SystemTools::GetEnv("VERBOSE") != 0) :Verbose(cmsys::SystemTools::GetEnv("VERBOSE") != 0)
,ColorOutput(true) ,ColorOutput(true)
@ -569,36 +613,9 @@ void cmQtAutomoc::ParseCppFile(const std::string& absFilename,
// basename should be the part of the moc filename used for // basename should be the part of the moc filename used for
// finding the correct header, so we need to remove the moc_ part // finding the correct header, so we need to remove the moc_ part
basename = basename.substr(4); basename = basename.substr(4);
std::string mocSubDir = extractSubDir(absPath, currentMoc);
std::string mocSubDir; std::string headerToMoc = findMatchingHeader(
if (currentMoc.find_first_of('/') != std::string::npos) absPath, mocSubDir, basename, headerExtensions);
{
mocSubDir = absPath
+ cmsys::SystemTools::GetFilenamePath(currentMoc) + '/';
}
std::string headerToMoc;
for(std::list<std::string>::const_iterator ext =
headerExtensions.begin();
ext != headerExtensions.end();
++ext)
{
std::string sourceFilePath = absPath + basename + (*ext);
if (cmsys::SystemTools::FileExists(sourceFilePath.c_str()))
{
headerToMoc = sourceFilePath;
break;
}
if (!mocSubDir.empty())
{
sourceFilePath = mocSubDir + basename + (*ext);
if (cmsys::SystemTools::FileExists(sourceFilePath.c_str()))
{
headerToMoc = sourceFilePath;
break;
}
}
}
if (!headerToMoc.empty()) if (!headerToMoc.empty())
{ {