mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
To use members of protocol extensions on existential types, we introduce an OpenExistentialExpr expression to open up the existential type (into a local archetype) and perform the operations on that local archetype. Unlike with uses of initializers or dynamic-Self-producing methods of protocols, which produce similar ASTs, we have the type checker perform the "open" operation and then track it through constraint application. This scheme is better (because it's more direct), but it's still using a simplistic approach to deciding where the actual OpenExistentialExpr goes that needs improvement. Swift SVN r26964
121 lines
3.1 KiB
C++
121 lines
3.1 KiB
C++
//===--- UUID.h - UUID generation -------------------------------*- 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This is an interface over the standard OSF uuid library that gives UUIDs
|
|
// sane value semantics and operators.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef SWIFT_BASIC_UUID_H
|
|
#define SWIFT_BASIC_UUID_H
|
|
|
|
#include "swift/Basic/LLVM.h"
|
|
#include "llvm/ADT/DenseMap.h"
|
|
#include "llvm/ADT/Optional.h"
|
|
#include "llvm/ADT/SmallString.h"
|
|
#include "llvm/ADT/StringRef.h"
|
|
#include "llvm/Support/raw_ostream.h"
|
|
#include <array>
|
|
|
|
namespace swift {
|
|
|
|
class UUID {
|
|
public:
|
|
enum {
|
|
/// The number of bytes in a UUID's binary representation.
|
|
Size = 16,
|
|
|
|
/// The number of characters in a UUID's string representation.
|
|
StringSize = 36,
|
|
|
|
/// The number of bytes necessary to store a null-terminated UUID's string
|
|
/// representation.
|
|
StringBufferSize = StringSize + 1,
|
|
};
|
|
|
|
unsigned char Value[Size];
|
|
|
|
private:
|
|
enum FromRandom_t { FromRandom };
|
|
enum FromTime_t { FromTime };
|
|
|
|
UUID(FromRandom_t);
|
|
|
|
UUID(FromTime_t);
|
|
|
|
public:
|
|
/// Default constructor.
|
|
UUID();
|
|
|
|
UUID(std::array<unsigned char, Size> bytes) {
|
|
memcpy(Value, &bytes, Size);
|
|
}
|
|
|
|
/// Create a new random UUID from entropy (/dev/random).
|
|
static UUID fromRandom() { return UUID(FromRandom); }
|
|
|
|
/// Create a new pseudorandom UUID using the time, MAC address, and pid.
|
|
static UUID fromTime() { return UUID(FromTime); }
|
|
|
|
/// Parse a UUID from a C string.
|
|
static Optional<UUID> fromString(const char *s);
|
|
|
|
/// Convert a UUID to its string representation.
|
|
void toString(llvm::SmallVectorImpl<char> &out) const;
|
|
|
|
int compare(UUID y) const;
|
|
|
|
#define COMPARE_UUID(op) \
|
|
bool operator op(UUID y) { return compare(y) op 0; }
|
|
|
|
COMPARE_UUID(==)
|
|
COMPARE_UUID(!=)
|
|
COMPARE_UUID(<)
|
|
COMPARE_UUID(<=)
|
|
COMPARE_UUID(>)
|
|
COMPARE_UUID(>=)
|
|
#undef COMPARE_UUID
|
|
};
|
|
|
|
llvm::raw_ostream &operator<<(llvm::raw_ostream &os, UUID uuid);
|
|
|
|
}
|
|
|
|
namespace llvm {
|
|
template<>
|
|
struct DenseMapInfo<swift::UUID> {
|
|
static inline swift::UUID getEmptyKey() {
|
|
return {{{0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
|
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}}};
|
|
}
|
|
static inline swift::UUID getTombstoneKey() {
|
|
return {{{0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
|
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE}}};
|
|
}
|
|
|
|
static unsigned getHashValue(swift::UUID uuid) {
|
|
union {
|
|
swift::UUID uu;
|
|
unsigned words[4];
|
|
} reinterpret = {uuid};
|
|
return reinterpret.words[0] ^ reinterpret.words[1]
|
|
^ reinterpret.words[2] ^ reinterpret.words[3];
|
|
}
|
|
|
|
static bool isEqual(swift::UUID a, swift::UUID b) {
|
|
return a == b;
|
|
}
|
|
};
|
|
}
|
|
|
|
#endif
|