Implement a new 'availability' attribute, that allows one to specify
which versions of an OS provide a certain facility. For example,
void foo()
__attribute__((availability(macosx,introduced=10.2,deprecated=10.4,obsoleted=10.6)));
says that the function "foo" was introduced in 10.2, deprecated in
10.4, and completely obsoleted in 10.6. This attribute ties in with
the deployment targets (e.g., -mmacosx-version-min=10.1 specifies that
we want to deploy back to Mac OS X 10.1). There are several concrete
behaviors that this attribute enables, as illustrated with the
function foo() above:
- If we choose a deployment target >= Mac OS X 10.4, uses of "foo"
will result in a deprecation warning, as if we had placed
attribute((deprecated)) on it (but with a better diagnostic)
- If we choose a deployment target >= Mac OS X 10.6, uses of "foo"
will result in an "unavailable" warning (in C)/error (in C++), as
if we had placed attribute((unavailable)) on it
- If we choose a deployment target prior to 10.2, foo() is
weak-imported (if it is a kind of entity that can be weak
imported), as if we had placed the weak_import attribute on it.
Naturally, there can be multiple availability attributes on a
declaration, for different platforms; only the current platform
matters when checking availability attributes.
The only platforms this attribute currently works for are "ios" and
"macosx", since we already have -mxxxx-version-min flags for them and we
have experience there with macro tricks translating down to the
deprecated/unavailable/weak_import attributes. The end goal is to open
this up to other platforms, and even extension to other "platforms"
that are really libraries (say, through a #pragma clang
define_system), but that hasn't yet been designed and we may want to
shake out more issues with this narrower problem first.
Addresses <rdar://problem/6690412>.
As a drive-by bug-fix, if an entity is both deprecated and
unavailable, we only emit the "unavailable" diagnostic.
llvm-svn: 128127
2011-03-23 08:50:03 +08:00
|
|
|
//===- VersionTuple.cpp - Version Number Handling ---------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the VersionTuple class, which represents a version in
|
|
|
|
// the form major[.minor[.subminor]].
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "clang/Basic/VersionTuple.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
|
|
|
|
using namespace clang;
|
|
|
|
|
|
|
|
std::string VersionTuple::getAsString() const {
|
|
|
|
std::string Result;
|
|
|
|
{
|
|
|
|
llvm::raw_string_ostream Out(Result);
|
|
|
|
Out << *this;
|
|
|
|
}
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2011-07-23 18:55:15 +08:00
|
|
|
raw_ostream& clang::operator<<(raw_ostream &Out,
|
Implement a new 'availability' attribute, that allows one to specify
which versions of an OS provide a certain facility. For example,
void foo()
__attribute__((availability(macosx,introduced=10.2,deprecated=10.4,obsoleted=10.6)));
says that the function "foo" was introduced in 10.2, deprecated in
10.4, and completely obsoleted in 10.6. This attribute ties in with
the deployment targets (e.g., -mmacosx-version-min=10.1 specifies that
we want to deploy back to Mac OS X 10.1). There are several concrete
behaviors that this attribute enables, as illustrated with the
function foo() above:
- If we choose a deployment target >= Mac OS X 10.4, uses of "foo"
will result in a deprecation warning, as if we had placed
attribute((deprecated)) on it (but with a better diagnostic)
- If we choose a deployment target >= Mac OS X 10.6, uses of "foo"
will result in an "unavailable" warning (in C)/error (in C++), as
if we had placed attribute((unavailable)) on it
- If we choose a deployment target prior to 10.2, foo() is
weak-imported (if it is a kind of entity that can be weak
imported), as if we had placed the weak_import attribute on it.
Naturally, there can be multiple availability attributes on a
declaration, for different platforms; only the current platform
matters when checking availability attributes.
The only platforms this attribute currently works for are "ios" and
"macosx", since we already have -mxxxx-version-min flags for them and we
have experience there with macro tricks translating down to the
deprecated/unavailable/weak_import attributes. The end goal is to open
this up to other platforms, and even extension to other "platforms"
that are really libraries (say, through a #pragma clang
define_system), but that hasn't yet been designed and we may want to
shake out more issues with this narrower problem first.
Addresses <rdar://problem/6690412>.
As a drive-by bug-fix, if an entity is both deprecated and
unavailable, we only emit the "unavailable" diagnostic.
llvm-svn: 128127
2011-03-23 08:50:03 +08:00
|
|
|
const VersionTuple &V) {
|
|
|
|
Out << V.getMajor();
|
2013-02-21 06:23:23 +08:00
|
|
|
if (Optional<unsigned> Minor = V.getMinor())
|
2014-10-07 00:46:02 +08:00
|
|
|
Out << (V.usesUnderscores() ? '_' : '.') << *Minor;
|
2013-02-21 06:23:23 +08:00
|
|
|
if (Optional<unsigned> Subminor = V.getSubminor())
|
2014-10-07 00:46:02 +08:00
|
|
|
Out << (V.usesUnderscores() ? '_' : '.') << *Subminor;
|
2015-03-22 16:39:22 +08:00
|
|
|
if (Optional<unsigned> Build = V.getBuild())
|
|
|
|
Out << (V.usesUnderscores() ? '_' : '.') << *Build;
|
Implement a new 'availability' attribute, that allows one to specify
which versions of an OS provide a certain facility. For example,
void foo()
__attribute__((availability(macosx,introduced=10.2,deprecated=10.4,obsoleted=10.6)));
says that the function "foo" was introduced in 10.2, deprecated in
10.4, and completely obsoleted in 10.6. This attribute ties in with
the deployment targets (e.g., -mmacosx-version-min=10.1 specifies that
we want to deploy back to Mac OS X 10.1). There are several concrete
behaviors that this attribute enables, as illustrated with the
function foo() above:
- If we choose a deployment target >= Mac OS X 10.4, uses of "foo"
will result in a deprecation warning, as if we had placed
attribute((deprecated)) on it (but with a better diagnostic)
- If we choose a deployment target >= Mac OS X 10.6, uses of "foo"
will result in an "unavailable" warning (in C)/error (in C++), as
if we had placed attribute((unavailable)) on it
- If we choose a deployment target prior to 10.2, foo() is
weak-imported (if it is a kind of entity that can be weak
imported), as if we had placed the weak_import attribute on it.
Naturally, there can be multiple availability attributes on a
declaration, for different platforms; only the current platform
matters when checking availability attributes.
The only platforms this attribute currently works for are "ios" and
"macosx", since we already have -mxxxx-version-min flags for them and we
have experience there with macro tricks translating down to the
deprecated/unavailable/weak_import attributes. The end goal is to open
this up to other platforms, and even extension to other "platforms"
that are really libraries (say, through a #pragma clang
define_system), but that hasn't yet been designed and we may want to
shake out more issues with this narrower problem first.
Addresses <rdar://problem/6690412>.
As a drive-by bug-fix, if an entity is both deprecated and
unavailable, we only emit the "unavailable" diagnostic.
llvm-svn: 128127
2011-03-23 08:50:03 +08:00
|
|
|
return Out;
|
|
|
|
}
|
2012-06-20 14:18:46 +08:00
|
|
|
|
|
|
|
static bool parseInt(StringRef &input, unsigned &value) {
|
|
|
|
assert(value == 0);
|
|
|
|
if (input.empty()) return true;
|
|
|
|
|
|
|
|
char next = input[0];
|
|
|
|
input = input.substr(1);
|
|
|
|
if (next < '0' || next > '9') return true;
|
|
|
|
value = (unsigned) (next - '0');
|
|
|
|
|
|
|
|
while (!input.empty()) {
|
|
|
|
next = input[0];
|
|
|
|
if (next < '0' || next > '9') return false;
|
|
|
|
input = input.substr(1);
|
|
|
|
value = value * 10 + (unsigned) (next - '0');
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VersionTuple::tryParse(StringRef input) {
|
2015-03-22 16:39:22 +08:00
|
|
|
unsigned major = 0, minor = 0, micro = 0, build = 0;
|
2012-06-20 14:18:46 +08:00
|
|
|
|
|
|
|
// Parse the major version, [0-9]+
|
|
|
|
if (parseInt(input, major)) return true;
|
|
|
|
|
|
|
|
if (input.empty()) {
|
|
|
|
*this = VersionTuple(major);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we're not done, parse the minor version, \.[0-9]+
|
|
|
|
if (input[0] != '.') return true;
|
|
|
|
input = input.substr(1);
|
|
|
|
if (parseInt(input, minor)) return true;
|
|
|
|
|
|
|
|
if (input.empty()) {
|
|
|
|
*this = VersionTuple(major, minor);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we're not done, parse the micro version, \.[0-9]+
|
|
|
|
if (input[0] != '.') return true;
|
|
|
|
input = input.substr(1);
|
|
|
|
if (parseInt(input, micro)) return true;
|
|
|
|
|
2015-03-22 16:39:22 +08:00
|
|
|
if (input.empty()) {
|
|
|
|
*this = VersionTuple(major, minor, micro);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we're not done, parse the micro version, \.[0-9]+
|
|
|
|
if (input[0] != '.') return true;
|
|
|
|
input = input.substr(1);
|
|
|
|
if (parseInt(input, build)) return true;
|
|
|
|
|
2012-06-20 14:18:46 +08:00
|
|
|
// If we have characters left over, it's an error.
|
|
|
|
if (!input.empty()) return true;
|
|
|
|
|
2015-03-22 16:39:22 +08:00
|
|
|
*this = VersionTuple(major, minor, micro, build);
|
2012-06-20 14:18:46 +08:00
|
|
|
return false;
|
|
|
|
}
|