<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def register_tool(self, tool, name=None):
 """Check tool and see if it is installed in the local cpp toolchain. All cpp tasks should request their tools using this method. Tools are validated and cached for quick lookup. :param string tool: Name or path of program tool, eg 'g++' :param string name: Logical name of tool, eg 'compiler'. If not supplied defaults to basename of `tool` """

    name = name or os.path.basename(tool)
    if name in self._validated_tools:
      return self._validated_tools[name]

    def which(program):
      def is_exe(fpath):
        return os.path.isfile(fpath) and os.access(fpath, os.X_OK)

      fpath, fname = os.path.split(program)
      if fpath:
        if is_exe(program):
          return program
      else:
        for path in os.environ['PATH'].split(os.pathsep):
          path = path.strip('"')
          exe_file = os.path.join(path, program)
          if is_exe(exe_file):
            return exe_file

      return None

    tool_path = which(tool)
    if tool_path is None:
      raise self.Error('Failed to locate {0}. Please install.'.format(tool))
    self._validated_tools[name] = tool_path
    return tool_path