[cmake-commits] king committed cmGetSourceFilePropertyCommand.cxx 1.9 1.9.10.1 cmSourceFile.cxx 1.35.8.3 1.35.8.4 cmSourceFile.h 1.21.2.3 1.21.2.4

cmake-commits at cmake.org cmake-commits at cmake.org
Wed Jun 13 16:12:15 EDT 2007


Update of /cvsroot/CMake/CMake/Source
In directory public:/mounts/ram/cvs-serv26525

Modified Files:
      Tag: CMake-SourceFile2-b
	cmGetSourceFilePropertyCommand.cxx cmSourceFile.cxx 
	cmSourceFile.h 
Log Message:
ENH: Improved const-correctness of cmSourceFile API.  On-demand computation of the full path is now done only for non-const cmSourceFile instances.


Index: cmSourceFile.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmSourceFile.cxx,v
retrieving revision 1.35.8.3
retrieving revision 1.35.8.4
diff -u -d -r1.35.8.3 -r1.35.8.4
--- cmSourceFile.cxx	13 Jun 2007 19:32:24 -0000	1.35.8.3
+++ cmSourceFile.cxx	13 Jun 2007 20:12:13 -0000	1.35.8.4
@@ -40,52 +40,52 @@
 std::string const& cmSourceFile::GetExtension() const
 {
   // Make sure the file location is known.
-  this->GetFullPath();
+  if(this->FullPath.empty())
+    {
+    abort();
+    }
   return this->Extension;
 }
 
 //----------------------------------------------------------------------------
 const char* cmSourceFile::GetLanguage() const
 {
-  if(this->Language.empty())
-    {
-    if(const char* lang = this->GetProperty("LANGUAGE"))
-      {
-      this->Language = lang;
-      }
-    else
-      {
-      this->GetFullPath();
-      cmLocalGenerator* lg =
-        this->Location.GetMakefile()->GetLocalGenerator();
-      cmGlobalGenerator* gg = lg->GetGlobalGenerator();
-      if(const char* l = gg->GetLanguageFromExtension(this->Extension.c_str()))
-        {
-        this->Language = l;
-        }
-      }
-    }
-  if(this->Language.empty())
+  // If the language was set explicitly by the user then use it.
+  if(const char* lang = this->GetProperty("LANGUAGE"))
     {
-    return 0;
+    return lang;
     }
-  else
+
+  // If the language was determined from the source file extension use it.
+  if(!this->Language.empty())
     {
     return this->Language.c_str();
     }
+
+  // The language is not known.
+  return 0;
 }
 
 //----------------------------------------------------------------------------
-std::string const& cmSourceFile::GetFullPath() const
+std::string const& cmSourceFile::GetFullPath()
 {
   if(this->FullPath.empty())
     {
-    cmSourceFile* self = const_cast<cmSourceFile*>(this);
-    if(self->FindFullPath())
+    if(this->FindFullPath())
       {
-      self->CheckExtension();
+      this->CheckExtension();
       }
     }
+  return static_cast<cmSourceFile const*>(this)->GetFullPath();
+}
+
+//----------------------------------------------------------------------------
+std::string const& cmSourceFile::GetFullPath() const
+{
+  if(this->FullPath.empty())
+    {
+    abort();
+    }
   return this->FullPath;
 }
 
@@ -216,6 +216,13 @@
     {
     this->SetProperty("HEADER_FILE_ONLY", "1");
     }
+
+  // Try to identify the source file language from the extension.
+  cmGlobalGenerator* gg = mf->GetLocalGenerator()->GetGlobalGenerator();
+  if(const char* l = gg->GetLanguageFromExtension(this->Extension.c_str()))
+    {
+    this->Language = l;
+    }
 }
 
 //----------------------------------------------------------------------------
@@ -242,11 +249,17 @@
 //----------------------------------------------------------------------------
 const char* cmSourceFile::GetProperty(const char* prop) const
 {
-  // watch for special "computed" properties that are dependent on other
-  // properties or variables, always recompute them
-  if (!strcmp(prop,"LOCATION"))
+  // Check for computed properties.
+  if(strcmp(prop, "LOCATION") == 0)
     {
-    return this->GetFullPath().c_str();
+    if(this->FullPath.empty())
+      {
+      return 0;
+      }
+    else
+      {
+      return this->FullPath.c_str();
+      }
     }
 
   bool chain = false;

Index: cmSourceFile.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmSourceFile.h,v
retrieving revision 1.21.2.3
retrieving revision 1.21.2.4
diff -u -d -r1.21.2.3 -r1.21.2.4
--- cmSourceFile.h	13 Jun 2007 19:32:24 -0000	1.21.2.3
+++ cmSourceFile.h	13 Jun 2007 20:12:13 -0000	1.21.2.4
@@ -55,6 +55,7 @@
   /**
    * The full path to the file.
    */
+  std::string const& GetFullPath();
   std::string const& GetFullPath() const;
 
   /**
@@ -90,7 +91,7 @@
   cmPropertyMap Properties;
   cmCustomCommand* CustomCommand;
   std::string Extension;
-  mutable std::string Language;
+  std::string Language;
   std::string FullPath;
 
   bool FindFullPath();

Index: cmGetSourceFilePropertyCommand.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmGetSourceFilePropertyCommand.cxx,v
retrieving revision 1.9
retrieving revision 1.9.10.1
diff -u -d -r1.9 -r1.9.10.1
--- cmGetSourceFilePropertyCommand.cxx	22 Mar 2006 19:06:52 -0000	1.9
+++ cmGetSourceFilePropertyCommand.cxx	13 Jun 2007 20:12:13 -0000	1.9.10.1
@@ -38,6 +38,11 @@
     }
   if(sf)
     {
+    if(args[2] == "LOCATION")
+      {
+      // Make sure the location is known.
+      sf->GetFullPath();
+      }
     const char *prop = sf->GetProperty(args[2].c_str());
     if (prop)
       {



More information about the Cmake-commits mailing list