Use llvm::VersionTuple instead of manual version marshalling

Summary:
This has multiple advantages:
- we need only one function argument/instance variable instead of three
- no need to default initialize variables
- no custom parsing code
- VersionTuple has comparison operators, which makes version comparisons much
  simpler

Reviewers: zturner, friss, clayborg, jingham

Subscribers: emaste, lldb-commits

Differential Revision: https://reviews.llvm.org/D47889

llvm-svn: 334950
diff --git a/lldb/source/API/SBModule.cpp b/lldb/source/API/SBModule.cpp
index 1de1e54..8866cf4 100644
--- a/lldb/source/API/SBModule.cpp
+++ b/lldb/source/API/SBModule.cpp
@@ -531,16 +531,29 @@
 }
 
 uint32_t SBModule::GetVersion(uint32_t *versions, uint32_t num_versions) {
-  ModuleSP module_sp(GetSP());
-  if (module_sp)
-    return module_sp->GetVersion(versions, num_versions);
-  else {
-    if (versions && num_versions) {
-      for (uint32_t i = 0; i < num_versions; ++i)
-        versions[i] = UINT32_MAX;
-    }
-    return 0;
-  }
+  llvm::VersionTuple version;
+  if (ModuleSP module_sp = GetSP())
+    version = module_sp->GetVersion();
+  uint32_t result = 0;
+  if (!version.empty())
+    ++result;
+  if (version.getMinor())
+    ++result;
+  if(version.getSubminor())
+    ++result;
+
+  if (!versions)
+    return result;
+
+  if (num_versions > 0)
+    versions[0] = version.empty() ? UINT32_MAX : version.getMajor();
+  if (num_versions > 1)
+    versions[1] = version.getMinor().getValueOr(UINT32_MAX);
+  if (num_versions > 2)
+    versions[2] = version.getSubminor().getValueOr(UINT32_MAX);
+  for (uint32_t i = 3; i < num_versions; ++i)
+    versions[i] = UINT32_MAX;
+  return result;
 }
 
 lldb::SBFileSpec SBModule::GetSymbolFileSpec() const {
diff --git a/lldb/source/API/SBPlatform.cpp b/lldb/source/API/SBPlatform.cpp
index d559a66..5f29f00 100644
--- a/lldb/source/API/SBPlatform.cpp
+++ b/lldb/source/API/SBPlatform.cpp
@@ -330,27 +330,24 @@
 }
 
 uint32_t SBPlatform::GetOSMajorVersion() {
-  uint32_t major, minor, update;
-  PlatformSP platform_sp(GetSP());
-  if (platform_sp && platform_sp->GetOSVersion(major, minor, update))
-    return major;
-  return UINT32_MAX;
+  llvm::VersionTuple version;
+  if (PlatformSP platform_sp = GetSP())
+    version = platform_sp->GetOSVersion();
+  return version.empty() ? UINT32_MAX : version.getMajor();
 }
 
 uint32_t SBPlatform::GetOSMinorVersion() {
-  uint32_t major, minor, update;
-  PlatformSP platform_sp(GetSP());
-  if (platform_sp && platform_sp->GetOSVersion(major, minor, update))
-    return minor;
-  return UINT32_MAX;
+  llvm::VersionTuple version;
+  if (PlatformSP platform_sp = GetSP())
+    version = platform_sp->GetOSVersion();
+  return version.getMinor().getValueOr(UINT32_MAX);
 }
 
 uint32_t SBPlatform::GetOSUpdateVersion() {
-  uint32_t major, minor, update;
-  PlatformSP platform_sp(GetSP());
-  if (platform_sp && platform_sp->GetOSVersion(major, minor, update))
-    return update;
-  return UINT32_MAX;
+  llvm::VersionTuple version;
+  if (PlatformSP platform_sp = GetSP())
+    version = platform_sp->GetOSVersion();
+  return version.getSubminor().getValueOr(UINT32_MAX);
 }
 
 SBError SBPlatform::Get(SBFileSpec &src, SBFileSpec &dst) {