Bläddra i källkod

cmMakefile: Trivially constify some methods.

Stephen Kelly 12 år sedan
förälder
incheckning
01d7ceda5d
2 ändrade filer med 51 tillägg och 51 borttagningar
  1. 25 22
      Source/cmMakefile.cxx
  2. 26 29
      Source/cmMakefile.h

+ 25 - 22
Source/cmMakefile.cxx

@@ -179,7 +179,7 @@ unsigned int cmMakefile::GetCacheMinorVersion() const
   return this->GetCacheManager()->GetCacheMinorVersion();
 }
 
-bool cmMakefile::NeedCacheCompatibility(int major, int minor)
+bool cmMakefile::NeedCacheCompatibility(int major, int minor) const
 {
   return this->GetCacheManager()->NeedCacheCompatibility(major, minor);
 }
@@ -260,7 +260,7 @@ void cmMakefile
 
 
 // call print on all the classes in the makefile
-void cmMakefile::Print()
+void cmMakefile::Print() const
 {
   // print the class lists
   std::cout << "classes:\n";
@@ -359,7 +359,7 @@ bool cmMakefile::GetBacktrace(cmListFileBacktrace& backtrace) const
 }
 
 //----------------------------------------------------------------------------
-void cmMakefile::PrintCommandTrace(const cmListFileFunction& lff)
+void cmMakefile::PrintCommandTrace(const cmListFileFunction& lff) const
 {
   cmOStringStream msg;
   msg << lff.FilePath << "(" << lff.Line << "):  ";
@@ -734,7 +734,7 @@ bool cmMakefile::ReadListFile(const char* filename_in,
 }
 
 //----------------------------------------------------------------------------
-void cmMakefile::EnforceDirectoryLevelRules()
+void cmMakefile::EnforceDirectoryLevelRules() const
 {
   // Diagnose a violation of CMP0000 if necessary.
   if(this->CheckCMP0000)
@@ -2058,7 +2058,8 @@ cmMakefile::AddNewTarget(cmTarget::TargetType type, const char* name)
   return &it->second;
 }
 
-cmSourceFile *cmMakefile::LinearGetSourceFileWithOutput(const char *cname)
+cmSourceFile*
+cmMakefile::LinearGetSourceFileWithOutput(const char *cname) const
 {
   std::string name = cname;
   std::string out;
@@ -2094,7 +2095,7 @@ cmSourceFile *cmMakefile::LinearGetSourceFileWithOutput(const char *cname)
   return 0;
 }
 
-cmSourceFile *cmMakefile::GetSourceFileWithOutput(const char *cname)
+cmSourceFile *cmMakefile::GetSourceFileWithOutput(const char *cname) const
 {
   std::string name = cname;
 
@@ -2105,7 +2106,7 @@ cmSourceFile *cmMakefile::GetSourceFileWithOutput(const char *cname)
     return LinearGetSourceFileWithOutput(cname);
     }
   // Otherwise we use an efficient lookup map.
-  OutputToSourceMap::iterator o = this->OutputToSource.find(name);
+  OutputToSourceMap::const_iterator o = this->OutputToSource.find(name);
   if (o != this->OutputToSource.end())
     {
     return (*o).second;
@@ -2376,7 +2377,7 @@ const char* cmMakefile::GetSONameFlag(const char* language) const
   return GetDefinition(name.c_str());
 }
 
-bool cmMakefile::CanIWriteThisFile(const char* fileName)
+bool cmMakefile::CanIWriteThisFile(const char* fileName) const
 {
   if ( !this->IsOn("CMAKE_DISABLE_SOURCE_CHANGES") )
     {
@@ -2518,7 +2519,7 @@ std::vector<std::string> cmMakefile
 }
 
 
-const char *cmMakefile::ExpandVariablesInString(std::string& source)
+const char *cmMakefile::ExpandVariablesInString(std::string& source) const
 {
   return this->ExpandVariablesInString(source, false, false);
 }
@@ -2530,7 +2531,7 @@ const char *cmMakefile::ExpandVariablesInString(std::string& source,
                                                 const char* filename,
                                                 long line,
                                                 bool removeEmpty,
-                                                bool replaceAt)
+                                                bool replaceAt) const
 {
   if ( source.empty() || source.find_first_of("$@\\") == source.npos)
     {
@@ -2865,7 +2866,7 @@ void cmMakefile::PopFunctionBlockerBarrier(bool reportError)
 
 bool cmMakefile::ExpandArguments(
   std::vector<cmListFileArgument> const& inArgs,
-  std::vector<std::string>& outArgs)
+  std::vector<std::string>& outArgs) const
 {
   std::vector<cmListFileArgument>::const_iterator i;
   std::string value;
@@ -3009,7 +3010,7 @@ void cmMakefile::SetArgcArgv(const std::vector<std::string>& args)
 }
 
 //----------------------------------------------------------------------------
-cmSourceFile* cmMakefile::GetSource(const char* sourceName)
+cmSourceFile* cmMakefile::GetSource(const char* sourceName) const
 {
   cmSourceFileLocation sfl(this, sourceName);
   for(std::vector<cmSourceFile*>::const_iterator
@@ -3057,7 +3058,7 @@ void cmMakefile::EnableLanguage(std::vector<std::string> const &  lang,
 
 void cmMakefile::ExpandSourceListArguments(
   std::vector<std::string> const& arguments,
-  std::vector<std::string>& newargs, unsigned int /* start */)
+  std::vector<std::string>& newargs, unsigned int /* start */) const
 {
   // now expand the args
   unsigned int i;
@@ -3257,7 +3258,7 @@ cmCacheManager *cmMakefile::GetCacheManager() const
   return this->GetCMakeInstance()->GetCacheManager();
 }
 
-void cmMakefile::DisplayStatus(const char* message, float s)
+void cmMakefile::DisplayStatus(const char* message, float s) const
 {
   cmake* cm = this->GetLocalGenerator()->GetGlobalGenerator()
                                                           ->GetCMakeInstance();
@@ -3270,7 +3271,7 @@ void cmMakefile::DisplayStatus(const char* message, float s)
   cm->UpdateProgress(message, s);
 }
 
-std::string cmMakefile::GetModulesFile(const char* filename)
+std::string cmMakefile::GetModulesFile(const char* filename) const
 {
   std::string result;
 
@@ -3939,13 +3940,13 @@ void cmMakefile::AddCMakeDependFilesFromUser()
     }
 }
 
-std::string cmMakefile::GetListFileStack()
+std::string cmMakefile::GetListFileStack() const
 {
   cmOStringStream tmp;
   size_t depth = this->ListFileStack.size();
   if (depth > 0)
     {
-    std::deque<cmStdString>::iterator it = this->ListFileStack.end();
+    std::deque<cmStdString>::const_iterator it = this->ListFileStack.end();
     do
       {
       if (depth != this->ListFileStack.size())
@@ -4091,7 +4092,7 @@ cmMakefile::AddImportedTarget(const char* name, cmTarget::TargetType type,
 
 //----------------------------------------------------------------------------
 cmTarget* cmMakefile::FindTargetToUse(const std::string& name,
-                                      bool excludeAliases)
+                                      bool excludeAliases) const
 {
   // Look for an imported target.  These take priority because they
   // are more local in scope and do not have to be globally unique.
@@ -4115,7 +4116,7 @@ cmTarget* cmMakefile::FindTargetToUse(const std::string& name,
 }
 
 //----------------------------------------------------------------------------
-bool cmMakefile::IsAlias(const std::string& name)
+bool cmMakefile::IsAlias(const std::string& name) const
 {
   if (this->AliasTargets.find(name) != this->AliasTargets.end())
     return true;
@@ -4124,7 +4125,8 @@ bool cmMakefile::IsAlias(const std::string& name)
 }
 
 //----------------------------------------------------------------------------
-cmGeneratorTarget* cmMakefile::FindGeneratorTargetToUse(const char* name)
+cmGeneratorTarget*
+cmMakefile::FindGeneratorTargetToUse(const char* name) const
 {
   if (cmTarget *t = this->FindTargetToUse(name))
     {
@@ -4135,7 +4137,7 @@ cmGeneratorTarget* cmMakefile::FindGeneratorTargetToUse(const char* name)
 
 //----------------------------------------------------------------------------
 bool cmMakefile::EnforceUniqueName(std::string const& name, std::string& msg,
-                                   bool isCustom)
+                                   bool isCustom) const
 {
   if(this->IsAlias(name))
     {
@@ -4226,7 +4228,8 @@ bool cmMakefile::EnforceUniqueName(std::string const& name, std::string& msg,
 }
 
 //----------------------------------------------------------------------------
-bool cmMakefile::EnforceUniqueDir(const char* srcPath, const char* binPath)
+bool cmMakefile::EnforceUniqueDir(const char* srcPath,
+                                  const char* binPath) const
 {
   // Make sure the binary directory is unique.
   cmGlobalGenerator* gg = this->LocalGenerator->GetGlobalGenerator();

+ 26 - 29
Source/cmMakefile.h

@@ -76,7 +76,7 @@ public:
   bool VariableUsed(const char* ) const;
   /** Return whether compatibility features needed for a version of
       the cache or lower should be enabled.  */
-  bool NeedCacheCompatibility(int major, int minor);
+  bool NeedCacheCompatibility(int major, int minor) const;
 
   /**
    * Construct an empty makefile.
@@ -149,7 +149,7 @@ public:
    * Help enforce global target name uniqueness.
    */
   bool EnforceUniqueName(std::string const& name, std::string& msg,
-                         bool isCustom = false);
+                         bool isCustom = false) const;
 
   /**
    * Perform FinalPass, Library dependency analysis etc before output of the
@@ -165,7 +165,7 @@ public:
   /**
    * Print the object state to std::cout.
    */
-  void Print();
+  void Print() const;
 
   /** Add a custom command to the build.  */
   void AddCustomCommandToTarget(const char* target,
@@ -498,7 +498,7 @@ public:
     {
       this->ComplainFileRegularExpression = regex;
     }
-  const char* GetComplainRegularExpression()
+  const char* GetComplainRegularExpression() const
     {
       return this->ComplainFileRegularExpression.c_str();
     }
@@ -532,9 +532,9 @@ public:
   /** Find a target to use in place of the given name.  The target
       returned may be imported or built within the project.  */
   cmTarget* FindTargetToUse(const std::string& name,
-                            bool excludeAliases = false);
-  bool IsAlias(const std::string& name);
-  cmGeneratorTarget* FindGeneratorTargetToUse(const char* name);
+                            bool excludeAliases = false) const;
+  bool IsAlias(const std::string& name) const;
+  cmGeneratorTarget* FindGeneratorTargetToUse(const char* name) const;
 
   /**
    * Mark include directories as system directories.
@@ -550,12 +550,12 @@ public:
    */
   void ExpandSourceListArguments(std::vector<std::string> const& argsIn,
                                  std::vector<std::string>& argsOut,
-                                 unsigned int startArgumentIndex);
+                                 unsigned int startArgumentIndex) const;
 
   /** Get a cmSourceFile pointer for a given source name, if the name is
    *  not found, then a null pointer is returned.
    */
-  cmSourceFile* GetSource(const char* sourceName);
+  cmSourceFile* GetSource(const char* sourceName) const;
 
   /** Get a cmSourceFile pointer for a given source name, if the name is
    *  not found, then create the source file and return it. generated
@@ -568,7 +568,7 @@ public:
   /**
    * Obtain a list of auxiliary source directories.
    */
-  std::vector<std::string>& GetAuxSourceDirectories()
+  const std::vector<std::string>& GetAuxSourceDirectories() const
     {return this->AuxSourceDirectories;}
 
   //@{
@@ -613,13 +613,13 @@ public:
   /**
    * Get a list of preprocessor define flags.
    */
-  const char* GetDefineFlags()
+  const char* GetDefineFlags() const
     {return this->DefineFlags.c_str();}
 
   /**
    * Make sure CMake can write this file
    */
-  bool CanIWriteThisFile(const char* fileName);
+  bool CanIWriteThisFile(const char* fileName) const;
 
 #if defined(CMAKE_BUILD_WITH_CMAKE)
   /**
@@ -644,10 +644,7 @@ public:
     { this->ListFiles.push_back(file);}
   void AddCMakeDependFilesFromUser();
 
-    /**
-     * Get the list file stack as a string
-     */
-    std::string GetListFileStack();
+  std::string GetListFileStack() const;
 
   /**
    * Get the current context backtrace.
@@ -669,14 +666,14 @@ public:
    * entry in the this->Definitions map.  Also \@var\@ is
    * expanded to match autoconf style expansions.
    */
-  const char *ExpandVariablesInString(std::string& source);
+  const char *ExpandVariablesInString(std::string& source) const;
   const char *ExpandVariablesInString(std::string& source, bool escapeQuotes,
                                       bool noEscapes,
                                       bool atOnly = false,
                                       const char* filename = 0,
                                       long line = -1,
                                       bool removeEmpty = false,
-                                      bool replaceAt = true);
+                                      bool replaceAt = true) const;
 
   /**
    * Remove any remaining variables in the string. Anything with ${var} or
@@ -716,7 +713,7 @@ public:
   /**
    * Print a command's invocation
    */
-  void PrintCommandTrace(const cmListFileFunction& lff);
+  void PrintCommandTrace(const cmListFileFunction& lff) const;
 
   /**
    * Execute a single CMake command.  Returns true if the command
@@ -752,14 +749,14 @@ public:
 #endif
 
   ///! Display progress or status message.
-  void DisplayStatus(const char*, float);
+  void DisplayStatus(const char*, float) const;
 
   /**
    * Expand the given list file arguments into the full set after
    * variable replacement and list expansion.
    */
   bool ExpandArguments(std::vector<cmListFileArgument> const& inArgs,
-                       std::vector<std::string>& outArgs);
+                       std::vector<std::string>& outArgs) const;
   /**
    * Get the instance
    */
@@ -776,7 +773,7 @@ public:
    * Is there a source file that has the provided source file as an output?
    * if so then return it
    */
-  cmSourceFile *GetSourceFileWithOutput(const char *outName);
+  cmSourceFile *GetSourceFileWithOutput(const char *outName) const;
 
   /**
    * Add a macro to the list of macros. The arguments should be name of the
@@ -800,7 +797,7 @@ public:
   /**
    * Return a location of a file in cmake or custom modules directory
    */
-  std::string GetModulesFile(const char* name);
+  std::string GetModulesFile(const char* name) const;
 
   ///! Set/Get a property of this directory
   void SetProperty(const char *prop, const char *value);
@@ -829,7 +826,7 @@ public:
 
   void AddTestGenerator(cmTestGenerator* g)
     { if(g) this->TestGenerators.push_back(g); }
-  std::vector<cmTestGenerator*>& GetTestGenerators()
+  const std::vector<cmTestGenerator*>& GetTestGenerators() const
     { return this->TestGenerators; }
 
   // Define the properties
@@ -869,7 +866,7 @@ public:
     return this->CompileDefinitionsEntries;
   }
 
-  bool IsGeneratingBuildSystem(){ return this->GeneratingBuildSystem; }
+  bool IsGeneratingBuildSystem() const { return this->GeneratingBuildSystem; }
   void SetGeneratingBuildSystem(){ this->GeneratingBuildSystem = true; }
 
   void AddQtUiFileWithOptions(cmSourceFile *sf);
@@ -950,7 +947,7 @@ private:
 
   bool ParseDefineFlag(std::string const& definition, bool remove);
 
-  bool EnforceUniqueDir(const char* srcPath, const char* binPath);
+  bool EnforceUniqueDir(const char* srcPath, const char* binPath) const;
 
   friend class cmMakeDepend;    // make depend needs direct access
                                 // to the Sources array
@@ -973,7 +970,7 @@ private:
 
   cmsys::RegularExpression cmDefineRegex;
   cmsys::RegularExpression cmDefine01Regex;
-  cmsys::RegularExpression cmAtVarRegex;
+  mutable cmsys::RegularExpression cmAtVarRegex;
 
   cmPropertyMap Properties;
 
@@ -1028,7 +1025,7 @@ private:
   bool CheckCMP0000;
 
   // Enforce rules about CMakeLists.txt files.
-  void EnforceDirectoryLevelRules();
+  void EnforceDirectoryLevelRules() const;
 
   bool GeneratingBuildSystem;
   /**
@@ -1037,7 +1034,7 @@ private:
    * relative file paths. It is used as a fall back by
    * GetSourceFileWithOutput(const char*).
    */
-  cmSourceFile *LinearGetSourceFileWithOutput(const char *cname);
+  cmSourceFile *LinearGetSourceFileWithOutput(const char *cname) const;
 
   // A map for fast output to input look up.
 #if defined(CMAKE_BUILD_WITH_CMAKE)