Explorar el Código

Autogen: Generators: Sort methods by task

Sebastian Holtermann hace 8 años
padre
commit
52688bf745
Se han modificado 2 ficheros con 157 adiciones y 150 borrados
  1. 122 114
      Source/cmQtAutoGenerators.cxx
  2. 35 36
      Source/cmQtAutoGenerators.h

+ 122 - 114
Source/cmQtAutoGenerators.cxx

@@ -27,6 +27,8 @@
 #include <unistd.h>
 #endif
 
+// -- Static functions
+
 static std::string findMatchingHeader(
   const std::string& absPath, const std::string& mocSubDir,
   const std::string& basename,
@@ -95,6 +97,8 @@ static bool ListContains(const std::vector<std::string>& list,
   return (std::find(list.begin(), list.end(), entry) != list.end());
 }
 
+// -- Class methods
+
 cmQtAutoGenerators::cmQtAutoGenerators()
   : Verbose(cmsys::SystemTools::HasEnv("VERBOSE"))
   , ColorOutput(true)
@@ -124,40 +128,6 @@ cmQtAutoGenerators::cmQtAutoGenerators()
                                  "[\"<](([^ \">]+/)?ui_[^ \">/]+\\.h)[\">]");
 }
 
-void cmQtAutoGenerators::MergeUicOptions(
-  std::vector<std::string>& opts, const std::vector<std::string>& fileOpts,
-  bool isQt5)
-{
-  static const char* valueOptions[] = { "tr",      "translate",
-                                        "postfix", "generator",
-                                        "include", // Since Qt 5.3
-                                        "g" };
-  std::vector<std::string> extraOpts;
-  for (std::vector<std::string>::const_iterator it = fileOpts.begin();
-       it != fileOpts.end(); ++it) {
-    std::vector<std::string>::iterator existingIt =
-      std::find(opts.begin(), opts.end(), *it);
-    if (existingIt != opts.end()) {
-      const char* o = it->c_str();
-      if (*o == '-') {
-        ++o;
-      }
-      if (isQt5 && *o == '-') {
-        ++o;
-      }
-      if (std::find_if(cmArrayBegin(valueOptions), cmArrayEnd(valueOptions),
-                       cmStrCmp(*it)) != cmArrayEnd(valueOptions)) {
-        assert(existingIt + 1 != opts.end());
-        *(existingIt + 1) = *(it + 1);
-        ++it;
-      }
-    } else {
-      extraOpts.push_back(*it);
-    }
-  }
-  opts.insert(opts.end(), extraOpts.begin(), extraOpts.end());
-}
-
 bool cmQtAutoGenerators::Run(const std::string& targetDirectory,
                              const std::string& config)
 {
@@ -567,6 +537,60 @@ bool cmQtAutoGenerators::RunAutogen(cmMakefile* makefile)
   return true;
 }
 
+/**
+ * @brief Tests if the C++ content requires moc processing
+ * @return True if moc is required
+ */
+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;
+}
+
+/**
+ * @brief Tests if the file should be ignored for moc scanning
+ * @return True if the file should be ignored
+ */
+bool cmQtAutoGenerators::MocSkipTest(const std::string& absFilename)
+{
+  // Test if moc scanning is enabled
+  if (!this->MocExecutable.empty()) {
+    // Test if the file name is on the skip list
+    if (!ListContains(this->SkipMoc, absFilename)) {
+      return false;
+    }
+  }
+  return true;
+}
+
+/**
+ * @brief Tests if the file name is in the skip list
+ */
+bool cmQtAutoGenerators::UicSkipTest(const std::string& absFilename)
+{
+  // Test if uic scanning is enabled
+  if (!this->UicExecutable.empty()) {
+    // Test if the file name is on the skip list
+    if (!ListContains(this->SkipUic, absFilename)) {
+      return false;
+    }
+  }
+  return true;
+}
+
 /**
  * @return True on success
  */
@@ -597,25 +621,6 @@ bool cmQtAutoGenerators::ParseSourceFile(
   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;
-}
-
 void cmQtAutoGenerators::ParseContentForUic(
   const std::string& absFilename, const std::string& contentsString,
   std::map<std::string, std::vector<std::string> >& includedUis)
@@ -1104,6 +1109,40 @@ bool cmQtAutoGenerators::GenerateMoc(const std::string& sourceFile,
   return false;
 }
 
+void cmQtAutoGenerators::MergeUicOptions(
+  std::vector<std::string>& opts, const std::vector<std::string>& fileOpts,
+  bool isQt5)
+{
+  static const char* valueOptions[] = { "tr",      "translate",
+                                        "postfix", "generator",
+                                        "include", // Since Qt 5.3
+                                        "g" };
+  std::vector<std::string> extraOpts;
+  for (std::vector<std::string>::const_iterator it = fileOpts.begin();
+       it != fileOpts.end(); ++it) {
+    std::vector<std::string>::iterator existingIt =
+      std::find(opts.begin(), opts.end(), *it);
+    if (existingIt != opts.end()) {
+      const char* o = it->c_str();
+      if (*o == '-') {
+        ++o;
+      }
+      if (isQt5 && *o == '-') {
+        ++o;
+      }
+      if (std::find_if(cmArrayBegin(valueOptions), cmArrayEnd(valueOptions),
+                       cmStrCmp(*it)) != cmArrayEnd(valueOptions)) {
+        assert(existingIt + 1 != opts.end());
+        *(existingIt + 1) = *(it + 1);
+        ++it;
+      }
+    } else {
+      extraOpts.push_back(*it);
+    }
+  }
+  opts.insert(opts.end(), extraOpts.begin(), extraOpts.end());
+}
+
 bool cmQtAutoGenerators::GenerateUiFiles(
   const std::map<std::string, std::vector<std::string> >& includedUis)
 {
@@ -1365,67 +1404,6 @@ bool cmQtAutoGenerators::GenerateQrc(const std::string& qrcInputFile,
   return false;
 }
 
-/**
- * @brief Tests if the file should be ignored for moc scanning
- * @return True if the file should be ignored
- */
-bool cmQtAutoGenerators::MocSkipTest(const std::string& absFilename)
-{
-  // Test if moc scanning is enabled
-  if (!this->MocExecutable.empty()) {
-    // Test if the file name is on the skip list
-    if (!ListContains(this->SkipMoc, absFilename)) {
-      return false;
-    }
-  }
-  return true;
-}
-
-/**
- * @brief Tests if the file name is in the skip list
- */
-bool cmQtAutoGenerators::UicSkipTest(const std::string& absFilename)
-{
-  // Test if uic scanning is enabled
-  if (!this->UicExecutable.empty()) {
-    // Test if the file name is on the skip list
-    if (!ListContains(this->SkipUic, absFilename)) {
-      return false;
-    }
-  }
-  return true;
-}
-
-/**
- * @brief Collects name collisions as output/input pairs
- * @return True if there were collisions
- */
-bool cmQtAutoGenerators::NameCollisionTest(
-  const std::map<std::string, std::string>& genFiles,
-  std::multimap<std::string, std::string>& collisions)
-{
-  typedef std::map<std::string, std::string>::const_iterator Iter;
-  typedef std::map<std::string, std::string>::value_type VType;
-  for (Iter ait = genFiles.begin(); ait != genFiles.end(); ++ait) {
-    bool first_match(true);
-    for (Iter bit = (++Iter(ait)); bit != genFiles.end(); ++bit) {
-      if (ait->second == bit->second) {
-        if (first_match) {
-          if (collisions.find(ait->second) != collisions.end()) {
-            // We already know of this collision from before
-            break;
-          }
-          collisions.insert(VType(ait->second, ait->first));
-          first_match = false;
-        }
-        collisions.insert(VType(bit->second, bit->first));
-      }
-    }
-  }
-
-  return !collisions.empty();
-}
-
 void cmQtAutoGenerators::LogErrorNameCollision(
   const std::string& message,
   const std::multimap<std::string, std::string>& collisions)
@@ -1484,6 +1462,36 @@ void cmQtAutoGenerators::LogCommand(const std::vector<std::string>& command)
   }
 }
 
+/**
+ * @brief Collects name collisions as output/input pairs
+ * @return True if there were collisions
+ */
+bool cmQtAutoGenerators::NameCollisionTest(
+  const std::map<std::string, std::string>& genFiles,
+  std::multimap<std::string, std::string>& collisions)
+{
+  typedef std::map<std::string, std::string>::const_iterator Iter;
+  typedef std::map<std::string, std::string>::value_type VType;
+  for (Iter ait = genFiles.begin(); ait != genFiles.end(); ++ait) {
+    bool first_match(true);
+    for (Iter bit = (++Iter(ait)); bit != genFiles.end(); ++bit) {
+      if (ait->second == bit->second) {
+        if (first_match) {
+          if (collisions.find(ait->second) != collisions.end()) {
+            // We already know of this collision from before
+            break;
+          }
+          collisions.insert(VType(ait->second, ait->first));
+          first_match = false;
+        }
+        collisions.insert(VType(bit->second, bit->first));
+      }
+    }
+  }
+
+  return !collisions.empty();
+}
+
 /**
  * @brief Generates the parent directory of the given file on demand
  * @return True on success

+ 35 - 36
Source/cmQtAutoGenerators.h

@@ -22,6 +22,7 @@ public:
   bool Run(const std::string& targetDirectory, const std::string& config);
 
 private:
+  // - Configuration
   bool ReadAutogenInfoFile(cmMakefile* makefile,
                            const std::string& targetDirectory,
                            const std::string& config);
@@ -29,25 +30,16 @@ private:
                                  const std::string& targetDirectory);
   bool WriteOldMocDefinitionsFile(const std::string& targetDirectory);
 
-  std::string MakeCompileSettingsString(cmMakefile* makefile);
+  static std::string MakeCompileSettingsString(cmMakefile* makefile);
 
+  // - Init and run
+  void Init();
   bool RunAutogen(cmMakefile* makefile);
 
-  bool GenerateMocFiles(
-    const std::map<std::string, std::string>& includedMocs,
-    const std::map<std::string, std::string>& notIncludedMocs);
-  bool GenerateMoc(const std::string& sourceFile,
-                   const std::string& mocFileName,
-                   const std::string& subDirPrefix);
-
-  bool GenerateUiFiles(
-    const std::map<std::string, std::vector<std::string> >& includedUis);
-  bool GenerateUi(const std::string& realName, const std::string& uiInputFile,
-                  const std::string& uiOutputFile);
-
-  bool GenerateQrcFiles();
-  bool GenerateQrc(const std::string& qrcInputFile,
-                   const std::string& qrcOutputFile, bool unique_n);
+  // - Content analysis
+  bool requiresMocing(const std::string& text, std::string& macroName);
+  bool MocSkipTest(const std::string& absFilename);
+  bool UicSkipTest(const std::string& absFilename);
 
   bool ParseSourceFile(
     const std::string& absFilename,
@@ -55,6 +47,7 @@ private:
     std::map<std::string, std::string>& includedMocs,
     std::map<std::string, std::vector<std::string> >& includedUis,
     bool relaxed);
+
   void SearchHeadersForSourceFile(
     const std::string& absFilename,
     const std::vector<std::string>& headerExtensions,
@@ -68,8 +61,6 @@ private:
     std::map<std::string, std::string>& notIncludedMocs,
     std::map<std::string, std::vector<std::string> >& includedUis);
 
-  bool requiresMocing(const std::string& text, std::string& macroName);
-
   void ParseContentForUic(
     const std::string& fileName, const std::string& contentsString,
     std::map<std::string, std::vector<std::string> >& includedUis);
@@ -80,18 +71,31 @@ private:
                           std::map<std::string, std::string>& includedMocs,
                           bool relaxed);
 
-  void ParseForUic(
-    const std::string& fileName,
-    std::map<std::string, std::vector<std::string> >& includedUis);
-
-  void Init();
+  // - Moc file generation
+  bool GenerateMocFiles(
+    const std::map<std::string, std::string>& includedMocs,
+    const std::map<std::string, std::string>& notIncludedMocs);
+  bool GenerateMoc(const std::string& sourceFile,
+                   const std::string& mocFileName,
+                   const std::string& subDirPrefix);
 
-  bool MocSkipTest(const std::string& absFilename);
-  bool UicSkipTest(const std::string& absFilename);
+  // - Uic file generation
+  static void MergeUicOptions(std::vector<std::string>& opts,
+                              const std::vector<std::string>& fileOpts,
+                              bool isQt5);
+  bool GenerateUiFiles(
+    const std::map<std::string, std::vector<std::string> >& includedUis);
+  bool GenerateUi(const std::string& realName, const std::string& uiInputFile,
+                  const std::string& uiOutputFile);
 
-  bool NameCollisionTest(const std::map<std::string, std::string>& genFiles,
-                         std::multimap<std::string, std::string>& collisions);
+  // - Qrc file generation
+  bool InputFilesNewerThanQrc(const std::string& qrcFile,
+                              const std::string& rccOutput);
+  bool GenerateQrcFiles();
+  bool GenerateQrc(const std::string& qrcInputFile,
+                   const std::string& qrcOutputFile, bool unique_n);
 
+  // - Logging
   void LogErrorNameCollision(
     const std::string& message,
     const std::multimap<std::string, std::string>& collisions);
@@ -101,16 +105,11 @@ private:
   void LogError(const std::string& message);
   void LogCommand(const std::vector<std::string>& command);
 
+  // - Utility
+  bool NameCollisionTest(const std::map<std::string, std::string>& genFiles,
+                         std::multimap<std::string, std::string>& collisions);
   bool MakeParentDirectory(const std::string& filename);
-
-  std::string JoinExts(const std::vector<std::string>& lst);
-
-  static void MergeUicOptions(std::vector<std::string>& opts,
-                              const std::vector<std::string>& fileOpts,
-                              bool isQt5);
-
-  bool InputFilesNewerThanQrc(const std::string& qrcFile,
-                              const std::string& rccOutput);
+  static std::string JoinExts(const std::vector<std::string>& lst);
 
   // - Target names
   std::string OriginTargetName;