diff options
author | Daniel Pfeifer <daniel@pfeifer-mail.de> | 2017-05-10 20:08:05 (GMT) |
---|---|---|
committer | Daniel Pfeifer <daniel@pfeifer-mail.de> | 2017-05-11 17:49:06 (GMT) |
commit | 4ba25a823e62271a74dfd1845f535400e2da125b (patch) | |
tree | e932951c7d36b888654fd08c4a023171efa5d9ae /Source/cmState.cxx | |
parent | a44dab461ffe269618f008f16e249d9101c5bd88 (diff) | |
download | CMake-4ba25a823e62271a74dfd1845f535400e2da125b.zip CMake-4ba25a823e62271a74dfd1845f535400e2da125b.tar.gz CMake-4ba25a823e62271a74dfd1845f535400e2da125b.tar.bz2 |
cmState: separate builtin and scripted commands
Diffstat (limited to 'Source/cmState.cxx')
-rw-r--r-- | Source/cmState.cxx | 117 |
1 files changed, 50 insertions, 67 deletions
diff --git a/Source/cmState.cxx b/Source/cmState.cxx index 6de4c9f..11ad6c0 100644 --- a/Source/cmState.cxx +++ b/Source/cmState.cxx @@ -36,7 +36,8 @@ cmState::cmState() cmState::~cmState() { delete this->CacheManager; - cmDeleteAll(this->Commands); + cmDeleteAll(this->BuiltinCommands); + cmDeleteAll(this->ScriptedCommands); } const char* cmState::GetTargetTypeName(cmStateEnums::TargetType targetType) @@ -377,47 +378,12 @@ void cmState::SetIsGeneratorMultiConfig(bool b) this->IsGeneratorMultiConfig = b; } -void cmState::RenameCommand(std::string const& oldName, - std::string const& newName) -{ - // if the command already exists, free the old one - std::string sOldName = cmSystemTools::LowerCase(oldName); - std::string sNewName = cmSystemTools::LowerCase(newName); - std::map<std::string, cmCommand*>::iterator pos = - this->Commands.find(sOldName); - if (pos == this->Commands.end()) { - return; - } - cmCommand* cmd = pos->second; - - pos = this->Commands.find(sNewName); - if (pos != this->Commands.end()) { - delete pos->second; - this->Commands.erase(pos); - } - this->Commands.insert(std::make_pair(sNewName, cmd)); - pos = this->Commands.find(sOldName); - this->Commands.erase(pos); -} - -void cmState::AddCommand(cmCommand* command) -{ - std::string name = cmSystemTools::LowerCase(command->GetName()); - // if the command already exists, free the old one - std::map<std::string, cmCommand*>::iterator pos = this->Commands.find(name); - if (pos != this->Commands.end()) { - delete pos->second; - this->Commands.erase(pos); - } - this->Commands.insert(std::make_pair(name, command)); -} - void cmState::AddBuiltinCommand(std::string const& name, cmCommand* command) { assert(name == cmSystemTools::LowerCase(name)); assert(name == cmSystemTools::LowerCase(command->GetName())); - assert(this->Commands.find(name) == this->Commands.end()); - this->Commands.insert(std::make_pair(name, command)); + assert(this->BuiltinCommands.find(name) == this->BuiltinCommands.end()); + this->BuiltinCommands.insert(std::make_pair(name, command)); } void cmState::AddDisallowedCommand(std::string const& name, cmCommand* command, @@ -435,53 +401,70 @@ void cmState::AddUnexpectedCommand(std::string const& name, const char* error) void cmState::AddScriptedCommand(std::string const& name, cmCommand* command) { - this->RenameCommand(name, "_" + name); - this->AddCommand(command); + std::string sName = cmSystemTools::LowerCase(name); + + // if the command already exists, give a new name to the old command. + if (cmCommand* oldCmd = this->GetCommand(sName)) { + std::string const newName = "_" + sName; + std::map<std::string, cmCommand*>::iterator pos = + this->ScriptedCommands.find(newName); + if (pos != this->ScriptedCommands.end()) { + delete pos->second; + this->ScriptedCommands.erase(pos); + } + this->ScriptedCommands.insert(std::make_pair(newName, oldCmd->Clone())); + } + + // if the command already exists, free the old one + std::map<std::string, cmCommand*>::iterator pos = + this->ScriptedCommands.find(sName); + if (pos != this->ScriptedCommands.end()) { + delete pos->second; + this->ScriptedCommands.erase(pos); + } + this->ScriptedCommands.insert(std::make_pair(sName, command)); } cmCommand* cmState::GetCommand(std::string const& name) const { - cmCommand* command = CM_NULLPTR; std::string sName = cmSystemTools::LowerCase(name); - std::map<std::string, cmCommand*>::const_iterator pos = - this->Commands.find(sName); - if (pos != this->Commands.end()) { - command = (*pos).second; + std::map<std::string, cmCommand*>::const_iterator pos; + pos = this->ScriptedCommands.find(sName); + if (pos != this->ScriptedCommands.end()) { + return pos->second; } - return command; + pos = this->BuiltinCommands.find(sName); + if (pos != this->BuiltinCommands.end()) { + return pos->second; + } + return CM_NULLPTR; } std::vector<std::string> cmState::GetCommandNames() const { std::vector<std::string> commandNames; - commandNames.reserve(this->Commands.size()); - std::map<std::string, cmCommand*>::const_iterator cmds = - this->Commands.begin(); - for (; cmds != this->Commands.end(); ++cmds) { + commandNames.reserve(this->BuiltinCommands.size() + + this->ScriptedCommands.size()); + for (std::map<std::string, cmCommand*>::const_iterator cmds = + this->BuiltinCommands.begin(); + cmds != this->BuiltinCommands.end(); ++cmds) { + commandNames.push_back(cmds->first); + } + for (std::map<std::string, cmCommand*>::const_iterator cmds = + this->ScriptedCommands.begin(); + cmds != this->ScriptedCommands.end(); ++cmds) { commandNames.push_back(cmds->first); } + std::sort(commandNames.begin(), commandNames.end()); + commandNames.erase(std::unique(commandNames.begin(), commandNames.end()), + commandNames.end()); return commandNames; } void cmState::RemoveUserDefinedCommands() { - std::vector<cmCommand*> renamedCommands; - for (std::map<std::string, cmCommand*>::iterator j = this->Commands.begin(); - j != this->Commands.end();) { - if (j->second->IsUserDefined()) { - delete j->second; - this->Commands.erase(j++); - } else if (j->first != j->second->GetName()) { - renamedCommands.push_back(j->second); - this->Commands.erase(j++); - } else { - ++j; - } - } - for (std::vector<cmCommand*>::const_iterator it = renamedCommands.begin(); - it != renamedCommands.end(); ++it) { - this->Commands[cmSystemTools::LowerCase((*it)->GetName())] = *it; - } + cmDeleteAll(this->ScriptedCommands); + this->ScriptedCommands.clear(); } void cmState::SetGlobalProperty(const std::string& prop, const char* value) |