Преглед изворни кода

cmSourceFile: Remove non-const GetProperties accessor

Manipulating the property map of cmSourceFile directly may invalidate the class
invariant of the cached value IsGenerated.  Provide the setter SetProperties
which also updates IsGenerated.
Daniel Eiband пре 6 година
родитељ
комит
8456f60dbc
3 измењених фајлова са 10 додато и 2 уклоњено
  1. 1 1
      Source/cmCPluginAPI.cxx
  2. 7 0
      Source/cmSourceFile.cxx
  3. 2 1
      Source/cmSourceFile.h

+ 1 - 1
Source/cmCPluginAPI.cxx

@@ -561,7 +561,7 @@ void* CCONV cmAddSource(void* arg, void* arg2)
 
 
   // Create the real cmSourceFile instance and copy over saved information.
   // Create the real cmSourceFile instance and copy over saved information.
   cmSourceFile* rsf = mf->GetOrCreateSource(osf->FullPath);
   cmSourceFile* rsf = mf->GetOrCreateSource(osf->FullPath);
-  rsf->GetProperties() = osf->Properties;
+  rsf->SetProperties(osf->Properties);
   for (std::string const& d : osf->Depends) {
   for (std::string const& d : osf->Depends) {
     rsf->AddDepend(d);
     rsf->AddDepend(d);
   }
   }

+ 7 - 0
Source/cmSourceFile.cxx

@@ -314,6 +314,13 @@ bool cmSourceFile::GetPropertyAsBool(const std::string& prop) const
   return cmIsOn(this->GetProperty(prop));
   return cmIsOn(this->GetProperty(prop));
 }
 }
 
 
+void cmSourceFile::SetProperties(cmPropertyMap properties)
+{
+  this->Properties = std::move(properties);
+
+  this->IsGenerated = this->GetPropertyAsBool(propGENERATED);
+}
+
 cmCustomCommand* cmSourceFile::GetCustomCommand() const
 cmCustomCommand* cmSourceFile::GetCustomCommand() const
 {
 {
   return this->CustomCommand.get();
   return this->CustomCommand.get();

+ 2 - 1
Source/cmSourceFile.h

@@ -94,8 +94,9 @@ public:
   void AddDepend(const std::string& d) { this->Depends.push_back(d); }
   void AddDepend(const std::string& d) { this->Depends.push_back(d); }
 
 
   // Get the properties
   // Get the properties
-  cmPropertyMap& GetProperties() { return this->Properties; }
   const cmPropertyMap& GetProperties() const { return this->Properties; }
   const cmPropertyMap& GetProperties() const { return this->Properties; }
+  // Set the properties
+  void SetProperties(cmPropertyMap properties);
 
 
   /**
   /**
    * Check whether the given source file location could refer to this
    * Check whether the given source file location could refer to this