mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
This name makes it clear that the function has not yet been deleted and also contrasts with the past tense used in the API notifyAddedOrModifiedFunction to show that said function has already added/modified the function.
88 lines
2.9 KiB
C++
88 lines
2.9 KiB
C++
//===--- ProtocolConformanceAnalysis.h - Protocol Conformance ---*- C++ -*-===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See https://swift.org/LICENSE.txt for license information
|
|
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
// This analysis collects a set of nominal types (classes, structs, and enums)
|
|
// that conform to a protocol during whole module compilation. We only track
|
|
// protocols that are non-public.
|
|
|
|
#ifndef SWIFT_SILOPTIMIZER_ANALYSIS_PROTOCOLCONFORMANCE_H
|
|
#define SWIFT_SILOPTIMIZER_ANALYSIS_PROTOCOLCONFORMANCE_H
|
|
|
|
#include "swift/SIL/SILArgument.h"
|
|
#include "swift/SIL/SILValue.h"
|
|
#include "swift/SILOptimizer/Analysis/Analysis.h"
|
|
#include "llvm/ADT/DenseMap.h"
|
|
#include "llvm/ADT/SmallSet.h"
|
|
#include "llvm/ADT/SmallVector.h"
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
namespace swift {
|
|
|
|
class SILModule;
|
|
class NominalTypeDecl;
|
|
class ProtocolDecl;
|
|
|
|
class ProtocolConformanceAnalysis : public SILAnalysis {
|
|
public:
|
|
typedef SmallVector<NominalTypeDecl *, 8> NominalTypeList;
|
|
typedef llvm::DenseMap<ProtocolDecl *, NominalTypeList>
|
|
ProtocolConformanceMap;
|
|
|
|
ProtocolConformanceAnalysis(SILModule *Mod)
|
|
: SILAnalysis(SILAnalysisKind::ProtocolConformance), M(Mod) {
|
|
init();
|
|
}
|
|
|
|
~ProtocolConformanceAnalysis();
|
|
|
|
static bool classof(const SILAnalysis *S) {
|
|
return S->getKind() == SILAnalysisKind::ProtocolConformance;
|
|
}
|
|
|
|
/// Invalidate all information in this analysis.
|
|
virtual void invalidate() override {}
|
|
|
|
/// Invalidate all of the information for a specific function.
|
|
virtual void invalidate(SILFunction *F, InvalidationKind K) override {}
|
|
|
|
/// Notify the analysis about a newly created function.
|
|
virtual void notifyAddedOrModifiedFunction(SILFunction *F) override {}
|
|
|
|
/// Notify the analysis about a function which will be deleted from the
|
|
/// module.
|
|
virtual void notifyWillDeleteFunction(SILFunction *F) override {}
|
|
|
|
/// Notify the analysis about changed witness or vtables.
|
|
virtual void invalidateFunctionTables() override {}
|
|
|
|
/// Get the nominal types that implement a protocol.
|
|
ArrayRef<NominalTypeDecl *> getConformances(const ProtocolDecl *P) const {
|
|
auto ConformsListIt = ProtocolConformanceCache.find(P);
|
|
return ConformsListIt != ProtocolConformanceCache.end()
|
|
? ArrayRef<NominalTypeDecl *>(ConformsListIt->second.begin(),
|
|
ConformsListIt->second.end())
|
|
: ArrayRef<NominalTypeDecl *>();
|
|
}
|
|
|
|
private:
|
|
/// Compute inheritance properties.
|
|
void init();
|
|
|
|
/// The module.
|
|
SILModule *M;
|
|
|
|
/// A cache that maps a protocol to its conformances
|
|
ProtocolConformanceMap ProtocolConformanceCache;
|
|
};
|
|
|
|
} // namespace swift
|
|
#endif
|