From 6ae19bf32e232beb59a0c427d82c0761e8248ab8 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Wed, 28 Dec 2016 10:25:16 +0100 Subject: AUTOGEN: Generators: Add dedicated method for moc content parsing --- Source/cmQtAutoGenerators.cxx | 136 +++++++++++++++++++++++------------------- Source/cmQtAutoGenerators.h | 6 ++ 2 files changed, 80 insertions(+), 62 deletions(-) diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index 33550b0..5877619 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -580,19 +580,90 @@ bool cmQtAutoGenerators::ParseSourceFile( std::map& includedMocs, std::map >& includedUis, bool relaxed) { + bool success = true; const std::string contentsString = ReadAll(absFilename); if (contentsString.empty()) { std::ostringstream err; err << "AUTOGEN: warning: " << absFilename << "\n" << "The file is empty\n"; this->LogWarning(err.str()); - return true; + } else { + // Parse source contents for UIC + this->ParseContentForUic(absFilename, contentsString, includedUis); + // Parse source contents for MOC + success = this->ParseContentForMoc( + absFilename, contentsString, headerExtensions, includedMocs, relaxed); + } + return success; +} + +bool cmQtAutoGenerators::requiresMocing(const std::string& text, + std::string& macroName) +{ + // Run a simple check before an expensive regular expression check + if (strstr(text.c_str(), "Q_OBJECT") != CM_NULLPTR) { + if (this->RegExpQObject.find(text)) { + macroName = "Q_OBJECT"; + return true; + } + } + if (strstr(text.c_str(), "Q_GADGET") != CM_NULLPTR) { + if (this->RegExpQGadget.find(text)) { + macroName = "Q_GADGET"; + return true; + } } + return false; +} - // Parse source contents for UIC +void cmQtAutoGenerators::ParseForUic( + const std::string& absFilename, + std::map >& includedUis) +{ + if (this->UicExecutable.empty()) { + return; + } + const std::string contentsString = ReadAll(absFilename); + if (contentsString.empty()) { + std::ostringstream err; + err << "AUTOGEN: warning: " << absFilename << ": file is empty\n" + << std::endl; + this->LogWarning(err.str()); + return; + } this->ParseContentForUic(absFilename, contentsString, includedUis); +} - // Continue with moc parsing on demand +void cmQtAutoGenerators::ParseContentForUic( + const std::string& absFilename, const std::string& contentsString, + std::map >& includedUis) +{ + if (this->UicExecutable.empty()) { + return; + } + const std::string realName = cmsys::SystemTools::GetRealPath(absFilename); + const char* contentChars = contentsString.c_str(); + if (strstr(contentChars, "ui_") != CM_NULLPTR) { + while (this->RegExpUicInclude.find(contentChars)) { + const std::string currentUi = this->RegExpUicInclude.match(1); + const std::string basename = + cmsys::SystemTools::GetFilenameWithoutLastExtension(currentUi); + // basename should be the part of the ui filename used for + // finding the correct header, so we need to remove the ui_ part + includedUis[realName].push_back(basename.substr(3)); + contentChars += this->RegExpUicInclude.end(); + } + } +} + +/** + * @return True on success + */ +bool cmQtAutoGenerators::ParseContentForMoc( + const std::string& absFilename, const std::string& contentsString, + const std::vector& headerExtensions, + std::map& includedMocs, bool relaxed) +{ if (this->MocExecutable.empty()) { return true; } @@ -775,65 +846,6 @@ bool cmQtAutoGenerators::ParseSourceFile( return true; } -bool cmQtAutoGenerators::requiresMocing(const std::string& text, - std::string& macroName) -{ - // Run a simple check before an expensive regular expression check - if (strstr(text.c_str(), "Q_OBJECT") != CM_NULLPTR) { - if (this->RegExpQObject.find(text)) { - macroName = "Q_OBJECT"; - return true; - } - } - if (strstr(text.c_str(), "Q_GADGET") != CM_NULLPTR) { - if (this->RegExpQGadget.find(text)) { - macroName = "Q_GADGET"; - return true; - } - } - return false; -} - -void cmQtAutoGenerators::ParseForUic( - const std::string& absFilename, - std::map >& includedUis) -{ - if (this->UicExecutable.empty()) { - return; - } - const std::string contentsString = ReadAll(absFilename); - if (contentsString.empty()) { - std::ostringstream err; - err << "AUTOGEN: warning: " << absFilename << ": file is empty\n" - << std::endl; - this->LogWarning(err.str()); - return; - } - this->ParseContentForUic(absFilename, contentsString, includedUis); -} - -void cmQtAutoGenerators::ParseContentForUic( - const std::string& absFilename, const std::string& contentsString, - std::map >& includedUis) -{ - if (this->UicExecutable.empty()) { - return; - } - const std::string realName = cmsys::SystemTools::GetRealPath(absFilename); - const char* contentChars = contentsString.c_str(); - if (strstr(contentChars, "ui_") != CM_NULLPTR) { - while (this->RegExpUicInclude.find(contentChars)) { - const std::string currentUi = this->RegExpUicInclude.match(1); - const std::string basename = - cmsys::SystemTools::GetFilenameWithoutLastExtension(currentUi); - // basename should be the part of the ui filename used for - // finding the correct header, so we need to remove the ui_ part - includedUis[realName].push_back(basename.substr(3)); - contentChars += this->RegExpUicInclude.end(); - } - } -} - void cmQtAutoGenerators::SearchHeadersForCppFile( const std::string& absFilename, const std::vector& headerExtensions, diff --git a/Source/cmQtAutoGenerators.h b/Source/cmQtAutoGenerators.h index f86e7c3..dac23d9 100644 --- a/Source/cmQtAutoGenerators.h +++ b/Source/cmQtAutoGenerators.h @@ -72,6 +72,12 @@ private: const std::string& fileName, const std::string& contentsString, std::map >& includedUis); + bool ParseContentForMoc(const std::string& absFilename, + const std::string& contentsString, + const std::vector& headerExtensions, + std::map& includedMocs, + bool relaxed); + void ParseForUic( const std::string& fileName, std::map >& includedUis); -- cgit v0.12