1//===--- DumpAST.h - Serialize clang AST to LSP -----------------*- C++-*--===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// Exposing clang's AST can give insight into the precise meaning of code.
10// (C++ is a complicated language, and very few people know all its rules).
11// Despite the name, clang's AST describes *semantics* and so includes nodes
12// for implicit behavior like conversions.
13//
14// It's also useful to developers who work with the clang AST specifically,
15// and want to know how certain constructs are represented.
16//
17// The main representation is not based on the familiar -ast-dump output,
18// which is heavy on internal details.
19// It also does not use the -ast-dump=json output, which captures the same
20// detail in a machine-friendly way, but requires client-side logic to present.
21// Instead, the key information is bundled into a few fields (role/kind/detail)
22// with weakly-defined semantics, optimized for easy presentation.
23// The -ast-dump output is preserved in the 'arcana' field, and may be shown
24// e.g. as a tooltip.
25//
26// The textDocument/ast method implemented here is a clangd extension.
27//
28//===----------------------------------------------------------------------===//
29
30#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_DUMPAST_H
31#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_DUMPAST_H
32
33#include "Protocol.h"
34#include "clang/AST/ASTContext.h"
35
36namespace clang {
37class DynTypedNode;
38namespace syntax {
39class TokenBuffer;
40} // namespace syntax
41namespace clangd {
42
43// Note: It's safe for the node to be a TranslationUnitDecl, as this function
44// does not deserialize the preamble.
45ASTNode dumpAST(const DynTypedNode &, const syntax::TokenBuffer &Tokens,
46 const ASTContext &);
47
48} // namespace clangd
49} // namespace clang
50
51#endif
52

source code of clang-tools-extra/clangd/DumpAST.h