mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Internal compiler versions must be able to be packed into a 64-bit value, and there is a limit on how many components we can use and which values they can take on. Versions must have no more than five components, assuming a version X.Y.Z.a.b, where X, Y, Z, a, and b are integers with the following inclusive ranges: X: [0 - 214747] Y: [0 - 999] Z: [0 - 999] a: [0 - 999] b: [0 - 999] Swift SVN r32724
98 lines
3.0 KiB
C++
98 lines
3.0 KiB
C++
//===- Version.h - Swift Version Number -------------------------*- C++ -*-===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See http://swift.org/LICENSE.txt for license information
|
|
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
///
|
|
/// \file
|
|
/// \brief Defines version macros and version-related utility functions
|
|
/// for Swift.
|
|
///
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef SWIFT_BASIC_VERSION_H
|
|
#define SWIFT_BASIC_VERSION_H
|
|
|
|
#include <string>
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
|
#include "llvm/ADT/SmallVector.h"
|
|
|
|
namespace swift {
|
|
|
|
class DiagnosticEngine;
|
|
class SourceLoc;
|
|
|
|
namespace version {
|
|
|
|
/// Represents an internal compiler version, represented as a tuple of
|
|
/// integers, or "version components".
|
|
///
|
|
/// For comparison, if a `CompilerVersion` contains more than one
|
|
/// version component, the second one is ignored for comparison,
|
|
/// as it represents a compiler variant with no defined ordering.
|
|
///
|
|
/// A CompilerVersion must have no more than five components and must fit in a
|
|
/// 64-bit unsigned integer representation.
|
|
///
|
|
/// Assuming a maximal version component layout of X.Y.Z.a.b,
|
|
/// X, Y, Z, a, b are integers with the following (inclusive) ranges:
|
|
/// X: [0 - 9223371]
|
|
/// Y: [0 - 999]
|
|
/// Z: [0 - 999]
|
|
/// a: [0 - 999]
|
|
/// b: [0 - 999]
|
|
class CompilerVersion {
|
|
llvm::SmallVector<unsigned, 5> Components;
|
|
public:
|
|
/// Create a version from the currently defined SWIFT_COMPILER_VERSION.
|
|
///
|
|
/// If SWIFT_COMPILER_VERSION is undefined, this will always compare greater
|
|
/// or equal to any other CompilerVersion, as in the case of building Swift
|
|
/// from latest sources outside of a build/integration/release context.
|
|
CompilerVersion();
|
|
|
|
/// Create a version from a string in source code.
|
|
///
|
|
/// Must include only groups of digits separated by a dot.
|
|
CompilerVersion(const llvm::StringRef VersionString, SourceLoc Loc,
|
|
DiagnosticEngine *Diags);
|
|
|
|
/// Return a printable string representation of the version.
|
|
std::string str() const;
|
|
|
|
/// Return the ith version component.
|
|
unsigned operator[](size_t i) const {
|
|
return Components[i];
|
|
}
|
|
|
|
/// Return the number of version components.
|
|
size_t size() const {
|
|
return Components.size();
|
|
}
|
|
|
|
bool empty() const {
|
|
return Components.empty();
|
|
}
|
|
};
|
|
|
|
bool operator>=(const CompilerVersion &lhs, const CompilerVersion &rhs);
|
|
|
|
/// Retrieves the numeric {major, minor} Swift version.
|
|
std::pair<unsigned, unsigned> getSwiftNumericVersion();
|
|
|
|
/// Retrieves a string representing the complete Swift version, which includes
|
|
/// the Swift version number, the repository version, and the vendor tag.
|
|
std::string getSwiftFullVersion();
|
|
|
|
} // end namespace version
|
|
} // end namespace swift
|
|
|
|
#endif
|