Files
swift-mirror/include/swift/AST/ConcreteDeclRef.h
Brent Royal-Gordon 99faa033fc [NFC] Standardize dump() methods in frontend
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.
2019-10-31 18:37:42 -07:00

92 lines
3.0 KiB
C++

//===--- ConcreteDeclRef.h - Reference to a concrete decl -------*- 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 file defines the ConcreteDeclRef class, which provides a reference to
// a declaration that is potentially specialized.
//===----------------------------------------------------------------------===//
#ifndef SWIFT_AST_CONCRETEDECLREF_H
#define SWIFT_AST_CONCRETEDECLREF_H
#include "swift/Basic/Debug.h"
#include "swift/Basic/LLVM.h"
#include "swift/AST/SubstitutionMap.h"
#include "swift/AST/TypeAlignments.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/PointerUnion.h"
#include "llvm/Support/Compiler.h"
#include <cstring>
namespace swift {
class ASTContext;
class SourceManager;
class ValueDecl;
/// A reference to a concrete representation of a particular declaration,
/// providing substitutions for all type parameters of the original,
/// underlying declaration.
class ConcreteDeclRef {
/// The declaration.
ValueDecl *decl = nullptr;
/// The substitutions.
SubstitutionMap substitutions;
public:
/// Create an empty declaration reference.
ConcreteDeclRef() { }
/// Construct a reference to the given value.
ConcreteDeclRef(ValueDecl *decl) : decl(decl) { }
/// Construct a reference to the given value, specialized with the given
/// substitutions.
///
/// \param decl The declaration to which this reference refers, which will
/// be specialized by applying the given substitutions.
///
/// \param substitutions The complete set of substitutions to apply to the
/// given declaration.
ConcreteDeclRef(ValueDecl *decl, SubstitutionMap substitutions)
: decl(decl), substitutions(substitutions) { }
/// Determine whether this declaration reference refers to anything.
explicit operator bool() const { return decl != nullptr; }
/// Retrieve the declarations to which this reference refers.
ValueDecl *getDecl() const { return decl; }
/// Retrieve a reference to the declaration this one overrides.
ConcreteDeclRef getOverriddenDecl() const;
/// Determine whether this reference specializes the declaration to which
/// it refers.
bool isSpecialized() const { return !substitutions.empty(); }
/// For a specialized reference, return the set of substitutions applied to
/// the declaration reference.
SubstitutionMap getSubstitutions() const { return substitutions; }
friend bool operator==(ConcreteDeclRef lhs, ConcreteDeclRef rhs) {
return lhs.decl == rhs.decl && lhs.substitutions == rhs.substitutions;
}
/// Dump a debug representation of this reference.
void dump(raw_ostream &os) const;
SWIFT_DEBUG_DUMP;
};
} // end namespace swift
#endif