mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
The use of ASTContext-allocated arrays to store the members of nominal type declarations and the extensions thereof is an abomination. Instead, introduce the notion of an "iterable" declaration context, which keeps track of the declarations within that context (stored as a singly-linked list) and allows iteration over them. When a member is added, it will also make sure that the member goes into the lookup table for its context immediately. This eliminates a ton of wasted memory when we have to reallocate the members arrays for types and extensions, and moves us toward a much more sane model. The only functionality change here is that the Clang importer no longer puts subscript declarations into the wrong class, nor does it nested a C struct within another C struct. Swift SVN r16572
76 lines
2.7 KiB
C++
76 lines
2.7 KiB
C++
//===--- DerivedConformances.h - Derived protocol conformance ---*- 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 file defines entry points to synthesize compiler-derived conformances
|
|
// to certain known protocols.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef SWIFT_SEMA_DERIVEDCONFORMANCES_H
|
|
#define SWIFT_SEMA_DERIVEDCONFORMANCES_H
|
|
|
|
namespace swift {
|
|
class Decl;
|
|
class NominalTypeDecl;
|
|
class TypeChecker;
|
|
class ValueDecl;
|
|
|
|
namespace DerivedConformance {
|
|
|
|
/// Derive a RawRepresentable requirement for an enum, if it has a valid
|
|
/// raw type and raw values for all of its cases.
|
|
///
|
|
/// \returns the derived member, which will also be added to the type.
|
|
ValueDecl *deriveRawRepresentable(TypeChecker &tc,
|
|
NominalTypeDecl *type,
|
|
ValueDecl *requirement);
|
|
|
|
/// Derive an Equatable requirement for a type.
|
|
///
|
|
/// Currently this is only implemented for simple enums. Obvious generalizations
|
|
/// would be to enums with all-Equatable payloads and to structs with all-
|
|
/// Equatable stored properties.
|
|
///
|
|
/// \returns the derived member, which will also be added to the type.
|
|
ValueDecl *deriveEquatable(TypeChecker &tc,
|
|
NominalTypeDecl *type,
|
|
ValueDecl *requirement);
|
|
|
|
/// Derive a Hashable requirement for a type.
|
|
///
|
|
/// Currently this is only implemented for simple enums. Obvious generalizations
|
|
/// would be to enums with all-Hashable payloads and to structs with all-
|
|
/// Hashable stored properties.
|
|
///
|
|
/// \returns the derived member, which will also be added to the type.
|
|
ValueDecl *deriveHashable(TypeChecker &tc,
|
|
NominalTypeDecl *type,
|
|
ValueDecl *requirement);
|
|
|
|
/// Insert an operator declaration associated with a nominal type. The
|
|
/// declaration is added at global scope
|
|
void _insertOperatorDecl(NominalTypeDecl *scope, Decl *member);
|
|
|
|
/// Insert a declaration as a member of a nominal type. The declaration is
|
|
/// added at file scope as close as possible to the
|
|
template<typename SomeDecl>
|
|
inline SomeDecl *insertOperatorDecl(NominalTypeDecl *scope, SomeDecl *member) {
|
|
::swift::DerivedConformance::_insertOperatorDecl(scope, member);
|
|
return member;
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|