diff options
author | Sebastian Holtermann <sebholt@xwmw.org> | 2017-02-16 09:31:03 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2017-02-21 15:12:52 (GMT) |
commit | 71c5ae253cb5498da319e36bcf49869509b6603c (patch) | |
tree | 6264707f70e33fb3e1f90f58a433957f4c169250 /Source | |
parent | 5308f954c9ad13cfc6cc84f1f1255fb5faff48c6 (diff) | |
download | CMake-71c5ae253cb5498da319e36bcf49869509b6603c.zip CMake-71c5ae253cb5498da319e36bcf49869509b6603c.tar.gz CMake-71c5ae253cb5498da319e36bcf49869509b6603c.tar.bz2 |
Autogen: Loop based macro detection instead of code duplication
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmQtAutoGenerators.cxx | 36 | ||||
-rw-r--r-- | Source/cmQtAutoGenerators.h | 8 |
2 files changed, 24 insertions, 20 deletions
diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index 4e4ab30..8bf41f8 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -214,9 +214,12 @@ cmQtAutoGenerators::cmQtAutoGenerators() } } + this->MacroFilters[0].first = "Q_OBJECT"; + this->MacroFilters[0].second.compile("[\n][ \t]*Q_OBJECT[^a-zA-Z0-9_]"); + this->MacroFilters[1].first = "Q_GADGET"; + this->MacroFilters[1].second.compile("[\n][ \t]*Q_GADGET[^a-zA-Z0-9_]"); + // Precompile regular expressions - this->RegExpQObject.compile("[\n][ \t]*Q_OBJECT[^a-zA-Z0-9_]"); - this->RegExpQGadget.compile("[\n][ \t]*Q_GADGET[^a-zA-Z0-9_]"); this->RegExpMocInclude.compile( "[\n][ \t]*#[ \t]*include[ \t]+" "[\"<](([^ \">]+/)?moc_[^ \">/]+\\.cpp|[^ \">]+\\.moc)[\">]"); @@ -632,19 +635,19 @@ bool cmQtAutoGenerators::RunAutogen() * @return True if moc is required */ bool cmQtAutoGenerators::MocRequired(const std::string& text, - std::string& macroName) + 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; + for (unsigned int ii = 0; ii != cmArraySize(this->MacroFilters); ++ii) { + MacroFilter& macroFilter = this->MacroFilters[ii]; + // Run a simple check before an expensive regular expression check + if (text.find(macroFilter.first) != std::string::npos) { + if (macroFilter.second.find(text)) { + // Return macro name on demand + if (macroName != CM_NULLPTR) { + *macroName = macroFilter.first; + } + return true; + } } } return false; @@ -754,7 +757,7 @@ bool cmQtAutoGenerators::ParseContentForMoc( cmsys::SystemTools::GetFilenameWithoutLastExtension(absFilename); std::string macroName; - const bool requiresMoc = this->MocRequired(contentsString, macroName); + const bool requiresMoc = this->MocRequired(contentsString, ¯oName); bool ownDotMocIncluded = false; bool ownMocUnderscoreIncluded = false; std::string ownMocUnderscoreFile; @@ -988,8 +991,7 @@ void cmQtAutoGenerators::ParseHeaders( err << "AutoMoc: Checking " << headerName << "\n"; this->LogInfo(err.str()); } - std::string macroName; - if (this->MocRequired(contents, macroName)) { + if (this->MocRequired(contents)) { mocsNotIncluded[headerName] = this->ChecksumedPath(headerName, "moc_", ".cpp"); } diff --git a/Source/cmQtAutoGenerators.h b/Source/cmQtAutoGenerators.h index e6f9160..2842660 100644 --- a/Source/cmQtAutoGenerators.h +++ b/Source/cmQtAutoGenerators.h @@ -10,6 +10,7 @@ #include <map> #include <set> #include <string> +#include <utility> #include <vector> class cmMakefile; @@ -46,7 +47,8 @@ private: bool RunAutogen(); // - Content analysis - bool MocRequired(const std::string& text, std::string& macroName); + bool MocRequired(const std::string& text, + std::string* macroName = CM_NULLPTR); bool MocSkip(const std::string& absFilename) const; bool UicSkip(const std::string& absFilename) const; @@ -160,8 +162,8 @@ private: // - Utility cmFilePathChecksum fpathCheckSum; std::vector<std::string> HeaderExtensions; - cmsys::RegularExpression RegExpQObject; - cmsys::RegularExpression RegExpQGadget; + typedef std::pair<std::string, cmsys::RegularExpression> MacroFilter; + MacroFilter MacroFilters[2]; cmsys::RegularExpression RegExpMocInclude; cmsys::RegularExpression RegExpUicInclude; // - Flags |