diff options
author | Tushar Maheshwari <tushar27192@gmail.com> | 2019-08-27 16:05:42 (GMT) |
---|---|---|
committer | Tushar Maheshwari <tushar27192@gmail.com> | 2019-08-27 16:05:42 (GMT) |
commit | 8cb3cffa42e11c2508ed8db703f2f9a1a73fbbb9 (patch) | |
tree | 88c3d054322f1e36ac67958e7da8c88897baaa82 | |
parent | 65fe80794d41ab6f0b1e608d7535b7530a2ff51d (diff) | |
download | CMake-8cb3cffa42e11c2508ed8db703f2f9a1a73fbbb9.zip CMake-8cb3cffa42e11c2508ed8db703f2f9a1a73fbbb9.tar.gz CMake-8cb3cffa42e11c2508ed8db703f2f9a1a73fbbb9.tar.bz2 |
cmSourceFile: Rename non-const GetLanguage
GetOrDetermineLanguage:
- Read the property if available
- Determine the Language using the file extension
Fix all usage of the non-const member in the repository.
-rw-r--r-- | Source/cmExtraCodeBlocksGenerator.cxx | 2 | ||||
-rw-r--r-- | Source/cmExtraSublimeTextGenerator.cxx | 6 | ||||
-rw-r--r-- | Source/cmFileAPICodemodel.cxx | 2 | ||||
-rw-r--r-- | Source/cmGeneratorTarget.cxx | 4 | ||||
-rw-r--r-- | Source/cmGetSourceFilePropertyCommand.cxx | 2 | ||||
-rw-r--r-- | Source/cmJsonObjects.cxx | 2 | ||||
-rw-r--r-- | Source/cmSourceFile.cxx | 19 | ||||
-rw-r--r-- | Source/cmSourceFile.h | 2 |
8 files changed, 18 insertions, 21 deletions
diff --git a/Source/cmExtraCodeBlocksGenerator.cxx b/Source/cmExtraCodeBlocksGenerator.cxx index d8a1a49..487d0de 100644 --- a/Source/cmExtraCodeBlocksGenerator.cxx +++ b/Source/cmExtraCodeBlocksGenerator.cxx @@ -365,7 +365,7 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile( // check whether it is a C/C++/CUDA implementation file bool isCFile = false; - std::string lang = s->GetLanguage(); + std::string lang = s->GetOrDetermineLanguage(); if (lang == "C" || lang == "CXX" || lang == "CUDA") { std::string const& srcext = s->GetExtension(); isCFile = cm->IsSourceExtension(srcext); diff --git a/Source/cmExtraSublimeTextGenerator.cxx b/Source/cmExtraSublimeTextGenerator.cxx index 33f5157..6f4472b 100644 --- a/Source/cmExtraSublimeTextGenerator.cxx +++ b/Source/cmExtraSublimeTextGenerator.cxx @@ -342,7 +342,7 @@ std::string cmExtraSublimeTextGenerator::ComputeFlagsForObject( cmSourceFile* source, cmLocalGenerator* lg, cmGeneratorTarget* gtgt) { std::string flags; - std::string language = source->GetLanguage(); + std::string language = source->GetOrDetermineLanguage(); if (language.empty()) { language = "C"; } @@ -377,7 +377,7 @@ std::string cmExtraSublimeTextGenerator::ComputeDefines( { std::set<std::string> defines; cmMakefile* makefile = lg->GetMakefile(); - const std::string& language = source->GetLanguage(); + const std::string& language = source->GetOrDetermineLanguage(); const std::string& config = makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"); cmGeneratorExpressionInterpreter genexInterpreter(lg, config, target, language); @@ -410,7 +410,7 @@ std::string cmExtraSublimeTextGenerator::ComputeIncludes( { std::vector<std::string> includes; cmMakefile* makefile = lg->GetMakefile(); - const std::string& language = source->GetLanguage(); + const std::string& language = source->GetOrDetermineLanguage(); const std::string& config = makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"); cmGeneratorExpressionInterpreter genexInterpreter(lg, config, target, language); diff --git a/Source/cmFileAPICodemodel.cxx b/Source/cmFileAPICodemodel.cxx index e4b7670..08db7c7 100644 --- a/Source/cmFileAPICodemodel.cxx +++ b/Source/cmFileAPICodemodel.cxx @@ -837,7 +837,7 @@ CompileData Target::BuildCompileData(cmSourceFile* sf) { CompileData fd; - fd.Language = sf->GetLanguage(); + fd.Language = sf->GetOrDetermineLanguage(); if (fd.Language.empty()) { return fd; } diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 3048c5f..1d64f1c 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -1593,7 +1593,7 @@ void cmGeneratorTarget::ComputeKindedSources(KindedSources& files, kind = SourceKindHeader; } else if (sf->GetPropertyAsBool("EXTERNAL_OBJECT")) { kind = SourceKindExternalObject; - } else if (!sf->GetLanguage().empty()) { + } else if (!sf->GetOrDetermineLanguage().empty()) { kind = SourceKindObjectSource; } else if (ext == "def") { kind = SourceKindModuleDefinition; @@ -6055,7 +6055,7 @@ void cmGeneratorTarget::GetLanguages(std::set<std::string>& languages, std::vector<cmSourceFile*> sourceFiles; this->GetSourceFiles(sourceFiles, config); for (cmSourceFile* src : sourceFiles) { - const std::string& lang = src->GetLanguage(); + const std::string& lang = src->GetOrDetermineLanguage(); if (!lang.empty()) { languages.insert(lang); } diff --git a/Source/cmGetSourceFilePropertyCommand.cxx b/Source/cmGetSourceFilePropertyCommand.cxx index a16076d..5a477b9 100644 --- a/Source/cmGetSourceFilePropertyCommand.cxx +++ b/Source/cmGetSourceFilePropertyCommand.cxx @@ -25,7 +25,7 @@ bool cmGetSourceFilePropertyCommand::InitialPass( } if (sf) { if (args[2] == "LANGUAGE") { - this->Makefile->AddDefinition(var, sf->GetLanguage()); + this->Makefile->AddDefinition(var, sf->GetOrDetermineLanguage()); return true; } const char* prop = nullptr; diff --git a/Source/cmJsonObjects.cxx b/Source/cmJsonObjects.cxx index b8eed13..4948b01 100644 --- a/Source/cmJsonObjects.cxx +++ b/Source/cmJsonObjects.cxx @@ -264,7 +264,7 @@ static Json::Value DumpSourceFilesList( std::unordered_map<LanguageData, std::vector<std::string>> fileGroups; for (cmSourceFile* file : files) { LanguageData fileData; - fileData.Language = file->GetLanguage(); + fileData.Language = file->GetOrDetermineLanguage(); if (!fileData.Language.empty()) { const LanguageData& ld = languageDataMap.at(fileData.Language); cmLocalGenerator* lg = target->GetLocalGenerator(); diff --git a/Source/cmSourceFile.cxx b/Source/cmSourceFile.cxx index a6d2807..738a1c0 100644 --- a/Source/cmSourceFile.cxx +++ b/Source/cmSourceFile.cxx @@ -45,11 +45,13 @@ std::string cmSourceFile::GetObjectLibrary() const return this->ObjectLibrary; } -std::string cmSourceFile::GetLanguage() +std::string const& cmSourceFile::GetOrDetermineLanguage() { // If the language was set explicitly by the user then use it. if (const char* lang = this->GetProperty(propLANGUAGE)) { - return lang; + // Assign to member in order to return a reference. + this->Language = lang; + return this->Language; } // Perform computation needed to get the language if necessary. @@ -72,8 +74,8 @@ std::string cmSourceFile::GetLanguage() } } - // Now try to determine the language. - return static_cast<cmSourceFile const*>(this)->GetLanguage(); + // Use the language determined from the file extension. + return this->Language; } std::string cmSourceFile::GetLanguage() const @@ -83,13 +85,8 @@ std::string cmSourceFile::GetLanguage() const return lang; } - // If the language was determined from the source file extension use it. - if (!this->Language.empty()) { - return this->Language; - } - - // The language is not known. - return ""; + // Use the language determined from the file extension. + return this->Language; } cmSourceFileLocation const& cmSourceFile::GetLocation() const diff --git a/Source/cmSourceFile.h b/Source/cmSourceFile.h index edad4c7..ccd5b62 100644 --- a/Source/cmSourceFile.h +++ b/Source/cmSourceFile.h @@ -88,7 +88,7 @@ public: /** * Get the language of the compiler to use for this source file. */ - std::string GetLanguage(); + std::string const& GetOrDetermineLanguage(); std::string GetLanguage() const; /** |