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.
This commit is contained in:
Tushar Maheshwari
2019-08-27 21:35:42 +05:30
parent 65fe80794d
commit 8cb3cffa42
8 changed files with 18 additions and 21 deletions
+1 -1
View File
@@ -365,7 +365,7 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile(
// check whether it is a C/C++/CUDA implementation file // check whether it is a C/C++/CUDA implementation file
bool isCFile = false; bool isCFile = false;
std::string lang = s->GetLanguage(); std::string lang = s->GetOrDetermineLanguage();
if (lang == "C" || lang == "CXX" || lang == "CUDA") { if (lang == "C" || lang == "CXX" || lang == "CUDA") {
std::string const& srcext = s->GetExtension(); std::string const& srcext = s->GetExtension();
isCFile = cm->IsSourceExtension(srcext); isCFile = cm->IsSourceExtension(srcext);
+3 -3
View File
@@ -342,7 +342,7 @@ std::string cmExtraSublimeTextGenerator::ComputeFlagsForObject(
cmSourceFile* source, cmLocalGenerator* lg, cmGeneratorTarget* gtgt) cmSourceFile* source, cmLocalGenerator* lg, cmGeneratorTarget* gtgt)
{ {
std::string flags; std::string flags;
std::string language = source->GetLanguage(); std::string language = source->GetOrDetermineLanguage();
if (language.empty()) { if (language.empty()) {
language = "C"; language = "C";
} }
@@ -377,7 +377,7 @@ std::string cmExtraSublimeTextGenerator::ComputeDefines(
{ {
std::set<std::string> defines; std::set<std::string> defines;
cmMakefile* makefile = lg->GetMakefile(); 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"); const std::string& config = makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
cmGeneratorExpressionInterpreter genexInterpreter(lg, config, target, cmGeneratorExpressionInterpreter genexInterpreter(lg, config, target,
language); language);
@@ -410,7 +410,7 @@ std::string cmExtraSublimeTextGenerator::ComputeIncludes(
{ {
std::vector<std::string> includes; std::vector<std::string> includes;
cmMakefile* makefile = lg->GetMakefile(); 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"); const std::string& config = makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
cmGeneratorExpressionInterpreter genexInterpreter(lg, config, target, cmGeneratorExpressionInterpreter genexInterpreter(lg, config, target,
language); language);
+1 -1
View File
@@ -837,7 +837,7 @@ CompileData Target::BuildCompileData(cmSourceFile* sf)
{ {
CompileData fd; CompileData fd;
fd.Language = sf->GetLanguage(); fd.Language = sf->GetOrDetermineLanguage();
if (fd.Language.empty()) { if (fd.Language.empty()) {
return fd; return fd;
} }
+2 -2
View File
@@ -1593,7 +1593,7 @@ void cmGeneratorTarget::ComputeKindedSources(KindedSources& files,
kind = SourceKindHeader; kind = SourceKindHeader;
} else if (sf->GetPropertyAsBool("EXTERNAL_OBJECT")) { } else if (sf->GetPropertyAsBool("EXTERNAL_OBJECT")) {
kind = SourceKindExternalObject; kind = SourceKindExternalObject;
} else if (!sf->GetLanguage().empty()) { } else if (!sf->GetOrDetermineLanguage().empty()) {
kind = SourceKindObjectSource; kind = SourceKindObjectSource;
} else if (ext == "def") { } else if (ext == "def") {
kind = SourceKindModuleDefinition; kind = SourceKindModuleDefinition;
@@ -6055,7 +6055,7 @@ void cmGeneratorTarget::GetLanguages(std::set<std::string>& languages,
std::vector<cmSourceFile*> sourceFiles; std::vector<cmSourceFile*> sourceFiles;
this->GetSourceFiles(sourceFiles, config); this->GetSourceFiles(sourceFiles, config);
for (cmSourceFile* src : sourceFiles) { for (cmSourceFile* src : sourceFiles) {
const std::string& lang = src->GetLanguage(); const std::string& lang = src->GetOrDetermineLanguage();
if (!lang.empty()) { if (!lang.empty()) {
languages.insert(lang); languages.insert(lang);
} }
+1 -1
View File
@@ -25,7 +25,7 @@ bool cmGetSourceFilePropertyCommand::InitialPass(
} }
if (sf) { if (sf) {
if (args[2] == "LANGUAGE") { if (args[2] == "LANGUAGE") {
this->Makefile->AddDefinition(var, sf->GetLanguage()); this->Makefile->AddDefinition(var, sf->GetOrDetermineLanguage());
return true; return true;
} }
const char* prop = nullptr; const char* prop = nullptr;
+1 -1
View File
@@ -264,7 +264,7 @@ static Json::Value DumpSourceFilesList(
std::unordered_map<LanguageData, std::vector<std::string>> fileGroups; std::unordered_map<LanguageData, std::vector<std::string>> fileGroups;
for (cmSourceFile* file : files) { for (cmSourceFile* file : files) {
LanguageData fileData; LanguageData fileData;
fileData.Language = file->GetLanguage(); fileData.Language = file->GetOrDetermineLanguage();
if (!fileData.Language.empty()) { if (!fileData.Language.empty()) {
const LanguageData& ld = languageDataMap.at(fileData.Language); const LanguageData& ld = languageDataMap.at(fileData.Language);
cmLocalGenerator* lg = target->GetLocalGenerator(); cmLocalGenerator* lg = target->GetLocalGenerator();
+8 -11
View File
@@ -45,11 +45,13 @@ std::string cmSourceFile::GetObjectLibrary() const
return this->ObjectLibrary; 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 the language was set explicitly by the user then use it.
if (const char* lang = this->GetProperty(propLANGUAGE)) { 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. // Perform computation needed to get the language if necessary.
@@ -72,8 +74,8 @@ std::string cmSourceFile::GetLanguage()
} }
} }
// Now try to determine the language. // Use the language determined from the file extension.
return static_cast<cmSourceFile const*>(this)->GetLanguage(); return this->Language;
} }
std::string cmSourceFile::GetLanguage() const std::string cmSourceFile::GetLanguage() const
@@ -83,13 +85,8 @@ std::string cmSourceFile::GetLanguage() const
return lang; return lang;
} }
// If the language was determined from the source file extension use it. // Use the language determined from the file extension.
if (!this->Language.empty()) { return this->Language;
return this->Language;
}
// The language is not known.
return "";
} }
cmSourceFileLocation const& cmSourceFile::GetLocation() const cmSourceFileLocation const& cmSourceFile::GetLocation() const
+1 -1
View File
@@ -88,7 +88,7 @@ public:
/** /**
* Get the language of the compiler to use for this source file. * Get the language of the compiler to use for this source file.
*/ */
std::string GetLanguage(); std::string const& GetOrDetermineLanguage();
std::string GetLanguage() const; std::string GetLanguage() const;
/** /**