Browse Source

Autogen: Use single KeyRegExp filter struct

Sebastian Holtermann 8 years ago
parent
commit
84658539bc
2 changed files with 39 additions and 26 deletions
  1. 19 19
      Source/cmQtAutoGenerators.cxx
  2. 20 7
      Source/cmQtAutoGenerators.h

+ 19 - 19
Source/cmQtAutoGenerators.cxx

@@ -224,10 +224,10 @@ cmQtAutoGenerators::cmQtAutoGenerators()
   }
 
   // Moc macro filters
-  this->MocMacroFilters.push_back(
-    MocMacroFilter("Q_OBJECT", "[\n][ \t]*{?[ \t]*Q_OBJECT[^a-zA-Z0-9_]"));
-  this->MocMacroFilters.push_back(
-    MocMacroFilter("Q_GADGET", "[\n][ \t]*{?[ \t]*Q_GADGET[^a-zA-Z0-9_]"));
+  this->MocMacroFilters.emplace_back(
+    "Q_OBJECT", "[\n][ \t]*{?[ \t]*Q_OBJECT[^a-zA-Z0-9_]");
+  this->MocMacroFilters.emplace_back(
+    "Q_GADGET", "[\n][ \t]*{?[ \t]*Q_GADGET[^a-zA-Z0-9_]");
 
   // Precompile regular expressions
   this->MocRegExpInclude.compile(
@@ -275,15 +275,15 @@ bool cmQtAutoGenerators::MocDependFilterPush(const std::string& key,
   bool success = false;
   if (!key.empty()) {
     if (!regExp.empty()) {
-      MocDependFilter filter;
-      filter.key = key;
-      if (filter.regExp.compile(regExp)) {
-        this->MocDependFilters.push_back(filter);
+      KeyRegExp filter;
+      filter.Key = key;
+      if (filter.RegExp.compile(regExp)) {
+        this->MocDependFilters.push_back(std::move(filter));
         success = true;
       } else {
         this->LogError("AutoMoc: Error in AUTOMOC_DEPEND_FILTERS: Compiling "
-                       "regular expression failed.\nKey:  " +
-                       Quoted(key) + "\nExp.: " + Quoted(regExp));
+                       "regular expression failed.\n  Key: " +
+                       Quoted(key) + "\n  RegExp.: " + Quoted(regExp));
       }
     } else {
       this->LogError("AutoMoc: Error in AUTOMOC_DEPEND_FILTERS: Regular "
@@ -739,14 +739,14 @@ bool cmQtAutoGenerators::RunAutogen()
 bool cmQtAutoGenerators::MocRequired(const std::string& contentText,
                                      std::string* macroName)
 {
-  for (MocMacroFilter& filter : this->MocMacroFilters) {
+  for (KeyRegExp& filter : this->MocMacroFilters) {
     // Run a simple find string operation before the expensive
     // regular expression check
-    if (contentText.find(filter.first) != std::string::npos) {
-      if (filter.second.find(contentText)) {
+    if (contentText.find(filter.Key) != std::string::npos) {
+      if (filter.RegExp.find(contentText)) {
         // Return macro name on demand
         if (macroName != nullptr) {
-          *macroName = filter.first;
+          *macroName = filter.Key;
         }
         return true;
       }
@@ -759,16 +759,16 @@ void cmQtAutoGenerators::MocFindDepends(
   const std::string& absFilename, const std::string& contentText,
   std::map<std::string, std::set<std::string>>& mocDepends)
 {
-  for (MocDependFilter& filter : this->MocDependFilters) {
+  for (KeyRegExp& filter : this->MocDependFilters) {
     // Run a simple find string operation before the expensive
     // regular expression check
-    if (contentText.find(filter.key) != std::string::npos) {
+    if (contentText.find(filter.Key) != std::string::npos) {
       // Run regular expression check loop
       const std::string sourcePath = SubDirPrefix(absFilename);
       const char* contentChars = contentText.c_str();
-      while (filter.regExp.find(contentChars)) {
+      while (filter.RegExp.find(contentChars)) {
         // Evaluate match
-        const std::string match = filter.regExp.match(1);
+        const std::string match = filter.RegExp.match(1);
         if (!match.empty()) {
           // Find the dependency file
           std::string incFile;
@@ -784,7 +784,7 @@ void cmQtAutoGenerators::MocFindDepends(
                              Quoted(match));
           }
         }
-        contentChars += filter.regExp.end();
+        contentChars += filter.RegExp.end();
       }
     }
   }

+ 20 - 7
Source/cmQtAutoGenerators.h

@@ -25,13 +25,26 @@ public:
 private:
   // -- Types
 
-  /// @brief Used to extract additional dependencies from content text
-  struct MocDependFilter
+  /// @brief Search key plus regular expression pair
+  struct KeyRegExp
   {
-    std::string key;
-    cmsys::RegularExpression regExp;
+    KeyRegExp() = default;
+
+    KeyRegExp(const char* key, const char* regExp)
+      : Key(key)
+      , RegExp(regExp)
+    {
+    }
+
+    KeyRegExp(const std::string& key, const std::string& regExp)
+      : Key(key)
+      , RegExp(regExp)
+    {
+    }
+
+    std::string Key;
+    cmsys::RegularExpression RegExp;
   };
-  typedef std::pair<std::string, cmsys::RegularExpression> MocMacroFilter;
 
   // -- Configuration
   bool MocDependFilterPush(const std::string& key, const std::string& regExp);
@@ -200,8 +213,8 @@ private:
   std::vector<std::string> MocDefinitions;
   std::vector<std::string> MocOptions;
   std::vector<std::string> MocPredefsCmd;
-  std::vector<MocDependFilter> MocDependFilters;
-  std::vector<MocMacroFilter> MocMacroFilters;
+  std::vector<KeyRegExp> MocDependFilters;
+  std::vector<KeyRegExp> MocMacroFilters;
   cmsys::RegularExpression MocRegExpInclude;
   // -- Uic
   bool UicSettingsChanged;