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.
59 lines
2.2 KiB
C++
59 lines
2.2 KiB
C++
//===--- SyntaxASTMap.h - Swift Container for Semantic Info -----*- 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 declares the interface for SyntaxASTMap, a container mapping Syntax
|
|
// nodes to the Semantic AST.
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef SWIFT_AST_SYNTAXASTMAP_H
|
|
#define SWIFT_AST_SYNTAXASTMAP_H
|
|
|
|
#include "swift/AST/ASTNode.h"
|
|
#include "swift/Basic/Debug.h"
|
|
#include "swift/Syntax/Syntax.h"
|
|
#include "llvm/ADT/DenseMap.h"
|
|
#include "llvm/ADT/Optional.h"
|
|
|
|
namespace swift {
|
|
|
|
/// The top-level container and manager for semantic analysis.
|
|
///
|
|
/// Eventually, this should contain cached semantic information such as
|
|
/// resolved symbols and types for Syntax nodes. For now, it only maintains
|
|
/// a mapping from lib/AST nodes to lib/Syntax nodes while we integrate
|
|
/// the infrastructure into the compiler.
|
|
class SyntaxASTMap final {
|
|
llvm::DenseMap<RC<syntax::SyntaxData>, ASTNode> SyntaxMap;
|
|
public:
|
|
|
|
/// Record a syntax node -> semantic node mapping for later retrieval.
|
|
///
|
|
/// This is a temporary measure to get a syntax node's Type or resolved
|
|
/// underlying declaration reference after semantic analysis is done.
|
|
void recordSyntaxMapping(RC<syntax::SyntaxData> FromNode,
|
|
ASTNode ToNode);
|
|
|
|
/// Get the semantic node for a piece of syntax. This must have been
|
|
/// previously recorded with a call to `recordSyntaxMapping`.
|
|
llvm::Optional<ASTNode> getNodeForSyntax(syntax::Syntax SyntaxNode) const;
|
|
|
|
/// Clear any associations between syntax nodes and semantic nodes.
|
|
void clearSyntaxMap();
|
|
|
|
/// Dump the entire syntax node -> semantic node map for debugging purposes.
|
|
SWIFT_DEBUG_DUMPER(dumpSyntaxMap());
|
|
};
|
|
|
|
} // end namespace swift
|
|
|
|
#endif // SWIFT_AST_SYNTAXASTMAP_H
|