mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 09:21:04 +01:00
Add Dump functions to Check, Parse, and Lex (#4669)
- Provide `Check::Dump(context, arg)` and similar. - gdb and lldb should do contextual lookup, and `call Dump(*this, Lex::TokenIndex::Invalid)` has been tested with gdb. - Since this is only for debug, keeps the functions fully separated from code. - Uses alwayslink to ensure objects are correctly linked, even though there are no calls. - `-Wno-missing-prototypes` is needed when we don't have forward declarations. - Code is not linked in opt builds, using `#ifndef NDEBUG`. - This probably could be doing something in BUILD files with a `select()`, but the `#ifndef` seemed easier. This is based on #4620, but uses free functions instead of member functions. Co-authored-by: Dana Jansens <danakj@orodu.net> --------- Co-authored-by: danakj <danakj@orodu.net>
This commit is contained in:
co-authored by
Dana Jansens
parent
79ba184dab
commit
3ce0df67bb
@@ -0,0 +1,39 @@
|
||||
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
||||
// Exceptions. See /LICENSE for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
#ifndef NDEBUG
|
||||
|
||||
#include "toolchain/parse/dump.h"
|
||||
|
||||
#include "common/ostream.h"
|
||||
#include "toolchain/lex/dump.h"
|
||||
|
||||
namespace Carbon::Parse {
|
||||
|
||||
auto DumpNoNewline(const Tree& tree, NodeId node_id) -> void {
|
||||
if (!node_id.is_valid()) {
|
||||
llvm::errs() << "NodeId(invalid)";
|
||||
return;
|
||||
}
|
||||
|
||||
auto kind = tree.node_kind(node_id);
|
||||
auto token = tree.node_token(node_id);
|
||||
|
||||
llvm::errs() << "NodeId(kind: " << kind << ", token: ";
|
||||
Lex::DumpNoNewline(tree.tokens(), token);
|
||||
llvm::errs() << ")";
|
||||
}
|
||||
|
||||
LLVM_DUMP_METHOD auto Dump(const Tree& tree, Lex::TokenIndex token) -> void {
|
||||
Lex::Dump(tree.tokens(), token);
|
||||
}
|
||||
|
||||
LLVM_DUMP_METHOD auto Dump(const Tree& tree, NodeId node_id) -> void {
|
||||
DumpNoNewline(tree, node_id);
|
||||
llvm::errs() << '\n';
|
||||
}
|
||||
|
||||
} // namespace Carbon::Parse
|
||||
|
||||
#endif // NDEBUG
|
||||
Reference in New Issue
Block a user