mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
By convention, most structs and classes in the Swift compiler include a `dump()` method which prints debugging information. This method is meant to be called only from the debugger, but this means they’re often unused and may be eliminated from optimized binaries. On the other hand, some parts of the compiler call `dump()` methods directly despite them being intended as a pure debugging aid. clang supports attributes which can be used to avoid these problems, but they’re used very inconsistently across the compiler. This commit adds `SWIFT_DEBUG_DUMP` and `SWIFT_DEBUG_DUMPER(<name>(<params>))` macros to declare `dump()` methods with the appropriate set of attributes and adopts this macro throughout the frontend. It does not pervasively adopt this macro in SILGen, SILOptimizer, or IRGen; these components use `dump()` methods in a different way where they’re frequently called from debugging code. Nor does it adopt it in runtime components like swiftRuntime and swiftReflection, because I’m a bit worried about size. Despite the large number of files and lines affected, this change is NFC.
67 lines
2.1 KiB
C++
67 lines
2.1 KiB
C++
//===--- ConcreteDeclRef.cpp - Reference to a concrete decl ---------------===//
|
|
//
|
|
// 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 file implements the ConcreteDeclRef class, which provides a reference to
|
|
// a declaration that is potentially specialized.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "swift/AST/ASTContext.h"
|
|
#include "swift/AST/ConcreteDeclRef.h"
|
|
#include "swift/AST/Decl.h"
|
|
#include "swift/AST/GenericSignature.h"
|
|
#include "swift/AST/ProtocolConformance.h"
|
|
#include "swift/AST/SubstitutionMap.h"
|
|
#include "swift/AST/Types.h"
|
|
#include "llvm/Support/raw_ostream.h"
|
|
using namespace swift;
|
|
|
|
ConcreteDeclRef ConcreteDeclRef::getOverriddenDecl() const {
|
|
auto *derivedDecl = getDecl();
|
|
auto *baseDecl = derivedDecl->getOverriddenDecl();
|
|
|
|
auto baseSig = baseDecl->getInnermostDeclContext()
|
|
->getGenericSignatureOfContext();
|
|
auto derivedSig = derivedDecl->getInnermostDeclContext()
|
|
->getGenericSignatureOfContext();
|
|
|
|
SubstitutionMap subs;
|
|
if (baseSig) {
|
|
Optional<SubstitutionMap> derivedSubMap;
|
|
if (derivedSig)
|
|
derivedSubMap = getSubstitutions();
|
|
subs = SubstitutionMap::getOverrideSubstitutions(baseDecl, derivedDecl,
|
|
derivedSubMap);
|
|
}
|
|
return ConcreteDeclRef(baseDecl, subs);
|
|
}
|
|
|
|
void ConcreteDeclRef::dump(raw_ostream &os) const {
|
|
if (!getDecl()) {
|
|
os << "**NULL**";
|
|
return;
|
|
}
|
|
|
|
getDecl()->dumpRef(os);
|
|
|
|
// If specialized, dump the substitutions.
|
|
if (isSpecialized()) {
|
|
os << " [with ";
|
|
getSubstitutions().dump(os, SubstitutionMap::DumpStyle::Minimal);
|
|
os << ']';
|
|
}
|
|
}
|
|
|
|
void ConcreteDeclRef::dump() const {
|
|
dump(llvm::errs());
|
|
}
|